@curvefi/api 2.25.2 → 2.25.4

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.
@@ -0,0 +1,51 @@
1
+ [
2
+ {
3
+ "stateMutability": "payable",
4
+ "type": "function",
5
+ "name": "deposit_and_stake",
6
+ "inputs": [
7
+ {
8
+ "name": "deposit",
9
+ "type": "address"
10
+ },
11
+ {
12
+ "name": "lp_token",
13
+ "type": "address"
14
+ },
15
+ {
16
+ "name": "gauge",
17
+ "type": "address"
18
+ },
19
+ {
20
+ "name": "n_coins",
21
+ "type": "uint256"
22
+ },
23
+ {
24
+ "name": "coins",
25
+ "type": "address[6]"
26
+ },
27
+ {
28
+ "name": "amounts",
29
+ "type": "uint256[6]"
30
+ },
31
+ {
32
+ "name": "min_mint_amount",
33
+ "type": "uint256"
34
+ },
35
+ {
36
+ "name": "use_underlying",
37
+ "type": "bool"
38
+ },
39
+ {
40
+ "name": "pool",
41
+ "type": "address"
42
+ }
43
+ ],
44
+ "outputs": [],
45
+ "gas": "409532"
46
+ },
47
+ {
48
+ "stateMutability": "payable",
49
+ "type": "fallback"
50
+ }
51
+ ]
@@ -23,7 +23,7 @@ exports.ALIASES_POLYGON = (0, utils_1.lowerCaseValues)({
23
23
  "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
24
24
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
25
25
  "router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
26
- "deposit_and_stake": "0x43FF7b96808988C9d19C1d05Ef19658B03e8a143",
26
+ "deposit_and_stake": "0xB7De33440B7171159a9718CBE748086cecDd9685",
27
27
  "factory": '0x722272d36ef0da72ff51c5a65db7b870e2e8d4ee',
28
28
  "crypto_factory": "0xE5De15A9C9bBedb4F5EC13B131E61245f2983A69",
29
29
  "registry_exchange": "",
package/lib/curve.js CHANGED
@@ -76,6 +76,7 @@ var address_provider_json_1 = __importDefault(require("./constants/abis/address_
76
76
  var gaugecontroller_json_1 = __importDefault(require("./constants/abis/gaugecontroller.json"));
77
77
  var router_json_1 = __importDefault(require("./constants/abis/router.json"));
78
78
  var deposit_and_stake_json_1 = __importDefault(require("./constants/abis/deposit_and_stake.json"));
79
+ var deposit_and_stake_6coins_json_1 = __importDefault(require("./constants/abis/deposit_and_stake_6coins.json"));
79
80
  var registry_exchange_json_1 = __importDefault(require("./constants/abis/registry_exchange.json"));
80
81
  var streamer_json_1 = __importDefault(require("./constants/abis/streamer.json"));
81
82
  var factory_json_1 = __importDefault(require("./constants/abis/factory.json"));
@@ -448,34 +449,19 @@ var Curve = /** @class */ (function () {
448
449
  _o.sent();
449
450
  for (_i = 0, _e = Object.values(this.constants.POOLS_DATA); _i < _e.length; _i++) {
450
451
  pool = _e[_i];
451
- this.contracts[pool.swap_address] = {
452
- contract: new ethers_1.Contract(pool.swap_address, pool.swap_abi, this.signer || this.provider),
453
- multicallContract: new ethcall_1.Contract(pool.swap_address, pool.swap_abi),
454
- };
452
+ this.setContract(pool.swap_address, pool.swap_abi);
455
453
  if (pool.token_address !== pool.swap_address) {
456
- this.contracts[pool.token_address] = {
457
- contract: new ethers_1.Contract(pool.token_address, ERC20_json_1.default, this.signer || this.provider),
458
- multicallContract: new ethcall_1.Contract(pool.token_address, ERC20_json_1.default),
459
- };
454
+ this.setContract(pool.token_address, ERC20_json_1.default);
460
455
  }
461
456
  if (pool.gauge_address !== ethers_1.ethers.constants.AddressZero) {
462
- this.contracts[pool.gauge_address] = {
463
- contract: new ethers_1.Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
464
- multicallContract: new ethcall_1.Contract(pool.gauge_address, pool.gauge_abi),
465
- };
457
+ this.setContract(pool.gauge_address, pool.gauge_abi);
466
458
  }
467
459
  if (pool.deposit_address && !this.contracts[pool.deposit_address]) {
468
- this.contracts[pool.deposit_address] = {
469
- contract: new ethers_1.Contract(pool.deposit_address, pool.deposit_abi, this.signer || this.provider),
470
- multicallContract: new ethcall_1.Contract(pool.deposit_address, pool.deposit_abi),
471
- };
460
+ this.setContract(pool.deposit_address, pool.deposit_abi);
472
461
  }
473
462
  for (_f = 0, _g = pool.underlying_coin_addresses; _f < _g.length; _f++) {
474
463
  coinAddr = _g[_f];
475
- this.contracts[coinAddr] = {
476
- contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
477
- multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
478
- };
464
+ this.setContract(coinAddr, ERC20_json_1.default);
479
465
  }
480
466
  for (_h = 0, _j = pool.wrapped_coin_addresses; _h < _j.length; _h++) {
481
467
  coinAddr = _j[_h];
@@ -483,135 +469,52 @@ var Curve = /** @class */ (function () {
483
469
  continue;
484
470
  if (coinAddr in this.contracts)
485
471
  continue;
486
- this.contracts[coinAddr] = {
487
- contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
488
- multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
489
- };
472
+ this.setContract(coinAddr, ERC20_json_1.default);
490
473
  }
491
474
  // TODO add all coins
492
475
  for (_k = 0, _l = pool.wrapped_coin_addresses; _k < _l.length; _k++) {
493
476
  coinAddr = _l[_k];
494
477
  if (cTokens.includes(coinAddr)) {
495
- this.contracts[coinAddr] = {
496
- contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
497
- multicallContract: new ethcall_1.Contract(coinAddr, cERC20_json_1.default),
498
- };
478
+ this.setContract(coinAddr, cERC20_json_1.default);
499
479
  }
500
480
  if (aTokens.includes(coinAddr)) {
501
- this.contracts[coinAddr] = {
502
- contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
503
- multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
504
- };
481
+ this.setContract(coinAddr, ERC20_json_1.default);
505
482
  }
506
483
  if (yTokens.includes(coinAddr) || ycTokens.includes(coinAddr)) {
507
- this.contracts[coinAddr] = {
508
- contract: new ethers_1.Contract(coinAddr, yERC20_json_1.default, this.signer || this.provider),
509
- multicallContract: new ethcall_1.Contract(coinAddr, yERC20_json_1.default),
510
- };
484
+ this.setContract(coinAddr, yERC20_json_1.default);
511
485
  }
512
486
  }
513
487
  if (pool.reward_contract) {
514
- this.contracts[pool.reward_contract] = {
515
- contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
516
- multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
517
- };
488
+ this.setContract(pool.reward_contract, streamer_json_1.default);
518
489
  }
519
490
  if (pool.sCurveRewards_address) {
520
- this.contracts[pool.sCurveRewards_address] = {
521
- contract: new ethers_1.Contract(pool.sCurveRewards_address, pool.sCurveRewards_abi, this.signer || this.provider),
522
- multicallContract: new ethcall_1.Contract(pool.sCurveRewards_address, pool.sCurveRewards_abi),
523
- };
491
+ this.setContract(pool.sCurveRewards_address, pool.sCurveRewards_abi);
524
492
  }
525
493
  }
526
494
  this.setContract(this.constants.NATIVE_TOKEN.wrappedAddress, ERC20_json_1.default);
527
- this.contracts[this.constants.ALIASES.crv] = {
528
- contract: new ethers_1.Contract(this.constants.ALIASES.crv, ERC20_json_1.default, this.signer || this.provider),
529
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.crv, ERC20_json_1.default),
530
- };
531
- this.contracts[this.constants.ALIASES.crv.toLowerCase()] = {
532
- contract: new ethers_1.Contract(this.constants.ALIASES.crv, ERC20_json_1.default, this.signer || this.provider),
533
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.crv, ERC20_json_1.default),
534
- };
495
+ this.setContract(this.constants.ALIASES.crv, ERC20_json_1.default);
535
496
  this.constants.DECIMALS[this.constants.ALIASES.crv] = 18;
536
497
  _minterABI = this.chainId === 1 ? minter_json_1.default : minter_child_json_1.default;
537
- this.contracts[this.constants.ALIASES.minter] = {
538
- contract: new ethers_1.Contract(this.constants.ALIASES.minter, _minterABI, this.signer || this.provider),
539
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.minter, _minterABI),
540
- };
541
- this.contracts[this.constants.ALIASES.minter.toLowerCase()] = {
542
- contract: new ethers_1.Contract(this.constants.ALIASES.minter, _minterABI, this.signer || this.provider),
543
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.minter, _minterABI),
544
- };
545
- this.contracts[this.constants.ALIASES.voting_escrow] = {
546
- contract: new ethers_1.Contract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default, this.signer || this.provider),
547
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default),
548
- };
549
- this.contracts[this.constants.ALIASES.voting_escrow.toLowerCase()] = {
550
- contract: new ethers_1.Contract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default, this.signer || this.provider),
551
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default),
552
- };
498
+ this.setContract(this.constants.ALIASES.minter, _minterABI);
499
+ this.setContract(this.constants.ALIASES.voting_escrow, votingescrow_json_1.default);
553
500
  this.setContract(this.constants.ALIASES.fee_distributor, fee_distributor_json_1.default);
