@curvefi/api 2.21.3 → 2.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -105,6 +105,7 @@ export declare class PoolTemplate {
105
105
  cryptoSeedAmounts(amount1: number | string): Promise<string[]>;
106
106
  depositBalancedAmounts(): Promise<string[]>;
107
107
  depositExpected(amounts: (number | string)[]): Promise<string>;
108
+ private _balancedAmountsWithSameValue;
108
109
  depositBonus(amounts: (number | string)[]): Promise<string>;
109
110
  depositIsApproved(amounts: (number | string)[]): Promise<boolean>;
110
111
  private depositApproveEstimateGas;
@@ -1282,6 +1282,7 @@ var PoolTemplate = /** @class */ (function () {
1282
1282
  });
1283
1283
  });
1284
1284
  };
1285
+ // OVERRIDE
1285
1286
  PoolTemplate.prototype.depositBalancedAmounts = function () {
1286
1287
  return __awaiter(this, void 0, void 0, function () {
1287
1288
  return __generator(this, function (_c) {
@@ -1299,11 +1300,56 @@ var PoolTemplate = /** @class */ (function () {
1299
1300
  });
1300
1301
  });
1301
1302
  };
1302
- // OVERRIDE
1303
+ // | balanced[i] / sum(balanced[j]) = balance[i] / sum(balance[j]) |
1304
+ // | sum(pj * balanced[j]) = sum(aj * pj) |
1305
+ //
1306
+ // --- Answer ---
1307
+ // balanced[i] = sum(aj * pj) / sum(rj * pj / ri)
1308
+ //
1309
+ // totalValueBN = sum(aj * pj)
1310
+ // totalBalanceBN = sum(balance[j])
1311
+ // ratiosBN[i] = balancesBN[i] / totalBalanceBN = ri = balance[i] / sum(balance[j])
1312
+ // denominatorBN = sum(rj * pj / ri)
1313
+ PoolTemplate.prototype._balancedAmountsWithSameValue = function (amountsBN, pricesBN, balancesBN) {
1314
+ var valuesBN = amountsBN.map(function (aBN, i) { return aBN.times(pricesBN[i]); });
1315
+ var totalValueBN = valuesBN.reduce(function (v1BN, v2BN) { return v1BN.plus(v2BN); });
1316
+ var totalBalanceBN = balancesBN.reduce(function (b1BN, b2BN) { return b1BN.plus(b2BN); });
1317
+ var ratiosBN = balancesBN.map(function (bBN) { return bBN.div(totalBalanceBN); });
1318
+ var balancedAmountsBN = [];
1319
+ var _loop_1 = function (i) {
1320
+ var denominatorBN = ratiosBN.map(function (rBN, j) { return rBN.times(pricesBN[j])
1321
+ .div(ratiosBN[i]); }).reduce(function (xBN, yBN) { return xBN.plus(yBN); });
1322
+ balancedAmountsBN.push(totalValueBN.div(denominatorBN));
1323
+ };
1324
+ for (var i = 0; i < amountsBN.length; i++) {
1325
+ _loop_1(i);
1326
+ }
1327
+ return balancedAmountsBN.map(String);
1328
+ };
1303
1329
  PoolTemplate.prototype.depositBonus = function (amounts) {
1304
1330
  return __awaiter(this, void 0, void 0, function () {
1305
- return __generator(this, function (_c) {
1306
- throw Error("depositBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1331
+ var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1332
+ return __generator(this, function (_e) {
1333
+ switch (_e.label) {
1334
+ case 0:
1335
+ amountsBN = amounts.map(utils_1.BN);
1336
+ return [4 /*yield*/, this._underlyingPrices()];
1337
+ case 1:
1338
+ pricesBN = (_e.sent()).map(utils_1.BN);
1339
+ return [4 /*yield*/, this.stats.underlyingBalances()];
1340
+ case 2:
1341
+ balancesBN = (_e.sent()).map(utils_1.BN);
1342
+ balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
1343
+ _c = utils_1.BN;
1344
+ return [4 /*yield*/, this.depositExpected(amounts)];
1345
+ case 3:
1346
+ expectedBN = _c.apply(void 0, [_e.sent()]);
1347
+ _d = utils_1.BN;
1348
+ return [4 /*yield*/, this.depositExpected(balancedAmounts)];
1349
+ case 4:
1350
+ balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
1351
+ return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
1352
+ }
1307
1353
  });
1308
1354
  });
1309
1355
  };
@@ -1376,11 +1422,30 @@ var PoolTemplate = /** @class */ (function () {
1376
1422
  });
1377
1423
  });
1378
1424
  };
1379
- // OVERRIDE
1380
1425
  PoolTemplate.prototype.depositWrappedBonus = function (amounts) {
1381
1426
  return __awaiter(this, void 0, void 0, function () {
1382
- return __generator(this, function (_c) {
1383
- throw Error("depositWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
1427
+ var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1428
+ return __generator(this, function (_e) {
1429
+ switch (_e.label) {
1430
+ case 0:
1431
+ amountsBN = amounts.map(utils_1.BN);
1432
+ return [4 /*yield*/, this._wrappedPrices()];
1433
+ case 1:
1434
+ pricesBN = (_e.sent()).map(utils_1.BN);
1435
+ return [4 /*yield*/, this.stats.wrappedBalances()];
1436
+ case 2:
1437
+ balancesBN = (_e.sent()).map(utils_1.BN);
1438
+ balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
1439
+ _c = utils_1.BN;
1440
+ return [4 /*yield*/, this.depositWrappedExpected(amounts)];
1441
+ case 3:
1442
+ expectedBN = _c.apply(void 0, [_e.sent()]);
1443
+ _d = utils_1.BN;
1444
+ return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
1445
+ case 4:
1446
+ balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
1447
+ return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
1448
+ }
1384
1449
  });
1385
1450
  });
1386
1451
  };
@@ -2194,11 +2259,24 @@ var PoolTemplate = /** @class */ (function () {
2194
2259
  });
2195
2260
  });
2196
2261
  };
2197
- // OVERRIDE
2198
2262
  PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
2199
2263
  return __awaiter(this, void 0, void 0, function () {
2264
+ var prices, value, lpTokenAmount, balancedAmounts, balancedValue;
2200
2265
  return __generator(this, function (_c) {
2201
- throw Error("withdrawImbalanceBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2266
+ switch (_c.label) {
2267
+ case 0: return [4 /*yield*/, this._underlyingPrices()];
2268
+ case 1:
2269
+ prices = _c.sent();
2270
+ value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2271
+ return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
2272
+ case 2:
2273
+ lpTokenAmount = _c.sent();
2274
+ return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2275
+ case 3:
2276
+ balancedAmounts = _c.sent();
2277
+ balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2278
+ return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2279
+ }
2202
2280
  });
2203
2281
  });
2204
2282
  };
@@ -2288,7 +2366,7 @@ var PoolTemplate = /** @class */ (function () {
2288
2366
  return __generator(this, function (_c) {
2289
2367
  switch (_c.label) {
2290
2368
  case 0:
2291
- if (this.isCrypto)
2369
+ if (this.isCrypto || this.isPlain || this.isFake)
2292
2370
  throw Error("withdrawImbalanceWrappedExpected method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2293
2371
  return [4 /*yield*/, this.calcLpTokenAmountWrapped(amounts, false)];
2294
2372
  case 1: return [2 /*return*/, _c.sent()];
@@ -2296,11 +2374,25 @@ var PoolTemplate = /** @class */ (function () {
2296
2374
  });
2297
2375
  });
2298
2376
  };
2299
- // OVERRIDE
2300
2377
  PoolTemplate.prototype.withdrawImbalanceWrappedBonus = function (amounts) {
2301
2378
  return __awaiter(this, void 0, void 0, function () {
2302
- return __generator(this, function (_c) {
2303
- throw Error("withdrawImbalanceWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2379
+ var prices, value, lpTokenAmount, _c, balancedAmounts, balancedValue;
2380
+ return __generator(this, function (_d) {
2381
+ switch (_d.label) {
2382
+ case 0: return [4 /*yield*/, this._wrappedPrices()];
2383
+ case 1:
2384
+ prices = _d.sent();
2385
+ value = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2386
+ _c = Number;
2387
+ return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
2388
+ case 2:
2389
+ lpTokenAmount = _c.apply(void 0, [_d.sent()]);
2390
+ return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
2391
+ case 3:
2392
+ balancedAmounts = _d.sent();
2393
+ balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2394
+ return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2395
+ }
2304
2396
  });
2305
2397
  });
2306
2398
  };
@@ -2346,11 +2438,26 @@ var PoolTemplate = /** @class */ (function () {
2346
2438
  });
2347
2439
  });
2348
2440
  };
2349
- // OVERRIDE
2350
2441
  PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
2351
2442
  return __awaiter(this, void 0, void 0, function () {
2352
- return __generator(this, function (_c) {
2353
- throw Error("withdrawOneCoinBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2443
+ var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
2444
+ return __generator(this, function (_d) {
2445
+ switch (_d.label) {
2446
+ case 0: return [4 /*yield*/, this._underlyingPrices()];
2447
+ case 1:
2448
+ prices = _d.sent();
2449
+ coinPrice = prices[this._getCoinIdx(coin)];
2450
+ _c = Number;
2451
+ return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
2452
+ case 2:
2453
+ amount = _c.apply(void 0, [_d.sent()]);
2454
+ value = amount * coinPrice;
2455
+ return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2456
+ case 3:
2457
+ balancedAmounts = _d.sent();
2458
+ balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2459
+ return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2460
+ }
2354
2461
  });
2355
2462
  });
2356
2463
  };
@@ -2435,11 +2542,26 @@ var PoolTemplate = /** @class */ (function () {
2435
2542
  });
2436
2543
  });
2437
2544
  };
2438
- // OVERRIDE
2439
2545
  PoolTemplate.prototype.withdrawOneCoinWrappedBonus = function (lpTokenAmount, coin) {
2440
2546
  return __awaiter(this, void 0, void 0, function () {
2441
- return __generator(this, function (_c) {
2442
- throw Error("withdrawOneCoinWrappedBonus method doesn't exist for pool ".concat(this.name, " (id: ").concat(this.name, ")"));
2547
+ var prices, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
2548
+ return __generator(this, function (_d) {
2549
+ switch (_d.label) {
2550
+ case 0: return [4 /*yield*/, this._wrappedPrices()];
2551
+ case 1:
2552
+ prices = _d.sent();
2553
+ coinPrice = prices[this._getCoinIdx(coin, false)];
2554
+ _c = Number;
2555
+ return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
2556
+ case 2:
2557
+ amount = _c.apply(void 0, [_d.sent()]);
2558
+ value = amount * coinPrice;
2559
+ return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
2560
+ case 3:
2561
+ balancedAmounts = _d.sent();
2562
+ balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2563
+ return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2564
+ }
2443
2565
  });
2444
2566
  });
2445
2567
  };
@@ -20,13 +20,11 @@ var curve_1 = require("../curve");
20
20
  var PoolTemplate_1 = require("./PoolTemplate");
21
21
  var poolBalancesMixin_1 = require("./mixins/poolBalancesMixin");
22
22
  var depositBalancedAmountsMixins_1 = require("./mixins/depositBalancedAmountsMixins");
23
- var depositBonusMixins_1 = require("./mixins/depositBonusMixins");
24
23
  var depositMixins_1 = require("./mixins/depositMixins");
25
24
  var depositWrappedMixins_1 = require("./mixins/depositWrappedMixins");
26
25
  var withdrawExpectedMixins_1 = require("./mixins/withdrawExpectedMixins");
27
26
  var withdrawMixins_1 = require("./mixins/withdrawMixins");
28
27
  var withdrawWrappedMixins_1 = require("./mixins/withdrawWrappedMixins");
29
- var withdrawBonusMixins_1 = require("./mixins/withdrawBonusMixins");
30
28
  var withdrawImbalanceMixins_1 = require("./mixins/withdrawImbalanceMixins");
31
29
  var withdrawImbalanceWrappedMixins_1 = require("./mixins/withdrawImbalanceWrappedMixins");
32
30
  var withdrawOneCoinExpectedMixins_1 = require("./mixins/withdrawOneCoinExpectedMixins");
@@ -70,17 +68,6 @@ var getPool = function (poolId) {
70
68
  Object.assign(Pool.prototype, depositBalancedAmountsMixins_1.depositWrappedBalancedAmountsMixin);
71
69
  }
72
70
  }
73
- // depositBonus and depositWrappedBonus
74
- if (poolDummy.isCrypto) {
75
- Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusCryptoMixin);
76
- if (!poolDummy.isPlain && !poolDummy.isFake)
77
- Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusCryptoMixin);
78
- }
79
- else {
80
- Object.assign(Pool.prototype, depositBonusMixins_1.depositBonusMixin);
81
- if (!poolDummy.isPlain && !poolDummy.isFake)
82
- Object.assign(Pool.prototype, depositBonusMixins_1.depositWrappedBonusMixin);
83
- }
84
71
  // deposit and depositEstimateGas
85
72
  if (poolDummy.isMetaFactory) {
86
73
  Object.assign(Pool.prototype, depositMixins_1.depositMetaFactoryMixin);
@@ -129,24 +116,6 @@ var getPool = function (poolId) {
129
116
  else {
130
117
  Object.assign(Pool.prototype, withdrawMixins_1.withdrawPlainMixin);
131
118
  }
132
- // withdrawImbalanceBonus and withdrawOneCoinBonus
133
- if (!poolDummy.isCrypto) {
134
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawImbalanceBonusMixin);
135
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinBonusMixin);
136
- }
137
- else {
138
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinCryptoBonusMixin);
139
- }
140
- // withdrawImbalanceWrappedBonus and withdrawOneCoinWrappedBonus
141
- if (!poolDummy.isPlain && !poolDummy.isFake) {
142
- if (!poolDummy.isCrypto) {
143
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawImbalanceWrappedBonusMixin);
144
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinWrappedBonusMixin);
145
- }
146
- else {
147
- Object.assign(Pool.prototype, withdrawBonusMixins_1.withdrawOneCoinWrappedCryptoBonusMixin);
148
- }
149
- }
150
119
  // withdrawWrapped and withdrawWrappedEstimateGas
