Skip to content

Commit

Permalink
feat: add curve pools (#409)
Browse files Browse the repository at this point in the history
* feat: Additional Curve pools

* more pools

* fix the format

* changlog

* lowercase address

Co-authored-by: Jacob Evans <jacob@dekz.net>
  • Loading branch information
shawnxin89 and dekz committed Jan 28, 2022
1 parent e036dee commit 5c2255c
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 7 deletions.
9 changes: 9 additions & 0 deletions packages/asset-swapper/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"version": "16.49.0",
"changes": [
{
"note": "Add more curve pools",
"pr": 409
}
]
},
{
"version": "16.48.0",
"changes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
CURVE_AVALANCHE_INFOS,
CURVE_FANTOM_INFOS,
CURVE_MAINNET_INFOS,
CURVE_OPTIMISM_INFOS,
CURVE_POLYGON_INFOS,
CURVE_V2_AVALANCHE_INFOS,
CURVE_V2_FANTOM_INFOS,
Expand Down Expand Up @@ -165,6 +166,15 @@ export function getCurveInfosForPair(chainId: ChainId, takerToken: string, maker
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
case ChainId.Optimism:
return Object.values(CURVE_OPTIMISM_INFOS).filter(c =>
[makerToken, takerToken].every(
t =>
(c.tokens.includes(t) && c.metaTokens === undefined) ||
(c.tokens.includes(t) &&
[makerToken, takerToken].filter(v => c.metaTokens?.includes(v)).length > 0),
),
);
default:
return [];
}
Expand Down
137 changes: 131 additions & 6 deletions packages/asset-swapper/src/utils/market_operation_utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ export const SELL_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
[ChainId.Optimism]: new SourceFilters([
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.MultiHop,
]),
},
Expand Down Expand Up @@ -344,6 +346,8 @@ export const BUY_SOURCE_FILTER_BY_CHAIN_ID = valueByChainId<SourceFilters>(
[ChainId.Optimism]: new SourceFilters([
ERC20BridgeSource.UniswapV3,
ERC20BridgeSource.Synapse,
ERC20BridgeSource.Curve,
ERC20BridgeSource.CurveV2,
ERC20BridgeSource.MultiHop,
]),
},
Expand Down Expand Up @@ -483,6 +487,12 @@ export const MAINNET_TOKENS = {
// Synapse ecosystem
nUSD: '0x1b84765de8b7566e4ceaf4d0fd3c5af52d3dde4f',
CVX: '0x4e3fbd56cd56c3e72c1403e103b45db9da5b9d2b',
UST_WORMHOLE: '0xa693b19d2931d498c5b318df961919bb4aee87a5',
RAI: '0x03ab458634910aad20ef5f1c8ee96f1d6ac54919',
DOLA: '0x865377367054516e17014ccded1e7d814edc9ce4',
OUSD: '0x2a8e1e676ec238d8a992307b495b45b3feaa5e86',
agEUR: '0x1a7e4e63778b4f12a199c062f3efdd288afcbce8',
ibEUR: '0x96e61422b6a9ba0e068b6c5add4ffabc6a4aae27',
};

