Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/uniswap token address #169

Merged
merged 4 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/chains/ethereum/ethereum-base.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading