From 2600342dbe6a04cb87ddf247b5a6437716b46010 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Sun, 18 Sep 2022 16:08:19 +0200 Subject: [PATCH 01/17] feat(investor-foxy): switch from web3 to ethers and JsonRpcBatchProvider --- packages/investor-foxy/package.json | 3 +- packages/investor-foxy/src/abi/erc20-abi.ts | 4 +- packages/investor-foxy/src/abi/foxy-abi.ts | 4 +- .../investor-foxy/src/abi/foxy-staking-abi.ts | 4 +- .../src/abi/liquidity-reserve-abi.ts | 4 +- .../investor-foxy/src/abi/toke-manager-abi.ts | 4 +- .../investor-foxy/src/abi/toke-pool-abi.ts | 4 +- .../src/abi/toke-reward-hash-abi.ts | 4 +- packages/investor-foxy/src/api/api.ts | 143 +++++++++--------- packages/investor-foxy/src/api/foxy-types.ts | 4 +- 10 files changed, 91 insertions(+), 87 deletions(-) diff --git a/packages/investor-foxy/package.json b/packages/investor-foxy/package.json index 88256735c..388f7ef6b 100644 --- a/packages/investor-foxy/package.json +++ b/packages/investor-foxy/package.json @@ -27,9 +27,10 @@ "cli": "yarn build && node ./dist/foxycli.js" }, "dependencies": { - "@ethersproject/providers": "^5.5.3", + "@ethersproject/providers": "^5.7.1", "axios": "^0.26.1", "bignumber.js": "^9.0.2", + "ethers": "^5.7.1", "lodash": "^4.17.21", "web3": "1.7.4", "web3-core": "1.7.4", diff --git a/packages/investor-foxy/src/abi/erc20-abi.ts b/packages/investor-foxy/src/abi/erc20-abi.ts index db3524488..7da1098f0 100644 --- a/packages/investor-foxy/src/abi/erc20-abi.ts +++ b/packages/investor-foxy/src/abi/erc20-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const erc20Abi: AbiItem[] = [ +export const erc20Abi: ContractInterface = [ { constant: true, inputs: [], diff --git a/packages/investor-foxy/src/abi/foxy-abi.ts b/packages/investor-foxy/src/abi/foxy-abi.ts index 9e39633a9..0983550f3 100644 --- a/packages/investor-foxy/src/abi/foxy-abi.ts +++ b/packages/investor-foxy/src/abi/foxy-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const foxyAbi: AbiItem[] = [ +export const foxyAbi: ContractInterface = [ { inputs: [], stateMutability: 'nonpayable', diff --git a/packages/investor-foxy/src/abi/foxy-staking-abi.ts b/packages/investor-foxy/src/abi/foxy-staking-abi.ts index 24fc3abde..17121bce0 100644 --- a/packages/investor-foxy/src/abi/foxy-staking-abi.ts +++ b/packages/investor-foxy/src/abi/foxy-staking-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const foxyStakingAbi: AbiItem[] = [ +export const foxyStakingAbi: ContractInterface = [ { inputs: [ { diff --git a/packages/investor-foxy/src/abi/liquidity-reserve-abi.ts b/packages/investor-foxy/src/abi/liquidity-reserve-abi.ts index 590e2b9fa..37ee768d6 100644 --- a/packages/investor-foxy/src/abi/liquidity-reserve-abi.ts +++ b/packages/investor-foxy/src/abi/liquidity-reserve-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const liquidityReserveAbi: AbiItem[] = [ +export const liquidityReserveAbi: ContractInterface = [ { inputs: [ { diff --git a/packages/investor-foxy/src/abi/toke-manager-abi.ts b/packages/investor-foxy/src/abi/toke-manager-abi.ts index a8b7dfc51..6b0b317f5 100644 --- a/packages/investor-foxy/src/abi/toke-manager-abi.ts +++ b/packages/investor-foxy/src/abi/toke-manager-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const tokeManagerAbi: AbiItem[] = [ +export const tokeManagerAbi: ContractInterface = [ { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, { anonymous: false, diff --git a/packages/investor-foxy/src/abi/toke-pool-abi.ts b/packages/investor-foxy/src/abi/toke-pool-abi.ts index 469ccedca..b7a962594 100644 --- a/packages/investor-foxy/src/abi/toke-pool-abi.ts +++ b/packages/investor-foxy/src/abi/toke-pool-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const tokePoolAbi: AbiItem[] = [ +export const tokePoolAbi: ContractInterface = [ { anonymous: false, inputs: [ diff --git a/packages/investor-foxy/src/abi/toke-reward-hash-abi.ts b/packages/investor-foxy/src/abi/toke-reward-hash-abi.ts index 2bcbf6e8d..f400abc7d 100644 --- a/packages/investor-foxy/src/abi/toke-reward-hash-abi.ts +++ b/packages/investor-foxy/src/abi/toke-reward-hash-abi.ts @@ -1,6 +1,6 @@ -import { AbiItem } from 'web3-utils' +import { ContractInterface } from 'ethers/lib/ethers' -export const tokeRewardHashAbi: AbiItem[] = [ +export const tokeRewardHashAbi: ContractInterface = [ { inputs: [], stateMutability: 'nonpayable', type: 'constructor' }, { anonymous: false, diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index c6dfad934..b798daa8c 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -1,13 +1,11 @@ -import { JsonRpcProvider } from '@ethersproject/providers' +import { JsonRpcBatchProvider } from '@ethersproject/providers' import { CHAIN_NAMESPACE, CHAIN_REFERENCE, ChainReference, toAssetId } from '@shapeshiftoss/caip' import { ChainAdapter } from '@shapeshiftoss/chain-adapters' import { KnownChainIds, WithdrawType } from '@shapeshiftoss/types' import axios from 'axios' import { BigNumber } from 'bignumber.js' +import { ethers } from 'ethers' import { toLower } from 'lodash' -import Web3 from 'web3' -import { HttpProvider, TransactionReceipt } from 'web3-core/types' -import { Contract } from 'web3-eth-contract' import { numberToHex } from 'web3-utils' import { erc20Abi } from '../abi/erc20-abi' @@ -85,12 +83,11 @@ const TOKE_IPFS_URL = 'https://ipfs.tokemaklabs.xyz/ipfs' export class FoxyApi { public adapter: ChainAdapter - public provider: HttpProvider + public provider: JsonRpcBatchProvider private providerUrl: string - public jsonRpcProvider: JsonRpcProvider - public web3: Web3 - private foxyStakingContracts: Contract[] - private liquidityReserveContracts: Contract[] + public jsonRpcProvider: JsonRpcBatchProvider + private foxyStakingContracts: ethers.Contract[] + private liquidityReserveContracts: ethers.Contract[] private readonly ethereumChainReference: ChainReference private foxyAddresses: FoxyAddressesType @@ -101,14 +98,14 @@ export class FoxyApi { chainReference = CHAIN_REFERENCE.EthereumMainnet, }: ConstructorArgs) { this.adapter = adapter - this.provider = new Web3.providers.HttpProvider(providerUrl) - this.jsonRpcProvider = new JsonRpcProvider(providerUrl) - this.web3 = new Web3(this.provider) + this.provider = new JsonRpcBatchProvider(providerUrl) + this.jsonRpcProvider = new JsonRpcBatchProvider(providerUrl) this.foxyStakingContracts = foxyAddresses.map( - (addresses) => new this.web3.eth.Contract(foxyStakingAbi, addresses.staking), + (addresses) => new ethers.Contract(addresses.staking, foxyStakingAbi, this.provider), ) this.liquidityReserveContracts = foxyAddresses.map( - (addresses) => new this.web3.eth.Contract(liquidityReserveAbi, addresses.liquidityReserve), + (addresses) => + new ethers.Contract(addresses.liquidityReserve, liquidityReserveAbi, this.provider), ) this.ethereumChainReference = chainReference this.providerUrl = providerUrl @@ -121,7 +118,7 @@ export class FoxyApi { * @param amount */ private normalizeAmount(amount: BigNumber) { - return this.web3.utils.toBN(amount.toFixed()) + return ethers.BigNumber.from(amount.toFixed()) } private async signAndBroadcastTx(input: SignAndBroadcastTx): Promise { @@ -132,8 +129,8 @@ export class FoxyApi { if (dryRun) return signedTx try { if (this.providerUrl.includes('localhost') || this.providerUrl.includes('127.0.0.1')) { - const sendSignedTx = await this.web3.eth.sendSignedTransaction(signedTx) - return sendSignedTx?.blockHash + const sendSignedTx = await this.provider.sendTransaction(signedTx) + return sendSignedTx?.blockHash ?? '' } return this.adapter.broadcastTransaction(signedTx) } catch (e) { @@ -150,7 +147,8 @@ export class FoxyApi { } checksumAddress(address: string): string { - return this.web3.utils.toChecksumAddress(address) + // ethers always returns checksum addresses from getAddress() calls + return ethers.utils.getAddress(address) } private verifyAddresses(addresses: string[]) { @@ -163,7 +161,7 @@ export class FoxyApi { } } - private getStakingContract(contractAddress: string): Contract { + private getStakingContract(contractAddress: string): ethers.Contract { const stakingContract = this.foxyStakingContracts.find( (item) => toLower(item.options.address) === toLower(contractAddress), ) @@ -171,7 +169,7 @@ export class FoxyApi { return stakingContract } - private getLiquidityReserveContract(liquidityReserveAddress: string): Contract { + private getLiquidityReserveContract(liquidityReserveAddress: string): ethers.Contract { const liquidityReserveContract = this.liquidityReserveContracts.find( (item) => toLower(item.options.address) === toLower(liquidityReserveAddress), ) @@ -182,13 +180,13 @@ export class FoxyApi { private async getGasPriceAndNonce(userAddress: string) { let nonce: number try { - nonce = await this.web3.eth.getTransactionCount(userAddress) + nonce = await this.provider.getTransactionCount(userAddress) } catch (e) { throw new Error(`Get nonce Error: ${e}`) } let gasPrice: string try { - gasPrice = await this.web3.eth.getGasPrice() + gasPrice = (await this.provider.getGasPrice()).toString() } catch (e) { throw new Error(`Get gasPrice Error: ${e}`) } @@ -238,13 +236,13 @@ export class FoxyApi { } async getGasPrice() { - const gasPrice = await this.web3.eth.getGasPrice() - return bnOrZero(gasPrice) + const gasPrice = await this.provider.getGasPrice() + return gasPrice } - async getTxReceipt({ txid }: TxReceipt): Promise { + async getTxReceipt({ txid }: TxReceipt): Promise { if (!txid) throw new Error('Must pass txid') - return this.web3.eth.getTransactionReceipt(txid) + return this.provider.getTransactionReceipt(txid) } async estimateClaimWithdrawGas(input: ClaimWithdrawal): Promise { @@ -349,7 +347,7 @@ export class FoxyApi { const { userAddress, tokenContractAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress, tokenContractAddress]) - const depositTokenContract = new this.web3.eth.Contract(erc20Abi, tokenContractAddress) + const depositTokenContract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { const estimatedGas = await depositTokenContract.methods @@ -401,7 +399,7 @@ export class FoxyApi { } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } - const depositTokenContract = new this.web3.eth.Contract(erc20Abi, tokenContractAddress) + const depositTokenContract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) const data: string = depositTokenContract.methods .approve(contractAddress, amount ? numberToHex(bnOrZero(amount).toString()) : MAX_ALLOWANCE) .encodeABI({ @@ -428,9 +426,10 @@ export class FoxyApi { const { userAddress, tokenContractAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress, tokenContractAddress]) - const depositTokenContract: Contract = new this.web3.eth.Contract( - erc20Abi, + const depositTokenContract: ethers.Contract = new ethers.Contract( tokenContractAddress, + erc20Abi, + this.provider, ) let allowance @@ -463,7 +462,7 @@ export class FoxyApi { } const stakingContract = this.getStakingContract(contractAddress) - const userChecksum = this.web3.utils.toChecksumAddress(userAddress) + const userChecksum = ethers.utils.getAddress(userAddress) const data: string = await stakingContract.methods .stake(this.normalizeAmount(amountDesired), userAddress) @@ -539,8 +538,12 @@ export class FoxyApi { async canClaimWithdraw(input: CanClaimWithdrawParams): Promise { const { userAddress, contractAddress } = input - const tokeManagerContract = new this.web3.eth.Contract(tokeManagerAbi, tokeManagerAddress) - const tokePoolContract = new this.web3.eth.Contract(tokePoolAbi, tokePoolAddress) + const tokeManagerContract = new ethers.Contract( + tokeManagerAddress, + tokeManagerAbi, + this.provider, + ) + const tokePoolContract = new ethers.Contract(tokePoolAddress, tokePoolAbi, this.provider) const stakingContract = this.getStakingContract(contractAddress) const coolDownInfo = await (async () => { @@ -654,7 +657,11 @@ export class FoxyApi { async canSendWithdrawalRequest(input: StakingContract): Promise { const { stakingContract } = input - const tokeManagerContract = new this.web3.eth.Contract(tokeManagerAbi, tokeManagerAddress) + const tokeManagerContract = new ethers.Contract( + tokeManagerAddress, + tokeManagerAbi, + this.provider, + ) const requestWithdrawalAmount = await (async () => { try { @@ -712,8 +719,8 @@ export class FoxyApi { const nextCycleStart = bnOrZero(currentCycleStart).plus(duration) - const blockNumber = await this.web3.eth.getBlockNumber() - const timestamp = (await this.web3.eth.getBlock(blockNumber)).timestamp + const blockNumber = await this.provider.getBlockNumber() + const timestamp = (await this.provider.getBlock(blockNumber)).timestamp const isTimeToRequest = bnOrZero(timestamp) .plus(timeLeftToRequestWithdrawal) @@ -879,7 +886,7 @@ export class FoxyApi { } let currentBlock try { - currentBlock = await this.web3.eth.getBlockNumber() + currentBlock = await this.provider.getBlockNumber() } catch (e) { throw new Error(`Failed to get block number: ${e}`) } @@ -901,7 +908,7 @@ export class FoxyApi { const { tokenContractAddress, userAddress } = input this.verifyAddresses([userAddress, tokenContractAddress]) - const contract = new this.web3.eth.Contract(erc20Abi, tokenContractAddress) + const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { const balance = await contract.methods.balanceOf(userAddress).call() return bnOrZero(balance) @@ -932,7 +939,7 @@ export class FoxyApi { async totalSupply({ tokenContractAddress }: TokenAddressInput): Promise { this.verifyAddresses([tokenContractAddress]) - const contract = new this.web3.eth.Contract(erc20Abi, tokenContractAddress) + const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { const totalSupply = await contract.methods.totalSupply().call() @@ -954,7 +961,7 @@ export class FoxyApi { async tvl(input: TokenAddressInput): Promise { const { tokenContractAddress } = input this.verifyAddresses([tokenContractAddress]) - const contract = new this.web3.eth.Contract(foxyAbi, tokenContractAddress) + const contract = new ethers.Contract(tokenContractAddress, foxyAbi, this.provider) try { const balance = await contract.methods.circulatingSupply().call() @@ -989,7 +996,11 @@ export class FoxyApi { async getClaimFromTokemakArgs(input: ContractAddressInput): Promise { const { contractAddress } = input - const rewardHashContract = new this.web3.eth.Contract(tokeRewardHashAbi, tokeRewardHashAddress) + const rewardHashContract = new ethers.Contract( + tokeRewardHashAddress, + tokeRewardHashAbi, + this.provider, + ) const latestCycleIndex = await (async () => { try { return rewardHashContract.methods.latestCycleIndex().call() @@ -1032,18 +1043,17 @@ export class FoxyApi { const { tokenContractAddress, userAddress } = input this.verifyAddresses([tokenContractAddress]) - const foxyContract = new this.web3.eth.Contract(foxyAbi, tokenContractAddress) + const foxyContract = new ethers.Contract(tokenContractAddress, foxyAbi, this.provider) const fromBlock = 14381454 // genesis rebase const rebaseEvents = await (async () => { try { - const events = ( - await foxyContract.getPastEvents('LogRebase', { - fromBlock, - toBlock: 'latest', - }) - ).filter((rebase) => rebase.returnValues.rebase !== '0') - return events + const filter = foxyContract.filters.LogRebase() + const events = await foxyContract.queryFilter(filter, fromBlock, 'latest') + const filteredEvents = events.filter( + (rebase) => rebase.args?.rebase && !rebase.args.rebase.isZero(), + ) + return filteredEvents } catch (e) { console.error(`Failed to get rebase events ${e}`) return undefined @@ -1054,10 +1064,8 @@ export class FoxyApi { const transferEvents = await (async () => { try { - const events = await foxyContract.getPastEvents('Transfer', { - fromBlock, - toBlock: 'latest', - }) + const filter = foxyContract.filters.Transfer() + const events = await foxyContract.queryFilter(filter, fromBlock, 'latest') return events } catch (e) { console.error(`Failed to get transfer events ${e}`) @@ -1066,10 +1074,7 @@ export class FoxyApi { })() const events: RebaseEvent[] = rebaseEvents.map((rebaseEvent) => { - const { - blockNumber, - returnValues: { epoch }, - } = rebaseEvent + const { blockNumber, args: { epoch } = { epoch: '' } } = rebaseEvent return { blockNumber, epoch, @@ -1090,23 +1095,21 @@ export class FoxyApi { // check transfer events to see if a user triggered a rebase through unstake or stake const unstakedTransferInfo = transferEvents?.filter( (e) => - e.blockNumber === event.blockNumber && - e.returnValues.from.toLowerCase() === userAddress, + e.blockNumber === event.blockNumber && e.args?.from.toLowerCase() === userAddress, ) - const unstakedTransferAmount = unstakedTransferInfo?.[0]?.returnValues?.value ?? 0 + const unstakedTransferAmount = unstakedTransferInfo?.[0]?.args?.value ?? 0 const stakedTransferInfo = transferEvents?.filter( (e) => - e.blockNumber === event.blockNumber && - e.returnValues.to.toLowerCase() === userAddress, + e.blockNumber === event.blockNumber && e.args?.to.toLowerCase() === userAddress, ) - const stakedTransferAmount = stakedTransferInfo?.[0]?.returnValues?.value ?? 0 + const stakedTransferAmount = stakedTransferInfo?.[0]?.args?.value ?? 0 - const postRebaseBalanceResult = await foxyContract.methods - .balanceOf(userAddress) - .call(null, event.blockNumber) - const unadjustedPreRebaseBalance = await foxyContract.methods - .balanceOf(userAddress) - .call(null, event.blockNumber - 1) + const postRebaseBalanceResult = await foxyContract.balanceOf(userAddress, { + blockTag: event.blockNumber, + }) + const unadjustedPreRebaseBalance = await foxyContract.balanceOf(userAddress, { + blockTag: event.blockNumber - 1, + }) // unstake events can trigger rebases, if they do, adjust the amount to not include that unstake's transfer amount const preRebaseBalanceResult = bnOrZero(unadjustedPreRebaseBalance) @@ -1129,7 +1132,7 @@ export class FoxyApi { const blockTime = await (async () => { try { - const block = await this.web3.eth.getBlock(event.blockNumber) + const block = await this.provider.getBlock(event.blockNumber) return bnOrZero(block.timestamp).toNumber() } catch (e) { console.error(`Failed to get timestamp of block ${e}`) diff --git a/packages/investor-foxy/src/api/foxy-types.ts b/packages/investor-foxy/src/api/foxy-types.ts index 3e68a4030..99e5deb7d 100644 --- a/packages/investor-foxy/src/api/foxy-types.ts +++ b/packages/investor-foxy/src/api/foxy-types.ts @@ -2,7 +2,7 @@ import { AssetId } from '@shapeshiftoss/caip' import { HDWallet } from '@shapeshiftoss/hdwallet-core' import { BIP44Params, WithdrawType } from '@shapeshiftoss/types' import { BigNumber } from 'bignumber.js' -import { Contract } from 'web3-eth-contract' +import ethers from 'ethers' export type FoxyAddressesType = { staking: string @@ -149,7 +149,7 @@ export type RebaseHistory = { } export type StakingContract = { - stakingContract: Contract + stakingContract: ethers.ethers.Contract } // this comment only exists to publish this package - delete me if you see me From 38e27cbc4934de7e6126cc69543507987f2c9bc1 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Sun, 18 Sep 2022 23:56:39 +0200 Subject: [PATCH 02/17] Fix: circulating supply ethers call() shorthand --- packages/investor-foxy/src/api/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index b798daa8c..95bfaa444 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -964,7 +964,7 @@ export class FoxyApi { const contract = new ethers.Contract(tokenContractAddress, foxyAbi, this.provider) try { - const balance = await contract.methods.circulatingSupply().call() + const balance = await contract.circulatingSupply() return bnOrZero(balance) } catch (e) { throw new Error(`Failed to get tvl: ${e}`) From e464f4b929330ae1d0c0bc02dba5c14a13418524 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 00:24:40 +0200 Subject: [PATCH 03/17] fix: contract.options.address -> contract.address --- packages/investor-foxy/src/api/api.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 95bfaa444..ed8ea9886 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -163,7 +163,7 @@ export class FoxyApi { private getStakingContract(contractAddress: string): ethers.Contract { const stakingContract = this.foxyStakingContracts.find( - (item) => toLower(item.options.address) === toLower(contractAddress), + (item) => toLower(item.address) === toLower(contractAddress), ) if (!stakingContract) throw new Error('Not a valid contract address') return stakingContract @@ -171,7 +171,7 @@ export class FoxyApi { private getLiquidityReserveContract(liquidityReserveAddress: string): ethers.Contract { const liquidityReserveContract = this.liquidityReserveContracts.find( - (item) => toLower(item.options.address) === toLower(liquidityReserveAddress), + (item) => toLower(item.address) === toLower(liquidityReserveAddress), ) if (!liquidityReserveContract) throw new Error('Not a valid reserve contract address') return liquidityReserveContract @@ -198,7 +198,7 @@ export class FoxyApi { const opportunities = await Promise.all( this.foxyAddresses.map(async (addresses) => { const stakingContract = this.foxyStakingContracts.find( - (item) => toLower(item.options.address) === toLower(addresses.staking), + (item) => toLower(item.address) === toLower(addresses.staking), ) try { const expired = await stakingContract?.methods.pauseStaking().call() @@ -569,7 +569,7 @@ export class FoxyApi { const requestedWithdrawals = await (async () => { try { - return tokePoolContract.methods.requestedWithdrawals(stakingContract.options.address).call() + return tokePoolContract.methods.requestedWithdrawals(stakingContract.address).call() } catch (e) { console.error(`Failed to get requestedWithdrawals: ${e}`) return {} From ae11ad245d1f1eb00ff9e72fffbd37dae574b11e Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 00:40:32 +0200 Subject: [PATCH 04/17] feat: moar api migration --- packages/investor-foxy/src/api/api.ts | 128 +++++++++++--------------- 1 file changed, 56 insertions(+), 72 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index ed8ea9886..c28684eff 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -201,7 +201,7 @@ export class FoxyApi { (item) => toLower(item.address) === toLower(addresses.staking), ) try { - const expired = await stakingContract?.methods.pauseStaking().call() + const expired = await stakingContract?.pauseStaking() const tvl = await this.tvl({ tokenContractAddress: addresses.foxy }) const apy = this.apy() return transformData({ ...addresses, expired, tvl, apy }) @@ -226,7 +226,7 @@ export class FoxyApi { const stakingContract = this.getStakingContract(addresses.staking) try { - const expired = await stakingContract.methods.pauseStaking().call() + const expired = await stakingContract.pauseStaking() const tvl = await this.tvl({ tokenContractAddress: addresses.foxy }) const apy = this.apy() return transformData({ ...addresses, tvl, apy, expired }) @@ -253,10 +253,8 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.methods.claimWithdraw(addressToClaim).estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await stakingContract.estimateGas.claimWithdraw(addressToClaim) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -271,10 +269,8 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.methods.sendWithdrawalRequests().estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await stakingContract.estimateGas.sendWithdrawalRequests() + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -288,12 +284,10 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) try { - const estimatedGas = await liquidityReserveContract.methods - .addLiquidity(this.normalizeAmount(amountDesired)) - .estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await liquidityReserveContract.estimateGas.addLiquidity( + this.normalizeAmount(amountDesired), + ) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -307,12 +301,10 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) try { - const estimatedGas = await liquidityReserveContract.methods - .removeLiquidity(this.normalizeAmount(amountDesired)) - .estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await liquidityReserveContract.estimateGas.removeLiquidity( + this.normalizeAmount(amountDesired), + ) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -329,15 +321,9 @@ export class FoxyApi { try { const estimatedGas = isDelayed - ? await stakingContract.methods - .unstake(this.normalizeAmount(amountDesired), true) - .estimateGas({ - from: userAddress, - }) - : await stakingContract.methods.instantUnstake(true).estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + ? await stakingContract.estimateGas.unstake(this.normalizeAmount(amountDesired), true) + : await stakingContract.estimateGas.instantUnstake(true) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -350,12 +336,11 @@ export class FoxyApi { const depositTokenContract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { - const estimatedGas = await depositTokenContract.methods - .approve(contractAddress, MAX_ALLOWANCE) - .estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await depositTokenContract.estimateGas.approve( + contractAddress, + MAX_ALLOWANCE, + ) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -369,12 +354,11 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.methods - .stake(this.normalizeAmount(amountDesired), userAddress) - .estimateGas({ - from: userAddress, - }) - return bnOrZero(estimatedGas) + const estimatedGas = await stakingContract.estimateGas.stake( + this.normalizeAmount(amountDesired), + userAddress, + ) + return bnOrZero(estimatedGas.toString()) } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -400,7 +384,7 @@ export class FoxyApi { throw new Error(`Estimate Gas Error: ${e}`) } const depositTokenContract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) - const data: string = depositTokenContract.methods + const data: string = depositTokenContract .approve(contractAddress, amount ? numberToHex(bnOrZero(amount).toString()) : MAX_ALLOWANCE) .encodeABI({ from: userAddress, @@ -434,7 +418,7 @@ export class FoxyApi { let allowance try { - allowance = await depositTokenContract.methods.allowance(userAddress, contractAddress).call() + allowance = await depositTokenContract.allowance(userAddress, contractAddress).call() } catch (e) { throw new Error(`Failed to get allowance ${e}`) } @@ -464,7 +448,7 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) const userChecksum = ethers.utils.getAddress(userAddress) - const data: string = await stakingContract.methods + const data: string = await stakingContract .stake(this.normalizeAmount(amountDesired), userAddress) .encodeABI({ value: 0, @@ -513,10 +497,10 @@ export class FoxyApi { if (isDelayed && !amountDesired.gt(0)) throw new Error('Must send valid amount') const data: string = isDelayed - ? stakingContract.methods.unstake(this.normalizeAmount(amountDesired), true).encodeABI({ + ? stakingContract.unstake(this.normalizeAmount(amountDesired), true).encodeABI({ from: userAddress, }) - : stakingContract.methods.instantUnstake(true).encodeABI({ + : stakingContract.instantUnstake(true).encodeABI({ from: userAddress, }) @@ -548,7 +532,7 @@ export class FoxyApi { const coolDownInfo = await (async () => { try { - const coolDown = await stakingContract.methods.coolDownInfo(userAddress).call() + const coolDown = await stakingContract.coolDownInfo(userAddress).call() return { ...coolDown, endEpoch: coolDown.expiry, @@ -560,7 +544,7 @@ export class FoxyApi { const epoch = await (async () => { try { - return stakingContract.methods.epoch().call() + return stakingContract.epoch().call() } catch (e) { console.error(`Failed to get epoch: ${e}`) return {} @@ -569,7 +553,7 @@ export class FoxyApi { const requestedWithdrawals = await (async () => { try { - return tokePoolContract.methods.requestedWithdrawals(stakingContract.address).call() + return tokePoolContract.requestedWithdrawals(stakingContract.address).call() } catch (e) { console.error(`Failed to get requestedWithdrawals: ${e}`) return {} @@ -578,7 +562,7 @@ export class FoxyApi { const currentCycleIndex = await (async () => { try { - return tokeManagerContract.methods.getCurrentCycleIndex().call() + return tokeManagerContract.getCurrentCycleIndex().call() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -587,7 +571,7 @@ export class FoxyApi { const withdrawalAmount = await (async () => { try { - return stakingContract.methods.withdrawalAmount().call() + return stakingContract.withdrawalAmount().call() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -635,7 +619,7 @@ export class FoxyApi { const canClaim = await this.canClaimWithdraw({ userAddress, contractAddress }) if (!canClaim) throw new Error('Not ready to claim') - const data: string = stakingContract.methods.claimWithdraw(addressToClaim).encodeABI({ + const data: string = stakingContract.claimWithdraw(addressToClaim).encodeABI({ from: userAddress, }) @@ -665,7 +649,7 @@ export class FoxyApi { const requestWithdrawalAmount = await (async () => { try { - return stakingContract.methods.requestWithdrawalAmount().call() + return stakingContract.requestWithdrawalAmount().call() } catch (e) { console.error(`Failed to get requestWithdrawalAmount: ${e}`) return 0 @@ -674,7 +658,7 @@ export class FoxyApi { const timeLeftToRequestWithdrawal = await (async () => { try { - return stakingContract.methods.timeLeftToRequestWithdrawal().call() + return stakingContract.timeLeftToRequestWithdrawal().call() } catch (e) { console.error(`Failed to get timeLeftToRequestWithdrawal: ${e}`) return 0 @@ -683,7 +667,7 @@ export class FoxyApi { const lastTokeCycleIndex = await (async () => { try { - return stakingContract.methods.lastTokeCycleIndex().call() + return stakingContract.lastTokeCycleIndex().call() } catch (e) { console.error(`Failed to get lastTokeCycleIndex: ${e}`) return 0 @@ -692,7 +676,7 @@ export class FoxyApi { const duration = await (async () => { try { - return tokeManagerContract.methods.getCycleDuration().call() + return tokeManagerContract.getCycleDuration().call() } catch (e) { console.error(`Failed to get cycleDuration: ${e}`) return 0 @@ -701,7 +685,7 @@ export class FoxyApi { const currentCycleIndex = await (async () => { try { - return tokeManagerContract.methods.getCurrentCycleIndex().call() + return tokeManagerContract.getCurrentCycleIndex().call() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -710,7 +694,7 @@ export class FoxyApi { const currentCycleStart = await (async () => { try { - return tokeManagerContract.methods.getCurrentCycle().call() + return tokeManagerContract.getCurrentCycle().call() } catch (e) { console.error(`Failed to get currentCycle: ${e}`) return 0 @@ -748,7 +732,7 @@ export class FoxyApi { const canSendRequest = await this.canSendWithdrawalRequest({ stakingContract }) if (!canSendRequest) throw new Error('Not ready to send request') - const data: string = stakingContract.methods.sendWithdrawalRequests().encodeABI({ + const data: string = stakingContract.sendWithdrawalRequests().encodeABI({ from: userAddress, }) @@ -793,7 +777,7 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) - const data: string = liquidityReserveContract.methods + const data: string = liquidityReserveContract .addLiquidity(this.normalizeAmount(amountDesired)) .encodeABI({ from: userAddress, @@ -839,7 +823,7 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) - const data: string = liquidityReserveContract.methods + const data: string = liquidityReserveContract .removeLiquidity(this.normalizeAmount(amountDesired)) .encodeABI({ from: userAddress, @@ -870,7 +854,7 @@ export class FoxyApi { let coolDownInfo try { - const coolDown = await stakingContract.methods.coolDownInfo(userAddress).call() + const coolDown = await stakingContract.coolDownInfo(userAddress).call() coolDownInfo = { ...coolDown, endEpoch: coolDown.expiry, @@ -880,7 +864,7 @@ export class FoxyApi { } let epoch try { - epoch = await stakingContract.methods.epoch().call() + epoch = await stakingContract.epoch().call() } catch (e) { throw new Error(`Failed to get epoch: ${e}`) } @@ -910,7 +894,7 @@ export class FoxyApi { const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { - const balance = await contract.methods.balanceOf(userAddress).call() + const balance = await contract.balanceOf(userAddress).call() return bnOrZero(balance) } catch (e) { throw new Error(`Failed to get balance: ${e}`) @@ -924,13 +908,13 @@ export class FoxyApi { let liquidityReserveAddress try { - liquidityReserveAddress = await stakingContract.methods.LIQUIDITY_RESERVE().call() + liquidityReserveAddress = await stakingContract.LIQUIDITY_RESERVE().call() } catch (e) { throw new Error(`Failed to get liquidityReserve address ${e}`) } const liquidityReserveContract = this.getLiquidityReserveContract(liquidityReserveAddress) try { - const feeInBasisPoints = await liquidityReserveContract.methods.fee().call() + const feeInBasisPoints = await liquidityReserveContract.fee().call() return bnOrZero(feeInBasisPoints).div(10000) // convert from basis points to decimal percentage } catch (e) { throw new Error(`Failed to get instantUnstake fee ${e}`) @@ -942,7 +926,7 @@ export class FoxyApi { const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { - const totalSupply = await contract.methods.totalSupply().call() + const totalSupply = await contract.totalSupply().call() return bnOrZero(totalSupply) } catch (e) { throw new Error(`Failed to get totalSupply: ${e}`) @@ -978,7 +962,7 @@ export class FoxyApi { let coolDownInfo try { - coolDownInfo = await stakingContract.methods.coolDownInfo(userAddress).call() + coolDownInfo = await stakingContract.coolDownInfo(userAddress).call() } catch (e) { throw new Error(`Failed to get coolDowninfo: ${e}`) } @@ -1003,14 +987,14 @@ export class FoxyApi { ) const latestCycleIndex = await (async () => { try { - return rewardHashContract.methods.latestCycleIndex().call() + return rewardHashContract.latestCycleIndex().call() } catch (e) { throw new Error(`Failed to get latestCycleIndex, ${e}`) } })() const cycleHashes = await (async () => { try { - return rewardHashContract.methods.cycleHashes(latestCycleIndex).call() + return rewardHashContract.cycleHashes(latestCycleIndex).call() } catch (e) { throw new Error(`Failed to get latestCycleIndex, ${e}`) } From 8f8db119bdb51e3fc182ce41bf051fbfba36c7ac Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 00:47:51 +0200 Subject: [PATCH 05/17] feat: remove .call() from web3 legacy --- packages/investor-foxy/src/api/api.ts | 42 +++++++++++++-------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index c28684eff..d002eacaf 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -418,7 +418,7 @@ export class FoxyApi { let allowance try { - allowance = await depositTokenContract.allowance(userAddress, contractAddress).call() + allowance = await depositTokenContract.allowance(userAddress, contractAddress) } catch (e) { throw new Error(`Failed to get allowance ${e}`) } @@ -532,7 +532,7 @@ export class FoxyApi { const coolDownInfo = await (async () => { try { - const coolDown = await stakingContract.coolDownInfo(userAddress).call() + const coolDown = await stakingContract.coolDownInfo(userAddress) return { ...coolDown, endEpoch: coolDown.expiry, @@ -544,7 +544,7 @@ export class FoxyApi { const epoch = await (async () => { try { - return stakingContract.epoch().call() + return stakingContract.epoch() } catch (e) { console.error(`Failed to get epoch: ${e}`) return {} @@ -553,7 +553,7 @@ export class FoxyApi { const requestedWithdrawals = await (async () => { try { - return tokePoolContract.requestedWithdrawals(stakingContract.address).call() + return tokePoolContract.requestedWithdrawals(stakingContract.address) } catch (e) { console.error(`Failed to get requestedWithdrawals: ${e}`) return {} @@ -562,7 +562,7 @@ export class FoxyApi { const currentCycleIndex = await (async () => { try { - return tokeManagerContract.getCurrentCycleIndex().call() + return tokeManagerContract.getCurrentCycleIndex() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -571,7 +571,7 @@ export class FoxyApi { const withdrawalAmount = await (async () => { try { - return stakingContract.withdrawalAmount().call() + return stakingContract.withdrawalAmount() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -649,7 +649,7 @@ export class FoxyApi { const requestWithdrawalAmount = await (async () => { try { - return stakingContract.requestWithdrawalAmount().call() + return stakingContract.requestWithdrawalAmount() } catch (e) { console.error(`Failed to get requestWithdrawalAmount: ${e}`) return 0 @@ -658,7 +658,7 @@ export class FoxyApi { const timeLeftToRequestWithdrawal = await (async () => { try { - return stakingContract.timeLeftToRequestWithdrawal().call() + return stakingContract.timeLeftToRequestWithdrawal() } catch (e) { console.error(`Failed to get timeLeftToRequestWithdrawal: ${e}`) return 0 @@ -667,7 +667,7 @@ export class FoxyApi { const lastTokeCycleIndex = await (async () => { try { - return stakingContract.lastTokeCycleIndex().call() + return stakingContract.lastTokeCycleIndex() } catch (e) { console.error(`Failed to get lastTokeCycleIndex: ${e}`) return 0 @@ -676,7 +676,7 @@ export class FoxyApi { const duration = await (async () => { try { - return tokeManagerContract.getCycleDuration().call() + return tokeManagerContract.getCycleDuration() } catch (e) { console.error(`Failed to get cycleDuration: ${e}`) return 0 @@ -685,7 +685,7 @@ export class FoxyApi { const currentCycleIndex = await (async () => { try { - return tokeManagerContract.getCurrentCycleIndex().call() + return tokeManagerContract.getCurrentCycleIndex() } catch (e) { console.error(`Failed to get currentCycleIndex: ${e}`) return 0 @@ -694,7 +694,7 @@ export class FoxyApi { const currentCycleStart = await (async () => { try { - return tokeManagerContract.getCurrentCycle().call() + return tokeManagerContract.getCurrentCycle() } catch (e) { console.error(`Failed to get currentCycle: ${e}`) return 0 @@ -854,7 +854,7 @@ export class FoxyApi { let coolDownInfo try { - const coolDown = await stakingContract.coolDownInfo(userAddress).call() + const coolDown = await stakingContract.coolDownInfo(userAddress) coolDownInfo = { ...coolDown, endEpoch: coolDown.expiry, @@ -864,7 +864,7 @@ export class FoxyApi { } let epoch try { - epoch = await stakingContract.epoch().call() + epoch = await stakingContract.epoch() } catch (e) { throw new Error(`Failed to get epoch: ${e}`) } @@ -894,7 +894,7 @@ export class FoxyApi { const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { - const balance = await contract.balanceOf(userAddress).call() + const balance = await contract.balanceOf(userAddress) return bnOrZero(balance) } catch (e) { throw new Error(`Failed to get balance: ${e}`) @@ -908,13 +908,13 @@ export class FoxyApi { let liquidityReserveAddress try { - liquidityReserveAddress = await stakingContract.LIQUIDITY_RESERVE().call() + liquidityReserveAddress = await stakingContract.LIQUIDITY_RESERVE() } catch (e) { throw new Error(`Failed to get liquidityReserve address ${e}`) } const liquidityReserveContract = this.getLiquidityReserveContract(liquidityReserveAddress) try { - const feeInBasisPoints = await liquidityReserveContract.fee().call() + const feeInBasisPoints = await liquidityReserveContract.fee() return bnOrZero(feeInBasisPoints).div(10000) // convert from basis points to decimal percentage } catch (e) { throw new Error(`Failed to get instantUnstake fee ${e}`) @@ -926,7 +926,7 @@ export class FoxyApi { const contract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) try { - const totalSupply = await contract.totalSupply().call() + const totalSupply = await contract.totalSupply() return bnOrZero(totalSupply) } catch (e) { throw new Error(`Failed to get totalSupply: ${e}`) @@ -962,7 +962,7 @@ export class FoxyApi { let coolDownInfo try { - coolDownInfo = await stakingContract.coolDownInfo(userAddress).call() + coolDownInfo = await stakingContract.coolDownInfo(userAddress) } catch (e) { throw new Error(`Failed to get coolDowninfo: ${e}`) } @@ -987,14 +987,14 @@ export class FoxyApi { ) const latestCycleIndex = await (async () => { try { - return rewardHashContract.latestCycleIndex().call() + return rewardHashContract.latestCycleIndex() } catch (e) { throw new Error(`Failed to get latestCycleIndex, ${e}`) } })() const cycleHashes = await (async () => { try { - return rewardHashContract.cycleHashes(latestCycleIndex).call() + return rewardHashContract.cycleHashes(latestCycleIndex) } catch (e) { throw new Error(`Failed to get latestCycleIndex, ${e}`) } From d9b2b179396a90b939cd886eda07ad0277b58ce6 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 14:25:30 +0200 Subject: [PATCH 06/17] feat: more accurate types, move from ethers.BigNumber to the more serializable string outputs --- packages/investor-foxy/src/api/api.ts | 65 ++++++++++++--------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index d002eacaf..5e139cd68 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -245,7 +245,7 @@ export class FoxyApi { return this.provider.getTransactionReceipt(txid) } - async estimateClaimWithdrawGas(input: ClaimWithdrawal): Promise { + async estimateClaimWithdrawGas(input: ClaimWithdrawal): Promise { const { claimAddress, userAddress, contractAddress } = input const addressToClaim = claimAddress ?? userAddress this.verifyAddresses([addressToClaim, userAddress, contractAddress]) @@ -254,15 +254,13 @@ export class FoxyApi { try { const estimatedGas = await stakingContract.estimateGas.claimWithdraw(addressToClaim) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateSendWithdrawalRequestsGas( - input: TxInputWithoutAmountAndWallet, - ): Promise { + async estimateSendWithdrawalRequestsGas(input: TxInputWithoutAmountAndWallet): Promise { const { userAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress]) @@ -270,13 +268,13 @@ export class FoxyApi { try { const estimatedGas = await stakingContract.estimateGas.sendWithdrawalRequests() - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateAddLiquidityGas(input: EstimateGasTxInput): Promise { + async estimateAddLiquidityGas(input: EstimateGasTxInput): Promise { const { amountDesired, userAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress]) if (!amountDesired.gt(0)) throw new Error('Must send valid amount') @@ -287,13 +285,13 @@ export class FoxyApi { const estimatedGas = await liquidityReserveContract.estimateGas.addLiquidity( this.normalizeAmount(amountDesired), ) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateRemoveLiquidityGas(input: EstimateGasTxInput): Promise { + async estimateRemoveLiquidityGas(input: EstimateGasTxInput): Promise { const { amountDesired, userAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress]) if (!amountDesired.gt(0)) throw new Error('Must send valid amount') @@ -304,13 +302,13 @@ export class FoxyApi { const estimatedGas = await liquidityReserveContract.estimateGas.removeLiquidity( this.normalizeAmount(amountDesired), ) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateWithdrawGas(input: WithdrawEstimateGasInput): Promise { + async estimateWithdrawGas(input: WithdrawEstimateGasInput): Promise { const { amountDesired, userAddress, contractAddress, type } = input this.verifyAddresses([userAddress, contractAddress]) @@ -323,13 +321,13 @@ export class FoxyApi { const estimatedGas = isDelayed ? await stakingContract.estimateGas.unstake(this.normalizeAmount(amountDesired), true) : await stakingContract.estimateGas.instantUnstake(true) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateApproveGas(input: EstimateGasApproveInput): Promise { + async estimateApproveGas(input: EstimateGasApproveInput): Promise { const { userAddress, tokenContractAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress, tokenContractAddress]) @@ -340,13 +338,13 @@ export class FoxyApi { contractAddress, MAX_ALLOWANCE, ) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } } - async estimateDepositGas(input: EstimateGasTxInput): Promise { + async estimateDepositGas(input: EstimateGasTxInput): Promise { const { amountDesired, userAddress, contractAddress } = input this.verifyAddresses([userAddress, contractAddress]) if (!amountDesired.gt(0)) throw new Error('Must send valid amount') @@ -358,7 +356,7 @@ export class FoxyApi { this.normalizeAmount(amountDesired), userAddress, ) - return bnOrZero(estimatedGas.toString()) + return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) } @@ -377,9 +375,9 @@ export class FoxyApi { this.verifyAddresses([userAddress, contractAddress, tokenContractAddress]) if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateApproveGas(input) + estimatedGas = await this.estimateApproveGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -392,7 +390,6 @@ export class FoxyApi { const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) - const estimatedGas = estimatedGasBN.toString() const payload = { bip44Params, chainId: chainReferenceAsNumber, @@ -438,9 +435,9 @@ export class FoxyApi { if (!amountDesired.gt(0)) throw new Error('Must send valid amount') if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateDepositGas(input) + estimatedGas = await this.estimateDepositGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -456,7 +453,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, @@ -484,9 +480,9 @@ export class FoxyApi { this.verifyAddresses([userAddress, contractAddress]) if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateWithdrawGas(input) + estimatedGas = await this.estimateWithdrawGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -505,7 +501,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, @@ -607,9 +602,9 @@ export class FoxyApi { this.verifyAddresses([userAddress, contractAddress, addressToClaim]) if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateClaimWithdrawGas(input) + estimatedGas = await this.estimateClaimWithdrawGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -624,7 +619,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, @@ -720,9 +714,9 @@ export class FoxyApi { this.verifyAddresses([userAddress, contractAddress]) if (!wallet || !contractAddress) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateSendWithdrawalRequestsGas(input) + estimatedGas = await this.estimateSendWithdrawalRequestsGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -737,7 +731,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, @@ -768,9 +761,9 @@ export class FoxyApi { if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateAddLiquidityGas(input) + estimatedGas = await this.estimateAddLiquidityGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -784,7 +777,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, @@ -814,9 +806,9 @@ export class FoxyApi { if (!amountDesired.gt(0)) throw new Error('Must send valid amount') if (!wallet) throw new Error('Missing inputs') - let estimatedGasBN: BigNumber + let estimatedGas: string try { - estimatedGasBN = await this.estimateRemoveLiquidityGas(input) + estimatedGas = await this.estimateRemoveLiquidityGas(input) } catch (e) { throw new Error(`Estimate Gas Error: ${e}`) } @@ -830,7 +822,6 @@ export class FoxyApi { }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) - const estimatedGas = estimatedGasBN.toString() const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { bip44Params, From 4414df37e175f5518b6a0a0f55c65e2a7a0feb82 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 14:25:40 +0200 Subject: [PATCH 07/17] fix: cooldownInfo tuple --- packages/investor-foxy/src/api/api.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 5e139cd68..54ece3b05 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -951,9 +951,11 @@ export class FoxyApi { this.verifyAddresses([userAddress, contractAddress]) const stakingContract = this.getStakingContract(contractAddress) - let coolDownInfo + let coolDownInfo: [amount: string, gons: string, expiry: string] try { - coolDownInfo = await stakingContract.coolDownInfo(userAddress) + coolDownInfo = (await stakingContract.coolDownInfo(userAddress)).map( + (info: ethers.BigNumber) => info.toString(), + ) } catch (e) { throw new Error(`Failed to get coolDowninfo: ${e}`) } @@ -963,8 +965,12 @@ export class FoxyApi { } catch (e) { throw new Error(`Failed to getTimeUntilClaimable: ${e}`) } + + const [amount, gons, expiry] = coolDownInfo return { - ...coolDownInfo, + amount, + gons, + expiry, releaseTime, } } From a501561b69d7cacbf62325ed2465ec295ed4b232 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 15:55:22 +0200 Subject: [PATCH 08/17] fix: approve() abi encoding --- packages/investor-foxy/src/api/api.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 54ece3b05..e298b0e27 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -382,11 +382,10 @@ export class FoxyApi { throw new Error(`Estimate Gas Error: ${e}`) } const depositTokenContract = new ethers.Contract(tokenContractAddress, erc20Abi, this.provider) - const data: string = depositTokenContract - .approve(contractAddress, amount ? numberToHex(bnOrZero(amount).toString()) : MAX_ALLOWANCE) - .encodeABI({ - from: userAddress, - }) + const data: string = depositTokenContract.interface.encodeFunctionData('approve', [ + contractAddress, + amount ? numberToHex(bnOrZero(amount).toString()) : MAX_ALLOWANCE, + ]) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) From 9d08004c2a0f15a36d108712f39564bc6e79b3db Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:06:27 +0200 Subject: [PATCH 09/17] fix: remaining encodeAbi -> encodeFunctionData --- packages/investor-foxy/src/api/api.ts | 57 ++++++++++++--------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index e298b0e27..7e5b88bfa 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -442,14 +442,17 @@ export class FoxyApi { } const stakingContract = this.getStakingContract(contractAddress) - const userChecksum = ethers.utils.getAddress(userAddress) + // const userChecksum = ethers.utils.getAddress(userAddress) - const data: string = await stakingContract - .stake(this.normalizeAmount(amountDesired), userAddress) - .encodeABI({ - value: 0, - from: userChecksum, - }) + const data: string = stakingContract.interface.encodeFunctionData('stake', [ + this.normalizeAmount(amountDesired), + userAddress, + ]) + + // { + // value: 0, + // from: userChecksum, + // }) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) @@ -491,13 +494,12 @@ export class FoxyApi { const isDelayed = type === WithdrawType.DELAYED && amountDesired if (isDelayed && !amountDesired.gt(0)) throw new Error('Must send valid amount') - const data: string = isDelayed - ? stakingContract.unstake(this.normalizeAmount(amountDesired), true).encodeABI({ - from: userAddress, - }) - : stakingContract.instantUnstake(true).encodeABI({ - from: userAddress, - }) + const stakingContractCallInput: Parameters< + typeof stakingContract.interface.encodeFunctionData + > = isDelayed + ? ['unstake', [this.normalizeAmount(amountDesired), true]] + : ['instantUnstake', ['true']] + const data: string = stakingContract.interface.encodeFunctionData(...stakingContractCallInput) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) @@ -613,9 +615,9 @@ export class FoxyApi { const canClaim = await this.canClaimWithdraw({ userAddress, contractAddress }) if (!canClaim) throw new Error('Not ready to claim') - const data: string = stakingContract.claimWithdraw(addressToClaim).encodeABI({ - from: userAddress, - }) + const data: string = stakingContract.interface.encodeFunctionData('claimWithdraw', [ + addressToClaim, + ]) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) @@ -725,10 +727,7 @@ export class FoxyApi { const canSendRequest = await this.canSendWithdrawalRequest({ stakingContract }) if (!canSendRequest) throw new Error('Not ready to send request') - const data: string = stakingContract.sendWithdrawalRequests().encodeABI({ - from: userAddress, - }) - + const data: string = stakingContract.interface.encodeFunctionData('sendWithdrawalRequests') const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) const payload = { @@ -769,11 +768,9 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) - const data: string = liquidityReserveContract - .addLiquidity(this.normalizeAmount(amountDesired)) - .encodeABI({ - from: userAddress, - }) + const data: string = liquidityReserveContract.interface.encodeFunctionData('addLiquidity', [ + this.normalizeAmount(amountDesired), + ]) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) @@ -814,11 +811,9 @@ export class FoxyApi { const liquidityReserveContract = this.getLiquidityReserveContract(contractAddress) - const data: string = liquidityReserveContract - .removeLiquidity(this.normalizeAmount(amountDesired)) - .encodeABI({ - from: userAddress, - }) + const data: string = liquidityReserveContract.interface.encodeFunctionData('removeLiquidity', [ + this.normalizeAmount(amountDesired), + ]) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) From bab81bbb510a07f35a660b4c2bb3b269fa319afb Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 16:43:10 +0200 Subject: [PATCH 10/17] fix: more conversions to string --- packages/investor-foxy/src/api/api.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 7e5b88bfa..d78e3da72 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -177,8 +177,10 @@ export class FoxyApi { return liquidityReserveContract } - private async getGasPriceAndNonce(userAddress: string) { - let nonce: number + private async getGasPriceAndNonce( + userAddress: string, + ): Promise<{ nonce: string; gasPrice: string }> { + let nonce try { nonce = await this.provider.getTransactionCount(userAddress) } catch (e) { @@ -190,7 +192,7 @@ export class FoxyApi { } catch (e) { throw new Error(`Get gasPrice Error: ${e}`) } - return { nonce: String(nonce), gasPrice } + return { nonce: nonce.toString(), gasPrice } } async getFoxyOpportunities() { @@ -235,9 +237,9 @@ export class FoxyApi { } } - async getGasPrice() { + async getGasPrice(): Promise { const gasPrice = await this.provider.getGasPrice() - return gasPrice + return gasPrice.toString() } async getTxReceipt({ txid }: TxReceipt): Promise { @@ -418,7 +420,7 @@ export class FoxyApi { } catch (e) { throw new Error(`Failed to get allowance ${e}`) } - return allowance + return allowance.toString() } async deposit(input: TxInput): Promise { From 5b59b9fef4c9588d308aa192639ab22c6eda388c Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Mon, 19 Sep 2022 17:07:21 +0200 Subject: [PATCH 11/17] fix: estimateGas full signature syntax --- packages/investor-foxy/src/api/api.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index d78e3da72..9f4c92ab2 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -321,7 +321,10 @@ export class FoxyApi { try { const estimatedGas = isDelayed - ? await stakingContract.estimateGas.unstake(this.normalizeAmount(amountDesired), true) + ? await stakingContract.estimateGas['unstake(uint256,bool)']( + this.normalizeAmount(amountDesired), + true, + ) : await stakingContract.estimateGas.instantUnstake(true) return estimatedGas.toString() } catch (e) { @@ -354,7 +357,7 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.estimateGas.stake( + const estimatedGas = await stakingContract.estimateGas['stake(uint256)']( this.normalizeAmount(amountDesired), userAddress, ) From a6a466611befc5295ffb081b80dfd64530337f9d Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Tue, 20 Sep 2022 17:38:29 +0200 Subject: [PATCH 12/17] feat: add from override on stake(uint256) estimateGas --- packages/investor-foxy/src/api/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 9f4c92ab2..fd79b96fa 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -359,7 +359,7 @@ export class FoxyApi { try { const estimatedGas = await stakingContract.estimateGas['stake(uint256)']( this.normalizeAmount(amountDesired), - userAddress, + { from: userAddress }, ) return estimatedGas.toString() } catch (e) { From 213ce96f73e7a94ffd02dacdd102bf4d67397b93 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Tue, 20 Sep 2022 20:30:59 +0200 Subject: [PATCH 13/17] fix: more conversion --- packages/investor-foxy/src/api/api.ts | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index fd79b96fa..616d19c1e 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -255,7 +255,9 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.estimateGas.claimWithdraw(addressToClaim) + const estimatedGas = await stakingContract.estimateGas.claimWithdraw(addressToClaim, { + from: userAddress, + }) return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) @@ -269,7 +271,9 @@ export class FoxyApi { const stakingContract = this.getStakingContract(contractAddress) try { - const estimatedGas = await stakingContract.estimateGas.sendWithdrawalRequests() + const estimatedGas = await stakingContract.estimateGas.sendWithdrawalRequests([], { + from: userAddress, + }) return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) @@ -286,6 +290,7 @@ export class FoxyApi { try { const estimatedGas = await liquidityReserveContract.estimateGas.addLiquidity( this.normalizeAmount(amountDesired), + { from: userAddress }, ) return estimatedGas.toString() } catch (e) { @@ -303,6 +308,7 @@ export class FoxyApi { try { const estimatedGas = await liquidityReserveContract.estimateGas.removeLiquidity( this.normalizeAmount(amountDesired), + { from: userAddress }, ) return estimatedGas.toString() } catch (e) { @@ -324,8 +330,9 @@ export class FoxyApi { ? await stakingContract.estimateGas['unstake(uint256,bool)']( this.normalizeAmount(amountDesired), true, + { from: userAddress }, ) - : await stakingContract.estimateGas.instantUnstake(true) + : await stakingContract.estimateGas.instantUnstake(true, { from: userAddress }) return estimatedGas.toString() } catch (e) { throw new Error(`Failed to get gas ${e}`) @@ -342,6 +349,7 @@ export class FoxyApi { const estimatedGas = await depositTokenContract.estimateGas.approve( contractAddress, MAX_ALLOWANCE, + { from: userAddress }, ) return estimatedGas.toString() } catch (e) { @@ -447,12 +455,16 @@ export class FoxyApi { } const stakingContract = this.getStakingContract(contractAddress) - // const userChecksum = ethers.utils.getAddress(userAddress) - - const data: string = stakingContract.interface.encodeFunctionData('stake', [ - this.normalizeAmount(amountDesired), - userAddress, - ]) + const userChecksum = ethers.utils.getAddress(userAddress) + + const data: string = + ( + await stakingContract.populateTransaction['stake(uint256,address)']( + this.normalizeAmount(amountDesired), + userAddress, + { from: userChecksum, value: 0 }, + ) + ).data ?? '' // { // value: 0, @@ -502,7 +514,7 @@ export class FoxyApi { const stakingContractCallInput: Parameters< typeof stakingContract.interface.encodeFunctionData > = isDelayed - ? ['unstake', [this.normalizeAmount(amountDesired), true]] + ? ['unstake(uint256,bool)', [this.normalizeAmount(amountDesired), true]] : ['instantUnstake', ['true']] const data: string = stakingContract.interface.encodeFunctionData(...stakingContractCallInput) From 1203af33680475fbecd772811bb82fa9461b9fa3 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Tue, 20 Sep 2022 21:08:38 +0200 Subject: [PATCH 14/17] feat: cleanup --- packages/investor-foxy/src/api/api.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 616d19c1e..14e22f960 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -455,21 +455,12 @@ export class FoxyApi { } const stakingContract = this.getStakingContract(contractAddress) - const userChecksum = ethers.utils.getAddress(userAddress) - - const data: string = - ( - await stakingContract.populateTransaction['stake(uint256,address)']( - this.normalizeAmount(amountDesired), - userAddress, - { from: userChecksum, value: 0 }, - ) - ).data ?? '' + // const userChecksum = ethers.utils.getAddress(userAddress) - // { - // value: 0, - // from: userChecksum, - // }) + const data = stakingContract.interface.encodeFunctionData('stake(uint256,address)', [ + this.normalizeAmount(amountDesired), + userAddress, + ]) const { nonce, gasPrice } = await this.getGasPriceAndNonce(userAddress) const chainReferenceAsNumber = Number(this.ethereumChainReference) From c7fea943986b604217c9b8cc4ede077656e13fd5 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 8 Dec 2022 14:45:59 -0700 Subject: [PATCH 15/17] feat: explicit normalizeAmount return value --- packages/investor-foxy/src/api/api.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 14e22f960..41de0fad9 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -117,7 +117,7 @@ export class FoxyApi { * to exponential notation ('1.6e+21') in javascript. * @param amount */ - private normalizeAmount(amount: BigNumber) { + private normalizeAmount(amount: BigNumber): ethers.BigNumber { return ethers.BigNumber.from(amount.toFixed()) } From a1ff69f27dc83748d0fb22ff31b76db71d7aa871 Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 8 Dec 2022 14:47:49 -0700 Subject: [PATCH 16/17] feat: in-place toString() --- packages/investor-foxy/src/api/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 41de0fad9..2b32a9f60 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -182,7 +182,7 @@ export class FoxyApi { ): Promise<{ nonce: string; gasPrice: string }> { let nonce try { - nonce = await this.provider.getTransactionCount(userAddress) + nonce = (await this.provider.getTransactionCount(userAddress)).toString() } catch (e) { throw new Error(`Get nonce Error: ${e}`) } @@ -192,7 +192,7 @@ export class FoxyApi { } catch (e) { throw new Error(`Get gasPrice Error: ${e}`) } - return { nonce: nonce.toString(), gasPrice } + return { nonce, gasPrice } } async getFoxyOpportunities() { From 7a6937848e26efdbf9f63a7f4340d63383bd758a Mon Sep 17 00:00:00 2001 From: gomes <17035424+gomesalexandre@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:08:41 -0700 Subject: [PATCH 17/17] feat: cleanup --- packages/investor-foxy/package.json | 4 ++-- packages/investor-foxy/src/api/api.ts | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/investor-foxy/package.json b/packages/investor-foxy/package.json index 388f7ef6b..6305eaa94 100644 --- a/packages/investor-foxy/package.json +++ b/packages/investor-foxy/package.json @@ -38,13 +38,13 @@ }, "peerDependencies": { "@shapeshiftoss/caip": "^8.0.0", - "@shapeshiftoss/chain-adapters": "^10.0.0", + "@shapeshiftoss/chain-adapters": "^10.5.0", "@shapeshiftoss/hdwallet-core": "^1.36.0", "@shapeshiftoss/types": "^8.1.0" }, "devDependencies": { "@shapeshiftoss/caip": "^8.0.0", - "@shapeshiftoss/chain-adapters": "^10.0.0", + "@shapeshiftoss/chain-adapters": "^10.5.0", "@shapeshiftoss/hdwallet-core": "^1.36.0", "@shapeshiftoss/types": "^8.1.0", "@shapeshiftoss/unchained-client": "^10.0.1" diff --git a/packages/investor-foxy/src/api/api.ts b/packages/investor-foxy/src/api/api.ts index 2b32a9f60..05558b214 100644 --- a/packages/investor-foxy/src/api/api.ts +++ b/packages/investor-foxy/src/api/api.ts @@ -455,7 +455,6 @@ export class FoxyApi { } const stakingContract = this.getStakingContract(contractAddress) - // const userChecksum = ethers.utils.getAddress(userAddress) const data = stakingContract.interface.encodeFunctionData('stake(uint256,address)', [ this.normalizeAmount(amountDesired),