Skip to content

Commit

Permalink
Merge pull request #169 from vic-en/fix/uniswap_token_address
Browse files Browse the repository at this point in the history
Fix/uniswap token address
  • Loading branch information
fengtality committed Jul 25, 2023
2 parents 8ffb349 + 0ea5f8c commit d272192
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 12 deletions.
9 changes: 7 additions & 2 deletions src/chains/ethereum/ethereum-base.ts
Expand Up @@ -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 {
Expand Down Expand Up @@ -153,15 +154,19 @@ export class EthereumBase {
tokenListSource: string,
tokenListType: TokenListType
): Promise<TokenInfo[]> {
let tokens;
let tokens: TokenInfo[];
if (tokenListType === 'URL') {
({
data: { tokens },
} = await axios.get(tokenListSource));
} 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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/defira/defira.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/openocean/openocean.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/pancakeswap/pancakeswap.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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)];
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/pangolin/pangolin.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/perp/perp.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/quickswap/quickswap.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/sushiswap/sushiswap.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/traderjoe/traderjoe.ts
Expand Up @@ -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'];
Expand Down Expand Up @@ -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() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/uniswap/uniswap.lp.helper.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -96,7 +97,7 @@ export class UniswapLPHelper {
* @param address Token address
*/
public getTokenByAddress(address: string): Token {
return this.tokenList[address];
return this.tokenList[getAddress(address)];
}

public async init() {
Expand Down
3 changes: 2 additions & 1 deletion src/connectors/uniswap/uniswap.ts
Expand Up @@ -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 };
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit d272192

Please sign in to comment.