@curvefi/api 2.8.4 → 2.8.7

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/curve.js CHANGED
@@ -188,11 +188,12 @@ var Curve = /** @class */ (function () {
188
188
  }
189
189
  Curve.prototype.init = function (providerType, providerSettings, options // gasPrice in Gwei
190
190
  ) {
191
+ var _a;
191
192
  if (options === void 0) { options = {}; }
192
193
  return __awaiter(this, void 0, void 0, function () {
193
- var network, _a, _b, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _c, err_1, _i, _d, pool, _e, _f, coinAddr, _g, _h, coinAddr, _j, _k, coinAddr, _minterABI, addressProviderContract, _l;
194
- return __generator(this, function (_m) {
195
- switch (_m.label) {
194
+ var network, _b, _c, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _d, err_1, _i, _e, pool, _f, _g, coinAddr, _h, _j, coinAddr, _k, _l, coinAddr, _minterABI, addressProviderContract, _m;
195
+ return __generator(this, function (_o) {
196
+ switch (_o.label) {
196
197
  case 0:
197
198
  // @ts-ignore
198
199
  this.provider = null;
@@ -228,7 +229,7 @@ var Curve = /** @class */ (function () {
228
229
  if (providerSettings.privateKey) {
229
230
  this.signer = new ethers_1.ethers.Wallet(providerSettings.privateKey, this.provider);
230
231
  }
231
- else {
232
+ else if (!((_a = providerSettings.url) === null || _a === void 0 ? void 0 : _a.startsWith("https://rpc.gnosischain.com"))) {
232
233
  this.signer = this.provider.getSigner();
233
234
  }
234
235
  // Web3 provider
@@ -253,14 +254,14 @@ var Curve = /** @class */ (function () {
253
254
  else {
254
255
  throw Error('Wrong providerType');
255
256
  }
256
- _a = this.provider.network;
257
- if (_a) return [3 /*break*/, 2];
257
+ _b = this.provider.network;
258
+ if (_b) return [3 /*break*/, 2];
258
259
  return [4 /*yield*/, this.provider._networkPromise];
259
260
  case 1:
260
- _a = (_m.sent());
261
- _m.label = 2;
261
+ _b = (_o.sent());
262
+ _o.label = 2;
262
263
  case 2:
263
- network = _a;
264
+ network = _b;
264
265
  console.log("CURVE-JS IS CONNECTED TO NETWORK:", network);
265
266
  this.chainId = network.chainId === 1337 ? 1 : network.chainId;
266
267
  this.constants.NETWORK_NAME = exports.NETWORK_CONSTANTS[this.chainId].NAME;
@@ -269,41 +270,41 @@ var Curve = /** @class */ (function () {
269
270
  this.constants.COINS = exports.NETWORK_CONSTANTS[this.chainId].COINS;
270
271
  this.constants.DECIMALS = (0, utils_1.extractDecimals)(this.constants.POOLS_DATA);
271
272
  this.constants.GAUGES = (0, utils_1.extractGauges)(this.constants.POOLS_DATA);
272
- _b = [
273
+ _c = [
273
274
  exports.NETWORK_CONSTANTS[this.chainId].cTokens,
274
275
  exports.NETWORK_CONSTANTS[this.chainId].yTokens,
275
276
  exports.NETWORK_CONSTANTS[this.chainId].ycTokens,
276
277
  exports.NETWORK_CONSTANTS[this.chainId].aTokens,
277
- ], cTokens = _b[0], yTokens = _b[1], ycTokens = _b[2], aTokens = _b[3];
278
+ ], cTokens = _c[0], yTokens = _c[1], ycTokens = _c[2], aTokens = _c[3];
278
279
  customAbiTokens = __spreadArray(__spreadArray(__spreadArray(__spreadArray([], cTokens, true), yTokens, true), ycTokens, true), aTokens, true);
279
280
  this.multicallProvider = new ethcall_1.Provider();
280
281
  return [4 /*yield*/, this.multicallProvider.init(this.provider)];
281
282
  case 3:
282
- _m.sent();
283
+ _o.sent();
283
284
  if (!this.signer) return [3 /*break*/, 8];
284
- _m.label = 4;
285
+ _o.label = 4;
285
286
  case 4:
286
- _m.trys.push([4, 6, , 7]);
287
- _c = this;
287
+ _o.trys.push([4, 6, , 7]);
288
+ _d = this;
288
289
  return [4 /*yield*/, this.signer.getAddress()];
289
290
  case 5:
290
- _c.signerAddress = _m.sent();
291
+ _d.signerAddress = _o.sent();
291
292
  return [3 /*break*/, 7];
292
293
  case 6:
293
- err_1 = _m.sent();
294
+ err_1 = _o.sent();
294
295
  this.signer = null;
295
296
  return [3 /*break*/, 7];
296
297
  case 7: return [3 /*break*/, 9];
297
298
  case 8:
298
299
  this.signerAddress = '';
299
- _m.label = 9;
300
+ _o.label = 9;
300
301
  case 9:
301
302
  this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
302
303
  return [4 /*yield*/, this.updateFeeData()];
303
304
  case 10:
304
- _m.sent();
305
- for (_i = 0, _d = Object.values(this.constants.POOLS_DATA); _i < _d.length; _i++) {
306
- pool = _d[_i];
305
+ _o.sent();
306
+ for (_i = 0, _e = Object.values(this.constants.POOLS_DATA); _i < _e.length; _i++) {
307
+ pool = _e[_i];
307
308
  this.contracts[pool.swap_address] = {
308
309
  contract: new ethers_1.Contract(pool.swap_address, pool.swap_abi, this.signer || this.provider),
309
310
  multicallContract: new ethcall_1.Contract(pool.swap_address, pool.swap_abi),
@@ -326,15 +327,15 @@ var Curve = /** @class */ (function () {
326
327
  multicallContract: new ethcall_1.Contract(pool.deposit_address, pool.deposit_abi),
327
328
  };
328
329
  }
329
- for (_e = 0, _f = pool.underlying_coin_addresses; _e < _f.length; _e++) {
330
- coinAddr = _f[_e];
330
+ for (_f = 0, _g = pool.underlying_coin_addresses; _f < _g.length; _f++) {
331
+ coinAddr = _g[_f];
331
332
  this.contracts[coinAddr] = {
332
333
  contract: new ethers_1.Contract(coinAddr, ERC20_json_1.default, this.signer || this.provider),
333
334
  multicallContract: new ethcall_1.Contract(coinAddr, ERC20_json_1.default),
334
335
  };
335
336
  }
336
- for (_g = 0, _h = pool.wrapped_coin_addresses; _g < _h.length; _g++) {
337
- coinAddr = _h[_g];
337
+ for (_h = 0, _j = pool.wrapped_coin_addresses; _h < _j.length; _h++) {
338
+ coinAddr = _j[_h];
338
339
  if (customAbiTokens.includes(coinAddr))
339
340
  continue;
340
341
  if (coinAddr in this.contracts)
@@ -345,8 +346,8 @@ var Curve = /** @class */ (function () {
345
346
  };
346
347
  }
347
348
  // TODO add all coins
348
- for (_j = 0, _k = pool.wrapped_coin_addresses; _j < _k.length; _j++) {
349
- coinAddr = _k[_j];
349
+ for (_k = 0, _l = pool.wrapped_coin_addresses; _k < _l.length; _k++) {
350
+ coinAddr = _l[_k];
350
351
  if (cTokens.includes(coinAddr)) {
351
352
  this.contracts[coinAddr] = {
352
353
  contract: new ethers_1.Contract(coinAddr, cERC20_json_1.default, this.signer || this.provider),
@@ -414,10 +415,10 @@ var Curve = /** @class */ (function () {
414
415
  multicallContract: new ethcall_1.Contract(this.constants.ALIASES.address_provider, address_provider_json_1.default),
415
416
  };
416
417
  addressProviderContract = this.contracts[this.constants.ALIASES.address_provider].contract;
417
- _l = this.constants.ALIASES;
418
+ _m = this.constants.ALIASES;
418
419
  return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
419
420
  case 11:
420
- _l.registry_exchange = _m.sent();
421
+ _m.registry_exchange = _o.sent();
421
422
  this.contracts[this.constants.ALIASES.registry_exchange] = {
422
423
  contract: new ethers_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default, this.signer || this.provider),
423
424
  multicallContract: new ethcall_1.Contract(this.constants.ALIASES.registry_exchange, registry_exchange_json_1.default),
@@ -32,6 +32,11 @@ function setFactoryZapContracts() {
32
32
  contract: new ethers_1.Contract(metaUsdZapAddress, deposit_json_1.default, this.signer || this.provider),
33
33
  multicallContract: new ethcall_1.Contract(metaUsdZapAddress, deposit_json_1.default),
34
34
  };
35
+ var metaUsd2ZapAddress = "0x4244eB811D6e0Ef302326675207A95113dB4E1F8".toLowerCase();
36
+ this.contracts[metaUsd2ZapAddress] = {
37
+ contract: new ethers_1.Contract(metaUsd2ZapAddress, DepositZapFantom_json_1.default, this.signer || this.provider),
38
+ multicallContract: new ethcall_1.Contract(metaUsd2ZapAddress, DepositZapFantom_json_1.default),
39
+ };
35
40
  }
36
41
  else if (this.chainId === 100) {
37
42
  var metaUsdZapAddress = "0x87C067fAc25f123554a0E76596BF28cFa37fD5E9".toLowerCase();
@@ -92,6 +97,11 @@ function setFactoryZapContracts() {
92
97
  contract: new ethers_1.Contract(metaBtcZapAddress, DepositZapFantom_json_1.default, this.signer || this.provider),
93
98
  multicallContract: new ethcall_1.Contract(metaBtcZapAddress, DepositZapFantom_json_1.default),
94
99
  };
100
+ var metaUsd2ZapAddress = "0x58AC91f5BE7dC0c35b24B96B19BAc55FBB8E705e".toLowerCase();
101
+ this.contracts[metaUsd2ZapAddress] = {
102
+ contract: new ethers_1.Contract(metaUsd2ZapAddress, DepositZapFantom_json_1.default, this.signer || this.provider),
103
+ multicallContract: new ethcall_1.Contract(metaUsd2ZapAddress, DepositZapFantom_json_1.default),
104
+ };
95
105
  }
96
106
  }
97
107
  exports.setFactoryZapContracts = setFactoryZapContracts;
@@ -110,6 +110,8 @@ exports.implementationABIDictArbitrum = {
110
110
  "0xBE175115BF33E12348ff77CcfEE4726866A0Fbd5": MetaUSDBalances_json_1.default,
111
111
  "0x094d12e5b541784701FD8d65F11fc0598FBC6332": MetaBTCRen_json_1.default,
112
112
  "0xF1f85a74AD6c64315F85af52d3d46bF715236ADc": MetaBTCBalancesRen_json_1.default,
113
+ "0x8DEb66a4A40E370355bEe35f12E55Fe9c755d686": MetaFraxUSD_json_1.default,
114
+ "0x3edE9b145F82e9e46C03f8A8F67B77aEE847b632": MetaFraxUSDBalances_json_1.default,
113
115
  "0x54e8A25d0Ac0E4945b697C80b8372445FEA17A62": Plain2Basic_json_1.default,
114
116
  "0xD68970e266cE1A015953897C7055a5E0bC657Af8": Plain2Balances_json_1.default,
115
117
  "0x7DA64233Fefb352f8F501B357c018158ED8aA455": Plain2ETH_json_1.default,
@@ -193,6 +195,8 @@ exports.implementationBasePoolIdDictArbitrum = {
193
195
  "0xBE175115BF33E12348ff77CcfEE4726866A0Fbd5": "2pool",
194
196
  "0x094d12e5b541784701FD8d65F11fc0598FBC6332": "ren",
195
197
  "0xF1f85a74AD6c64315F85af52d3d46bF715236ADc": "ren",
198
+ "0x8DEb66a4A40E370355bEe35f12E55Fe9c755d686": "factory-v2-41",
199
+ "0x3edE9b145F82e9e46C03f8A8F67B77aEE847b632": "factory-v2-41", // fraxbp
196
200
  };
197
201
  exports.implementationBasePoolIdDictOptimism = {
198
202
  "0x78CF256256C8089d68Cde634Cf7cDEFb39286470": "3pool",
@@ -226,10 +230,11 @@ exports.basePoolIdZapDictAvalanche = {
226
230
  exports.basePoolIdZapDictArbitrum = {
227
231
  "2pool": "0x7544Fe3d184b6B55D6B36c3FCA1157eE0Ba30287".toLowerCase(),
228
232
  ren: "0x803A2B40c5a9BB2B86DD630B274Fa2A9202874C2".toLowerCase(),
233
+ "factory-v2-41": "0x58AC91f5BE7dC0c35b24B96B19BAc55FBB8E705e".toLowerCase(),
229
234
  };
230
235
  exports.basePoolIdZapDictOptimism = {
231
236
  "3pool": "0x167e42a1c7ab4be03764a2222aac57f5f6754411".toLowerCase(),
232
- "factory-v2-16": "'0x4244eB811D6e0Ef302326675207A95113dB4E1F8'".toLowerCase(),
237
+ "factory-v2-16": "0x4244eB811D6e0Ef302326675207A95113dB4E1F8".toLowerCase(),
233
238
  };
234
239
  exports.basePoolIdZapDictXDai = {
235
240
  "3pool": "0x87C067fAc25f123554a0E76596BF28cFa37fD5E9".toLowerCase(),
@@ -569,9 +569,9 @@ var PoolTemplate = /** @class */ (function () {
569
569
  };
570
570
  // ---------------- REWARDS PROFIT, CLAIM ----------------
571
571
  this.rewardTokens = (0, memoizee_1.default)(function () { return __awaiter(_this, void 0, void 0, function () {
572
- var gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, _f, symbol, decimals;
573
- return __generator(this, function (_g) {
574
- switch (_g.label) {
572
+ var gaugeContract, gaugeMulticallContract, rewardCount, _c, _d, _e, tokenCalls, i, tokens, tokenInfoCalls, _i, tokens_1, token, tokenMulticallContract, tokenInfo_1, i, rewardContract, method, token, tokenMulticallContract, res, symbol, decimals;
573
+ return __generator(this, function (_f) {
574
+ switch (_f.label) {
575
575
  case 0:
576
576
  if (this.gauge === ethers_1.ethers.constants.AddressZero)
577
577
  return [2 /*return*/, []];
@@ -584,8 +584,8 @@ var PoolTemplate = /** @class */ (function () {
584
584
  _e = (_d = ethers_1.ethers.utils).formatUnits;
585
585
  return [4 /*yield*/, gaugeContract.reward_count(curve_1.curve.constantOptions)];
586
586
  case 1:
587
- rewardCount = _c.apply(void 0, [_e.apply(_d, [_g.sent(), 0])]);
588
- _g.label = 2;
587
+ rewardCount = _c.apply(void 0, [_e.apply(_d, [_f.sent(), 0])]);
588
+ _f.label = 2;
589
589
  case 2:
590
590
  tokenCalls = [];
591
591
  for (i = 0; i < rewardCount; i++) {
@@ -593,7 +593,7 @@ var PoolTemplate = /** @class */ (function () {
593
593
  }
594
594
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenCalls)];
595
595
  case 3:
596
- tokens = (_g.sent())
596
+ tokens = (_f.sent())
597
597
  .filter(function (addr) { return addr !== ethers_1.ethers.constants.AddressZero; })
598
598
  .map(function (addr) { return addr.toLowerCase(); });
599
599
  tokenInfoCalls = [];
@@ -605,7 +605,7 @@ var PoolTemplate = /** @class */ (function () {
605
605
  }
606
606
  return [4 /*yield*/, curve_1.curve.multicallProvider.all(tokenInfoCalls)];
607
607
  case 4:
608
- tokenInfo_1 = _g.sent();
608
+ tokenInfo_1 = _f.sent();
609
609
  for (i = 0; i < tokens.length; i++) {
610
610
  curve_1.curve.constants.DECIMALS[tokens[i]] = tokenInfo_1[(i * 2) + 1];
611
611
  }
@@ -617,7 +617,7 @@ var PoolTemplate = /** @class */ (function () {
617
617
  ;
618
618
  return [4 /*yield*/, rewardContract[method](curve_1.curve.constantOptions)];
619
619
  case 6:
620
- token = (_g.sent()).toLowerCase();
620
+ token = (_f.sent()).toLowerCase();
621
621
  (0, utils_1._setContracts)(token, ERC20_json_1.default);
622
622
  tokenMulticallContract = curve_1.curve.contracts[token].multicallContract;
623
623
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
@@ -625,7 +625,9 @@ var PoolTemplate = /** @class */ (function () {
625
625
  tokenMulticallContract.decimals(),
626
626
  ])];
627
627
  case 7:
628
- _f = _g.sent(), symbol = _f[0], decimals = _f[1];
628
+ res = _f.sent();
629
+ symbol = res[0];
630
+ decimals = res[0].toNumber();
629
631
  return [2 /*return*/, [{ token: token, symbol: symbol, decimals: decimals }]];
630
632
  case 8: return [2 /*return*/, []]; // gauge
631
633
  }
@@ -699,7 +701,7 @@ var PoolTemplate = /** @class */ (function () {
699
701
  ])];
700
702
  case 8:
701
703
  _d = _f.sent(), _inflationRate = _d[0], _periodFinish = _d[1], _balance = _d[2], _totalSupply = _d[3];
702
- periodFinish = Number(ethers_1.ethers.utils.formatUnits(_periodFinish, 0)) * 1000;
704
+ periodFinish = _periodFinish.toNumber() * 1000;
703
705
  inflationRateBN = periodFinish > Date.now() ? (0, utils_1.toBN)(_inflationRate, rewardToken.decimals) : (0, utils_1.BN)(0);
704
706
  balanceBN = (0, utils_1.toBN)(_balance);
705
707
  totalSupplyBN = (0, utils_1.toBN)(_totalSupply);
package/lib/utils.d.ts CHANGED
@@ -13,6 +13,7 @@ export declare const formatNumber: (n: number | string, decimals?: number) => st
13
13
  export declare const parseUnits: (n: number | string, decimals?: number) => ethers.BigNumber;
14
14
  export declare const isEth: (address: string) => boolean;
15
15
  export declare const getEthIndex: (addresses: string[]) => number;
16
+ export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
16
17
  export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
17
18
  export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
18
19
  export declare const _getBalances: (coins: string[], addresses: string[]) => Promise<IDict<string[]>>;
package/lib/utils.js CHANGED
@@ -59,7 +59,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
59
59
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
60
  };
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
- exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
62
+ exports._setContracts = exports.getTVL = exports.getUsdRate = exports._getUsdRate = exports._getUsdPricesFromApi = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports.ensureAllowanceEstimateGas = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports._getCoinAddressesNoCheck = exports.getEthIndex = exports.isEth = exports.parseUnits = exports.formatNumber = exports.checkNumber = exports._cutZeros = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = exports.ETH_ADDRESS = void 0;
63
63
  var axios_1 = __importDefault(require("axios"));
64
64
  var ethers_1 = require("ethers");
65
65
  var bignumber_js_1 = __importDefault(require("bignumber.js"));
@@ -116,7 +116,7 @@ exports.isEth = isEth;
116
116
  var getEthIndex = function (addresses) { return addresses.map(function (address) { return address.toLowerCase(); }).indexOf(exports.ETH_ADDRESS.toLowerCase()); };
117
117
  exports.getEthIndex = getEthIndex;
118
118
  // coins can be either addresses or symbols
119
- var _getCoinAddresses = function () {
119
+ var _getCoinAddressesNoCheck = function () {
120
120
  var coins = [];
121
121
  for (var _i = 0; _i < arguments.length; _i++) {
122
122
  coins[_i] = arguments[_i];
@@ -124,7 +124,15 @@ var _getCoinAddresses = function () {
124
124
  if (coins.length == 1 && Array.isArray(coins[0]))
125
125
  coins = coins[0];
126
126
  coins = coins;
127
- var coinAddresses = coins.map(function (c) { return c.toLowerCase(); }).map(function (c) { return curve_1.curve.constants.COINS[c] || c; });
127
+ return coins.map(function (c) { return c.toLowerCase(); }).map(function (c) { return curve_1.curve.constants.COINS[c] || c; });
128
+ };
129
+ exports._getCoinAddressesNoCheck = _getCoinAddressesNoCheck;
130
+ var _getCoinAddresses = function () {
131
+ var coins = [];
132
+ for (var _i = 0; _i < arguments.length; _i++) {
133
+ coins[_i] = arguments[_i];
134
+ }
135
+ var coinAddresses = exports._getCoinAddressesNoCheck.apply(void 0, coins);
128
136
  var availableAddresses = __spreadArray(__spreadArray([], Object.keys(curve_1.curve.constants.DECIMALS), true), curve_1.curve.constants.GAUGES, true);
129
137
  for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
130
138
  var coinAddr = coinAddresses_1[_a];
@@ -512,7 +520,7 @@ var getUsdRate = function (coin) { return __awaiter(void 0, void 0, void 0, func
512
520
  return __generator(this, function (_a) {
513
521
  switch (_a.label) {
514
522
  case 0:
515
- coinAddress = (0, exports._getCoinAddresses)(coin)[0];
523
+ coinAddress = (0, exports._getCoinAddressesNoCheck)(coin)[0];
516
524
  return [4 /*yield*/, (0, exports._getUsdRate)(coinAddress)];
517
525
  case 1: return [2 /*return*/, _a.sent()];
518
526
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.8.4",
3
+ "version": "2.8.7",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",