554
- this.contracts[this.constants.ALIASES.address_provider] = {
555
- contract: new ethers_1.Contract(this.constants.ALIASES.address_provider, address_provider_json_1.default, this.signer || this.provider),
556
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.address_provider, address_provider_json_1.default),
557
- };
558
- this.contracts[this.constants.ALIASES.address_provider.toLowerCase()] = {
559
- contract: new ethers_1.Contract(this.constants.ALIASES.address_provider, address_provider_json_1.default, this.signer || this.provider),
560
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.address_provider, address_provider_json_1.default),
561
- };
501
+ this.setContract(this.constants.ALIASES.address_provider, address_provider_json_1.default);
562
502
  addressProviderContract = this.contracts[this.constants.ALIASES.address_provider].contract;
563
503
  _m = this.constants.ALIASES;
564
504
  return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
565
505
  case 12:
566
- _m.registry_exchange = _o.sent();
567
- this.contracts[this.constants.ALIASES.registry_exchange] = {
568
- contract: new ethers_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default, this.signer || this.provider),
569
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default),
570
- };
571
- this.contracts[this.constants.ALIASES.registry_exchange.toLowerCase()] = {
572
- contract: new ethers_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default, this.signer || this.provider),
573
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default),
574
- };
575
- this.contracts[this.constants.ALIASES.gauge_controller] = {
576
- contract: new ethers_1.Contract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default, this.signer || this.provider),
577
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default),
578
- };
579
- this.contracts[this.constants.ALIASES.gauge_controller.toLowerCase()] = {
580
- contract: new ethers_1.Contract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default, this.signer || this.provider),
581
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default),
582
- };
583
- this.contracts[this.constants.ALIASES.router] = {
584
- contract: new ethers_1.Contract(this.constants.ALIASES.router, router_json_1.default, this.signer || this.provider),
585
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.router, router_json_1.default),
586
- };
587
- this.contracts[this.constants.ALIASES.router.toLowerCase()] = {
588
- contract: new ethers_1.Contract(this.constants.ALIASES.router, router_json_1.default, this.signer || this.provider),
589
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.router, router_json_1.default),
590
- };
591
- this.contracts[this.constants.ALIASES.deposit_and_stake] = {
592
- contract: new ethers_1.Contract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default, this.signer || this.provider),
593
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default),
594
- };
595
- this.contracts[this.constants.ALIASES.deposit_and_stake.toLowerCase()] = {
596
- contract: new ethers_1.Contract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default, this.signer || this.provider),
597
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default),
598
- };
599
- this.contracts[this.constants.ALIASES.factory] = {
600
- contract: new ethers_1.Contract(this.constants.ALIASES.factory, factory_json_1.default, this.signer || this.provider),
601
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.factory, factory_json_1.default),
602
- };
603
- this.contracts[this.constants.ALIASES.factory.toLowerCase()] = {
604
- contract: new ethers_1.Contract(this.constants.ALIASES.factory, factory_json_1.default, this.signer || this.provider),
605
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.factory, factory_json_1.default),
606
- };
607
- this.contracts[this.constants.ALIASES.crypto_factory] = {
608
- contract: new ethers_1.Contract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default, this.signer || this.provider),
609
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default),
610
- };
611
- this.contracts[this.constants.ALIASES.crypto_factory.toLowerCase()] = {
612
- contract: new ethers_1.Contract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default, this.signer || this.provider),
613
- multicallContract: new ethcall_1.Contract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default),
614
- };
506
+ _m.registry_exchange = (_o.sent()).toLowerCase();
507
+ this.setContract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default);
508
+ this.setContract(this.constants.ALIASES.gauge_controller, gaugecontroller_json_1.default);
509
+ this.setContract(this.constants.ALIASES.router, router_json_1.default);
510
+ if (this.chainId === 137) {
511
+ this.setContract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_6coins_json_1.default);
512
+ }
513
+ else {
514
+ this.setContract(this.constants.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default);
515
+ }
516
+ this.setContract(this.constants.ALIASES.factory, factory_json_1.default);
517
+ this.setContract(this.constants.ALIASES.crypto_factory, factory_crypto_json_1.default);
615
518
  return [2 /*return*/];
