@curvefi/api 2.68.14 → 2.68.16

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.
@@ -435,39 +435,6 @@
435
435
  "stateMutability": "nonpayable",
436
436
  "type": "function"
437
437
  },
438
- {
439
- "inputs": [
440
- {
441
- "name": "i",
442
- "type": "uint256"
443
- },
444
- {
445
- "name": "j",
446
- "type": "uint256"
447
- },
448
- {
449
- "name": "dx",
450
- "type": "uint256"
451
- },
452
- {
453
- "name": "min_dy",
454
- "type": "uint256"
455
- },
456
- {
457
- "name": "receiver",
458
- "type": "address"
459
- }
460
- ],
461
- "name": "exchange",
462
- "outputs": [
463
- {
464
- "name": "",
465
- "type": "uint256"
466
- }
467
- ],
468
- "stateMutability": "nonpayable",
469
- "type": "function"
470
- },
471
438
  {
472
439
  "inputs": [
473
440
  {
@@ -32,6 +32,12 @@ export interface IStatsPool {
32
32
  export declare class StatsPool implements IStatsPool {
33
33
  pool: PoolTemplate;
34
34
  constructor(pool: PoolTemplate);
35
+ /**
36
+ * Safely fetches admin_fee from contract with fallback logic.
37
+ * This is necessary because for new pools we don't know their ABI in advance,
38
+ * and there's no way to determine it beforehand.
39
+ */
40
+ private _getAdminFeeSafely;
35
41
  parameters: () => Promise<IStatsParameters>;
36
42
  wrappedBalances(): Promise<string[]>;
37
43
  underlyingBalances(): Promise<string[]>;
@@ -11,16 +11,17 @@ import { _getPoolsFromApi, _getCrvApyFromApi } from '../../cached.js';
11
11
  import { _getUsdRate, BN, toBN, _getRewardsFromApi, getVolumeApiController, } from '../../utils.js';
12
12
  import { rewardNetworks } from '../../constants/rewardNetworks.js';
13
13
  import memoize from "memoizee";
14
+ import { Contract } from "ethers";
14
15
  export class StatsPool {
15
16
  constructor(pool) {
16
17
  this.parameters = () => __awaiter(this, void 0, void 0, function* () {
17
18
  const curve = this.pool.curve;
18
19
  const multicallContract = curve.contracts[this.pool.address].multicallContract;
19
20
  const lpMulticallContract = curve.contracts[this.pool.lpToken].multicallContract;
21
+ const _adminFee = yield this._getAdminFeeSafely();
20
22
  const calls = [
21
23
  multicallContract.get_virtual_price(),
22
24
  multicallContract.fee(),
23
- "admin_fee" in multicallContract ? multicallContract.admin_fee() : multicallContract.ADMIN_FEE(),
24
25
  multicallContract.A(),
25
26
  lpMulticallContract.totalSupply(),
26
27
  ];
@@ -43,19 +44,19 @@ export class StatsPool {
43
44
  }
44
45
  let _virtualPrice = curve.parseUnits("0");
45
46
  let _fee = curve.parseUnits("0");
46
- let _prices, _adminFee, _A, _lpTokenSupply, _gamma;
47
+ let _prices, _A, _lpTokenSupply, _gamma;
47
48
  try {
48
- [_virtualPrice, _fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
49
+ [_virtualPrice, _fee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
49
50
  }
50
51
  catch ( // Empty pool
51
52
  _a) { // Empty pool
52
53
  calls.shift();
53
54
  if (this.pool.isCrypto) {
54
55
  calls.shift();
55
- [_adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
56
+ [_A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
56
57
  }
57
58
  else {
58
- [_fee, _adminFee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
59
+ [_fee, _A, _lpTokenSupply, _gamma, ..._prices] = (yield curve.multicallProvider.all(calls));
59
60
  }
60
61
  }
61
62
  const [virtualPrice, fee, adminFee, A, lpTokenSupply, gamma] = [
@@ -221,6 +222,30 @@ export class StatsPool {
221
222
  });
222
223
  this.pool = pool;
223
224
  }
225
+ /**
226
+ * Safely fetches admin_fee from contract with fallback logic.
227
+ * This is necessary because for new pools we don't know their ABI in advance,
228
+ * and there's no way to determine it beforehand.
229
+ */
230
+ _getAdminFeeSafely() {
231
+ return __awaiter(this, void 0, void 0, function* () {
232
+ const curve = this.pool.curve;
233
+ const contract = curve.contracts[this.pool.address].contract;
234
+ try {
235
+ if ('admin_fee' in contract) {
236
+ return yield contract.admin_fee();
237
+ }
238
+ else {
239
+ return yield contract.ADMIN_FEE();
240
+ }
241
+ }
242
+ catch (_a) {
243
+ const ADMIN_FEE_ABI = { "stateMutability": "view", "type": "function", "name": "admin_fee", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] };
244
+ const tmpContract = new Contract(this.pool.address, [ADMIN_FEE_ABI], curve.signer || curve.provider);
245
+ return yield tmpContract.admin_fee();
246
+ }
247
+ });
248
+ }
224
249
  wrappedBalances() {
225
250
  return __awaiter(this, void 0, void 0, function* () {
226
251
  const curve = this.pool.curve;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "2.68.14",
3
+ "version": "2.68.16",
4
4
  "description": "JavaScript library for curve.finance",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",