@curvefi/api 2.61.15 → 2.63.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
@@ -1607,7 +1607,9 @@ import curve from "@curvefi/api";
1607
1607
  // factory-v2-221
1608
1608
  const pool = curve.getPool(poolId);
1609
1609
 
1610
- await pool.depositAndStake([10, 10, 10]); // Initial amounts for stable pool must be equal
1610
+ const amounts = await pool.getSeedAmounts(10);
1611
+ // [ '10.0', '10.0', '10.0' ]
1612
+ await pool.depositAndStake(amounts);
1611
1613
  const balances = await pool.stats.underlyingBalances();
1612
1614
  // [ '10.0', '10.0', '10.0' ]
1613
1615
  })()
@@ -1748,17 +1750,19 @@ import curve from "@curvefi/api";
1748
1750
  const pool = curve.getPool(poolId);
1749
1751
 
1750
1752
  // Deposit & Stake Wrapped
1751
-
1752
- await pool.depositAndStakeWrapped([10, 10]); // Initial wrapped amounts for stable metapool must be equal
1753
+
1754
+ const amounts = await pool.getSeedAmounts(10);
1755
+ // [ '10', '9.666800376685890985' ]
1756
+ await pool.depositAndStakeWrapped(amounts);
1753
1757
  const balances = await pool.stats.wrappedBalances();
1754
- // [ '10.0', '10.0' ]
1758
+ // [ '10', '9.666800376685890985' ]
1755
1759
 
1756
1760
  // Or deposit & Stake Underlying
1757
1761
 
1758
- // const amounts = pool.metaUnderlyingSeedAmounts(30);
1759
- // [ '30', '10.000000000000000000', '10.000000', '10.000000' ]
1762
+ // const amounts = pool.getSeedAmounts(10, true); // useUnderlying = true
1763
+ // [ '10', '3.690404151768511181', '3.713621', '2.595975' ]
1760
1764
  // await pool.depositAndStake(amounts);
1761
- // [ '30.0', '9.272021785560442569', '8.927595', '11.800485' ]
1765
+ // [ '10', '3.690404151768511181', '3.713621', '2.595975' ]
1762
1766
  })()
