@curvefi/api 2.33.1 → 2.34.1
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/lib/constants/abis/llamma.json +984 -0
- package/lib/constants/coins/ethereum.js +1 -0
- package/lib/constants/pools/ethereum.d.ts +1 -0
- package/lib/constants/pools/ethereum.js +29 -0
- package/lib/constants/pools/index.d.ts +2 -1
- package/lib/constants/pools/index.js +2 -1
- package/lib/curve.d.ts +1 -0
- package/lib/curve.js +20 -12
- package/lib/factory/constants.js +1 -1
- package/lib/factory/factory-crypto.js +6 -6
- package/lib/factory/factory.js +6 -6
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +41 -19
- package/lib/router.js +56 -62
- package/package.json +1 -1
|
@@ -53,6 +53,7 @@ export var COINS_ETHEREUM = lowerCaseValues({
|
|
|
53
53
|
reth: "0x9559aaa82d9649c7a7b220e7c461d2e74c9a3593",
|
|
54
54
|
weth: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
55
55
|
frxeth: "0x5E8422345238F34275888049021821E8E08CAa1f",
|
|
56
|
+
sfrxeth: "0xac3E018457B222d93114458476f3E3416Abbe38F",
|
|
56
57
|
// --- BTC ---
|
|
57
58
|
sbtccrv: "0x075b1bb99792c9E1041bA13afEf80C91a1e70fB3",
|
|
58
59
|
hbtc: "0x0316EB71485b0Ab14103307bf65a021042c6d380",
|
|
@@ -87,6 +87,7 @@ import fraxusdcSwapABI from '../abis/fraxusdc/swap.json' assert { type: 'json' }
|
|
|
87
87
|
import frxethSwapABI from '../abis/frxeth/swap.json' assert { type: 'json' };
|
|
88
88
|
import sbtc2SwapABI from '../abis/sbtc2/swap.json' assert { type: 'json' };
|
|
89
89
|
import wbethSwapABI from '../abis/wbeth/swap.json' assert { type: 'json' };
|
|
90
|
+
import LlammaABI from '../abis/llamma.json' assert { type: 'json' };
|
|
90
91
|
export var POOLS_DATA_ETHEREUM = lowerCasePoolDataAddresses({
|
|
91
92
|
compound: {
|
|
92
93
|
name: "compound",
|
|
@@ -1643,3 +1644,31 @@ export var POOLS_DATA_ETHEREUM = lowerCasePoolDataAddresses({
|
|
|
1643
1644
|
gauge_abi: gaugeV5ABI,
|
|
1644
1645
|
},
|
|
1645
1646
|
});
|
|
1647
|
+
export var LLAMMAS_DATA_ETHEREUM = lowerCasePoolDataAddresses({
|
|
1648
|
+
'sfrxeth-llamma': {
|
|
1649
|
+
name: "sfrxeth",
|
|
1650
|
+
full_name: "sfrxeth",
|
|
1651
|
+
symbol: "sfrxeth",
|
|
1652
|
+
reference_asset: 'CRYPTO',
|
|
1653
|
+
swap_address: '0x77fCFB78151c676f390a6236A78b5d3152e43384',
|
|
1654
|
+
token_address: '0x0000000000000000000000000000000000000000',
|
|
1655
|
+
gauge_address: '0x0000000000000000000000000000000000000000',
|
|
1656
|
+
is_crypto: true,
|
|
1657
|
+
is_plain: true,
|
|
1658
|
+
is_llamma: true,
|
|
1659
|
+
underlying_coins: ['crvUSD', 'sfrxETH'],
|
|
1660
|
+
wrapped_coins: ['crvUSD', 'sfrxETH'],
|
|
1661
|
+
underlying_coin_addresses: [
|
|
1662
|
+
'0xf71040d20Cc3FFBb28c1abcEF46134C7936624e0',
|
|
1663
|
+
'0xac3E018457B222d93114458476f3E3416Abbe38F',
|
|
1664
|
+
],
|
|
1665
|
+
wrapped_coin_addresses: [
|
|
1666
|
+
'0xf71040d20Cc3FFBb28c1abcEF46134C7936624e0',
|
|
1667
|
+
'0xac3E018457B222d93114458476f3E3416Abbe38F',
|
|
1668
|
+
],
|
|
1669
|
+
underlying_decimals: [18, 18],
|
|
1670
|
+
wrapped_decimals: [18, 18],
|
|
1671
|
+
swap_abi: LlammaABI,
|
|
1672
|
+
gauge_abi: gaugeV5ABI,
|
|
1673
|
+
},
|
|
1674
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { POOLS_DATA_ETHEREUM } from "./ethereum.js";
|
|
2
|
+
import { LLAMMAS_DATA_ETHEREUM } from "./ethereum.js";
|
|
2
3
|
import { POOLS_DATA_POLYGON } from "./polygon.js";
|
|
3
4
|
import { POOLS_DATA_FANTOM } from "./fantom.js";
|
|
4
5
|
import { POOLS_DATA_AVALANCHE } from "./avalanche.js";
|
|
@@ -9,4 +10,4 @@ import { POOLS_DATA_MOONBEAM } from "./moonbeam.js";
|
|
|
9
10
|
import { POOLS_DATA_AURORA } from "./aurora.js";
|
|
10
11
|
import { POOLS_DATA_KAVA } from "./kava.js";
|
|
11
12
|
import { POOLS_DATA_CELO } from "./celo.js";
|
|
12
|
-
export { POOLS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, };
|
|
13
|
+
export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { POOLS_DATA_ETHEREUM } from "./ethereum.js";
|
|
2
|
+
import { LLAMMAS_DATA_ETHEREUM } from "./ethereum.js";
|
|
2
3
|
import { POOLS_DATA_POLYGON } from "./polygon.js";
|
|
3
4
|
import { POOLS_DATA_FANTOM } from "./fantom.js";
|
|
4
5
|
import { POOLS_DATA_AVALANCHE } from "./avalanche.js";
|
|
@@ -9,4 +10,4 @@ import { POOLS_DATA_MOONBEAM } from "./moonbeam.js";
|
|
|
9
10
|
import { POOLS_DATA_AURORA } from "./aurora.js";
|
|
10
11
|
import { POOLS_DATA_KAVA } from "./kava.js";
|
|
11
12
|
import { POOLS_DATA_CELO } from "./celo.js";
|
|
12
|
-
export { POOLS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, };
|
|
13
|
+
export { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, };
|
package/lib/curve.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ declare class Curve implements ICurve {
|
|
|
49
49
|
POOLS_DATA: IDict<IPoolData>;
|
|
50
50
|
FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
51
51
|
CRYPTO_FACTORY_POOLS_DATA: IDict<IPoolData>;
|
|
52
|
+
LLAMMAS_DATA: IDict<IPoolData>;
|
|
52
53
|
COINS: IDict<string>;
|
|
53
54
|
DECIMALS: IDict<number>;
|
|
54
55
|
GAUGES: string[];
|
package/lib/curve.js
CHANGED
|
@@ -76,7 +76,7 @@ import registryExchangeABI from './constants/abis/registry_exchange.json' assert
|
|
|
76
76
|
import streamerABI from './constants/abis/streamer.json' assert { type: 'json' };
|
|
77
77
|
import factoryABI from './constants/abis/factory.json' assert { type: 'json' };
|
|
78
78
|
import cryptoFactoryABI from './constants/abis/factory-crypto.json' assert { type: 'json' };
|
|
79
|
-
import { POOLS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, } from './constants/pools/index.js';
|
|
79
|
+
import { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, } from './constants/pools/index.js';
|
|
80
80
|
import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_POLYGON, ALIASES_FANTOM, ALIASES_AVALANCHE, ALIASES_ARBITRUM, ALIASES_XDAI, ALIASES_MOONBEAM, ALIASES_AURORA, ALIASES_KAVA, ALIASES_CELO, } from "./constants/aliases.js";
|
|
81
81
|
import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum } from "./constants/coins/ethereum.js";
|
|
82
82
|
import { COINS_OPTIMISM, cTokensOptimism, yTokensOptimism, ycTokensOptimism, aTokensOptimism } from "./constants/coins/optimism.js";
|
|
@@ -185,6 +185,7 @@ export var NETWORK_CONSTANTS = {
|
|
|
185
185
|
NAME: 'ethereum',
|
|
186
186
|
ALIASES: ALIASES_ETHEREUM,
|
|
187
187
|
POOLS_DATA: POOLS_DATA_ETHEREUM,
|
|
188
|
+
LLAMMAS_DATA: LLAMMAS_DATA_ETHEREUM,
|
|
188
189
|
COINS: COINS_ETHEREUM,
|
|
189
190
|
cTokens: cTokensEthereum,
|
|
190
191
|
yTokens: yTokensEthereum,
|
|
@@ -304,38 +305,41 @@ var Curve = /** @class */ (function () {
|
|
|
304
305
|
case 0:
|
|
305
306
|
if (this.chainId === 1313161554)
|
|
306
307
|
return [2 /*return*/];
|
|
307
|
-
if (!useApi) return [3 /*break*/,
|
|
308
|
+
if (!useApi) return [3 /*break*/, 4];
|
|
308
309
|
_a = this.constants;
|
|
309
310
|
_b = lowerCasePoolDataAddresses;
|
|
310
311
|
return [4 /*yield*/, getFactoryPoolsDataFromApi.call(this, false)];
|
|
311
312
|
case 1:
|
|
312
313
|
_a.FACTORY_POOLS_DATA = _b.apply(void 0, [_h.sent()]);
|
|
314
|
+
if (!(this.chainId === 1)) return [3 /*break*/, 3];
|
|
313
315
|
_c = lowerCasePoolDataAddresses;
|
|
314
316
|
return [4 /*yield*/, getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.crvusd_factory)];
|
|
315
317
|
case 2:
|
|
316
318
|
poolData = _c.apply(void 0, [_h.sent()]);
|
|
317
319
|
this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
|
|
318
|
-
|
|
319
|
-
case 3:
|
|
320
|
+
_h.label = 3;
|
|
321
|
+
case 3: return [3 /*break*/, 7];
|
|
322
|
+
case 4:
|
|
320
323
|
_d = this.constants;
|
|
321
324
|
_e = lowerCasePoolDataAddresses;
|
|
322
325
|
return [4 /*yield*/, getFactoryPoolData.call(this)];
|
|
323
|
-
case
|
|
326
|
+
case 5:
|
|
324
327
|
_d.FACTORY_POOLS_DATA = _e.apply(void 0, [_h.sent()]);
|
|
328
|
+
if (!(this.chainId === 1)) return [3 /*break*/, 7];
|
|
325
329
|
_f = lowerCasePoolDataAddresses;
|
|
326
330
|
return [4 /*yield*/, getFactoryPoolData.call(this, 0, undefined, this.constants.ALIASES.crvusd_factory)];
|
|
327
|
-
case
|
|
331
|
+
case 6:
|
|
328
332
|
poolData = _f.apply(void 0, [_h.sent()]);
|
|
329
333
|
this.constants.FACTORY_POOLS_DATA = __assign(__assign({}, this.constants.FACTORY_POOLS_DATA), poolData);
|
|
330
|
-
_h.label =
|
|
331
|
-
case
|
|
334
|
+
_h.label = 7;
|
|
335
|
+
case 7:
|
|
332
336
|
_g = this.constants;
|
|
333
337
|
return [4 /*yield*/, this._filterHiddenPools(this.constants.FACTORY_POOLS_DATA)];
|
|
334
|
-
case
|
|
338
|
+
case 8:
|
|
335
339
|
_g.FACTORY_POOLS_DATA = _h.sent();
|
|
336
340
|
this._updateDecimalsAndGauges(this.constants.FACTORY_POOLS_DATA);
|
|
337
341
|
return [4 /*yield*/, _killGauges(this.constants.FACTORY_POOLS_DATA)];
|
|
338
|
-
case
|
|
342
|
+
case 9:
|
|
339
343
|
_h.sent();
|
|
340
344
|
return [2 /*return*/];
|
|
341
345
|
}
|
|
@@ -473,6 +477,7 @@ var Curve = /** @class */ (function () {
|
|
|
473
477
|
POOLS_DATA: {},
|
|
474
478
|
FACTORY_POOLS_DATA: {},
|
|
475
479
|
CRYPTO_FACTORY_POOLS_DATA: {},
|
|
480
|
+
LLAMMAS_DATA: {},
|
|
476
481
|
COINS: {},
|
|
477
482
|
DECIMALS: {},
|
|
478
483
|
GAUGES: [],
|
|
@@ -507,6 +512,7 @@ var Curve = /** @class */ (function () {
|
|
|
507
512
|
POOLS_DATA: {},
|
|
508
513
|
FACTORY_POOLS_DATA: {},
|
|
509
514
|
CRYPTO_FACTORY_POOLS_DATA: {},
|
|
515
|
+
LLAMMAS_DATA: {},
|
|
510
516
|
COINS: {},
|
|
511
517
|
DECIMALS: {},
|
|
512
518
|
GAUGES: [],
|
|
@@ -572,10 +578,12 @@ var Curve = /** @class */ (function () {
|
|
|
572
578
|
this.constants.NETWORK_NAME = NETWORK_CONSTANTS[this.chainId].NAME;
|
|
573
579
|
this.constants.ALIASES = NETWORK_CONSTANTS[this.chainId].ALIASES;
|
|
574
580
|
this.constants.POOLS_DATA = NETWORK_CONSTANTS[this.chainId].POOLS_DATA;
|
|
581
|
+
if (this.chainId === 1)
|
|
582
|
+
this.constants.LLAMMAS_DATA = NETWORK_CONSTANTS[this.chainId].LLAMMAS_DATA;
|
|
575
583
|
for (poolId in this.constants.POOLS_DATA)
|
|
576
584
|
this.constants.POOLS_DATA[poolId].in_api = true;
|
|
577
585
|
this.constants.COINS = NETWORK_CONSTANTS[this.chainId].COINS;
|
|
578
|
-
this.constants.DECIMALS = extractDecimals(this.constants.POOLS_DATA);
|
|
586
|
+
this.constants.DECIMALS = extractDecimals(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA));
|
|
579
587
|
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.address] = 18;
|
|
580
588
|
this.constants.DECIMALS[this.constants.NATIVE_TOKEN.wrappedAddress] = 18;
|
|
581
589
|
this.constants.GAUGES = extractGauges(this.constants.POOLS_DATA);
|
|
@@ -612,7 +620,7 @@ var Curve = /** @class */ (function () {
|
|
|
612
620
|
return [4 /*yield*/, this.updateFeeData()];
|
|
613
621
|
case 18:
|
|
614
622
|
_p.sent();
|
|
615
|
-
for (_i = 0, _f = Object.values(this.constants.POOLS_DATA); _i < _f.length; _i++) {
|
|
623
|
+
for (_i = 0, _f = Object.values(__assign(__assign({}, this.constants.POOLS_DATA), this.constants.LLAMMAS_DATA)); _i < _f.length; _i++) {
|
|
616
624
|
pool = _f[_i];
|
|
617
625
|
this.setContract(pool.swap_address, pool.swap_abi);
|
|
618
626
|
if (pool.token_address !== pool.swap_address) {
|
package/lib/factory/constants.js
CHANGED
|
@@ -52,7 +52,7 @@ export var implementationABIDictEthereum = lowerCaseKeys({
|
|
|
52
52
|
"0x4A4d7868390EF5CaC51cDA262888f34bD3025C3F": Plain2OptimizedABI,
|
|
53
53
|
"0xc629a01eC23AB04E1050500A3717A2a5c0701497": Plain2BasicABI,
|
|
54
54
|
"0x94b4DFd9Ba5865Cc931195c99A2db42F3fc5d45B": Plain2ETHABI,
|
|
55
|
-
"
|
|
55
|
+
"0xAee70429bdfbf599a979f50d5Fde5EB0d317E0f7": Plain2BasicABI,
|
|
56
56
|
"0x9B52F13DF69D79Ec5aAB6D1aCe3157d29B409cC3": Plain3BasicABI,
|
|
57
57
|
"0x50b085f2e5958C4A87baf93A8AB79F6bec068494": Plain3BalancesABI,
|
|
58
58
|
"0x8c1aB78601c259E1B43F19816923609dC7d7de9B": Plain3ETHABI,
|
|
@@ -314,11 +314,11 @@ export function getCryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
|
314
314
|
is_factory: true,
|
|
315
315
|
base_pool: basePoolId,
|
|
316
316
|
underlying_coins: __spreadArray([coinAddressNameDict[underlyingCoinAddresses[i][0]]], basePoolCoinNames, true),
|
|
317
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
317
|
+
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
318
318
|
underlying_coin_addresses: __spreadArray([underlyingCoinAddresses[i][0]], basePoolCoinAddresses, true),
|
|
319
319
|
wrapped_coin_addresses: coinAddresses[i],
|
|
320
320
|
underlying_decimals: __spreadArray([coinAddressDecimalsDict[underlyingCoinAddresses[i][0]]], basePoolDecimals, true),
|
|
321
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
321
|
+
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
322
322
|
swap_abi: cryptoFactorySwapABI,
|
|
323
323
|
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
324
324
|
deposit_abi: basePoolZap.ABI,
|
|
@@ -336,12 +336,12 @@ export function getCryptoFactoryPoolData(fromIdx, swapAddress) {
|
|
|
336
336
|
is_crypto: true,
|
|
337
337
|
is_plain: underlyingCoinAddresses[i].toString() === coinAddresses[i].toString(),
|
|
338
338
|
is_factory: true,
|
|
339
|
-
underlying_coins: underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
340
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
339
|
+
underlying_coins: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
340
|
+
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
341
341
|
underlying_coin_addresses: underlyingCoinAddresses[i],
|
|
342
342
|
wrapped_coin_addresses: coinAddresses[i],
|
|
343
|
-
underlying_decimals: underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
344
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
343
|
+
underlying_decimals: __spreadArray([], underlyingCoinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
344
|
+
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
345
345
|
swap_abi: cryptoFactorySwapABI,
|
|
346
346
|
gauge_abi: this.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
347
347
|
};
|
package/lib/factory/factory.js
CHANGED
|
@@ -337,12 +337,12 @@ export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
|
|
|
337
337
|
implementation_address: implementations[i],
|
|
338
338
|
is_plain: true,
|
|
339
339
|
is_factory: true,
|
|
340
|
-
underlying_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
341
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
340
|
+
underlying_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
341
|
+
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
342
342
|
underlying_coin_addresses: coinAddresses[i],
|
|
343
343
|
wrapped_coin_addresses: coinAddresses[i],
|
|
344
|
-
underlying_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
345
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
344
|
+
underlying_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
345
|
+
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
346
346
|
swap_abi: swapABIs[i],
|
|
347
347
|
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
348
348
|
};
|
|
@@ -371,11 +371,11 @@ export function getFactoryPoolData(fromIdx, swapAddress, factoryAddress) {
|
|
|
371
371
|
is_factory: true,
|
|
372
372
|
base_pool: basePoolIds[i],
|
|
373
373
|
underlying_coins: __spreadArray([coinAddressNameDict[coinAddresses[i][0]]], basePoolIdCoinsDict[basePoolIds[i]], true),
|
|
374
|
-
wrapped_coins: coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }),
|
|
374
|
+
wrapped_coins: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressNameDict[addr]; }), true),
|
|
375
375
|
underlying_coin_addresses: __spreadArray([coinAddresses[i][0]], basePoolIdCoinAddressesDict[basePoolIds[i]], true),
|
|
376
376
|
wrapped_coin_addresses: coinAddresses[i],
|
|
377
377
|
underlying_decimals: __spreadArray([coinAddressDecimalsDict[coinAddresses[i][0]]], basePoolIdDecimalsDict[basePoolIds[i]], true),
|
|
378
|
-
wrapped_decimals: coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }),
|
|
378
|
+
wrapped_decimals: __spreadArray([], coinAddresses[i].map(function (addr) { return coinAddressDecimalsDict[addr]; }), true),
|
|
379
379
|
swap_abi: swapABIs[i],
|
|
380
380
|
gauge_abi: this_1.chainId === 1 ? factoryGaugeABI : gaugeChildABI,
|
|
381
381
|
deposit_abi: basePoolZap.ABI,
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -157,20 +157,39 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
157
157
|
this.statsTotalLiquidity = function (useApi) {
|
|
158
158
|
if (useApi === void 0) { useApi = true; }
|
|
159
159
|
return __awaiter(_this, void 0, void 0, function () {
|
|
160
|
-
var network, poolType, poolsData, totalLiquidity_1, balances, promises, _i,
|
|
160
|
+
var stablecoinContract, collateralContract, ammContract, _c, _balance_x, _fee_x, _balance_y, _fee_y, collateralRate, stablecoinTvlBN, collateralTvlBN, network, poolType, poolsData, totalLiquidity_1, balances, promises, _i, _d, addr, prices, totalLiquidity;
|
|
161
161
|
var _this = this;
|
|
162
|
-
return __generator(this, function (
|
|
163
|
-
switch (
|
|
162
|
+
return __generator(this, function (_e) {
|
|
163
|
+
switch (_e.label) {
|
|
164
164
|
case 0:
|
|
165
|
-
if (!
|
|
165
|
+
if (!this.isLlamma) return [3 /*break*/, 3];
|
|
166
|
+
stablecoinContract = curve.contracts[this.underlyingCoinAddresses[0]].multicallContract;
|
|
167
|
+
collateralContract = curve.contracts[this.underlyingCoinAddresses[1]].multicallContract;
|
|
168
|
+
ammContract = curve.contracts[this.address].multicallContract;
|
|
169
|
+
return [4 /*yield*/, curve.multicallProvider.all([
|
|
170
|
+
stablecoinContract.balanceOf(this.address),
|
|
171
|
+
ammContract.admin_fees_x(),
|
|
172
|
+
collateralContract.balanceOf(this.address),
|
|
173
|
+
ammContract.admin_fees_y(),
|
|
174
|
+
])];
|
|
175
|
+
case 1:
|
|
176
|
+
_c = _e.sent(), _balance_x = _c[0], _fee_x = _c[1], _balance_y = _c[2], _fee_y = _c[3];
|
|
177
|
+
return [4 /*yield*/, _getUsdRate(this.underlyingCoinAddresses[1])];
|
|
178
|
+
case 2:
|
|
179
|
+
collateralRate = _e.sent();
|
|
180
|
+
stablecoinTvlBN = toBN(_balance_x).minus(toBN(_fee_x));
|
|
181
|
+
collateralTvlBN = toBN(_balance_y).minus(toBN(_fee_y)).times(collateralRate);
|
|
182
|
+
return [2 /*return*/, stablecoinTvlBN.plus(collateralTvlBN).toString()];
|
|
183
|
+
case 3:
|
|
184
|
+
if (!useApi) return [3 /*break*/, 5];
|
|
166
185
|
network = curve.constants.NETWORK_NAME;
|
|
167
186
|
poolType = !this.isFactory && !this.isCrypto ? "main" :
|
|
168
187
|
!this.isFactory ? "crypto" :
|
|
169
188
|
!(this.isCrypto && this.isFactory) ? "factory" :
|
|
170
189
|
"factory-crypto";
|
|
171
190
|
return [4 /*yield*/, _getPoolsFromApi(network, poolType)];
|
|
172
|
-
case
|
|
173
|
-
poolsData = (
|
|
191
|
+
case 4:
|
|
192
|
+
poolsData = (_e.sent()).poolData;
|
|
174
193
|
try {
|
|
175
194
|
totalLiquidity_1 = poolsData.filter(function (data) { return data.address.toLowerCase() === _this.address.toLowerCase(); })[0].usdTotal;
|
|
176
195
|
return [2 /*return*/, String(totalLiquidity_1)];
|
|
@@ -178,18 +197,18 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
178
197
|
catch (err) {
|
|
179
198
|
console.log(this.id, err.message);
|
|
180
199
|
}
|
|
181
|
-
|
|
182
|
-
case
|
|
183
|
-
case
|
|
184
|
-
balances =
|
|
200
|
+
_e.label = 5;
|
|
201
|
+
case 5: return [4 /*yield*/, this.statsUnderlyingBalances()];
|
|
202
|
+
case 6:
|
|
203
|
+
balances = _e.sent();
|
|
185
204
|
promises = [];
|
|
186
|
-
for (_i = 0,
|
|
187
|
-
addr =
|
|
205
|
+
for (_i = 0, _d = this.underlyingCoinAddresses; _i < _d.length; _i++) {
|
|
206
|
+
addr = _d[_i];
|
|
188
207
|
promises.push(_getUsdRate(addr));
|
|
189
208
|
}
|
|
190
209
|
return [4 /*yield*/, Promise.all(promises)];
|
|
191
|
-
case
|
|
192
|
-
prices =
|
|
210
|
+
case 7:
|
|
211
|
+
prices = _e.sent();
|
|
193
212
|
totalLiquidity = balances.reduce(function (liquidity, b, i) { return liquidity + (Number(b) * prices[i]); }, 0);
|
|
194
213
|
return [2 /*return*/, totalLiquidity.toFixed(8)];
|
|
195
214
|
}
|
|
@@ -1060,7 +1079,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1060
1079
|
}
|
|
1061
1080
|
});
|
|
1062
1081
|
}); };
|
|
1063
|
-
var poolData = __assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA)[id];
|
|
1082
|
+
var poolData = __assign(__assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA), curve.constants.LLAMMAS_DATA)[id];
|
|
1064
1083
|
this.id = id;
|
|
1065
1084
|
this.name = poolData.name;
|
|
1066
1085
|
this.fullName = poolData.full_name;
|
|
@@ -1079,6 +1098,7 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1079
1098
|
this.isFake = poolData.is_fake || false;
|
|
1080
1099
|
this.isFactory = poolData.is_factory || false;
|
|
1081
1100
|
this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
|
|
1101
|
+
this.isLlamma = poolData.is_llamma || false;
|
|
1082
1102
|
this.basePool = poolData.base_pool || '';
|
|
1083
1103
|
this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
|
|
1084
1104
|
this.underlyingCoins = poolData.underlying_coins;
|
|
@@ -1145,14 +1165,16 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1145
1165
|
};
|
|
1146
1166
|
PoolTemplate.prototype.statsWrappedBalances = function () {
|
|
1147
1167
|
return __awaiter(this, void 0, void 0, function () {
|
|
1148
|
-
var
|
|
1168
|
+
var contract, calls, i, _wrappedBalances;
|
|
1149
1169
|
var _this = this;
|
|
1150
1170
|
return __generator(this, function (_c) {
|
|
1151
1171
|
switch (_c.label) {
|
|
1152
1172
|
case 0:
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1173
|
+
contract = curve.contracts[this.address].multicallContract;
|
|
1174
|
+
calls = [];
|
|
1175
|
+
for (i = 0; i < this.wrappedCoins.length; i++)
|
|
1176
|
+
calls.push(contract.balances(i));
|
|
1177
|
+
return [4 /*yield*/, curve.multicallProvider.all(calls)];
|
|
1156
1178
|
case 1:
|
|
1157
1179
|
_wrappedBalances = _c.sent();
|
|
1158
1180
|
return [2 /*return*/, _wrappedBalances.map(function (_b, i) { return curve.formatUnits(_b, _this.wrappedDecimals[i]); })];
|
package/lib/router.js
CHANGED
|
@@ -115,6 +115,17 @@ var filterRoutes = function (routes, inputCoinAddress, sortFn) {
|
|
|
115
115
|
};
|
|
116
116
|
var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.route.length - b.route.length; };
|
|
117
117
|
var sortByLength = function (a, b) { return a.route.length - b.route.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
|
|
118
|
+
var _getTVL = memoize(function (poolId) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) {
|
|
119
|
+
switch (_b.label) {
|
|
120
|
+
case 0:
|
|
121
|
+
_a = Number;
|
|
122
|
+
return [4 /*yield*/, (getPool(poolId)).stats.totalLiquidity()];
|
|
123
|
+
case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
|
|
124
|
+
}
|
|
125
|
+
}); }); }, {
|
|
126
|
+
promise: true,
|
|
127
|
+
maxAge: 5 * 60 * 1000, // 5m
|
|
128
|
+
});
|
|
118
129
|
// Inspired by Dijkstra's algorithm
|
|
119
130
|
var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
|
|
120
131
|
var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_1, inCoin, routes;
|
|
@@ -125,7 +136,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
125
136
|
case 0:
|
|
126
137
|
inputCoinAddress = inputCoinAddress.toLowerCase();
|
|
127
138
|
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
128
|
-
ALL_POOLS = Object.entries(__assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA));
|
|
139
|
+
ALL_POOLS = Object.entries(__assign(__assign(__assign(__assign({}, curve.constants.POOLS_DATA), curve.constants.FACTORY_POOLS_DATA), curve.constants.CRYPTO_FACTORY_POOLS_DATA), curve.constants.LLAMMAS_DATA));
|
|
129
140
|
return [4 /*yield*/, _getAmplificationCoefficientsFromApi()];
|
|
130
141
|
case 1:
|
|
131
142
|
amplificationCoefficientDict = _s.sent();
|
|
@@ -157,9 +168,9 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
157
168
|
nextCoins.add(outCoin_1);
|
|
158
169
|
}
|
|
159
170
|
_loop_2 = function (poolId, poolData) {
|
|
160
|
-
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_aave_like_lending, tvlMultiplier, inCoinIndexes, tvl, _w,
|
|
161
|
-
return __generator(this, function (
|
|
162
|
-
switch (
|
|
171
|
+
var wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_aave_like_lending, tvlMultiplier, inCoinIndexes, tvl, _w, poolAddress, coin_addresses, _loop_3, j, inCoinIndex, swapType_1, newRoutesByTvl, newRoutesByLength, _loop_4, j, _loop_5, j;
|
|
172
|
+
return __generator(this, function (_x) {
|
|
173
|
+
switch (_x.label) {
|
|
163
174
|
case 0:
|
|
164
175
|
wrapped_coin_addresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
165
176
|
underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
|
|
@@ -179,12 +190,10 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
179
190
|
if (!poolId.startsWith('factory-crvusd-')) return [3 /*break*/, 1];
|
|
180
191
|
_w = 500000 * 100;
|
|
181
192
|
return [3 /*break*/, 3];
|
|
182
|
-
case 1:
|
|
183
|
-
_x = Number;
|
|
184
|
-
return [4 /*yield*/, (getPool(poolId)).stats.totalLiquidity()];
|
|
193
|
+
case 1: return [4 /*yield*/, _getTVL(poolId)];
|
|
185
194
|
case 2:
|
|
186
|
-
_w = _x.
|
|
187
|
-
|
|
195
|
+
_w = (_x.sent()) * tvlMultiplier;
|
|
196
|
+
_x.label = 3;
|
|
188
197
|
case 3:
|
|
189
198
|
tvl = _w;
|
|
190
199
|
// Skip empty pools
|
|
@@ -216,7 +225,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
216
225
|
}
|
|
217
226
|
}
|
|
218
227
|
inCoinIndex = (is_aave_like_lending || poolData.is_fake) ? inCoinIndexes.underlying_coin : inCoinIndexes.wrapped_coin;
|
|
219
|
-
if (coin_addresses.length < 6 && inCoinIndex >= 0) {
|
|
228
|
+
if (coin_addresses.length < 6 && inCoinIndex >= 0 && !poolData.is_llamma) {
|
|
220
229
|
// Looking for outputCoinAddress only on the final step
|
|
221
230
|
if (!(step === 3 && token_address !== outputCoinAddress)) {
|
|
222
231
|
swapType_1 = is_aave_like_lending ? 9
|
|
@@ -263,58 +272,43 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
|
|
|
263
272
|
// Only for underlying swaps
|
|
264
273
|
poolAddress = (poolData.is_crypto && poolData.is_meta) || ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ?
|
|
265
274
|
poolData.deposit_address : poolData.swap_address;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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
|
-
});
|
|
305
|
-
};
|
|
306
|
-
j = 0;
|
|
307
|
-
_y.label = 4;
|
|
308
|
-
case 4:
|
|
309
|
-
if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 7];
|
|
310
|
-
return [5 /*yield**/, _loop_5(j)];
|
|
311
|
-
case 5:
|
|
312
|
-
_y.sent();
|
|
313
|
-
_y.label = 6;
|
|
314
|
-
case 6:
|
|
315
|
-
j++;
|
|
316
|
-
return [3 /*break*/, 4];
|
|
317
|
-
case 7: return [2 /*return*/];
|
|
275
|
+
// Underlying swaps
|
|
276
|
+
if (!poolData.is_plain && inCoinIndexes.underlying_coin >= 0) {
|
|
277
|
+
_loop_5 = function (j) {
|
|
278
|
+
if (j === inCoinIndexes.underlying_coin)
|
|
279
|
+
return "continue";
|
|
280
|
+
// Don't swap metacoins since they can be swapped directly in base pool
|
|
281
|
+
if (inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
|
|
282
|
+
return "continue";
|
|
283
|
+
// Looking for outputCoinAddress only on the final step
|
|
284
|
+
if (step === 3 && underlying_coin_addresses[j] !== outputCoinAddress)
|
|
285
|
+
return "continue";
|
|
286
|
+
// Exclude such cases as cvxeth -> tricrypto2 -> tusd -> susd or cvxeth -> tricrypto2 -> susd -> susd
|
|
287
|
+
var outputCoinIdx = underlying_coin_addresses.indexOf(outputCoinAddress);
|
|
288
|
+
if (outputCoinIdx >= 0 && j !== outputCoinIdx)
|
|
289
|
+
return "continue";
|
|
290
|
+
// Skip empty pools
|
|
291
|
+
if (tvl === 0)
|
|
292
|
+
return "continue";
|
|
293
|
+
var hasEth = (inCoin === curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve.constants.NATIVE_TOKEN.address);
|
|
294
|
+
var swapType = (poolData.is_crypto && poolData.is_meta && poolData.is_factory) ? 6
|
|
295
|
+
: ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ? 5
|
|
296
|
+
: hasEth && poolId !== 'avaxcrypto' ? 3
|
|
297
|
+
: poolData.is_crypto ? 4
|
|
298
|
+
: 2;
|
|
299
|
+
var newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : curve.constants.ZERO_ADDRESS, tvl); });
|
|
300
|
+
var newRoutesByLength = routesByLength[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : curve.constants.ZERO_ADDRESS, tvl); });
|
|
301
|
+
routesByTvl[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_o = routesByTvl[underlying_coin_addresses[j]]) !== null && _o !== void 0 ? _o : []), true), newRoutesByTvl, true);
|
|
302
|
+
routesByTvl[underlying_coin_addresses[j]] = filterRoutes(routesByTvl[underlying_coin_addresses[j]], inputCoinAddress, sortByTvl);
|
|
303
|
+
routesByLength[underlying_coin_addresses[j]] = __spreadArray(__spreadArray([], ((_p = routesByLength[underlying_coin_addresses[j]]) !== null && _p !== void 0 ? _p : []), true), newRoutesByLength, true);
|
|
304
|
+
routesByLength[underlying_coin_addresses[j]] = filterRoutes(routesByLength[underlying_coin_addresses[j]], inputCoinAddress, sortByLength);
|
|
305
|
+
nextCoins.add(underlying_coin_addresses[j]);
|
|
306
|
+
};
|
|
307
|
+
for (j = 0; j < underlying_coin_addresses.length; j++) {
|
|
308
|
+
_loop_5(j);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return [2 /*return*/];
|
|
318
312
|
}
|
|
319
313
|
});
|
|
320
314
|
};
|