@curvefi/api 1.2.0 → 1.4.2
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/boosting.d.ts +4 -0
- package/lib/boosting.js +136 -22
- package/lib/constants/coins.js +4 -2
- package/lib/curve.d.ts +18 -2
- package/lib/curve.js +76 -27
- package/lib/index.d.ts +19 -2
- package/lib/index.js +14 -3
- package/lib/pools.d.ts +31 -1
- package/lib/pools.js +1062 -397
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +85 -38
- package/package.json +2 -2
package/lib/utils.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare const _getAllowance: (coins: string[], address: string, spender:
|
|
|
17
17
|
export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
18
18
|
export declare const hasAllowance: (coins: string[], amounts: string[], address: string, spender: string) => Promise<boolean>;
|
|
19
19
|
export declare const _ensureAllowance: (coins: string[], amounts: ethers.BigNumber[], spender: string) => Promise<string[]>;
|
|
20
|
+
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: string[], spender: string) => Promise<number>;
|
|
20
21
|
export declare const ensureAllowance: (coins: string[], amounts: string[], spender: string) => Promise<string[]>;
|
|
21
22
|
export declare const getPoolNameBySwapAddress: (swapAddress: string) => string;
|
|
22
23
|
export declare const getCrvRate: () => Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -46,16 +46,20 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from) {
|
|
50
|
-
for (var i = 0,
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
53
57
|
};
|
|
54
58
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
55
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
56
60
|
};
|
|
57
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
58
|
-
exports.getCrvRate = exports.getPoolNameBySwapAddress = exports.ensureAllowance = exports._ensureAllowance = exports.hasAllowance = exports.getAllowance = exports._getAllowance = exports.getBalances = exports._prepareAddresses = exports._getBalances = exports._getCoinDecimals = exports._getCoinAddresses = exports.getEthIndex = exports.isEth = exports.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
62
|
+
exports.getCrvRate = 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.fromBN = exports.toStringFromBN = exports.toBN = exports.BN = exports.MAX_ALLOWANCE = void 0;
|
|
59
63
|
var axios_1 = __importDefault(require("axios"));
|
|
60
64
|
var ethers_1 = require("ethers");
|
|
61
65
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
@@ -71,7 +75,7 @@ var BN = function (val) { return new bignumber_js_1.default(val); };
|
|
|
71
75
|
exports.BN = BN;
|
|
72
76
|
var toBN = function (n, decimals) {
|
|
73
77
|
if (decimals === void 0) { decimals = 18; }
|
|
74
|
-
return exports.BN(ethers_1.ethers.utils.formatUnits(n, decimals)).times(decimals);
|
|
78
|
+
return (0, exports.BN)(ethers_1.ethers.utils.formatUnits(n, decimals)).times(decimals);
|
|
75
79
|
};
|
|
76
80
|
exports.toBN = toBN;
|
|
77
81
|
var toStringFromBN = function (bn, decimals) {
|
|
@@ -81,7 +85,7 @@ var toStringFromBN = function (bn, decimals) {
|
|
|
81
85
|
exports.toStringFromBN = toStringFromBN;
|
|
82
86
|
var fromBN = function (bn, decimals) {
|
|
83
87
|
if (decimals === void 0) { decimals = 18; }
|
|
84
|
-
return ethers_1.ethers.utils.parseUnits(exports.toStringFromBN(bn, decimals), decimals);
|
|
88
|
+
return ethers_1.ethers.utils.parseUnits((0, exports.toStringFromBN)(bn, decimals), decimals);
|
|
85
89
|
};
|
|
86
90
|
exports.fromBN = fromBN;
|
|
87
91
|
// -------------------
|
|
@@ -99,7 +103,7 @@ var _getCoinAddresses = function () {
|
|
|
99
103
|
coins = coins[0];
|
|
100
104
|
coins = coins;
|
|
101
105
|
var coinAddresses = coins.map(function (c) { return coins_1.COINS[c.toLowerCase()] || c; });
|
|
102
|
-
var availableAddresses = __spreadArray(__spreadArray(__spreadArray([], Object.keys(coins_1.LOWER_CASE_DECIMALS).filter(function (c) { return c !== coins_1.COINS['snx'].toLowerCase(); })), LP_TOKENS), GAUGES);
|
|
106
|
+
var availableAddresses = __spreadArray(__spreadArray(__spreadArray([], Object.keys(coins_1.LOWER_CASE_DECIMALS).filter(function (c) { return c !== coins_1.COINS['snx'].toLowerCase(); }), true), LP_TOKENS, true), GAUGES, true);
|
|
103
107
|
for (var _a = 0, coinAddresses_1 = coinAddresses; _a < coinAddresses_1.length; _a++) {
|
|
104
108
|
var coinAddr = coinAddresses_1[_a];
|
|
105
109
|
if (!availableAddresses.includes(coinAddr.toLowerCase()))
|
|
@@ -124,9 +128,9 @@ var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0
|
|
|
124
128
|
return __generator(this, function (_e) {
|
|
125
129
|
switch (_e.label) {
|
|
126
130
|
case 0:
|
|
127
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
128
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
129
|
-
ethIndex = exports.getEthIndex(coinAddresses);
|
|
131
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
132
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
133
|
+
ethIndex = (0, exports.getEthIndex)(coinAddresses);
|
|
130
134
|
if (ethIndex !== -1) {
|
|
131
135
|
coinAddresses.splice(ethIndex, 1);
|
|
132
136
|
}
|
|
@@ -157,7 +161,7 @@ var _getBalances = function (coins, addresses) { return __awaiter(void 0, void 0
|
|
|
157
161
|
_a++;
|
|
158
162
|
return [3 /*break*/, 2];
|
|
159
163
|
case 5:
|
|
160
|
-
response.splice.apply(response, __spreadArray([ethIndex * addresses.length, 0], ethBalances));
|
|
164
|
+
response.splice.apply(response, __spreadArray([ethIndex * addresses.length, 0], ethBalances, false));
|
|
161
165
|
_e.label = 6;
|
|
162
166
|
case 6:
|
|
163
167
|
_balances = {};
|
|
@@ -193,8 +197,8 @@ var getBalances = function (coins) {
|
|
|
193
197
|
return __generator(this, function (_a) {
|
|
194
198
|
switch (_a.label) {
|
|
195
199
|
case 0:
|
|
196
|
-
addresses = exports._prepareAddresses(addresses);
|
|
197
|
-
return [4 /*yield*/, exports._getBalances(coins, addresses)];
|
|
200
|
+
addresses = (0, exports._prepareAddresses)(addresses);
|
|
201
|
+
return [4 /*yield*/, (0, exports._getBalances)(coins, addresses)];
|
|
198
202
|
case 1:
|
|
199
203
|
balances = _a.sent();
|
|
200
204
|
return [2 /*return*/, addresses.length === 1 ? balances[addresses[0]] : balances];
|
|
@@ -208,8 +212,8 @@ var _getAllowance = function (coins, address, spender) { return __awaiter(void 0
|
|
|
208
212
|
return __generator(this, function (_a) {
|
|
209
213
|
switch (_a.label) {
|
|
210
214
|
case 0:
|
|
211
|
-
_coins = __spreadArray([], coins);
|
|
212
|
-
ethIndex = exports.getEthIndex(_coins);
|
|
215
|
+
_coins = __spreadArray([], coins, true);
|
|
216
|
+
ethIndex = (0, exports.getEthIndex)(_coins);
|
|
213
217
|
if (ethIndex !== -1) {
|
|
214
218
|
_coins.splice(ethIndex, 1);
|
|
215
219
|
}
|
|
@@ -239,9 +243,9 @@ var getAllowance = function (coins, address, spender) { return __awaiter(void 0,
|
|
|
239
243
|
return __generator(this, function (_a) {
|
|
240
244
|
switch (_a.label) {
|
|
241
245
|
case 0:
|
|
242
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
243
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
244
|
-
return [4 /*yield*/, exports._getAllowance(coinAddresses, address, spender)];
|
|
246
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
247
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
248
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
245
249
|
case 1:
|
|
246
250
|
_allowance = _a.sent();
|
|
247
251
|
return [2 /*return*/, _allowance.map(function (a, i) { return ethers_1.ethers.utils.formatUnits(a, decimals[i]); })];
|
|
@@ -255,9 +259,9 @@ var hasAllowance = function (coins, amounts, address, spender) { return __awaite
|
|
|
255
259
|
return __generator(this, function (_a) {
|
|
256
260
|
switch (_a.label) {
|
|
257
261
|
case 0:
|
|
258
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
259
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
260
|
-
return [4 /*yield*/, exports._getAllowance(coinAddresses, address, spender)];
|
|
262
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
263
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
264
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
261
265
|
case 1:
|
|
262
266
|
_allowance = _a.sent();
|
|
263
267
|
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
@@ -272,51 +276,94 @@ var _ensureAllowance = function (coins, amounts, spender) { return __awaiter(voi
|
|
|
272
276
|
switch (_e.label) {
|
|
273
277
|
case 0:
|
|
274
278
|
address = curve_1.curve.signerAddress;
|
|
275
|
-
return [4 /*yield*/, exports._getAllowance(coins, address, spender)];
|
|
279
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coins, address, spender)];
|
|
276
280
|
case 1:
|
|
277
281
|
allowance = _e.sent();
|
|
278
282
|
txHashes = [];
|
|
279
283
|
i = 0;
|
|
280
284
|
_e.label = 2;
|
|
281
285
|
case 2:
|
|
282
|
-
if (!(i < allowance.length)) return [3 /*break*/,
|
|
283
|
-
if (!allowance[i].lt(amounts[i])) return [3 /*break*/,
|
|
286
|
+
if (!(i < allowance.length)) return [3 /*break*/, 10];
|
|
287
|
+
if (!allowance[i].lt(amounts[i])) return [3 /*break*/, 9];
|
|
284
288
|
contract = curve_1.curve.contracts[coins[i]].contract;
|
|
285
|
-
|
|
286
|
-
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.options)];
|
|
289
|
+
return [4 /*yield*/, curve_1.curve.updateFeeData()];
|
|
287
290
|
case 3:
|
|
291
|
+
_e.sent();
|
|
292
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 6];
|
|
293
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
294
|
+
case 4:
|
|
288
295
|
gasLimit_1 = (_e.sent()).mul(130).div(100);
|
|
289
296
|
_b = (_a = txHashes).push;
|
|
290
297
|
return [4 /*yield*/, contract.approve(spender, ethers_1.ethers.BigNumber.from(0), __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit_1 }))];
|
|
291
|
-
case
|
|
298
|
+
case 5:
|
|
292
299
|
_b.apply(_a, [(_e.sent()).hash]);
|
|
293
|
-
_e.label =
|
|
294
|
-
case
|
|
295
|
-
case
|
|
300
|
+
_e.label = 6;
|
|
301
|
+
case 6: return [4 /*yield*/, contract.estimateGas.approve(spender, exports.MAX_ALLOWANCE, curve_1.curve.constantOptions)];
|
|
302
|
+
case 7:
|
|
296
303
|
gasLimit = (_e.sent()).mul(130).div(100);
|
|
297
304
|
_d = (_c = txHashes).push;
|
|
298
305
|
return [4 /*yield*/, contract.approve(spender, exports.MAX_ALLOWANCE, __assign(__assign({}, curve_1.curve.options), { gasLimit: gasLimit }))];
|
|
299
|
-
case 7:
|
|
300
|
-
_d.apply(_c, [(_e.sent()).hash]);
|
|
301
|
-
_e.label = 8;
|
|
302
306
|
case 8:
|
|
307
|
+
_d.apply(_c, [(_e.sent()).hash]);
|
|
308
|
+
_e.label = 9;
|
|
309
|
+
case 9:
|
|
303
310
|
i++;
|
|
304
311
|
return [3 /*break*/, 2];
|
|
305
|
-
case
|
|
312
|
+
case 10: return [2 /*return*/, txHashes];
|
|
306
313
|
}
|
|
307
314
|
});
|
|
308
315
|
}); };
|
|
309
316
|
exports._ensureAllowance = _ensureAllowance;
|
|
310
317
|
// coins can be either addresses or symbols
|
|
318
|
+
var ensureAllowanceEstimateGas = function (coins, amounts, spender) { return __awaiter(void 0, void 0, void 0, function () {
|
|
319
|
+
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _a, _b;
|
|
320
|
+
return __generator(this, function (_c) {
|
|
321
|
+
switch (_c.label) {
|
|
322
|
+
case 0:
|
|
323
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
324
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
325
|
+
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
326
|
+
address = curve_1.curve.signerAddress;
|
|
327
|
+
return [4 /*yield*/, (0, exports._getAllowance)(coinAddresses, address, spender)];
|
|
328
|
+
case 1:
|
|
329
|
+
allowance = _c.sent();
|
|
330
|
+
gas = 0;
|
|
331
|
+
i = 0;
|
|
332
|
+
_c.label = 2;
|
|
333
|
+
case 2:
|
|
334
|
+
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
335
|
+
if (!allowance[i].lt(_amounts[i])) return [3 /*break*/, 6];
|
|
336
|
+
contract = curve_1.curve.contracts[coinAddresses[i]].contract;
|
|
337
|
+
if (!allowance[i].gt(ethers_1.ethers.BigNumber.from(0))) return [3 /*break*/, 4];
|
|
338
|
+
_a = gas;
|
|
339
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, ethers_1.ethers.BigNumber.from(0), curve_1.curve.constantOptions)];
|
|
340
|
+
case 3:
|
|
341
|
+
gas = _a + (_c.sent()).toNumber();
|
|
342
|
+
_c.label = 4;
|
|
343
|
+
case 4:
|
|
344
|
+
_b = gas;
|
|
345
|
+
return [4 /*yield*/, contract.estimateGas.approve(spender, exports.MAX_ALLOWANCE, curve_1.curve.constantOptions)];
|
|
346
|
+
case 5:
|
|
347
|
+
gas = _b + (_c.sent()).toNumber();
|
|
348
|
+
_c.label = 6;
|
|
349
|
+
case 6:
|
|
350
|
+
i++;
|
|
351
|
+
return [3 /*break*/, 2];
|
|
352
|
+
case 7: return [2 /*return*/, gas];
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
}); };
|
|
356
|
+
exports.ensureAllowanceEstimateGas = ensureAllowanceEstimateGas;
|
|
357
|
+
// coins can be either addresses or symbols
|
|
311
358
|
var ensureAllowance = function (coins, amounts, spender) { return __awaiter(void 0, void 0, void 0, function () {
|
|
312
359
|
var coinAddresses, decimals, _amounts;
|
|
313
360
|
return __generator(this, function (_a) {
|
|
314
361
|
switch (_a.label) {
|
|
315
362
|
case 0:
|
|
316
|
-
coinAddresses = exports._getCoinAddresses(coins);
|
|
317
|
-
decimals = exports._getCoinDecimals(coinAddresses);
|
|
363
|
+
coinAddresses = (0, exports._getCoinAddresses)(coins);
|
|
364
|
+
decimals = (0, exports._getCoinDecimals)(coinAddresses);
|
|
318
365
|
_amounts = amounts.map(function (a, i) { return ethers_1.ethers.utils.parseUnits(a, decimals[i]); });
|
|
319
|
-
return [4 /*yield*/, exports._ensureAllowance(coinAddresses, _amounts, spender)];
|
|
366
|
+
return [4 /*yield*/, (0, exports._ensureAllowance)(coinAddresses, _amounts, spender)];
|
|
320
367
|
case 1: return [2 /*return*/, _a.sent()];
|
|
321
368
|
}
|
|
322
369
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/api",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "JavaScript library for curve.fi",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"axios": "^0.21.1",
|
|
25
25
|
"bignumber.js": "^9.0.1",
|
|
26
|
-
"ethers": "^5.
|
|
26
|
+
"ethers": "^5.4.6",
|
|
27
27
|
"ethers-multicall": "^0.1.6"
|
|
28
28
|
}
|
|
29
29
|
}
|