Skip to content

Commit

Permalink
(merge) resolved merge conflicts in uniswap BNB
Browse files Browse the repository at this point in the history
  • Loading branch information
fengtality committed Jul 25, 2024
2 parents 70ca18a + 373c577 commit 1f2795c
Show file tree
Hide file tree
Showing 14 changed files with 1,740 additions and 342 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@types/uuid": "^8.3.4",
"@uniswap/sdk": "3.0.2",
"@uniswap/sdk-core": "^3.0.0",
"@uniswap/smart-order-router": "^2.5.26",
"@uniswap/smart-order-router": "^3.28.7",
"@uniswap/v3-core": "^1.0.0",
"@uniswap/v3-periphery": "^1.1.1",
"@uniswap/v3-sdk": "^3.7.0",
Expand Down
8 changes: 8 additions & 0 deletions src/chains/binance-smart-chain/binance-smart-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SushiswapConfig } from '../../connectors/sushiswap/sushiswap.config';
import { ConfigManagerV2 } from '../../services/config-manager-v2';
import { OpenoceanConfig } from '../../connectors/openocean/openocean.config';
import { EVMController } from '../ethereum/evm.controllers';
import {UniswapConfig} from "../../connectors/uniswap/uniswap.config";

export class BinanceSmartChain extends EthereumBase implements Ethereumish {
private static _instances: { [name: string]: BinanceSmartChain };
Expand Down Expand Up @@ -113,6 +114,13 @@ export class BinanceSmartChain extends EthereumBase implements Ethereumish {
'binance-smart-chain',
this._chain
);
} else if (reqSpender === 'uniswap') {
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress(
'binance-smart-chain',
this._chain
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress('binance-smart-chain', this._chain);
} else {
spender = reqSpender;
}
Expand Down
5 changes: 4 additions & 1 deletion src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export class Ethereum extends EthereumBase implements Ethereumish {
let spender: string;
if (reqSpender === 'uniswap') {
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress(
this.chainName,
this._chain,
);
} else if (reqSpender === 'pancakeswap') {
Expand All @@ -196,7 +197,9 @@ export class Ethereum extends EthereumBase implements Ethereumish {
this._chain,
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
spender = UniswapConfig.config.uniswapV3NftManagerAddress(
this.chainName,
this._chain);
} else if (reqSpender === 'carbonamm') {
spender = CarbonConfig.config.carbonContractsConfig(
'ethereum',
Expand Down
3 changes: 2 additions & 1 deletion src/chains/polygon/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ export class Polygon extends EthereumBase implements Ethereumish {
let spender: string;
if (reqSpender === 'uniswap') {
spender = UniswapConfig.config.uniswapV3SmartOrderRouterAddress(
'polygon',
this._chain
);
} else if (reqSpender === 'uniswapLP') {
spender = UniswapConfig.config.uniswapV3NftManagerAddress(this._chain);
spender = UniswapConfig.config.uniswapV3NftManagerAddress('polygon', this._chain);
} else if (reqSpender === 'quickswap') {
spender = QuickswapConfig.config.routerAddress(this._chain);
} else if (reqSpender === 'sushiswap') {
Expand Down
66 changes: 36 additions & 30 deletions src/connectors/uniswap/uniswap.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export namespace UniswapConfig {
gasLimitEstimate: number;
ttl: number;
maximumHops: number;
uniswapV3SmartOrderRouterAddress: (network: string) => string;
uniswapV3NftManagerAddress: (network: string) => string;
uniswapV3FactoryAddress: (network: string) => string;
uniswapV3SmartOrderRouterAddress: (chain: string, network: string) => string;
uniswapV3NftManagerAddress: (chain: string, network: string) => string;
uniswapV3FactoryAddress: (chain: string, network: string) => string;
tradingTypes: (type: string) => Array<string>;
chainType: string;
availableNetworks: Array<AvailableNetworks>;
useRouter?: boolean;
feeTier?: string;
quoterContractAddress: (network: string) => string;
quoterContractAddress: (chain: string, network: string) => string;
}

export const config: NetworkConfig = {
Expand All @@ -26,17 +26,37 @@ export namespace UniswapConfig {
),
ttl: ConfigManagerV2.getInstance().get(`uniswap.ttl`),
maximumHops: ConfigManagerV2.getInstance().get(`uniswap.maximumHops`),
uniswapV3SmartOrderRouterAddress: (network: string) =>
uniswapV3SmartOrderRouterAddress: (chain: string, network: string) =>
ConfigManagerV2.getInstance().get(
`uniswap.contractAddresses.${network}.uniswapV3SmartOrderRouterAddress`
'uniswap.contractAddresses.' +
chain +
'.' +
network +
'.uniswapV3SmartOrderRouterAddress'
),
uniswapV3NftManagerAddress: (network: string) =>
uniswapV3NftManagerAddress: (chain: string, network: string) =>
ConfigManagerV2.getInstance().get(
`uniswap.contractAddresses.${network}.uniswapV3NftManagerAddress`
'uniswap.contractAddresses.' +
chain +
'.' +
network +
'.uniswapV3NftManagerAddress'
),
uniswapV3FactoryAddress: (network: string) =>
uniswapV3FactoryAddress: (chain: string, network: string) =>
ConfigManagerV2.getInstance().get(
`uniswap.contractAddresses.${network}.uniswapV3FactoryAddress`
'uniswap.contractAddresses.' +
chain +
'.' +
network +
'.uniswapV3FactoryAddress'
),
quoterContractAddress: (chain: string, network: string) =>
ConfigManagerV2.getInstance().get(
'uniswap.contractAddresses.' +
chain +
'.' +
network +
'.uniswapV3QuoterV2ContractAddress'
),
tradingTypes: (type: string) => {
return type === 'swap' ? ['AMM'] : ['AMM_LP'];
Expand All @@ -45,30 +65,16 @@ export namespace UniswapConfig {
availableNetworks: [
{
chain: 'ethereum',
networks: Object.keys(
ConfigManagerV2.getInstance().get('uniswap.contractAddresses')
).filter((network) =>
Object.keys(
ConfigManagerV2.getInstance().get('ethereum.networks')
).includes(network)
),
networks: ['mainnet', 'goerli', 'arbitrum', 'optimism'],
},
{
chain: 'polygon',
networks: Object.keys(
ConfigManagerV2.getInstance().get('uniswap.contractAddresses')
).filter((network) =>
Object.keys(
ConfigManagerV2.getInstance().get('polygon.networks')
).includes(network)
),
{ chain: 'polygon',
networks: ['mainnet', 'mumbai']
},
{ chain: 'binance-smart-chain',
networks: ['mainnet']
},
],
useRouter: ConfigManagerV2.getInstance().get(`uniswap.useRouter`),
feeTier: ConfigManagerV2.getInstance().get(`uniswap.feeTier`),
quoterContractAddress: (network: string) =>
ConfigManagerV2.getInstance().get(
`uniswap.contractAddresses.${network}.uniswapV3QuoterV2ContractAddress`
),
};
}
4 changes: 2 additions & 2 deletions src/connectors/uniswap/uniswap.lp.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class UniswapLPHelper {
provider: this.ethereum.provider,
});
this._router =
UniswapConfig.config.uniswapV3SmartOrderRouterAddress(network);
this._nftManager = UniswapConfig.config.uniswapV3NftManagerAddress(network);
UniswapConfig.config.uniswapV3SmartOrderRouterAddress(chain, network);
this._nftManager = UniswapConfig.config.uniswapV3NftManagerAddress(chain, network);
this._ttl = UniswapConfig.config.ttl;
this._routerAbi =
require('@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json').abi;
Expand Down
19 changes: 11 additions & 8 deletions src/connectors/uniswap/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Pool,
SwapQuoter,
Trade as UniswapV3Trade,
Route
Route,
} from '@uniswap/v3-sdk';
import { abi as IUniswapV3PoolABI } from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Pool.sol/IUniswapV3Pool.json';
import { abi as IUniswapV3FactoryABI } from '@uniswap/v3-core/artifacts/contracts/interfaces/IUniswapV3Factory.sol/IUniswapV3Factory.json';
Expand All @@ -37,15 +37,17 @@ import { logger } from '../../services/logger';
import { percentRegexp } from '../../services/config-manager-v2';
import { Ethereum } from '../../chains/ethereum/ethereum';
import { Polygon } from '../../chains/polygon/polygon';
import { BinanceSmartChain } from "../../chains/binance-smart-chain/binance-smart-chain";
import { ExpectedTrade, Uniswapish } from '../../services/common-interfaces';
import { getAddress } from 'ethers/lib/utils';

export class Uniswap implements Uniswapish {
private static _instances: { [name: string]: Uniswap };
private chain: Ethereum | Polygon;
private chain: Ethereum | Polygon | BinanceSmartChain;
private _alphaRouter: AlphaRouter | null;
private _router: string;
private _routerAbi: ContractInterface;
private _v3Factory: string;
private _gasLimitEstimate: number;
private _ttl: number;
private _maximumHops: number;
Expand All @@ -55,14 +57,15 @@ export class Uniswap implements Uniswapish {
private readonly _useRouter: boolean;
private readonly _feeTier: FeeAmount;
private readonly _quoterContractAddress: string;
private readonly _factoryAddress: string;

private constructor(chain: string, network: string) {
const config = UniswapConfig.config;
if (chain === 'ethereum') {
this.chain = Ethereum.getInstance(network);
} else {
} else if (chain === 'polygon') {
this.chain = Polygon.getInstance(network);
} else {
this.chain = BinanceSmartChain.getInstance(network);
}
this.chainId = this.chain.chainId;
this._ttl = UniswapConfig.config.ttl;
Expand All @@ -77,7 +80,8 @@ export class Uniswap implements Uniswapish {
}
this._routerAbi = routerAbi.abi;
this._gasLimitEstimate = UniswapConfig.config.gasLimitEstimate;
this._router = config.uniswapV3SmartOrderRouterAddress(network);
this._router = config.uniswapV3SmartOrderRouterAddress(chain, network);
this._v3Factory = config.uniswapV3FactoryAddress(chain, network);

if (config.useRouter === false && config.feeTier == null) {
throw new Error('Must specify fee tier if not using router');
Expand All @@ -91,8 +95,7 @@ export class Uniswap implements Uniswapish {
this._feeTier = config.feeTier
? FeeAmount[config.feeTier as keyof typeof FeeAmount]
: FeeAmount.MEDIUM;
this._quoterContractAddress = config.quoterContractAddress(network);
this._factoryAddress = config.uniswapV3FactoryAddress(network);
this._quoterContractAddress = config.quoterContractAddress(chain, network);
}

public static getInstance(chain: string, network: string): Uniswap {
Expand Down Expand Up @@ -442,7 +445,7 @@ export class Uniswap implements Uniswapish {
poolId?: string
): Promise<Pool | null> {
const uniswapFactory = new Contract(
this._factoryAddress,
this._v3Factory,
IUniswapV3FactoryABI,
this.chain.provider
);
Expand Down
4 changes: 2 additions & 2 deletions src/services/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ export async function getConnector<T>(
let connectorInstance: ConnectorUnion;

if (
(chain === 'ethereum' || chain === 'polygon') &&
(chain === 'ethereum' || chain === 'polygon' || chain === 'binance-smart-chain') &&
connector === 'uniswap'
) {
connectorInstance = Uniswap.getInstance(chain, network);
} else if (chain === 'polygon' && connector === 'quickswap') {
connectorInstance = Quickswap.getInstance(chain, network);
} else if (
(chain === 'ethereum' || chain === 'polygon') &&
(chain === 'ethereum' || chain === 'polygon' || chain === 'binance-smart-chain') &&
connector === 'uniswapLP'
) {
connectorInstance = UniswapLP.getInstance(chain, network);
Expand Down
28 changes: 16 additions & 12 deletions src/services/schema/uniswap-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,24 @@
"contractAddresses": {
"type": "object",
"patternProperties": {
"^\\w+$": {
"[\\w-]+$": {
"type": "object",
"properties": {
"uniswapV3SmartOrderRouterAddress": { "type": "string" },
"uniswapV3NftManagerAddress": { "type": "string" },
"uniswapV3QuoterV2ContractAddress": { "type": "string" },
"uniswapV3FactoryAddress": { "type": "string" }
"patternProperties": {
"^\\w+$": {
"type": "object",
"properties": {
"uniswapV3SmartOrderRouterAddress": { "type": "string" },
"uniswapV3NftManagerAddress": { "type": "string" },
"uniswapV3QuoterV2ContractAddress": { "type": "string" },
"uniswapV3FactoryAddress": { "type": "string" }
},
"required": [
"uniswapV3SmartOrderRouterAddress",
"uniswapV3NftManagerAddress"
],
"additionalProperties": false
}
},
"required": [
"uniswapV3SmartOrderRouterAddress",
"uniswapV3NftManagerAddress",
"uniswapV3QuoterV2ContractAddress",
"uniswapV3FactoryAddress"
],
"additionalProperties": false
}
},
Expand Down
78 changes: 48 additions & 30 deletions src/templates/uniswap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,51 @@ useRouter: false
feeTier: 'MEDIUM'

contractAddresses:
mainnet:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
goerli:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
arbitrum:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
optimism:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
base:
uniswapV3SmartOrderRouterAddress: '0x2626664c2603336E57B271c5C0b26F421741e481'
uniswapV3NftManagerAddress: '0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1'
uniswapV3QuoterV2ContractAddress: '0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a'
uniswapV3FactoryAddress: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD'
sepolia:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
ethereum:
mainnet:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
goerli:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
arbitrum:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
optimism:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
base:
uniswapV3SmartOrderRouterAddress: '0x2626664c2603336E57B271c5C0b26F421741e481'
uniswapV3NftManagerAddress: '0x03a520b32C04BF3bEEf7BEb72E919cf822Ed34f1'
uniswapV3QuoterV2ContractAddress: '0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a'
uniswapV3FactoryAddress: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD'
sepolia:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
polygon:
mainnet:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
mumbai:
uniswapV3SmartOrderRouterAddress: '0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45'
uniswapV3NftManagerAddress: '0xC36442b4a4522E871399CD717aBDD847Ab11FE88'
uniswapV3QuoterV2ContractAddress: '0x61fFE014bA17989E743c5F6cB21bF9697530B21e'
uniswapV3FactoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984'
binance-smart-chain:
mainnet:
uniswapV3SmartOrderRouterAddress: '0xB971eF87ede563556b2ED4b1C0b0019111Dd85d2'
uniswapV3NftManagerAddress: '0x7b8A01B39D58278b5DE7e48c8449c9f4F5170613'
uniswapV3QuoterV2ContractAddress: '0x78D78E420Da98ad378D7799bE8f4AF69033EB077'
uniswapV3FactoryAddress: '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7'
Loading

0 comments on commit 1f2795c

Please sign in to comment.