diff --git a/README.md b/README.md index 67f36ec4..ce05be9d 100644 --- a/README.md +++ b/README.md @@ -129,9 +129,32 @@ export interface CloneUniswapContractDetails { v3Override?: CloneUniswapContractDetailsV3 | undefined; } +export interface Token { + chainId: ChainId; + contractAddress: string; + decimals: number; + symbol: string; + name: string; +} + +export interface NativeCurrencyInfo { + name: string; + symbol: string; +} + export interface CustomNetwork { nameNetwork: string; multicallContractAddress: string; + nativeCurrency: NativeCurrencyInfo; + nativeWrappedTokenInfo: Token; + // defined your base tokens here! + baseTokens?: { + usdt?: Token | undefined; + dai?: Token | undefined; + comp?: Token | undefined; + usdc?: Token | undefined; + wbtc?: Token | undefined; + }; } export class UniswapPairSettings { @@ -182,9 +205,9 @@ export class UniswapPairSettings { } ``` -### Ethereum provider +### With only the chainId -This will use your ethereum provider you pass in. This will work with any web3 provider, ethers provider or custom provider. For example when using MetaMask you can pass in the window.ethereum and it work. You must supply the ethereum address and the wallet be approved to use for the dApp and unlocked before passing it in. The uniswap sdk makes those assumptions without them it will not work as MetaMask is not allowed access to your dApp. Any change of network or ethereum address change you will need to handle in your dApp and regenerate the uniswap pair context. Most the time the contract addresses for your tokens are different anyway. +This will use a infura endpoint without you having to pass in a node ```ts import { UniswapPair, ChainId, UniswapVersion, ETH } from 'simple-uniswap-sdk'; @@ -196,7 +219,7 @@ const uniswapPair = new UniswapPair({ toTokenContractAddress: '0x1985365e9f78359a9B6AD760e32412f4a445E862', // the ethereum address of the user using this part of the dApp ethereumAddress: '0xB1E6079212888f0bE0cf55874B2EB9d7a5e02cD9', - ethereumProvider: YOUR_WEB3_ETHERS_OR_CUSTOM_ETHEREUM_PROVIDER, + chainId: ChainId.MAINNET, settings: new UniswapPairSettings({ // if not supplied it will use `0.005` which is 0.5% // please pass it in as a full number decimal so 0.7% @@ -219,9 +242,9 @@ const uniswapPair = new UniswapPair({ const uniswapPairFactory = await uniswapPair.createFactory(); ``` -### With only the chainId +### With your own provider url -This will use a infura endpoint without you having to pass in a node +This will use your node you pass in you must pass us the chainId as well, this stops the ethers instance calling pointless `JSONRPC` calls to get the chain id before every `JSONRPC` call. ```ts import { UniswapPair, ChainId, UniswapVersion, ETH } from 'simple-uniswap-sdk'; @@ -234,6 +257,7 @@ const uniswapPair = new UniswapPair({ // the ethereum address of the user using this part of the dApp ethereumAddress: '0xB1E6079212888f0bE0cf55874B2EB9d7a5e02cD9', chainId: ChainId.MAINNET, + providerUrl: YOUR_PROVIDER_URL, settings: new UniswapPairSettings({ // if not supplied it will use `0.005` which is 0.5% // please pass it in as a full number decimal so 0.7% @@ -256,9 +280,9 @@ const uniswapPair = new UniswapPair({ const uniswapPairFactory = await uniswapPair.createFactory(); ``` -### With your own provider url +### Custom Ethereum provider -This will use your node you pass in you must pass us the chainId as well, this stops the ethers instance calling pointless `JSONRPC` calls to get the chain id before every `JSONRPC` call. +This will use your ethereum provider you pass in. This will work with any web3 provider, ethers provider or custom provider. For example when using MetaMask you can pass in the window.ethereum and it work. You must supply the ethereum address and the wallet be approved to use for the dApp and unlocked before passing it in. The uniswap sdk makes those assumptions without them it will not work as MetaMask is not allowed access to your dApp. Any change of network or ethereum address change you will need to handle in your dApp and regenerate the uniswap pair context. Most the time the contract addresses for your tokens are different anyway. ```ts import { UniswapPair, ChainId, UniswapVersion, ETH } from 'simple-uniswap-sdk'; @@ -270,8 +294,7 @@ const uniswapPair = new UniswapPair({ toTokenContractAddress: '0x1985365e9f78359a9B6AD760e32412f4a445E862', // the ethereum address of the user using this part of the dApp ethereumAddress: '0xB1E6079212888f0bE0cf55874B2EB9d7a5e02cD9', - chainId: ChainId.MAINNET, - providerUrl: YOUR_PROVIDER_URL, + ethereumProvider: YOUR_WEB3_ETHERS_OR_CUSTOM_ETHEREUM_PROVIDER, settings: new UniswapPairSettings({ // if not supplied it will use `0.005` which is 0.5% // please pass it in as a full number decimal so 0.7% diff --git a/src/common/tokens/eth.ts b/src/common/tokens/eth.ts index 10495fa5..4c5baac8 100644 --- a/src/common/tokens/eth.ts +++ b/src/common/tokens/eth.ts @@ -1,4 +1,5 @@ import { ChainId } from '../../enums/chain-id'; +import { NativeCurrencyInfo } from '../../factories/pair/models/custom-network'; import { Token } from '../../factories/token/models/token'; import { ErrorCodes } from '../errors/error-codes'; import { UniswapError } from '../errors/uniswap-error'; @@ -24,12 +25,20 @@ export const isNativeEth = (contractAddress: string): boolean => { return contractAddress.includes(ETH_PREFIX); }; -export const turnTokenIntoEthForResponse = (token: Token): Token => { +export const turnTokenIntoEthForResponse = ( + token: Token, + nativeCurrencyInfo: NativeCurrencyInfo | undefined +): Token => { const clone = deepClone(token); // clear down contract address clone.contractAddress = 'NO_CONTRACT_ADDRESS'; - clone.symbol = ETH_SYMBOL; - clone.name = ETH_NAME; + if (nativeCurrencyInfo) { + clone.symbol = nativeCurrencyInfo.symbol; + clone.name = nativeCurrencyInfo.name; + } else { + clone.symbol = ETH_SYMBOL; + clone.name = ETH_NAME; + } return clone; }; @@ -102,7 +111,18 @@ export class ETH { * Get ETH token info by chain id * @param chainId The chain id */ - public static info(chainId: ChainId | number): Token { + public static info( + chainId: ChainId | number, + customNetworkNativeWrappedTokenInfo: Token | undefined = undefined + ): Token { + if (customNetworkNativeWrappedTokenInfo) { + return { + ...customNetworkNativeWrappedTokenInfo, + contractAddress: appendEthToContractAddress( + customNetworkNativeWrappedTokenInfo.contractAddress + ), + }; + } switch (chainId) { case ChainId.MAINNET: return this.MAINNET(); diff --git a/src/common/utils/trade-path.ts b/src/common/utils/trade-path.ts index 346ddbdf..ca401b41 100644 --- a/src/common/utils/trade-path.ts +++ b/src/common/utils/trade-path.ts @@ -6,13 +6,20 @@ import { ETH } from '../tokens/eth'; export function getTradePath( chainId: ChainId, fromToken: Token, - toToken: Token + toToken: Token, + customNetworkNativeWrappedTokenInfo: Token | undefined ): TradePath { - if (fromToken.contractAddress === ETH.info(chainId).contractAddress) { + if ( + fromToken.contractAddress === + ETH.info(chainId, customNetworkNativeWrappedTokenInfo).contractAddress + ) { return TradePath.ethToErc20; } - if (toToken.contractAddress === ETH.info(chainId).contractAddress) { + if ( + toToken.contractAddress === + ETH.info(chainId, customNetworkNativeWrappedTokenInfo).contractAddress + ) { return TradePath.erc20ToEth; } diff --git a/src/factories/pair/models/custom-network.ts b/src/factories/pair/models/custom-network.ts index 4c12b814..cdc70980 100644 --- a/src/factories/pair/models/custom-network.ts +++ b/src/factories/pair/models/custom-network.ts @@ -1,4 +1,21 @@ +import { Token } from '../../token/models/token'; + +export interface NativeCurrencyInfo { + name: string; + symbol: string; +} + export interface CustomNetwork { nameNetwork: string; multicallContractAddress: string; + nativeCurrency: NativeCurrencyInfo; + nativeWrappedTokenInfo: Token; + // defined your base tokens here! + baseTokens?: { + usdt?: Token | undefined; + dai?: Token | undefined; + comp?: Token | undefined; + usdc?: Token | undefined; + wbtc?: Token | undefined; + }; } diff --git a/src/factories/pair/uniswap-pair.factory.ts b/src/factories/pair/uniswap-pair.factory.ts index ccf5d265..ab8f32e4 100644 --- a/src/factories/pair/uniswap-pair.factory.ts +++ b/src/factories/pair/uniswap-pair.factory.ts @@ -30,14 +30,14 @@ export class UniswapPairFactory { private _fromTokenFactory = new TokenFactory( this._uniswapPairFactoryContext.fromToken.contractAddress, this._uniswapPairFactoryContext.ethersProvider, - this._uniswapPairFactoryContext.settings.customNetwork?.multicallContractAddress, + this._uniswapPairFactoryContext.settings.customNetwork, this._uniswapPairFactoryContext.settings.cloneUniswapContractDetails ); private _toTokenFactory = new TokenFactory( this._uniswapPairFactoryContext.toToken.contractAddress, this._uniswapPairFactoryContext.ethersProvider, - this._uniswapPairFactoryContext.settings.customNetwork?.multicallContractAddress + this._uniswapPairFactoryContext.settings.customNetwork ); private _uniswapRouterFactory = new UniswapRouterFactory( @@ -354,7 +354,10 @@ export class UniswapPairFactory { bestRouteQuote.uniswapVersion ) : undefined, - toToken: turnTokenIntoEthForResponse(this.toToken), + toToken: turnTokenIntoEthForResponse( + this.toToken, + this._uniswapPairFactoryContext.settings?.customNetwork?.nativeCurrency + ), toBalance: new BigNumber(bestRouteQuotes.toBalance) .shiftedBy(this.toToken.decimals * -1) .toFixed(), @@ -487,7 +490,10 @@ export class UniswapPairFactory { toBalance: new BigNumber(bestRouteQuotes.toBalance) .shiftedBy(this.toToken.decimals * -1) .toFixed(), - fromToken: turnTokenIntoEthForResponse(this.fromToken), + fromToken: turnTokenIntoEthForResponse( + this.fromToken, + this._uniswapPairFactoryContext.settings?.customNetwork?.nativeCurrency + ), fromBalance: { hasEnough: bestRouteQuotes.hasEnoughBalance, balance: bestRouteQuotes.fromBalance, @@ -507,7 +513,13 @@ export class UniswapPairFactory { */ private tradePath(): TradePath { const network = this._uniswapPairFactoryContext.ethersProvider.network(); - return getTradePath(network.chainId, this.fromToken, this.toToken); + return getTradePath( + network.chainId, + this.fromToken, + this.toToken, + this._uniswapPairFactoryContext.settings.customNetwork + ?.nativeWrappedTokenInfo + ); } /** diff --git a/src/factories/pair/uniswap-pair.ts b/src/factories/pair/uniswap-pair.ts index 328c0937..7c68d2e2 100644 --- a/src/factories/pair/uniswap-pair.ts +++ b/src/factories/pair/uniswap-pair.ts @@ -141,7 +141,7 @@ export class UniswapPair { const tokensFactory = new TokensFactory( this._ethersProvider, - this._uniswapPairContext.settings?.customNetwork?.multicallContractAddress + this._uniswapPairContext.settings?.customNetwork ); const tokens = await tokensFactory.getTokens([ this._uniswapPairContext.fromTokenContractAddress, diff --git a/src/factories/router/uniswap-router.factory.ts b/src/factories/router/uniswap-router.factory.ts index 7f4396b0..21b9e3bd 100644 --- a/src/factories/router/uniswap-router.factory.ts +++ b/src/factories/router/uniswap-router.factory.ts @@ -82,7 +82,7 @@ export class UniswapRouterFactory { private _tokensFactory = new TokensFactory( this._ethersProvider, - this._settings.customNetwork?.multicallContractAddress, + this._settings.customNetwork, this._settings.cloneUniswapContractDetails ); @@ -1703,7 +1703,10 @@ export class UniswapRouterFactory { this.allTokens.find((t) => t.contractAddress === c)! ); if (index === 0) { - return turnTokenIntoEthForResponse(token); + return turnTokenIntoEthForResponse( + token, + this._settings?.customNetwork?.nativeCurrency + ); } return token; @@ -1731,11 +1734,17 @@ export class UniswapRouterFactory { transaction, tradeExpires, routePathArrayTokenMap: [ - turnTokenIntoEthForResponse(this._fromToken), + turnTokenIntoEthForResponse( + this._fromToken, + this._settings?.customNetwork?.nativeCurrency + ), this._toToken, ], routeText: `${ - turnTokenIntoEthForResponse(this._fromToken).symbol + turnTokenIntoEthForResponse( + this._fromToken, + this._settings?.customNetwork?.nativeCurrency + ).symbol } > ${this._toToken.symbol}`, routePathArray: [ this._fromToken.contractAddress, @@ -1822,7 +1831,10 @@ export class UniswapRouterFactory { this.allTokens.find((t) => t.contractAddress === c)! ); if (index === callReturnContext.methodParameters[1].length - 1) { - return turnTokenIntoEthForResponse(token); + return turnTokenIntoEthForResponse( + token, + this._settings?.customNetwork?.nativeCurrency + ); } return token; @@ -1851,10 +1863,16 @@ export class UniswapRouterFactory { tradeExpires, routePathArrayTokenMap: [ this._fromToken, - turnTokenIntoEthForResponse(this._toToken), + turnTokenIntoEthForResponse( + this._toToken, + this._settings?.customNetwork?.nativeCurrency + ), ], routeText: `${this._fromToken.symbol} > ${ - turnTokenIntoEthForResponse(this._toToken).symbol + turnTokenIntoEthForResponse( + this._toToken, + this._settings?.customNetwork?.nativeCurrency + ).symbol }`, routePathArray: [ this._fromToken.contractAddress, @@ -1977,7 +1995,12 @@ export class UniswapRouterFactory { */ private tradePath(): TradePath { const network = this._ethersProvider.network(); - return getTradePath(network.chainId, this._fromToken, this._toToken); + return getTradePath( + network.chainId, + this._fromToken, + this._toToken, + this._settings.customNetwork?.nativeWrappedTokenInfo + ); } private get allTokens(): Token[] { @@ -1986,7 +2009,7 @@ export class UniswapRouterFactory { private get allMainTokens(): Token[] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - return [ + const tokens: (Token | undefined)[] = [ this.USDTTokenForConnectedNetwork, this.COMPTokenForConnectedNetwork, this.USDCTokenForConnectedNetwork, @@ -1994,6 +2017,8 @@ export class UniswapRouterFactory { this.WETHTokenForConnectedNetwork, this.WBTCTokenForConnectedNetwork, ]; + + return tokens.filter((t) => t !== undefined) as Token[]; } return [this.WETHTokenForConnectedNetwork]; @@ -2016,7 +2041,9 @@ export class UniswapRouterFactory { pairs.push([this._fromToken, this.WETHTokenForConnectedNetwork]); } - return pairs.filter((t) => t[0].contractAddress !== t[1].contractAddress); + return this.filterUndefinedTokens(pairs).filter( + (t) => t[0].contractAddress !== t[1].contractAddress + ); } const pairs = [[this._fromToken, this.WETHTokenForConnectedNetwork]]; @@ -2025,7 +2052,7 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForToToken(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - const pairs: Token[][] = [ + const pairs: (Token | undefined)[][] = [ [this.USDTTokenForConnectedNetwork, this._toToken], [this.COMPTokenForConnectedNetwork, this._toToken], [this.USDCTokenForConnectedNetwork, this._toToken], @@ -2040,7 +2067,9 @@ export class UniswapRouterFactory { pairs.push([this.WETHTokenForConnectedNetwork, this._toToken]); } - return pairs.filter((t) => t[0].contractAddress !== t[1].contractAddress); + return this.filterUndefinedTokens(pairs).filter( + (t) => t[0].contractAddress !== t[1].contractAddress + ); } const pairs: Token[][] = [ @@ -2052,7 +2081,7 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForUSDT(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - const pairs: Token[][] = [ + const pairs: (Token | undefined)[][] = [ [this.USDTTokenForConnectedNetwork, this.COMPTokenForConnectedNetwork], [this.USDTTokenForConnectedNetwork, this.DAITokenForConnectedNetwork], [this.USDTTokenForConnectedNetwork, this.USDCTokenForConnectedNetwork], @@ -2069,7 +2098,7 @@ export class UniswapRouterFactory { ]); } - return pairs; + return this.filterUndefinedTokens(pairs); } return []; @@ -2077,7 +2106,7 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForCOMP(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - const pairs: Token[][] = [ + const pairs: (Token | undefined)[][] = [ [this.COMPTokenForConnectedNetwork, this.USDTTokenForConnectedNetwork], [this.COMPTokenForConnectedNetwork, this.DAITokenForConnectedNetwork], [this.COMPTokenForConnectedNetwork, this.USDCTokenForConnectedNetwork], @@ -2093,7 +2122,7 @@ export class UniswapRouterFactory { ]); } - return pairs; + return this.filterUndefinedTokens(pairs); } return []; @@ -2101,7 +2130,7 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForDAI(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - const pairs: Token[][] = [ + const pairs: (Token | undefined)[][] = [ [this.DAITokenForConnectedNetwork, this.COMPTokenForConnectedNetwork], [this.DAITokenForConnectedNetwork, this.WBTCTokenForConnectedNetwork], [this.DAITokenForConnectedNetwork, this.USDTTokenForConnectedNetwork], @@ -2118,7 +2147,7 @@ export class UniswapRouterFactory { ]); } - return pairs; + return this.filterUndefinedTokens(pairs); } return []; @@ -2126,7 +2155,7 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForUSDC(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - const pairs: Token[][] = [ + const pairs: (Token | undefined)[][] = [ [this.USDCTokenForConnectedNetwork, this.USDTTokenForConnectedNetwork], [this.USDCTokenForConnectedNetwork, this.COMPTokenForConnectedNetwork], [this.USDCTokenForConnectedNetwork, this.DAITokenForConnectedNetwork], @@ -2143,7 +2172,7 @@ export class UniswapRouterFactory { ]); } - return pairs; + return this.filterUndefinedTokens(pairs); } return []; @@ -2151,12 +2180,14 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForWBTC(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - return [ + const tokens: (Token | undefined)[][] = [ [this.WBTCTokenForConnectedNetwork, this.USDTTokenForConnectedNetwork], [this.WBTCTokenForConnectedNetwork, this.DAITokenForConnectedNetwork], [this.WBTCTokenForConnectedNetwork, this.USDCTokenForConnectedNetwork], [this.WBTCTokenForConnectedNetwork, this.WETHTokenForConnectedNetwork], ]; + + return this.filterUndefinedTokens(tokens); } return []; @@ -2164,39 +2195,71 @@ export class UniswapRouterFactory { private get mainCurrenciesPairsForWETH(): Token[][] { if (this._ethersProvider.provider.network.chainId === ChainId.MAINNET) { - return [ + const tokens: (Token | undefined)[][] = [ [this.WETHTokenForConnectedNetwork, this.USDTTokenForConnectedNetwork], [this.WETHTokenForConnectedNetwork, this.COMPTokenForConnectedNetwork], [this.WETHTokenForConnectedNetwork, this.DAITokenForConnectedNetwork], [this.WETHTokenForConnectedNetwork, this.USDCTokenForConnectedNetwork], [this.WETHTokenForConnectedNetwork, this.WBTCTokenForConnectedNetwork], ]; + + return this.filterUndefinedTokens(tokens); } return []; } + private filterUndefinedTokens(tokens: (Token | undefined)[][]): Token[][] { + return tokens.filter( + (t) => t[0] !== undefined && t[1] !== undefined + ) as Token[][]; + } + private get USDTTokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.baseTokens?.usdt; + } + return USDT.token(this._ethersProvider.provider.network.chainId); } private get COMPTokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.baseTokens?.comp; + } + return COMP.token(this._ethersProvider.provider.network.chainId); } private get DAITokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.baseTokens?.dai; + } + return DAI.token(this._ethersProvider.provider.network.chainId); } private get USDCTokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.baseTokens?.usdc; + } + return USDC.token(this._ethersProvider.provider.network.chainId); } private get WETHTokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.nativeWrappedTokenInfo; + } + return WETHContract.token(this._ethersProvider.provider.network.chainId); } private get WBTCTokenForConnectedNetwork() { + if (this._settings.customNetwork) { + return this._settings.customNetwork.baseTokens?.wbtc; + } + return WBTC.token(this._ethersProvider.provider.network.chainId); } } diff --git a/src/factories/token/token.factory.ts b/src/factories/token/token.factory.ts index 77069ca3..6032a2cf 100644 --- a/src/factories/token/token.factory.ts +++ b/src/factories/token/token.factory.ts @@ -10,13 +10,14 @@ import { UniswapVersion } from '../../enums/uniswap-version'; import { EthersProvider } from '../../ethers-provider'; import { uniswapContracts } from '../../uniswap-contract-context/get-uniswap-contracts'; import { CloneUniswapContractDetails } from '../pair/models/clone-uniswap-contract-details'; +import { CustomNetwork } from '../pair/models/custom-network'; import { AllowanceAndBalanceOf } from './models/allowance-balance-of'; import { Token } from './models/token'; export class TokenFactory { private _multicall = new CustomMulticall( this._ethersProvider.provider, - this._customNetworkMulticallContractAddress + this._customNetwork?.multicallContractAddress ); private _erc20TokenContract = @@ -28,7 +29,7 @@ export class TokenFactory { constructor( private _tokenContractAddress: string, private _ethersProvider: EthersProvider, - private _customNetworkMulticallContractAddress?: string | undefined, + private _customNetwork?: CustomNetwork | undefined, private _cloneUniswapContractDetails?: | CloneUniswapContractDetails | undefined @@ -39,7 +40,10 @@ export class TokenFactory { */ public async getToken(): Promise { if (isNativeEth(this._tokenContractAddress)) { - return ETH.info(this._ethersProvider.network().chainId); + return ETH.info( + this._ethersProvider.network().chainId, + this._customNetwork?.nativeWrappedTokenInfo + ); } else { const overridenToken = isTokenOverrideInfo(this._tokenContractAddress); if (overridenToken) { diff --git a/src/factories/token/tokens.factory.ts b/src/factories/token/tokens.factory.ts index 19bb1e9e..ddbf3bfb 100644 --- a/src/factories/token/tokens.factory.ts +++ b/src/factories/token/tokens.factory.ts @@ -12,18 +12,19 @@ import { UniswapVersion } from '../../enums/uniswap-version'; import { EthersProvider } from '../../ethers-provider'; import { uniswapContracts } from '../../uniswap-contract-context/get-uniswap-contracts'; import { CloneUniswapContractDetails } from '../pair/models/clone-uniswap-contract-details'; +import { CustomNetwork } from '../pair/models/custom-network'; import { Token } from './models/token'; import { TokenWithAllowanceInfo } from './models/token-with-allowance-info'; export class TokensFactory { private _multicall = new CustomMulticall( this._ethersProvider.provider, - this._customNetworkMulticallContractAddress + this._customNetwork?.multicallContractAddress ); constructor( private _ethersProvider: EthersProvider, - private _customNetworkMulticallContractAddress?: string | undefined, + private _customNetwork?: CustomNetwork | undefined, private _cloneUniswapContractDetails?: | CloneUniswapContractDetails | undefined @@ -74,7 +75,12 @@ export class TokensFactory { contractCallContexts.push(contractCallContext); } else { - tokens.push(ETH.info(this._ethersProvider.network().chainId)); + tokens.push( + ETH.info( + this._ethersProvider.network().chainId, + this._customNetwork?.nativeWrappedTokenInfo + ) + ); } } @@ -142,7 +148,11 @@ export class TokensFactory { ) ); } else { - const token = ETH.info(this._ethersProvider.network().chainId); + const token = ETH.info( + this._ethersProvider.network().chainId, + this._customNetwork?.nativeWrappedTokenInfo + ); + if (format) { results.push({ allowanceAndBalanceOf: { @@ -173,7 +183,10 @@ export class TokensFactory { '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', balanceOf: await this._ethersProvider.balanceOf(ethereumAddress), }, - token: ETH.info(this._ethersProvider.network().chainId), + token: ETH.info( + this._ethersProvider.network().chainId, + this._customNetwork?.nativeWrappedTokenInfo + ), }); } }