616
519
  }
617
520
  });
@@ -2124,7 +2124,7 @@ var PoolTemplate = /** @class */ (function () {
2124
2124
  };
2125
2125
  PoolTemplate.prototype._depositAndStake = function (amounts, slippage, isUnderlying, estimateGas) {
2126
2126
  return __awaiter(this, void 0, void 0, function () {
2127
- var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _expectedLpTokenAmount, _j, _k, _l, _m, _o, minAmountBN, _minMintAmount, ethIndex, value, i, _gas, gasLimit;
2127
+ var coinAddresses, coins, decimals, depositAddress, balances, _c, _d, _e, _f, _g, i, allowance, _h, _amounts, contract, useUnderlying, _expectedLpTokenAmount, _j, _k, _l, _m, _o, minAmountBN, _minMintAmount, ethIndex, value, maxCoins, i, _gas, gasLimit;
2128
2128
  return __generator(this, function (_q) {
2129
2129
  switch (_q.label) {
2130
2130
  case 0:
@@ -2200,7 +2200,8 @@ var PoolTemplate = /** @class */ (function () {
2200
2200
  _minMintAmount = (0, utils_1.fromBN)(minAmountBN);
2201
2201
  ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
2202
2202
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
2203
- for (i = 0; i < 5; i++) {
2203
+ maxCoins = curve_1.curve.chainId === 137 ? 6 : 5;
2204
+ for (i = 0; i < maxCoins; i++) {
2204
2205
  coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
2205
2206
  _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
2206
2207
  }
@@ -2794,7 +2795,7 @@ var PoolTemplate = /** @class */ (function () {
2794
2795
  case 1:
2795
2796
  lpTotalBalanceBN = _c.sent();
2796
2797
  if (lpTotalBalanceBN.eq(0))
2797
- return [2 /*return*/, this.underlyingCoins.map(function () { return "0"; })];
2798
+ return [2 /*return*/, this.wrappedCoins.map(function () { return "0"; })];
2798
2799
  return [4 /*yield*/, this.withdrawWrappedExpected(lpTotalBalanceBN.toFixed(18))];
2799
2800
  case 2: return [2 /*return*/, _c.sent()];
2800
2801
  }
package/lib/router.d.ts CHANGED
@@ -1,8 +1,5 @@
1
1
  import { ethers } from "ethers";
2
2
  import { IRouteStep } from "./interfaces";
3
- export declare const _findAllRoutesTheShorterTheBetter: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
4
- export declare const _findAllRoutesTvl: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
5
- export declare const _findAllRoutes: (inputCoinAddress: string, outputCoinAddress: string) => Promise<IRouteStep[][]>;
6
3
  export declare const getBestRouteAndOutput: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<{
7
4
  route: IRouteStep[];
8
5
  output: string;
package/lib/router.js CHANGED
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
59
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
60
  };
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports.getSwappedAmount = exports.swap = exports.swapEstimateGas = exports.swapApprove = exports.swapApproveEstimateGas = exports.swapIsApproved = exports.swapPriceImpact = exports.swapExpected = exports.getBestRouteAndOutput = exports._findAllRoutes = exports._findAllRoutesTvl = exports._findAllRoutesTheShorterTheBetter = void 0;
62
+ exports.getSwappedAmount = exports.swap = exports.swapEstimateGas = exports.swapApprove = exports.swapApproveEstimateGas = exports.swapIsApproved = exports.swapPriceImpact = exports.swapExpected = exports.getBestRouteAndOutput = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var memoizee_1 = __importDefault(require("memoizee"));
65
65
  var ethers_1 = require("ethers");
@@ -67,228 +67,6 @@ var curve_1 = require("./curve");
67
67
  var utils_1 = require("./utils");
68
68
  var pools_1 = require("./pools");
69
69
  var utils_2 = require("./pools/utils");
70
- // --------------------------- LEGACY ROUTER ---------------------------
71
- // Inspired by Dijkstra's algorithm
72
- var _findAllRoutesTheShorterTheBetter = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
73
- var ALL_POOLS, basePoolsSet, _i, ALL_POOLS_1, pool, basePoolIds, markedCoins, curCoins, nextCoins, routes, step, _a, curCoins_1, inCoin, _b, ALL_POOLS_2, _c, poolId, poolData, wrapped_coin_addresses, underlying_coin_addresses, base_pool, meta_coin_addresses, token_address, is_lending, inCoinIndexes, j, swapType, _d, _e, inCoinRoute, flag, swapType, _f, _h, inCoinRoute, j, tvl, _j, swapType, _k, _l, inCoinRoute, poolAddress, j, tvl, _m, hasEth, swapType, _o, _p, inCoinRoute;
74
- var _q;
75
- var _r, _s, _t, _u, _v, _w;
76
- return __generator(this, function (_x) {
77
- switch (_x.label) {
78
- case 0:
79
- inputCoinAddress = inputCoinAddress.toLowerCase();
80
- outputCoinAddress = outputCoinAddress.toLowerCase();
81
- ALL_POOLS = Object.entries(__assign(__assign(__assign({}, curve_1.curve.constants.POOLS_DATA), curve_1.curve.constants.FACTORY_POOLS_DATA), curve_1.curve.constants.CRYPTO_FACTORY_POOLS_DATA));
82
- basePoolsSet = new Set();
83
- for (_i = 0, ALL_POOLS_1 = ALL_POOLS; _i < ALL_POOLS_1.length; _i++) {
84
- pool = ALL_POOLS_1[_i];
85
- if (pool[1].wrapped_coin_addresses.length < 6)
86
- basePoolsSet.add(pool[0]);
87
- }
88
- basePoolIds = Array.from(basePoolsSet);
89
- markedCoins = [];
90
- curCoins = [inputCoinAddress];
91
- nextCoins = new Set();
92
- routes = (_q = {},
93
- _q[inputCoinAddress] = [[]],
94
- _q);
95
- step = 0;
96
- _x.label = 1;
97
- case 1:
98
- if (!(step < 4)) return [3 /*break*/, 15];
99
- _a = 0, curCoins_1 = curCoins;
100
- _x.label = 2;
101
- case 2:
102
- if (!(_a < curCoins_1.length)) return [3 /*break*/, 13];
103
- inCoin = curCoins_1[_a];
104
- _b = 0, ALL_POOLS_2 = ALL_POOLS;
105
- _x.label = 3;
106
- case 3:
107
- if (!(_b < ALL_POOLS_2.length)) return [3 /*break*/, 12];
108
- _c = ALL_POOLS_2[_b], poolId = _c[0], poolData = _c[1];
109
- wrapped_coin_addresses = poolData.wrapped_coin_addresses.map(function (a) { return a.toLowerCase(); });
110
- underlying_coin_addresses = poolData.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); });
111
- base_pool = poolData.is_meta ? curve_1.curve.constants.POOLS_DATA[poolData.base_pool] : null;
112
- meta_coin_addresses = base_pool ? base_pool.underlying_coin_addresses.map(function (a) { return a.toLowerCase(); }) : [];
113
- token_address = poolData.token_address.toLowerCase();
114
- is_lending = (_r = poolData.is_lending) !== null && _r !== void 0 ? _r : false;
115
- inCoinIndexes = {
116
- wrapped_coin: wrapped_coin_addresses.indexOf(inCoin),
117
- underlying_coin: underlying_coin_addresses.indexOf(inCoin),
118
- meta_coin: meta_coin_addresses ? meta_coin_addresses.indexOf(inCoin) : -1,
119
- };
120
- // LP -> wrapped coin "swaps" (actually remove_liquidity_one_coin)
121
- if (basePoolIds.includes(poolId) && inCoin === token_address) {
122
- for (j = 0; j < wrapped_coin_addresses.length; j++) {
123
- // If this coin already marked or will be marked on the current step, no need to consider it on the next step
124
- if (markedCoins.includes(wrapped_coin_addresses[j]) || curCoins.includes(wrapped_coin_addresses[j]))
125
- continue;
126
- // Looking for outputCoinAddress only on the final step
127
- if (step === 3 && wrapped_coin_addresses[j] !== outputCoinAddress)
128
- continue;
129
- swapType = poolId === 'aave' ? 11 : 10;
130
- for (_d = 0, _e = routes[inCoin]; _d < _e.length; _d++) {
131
- inCoinRoute = _e[_d];
132
- routes[wrapped_coin_addresses[j]] = ((_s = routes[wrapped_coin_addresses[j]]) !== null && _s !== void 0 ? _s : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
133
- {
134
- poolId: poolId,
135
- poolAddress: poolData.swap_address,
136
- inputCoinAddress: inCoin,
137
- outputCoinAddress: wrapped_coin_addresses[j],
138
- i: 0,
139
- j: j,
140
- swapType: swapType,
141
- swapAddress: ethers_1.ethers.constants.AddressZero,
142
- },
143
- ], false)]);
144
- }
145
- nextCoins.add(wrapped_coin_addresses[j]);
146
- }
147
- }
148
- // Wrapped coin -> LP "swaps" (actually add_liquidity)
149
- if (basePoolIds.includes(poolId) && wrapped_coin_addresses.includes(inCoin)) {
150
- flag = true;
151
- // If this coin already marked or will be marked on the current step, no need to consider it on the next step
152
- if (markedCoins.includes(token_address) || curCoins.includes(token_address))
153
- flag = false;
154
- // Looking for outputCoinAddress only on the final step
155
- if (step === 3 && token_address !== outputCoinAddress)
156
- flag = false;
157
- if (flag) {
158
- swapType = is_lending ? 9 : wrapped_coin_addresses.length === 2 ? 7 : 8;
159
- for (_f = 0, _h = routes[inCoin]; _f < _h.length; _f++) {
160
- inCoinRoute = _h[_f];
161
- routes[token_address] = ((_t = routes[token_address]) !== null && _t !== void 0 ? _t : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
162
- {
163
- poolId: poolId,
164
- poolAddress: poolData.swap_address,
165
- inputCoinAddress: inCoin,
166
- outputCoinAddress: token_address,
167
- i: wrapped_coin_addresses.indexOf(inCoin),
168
- j: 0,
169
- swapType: swapType,
170
- swapAddress: ethers_1.ethers.constants.AddressZero,
171
- },
172
- ], false)]);
173
- }
174
- nextCoins.add(token_address);
175
- }
176
- }
177
- // No input coin in this pool --> skip
178
- if (inCoinIndexes.wrapped_coin === -1 && inCoinIndexes.underlying_coin === -1 && inCoinIndexes.meta_coin === -1)
179
- return [3 /*break*/, 11];
180
- if (!(inCoinIndexes.wrapped_coin >= 0 && !poolData.is_fake)) return [3 /*break*/, 7];
181
- j = 0;
182
- _x.label = 4;
183
- case 4:
184
- if (!(j < wrapped_coin_addresses.length)) return [3 /*break*/, 7];
185
- // If this coin already marked or will be marked on the current step, no need to consider it on the next step
186
- if (markedCoins.includes(wrapped_coin_addresses[j]) || curCoins.includes(wrapped_coin_addresses[j]))
187
- return [3 /*break*/, 6];
188
- // Native swaps spend less gas
189
- if (wrapped_coin_addresses[j] !== outputCoinAddress && wrapped_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress)
190
- return [3 /*break*/, 6];
191
- // Looking for outputCoinAddress only on the final step
192
- if (step === 3 && wrapped_coin_addresses[j] !== outputCoinAddress)
193
- return [3 /*break*/, 6];
194
- _j = Number;
195
- return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
196
- case 5:
197
- tvl = _j.apply(void 0, [_x.sent()]);
198
- if (tvl === 0)
199
- return [3 /*break*/, 6];
200
- swapType = poolData.is_crypto ? 3 : 1;
201
- for (_k = 0, _l = routes[inCoin]; _k < _l.length; _k++) {
202
- inCoinRoute = _l[_k];
203
- routes[wrapped_coin_addresses[j]] = ((_u = routes[wrapped_coin_addresses[j]]) !== null && _u !== void 0 ? _u : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
204
- {
205
- poolId: poolId,
206
- poolAddress: poolData.swap_address,
207
- inputCoinAddress: inCoin,
208
- outputCoinAddress: wrapped_coin_addresses[j],
209
- i: inCoinIndexes.wrapped_coin,
210
- j: j,
211
- swapType: swapType,
212
- swapAddress: ethers_1.ethers.constants.AddressZero,
213
- },
214
- ], false)]);
215
- }
216
- nextCoins.add(wrapped_coin_addresses[j]);
217
- _x.label = 6;
218
- case 6:
219
- j++;
220
- return [3 /*break*/, 4];
221
- case 7:
222
- poolAddress = (poolData.is_crypto && poolData.is_meta) || ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ?
223
- poolData.deposit_address : poolData.swap_address;
224
- if (!(!poolData.is_plain && inCoinIndexes.underlying_coin >= 0)) return [3 /*break*/, 11];
225
- j = 0;
226
- _x.label = 8;
227
- case 8:
228
- if (!(j < underlying_coin_addresses.length)) return [3 /*break*/, 11];
229
- // Don't swap metacoins since they can be swapped directly in base pool
230
- if (inCoinIndexes.meta_coin >= 0 && meta_coin_addresses.includes(underlying_coin_addresses[j]))
231
- return [3 /*break*/, 10];
232
- // If this coin already marked or will be marked on the current step, no need to consider it on the next step
233
- if (markedCoins.includes(underlying_coin_addresses[j]) || curCoins.includes(underlying_coin_addresses[j]))
234
- return [3 /*break*/, 10];
235
- // Looking for outputCoinAddress only on the final step
236
- if (step === 3 && underlying_coin_addresses[j] !== outputCoinAddress)
237
- return [3 /*break*/, 10];
238
- _m = Number;
239
- return [4 /*yield*/, ((0, pools_1.getPool)(poolId)).stats.totalLiquidity()];
240
- case 9:
241
- tvl = _m.apply(void 0, [_x.sent()]);
242
- if (tvl === 0)
243
- return [3 /*break*/, 10];
244
- hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
245
- swapType = (poolData.is_crypto && poolData.is_meta && poolData.is_factory) ? 6
246
- : ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ? 5
247
- : hasEth ? 3
248
- : poolData.is_crypto ? 4
249
- : 2;
250
- for (_o = 0, _p = routes[inCoin]; _o < _p.length; _o++) {
251
- inCoinRoute = _p[_o];
252
- routes[underlying_coin_addresses[j]] = ((_v = routes[underlying_coin_addresses[j]]) !== null && _v !== void 0 ? _v : []).concat([__spreadArray(__spreadArray([], inCoinRoute, true), [
253
- {
254
- poolId: poolId,
255
- poolAddress: poolAddress,
256
- inputCoinAddress: inCoin,
257
- outputCoinAddress: underlying_coin_addresses[j],
258
- i: inCoinIndexes.underlying_coin,
259
- j: j,
260
- swapType: swapType,
261
- swapAddress: (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero,
262
- },
263
- ], false)]);
264
- }
265
- nextCoins.add(underlying_coin_addresses[j]);
266
- _x.label = 10;
267
- case 10:
268
- j++;
269
- return [3 /*break*/, 8];
270
- case 11:
271
- _b++;
272
- return [3 /*break*/, 3];
273
- case 12:
274
- _a++;
275
- return [3 /*break*/, 2];
276
- case 13:
277
- // If target output coin is reached, search is finished. Assumption: the shorter route, the better.
278
- if (outputCoinAddress in routes)
279
- return [3 /*break*/, 15];
280
- markedCoins.push.apply(markedCoins, curCoins);
281
- curCoins = Array.from(nextCoins);
282
- nextCoins = new Set();
283
- _x.label = 14;
284
- case 14:
285
- step++;
286
- return [3 /*break*/, 1];
287
- case 15: return [2 /*return*/, (_w = routes[outputCoinAddress]) !== null && _w !== void 0 ? _w : []];
288
- }
289
- });
290
- }); };
291
- exports._findAllRoutesTheShorterTheBetter = _findAllRoutesTheShorterTheBetter;
292
70
  var getNewRoute = function (route, poolId, poolAddress, inputCoinAddress, outputCoinAddress, i, j, swapType, swapAddress, tvl) {
293
71
  var routePoolIds = route.steps.map(function (s) { return s.poolId; });
294
72
  // Steps <= 4
@@ -303,14 +81,15 @@ var getNewRoute = function (route, poolId, poolAddress, inputCoinAddress, output
303
81
  totalTvl: route.totalTvl + tvl,
304
82
  };
305
83
  };
