@curvefi/api 2.49.1 → 2.49.3
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 +5 -0
- package/lib/boosting.d.ts +1 -1
- package/lib/boosting.js +1 -1
- package/lib/constants/L2Networks.js +1 -1
- package/lib/constants/aliases.js +1 -0
- package/lib/curve.js +31 -2
- package/lib/index.d.ts +3 -3
- package/lib/pools/PoolTemplate.d.ts +13 -13
- package/lib/pools/PoolTemplate.js +16 -4
- package/lib/router.d.ts +1 -1
- package/lib/router.js +1 -1
- package/lib/utils.d.ts +3 -1
- package/lib/utils.js +34 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1472,6 +1472,11 @@ import curve from "@curvefi/api";
|
|
|
1472
1472
|
```
|
|
1473
1473
|
|
|
1474
1474
|
## Gas estimation L2
|
|
1475
|
+
|
|
1476
|
+
**Only for OPTIMISM and BASE!**
|
|
1477
|
+
|
|
1478
|
+
Arbitrium is also L2 network, but for estimateGas should use default method `estimateGas`, which return `Number`.
|
|
1479
|
+
|
|
1475
1480
|
For L2 networks `estimateGas` return array `[L2GasUsed, L1GasUsed]`, where `L2GasUsed` - gas estimate for execution transaction in current L2 network, and `L1GasUsed` - gas estimate for data storage in parent L1 network.
|
|
1476
1481
|
|
|
1477
1482
|
Gas Price in L1 is required to calculate the fee.
|
package/lib/boosting.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const getLockedAmountAndUnlockTime: (...addresses: string[] | str
|
|
|
10
10
|
export declare const getVeCrv: (...addresses: string[] | string[][]) => Promise<IDict<string> | string>;
|
|
11
11
|
export declare const getVeCrvPct: (...addresses: string[] | string[][]) => Promise<IDict<string> | string>;
|
|
12
12
|
export declare const isApproved: (amount: number | string) => Promise<boolean>;
|
|
13
|
-
export declare const approveEstimateGas: (amount: number | string) => Promise<number>;
|
|
13
|
+
export declare const approveEstimateGas: (amount: number | string) => Promise<number | number[]>;
|
|
14
14
|
export declare const approve: (amount: number | string) => Promise<string[]>;
|
|
15
15
|
export declare const createLockEstimateGas: (amount: number | string, days: number) => Promise<number>;
|
|
16
16
|
export declare const calcUnlockTime: (days: number, start?: number) => number;
|
package/lib/boosting.js
CHANGED
|
@@ -48,7 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
48
48
|
import { Contract } from "ethers";
|
|
49
49
|
import { curve } from "./curve.js";
|
|
50
50
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" assert { type: 'json' };
|
|
51
|
-
import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber } from "./utils.js";
|
|
51
|
+
import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber, } from "./utils.js";
|
|
52
52
|
import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
|
|
53
53
|
import { _generateBoostingProof } from './external-api.js';
|
|
54
54
|
export var getCrv = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export var L2Networks = [10]; //
|
|
1
|
+
export var L2Networks = [10, 8453]; // 42161 (arbitrum) is L2 network, but does not need a change to estimateGas.
|
package/lib/constants/aliases.js
CHANGED
|
@@ -234,6 +234,7 @@ export var ALIASES_BASE = lowerCaseValues({
|
|
|
234
234
|
"crypto_factory": '0x5EF72230578b3e399E6C6F4F6360edF95e83BBfd',
|
|
235
235
|
"tricrypto_factory": '0xA5961898870943c68037F6848d2D866Ed2016bcB',
|
|
236
236
|
"factory_admin": "0x0000000000000000000000000000000000000000",
|
|
237
|
+
"gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f', // <-- NEW
|
|
237
238
|
});
|
|
238
239
|
var registry_exchange_deprecated = {
|
|
239
240
|
'1': '0x99a58482bd75cbab83b27ec03ca68ff489b5788f',
|
package/lib/curve.js
CHANGED
|
@@ -102,7 +102,7 @@ import { COINS_ZKSYNC, cTokensZkSync, yTokensZkSync, ycTokensZkSync, aTokensZkSy
|
|
|
102
102
|
import { COINS_BASE, cTokensBase, yTokensBase, ycTokensBase, aTokensBase } from "./constants/coins/base.js";
|
|
103
103
|
import { lowerCasePoolDataAddresses, extractDecimals, extractGauges } from "./constants/utils.js";
|
|
104
104
|
import { _getAllGauges, _getHiddenPools } from "./external-api.js";
|
|
105
|
-
import { L2Networks } from "./constants/L2Networks";
|
|
105
|
+
import { L2Networks } from "./constants/L2Networks.js";
|
|
106
106
|
var _killGauges = function (poolsData) { return __awaiter(void 0, void 0, void 0, function () {
|
|
107
107
|
var gaugeData, isKilled, gaugeStatuses, poolId;
|
|
108
108
|
return __generator(this, function (_a) {
|
|
@@ -708,7 +708,7 @@ var Curve = /** @class */ (function () {
|
|
|
708
708
|
var _a;
|
|
709
709
|
if (options === void 0) { options = {}; }
|
|
710
710
|
return __awaiter(this, void 0, void 0, function () {
|
|
711
|
-
var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _gaugeFactoryABI, factoryContract, _o, curveInstance_1, originalEstimate_1, newEstimate;
|
|
711
|
+
var jsonRpcApiProviderOptions, _b, e_1, _c, network, poolId, _d, cTokens, yTokens, ycTokens, aTokens, customAbiTokens, _e, err_1, _i, _f, pool, _g, _h, coinAddr, _j, _k, coinAddr, _l, _m, coinAddr, _gaugeFactoryABI, factoryContract, _o, curveInstance_1, originalEstimate_1, oldEstimate, newEstimate;
|
|
712
712
|
return __generator(this, function (_p) {
|
|
713
713
|
switch (_p.label) {
|
|
714
714
|
case 0:
|
|
@@ -939,7 +939,27 @@ var Curve = /** @class */ (function () {
|
|
|
939
939
|
if (L2Networks.includes(this.chainId)) {
|
|
940
940
|
curveInstance_1 = this;
|
|
941
941
|
curveInstance_1.setContract(curveInstance_1.constants.ALIASES.gas_oracle, gasOracleABI);
|
|
942
|
+
// @ts-ignore
|
|
943
|
+
if (JsonRpcSigner.prototype.originalEstimate) {
|
|
944
|
+
// @ts-ignore
|
|
945
|
+
JsonRpcSigner.prototype.estimateGas = JsonRpcSigner.prototype.originalEstimate;
|
|
946
|
+
}
|
|
942
947
|
originalEstimate_1 = JsonRpcSigner.prototype.estimateGas;
|
|
948
|
+
oldEstimate = function (arg) {
|
|
949
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
950
|
+
var originalEstimateFunc, gas;
|
|
951
|
+
return __generator(this, function (_a) {
|
|
952
|
+
switch (_a.label) {
|
|
953
|
+
case 0:
|
|
954
|
+
originalEstimateFunc = originalEstimate_1.bind(this);
|
|
955
|
+
return [4 /*yield*/, originalEstimateFunc(arg)];
|
|
956
|
+
case 1:
|
|
957
|
+
gas = _a.sent();
|
|
958
|
+
return [2 /*return*/, gas];
|
|
959
|
+
}
|
|
960
|
+
});
|
|
961
|
+
});
|
|
962
|
+
};
|
|
943
963
|
newEstimate = function (arg) {
|
|
944
964
|
return __awaiter(this, void 0, void 0, function () {
|
|
945
965
|
var L2EstimateGas, L1GasUsed, L2GasUsed;
|
|
@@ -960,6 +980,15 @@ var Curve = /** @class */ (function () {
|
|
|
960
980
|
};
|
|
961
981
|
// @ts-ignore
|
|
962
982
|
JsonRpcSigner.prototype.estimateGas = newEstimate;
|
|
983
|
+
// @ts-ignore
|
|
984
|
+
JsonRpcSigner.prototype.originalEstimate = oldEstimate;
|
|
985
|
+
}
|
|
986
|
+
else {
|
|
987
|
+
// @ts-ignore
|
|
988
|
+
if (JsonRpcSigner.prototype.originalEstimate) {
|
|
989
|
+
// @ts-ignore
|
|
990
|
+
JsonRpcSigner.prototype.estimateGas = JsonRpcSigner.prototype.originalEstimate;
|
|
991
|
+
}
|
|
963
992
|
}
|
|
964
993
|
return [2 /*return*/];
|
|
965
994
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -135,7 +135,7 @@ declare const curve: {
|
|
|
135
135
|
};
|
|
136
136
|
};
|
|
137
137
|
estimateGas: {
|
|
138
|
-
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
138
|
+
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean) => Promise<number | number[]>;
|
|
139
139
|
};
|
|
140
140
|
boosting: {
|
|
141
141
|
getCrv: (...addresses: string[] | string[][]) => Promise<string | import("./interfaces.js").IDict<string>>;
|
|
@@ -158,7 +158,7 @@ declare const curve: {
|
|
|
158
158
|
claimableFees: (address?: string) => Promise<string>;
|
|
159
159
|
claimFees: (address?: string) => Promise<string>;
|
|
160
160
|
estimateGas: {
|
|
161
|
-
approve: (amount: string | number) => Promise<number>;
|
|
161
|
+
approve: (amount: string | number) => Promise<number | number[]>;
|
|
162
162
|
createLock: (amount: string | number, days: number) => Promise<number>;
|
|
163
163
|
increaseAmount: (amount: string | number) => Promise<number>;
|
|
164
164
|
increaseUnlockTime: (days: number) => Promise<number>;
|
|
@@ -202,7 +202,7 @@ declare const curve: {
|
|
|
202
202
|
swap: (inputCoin: string, outputCoin: string, amount: string | number, slippage?: number) => Promise<ethers.ContractTransactionResponse>;
|
|
203
203
|
getSwappedAmount: (tx: ethers.ContractTransactionResponse, outputCoin: string) => Promise<string>;
|
|
204
204
|
estimateGas: {
|
|
205
|
-
approve: (inputCoin: string, amount: string | number) => Promise<number>;
|
|
205
|
+
approve: (inputCoin: string, amount: string | number) => Promise<number | number[]>;
|
|
206
206
|
swap: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
|
|
207
207
|
};
|
|
208
208
|
};
|
|
@@ -34,32 +34,32 @@ export declare class PoolTemplate {
|
|
|
34
34
|
isGaugeKilled: boolean;
|
|
35
35
|
gaugeStatus: Record<string, boolean> | null;
|
|
36
36
|
estimateGas: {
|
|
37
|
-
depositApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
38
|
-
deposit: (amounts: (number | string)[]) => Promise<number>;
|
|
39
|
-
depositWrappedApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
40
|
-
depositWrapped: (amounts: (number | string)[]) => Promise<number>;
|
|
41
|
-
stakeApprove: (lpTokenAmount: number | string) => Promise<number>;
|
|
37
|
+
depositApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
38
|
+
deposit: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
39
|
+
depositWrappedApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
40
|
+
depositWrapped: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
41
|
+
stakeApprove: (lpTokenAmount: number | string) => Promise<number | number[]>;
|
|
42
42
|
stake: (lpTokenAmount: number | string) => Promise<number>;
|
|
43
43
|
unstake: (lpTokenAmount: number | string) => Promise<number>;
|
|
44
44
|
claimCrv: () => Promise<number>;
|
|
45
45
|
claimRewards: () => Promise<number>;
|
|
46
|
-
depositAndStakeApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
46
|
+
depositAndStakeApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
47
47
|
depositAndStake: (amounts: (number | string)[]) => Promise<number>;
|
|
48
|
-
depositAndStakeWrappedApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
48
|
+
depositAndStakeWrappedApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
49
49
|
depositAndStakeWrapped: (amounts: (number | string)[]) => Promise<number>;
|
|
50
|
-
withdrawApprove: (lpTokenAmount: number | string) => Promise<number>;
|
|
50
|
+
withdrawApprove: (lpTokenAmount: number | string) => Promise<number | number[]>;
|
|
51
51
|
withdraw: (lpTokenAmount: number | string) => Promise<number>;
|
|
52
52
|
withdrawWrapped: (lpTokenAmount: number | string) => Promise<number>;
|
|
53
|
-
withdrawImbalanceApprove: (amounts: (number | string)[]) => Promise<number>;
|
|
53
|
+
withdrawImbalanceApprove: (amounts: (number | string)[]) => Promise<number | number[]>;
|
|
54
54
|
withdrawImbalance: (amounts: (number | string)[]) => Promise<number>;
|
|
55
55
|
withdrawImbalanceWrapped: (amounts: (number | string)[]) => Promise<number>;
|
|
56
|
-
withdrawOneCoinApprove: (lpTokenAmount: number | string) => Promise<number>;
|
|
56
|
+
withdrawOneCoinApprove: (lpTokenAmount: number | string) => Promise<number | number[]>;
|
|
57
57
|
withdrawOneCoin: (lpTokenAmount: number | string, coin: string | number) => Promise<number>;
|
|
58
58
|
withdrawOneCoinWrapped: (lpTokenAmount: number | string, coin: string | number) => Promise<number>;
|
|
59
|
-
swapApprove: (inputCoin: string | number, amount: number | string) => Promise<number>;
|
|
59
|
+
swapApprove: (inputCoin: string | number, amount: number | string) => Promise<number | number[]>;
|
|
60
60
|
swap: (inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage: number) => Promise<number>;
|
|
61
|
-
swapWrappedApprove: (inputCoin: string | number, amount: number | string) => Promise<number>;
|
|
62
|
-
swapWrapped: (inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage: number) => Promise<number>;
|
|
61
|
+
swapWrappedApprove: (inputCoin: string | number, amount: number | string) => Promise<number | number[]>;
|
|
62
|
+
swapWrapped: (inputCoin: string | number, outputCoin: string | number, amount: number | string, slippage: number) => Promise<number | number[]>;
|
|
63
63
|
};
|
|
64
64
|
stats: {
|
|
65
65
|
parameters: () => Promise<{
|
|
@@ -56,7 +56,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
56
|
};
|
|
57
57
|
import memoize from "memoizee";
|
|
58
58
|
import { _getPoolsFromApi, _getSubgraphData, _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes } from '../external-api.js';
|
|
59
|
-
import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, } from '../utils.js';
|
|
59
|
+
import { _getCoinAddresses, _getBalances, _prepareAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getCrvApyFromApi, _getRewardsFromApi, mulBy1_3, smartNumber, } from '../utils.js';
|
|
60
60
|
import { curve as _curve, curve } from "../curve.js";
|
|
61
61
|
import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
|
|
62
62
|
var DAY = 86400;
|
|
@@ -1945,11 +1945,17 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
1945
1945
|
case 2:
|
|
1946
1946
|
gaugeAllowance = _d.sent();
|
|
1947
1947
|
if (!!gaugeAllowance) return [3 /*break*/, 4];
|
|
1948
|
-
_c =
|
|
1948
|
+
_c = smartNumber;
|
|
1949
1949
|
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
1950
1950
|
case 3:
|
|
1951
1951
|
approveGaugeGas = _c.apply(void 0, [_d.sent()]);
|
|
1952
|
-
|
|
1952
|
+
if (Array.isArray(approveCoinsGas) && Array.isArray(approveGaugeGas)) {
|
|
1953
|
+
return [2 /*return*/, [approveCoinsGas[0] + approveGaugeGas[0], approveCoinsGas[1] + approveGaugeGas[1]]];
|
|
1954
|
+
}
|
|
1955
|
+
if (!Array.isArray(approveCoinsGas) && !Array.isArray(approveGaugeGas)) {
|
|
1956
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
1957
|
+
}
|
|
1958
|
+
_d.label = 4;
|
|
1953
1959
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
1954
1960
|
}
|
|
1955
1961
|
});
|
|
@@ -2097,7 +2103,13 @@ var PoolTemplate = /** @class */ (function () {
|
|
|
2097
2103
|
return [4 /*yield*/, gaugeContract.set_approve_deposit.estimateGas(curve.constants.ALIASES.deposit_and_stake, true, curve.constantOptions)];
|
|
2098
2104
|
case 3:
|
|
2099
2105
|
approveGaugeGas = _c.apply(void 0, [_d.sent()]);
|
|
2100
|
-
|
|
2106
|
+
if (Array.isArray(approveCoinsGas) && Array.isArray(approveGaugeGas)) {
|
|
2107
|
+
return [2 /*return*/, [approveCoinsGas[0] + approveGaugeGas[0], approveCoinsGas[1] + approveGaugeGas[1]]];
|
|
2108
|
+
}
|
|
2109
|
+
if (!Array.isArray(approveCoinsGas) && !Array.isArray(approveGaugeGas)) {
|
|
2110
|
+
return [2 /*return*/, approveCoinsGas + approveGaugeGas];
|
|
2111
|
+
}
|
|
2112
|
+
_d.label = 4;
|
|
2101
2113
|
case 4: return [2 /*return*/, approveCoinsGas];
|
|
2102
2114
|
}
|
|
2103
2115
|
});
|
package/lib/router.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export declare const swapExpected: (inputCoin: string, outputCoin: string, amoun
|
|
|
17
17
|
export declare const swapRequired: (inputCoin: string, outputCoin: string, outAmount: number | string) => Promise<string>;
|
|
18
18
|
export declare const swapPriceImpact: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
|
|
19
19
|
export declare const swapIsApproved: (inputCoin: string, amount: number | string) => Promise<boolean>;
|
|
20
|
-
export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number>;
|
|
20
|
+
export declare const swapApproveEstimateGas: (inputCoin: string, amount: number | string) => Promise<number | number[]>;
|
|
21
21
|
export declare const swapApprove: (inputCoin: string, amount: number | string) => Promise<string[]>;
|
|
22
22
|
export declare const swapEstimateGas: (inputCoin: string, outputCoin: string, amount: number | string) => Promise<number>;
|
|
23
23
|
export declare const swap: (inputCoin: string, outputCoin: string, amount: number | string, slippage?: number) => Promise<ethers.ContractTransactionResponse>;
|
package/lib/router.js
CHANGED
|
@@ -707,7 +707,7 @@ export var getBestRouteAndOutput = function (inputCoin, outputCoin, amount) { re
|
|
|
707
707
|
return [4 /*yield*/, _getOutputForRoute(route, parseUnits(amount, inputCoinDecimals))];
|
|
708
708
|
case 2:
|
|
709
709
|
_output = _c.sent();
|
|
710
|
-
return [2 /*return*/, { route: route, output: curve.formatUnits(_output, outputCoinDecimals) }];
|
|
710
|
+
return [2 /*return*/, { route: route, output: curve.formatUnits(_output + BigInt(1), outputCoinDecimals) }];
|
|
711
711
|
}
|
|
712
712
|
});
|
|
713
713
|
}); };
|
package/lib/utils.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare const getEthIndex: (addresses: string[]) => number;
|
|
|
15
15
|
export declare const mulBy1_3: (n: bigint) => bigint;
|
|
16
16
|
export declare const smartNumber: (abstractNumber: bigint | bigint[]) => number | number[];
|
|
17
17
|
export declare const DIGas: (gas: bigint | Array<bigint>) => bigint;
|
|
18
|
+
export declare const getGasFromArray: (gas: number[]) => number | number[];
|
|
19
|
+
export declare const gasSum: (gas: number[], currentGas: number | number[]) => number[];
|
|
18
20
|
export declare const _getCoinAddressesNoCheck: (...coins: string[] | string[][]) => string[];
|
|
19
21
|
export declare const _getCoinAddresses: (...coins: string[] | string[][]) => string[];
|
|
20
22
|
export declare const _getCoinDecimals: (...coinAddresses: string[] | string[][]) => number[];
|
|
@@ -25,7 +27,7 @@ export declare const _getAllowance: (coins: string[], address: string, spender:
|
|
|
25
27
|
export declare const getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
26
28
|
export declare const hasAllowance: (coins: string[], amounts: (number | string)[], address: string, spender: string) => Promise<boolean>;
|
|
27
29
|
export declare const _ensureAllowance: (coins: string[], amounts: bigint[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
28
|
-
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number>;
|
|
30
|
+
export declare const ensureAllowanceEstimateGas: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<number | number[]>;
|
|
29
31
|
export declare const ensureAllowance: (coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean) => Promise<string[]>;
|
|
30
32
|
export declare const getPoolIdBySwapAddress: (swapAddress: string) => string;
|
|
31
33
|
export declare const _getUsdPricesFromApi: () => Promise<IDict<number>>;
|
package/lib/utils.js
CHANGED
|
@@ -61,7 +61,7 @@ import BigNumber from 'bignumber.js';
|
|
|
61
61
|
import { curve, NETWORK_CONSTANTS } from "./curve.js";
|
|
62
62
|
import { _getFactoryAPYsAndVolumes, _getLegacyAPYsAndVolumes, _getAllPoolsFromApi, _getSubgraphData } from "./external-api.js";
|
|
63
63
|
import ERC20Abi from './constants/abis/ERC20.json' assert { type: 'json' };
|
|
64
|
-
import { L2Networks } from './constants/L2Networks';
|
|
64
|
+
import { L2Networks } from './constants/L2Networks.js';
|
|
65
65
|
export var ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
66
66
|
// export const MAX_ALLOWANCE = curve.parseUnits(new BigNumber(2).pow(256).minus(1).toFixed(), 0);
|
|
67
67
|
export var MAX_ALLOWANCE = BigInt("115792089237316195423570985008687907853269984665640564039457584007913129639935"); // 2**256 - 1
|
|
@@ -119,6 +119,24 @@ export var DIGas = function (gas) {
|
|
|
119
119
|
return gas;
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
|
+
export var getGasFromArray = function (gas) {
|
|
123
|
+
if (gas.length === 1) {
|
|
124
|
+
return gas[0];
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
return gas;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export var gasSum = function (gas, currentGas) {
|
|
131
|
+
if (Array.isArray(currentGas)) {
|
|
132
|
+
gas[0] = gas[0] + currentGas[0];
|
|
133
|
+
gas[1] = gas[1] + currentGas[1];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
gas[0] = gas[0] + currentGas;
|
|
137
|
+
}
|
|
138
|
+
return gas;
|
|
139
|
+
};
|
|
122
140
|
// coins can be either addresses or symbols
|
|
123
141
|
export var _getCoinAddressesNoCheck = function () {
|
|
124
142
|
var coins = [];
|
|
@@ -351,9 +369,9 @@ export var _ensureAllowance = function (coins, amounts, spender, isMax) {
|
|
|
351
369
|
export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax) {
|
|
352
370
|
if (isMax === void 0) { isMax = true; }
|
|
353
371
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
354
|
-
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount,
|
|
355
|
-
return __generator(this, function (
|
|
356
|
-
switch (
|
|
372
|
+
var coinAddresses, decimals, _amounts, address, allowance, gas, i, contract, _approveAmount, currentGas_1, _a, currentGas, _b;
|
|
373
|
+
return __generator(this, function (_c) {
|
|
374
|
+
switch (_c.label) {
|
|
357
375
|
case 0:
|
|
358
376
|
coinAddresses = _getCoinAddresses(coins);
|
|
359
377
|
decimals = _getCoinDecimals(coinAddresses);
|
|
@@ -361,35 +379,33 @@ export var ensureAllowanceEstimateGas = function (coins, amounts, spender, isMax
|
|
|
361
379
|
address = curve.signerAddress;
|
|
362
380
|
return [4 /*yield*/, _getAllowance(coinAddresses, address, spender)];
|
|
363
381
|
case 1:
|
|
364
|
-
allowance =
|
|
365
|
-
gas = 0;
|
|
382
|
+
allowance = _c.sent();
|
|
383
|
+
gas = [0, 0];
|
|
366
384
|
i = 0;
|
|
367
|
-
|
|
385
|
+
_c.label = 2;
|
|
368
386
|
case 2:
|
|
369
387
|
if (!(i < allowance.length)) return [3 /*break*/, 7];
|
|
370
388
|
if (!(allowance[i] < _amounts[i])) return [3 /*break*/, 6];
|
|
371
389
|
contract = curve.contracts[coinAddresses[i]].contract;
|
|
372
390
|
_approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
373
391
|
if (!(allowance[i] > curve.parseUnits("0"))) return [3 /*break*/, 4];
|
|
374
|
-
_a =
|
|
375
|
-
_b = Number;
|
|
376
|
-
_c = DIGas;
|
|
392
|
+
_a = smartNumber;
|
|
377
393
|
return [4 /*yield*/, contract.approve.estimateGas(spender, curve.parseUnits("0"), curve.constantOptions)];
|
|
378
394
|
case 3:
|
|
379
|
-
|
|
380
|
-
|
|
395
|
+
currentGas_1 = _a.apply(void 0, [_c.sent()]);
|
|
396
|
+
gas = gasSum(gas, currentGas_1);
|
|
397
|
+
_c.label = 4;
|
|
381
398
|
case 4:
|
|
382
|
-
|
|
383
|
-
_e = Number;
|
|
384
|
-
_f = DIGas;
|
|
399
|
+
_b = smartNumber;
|
|
385
400
|
return [4 /*yield*/, contract.approve.estimateGas(spender, _approveAmount, curve.constantOptions)];
|
|
386
401
|
case 5:
|
|
387
|
-
|
|
388
|
-
|
|
402
|
+
currentGas = _b.apply(void 0, [_c.sent()]);
|
|
403
|
+
gas = gasSum(gas, currentGas);
|
|
404
|
+
_c.label = 6;
|
|
389
405
|
case 6:
|
|
390
406
|
i++;
|
|
391
407
|
return [3 /*break*/, 2];
|
|
392
|
-
case 7: return [2 /*return*/, gas];
|
|
408
|
+
case 7: return [2 /*return*/, getGasFromArray(gas)];
|
|
393
409
|
}
|
|
394
410
|
});
|
|
395
411
|
});
|