@curvefi/api 2.52.4 → 2.53.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/lib/utils.js CHANGED
@@ -234,6 +234,12 @@ export var _prepareAddresses = function (addresses) {
234
234
  addresses = addresses;
235
235
  return addresses.filter(function (val, idx, arr) { return arr.indexOf(val) === idx; });
236
236
  };
237
+ export var _getAddress = function (address) {
238
+ address = address || curve.signerAddress;
239
+ if (!address)
240
+ throw Error("Need to connect wallet or pass address into args");
241
+ return address;
242
+ };
237
243
  export var getBalances = function (coins) {
238
244
  var addresses = [];
239
245
  for (var _i = 1; _i < arguments.length; _i++) {
@@ -369,7 +375,7 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
369
375
  export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
370
376
  if (isMax === void 0) { isMax = true; }
371
377
  return __awaiter(void 0, void 0, void 0, function () {
372
- var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, currentGas_1, _a, currentGas, _b;
378
+ var coinAddresses, decimals, _amounts, address, _allowance, gas, i, contract, _approveAmount, currentGas, _a, currentGas, _b;
373
379
  return __generator(this, function (_c) {
374
380
  switch (_c.label) {
375
381
  case 0:
@@ -379,22 +385,29 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
379
385
  address = curve.signerAddress;
380
386
  return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
381
387
  case 1:
382
- allowance = _c.sent();
388
+ _allowance = _c.sent();
383
389
  gas = [0, 0];
384
390
  i = 0;
385
391
  _c.label = 2;
386
392
  case 2:
387
- if (!(i < allowance.length)) return [3 /*break*/, 7];
388
- if (!(allowance[i] < _amounts[i])) return [3 /*break*/, 6];
393
+ if (!(i < _allowance.length)) return [3 /*break*/, 7];
394
+ if (!(_allowance[i] < _amounts[i])) return [3 /*break*/, 6];
389
395
  contract = curve.contracts[coinAddresses[i]].contract;
390
396
  _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
391
- if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
397
+ if (!(_allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
392
398
  _a = smartNumber;
393
399
  return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
394
400
  case 3:
395
- currentGas_1 = _a.apply(void 0, [_c.sent()]);
396
- gas = gasSum(gas, currentGas_1);
397
- _c.label = 4;
401
+ currentGas = _a.apply(void 0, [_c.sent()]);
402
+ // For some coins (crv for example ) we can't estimate the second tx gas (approve: 0 --> amount), so we assume it will cost the same amount of gas
403
+ if (typeof currentGas === "number") {
404
+ currentGas = currentGas * 2;
405
+ }
406
+ else {
407
+ currentGas = currentGas.map(function (g) { return g * 2; });
408
+ }
409
+ gas = gasSum(gas, currentGas);
410
+ return [3 /*break*/, 6];
398
411
  case 4:
399
412
  _b = smartNumber;
400
413
  return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
@@ -429,10 +442,13 @@ export var ensureAllowance = function (coins, amounts, spender, isMax) {
429
442
  };
430
443
  export var getPoolIdBySwapAddress = function (swapAddress) {
431
444
  var poolsData = curve.getPoolsData();
432
- return Object.entries(poolsData).filter(function (_a) {
445
+ var poolIds = Object.entries(poolsData).filter(function (_a) {
433
446
  var _ = _a[0], poolData = _a[1];
434
447
  return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
435
- })[0][0];
448
+ });
449
+ if (poolIds.length === 0)
450
+ return "";
451
+ return poolIds[0][0];
436
452
  };
437
453
  var _getTokenAddressBySwapAddress = function (swapAddress) {
438
454
  var poolsData = curve.getPoolsData();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.52.4",
3
+ "version": "2.53.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",