306
- // --------------------------- MAIN ROUTER ---------------------------
307
84
  var MAX_ROUTES_FOR_ONE_COIN = 3;
308
85
  var filterRoutes = function (routes, inputCoinAddress, sortFn) {
309
- var routesByPoolIds = routes.map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
310
86
  return routes
311
87
  .filter(function (r) { return r.steps.length > 0; })
312
88
  .filter(function (r) { return r.steps[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
313
- .filter(function (r, i) { return routesByPoolIds.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i; }) // Route duplications
89
+ .filter(function (r, i, _routes) {
90
+ var routesByPoolIds = _routes.map(function (r) { return r.steps.map(function (s) { return s.poolId; }).toString(); });
91
+ return routesByPoolIds.indexOf(r.steps.map(function (s) { return s.poolId; }).toString()) === i;
92
+ }) // Route duplications
314
93
  .sort(sortFn).slice(0, MAX_ROUTES_FOR_ONE_COIN);
315
94
  };
316
95
  var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.steps.length - b.steps.length; };
@@ -323,8 +102,8 @@ var filterMaticFactory83Route = function (routes) {
323
102
  });
324
103
  };
325
104
  // Inspired by Dijkstra's algorithm
326
- var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
327
- var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_2, inCoin, routes;
105
+ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
106
+ var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_1, inCoin, routes;
328
107
  var _a, _b;
