@curvefi/api 2.52.4 → 2.53.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.
- package/README.md +485 -2
- package/lib/constants/abis/circulating_supply.json +114 -0
- package/lib/constants/abis/voting_proposal.json +1086 -0
- package/lib/constants/aliases.js +3 -0
- package/lib/curve.js +8 -1
- package/lib/dao.d.ts +44 -0
- package/lib/dao.js +675 -0
- package/lib/external-api.d.ts +4 -10
- package/lib/external-api.js +33 -0
- package/lib/index.d.ts +53 -0
- package/lib/index.js +57 -0
- package/lib/interfaces.d.ts +66 -0
- package/lib/pools/PoolTemplate.d.ts +5 -1
- package/lib/pools/PoolTemplate.js +159 -59
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +26 -10
- package/package.json +1 -1
package/lib/utils.js
CHANGED
|
@@ -234,6 +234,12 @@ export var _prepareAddresses = function (addresses) {
|
|
|
234
234
|
addresses = addresses;
|
|
235
235
|
return addresses.filter(function (val, idx, arr) { return arr.indexOf(val) === idx; });
|
|
236
236
|
};
|
|
237
|
+
export var _getAddress = function (address) {
|
|
238
|
+
address = address || curve.signerAddress;
|
|
239
|
+
if (!address)
|
|
240
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
241
|
+
return address;
|
|
242
|
+
};
|
|
237
243
|
export var getBalances = function (coins) {
|
|
238
244
|
var addresses = [];
|
|
239
245
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
@@ -369,7 +375,7 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
369
375
|
export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
|
|
370
376
|
if (isMax === void 0) { isMax = true; }
|
|
371
377
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
372
|
-
var coinAddresses, decimals, _amounts, address,
|
|
378
|
+
var coinAddresses, decimals, _amounts, address, _allowance, gas, i, contract, _approveAmount, currentGas, _a, currentGas, _b;
|
|
373
379
|
return __generator(this, function (_c) {
|
|
374
380
|
switch (_c.label) {
|
|
375
381
|
case 0:
|
|
@@ -379,22 +385,29 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
|
|
|
379
385
|
address = curve.signerAddress;
|
|
380
386
|
return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
|
|
381
387
|
case 1:
|
|
382
|
-
|
|
388
|
+
_allowance = _c.sent();
|
|
383
389
|
gas = [0, 0];
|
|
384
390
|
i = 0;
|
|
385
391
|
_c.label = 2;
|
|
386
392
|
case 2:
|
|
387
|
-
if (!(i <
|
|
388
|
-
if (!(
|
|
393
|
+
if (!(i < _allowance.length)) return [3 /*break*/, 7];
|
|
394
|
+
if (!(_allowance[i] < _amounts[i])) return [3 /*break*/, 6];
|
|
389
395
|
contract = curve.contracts[coinAddresses[i]].contract;
|
|
390
396
|
_approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
391
|
-
if (!(
|
|
397
|
+
if (!(_allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
|
|
392
398
|
_a = smartNumber;
|
|
393
399
|
return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
|
|
394
400
|
case 3:
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
401
|
+
currentGas = _a.apply(void 0, [_c.sent()]);
|
|
402
|
+
// For some coins (crv for example ) we can't estimate the second tx gas (approve: 0 --> amount), so we assume it will cost the same amount of gas
|
|
403
|
+
if (typeof currentGas === "number") {
|
|
404
|
+
currentGas = currentGas * 2;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
currentGas = currentGas.map(function (g) { return g * 2; });
|
|
408
|
+
}
|
|
409
|
+
gas = gasSum(gas, currentGas);
|
|
410
|
+
return [3 /*break*/, 6];
|
|
398
411
|
case 4:
|
|
399
412
|
_b = smartNumber;
|
|
400
413
|
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
|
|
@@ -429,10 +442,13 @@ export var ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
429
442
|
};
|
|
430
443
|
export var getPoolIdBySwapAddress = function (swapAddress) {
|
|
431
444
|
var poolsData = curve.getPoolsData();
|
|
432
|
-
|
|
445
|
+
var poolIds = Object.entries(poolsData).filter(function (_a) {
|
|
433
446
|
var _ = _a[0], poolData = _a[1];
|
|
434
447
|
return poolData.swap_address.toLowerCase() === swapAddress.toLowerCase();
|
|
435
|
-
})
|
|
448
|
+
});
|
|
449
|
+
if (poolIds.length === 0)
|
|
450
|
+
return "";
|
|
451
|
+
return poolIds[0][0];
|
|
436
452
|
};
|
|
437
453
|
var _getTokenAddressBySwapAddress = function (swapAddress) {
|
|
438
454
|
var poolsData = curve.getPoolsData();
|