@curvefi/api 2.30.0 → 2.31.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.
@@ -73,6 +73,7 @@ var YEAR = 365 * DAY;
73
73
  var PoolTemplate = /** @class */ (function () {
74
74
  function PoolTemplate(id) {
75
75
  var _this = this;
76
+ var _c, _d;
76
77
  this.statsParameters = function () { return __awaiter(_this, void 0, void 0, function () {
77
78
  var multicallContract, lpMulticallContract, calls, i, additionalCalls, _virtualPrice, _fee, _prices, _adminFee, _A, _lpTokenSupply, _gamma, e_1, _c, virtualPrice, fee, adminFee, A, lpTokenSupply, gamma, priceOracle, priceScale, prices, i, A_PRECISION, _d, _future_A, _initial_A, _future_A_time, _initial_A_time, _e, future_A, initial_A, future_A_time, initial_A_time;
78
79
  var _f, _g, _h;
@@ -1133,6 +1134,7 @@ var PoolTemplate = /** @class */ (function () {
1133
1134
  this.isFactory = poolData.is_factory || false;
1134
1135
  this.isMetaFactory = (this.isMeta && this.isFactory) || this.zap === '0xa79828df1850e8a3a3064576f380d90aecdd3359';
1135
1136
  this.basePool = poolData.base_pool || '';
1137
+ this.metaCoinIdx = this.isMeta ? (_c = poolData.meta_coin_idx) !== null && _c !== void 0 ? _c : poolData.wrapped_coins.length - 1 : -1;
1136
1138
  this.underlyingCoins = poolData.underlying_coins;
1137
1139
  this.wrappedCoins = poolData.wrapped_coins;
1138
1140
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -1140,6 +1142,7 @@ var PoolTemplate = /** @class */ (function () {
1140
1142
  this.underlyingDecimals = poolData.underlying_decimals;
1141
1143
  this.wrappedDecimals = poolData.wrapped_decimals;
1142
1144
  this.useLending = poolData.use_lending || poolData.underlying_coin_addresses.map(function () { return false; });
1145
+ this.inApi = (_d = poolData.in_api) !== null && _d !== void 0 ? _d : false;
1143
1146
  this.estimateGas = {
1144
1147
  depositApprove: this.depositApproveEstimateGas.bind(this),
1145
1148
  deposit: this.depositEstimateGas.bind(this),
@@ -2182,7 +2185,7 @@ var PoolTemplate = /** @class */ (function () {
2182
2185
  case 12:
2183
2186
  _amounts = amounts.map(function (amount, i) { return (0, utils_1.parseUnits)(amount, decimals[i]); });
2184
2187
  contract = curve_1.curve.contracts[curve_1.curve.constants.ALIASES.deposit_and_stake].contract;
2185
- useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && !this.zap;
2188
+ useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && (!this.zap || this.id == 'avaxcrypto');
2186
2189
  if (!isUnderlying) return [3 /*break*/, 14];
2187
2190
  _l = (_k = ethers_1.ethers.utils).parseUnits;
2188
2191
  return [4 /*yield*/, this.depositAndStakeExpected(amounts)];
@@ -1,4 +1,4 @@
1
1
  import { ethers } from "ethers";
2
2
  import { PoolTemplate } from "../PoolTemplate";
3
3
  export declare function _calcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
4
- export declare function _atricrypto3CalcExpectedAmounts(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
4
+ export declare function _calcExpectedUnderlyingAmountsMeta(this: PoolTemplate, _lpTokenAmount: ethers.BigNumber): Promise<ethers.BigNumber[]>;
@@ -45,7 +45,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
45
  return to.concat(ar || Array.prototype.slice.call(from));
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports._atricrypto3CalcExpectedAmounts = exports._calcExpectedAmounts = void 0;
48
+ exports._calcExpectedUnderlyingAmountsMeta = exports._calcExpectedAmounts = void 0;
49
49
  var PoolTemplate_1 = require("../PoolTemplate");
50
50
  var curve_1 = require("../../curve");
51
51
  var utils_1 = require("../../utils");
@@ -85,22 +85,32 @@ function _calcExpectedAmounts(_lpTokenAmount) {
85
85
  });
86
86
  }
87
87
  exports._calcExpectedAmounts = _calcExpectedAmounts;
88
- function _atricrypto3CalcExpectedAmounts(_lpTokenAmount) {
88
+ function _calcExpectedUnderlyingAmountsMeta(_lpTokenAmount) {
89
89
  return __awaiter(this, void 0, void 0, function () {
90
- var _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts;
91
- return __generator(this, function (_a) {
92
- switch (_a.label) {
90
+ var _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a;
91
+ return __generator(this, function (_b) {
92
+ switch (_b.label) {
93
93
  case 0: return [4 /*yield*/, _calcExpectedAmounts.call(this, _lpTokenAmount)];
94
94
  case 1:
95
- _expectedWrappedAmounts = _a.sent();
96
- _expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
95
+ _expectedWrappedAmounts = _b.sent();
96
+ _expectedMetaCoinAmount = _expectedWrappedAmounts.splice(this.metaCoinIdx, 1)[0];
97
+ _expectedUnderlyingAmounts = _expectedWrappedAmounts;
97
98
  basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
98
- return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
99
+ if (!basePool.isMeta) return [3 /*break*/, 3];
100
+ return [4 /*yield*/, _calcExpectedUnderlyingAmountsMeta.call(basePool, _expectedMetaCoinAmount)];
99
101
  case 2:
100
- _basePoolExpectedAmounts = _a.sent();
101
- return [2 /*return*/, __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _expectedUnderlyingAmounts, true)];
102
+ _a = _b.sent();
103
+ return [3 /*break*/, 5];
104
+ case 3: return [4 /*yield*/, _calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
105
+ case 4:
106
+ _a = _b.sent();
107
+ _b.label = 5;
108
+ case 5:
109
+ _basePoolExpectedAmounts = _a;
110
+ _expectedUnderlyingAmounts.splice.apply(_expectedUnderlyingAmounts, __spreadArray([this.metaCoinIdx, 0], _basePoolExpectedAmounts, false));
111
+ return [2 /*return*/, _expectedUnderlyingAmounts];
102
112
  }
103
113
  });
104
114
  });
105
115
  }
106
- exports._atricrypto3CalcExpectedAmounts = _atricrypto3CalcExpectedAmounts;
116
+ exports._calcExpectedUnderlyingAmountsMeta = _calcExpectedUnderlyingAmountsMeta;
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.depositPlainMixin = exports.depositLendingOrCryptoMixin = exports.depositZapMixin = exports.depositCryptoMetaFactoryMixin = exports.depositMetaFactoryMixin = void 0;
51
60
  var utils_1 = require("../../utils");
@@ -245,29 +254,33 @@ exports.depositZapMixin = {
245
254
  _deposit: function (_amounts, slippage, estimateGas) {
246
255
  if (estimateGas === void 0) { estimateGas = false; }
247
256
  return __awaiter(this, void 0, void 0, function () {
248
- var _minMintAmount, ethIndex, value, contract, gas, gasLimit;
249
- return __generator(this, function (_a) {
250
- switch (_a.label) {
257
+ var _minMintAmount, ethIndex, value, contract, args, gas, gasLimit;
258
+ var _a;
259
+ return __generator(this, function (_b) {
260
+ switch (_b.label) {
251
261
  case 0:
252
262
  if (!!estimateGas) return [3 /*break*/, 2];
253
263
  return [4 /*yield*/, (0, utils_1._ensureAllowance)(this.underlyingCoinAddresses, _amounts, this.zap)];
254
264
  case 1:
255
- _a.sent();
256
- _a.label = 2;
265
+ _b.sent();
266
+ _b.label = 2;
257
267
  case 2: return [4 /*yield*/, _depositMinAmount.call(this, _amounts, slippage)];
258
268
  case 3:
259
- _minMintAmount = _a.sent();
269
+ _minMintAmount = _b.sent();
260
270
  ethIndex = (0, utils_1.getEthIndex)(this.underlyingCoinAddresses);
261
271
  value = _amounts[ethIndex] || ethers_1.ethers.BigNumber.from(0);
262
272
  contract = curve_1.curve.contracts[this.zap].contract;
263
- return [4 /*yield*/, contract.estimateGas.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.constantOptions), { value: value }))];
273
+ args = [_amounts, _minMintAmount];
274
+ if ("add_liquidity(uint256[".concat(this.underlyingCoinAddresses.length, "],uint256,bool)") in contract)
275
+ args.push(true);
276
+ return [4 /*yield*/, (_a = contract.estimateGas).add_liquidity.apply(_a, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.constantOptions), { value: value })], false))];
264
277
  case 4:
265
- gas = _a.sent();
278
+ gas = _b.sent();
266
279
  if (estimateGas)
267
280
  return [2 /*return*/, gas.toNumber()];
268
281
  gasLimit = gas.mul(130).div(100);
269
- return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value }))];
270
- case 5: return [2 /*return*/, (_a.sent()).hash];
282
+ return [4 /*yield*/, contract.add_liquidity.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit, value: value })], false))];
283
+ case 5: return [2 /*return*/, (_b.sent()).hash];
271
284
  }
272
285
  });
273
286
  });
@@ -1,4 +1,3 @@
1
1
  import { PoolTemplate } from "../PoolTemplate";
2
- export declare const poolBalancesAtricrypto3Mixin: PoolTemplate;
3
2
  export declare const poolBalancesMetaMixin: PoolTemplate;
4
3
  export declare const poolBalancesLendingMixin: PoolTemplate;
@@ -45,42 +45,16 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
45
45
  return to.concat(ar || Array.prototype.slice.call(from));
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.poolBalancesLendingMixin = exports.poolBalancesMetaMixin = exports.poolBalancesAtricrypto3Mixin = void 0;
48
+ exports.poolBalancesLendingMixin = exports.poolBalancesMetaMixin = void 0;
49
49
  var ethers_1 = require("ethers");
50
50
  var curve_1 = require("../../curve");
51
51
  var common_1 = require("./common");
52
52
  var PoolTemplate_1 = require("../PoolTemplate");
53
53
  // @ts-ignore
54
- exports.poolBalancesAtricrypto3Mixin = {
55
- statsUnderlyingBalances: function () {
56
- return __awaiter(this, void 0, void 0, function () {
57
- var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalances, basePool, _basePoolExpectedAmounts, _poolUnderlyingBalances;
58
- var _this = this;
59
- return __generator(this, function (_a) {
60
- switch (_a.label) {
61
- case 0:
62
- swapContract = curve_1.curve.contracts[this.address].multicallContract;
63
- contractCalls = this.wrappedCoins.map(function (_, i) { return swapContract.balances(i); });
64
- return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
65
- case 1:
66
- _poolWrappedBalances = _a.sent();
67
- _poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalances = _poolWrappedBalances.slice(1);
68
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
69
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
70
- case 2:
71
- _basePoolExpectedAmounts = _a.sent();
72
- _poolUnderlyingBalances = __spreadArray(__spreadArray([], _basePoolExpectedAmounts, true), _poolNonMetaBalances, true);
73
- return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
74
- }
75
- });
76
- });
77
- },
78
- };
79
- // @ts-ignore
80
54
  exports.poolBalancesMetaMixin = {
81
55
  statsUnderlyingBalances: function () {
82
56
  return __awaiter(this, void 0, void 0, function () {
83
- var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolNonMetaBalance, basePool, _basePoolExpectedAmounts, _a, _poolUnderlyingBalances;
57
+ var swapContract, contractCalls, _poolWrappedBalances, _poolMetaCoinBalance, _poolUnderlyingBalances, basePool, _basePoolExpectedAmounts, _a;
84
58
  var _this = this;
85
59
  return __generator(this, function (_c) {
86
60
  switch (_c.label) {
@@ -90,11 +64,11 @@ exports.poolBalancesMetaMixin = {
90
64
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(contractCalls)];
91
65
  case 1:
92
66
  _poolWrappedBalances = _c.sent();
93
- _poolWrappedBalances.unshift(_poolWrappedBalances.pop());
94
- _poolMetaCoinBalance = _poolWrappedBalances[0], _poolNonMetaBalance = _poolWrappedBalances.slice(1);
67
+ _poolMetaCoinBalance = _poolWrappedBalances.splice(this.metaCoinIdx, 1)[0];
68
+ _poolUnderlyingBalances = _poolWrappedBalances;
95
69
  basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
96
- if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
97
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _poolMetaCoinBalance)];
70
+ if (!basePool.isMeta) return [3 /*break*/, 3];
71
+ return [4 /*yield*/, common_1._calcExpectedUnderlyingAmountsMeta.call(basePool, _poolMetaCoinBalance)];
98
72
  case 2:
99
73
  _a = _c.sent();
100
74
  return [3 /*break*/, 5];
@@ -104,7 +78,7 @@ exports.poolBalancesMetaMixin = {
104
78
  _c.label = 5;
105
79
  case 5:
106
80
  _basePoolExpectedAmounts = _a;
107
- _poolUnderlyingBalances = __spreadArray(__spreadArray([], _poolNonMetaBalance, true), _basePoolExpectedAmounts, true);
81
+ _poolUnderlyingBalances.splice.apply(_poolUnderlyingBalances, __spreadArray([this.metaCoinIdx, 0], _basePoolExpectedAmounts, false));
108
82
  return [2 /*return*/, _poolUnderlyingBalances.map(function (_b, i) { return ethers_1.ethers.utils.formatUnits(_b, _this.underlyingDecimals[i]); })];
109
83
  }
110
84
  });
@@ -2,5 +2,4 @@ import { PoolTemplate } from "../PoolTemplate";
2
2
  export declare const withdrawExpectedMixin: PoolTemplate;
3
3
  export declare const withdrawExpectedLendingOrCryptoMixin: PoolTemplate;
4
4
  export declare const withdrawExpectedMetaMixin: PoolTemplate;
5
- export declare const withdrawExpectedAtricrypto3Mixin: PoolTemplate;
6
5
  export declare const withdrawWrappedExpectedMixin: PoolTemplate;
@@ -35,20 +35,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
35
35
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
36
  }
37
37
  };
38
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40
- if (ar || !(i in from)) {
41
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42
- ar[i] = from[i];
43
- }
44
- }
45
- return to.concat(ar || Array.prototype.slice.call(from));
46
- };
47
38
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedAtricrypto3Mixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
39
+ exports.withdrawWrappedExpectedMixin = exports.withdrawExpectedMetaMixin = exports.withdrawExpectedLendingOrCryptoMixin = exports.withdrawExpectedMixin = void 0;
49
40
  var ethers_1 = require("ethers");
50
41
  var common_1 = require("./common");
51
- var PoolTemplate_1 = require("../PoolTemplate");
52
42
  var utils_1 = require("../../utils");
53
43
  // @ts-ignore
54
44
  exports.withdrawExpectedMixin = {
@@ -94,40 +84,6 @@ exports.withdrawExpectedLendingOrCryptoMixin = {
94
84
  };
95
85
  // @ts-ignore
96
86
  exports.withdrawExpectedMetaMixin = {
97
- withdrawExpected: function (lpTokenAmount) {
98
- return __awaiter(this, void 0, void 0, function () {
99
- var _lpTokenAmount, _expectedWrappedAmounts, _expectedMetaCoinAmount, _expectedUnderlyingAmounts, basePool, _basePoolExpectedAmounts, _a, _expected;
100
- var _this = this;
101
- return __generator(this, function (_b) {
102
- switch (_b.label) {
103
- case 0:
104
- _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
105
- return [4 /*yield*/, common_1._calcExpectedAmounts.call(this, _lpTokenAmount)];
106
- case 1:
107
- _expectedWrappedAmounts = _b.sent();
108
- _expectedWrappedAmounts.unshift(_expectedWrappedAmounts.pop());
109
- _expectedMetaCoinAmount = _expectedWrappedAmounts[0], _expectedUnderlyingAmounts = _expectedWrappedAmounts.slice(1);
110
- basePool = new PoolTemplate_1.PoolTemplate(this.basePool);
111
- if (!(this.basePool === "atricrypto3")) return [3 /*break*/, 3];
112
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
113
- case 2:
114
- _a = _b.sent();
115
- return [3 /*break*/, 5];
116
- case 3: return [4 /*yield*/, common_1._calcExpectedAmounts.call(basePool, _expectedMetaCoinAmount)];
117
- case 4:
118
- _a = _b.sent();
119
- _b.label = 5;
120
- case 5:
121
- _basePoolExpectedAmounts = _a;
122
- _expected = __spreadArray(__spreadArray([], _expectedUnderlyingAmounts, true), _basePoolExpectedAmounts, true);
123
- return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
124
- }
125
- });
126
- });
127
- },
128
- };
129
- // @ts-ignore
130
- exports.withdrawExpectedAtricrypto3Mixin = {
131
87
  withdrawExpected: function (lpTokenAmount) {
132
88
  return __awaiter(this, void 0, void 0, function () {
133
89
  var _lpTokenAmount, _expected;
@@ -136,7 +92,7 @@ exports.withdrawExpectedAtricrypto3Mixin = {
136
92
  switch (_a.label) {
137
93
  case 0:
138
94
  _lpTokenAmount = (0, utils_1.parseUnits)(lpTokenAmount);
139
- return [4 /*yield*/, common_1._atricrypto3CalcExpectedAmounts.call(this, _lpTokenAmount)];
95
+ return [4 /*yield*/, common_1._calcExpectedUnderlyingAmountsMeta.call(this, _lpTokenAmount)];
140
96
  case 1:
141
97
  _expected = _a.sent();
142
98
  return [2 /*return*/, _expected.map(function (amount, i) { return ethers_1.ethers.utils.formatUnits(amount, _this.underlyingDecimals[i]); })];
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.withdrawPlainMixin = exports.withdrawLendingOrCryptoMixin = exports.withdrawZapMixin = exports.withdrawCryptoMetaFactoryMixin = exports.withdrawMetaFactoryMixin = void 0;
51
60
  var ethers_1 = require("ethers");
@@ -235,27 +244,31 @@ exports.withdrawZapMixin = {
235
244
  _withdraw: function (_lpTokenAmount, slippage, estimateGas) {
236
245
  if (estimateGas === void 0) { estimateGas = false; }
237
246
  return __awaiter(this, void 0, void 0, function () {
238
- var _minAmounts, contract, gas, gasLimit;
239
- return __generator(this, function (_b) {
240
- switch (_b.label) {
247
+ var _minAmounts, contract, args, gas, gasLimit;
248
+ var _b;
249
+ return __generator(this, function (_c) {
250
+ switch (_c.label) {
241
251
  case 0:
242
252
  if (!!estimateGas) return [3 /*break*/, 2];
243
253
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
244
254
  case 1:
245
- _b.sent();
246
- _b.label = 2;
255
+ _c.sent();
256
+ _c.label = 2;
247
257
  case 2: return [4 /*yield*/, _withdrawMinAmounts.call(this, _lpTokenAmount, slippage)];
248
258
  case 3:
249
- _minAmounts = _b.sent();
259
+ _minAmounts = _c.sent();
250
260
  contract = curve_1.curve.contracts[this.zap].contract;
251
- return [4 /*yield*/, contract.estimateGas.remove_liquidity(_lpTokenAmount, _minAmounts, curve_1.curve.constantOptions)];
261
+ args = [_lpTokenAmount, _minAmounts];
262
+ if ("remove_liquidity(uint256,uint256[".concat(this.underlyingCoinAddresses.length, "],bool)") in contract)
263
+ args.push(true);
264
+ return [4 /*yield*/, (_b = contract.estimateGas).remove_liquidity.apply(_b, __spreadArray(__spreadArray([], args, false), [curve_1.curve.constantOptions], false))];
252
265
  case 4:
253
- gas = _b.sent();
266
+ gas = _c.sent();
254
267
  if (estimateGas)
255
268
  return [2 /*return*/, gas.toNumber()];
256
269
  gasLimit = gas.mul(130).div(100);
257
- return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
258
- case 5: return [2 /*return*/, (_b.sent()).hash];
270
+ return [4 /*yield*/, contract.remove_liquidity.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit })], false))];
271
+ case 5: return [2 /*return*/, (_c.sent()).hash];
259
272
  }
260
273
  });
261
274
  });
@@ -46,6 +46,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
47
  }
48
48
  };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
49
58
  Object.defineProperty(exports, "__esModule", { value: true });
50
59
  exports.withdrawOneCoinPlainMixin = exports.withdrawOneCoinLendingOrCryptoMixin = exports.withdrawOneCoinZapMixin = exports.withdrawOneCoinCryptoMetaFactoryMixin = exports.withdrawOneCoinMetaFactoryMixin = void 0;
51
60
  var curve_1 = require("../../curve");
@@ -235,27 +244,31 @@ exports.withdrawOneCoinZapMixin = {
235
244
  _withdrawOneCoin: function (_lpTokenAmount, i, slippage, estimateGas) {
236
245
  if (estimateGas === void 0) { estimateGas = false; }
237
246
  return __awaiter(this, void 0, void 0, function () {
238
- var _minAmount, contract, gas, gasLimit;
239
- return __generator(this, function (_a) {
240
- switch (_a.label) {
247
+ var _minAmount, contract, args, gas, gasLimit;
248
+ var _a;
249
+ return __generator(this, function (_b) {
250
+ switch (_b.label) {
241
251
  case 0:
242
252
  if (!!estimateGas) return [3 /*break*/, 2];
243
253
  return [4 /*yield*/, (0, utils_1._ensureAllowance)([this.lpToken], [_lpTokenAmount], this.zap)];
244
254
  case 1:
245
- _a.sent();
246
- _a.label = 2;
255
+ _b.sent();
256
+ _b.label = 2;
247
257
  case 2: return [4 /*yield*/, _withdrawOneCoinMinAmount.call(this, _lpTokenAmount, i, slippage)];
248
258
  case 3:
249
- _minAmount = _a.sent();
259
+ _minAmount = _b.sent();
250
260
  contract = curve_1.curve.contracts[this.zap].contract;
251
- return [4 /*yield*/, contract.estimateGas.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, curve_1.curve.constantOptions)];
261
+ args = [_lpTokenAmount, i, _minAmount];
262
+ if ("remove_liquidity_one_coin(uint256,uint256,uint256,bool)" in contract)
263
+ args.push(true);
264
+ return [4 /*yield*/, (_a = contract.estimateGas).remove_liquidity_one_coin.apply(_a, __spreadArray(__spreadArray([], args, false), [curve_1.curve.constantOptions], false))];
252
265
  case 4:
253
- gas = _a.sent();
266
+ gas = _b.sent();
254
267
  if (estimateGas)
255
268
  return [2 /*return*/, gas.toNumber()];
256
269
  gasLimit = gas.mul(130).div(100);
257
- return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
258
- case 5: return [2 /*return*/, (_a.sent()).hash];
270
+ return [4 /*yield*/, contract.remove_liquidity_one_coin.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit })], false))];
271
+ case 5: return [2 /*return*/, (_b.sent()).hash];
259
272
  }
260
273
  });
261
274
  });
@@ -43,10 +43,7 @@ var getPool = function (poolId) {
43
43
  return Pool;
44
44
  }(PoolTemplate_1.PoolTemplate));
45
45
  // statsBalances
46
- if (poolDummy.isFake || (curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // 100 is xDAI
47
- Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesAtricrypto3Mixin);
48
- }
49
- else if (poolDummy.isMeta) {
46
+ if (poolDummy.isMeta) {
50
47
  Object.assign(Pool.prototype, poolBalancesMixin_1.poolBalancesMetaMixin);
51
48
  }
52
49
  else if (poolDummy.useLending.reduce(function (x, y) { return x || y; })) {
@@ -96,10 +93,7 @@ var getPool = function (poolId) {
96
93
  }
97
94
  }
98
95
  // withdrawExpected
99
- if (poolDummy.isFake || (curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // 100 is xDAI
100
- Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedAtricrypto3Mixin);
101
- }
102
- else if (poolDummy.isMeta) {
96
+ if (poolDummy.isMeta) {
103
97
  Object.assign(Pool.prototype, withdrawExpectedMixins_1.withdrawExpectedMetaMixin);
104
98
  }
105
99
  else if (poolDummy.isLending || (poolDummy.isCrypto && !poolDummy.isPlain)) {
@@ -212,7 +206,7 @@ var getPool = function (poolId) {
212
206
  }
213
207
  // swap and swapEstimateGas
214
208
  if ('exchange(uint256,uint256,uint256,uint256,bool)' in curve_1.curve.contracts[poolDummy.address].contract &&
215
- !(curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum); 100 is xDAI
209
+ !(curve_1.curve.chainId === 100 && poolDummy.id === "tricrypto")) { // tricrypto2 (eth), tricrypto (arbitrum), avaxcrypto (avalanche); 100 is xDAI
216
210
  Object.assign(Pool.prototype, swapMixins_1.swapTricrypto2Mixin);
217
211
  }
218
212
  else if (poolDummy.isMetaFactory && ((0, exports.getPool)(poolDummy.basePool).isLending || (0, exports.getPool)(poolDummy.basePool).isFake || poolDummy.isCrypto)) {
package/lib/router.js CHANGED
@@ -81,8 +81,35 @@ var getNewRoute = function (routeTvl, poolId, poolAddress, inputCoinAddress, out
81
81
  totalTvl: routeTvl.totalTvl + tvl,
82
82
  };
83
83
  };
84
+ // TODO REMOVE IT!!!
85
+ var filterMaticFactory83Route = function (routes) {
86
+ return routes.filter(function (r) {
87
+ for (var _i = 0, _a = r.route; _i < _a.length; _i++) {
88
+ var step = _a[_i];
89
+ if (step.poolId === "factory-crypto-83" && step.inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address)
90
+ return false;
91
+ }
92
+ return true;
93
+ });
94
+ };
95
+ // TODO REMOVE IT!!!
96
+ var filterAvax = function (routes) {
97
+ return routes.filter(function (r) {
98
+ for (var _i = 0, _a = r.route; _i < _a.length; _i++) {
99
+ var step = _a[_i];
100
+ if (step.poolId == 'avaxcrypto' && step.swapType == 4 && (step.i === 3 || step.j === 3))
101
+ return false;
102
+ }
103
+ return true;
104
+ });
105
+ };
84
106
  var MAX_ROUTES_FOR_ONE_COIN = 3;
85
107
  var filterRoutes = function (routes, inputCoinAddress, sortFn) {
108
+ // TODO REMOVE IT!!!
109
+ if (curve_1.curve.chainId === 137)
110
+ routes = filterMaticFactory83Route(routes);
111
+ if (curve_1.curve.chainId === 43114)
112
+ routes = filterAvax(routes);
86
113
  return routes
87
114
  .filter(function (r) { return r.route.length > 0; })
88
115
  .filter(function (r) { return r.route[0].inputCoinAddress === inputCoinAddress; }) // Truncated routes
@@ -94,13 +121,6 @@ var filterRoutes = function (routes, inputCoinAddress, sortFn) {
94
121
  };
95
122
  var sortByTvl = function (a, b) { return b.minTvl - a.minTvl || b.totalTvl - a.totalTvl || a.route.length - b.route.length; };
96
123
  var sortByLength = function (a, b) { return a.route.length - b.route.length || b.minTvl - a.minTvl || b.totalTvl - a.totalTvl; };
97
- // TODO REMOVE IT!!!
98
- var filterMaticFactory83Route = function (routes) {
99
- return routes
100
- .filter(function (r) {
101
- return !(r.route.length === 1 && r.route[0].poolId === "factory-crypto-83" && r.route[0].inputCoinAddress === curve_1.curve.constants.NATIVE_TOKEN.address);
102
- });
103
- };
104
124
  // Inspired by Dijkstra's algorithm
105
125
  var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __awaiter(void 0, void 0, void 0, function () {
106
126
  var ALL_POOLS, amplificationCoefficientDict, curCoins, nextCoins, routesByTvl, routesByLength, step, _loop_1, _i, curCoins_1, inCoin, routes;
@@ -217,8 +237,8 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
217
237
  if (j === inCoinIndexes.wrapped_coin)
218
238
  return "continue";
219
239
  // Native swaps spend less gas
220
- if (wrapped_coin_addresses[j] !== outputCoinAddress && wrapped_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.wrappedAddress)
221
- return "continue";
240
+ // TODO uncomment
241
+ // if (wrapped_coin_addresses[j] !== outputCoinAddress && wrapped_coin_addresses[j] === curve.constants.NATIVE_TOKEN.wrappedAddress) continue;
222
242
  // Looking for outputCoinAddress only on the final step
223
243
  if (step === 3 && wrapped_coin_addresses[j] !== outputCoinAddress)
224
244
  return "continue";
@@ -268,7 +288,7 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
268
288
  hasEth = (inCoin === curve_1.curve.constants.NATIVE_TOKEN.address || underlying_coin_addresses[j] === curve_1.curve.constants.NATIVE_TOKEN.address);
269
289
  swapType = (poolData.is_crypto && poolData.is_meta && poolData.is_factory) ? 6
270
290
  : ((base_pool === null || base_pool === void 0 ? void 0 : base_pool.is_lending) && poolData.is_factory) ? 5
271
- : hasEth ? 3
291
+ : hasEth && poolId !== 'avaxcrypto' ? 3
272
292
  : poolData.is_crypto ? 4
273
293
  : 2;
274
294
  newRoutesByTvl = routesByTvl[inCoin].map(function (route) { return getNewRoute(route, poolId, poolAddress, inCoin, underlying_coin_addresses[j], inCoinIndexes.underlying_coin, j, swapType, (swapType === 5 || swapType === 6) ? poolData.swap_address : ethers_1.ethers.constants.AddressZero, tvl_1); });
@@ -334,9 +354,6 @@ var _findAllRoutes = function (inputCoinAddress, outputCoinAddress) { return __a
334
354
  return [3 /*break*/, 2];
335
355
  case 8:
336
356
  routes = __spreadArray(__spreadArray([], ((_q = routesByTvl[outputCoinAddress]) !== null && _q !== void 0 ? _q : []), true), ((_r = routesByLength[outputCoinAddress]) !== null && _r !== void 0 ? _r : []), true);
337
- // TODO REMOVE IT!!!
338
- if (curve_1.curve.chainId === 137)
339
- routes = filterMaticFactory83Route(routes);
340
357
  return [2 /*return*/, routes.map(function (r) { return r.route; })];
341
358
  }
342
359
  });
@@ -523,6 +540,8 @@ var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { return __
523
540
  return [4 /*yield*/, _getBestRoute(inputCoinAddress, outputCoinAddress, amount)];
524
541
  case 1:
525
542
  route = _c.sent();
543
+ if (route.length === 0)
544
+ return [2 /*return*/, { route: route, output: '0.0' }];
526
545
  return [4 /*yield*/, _getOutputForRoute(route, (0, utils_1.parseUnits)(amount, inputCoinDecimals))];
527
546
  case 2:
528
547
  _output = _c.sent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.30.0",
3
+ "version": "2.31.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",