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 2 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
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export default class ToucanClient {
redeemAuto = async (
pool: PoolSymbol,
amount: BigNumber
): Promise<ContractReceipt> => {
): Promise<{ address: string; amount: BigNumber }[]> => {
Niwilai marked this conversation as resolved.
Show resolved Hide resolved
if (!this.signer) throw new Error("No signer set");
const signer = this.signer;

Expand All @@ -320,6 +320,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 Down
26 changes: 20 additions & 6 deletions src/subclasses/ContractInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,17 +316,31 @@ class ContractInteractions {
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<ContractReceipt> => {
): Promise<{ address: string; amount: BigNumber }[]> => {
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
.filter((event) => {
return (
event.event == "Redeemed" && event.args?.erc20 && event.args?.amount
Niwilai marked this conversation as resolved.
Show resolved Hide resolved
);
})
.map((event) => {
return { address: event.args?.erc20, amount: event.args?.amount };
});
};

/**
*
* @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 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