@curvefi/api 1.14.0 → 1.15.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.
Files changed (31) hide show
  1. package/README.md +30 -0
  2. package/lib/constants/abis/abis-ethereum.js +78 -16
  3. package/lib/constants/abis/abis-polygon.js +13 -5
  4. package/lib/constants/abis/json/aave/rewards.json +107 -0
  5. package/lib/constants/abis/json/atricrypto3/swap.json +63 -63
  6. package/lib/constants/abis/json/atricrypto3/zap.json +8 -8
  7. package/lib/constants/abis/json/crveth/swap.json +61 -61
  8. package/lib/constants/abis/json/eurt/swap.json +29 -29
  9. package/lib/constants/abis/json/eurtusd/deposit.json +13 -13
  10. package/lib/constants/abis/json/eurtusd/swap.json +59 -59
  11. package/lib/constants/abis/json/gauge.json +1 -1
  12. package/lib/constants/abis/json/gauge_factory.json +879 -0
  13. package/lib/constants/abis/json/gauge_rewards_only.json +649 -0
  14. package/lib/constants/abis/json/gauge_synthetix.json +590 -0
  15. package/lib/constants/abis/json/gauge_v2.json +942 -0
  16. package/lib/constants/abis/json/gauge_v3.json +954 -0
  17. package/lib/constants/abis/json/gauge_v4.json +913 -0
  18. package/lib/constants/abis/json/minter.json +165 -0
  19. package/lib/constants/abis/json/ren-polygon/swap.json +46 -46
  20. package/lib/constants/abis/json/reth/swap.json +38 -38
  21. package/lib/constants/abis/json/tricrypto2/deposit.json +3 -3
  22. package/lib/constants/abis/json/tricrypto2/swap.json +60 -60
  23. package/lib/constants/aliases.d.ts +2 -0
  24. package/lib/constants/aliases.js +2 -0
  25. package/lib/constants/coins-polygon.js +3 -2
  26. package/lib/curve.d.ts +1 -0
  27. package/lib/curve.js +43 -23
  28. package/lib/interfaces.d.ts +7 -1
  29. package/lib/pools.d.ts +13 -2
  30. package/lib/pools.js +187 -25
  31. package/package.json +1 -1
package/lib/curve.js CHANGED
@@ -65,7 +65,7 @@ var ethcall_1 = require("ethcall");
65
65
  var ERC20_json_1 = __importDefault(require("./constants/abis/json/ERC20.json"));
66
66
  var cERC20_json_1 = __importDefault(require("./constants/abis/json/cERC20.json"));
67
67
  var yERC20_json_1 = __importDefault(require("./constants/abis/json/yERC20.json"));
68
- var gauge_json_1 = __importDefault(require("./constants/abis/json/gauge.json"));
68
+ var minter_json_1 = __importDefault(require("./constants/abis/json/minter.json"));
69
69
  var votingescrow_json_1 = __importDefault(require("./constants/abis/json/votingescrow.json"));
70
70
  var address_provider_json_1 = __importDefault(require("./constants/abis/json/address_provider.json"));
71
71
  var gaugecontroller_json_1 = __importDefault(require("./constants/abis/json/gaugecontroller.json"));
@@ -79,6 +79,7 @@ var coins_polygon_1 = require("./constants/coins-polygon");
79
79
  var aliases_1 = require("./constants/aliases");
