Skip to content

Commit

Permalink
Merge pull request #28 from lazaralex98/prt-286-refactor-nits-for-sdk
Browse files Browse the repository at this point in the history
PRT-286: Refactor nits
  • Loading branch information
mauricedesaxe authored Jul 4, 2022
2 parents 5b725f1 + 77badca commit 1e711c4
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 89 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
48 changes: 21 additions & 27 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
IToucanPoolToken,
OffsetHelper,
} from "./typechain";
import { Network, poolSymbol } from "./types";
import { Network, PoolSymbol } from "./types";
import {
fetchAggregationsMethod,
fetchAllTCO2TokensMethod,
Expand Down Expand Up @@ -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<ContractReceipt> => {
Expand All @@ -228,7 +228,7 @@ export class ToucanClient {
* @param tco2 address of TCO2 to deposit
* @returns boolean
*/
checkEligible = async (pool: poolSymbol, tco2: string): Promise<boolean> => {
checkEligible = async (pool: PoolSymbol, tco2: string): Promise<boolean> => {
const signerOrProvider = this.signer ? this.signer : this.provider;
if (!signerOrProvider) throw new Error("No signer or provider set");

Expand All @@ -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<BigNumber> => {
Expand All @@ -273,7 +273,7 @@ export class ToucanClient {
* @returns redeem transaction
*/
redeemMany = async (
pool: poolSymbol,
pool: PoolSymbol,
tco2s: string[],
amounts: BigNumber[]
): Promise<ContractReceipt> => {
Expand All @@ -291,7 +291,7 @@ export class ToucanClient {
* @returns redeem transaction
*/
redeemAuto = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber
): Promise<ContractReceipt> => {
if (!this.signer) throw new Error("No signer set");
Expand All @@ -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");
Expand All @@ -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<BigNumber> => {
getPoolRemaining = async (pool: PoolSymbol): Promise<BigNumber> => {
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);
};

/**
Expand All @@ -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<string[]> => {
getScoredTCO2s = async (pool: PoolSymbol): Promise<string[]> => {
const signerOrProvider = this.signer ? this.signer : this.provider;
if (!signerOrProvider) throw new Error("No signer or provider set");

Expand Down Expand Up @@ -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<ContractReceipt> => {
if (!this.signer) throw new Error("No signer set");
Expand All @@ -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<ContractReceipt> => {
Expand All @@ -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<ContractReceipt> => {
if (!this.signer) throw new Error("No signer set");
Expand All @@ -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<BigNumber> => {
Expand All @@ -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<BigNumber> => {
const signerOrProvider = this.signer ? this.signer : this.provider;
Expand Down Expand Up @@ -672,7 +669,7 @@ export class ToucanClient {
// --------------------------------------------------------------------------------

fetchTokenPriceOnSushiSwap = async (
pool: poolSymbol
pool: PoolSymbol
): Promise<{
price: number | null;
url: string | null;
Expand All @@ -692,25 +689,22 @@ 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);
};

/**
*
* @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);
};

/**
Expand Down
40 changes: 20 additions & 20 deletions subclasses/ContractInteractions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -195,7 +195,7 @@ class ContractInteractions {
* @returns deposit transaction
*/
depositTCO2 = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber,
tco2Address: string,
signer: ethers.Signer
Expand Down Expand Up @@ -226,7 +226,7 @@ class ContractInteractions {
* @returns boolean
*/
checkEligible = async (
pool: poolSymbol,
pool: PoolSymbol,
tco2: string,
signerOrProvider: ethers.Signer | ethers.providers.Provider
): Promise<boolean> => {
Expand Down Expand Up @@ -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
Expand All @@ -274,7 +274,7 @@ class ContractInteractions {
* @returns redeem transaction
*/
redeemMany = async (
pool: poolSymbol,
pool: PoolSymbol,
tco2s: string[],
amounts: BigNumber[],
signer: ethers.Signer
Expand All @@ -298,7 +298,7 @@ class ContractInteractions {
* @returns redeem transaction
*/
redeemAuto = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<ContractReceipt> => {
Expand All @@ -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 }[]> => {
Expand All @@ -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<BigNumber> => {
const poolToken = this.getPoolContract(poolSymbol, signerOrProvider);
const poolToken = this.getPoolContract(pool, signerOrProvider);
return await poolToken.getRemaining();
};

Expand All @@ -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<string[]> => {
const poolToken = this.getPoolContract(pool, signerOrProvider);
Expand Down Expand Up @@ -410,7 +410,7 @@ class ContractInteractions {
* @returns offset transaction
*/
autoOffsetUsingPoolToken = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<ContractReceipt> => {
Expand Down Expand Up @@ -442,7 +442,7 @@ class ContractInteractions {
* @returns offset transaction
*/
autoOffsetUsingSwapToken = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber,
swapToken: Contract,
signer: ethers.Signer
Expand Down Expand Up @@ -480,7 +480,7 @@ class ContractInteractions {
* @returns offset transaction
*/
autoOffsetUsingETH = async (
pool: poolSymbol,
pool: PoolSymbol,
amount: BigNumber,
signer: ethers.Signer
): Promise<ContractReceipt> => {
Expand All @@ -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
Expand All @@ -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<BigNumber> => {
Expand All @@ -548,24 +548,24 @@ 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;
};

/**
*
* @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;
Expand Down
6 changes: 3 additions & 3 deletions subclasses/SubgraphInteractions.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -725,7 +725,7 @@ class SubgraphInteractions {
};

fetchTokenPriceOnSushiSwap = async (
pool: poolSymbol
pool: PoolSymbol
): Promise<{
price: number | null;
url: string | null;
Expand All @@ -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;
};
}
Expand Down
Loading

0 comments on commit 1e711c4

Please sign in to comment.