329
108
  var _c, _d, _e, _f, _h, _j, _k, _l, _m, _o, _p, _q, _r;
330
109
  return __generator(this, function (_s) {
@@ -349,7 +128,7 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
349
128
  case 2:
350
129
  if (!(step < 4)) return [3 /*break*/, 8];
351
130
  _loop_1 = function (inCoin) {
352
- var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2, _t, ALL_POOLS_3, _u, poolId, poolData;
131
+ var outCoin_1, newRoutesByTvl, newRoutesByLength, _loop_2, _t, ALL_POOLS_1, _u, poolId, poolData;
353
132
  return __generator(this, function (_v) {
354
133
  switch (_v.label) {
355
134
  case 0:
@@ -518,11 +297,11 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
518
297
  }
519
298
  });
520
299
  };
521
- _t = 0, ALL_POOLS_3 = ALL_POOLS;
300
+ _t = 0, ALL_POOLS_1 = ALL_POOLS;
522
301
  _v.label = 1;
523
302
  case 1:
524
- if (!(_t < ALL_POOLS_3.length)) return [3 /*break*/, 4];
525
- _u = ALL_POOLS_3[_t], poolId = _u[0], poolData = _u[1];
303
+ if (!(_t < ALL_POOLS_1.length)) return [3 /*break*/, 4];
304
+ _u = ALL_POOLS_1[_t], poolId = _u[0], poolData = _u[1];
526
305
  return [5 /*yield**/, _loop_2(poolId, poolData)];
527
306
  case 2:
528
307
  _v.sent();
@@ -534,11 +313,11 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
534
313
  }
535
314
  });
536
315
  };
537
- _i = 0, curCoins_2 = curCoins;
316
+ _i = 0, curCoins_1 = curCoins;
538
317
  _s.label = 3;
539
318
  case 3:
540
- if (!(_i < curCoins_2.length)) return [3 /*break*/, 6];
541
- inCoin = curCoins_2[_i];
319
+ if (!(_i < curCoins_1.length)) return [3 /*break*/, 6];
320
+ inCoin = curCoins_1[_i];
542
321
  return [5 /*yield**/, _loop_1(inCoin)];
543
322
  case 4:
544
323
  _s.sent();
@@ -562,16 +341,6 @@ var _findAllRoutesTvl = function (inputCoinAddress, outputCoinAddress) { return
562
341
  }
563
342
  });
564
343
  }); };
565
- exports._findAllRoutesTvl = _findAllRoutesTvl;
566
- var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
567
- return __generator(this, function (_a) {
568
- switch (_a.label) {
569
- case 0: return [4 /*yield*/, (0, exports._findAllRoutesTvl)(inputCoinAddress, outputCoinAddress)];
570
- case 1: return [2 /*return*/, _a.sent()];
571
- }
572
- });
573
- }); };
574
- exports._findAllRoutes = _findAllRoutes;
575
344
  var _getRouteKey = function (route, inputCoinAddress, outputCoinAddress) {
576
345
  var sortedCoins = [inputCoinAddress, outputCoinAddress].sort();
577
346
  var key = "".concat(sortedCoins[0], "-->");
@@ -654,7 +423,7 @@ var _getBestRouteAndOutput = (0, memoizee_1.default)(function (inputCoinAddress,
654
423
  outputUsd: 0,
655
424
  txCostUsd: 0,
656
425
  }];
657
- return [4 /*yield*/, (0, exports._findAllRoutes)(inputCoinAddress, outputCoinAddress)];
426
+ return [4 /*yield*/, _findAllRoutes(inputCoinAddress, outputCoinAddress)];
658
427
  case 1:
659
428
  routesRaw = (_f.sent()).map(function (steps) { return ({ steps: steps, _output: ethers_1.ethers.BigNumber.from(0), outputUsd: 0, txCostUsd: 0 }); });
660
429
  routes = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.25.2",
3
+ "version": "2.25.4",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",