diff --git a/.env.example b/.env.example index 7e44fac..a51288b 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ -NODE_PROVIDER_MATIC_RPC_URL=https://matic-mainnet.chainstacklabs.com -TEST_TIMEOUT=300000 -NODE_PROVIDER_MUMBAI_RPC_URL=https://matic-mumbai.chainstacklabs.com -NODE_PROVIDER_CELO_RPC_URL=https://forno.celo.org +NODE_PROVIDER_MATIC_RPC_URL=https://rpc.ankr.com/polygon +TEST_TIMEOUT=700000 +NODE_PROVIDER_MUMBAI_RPC_URL=https://rpc.ankr.com/polygon_mumbai +NODE_PROVIDER_CELO_RPC_URL=https://rpc.ankr.com/celo NODE_PROVIDER_ALFAJORES_RPC_URL=https://alfajores-forno.celo-testnet.org diff --git a/README.md b/README.md index 9b92425..ff3c9c7 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ To retire Carbon Credits on mainnet, you will have to get Carbon Pool Tokens fro **Redeem your Pool Tokens and get an array of redeemed TCO2s** ```typescript -const tco2addresses = await toucan.redeemAuto2("NCT", parseEther("1")); +const tco2Addresses = await toucan.redeemAuto("NCT", parseEther("1")); ``` **Retire the Carbon Credits** diff --git a/hardhat.config.ts b/hardhat.config.ts index 38a8fa4..3a2612d 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -26,7 +26,7 @@ const config: HardhatUserConfig = { forking: { url: process.env.NODE_PROVIDER_MATIC_RPC_URL || - "https://matic-mainnet.chainstacklabs.com", + "https://rpc.ankr.com/polygon", }, }, }, diff --git a/src/index.ts b/src/index.ts index 5a12800..87d0c0a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -43,6 +43,7 @@ import { UserRedeemsMethod, UserRetirementsMethod, } from "./types/methods"; +import { RedeemAutoResponse } from "./types/responses"; /** * @@ -311,7 +312,7 @@ export default class ToucanClient { redeemAuto = async ( pool: PoolSymbol, amount: BigNumber - ): Promise => { + ): Promise => { if (!this.signer) throw new Error("No signer set"); const signer = this.signer; @@ -320,6 +321,7 @@ export default class ToucanClient { /** * + * @deprecated This function is deprecated. Please use `redeemAuto` instead. * @description automatically redeems pool tokens for TCO2s * @param pool symbol of the pool (token) to use * @param amount amount to redeem @@ -328,7 +330,7 @@ export default class ToucanClient { redeemAuto2 = async ( pool: PoolSymbol, amount: BigNumber - ): Promise<{ address: string; amount: BigNumber }[]> => { + ): Promise => { if (!this.signer) throw new Error("No signer set"); const signer = this.signer; diff --git a/src/subclasses/ContractInteractions.ts b/src/subclasses/ContractInteractions.ts index b1d880c..99b9b45 100644 --- a/src/subclasses/ContractInteractions.ts +++ b/src/subclasses/ContractInteractions.ts @@ -31,6 +31,7 @@ import { OffsetHelper, } from "../typechain"; import { Network, PoolSymbol } from "../types"; +import { RedeemAutoResponse } from "../types/responses"; import { GAS_LIMIT } from "../utils"; import { poolTokenABI, @@ -316,17 +317,33 @@ class ContractInteractions { pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer - ): Promise => { + ): Promise => { const poolToken = this.getPoolContract(pool, signer); + const redeemReceipt = await ( + await poolToken.redeemAuto(amount, { gasLimit: GAS_LIMIT }) + ).wait(); - const redeemTxn: ContractTransaction = await poolToken.redeemAuto(amount, { - gasLimit: GAS_LIMIT, - }); - return await redeemTxn.wait(); + if (!redeemReceipt.events) { + throw new Error("No events to get tco2 addresses and amounts from"); + } + + return redeemReceipt.events.reduce( + (acc: Array<{ address: string; amount: BigNumber }>, event) => { + if ( + event.event === "Redeemed" && + event.args?.erc20 && + event.args?.amount + ) { + acc.push({ address: event.args.erc20, amount: event.args.amount }); + } + return acc; + }, + [] + ); }; /** - * + * @deprecated This function is deprecated. Please use `redeemAuto` instead. * @description automatically redeems pool tokens for TCO2s * @param pool symbol of the pool (token) to use * @param amount amount to redeem @@ -337,7 +354,7 @@ class ContractInteractions { pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer - ): Promise<{ address: string; amount: BigNumber }[]> => { + ): Promise => { const poolToken = this.getPoolContract(pool, signer); const redeemReceipt = await ( await poolToken.redeemAuto2(amount, { gasLimit: GAS_LIMIT }) @@ -347,15 +364,19 @@ class ContractInteractions { throw new Error("No events to get tco2 addresses and amounts from"); } - return redeemReceipt.events - .filter((event) => { - return ( - event.event == "Redeemed" && event.args?.erc20 && event.args?.amount - ); - }) - .map((event) => { - return { address: event.args?.erc20, amount: event.args?.amount }; - }); + return redeemReceipt.events.reduce( + (acc: Array<{ address: string; amount: BigNumber }>, event) => { + if ( + event.event === "Redeemed" && + event.args?.erc20 && + event.args?.amount + ) { + acc.push({ address: event.args.erc20, amount: event.args.amount }); + } + return acc; + }, + [] + ); }; /** diff --git a/src/typechain/IToucanPoolToken.d.ts b/src/typechain/IToucanPoolToken.d.ts index ad4766f..643bac2 100644 --- a/src/typechain/IToucanPoolToken.d.ts +++ b/src/typechain/IToucanPoolToken.d.ts @@ -382,7 +382,12 @@ export class IToucanPoolToken extends BaseContract { getScoredTCO2s(overrides?: CallOverrides): Promise; - redeemAuto(amount: BigNumberish, overrides?: CallOverrides): Promise; + redeemAuto( + amount: BigNumberish, + overrides?: CallOverrides + ): Promise< + [string[], BigNumber[]] & { tco2s: string[]; amounts: BigNumber[] } + >; redeemAuto2( amount: BigNumberish, diff --git a/src/typechain/OffsetHelper.d.ts b/src/typechain/OffsetHelper.d.ts index bbf34a7..ce82d6a 100644 --- a/src/typechain/OffsetHelper.d.ts +++ b/src/typechain/OffsetHelper.d.ts @@ -30,16 +30,23 @@ interface OffsetHelperInterface extends ethers.utils.Interface { "balances(address,address)": FunctionFragment; "calculateNeededETHAmount(address,uint256)": FunctionFragment; "calculateNeededTokenAmount(address,address,uint256)": FunctionFragment; - "contractRegistryAddress()": FunctionFragment; - "deleteEligibleTokenAddress(string)": FunctionFragment; "deposit(address,uint256)": FunctionFragment; - "eligibleTokenAddresses(string)": FunctionFragment; + "dexRouterAddress()": FunctionFragment; + "eligibleSwapPaths(address,uint256)": FunctionFragment; + "eligibleSwapPathsBySymbol(string,uint256)": FunctionFragment; + "isERC20AddressEligible(address)": FunctionFragment; + "isPoolAddressEligible(address)": FunctionFragment; "owner()": FunctionFragment; + "paths(uint256,uint256)": FunctionFragment; + "poolAddresses(uint256)": FunctionFragment; + "removePath(string)": FunctionFragment; + "removePoolToken(address)": FunctionFragment; "renounceOwnership()": FunctionFragment; - "setEligibleTokenAddress(string,address)": FunctionFragment; - "setToucanContractRegistry(address)": FunctionFragment; - "sushiRouterAddress()": FunctionFragment; - "swap(address,uint256)": FunctionFragment; + "swapExactInETH(address)": FunctionFragment; + "swapExactInToken(address,address,uint256)": FunctionFragment; + "swapExactOutETH(address,uint256)": FunctionFragment; + "swapExactOutToken(address,address,uint256)": FunctionFragment; + "tokenSymbolsForPaths(uint256)": FunctionFragment; "transferOwnership(address)": FunctionFragment; "withdraw(address,uint256)": FunctionFragment; }; @@ -77,42 +84,68 @@ interface OffsetHelperInterface extends ethers.utils.Interface { values: [string, string, BigNumberish] ): string; encodeFunctionData( - functionFragment: "contractRegistryAddress", + functionFragment: "deposit", + values: [string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "dexRouterAddress", values?: undefined ): string; encodeFunctionData( - functionFragment: "deleteEligibleTokenAddress", - values: [string] + functionFragment: "eligibleSwapPaths", + values: [string, BigNumberish] ): string; encodeFunctionData( - functionFragment: "deposit", + functionFragment: "eligibleSwapPathsBySymbol", values: [string, BigNumberish] ): string; encodeFunctionData( - functionFragment: "eligibleTokenAddresses", + functionFragment: "isERC20AddressEligible", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "isPoolAddressEligible", values: [string] ): string; encodeFunctionData(functionFragment: "owner", values?: undefined): string; encodeFunctionData( - functionFragment: "renounceOwnership", - values?: undefined + functionFragment: "paths", + values: [BigNumberish, BigNumberish] ): string; encodeFunctionData( - functionFragment: "setEligibleTokenAddress", - values: [string, string] + functionFragment: "poolAddresses", + values: [BigNumberish] ): string; + encodeFunctionData(functionFragment: "removePath", values: [string]): string; encodeFunctionData( - functionFragment: "setToucanContractRegistry", + functionFragment: "removePoolToken", values: [string] ): string; + encodeFunctionData(functionFragment: "owner", values?: undefined): string; encodeFunctionData( - functionFragment: "sushiRouterAddress", + functionFragment: "renounceOwnership", values?: undefined ): string; encodeFunctionData( - functionFragment: "swap", + functionFragment: "swapExactInETH", + values: [string] + ): string; + encodeFunctionData( + functionFragment: "swapExactInToken", + values: [string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "swapExactOutETH", values: [string, BigNumberish] ): string; + encodeFunctionData( + functionFragment: "swapExactOutToken", + values: [string, string, BigNumberish] + ): string; + encodeFunctionData( + functionFragment: "tokenSymbolsForPaths", + values: [BigNumberish] + ): string; encodeFunctionData( functionFragment: "transferOwnership", values: [string] @@ -145,20 +178,26 @@ interface OffsetHelperInterface extends ethers.utils.Interface { functionFragment: "calculateNeededTokenAmount", data: BytesLike ): Result; + decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "contractRegistryAddress", + functionFragment: "eligibleTokenAddresses", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "deleteEligibleTokenAddress", + functionFragment: "isERC20AddressEligible", data: BytesLike ): Result; - decodeFunctionResult(functionFragment: "deposit", data: BytesLike): Result; decodeFunctionResult( - functionFragment: "eligibleTokenAddresses", + functionFragment: "isPoolAddressEligible", data: BytesLike ): Result; decodeFunctionResult(functionFragment: "owner", data: BytesLike): Result; + decodeFunctionResult(functionFragment: "paths", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "poolAddresses", + data: BytesLike + ): Result; + decodeFunctionResult(functionFragment: "removePath", data: BytesLike): Result; decodeFunctionResult( functionFragment: "renounceOwnership", data: BytesLike @@ -168,14 +207,26 @@ interface OffsetHelperInterface extends ethers.utils.Interface { data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "setToucanContractRegistry", + functionFragment: "swapExactInETH", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "swapExactInToken", + data: BytesLike + ): Result; + decodeFunctionResult( + functionFragment: "swapExactOutETH", data: BytesLike ): Result; decodeFunctionResult( - functionFragment: "sushiRouterAddress", + functionFragment: "swapExactOutToken", data: BytesLike ): Result; decodeFunctionResult(functionFragment: "swap", data: BytesLike): Result; + decodeFunctionResult( + functionFragment: "tokenSymbolsForPaths", + data: BytesLike + ): Result; decodeFunctionResult( functionFragment: "transferOwnership", data: BytesLike @@ -183,18 +234,14 @@ interface OffsetHelperInterface extends ethers.utils.Interface { decodeFunctionResult(functionFragment: "withdraw", data: BytesLike): Result; events: { - "Initialized(uint8)": EventFragment; "OwnershipTransferred(address,address)": EventFragment; "Redeemed(address,address,address[],uint256[])": EventFragment; }; - getEvent(nameOrSignatureOrTopic: "Initialized"): EventFragment; getEvent(nameOrSignatureOrTopic: "OwnershipTransferred"): EventFragment; getEvent(nameOrSignatureOrTopic: "Redeemed"): EventFragment; } -export type InitializedEvent = TypedEvent<[number] & { version: number }>; - export type OwnershipTransferredEvent = TypedEvent< [string, string] & { previousOwner: string; newOwner: string } >; @@ -289,20 +336,31 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise<[BigNumber]>; + calculateExpectedPoolTokenForETH( + _poolToken: string, + _fromTokenAmount: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber] & { amountOut: BigNumber }>; + + calculateExpectedPoolTokenForToken( + _fromToken: string, + _poolToken: string, + _fromAmount: BigNumberish, + overrides?: CallOverrides + ): Promise<[BigNumber] & { amountOut: BigNumber }>; + calculateNeededETHAmount( _toToken: string, _amount: BigNumberish, overrides?: CallOverrides - ): Promise<[BigNumber]>; + ): Promise<[BigNumber] & { amountIn: BigNumber }>; calculateNeededTokenAmount( _fromToken: string, _toToken: string, _amount: BigNumberish, overrides?: CallOverrides - ): Promise<[BigNumber]>; - - contractRegistryAddress(overrides?: CallOverrides): Promise<[string]>; + ): Promise<[BigNumber] & { amountIn: BigNumber }>; deleteEligibleTokenAddress( _tokenSymbol: string, @@ -320,28 +378,45 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise<[string]>; + isERC20AddressEligible( + _erc20Address: string, + overrides?: CallOverrides + ): Promise<[string[]] & { _path: string[] }>; + + isPoolAddressEligible( + _poolToken: string, + overrides?: CallOverrides + ): Promise<[boolean] & { _isEligible: boolean }>; + owner(overrides?: CallOverrides): Promise<[string]>; - renounceOwnership( - overrides?: Overrides & { from?: string | Promise } - ): Promise; + paths( + arg0: BigNumberish, + arg1: BigNumberish, + overrides?: CallOverrides + ): Promise<[string]>; - setEligibleTokenAddress( + poolAddresses( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise<[string]>; + + removePath( _tokenSymbol: string, - _address: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - setToucanContractRegistry( - _address: string, + removePoolToken( + _poolToken: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - sushiRouterAddress(overrides?: CallOverrides): Promise<[string]>; + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; - "swap(address,uint256)"( - _toToken: string, - _amount: BigNumberish, + swapExactInETH( + _poolToken: string, overrides?: PayableOverrides & { from?: string | Promise } ): Promise; @@ -352,6 +427,11 @@ export class OffsetHelper extends BaseContract { overrides?: Overrides & { from?: string | Promise } ): Promise; + tokenSymbolsForPaths( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise<[string]>; + transferOwnership( newOwner: string, overrides?: Overrides & { from?: string | Promise } @@ -414,13 +494,6 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; - contractRegistryAddress(overrides?: CallOverrides): Promise; - - deleteEligibleTokenAddress( - _tokenSymbol: string, - overrides?: Overrides & { from?: string | Promise } - ): Promise; - deposit( _erc20Addr: string, _amount: BigNumberish, @@ -432,28 +505,42 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; + isERC20AddressEligible( + _erc20Address: string, + overrides?: CallOverrides + ): Promise; + + isPoolAddressEligible( + _poolToken: string, + overrides?: CallOverrides + ): Promise; + owner(overrides?: CallOverrides): Promise; - renounceOwnership( - overrides?: Overrides & { from?: string | Promise } - ): Promise; + paths( + arg0: BigNumberish, + arg1: BigNumberish, + overrides?: CallOverrides + ): Promise; - setEligibleTokenAddress( + poolAddresses(arg0: BigNumberish, overrides?: CallOverrides): Promise; + + removePath( _tokenSymbol: string, - _address: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - setToucanContractRegistry( - _address: string, + removePoolToken( + _poolToken: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - sushiRouterAddress(overrides?: CallOverrides): Promise; + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; - "swap(address,uint256)"( - _toToken: string, - _amount: BigNumberish, + swapExactInETH( + _poolToken: string, overrides?: PayableOverrides & { from?: string | Promise } ): Promise; @@ -464,6 +551,11 @@ export class OffsetHelper extends BaseContract { overrides?: Overrides & { from?: string | Promise } ): Promise; + tokenSymbolsForPaths( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + transferOwnership( newOwner: string, overrides?: Overrides & { from?: string | Promise } @@ -534,13 +626,6 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; - contractRegistryAddress(overrides?: CallOverrides): Promise; - - deleteEligibleTokenAddress( - _tokenSymbol: string, - overrides?: CallOverrides - ): Promise; - deposit( _erc20Addr: string, _amount: BigNumberish, @@ -552,9 +637,30 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; + isERC20AddressEligible( + _erc20Address: string, + overrides?: CallOverrides + ): Promise; + + isPoolAddressEligible( + _poolToken: string, + overrides?: CallOverrides + ): Promise; + owner(overrides?: CallOverrides): Promise; - renounceOwnership(overrides?: CallOverrides): Promise; + paths( + arg0: BigNumberish, + arg1: BigNumberish, + overrides?: CallOverrides + ): Promise; + + poolAddresses( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + + removePath(_tokenSymbol: string, overrides?: CallOverrides): Promise; setEligibleTokenAddress( _tokenSymbol: string, @@ -562,16 +668,23 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; - setToucanContractRegistry( - _address: string, + renounceOwnership(overrides?: CallOverrides): Promise; + + swapExactInETH( + _poolToken: string, overrides?: CallOverrides - ): Promise; + ): Promise; - sushiRouterAddress(overrides?: CallOverrides): Promise; + swapExactInToken( + _fromToken: string, + _poolToken: string, + _fromAmount: BigNumberish, + overrides?: CallOverrides + ): Promise; - "swap(address,uint256)"( - _toToken: string, - _amount: BigNumberish, + swapExactOutETH( + _poolToken: string, + _toAmount: BigNumberish, overrides?: CallOverrides ): Promise; @@ -582,6 +695,11 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; + tokenSymbolsForPaths( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + transferOwnership( newOwner: string, overrides?: CallOverrides @@ -595,14 +713,6 @@ export class OffsetHelper extends BaseContract { }; filters: { - "Initialized(uint8)"( - version?: null - ): TypedEventFilter<[number], { version: number }>; - - Initialized( - version?: null - ): TypedEventFilter<[number], { version: number }>; - "OwnershipTransferred(address,address)"( previousOwner?: string | null, newOwner?: string | null @@ -691,13 +801,6 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; - contractRegistryAddress(overrides?: CallOverrides): Promise; - - deleteEligibleTokenAddress( - _tokenSymbol: string, - overrides?: Overrides & { from?: string | Promise } - ): Promise; - deposit( _erc20Addr: string, _amount: BigNumberish, @@ -709,28 +812,45 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; + isERC20AddressEligible( + _erc20Address: string, + overrides?: CallOverrides + ): Promise; + + isPoolAddressEligible( + _poolToken: string, + overrides?: CallOverrides + ): Promise; + owner(overrides?: CallOverrides): Promise; - renounceOwnership( - overrides?: Overrides & { from?: string | Promise } + paths( + arg0: BigNumberish, + arg1: BigNumberish, + overrides?: CallOverrides ): Promise; - setEligibleTokenAddress( + poolAddresses( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + + removePath( _tokenSymbol: string, - _address: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - setToucanContractRegistry( - _address: string, + removePoolToken( + _poolToken: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - sushiRouterAddress(overrides?: CallOverrides): Promise; + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } + ): Promise; - "swap(address,uint256)"( - _toToken: string, - _amount: BigNumberish, + swapExactInETH( + _poolToken: string, overrides?: PayableOverrides & { from?: string | Promise } ): Promise; @@ -741,6 +861,11 @@ export class OffsetHelper extends BaseContract { overrides?: Overrides & { from?: string | Promise } ): Promise; + tokenSymbolsForPaths( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + transferOwnership( newOwner: string, overrides?: Overrides & { from?: string | Promise } @@ -804,15 +929,6 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; - contractRegistryAddress( - overrides?: CallOverrides - ): Promise; - - deleteEligibleTokenAddress( - _tokenSymbol: string, - overrides?: Overrides & { from?: string | Promise } - ): Promise; - deposit( _erc20Addr: string, _amount: BigNumberish, @@ -824,30 +940,45 @@ export class OffsetHelper extends BaseContract { overrides?: CallOverrides ): Promise; + isERC20AddressEligible( + _erc20Address: string, + overrides?: CallOverrides + ): Promise; + + isPoolAddressEligible( + _poolToken: string, + overrides?: CallOverrides + ): Promise; + owner(overrides?: CallOverrides): Promise; - renounceOwnership( - overrides?: Overrides & { from?: string | Promise } + paths( + arg0: BigNumberish, + arg1: BigNumberish, + overrides?: CallOverrides ): Promise; - setEligibleTokenAddress( + poolAddresses( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + + removePath( _tokenSymbol: string, - _address: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - setToucanContractRegistry( - _address: string, + removePoolToken( + _poolToken: string, overrides?: Overrides & { from?: string | Promise } ): Promise; - sushiRouterAddress( - overrides?: CallOverrides + renounceOwnership( + overrides?: Overrides & { from?: string | Promise } ): Promise; - "swap(address,uint256)"( - _toToken: string, - _amount: BigNumberish, + swapExactInETH( + _poolToken: string, overrides?: PayableOverrides & { from?: string | Promise } ): Promise; @@ -858,6 +989,11 @@ export class OffsetHelper extends BaseContract { overrides?: Overrides & { from?: string | Promise } ): Promise; + tokenSymbolsForPaths( + arg0: BigNumberish, + overrides?: CallOverrides + ): Promise; + transferOwnership( newOwner: string, overrides?: Overrides & { from?: string | Promise } diff --git a/src/types/responses.ts b/src/types/responses.ts index d1c6a13..56da347 100644 --- a/src/types/responses.ts +++ b/src/types/responses.ts @@ -16,6 +16,8 @@ along with this program. If not, see . */ +import { BigNumber } from "ethers"; + import { BatchCommentSchema, BatchTokenSchema, @@ -30,6 +32,12 @@ import { UserSchema, } from "./schemas"; +// -------------------------------------------------------------------------------- +// Contract Interactions Responses +// -------------------------------------------------------------------------------- + +export type RedeemAutoResponse = Array<{ address: string; amount: BigNumber }>; + /** * I have decided to separated the types for the subgraph methods here as using Pick to separate * the needed properties from the schemas can become verbose as you will see below. diff --git a/src/utils/ABIs.ts b/src/utils/ABIs.ts index ac703da..eea0ef1 100644 --- a/src/utils/ABIs.ts +++ b/src/utils/ABIs.ts @@ -1386,7 +1386,18 @@ export const poolTokenABI = [ }, ], name: "redeemAuto", - outputs: [], + outputs: [ + { + internalType: "address[]", + name: "tco2s", + type: "address[]", + }, + { + internalType: "uint256[]", + name: "amounts", + type: "uint256[]", + }, + ], stateMutability: "nonpayable", type: "function", }, diff --git a/test/index.test.ts b/test/index.test.ts index d6e040d..64c220c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -214,7 +214,7 @@ describe("Testing Toucan-SDK contract interactions", function () { amount: BigNumber; }[] = [{ address: tco2Address, amount: amountToRedeem }]; - const tco2s = await toucan.redeemAuto2("NCT", amountToRedeem); + const tco2s = await toucan.redeemAuto("NCT", amountToRedeem); expect(tco2s, "Expect returned TCO2s to match").to.be.eql(expectedTco2s); }); @@ -348,7 +348,7 @@ describe("Testing Toucan-SDK contract interactions", function () { describe("Testing TCO related methods", function () { it("Should retire TCO2 & mint the certificate", async function () { - const tco2s = await toucan.redeemAuto2("NCT", ONE_ETHER); + const tco2s = await toucan.redeemAuto("NCT", ONE_ETHER); const { address, amount } = tco2s[0]; const tco2 = toucan.getTCO2Contract(address); @@ -383,7 +383,7 @@ describe("Testing Toucan-SDK contract interactions", function () { }); it("Should retire TCO2", async function () { - const tco2s = await toucan.redeemAuto2("NCT", ONE_ETHER); + const tco2s = await toucan.redeemAuto("NCT", ONE_ETHER); const { address, amount } = tco2s[0]; const tco2 = toucan.getTCO2Contract(address); @@ -411,7 +411,7 @@ describe("Testing Toucan-SDK contract interactions", function () { }); it("Should retire TCO2 for another address", async function () { - const tco2s = await toucan.redeemAuto2("NCT", ONE_ETHER); + const tco2s = await toucan.redeemAuto("NCT", ONE_ETHER); const { address, amount } = tco2s[0]; const tco2 = toucan.getTCO2Contract(address);