80
80
  exports.ALIASES = {
81
81
  "crv": "0xD533a949740bb3306d119CC777fa900bA034cd52",
82
+ "minter": "0xd061D61a4d941c39E5453435B6345Dc261C2fcE0",
82
83
  "voting_escrow": "0x5f3b5DfEb7B28CDbD7FAba78963EE202a494e2A2",
83
84
  "gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
84
85
  "address_provider": "0x0000000022d53366457f9d5e68ec105046fc4383",
@@ -104,9 +105,9 @@ var Curve = /** @class */ (function () {
104
105
  ) {
105
106
  if (options === void 0) { options = {}; }
106
107
  return __awaiter(this, void 0, void 0, function () {
107
- var cTokens, yTokens, ycTokens, aTokens, network, _a, customAbiTokens, _b, _i, _c, pool, _d, _e, coinAddr, _f, _g, coinAddr, _h, _j, coinAddr, addressProviderContract, _k;
108
- return __generator(this, function (_l) {
109
- switch (_l.label) {
108
+ var cTokens, yTokens, ycTokens, aTokens, network, _a, customAbiTokens, _b, _i, _c, pool, _d, _e, coinAddr, _f, _g, coinAddr, _h, _j, coinAddr, _k, _l, rewardTokenAddr, addressProviderContract, _m;
109
+ return __generator(this, function (_o) {
110
+ switch (_o.label) {
110
111
  case 0:
111
112
  // JsonRpc provider
112
113
  if (providerType.toLowerCase() === 'JsonRpc'.toLowerCase()) {
@@ -146,8 +147,8 @@ var Curve = /** @class */ (function () {
146
147
  if (_a) return [3 /*break*/, 2];
147
148
  return [4 /*yield*/, this.provider._networkPromise];
148
149
  case 1:
149
- _a = (_l.sent());
150
- _l.label = 2;
150
+ _a = (_o.sent());
151
+ _o.label = 2;
151
152
  case 2:
152
153
  network = _a;
153
154
  console.log("CURVE-JS IS CONNECTED TO NETWORK:", network);
@@ -203,21 +204,21 @@ var Curve = /** @class */ (function () {
203
204
  this.multicallProvider = new ethcall_1.Provider();
204
205
  return [4 /*yield*/, this.multicallProvider.init(this.provider)];
205
206
  case 3:
206
- _l.sent();
207
+ _o.sent();
207
208
  if (!this.signer) return [3 /*break*/, 5];
208
209
  _b = this;
209
210
  return [4 /*yield*/, this.signer.getAddress()];
210
211
  case 4:
211
- _b.signerAddress = _l.sent();
212
+ _b.signerAddress = _o.sent();
212
213
  return [3 /*break*/, 6];
213
214
  case 5:
214
215
  this.signerAddress = '';
215
- _l.label = 6;
216
+ _o.label = 6;
216
217
  case 6:
217
218
  this.feeData = { gasPrice: options.gasPrice, maxFeePerGas: options.maxFeePerGas, maxPriorityFeePerGas: options.maxPriorityFeePerGas };
218
219
  return [4 /*yield*/, this.updateFeeData()];
219
220
  case 7:
220
- _l.sent();
221
+ _o.sent();
221
222
  // TODO delete toLowerCase()
222
223
  for (_i = 0, _c = Object.values(exports.POOLS_DATA); _i < _c.length; _i++) {
223
224
  pool = _c[_i];
@@ -240,12 +241,12 @@ var Curve = /** @class */ (function () {
240
241
  };
241
242
  }
242
243
  this.contracts[pool.gauge_address] = {
243
- contract: new ethers_1.Contract(pool.gauge_address, gauge_json_1.default, this.signer || this.provider),
244
- multicallContract: new ethcall_1.Contract(pool.gauge_address, gauge_json_1.default),
244
+ contract: new ethers_1.Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
245
+ multicallContract: new ethcall_1.Contract(pool.gauge_address, pool.gauge_abi),
245
246
  };
246
247
  this.contracts[pool.gauge_address.toLowerCase()] = {
247
- contract: new ethers_1.Contract(pool.gauge_address, gauge_json_1.default, this.signer || this.provider),
248
- multicallContract: new ethcall_1.Contract(pool.gauge_address, gauge_json_1.default),
248
+ contract: new ethers_1.Contract(pool.gauge_address, pool.gauge_abi, this.signer || this.provider),
249
+ multicallContract: new ethcall_1.Contract(pool.gauge_address, pool.gauge_abi),
249
250
  };
250
251
  if (pool.deposit_address && this.contracts[pool.deposit_address] === undefined) {
251
252
  this.contracts[pool.deposit_address] = {
@@ -315,14 +316,25 @@ var Curve = /** @class */ (function () {
315
316
  };
316
317
  }
317
318
  }
318
- if (pool.crv_reward_contract) {
319
- this.contracts[pool.crv_reward_contract] = {
320
- contract: new ethers_1.Contract(pool.crv_reward_contract, streamer_json_1.default, this.signer || this.provider),
321
- multicallContract: new ethcall_1.Contract(pool.crv_reward_contract, streamer_json_1.default),
319
+ if (pool.reward_contract) {
320
+ this.contracts[pool.reward_contract] = {
321
+ contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
322
+ multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
322
323
  };
323
- this.contracts[pool.crv_reward_contract.toLowerCase()] = {
324
- contract: new ethers_1.Contract(pool.crv_reward_contract, streamer_json_1.default, this.signer || this.provider),
325
- multicallContract: new ethcall_1.Contract(pool.crv_reward_contract, streamer_json_1.default),
324
+ this.contracts[pool.reward_contract.toLowerCase()] = {
325
+ contract: new ethers_1.Contract(pool.reward_contract, streamer_json_1.default, this.signer || this.provider),
326
+ multicallContract: new ethcall_1.Contract(pool.reward_contract, streamer_json_1.default),
327
+ };
328
+ }
329
+ for (_k = 0, _l = pool.reward_tokens || []; _k < _l.length; _k++) {
330
+ rewardTokenAddr = _l[_k];
331
+ this.contracts[rewardTokenAddr] = {
332
+ contract: new ethers_1.Contract(rewardTokenAddr, ERC20_json_1.default, this.signer || this.provider),
333
+ multicallContract: new ethcall_1.Contract(rewardTokenAddr, ERC20_json_1.default),
334
+ };
335
+ this.contracts[rewardTokenAddr.toLowerCase()] = {
336
+ contract: new ethers_1.Contract(rewardTokenAddr, ERC20_json_1.default, this.signer || this.provider),
337
+ multicallContract: new ethcall_1.Contract(rewardTokenAddr, ERC20_json_1.default),
326
338
  };
327
339
  }
328
340
  }
@@ -334,6 +346,14 @@ var Curve = /** @class */ (function () {
334
346
  contract: new ethers_1.Contract(exports.ALIASES.crv, ERC20_json_1.default, this.signer || this.provider),
335
347
  multicallContract: new ethcall_1.Contract(exports.ALIASES.crv, ERC20_json_1.default),
336
348
  };
349
+ this.contracts[exports.ALIASES.minter] = {
350
+ contract: new ethers_1.Contract(exports.ALIASES.minter, minter_json_1.default, this.signer || this.provider),
351
+ multicallContract: new ethcall_1.Contract(exports.ALIASES.minter, minter_json_1.default),
352
+ };
353
+ this.contracts[exports.ALIASES.minter.toLowerCase()] = {
354
+ contract: new ethers_1.Contract(exports.ALIASES.minter, minter_json_1.default, this.signer || this.provider),
355
+ multicallContract: new ethcall_1.Contract(exports.ALIASES.minter, minter_json_1.default),
356
+ };
337
357
  this.contracts[exports.ALIASES.voting_escrow] = {
338
358
  contract: new ethers_1.Contract(exports.ALIASES.voting_escrow, votingescrow_json_1.default, this.signer || this.provider),
339
359
  multicallContract: new ethcall_1.Contract(exports.ALIASES.voting_escrow, votingescrow_json_1.default),
@@ -351,10 +371,10 @@ var Curve = /** @class */ (function () {
351
371
  multicallContract: new ethcall_1.Contract(exports.ALIASES.address_provider, address_provider_json_1.default),
352
372
  };
353
373
  addressProviderContract = this.contracts[exports.ALIASES.address_provider].contract;
354
- _k = exports.ALIASES;
374
+ _m = exports.ALIASES;
355
375
  return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
356
376
  case 8:
357
- _k.registry_exchange = _l.sent();
377
+ _m.registry_exchange = _o.sent();
358
378
  this.contracts[exports.ALIASES.registry_exchange] = {
359
379
  contract: new ethers_1.Contract(exports.ALIASES.registry_exchange, registry_exchange_json_1.default, this.signer || this.provider),
360
380
  multicallContract: new ethcall_1.Contract(exports.ALIASES.registry_exchange, registry_exchange_json_1.default),
@@ -24,6 +24,7 @@ export interface PoolDataInterface {
24
24
  underlying_coin_addresses: string[];
25
25
  coin_addresses: string[];
26
26
  swap_abi: any;
27
+ gauge_abi: any;
27
28
  deposit_abi?: any;
28
29
  old_swap_abi?: any;
29
30
  is_meta?: boolean;
@@ -49,5 +50,10 @@ export interface PoolDataInterface {
49
50
  reward_token?: string;
50
51
  reward_tokens?: string[];
51
52
  pool_type?: string;
52
- crv_reward_contract?: string;
53
+ reward_contract?: string;
54
+ }
55
+ export interface RewardsApyInterface {
56
+ token: string;
57
+ symbol: string;
58
+ apy: string;
53
59
  }
package/lib/pools.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ethers } from "ethers";
2
2
  import BigNumber from 'bignumber.js';
3
- import { DictInterface } from './interfaces';
3
+ import { DictInterface, RewardsApyInterface } from './interfaces';
4
4
  export declare class Pool {
5
5
  name: string;
6
6
  referenceAsset: string;
@@ -8,7 +8,7 @@ export declare class Pool {
8
8
  zap: string | null;
9
9
  lpToken: string;
10
10
  gauge: string;
11
- crvRewardContract: string | null;
11
+ rewardContract: string | null;
12
12
  underlyingCoins: string[];
13
13
  coins: string[];
14
14
  underlyingCoinAddresses: string[];
@@ -21,6 +21,7 @@ export declare class Pool {
21
21
  isCrypto: boolean;
22
22
  basePool: string;
23
23
  isFactory: boolean;
24
+ rewardTokens: string[];
24
25
  estimateGas: {
25
26
  addLiquidityApprove: (amounts: string[]) => Promise<number>;
26
27
  addLiquidity: (amounts: string[]) => Promise<number>;
@@ -57,6 +58,7 @@ export declare class Pool {
57
58
  getVolume: () => Promise<string>;
58
59
  getBaseApy: () => Promise<[daily: string, weekly: string, monthly: string, total: string]>;
59
60
  getTokenApy: () => Promise<[baseApy: string, boostedApy: string]>;
61
+ getRewardsApy: () => Promise<RewardsApyInterface[]>;
60
62
  };
61
63
  constructor(name: string);
62
64
  calcLpTokenAmount: (amounts: string[], isDeposit?: boolean) => Promise<string>;
@@ -68,6 +70,7 @@ export declare class Pool {
68
70
  private getVolume;
69
71
  private getBaseApy;
70
72
  private getTokenApy;
73
+ private getRewardsApy;
71
74
  addLiquidityExpected: (amounts: string[]) => Promise<string>;
72
75
  addLiquiditySlippage: (amounts: string[]) => Promise<string>;
73
76
  addLiquidityIsApproved: (amounts: string[]) => Promise<boolean>;
@@ -122,6 +125,14 @@ export declare class Pool {
122
125
  gaugeDeposit: (lpTokenAmount: string) => Promise<string>;
123
126
  private gaugeWithdrawEstimateGas;
124
127
  gaugeWithdraw: (lpTokenAmount: string) => Promise<string>;
128
+ gaugeClaimableTokens: (address?: string) => Promise<string>;
129
+ gaugeClaimTokens: () => Promise<string>;
130
+ gaugeClaimableRewards: (address?: string) => Promise<{
131
+ token: string;
132
+ symbol: string;
133
+ amount: string;
134
+ }[]>;
135
+ gaugeClaimRewards: () => Promise<string>;
125
136
  balances: (...addresses: string[] | string[][]) => Promise<DictInterface<DictInterface<string>> | DictInterface<string>>;
126
137
  lpTokenBalances: (...addresses: string[] | string[][]) => Promise<DictInterface<DictInterface<string>> | DictInterface<string>>;
127
138
  underlyingCoinBalances: (...addresses: string[] | string[][]) => Promise<DictInterface<DictInterface<string>> | DictInterface<string>>;
package/lib/pools.js CHANGED
@@ -263,49 +263,92 @@ var Pool = /** @class */ (function () {
263
263
  });
264
264
  }); };
265
265
  this.getTokenApy = function () { return __awaiter(_this, void 0, void 0, function () {
266
- var rewardContract, totalLiquidityUSD, crvRate, inflation, _a, baseApy, gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _c, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
267
- return __generator(this, function (_d) {
268
- switch (_d.label) {
266
+ var gaugeContract, lpTokenContract, gaugeControllerContract, totalLiquidityUSD, _a, inflation, weight, workingSupply, totalSupply, rate, crvRate, baseApy, boostedApy;
267
+ return __generator(this, function (_c) {
268
+ switch (_c.label) {
269
269
  case 0:
270
- if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 4];
271
- rewardContract = curve_1.curve.contracts[this.crvRewardContract].contract;
272
- return [4 /*yield*/, this.getTotalLiquidity()];
273
- case 1:
274
- totalLiquidityUSD = _d.sent();
275
- return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
276
- case 2:
277
- crvRate = _d.sent();
278
- _a = utils_1.toBN;
279
- return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
280
- case 3:
281
- inflation = _a.apply(void 0, [(_d.sent()).rate]);
282
- baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
283
- return [2 /*return*/, [baseApy.times(100).toFixed(4), ""]];
284
- case 4:
270
+ if (curve_1.curve.chainId === 137)
271
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use getRewardsApy instead"));
285
272
  gaugeContract = curve_1.curve.contracts[this.gauge].multicallContract;
286
273
  lpTokenContract = curve_1.curve.contracts[this.lpToken].multicallContract;
287
274
  gaugeControllerContract = curve_1.curve.contracts[curve_1.ALIASES.gauge_controller].multicallContract;
288
275
  return [4 /*yield*/, this.getTotalLiquidity()];
289
- case 5:
290
- totalLiquidityUSD = _d.sent();
276
+ case 1:
277
+ totalLiquidityUSD = _c.sent();
291
278
  return [4 /*yield*/, curve_1.curve.multicallProvider.all([
292
279
  gaugeContract.inflation_rate(),
293
280
  gaugeControllerContract.gauge_relative_weight(this.gauge),
294
281
  gaugeContract.working_supply(),
295
282
  lpTokenContract.totalSupply(),
296
283
  ])];
297
- case 6:
298
- _c = (_d.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _c[0], weight = _c[1], workingSupply = _c[2], totalSupply = _c[3];
284
+ case 2:
285
+ _a = (_c.sent()).map(function (value) { return (0, utils_1.toBN)(value); }), inflation = _a[0], weight = _a[1], workingSupply = _a[2], totalSupply = _a[3];
299
286
  rate = inflation.times(weight).times(31536000).times(0.4).div(workingSupply).times(totalSupply).div(Number(totalLiquidityUSD));
300
287
  return [4 /*yield*/, (0, utils_1._getUsdRate)(curve_1.ALIASES.crv)];
301
- case 7:
302
- crvRate = _d.sent();
288
+ case 3:
289
+ crvRate = _c.sent();
303
290
  baseApy = rate.times(crvRate);
304
291
  boostedApy = baseApy.times(2.5);
305
292
  return [2 /*return*/, [baseApy.times(100).toFixed(4), boostedApy.times(100).toFixed(4)]];
306
293
  }
307
294
  });
308
295
  }); };
296
+ this.getRewardsApy = function () { return __awaiter(_this, void 0, void 0, function () {
297
+ var apy_1, _i, _a, rewardToken, rewardContract, totalLiquidityUSD, crvRate, inflation, _c, baseApy, rewardTokenContract, symbol, mainPoolsGaugeRewards, mainPoolsGaugeRewardsLowerCase, apyData, apy, _d, apyData_1, data;
298
+ return __generator(this, function (_e) {
299
+ switch (_e.label) {
300
+ case 0:
301
+ if (!(curve_1.curve.chainId === 137)) return [3 /*break*/, 8];
302
+ apy_1 = [];
303
+ _i = 0, _a = this.rewardTokens;
304
+ _e.label = 1;
305
+ case 1:
306
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
307
+ rewardToken = _a[_i];
308
+ rewardContract = curve_1.curve.contracts[this.rewardContract].contract;
309
+ return [4 /*yield*/, this.getTotalLiquidity()];
310
+ case 2:
311
+ totalLiquidityUSD = _e.sent();
312
+ return [4 /*yield*/, (0, utils_1._getUsdRate)(rewardToken)];
313
+ case 3:
314
+ crvRate = _e.sent();
315
+ _c = utils_1.toBN;
316
+ return [4 /*yield*/, rewardContract.reward_data(curve_1.ALIASES.crv, curve_1.curve.constantOptions)];
317
+ case 4:
318
+ inflation = _c.apply(void 0, [(_e.sent()).rate]);
319
+ baseApy = inflation.times(31536000).times(crvRate).div(Number(totalLiquidityUSD));
320
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
321
+ return [4 /*yield*/, rewardTokenContract.symbol()];
322
+ case 5:
323
+ symbol = _e.sent();
324
+ apy_1.push({
325
+ token: rewardToken,
326
+ symbol: symbol,
327
+ apy: baseApy.times(100).toFixed(4),
328
+ });
329
+ _e.label = 6;
330
+ case 6:
331
+ _i++;
332
+ return [3 /*break*/, 1];
333
+ case 7: return [2 /*return*/, apy_1];
334
+ case 8: return [4 /*yield*/, axios_1.default.get("https://api.curve.fi/api/getMainPoolsGaugeRewards")];
335
+ case 9:
336
+ mainPoolsGaugeRewards = (_e.sent()).data.data.mainPoolsGaugeRewards;
337
+ mainPoolsGaugeRewardsLowerCase = Object.fromEntries(Object.entries(mainPoolsGaugeRewards).map(function (entry) { return [entry[0].toLowerCase(), entry[1]]; }));
338
+ apyData = mainPoolsGaugeRewardsLowerCase[this.gauge.toLowerCase()] || [];
339
+ apy = [];
340
+ for (_d = 0, apyData_1 = apyData; _d < apyData_1.length; _d++) {
341
+ data = apyData_1[_d];
342
+ apy.push({
343
+ token: data.tokenAddress,
344
+ symbol: data.symbol,
345
+ apy: String(data.apy),
346
+ });
347
+ }
348
+ return [2 /*return*/, apy];
349
+ }
350
+ });
351
+ }); };
309
352
  this.addLiquidityExpected = function (amounts) { return __awaiter(_this, void 0, void 0, function () {
310
353
  var _this = this;
311
354
  return __generator(this, function (_a) {
@@ -1360,6 +1403,123 @@ var Pool = /** @class */ (function () {
1360
1403
  }
1361
1404
  });
1362
1405
  }); };
1406
+ this.gaugeClaimableTokens = function (address) {
1407
+ if (address === void 0) { address = ""; }
1408
+ return __awaiter(_this, void 0, void 0, function () {
1409
+ var _a, _c;
1410
+ return __generator(this, function (_d) {
1411
+ switch (_d.label) {
1412
+ case 0:
1413
+ if (curve_1.curve.chainId !== 1)
1414
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimableRewards instead"));
1415
+ address = address || curve_1.curve.signerAddress;
1416
+ if (!address)
1417
+ throw Error("Need to connect wallet or pass address into args");
1418
+ _c = (_a = ethers_1.ethers.utils).formatUnits;
1419
+ return [4 /*yield*/, curve_1.curve.contracts[this.gauge].contract.claimable_tokens(address, curve_1.curve.constantOptions)];
1420
+ case 1: return [2 /*return*/, _c.apply(_a, [_d.sent()])];
1421
+ }
1422
+ });
1423
+ });
1424
+ };
1425
+ this.gaugeClaimTokens = function () { return __awaiter(_this, void 0, void 0, function () {
1426
+ var gasLimit;
1427
+ return __generator(this, function (_a) {
1428
+ switch (_a.label) {
1429
+ case 0:
1430
+ if (curve_1.curve.chainId !== 1)
1431
+ throw Error("No such method on network with id ".concat(curve_1.curve.chainId, ". Use gaugeClaimRewards instead"));
1432
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.estimateGas.mint(this.gauge, curve_1.curve.constantOptions)];
1433
+ case 1:
1434
+ gasLimit = (_a.sent()).mul(130).div(100);
1435
+ return [4 /*yield*/, curve_1.curve.contracts[curve_1.ALIASES.minter].contract.mint(this.gauge, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1436
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1437
+ }
1438
+ });
1439
+ }); };
1440
+ // TODO 1. Fix aave and saave error
1441
+ // TODO 2. Figure out Synthetix cumulative results
1442
+ this.gaugeClaimableRewards = function (address) {
1443
+ if (address === void 0) { address = ""; }
1444
+ return __awaiter(_this, void 0, void 0, function () {
1445
+ var gaugeContract, rewards, _i, _a, rewardToken, rewardTokenContract, symbol, decimals, method, amount, _c, _d, rewardToken, rewardTokenContract, symbol, decimals, amount, _e, _f;
1446
+ return __generator(this, function (_h) {
1447
+ switch (_h.label) {
1448
+ case 0:
1449
+ address = address || curve_1.curve.signerAddress;
1450
+ if (!address)
1451
+ throw Error("Need to connect wallet or pass address into args");
1452
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1453
+ rewards = [];
1454
+ if (!('claimable_reward(address,address)' in gaugeContract)) return [3 /*break*/, 7];
1455
+ _i = 0, _a = this.rewardTokens;
1456
+ _h.label = 1;
1457
+ case 1:
1458
+ if (!(_i < _a.length)) return [3 /*break*/, 6];
1459
+ rewardToken = _a[_i];
1460
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1461
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1462
+ case 2:
1463
+ symbol = _h.sent();
1464
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1465
+ case 3:
1466
+ decimals = _h.sent();
1467
+ method = curve_1.curve.chainId === 1 ? "claimable_reward" : "claimable_reward_write";
1468
+ _d = (_c = ethers_1.ethers.utils).formatUnits;
1469
+ return [4 /*yield*/, gaugeContract[method](address, rewardToken, curve_1.curve.constantOptions)];
1470
+ case 4:
1471
+ amount = _d.apply(_c, [_h.sent(), decimals]);
1472
+ rewards.push({
1473
+ token: rewardToken,
1474
+ symbol: symbol,
1475
+ amount: amount,
1476
+ });
1477
+ _h.label = 5;
1478
+ case 5:
1479
+ _i++;
1480
+ return [3 /*break*/, 1];
1481
+ case 6: return [3 /*break*/, 11];
1482
+ case 7:
1483
+ if (!('claimable_reward(address)' in gaugeContract && this.rewardTokens.length > 0)) return [3 /*break*/, 11];
1484
+ rewardToken = this.rewardTokens[0];
1485
+ rewardTokenContract = curve_1.curve.contracts[rewardToken].contract;
1486
+ return [4 /*yield*/, rewardTokenContract.symbol()];
1487
+ case 8:
1488
+ symbol = _h.sent();
1489
+ return [4 /*yield*/, rewardTokenContract.decimals()];
1490
+ case 9:
1491
+ decimals = _h.sent();
1492
+ _f = (_e = ethers_1.ethers.utils).formatUnits;
1493
+ return [4 /*yield*/, gaugeContract.claimable_reward(address, curve_1.curve.constantOptions)];
1494
+ case 10:
1495
+ amount = _f.apply(_e, [_h.sent(), decimals]);
1496
+ rewards.push({
1497
+ token: rewardToken,
1498
+ symbol: symbol,
1499
+ amount: amount,
1500
+ });
1501
+ _h.label = 11;
1502
+ case 11: return [2 /*return*/, rewards];
1503
+ }
1504
+ });
1505
+ });
1506
+ };
1507
+ this.gaugeClaimRewards = function () { return __awaiter(_this, void 0, void 0, function () {
1508
+ var gaugeContract, gasLimit;
1509
+ return __generator(this, function (_a) {
1510
+ switch (_a.label) {
1511
+ case 0:
1512
+ gaugeContract = curve_1.curve.contracts[this.gauge].contract;
1513
+ if (!("claim_rewards()" in gaugeContract))
1514
+ throw Error("".concat(this.name, " pool doesn't have such method"));
1515
+ return [4 /*yield*/, gaugeContract.estimateGas.claim_rewards(curve_1.curve.constantOptions)];
1516
+ case 1:
1517
+ gasLimit = (_a.sent()).mul(130).div(100);
1518
+ return [4 /*yield*/, gaugeContract.claim_rewards(__assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
1519
+ case 2: return [2 /*return*/, (_a.sent()).hash];
1520
+ }
1521
+ });
1522
+ }); };
1363
1523
  this.balances = function () {
1364
1524
  var addresses = [];
1365
1525
  for (var _i = 0; _i < arguments.length; _i++) {
@@ -2740,7 +2900,7 @@ var Pool = /** @class */ (function () {
2740
2900
  this.zap = poolData.deposit_address || null;
2741
2901
  this.lpToken = poolData.token_address;
2742
2902
  this.gauge = poolData.gauge_address;
2743
- this.crvRewardContract = poolData.crv_reward_contract || null;
2903
+ this.rewardContract = poolData.reward_contract || null;
2744
2904
  this.underlyingCoins = poolData.underlying_coins;
2745
2905
  this.coins = poolData.coins;
2746
2906
  this.underlyingCoinAddresses = poolData.underlying_coin_addresses;
@@ -2753,6 +2913,7 @@ var Pool = /** @class */ (function () {
2753
2913
  this.isCrypto = poolData.is_crypto || false;
2754
2914
  this.isFactory = poolData.is_factory || false;
2755
2915
  this.basePool = poolData.base_pool || '';
2916
+ this.rewardTokens = poolData.reward_tokens || [];
2756
2917
  this.estimateGas = {
2757
2918
  addLiquidityApprove: this.addLiquidityApproveEstimateGas,
2758
2919
  addLiquidity: this.addLiquidityEstimateGas,
@@ -2783,6 +2944,7 @@ var Pool = /** @class */ (function () {
2783
2944
  getVolume: this.getVolume,
2784
2945
  getBaseApy: this.getBaseApy,
2785
2946
  getTokenApy: this.getTokenApy,
2947
+ getRewardsApy: this.getRewardsApy,
2786
2948
  };
2787
2949
  if (this.isMeta && !this.isFake) {
2788
2950
  var metaCoins = poolData.meta_coin_addresses;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/api",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "description": "JavaScript library for curve.fi",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {