@curvefi/api 1.16.1 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md 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/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;
package/lib/pools.js CHANGED
@@ -541,6 +541,195 @@ var Pool = /** @class */ (function () {
541
541
  }
542
542
  });
543
543
  }); };
544
+ this.depositAndStakeExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
545
+ return __generator(this, function (_a) {
546
+ switch (_a.label) {
547
+ case 0: return [4 /*yield*/, this.addLiquidityExpected(amounts)];
548
+ case 1: return [2 /*return*/, _a.sent()];
549
+ }
550
+ });
551
+ }); };
552
+ this.depositAndStakeSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
553
+ return __generator(this, function (_a) {
554
+ switch (_a.label) {
555
+ case 0: return [4 /*yield*/, this.addLiquiditySlippage(amounts)];
556
+ case 1: return [2 /*return*/, _a.sent()];
557
+ }
558
+ });
559
+ }); };
560
+ this.depositAndStakeIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
561
+ var coinsAllowance, gaugeContract, gaugeAllowance;
562
+ return __generator(this, function (_a) {
563
+ switch (_a.label) {
564
+ case 0: return [4 /*yield*/, (0, utils_1.hasAllowance)(this.underlyingCoinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
565
+ case 1:
566
+ coinsAllowance = _a.sent();
567
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
568
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
569
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
570
+ case 2:
571
+ gaugeAllowance = _a.sent();
572
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
573
+ case 3: return [2 /*return*/, coinsAllowance];
574
+ }
575
+ });
576
+ }); };
577
+ this.depositAndStakeApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
578
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
579
+ return __generator(this, function (_a) {
580
+ switch (_a.label) {
581
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
582
+ case 1:
583
+ approveCoinsGas = _a.sent();
584
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
585
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
586
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
587
+ case 2:
588
+ gaugeAllowance = _a.sent();
589
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
590
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
591
+ case 3:
592
+ approveGaugeGas = (_a.sent()).toNumber();
593
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
594
+ case 4: return [2 /*return*/, approveCoinsGas];
595
+ }
596
+ });
597
+ }); };
598
+ this.depositAndStakeApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
599
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
600
+ return __generator(this, function (_a) {
601
+ switch (_a.label) {
602
+ case 0: return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.underlyingCoinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
603
+ case 1:
604
+ approveCoinsTx = _a.sent();
605
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
606
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
607
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
608
+ case 2:
609
+ gaugeAllowance = _a.sent();
610
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
611
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
612
+ case 3:
613
+ gasLimit = (_a.sent()).mul(130).div(100);
614
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
615
+ case 4:
616
+ approveGaugeTx = (_a.sent()).hash;
617
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
618
+ case 5: return [2 /*return*/, approveCoinsTx];
619
+ }
620
+ });
621
+ }); };
622
+ this.depositAndStakeEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
623
+ return __generator(this, function (_a) {
624
+ switch (_a.label) {
625
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, true)];
626
+ case 1: return [2 /*return*/, _a.sent()];
627
+ }
628
+ });
629
+ }); };
630
+ this.depositAndStake = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
631
+ return __generator(this, function (_a) {
632
+ switch (_a.label) {
633
+ case 0: return [4 /*yield*/, this._depositAndStake(amounts, true, false)];
634
+ case 1: return [2 /*return*/, _a.sent()];
635
+ }
636
+ });
637
+ }); };
638
+ this._depositAndStake = function (amounts, isUnderlying, estimateGas) { return __awaiter(_this, void 0, void 0, function () {
639
+ 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;
640
+ return __generator(this, function (_p) {
641
+ switch (_p.label) {
642
+ case 0:
643
+ coinAddresses = isUnderlying ? __spreadArray([], this.underlyingCoinAddresses, true) : __spreadArray([], this.coinAddresses, true);
644
+ coins = isUnderlying ? this.underlyingCoins : this.coinAddresses;
645
+ decimals = isUnderlying ? this.underlyingDecimals : this.decimals;
646
+ depositAddress = isUnderlying ? this.zap || this.swap : this.swap;
647
+ if (amounts.length !== coinAddresses.length) {
648
+ throw Error("".concat(this.name, " pool has ").concat(coinAddresses.length, " coins (amounts provided for ").concat(amounts.length, ")"));
649
+ }
650
+ if (!isUnderlying) return [3 /*break*/, 2];
651
+ _d = (_c = Object).values;
652
+ return [4 /*yield*/, this.underlyingCoinBalances()];
653
+ case 1:
654
+ _a = _d.apply(_c, [_p.sent()]);
655
+ return [3 /*break*/, 4];
656
+ case 2:
657
+ _f = (_e = Object).values;
658
+ return [4 /*yield*/, this.coinBalances()];
659
+ case 3:
660
+ _a = _f.apply(_e, [_p.sent()]);
661
+ _p.label = 4;
662
+ case 4:
663
+ balances = _a;
664
+ for (i = 0; i < balances.length; i++) {
665
+ if (Number(balances[i]) < Number(amounts[i])) {
666
+ throw Error("Not enough ".concat(coins[i], ". Actual: ").concat(balances[i], ", required: ").concat(amounts[i]));
667
+ }
668
+ }
669
+ if (!isUnderlying) return [3 /*break*/, 6];
670
+ return [4 /*yield*/, this.depositAndStakeIsApproved(amounts)];
671
+ case 5:
672
+ _h = _p.sent();
673
+ return [3 /*break*/, 8];
674
+ case 6: return [4 /*yield*/, this.depositAndStakeWrappedIsApproved(amounts)];
675
+ case 7:
676
+ _h = _p.sent();
677
+ _p.label = 8;
678
+ case 8:
679
+ allowance = _h;
680
+ if (estimateGas && !allowance) {
681
+ throw Error("Token allowance is needed to estimate gas");
682
+ }
683
+ if (!!estimateGas) return [3 /*break*/, 12];
684
+ if (!isUnderlying) return [3 /*break*/, 10];
685
+ return [4 /*yield*/, this.depositAndStakeApprove(amounts)];
686
+ case 9:
687
+ _p.sent();
688
+ return [3 /*break*/, 12];
689
+ case 10: return [4 /*yield*/, this.depositAndStakeWrappedApprove(amounts)];
690
+ case 11:
691
+ _p.sent();
692
+ _p.label = 12;
693
+ case 12:
694
+ _amounts = amounts.map(function (amount, i) {
695
+ return ethers_1.ethers.utils.parseUnits(amount, decimals[i]);
696
+ });
697
+ contract = curve_1.curve.contracts[curve_1.ALIASES.deposit_and_stake].contract;
698
+ useUnderlying = isUnderlying && (['aave', 'saave', 'ib', 'crveth', "cvxeth", "spelleth", "teth"].includes(this.name) || (curve_1.curve.chainId === 137 && this.name === 'ren'));
699
+ if (!isUnderlying) return [3 /*break*/, 14];
700
+ _l = (_k = ethers_1.ethers.utils).parseUnits;
701
+ return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
702
+ case 13:
703
+ _j = _l.apply(_k, [_p.sent()]).mul(99).div(100);
704
+ return [3 /*break*/, 16];
705
+ case 14:
706
+ _o = (_m = ethers_1.ethers.utils).parseUnits;
707
+ return [4 /*yield*/, this.depositAndStakeWrappedExpected(amounts)];
708
+ case 15:
709
+ _j = _o.apply(_m, [_p.sent()]).mul(99).div(100);
710
+ _p.label = 16;
711
+ case 16:
712
+ _minMintAmount = _j;
713
+ ethIndex = (0, utils_1.getEthIndex)(coinAddresses);
714
+ value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
715
+ for (i = 0; i < 5; i++) {
716
+ coinAddresses[i] = coinAddresses[i] || ethers_1.ethers.constants.AddressZero;
717
+ _amounts[i] = _amounts[i] || ethers_1.ethers.BigNumber.from(0);
718
+ }
719
+ 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 }))];
720
+ case 17:
721
+ _gas = (_p.sent());
722
+ if (estimateGas)
723
+ return [2 /*return*/, _gas.toNumber()];
724
+ return [4 /*yield*/, curve_1.curve.updateFeeData()];
725
+ case 18:
726
+ _p.sent();
727
+ gasLimit = _gas.mul(200).div(100);
728
+ 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 }))];
729
+ case 19: return [2 /*return*/, (_p.sent()).hash];
730
+ }
731
+ });
732
+ }); };
544
733
  this.balancedWrappedAmounts = function () { return __awaiter(_this, void 0, void 0, function () {
545
734
  var poolBalances, walletBalances, _a, _c, prices_3, poolBalancesUSD, walletBalancesUSD, balancedAmountsUSD;
546
735
  return __generator(this, function (_d) {
@@ -715,6 +904,128 @@ var Pool = /** @class */ (function () {
715
904
  }
716
905
  });
717
906
  }); };
907
+ this.depositAndStakeWrappedExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
908
+ return __generator(this, function (_a) {
909
+ switch (_a.label) {
910
+ case 0:
911
+ if (this.isFake) {
912
+ throw Error("".concat(this.name, " pool doesn't have this method"));
913
+ }
914
+ return [4 /*yield*/, this.addLiquidityWrappedExpected(amounts)];
915
+ case 1: return [2 /*return*/, _a.sent()];
916
+ }
917
+ });
918
+ }); };
919
+ this.depositAndStakeWrappedSlippage = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
920
+ return __generator(this, function (_a) {
921
+ switch (_a.label) {
922
+ case 0:
923
+ if (this.isFake) {
924
+ throw Error("".concat(this.name, " pool doesn't have this method"));
925
+ }
926
+ return [4 /*yield*/, this.addLiquidityWrappedSlippage(amounts)];
927
+ case 1: return [2 /*return*/, _a.sent()];
928
+ }
929
+ });
930
+ }); };
931
+ this.depositAndStakeWrappedIsApproved = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
932
+ var coinsAllowance, gaugeContract, gaugeAllowance;
933
+ return __generator(this, function (_a) {
934
+ switch (_a.label) {
935
+ case 0:
936
+ if (this.isFake) {
937
+ throw Error("".concat(this.name, " pool doesn't have this method"));
938
+ }
939
+ return [4 /*yield*/, (0, utils_1.hasAllowance)(this.coinAddresses, amounts, curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake)];
940
+ case 1:
941
+ coinsAllowance = _a.sent();
942
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
943
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 3];
944
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
945
+ case 2:
946
+ gaugeAllowance = _a.sent();
947
+ return [2 /*return*/, coinsAllowance && gaugeAllowance];
948
+ case 3: return [2 /*return*/, coinsAllowance];
949
+ }
950
+ });
951
+ }); };
952
+ this.depositAndStakeWrappedApproveEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
953
+ var approveCoinsGas, gaugeContract, gaugeAllowance, approveGaugeGas;
954
+ return __generator(this, function (_a) {
955
+ switch (_a.label) {
956
+ case 0:
957
+ if (this.isFake) {
958
+ throw Error("".concat(this.name, " pool doesn't have this method"));
959
+ }
960
+ return [4 /*yield*/, (0, utils_1.ensureAllowanceEstimateGas)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
961
+ case 1:
962
+ approveCoinsGas = _a.sent();
963
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
964
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 4];
965
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
966
+ case 2:
967
+ gaugeAllowance = _a.sent();
968
+ if (!!gaugeAllowance) return [3 /*break*/, 4];
969
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
970
+ case 3:
971
+ approveGaugeGas = (_a.sent()).toNumber();
972
+ return [2 /*return*/, approveCoinsGas + approveGaugeGas];
973
+ case 4: return [2 /*return*/, approveCoinsGas];
974
+ }
975
+ });
976
+ }); };
977
+ this.depositAndStakeWrappedApprove = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
978
+ var approveCoinsTx, gaugeContract, gaugeAllowance, gasLimit, approveGaugeTx;
979
+ return __generator(this, function (_a) {
980
+ switch (_a.label) {
981
+ case 0:
982
+ if (this.isFake) {
983
+ throw Error("".concat(this.name, " pool doesn't have this method"));
984
+ }
985
+ return [4 /*yield*/, (0, utils_1.ensureAllowance)(this.coinAddresses, amounts, curve_1.ALIASES.deposit_and_stake)];
986
+ case 1:
987
+ approveCoinsTx = _a.sent();
988
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
989
+ if (!Object.prototype.hasOwnProperty.call(gaugeContract, 'approved_to_deposit')) return [3 /*break*/, 5];
990
+ return [4 /*yield*/, gaugeContract.approved_to_deposit(curve_1.curve.signerAddress, curve_1.ALIASES.deposit_and_stake, curve_1.curve.constantOptions)];
991
+ case 2:
992
+ gaugeAllowance = _a.sent();
993
+ if (!!gaugeAllowance) return [3 /*break*/, 5];
994
+ return [4 /*yield*/, gaugeContract.estimateGas.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, curve_1.curve.constantOptions)];
995
+ case 3:
996
+ gasLimit = (_a.sent()).mul(130).div(100);
997
+ return [4 /*yield*/, gaugeContract.set_approve_deposit(curve_1.ALIASES.deposit_and_stake, true, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
998
+ case 4:
999
+ approveGaugeTx = (_a.sent()).hash;
1000
+ return [2 /*return*/, __spreadArray(__spreadArray([], approveCoinsTx, true), [approveGaugeTx], false)];
1001
+ case 5: return [2 /*return*/, approveCoinsTx];
1002
+ }
1003
+ });
1004
+ }); };
1005
+ this.depositAndStakeWrappedEstimateGas = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1006
+ return __generator(this, function (_a) {
1007
+ switch (_a.label) {
1008
+ case 0:
1009
+ if (this.isFake) {
1010
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1011
+ }
1012
+ return [4 /*yield*/, this._depositAndStake(amounts, false, true)];
1013
+ case 1: return [2 /*return*/, _a.sent()];
1014
+ }
1015
+ });
1016
+ }); };
1017
+ this.depositAndStakeWrapped = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
1018
+ return __generator(this, function (_a) {
1019
+ switch (_a.label) {
1020
+ case 0:
1021
+ if (this.isFake) {
1022
+ throw Error("".concat(this.name, " pool doesn't have this method"));
1023
+ }
1024
+ return [4 /*yield*/, this._depositAndStake(amounts, false, false)];
1025
+ case 1: return [2 /*return*/, _a.sent()];
1026
+ }
1027
+ });
1028
+ }); };
718
1029
  this.removeLiquidityExpected = function (lpTokenAmount) { return __awaiter(_this, void 0, void 0, function () {
719
1030
  var _lpTokenAmount, _expected;
720
1031
  var _this = this;
@@ -3116,8 +3427,12 @@ var Pool = /** @class */ (function () {
3116
3427
  this.estimateGas = {
3117
3428
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
3118
3429
  addLiquidity: this.addLiquidityEstimateGas,
3430
+ depositAndStakeApprove: this.depositAndStakeApproveEstimateGas,
3431
+ depositAndStake: this.depositAndStakeEstimateGas,
3119
3432
  addLiquidityWrappedApprove: this.addLiquidityWrappedApproveEstimateGas,
3120
3433
  addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
3434
+ depositAndStakeWrappedApprove: this.depositAndStakeWrappedApproveEstimateGas,
3435
+ depositAndStakeWrapped: this.depositAndStakeWrappedEstimateGas,
3121
3436
  gaugeDepositApprove: this.gaugeDepositApproveEstimateGas,
3122
3437
  gaugeDeposit: this.gaugeDepositEstimateGas,
3123
3438
  gaugeWithdraw: this.gaugeWithdrawEstimateGas,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.16.1",
3
+ "version": "1.17.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {