Skip to content

Commit

Permalink
Merge pull request #365 from curvefi/router-upgrade-v1.1
Browse files Browse the repository at this point in the history
Router upgrade v1.1
  • Loading branch information
Macket authored Jul 8, 2024
2 parents 9fb54c7 + 5787d73 commit 5a6c96e
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 84 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "2.60.5",
"version": "2.61.0",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"author": "Macket",
Expand Down
145 changes: 145 additions & 0 deletions src/constants/abis/router-ng-pools-only.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
[
{
"name": "Exchange",
"inputs": [
{
"name": "sender",
"type": "address",
"indexed": true
},
{
"name": "receiver",
"type": "address",
"indexed": true
},
{
"name": "route",
"type": "address[11]",
"indexed": false
},
{
"name": "swap_params",
"type": "uint256[4][5]",
"indexed": false
},
{
"name": "in_amount",
"type": "uint256",
"indexed": false
},
{
"name": "out_amount",
"type": "uint256",
"indexed": false
}
],
"anonymous": false,
"type": "event"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"stateMutability": "nonpayable",
"type": "constructor",
"inputs": [
{
"name": "_weth",
"type": "address"
}
],
"outputs": []
},
{
"stateMutability": "payable",
"type": "function",
"name": "exchange",
"inputs": [
{
"name": "_route",
"type": "address[11]"
},
{
"name": "_swap_params",
"type": "uint256[4][5]"
},
{
"name": "_amount",
"type": "uint256"
},
{
"name": "_min_dy",
"type": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "get_dy",
"inputs": [
{
"name": "_route",
"type": "address[11]"
},
{
"name": "_swap_params",
"type": "uint256[4][5]"
},
{
"name": "_amount",
"type": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "get_dx",
"inputs": [
{
"name": "_route",
"type": "address[11]"
},
{
"name": "_swap_params",
"type": "uint256[4][5]"
},
{
"name": "_out_amount",
"type": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "uint256"
}
]
},
{
"stateMutability": "view",
"type": "function",
"name": "version",
"inputs": [],
"outputs": [
{
"name": "",
"type": "string"
}
]
}
]
28 changes: 14 additions & 14 deletions src/constants/aliases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const ALIASES_ETHEREUM = lowerCaseValues({
"fee_distributor_crvusd": "0xD16d5eC345Dd86Fb63C6a9C43c517210F1027914",
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x16C6521Dff6baB339122a0FE25a9116693265353",
"deposit_and_stake": "0x56C526b0159a258887e0d79ec3a80dfb940d0cD7", // <--- CHANGE
"stable_calc": "0x0DCDED3545D565bA3B19E683431381007245d983", // <-- CHANGE
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- CHANGE
Expand All @@ -35,7 +35,7 @@ export const ALIASES_POLYGON = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand All @@ -56,7 +56,7 @@ export const ALIASES_FANTOM = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand All @@ -77,7 +77,7 @@ export const ALIASES_AVALANCHE = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand All @@ -98,7 +98,7 @@ export const ALIASES_ARBITRUM = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x2191718CD32d02B8E60BAdFFeA33E4B5DD9A0A0D",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand All @@ -119,7 +119,7 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
Expand All @@ -142,7 +142,7 @@ export const ALIASES_XDAI = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand Down Expand Up @@ -205,7 +205,7 @@ export const ALIASES_KAVA = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
"router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
"router": "0x0DCDED3545D565bA3B19E683431381007245d983",
"deposit_and_stake": "0x37c5ab57AF7100Bdc9B668d766e193CCbF6614FD",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4", // <-- CHANGED
"crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC', // <--- NEW
Expand Down Expand Up @@ -247,7 +247,7 @@ export const ALIASES_ZKSYNC = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB", // <--- TODO CHANGE
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383", // <--- TODO CHANGE
"router": "0x0000000000000000000000000000000000000000",
"router": "0x7C915390e109CA66934f1eB285854375D1B127FA",
"deposit_and_stake": "0x0000000000000000000000000000000000000000",
"stable_calc": "0x0000000000000000000000000000000000000000",
"crypto_calc": '0x0000000000000000000000000000000000000000',
Expand All @@ -268,7 +268,7 @@ export const ALIASES_BASE = lowerCaseValues({
"fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc", // <-- DUMMY
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB", // <--- TODO CHANGE
"address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383", // <--- TODO CHANGE
"router": "0xd6681e74eEA20d196c15038C580f721EF2aB6320",
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
"deposit_and_stake": "0x69522fb5337663d3B4dFB0030b881c1A750Adb4f",
"stable_calc": "0x5552b631e2aD801fAa129Aacf4B701071cC9D1f7",
"crypto_calc": '0xEfadDdE5B43917CcC738AdE6962295A0B343f7CE',
Expand All @@ -291,7 +291,7 @@ export const ALIASES_BSC = lowerCaseValues({
"fee_distributor": "0x0000000000000000000000000000000000000000", // <-- TODO CHANGE
"gauge_controller": "0x0000000000000000000000000000000000000000", // <--- TODO CHANGE
"address_provider": "0x0000000000000000000000000000000000000000", // <--- TODO CHANGE
"router": "0x69522fb5337663d3B4dFB0030b881c1A750Adb4f",
"router": "0xA72C85C258A81761433B4e8da60505Fe3Dd551CC",
"deposit_and_stake": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
"crypto_calc": '0xd6681e74eEA20d196c15038C580f721EF2aB6320',
Expand All @@ -312,7 +312,7 @@ export const ALIASES_FRAXTAL = lowerCaseValues({
"fee_distributor": "0x0000000000000000000000000000000000000000",
"gauge_controller": "0x0000000000000000000000000000000000000000",
"address_provider": "0x0000000000000000000000000000000000000000",
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
"router": "0x9f2Fa7709B30c75047980a0d70A106728f0Ef2db",
"deposit_and_stake": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
"stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
"crypto_calc": '0x69522fb5337663d3B4dFB0030b881c1A750Adb4f',
Expand All @@ -333,7 +333,7 @@ export const ALIASES_XLAYER = lowerCaseValues({
"fee_distributor": "0x0000000000000000000000000000000000000000",
"gauge_controller": "0x0000000000000000000000000000000000000000",
"address_provider": "0x0000000000000000000000000000000000000000",
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
"router": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855",
"deposit_and_stake": "0x5552b631e2aD801fAa129Aacf4B701071cC9D1f7",
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
"crypto_calc": '0x69522fb5337663d3B4dFB0030b881c1A750Adb4f',
Expand All @@ -354,7 +354,7 @@ export const ALIASES_MANTLE = lowerCaseValues({
"fee_distributor": "0x0000000000000000000000000000000000000000",
"gauge_controller": "0x0000000000000000000000000000000000000000",
"address_provider": "0x0000000000000000000000000000000000000000",
"router": "0x69522fb5337663d3B4dFB0030b881c1A750Adb4f",
"router": "0x4f37A9d177470499A2dD084621020b023fcffc1F",
"deposit_and_stake": "0x5552b631e2ad801faa129aacf4b701071cc9d1f7",
"stable_calc": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF",
"crypto_calc": '0xd6681e74eEA20d196c15038C580f721EF2aB6320',
Expand Down
2 changes: 1 addition & 1 deletion src/constants/coins/fraxtal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const COINS_FRAXTAL: IDict<string> = lowerCaseValues({
crv: '0x331B9182088e2A7d6D3Fe4742AbA1fB231aEcc56',

// --- FRAXTAL ---
frxETH: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
frxeth: "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
});

export const cTokensFraxtal = []; //.map((a) => a.toLowerCase());
Expand Down
7 changes: 6 additions & 1 deletion src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import cryptoCalcZapABI from './constants/abis/crypto_calc.json' assert { type:
import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type: 'json' };
import routerABI from './constants/abis/router.json' assert { type: 'json' };
import routerPolygonABI from './constants/abis/routerPolygon.json' assert { type: 'json' };
import routerNgPoolsOnlyABI from './constants/abis/router-ng-pools-only.json' assert { type: 'json' };
import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
import factoryEywaABI from './constants/abis/factory-eywa.json' assert { type: 'json' };
Expand Down Expand Up @@ -405,6 +406,8 @@ export const NETWORK_CONSTANTS: { [index: number]: any } = {
},
}

const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools

class Curve implements ICurve {
provider: ethers.BrowserProvider | ethers.JsonRpcProvider;
multicallProvider: MulticallProvider;
Expand Down Expand Up @@ -675,8 +678,10 @@ class Curve implements ICurve {

if (this.chainId == 137) {
this.setContract(this.constants.ALIASES.router, routerPolygonABI);
} else {
} else if (OLD_CHAINS.includes(this.chainId)) {
this.setContract(this.constants.ALIASES.router, routerABI);
} else {
this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
}

this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
Expand Down
8 changes: 4 additions & 4 deletions src/factory/factory-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
deposit_abi: basePoolZap.ABI,
in_api: true,
is_stable_ng: false,
is_ng: false,
};
} else {
FACTORY_POOLS_DATA[pool.id] = {
Expand All @@ -208,7 +208,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
swap_abi: getSwapAbiByFactoryType(factoryType, pool),
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
in_api: true,
is_stable_ng: false,
is_ng: factoryType === "factory-tricrypto" || factoryType === "factory-twocrypto",
};
}
} else if (pool.isMetaPool) {
Expand Down Expand Up @@ -252,7 +252,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
deposit_abi: basePoolZap.ABI,
in_api: true,
is_stable_ng: factoryType === 'factory-stable-ng',
is_ng: factoryType === 'factory-stable-ng',
};
} else {
const implementationABIDict = FACTORY_CONSTANTS[this.chainId].implementationABIDict;
Expand All @@ -276,7 +276,7 @@ export async function getFactoryPoolsDataFromApi(this: ICurve, factoryType: IFac
swap_abi: implementationABIDict[pool.implementationAddress],
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
in_api: true,
is_stable_ng: factoryType === 'factory-stable-ng',
is_ng: factoryType === 'factory-stable-ng',
};
}
})
Expand Down
1 change: 1 addition & 0 deletions src/factory/factory-tricrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export async function getTricryptoFactoryPoolData(this: ICurve, fromIdx = 0, swa
wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
swap_abi: tricryptoFactorySwapABI,
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
is_ng: true,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/factory/factory-twocrypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export async function getTwocryptoFactoryPoolData(this: ICurve, fromIdx = 0, swa
wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
swap_abi: twocryptoFactorySwapABI,
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
is_ng: true,
};
}

Expand Down
5 changes: 3 additions & 2 deletions src/factory/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ export async function getFactoryPoolData(this: ICurve, fromIdx = 0, swapAddress?
wrapped_decimals: [...coinAddresses[i].map((addr) => coinAddressDecimalsDict[addr])],
swap_abi: swapABIs[i],
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
is_stable_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,

is_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,
};
} else {
const allPoolsData = {...this.constants.POOLS_DATA, ...this.constants.FACTORY_POOLS_DATA, ...FACTORY_POOLS_DATA};
Expand Down Expand Up @@ -363,7 +364,7 @@ export async function getFactoryPoolData(this: ICurve, fromIdx = 0, swapAddress?
swap_abi: swapABIs[i],
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
deposit_abi: basePoolZap.ABI,
is_stable_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,
is_ng: factoryAddress === curve.constants.ALIASES.stable_ng_factory,
};
}
}
Expand Down
Loading

0 comments on commit 5a6c96e

Please sign in to comment.