@curvefi/api 2.68.22 → 2.68.23
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.d.ts +3 -0
- package/lib/curve.js +9 -0
- package/lib/external-api.js +5 -2
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +2 -2
- package/lib/pools/mixins/depositMixins.js +6 -6
- package/lib/pools/mixins/depositWrappedMixins.js +3 -3
- package/lib/pools/mixins/swapMixins.js +5 -5
- package/lib/pools/mixins/swapWrappedMixins.js +3 -3
- package/lib/route-graph.worker.js +3 -2
- package/lib/router.js +4 -4
- package/lib/utils.d.ts +0 -2
- package/lib/utils.js +16 -7
- package/package.json +1 -1
package/lib/curve.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare class Curve implements ICurve {
|
|
|
35
35
|
};
|
|
36
36
|
L1WeightedGasPrice?: number;
|
|
37
37
|
constants: INetworkConstants;
|
|
38
|
+
nativeTokenAddress: string;
|
|
38
39
|
constructor();
|
|
39
40
|
init(providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy' | 'NoRPC', providerSettings: {
|
|
40
41
|
url?: string;
|
|
@@ -95,5 +96,7 @@ export declare class Curve implements ICurve {
|
|
|
95
96
|
updateFeeData(): Promise<void>;
|
|
96
97
|
getNetworkConstants: () => INetworkConstants;
|
|
97
98
|
getIsLiteChain: () => boolean;
|
|
99
|
+
isEth: (address: string) => boolean;
|
|
100
|
+
getEthIndex: (addresses: string[]) => number;
|
|
98
101
|
}
|
|
99
102
|
export declare const curve: Curve;
|
package/lib/curve.js
CHANGED
|
@@ -323,6 +323,12 @@ export class Curve {
|
|
|
323
323
|
this.getIsLiteChain = () => {
|
|
324
324
|
return this.isLiteChain;
|
|
325
325
|
};
|
|
326
|
+
this.isEth = (address) => {
|
|
327
|
+
return address.toLowerCase() === this.nativeTokenAddress.toLowerCase();
|
|
328
|
+
};
|
|
329
|
+
this.getEthIndex = (addresses) => {
|
|
330
|
+
return addresses.map((address) => address.toLowerCase()).indexOf(this.nativeTokenAddress.toLowerCase());
|
|
331
|
+
};
|
|
326
332
|
this.provider = null;
|
|
327
333
|
this.signer = null;
|
|
328
334
|
this.isNoRPC = false;
|
|
@@ -334,6 +340,7 @@ export class Curve {
|
|
|
334
340
|
this.feeData = {};
|
|
335
341
|
this.constantOptions = { gasLimit: 12000000 };
|
|
336
342
|
this.options = {};
|
|
343
|
+
this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
|
|
337
344
|
this.constants = {
|
|
338
345
|
NATIVE_TOKEN: NETWORK_CONSTANTS[1].NATIVE_COIN,
|
|
339
346
|
NETWORK_NAME: 'ethereum',
|
|
@@ -371,6 +378,7 @@ export class Curve {
|
|
|
371
378
|
this.feeData = {};
|
|
372
379
|
this.constantOptions = { gasLimit: 12000000 };
|
|
373
380
|
this.options = {};
|
|
381
|
+
this.nativeTokenAddress = NETWORK_CONSTANTS[1].NATIVE_COIN.address;
|
|
374
382
|
this.constants = {
|
|
375
383
|
NATIVE_TOKEN: NETWORK_CONSTANTS[1].NATIVE_COIN,
|
|
376
384
|
NETWORK_NAME: 'ethereum',
|
|
@@ -456,6 +464,7 @@ export class Curve {
|
|
|
456
464
|
this.isLiteChain = !(this.chainId in NETWORK_CONSTANTS);
|
|
457
465
|
const network_constants = yield getNetworkConstants.call(this, this.chainId);
|
|
458
466
|
this.constants.NATIVE_TOKEN = network_constants.NATIVE_COIN;
|
|
467
|
+
this.nativeTokenAddress = network_constants.NATIVE_COIN.address;
|
|
459
468
|
this.constants.NETWORK_NAME = network_constants.NAME;
|
|
460
469
|
this.constants.ALIASES = network_constants.ALIASES;
|
|
461
470
|
this.constants.ALIASES.anycall = "0x37414a8662bc1d25be3ee51fb27c2686e2490a89";
|
package/lib/external-api.js
CHANGED
|
@@ -213,7 +213,7 @@ export const _getDaoProposal = memoize((type, id) => fetchJson(`https://api-py.l
|
|
|
213
213
|
});
|
|
214
214
|
// --- CURVE LITE ---
|
|
215
215
|
export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
|
-
var _a, _b;
|
|
216
|
+
var _a, _b, _c, _d;
|
|
217
217
|
try {
|
|
218
218
|
const url = `https://api-core.curve.finance/v1/getDeployment/${networkName}`;
|
|
219
219
|
const response = yield fetch(url);
|
|
@@ -226,6 +226,8 @@ export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, v
|
|
|
226
226
|
const network_name = config.network_name || 'Unknown Network';
|
|
227
227
|
const native_currency_symbol = config.native_currency_symbol || 'N/A';
|
|
228
228
|
const wrapped_native_token = ((_b = config.wrapped_native_token) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || '';
|
|
229
|
+
const native_token = ((_c = config.native_token) === null || _c === void 0 ? void 0 : _c.toLowerCase()) || '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
|
|
230
|
+
const wrapper = ((_d = config.wrapper) === null || _d === void 0 ? void 0 : _d.toLowerCase()) || wrapped_native_token;
|
|
229
231
|
return {
|
|
230
232
|
NAME: network_name,
|
|
231
233
|
ALIASES: {
|
|
@@ -241,11 +243,12 @@ export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, v
|
|
|
241
243
|
},
|
|
242
244
|
NATIVE_COIN: {
|
|
243
245
|
symbol: native_currency_symbol,
|
|
244
|
-
address:
|
|
246
|
+
address: native_token,
|
|
245
247
|
wrappedSymbol: native_currency_symbol[0].toLowerCase() === native_currency_symbol[0]
|
|
246
248
|
? `w${native_currency_symbol}`
|
|
247
249
|
: `W${native_currency_symbol}`,
|
|
248
250
|
wrappedAddress: wrapped_native_token,
|
|
251
|
+
wrapperAddress: wrapper,
|
|
249
252
|
},
|
|
250
253
|
API_CONSTANTS: {
|
|
251
254
|
nativeTokenName: config.native_currency_coingecko_id,
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import { _getAllGaugesFormatted } from '../external-api.js';
|
|
12
|
-
import { _cutZeros, _ensureAllowance, _get_price_impact, _get_small_x, _getAddress, _getCoinAddresses, _getRewardsFromApi, _getUsdRate, _setContracts, BN, checkNumber, DIGas, ensureAllowance, ensureAllowanceEstimateGas, findAbiFunction, fromBN,
|
|
12
|
+
import { _cutZeros, _ensureAllowance, _get_price_impact, _get_small_x, _getAddress, _getCoinAddresses, _getRewardsFromApi, _getUsdRate, _setContracts, BN, checkNumber, DIGas, ensureAllowance, ensureAllowanceEstimateGas, findAbiFunction, fromBN, hasAllowance, mulBy1_3, parseUnits, PERIODS, smartNumber, toBN, toStringFromBN, } from '../utils.js';
|
|
13
13
|
import { OLD_CHAINS } from "../curve.js";
|
|
14
14
|
import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
|
|
15
15
|
import { CorePool } from "./subClasses/corePool.js";
|
|
@@ -1247,7 +1247,7 @@ export class PoolTemplate extends CorePool {
|
|
|
1247
1247
|
this.curve.parseUnits(yield this.depositAndStakeWrappedExpected(amounts));
|
|
1248
1248
|
const minAmountBN = toBN(_expectedLpTokenAmount).times(100 - slippage).div(100);
|
|
1249
1249
|
const _minMintAmount = fromBN(minAmountBN);
|
|
1250
|
-
const ethIndex = getEthIndex(coinAddresses);
|
|
1250
|
+
const ethIndex = this.curve.getEthIndex(coinAddresses);
|
|
1251
1251
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
1252
1252
|
const _gas = OLD_CHAINS.includes(this.curve.chainId) ? (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
|
|
1253
1253
|
useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.constantOptions), { value }))) : (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : this.curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, this.curve.constantOptions), { value })));
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { _ensureAllowance, DIGas, fromBN,
|
|
10
|
+
import { _ensureAllowance, DIGas, fromBN, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
11
11
|
function _depositCheck(amounts_1) {
|
|
12
12
|
return __awaiter(this, arguments, void 0, function* (amounts, estimateGas = false) {
|
|
13
13
|
if (amounts.length !== this.underlyingCoinAddresses.length) {
|
|
@@ -40,7 +40,7 @@ export const depositMetaFactoryMixin = {
|
|
|
40
40
|
if (!estimateGas)
|
|
41
41
|
yield _ensureAllowance.call(this.curve, this.underlyingCoinAddresses, _amounts, this.zap);
|
|
42
42
|
const _minMintAmount = yield _depositMinAmount.call(this, _amounts, slippage);
|
|
43
|
-
const ethIndex = getEthIndex(this.underlyingCoinAddresses);
|
|
43
|
+
const ethIndex = this.curve.getEthIndex(this.underlyingCoinAddresses);
|
|
44
44
|
const value = _amounts[ethIndex] || parseUnits("0");
|
|
45
45
|
const contract = this.curve.contracts[this.zap].contract;
|
|
46
46
|
const gas = yield contract.add_liquidity.estimateGas(this.address, _amounts, _minMintAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -69,7 +69,7 @@ export const depositCryptoMetaFactoryMixin = {
|
|
|
69
69
|
if (!estimateGas)
|
|
70
70
|
yield _ensureAllowance.call(this.curve, this.underlyingCoinAddresses, _amounts, this.zap);
|
|
71
71
|
const _minMintAmount = yield _depositMinAmount.call(this, _amounts, slippage);
|
|
72
|
-
const ethIndex = getEthIndex(this.underlyingCoinAddresses);
|
|
72
|
+
const ethIndex = this.curve.getEthIndex(this.underlyingCoinAddresses);
|
|
73
73
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
74
74
|
const contract = this.curve.contracts[this.zap].contract;
|
|
75
75
|
const gas = yield contract.add_liquidity.estimateGas(this.address, _amounts, _minMintAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -98,7 +98,7 @@ export const depositZapMixin = {
|
|
|
98
98
|
if (!estimateGas)
|
|
99
99
|
yield _ensureAllowance.call(this.curve, this.underlyingCoinAddresses, _amounts, this.zap);
|
|
100
100
|
const _minMintAmount = yield _depositMinAmount.call(this, _amounts, slippage);
|
|
101
|
-
const ethIndex = getEthIndex(this.underlyingCoinAddresses);
|
|
101
|
+
const ethIndex = this.curve.getEthIndex(this.underlyingCoinAddresses);
|
|
102
102
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
103
103
|
const contract = this.curve.contracts[this.zap].contract;
|
|
104
104
|
const args = [_amounts, _minMintAmount];
|
|
@@ -130,7 +130,7 @@ export const depositLendingOrCryptoMixin = {
|
|
|
130
130
|
if (!estimateGas)
|
|
131
131
|
yield _ensureAllowance.call(this.curve, this.underlyingCoinAddresses, _amounts, this.address);
|
|
132
132
|
const _minMintAmount = yield _depositMinAmount.call(this, _amounts, slippage);
|
|
133
|
-
const ethIndex = getEthIndex(this.underlyingCoinAddresses);
|
|
133
|
+
const ethIndex = this.curve.getEthIndex(this.underlyingCoinAddresses);
|
|
134
134
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
135
135
|
const contract = this.curve.contracts[this.address].contract;
|
|
136
136
|
const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -159,7 +159,7 @@ export const depositPlainMixin = {
|
|
|
159
159
|
if (!estimateGas)
|
|
160
160
|
yield _ensureAllowance.call(this.curve, this.wrappedCoinAddresses, _amounts, this.address);
|
|
161
161
|
const _minMintAmount = yield _depositMinAmount.call(this, _amounts, slippage);
|
|
162
|
-
const ethIndex = getEthIndex(this.wrappedCoinAddresses);
|
|
162
|
+
const ethIndex = this.curve.getEthIndex(this.wrappedCoinAddresses);
|
|
163
163
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
164
164
|
const contract = this.curve.contracts[this.address].contract;
|
|
165
165
|
const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { _ensureAllowance, DIGas, fromBN,
|
|
10
|
+
import { _ensureAllowance, DIGas, fromBN, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
11
11
|
function _depositWrappedCheck(amounts_1) {
|
|
12
12
|
return __awaiter(this, arguments, void 0, function* (amounts, estimateGas = false) {
|
|
13
13
|
if (this.isFake) {
|
|
@@ -43,7 +43,7 @@ export const depositWrapped2argsMixin = {
|
|
|
43
43
|
if (!estimateGas)
|
|
44
44
|
yield _ensureAllowance.call(this.curve, this.wrappedCoinAddresses, _amounts, this.address);
|
|
45
45
|
const _minMintAmount = yield _depositWrappedMinAmount.call(this, _amounts, slippage);
|
|
46
|
-
const ethIndex = getEthIndex(this.wrappedCoinAddresses);
|
|
46
|
+
const ethIndex = this.curve.getEthIndex(this.wrappedCoinAddresses);
|
|
47
47
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
48
48
|
const contract = this.curve.contracts[this.address].contract;
|
|
49
49
|
const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -72,7 +72,7 @@ export const depositWrapped3argsMixin = {
|
|
|
72
72
|
if (!estimateGas)
|
|
73
73
|
yield _ensureAllowance.call(this.curve, this.wrappedCoinAddresses, _amounts, this.address);
|
|
74
74
|
const _minMintAmount = yield _depositWrappedMinAmount.call(this, _amounts, slippage);
|
|
75
|
-
const ethIndex = getEthIndex(this.wrappedCoinAddresses);
|
|
75
|
+
const ethIndex = this.curve.getEthIndex(this.wrappedCoinAddresses);
|
|
76
76
|
const value = _amounts[ethIndex] || this.curve.parseUnits("0");
|
|
77
77
|
const contract = this.curve.contracts[this.address].contract;
|
|
78
78
|
const gas = yield contract.add_liquidity.estimateGas(_amounts, _minMintAmount, false, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { _ensureAllowance, _getCoinDecimals, DIGas, fromBN, hasAllowance,
|
|
10
|
+
import { _ensureAllowance, _getCoinDecimals, DIGas, fromBN, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
11
11
|
function _swapCheck(inputCoin_1, outputCoin_1, amount_1) {
|
|
12
12
|
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, estimateGas = false) {
|
|
13
13
|
const contractAddress = this._swapContractAddress();
|
|
@@ -43,7 +43,7 @@ export const swapTricrypto2Mixin = {
|
|
|
43
43
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
44
44
|
const contract = this.curve.contracts[contractAddress].contract;
|
|
45
45
|
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
46
|
-
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
46
|
+
const value = this.curve.isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
47
47
|
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
48
48
|
if (estimateGas)
|
|
49
49
|
return smartNumber(gas);
|
|
@@ -73,7 +73,7 @@ export const swapMetaFactoryMixin = {
|
|
|
73
73
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
74
74
|
const contract = this.curve.contracts[contractAddress].contract;
|
|
75
75
|
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
76
|
-
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
76
|
+
const value = this.curve.isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
77
77
|
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
78
78
|
if (estimateGas)
|
|
79
79
|
return smartNumber(gas);
|
|
@@ -103,7 +103,7 @@ export const swapCryptoMetaFactoryMixin = {
|
|
|
103
103
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
104
104
|
const contract = this.curve.contracts[contractAddress].contract;
|
|
105
105
|
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
106
|
-
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
106
|
+
const value = this.curve.isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
107
107
|
const gas = yield contract[exchangeMethod].estimateGas(this.address, i, j, _amount, _minRecvAmount, true, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
108
108
|
if (estimateGas)
|
|
109
109
|
return smartNumber(gas);
|
|
@@ -133,7 +133,7 @@ export const swapMixin = {
|
|
|
133
133
|
const _minRecvAmount = yield _swapMinAmount.call(this, i, j, _amount, slippage);
|
|
134
134
|
const contract = this.curve.contracts[contractAddress].contract;
|
|
135
135
|
const exchangeMethod = 'exchange_underlying' in contract ? 'exchange_underlying' : 'exchange';
|
|
136
|
-
const value = isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
136
|
+
const value = this.curve.isEth(this.underlyingCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
137
137
|
const gas = yield contract[exchangeMethod].estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
138
138
|
if (estimateGas)
|
|
139
139
|
return smartNumber(gas);
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { _ensureAllowance, _getCoinDecimals, DIGas, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance,
|
|
10
|
+
import { _ensureAllowance, _getCoinDecimals, DIGas, ensureAllowance, ensureAllowanceEstimateGas, fromBN, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, } from '../../utils.js';
|
|
11
11
|
function _swapWrappedCheck(inputCoin_1, outputCoin_1, amount_1) {
|
|
12
12
|
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, estimateGas = false) {
|
|
13
13
|
const i = this._getCoinIdx(inputCoin, false);
|
|
@@ -40,7 +40,7 @@ export const swapWrappedTricrypto2Mixin = {
|
|
|
40
40
|
yield _ensureAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
41
41
|
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
42
42
|
const contract = this.curve.contracts[this.address].contract;
|
|
43
|
-
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
43
|
+
const value = this.curve.isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
44
44
|
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, false, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
45
45
|
if (estimateGas)
|
|
46
46
|
return smartNumber(gas);
|
|
@@ -68,7 +68,7 @@ export const swapWrappedMixin = {
|
|
|
68
68
|
yield _ensureAllowance.call(this.curve, [this.wrappedCoinAddresses[i]], [_amount], this.address);
|
|
69
69
|
const _minRecvAmount = yield _swapWrappedMinAmount.call(this, i, j, _amount, slippage);
|
|
70
70
|
const contract = this.curve.contracts[this.address].contract;
|
|
71
|
-
const value = isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
71
|
+
const value = this.curve.isEth(this.wrappedCoinAddresses[i]) ? _amount : this.curve.parseUnits("0");
|
|
72
72
|
const gas = yield contract.exchange.estimateGas(i, j, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.curve.constantOptions), { value }));
|
|
73
73
|
if (estimateGas)
|
|
74
74
|
return smartNumber(gas);
|
|
@@ -16,10 +16,11 @@ export function routeGraphWorker() {
|
|
|
16
16
|
const routerGraph = {};
|
|
17
17
|
// ETH <-> WETH (exclude Celo)
|
|
18
18
|
if (chainId !== 42220) {
|
|
19
|
+
const wrapperAddress = constants.NATIVE_TOKEN.wrapperAddress || constants.NATIVE_TOKEN.wrappedAddress;
|
|
19
20
|
routerGraph[constants.NATIVE_TOKEN.address] = {};
|
|
20
21
|
routerGraph[constants.NATIVE_TOKEN.address][constants.NATIVE_TOKEN.wrappedAddress] = [{
|
|
21
22
|
poolId: "WETH wrapper",
|
|
22
|
-
swapAddress:
|
|
23
|
+
swapAddress: wrapperAddress,
|
|
23
24
|
inputCoinAddress: constants.NATIVE_TOKEN.address,
|
|
24
25
|
outputCoinAddress: constants.NATIVE_TOKEN.wrappedAddress,
|
|
25
26
|
swapParams: [0, 0, 8, 0, 0],
|
|
@@ -33,7 +34,7 @@ export function routeGraphWorker() {
|
|
|
33
34
|
routerGraph[constants.NATIVE_TOKEN.wrappedAddress] = {};
|
|
34
35
|
routerGraph[constants.NATIVE_TOKEN.wrappedAddress][constants.NATIVE_TOKEN.address] = [{
|
|
35
36
|
poolId: "WETH wrapper",
|
|
36
|
-
swapAddress:
|
|
37
|
+
swapAddress: wrapperAddress,
|
|
37
38
|
inputCoinAddress: constants.NATIVE_TOKEN.wrappedAddress,
|
|
38
39
|
outputCoinAddress: constants.NATIVE_TOKEN.address,
|
|
39
40
|
swapParams: [0, 0, 8, 0, 0],
|
package/lib/router.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ethers } from "ethers";
|
|
11
11
|
import { OLD_CHAINS } from "./curve.js";
|
|
12
|
-
import { _cutZeros, _get_price_impact, _get_small_x, _getCoinAddresses, _getCoinDecimals, _getUsdRate, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, ETH_ADDRESS, fromBN, getGasPriceFromL1, getTxCostsUsd, hasAllowance,
|
|
12
|
+
import { _cutZeros, _get_price_impact, _get_small_x, _getCoinAddresses, _getCoinDecimals, _getUsdRate, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, ETH_ADDRESS, fromBN, getGasPriceFromL1, getTxCostsUsd, hasAllowance, parseUnits, populateApprove, runWorker, smartNumber, toBN, } from "./utils.js";
|
|
13
13
|
import { getPool } from "./pools/index.js";
|
|
14
14
|
import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
|
|
15
15
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
@@ -114,7 +114,7 @@ function _estimateGasForDifferentRoutes(routes, inputCoinAddress, outputCoinAddr
|
|
|
114
114
|
outputCoinAddress = outputCoinAddress.toLowerCase();
|
|
115
115
|
const contract = this.contracts[this.constants.ALIASES.router].contract;
|
|
116
116
|
const gasPromises = [];
|
|
117
|
-
const value = isEth(inputCoinAddress) ? _amount : this.parseUnits("0");
|
|
117
|
+
const value = this.isEth(inputCoinAddress) ? _amount : this.parseUnits("0");
|
|
118
118
|
for (const route of routes) {
|
|
119
119
|
const routeKey = _getRouteKey(route, inputCoinAddress, outputCoinAddress);
|
|
120
120
|
let gasPromise;
|
|
@@ -404,7 +404,7 @@ function prepareSwap(inputCoin_1, outputCoin_1, amount_1) {
|
|
|
404
404
|
const minRecvAmountBN = BN(output).times(100 - slippage).div(100);
|
|
405
405
|
const _minRecvAmount = fromBN(minRecvAmountBN, outputCoinDecimals);
|
|
406
406
|
const contract = this.contracts[this.constants.ALIASES.router].contract;
|
|
407
|
-
const value = isEth(inputCoinAddress) ? _amount : this.parseUnits("0");
|
|
407
|
+
const value = this.isEth(inputCoinAddress) ? _amount : this.parseUnits("0");
|
|
408
408
|
yield this.updateFeeData();
|
|
409
409
|
if (_pools) {
|
|
410
410
|
const gasLimit = (DIGas(yield contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, _pools, Object.assign(Object.assign({}, this.constantOptions), { value })))) * (this.chainId === 1 ? this.parseUnits("130", 0) : this.parseUnits("160", 0)) / this.parseUnits("100", 0);
|
|
@@ -437,7 +437,7 @@ export function populateSwap(inputCoin_1, outputCoin_1, amount_1) {
|
|
|
437
437
|
return yield contract.exchange.populateTransaction(...[
|
|
438
438
|
_route, _swapParams, _amount, _minRecvAmount,
|
|
439
439
|
..._pools ? [_pools] : [],
|
|
440
|
-
{ value: isEth(inputCoinAddress) ? _amount : this.parseUnits("0") },
|
|
440
|
+
{ value: this.isEth(inputCoinAddress) ? _amount : this.parseUnits("0") },
|
|
441
441
|
]);
|
|
442
442
|
});
|
|
443
443
|
}
|
package/lib/utils.d.ts
CHANGED
|
@@ -13,8 +13,6 @@ export declare const BN: (val: number | string) => BigNumber;
|
|
|
13
13
|
export declare const toBN: (n: bigint, decimals?: number) => BigNumber;
|
|
14
14
|
export declare const toStringFromBN: (bn: BigNumber, decimals?: number) => string;
|
|
15
15
|
export declare const fromBN: (bn: BigNumber, decimals?: number) => bigint;
|
|
16
|
-
export declare const isEth: (address: string) => boolean;
|
|
17
|
-
export declare const getEthIndex: (addresses: string[]) => number;
|
|
18
16
|
export declare const mulBy1_3: (n: bigint) => bigint;
|
|
19
17
|
export declare const smartNumber: (abstractNumber: bigint | bigint[]) => number | number[];
|
|
20
18
|
export declare const DIGas: (gas: bigint | Array<bigint>) => bigint;
|
package/lib/utils.js
CHANGED
|
@@ -51,8 +51,6 @@ export const fromBN = (bn, decimals = 18) => {
|
|
|
51
51
|
return parseUnits(toStringFromBN(bn, decimals), decimals);
|
|
52
52
|
};
|
|
53
53
|
// -------------------
|
|
54
|
-
export const isEth = (address) => address.toLowerCase() === ETH_ADDRESS.toLowerCase();
|
|
55
|
-
export const getEthIndex = (addresses) => addresses.map((address) => address.toLowerCase()).indexOf(ETH_ADDRESS.toLowerCase());
|
|
56
54
|
export const mulBy1_3 = (n) => n * parseUnits("130", 0) / parseUnits("100", 0);
|
|
57
55
|
export const smartNumber = (abstractNumber) => {
|
|
58
56
|
if (Array.isArray(abstractNumber)) {
|
|
@@ -114,7 +112,7 @@ export function _getBalances(coins, addresses) {
|
|
|
114
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
113
|
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
116
114
|
const decimals = _getCoinDecimals.call(this, coinAddresses);
|
|
117
|
-
const ethIndex = getEthIndex(coinAddresses);
|
|
115
|
+
const ethIndex = this.getEthIndex(coinAddresses);
|
|
118
116
|
if (ethIndex !== -1) {
|
|
119
117
|
coinAddresses.splice(ethIndex, 1);
|
|
120
118
|
}
|
|
@@ -165,7 +163,7 @@ export function getBalances(coins, ...addresses) {
|
|
|
165
163
|
export function _getAllowance(coins, address, spender) {
|
|
166
164
|
return __awaiter(this, void 0, void 0, function* () {
|
|
167
165
|
const _coins = [...coins];
|
|
168
|
-
const ethIndex = getEthIndex(_coins);
|
|
166
|
+
const ethIndex = this.getEthIndex(_coins);
|
|
169
167
|
if (ethIndex !== -1) {
|
|
170
168
|
_coins.splice(ethIndex, 1);
|
|
171
169
|
}
|
|
@@ -387,7 +385,15 @@ export function _getUsdRate(assetId) {
|
|
|
387
385
|
'ETH': 'ethereum',
|
|
388
386
|
'LINK': 'link',
|
|
389
387
|
}[assetId.toUpperCase()] || assetId;
|
|
390
|
-
|
|
388
|
+
// Special case for chainId 988 native and wrapped tokens are USDT
|
|
389
|
+
if (this.chainId === 988) {
|
|
390
|
+
if (this.isEth(assetId) || assetId.toLowerCase() === this.constants.NATIVE_TOKEN.wrappedAddress.toLowerCase()) {
|
|
391
|
+
assetId = 'tether';
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
assetId = this.isEth(assetId) ? nativeTokenName : assetId.toLowerCase();
|
|
396
|
+
}
|
|
391
397
|
// No EURT on Coingecko Polygon
|
|
392
398
|
if (this.chainId === 137 && assetId.toLowerCase() === this.constants.COINS.eurt) {
|
|
393
399
|
chainName = 'ethereum';
|
|
@@ -398,7 +404,10 @@ export function _getUsdRate(assetId) {
|
|
|
398
404
|
assetId = 'curve-dao-token';
|
|
399
405
|
}
|
|
400
406
|
if (this.isLiteChain && assetId.toLowerCase() === ((_f = this.constants.API_CONSTANTS) === null || _f === void 0 ? void 0 : _f.wrappedNativeTokenAddress.toLowerCase())) {
|
|
401
|
-
|
|
407
|
+
// For chainId 988, already handled above (tether)
|
|
408
|
+
if (this.chainId !== 988) {
|
|
409
|
+
assetId = nativeTokenName;
|
|
410
|
+
}
|
|
402
411
|
}
|
|
403
412
|
if ((((_g = _usdRatesCache[assetId]) === null || _g === void 0 ? void 0 : _g.time) || 0) + 600000 < Date.now()) {
|
|
404
413
|
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
@@ -631,7 +640,7 @@ export function getCoinsData(...coins) {
|
|
|
631
640
|
coins = coins;
|
|
632
641
|
const coinAddresses = _getCoinAddressesNoCheck.call(this, coins);
|
|
633
642
|
console.log(coinAddresses);
|
|
634
|
-
const ethIndex = getEthIndex(coinAddresses);
|
|
643
|
+
const ethIndex = this.getEthIndex(coinAddresses);
|
|
635
644
|
if (ethIndex !== -1) {
|
|
636
645
|
coinAddresses.splice(ethIndex, 1);
|
|
637
646
|
}
|