@curvefi/api 2.8.5 → 2.8.6
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 +30 -29
- package/lib/pools/PoolTemplate.js +12 -10
- package/package.json +1 -1
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,
|
|
194
|
-
return __generator(this, function (
|
|
195
|
-
switch (
|
|
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
|
-
|
|
257
|
-
if (
|
|
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
|
-
|
|
261
|
-
|
|
261
|
+
_b = (_o.sent());
|
|
262
|
+
_o.label = 2;
|
|
262
263
|
case 2:
|
|
263
|
-
network =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
283
|
+
_o.sent();
|
|
283
284
|
if (!this.signer) return [3 /*break*/, 8];
|
|
284
|
-
|
|
285
|
+
_o.label = 4;
|
|
285
286
|
case 4:
|
|
286
|
-
|
|
287
|
-
|
|
287
|
+
_o.trys.push([4, 6, , 7]);
|
|
288
|
+
_d = this;
|
|
288
289
|
return [4 /*yield*/, this.signer.getAddress()];
|
|
289
290
|
case 5:
|
|
290
|
-
|
|
291
|
+
_d.signerAddress = _o.sent();
|
|
291
292
|
return [3 /*break*/, 7];
|
|
292
293
|
case 6:
|
|
293
|
-
err_1 =
|
|
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
|
-
|
|
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
|
-
|
|
305
|
-
for (_i = 0,
|
|
306
|
-
pool =
|
|
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 (
|
|
330
|
-
coinAddr = _f
|
|
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 (
|
|
337
|
-
coinAddr = _h
|
|
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 (
|
|
349
|
-
coinAddr = _k
|
|
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
|
-
|
|
418
|
+
_m = this.constants.ALIASES;
|
|
418
419
|
return [4 /*yield*/, addressProviderContract.get_address(2, this.constantOptions)];
|
|
419
420
|
case 11:
|
|
420
|
-
|
|
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),
|
|
@@ -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,
|
|
573
|
-
return __generator(this, function (
|
|
574
|
-
switch (
|
|
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, [
|
|
588
|
-
|
|
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 = (
|
|
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 =
|
|
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 = (
|
|
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
|
-
|
|
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 =
|
|
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);
|