export const BSC_TOKENS = {
Expand Down Expand Up @@ -525,14 +535,18 @@ export const AVALANCHE_TOKENS = {
WETH: '0x49d5c2bdffac6ce2bfdb6640f4f80f226bc10bab',
WBTC: '0x50b7545627a5162f82a992c33b87adc75187b218',
DAI: '0xd586e7f844cea2f87f50152665bcbc2c279d8d70',
// bridged USDC
USDC: '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664',
// native USDC on Avalanche
nUSDC: '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e',
USDT: '0xc7198437980c041c805a1edcba50c1ce5db95118',
aDAI: '0x47afa96cdc9fab46904a55a6ad4bf6660b53c38a',
aUSDC: '0x46a51127c3ce23fb7ab1de06226147f446e4a857',
aUSDT: '0x532e6537fea298397212f09a61e03311686f548e',
nETH: '0x19e1ae0ee35c0404f835521146206595d37981ae',
nUSD: '0xcfc37a6ab183dd4aed08c204d1c2773c0b1bdf46',
aWETH: '0x53f7c5869a859f0aec3d334ee8b4cf01e3492f21',
MIM: '0x130966628846bfd36ff31a822705796e8cb8c18d',
};

export const CELO_TOKENS = {
Expand Down Expand Up @@ -566,6 +580,10 @@ export const FANTOM_TOKENS = {
MIM: '0x82f0b8b456c1a451378467398982d4834b6829c1',
nUSD: '0xed2a7edd7413021d440b09d654f3b87712abab66',
nETH: '0x67c10c397dd0ba417329543c1a40eb48aaa7cd00',
gfUSDT: '0x940f41f0ec9ba1a34cf001cc03347ac092f5f6b5',
gUSDC: '0xe578c856933d8e1082740bf7661e379aa2a30b26',
gDAI: '0x07e6332dd090d287d3489245038daf987955dcfb',
FRAX: '0xdc301622e621166bd8e82f2ca0a26c13ad0be355',
};

export const OPTIMISM_TOKENS = {
Expand Down Expand Up @@ -624,6 +642,15 @@ export const CURVE_POOLS = {
eurt: '0xfd5db7463a3ab53fd211b4af195c5bccc1a03890',
ethcrv: '0x8301ae4fc9c624d1d396cbdaa1ed877821d7c511',
ethcvx: '0xb576491f1e6e5e62f1d8f26062ee822b40b0e0d4',
mimust: '0x55a8a39bc9694714e2874c1ce77aa1e599461e18',
usttri_wormhole: '0xceaf7747579696a2f0bb206a14210e3c9e6fb269',
fei_tri: '0x06cb22615ba53e60d67bf6c341a0fd5e718e1655',
rai_tri: '0x618788357d0ebd8a37e763adab3bc575d54c2c7d',
DOLA_tri: '0xaa5a67c256e27a5d80712c51971408db3370927d',
OUSD_tri: '0x87650d7bbfc3a9f10587d7778206671719d9910d',
d3pool: '0xbaaa1f5dba42c3389bdbc2c9d2de134f5cd0dc89',
triEURpool: '0xb9446c4ef5ebe66268da6700d26f96273de3d571',
ibEURsEUR: '0x19b080fe1ffa0553469d20ca36219f17fcf03859',
};

export const CURVE_V2_POOLS = {
Expand All @@ -637,12 +664,13 @@ export const CURVE_POLYGON_POOLS = {
};

export const CURVE_V2_POLYGON_POOLS = {
atricrypto: '0x3fcd5de6a9fc8a99995c406c77dda3ed7e406f81',
atricrypto3: '0x1d8b86e3d88cdb2d34688e87e72f388cb541b7c8',
};

export const CURVE_AVALANCHE_POOLS = {
aave: '0x7f90122bf0700f9e7e1f688fe926940e8839f353',
mim: '0xaea2e71b631fa93683bcf256a8689dfa0e094fcd',
USDC: '0x3a43a5851a3e3e0e25a3c1089670269786be1577',
};

export const CURVE_V2_AVALANCHE_POOLS = {
Expand All @@ -653,12 +681,19 @@ export const CURVE_FANTOM_POOLS = {
fUSDT: '0x92d5ebf3593a92888c25c0abef126583d4b5312e',
twoPool: '0x27e611fd27b276acbd5ffd632e5eaebec9761e40',
ren: '0x3ef6a01a0f81d6046290f3e2a8c5b843e738e604',
tri_v2: '0x2dd7c9371965472e5a5fd28fbe165007c61439e1',
geist: '0x0fa949783947bf6c1b171db13aeacbb488845b3f',
FRAX_twoPool: '0x7a656b342e14f745e2b164890e88017e27ae7320',
};

export const CURVE_V2_FANTOM_POOLS = {
tricrypto: '0x3a1659ddcf2339be3aea159ca010979fb49155ff',
};

export const CURVE_OPTIMISM_POOLS = {
tri: '0x1337bedc9d22ecbe766df105c9623922a27963ec',
};

export const SWERVE_POOLS = {
y: '0x329239599afb305da0a2ec69c58f8a6697f9f88d',
};
Expand Down Expand Up @@ -807,6 +842,7 @@ export const DEFAULT_INTERMEDIATE_TOKENS_BY_CHAIN_ID = valueByChainId<string[]>(
OPTIMISM_TOKENS.WETH,
OPTIMISM_TOKENS.DAI,
OPTIMISM_TOKENS.USDC,
OPTIMISM_TOKENS.USDT,
OPTIMISM_TOKENS.nETH,
OPTIMISM_TOKENS.sWETH,
],
Expand Down Expand Up @@ -890,6 +926,7 @@ const CURVE_TRI_POOL_MAINNET_TOKENS = [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC,
const CURVE_TRI_BTC_POOL_TOKEN = [MAINNET_TOKENS.RenBTC, MAINNET_TOKENS.WBTC, MAINNET_TOKENS.sBTC];
const CURVE_POLYGON_ATRICRYPTO_UNDERLYING_TOKENS = [POLYGON_TOKENS.DAI, POLYGON_TOKENS.USDC, POLYGON_TOKENS.USDT];
const CURVE_POLYGON_ATRICRYPTO_TOKENS = [POLYGON_TOKENS.amDAI, POLYGON_TOKENS.amUSDC, POLYGON_TOKENS.amUSDT];
const CURVE_FANTOM_TWO_POOL_TOKENS = [FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC];

const createCurveExchangePool = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange,
Expand Down Expand Up @@ -931,6 +968,16 @@ const createCurveMetaTriBtcPool = (info: { tokens: string[]; pool: string; gasSc
gasSchedule: info.gasSchedule,
});

const createCurveMetaTwoPoolFantom = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_underlying,
buyQuoteFunctionSelector: CurveFunctionSelectors.None,
tokens: [...info.tokens, ...CURVE_FANTOM_TWO_POOL_TOKENS],
metaTokens: info.tokens,
poolAddress: info.pool,
gasSchedule: info.gasSchedule,
});

const createCurveExchangeV2Pool = (info: { tokens: string[]; pool: string; gasSchedule: number }) => ({
exchangeFunctionSelector: CurveFunctionSelectors.exchange_v2,
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_v2,
Expand Down Expand Up @@ -1172,6 +1219,51 @@ export const CURVE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
sellQuoteFunctionSelector: CurveFunctionSelectors.get_dy_uint256,
exchangeFunctionSelector: CurveFunctionSelectors.exchange_underlying_uint256,
},
[CURVE_POOLS.mimust]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.MIM, MAINNET_TOKENS.UST],
pool: CURVE_POOLS.mimust,
gasSchedule: 105e3,
}),
[CURVE_POOLS.usttri_wormhole]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.UST_WORMHOLE],
pool: CURVE_POOLS.usttri_wormhole,
gasSchedule: 340e3,
}),
[CURVE_POOLS.fei_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.FEI],
pool: CURVE_POOLS.fei_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.rai_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.RAI],
pool: CURVE_POOLS.rai_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.DOLA_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.DOLA],
pool: CURVE_POOLS.DOLA_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.OUSD_tri]: createCurveMetaTriPool({
tokens: [MAINNET_TOKENS.OUSD],
pool: CURVE_POOLS.OUSD_tri,
gasSchedule: 340e3,
}),
[CURVE_POOLS.d3pool]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.FRAX, MAINNET_TOKENS.FEI, MAINNET_TOKENS.alUSD],
pool: CURVE_POOLS.d3pool,
gasSchedule: 176e3,
}),
[CURVE_POOLS.triEURpool]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.agEUR, MAINNET_TOKENS.EURT, MAINNET_TOKENS.EURS],
pool: CURVE_POOLS.triEURpool,
gasSchedule: 176e3,
}),
[CURVE_POOLS.ibEURsEUR]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.ibEUR, MAINNET_TOKENS.sEUR],
pool: CURVE_POOLS.ibEURsEUR,
gasSchedule: 176e3,
}),
};

