@curvefi/api 1.16.0 → 1.17.2

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 CHANGED
@@ -717,3 +717,64 @@ console.log(await pool.gaugeClaimableRewards());
717
717
  // ]
718
718
  await pool.gaugeClaimRewards();
719
719
  ```
720
+
721
+ ## Deposit&Stake
722
+ Add liquidity and deposit into gauge in one transaction.
723
+
724
+ ### Underlying
725
+ ```ts
726
+ (async () => {
727
+ const pool = new curve.Pool('compound');
728
+ const amounts = ['1000', '1000'];
729
+
730
+ console.log(await pool.underlyingCoinBalances());
731
+ // { DAI: '10000.0', USDC: '10000.0' }
732
+ console.log(await pool.lpTokenBalances());
733
+ // { lpToken: '0.0', gauge: '0.0' }
734
+
735
+ console.log(await pool.depositAndStakeExpected(amounts));
736
+ // 1820.604572902286288394
737
+ console.log(await pool.depositAndStakeSlippage(amounts));
738
+ // -0.0000036435051742755193
739
+
740
+ console.log(await pool.depositAndStakeIsApproved(amounts));
741
+ // false
742
+
743
+ await pool.depositAndStakeApprove(amounts);
744
+ await pool.depositAndStake(amounts);
745
+
746
+ console.log(await pool.underlyingCoinBalances());
747
+ // { DAI: '9000.0', USDC: '9000.0' }
748
+ console.log(await pool.lpTokenBalances());
749
+ // { lpToken: '0.0', gauge: '1820.556829935710883568' }
750
+ })();
751
+ ```
752
+
753
+ ### Wrapped
754
+ ```ts
755
+ (async () => {
756
+ const pool = new curve.Pool('compound');
757
+ const amounts = ['1000', '1000'];
758
+
759
+ console.log(await pool.coinBalances());
760
+ // { cDAI: '10000.0', cUSDC: '10000.0' }
761
+ console.log(await pool.lpTokenBalances());
762
+ // { lpToken: '0.0', gauge: '1820.556829935710883568' }
763
+
764
+ console.log(await pool.depositAndStakeWrappedExpected(amounts));
765
+ // 40.328408669183101673
766
+ console.log(await pool.depositAndStakeWrappedSlippage(amounts));
767
+ // -0.0020519915272297325
768
+
769
+ console.log(await pool.depositAndStakeWrappedIsApproved(amounts));
770
+ // false
771
+
772
+ await pool.depositAndStakeWrappedApprove(amounts);
773
+ await pool.depositAndStakeWrapped(amounts);
774
+
775
+ console.log(await pool.coinBalances());
776
+ // { cDAI: '9000.0', cUSDC: '9000.0' }
777
+ console.log(await pool.lpTokenBalances());
778
+ // { lpToken: '0.0', gauge: '1860.884096082215274556' }
779
+ })();
780
+ ```
@@ -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[5]"
26
+ },
27
+ {
28
+ "name": "amounts",
29
+ "type": "uint256[5]"
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
+ ]
@@ -5,6 +5,7 @@ export declare const ALIASES_ETHEREUM: {
5
5
  gauge_controller: string;
6
6
  address_provider: string;
7
7
  router: string;
8
+ deposit_and_stake: string;
8
9
  registry_exchange: string;
9
10
  };
10
11
  export declare const ALIASES_POLYGON: {
@@ -14,5 +15,6 @@ export declare const ALIASES_POLYGON: {
14
15
  gauge_controller: string;
15
16
  address_provider: string;
16
17
  router: string;
18
+ deposit_and_stake: string;
17
19
  registry_exchange: string;
18
20
  };
@@ -8,6 +8,7 @@ exports.ALIASES_ETHEREUM = {
8
8
  "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
9
9
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
10
10
  "router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
11
+ "deposit_and_stake": "0x271fbE8aB7f1fB262f81C77Ea5303F03DA9d3d6A",
11
12
  "registry_exchange": "",
12
13
  };
13
14
  exports.ALIASES_POLYGON = {
@@ -17,5 +18,6 @@ exports.ALIASES_POLYGON = {
17
18
  "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
18
19
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
19
20
  "router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
21
+ "deposit_and_stake": "0x43FF7b96808988C9d19C1d05Ef19658B03e8a143",
20
22
  "registry_exchange": "",
21
23
  };
package/lib/curve.d.ts CHANGED
@@ -27,6 +27,7 @@ export declare let ALIASES: {
27
27
  gauge_controller: string;
28
28
  address_provider: string;
29
29
  router: string;
30
+ deposit_and_stake: string;
30
31
  registry_exchange: string;
31
32
  };
32
33
  declare class Curve {
package/lib/curve.js CHANGED
@@ -70,6 +70,7 @@ var votingescrow_json_1 = __importDefault(require("./constants/abis/json/votinge
70
70
  var address_provider_json_1 = __importDefault(require("./constants/abis/json/address_provider.json"));
71
71
  var gaugecontroller_json_1 = __importDefault(require("./constants/abis/json/gaugecontroller.json"));
72
72
  var router_json_1 = __importDefault(require("./constants/abis/json/router.json"));
73
+ var deposit_and_stake_json_1 = __importDefault(require("./constants/abis/json/deposit_and_stake.json"));
73
74
  var registry_exchange_json_1 = __importDefault(require("./constants/abis/json/registry_exchange.json"));
74
75
  var streamer_json_1 = __importDefault(require("./constants/abis/json/streamer.json"));
75
76
  var abis_ethereum_1 = require("./constants/abis/abis-ethereum");
@@ -84,6 +85,7 @@ exports.ALIASES = {
84
85
  "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
85
86
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
86
87
  "router": "0xfA9a30350048B2BF66865ee20363067c66f67e58",
88
+ "deposit_and_stake": "0x271fbE8aB7f1fB262f81C77Ea5303F03DA9d3d6A",
87
89
  "registry_exchange": "",
88
90
  };
89
91
  var Curve = /** @class */ (function () {
@@ -399,6 +401,14 @@ var Curve = /** @class */ (function () {
399
401
  contract: new ethers_1.Contract(exports.ALIASES.router, router_json_1.default, this.signer || this.provider),
400
402
  multicallContract: new ethcall_1.Contract(exports.ALIASES.router, router_json_1.default),
401
403
  };
404
+ this.contracts[exports.ALIASES.deposit_and_stake] = {
405
+ contract: new ethers_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default, this.signer || this.provider),
406
+ multicallContract: new ethcall_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default),
407
+ };
408
+ this.contracts[exports.ALIASES.deposit_and_stake.toLowerCase()] = {
409
+ contract: new ethers_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default, this.signer || this.provider),
410
+ multicallContract: new ethcall_1.Contract(exports.ALIASES.deposit_and_stake, deposit_and_stake_json_1.default),
411
+ };
402
412
  return [2 /*return*/];
403
413
  }
404
414
  });
package/lib/index.d.ts CHANGED
@@ -23,6 +23,7 @@ declare function setCustomFeeData(customFeeData: {
23
23
  declare const curve: {
24
24
  init: typeof init;
25
25
  getPoolList: () => string[];
26
+ getUsdRate: (coin: string) => Promise<number>;
26
27
  setCustomFeeData: typeof setCustomFeeData;
27
28
  signerAddress: string;
28
29
  chainId: number;
package/lib/index.js CHANGED
@@ -63,6 +63,7 @@ function setCustomFeeData(customFeeData) {
63
63
  var curve = {
64
64
  init: init,
65
65
  getPoolList: utils_1.getPoolList,
66
+ getUsdRate: utils_1.getUsdRate,
66
67
  setCustomFeeData: setCustomFeeData,
67
68
  signerAddress: '',
68
69
  chainId: 0,
package/lib/pools.d.ts CHANGED
@@ -25,8 +25,12 @@ export declare class Pool {
25
25
  estimateGas: {
26
26
  addLiquidityApprove: (amounts: string[]) => Promise<number>;
27
27
  addLiquidity: (amounts: string[]) => Promise<number>;
28
+ depositAndStakeApprove: (amounts: string[]) => Promise<number>;
29
+ depositAndStake: (amounts: string[]) => Promise<number>;
28
30
  addLiquidityWrappedApprove: (amounts: string[]) => Promise<number>;
29
31
  addLiquidityWrapped: (amounts: string[]) => Promise<number>;
32
+ depositAndStakeWrappedApprove: (amounts: string[]) => Promise<number>;
33
+ depositAndStakeWrapped: (amounts: string[]) => Promise<number>;
30
34
  gaugeDepositApprove: (lpTokenAmount: string) => Promise<number>;
31
35
  gaugeDeposit: (lpTokenAmount: string) => Promise<number>;
32
36
  gaugeWithdraw: (lpTokenAmount: string) => Promise<number>;
@@ -84,6 +88,14 @@ export declare class Pool {
84
88
  private addLiquidityEstimateGas;
85
89
  balancedAmounts: () => Promise<string[]>;
86
90
  addLiquidity: (amounts: string[]) => Promise<string>;
91
+ depositAndStakeExpected: (amounts: string[]) => Promise<string>;
92
+ depositAndStakeSlippage: (amounts: string[]) => Promise<string>;
93
+ depositAndStakeIsApproved: (amounts: string[]) => Promise<boolean>;
94
+ private depositAndStakeApproveEstimateGas;
95
+ depositAndStakeApprove: (amounts: string[]) => Promise<string[]>;
96
+ private depositAndStakeEstimateGas;
97
+ depositAndStake: (amounts: string[]) => Promise<string>;
98
+ private _depositAndStake;
87
99
  balancedWrappedAmounts: () => Promise<string[]>;
88
100
  addLiquidityWrappedExpected: (amounts: string[]) => Promise<string>;
89
101
  addLiquidityWrappedSlippage: (amounts: string[]) => Promise<string>;
@@ -92,6 +104,13 @@ export declare class Pool {
92
104
  addLiquidityWrappedApprove: (amounts: string[]) => Promise<string[]>;
93
105
  private addLiquidityWrappedEstimateGas;
94
106
  addLiquidityWrapped: (amounts: string[]) => Promise<string>;
107
+ depositAndStakeWrappedExpected: (amounts: string[]) => Promise<string>;
108
+ depositAndStakeWrappedSlippage: (amounts: string[]) => Promise<string>;
109
+ depositAndStakeWrappedIsApproved: (amounts: string[]) => Promise<boolean>;
110
+ private depositAndStakeWrappedApproveEstimateGas;
111
+ depositAndStakeWrappedApprove: (amounts: string[]) => Promise<string[]>;
112
+ private depositAndStakeWrappedEstimateGas;
113
+ depositAndStakeWrapped: (amounts: string[]) => Promise<string>;
95
114
  removeLiquidityExpected: (lpTokenAmount: string) => Promise<string[]>;
96
115
  removeLiquidityIsApproved: (lpTokenAmount: string) => Promise<boolean>;
97
116
  private removeLiquidityApproveEstimateGas;
@@ -161,7 +180,11 @@ export declare class Pool {
161
180
  private _getCoinIdx;
162
181
  private _getRates;
163
182
  private _balances;
183
+ private _underlyingPrices;
184
+ private _wrappedPrices;
185
+ private _addLiquidityCryptoSlippage;
164
186
  private _addLiquiditySlippage;
187
+ private _removeLiquidityCryptoSlippage;
165
188
  private _removeLiquiditySlippage;
166
189
  private _balancedAmounts;
167
190
  private _calcLpTokenAmount;
package/lib/pools.js CHANGED
@@ -382,49 +382,52 @@ var Pool = /** @class */ (function () {
382
382
  });
383
383
  }); };
384
384
  this.addLiquiditySlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
385
- var totalAmount, expected, _a;
386
- return __generator(this, function (_c) {
387
- switch (_c.label) {
385
+ var prices_1, totalAmountUSD, expected_1, _a, totalAmount, expected, _c;
386
+ return __generator(this, function (_d) {
387
+ switch (_d.label) {
388
388
  case 0:
389
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
389
+ if (!this.isCrypto) return [3 /*break*/, 4];
390
+ return [4 /*yield*/, this._underlyingPrices()];
391
+ case 1:
392
+ prices_1 = _d.sent();
393
+ totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_1[i]); }, 0);
390
394
  _a = Number;
391
395
  return [4 /*yield*/, this.addLiquidityExpected(amounts)];
392
- case 1:
393
- expected = _a.apply(void 0, [_c.sent()]);
396
+ case 2:
397
+ expected_1 = _a.apply(void 0, [_d.sent()]);
398
+ return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_1)];
399
+ case 3: return [2 /*return*/, _d.sent()];
400
+ case 4:
401
+ totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
402
+ _c = Number;
403
+ return [4 /*yield*/, this.addLiquidityExpected(amounts)];
404
+ case 5:
405
+ expected = _c.apply(void 0, [_d.sent()]);
394
406
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected)];
395
- case 2: return [2 /*return*/, _c.sent()];
407
+ case 6: return [2 /*return*/, _d.sent()];
396
408
  }
397
409
  });
398
410
  }); };
399
411
  this.addLiquidityIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
400
- var spender;
401
412
  return __generator(this, function (_a) {
402
413
  switch (_a.label) {
403
- case 0:
404
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
405
- return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, spender)];
414
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, this.zap || this.swap)];
406
415
  case 1: return [2 /*return*/, _a.sent()];
407
416
  }
408
417
  });
409
418
  }); };
410
419
  this.addLiquidityApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
411
- var spender;
412
420
  return __generator(this, function (_a) {
413
421
  switch (_a.label) {
414
- case 0:
415
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
416
- return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, spender)];
422
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
417
423
  case 1: return [2 /*return*/, _a.sent()];
418
424
  }
419
425
  });
420
426
  }); };
421
427
  this.addLiquidityApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
422
- var spender;
423
428
  return __generator(this, function (_a) {
424
429
  switch (_a.label) {
425
- case 0:
426
- spender = (['compound', 'usdt', 'y', 'busd', 'pax'].includes(this.name) || this.isMeta) ? this.zap : this.swap;
427
- return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, spender)];
430
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, this.zap || this.swap)];
428
431
  case 1: return [2 /*return*/, _a.sent()];
429
432
  }
430
433
  });
@@ -474,7 +477,7 @@ var Pool = /** @class */ (function () {
474
477
  });
475
478
  }); };
476
479
  this.balancedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
477
- var poolBalances, walletBalances, _a, _c;
480
+ var poolBalances, walletBalances, _a, _c, prices_2, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
478
481
  return __generator(this, function (_d) {
479
482
  switch (_d.label) {
480
483
  case 0: return [4 /*yield*/, this.getPoolBalances()];
@@ -484,7 +487,15 @@ var Pool = /** @class */ (function () {
484
487
  return [4 /*yield*/, this.underlyingCoinBalances()];
485
488
  case 2:
486
489
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
487
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
490
+ if (!this.isCrypto) return [3 /*break*/, 4];
491
+ return [4 /*yield*/, this._underlyingPrices()];
492
+ case 3:
493
+ prices_2 = _d.sent();
494
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_2[i]; });
495
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_2[i]; });
496
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.underlyingDecimals);
497
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_2[i], poolBalances[i])); })];
498
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.underlyingDecimals)];
488
499
  }
489
500
  });
490
501
  }); };
@@ -521,8 +532,197 @@ var Pool = /** @class */ (function () {
521
532
  }
522
533
  });
523
534
  }); };
535
+ this.depositAndStakeExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
536
+ return __generator(this, function (_a) {
537
+ switch (_a.label) {
538
+ case 0: return [4 /*yield*/, this.addLiquidityExpected(amounts)];
539
+ case 1: return [2 /*return*/, _a.sent()];
540
+ }
541
+ });
542
+ }); };
543
+ this.depositAndStakeSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
544
+ return __generator(this, function (_a) {
545
+ switch (_a.label) {
546
+ case 0: return [4 /*yield*/, this.addLiquiditySlippage(amounts)];
547
+ case 1: return [2 /*return*/, _a.sent()];
548
+ }
549
+ });
550
+ }); };
551
+ this.depositAndStakeIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
552
+ var coinsAllowance, gaugeContract, gaugeAllowance;
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
556
+ case 1:
557
+ coinsAllowance = _a.sent();
558
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
559
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
560
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
561
+ case 2:
562
+ gaugeAllowance = _a.sent();
563
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
564
+ case 3: return [2 /*return*/, coinsAllowance];
565
+ }
566
+ });
567
+ }); };
568
+ this.depositAndStakeApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
569
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
570
+ return __generator(this, function (_a) {
571
+ switch (_a.label) {
572
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
573
+ case 1:
574
+ approveCoinsGas = _a.sent();
575
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
576
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
577
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
578
+ case 2:
579
+ gaugeAllowance = _a.sent();
580
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
581
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
582
+ case 3:
583
+ approveGaugeGas = (_a.sent()).toNumber();
584
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
585
+ case 4: return [2 /*return*/, approveCoinsGas];
586
+ }
587
+ });
588
+ }); };
589
+ this.depositAndStakeApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
590
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
591
+ return __generator(this, function (_a) {
592
+ switch (_a.label) {
593
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
594
+ case 1:
595
+ approveCoinsTx = _a.sent();
596
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
597
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
598
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
599
+ case 2:
600
+ gaugeAllowance = _a.sent();
601
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
602
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
603
+ case 3:
604
+ gasLimit = (_a.sent()).mul(130).div(100);
605
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
606
+ case 4:
607
+ approveGaugeTx = (_a.sent()).hash;
608
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
609
+ case 5: return [2 /*return*/, approveCoinsTx];
610
+ }
611
+ });
612
+ }); };
613
+ this.depositAndStakeEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
614
+ return __generator(this, function (_a) {
615
+ switch (_a.label) {
616
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
617
+ case 1: return [2 /*return*/, _a.sent()];
618
+ }
619
+ });
620
+ }); };
621
+ this.depositAndStake = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
622
+ return __generator(this, function (_a) {
623
+ switch (_a.label) {
624
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
625
+ case 1: return [2 /*return*/, _a.sent()];
626
+ }
627
+ });
628
+ }); };
629
+ this._depositAndStake = function (amounts, isUnderlying, estimateGas) { return __awaiter(_this, void 0, void 0, function () {
630
+ var coinAddresses, coins, decimals, depositAddress, balances, _a, _c, _d, _e, _f, i, allowance, _h, _amounts, contract, useUnderlying, _minMintAmount, _j, _k, _l, _m, _o, ethIndex, value, i, _gas, gasLimit;
631
+ return __generator(this, function (_p) {
632
+ switch (_p.label) {
633
+ case 0:
634
+ coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
635
+ coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
636
+ decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
637
+ depositAddress = isUnderlying ? this.zap || this.swap : this.swap;
638
+ if (amounts.length !== coinAddresses.length) {
639
+ throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
640
+ }
641
+ if (!isUnderlying) return [3 /*break*/, 2];
642
+ _d = (_c = Object).values;
643
+ return [4 /*yield*/, this.underlyingCoinBalances()];
644
+ case 1:
645
+ _a = _d.apply(_c, [_p.sent()]);
646
+ return [3 /*break*/, 4];
647
+ case 2:
648
+ _f = (_e = Object).values;
649
+ return [4 /*yield*/, this.coinBalances()];
650
+ case 3:
651
+ _a = _f.apply(_e, [_p.sent()]);
652
+ _p.label = 4;
653
+ case 4:
654
+ balances = _a;
655
+ for (i = 0; i < balances.length; i++) {
656
+ if (Number(balances[i]) < Number(amounts[i])) {
657
+ throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
658
+ }
659
+ }
660
+ if (!isUnderlying) return [3 /*break*/, 6];
661
+ return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
662
+ case 5:
663
+ _h = _p.sent();
664
+ return [3 /*break*/, 8];
665
+ case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
666
+ case 7:
667
+ _h = _p.sent();
668
+ _p.label = 8;
669
+ case 8:
670
+ allowance = _h;
671
+ if (estimateGas && !allowance) {
672
+ throw Error("Token allowance is needed to estimate gas");
673
+ }
674
+ if (!!estimateGas) return [3 /*break*/, 12];
675
+ if (!isUnderlying) return [3 /*break*/, 10];
676
+ return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
677
+ case 9:
678
+ _p.sent();
679
+ return [3 /*break*/, 12];
680
+ case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
681
+ case 11:
682
+ _p.sent();
683
+ _p.label = 12;
684
+ case 12:
685
+ _amounts = amounts.map(function (amount, i) {
686
+ return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
687
+ });
688
+ contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
689
+ useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
690
+ if (!isUnderlying) return [3 /*break*/, 14];
691
+ _l = (_k = ethers_1.ethers.utils).parseUnits;
692
+ return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
693
+ case 13:
694
+ _j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
695
+ return [3 /*break*/, 16];
696
+ case 14:
697
+ _o = (_m = ethers_1.ethers.utils).parseUnits;
698
+ return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
699
+ case 15:
700
+ _j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
701
+ _p.label = 16;
702
+ case 16:
703
+ _minMintAmount = _j;
704
+ ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
705
+ value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
706
+ for (i = 0; i < 5; i++) {
707
+ coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
708
+ _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
709
+ }
710
+ return [4 /*yield*/, contract.estimateGas.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
711
+ case 17:
712
+ _gas = (_p.sent());
713
+ if (estimateGas)
714
+ return [2 /*return*/, _gas.toNumber()];
715
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
716
+ case 18:
717
+ _p.sent();
718
+ gasLimit = _gas.mul(200).div(100);
719
+ return [4 /*yield*/, contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, this.isFactory && isUnderlying ? this.swap : ethers_1.ethers.constants.AddressZero, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
720
+ case 19: return [2 /*return*/, (_p.sent()).hash];
721
+ }
722
+ });
723
+ }); };
524
724
  this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
525
- var poolBalances, walletBalances, _a, _c;
725
+ var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
526
726
  return __generator(this, function (_d) {
527
727
  switch (_d.label) {
528
728
  case 0:
@@ -536,7 +736,15 @@ var Pool = /** @class */ (function () {
536
736
  return [4 /*yield*/, this.coinBalances()];
537
737
  case 2:
538
738
  walletBalances = _c.apply(_a, [_d.sent()]).map(Number);
539
- return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
739
+ if (!this.isCrypto) return [3 /*break*/, 4];
740
+ return [4 /*yield*/, this._wrappedPrices()];
741
+ case 3:
742
+ prices_3 = _d.sent();
743
+ poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices_3[i]; });
744
+ walletBalancesUSD = walletBalances.map(function (b, i) { return b * prices_3[i]; });
745
+ balancedAmountsUSD = this._balancedAmounts(poolBalancesUSD, walletBalancesUSD, this.decimals);
746
+ return [2 /*return*/, balancedAmountsUSD.map(function (b, i) { return String(Math.min(Number(b) / prices_3[i], poolBalances[i])); })];
747
+ case 4: return [2 /*return*/, this._balancedAmounts(poolBalances, walletBalances, this.decimals)];
540
748
  }
541
749
  });
542
750
  }); };
@@ -555,20 +763,32 @@ var Pool = /** @class */ (function () {
555
763
  });
556
764
  }); };
557
765
  this.addLiquidityWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
558
- var totalAmount, expected, _a;
559
- return __generator(this, function (_c) {
560
- switch (_c.label) {
766
+ var prices_4, totalAmountUSD, expected_2, _a, totalAmount, expected, _c;
767
+ return __generator(this, function (_d) {
768
+ switch (_d.label) {
561
769
  case 0:
562
770
  if (this.isFake) {
563
771
  throw Error("".concat(this.name, " pool doesn't have this method"));
564
772
  }
565
- totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
773
+ if (!this.isCrypto) return [3 /*break*/, 4];
774
+ return [4 /*yield*/, this._wrappedPrices()];
775
+ case 1:
776
+ prices_4 = _d.sent();
777
+ totalAmountUSD = amounts.reduce(function (s, a, i) { return s + (Number(a) * prices_4[i]); }, 0);
566
778
  _a = Number;
567
779
  return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
568
- case 1:
569
- expected = _a.apply(void 0, [_c.sent()]);
780
+ case 2:
781
+ expected_2 = _a.apply(void 0, [_d.sent()]);
782
+ return [4 /*yield*/, this._addLiquidityCryptoSlippage(totalAmountUSD, expected_2, false)];
783
+ case 3: return [2 /*return*/, _d.sent()];
784
+ case 4:
785
+ totalAmount = amounts.reduce(function (s, a) { return s + Number(a); }, 0);
786
+ _c = Number;
787
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
788
+ case 5:
789
+ expected = _c.apply(void 0, [_d.sent()]);
570
790
  return [4 /*yield*/, this._addLiquiditySlippage(totalAmount, expected, false)];
571
- case 2: return [2 /*return*/, _c.sent()];
791
+ case 6: return [2 /*return*/, _d.sent()];
572
792
  }
573
793
  });
574
794
  }); };
@@ -675,6 +895,128 @@ var Pool = /** @class */ (function () {
675
895
  }
676
896
  });
677
897
  }); };
898
+ this.depositAndStakeWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
899
+ return __generator(this, function (_a) {
900
+ switch (_a.label) {
901
+ case 0:
902
+ if (this.isFake) {
903
+ throw Error("".concat(this.name, " pool doesn't have this method"));
904
+ }
905
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
906
+ case 1: return [2 /*return*/, _a.sent()];
907
+ }
908
+ });
909
+ }); };
910
+ this.depositAndStakeWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
911
+ return __generator(this, function (_a) {
912
+ switch (_a.label) {
913
+ case 0:
914
+ if (this.isFake) {
915
+ throw Error("".concat(this.name, " pool doesn't have this method"));
916
+ }
917
+ return [4 /*yield*/, this.addLiquidityWrappedSlippage(amounts)];
918
+ case 1: return [2 /*return*/, _a.sent()];
919
+ }
920
+ });
921
+ }); };
922
+ this.depositAndStakeWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
923
+ var coinsAllowance, gaugeContract, gaugeAllowance;
924
+ return __generator(this, function (_a) {
925
+ switch (_a.label) {
926
+ case 0:
927
+ if (this.isFake) {
928
+ throw Error("".concat(this.name, " pool doesn't have this method"));
929
+ }
930
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
931
+ case 1:
932
+ coinsAllowance = _a.sent();
933
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
934
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
935
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
936
+ case 2:
937
+ gaugeAllowance = _a.sent();
938
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
939
+ case 3: return [2 /*return*/, coinsAllowance];
940
+ }
941
+ });
942
+ }); };
943
+ this.depositAndStakeWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
944
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
945
+ return __generator(this, function (_a) {
946
+ switch (_a.label) {
947
+ case 0:
948
+ if (this.isFake) {
949
+ throw Error("".concat(this.name, " pool doesn't have this method"));
950
+ }
951
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
952
+ case 1:
953
+ approveCoinsGas = _a.sent();
954
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
955
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
956
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
957
+ case 2:
958
+ gaugeAllowance = _a.sent();
959
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
960
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
961
+ case 3:
962
+ approveGaugeGas = (_a.sent()).toNumber();
963
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
964
+ case 4: return [2 /*return*/, approveCoinsGas];
965
+ }
966
+ });
967
+ }); };
968
+ this.depositAndStakeWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
969
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
970
+ return __generator(this, function (_a) {
971
+ switch (_a.label) {
972
+ case 0:
973
+ if (this.isFake) {
974
+ throw Error("".concat(this.name, " pool doesn't have this method"));
975
+ }
976
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
977
+ case 1:
978
+ approveCoinsTx = _a.sent();
979
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
980
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
981
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
982
+ case 2:
983
+ gaugeAllowance = _a.sent();
984
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
985
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
986
+ case 3:
987
+ gasLimit = (_a.sent()).mul(130).div(100);
988
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
989
+ case 4:
990
+ approveGaugeTx = (_a.sent()).hash;
991
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
992
+ case 5: return [2 /*return*/, approveCoinsTx];
993
+ }
994
+ });
995
+ }); };
996
+ this.depositAndStakeWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
997
+ return __generator(this, function (_a) {
998
+ switch (_a.label) {
999
+ case 0:
1000
+ if (this.isFake) {
1001
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1002
+ }
1003
+ return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1004
+ case 1: return [2 /*return*/, _a.sent()];
1005
+ }
1006
+ });
1007
+ }); };
1008
+ this.depositAndStakeWrapped = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1009
+ return __generator(this, function (_a) {
1010
+ switch (_a.label) {
1011
+ case 0:
1012
+ if (this.isFake) {
1013
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1014
+ }
1015
+ return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1016
+ case 1: return [2 /*return*/, _a.sent()];
1017
+ }
1018
+ });
1019
+ }); };
678
1020
  this.removeLiquidityExpected = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
679
1021
  var _lpTokenAmount, _expected;
680
1022
  var _this = this;
@@ -705,7 +1047,7 @@ var Pool = /** @class */ (function () {
705
1047
  return __generator(this, function (_a) {
706
1048
  switch (_a.label) {
707
1049
  case 0:
708
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1050
+ if (!this.zap)
709
1051
  return [2 /*return*/, true];
710
1052
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
711
1053
  case 1: return [2 /*return*/, _a.sent()];
@@ -716,7 +1058,7 @@ var Pool = /** @class */ (function () {
716
1058
  return __generator(this, function (_a) {
717
1059
  switch (_a.label) {
718
1060
  case 0:
719
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1061
+ if (!this.zap)
720
1062
  return [2 /*return*/, 0];
721
1063
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
722
1064
  case 1: return [2 /*return*/, _a.sent()];
@@ -727,7 +1069,7 @@ var Pool = /** @class */ (function () {
727
1069
  return __generator(this, function (_a) {
728
1070
  switch (_a.label) {
729
1071
  case 0:
730
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !this.isMeta)
1072
+ if (!this.zap)
731
1073
  return [2 /*return*/, []];
732
1074
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
733
1075
  case 1: return [2 /*return*/, _a.sent()];
@@ -1153,7 +1495,7 @@ var Pool = /** @class */ (function () {
1153
1495
  });
1154
1496
  }); };
1155
1497
  this.removeLiquidityOneCoinSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1156
- var totalAmount, _a;
1498
+ var totalAmount, _a, coinPrice;
1157
1499
  return __generator(this, function (_c) {
1158
1500
  switch (_c.label) {
1159
1501
  case 0:
@@ -1161,8 +1503,14 @@ var Pool = /** @class */ (function () {
1161
1503
  return [4 /*yield*/, this.removeLiquidityOneCoinExpected(lpTokenAmount, coin)];
1162
1504
  case 1:
1163
1505
  totalAmount = _a.apply(void 0, [_c.sent()]);
1164
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1165
- case 2: return [2 /*return*/, _c.sent()];
1506
+ if (!this.isCrypto) return [3 /*break*/, 4];
1507
+ return [4 /*yield*/, this._underlyingPrices()];
1508
+ case 2:
1509
+ coinPrice = (_c.sent())[this._getCoinIdx(coin)];
1510
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1511
+ case 3: return [2 /*return*/, _c.sent()];
1512
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount))];
1513
+ case 5: return [2 /*return*/, _c.sent()];
1166
1514
  }
1167
1515
  });
1168
1516
  }); };
@@ -1170,7 +1518,7 @@ var Pool = /** @class */ (function () {
1170
1518
  return __generator(this, function (_a) {
1171
1519
  switch (_a.label) {
1172
1520
  case 0:
1173
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1521
+ if (!this.zap)
1174
1522
  return [2 /*return*/, true];
1175
1523
  return [4 /*yield*/, (0, utils_1.hasAllowance)([this.lpToken], [lpTokenAmount], curve_1.curve.signerAddress, this.zap)];
1176
1524
  case 1: return [2 /*return*/, _a.sent()];
@@ -1181,7 +1529,7 @@ var Pool = /** @class */ (function () {
1181
1529
  return __generator(this, function (_a) {
1182
1530
  switch (_a.label) {
1183
1531
  case 0:
1184
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1532
+ if (!this.zap)
1185
1533
  return [2 /*return*/, 0];
1186
1534
  return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)([this.lpToken], [lpTokenAmount], this.zap)];
1187
1535
  case 1: return [2 /*return*/, _a.sent()];
@@ -1192,7 +1540,7 @@ var Pool = /** @class */ (function () {
1192
1540
  return __generator(this, function (_a) {
1193
1541
  switch (_a.label) {
1194
1542
  case 0:
1195
- if (!['compound', 'usdt', 'y', 'busd', 'pax', 'tricrypto2'].includes(this.name) && !(this.name === 'susd') && !this.isMeta)
1543
+ if (!this.zap)
1196
1544
  return [2 /*return*/, []];
1197
1545
  return [4 /*yield*/, (0, utils_1.ensureAllowance)([this.lpToken], [lpTokenAmount], this.zap)];
1198
1546
  case 1: return [2 /*return*/, _a.sent()];
@@ -1286,7 +1634,7 @@ var Pool = /** @class */ (function () {
1286
1634
  });
1287
1635
  }); };
1288
1636
  this.removeLiquidityOneCoinWrappedSlippage = function (lpTokenAmount, coin) { return __awaiter(_this, void 0, void 0, function () {
1289
- var totalAmount, _a;
1637
+ var totalAmount, _a, coinPrice;
1290
1638
  return __generator(this, function (_c) {
1291
1639
  switch (_c.label) {
1292
1640
  case 0:
@@ -1297,8 +1645,14 @@ var Pool = /** @class */ (function () {
1297
1645
  return [4 /*yield*/, this.removeLiquidityOneCoinWrappedExpected(lpTokenAmount, coin)];
1298
1646
  case 1:
1299
1647
  totalAmount = _a.apply(void 0, [_c.sent()]);
1300
- return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1301
- case 2: return [2 /*return*/, _c.sent()];
1648
+ if (!this.isCrypto) return [3 /*break*/, 4];
1649
+ return [4 /*yield*/, this._underlyingPrices()];
1650
+ case 2:
1651
+ coinPrice = (_c.sent())[this._getCoinIdx(coin, false)];
1652
+ return [4 /*yield*/, this._removeLiquidityCryptoSlippage(totalAmount * coinPrice, Number(lpTokenAmount))];
1653
+ case 3: return [2 /*return*/, _c.sent()];
1654
+ case 4: return [4 /*yield*/, this._removeLiquiditySlippage(totalAmount, Number(lpTokenAmount), false)];
1655
+ case 5: return [2 /*return*/, _c.sent()];
1302
1656
  }
1303
1657
  });
1304
1658
  }); };
@@ -2121,6 +2475,90 @@ var Pool = /** @class */ (function () {
2121
2475
  });
2122
2476
  });
2123
2477
  };
2478
+ this._underlyingPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2479
+ var promises, _i, _a, addr;
2480
+ return __generator(this, function (_c) {
2481
+ switch (_c.label) {
2482
+ case 0:
2483
+ promises = [];
2484
+ for (_i = 0, _a = this.underlyingCoinAddresses; _i < _a.length; _i++) {
2485
+ addr = _a[_i];
2486
+ promises.push((0, utils_1._getUsdRate)(addr));
2487
+ }
2488
+ return [4 /*yield*/, Promise.all(promises)];
2489
+ case 1: return [2 /*return*/, _c.sent()];
2490
+ }
2491
+ });
2492
+ }); };
2493
+ // NOTE! It may crash!
2494
+ this._wrappedPrices = function () { return __awaiter(_this, void 0, void 0, function () {
2495
+ var promises, _i, _a, addr;
2496
+ return __generator(this, function (_c) {
2497
+ switch (_c.label) {
2498
+ case 0:
2499
+ promises = [];
2500
+ for (_i = 0, _a = this.coinAddresses; _i < _a.length; _i++) {
2501
+ addr = _a[_i];
2502
+ promises.push((0, utils_1._getUsdRate)(addr));
2503
+ }
2504
+ return [4 /*yield*/, Promise.all(promises)];
2505
+ case 1: return [2 /*return*/, _c.sent()];
2506
+ }
2507
+ });
2508
+ }); };
2509
+ this._addLiquidityCryptoSlippage = function (totalAmountUSD, expected, useUnderlying) {
2510
+ if (useUnderlying === void 0) { useUnderlying = true; }
2511
+ return __awaiter(_this, void 0, void 0, function () {
2512
+ var poolBalances, _a, prices, _c, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _d, _e, _f;
2513
+ return __generator(this, function (_h) {
2514
+ switch (_h.label) {
2515
+ case 0:
2516
+ if (!useUnderlying) return [3 /*break*/, 2];
2517
+ return [4 /*yield*/, this.getPoolBalances()];
2518
+ case 1:
2519
+ _a = (_h.sent()).map(Number);
2520
+ return [3 /*break*/, 4];
2521
+ case 2: return [4 /*yield*/, this.getPoolWrappedBalances()];
2522
+ case 3:
2523
+ _a = (_h.sent()).map(Number);
2524
+ _h.label = 4;
2525
+ case 4:
2526
+ poolBalances = _a;
2527
+ if (!useUnderlying) return [3 /*break*/, 6];
2528
+ return [4 /*yield*/, this._underlyingPrices()];
2529
+ case 5:
2530
+ _c = _h.sent();
2531
+ return [3 /*break*/, 8];
2532
+ case 6: return [4 /*yield*/, this._wrappedPrices()];
2533
+ case 7:
2534
+ _c = _h.sent();
2535
+ _h.label = 8;
2536
+ case 8:
2537
+ prices = _c;
2538
+ poolBalancesUSD = poolBalances.map(function (b, i) { return Number(b) * prices[i]; });
2539
+ poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
2540
+ poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
2541
+ balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
2542
+ balancedAmounts = balancedAmountsUSD.map(function (a, i) { return String(a / prices[i]); });
2543
+ if (!useUnderlying) return [3 /*break*/, 10];
2544
+ _e = Number;
2545
+ return [4 /*yield*/, this.addLiquidityExpected(balancedAmounts)];
2546
+ case 9:
2547
+ _d = _e.apply(void 0, [_h.sent()]);
2548
+ return [3 /*break*/, 12];
2549
+ case 10:
2550
+ _f = Number;
2551
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(balancedAmounts)];
2552
+ case 11:
2553
+ _d = _f.apply(void 0, [_h.sent()]);
2554
+ _h.label = 12;
2555
+ case 12:
2556
+ balancedExpected = _d;
2557
+ return [2 /*return*/, String((balancedExpected - expected) / balancedExpected)];
2558
+ }
2559
+ });
2560
+ });
2561
+ };
2124
2562
  this._addLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
2125
2563
  if (useUnderlying === void 0) { useUnderlying = true; }
2126
2564
  return __awaiter(_this, void 0, void 0, function () {
@@ -2161,6 +2599,41 @@ var Pool = /** @class */ (function () {
2161
2599
  });
2162
2600
  });
2163
2601
  };
2602
+ this._removeLiquidityCryptoSlippage = function (totalAmountUSD, lpTokenAmount, useUnderlying) {
2603
+ if (useUnderlying === void 0) { useUnderlying = true; }
2604
+ return __awaiter(_this, void 0, void 0, function () {
2605
+ var prices, _a, balancedAmounts, _c, balancedTotalAmountsUSD;
2606
+ return __generator(this, function (_d) {
2607
+ switch (_d.label) {
2608
+ case 0:
2609
+ if (!useUnderlying) return [3 /*break*/, 2];
2610
+ return [4 /*yield*/, this._underlyingPrices()];
2611
+ case 1:
2612
+ _a = _d.sent();
2613
+ return [3 /*break*/, 4];
2614
+ case 2: return [4 /*yield*/, this._wrappedPrices()];
2615
+ case 3:
2616
+ _a = _d.sent();
2617
+ _d.label = 4;
2618
+ case 4:
2619
+ prices = _a;
2620
+ if (!useUnderlying) return [3 /*break*/, 6];
2621
+ return [4 /*yield*/, this.removeLiquidityExpected(String(lpTokenAmount))];
2622
+ case 5:
2623
+ _c = _d.sent();
2624
+ return [3 /*break*/, 8];
2625
+ case 6: return [4 /*yield*/, this.removeLiquidityWrappedExpected(String(lpTokenAmount))];
2626
+ case 7:
2627
+ _c = _d.sent();
2628
+ _d.label = 8;
2629
+ case 8:
2630
+ balancedAmounts = _c;
2631
+ balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
2632
+ return [2 /*return*/, String((balancedTotalAmountsUSD - totalAmountUSD) / balancedTotalAmountsUSD)];
2633
+ }
2634
+ });
2635
+ });
2636
+ };
2164
2637
  this._removeLiquiditySlippage = function (totalAmount, expected, useUnderlying) {
2165
2638
  if (useUnderlying === void 0) { useUnderlying = true; }
2166
2639
  return __awaiter(_this, void 0, void 0, function () {
@@ -2202,7 +2675,8 @@ var Pool = /** @class */ (function () {
2202
2675
  });
2203
2676
  };
2204
2677
  this._balancedAmounts = function (poolBalances, walletBalances, decimals) {
2205
- var poolBalancesRatios = poolBalances.map(function (b) { return b / poolBalances.reduce(function (a, b) { return a + b; }); });
2678
+ var poolTotalLiquidity = poolBalances.reduce(function (a, b) { return a + b; });
2679
+ var poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalLiquidity; });
2206
2680
  // Cross factors for each wallet balance used as reference to see the
2207
2681
  // max that can be used according to the lowest relative wallet balance
2208
2682
  var balancedAmountsForEachScenario = walletBalances.map(function (_, i) { return (walletBalances.map(function (_, j) { return (poolBalancesRatios[j] * walletBalances[i] / poolBalancesRatios[i]); })); });
@@ -2944,8 +3418,12 @@ var Pool = /** @class */ (function () {
2944
3418
  this.estimateGas = {
2945
3419
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2946
3420
  addLiquidity: this.addLiquidityEstimateGas,
3421
+ depositAndStakeApprove: this.depositAndStakeApproveEstimateGas,
3422
+ depositAndStake: this.depositAndStakeEstimateGas,
2947
3423
  addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
2948
3424
  addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
3425
+ depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas,
3426
+ depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas,
2949
3427
  gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
2950
3428
  gaugeDeposit: this.gaugeDepositEstimateGas,
2951
3429
  gaugeWithdraw: this.gaugeWithdrawEstimateGas,
package/lib/utils.d.ts CHANGED
@@ -23,3 +23,4 @@ export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
23
23
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
24
24
  export declare const _getStatsUrl: (isCrypto?: boolean) => string;
25
25
  export declare const getPoolList: () => string[];
26
+ export declare const getUsdRate: (coin: string) => Promise<number>;
package/lib/utils.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.getPoolList = exports._getStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
62
+ exports.getUsdRate = exports.getPoolList = exports._getStatsUrl = exports._getUsdRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var ethers_1 = require("ethers");
65
65
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
@@ -431,3 +431,15 @@ var _getStatsUrl = function (isCrypto) {
431
431
  exports._getStatsUrl = _getStatsUrl;
432
432
  var getPoolList = function () { return Object.keys(curve_1.POOLS_DATA); };
433
433
  exports.getPoolList = getPoolList;
434
+ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, function () {
435
+ var coinAddress;
436
+ return __generator(this, function (_a) {
437
+ switch (_a.label) {
438
+ case 0:
439
+ coinAddress = (0, exports._getCoinAddresses)(coin)[0];
440
+ return [4 /*yield*/, (0, exports._getUsdRate)(coinAddress)];
441
+ case 1: return [2 /*return*/, _a.sent()];
442
+ }
443
+ });
444
+ }); };
445
+ exports.getUsdRate = getUsdRate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.16.0",
3
+ "version": "1.17.2",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {