Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2: LILA-5572/update-redeemauto-function-to-work-like-autoredeem2-in-sdk #89

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
},
Expand Down
6 changes: 4 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
UserRedeemsMethod,
UserRetirementsMethod,
} from "./types/methods";
import { RedeemAutoResponse } from "./types/responses";

/**
*
Expand Down Expand Up @@ -311,7 +312,7 @@ export default class ToucanClient {
redeemAuto = async (
pool: PoolSymbol,
amount: BigNumber
): Promise<ContractReceipt> => {
): Promise<RedeemAutoResponse> => {
if (!this.signer) throw new Error("No signer set");
const signer = this.signer;

Expand All @@ -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
Expand All @@ -328,7 +330,7 @@ export default class ToucanClient {
redeemAuto2 = async (
pool: PoolSymbol,
amount: BigNumber
): Promise<{ address: string; amount: BigNumber }[]> => {
): Promise<RedeemAutoResponse> => {
if (!this.signer) throw new Error("No signer set");
const signer = this.signer;

Expand Down
53 changes: 37 additions & 16 deletions src/subclasses/ContractInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
OffsetHelper,
} from "../typechain";
import { Network, PoolSymbol } from "../types";
import { RedeemAutoResponse } from "../types/responses";
import { GAS_LIMIT } from "../utils";
import {
poolTokenABI,
Expand Down Expand Up @@ -316,17 +317,33 @@
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<ContractReceipt> => {
): Promise<RedeemAutoResponse> => {
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
Expand All @@ -337,7 +354,7 @@
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<{ address: string; amount: BigNumber }[]> => {
): Promise<RedeemAutoResponse> => {
const poolToken = this.getPoolContract(pool, signer);
const redeemReceipt = await (
await poolToken.redeemAuto2(amount, { gasLimit: GAS_LIMIT })
Expand All @@ -347,15 +364,19 @@
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;
},
[]
);
};

/**
Expand Down Expand Up @@ -634,7 +655,7 @@
* @returns a ethers.contract to interact with the OffsetHelper
*/
public getOffsetHelperContract = (
signerOrProvider: ethers.Signer | ethers.providers.Provider

Check warning on line 658 in src/subclasses/ContractInteractions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'signerOrProvider' is defined but never used. Allowed unused args must match /^_/u

Check warning on line 658 in src/subclasses/ContractInteractions.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'signerOrProvider' is defined but never used
): OffsetHelper => {
throw new Error("OffsetHelper is not supported yet");
};
Expand Down
7 changes: 6 additions & 1 deletion src/typechain/IToucanPoolToken.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ export class IToucanPoolToken extends BaseContract {

getScoredTCO2s(overrides?: CallOverrides): Promise<string[]>;

redeemAuto(amount: BigNumberish, overrides?: CallOverrides): Promise<void>;
redeemAuto(
amount: BigNumberish,
overrides?: CallOverrides
): Promise<
[string[], BigNumber[]] & { tco2s: string[]; amounts: BigNumber[] }
Niwilai marked this conversation as resolved.
Show resolved Hide resolved
>;

redeemAuto2(
amount: BigNumberish,
Expand Down
Loading
Loading