export const CURVE_V2_MAINNET_INFOS: { [name: string]: CurveInfo } = {
Expand Down Expand Up @@ -1206,11 +1298,6 @@ export const CURVE_POLYGON_INFOS: { [name: string]: CurveInfo } = {
};

export const CURVE_V2_POLYGON_INFOS: { [name: string]: CurveInfo } = {
[CURVE_V2_POLYGON_POOLS.atricrypto]: createCurveV2MetaTriPool({
tokens: [POLYGON_TOKENS.WBTC, POLYGON_TOKENS.WETH],
pool: CURVE_V2_POLYGON_POOLS.atricrypto,
gasSchedule: 300e3,
}),
[CURVE_V2_POLYGON_POOLS.atricrypto3]: createCurveV2MetaTriPool({
tokens: [POLYGON_TOKENS.WBTC, POLYGON_TOKENS.WETH],
pool: CURVE_V2_POLYGON_POOLS.atricrypto3,
Expand All @@ -1229,6 +1316,16 @@ export const CURVE_AVALANCHE_INFOS: { [name: string]: CurveInfo } = {
pool: CURVE_AVALANCHE_POOLS.aave,
gasSchedule: 150e3,
}),
[CURVE_AVALANCHE_POOLS.mim]: createCurveExchangePool({
tokens: [AVALANCHE_TOKENS.MIM, AVALANCHE_TOKENS.USDT, AVALANCHE_TOKENS.USDC],
pool: CURVE_AVALANCHE_POOLS.mim,
gasSchedule: 150e3,
}),
[CURVE_AVALANCHE_POOLS.USDC]: createCurveExchangePool({
tokens: [AVALANCHE_TOKENS.USDC, AVALANCHE_TOKENS.nUSDC],
pool: CURVE_AVALANCHE_POOLS.USDC,
gasSchedule: 150e3,
}),
};

export const CURVE_V2_AVALANCHE_INFOS: { [name: string]: CurveInfo } = {
Expand Down Expand Up @@ -1266,6 +1363,26 @@ export const CURVE_FANTOM_INFOS: { [name: string]: CurveInfo } = {
pool: CURVE_FANTOM_POOLS.fUSDT,
gasSchedule: 587e3,
}),
[CURVE_FANTOM_POOLS.tri_v2]: createCurveExchangePool({
tokens: [FANTOM_TOKENS.MIM, FANTOM_TOKENS.fUSDT, FANTOM_TOKENS.USDC],
pool: CURVE_FANTOM_POOLS.tri_v2,
gasSchedule: 176e3,
}),
['geist_exchangeunderlying']: createCurveExchangeUnderlyingPool({
tokens: [FANTOM_TOKENS.DAI, FANTOM_TOKENS.USDC, FANTOM_TOKENS.fUSDT],
pool: CURVE_FANTOM_POOLS.geist,
gasSchedule: 850e3,
}),
['geist_exchange']: createCurveExchangePool({
tokens: [FANTOM_TOKENS.gDAI, FANTOM_TOKENS.gUSDC, FANTOM_TOKENS.gfUSDT],
pool: CURVE_FANTOM_POOLS.geist,
gasSchedule: 150e3,
}),
[CURVE_FANTOM_POOLS.FRAX_twoPool]: createCurveMetaTwoPoolFantom({
tokens: [FANTOM_TOKENS.FRAX],
pool: CURVE_FANTOM_POOLS.FRAX_twoPool,
gasSchedule: 411e3,
}),
};

export const CURVE_V2_FANTOM_INFOS: { [name: string]: CurveInfo } = {
Expand All @@ -1276,6 +1393,14 @@ export const CURVE_V2_FANTOM_INFOS: { [name: string]: CurveInfo } = {
}),
};

export const CURVE_OPTIMISM_INFOS: { [name: string]: CurveInfo } = {
[CURVE_OPTIMISM_POOLS.tri]: createCurveExchangePool({
tokens: [OPTIMISM_TOKENS.DAI, OPTIMISM_TOKENS.USDC, OPTIMISM_TOKENS.USDT],
pool: CURVE_OPTIMISM_POOLS.tri,
gasSchedule: 150e3,
}),
};

export const SWERVE_MAINNET_INFOS: { [name: string]: CurveInfo } = {
[SWERVE_POOLS.y]: createCurveExchangePool({
tokens: [MAINNET_TOKENS.DAI, MAINNET_TOKENS.USDC, MAINNET_TOKENS.USDT, MAINNET_TOKENS.TUSD],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export type SourcesWithPoolsCache =
export enum CurveFunctionSelectors {
None = '0x00000000',
exchange = '0x3df02124',
exchange_underlying = '0xa6417ed6',
exchange_underlying = '0xa6417ed6', // exchange_underlying(int128 i, int128 j, uint256 dx, uint256 min_dy)
get_dy_underlying = '0x07211ef7',
get_dx_underlying = '0x0e71d1b9',
get_dy = '0x5e0d443f', // get_dy(int128,int128,uint256)
Expand Down

0 comments on commit 5c2255c

Please sign in to comment.