151
120
  if (!poolDummy.isPlain && !poolDummy.isFake) {
152
121
  if ((poolDummy.isLending || poolDummy.isCrypto) && !poolDummy.zap) {
package/lib/utils.d.ts CHANGED
@@ -3,14 +3,14 @@ import BigNumber from 'bignumber.js';
3
3
  import { IDict } from './interfaces';
4
4
  export declare const ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
5
5
  export declare const MAX_ALLOWANCE: ethers.BigNumber;
6
- export declare const BN: (val: number | string) => BigNumber;
7
- export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
8
- export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
9
- export declare const fromBN: (bn: BigNumber, decimals?: number) => ethers.BigNumber;
10
6
  export declare const _cutZeros: (strn: string) => string;
11
7
  export declare const checkNumber: (n: number | string) => number | string;
12
8
  export declare const formatNumber: (n: number | string, decimals?: number) => string;
13
9
  export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
10
+ export declare const BN: (val: number | string) => BigNumber;
11
+ export declare const toBN: (n: ethers.BigNumber, decimals?: number) => BigNumber;
12
+ export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
13
+ export declare const fromBN: (bn: BigNumber, decimals?: number) => ethers.BigNumber;
14
14
  export declare const isEth: (address: string) => boolean;
15
15
  export declare const getEthIndex: (addresses: string[]) => number;
16
16
  export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
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.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = 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._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
62
+ exports.getCoinNamesAndSymbols = exports._get_price_impact = exports._get_small_x = exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = 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._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var ethers_1 = require("ethers");
65
65
  var ethcall_1 = require("ethcall");
@@ -69,24 +69,6 @@ var external_api_1 = require("./external-api");
69
69
  var ERC20_json_1 = __importDefault(require("./constants/abis/ERC20.json"));
70
70
  exports.ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
71
71
  exports.MAX_ALLOWANCE = ethers_1.ethers.BigNumber.from(2).pow(ethers_1.ethers.BigNumber.from(256)).sub(ethers_1.ethers.BigNumber.from(1));
72
- // bignumber.js
73
- var BN = function (val) { return new bignumber_js_1.default(val); };
74
- exports.BN = BN;
75
- var toBN = function (n, decimals) {
76
- if (decimals === void 0) { decimals = 18; }
77
- return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
78
- };
79
- exports.toBN = toBN;
80
- var toStringFromBN = function (bn, decimals) {
81
- if (decimals === void 0) { decimals = 18; }
82
- return bn.toFixed(decimals);
83
- };
84
- exports.toStringFromBN = toStringFromBN;
85
- var fromBN = function (bn, decimals) {
86
- if (decimals === void 0) { decimals = 18; }
87
- return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
88
- };
89
- exports.fromBN = fromBN;
90
72
  // Formatting numbers
91
73
  var _cutZeros = function (strn) {
92
74
  return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
@@ -111,6 +93,24 @@ var parseUnits = function (n, decimals) {
111
93
  return ethers_1.ethers.utils.parseUnits((0, exports.formatNumber)(n, decimals), decimals);
112
94
  };
113
95
  exports.parseUnits = parseUnits;
96
+ // bignumber.js
97
+ var BN = function (val) { return new bignumber_js_1.default((0, exports.checkNumber)(val)); };
98
+ exports.BN = BN;
99
+ var toBN = function (n, decimals) {
100
+ if (decimals === void 0) { decimals = 18; }
101
+ return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals));
102
+ };
103
+ exports.toBN = toBN;
104
+ var toStringFromBN = function (bn, decimals) {
105
+ if (decimals === void 0) { decimals = 18; }
106
+ return bn.toFixed(decimals);
107
+ };
108
+ exports.toStringFromBN = toStringFromBN;
109
+ var fromBN = function (bn, decimals) {
110
+ if (decimals === void 0) { decimals = 18; }
111
+ return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
112
+ };
113
+ exports.fromBN = fromBN;
114
114
  // -------------------
115
115
  var isEth = function (address) { return address.toLowerCase() === exports.ETH_ADDRESS.toLowerCase(); };
116
116
  exports.isEth = isEth;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -1,5 +0,0 @@
1
- import { PoolTemplate } from "../PoolTemplate";
2
- export declare const depositBonusMixin: PoolTemplate;
3
- export declare const depositWrappedBonusMixin: PoolTemplate;
4
- export declare const depositBonusCryptoMixin: PoolTemplate;
5
- export declare const depositWrappedBonusCryptoMixin: PoolTemplate;
@@ -1,190 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.depositWrappedBonusCryptoMixin = exports.depositBonusCryptoMixin = exports.depositWrappedBonusMixin = exports.depositBonusMixin = void 0;
40
- var ethers_1 = require("ethers");
41
- var curve_1 = require("../../curve");
42
- var utils_1 = require("../../utils");
43
- // @ts-ignore
44
- exports.depositBonusMixin = {
45
- depositBonus: function (amounts) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- var totalAmount, expected, _a, poolBalances, poolTotalBalance, poolBalancesRatios, balancedAmounts, balancedExpected, _b;
48
- return __generator(this, function (_c) {
49
- switch (_c.label) {
50
- case 0:
51
- totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
52
- _a = Number;
53
- return [4 /*yield*/, this.depositExpected(amounts)];
54
- case 1:
55
- expected = _a.apply(void 0, [_c.sent()]);
56
- return [4 /*yield*/, this.stats.underlyingBalances()];
57
- case 2:
58
- poolBalances = (_c.sent()).map(Number);
59
- poolTotalBalance = poolBalances.reduce(function (a, b) { return a + b; });
60
- poolBalancesRatios = poolBalances.map(function (b) { return b / poolTotalBalance; });
61
- balancedAmounts = poolBalancesRatios.map(function (r) { return r * totalAmount; });
62
- _b = Number;
63
- return [4 /*yield*/, this.depositExpected(balancedAmounts)];
64
- case 3:
65
- balancedExpected = _b.apply(void 0, [_c.sent()]);
66
- return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
67
- }
68
- });
69
- });
70
- },
71
- };
72
- // @ts-ignore
73
- exports.depositWrappedBonusMixin = {
74
- depositWrappedBonus: function (amounts) {
75
- return __awaiter(this, void 0, void 0, function () {
76
- var vp, basePoolAddress, _a, _b, _c, prices, totalValue, expected, _d, poolBalances, poolValues, poolTotalValue, poolRatios, balancedValues, balancedAmounts, balancedExpected, _e;
77
- return __generator(this, function (_f) {
78
- switch (_f.label) {
79
- case 0:
80
- vp = 1;
81
- if (!this.isMeta) return [3 /*break*/, 2];
82
- basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
83
- _a = Number;
84
- _c = (_b = ethers_1.ethers.utils).formatUnits;
85
- return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
86
- case 1:
87
- vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
88
- _f.label = 2;
89
- case 2:
90
- prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
91
- totalValue = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
92
- _d = Number;
93
- return [4 /*yield*/, this.depositWrappedExpected(amounts)];
94
- case 3:
95
- expected = _d.apply(void 0, [_f.sent()]);
96
- return [4 /*yield*/, this.stats.wrappedBalances()];
97
- case 4:
98
- poolBalances = (_f.sent()).map(Number);
99
- poolValues = poolBalances.map(function (b, i) { return b * prices[i]; });
100
- poolTotalValue = poolValues.reduce(function (a, b) { return a + b; });
101
- poolRatios = poolValues.map(function (b) { return b / poolTotalValue; });
102
- balancedValues = poolRatios.map(function (r) { return r * totalValue; });
103
- balancedAmounts = balancedValues.map(function (a, i) { return a / prices[i]; });
104
- _e = Number;
105
- return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
106
- case 5:
107
- balancedExpected = _e.apply(void 0, [_f.sent()]);
108
- return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
109
- }
110
- });
111
- });
112
- },
113
- };
114
- // @ts-ignore
115
- exports.depositBonusCryptoMixin = {
116
- depositBonus: function (amounts) {
117
- return __awaiter(this, void 0, void 0, function () {
118
- var prices, totalAmountUSD, expected, _a, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _b;
119
- return __generator(this, function (_c) {
120
- switch (_c.label) {
121
- case 0: return [4 /*yield*/, this._underlyingPrices()];
122
- case 1:
123
- prices = _c.sent();
124
- totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
125
- _a = Number;
126
- return [4 /*yield*/, this.depositExpected(amounts)];
127
- case 2:
128
- expected = _a.apply(void 0, [_c.sent()]);
129
- return [4 /*yield*/, this.stats.underlyingBalances()];
130
- case 3:
131
- poolBalances = (_c.sent()).map(Number);
132
- poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
133
- poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
134
- poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
135
- balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
136
- balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
137
- _b = Number;
138
- return [4 /*yield*/, this.depositExpected(balancedAmounts)];
139
- case 4:
140
- balancedExpected = _b.apply(void 0, [_c.sent()]);
141
- return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
142
- }
143
- });
144
- });
145
- },
146
- };
147
- // @ts-ignore
148
- exports.depositWrappedBonusCryptoMixin = {
149
- depositWrappedBonus: function (amounts) {
150
- return __awaiter(this, void 0, void 0, function () {
151
- var prices, vp, basePoolAddress, _a, _b, _c, totalAmountUSD, expected, _d, poolBalances, poolBalancesUSD, poolTotalBalance, poolBalancesRatios, balancedAmountsUSD, balancedAmounts, balancedExpected, _e;
152
- return __generator(this, function (_f) {
153
- switch (_f.label) {
154
- case 0: return [4 /*yield*/, this._wrappedPrices()];
155
- case 1:
156
- prices = _f.sent();
157
- vp = 1;
158
- if (!this.isMeta) return [3 /*break*/, 3];
159
- basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
160
- _a = Number;
161
- _c = (_b = ethers_1.ethers.utils).formatUnits;
162
- return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
163
- case 2:
164
- vp = _a.apply(void 0, [_c.apply(_b, [_f.sent()])]);
165
- _f.label = 3;
166
- case 3:
167
- prices = prices.map(function (p, i) { return i === prices.length - 1 ? p * vp : p; });
168
- totalAmountUSD = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
169
- _d = Number;
170
- return [4 /*yield*/, this.depositWrappedExpected(amounts)];
171
- case 4:
172
- expected = _d.apply(void 0, [_f.sent()]);
173
- return [4 /*yield*/, this.stats.wrappedBalances()];
174
- case 5:
175
- poolBalances = (_f.sent()).map(Number);
176
- poolBalancesUSD = poolBalances.map(function (b, i) { return b * prices[i]; });
177
- poolTotalBalance = poolBalancesUSD.reduce(function (a, b) { return a + b; });
178
- poolBalancesRatios = poolBalancesUSD.map(function (b) { return b / poolTotalBalance; });
179
- balancedAmountsUSD = poolBalancesRatios.map(function (r) { return r * totalAmountUSD; });
180
- balancedAmounts = balancedAmountsUSD.map(function (a, i) { return a / prices[i]; });
181
- _e = Number;
182
- return [4 /*yield*/, this.depositWrappedExpected(balancedAmounts)];
183
- case 6:
184
- balancedExpected = _e.apply(void 0, [_f.sent()]);
185
- return [2 /*return*/, String((expected - balancedExpected) / expected * 100)];
186
- }
187
- });
188
- });
189
- },
190
- };
@@ -1,7 +0,0 @@
1
- import { PoolTemplate } from "../PoolTemplate";
2
- export declare const withdrawImbalanceBonusMixin: PoolTemplate;
3
- export declare const withdrawImbalanceWrappedBonusMixin: PoolTemplate;
4
- export declare const withdrawOneCoinBonusMixin: PoolTemplate;
5
- export declare const withdrawOneCoinWrappedBonusMixin: PoolTemplate;
6
- export declare const withdrawOneCoinCryptoBonusMixin: PoolTemplate;
7
- export declare const withdrawOneCoinWrappedCryptoBonusMixin: PoolTemplate;
@@ -1,216 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.withdrawOneCoinWrappedCryptoBonusMixin = exports.withdrawOneCoinCryptoBonusMixin = exports.withdrawOneCoinWrappedBonusMixin = exports.withdrawOneCoinBonusMixin = exports.withdrawImbalanceWrappedBonusMixin = exports.withdrawImbalanceBonusMixin = void 0;
40
- var ethers_1 = require("ethers");
41
- var curve_1 = require("../../curve");
42
- var utils_1 = require("../../utils");
43
- // @ts-ignore
44
- exports.withdrawImbalanceBonusMixin = {
45
- withdrawImbalanceBonus: function (amounts) {
46
- return __awaiter(this, void 0, void 0, function () {
47
- var totalAmount, lpTokenAmount, balancedAmounts, balancedTotalAmount;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0:
51
- totalAmount = amounts.map(utils_1.checkNumber).map(Number).reduce(function (a, b) { return a + b; });
52
- return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
53
- case 1:
54
- lpTokenAmount = _a.sent();
55
- return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
56
- case 2:
57
- balancedAmounts = _a.sent();
58
- balancedTotalAmount = balancedAmounts.map(Number).reduce(function (a, b) { return a + b; });
59
- return [2 /*return*/, String((totalAmount - balancedTotalAmount) / Math.max(totalAmount, balancedTotalAmount) * 100)];
60
- }
61
- });
62
- });
63
- },
64
- };
65
- // @ts-ignore
66
- exports.withdrawImbalanceWrappedBonusMixin = {
67
- withdrawImbalanceWrappedBonus: function (amounts) {
68
- return __awaiter(this, void 0, void 0, function () {
69
- var vp, basePoolAddress, _a, _b, _c, prices, totalValue, lpTokenAmount, _d, balancedAmounts, balancedTotalValue;
70
- return __generator(this, function (_e) {
71
- switch (_e.label) {
72
- case 0:
73
- vp = 1;
74
- if (!this.isMeta) return [3 /*break*/, 2];
75
- basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
76
- _a = Number;
77
- _c = (_b = ethers_1.ethers.utils).formatUnits;
78
- return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
79
- case 1:
80
- vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
81
- _e.label = 2;
82
- case 2:
83
- prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
84
- totalValue = amounts.map(utils_1.checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
85
- _d = Number;
86
- return [4 /*yield*/, this.withdrawImbalanceWrappedExpected(amounts)];
87
- case 3:
88
- lpTokenAmount = _d.apply(void 0, [_e.sent()]);
89
- return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
90
- case 4:
91
- balancedAmounts = _e.sent();
92
- balancedTotalValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
93
- return [2 /*return*/, String((totalValue - balancedTotalValue) / Math.max(totalValue, balancedTotalValue) * 100)];
94
- }
95
- });
96
- });
97
- },
98
- };
99
- // @ts-ignore
100
- exports.withdrawOneCoinBonusMixin = {
101
- withdrawOneCoinBonus: function (lpTokenAmount, coin) {
102
- return __awaiter(this, void 0, void 0, function () {
103
- var totalAmount, _a, balancedAmounts, balancedTotalAmount;
104
- return __generator(this, function (_b) {
105
- switch (_b.label) {
106
- case 0:
107
- _a = Number;
108
- return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
109
- case 1:
110
- totalAmount = _a.apply(void 0, [_b.sent()]);
111
- return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
112
- case 2:
113
- balancedAmounts = _b.sent();
114
- balancedTotalAmount = balancedAmounts.map(Number).reduce(function (a, b) { return a + b; });
115
- return [2 /*return*/, String((totalAmount - balancedTotalAmount) / Math.max(totalAmount, balancedTotalAmount) * 100)];
116
- }
117
- });
118
- });
119
- },
120
- };
121
- // @ts-ignore
122
- exports.withdrawOneCoinWrappedBonusMixin = {
123
- withdrawOneCoinWrappedBonus: function (lpTokenAmount, coin) {
124
- return __awaiter(this, void 0, void 0, function () {
125
- var vp, basePoolAddress, _a, _b, _c, prices, coinAmount, _d, totalValue, balancedAmounts, balancedTotalValue;
126
- return __generator(this, function (_e) {
127
- switch (_e.label) {
128
- case 0:
129
- vp = 1;
130
- if (!this.isMeta) return [3 /*break*/, 2];
131
- basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
132
- _a = Number;
133
- _c = (_b = ethers_1.ethers.utils).formatUnits;
134
- return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
135
- case 1:
136
- vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
137
- _e.label = 2;
138
- case 2:
139
- prices = this.wrappedCoins.map(function (_, i, arr) { return i === arr.length - 1 ? vp : 1; });
140
- _d = Number;
141
- return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
142
- case 3:
143
- coinAmount = _d.apply(void 0, [_e.sent()]);
144
- totalValue = coinAmount * prices[this._getCoinIdx(coin, false)];
145
- return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
146
- case 4:
147
- balancedAmounts = _e.sent();
148
- balancedTotalValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
149
- return [2 /*return*/, String((totalValue - balancedTotalValue) / Math.max(totalValue, balancedTotalValue) * 100)];
150
- }
151
- });
152
- });
153
- },
154
- };
155
- // @ts-ignore
156
- exports.withdrawOneCoinCryptoBonusMixin = {
157
- withdrawOneCoinBonus: function (lpTokenAmount, coin) {
158
- return __awaiter(this, void 0, void 0, function () {
159
- var prices, coinPrice, totalAmount, _a, totalAmountUSD, balancedAmounts, balancedTotalAmountsUSD;
160
- return __generator(this, function (_b) {
161
- switch (_b.label) {
162
- case 0: return [4 /*yield*/, this._underlyingPrices()];
163
- case 1:
164
- prices = _b.sent();
165
- coinPrice = prices[this._getCoinIdx(coin)];
166
- _a = Number;
167
- return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
168
- case 2:
169
- totalAmount = _a.apply(void 0, [_b.sent()]);
170
- totalAmountUSD = totalAmount * coinPrice;
171
- return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
172
- case 3:
173
- balancedAmounts = _b.sent();
174
- balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
175
- return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / Math.max(totalAmountUSD, balancedTotalAmountsUSD) * 100)];
176
- }
177
- });
178
- });
179
- },
180
- };
181
- // @ts-ignore
182
- exports.withdrawOneCoinWrappedCryptoBonusMixin = {
183
- withdrawOneCoinWrappedBonus: function (lpTokenAmount, coin) {
184
- return __awaiter(this, void 0, void 0, function () {
185
- var vp, basePoolAddress, _a, _b, _c, prices, coinPrice, totalAmount, _d, totalAmountUSD, balancedAmounts, balancedTotalAmountsUSD;
186
- return __generator(this, function (_e) {
187
- switch (_e.label) {
188
- case 0:
189
- vp = 1;
190
- if (!this.isMeta) return [3 /*break*/, 2];
191
- basePoolAddress = curve_1.curve.constants.POOLS_DATA[this.basePool].swap_address;
192
- _a = Number;
193
- _c = (_b = ethers_1.ethers.utils).formatUnits;
194
- return [4 /*yield*/, curve_1.curve.contracts[basePoolAddress].contract.get_virtual_price(curve_1.curve.constantOptions)];
195
- case 1:
196
- vp = _a.apply(void 0, [_c.apply(_b, [_e.sent()])]);
197
- _e.label = 2;
198
- case 2: return [4 /*yield*/, this._wrappedPrices()];
199
- case 3:
200
- prices = (_e.sent()).map(function (p, i, arr) { return i === arr.length - 1 ? p * vp : p; });
201
- coinPrice = prices[this._getCoinIdx(coin, false)];
202
- _d = Number;
203
- return [4 /*yield*/, this.withdrawOneCoinWrappedExpected(lpTokenAmount, coin)];
204
- case 4:
205
- totalAmount = _d.apply(void 0, [_e.sent()]);
206
- totalAmountUSD = totalAmount * coinPrice;
207
- return [4 /*yield*/, this.withdrawWrappedExpected(lpTokenAmount)];
208
- case 5:
209
- balancedAmounts = _e.sent();
210
- balancedTotalAmountsUSD = balancedAmounts.reduce(function (s, b, i) { return s + (Number(b) * prices[i]); }, 0);
211
- return [2 /*return*/, String((totalAmountUSD - balancedTotalAmountsUSD) / Math.max(totalAmountUSD, balancedTotalAmountsUSD) * 100)];
212
- }
213
- });
214
- });
215
- },
216
- };