1763
1767
  ```
1764
1768
 
@@ -1891,7 +1895,7 @@ import curve from "@curvefi/api";
1891
1895
  // factory-crypto-155
1892
1896
  const pool = curve.getPool(poolId);
1893
1897
 
1894
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1898
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1895
1899
  // [ '30', '0.02' ]
1896
1900
  await pool.depositAndStake(amounts);
1897
1901
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -1943,7 +1947,7 @@ import curve from "@curvefi/api";
1943
1947
  // factory-twocrypto-155
1944
1948
  const pool = curve.getPool(poolId);
1945
1949
 
1946
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1950
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
1947
1951
  // [ '30', '0.02' ]
1948
1952
  await pool.depositAndStake(amounts);
1949
1953
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -2030,7 +2034,7 @@ import curve from "@curvefi/api";
2030
2034
  // factory-tricrypto-2
2031
2035
  const pool = curve.getPool(poolId);
2032
2036
 
2033
- const amounts = await pool.cryptoSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
2037
+ const amounts = await pool.getSeedAmounts(30); // Initial amounts for crypto pools must have the ratio corresponding to initialPrice
2034
2038
  // [ '30', '0.017647058823529412', '0.00111111' ]
2035
2039
  await pool.depositAndStake(amounts);
2036
2040
  const underlyingBalances = await pool.stats.underlyingBalances();
@@ -228,23 +228,23 @@ export var ALIASES_CELO = lowerCaseValues({
228
228
  "factory_admin": "",
229
229
  });
230
230
  export var ALIASES_ZKSYNC = lowerCaseValues({
231
- "crv": "0x0a7432cF27F1aE3825c313F3C81e7D3efD7639aB",
231
+ "crv": "0x5945932099f124194452a4c62d34bB37f16183B2",
232
232
  "gauge_factory": "0x0000000000000000000000000000000000000000",
233
233
  "voting_escrow": "0x0000000000000000000000000000000000000000",
234
- "fee_distributor": "0xA464e6DCda8AC41e03616F95f4BC98a13b8922Dc",
235
- "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
236
- "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
234
+ "fee_distributor": "0x0000000000000000000000000000000000000000",
235
+ "gauge_controller": "0x0000000000000000000000000000000000000000",
236
+ "address_provider": "0x0000000000000000000000000000000000000000",
237
237
  "router": "0x7C915390e109CA66934f1eB285854375D1B127FA",
238
- "deposit_and_stake": "0x0000000000000000000000000000000000000000",
238
+ "deposit_and_stake": "0x253548e98C769aD2850da8DB3E4c2b2cE46E3839",
239
239
  "stable_calc": "0x0000000000000000000000000000000000000000",
240
240
  "crypto_calc": '0x0000000000000000000000000000000000000000',
241
- "factory": '0xAF5261eD780fd5b80CF6E206b6BF90CbB97F511B',
242
- "crvusd_factory": '0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d',
243
- "eywa_factory": '0x37F22A0B028f2152e6CAcef210e0C4d3b875f367',
244
- "crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99',
245
- "twocrypto_factory": '0x0000000000000000000000000000000000000000',
246
- "tricrypto_factory": '0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963',
247
- "stable_ng_factory": '0x0000000000000000000000000000000000000000',
241
+ "factory": '0x0000000000000000000000000000000000000000',
242
+ "crvusd_factory": '0x0000000000000000000000000000000000000000',
243
+ "eywa_factory": '0x0000000000000000000000000000000000000000',
244
+ "crypto_factory": '0x0000000000000000000000000000000000000000',
245
+ "twocrypto_factory": '0xf3a546AF64aFd6BB8292746BA66DB33aFAE72114',
246
+ "tricrypto_factory": '0x5d4174C40f1246dABe49693845442927d5929f0D',
247
+ "stable_ng_factory": '0xFcAb5d04e8e031334D5e8D2C166B08daB0BE6CaE',
248
248
  "factory_admin": "0x0000000000000000000000000000000000000000",
249
249
  });
250
250
  export var ALIASES_BASE = lowerCaseValues({
@@ -40,8 +40,8 @@ export var tricryptoDeployImplementations = {
40
40
  implementationIdx: 1,
41
41
  },
42
42
  324: {
43
- amm_native_transfers_disabled: '0x0000000000000000000000000000000000000000'.toLowerCase(),
44
- amm_native_transfers_enabled: '0x0000000000000000000000000000000000000000'.toLowerCase(),
43
+ amm_native_transfers_disabled: '0x1BD7d40CF9bBb63537746C89992f421bC35C6716'.toLowerCase(),
44
+ amm_native_transfers_enabled: '0x18d01726FeDaBd91579A9368DFB2F8A24f905280'.toLowerCase(),
45
45
  implementationIdx: 0,
46
46
  },
47
47
  1284: {
package/lib/curve.js CHANGED
@@ -432,7 +432,7 @@ var Curve = /** @class */ (function () {
432
432
  return __generator(this, function (_h) {
433
433
  switch (_h.label) {
434
434
  case 0:
435
- if ([196, 252, 5000, 1313161554].includes(this.chainId))
435
+ if ([196, 252, 324, 5000, 1313161554].includes(this.chainId))
436
436
  return [2 /*return*/];
437
437
  if (!useApi) return [3 /*break*/, 2];
438
438
  _a = this.constants;
@@ -578,7 +578,7 @@ var Curve = /** @class */ (function () {
578
578
  return __generator(this, function (_h) {
579
579
  switch (_h.label) {
580
580
  case 0:
581
- if ([324, 1284].includes(this.chainId))
581
+ if ([1284].includes(this.chainId))
582
582
  return [2 /*return*/];
583
583
  if (!useApi) return [3 /*break*/, 2];
584
584
  _a = this.constants;
@@ -617,7 +617,7 @@ var Curve = /** @class */ (function () {
617
617
  return __generator(this, function (_k) {
618
618
  switch (_k.label) {
619
619
  case 0:
620
- if ([324, 1284].includes(this.chainId))
620
+ if ([1284].includes(this.chainId))
621
621
  return [2 /*return*/];
622
622
  if (!useApi) return [3 /*break*/, 2];
623
623
  _a = this.constants;
@@ -754,7 +754,7 @@ var Curve = /** @class */ (function () {
754
754
  return __generator(this, function (_b) {
755
755
  switch (_b.label) {
756
756
  case 0:
757
- if ([324, 1284].includes(this.chainId))
757
+ if ([1284].includes(this.chainId))
758
758
  return [2 /*return*/, []];
759
759
  currentPoolIds = Object.keys(this.constants.TWOCRYPTO_FACTORY_POOLS_DATA);
760
760
  lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
@@ -773,7 +773,7 @@ var Curve = /** @class */ (function () {
773
773
  return __generator(this, function (_b) {
774
774
  switch (_b.label) {
775
775
  case 0:
776
- if ([324, 1284].includes(this.chainId))
776
+ if ([1284].includes(this.chainId))
777
777
  return [2 /*return*/, []];
778
778
  currentPoolIds = Object.keys(this.constants.TRICRYPTO_FACTORY_POOLS_DATA);
779
779
  lastPoolIdx = currentPoolIds.length === 0 ? -1 : Number(currentPoolIds[currentPoolIds.length - 1].split("-")[2]);
@@ -843,7 +843,7 @@ var Curve = /** @class */ (function () {
843
843
  return __generator(this, function (_b) {
844
844
  switch (_b.label) {
845
845
  case 0:
846
- if ([324, 1284].includes(this.chainId))
846
+ if ([1284].includes(this.chainId))
847
847
  return [2 /*return*/, ''];
848
848
  _a = lowerCasePoolDataAddresses;
849
849
  return [4 /*yield*/, getTwocryptoFactoryPoolData.call(this, 0, poolAddress)];
@@ -860,7 +860,7 @@ var Curve = /** @class */ (function () {
860
860
  return __generator(this, function (_b) {
861
861
  switch (_b.label) {
862
862
  case 0:
863
- if ([324, 1284].includes(this.chainId))
863
+ if ([1284].includes(this.chainId))
864
864
  return [2 /*return*/, ''];
865
865
  _a = lowerCasePoolDataAddresses;
866
866
  return [4 /*yield*/, getTricryptoFactoryPoolData.call(this, 0, poolAddress)];
@@ -1141,7 +1141,7 @@ var Curve = /** @class */ (function () {
1141
1141
  this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
1142
1142
  this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
1143
1143
  this.setContract(this.constants.ALIASES.factory, factoryABI);
1144
- if (!(this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 196 && this.chainId !== 5000)) return [3 /*break*/, 19];
1144
+ if (!(this.chainId !== 1313161554 && this.chainId !== 252 && this.chainId !== 324 && this.chainId !== 196 && this.chainId !== 5000)) return [3 /*break*/, 19];
1145
1145
  factoryContract = this.contracts[this.constants.ALIASES.factory].contract;
1146
1146
  _o = this.constants.ALIASES;
1147
1147
  return [4 /*yield*/, factoryContract.admin(this.constantOptions)];
@@ -291,18 +291,8 @@ export var implementationABIDictCelo = lowerCaseKeys({
291
291
  "0xa7b9d886A9a374A1C86DC52d2BA585c5CDFdac26": MetaStableSwapNGABI,
292
292
  });
293
293
  export var implementationABIDictZkSync = lowerCaseKeys({
294
- "0x7c2a205C52361410233540008f7095dEF5915843": Plain2BasicABI,
295
- "0xEF04fC6b95b1658AfdFd527aF9b947cd7BD46bde": Plain2BalancesABI,
296
- "0x4887ef1a68f30364a25a8b0bAA13EeeA7eeBE574": Plain2ETHABI,
297
- "0x044f8F31078c0CB898f25fff3286cE905C18434e": Plain2OptimizedABI,
298
- "0x2e6De7148Afc6e4B1ee766D070DDeff0C84831a5": Plain3BasicABI,
299
- "0x5D18b28C052Bb0C1573d90Ea055b13048026d83F": Plain3BalancesABI,
300
- "0x9707Bbf96eBB136B67788aa7E46d771Ec18895f4": Plain3ETHABI,
301
- "0xb274f2cdCff70A0bac146e9Ca5a8a28f59a3f812": Plain3OptimizedABI,
302
- "0x30eb3F0EF60993584e8dD231dF7539db31800555": Plain4BasicABI,
303
- "0x3D21E268d6A526948e978ad1595052c949927e54": Plain4BalancesABI,
304
- "0xD46aed59fBd5eB6c134b1AFb364240bb62dA0451": Plain4ETHABI,
305
- "0xE80AeF1a4782eA7b7f9Ad9F0c2ed9343861934e3": Plain4OptimizedABI,
294
+ "0x04D0095a1A4Ae881a078ae61F36945E85464e6d7": PlainStableSwapNGABI,
295
+ "0xC5d5402481aefec461Ab86b1051AC26dF05BeE3B": MetaStableSwapNGABI,
306
296
  });
307
297
  export var implementationABIDictBase = lowerCaseKeys({
308
298
  "0xD166EEdf272B860E991d331B71041799379185D5": Plain2BasicABI,
@@ -112,8 +112,7 @@ export declare class PoolTemplate {
112
112
  private _calcLpTokenAmount;
113
113
  private calcLpTokenAmount;
114
114
  private calcLpTokenAmountWrapped;
115
- metaUnderlyingSeedAmounts(amount1: number | string): string[];
116
- cryptoSeedAmounts(amount1: number | string): Promise<string[]>;
115
+ getSeedAmounts(amount1: number | string, useUnderlying?: boolean): Promise<string[]>;
117
116
  depositBalancedAmounts(): Promise<string[]>;
118
117
  depositExpected(amounts: (number | string)[]): Promise<string>;
119
118
  private _balancedAmountsWithSameValue;
@@ -260,7 +259,7 @@ export declare class PoolTemplate {
260
259
  private _getCoinIdx;
261
260
  private _getRates;
262
261
  private _balances;
263
- private _stored_rates;
262
+ private _storedRatesBN;
264
263
  private _underlyingPrices;
265
264
  private _wrappedPrices;
266
265
  private getGaugeStatus;
@@ -412,7 +412,7 @@ var PoolTemplate = /** @class */ (function () {
412
412
  if (isDeposit === void 0) { isDeposit = true; }
413
413
  if (useUnderlying === void 0) { useUnderlying = true; }
414
414
  return __awaiter(_this, void 0, void 0, function () {
415
- var e_2, lpContract, _lpTotalSupply, decimals_1, amounts, seedAmounts_1, contract, basePool, e_3, lpContract, _lpTotalSupply, decimals_2, amounts_1, seedAmounts_2, _amounts18Decimals;
415
+ var e_2, lpContract, _lpTotalSupply, decimals_1, amounts, seedAmounts_1, contract, basePool, e_3, lpContract, _lpTotalSupply, decimals_2, amounts, seedAmounts_2, _amounts18Decimals;
416
416
  return __generator(this, function (_c) {
417
417
  switch (_c.label) {
418
418
  case 0:
@@ -434,7 +434,7 @@ var PoolTemplate = /** @class */ (function () {
434
434
  throw Error("Initial deposit for crypto meta pools must be in wrapped coins");
435
435
  decimals_1 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
436
436
  amounts = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_1[i]); });
437
- return [4 /*yield*/, this.cryptoSeedAmounts(amounts[0])];
437
+ return [4 /*yield*/, this.getSeedAmounts(amounts[0])];
438
438
  case 5:
439
439
  seedAmounts_1 = _c.sent();
440
440
  amounts.forEach(function (a, i) {
@@ -443,7 +443,7 @@ var PoolTemplate = /** @class */ (function () {
443
443
  });
444
444
  return [2 /*return*/, parseUnits(Math.pow(amounts.map(Number).reduce(function (a, b) { return a * b; }), 1 / amounts.length))];
445
445
  case 6:
446
- _c.trys.push([6, 13, , 15]);
446
+ _c.trys.push([6, 13, , 16]);
447
447
  contract = curve.contracts[curve.constants.ALIASES.stable_calc].contract;
448
448
  if (!(curve.constants.ALIASES.stable_calc === curve.constants.ZERO_ADDRESS || this.id.startsWith("factory-stable-ng"))) return [3 /*break*/, 8];
449
449
  return [4 /*yield*/, this._pureCalcLpTokenAmount(_amounts, isDeposit, useUnderlying)];
@@ -455,7 +455,7 @@ var PoolTemplate = /** @class */ (function () {
455
455
  case 9: return [2 /*return*/, _c.sent()];
456
456
  case 10: return [4 /*yield*/, contract.calc_token_amount(this.address, this.lpToken, _amounts.concat(Array(10 - _amounts.length).fill(curve.parseUnits("0"))), _amounts.length, isDeposit, useUnderlying && this.isLending)];
457
457
  case 11: return [2 /*return*/, _c.sent()];
458
- case 12: return [3 /*break*/, 15];
458
+ case 12: return [3 /*break*/, 16];
459
459
  case 13:
460
460
  e_3 = _c.sent();
461
461
  if (!isDeposit)
@@ -467,25 +467,17 @@ var PoolTemplate = /** @class */ (function () {
467
467
  if (_lpTotalSupply > curve.parseUnits("0"))
468
468
  throw e_3; // Already seeded
469
469
  decimals_2 = useUnderlying ? this.underlyingDecimals : this.wrappedDecimals;
470
- amounts_1 = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_2[i]); });
471
- if (this.isMeta && useUnderlying) {
472
- seedAmounts_2 = this.metaUnderlyingSeedAmounts(amounts_1[0]);
473
- amounts_1.forEach(function (a, i) {
474
- if (!BN(a).eq(BN(seedAmounts_2[i])))
475
- throw Error("Amounts must be = ".concat(seedAmounts_2));
476
- });
477
- }
478
- else {
479
- if (_amounts[0] <= curve.parseUnits("0"))
480
- throw Error("Initial deposit amounts must be > 0");
481
- amounts_1.forEach(function (a) {
482
- if (a !== amounts_1[0])
483
- throw Error("Initial deposit amounts must be equal");
484
- });
485
- }
486
- _amounts18Decimals = amounts_1.map(function (a) { return parseUnits(a); });
470
+ amounts = _amounts.map(function (_a, i) { return curve.formatUnits(_a, decimals_2[i]); });
471
+ return [4 /*yield*/, this.getSeedAmounts(amounts[0])];
472
+ case 15:
473
+ seedAmounts_2 = _c.sent();
474
+ amounts.forEach(function (a, i) {
475
+ if (!BN(a).eq(BN(seedAmounts_2[i])))
476
+ throw Error("Amounts must be = ".concat(seedAmounts_2));
477
+ });
478
+ _amounts18Decimals = amounts.map(function (a) { return parseUnits(a); });
487
479
  return [2 /*return*/, _amounts18Decimals.reduce(function (_a, _b) { return _a + _b; })];
488
- case 15: return [2 /*return*/];
480
+ case 16: return [2 /*return*/];
489
481
  }
490
482
  });
491
483
  });
@@ -1110,11 +1102,27 @@ var PoolTemplate = /** @class */ (function () {
1110
1102
  });
1111
1103
  });
1112
1104
  };
1113
- this._stored_rates = function () { return __awaiter(_this, void 0, void 0, function () {
1105
+ this._storedRatesBN = function (useUnderlying) { return __awaiter(_this, void 0, void 0, function () {
1106
+ var _vp, isUseStoredRates, _stored_rates;
1107
+ var _this = this;
1114
1108
  return __generator(this, function (_c) {
1115
1109
  switch (_c.label) {
1116
- case 0: return [4 /*yield*/, curve.contracts[this.address].contract.stored_rates()];
1117
- case 1: return [2 /*return*/, _c.sent()];
1110
+ case 0:
1111
+ if (!this.isMeta) return [3 /*break*/, 2];
1112
+ if (useUnderlying)
1113
+ return [2 /*return*/, this.underlyingCoins.map(function () { return BN(1); })];
1114
+ return [4 /*yield*/, curve.contracts[curve.getPoolsData()[this.basePool].swap_address].contract.get_virtual_price()];
1115
+ case 1:
1116
+ _vp = _c.sent();
1117
+ return [2 /*return*/, [BN(1), toBN(_vp)]];
1118
+ case 2:
1119
+ isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
1120
+ if (!isUseStoredRates) return [3 /*break*/, 4];
1121
+ return [4 /*yield*/, curve.contracts[this.address].contract.stored_rates()];
1122
+ case 3:
1123
+ _stored_rates = _c.sent();
1124
+ return [2 /*return*/, _stored_rates.map(function (_r, i) { return toBN(_r, 36 - _this.wrappedDecimals[i]); })];
1125
+ case 4: return [2 /*return*/, this.wrappedCoins.map(function () { return BN(1); })];
1118
1126
  }
1119
1127
  });
1120
1128
  }); };
@@ -1374,32 +1382,18 @@ var PoolTemplate = /** @class */ (function () {
1374
1382
  });
1375
1383
  };
1376
1384
  // ---------------- DEPOSIT ----------------
1377
- PoolTemplate.prototype.metaUnderlyingSeedAmounts = function (amount1) {
1378
- if (this.isCrypto)
1379
- throw Error("Use cryptoSeedAmounts method for ".concat(this.name, " pool"));
1380
- if (!this.isMeta)
1381
- throw Error("metaUnderlyingSeedAmounts method exists only for meta stable pools");
1382
- var amount1BN = BN(amount1);
1383
- if (amount1BN.lte(0))
1384
- throw Error("Initial deposit amounts must be > 0");
1385
- var amounts = [_cutZeros(amount1BN.toFixed(this.underlyingDecimals[0]))];
1386
- for (var i = 1; i < this.underlyingDecimals.length; i++) {
1387
- amounts.push(amount1BN.div(this.underlyingDecimals.length - 1).toFixed(this.underlyingDecimals[i]));
1388
- }
1389
- return amounts;
1390
- };
1391
- PoolTemplate.prototype.cryptoSeedAmounts = function (amount1) {
1385
+ PoolTemplate.prototype.getSeedAmounts = function (amount1, useUnderlying) {
1386
+ if (useUnderlying === void 0) { useUnderlying = false; }
1392
1387
  return __awaiter(this, void 0, void 0, function () {
1393
- var decimals, amount1BN, priceScaleBN, _c, priceScaleBN;
1388
+ var amount1BN, decimals, priceScaleBN, _c, priceScaleBN, amounts, basePool, basePoolBalancesBN, totalBN, i, storedRatesBN, i;
1394
1389
  return __generator(this, function (_d) {
1395
1390
  switch (_d.label) {
1396
1391
  case 0:
1397
- if (!this.isCrypto)
1398
- throw Error("cryptoSeedAmounts method doesn't exist for stable pools");
1399
- decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
1400
1392
  amount1BN = BN(amount1);
1401
1393
  if (amount1BN.lte(0))
1402
1394
  throw Error("Initial deposit amounts must be > 0");
1395
+ if (!this.isCrypto) return [3 /*break*/, 5];
1396
+ decimals = this.isMeta ? this.wrappedDecimals : this.underlyingDecimals;
1403
1397
  if (!(decimals.length === 2)) return [3 /*break*/, 2];
1404
1398
  _c = toBN;
1405
1399
  return [4 /*yield*/, curve.contracts[this.address].contract.price_scale(curve.constantOptions)];
@@ -1419,7 +1413,26 @@ var PoolTemplate = /** @class */ (function () {
1419
1413
  _cutZeros(amount1BN.div(priceScaleBN[0]).toFixed(decimals[1])),
1420
1414
  _cutZeros(amount1BN.div(priceScaleBN[1]).toFixed(decimals[2])),
1421
1415
  ]];
1422
- case 4: throw Error("cryptoSeedAmounts method doesn't exist for pools with N coins > 3");
1416
+ case 4: throw Error("getSeedAmounts method doesn't exist for crypto pools with N coins > 3");
1417
+ case 5:
1418
+ amounts = [_cutZeros(amount1BN.toFixed(this.wrappedDecimals[0]))];
1419
+ if (!(this.isMeta && useUnderlying)) return [3 /*break*/, 7];
1420
+ basePool = new PoolTemplate(this.basePool);
1421
+ return [4 /*yield*/, basePool.stats.underlyingBalances()];
1422
+ case 6:
1423
+ basePoolBalancesBN = (_d.sent()).map(BN);
1424
+ totalBN = basePoolBalancesBN.reduce(function (a, b) { return a.plus(b); });
1425
+ for (i = 1; i < this.underlyingDecimals.length; i++) {
1426
+ amounts.push(amount1BN.times(basePoolBalancesBN[i - 1]).div(totalBN).toFixed(this.underlyingDecimals[i]));
1427
+ }
1428
+ return [2 /*return*/, amounts.map(_cutZeros)];
1429
+ case 7: return [4 /*yield*/, this._storedRatesBN(false)];
1430
+ case 8:
1431
+ storedRatesBN = _d.sent();
1432
+ for (i = 1; i < this.wrappedDecimals.length; i++) {
1433
+ amounts.push(amount1BN.times(storedRatesBN[0]).div(storedRatesBN[i]).toFixed(this.wrappedDecimals[i]));
1434
+ }
1435
+ return [2 /*return*/, amounts.map(_cutZeros)];
1423
1436
  }
1424
1437
  });
1425
1438
  });
@@ -1470,46 +1483,34 @@ var PoolTemplate = /** @class */ (function () {
1470
1483
  };
1471
1484
  PoolTemplate.prototype.depositBonus = function (amounts) {
1472
1485
  return __awaiter(this, void 0, void 0, function () {
1473
- var amountsBN, prices, isUseStoredRates, result, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1474
- var _this = this;
1486
+ var amountsBN, pricesBN, balancesBN, balancedAmounts, expectedBN, _c, balancedExpectedBN, _d;
1475
1487
  return __generator(this, function (_e) {
1476
1488
  switch (_e.label) {
1477
1489
  case 0:
1478
1490
  amountsBN = amounts.map(BN);
1479
- prices = [];
1480
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
1491
+ pricesBN = [];
1481
1492
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
1482
1493
  return [4 /*yield*/, this._underlyingPrices()];
1483
1494
  case 1:
1484
- prices = _e.sent();
1485
- return [3 /*break*/, 5];
1486
- case 2:
1487
- if (!isUseStoredRates) return [3 /*break*/, 4];
1488
- return [4 /*yield*/, this._stored_rates()];
1495
+ pricesBN = (_e.sent()).map(BN);
1496
+ return [3 /*break*/, 4];
1497
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
1489
1498
  case 3:
1490
- result = _e.sent();
1491
- result.forEach(function (item, index) {
1492
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
1493
- });
1494
- return [3 /*break*/, 5];
1495
- case 4:
1496
- prices = this.underlyingCoins.map(function () { return 1; });
1497
- _e.label = 5;
1499
+ pricesBN = _e.sent();
1500
+ _e.label = 4;
1501
+ case 4: return [4 /*yield*/, this.stats.underlyingBalances()];
1498
1502
  case 5:
1499
- pricesBN = prices.map(BN);
1500
- return [4 /*yield*/, this.stats.underlyingBalances()];
1501
- case 6:
1502
1503
  balancesBN = (_e.sent()).map(BN);
1503
1504
  balancedAmounts = this._balancedAmountsWithSameValue(amountsBN, pricesBN, balancesBN);
1504
1505
  _c = BN;
1505
1506
  return [4 /*yield*/, this.depositExpected(amounts)];
1506
- case 7:
1507
+ case 6:
1507
1508
  expectedBN = _c.apply(void 0, [_e.sent()]);
1508
1509
  _d = BN;
1509
1510
  return [4 /*yield*/, this.depositExpected(balancedAmounts)];
1510
- case 8:
1511
+ case 7:
1511
1512
  balancedExpectedBN = _d.apply(void 0, [_e.sent()]);
1512
- return [2 /*return*/, String(expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100))];
1513
+ return [2 /*return*/, expectedBN.minus(balancedExpectedBN).div(balancedExpectedBN).times(100).toString()];
1513
1514
  }
1514
1515
  });
1515
1516
  });
@@ -2468,40 +2469,30 @@ var PoolTemplate = /** @class */ (function () {
2468
2469
  };
2469
2470
  PoolTemplate.prototype.withdrawImbalanceBonus = function (amounts) {
2470
2471
  return __awaiter(this, void 0, void 0, function () {
2471
- var prices, isUseStoredRates, result, value, lpTokenAmount, balancedAmounts, balancedValue;
2472
- var _this = this;
2472
+ var pricesBN, valueBN, lpTokenAmount, balancedAmounts, balancedValueBN;
2473
2473
  return __generator(this, function (_c) {
2474
2474
  switch (_c.label) {
2475
2475
  case 0:
2476
- prices = [];
2477
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2476
+ pricesBN = [];
2478
2477
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2479
2478
  return [4 /*yield*/, this._underlyingPrices()];
2480
2479
  case 1:
2481
- prices = _c.sent();
2482
- return [3 /*break*/, 5];
2483
- case 2:
2484
- if (!isUseStoredRates) return [3 /*break*/, 4];
2485
- return [4 /*yield*/, this._stored_rates()];
2480
+ pricesBN = (_c.sent()).map(BN);
2481
+ return [3 /*break*/, 4];
2482
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
2486
2483
  case 3:
2487
- result = _c.sent();
2488
- result.forEach(function (item, index) {
2489
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2490
- });
2491
- return [3 /*break*/, 5];
2484
+ pricesBN = _c.sent();
2485
+ _c.label = 4;
2492
2486
  case 4:
2493
- prices = this.underlyingCoins.map(function () { return 1; });
2494
- _c.label = 5;
2495
- case 5:
2496
- value = amounts.map(checkNumber).map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2487
+ valueBN = amounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2497
2488
  return [4 /*yield*/, this.withdrawImbalanceExpected(amounts)];
2498
- case 6:
2489
+ case 5:
2499
2490
  lpTokenAmount = _c.sent();
2500
2491
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2501
- case 7:
2492
+ case 6:
2502
2493
  balancedAmounts = _c.sent();
2503
- balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2504
- return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2494
+ balancedValueBN = balancedAmounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2495
+ return [2 /*return*/, valueBN.minus(balancedValueBN).div(balancedValueBN).times(100).toString()];
2505
2496
  }
2506
2497
  });
2507
2498
  });
@@ -2666,42 +2657,32 @@ var PoolTemplate = /** @class */ (function () {
2666
2657
  };
2667
2658
  PoolTemplate.prototype.withdrawOneCoinBonus = function (lpTokenAmount, coin) {
2668
2659
  return __awaiter(this, void 0, void 0, function () {
2669
- var prices, isUseStoredRates, result, coinPrice, amount, _c, value, balancedAmounts, balancedValue;
2670
- var _this = this;
2660
+ var pricesBN, coinPriceBN, amountBN, _c, valueBN, balancedAmounts, balancedValueBN;
2671
2661
  return __generator(this, function (_d) {
2672
2662
  switch (_d.label) {
2673
2663
  case 0:
2674
- prices = [];
2675
- isUseStoredRates = isMethodExist(curve.contracts[this.address].contract, 'stored_rates') && this.isPlain;
2664
+ pricesBN = [];
2676
2665
  if (!(this.isCrypto || this.id === 'wsteth')) return [3 /*break*/, 2];
2677
2666
  return [4 /*yield*/, this._underlyingPrices()];
2678
2667
  case 1:
2679
- prices = _d.sent();
2680
- return [3 /*break*/, 5];
2681
- case 2:
2682
- if (!isUseStoredRates) return [3 /*break*/, 4];
2683
- return [4 /*yield*/, this._stored_rates()];
2668
+ pricesBN = (_d.sent()).map(BN);
2669
+ return [3 /*break*/, 4];
2670
+ case 2: return [4 /*yield*/, this._storedRatesBN(true)];
2684
2671
  case 3:
2685
- result = _d.sent();
2686
- result.forEach(function (item, index) {
2687
- prices.push(Number(item) / (Math.pow(10, (36 - _this.underlyingDecimals[index]))));
2688
- });
2689
- return [3 /*break*/, 5];
2672
+ pricesBN = _d.sent();
2673
+ _d.label = 4;
2690
2674
  case 4:
2691
- prices = this.underlyingCoins.map(function () { return 1; });
2692
- _d.label = 5;
2693
- case 5:
2694
- coinPrice = prices[this._getCoinIdx(coin)];
2695
- _c = Number;
2675
+ coinPriceBN = pricesBN[this._getCoinIdx(coin)];
2676
+ _c = BN;
2696
2677
  return [4 /*yield*/, this.withdrawOneCoinExpected(lpTokenAmount, coin)];
2697
- case 6:
2698
- amount = _c.apply(void 0, [_d.sent()]);
2699
- value = amount * coinPrice;
2678
+ case 5:
2679
+ amountBN = _c.apply(void 0, [_d.sent()]);
2680
+ valueBN = amountBN.times(coinPriceBN);
2700
2681
  return [4 /*yield*/, this.withdrawExpected(lpTokenAmount)];
2701
- case 7:
2682
+ case 6:
2702
2683
  balancedAmounts = _d.sent();
2703
- balancedValue = balancedAmounts.map(Number).reduce(function (s, a, i) { return s + (a * prices[i]); }, 0);
2704
- return [2 /*return*/, String((value - balancedValue) / balancedValue * 100)];
2684
+ balancedValueBN = balancedAmounts.map(BN).reduce(function (sBN, aBN, i) { return pricesBN[i].times(aBN).plus(sBN); }, BN(0));
2685
+ return [2 /*return*/, valueBN.minus(balancedValueBN).div(balancedValueBN).times(100).toString()];
2705
2686
  }
2706
2687
  });
2707
2688
  });
package/lib/utils.js CHANGED
@@ -69,7 +69,7 @@ export var ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
69
69
  export var MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
70
70
  // Formatting numbers
71
71
  export var _cutZeros = function (strn) {
72
- return strn.replace(/0+$/gi, '').replace(/\.$/gi, '');
72
+ return strn.replace(/(\.\d*[1-9])0+$/gi, '$1').replace(/\.0+$/gi, '');
73
73
  };
74
74
  export var checkNumber = function (n) {
75
75
  if (Number(n) !== Number(n))
@@ -774,21 +774,25 @@ export var getGasPriceFromL2 = function () { return __awaiter(void 0, void 0, vo
774
774
  return [4 /*yield*/, getGasPrice()]; // gwei
775
775
  case 3: return [2 /*return*/, _a.sent()]; // gwei
776
776
  case 4:
777
- if (!(curve.chainId === 5000)) return [3 /*break*/, 6];
777
+ if (!(curve.chainId === 324)) return [3 /*break*/, 6];
778
778
  return [4 /*yield*/, getGasPrice()]; // gwei
779
779
  case 5: return [2 /*return*/, _a.sent()]; // gwei
780
780
  case 6:
781
- if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 8];
781
+ if (!(curve.chainId === 5000)) return [3 /*break*/, 8];
782
+ return [4 /*yield*/, getGasPrice()]; // gwei
783
+ case 7: return [2 /*return*/, _a.sent()]; // gwei
784
+ case 8:
785
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 10];
782
786
  return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle_blob].contract.gasPrice({ "gasPrice": "0x2000000" })];
783
- case 7:
787
+ case 9:
784
788
  gasPrice = _a.sent();
785
789
  return [2 /*return*/, Number(gasPrice)];
786
- case 8: throw Error("This method exists only for L2 networks");
790
+ case 10: throw Error("This method exists only for L2 networks");
787
791
  }
788
792
  });
789
793
  }); };
790
794
  export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void 0, function () {
791
- var baseFee, gasPrice, baseFee;
795
+ var baseFee, gasPrice, gasPrice, baseFee;
792
796
  return __generator(this, function (_a) {
793
797
  switch (_a.label) {
794
798
  case 0:
@@ -809,15 +813,23 @@ export var getGasInfoForL2 = function () { return __awaiter(void 0, void 0, void
809
813
  gasPrice: gasPrice,
810
814
  }];
811
815
  case 4:
812
- if (!(curve.chainId === 5000)) return [3 /*break*/, 6];
813
- return [4 /*yield*/, getBaseFeeByLastBlock()];
816
+ if (!(curve.chainId === 324)) return [3 /*break*/, 6];
817
+ return [4 /*yield*/, getGasPrice()];
814
818
  case 5:
819
+ gasPrice = _a.sent();
820
+ return [2 /*return*/, {
821
+ gasPrice: gasPrice,
822
+ }];
823
+ case 6:
824
+ if (!(curve.chainId === 5000)) return [3 /*break*/, 8];
825
+ return [4 /*yield*/, getBaseFeeByLastBlock()];
826
+ case 7:
815
827
  baseFee = _a.sent();
816
828
  return [2 /*return*/, {
817
829
  maxFeePerGas: Number(((baseFee * 1.1) + 0.01).toFixed(2)),
818
830
  maxPriorityFeePerGas: 0.01,
819
831
  }];
820
- case 6: throw Error("This method exists only for L2 networks");
832
+ case 8: throw Error("This method exists only for L2 networks");
821
833
  }
822
834
  });
823
835
  }); };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.61.15",
3
+ "version": "2.63.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",