@curvefi/api 2.48.0 → 2.49.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
@@ -1464,6 +1464,20 @@ import curve from "@curvefi/api";
1464
1464
  })()
1465
1465
  ```
1466
1466
 
1467
+ ## Gas estimation L2
1468
+ For L2 networks `estimateGas` return array `[L2GasUsed, L1GasUsed]`, where `L2GasUsed` - gas estimate for execution transaction in current L2 network, and `L1GasUsed` - gas estimate for data storage in parent L1 network.
1469
+
1470
+ Gas Price in L1 is required to calculate the fee.
1471
+ You can use `getGasPriceFromL1` for get Gas Price in L1.
1472
+ ````ts
1473
+ const L1GasPrice = await curve.L1GasPrice()
1474
+ // 13161051
1475
+ ````
1476
+
1477
+ **Calculate fee**
1478
+ `fee = L2GasUsed*L2GasPrice + L1GasUsed*L1GasPrice`
1479
+
1480
+
1467
1481
  ## Factory
1468
1482
 
1469
1483
  ### Fetch new pools from blockchain
package/lib/boosting.js CHANGED
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  import { Contract } from "ethers";
49
49
  import { curve } from "./curve.js";
50
50
  import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
51
- import { _getBalances, _prepareAddresses, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3 } from "./utils.js";
51
+ import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber } from "./utils.js";
52
52
  import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
53
53
  import { _generateBoostingProof } from './external-api.js';
54
54
  export var getCrv = function () {
@@ -214,25 +214,26 @@ export var calcUnlockTime = function (days, start) {
214
214
  return Math.floor(unlockTime / week) * week * 1000;
215
215
  };
216
216
  export var createLock = function (amount, days) { return __awaiter(void 0, void 0, void 0, function () {
217
- var _amount, unlockTime, contract, gasLimit, _a;
218
- return __generator(this, function (_b) {
219
- switch (_b.label) {
217
+ var _amount, unlockTime, contract, gasLimit, _a, _b;
218
+ return __generator(this, function (_c) {
219
+ switch (_c.label) {
220
220
  case 0:
221
221
  _amount = parseUnits(amount);
222
222
  unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
223
223
  return [4 /*yield*/, _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false)];
224
224
  case 1:
225
- _b.sent();
225
+ _c.sent();
226
226
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
227
227
  return [4 /*yield*/, curve.updateFeeData()];
228
228
  case 2:
229
- _b.sent();
229
+ _c.sent();
230
230
  _a = mulBy1_3;
231
+ _b = DIGas;
231
232
  return [4 /*yield*/, contract.create_lock.estimateGas(_amount, unlockTime, curve.constantOptions)];
232
233
  case 3:
233
- gasLimit = _a.apply(void 0, [_b.sent()]);
234
+ gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
234
235
  return [4 /*yield*/, contract.create_lock(_amount, unlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
235
- case 4: return [2 /*return*/, (_b.sent()).hash];
236
+ case 4: return [2 /*return*/, (_c.sent()).hash];
236
237
  }
237
238
  });
238
239
  }); };
@@ -260,90 +261,95 @@ export var increaseAmountEstimateGas = function (amount) { return __awaiter(void
260
261
  });
261
262
  }); };
262
263
  export var increaseAmount = function (amount) { return __awaiter(void 0, void 0, void 0, function () {
263
- var _amount, contract, gasLimit, _a;
264
- return __generator(this, function (_b) {
265
- switch (_b.label) {
264
+ var _amount, contract, gasLimit, _a, _b;
265
+ return __generator(this, function (_c) {
266
+ switch (_c.label) {
266
267
  case 0:
267
268
  _amount = parseUnits(amount);
268
269
  return [4 /*yield*/, _ensureAllowance([curve.constants.ALIASES.crv], [_amount], curve.constants.ALIASES.voting_escrow, false)];
269
270
  case 1:
270
- _b.sent();
271
+ _c.sent();
271
272
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
272
273
  return [4 /*yield*/, curve.updateFeeData()];
273
274
  case 2:
274
- _b.sent();
275
+ _c.sent();
275
276
  _a = mulBy1_3;
277
+ _b = DIGas;
276
278
  return [4 /*yield*/, contract.increase_amount.estimateGas(_amount, curve.constantOptions)];
277
279
  case 3:
278
- gasLimit = _a.apply(void 0, [_b.sent()]);
280
+ gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
279
281
  return [4 /*yield*/, contract.increase_amount(_amount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
280
- case 4: return [2 /*return*/, (_b.sent()).hash];
282
+ case 4: return [2 /*return*/, (_c.sent()).hash];
281
283
  }
282
284
  });
283
285
  }); };
284
286
  export var increaseUnlockTimeEstimateGas = function (days) { return __awaiter(void 0, void 0, void 0, function () {
285
- var unlockTime, newUnlockTime, contract, _a;
286
- return __generator(this, function (_b) {
287
- switch (_b.label) {
287
+ var unlockTime, newUnlockTime, contract, _a, _b;
288
+ return __generator(this, function (_c) {
289
+ switch (_c.label) {
288
290
  case 0: return [4 /*yield*/, getLockedAmountAndUnlockTime()];
289
291
  case 1:
290
- unlockTime = (_b.sent()).unlockTime;
292
+ unlockTime = (_c.sent()).unlockTime;
291
293
  newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
292
294
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
293
295
  _a = Number;
296
+ _b = DIGas;
294
297
  return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
295
- case 2: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
298
+ case 2: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
296
299
  }
297
300
  });
298
301
  }); };
299
302
  export var increaseUnlockTime = function (days) { return __awaiter(void 0, void 0, void 0, function () {
300
- var unlockTime, newUnlockTime, contract, gasLimit, _a;
301
- return __generator(this, function (_b) {
302
- switch (_b.label) {
303
+ var unlockTime, newUnlockTime, contract, gasLimit, _a, _b;
304
+ return __generator(this, function (_c) {
305
+ switch (_c.label) {
303
306
  case 0: return [4 /*yield*/, getLockedAmountAndUnlockTime()];
304
307
  case 1:
305
- unlockTime = (_b.sent()).unlockTime;
308
+ unlockTime = (_c.sent()).unlockTime;
306
309
  newUnlockTime = Math.floor(unlockTime / 1000) + (days * 86400);
307
310
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
308
311
  return [4 /*yield*/, curve.updateFeeData()];
309
312
  case 2:
310
- _b.sent();
313
+ _c.sent();
311
314
  _a = mulBy1_3;
315
+ _b = DIGas;
312
316
  return [4 /*yield*/, contract.increase_unlock_time.estimateGas(newUnlockTime, curve.constantOptions)];
313
317
  case 3:
314
- gasLimit = _a.apply(void 0, [_b.sent()]);
318
+ gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
315
319
  return [4 /*yield*/, contract.increase_unlock_time(newUnlockTime, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
316
- case 4: return [2 /*return*/, (_b.sent()).hash];
320
+ case 4: return [2 /*return*/, (_c.sent()).hash];
317
321
  }
318
322
  });
319
323
  }); };
320
324
  export var withdrawLockedCrvEstimateGas = function () { return __awaiter(void 0, void 0, void 0, function () {
321
- var contract, _a;
322
- return __generator(this, function (_b) {
323
- switch (_b.label) {
325
+ var contract, _a, _b;
326
+ return __generator(this, function (_c) {
327
+ switch (_c.label) {
324
328
  case 0:
325
329
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
326
330
  _a = Number;
331
+ _b = DIGas;
327
332
  return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
328
- case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
333
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
329
334
  }
330
335
  });
331
336
  }); };
332
337
  export var withdrawLockedCrv = function () { return __awaiter(void 0, void 0, void 0, function () {
333
- var contract, gasLimit, _a;
334
- return __generator(this, function (_b) {
335
- switch (_b.label) {
338
+ var contract, gasLimit, _a, _b;
339
+ return __generator(this, function (_c) {
340
+ switch (_c.label) {
336
341
  case 0:
337
342
  contract = curve.contracts[curve.constants.ALIASES.voting_escrow].contract;
338
343
  return [4 /*yield*/, curve.updateFeeData()];
339
344
  case 1:
340
- _b.sent();
345
+ _c.sent();
341
346
  _a = mulBy1_3;
347
+ _b = DIGas;
342
348
  return [4 /*yield*/, contract.withdraw.estimateGas(curve.constantOptions)];
343
349
  case 2:
344
- gasLimit = _a.apply(void 0, [_b.sent()]);
350
+ gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
345
351
  return [4 /*yield*/, contract.withdraw(__assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
346
- case 3: return [2 /*return*/, (_b.sent()).hash];
352
+ case 3: return [2 /*return*/, (_c.sent()).hash];
347
353
  }
348
354
  });
349
355
  }); };
@@ -366,15 +372,16 @@ export var claimableFees = function (address) {
366
372
  export var claimFeesEstimateGas = function (address) {
367
373
  if (address === void 0) { address = ""; }
368
374
  return __awaiter(void 0, void 0, void 0, function () {
369
- var contract, _a;
370
- return __generator(this, function (_b) {
371
- switch (_b.label) {
375
+ var contract, _a, _b;
376
+ return __generator(this, function (_c) {
377
+ switch (_c.label) {
372
378
  case 0:
373
379
  address = address || curve.signerAddress;
374
380
  contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
375
381
  _a = Number;
382
+ _b = DIGas;
376
383
  return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
377
- case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
384
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.apply(void 0, [_c.sent()])])];
378
385
  }
379
386
  });
380
387
  });
@@ -382,21 +389,22 @@ export var claimFeesEstimateGas = function (address) {
382
389
  export var claimFees = function (address) {
383
390
  if (address === void 0) { address = ""; }
384
391
  return __awaiter(void 0, void 0, void 0, function () {
385
- var contract, gasLimit, _a;
386
- return __generator(this, function (_b) {
387
- switch (_b.label) {
392
+ var contract, gasLimit, _a, _b;
393
+ return __generator(this, function (_c) {
394
+ switch (_c.label) {
388
395
  case 0:
389
396
  address = address || curve.signerAddress;
390
397
  contract = curve.contracts[curve.constants.ALIASES.fee_distributor].contract;
391
398
  return [4 /*yield*/, curve.updateFeeData()];
392
399
  case 1:
393
- _b.sent();
400
+ _c.sent();
394
401
  _a = mulBy1_3;
402
+ _b = DIGas;
395
403
  return [4 /*yield*/, contract.claim.estimateGas(address, curve.constantOptions)];
396
404
  case 2:
397
- gasLimit = _a.apply(void 0, [_b.sent()]);
405
+ gasLimit = _a.apply(void 0, [_b.apply(void 0, [_c.sent()])]);
398
406
  return [4 /*yield*/, contract.claim(address, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
399
- case 3: return [2 /*return*/, (_b.sent()).hash];
407
+ case 3: return [2 /*return*/, (_c.sent()).hash];
400
408
  }
401
409
  });
402
410
  });
@@ -445,11 +453,11 @@ var _topUpAnycall = function (amount, estimateGas) { return __awaiter(void 0, vo
445
453
  case 1:
446
454
  gas = _a.sent();
447
455
  if (estimateGas)
448
- return [2 /*return*/, Number(gas)];
456
+ return [2 /*return*/, smartNumber(gas)];
449
457
  return [4 /*yield*/, curve.updateFeeData()];
450
458
  case 2:
451
459
  _a.sent();
452
- gasLimit = mulBy1_3(gas);
460
+ gasLimit = mulBy1_3(DIGas(gas));
453
461
  return [4 /*yield*/, anycallContract.deposit(curve.constants.ALIASES.voting_escrow_oracle, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
454
462
  case 3: return [2 /*return*/, (_a.sent()).hash];
455
463
  }
@@ -514,11 +522,11 @@ var _sendBlockhash = function (block, chainId, estimateGas) { return __awaiter(v
514
522
  case 1:
515
523
  gas = _a.sent();
516
524
  if (estimateGas)
517
- return [2 /*return*/, Number(gas)];
525
+ return [2 /*return*/, smartNumber(gas)];
518
526
  return [4 /*yield*/, curve.updateFeeData()];
519
527
  case 2:
520
528
  _a.sent();
521
- gasLimit = mulBy1_3(gas);
529
+ gasLimit = mulBy1_3(DIGas(gas));
522
530
  return [4 /*yield*/, veOracleContract.send_blockhash(block, chainId, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
523
531
  case 3: return [2 /*return*/, (_a.sent()).hash];
524
532
  }
@@ -559,11 +567,11 @@ var _submitProof = function (block, address, estimateGas) {
559
567
  case 2:
560
568
  gas = _a.sent();
561
569
  if (estimateGas)
562
- return [2 /*return*/, Number(gas)];
570
+ return [2 /*return*/, smartNumber(gas)];
563
571
  return [4 /*yield*/, curve.updateFeeData()];
564
572
  case 3:
565
573
  _a.sent();
566
- gasLimit = mulBy1_3(gas);
574
+ gasLimit = mulBy1_3(DIGas(gas));
567
575
  return [4 /*yield*/, veOracleContract.submit_state(address, "0x" + proof.block_header_rlp, "0x" + proof.proof_rlp, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
568
576
  case 4: return [2 /*return*/, (_a.sent()).hash];
569
577
  }
@@ -0,0 +1 @@
1
+ export declare const L2Networks: number[];
@@ -0,0 +1 @@
1
+ export var L2Networks = [10]; // <-- Will be added later: 8453 (base), 42161 (arbitrum)
@@ -0,0 +1 @@
1
+ [{ "inputs": [], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "DECIMALS", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "baseFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "decimals", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "pure", "type": "function" }, { "inputs": [], "name": "gasPrice", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes", "name": "_data", "type": "bytes" }], "name": "getL1Fee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "bytes", "name": "_data", "type": "bytes" }], "name": "getL1GasUsed", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "l1BaseFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "overhead", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "scalar", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "version", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "stateMutability": "view", "type": "function" }]
@@ -9,7 +9,7 @@ export var ALIASES_ETHEREUM = lowerCaseValues({
9
9
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
10
10
  "router": "0xF0d4c12A5768D806021F80a262B4d39d26C58b8D",
11
11
  "deposit_and_stake": "0x271fbE8aB7f1fB262f81C77Ea5303F03DA9d3d6A",
12
- "stable_calc": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
12
+ "stable_calc": "0x0DCDED3545D565bA3B19E683431381007245d983",
13
13
  "crypto_calc": '0xA72C85C258A81761433B4e8da60505Fe3Dd551CC',
14
14
  "factory": '0xb9fc157394af804a3578134a6585c0dc9cc990d4',
15
15
  "crvusd_factory": '0x4F8846Ae9380B90d2E71D5e3D042dff3E7ebb40d',
@@ -107,6 +107,7 @@ export var ALIASES_OPTIMISM = lowerCaseValues({
107
107
  "crypto_factory": '0xF18056Bbd320E96A48e3Fbf8bC061322531aac99',
108
108
  "tricrypto_factory": '0x0c0e5f2fF0ff18a3be9b835635039256dC4B4963',
109
109
  "factory_admin": "",
110
+ "gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f', // <-- NEW
110
111
  });
111
112
  export var ALIASES_XDAI = lowerCaseValues({
112
113
  "crv": "0x712b3d230f3c1c19db860d80619288b1f0bdd0bd",
package/lib/curve.js CHANGED
@@ -54,7 +54,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
54
54
  }
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
- import { ethers, Contract } from "ethers";
57
+ import { ethers, Contract, JsonRpcSigner } from "ethers";
58
58
  import { Provider as MulticallProvider, Contract as MulticallContract } from 'ethcall';
59
59
  import { getFactoryPoolData } from "./factory/factory.js";
60
60
  import { getFactoryPoolsDataFromApi } from "./factory/factory-api.js";
@@ -84,6 +84,7 @@ import factoryEywaABI from './constants/abis/factory-eywa.json' assert { type: '
84
84
  import factoryAdminABI from './constants/abis/factory-admin.json' assert { type: 'json' };
85
85
  import cryptoFactoryABI from './constants/abis/factory-crypto.json' assert { type: 'json' };
86
86
  import tricryptoFactoryABI from './constants/abis/factory-tricrypto.json' assert { type: 'json' };
87
+ import gasOracleABI from './constants/abis/gas_oracle_optimism.json' assert { type: 'json' };
87
88
  import { POOLS_DATA_ETHEREUM, LLAMMAS_DATA_ETHEREUM, POOLS_DATA_POLYGON, POOLS_DATA_FANTOM, POOLS_DATA_AVALANCHE, POOLS_DATA_ARBITRUM, POOLS_DATA_OPTIMISM, POOLS_DATA_XDAI, POOLS_DATA_MOONBEAM, POOLS_DATA_AURORA, POOLS_DATA_KAVA, POOLS_DATA_CELO, POOLS_DATA_ZKSYNC, POOLS_DATA_BASE, } from './constants/pools/index.js';
88
89
  import { ALIASES_ETHEREUM, ALIASES_OPTIMISM, ALIASES_POLYGON, ALIASES_FANTOM, ALIASES_AVALANCHE, ALIASES_ARBITRUM, ALIASES_XDAI, ALIASES_MOONBEAM, ALIASES_AURORA, ALIASES_KAVA, ALIASES_CELO, ALIASES_ZKSYNC, ALIASES_BASE, } from "./constants/aliases.js";
89
90
  import { COINS_ETHEREUM, cTokensEthereum, yTokensEthereum, ycTokensEthereum, aTokensEthereum } from "./constants/coins/ethereum.js";
@@ -101,6 +102,7 @@ import { COINS_ZKSYNC, cTokensZkSync, yTokensZkSync, ycTokensZkSync, aTokensZkSy
101
102
  import { COINS_BASE, cTokensBase, yTokensBase, ycTokensBase, aTokensBase } from "./constants/coins/base.js";
102
103
  import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils.js";
103
104
  import { _getAllGauges, _getHiddenPools } from "./external-api.js";
105
+ import { L2Networks } from "./constants/L2Networks";
104
106
  var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
105
107
  var gaugeData, isKilled, poolId;
106
108
  return __generator(this, function (_a) {
@@ -701,7 +703,7 @@ var Curve = /** @class */ (function () {
701
703
  var _a;
702
704
  if (options === void 0) { options = {}; }
703
705
  return __awaiter(this, void 0, void 0, function () {
704
- var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _gaugeFactoryABI, factoryContract, _o;
706
+ var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _gaugeFactoryABI, factoryContract, _o, curveInstance_1, originalEstimate_1, newEstimate;
705
707
  return __generator(this, function (_p) {
706
708
  switch (_p.label) {
707
709
  case 0:
@@ -929,6 +931,31 @@ var Curve = /** @class */ (function () {
929
931
  this.setContract(this.constants.ALIASES.tricrypto_factory, tricryptoFactoryABI);
930
932
  this.setContract(this.constants.ALIASES.anycall, anycallABI);
931
933
  this.setContract(this.constants.ALIASES.voting_escrow_oracle, this.chainId === 1 ? votingEscrowOracleEthABI : votingEscrowOracleABI);
934
+ if (L2Networks.includes(this.chainId)) {
935
+ curveInstance_1 = this;
936
+ curveInstance_1.setContract(curveInstance_1.constants.ALIASES.gas_oracle, gasOracleABI);
937
+ originalEstimate_1 = JsonRpcSigner.prototype.estimateGas;
938
+ newEstimate = function (arg) {
939
+ return __awaiter(this, void 0, void 0, function () {
940
+ var L2EstimateGas, L1GasUsed, L2GasUsed;
941
+ return __generator(this, function (_a) {
942
+ switch (_a.label) {
943
+ case 0:
944
+ L2EstimateGas = originalEstimate_1.bind(this);
945
+ return [4 /*yield*/, curveInstance_1.contracts[curveInstance_1.constants.ALIASES.gas_oracle].contract.getL1GasUsed(arg.data)];
946
+ case 1:
947
+ L1GasUsed = _a.sent();
948
+ return [4 /*yield*/, L2EstimateGas(arg)];
949
+ case 2:
950
+ L2GasUsed = _a.sent();
951
+ return [2 /*return*/, [L2GasUsed, L1GasUsed]];
952
+ }
953
+ });
954
+ });
955
+ };
956
+ // @ts-ignore
957
+ JsonRpcSigner.prototype.estimateGas = newEstimate;
958
+ }
932
959
  return [2 /*return*/];
933
960
  }
934
961
  });
@@ -58,9 +58,11 @@ export var implementationABIDictEthereum = lowerCaseKeys({
58
58
  "0xc629a01eC23AB04E1050500A3717A2a5c0701497": Plain2BasicABI,
59
59
  "0x847ee1227A9900B73aEeb3a47fAc92c52FD54ed9": Plain2ETHOracleABI,
60
60
  "0x94b4DFd9Ba5865Cc931195c99A2db42F3fc5d45B": Plain2ETHABI,
61
+ // !!! crvUSD Factory !!!
61
62
  "0x67fe41A94e779CcFa22cff02cc2957DC9C0e4286": Plain2BasicABI,
62
63
  "0x7Ca46A636b02D4aBC66883D7FF164bDE506DC66a": Plain2BalancesABI,
63
- "0x0C9D8c7e486e822C29488Ff51BFf0167B4650953": Plain2BasicABI,
64
+ "0x36Dc03C0e12a1C241306a6A8F327Fe28bA2Be5b0": Plain2BasicABI,
65
+ // !!! crvUSD Factory !!!
64
66
  "0x9B52F13DF69D79Ec5aAB6D1aCe3157d29B409cC3": Plain3BasicABI,
65
67
  "0x50b085f2e5958C4A87baf93A8AB79F6bec068494": Plain3BalancesABI,
66
68
  "0x8c1aB78601c259E1B43F19816923609dC7d7de9B": Plain3ETHABI,
@@ -57,7 +57,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
57
57
  import { ethers, Contract, Typed } from "ethers";
58
58
  import { curve } from "../curve.js";
59
59
  import { getPool } from "../pools/index.js";
60
- import { parseUnits, BN, mulBy1_3, getPoolIdBySwapAddress } from "../utils.js";
60
+ import { parseUnits, BN, mulBy1_3, getPoolIdBySwapAddress, DIGas, smartNumber } from '../utils.js';
61
61
  import CurveLpTokenV5ABI from "../constants/abis/curve_lp_token_v5.json" assert { type: 'json' };
62
62
  import Plain2ETHOracleABIABI from "../constants/abis/factory-v2/Plain2ETHOracle.json" assert { type: 'json' };
63
63
  // ------- STABLE PLAIN POOLS -------
@@ -113,8 +113,8 @@ oracleAddress, methodName, estimateGas) { return __awaiter(void 0, void 0, void
113
113
  case 1:
114
114
  gas = _b.sent();
115
115
  if (estimateGas)
116
- return [2 /*return*/, Number(gas)];
117
- gasLimit = mulBy1_3(gas);
116
+ return [2 /*return*/, smartNumber(gas)];
117
+ gasLimit = mulBy1_3(DIGas(gas));
118
118
  return [4 /*yield*/, curve.updateFeeData()];
119
119
  case 2:
120
120
  _b.sent();
@@ -238,8 +238,8 @@ implementationIdx, estimateGas) { return __awaiter(void 0, void 0, void 0, funct
238
238
  case 1:
239
239
  gas = _a.sent();
240
240
  if (estimateGas)
241
- return [2 /*return*/, Number(gas)];
242
- gasLimit = mulBy1_3(gas);
241
+ return [2 /*return*/, smartNumber(gas)];
242
+ gasLimit = mulBy1_3(DIGas(gas));
243
243
  return [4 /*yield*/, curve.updateFeeData()];
244
244
  case 2:
245
245
  _a.sent();
@@ -353,8 +353,8 @@ initialPrice, estimateGas) { return __awaiter(void 0, void 0, void 0, function (
353
353
  case 1:
354
354
  gas = _a.sent();
355
355
  if (estimateGas)
356
- return [2 /*return*/, Number(gas)];
357
- gasLimit = mulBy1_3(gas);
356
+ return [2 /*return*/, smartNumber(gas)];
357
+ gasLimit = mulBy1_3(DIGas(gas));
358
358
  return [4 /*yield*/, curve.updateFeeData()];
359
359
  case 2:
360
360
  _a.sent();
@@ -475,8 +475,8 @@ initialPrices, estimateGas) { return __awaiter(void 0, void 0, void 0, function
475
475
  case 1:
476
476
  gas = _a.sent();
477
477
  if (estimateGas)
478
- return [2 /*return*/, Number(gas)];
479
- gasLimit = mulBy1_3(gas);
478
+ return [2 /*return*/, smartNumber(gas)];
479
+ gasLimit = mulBy1_3(DIGas(gas));
480
480
  return [4 /*yield*/, curve.updateFeeData()];
481
481
  case 2:
482
482
  _a.sent();
@@ -539,8 +539,8 @@ var _deployGauge = function (pool, factory, estimateGas) { return __awaiter(void
539
539
  case 1:
540
540
  gas = _a.sent();
541
541
  if (estimateGas)
542
- return [2 /*return*/, Number(gas)];
543
- gasLimit = mulBy1_3(gas);
542
+ return [2 /*return*/, smartNumber(gas)];
543
+ gasLimit = mulBy1_3(DIGas(gas));
544
544
  return [4 /*yield*/, curve.updateFeeData()];
545
545
  case 2:
546
546
  _a.sent();
@@ -562,8 +562,8 @@ var _deployGaugeSidechain = function (pool, salt, estimateGas) { return __awaite
562
562
  case 1:
563
563
  gas = _a.sent();
564
564
  if (estimateGas)
565
- return [2 /*return*/, Number(gas)];
566
- gasLimit = mulBy1_3(gas);
565
+ return [2 /*return*/, smartNumber(gas)];
566
+ gasLimit = mulBy1_3(DIGas(gas));
567
567
  return [4 /*yield*/, curve.updateFeeData()];
568
568
  case 2:
569
569
  _a.sent();
@@ -585,8 +585,8 @@ var _deployGaugeMirror = function (chainId, salt, estimateGas) { return __awaite
585
585
  case 1:
586
586
  gas = _a.sent();
587
587
  if (estimateGas)
588
- return [2 /*return*/, Number(gas)];
589
- gasLimit = mulBy1_3(gas);
588
+ return [2 /*return*/, smartNumber(gas)];
589
+ gasLimit = mulBy1_3(DIGas(gas));
590
590
  return [4 /*yield*/, curve.updateFeeData()];
591
591
  case 2:
592
592
  _a.sent();
package/lib/index.d.ts CHANGED
@@ -40,6 +40,7 @@ declare const curve: {
40
40
  PoolTemplate: typeof PoolTemplate;
41
41
  getPool: (poolId: string) => PoolTemplate;
42
42
  getUsdRate: (coin: string) => Promise<number>;
43
+ getGasPriceFromL1: () => Promise<number>;
43
44
  getTVL: (network?: import("./interfaces.js").INetworkName | import("./interfaces.js").IChainId) => Promise<number>;
44
45
  getBalances: (coins: string[], ...addresses: string[] | string[][]) => Promise<string[] | import("./interfaces.js").IDict<string[]>>;
45
46
  getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
package/lib/index.js CHANGED
@@ -39,7 +39,7 @@ import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList
39
39
  import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
40
40
  import { curve as _curve } from "./curve.js";
41
41
  import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, } from "./boosting.js";
42
- import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
42
+ import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, } from "./utils.js";
43
43
  import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, getDeployedGaugeMirrorAddressByTx, } from './factory/deploy.js';
44
44
  function init(providerType, providerSettings, options) {
45
45
  if (options === void 0) { options = {}; }
@@ -76,6 +76,7 @@ var curve = {
76
76
  PoolTemplate: PoolTemplate,
77
77
  getPool: getPool,
78
78
  getUsdRate: getUsdRate,
79
+ getGasPriceFromL1: getGasPriceFromL1,
79
80
  getTVL: getTVL,
80
81
  getBalances: getBalances,
81
82
  getAllowance: getAllowance,
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
57
  import { curve } from "../../curve.js";
58
- import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
58
+ import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
59
59
  // @ts-ignore
60
60
  function _depositCheck(amounts, estimateGas) {
61
61
  if (estimateGas === void 0) { estimateGas = false; }
@@ -137,8 +137,8 @@ export var depositMetaFactoryMixin = {
137
137
  case 4:
138
138
  gas = _a.sent();
139
139
  if (estimateGas)
140
- return [2 /*return*/, Number(gas)];
141
- gasLimit = mulBy1_3(gas);
140
+ return [2 /*return*/, smartNumber(gas)];
141
+ gasLimit = mulBy1_3(DIGas(gas));
142
142
  return [4 /*yield*/, contract.add_liquidity(this.address, _amounts, _minMintAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
143
143
  case 5: return [2 /*return*/, (_a.sent()).hash];
144
144
  }
@@ -203,8 +203,8 @@ export var depositCryptoMetaFactoryMixin = {
203
203
  case 4:
204
204
  gas = _a.sent();
205
205
  if (estimateGas)
206
- return [2 /*return*/, Number(gas)];
207
- gasLimit = mulBy1_3(gas);
206
+ return [2 /*return*/, smartNumber(gas)];
207
+ gasLimit = mulBy1_3(DIGas(gas));
208
208
  return [4 /*yield*/, contract.add_liquidity(this.address, _amounts, _minMintAmount, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
209
209
  case 5: return [2 /*return*/, (_a.sent()).hash];
210
210
  }
@@ -273,8 +273,8 @@ export var depositZapMixin = {
273
273
  case 4:
274
274
  gas = _b.sent();
275
275
  if (estimateGas)
276
- return [2 /*return*/, Number(gas)];
277
- gasLimit = mulBy1_3(gas);
276
+ return [2 /*return*/, smartNumber(gas)];
277
+ gasLimit = mulBy1_3(DIGas(gas));
278
278
  return [4 /*yield*/, contract.add_liquidity.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value })], false))];
279
279
  case 5: return [2 /*return*/, (_b.sent()).hash];
280
280
  }
@@ -339,8 +339,8 @@ export var depositLendingOrCryptoMixin = {
339
339
  case 4:
340
340
  gas = _a.sent();
341
341
  if (estimateGas)
342
- return [2 /*return*/, Number(gas)];
343
- gasLimit = mulBy1_3(gas);
342
+ return [2 /*return*/, smartNumber(gas)];
343
+ gasLimit = mulBy1_3(DIGas(gas));
344
344
  return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
345
345
  case 5: return [2 /*return*/, (_a.sent()).hash];
346
346
  }
@@ -405,8 +405,8 @@ export var depositPlainMixin = {
405
405
  case 4:
406
406
  gas = _a.sent();
407
407
  if (estimateGas)
408
- return [2 /*return*/, Number(gas)];
409
- gasLimit = mulBy1_3(gas);
408
+ return [2 /*return*/, smartNumber(gas)];
409
+ gasLimit = mulBy1_3(DIGas(gas));
410
410
  return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
411
411
  case 5: return [2 /*return*/, (_a.sent()).hash];
412
412
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { _ensureAllowance, fromBN, getEthIndex, hasAllowance, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
50
  function _depositWrappedCheck(amounts, estimateGas) {
51
51
  if (estimateGas === void 0) { estimateGas = false; }
52
52
  return __awaiter(this, void 0, void 0, function () {
@@ -130,8 +130,8 @@ export var depositWrapped2argsMixin = {
130
130
  case 4:
131
131
  gas = _a.sent();
132
132
  if (estimateGas)
133
- return [2 /*return*/, Number(gas)];
134
- gasLimit = mulBy1_3(gas);
133
+ return [2 /*return*/, smartNumber(gas)];
134
+ gasLimit = mulBy1_3(DIGas(gas));
135
135
  return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
136
136
  case 5: return [2 /*return*/, (_a.sent()).hash];
137
137
  }
@@ -196,8 +196,8 @@ export var depositWrapped3argsMixin = {
196
196
  case 4:
197
197
  gas = _a.sent();
198
198
  if (estimateGas)
199
- return [2 /*return*/, Number(gas)];
200
- gasLimit = mulBy1_3(gas);
199
+ return [2 /*return*/, smartNumber(gas)];
200
+ gasLimit = mulBy1_3(DIGas(gas));
201
201
  return [4 /*yield*/, contract.add_liquidity(_amounts, _minMintAmount, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit, value: value }))];
202
202
  case 5: return [2 /*return*/, (_a.sent()).hash];
203
203
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { _ensureAllowance, _getCoinDecimals, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _swapCheck(inputCoin, outputCoin, amount, estimateGas) {
52
52
  if (estimateGas === void 0) { estimateGas = false; }
@@ -129,8 +129,8 @@ export var swapTricrypto2Mixin = {
129
129
  case 4:
130
130
  gas = _a.sent();
131
131
  if (estimateGas)
132
- return [2 /*return*/, Number(gas)];
133
- gasLimit = mulBy1_3(gas);
132
+ return [2 /*return*/, smartNumber(gas)];
133
+ gasLimit = mulBy1_3(DIGas(gas));
134
134
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
135
135
  case 5: return [2 /*return*/, (_a.sent()).hash];
136
136
  }
@@ -196,8 +196,8 @@ export var swapMetaFactoryMixin = {
196
196
  case 4:
197
197
  gas = _a.sent();
198
198
  if (estimateGas)
199
- return [2 /*return*/, Number(gas)];
200
- gasLimit = gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
199
+ return [2 /*return*/, smartNumber(gas)];
200
+ gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
201
201
  return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
202
202
  case 5: return [2 /*return*/, (_a.sent()).hash];
203
203
  }
@@ -263,8 +263,8 @@ export var swapCryptoMetaFactoryMixin = {
263
263
  case 4:
264
264
  gas = _a.sent();
265
265
  if (estimateGas)
266
- return [2 /*return*/, Number(gas)];
267
- gasLimit = gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
266
+ return [2 /*return*/, smartNumber(gas)];
267
+ gasLimit = DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0);
268
268
  return [4 /*yield*/, contract[exchangeMethod](this.address, i, j, _amount, _minRecvAmount, true, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
269
269
  case 5: return [2 /*return*/, (_a.sent()).hash];
270
270
  }
@@ -330,11 +330,11 @@ export var swapMixin = {
330
330
  case 4:
331
331
  gas = _a.sent();
332
332
  if (estimateGas)
333
- return [2 /*return*/, Number(gas)];
333
+ return [2 /*return*/, smartNumber(gas)];
334
334
  return [4 /*yield*/, curve.updateFeeData()];
335
335
  case 5:
336
336
  _a.sent();
337
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
337
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
338
338
  return [4 /*yield*/, contract[exchangeMethod](i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
339
339
  case 6: return [2 /*return*/, (_a.sent()).hash];
340
340
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, } from "../../utils.js";
49
+ import { _ensureAllowance, _getCoinDecimals, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, parseUnits, mulBy1_3, DIGas, smartNumber } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _swapWrappedCheck(inputCoin, outputCoin, amount, estimateGas) {
52
52
  if (estimateGas === void 0) { estimateGas = false; }
@@ -126,8 +126,8 @@ export var swapWrappedTricrypto2Mixin = {
126
126
  case 4:
127
127
  gas = _a.sent();
128
128
  if (estimateGas)
129
- return [2 /*return*/, Number(gas)];
130
- gasLimit = mulBy1_3(gas);
129
+ return [2 /*return*/, smartNumber(gas)];
130
+ gasLimit = mulBy1_3(DIGas(gas));
131
131
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, false, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
132
132
  case 5: return [2 /*return*/, (_a.sent()).hash];
133
133
  }
@@ -191,8 +191,8 @@ export var swapWrappedMixin = {
191
191
  case 4:
192
192
  gas = _a.sent();
193
193
  if (estimateGas)
194
- return [2 /*return*/, Number(gas)];
195
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
194
+ return [2 /*return*/, smartNumber(gas)];
195
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
196
196
  return [4 /*yield*/, contract.exchange(i, j, _amount, _minRecvAmount, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
197
197
  case 5: return [2 /*return*/, (_a.sent()).hash];
198
198
  }
@@ -309,5 +309,5 @@ export var swapWrappedRequiredMixin = {
309
309
  }
310
310
  });
311
311
  });
312
- }
312
+ },
313
313
  };
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _withdrawImbalanceCheck(amounts, estimateGas) {
52
52
  if (estimateGas === void 0) { estimateGas = false; }
@@ -122,8 +122,8 @@ export var withdrawImbalanceMetaFactoryMixin = {
122
122
  case 4:
123
123
  gas = _a.sent();
124
124
  if (estimateGas)
125
- return [2 /*return*/, Number(gas)];
126
- gasLimit = mulBy1_3(gas);
125
+ return [2 /*return*/, smartNumber(gas)];
126
+ gasLimit = mulBy1_3(DIGas(gas));
127
127
  return [4 /*yield*/, contract.remove_liquidity_imbalance(this.address, _amounts, _maxBurnAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
128
128
  case 5: return [2 /*return*/, (_a.sent()).hash];
129
129
  }
@@ -186,8 +186,8 @@ export var withdrawImbalanceZapMixin = {
186
186
  case 4:
187
187
  gas = _a.sent();
188
188
  if (estimateGas)
189
- return [2 /*return*/, Number(gas)];
190
- gasLimit = mulBy1_3(gas);
189
+ return [2 /*return*/, smartNumber(gas)];
190
+ gasLimit = mulBy1_3(DIGas(gas));
191
191
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
192
192
  case 5: return [2 /*return*/, (_a.sent()).hash];
193
193
  }
@@ -244,8 +244,8 @@ export var withdrawImbalanceLendingMixin = {
244
244
  case 2:
245
245
  gas = _a.sent();
246
246
  if (estimateGas)
247
- return [2 /*return*/, Number(gas)];
248
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
247
+ return [2 /*return*/, smartNumber(gas)];
248
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
249
249
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
250
250
  case 3: return [2 /*return*/, (_a.sent()).hash];
251
251
  }
@@ -302,8 +302,8 @@ export var withdrawImbalancePlainMixin = {
302
302
  case 2:
303
303
  gas = _a.sent();
304
304
  if (estimateGas)
305
- return [2 /*return*/, Number(gas)];
306
- gasLimit = mulBy1_3(gas);
305
+ return [2 /*return*/, smartNumber(gas)];
306
+ gasLimit = mulBy1_3(DIGas(gas));
307
307
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
308
308
  case 3: return [2 /*return*/, (_a.sent()).hash];
309
309
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { fromBN, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _withdrawImbalanceWrappedCheck(amounts) {
52
52
  return __awaiter(this, void 0, void 0, function () {
@@ -103,8 +103,8 @@ export var withdrawImbalanceWrapped2argsMixin = {
103
103
  case 2:
104
104
  gas = _a.sent();
105
105
  if (estimateGas)
106
- return [2 /*return*/, Number(gas)];
107
- gasLimit = mulBy1_3(gas);
106
+ return [2 /*return*/, smartNumber(gas)];
107
+ gasLimit = mulBy1_3(DIGas(gas));
108
108
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
109
109
  case 3: return [2 /*return*/, (_a.sent()).hash];
110
110
  }
@@ -161,8 +161,8 @@ export var withdrawImbalanceWrapped3argsMixin = {
161
161
  case 2:
162
162
  gas = _a.sent();
163
163
  if (estimateGas)
164
- return [2 /*return*/, Number(gas)];
165
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
164
+ return [2 /*return*/, smartNumber(gas)];
165
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("140", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
166
166
  return [4 /*yield*/, contract.remove_liquidity_imbalance(_amounts, _maxBurnAmount, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
167
167
  case 3: return [2 /*return*/, (_a.sent()).hash];
168
168
  }
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
57
  import { curve } from "../../curve.js";
58
- import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
58
+ import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
59
59
  // @ts-ignore
60
60
  function _withdrawCheck(lpTokenAmount, estimateGas) {
61
61
  if (estimateGas === void 0) { estimateGas = false; }
@@ -129,8 +129,8 @@ export var withdrawMetaFactoryMixin = {
129
129
  case 4:
130
130
  gas = _b.sent();
131
131
  if (estimateGas)
132
- return [2 /*return*/, Number(gas)];
133
- gasLimit = mulBy1_3(gas);
132
+ return [2 /*return*/, smartNumber(gas)];
133
+ gasLimit = mulBy1_3(DIGas(gas));
134
134
  return [4 /*yield*/, contract.remove_liquidity(this.address, _lpTokenAmount, _minAmounts, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
135
135
  case 5: return [2 /*return*/, (_b.sent()).hash];
136
136
  }
@@ -193,8 +193,8 @@ export var withdrawCryptoMetaFactoryMixin = {
193
193
  case 4:
194
194
  gas = _b.sent();
195
195
  if (estimateGas)
196
- return [2 /*return*/, Number(gas)];
197
- gasLimit = mulBy1_3(gas);
196
+ return [2 /*return*/, smartNumber(gas)];
197
+ gasLimit = mulBy1_3(DIGas(gas));
198
198
  return [4 /*yield*/, contract.remove_liquidity(this.address, _lpTokenAmount, _minAmounts, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
199
199
  case 5: return [2 /*return*/, (_b.sent()).hash];
200
200
  }
@@ -261,8 +261,8 @@ export var withdrawZapMixin = {
261
261
  case 4:
262
262
  gas = _c.sent();
263
263
  if (estimateGas)
264
- return [2 /*return*/, Number(gas)];
265
- gasLimit = mulBy1_3(gas);
264
+ return [2 /*return*/, smartNumber(gas)];
265
+ gasLimit = mulBy1_3(DIGas(gas));
266
266
  return [4 /*yield*/, contract.remove_liquidity.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
267
267
  case 5: return [2 /*return*/, (_c.sent()).hash];
268
268
  }
@@ -319,8 +319,8 @@ export var withdrawLendingOrCryptoMixin = {
319
319
  case 2:
320
320
  gas = _b.sent();
321
321
  if (estimateGas)
322
- return [2 /*return*/, Number(gas)];
323
- gasLimit = mulBy1_3(gas);
322
+ return [2 /*return*/, smartNumber(gas)];
323
+ gasLimit = mulBy1_3(DIGas(gas));
324
324
  return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
325
325
  case 3: return [2 /*return*/, (_b.sent()).hash];
326
326
  }
@@ -377,8 +377,8 @@ export var withdrawPlainMixin = {
377
377
  case 2:
378
378
  gas = _b.sent();
379
379
  if (estimateGas)
380
- return [2 /*return*/, Number(gas)];
381
- gasLimit = mulBy1_3(gas);
380
+ return [2 /*return*/, smartNumber(gas)];
381
+ gasLimit = mulBy1_3(DIGas(gas));
382
382
  return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
383
383
  case 3: return [2 /*return*/, (_b.sent()).hash];
384
384
  }
@@ -55,7 +55,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
55
55
  return to.concat(ar || Array.prototype.slice.call(from));
56
56
  };
57
57
  import { curve } from "../../curve.js";
58
- import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
58
+ import { _ensureAllowance, fromBN, hasAllowance, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
59
59
  // @ts-ignore
60
60
  function _withdrawOneCoinCheck(lpTokenAmount, coin, estimateGas) {
61
61
  if (estimateGas === void 0) { estimateGas = false; }
@@ -130,8 +130,8 @@ export var withdrawOneCoinMetaFactoryMixin = {
130
130
  case 4:
131
131
  gas = _a.sent();
132
132
  if (estimateGas)
133
- return [2 /*return*/, Number(gas)];
134
- gasLimit = mulBy1_3(gas);
133
+ return [2 /*return*/, smartNumber(gas)];
134
+ gasLimit = mulBy1_3(DIGas(gas));
135
135
  return [4 /*yield*/, contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
136
136
  case 5: return [2 /*return*/, (_a.sent()).hash];
137
137
  }
@@ -194,8 +194,8 @@ export var withdrawOneCoinCryptoMetaFactoryMixin = {
194
194
  case 4:
195
195
  gas = _a.sent();
196
196
  if (estimateGas)
197
- return [2 /*return*/, Number(gas)];
198
- gasLimit = mulBy1_3(gas);
197
+ return [2 /*return*/, smartNumber(gas)];
198
+ gasLimit = mulBy1_3(DIGas(gas));
199
199
  return [4 /*yield*/, contract.remove_liquidity_one_coin(this.address, _lpTokenAmount, i, _minAmount, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
200
200
  case 5: return [2 /*return*/, (_a.sent()).hash];
201
201
  }
@@ -262,8 +262,8 @@ export var withdrawOneCoinZapMixin = {
262
262
  case 4:
263
263
  gas = _b.sent();
264
264
  if (estimateGas)
265
- return [2 /*return*/, Number(gas)];
266
- gasLimit = mulBy1_3(gas);
265
+ return [2 /*return*/, smartNumber(gas)];
266
+ gasLimit = mulBy1_3(DIGas(gas));
267
267
  return [4 /*yield*/, contract.remove_liquidity_one_coin.apply(contract, __spreadArray(__spreadArray([], args, false), [__assign(__assign({}, curve.options), { gasLimit: gasLimit })], false))];
268
268
  case 5: return [2 /*return*/, (_b.sent()).hash];
269
269
  }
@@ -320,8 +320,8 @@ export var withdrawOneCoinLendingOrCryptoMixin = {
320
320
  case 2:
321
321
  gas = _a.sent();
322
322
  if (estimateGas)
323
- return [2 /*return*/, Number(gas)];
324
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
323
+ return [2 /*return*/, smartNumber(gas)];
324
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
325
325
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, true, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
326
326
  case 3: return [2 /*return*/, (_a.sent()).hash];
327
327
  }
@@ -378,8 +378,8 @@ export var withdrawOneCoinPlainMixin = {
378
378
  case 2:
379
379
  gas = _a.sent();
380
380
  if (estimateGas)
381
- return [2 /*return*/, Number(gas)];
382
- gasLimit = mulBy1_3(gas);
381
+ return [2 /*return*/, smartNumber(gas)];
382
+ gasLimit = mulBy1_3(DIGas(gas));
383
383
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
384
384
  case 3: return [2 /*return*/, (_a.sent()).hash];
385
385
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { fromBN, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _withdrawOneCoinWrappedCheck(lpTokenAmount, coin) {
52
52
  return __awaiter(this, void 0, void 0, function () {
@@ -101,8 +101,8 @@ export var withdrawOneCoinWrappedLendingOrCryptoMixin = {
101
101
  case 2:
102
102
  gas = _a.sent();
103
103
  if (estimateGas)
104
- return [2 /*return*/, Number(gas)];
105
- gasLimit = curve.chainId === 137 && this.id === 'ren' ? gas * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(gas);
104
+ return [2 /*return*/, smartNumber(gas)];
105
+ gasLimit = curve.chainId === 137 && this.id === 'ren' ? DIGas(gas) * curve.parseUnits("160", 0) / curve.parseUnits("100", 0) : mulBy1_3(DIGas(gas));
106
106
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
107
107
  case 3: return [2 /*return*/, (_a.sent()).hash];
108
108
  }
@@ -159,8 +159,8 @@ export var withdrawOneCoinWrappedMixin = {
159
159
  case 2:
160
160
  gas = _a.sent();
161
161
  if (estimateGas)
162
- return [2 /*return*/, Number(gas)];
163
- gasLimit = mulBy1_3(gas);
162
+ return [2 /*return*/, smartNumber(gas)];
163
+ gasLimit = mulBy1_3(DIGas(gas));
164
164
  return [4 /*yield*/, contract.remove_liquidity_one_coin(_lpTokenAmount, i, _minAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
165
165
  case 3: return [2 /*return*/, (_a.sent()).hash];
166
166
  }
@@ -46,7 +46,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
46
  }
47
47
  };
48
48
  import { curve } from "../../curve.js";
49
- import { fromBN, toBN, parseUnits, mulBy1_3 } from "../../utils.js";
49
+ import { fromBN, toBN, parseUnits, mulBy1_3, smartNumber, DIGas } from '../../utils.js';
50
50
  // @ts-ignore
51
51
  function _withdrawWrappedCheck(lpTokenAmount) {
52
52
  return __awaiter(this, void 0, void 0, function () {
@@ -101,8 +101,8 @@ export var withdrawWrapped2argsMixin = {
101
101
  case 2:
102
102
  gas = _b.sent();
103
103
  if (estimateGas)
104
- return [2 /*return*/, Number(gas)];
105
- gasLimit = mulBy1_3(gas);
104
+ return [2 /*return*/, smartNumber(gas)];
105
+ gasLimit = mulBy1_3(DIGas(gas));
106
106
  return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
107
107
  case 3: return [2 /*return*/, (_b.sent()).hash];
108
108
  }
@@ -159,8 +159,8 @@ export var withdrawWrapped3argsMixin = {
159
159
  case 2:
160
160
  gas = _b.sent();
161
161
  if (estimateGas)
162
- return [2 /*return*/, Number(gas)];
163
- gasLimit = mulBy1_3(gas);
162
+ return [2 /*return*/, smartNumber(gas)];
163
+ gasLimit = mulBy1_3(DIGas(gas));
164
164
  return [4 /*yield*/, contract.remove_liquidity(_lpTokenAmount, _minAmounts, false, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
165
165
  case 3: return [2 /*return*/, (_b.sent()).hash];
166
166
  }
package/lib/router.js CHANGED
@@ -58,7 +58,7 @@ import axios from "axios";
58
58
  import memoize from "memoizee";
59
59
  import { ethers } from "ethers";
60
60
  import { curve } from "./curve.js";
61
- import { _getCoinAddresses, _getCoinDecimals, _getUsdRate, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, BN, parseUnits, _cutZeros, ETH_ADDRESS, _get_small_x, _get_price_impact, } from "./utils.js";
61
+ import { _getCoinAddresses, _getCoinDecimals, _getUsdRate, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, isEth, toBN, BN, parseUnits, _cutZeros, ETH_ADDRESS, _get_small_x, _get_price_impact, DIGas, } from "./utils.js";
62
62
  import { getPool } from "./pools/index.js";
63
63
  import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
64
64
  var MAX_STEPS = 5;
@@ -568,7 +568,7 @@ var _estimateGasForDifferentRoutes = function (routes, inputCoinAddress, outputC
568
568
  var routeKey = _getRouteKey(route, inputCoinAddress, outputCoinAddress);
569
569
  _estimatedGasForDifferentRoutesCache[routeKey] = { 'gas': _gasAmounts_1[i], 'time': Date.now() };
570
570
  });
571
- return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(curve.formatUnits(_g, 0)); })];
571
+ return [2 /*return*/, _gasAmounts_1.map(function (_g) { return Number(curve.formatUnits(DIGas(_g), 0)); })];
572
572
  case 3:
573
573
  err_1 = _c.sent();
574
574
  return [2 /*return*/, routes.map(function () { return 0; })];
@@ -842,18 +842,18 @@ export var swapEstimateGas = function (inputCoin, outputCoin, amount) { return _
842
842
  export var swap = function (inputCoin, outputCoin, amount, slippage) {
843
843
  if (slippage === void 0) { slippage = 0.5; }
844
844
  return __awaiter(void 0, void 0, void 0, function () {
845
- var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _d, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit;
846
- return __generator(this, function (_e) {
847
- switch (_e.label) {
845
+ var _a, inputCoinAddress, outputCoinAddress, _b, inputCoinDecimals, outputCoinDecimals, _c, route, output, _d, _route, _swapParams, _pools, _amount, minRecvAmountBN, _minRecvAmount, contract, value, gasLimit, _e;
846
+ return __generator(this, function (_f) {
847
+ switch (_f.label) {
848
848
  case 0:
849
849
  _a = _getCoinAddresses(inputCoin, outputCoin), inputCoinAddress = _a[0], outputCoinAddress = _a[1];
850
850
  _b = _getCoinDecimals(inputCoinAddress, outputCoinAddress), inputCoinDecimals = _b[0], outputCoinDecimals = _b[1];
851
851
  return [4 /*yield*/, swapApprove(inputCoin, amount)];
852
852
  case 1:
853
- _e.sent();
853
+ _f.sent();
854
854
  return [4 /*yield*/, getBestRouteAndOutput(inputCoinAddress, outputCoinAddress, amount)];
855
855
  case 2:
856
- _c = _e.sent(), route = _c.route, output = _c.output;
856
+ _c = _f.sent(), route = _c.route, output = _c.output;
857
857
  if (route.length === 0) {
858
858
  throw new Error("This pair can't be exchanged");
859
859
  }
@@ -865,12 +865,13 @@ export var swap = function (inputCoin, outputCoin, amount, slippage) {
865
865
  value = isEth(inputCoinAddress) ? _amount : curve.parseUnits("0");
866
866
  return [4 /*yield*/, curve.updateFeeData()];
867
867
  case 3:
868
- _e.sent();
868
+ _f.sent();
869
+ _e = DIGas;
869
870
  return [4 /*yield*/, contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.constantOptions), { value: value }))];
870
871
  case 4:
871
- gasLimit = (_e.sent()) * (curve.chainId === 1 ? curve.parseUnits("130", 0) : curve.parseUnits("160", 0)) / curve.parseUnits("100", 0);
872
+ gasLimit = (_e.apply(void 0, [_f.sent()])) * (curve.chainId === 1 ? curve.parseUnits("130", 0) : curve.parseUnits("160", 0)) / curve.parseUnits("100", 0);
872
873
  return [4 /*yield*/, contract.exchange(_route, _swapParams, _amount, _minRecvAmount, _pools, __assign(__assign({}, curve.options), { value: value, gasLimit: gasLimit }))];
873
- case 5: return [2 /*return*/, _e.sent()];
874
+ case 5: return [2 /*return*/, _f.sent()];
874
875
  }
875
876
  });
876
877
  });
package/lib/utils.d.ts CHANGED
@@ -13,6 +13,8 @@ export declare const fromBN: (bn: BigNumber, decimals?: number) => bigint;
13
13
  export declare const isEth: (address: string) => boolean;
14
14
  export declare const getEthIndex: (addresses: string[]) => number;
15
15
  export declare const mulBy1_3: (n: bigint) => bigint;
16
+ export declare const smartNumber: (abstractNumber: bigint | bigint[]) => number | number[];
17
+ export declare const DIGas: (gas: bigint | Array<bigint>) => bigint;
16
18
  export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
17
19
  export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
18
20
  export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
@@ -31,6 +33,7 @@ export declare const _getCrvApyFromApi: () => Promise<IDict<[number, number]>>;
31
33
  export declare const _getRewardsFromApi: () => Promise<IDict<IRewardFromApi[]>>;
32
34
  export declare const _getUsdRate: (assetId: string) => Promise<number>;
33
35
  export declare const getUsdRate: (coin: string) => Promise<number>;
36
+ export declare const getGasPriceFromL1: () => Promise<number>;
34
37
  export declare const getTVL: (network?: INetworkName | IChainId) => Promise<number>;
35
38
  export declare const getVolume: (network?: INetworkName | IChainId) => Promise<{
36
39
  totalVolume: number;
package/lib/utils.js CHANGED
@@ -61,6 +61,7 @@ import BigNumber from 'bignumber.js';
61
61
  import { curve, NETWORK_CONSTANTS } from "./curve.js";
62
62
  import { _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes, _getAllPoolsFromApi, _getSubgraphData } from "./external-api.js";
63
63
  import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
64
+ import { L2Networks } from './constants/L2Networks';
64
65
  export var ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
65
66
  // export const MAX_ALLOWANCE = curve.parseUnits(new BigNumber(2).pow(256).minus(1).toFixed(), 0);
66
67
  export var MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
@@ -102,6 +103,22 @@ export var fromBN = function (bn, decimals) {
102
103
  export var isEth = function (address) { return address.toLowerCase() === ETH_ADDRESS.toLowerCase(); };
103
104
  export var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(ETH_ADDRESS.toLowerCase()); };
104
105
  export var mulBy1_3 = function (n) { return n * curve.parseUnits("130", 0) / curve.parseUnits("100", 0); };
106
+ export var smartNumber = function (abstractNumber) {
107
+ if (Array.isArray(abstractNumber)) {
108
+ return [Number(abstractNumber[0]), Number(abstractNumber[1])];
109
+ }
110
+ else {
111
+ return Number(abstractNumber);
112
+ }
113
+ };
114
+ export var DIGas = function (gas) {
115
+ if (Array.isArray(gas)) {
116
+ return gas[0];
117
+ }
118
+ else {
119
+ return gas;
120
+ }
121
+ };
105
122
  // coins can be either addresses or symbols
106
123
  export var _getCoinAddressesNoCheck = function () {
107
124
  var coins = [];
@@ -281,17 +298,17 @@ export var hasAllowance = function (coins, amounts, address, spender) { return _
281
298
  export var _ensureAllowance = function (coins, amounts, spender, isMax) {
282
299
  if (isMax === void 0) { isMax = true; }
283
300
  return __awaiter(void 0, void 0, void 0, function () {
284
- var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, _c, gasLimit, _d, _e, _f;
285
- return __generator(this, function (_g) {
286
- switch (_g.label) {
301
+ var address, allowance, txHashes, i, contract, _approveAmount, gasLimit_1, _a, _b, _c, _d, gasLimit, _e, _f, _g, _h;
302
+ return __generator(this, function (_j) {
303
+ switch (_j.label) {
287
304
  case 0:
288
305
  address = curve.signerAddress;
289
306
  return [4 /*yield*/, _getAllowance(coins, address, spender)];
290
307
  case 1:
291
- allowance = _g.sent();
308
+ allowance = _j.sent();
292
309
  txHashes = [];
293
310
  i = 0;
294
- _g.label = 2;
311
+ _j.label = 2;
295
312
  case 2:
296
313
  if (!(i < allowance.length)) return [3 /*break*/, 10];
297
314
  if (!(allowance[i] < amounts[i])) return [3 /*break*/, 9];
@@ -299,27 +316,29 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
299
316
  _approveAmount = isMax ? MAX_ALLOWANCE : amounts[i];
300
317
  return [4 /*yield*/, curve.updateFeeData()];
301
318
  case 3:
302
- _g.sent();
319
+ _j.sent();
303
320
  if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 6];
304
321
  _a = mulBy1_3;
322
+ _b = DIGas;
305
323
  return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
306
324
  case 4:
307
- gasLimit_1 = _a.apply(void 0, [_g.sent()]);
308
- _c = (_b = txHashes).push;
325
+ gasLimit_1 = _a.apply(void 0, [_b.apply(void 0, [_j.sent()])]);
326
+ _d = (_c = txHashes).push;
309
327
  return [4 /*yield*/, contract.approve(spender, curve.parseUnits("0"), __assign(__assign({}, curve.options), { gasLimit: gasLimit_1 }))];
310
328
  case 5:
311
- _c.apply(_b, [(_g.sent()).hash]);
312
- _g.label = 6;
329
+ _d.apply(_c, [(_j.sent()).hash]);
330
+ _j.label = 6;
313
331
  case 6:
314
- _d = mulBy1_3;
332
+ _e = mulBy1_3;
333
+ _f = DIGas;
315
334
  return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
316
335
  case 7:
317
- gasLimit = _d.apply(void 0, [_g.sent()]);
318
- _f = (_e = txHashes).push;
336
+ gasLimit = _e.apply(void 0, [_f.apply(void 0, [_j.sent()])]);
337
+ _h = (_g = txHashes).push;
319
338
  return [4 /*yield*/, contract.approve(spender, _approveAmount, __assign(__assign({}, curve.options), { gasLimit: gasLimit }))];
320
339
  case 8:
321
- _f.apply(_e, [(_g.sent()).hash]);
322
- _g.label = 9;
340
+ _h.apply(_g, [(_j.sent()).hash]);
341
+ _j.label = 9;
323
342
  case 9:
324
343
  i++;
325
344
  return [3 /*break*/, 2];
@@ -332,9 +351,9 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
332
351
  export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
333
352
  if (isMax === void 0) { isMax = true; }
334
353
  return __awaiter(void 0, void 0, void 0, function () {
335
- var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b, _c, _d;
336
- return __generator(this, function (_e) {
337
- switch (_e.label) {
354
+ var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, _a, _b, _c, _d, _e, _f;
355
+ return __generator(this, function (_g) {
356
+ switch (_g.label) {
338
357
  case 0:
339
358
  coinAddresses = _getCoinAddresses(coins);
340
359
  decimals = _getCoinDecimals(coinAddresses);
@@ -342,10 +361,10 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
342
361
  address = curve.signerAddress;
343
362
  return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
344
363
  case 1:
345
- allowance = _e.sent();
364
+ allowance = _g.sent();
346
365
  gas = 0;
347
366
  i = 0;
348
- _e.label = 2;
367
+ _g.label = 2;
349
368
  case 2:
350
369
  if (!(i < allowance.length)) return [3 /*break*/, 7];
351
370
  if (!(allowance[i] < _amounts[i])) return [3 /*break*/, 6];
@@ -354,17 +373,19 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
354
373
  if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
355
374
  _a = gas;
356
375
  _b = Number;
376
+ _c = DIGas;
357
377
  return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
358
378
  case 3:
359
- gas = _a + _b.apply(void 0, [_e.sent()]);
360
- _e.label = 4;
379
+ gas = _a + _b.apply(void 0, [_c.apply(void 0, [_g.sent()])]);
380
+ _g.label = 4;
361
381
  case 4:
362
- _c = gas;
363
- _d = Number;
382
+ _d = gas;
383
+ _e = Number;
384
+ _f = DIGas;
364
385
  return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
365
386
  case 5:
366
- gas = _c + _d.apply(void 0, [_e.sent()]);
367
- _e.label = 6;
387
+ gas = _d + _e.apply(void 0, [_f.apply(void 0, [_g.sent()])]);
388
+ _g.label = 6;
368
389
  case 6:
369
390
  i++;
370
391
  return [3 /*break*/, 2];
@@ -645,6 +666,17 @@ export var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void
645
666
  }
646
667
  });
647
668
  }); };
669
+ export var getGasPriceFromL1 = function () { return __awaiter(void 0, void 0, void 0, function () {
670
+ return __generator(this, function (_a) {
671
+ switch (_a.label) {
672
+ case 0:
673
+ if (!L2Networks.includes(curve.chainId)) return [3 /*break*/, 2];
674
+ return [4 /*yield*/, curve.contracts[curve.constants.ALIASES.gas_oracle].contract.gasPrice()];
675
+ case 1: return [2 /*return*/, _a.sent()];
676
+ case 2: throw Error("This method exists only for L2 networks");
677
+ }
678
+ });
679
+ }); };
648
680
  var _getNetworkName = function (network) {
649
681
  if (network === void 0) { network = curve.chainId; }
650
682
  if (typeof network === "number" && NETWORK_CONSTANTS[network]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.48.0",
3
+ "version": "2.49.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",