diff --git a/src/chains/ethereum/ethereum-base.ts b/src/chains/ethereum/ethereum-base.ts index 64aefbe3a8..55101b30ce 100644 --- a/src/chains/ethereum/ethereum-base.ts +++ b/src/chains/ethereum/ethereum-base.ts @@ -18,6 +18,7 @@ import fse from 'fs-extra'; import { ConfigManagerCertPassphrase } from '../../services/config-manager-cert-passphrase'; import { logger } from '../../services/logger'; import { ReferenceCountingCloseable } from '../../services/refcounting-closeable'; +import { getAddress } from 'ethers/lib/utils'; // information about an Ethereum token export interface TokenInfo { @@ -153,7 +154,7 @@ export class EthereumBase { tokenListSource: string, tokenListType: TokenListType ): Promise { - let tokens; + let tokens: TokenInfo[]; if (tokenListType === 'URL') { ({ data: { tokens }, @@ -161,7 +162,11 @@ export class EthereumBase { } else { ({ tokens } = JSON.parse(await fs.readFile(tokenListSource, 'utf8'))); } - return tokens; + const mappedTokens: TokenInfo[] = tokens.map((token) => { + token.address = getAddress(token.address); + return token; + }); + return mappedTokens; } public get nonceManager() { diff --git a/src/connectors/defikingdoms/defikingdoms.ts b/src/connectors/defikingdoms/defikingdoms.ts index a1d2460b07..2e8e1059dc 100644 --- a/src/connectors/defikingdoms/defikingdoms.ts +++ b/src/connectors/defikingdoms/defikingdoms.ts @@ -24,6 +24,7 @@ import { percentRegexp } from '../../services/config-manager-v2'; // import { Ethereum } from '../../chains/ethereum/ethereum'; import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces'; import { Harmony } from '../../chains/harmony/harmony'; +import { getAddress } from 'ethers/lib/utils'; export class Defikingdoms implements Uniswapish { private static _instances: { [name: string]: Defikingdoms }; @@ -65,7 +66,7 @@ export class Defikingdoms implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/defira/defira.ts b/src/connectors/defira/defira.ts index a179310fcb..c91a3472dd 100644 --- a/src/connectors/defira/defira.ts +++ b/src/connectors/defira/defira.ts @@ -21,6 +21,7 @@ import { logger } from '../../services/logger'; import { percentRegexp } from '../../services/config-manager-v2'; import { Harmony } from '../../chains/harmony/harmony'; import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces'; +import { getAddress } from 'ethers/lib/utils'; export class Defira implements Uniswapish { private static _instances: { [name: string]: Defira }; @@ -65,7 +66,7 @@ export class Defira implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/openocean/openocean.ts b/src/connectors/openocean/openocean.ts index b090df3d2e..a151c2dd88 100644 --- a/src/connectors/openocean/openocean.ts +++ b/src/connectors/openocean/openocean.ts @@ -28,6 +28,7 @@ import { UNKNOWN_ERROR_ERROR_CODE, UNKNOWN_ERROR_MESSAGE, } from '../../services/error-handler'; +import { getAddress } from 'ethers/lib/utils'; export function newFakeTrade( tokenIn: Token, @@ -110,7 +111,7 @@ export class Openocean implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/pancakeswap/pancakeswap.ts b/src/connectors/pancakeswap/pancakeswap.ts index 9296dad496..0ea4ab6242 100644 --- a/src/connectors/pancakeswap/pancakeswap.ts +++ b/src/connectors/pancakeswap/pancakeswap.ts @@ -29,6 +29,7 @@ import { logger } from '../../services/logger'; import { isFractionString } from '../../services/validators'; import { PancakeSwapConfig } from './pancakeswap.config'; import routerAbi from './pancakeswap_router_abi.json'; +import { getAddress } from 'ethers/lib/utils'; export class PancakeSwap implements Uniswapish { private static _instances: { [name: string]: PancakeSwap }; @@ -91,7 +92,7 @@ export class PancakeSwap implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } /** diff --git a/src/connectors/pangolin/pangolin.ts b/src/connectors/pangolin/pangolin.ts index bc0a149e42..7528435185 100644 --- a/src/connectors/pangolin/pangolin.ts +++ b/src/connectors/pangolin/pangolin.ts @@ -23,6 +23,7 @@ import { import { logger } from '../../services/logger'; import { Avalanche } from '../../chains/avalanche/avalanche'; import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces'; +import { getAddress } from 'ethers/lib/utils'; export class Pangolin implements Uniswapish { private static _instances: { [name: string]: Pangolin }; @@ -63,7 +64,7 @@ export class Pangolin implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/perp/perp.ts b/src/connectors/perp/perp.ts index 0590673c52..8a3c74e5d6 100644 --- a/src/connectors/perp/perp.ts +++ b/src/connectors/perp/perp.ts @@ -23,6 +23,7 @@ import { logger } from '../../services/logger'; import { percentRegexp } from '../../services/config-manager-v2'; import { Ethereum } from '../../chains/ethereum/ethereum'; import { Perpish } from '../../services/common-interfaces'; +import { getAddress } from 'ethers/lib/utils'; export interface PerpPosition { positionAmt: string; @@ -88,7 +89,7 @@ export class Perp implements Perpish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/quickswap/quickswap.ts b/src/connectors/quickswap/quickswap.ts index c58b4d3708..fff24ad3b4 100644 --- a/src/connectors/quickswap/quickswap.ts +++ b/src/connectors/quickswap/quickswap.ts @@ -22,6 +22,7 @@ import { import { logger } from '../../services/logger'; import { Polygon } from '../../chains/polygon/polygon'; import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces'; +import { getAddress } from 'ethers/lib/utils'; export class Quickswap implements Uniswapish { private static _instances: { [name: string]: Quickswap }; @@ -62,7 +63,7 @@ export class Quickswap implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/sushiswap/sushiswap.ts b/src/connectors/sushiswap/sushiswap.ts index 444264d657..110f2bada2 100644 --- a/src/connectors/sushiswap/sushiswap.ts +++ b/src/connectors/sushiswap/sushiswap.ts @@ -31,6 +31,7 @@ import { } from 'ethers'; import { percentRegexp } from '../../services/config-manager-v2'; import { logger } from '../../services/logger'; +import { getAddress } from 'ethers/lib/utils'; export class Sushiswap implements Uniswapish { private static _instances: { [name: string]: Sushiswap }; @@ -83,7 +84,7 @@ export class Sushiswap implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/traderjoe/traderjoe.ts b/src/connectors/traderjoe/traderjoe.ts index 45567697e0..fbec8ace3b 100644 --- a/src/connectors/traderjoe/traderjoe.ts +++ b/src/connectors/traderjoe/traderjoe.ts @@ -22,6 +22,7 @@ import { import { EVMTxBroadcaster } from '../../chains/ethereum/evm.broadcaster'; import { createPublicClient, http } from 'viem'; import { avalanche, avalancheFuji } from 'viem/chains'; +import { getAddress } from 'ethers/lib/utils'; const MAX_HOPS = 2; const BASES = ['USDT', 'USDC', 'WAVAX']; @@ -71,7 +72,7 @@ export class Traderjoe implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/uniswap/uniswap.lp.helper.ts b/src/connectors/uniswap/uniswap.lp.helper.ts index 670288292f..00fe102995 100644 --- a/src/connectors/uniswap/uniswap.lp.helper.ts +++ b/src/connectors/uniswap/uniswap.lp.helper.ts @@ -18,6 +18,7 @@ import { ReduceLiquidityData, } from './uniswap.lp.interfaces'; import * as math from 'mathjs'; +import { getAddress } from 'ethers/lib/utils'; export class UniswapLPHelper { protected ethereum: Ethereum; @@ -96,7 +97,7 @@ export class UniswapLPHelper { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address.toLowerCase()]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/uniswap/uniswap.ts b/src/connectors/uniswap/uniswap.ts index 873cdc0469..4501f489fc 100644 --- a/src/connectors/uniswap/uniswap.ts +++ b/src/connectors/uniswap/uniswap.ts @@ -39,6 +39,7 @@ import { percentRegexp } from '../../services/config-manager-v2'; import { Ethereum } from '../../chains/ethereum/ethereum'; import { Polygon } from '../../chains/polygon/polygon'; import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces'; +import { getAddress } from 'ethers/lib/utils'; export class Uniswap implements Uniswapish { private static _instances: { [name: string]: Uniswap }; @@ -107,7 +108,7 @@ export class Uniswap implements Uniswapish { * @param address Token address */ public getTokenByAddress(address: string): Token { - return this.tokenList[address]; + return this.tokenList[getAddress(address)]; } public async init() { diff --git a/src/connectors/zigzag/zigzag.ts b/src/connectors/zigzag/zigzag.ts index b45595a640..df05ccc5ce 100644 --- a/src/connectors/zigzag/zigzag.ts +++ b/src/connectors/zigzag/zigzag.ts @@ -10,6 +10,7 @@ import { ZigZagish } from '../../services/common-interfaces'; import { logger } from '../../services/logger'; import { EVMTxBroadcaster } from '../../chains/ethereum/evm.broadcaster'; import { abi } from './zigzag.exchange.abi.json'; +import { getAddress } from 'ethers/lib/utils'; // https://api.arbitrum.zigzag.exchange/v1/info @@ -121,7 +122,7 @@ export class ZigZag implements ZigZagish { // } public getTokenByAddress(address: string): Token { - return this.tokenList[address.toLowerCase()]; + return this.tokenList[getAddress(address)]; } public async init() { @@ -132,21 +133,19 @@ export class ZigZag implements ZigZagish { if (response.status === 200) { const zigZagData: ZigZagInfo = response.data; for (const token of zigZagData.verifiedTokens) { - this.tokenList[token.address.toLowerCase()] = new Token( + this.tokenList[getAddress(token.address)] = new Token( this._chain.chainId, - token.address.toLowerCase(), + getAddress(token.address), token.decimals, token.symbol, token.name ); } for (const market of zigZagData.markets) { - const base = this.tokenList[market.buyToken]; - const quote = this.tokenList[market.sellToken]; + const base = this.getTokenByAddress(market.buyToken); + const quote = this.getTokenByAddress(market.sellToken); // this.markets.push(base.symbol + '-' + quote.symbol); - this.markets.push( - base.address.toLowerCase() + '-' + quote.address.toLowerCase() - ); + this.markets.push(base.address + '-' + quote.address); } } @@ -284,8 +283,8 @@ export class ZigZag implements ZigZagish { const quoteBuyAmount = ethers.BigNumber.from(order.buyAmount); if (side === 'buy' && quoteSellAmount.lt(stepBuyAmount)) return; - const quoteSellToken = this.tokenList[order.sellToken]; - const quoteBuyToken = this.tokenList[order.buyToken]; + const quoteSellToken = this.getTokenByAddress(order.sellToken); + const quoteBuyToken = this.getTokenByAddress(order.buyToken); if (!quoteSellToken || !quoteBuyToken) return; const quoteSellAmountFormated = Number(