@curvefi/api 2.47.4 → 2.48.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/lib/factory/deploy.d.ts +1 -0
- package/lib/factory/deploy.js +17 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +4 -1
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/utils.js +1 -1
- package/lib/router.js +360 -236
- package/lib/utils.js +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1753,7 +1753,9 @@ import curve from "@curvefi/api";
|
|
|
1753
1753
|
const gaugeSidechainAddress = await curve.factory.getDeployedGaugeAddress(deployGaugeSidechain);
|
|
1754
1754
|
// 0x60d3d7ebbc44dc810a743703184f062d00e6db7e
|
|
1755
1755
|
//After that should be deployed mirror gauge on mainnet with same salt
|
|
1756
|
-
//await curve.tricryptoFactory.deployGaugeMirror(sidechainId, salt);
|
|
1756
|
+
//const gaugeMirrorTx = await curve.tricryptoFactory.deployGaugeMirror(sidechainId, salt);
|
|
1757
|
+
//const deployedGaugeMirrorAddress = await curve.tricryptoFactory.getDeployedGaugeMirrorAddressByTx(gaugeMirrorTx);
|
|
1758
|
+
//OR
|
|
1757
1759
|
//const deployedGaugeMirrorAddress = await curve.tricryptoFactory.getDeployedGaugeMirrorAddress(sidechainId);
|
|
1758
1760
|
|
|
1759
1761
|
// Deposit & Stake
|
package/lib/factory/deploy.d.ts
CHANGED
|
@@ -21,4 +21,5 @@ export declare const deployGaugeSidechain: (pool: string, salt: string) => Promi
|
|
|
21
21
|
export declare const deployGaugeMirrorEstimateGas: (chainId: number, salt: string) => Promise<number>;
|
|
22
22
|
export declare const deployGaugeMirror: (chainId: number, salt: string) => Promise<ethers.ContractTransactionResponse>;
|
|
23
23
|
export declare const getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
24
|
+
export declare const getDeployedGaugeMirrorAddressByTx: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
24
25
|
export declare const getDeployedGaugeMirrorAddress: (chainId: number) => Promise<string>;
|
package/lib/factory/deploy.js
CHANGED
|
@@ -645,6 +645,23 @@ export var getDeployedGaugeAddress = function (tx) { return __awaiter(void 0, vo
|
|
|
645
645
|
}
|
|
646
646
|
});
|
|
647
647
|
}); };
|
|
648
|
+
export var getDeployedGaugeMirrorAddressByTx = function (tx) { return __awaiter(void 0, void 0, void 0, function () {
|
|
649
|
+
var txInfo;
|
|
650
|
+
return __generator(this, function (_a) {
|
|
651
|
+
switch (_a.label) {
|
|
652
|
+
case 0:
|
|
653
|
+
if (curve.chainId !== 1)
|
|
654
|
+
throw Error("There is no getDeployedGaugeMirrorAddressByTx method on sidechain network");
|
|
655
|
+
return [4 /*yield*/, tx.wait()];
|
|
656
|
+
case 1:
|
|
657
|
+
txInfo = _a.sent();
|
|
658
|
+
if (!txInfo)
|
|
659
|
+
throw Error("Can't get tx info");
|
|
660
|
+
// @ts-ignore
|
|
661
|
+
return [2 /*return*/, txInfo.logs[1].args[txInfo.logs[1].args.length - 1].toLowerCase()];
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
}); };
|
|
648
665
|
export var getDeployedGaugeMirrorAddress = function (chainId) { return __awaiter(void 0, void 0, void 0, function () {
|
|
649
666
|
var contract, gaugeCount, currentIndex;
|
|
650
667
|
return __generator(this, function (_a) {
|
package/lib/index.d.ts
CHANGED
|
@@ -71,6 +71,7 @@ declare const curve: {
|
|
|
71
71
|
getDeployedMetaPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
72
72
|
getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
73
73
|
getDeployedGaugeMirrorAddress: (chainId: number) => Promise<string>;
|
|
74
|
+
getDeployedGaugeMirrorAddressByTx: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
74
75
|
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
75
76
|
gaugeImplementation: () => string;
|
|
76
77
|
estimateGas: {
|
|
@@ -101,6 +102,7 @@ declare const curve: {
|
|
|
101
102
|
getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
102
103
|
getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
103
104
|
getDeployedGaugeMirrorAddress: (chainId: number) => Promise<string>;
|
|
105
|
+
getDeployedGaugeMirrorAddressByTx: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
104
106
|
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
105
107
|
gaugeImplementation: () => string;
|
|
106
108
|
estimateGas: {
|
|
@@ -121,6 +123,7 @@ declare const curve: {
|
|
|
121
123
|
getDeployedPoolAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
122
124
|
getDeployedGaugeAddress: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
123
125
|
getDeployedGaugeMirrorAddress: (chainId: number) => Promise<string>;
|
|
126
|
+
getDeployedGaugeMirrorAddressByTx: (tx: ethers.ContractTransactionResponse) => Promise<string>;
|
|
124
127
|
fetchRecentlyDeployedPool: (poolAddress: string) => Promise<string>;
|
|
125
128
|
gaugeImplementation: () => string;
|
|
126
129
|
estimateGas: {
|
package/lib/index.js
CHANGED
|
@@ -40,7 +40,7 @@ import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceIm
|
|
|
40
40
|
import { curve as _curve } from "./curve.js";
|
|
41
41
|
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
|
|
42
42
|
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
|
|
43
|
-
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, } from './factory/deploy.js';
|
|
43
|
+
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, getDeployedGaugeMirrorAddressByTx, } from './factory/deploy.js';
|
|
44
44
|
function init(providerType, providerSettings, options) {
|
|
45
45
|
if (options === void 0) { options = {}; }
|
|
46
46
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -105,6 +105,7 @@ var curve = {
|
|
|
105
105
|
getDeployedMetaPoolAddress: getDeployedStableMetaPoolAddress,
|
|
106
106
|
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
107
107
|
getDeployedGaugeMirrorAddress: getDeployedGaugeMirrorAddress,
|
|
108
|
+
getDeployedGaugeMirrorAddressByTx: getDeployedGaugeMirrorAddressByTx,
|
|
108
109
|
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedFactoryPool,
|
|
109
110
|
gaugeImplementation: function () { return _curve.getGaugeImplementation("factory"); },
|
|
110
111
|
estimateGas: {
|
|
@@ -147,6 +148,7 @@ var curve = {
|
|
|
147
148
|
getDeployedPoolAddress: getDeployedCryptoPoolAddress,
|
|
148
149
|
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
149
150
|
getDeployedGaugeMirrorAddress: getDeployedGaugeMirrorAddress,
|
|
151
|
+
getDeployedGaugeMirrorAddressByTx: getDeployedGaugeMirrorAddressByTx,
|
|
150
152
|
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedCryptoFactoryPool,
|
|
151
153
|
gaugeImplementation: function () { return _curve.getGaugeImplementation("factory-crypto"); },
|
|
152
154
|
estimateGas: {
|
|
@@ -179,6 +181,7 @@ var curve = {
|
|
|
179
181
|
getDeployedPoolAddress: getDeployedTricryptoPoolAddress,
|
|
180
182
|
getDeployedGaugeAddress: getDeployedGaugeAddress,
|
|
181
183
|
getDeployedGaugeMirrorAddress: getDeployedGaugeMirrorAddress,
|
|
184
|
+
getDeployedGaugeMirrorAddressByTx: getDeployedGaugeMirrorAddressByTx,
|
|
182
185
|
fetchRecentlyDeployedPool: _curve.fetchRecentlyDeployedTricryptoFactoryPool,
|
|
183
186
|
gaugeImplementation: function () { return _curve.getGaugeImplementation("factory-tricrypto"); },
|
|
184
187
|
estimateGas: {
|
package/lib/interfaces.d.ts
CHANGED
package/lib/pools/utils.js
CHANGED
|
@@ -489,7 +489,7 @@ export var _getAmplificationCoefficientsFromApi = function () { return __awaiter
|
|
|
489
489
|
extendedPoolData = allTypesExtendedPoolData_1[_i];
|
|
490
490
|
for (_a = 0, _b = extendedPoolData.poolData; _a < _b.length; _a++) {
|
|
491
491
|
pool = _b[_a];
|
|
492
|
-
amplificationCoefficientDict[pool.address] = Number(pool.amplificationCoefficient);
|
|
492
|
+
amplificationCoefficientDict[pool.address.toLowerCase()] = Number(pool.amplificationCoefficient);
|
|
493
493
|
}
|
|
494
494
|
}
|
|
495
495
|
return [2 /*return*/, amplificationCoefficientDict];
|
package/lib/router.js
CHANGED
|
@@ -63,59 +63,16 @@ import { getPool } from "./pools/index.js";
|
|
|
63
63
|
import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
|
|
64
64
|
var MAX_STEPS = 5;
|
|
65
65
|
var ROUTE_LENGTH = (MAX_STEPS * 2) + 1;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var
|
|
69
|
-
|
|
70
|
-
return "4";
|
|
71
|
-
if (swapType === 7)
|
|
72
|
-
return "5";
|
|
73
|
-
return swapType.toString();
|
|
74
|
-
};
|
|
75
|
-
var _getNewRoute = function (routeTvl, poolId, swapAddress, inputCoinAddress, outputCoinAddress, swapParams, // i, j, swap_type, pool_type, n_coins
|
|
76
|
-
poolAddress, basePool, baseToken, secondBasePool, secondBaseToken, tvl) {
|
|
77
|
-
var routePoolIdsPlusSwapType = routeTvl.route.map(function (s) { return s.poolId + "+" + _handleSwapType(s.swapParams[2]); });
|
|
78
|
-
// Steps <= MAX_STEPS
|
|
79
|
-
if (routePoolIdsPlusSwapType.length >= MAX_STEPS)
|
|
80
|
-
return { route: [], minTvl: Infinity, totalTvl: 0 };
|
|
81
|
-
// Exclude such cases as cvxeth -> tricrypto2 -> tricrypto2 -> susd
|
|
82
|
-
if (routePoolIdsPlusSwapType.includes(poolId + "+" + _handleSwapType(swapParams[2])))
|
|
83
|
-
return { route: [], minTvl: Infinity, totalTvl: 0 };
|
|
84
|
-
return {
|
|
85
|
-
route: __spreadArray(__spreadArray([], routeTvl.route, true), [
|
|
86
|
-
{ poolId: poolId, swapAddress: swapAddress, inputCoinAddress: inputCoinAddress, outputCoinAddress: outputCoinAddress, swapParams: swapParams, poolAddress: poolAddress, basePool: basePool, baseToken: baseToken, secondBasePool: secondBasePool, secondBaseToken: secondBaseToken },
|
|
87
|
-
], false),
|
|
88
|
-
minTvl: Math.min(tvl, routeTvl.minTvl),
|
|
89
|
-
totalTvl: routeTvl.totalTvl + tvl,
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
var MAX_ROUTES_FOR_ONE_COIN = 3;
|
|
93
|
-
var _filterRoutes = function (routes, inputCoinAddress, sortFn) {
|
|
94
|
-
return routes
|
|
95
|
-
.filter(function (r) { return r.route.length > 0; })
|
|
96
|
-
.filter(function (r) { return r.route[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
|
|
97
|
-
.filter(function (r, i, _routes) {
|
|
66
|
+
var GRAPH_MAX_EDGES = 3;
|
|
67
|
+
var MAX_ROUTES_FOR_ONE_COIN = 5;
|
|
68
|
+
var _removeDuplications = function (routes) {
|
|
69
|
+
return routes.filter(function (r, i, _routes) {
|
|
98
70
|
var routesByPoolIds = _routes.map(function (r) { return r.route.map(function (s) { return s.poolId; }).toString(); });
|
|
99
71
|
return routesByPoolIds.indexOf(r.route.map(function (s) { return s.poolId; }).toString()) === i;
|
|
100
|
-
})
|
|
101
|
-
.sort(sortFn).slice(0, MAX_ROUTES_FOR_ONE_COIN);
|
|
72
|
+
});
|
|
102
73
|
};
|
|
103
74
|
var _sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.route.length - b.route.length; };
|
|
104
75
|
var _sortByLength = function (a, b) { return a.route.length - b.route.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
|
|
105
|
-
var _updateRoutes = function (inputCoinAddress, routesByTvl, routesByLength, poolId, swapAddress, inCoin, outCoin, swapParams, // i, j, swap_type, pool_type, n_coins
|
|
106
|
-
poolAddress, basePool, baseToken, secondBasePool, secondBaseToken, tvl) {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
var newRoutesByTvl = routesByTvl[inCoin].map(function (route) {
|
|
109
|
-
return _getNewRoute(route, poolId, swapAddress, inCoin, outCoin, swapParams, poolAddress, basePool, baseToken, secondBasePool, secondBaseToken, tvl);
|
|
110
|
-
});
|
|
111
|
-
var newRoutesByLength = routesByLength[inCoin].map(function (route) {
|
|
112
|
-
return _getNewRoute(route, poolId, swapAddress, inCoin, outCoin, swapParams, poolAddress, basePool, baseToken, secondBasePool, secondBaseToken, tvl);
|
|
113
|
-
});
|
|
114
|
-
routesByTvl[outCoin] = __spreadArray(__spreadArray([], ((_a = routesByTvl[outCoin]) !== null && _a !== void 0 ? _a : []), true), newRoutesByTvl, true);
|
|
115
|
-
routesByTvl[outCoin] = _filterRoutes(routesByTvl[outCoin], inputCoinAddress, _sortByTvl);
|
|
116
|
-
routesByLength[outCoin] = __spreadArray(__spreadArray([], ((_b = routesByLength[outCoin]) !== null && _b !== void 0 ? _b : []), true), newRoutesByLength, true);
|
|
117
|
-
routesByLength[outCoin] = _filterRoutes(routesByLength[outCoin], inputCoinAddress, _sortByLength);
|
|
118
|
-
};
|
|
119
76
|
var _getTVL = memoize(function (poolId) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
120
77
|
switch (_b.label) {
|
|
121
78
|
case 0:
|
|
@@ -127,6 +84,15 @@ var _getTVL = memoize(function (poolId) { return __awaiter(void 0, void 0, void
|
|
|
127
84
|
promise: true,
|
|
128
85
|
maxAge: 5 * 60 * 1000, // 5m
|
|
129
86
|
});
|
|
87
|
+
// 4 --> 6, 5 --> 7 not allowed
|
|
88
|
+
// 4 --> 7, 5 --> 6 allowed
|
|
89
|
+
var _handleSwapType = function (swapType) {
|
|
90
|
+
if (swapType === 6)
|
|
91
|
+
return "4";
|
|
92
|
+
if (swapType === 7)
|
|
93
|
+
return "5";
|
|
94
|
+
return swapType.toString();
|
|
95
|
+
};
|
|
130
96
|
var SNX = {
|
|
131
97
|
1: {
|
|
132
98
|
swap: "0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F".toLowerCase(),
|
|
@@ -147,226 +113,384 @@ var SNX = {
|
|
|
147
113
|
].map(function (a) { return a.toLowerCase(); }),
|
|
148
114
|
},
|
|
149
115
|
};
|
|
150
|
-
|
|
151
|
-
var
|
|
152
|
-
var
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return __generator(this, function (_s) {
|
|
156
|
-
switch (_s.label) {
|
|
116
|
+
var _buildRouteGraph = memoize(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
117
|
+
var routerGraph, _i, _a, outCoin, _b, _c, inCoin, _d, _e, outCoin, ALL_POOLS, amplificationCoefficientDict, _f, ALL_POOLS_1, _h, poolId, poolData, wrappedCoinAddresses, underlyingCoinAddresses, poolAddress, tokenAddress, isAaveLikeLending, poolType, tvlMultiplier, basePool, basePoolAddress, baseTokenAddress, secondBasePool, secondBasePoolAddress, secondBaseTokenAddress, metaCoinAddresses, swapAddress, tvl, coins, k, l, i, j, swapType, coins, k, l, i, j, swapType, i, j, i, j, hasEth, swapType;
|
|
118
|
+
var _j, _k, _l;
|
|
119
|
+
return __generator(this, function (_m) {
|
|
120
|
+
switch (_m.label) {
|
|
157
121
|
case 0:
|
|
158
|
-
|
|
159
|
-
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
160
|
-
ALL_POOLS = Object.entries(curve.getPoolsData()).filter(function (_a) {
|
|
161
|
-
var id = _a[0], _ = _a[1];
|
|
162
|
-
return id !== "crveth";
|
|
163
|
-
});
|
|
164
|
-
return [4 /*yield*/, _getAmplificationCoefficientsFromApi()];
|
|
165
|
-
case 1:
|
|
166
|
-
amplificationCoefficientDict = _s.sent();
|
|
167
|
-
curCoins = [inputCoinAddress];
|
|
168
|
-
nextCoins = new Set();
|
|
169
|
-
routesByTvl = (_h = {},
|
|
170
|
-
_h[inputCoinAddress] = [{ route: [], minTvl: Infinity, totalTvl: 0 }],
|
|
171
|
-
_h);
|
|
172
|
-
routesByLength = (_j = {},
|
|
173
|
-
_j[inputCoinAddress] = [{ route: [], minTvl: Infinity, totalTvl: 0 }],
|
|
174
|
-
_j);
|
|
175
|
-
step = 0;
|
|
176
|
-
_s.label = 2;
|
|
177
|
-
case 2:
|
|
178
|
-
if (!(step < MAX_STEPS)) return [3 /*break*/, 10];
|
|
179
|
-
_i = 0, curCoins_1 = curCoins;
|
|
180
|
-
_s.label = 3;
|
|
181
|
-
case 3:
|
|
182
|
-
if (!(_i < curCoins_1.length)) return [3 /*break*/, 8];
|
|
183
|
-
inCoin = curCoins_1[_i];
|
|
122
|
+
routerGraph = {};
|
|
184
123
|
// ETH <-> WETH (exclude Celo)
|
|
185
|
-
if (curve.chainId !== 42220
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
124
|
+
if (curve.chainId !== 42220) {
|
|
125
|
+
routerGraph[curve.constants.NATIVE_TOKEN.address] = {};
|
|
126
|
+
routerGraph[curve.constants.NATIVE_TOKEN.address][curve.constants.NATIVE_TOKEN.wrappedAddress] = [{
|
|
127
|
+
poolId: "WETH wrapper",
|
|
128
|
+
swapAddress: curve.constants.NATIVE_TOKEN.wrappedAddress,
|
|
129
|
+
inputCoinAddress: curve.constants.NATIVE_TOKEN.address,
|
|
130
|
+
outputCoinAddress: curve.constants.NATIVE_TOKEN.wrappedAddress,
|
|
131
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
132
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
133
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
134
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
135
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
136
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
137
|
+
tvl: Infinity,
|
|
138
|
+
}];
|
|
139
|
+
routerGraph[curve.constants.NATIVE_TOKEN.wrappedAddress] = {};
|
|
140
|
+
routerGraph[curve.constants.NATIVE_TOKEN.wrappedAddress][curve.constants.NATIVE_TOKEN.address] = [{
|
|
141
|
+
poolId: "WETH wrapper",
|
|
142
|
+
swapAddress: curve.constants.NATIVE_TOKEN.wrappedAddress,
|
|
143
|
+
inputCoinAddress: curve.constants.NATIVE_TOKEN.wrappedAddress,
|
|
144
|
+
outputCoinAddress: curve.constants.NATIVE_TOKEN.address,
|
|
145
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
146
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
147
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
148
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
149
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
150
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
151
|
+
tvl: Infinity,
|
|
152
|
+
}];
|
|
189
153
|
}
|
|
190
154
|
// ETH -> stETH, ETH -> frxETH, ETH -> wBETH (Ethereum only)
|
|
191
|
-
if (curve.chainId == 1
|
|
192
|
-
for (
|
|
193
|
-
outCoin =
|
|
194
|
-
|
|
195
|
-
|
|
155
|
+
if (curve.chainId == 1) {
|
|
156
|
+
for (_i = 0, _a = ["stETH", "frxETH", "wBETH"]; _i < _a.length; _i++) {
|
|
157
|
+
outCoin = _a[_i];
|
|
158
|
+
routerGraph[curve.constants.NATIVE_TOKEN.address][curve.constants.COINS[outCoin.toLowerCase()]] = [{
|
|
159
|
+
poolId: outCoin + " minter",
|
|
160
|
+
swapAddress: outCoin === "frxETH" ? "0xbAFA44EFE7901E04E39Dad13167D089C559c1138".toLowerCase() : curve.constants.COINS[outCoin.toLowerCase()],
|
|
161
|
+
inputCoinAddress: curve.constants.NATIVE_TOKEN.address,
|
|
162
|
+
outputCoinAddress: curve.constants.COINS[outCoin.toLowerCase()],
|
|
163
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
164
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
165
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
166
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
167
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
168
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
169
|
+
tvl: Infinity,
|
|
170
|
+
}];
|
|
196
171
|
}
|
|
197
172
|
}
|
|
198
173
|
// stETH <-> wstETH (Ethereum only)
|
|
199
|
-
if (curve.chainId === 1
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
174
|
+
if (curve.chainId === 1) {
|
|
175
|
+
routerGraph[curve.constants.COINS.steth] = {};
|
|
176
|
+
routerGraph[curve.constants.COINS.steth][curve.constants.COINS.wsteth] = [{
|
|
177
|
+
poolId: "wstETH wrapper",
|
|
178
|
+
swapAddress: curve.constants.COINS.wsteth,
|
|
179
|
+
inputCoinAddress: curve.constants.COINS.steth,
|
|
180
|
+
outputCoinAddress: curve.constants.COINS.wsteth,
|
|
181
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
182
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
183
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
184
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
185
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
186
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
187
|
+
tvl: Infinity,
|
|
188
|
+
}];
|
|
189
|
+
routerGraph[curve.constants.COINS.wsteth] = {};
|
|
190
|
+
routerGraph[curve.constants.COINS.wsteth][curve.constants.COINS.steth] = [{
|
|
191
|
+
poolId: "wstETH wrapper",
|
|
192
|
+
swapAddress: curve.constants.COINS.wsteth,
|
|
193
|
+
inputCoinAddress: curve.constants.COINS.wsteth,
|
|
194
|
+
outputCoinAddress: curve.constants.COINS.steth,
|
|
195
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
196
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
197
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
198
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
199
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
200
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
201
|
+
tvl: Infinity,
|
|
202
|
+
}];
|
|
203
203
|
}
|
|
204
204
|
// frxETH <-> sfrxETH (Ethereum only)
|
|
205
|
-
if (curve.chainId === 1
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
205
|
+
if (curve.chainId === 1) {
|
|
206
|
+
routerGraph[curve.constants.COINS.frxeth] = {};
|
|
207
|
+
routerGraph[curve.constants.COINS.frxeth][curve.constants.COINS.sfrxeth] = [{
|
|
208
|
+
poolId: "sfrxETH wrapper",
|
|
209
|
+
swapAddress: curve.constants.COINS.sfrxeth,
|
|
210
|
+
inputCoinAddress: curve.constants.COINS.frxeth,
|
|
211
|
+
outputCoinAddress: curve.constants.COINS.sfrxeth,
|
|
212
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
213
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
214
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
215
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
216
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
217
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
218
|
+
tvl: Infinity,
|
|
219
|
+
}];
|
|
220
|
+
routerGraph[curve.constants.COINS.sfrxeth] = {};
|
|
221
|
+
routerGraph[curve.constants.COINS.sfrxeth][curve.constants.COINS.frxeth] = [{
|
|
222
|
+
poolId: "sfrxETH wrapper",
|
|
223
|
+
swapAddress: curve.constants.COINS.sfrxeth,
|
|
224
|
+
inputCoinAddress: curve.constants.COINS.sfrxeth,
|
|
225
|
+
outputCoinAddress: curve.constants.COINS.frxeth,
|
|
226
|
+
swapParams: [0, 0, 8, 0, 0],
|
|
227
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
228
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
229
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
230
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
231
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
232
|
+
tvl: Infinity,
|
|
233
|
+
}];
|
|
209
234
|
}
|
|
210
235
|
// SNX swaps
|
|
211
|
-
|
|
212
|
-
if (((_l = (_k = SNX[curve.chainId]) === null || _k === void 0 ? void 0 : _k.coins) !== null && _l !== void 0 ? _l : []).includes(inCoin)) {
|
|
236
|
+
if (curve.chainId in SNX) {
|
|
213
237
|
// @ts-ignore
|
|
214
|
-
for (
|
|
215
|
-
|
|
216
|
-
if (inCoin === outCoin)
|
|
217
|
-
continue;
|
|
218
|
-
_updateRoutes(inputCoinAddress, routesByTvl, routesByLength, "SNX exchange",
|
|
238
|
+
for (_b = 0, _c = SNX[curve.chainId].coins; _b < _c.length; _b++) {
|
|
239
|
+
inCoin = _c[_b];
|
|
219
240
|
// @ts-ignore
|
|
220
|
-
|
|
221
|
-
|
|
241
|
+
for (_d = 0, _e = SNX[curve.chainId].coins; _d < _e.length; _d++) {
|
|
242
|
+
outCoin = _e[_d];
|
|
243
|
+
if (inCoin === outCoin)
|
|
244
|
+
continue;
|
|
245
|
+
if (!routerGraph[inCoin])
|
|
246
|
+
routerGraph[inCoin] = {};
|
|
247
|
+
routerGraph[inCoin][outCoin] = [{
|
|
248
|
+
poolId: "SNX exchanger",
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
swapAddress: SNX[curve.chainId].swap,
|
|
251
|
+
inputCoinAddress: inCoin,
|
|
252
|
+
outputCoinAddress: outCoin,
|
|
253
|
+
swapParams: [0, 0, 9, 0, 0],
|
|
254
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
255
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
256
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
257
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
258
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
259
|
+
tvl: Infinity,
|
|
260
|
+
}];
|
|
261
|
+
}
|
|
222
262
|
}
|
|
223
263
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
264
|
+
ALL_POOLS = Object.entries(curve.getPoolsData()).filter(function (_a) {
|
|
265
|
+
var id = _a[0], _ = _a[1];
|
|
266
|
+
return id !== "crveth";
|
|
267
|
+
});
|
|
268
|
+
return [4 /*yield*/, _getAmplificationCoefficientsFromApi()];
|
|
269
|
+
case 1:
|
|
270
|
+
amplificationCoefficientDict = _m.sent();
|
|
271
|
+
_f = 0, ALL_POOLS_1 = ALL_POOLS;
|
|
272
|
+
_m.label = 2;
|
|
273
|
+
case 2:
|
|
274
|
+
if (!(_f < ALL_POOLS_1.length)) return [3 /*break*/, 5];
|
|
275
|
+
_h = ALL_POOLS_1[_f], poolId = _h[0], poolData = _h[1];
|
|
276
|
+
wrappedCoinAddresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
277
|
+
underlyingCoinAddresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
278
|
+
poolAddress = poolData.swap_address.toLowerCase();
|
|
279
|
+
tokenAddress = poolData.token_address.toLowerCase();
|
|
280
|
+
isAaveLikeLending = poolData.is_lending && wrappedCoinAddresses.length === 3 && !poolData.deposit_address;
|
|
281
|
+
poolType = poolData.is_llamma ? 4 : poolData.is_crypto ? Math.min(poolData.wrapped_coins.length, 3) : 1;
|
|
282
|
+
tvlMultiplier = poolData.is_crypto ? 1 : ((_j = amplificationCoefficientDict[poolData.swap_address]) !== null && _j !== void 0 ? _j : 1);
|
|
283
|
+
basePool = poolData.is_meta ? __assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA)[poolData.base_pool] : null;
|
|
284
|
+
basePoolAddress = basePool ? basePool.swap_address.toLowerCase() : curve.constants.ZERO_ADDRESS;
|
|
285
|
+
baseTokenAddress = basePool ? basePool.token_address.toLowerCase() : curve.constants.ZERO_ADDRESS;
|
|
286
|
+
secondBasePool = basePool && basePool.base_pool ? __assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRVUSD_FACTORY_POOLS_DATA)[basePool.base_pool] : null;
|
|
287
|
+
secondBasePoolAddress = secondBasePool ? secondBasePool.swap_address.toLowerCase() : curve.constants.ZERO_ADDRESS;
|
|
241
288
|
// for double meta underlying (crv/tricrypto, wmatic/tricrypto)
|
|
242
|
-
if (
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
inCoinIndexes = {
|
|
248
|
-
wrapped_coin: wrapped_coin_addresses.indexOf(inCoin),
|
|
249
|
-
underlying_coin: underlying_coin_addresses.indexOf(inCoin),
|
|
250
|
-
meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(inCoin) : -1,
|
|
251
|
-
};
|
|
252
|
-
// Skip pools which don't contain inCoin
|
|
253
|
-
if (inCoinIndexes.wrapped_coin === -1 && inCoinIndexes.underlying_coin === -1 && inCoinIndexes.meta_coin === -1 && inCoin !== token_address)
|
|
254
|
-
return [3 /*break*/, 6];
|
|
289
|
+
if (basePool && secondBasePoolAddress !== curve.constants.ZERO_ADDRESS)
|
|
290
|
+
baseTokenAddress = (_k = basePool.deposit_address) === null || _k === void 0 ? void 0 : _k.toLowerCase();
|
|
291
|
+
secondBaseTokenAddress = secondBasePool ? secondBasePool.token_address.toLowerCase() : curve.constants.ZERO_ADDRESS;
|
|
292
|
+
metaCoinAddresses = basePool ? basePool.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); }) : [];
|
|
293
|
+
swapAddress = poolData.is_fake ? (_l = poolData.deposit_address) === null || _l === void 0 ? void 0 : _l.toLowerCase() : poolAddress;
|
|
255
294
|
return [4 /*yield*/, _getTVL(poolId)];
|
|
256
|
-
case
|
|
257
|
-
tvl = (
|
|
295
|
+
case 3:
|
|
296
|
+
tvl = (_m.sent()) * tvlMultiplier;
|
|
258
297
|
// Skip empty pools
|
|
259
298
|
if (curve.chainId === 1 && tvl < 1000)
|
|
260
|
-
return [3 /*break*/,
|
|
299
|
+
return [3 /*break*/, 4];
|
|
261
300
|
if (curve.chainId !== 1 && tvl < 100)
|
|
262
|
-
return [3 /*break*/,
|
|
263
|
-
//
|
|
264
|
-
if (!poolData.is_fake && !poolData.is_llamma &&
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
301
|
+
return [3 /*break*/, 4];
|
|
302
|
+
// Wrapped coin <-> LP "swaps" (actually add_liquidity/remove_liquidity_one_coin)
|
|
303
|
+
if (!poolData.is_fake && !poolData.is_llamma && wrappedCoinAddresses.length < 6) {
|
|
304
|
+
coins = __spreadArray([tokenAddress], wrappedCoinAddresses, true);
|
|
305
|
+
for (k = 0; k < coins.length; k++) {
|
|
306
|
+
for (l = 0; l < coins.length; l++) {
|
|
307
|
+
if (k > 0 && l > 0)
|
|
308
|
+
continue;
|
|
309
|
+
i = Math.max(k - 1, 0);
|
|
310
|
+
j = Math.max(l - 1, 0);
|
|
311
|
+
swapType = k == 0 ? 6 : 4;
|
|
312
|
+
if (!routerGraph[coins[k]])
|
|
313
|
+
routerGraph[coins[k]] = {};
|
|
314
|
+
if (!routerGraph[coins[k]][coins[l]])
|
|
315
|
+
routerGraph[coins[k]][coins[l]] = [];
|
|
316
|
+
routerGraph[coins[k]][coins[l]].push({
|
|
317
|
+
poolId: poolId,
|
|
318
|
+
swapAddress: swapAddress,
|
|
319
|
+
inputCoinAddress: coins[k],
|
|
320
|
+
outputCoinAddress: coins[l],
|
|
321
|
+
swapParams: [i, j, swapType, poolType, wrappedCoinAddresses.length],
|
|
322
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
323
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
324
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
325
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
326
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
327
|
+
tvl: tvl,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
274
330
|
}
|
|
275
331
|
}
|
|
276
|
-
//
|
|
277
|
-
if ((poolData.is_fake ||
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
332
|
+
// Underlying coin <-> LP "swaps" (actually add_liquidity/remove_liquidity_one_coin)
|
|
333
|
+
if ((poolData.is_fake || isAaveLikeLending) && underlyingCoinAddresses.length < 6) {
|
|
334
|
+
coins = __spreadArray([tokenAddress], underlyingCoinAddresses, true);
|
|
335
|
+
for (k = 0; k < coins.length; k++) {
|
|
336
|
+
for (l = 0; l < coins.length; l++) {
|
|
337
|
+
if (k > 0 && l > 0)
|
|
338
|
+
continue;
|
|
339
|
+
i = Math.max(k - 1, 0);
|
|
340
|
+
j = Math.max(l - 1, 0);
|
|
341
|
+
swapType = isAaveLikeLending ? 7 : 6;
|
|
342
|
+
if (k > 0)
|
|
343
|
+
swapType = isAaveLikeLending ? 5 : 4;
|
|
344
|
+
if (!routerGraph[coins[k]])
|
|
345
|
+
routerGraph[coins[k]] = {};
|
|
346
|
+
if (!routerGraph[coins[k]][coins[l]])
|
|
347
|
+
routerGraph[coins[k]][coins[l]] = [];
|
|
348
|
+
routerGraph[coins[k]][coins[l]].push({
|
|
349
|
+
poolId: poolId,
|
|
350
|
+
swapAddress: swapAddress,
|
|
351
|
+
inputCoinAddress: coins[k],
|
|
352
|
+
outputCoinAddress: coins[l],
|
|
353
|
+
swapParams: [i, j, swapType, poolType, underlyingCoinAddresses.length],
|
|
354
|
+
poolAddress: curve.constants.ZERO_ADDRESS,
|
|
355
|
+
basePool: curve.constants.ZERO_ADDRESS,
|
|
356
|
+
baseToken: curve.constants.ZERO_ADDRESS,
|
|
357
|
+
secondBasePool: curve.constants.ZERO_ADDRESS,
|
|
358
|
+
secondBaseToken: curve.constants.ZERO_ADDRESS,
|
|
359
|
+
tvl: tvl,
|
|
360
|
+
});
|
|
361
|
+
}
|
|
305
362
|
}
|
|
306
363
|
}
|
|
307
364
|
// Wrapped swaps
|
|
308
|
-
if (
|
|
309
|
-
for (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
365
|
+
if (!poolData.is_fake) {
|
|
366
|
+
for (i = 0; i < wrappedCoinAddresses.length; i++) {
|
|
367
|
+
for (j = 0; j < wrappedCoinAddresses.length; j++) {
|
|
368
|
+
if (i == j)
|
|
369
|
+
continue;
|
|
370
|
+
if (!routerGraph[wrappedCoinAddresses[i]])
|
|
371
|
+
routerGraph[wrappedCoinAddresses[i]] = {};
|
|
372
|
+
if (!routerGraph[wrappedCoinAddresses[i]][wrappedCoinAddresses[j]])
|
|
373
|
+
routerGraph[wrappedCoinAddresses[i]][wrappedCoinAddresses[j]] = [];
|
|
374
|
+
routerGraph[wrappedCoinAddresses[i]][wrappedCoinAddresses[j]] = routerGraph[wrappedCoinAddresses[i]][wrappedCoinAddresses[j]].concat({
|
|
375
|
+
poolId: poolId,
|
|
376
|
+
swapAddress: swapAddress,
|
|
377
|
+
inputCoinAddress: wrappedCoinAddresses[i],
|
|
378
|
+
outputCoinAddress: wrappedCoinAddresses[j],
|
|
379
|
+
swapParams: [i, j, 1, poolType, wrappedCoinAddresses.length],
|
|
380
|
+
poolAddress: poolAddress,
|
|
381
|
+
basePool: basePoolAddress,
|
|
382
|
+
baseToken: baseTokenAddress,
|
|
383
|
+
secondBasePool: secondBasePoolAddress,
|
|
384
|
+
secondBaseToken: secondBaseTokenAddress,
|
|
385
|
+
tvl: tvl,
|
|
386
|
+
}).sort(function (a, b) { return b.tvl - a.tvl; }).slice(0, GRAPH_MAX_EDGES);
|
|
387
|
+
}
|
|
323
388
|
}
|
|
324
389
|
}
|
|
325
390
|
// Only for underlying swaps
|
|
326
|
-
|
|
391
|
+
swapAddress = (poolData.is_crypto && poolData.is_meta) || ((basePool === null || basePool === void 0 ? void 0 : basePool.is_lending) && poolData.is_factory) ?
|
|
327
392
|
poolData.deposit_address : poolData.swap_address;
|
|
328
393
|
// Underlying swaps
|
|
329
|
-
if (!poolData.is_plain
|
|
330
|
-
for (
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
:
|
|
349
|
-
|
|
350
|
-
|
|
394
|
+
if (!poolData.is_plain) {
|
|
395
|
+
for (i = 0; i < underlyingCoinAddresses.length; i++) {
|
|
396
|
+
for (j = 0; j < underlyingCoinAddresses.length; j++) {
|
|
397
|
+
if (i === j)
|
|
398
|
+
continue;
|
|
399
|
+
// Don't swap metacoins since they can be swapped directly in base pool
|
|
400
|
+
if (metaCoinAddresses.includes(underlyingCoinAddresses[i]) && metaCoinAddresses.includes(underlyingCoinAddresses[j]))
|
|
401
|
+
continue;
|
|
402
|
+
hasEth = [underlyingCoinAddresses[i], underlyingCoinAddresses[j]].includes(curve.constants.NATIVE_TOKEN.address);
|
|
403
|
+
swapType = (poolData.is_crypto && poolData.is_meta && poolData.is_factory) || ((basePool === null || basePool === void 0 ? void 0 : basePool.is_lending) && poolData.is_factory) ? 3
|
|
404
|
+
: hasEth && poolId !== 'avaxcrypto' ? 1 : 2;
|
|
405
|
+
if (!routerGraph[underlyingCoinAddresses[i]])
|
|
406
|
+
routerGraph[underlyingCoinAddresses[i]] = {};
|
|
407
|
+
if (!routerGraph[underlyingCoinAddresses[i]][underlyingCoinAddresses[j]])
|
|
408
|
+
routerGraph[underlyingCoinAddresses[i]][underlyingCoinAddresses[j]] = [];
|
|
409
|
+
routerGraph[underlyingCoinAddresses[i]][underlyingCoinAddresses[j]] = routerGraph[underlyingCoinAddresses[i]][underlyingCoinAddresses[j]].concat({
|
|
410
|
+
poolId: poolId,
|
|
411
|
+
swapAddress: swapAddress,
|
|
412
|
+
inputCoinAddress: underlyingCoinAddresses[i],
|
|
413
|
+
outputCoinAddress: underlyingCoinAddresses[j],
|
|
414
|
+
swapParams: [i, j, swapType, poolType, underlyingCoinAddresses.length],
|
|
415
|
+
poolAddress: poolAddress,
|
|
416
|
+
basePool: basePoolAddress,
|
|
417
|
+
baseToken: baseTokenAddress,
|
|
418
|
+
secondBasePool: secondBasePoolAddress,
|
|
419
|
+
secondBaseToken: secondBaseTokenAddress,
|
|
420
|
+
tvl: tvl,
|
|
421
|
+
}).sort(function (a, b) { return b.tvl - a.tvl; }).slice(0, GRAPH_MAX_EDGES);
|
|
422
|
+
}
|
|
351
423
|
}
|
|
352
424
|
}
|
|
353
|
-
|
|
354
|
-
case
|
|
355
|
-
|
|
356
|
-
return [3 /*break*/, 4];
|
|
357
|
-
case 7:
|
|
358
|
-
_i++;
|
|
359
|
-
return [3 /*break*/, 3];
|
|
360
|
-
case 8:
|
|
361
|
-
curCoins = Array.from(nextCoins);
|
|
362
|
-
nextCoins = new Set();
|
|
363
|
-
_s.label = 9;
|
|
364
|
-
case 9:
|
|
365
|
-
step++;
|
|
425
|
+
_m.label = 4;
|
|
426
|
+
case 4:
|
|
427
|
+
_f++;
|
|
366
428
|
return [3 /*break*/, 2];
|
|
367
|
-
case
|
|
368
|
-
|
|
369
|
-
|
|
429
|
+
case 5: return [2 /*return*/, routerGraph];
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}); }, {
|
|
433
|
+
promise: true,
|
|
434
|
+
maxAge: 5 * 1000, // 5m
|
|
435
|
+
});
|
|
436
|
+
var _isVisitedCoin = function (coinAddress, route) {
|
|
437
|
+
return route.route.map(function (r) { return r.inputCoinAddress; }).includes(coinAddress);
|
|
438
|
+
};
|
|
439
|
+
var _isVisitedPool = function (poolId, route) {
|
|
440
|
+
return route.route.map(function (r) { return r.poolId; }).includes(poolId);
|
|
441
|
+
};
|
|
442
|
+
// Breadth-first search
|
|
443
|
+
var _findRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
444
|
+
var routes, targetRoutes, routerGraph, ALL_POOLS, route, inCoin, outCoin, _i, _a, step, poolData, routePoolIdsPlusSwapType, poolCoins;
|
|
445
|
+
return __generator(this, function (_b) {
|
|
446
|
+
switch (_b.label) {
|
|
447
|
+
case 0:
|
|
448
|
+
inputCoinAddress = inputCoinAddress.toLowerCase();
|
|
449
|
+
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
450
|
+
routes = [{ route: [], minTvl: Infinity, totalTvl: 0 }];
|
|
451
|
+
targetRoutes = [];
|
|
452
|
+
return [4 /*yield*/, _buildRouteGraph()];
|
|
453
|
+
case 1:
|
|
454
|
+
routerGraph = _b.sent();
|
|
455
|
+
ALL_POOLS = curve.getPoolsData();
|
|
456
|
+
while (routes.length > 0) {
|
|
457
|
+
route = routes.pop();
|
|
458
|
+
inCoin = route.route.length > 0 ? route.route[route.route.length - 1].outputCoinAddress : inputCoinAddress;
|
|
459
|
+
if (inCoin === outputCoinAddress) {
|
|
460
|
+
targetRoutes.push(route);
|
|
461
|
+
}
|
|
462
|
+
else if (route.route.length < 5) {
|
|
463
|
+
for (outCoin in routerGraph[inCoin]) {
|
|
464
|
+
if (_isVisitedCoin(outCoin, route))
|
|
465
|
+
continue;
|
|
466
|
+
for (_i = 0, _a = routerGraph[inCoin][outCoin]; _i < _a.length; _i++) {
|
|
467
|
+
step = _a[_i];
|
|
468
|
+
poolData = ALL_POOLS[step.poolId];
|
|
469
|
+
if (!(poolData === null || poolData === void 0 ? void 0 : poolData.is_lending) && _isVisitedPool(step.poolId, route))
|
|
470
|
+
continue;
|
|
471
|
+
routePoolIdsPlusSwapType = route.route.map(function (s) { return s.poolId + "+" + _handleSwapType(s.swapParams[2]); });
|
|
472
|
+
if (routePoolIdsPlusSwapType.includes(step.poolId + "+" + _handleSwapType(step.swapParams[2])))
|
|
473
|
+
continue;
|
|
474
|
+
poolCoins = poolData ? poolData.wrapped_coin_addresses.concat(poolData.underlying_coin_addresses) : [];
|
|
475
|
+
// Exclude such cases as:
|
|
476
|
+
// cvxeth -> tricrypto2 -> tusd -> susd (cvxeth -> tricrypto2 -> tusd instead)
|
|
477
|
+
if (!(poolData === null || poolData === void 0 ? void 0 : poolData.is_lending) && poolCoins.includes(outputCoinAddress) && outCoin !== outputCoinAddress)
|
|
478
|
+
continue;
|
|
479
|
+
// Exclude such cases as:
|
|
480
|
+
// aave -> aave -> 3pool (aave -> aave instead)
|
|
481
|
+
if ((poolData === null || poolData === void 0 ? void 0 : poolData.is_lending) && poolCoins.includes(outputCoinAddress) && outCoin !== outputCoinAddress && outCoin !== poolData.token_address)
|
|
482
|
+
continue;
|
|
483
|
+
routes.push({
|
|
484
|
+
route: __spreadArray(__spreadArray([], route.route, true), [step], false),
|
|
485
|
+
minTvl: Math.min(step.tvl, route.minTvl),
|
|
486
|
+
totalTvl: route.totalTvl + step.tvl,
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
targetRoutes = _removeDuplications(__spreadArray(__spreadArray([], targetRoutes.sort(_sortByTvl).slice(0, MAX_ROUTES_FOR_ONE_COIN), true), targetRoutes.sort(_sortByLength).slice(0, MAX_ROUTES_FOR_ONE_COIN), true));
|
|
493
|
+
return [2 /*return*/, targetRoutes.map(function (r) { return r.route; })];
|
|
370
494
|
}
|
|
371
495
|
});
|
|
372
496
|
}); };
|
|
@@ -461,7 +585,7 @@ var _getBestRoute = memoize(function (inputCoinAddress, outputCoinAddress, amoun
|
|
|
461
585
|
_amount = parseUnits(amount, inputCoinDecimals);
|
|
462
586
|
if (_amount === curve.parseUnits("0"))
|
|
463
587
|
return [2 /*return*/, []];
|
|
464
|
-
return [4 /*yield*/,
|
|
588
|
+
return [4 /*yield*/, _findRoutes(inputCoinAddress, outputCoinAddress)];
|
|
465
589
|
case 1:
|
|
466
590
|
routesRaw = (_j.sent()).map(function (route) { return ({ route: route, _output: curve.parseUnits("0"), outputUsd: 0, txCostUsd: 0 }); });
|
|
467
591
|
routes = [];
|
package/lib/utils.js
CHANGED
|
@@ -428,14 +428,14 @@ export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0,
|
|
|
428
428
|
if (lpTokenAddress.toLowerCase() in priceDict) {
|
|
429
429
|
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
430
430
|
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
431
|
-
tvl: pool.usdTotal
|
|
431
|
+
tvl: pool.usdTotal,
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
434
|
else {
|
|
435
435
|
priceDict[lpTokenAddress.toLowerCase()] = [];
|
|
436
436
|
priceDict[lpTokenAddress.toLowerCase()].push({
|
|
437
437
|
price: pool.usdTotal && totalSupply ? pool.usdTotal / totalSupply : 0,
|
|
438
|
-
tvl: pool.usdTotal
|
|
438
|
+
tvl: pool.usdTotal,
|
|
439
439
|
});
|
|
440
440
|
}
|
|
441
441
|
for (_c = 0, _d = pool.coins; _c < _d.length; _c++) {
|
|
@@ -444,14 +444,14 @@ export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0,
|
|
|
444
444
|
if (coin.address.toLowerCase() in priceDict) {
|
|
445
445
|
priceDict[coin.address.toLowerCase()].push({
|
|
446
446
|
price: coin.usdPrice,
|
|
447
|
-
tvl: pool.usdTotal
|
|
447
|
+
tvl: pool.usdTotal,
|
|
448
448
|
});
|
|
449
449
|
}
|
|
450
450
|
else {
|
|
451
451
|
priceDict[coin.address.toLowerCase()] = [];
|
|
452
452
|
priceDict[coin.address.toLowerCase()].push({
|
|
453
453
|
price: coin.usdPrice,
|
|
454
|
-
tvl: pool.usdTotal
|
|
454
|
+
tvl: pool.usdTotal,
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
}
|
|
@@ -462,14 +462,14 @@ export var _getUsdPricesFromApi = function () { return __awaiter(void 0, void 0,
|
|
|
462
462
|
if (coin.tokenAddress.toLowerCase() in priceDict) {
|
|
463
463
|
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
464
464
|
price: coin.tokenPrice,
|
|
465
|
-
tvl: pool.usdTotal
|
|
465
|
+
tvl: pool.usdTotal,
|
|
466
466
|
});
|
|
467
467
|
}
|
|
468
468
|
else {
|
|
469
469
|
priceDict[coin.tokenAddress.toLowerCase()] = [];
|
|
470
470
|
priceDict[coin.tokenAddress.toLowerCase()].push({
|
|
471
471
|
price: coin.tokenPrice,
|
|
472
|
-
tvl: pool.usdTotal
|
|
472
|
+
tvl: pool.usdTotal,
|
|
473
473
|
});
|
|
474
474
|
}
|
|
475
475
|
}
|