diff --git a/README.md b/README.md index bc0baf1..497f195 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ const result = await toucan.fetchCustomQuery(query, { id: "1" }); # What if I can't find contract interactions that I need? -You can always access any method or property of the bct, nct and tco2 contracts by first getting and storing them in a variable, like so: +You can always access any method or property of the BCT, NCT and TCO2 contracts by first getting and storing them in a variable, like so: ```typescript toucan.setSigner(signer); diff --git a/index.ts b/index.ts index dcafba6..9ba052a 100644 --- a/index.ts +++ b/index.ts @@ -10,7 +10,7 @@ import { IToucanPoolToken, OffsetHelper, } from "./typechain"; -import { Network, poolSymbol } from "./types"; +import { Network, PoolSymbol } from "./types"; import { fetchAggregationsMethod, fetchAllTCO2TokensMethod, @@ -206,7 +206,7 @@ export class ToucanClient { * @param tco2Address address of the TCO2 token to deposit* @returns deposit transaction */ depositTCO2 = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, tco2Address: string ): Promise => { @@ -228,7 +228,7 @@ export class ToucanClient { * @param tco2 address of TCO2 to deposit * @returns boolean */ - checkEligible = async (pool: poolSymbol, tco2: string): Promise => { + checkEligible = async (pool: PoolSymbol, tco2: string): Promise => { const signerOrProvider = this.signer ? this.signer : this.provider; if (!signerOrProvider) throw new Error("No signer or provider set"); @@ -249,7 +249,7 @@ export class ToucanClient { * @returns amount (BigNumber) of fees it will cost to redeem */ calculateRedeemFees = async ( - pool: poolSymbol, + pool: PoolSymbol, tco2s: string[], amounts: BigNumber[] ): Promise => { @@ -273,7 +273,7 @@ export class ToucanClient { * @returns redeem transaction */ redeemMany = async ( - pool: poolSymbol, + pool: PoolSymbol, tco2s: string[], amounts: BigNumber[] ): Promise => { @@ -291,7 +291,7 @@ export class ToucanClient { * @returns redeem transaction */ redeemAuto = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber ): Promise => { if (!this.signer) throw new Error("No signer set"); @@ -308,7 +308,7 @@ export class ToucanClient { * @returns array containing tco2 addresses (string) and amounts (BigNumber) */ redeemAuto2 = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber ): Promise<{ address: string; amount: BigNumber }[]> => { if (!this.signer) throw new Error("No signer set"); @@ -320,17 +320,14 @@ export class ToucanClient { /** * * @description gets the remaining space in pool contract before hitting the cap - * @param poolSymbol symbol of the token to use + * @param PoolSymbol symbol of the token to use * @returns BigNumber representing the remaining space */ - getPoolRemaining = async (poolSymbol: poolSymbol): Promise => { + getPoolRemaining = async (pool: PoolSymbol): Promise => { const signerOrProvider = this.signer ? this.signer : this.provider; if (!signerOrProvider) throw new Error("No signer or provider set"); - return this.contractInteractions.getPoolRemaining( - poolSymbol, - signerOrProvider - ); + return this.contractInteractions.getPoolRemaining(pool, signerOrProvider); }; /** @@ -339,7 +336,7 @@ export class ToucanClient { * @param pool symbol of the pool (token) to use * @returns array of TCO2 addresses by rank */ - getScoredTCO2s = async (pool: poolSymbol): Promise => { + getScoredTCO2s = async (pool: PoolSymbol): Promise => { const signerOrProvider = this.signer ? this.signer : this.provider; if (!signerOrProvider) throw new Error("No signer or provider set"); @@ -379,7 +376,7 @@ export class ToucanClient { * @param amount amount of CO2 tons to offset* @returns offset transaction */ autoOffsetUsingPoolToken = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber ): Promise => { if (!this.signer) throw new Error("No signer set"); @@ -401,7 +398,7 @@ export class ToucanClient { * @param swapToken portal for the token to swap into pool tokens (only accepts WETH, WMATIC and USDC)* @returns offset transaction */ autoOffsetUsingSwapToken = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, swapToken: Contract ): Promise => { @@ -424,7 +421,7 @@ export class ToucanClient { * @param amount amount of CO2 tons to offset* @returns offset transaction */ autoOffsetUsingETH = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber ): Promise => { if (!this.signer) throw new Error("No signer set"); @@ -442,7 +439,7 @@ export class ToucanClient { * @returns amount (BigNumber) of swapToken needed to deposit */ calculateNeededTokenAmount = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, swapToken: Contract ): Promise => { @@ -465,7 +462,7 @@ export class ToucanClient { * @returns amount (BigNumber) of ETH needed to deposit; ETH = native currency of network you are on */ calculateNeededETHAmount = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber ): Promise => { const signerOrProvider = this.signer ? this.signer : this.provider; @@ -672,7 +669,7 @@ export class ToucanClient { // -------------------------------------------------------------------------------- fetchTokenPriceOnSushiSwap = async ( - pool: poolSymbol + pool: PoolSymbol ): Promise<{ price: number | null; url: string | null; @@ -692,7 +689,7 @@ export class ToucanClient { * @param pool symbol of the pool (token) to use * @returns a ethers.contract to interact with the pool */ - public getPoolAddress = (pool: poolSymbol): string => { + public getPoolAddress = (pool: PoolSymbol): string => { return this.contractInteractions.getPoolAddress(pool); }; @@ -700,17 +697,14 @@ export class ToucanClient { * * @dev * @description gets the contract of a pool token based on the symbol - * @param poolSymbol symbol of the pool (token) to use + * @param PoolSymbol symbol of the pool (token) to use * @returns a ethers.contract to interact with the pool */ - public getPoolContract = (poolSymbol: poolSymbol): IToucanPoolToken => { + public getPoolContract = (pool: PoolSymbol): IToucanPoolToken => { const signerOrProvider = this.signer ? this.signer : this.provider; if (!signerOrProvider) throw new Error("No signer or provider set"); - return this.contractInteractions.getPoolContract( - poolSymbol, - signerOrProvider - ); + return this.contractInteractions.getPoolContract(pool, signerOrProvider); }; /** diff --git a/subclasses/ContractInteractions.ts b/subclasses/ContractInteractions.ts index 90aa4a8..d4f4c3c 100644 --- a/subclasses/ContractInteractions.ts +++ b/subclasses/ContractInteractions.ts @@ -12,7 +12,7 @@ import { IToucanPoolToken, OffsetHelper, } from "../typechain"; -import { Network, poolSymbol } from "../types"; +import { Network, PoolSymbol } from "../types"; import { GAS_LIMIT } from "../utils"; import { offsetHelperABI, @@ -195,7 +195,7 @@ class ContractInteractions { * @returns deposit transaction */ depositTCO2 = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, tco2Address: string, signer: ethers.Signer @@ -226,7 +226,7 @@ class ContractInteractions { * @returns boolean */ checkEligible = async ( - pool: poolSymbol, + pool: PoolSymbol, tco2: string, signerOrProvider: ethers.Signer | ethers.providers.Provider ): Promise => { @@ -255,7 +255,7 @@ class ContractInteractions { * @returns amount (BigNumber) of fees it will cost to redeem */ calculateRedeemFees = async ( - pool: poolSymbol, + pool: PoolSymbol, tco2s: string[], amounts: BigNumber[], signerOrProvider: ethers.Signer | ethers.providers.Provider @@ -274,7 +274,7 @@ class ContractInteractions { * @returns redeem transaction */ redeemMany = async ( - pool: poolSymbol, + pool: PoolSymbol, tco2s: string[], amounts: BigNumber[], signer: ethers.Signer @@ -298,7 +298,7 @@ class ContractInteractions { * @returns redeem transaction */ redeemAuto = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer ): Promise => { @@ -319,7 +319,7 @@ class ContractInteractions { * @returns array containing tco2 addresses (string) and amounts (BigNumber) */ redeemAuto2 = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer ): Promise<{ address: string; amount: BigNumber }[]> => { @@ -346,15 +346,15 @@ class ContractInteractions { /** * * @description gets the remaining space in pool contract before hitting the cap - * @param poolSymbol symbol of the token to use + * @param PoolSymbol symbol of the token to use * @param signerOrProvider this being a read transaction, we need a signer or provider * @returns BigNumber representing the remaining space */ getPoolRemaining = async ( - poolSymbol: poolSymbol, + pool: PoolSymbol, signerOrProvider: ethers.Signer | ethers.providers.Provider ): Promise => { - const poolToken = this.getPoolContract(poolSymbol, signerOrProvider); + const poolToken = this.getPoolContract(pool, signerOrProvider); return await poolToken.getRemaining(); }; @@ -366,7 +366,7 @@ class ContractInteractions { * @returns array of TCO2 addresses by rank */ getScoredTCO2s = async ( - pool: poolSymbol, + pool: PoolSymbol, signerOrProvider: ethers.Signer | ethers.providers.Provider ): Promise => { const poolToken = this.getPoolContract(pool, signerOrProvider); @@ -410,7 +410,7 @@ class ContractInteractions { * @returns offset transaction */ autoOffsetUsingPoolToken = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer ): Promise => { @@ -442,7 +442,7 @@ class ContractInteractions { * @returns offset transaction */ autoOffsetUsingSwapToken = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, swapToken: Contract, signer: ethers.Signer @@ -480,7 +480,7 @@ class ContractInteractions { * @returns offset transaction */ autoOffsetUsingETH = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, signer: ethers.Signer ): Promise => { @@ -505,7 +505,7 @@ class ContractInteractions { * @returns amount (BigNumber) of swapToken needed to deposit */ calculateNeededTokenAmount = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, swapToken: Contract, signerOrProvider: ethers.Signer | ethers.providers.Provider @@ -527,7 +527,7 @@ class ContractInteractions { * @returns amount (BigNumber) of ETH needed to deposit; ETH = native currency of network you are on */ calculateNeededETHAmount = async ( - pool: poolSymbol, + pool: PoolSymbol, amount: BigNumber, signerOrProvider: ethers.Signer | ethers.providers.Provider ): Promise => { @@ -548,7 +548,7 @@ class ContractInteractions { * @param pool symbol of the pool (token) to use * @returns a ethers.contract to interact with the pool */ - public getPoolAddress = (pool: poolSymbol): string => { + public getPoolAddress = (pool: PoolSymbol): string => { return pool == "BCT" ? this.addresses.bct : this.addresses.nct; }; @@ -556,16 +556,16 @@ class ContractInteractions { * * @dev * @description gets the contract of a pool token based on the symbol - * @param poolSymbol symbol of the pool (token) to use + * @param PoolSymbol symbol of the pool (token) to use * @param signerOrProvider depending on what you intend to do with the contract, a signer or provider * @returns a ethers.contract to interact with the pool */ public getPoolContract = ( - poolSymbol: poolSymbol, + pool: PoolSymbol, signerOrProvider: ethers.Signer | ethers.providers.Provider ): IToucanPoolToken => { const poolContract = new ethers.Contract( - this.getPoolAddress(poolSymbol), + this.getPoolAddress(pool), poolTokenABI, signerOrProvider ) as IToucanPoolToken; diff --git a/subclasses/SubgraphInteractions.ts b/subclasses/SubgraphInteractions.ts index 507c3df..e3dc7cb 100644 --- a/subclasses/SubgraphInteractions.ts +++ b/subclasses/SubgraphInteractions.ts @@ -1,7 +1,7 @@ import { Client, gql } from "@urql/core"; import { IToucanCarbonOffsets } from "../typechain"; -import { Network, poolSymbol } from "../types"; +import { Network, PoolSymbol } from "../types"; import { fetchAggregationsMethod, fetchAllTCO2TokensMethod, @@ -725,7 +725,7 @@ class SubgraphInteractions { }; fetchTokenPriceOnSushiSwap = async ( - pool: poolSymbol + pool: PoolSymbol ): Promise<{ price: number | null; url: string | null; @@ -752,7 +752,7 @@ class SubgraphInteractions { * @param pool symbol of the pool (token) to use * @returns a ethers.contract to interact with the pool */ - private getPoolAddress = (pool: poolSymbol): string => { + private getPoolAddress = (pool: PoolSymbol): string => { return pool == "BCT" ? this.addresses.bct : this.addresses.nct; }; } diff --git a/test/index.ts b/test/index.ts index b8eca8f..7cfdf26 100644 --- a/test/index.ts +++ b/test/index.ts @@ -12,15 +12,13 @@ import addresses from "../utils/addresses"; describe("Testing Toucan-SDK", function () { let addr1: SignerWithAddress; let addr2: SignerWithAddress; - let addrs: SignerWithAddress[]; let toucan: ToucanClient; let swapper: Contract; let scoredTCO2sBCT: string[]; let scoredTCO2sNCT: string[]; - let res; before(async () => { - [addr1, addr2, ...addrs] = await ethers.getSigners(); + [addr1, addr2] = await ethers.getSigners(); toucan = new ToucanClient("polygon"); toucan.setSigner(addr1); @@ -132,12 +130,11 @@ describe("Testing Toucan-SDK", function () { }); it("Should automatically redeem NCT & deposit the TCO2 back", async function () { - // @ts-ignore - const tco2: IToucanCarbonOffsets = new ethers.Contract( + const tco2 = new ethers.Contract( scoredTCO2sNCT[0], tco2ABI, addr1 - ); + ) as IToucanCarbonOffsets; const tco2BalanceBefore = await tco2.balanceOf(addr1.address); const nct = new ethers.Contract( addresses.polygon.nct, @@ -174,11 +171,6 @@ describe("Testing Toucan-SDK", function () { [parseEther("1.0")] ); - const remainingTCO2 = await toucan - .getPoolContract("BCT") - // @ts-ignore tokenBalances is an autogenerated getter for a mapping within inherited storage - .tokenBalances(tco2Address); - await expect(toucan.redeemMany("BCT", [tco2Address], [parseEther("1.0")])) .to.not.be.reverted; @@ -222,7 +214,7 @@ describe("Testing Toucan-SDK", function () { it("Should retire 1 TCO2 & mint the certificate", async function () { const tco2s = await toucan.redeemAuto2("NCT", parseEther("1.0")); - const retirementReceipt = await toucan.retireAndMintCertificate( + await toucan.retireAndMintCertificate( "Test", addr1.address, "Test", @@ -241,7 +233,7 @@ describe("Testing Toucan-SDK", function () { parseEther("1.0"), tco2s[0].address ); - const retiredEvents = retirementReceipt.events?.filter((event, index) => { + const retiredEvents = retirementReceipt.events?.filter((event) => { return event.event == "Retired"; }); @@ -266,69 +258,65 @@ describe("Testing Toucan-SDK", function () { describe("Testing subgraph related methods", function () { it("Should fetch user batches", async function () { - expect((res = await toucan.fetchUserBatches(addr1.address))).to.not.throw; + expect(await toucan.fetchUserBatches(addr1.address)).to.not.throw; }); describe("Testing TCO2 Token fetching methods", function () { it("Should fetch details about TCO2 based on its address", async function () { expect( - (res = await toucan.fetchTCO2TokenById( + await toucan.fetchTCO2TokenById( "0x0044c5a5a6f626b673224a3c0d71e851ad3d5153" - )) + ) ).to.not.throw; }); it("Should fetch details about TCO2 based on its full symbol", async function () { - expect( - (res = await toucan.fetchTCO2TokenByFullSymbol("TCO2-VCS-1718-2013")) - ).to.not.throw; + expect(await toucan.fetchTCO2TokenByFullSymbol("TCO2-VCS-1718-2013")).to + .not.throw; }); it("Should fetch all TCO2 Tokens", async function () { - expect((res = await toucan.fetchAllTCO2Tokens())).to.not.throw; + expect(await toucan.fetchAllTCO2Tokens()).to.not.throw; }); }); it("Should fetch bridged batch tokens", async function () { - expect((res = await toucan.fetchBridgedBatchTokens())).to.not.throw; + expect(await toucan.fetchBridgedBatchTokens()).to.not.throw; }); it("Should fetch user retirements", async function () { - expect((res = await toucan.fetchUserRetirements(addr1.address))).to.not - .throw; + expect(await toucan.fetchUserRetirements(addr1.address)).to.not.throw; }); describe("Testing Redeems fetching methods", function () { it("Should fetch redeems", async function () { - expect((res = await toucan.fetchRedeems("NCT"))).to.not.throw; + expect(await toucan.fetchRedeems("NCT")).to.not.throw; }); it("Should fetch user redeems", async function () { - expect((res = await toucan.fetchUserRedeems(addr1.address, "NCT"))).to - .not.throw; + expect(await toucan.fetchUserRedeems(addr1.address, "NCT")).to.not + .throw; }); }); it("Should fetch pooled tokens", async function () { - expect((res = await toucan.fetchPoolContents("NCT"))).to.not.throw; + expect(await toucan.fetchPoolContents("NCT")).to.not.throw; }); it("Should fetch a project by its id", async function () { - expect((res = await toucan.fetchProjectById("1"))).to.not.throw; + expect(await toucan.fetchProjectById("1")).to.not.throw; }); it("Should fetch aggregations", async function () { - expect((res = await toucan.fetchAggregations())).to.not.throw; + expect(await toucan.fetchAggregations()).to.not.throw; }); it("Should fetch price of BCT", async function () { - expect((res = await toucan.fetchTokenPriceOnSushiSwap("BCT"))).to.not - .throw; + expect(await toucan.fetchTokenPriceOnSushiSwap("BCT")).to.not.throw; }); it("Should fetch price of NCT", async function () { - expect((res = await toucan.fetchTokenPriceOnSushiSwap("NCT"))).to.not - .throw; + expect(await toucan.fetchTokenPriceOnSushiSwap("NCT")).to.not.throw; }); }); }); diff --git a/types/index.ts b/types/index.ts index eb9ad97..121e914 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,6 +1,6 @@ export type Network = "polygon" | "mumbai"; -export type poolSymbol = "BCT" | "NCT"; +export type PoolSymbol = "BCT" | "NCT"; export declare enum RetirementStatus { Pending = 0, diff --git a/types/methods.ts b/types/methods.ts index a888d5f..b718afd 100644 --- a/types/methods.ts +++ b/types/methods.ts @@ -1,6 +1,6 @@ import { TypedDocumentNode } from "@urql/core"; -import { poolSymbol } from "."; +import { PoolSymbol } from "."; import { AggregationsSchema, BatchCommentSchema, @@ -130,14 +130,14 @@ export type fetchRedeemsResult = Pick< }; export type fetchRedeemsMethod = ( - pool: poolSymbol, + pool: PoolSymbol, first?: number, skip?: number ) => Promise; export type fetchUserRedeemsMethod = ( walletAddress: string, - pool: poolSymbol, + pool: PoolSymbol, first?: number, skip?: number ) => Promise; @@ -155,7 +155,7 @@ export type fetchPoolContentsResult = Pick & { }; export type fetchPoolContentsMethod = ( - poolSymbol: poolSymbol, + pool: PoolSymbol, first?: number, skip?: number ) => Promise;