From 30dff38f26c7f6df06b38eaf2885fe25b75b6e4c Mon Sep 17 00:00:00 2001 From: Alex Lazar Date: Wed, 15 Jun 2022 00:34:42 +0300 Subject: [PATCH] refactor: no need for address in constructor - remove the need for the user to provide his signer's address - removed signerish & providerish - allow more provider types - updated docs We can now fetch the signer's address with `await this.signer.getAddress();`. --- README.md | 2 +- index.ts | 14 +++++--------- test/index.ts | 9 ++------- types/index.ts | 8 -------- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index bd28fa4..75903eb 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Instantiate the Toucan client to interact with our infrastructure. ```typescript import ToucanClient from "toucan-sdk"; -const toucan = new ToucanClient("polygon", signer.address, provider, signer); +const toucan = new ToucanClient("polygon", provider, signer); ``` ## Fetch pool prices from SushiSwap diff --git a/index.ts b/index.ts index f812be0..7657b7a 100644 --- a/index.ts +++ b/index.ts @@ -15,7 +15,7 @@ import { IToucanPoolToken, OffsetHelper, } from "./typechain"; -import { Network, poolSymbol, providerish, signerish } from "./types"; +import { Network, poolSymbol } from "./types"; import { fetchAggregationsMethod, fetchAllTCO2TokensMethod, @@ -44,9 +44,8 @@ import addresses, { IfcOneNetworksAddresses } from "./utils/addresses"; import { MUMBAI_GRAPH_API_URL, POLYGON_GRAPH_API_URL } from "./utils/graphAPIs"; class ToucanClient { - provider: providerish; - signer: signerish; - walletAddress: string; + provider: ethers.providers.Provider; + signer: ethers.Wallet | ethers.Signer; network: Network; addresses: IfcOneNetworksAddresses; offsetHelper: OffsetHelper; @@ -59,18 +58,15 @@ class ToucanClient { /** * * @param network network that you want to work on - * @param walletAddress address of the signer you want to use * @param provider web3 or jsonRpc provider * @param signer signer */ constructor( network: Network, - walletAddress: string, - provider: providerish, - signer: signerish + provider: ethers.providers.Provider, + signer: ethers.Wallet | ethers.Signer ) { this.network = network; - this.walletAddress = walletAddress; this.provider = provider; this.signer = signer; diff --git a/test/index.ts b/test/index.ts index 1bd55fd..72369cf 100644 --- a/test/index.ts +++ b/test/index.ts @@ -21,7 +21,7 @@ describe("Testing Toucan-SDK", function () { before(async () => { [addr1, addr2, ...addrs] = await ethers.getSigners(); - toucan = new ToucanClient("polygon", addr1.address, ethers.provider, addr1); + toucan = new ToucanClient("polygon", ethers.provider, addr1); swapper = new ethers.Contract(addresses.polygon.swapper, swapperABI, addr1); await swapper.swap(addresses.polygon.nct, parseEther("100.0"), { @@ -260,12 +260,7 @@ describe("Testing Toucan-SDK", function () { toucan.instantiateTCO2(tco2s[0].address); await toucan.TCO2?.approve(addr2.address, parseEther("1.0")); - const toucan2 = new ToucanClient( - "polygon", - addr2.address, - ethers.provider, - addr2 - ); + const toucan2 = new ToucanClient("polygon", ethers.provider, addr2); toucan2.instantiateTCO2(tco2s[0].address); await expect(toucan2.retireFrom(parseEther("1.0"), addr1.address)).to.not .be.reverted; diff --git a/types/index.ts b/types/index.ts index 901a3a2..eb9ad97 100644 --- a/types/index.ts +++ b/types/index.ts @@ -1,13 +1,5 @@ -import { ethers } from "ethers"; - export type Network = "polygon" | "mumbai"; -export type providerish = - | ethers.providers.Web3Provider - | ethers.providers.JsonRpcProvider; - -export type signerish = ethers.providers.Provider | ethers.Signer; - export type poolSymbol = "BCT" | "NCT"; export declare enum RetirementStatus {