@curvefi/api 2.65.7 → 2.65.9
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/constants/abis/deposit_and_stake_ng_only.json +50 -0
- package/lib/curve.d.ts +1 -0
- package/lib/curve.js +8 -1
- package/lib/external-api.js +1 -0
- package/lib/interfaces.d.ts +1 -0
- package/lib/pools/PoolTemplate.js +17 -3
- package/lib/router.js +1 -2
- package/lib/utils.js +6 -3
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"stateMutability": "payable",
|
|
4
|
+
"type": "function",
|
|
5
|
+
"name": "deposit_and_stake",
|
|
6
|
+
"inputs": [
|
|
7
|
+
{
|
|
8
|
+
"name": "deposit",
|
|
9
|
+
"type": "address"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "lp_token",
|
|
13
|
+
"type": "address"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "gauge",
|
|
17
|
+
"type": "address"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "n_coins",
|
|
21
|
+
"type": "uint256"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"name": "coins",
|
|
25
|
+
"type": "address[]"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
"name": "amounts",
|
|
29
|
+
"type": "uint256[]"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "min_mint_amount",
|
|
33
|
+
"type": "uint256"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"name": "use_dynarray",
|
|
37
|
+
"type": "bool"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "pool",
|
|
41
|
+
"type": "address"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"outputs": []
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"stateMutability": "payable",
|
|
48
|
+
"type": "fallback"
|
|
49
|
+
}
|
|
50
|
+
]
|
package/lib/curve.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ethers, Contract, Networkish, BigNumberish, Numeric, BrowserProvider, JsonRpcProvider, Signer } from "ethers";
|
|
2
2
|
import { Provider as MulticallProvider, Contract as MulticallContract } from "@curvefi/ethcall";
|
|
3
3
|
import { IPoolData, IDict, ICurve, IChainId, IFactoryPoolType, Abi, INetworkConstants } from "./interfaces";
|
|
4
|
+
export declare const OLD_CHAINS: number[];
|
|
4
5
|
export declare const memoizedContract: () => (address: string, abi: any, provider: BrowserProvider | JsonRpcProvider | Signer) => Contract;
|
|
5
6
|
export declare const memoizedMulticallContract: () => (address: string, abi: any) => MulticallContract;
|
|
6
7
|
export type ContractItem = {
|
package/lib/curve.js
CHANGED
|
@@ -28,6 +28,7 @@ import feeDistributorABI from './constants/abis/fee_distributor.json' assert { t
|
|
|
28
28
|
import feeDistributorCrvUSDABI from './constants/abis/fee_distributor_crvusd.json' assert { type: 'json' };
|
|
29
29
|
import gaugeControllerABI from './constants/abis/gaugecontroller.json' assert { type: 'json' };
|
|
30
30
|
import depositAndStakeABI from './constants/abis/deposit_and_stake.json' assert { type: 'json' };
|
|
31
|
+
import depositAndStakeNgOnlyABI from './constants/abis/deposit_and_stake_ng_only.json' assert { type: 'json' };
|
|
31
32
|
import cryptoCalcZapABI from './constants/abis/crypto_calc.json' assert { type: 'json' };
|
|
32
33
|
import StableCalcZapABI from './constants/abis/stable_calc.json' assert { type: 'json' };
|
|
33
34
|
import routerABI from './constants/abis/router.json' assert { type: 'json' };
|
|
@@ -52,6 +53,7 @@ import { _getHiddenPools } from "./external-api.js";
|
|
|
52
53
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
53
54
|
import { getTwocryptoFactoryPoolData } from "./factory/factory-twocrypto.js";
|
|
54
55
|
import { getNetworkConstants } from "./utils.js";
|
|
56
|
+
export const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
|
|
55
57
|
export const memoizedContract = () => {
|
|
56
58
|
const cache = {};
|
|
57
59
|
return (address, abi, provider) => {
|
|
@@ -549,7 +551,12 @@ class Curve {
|
|
|
549
551
|
else {
|
|
550
552
|
this.setContract(this.constants.ALIASES.router, routerNgPoolsOnlyABI);
|
|
551
553
|
}
|
|
552
|
-
|
|
554
|
+
if (OLD_CHAINS.includes(this.chainId)) {
|
|
555
|
+
this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeABI);
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
this.setContract(this.constants.ALIASES.deposit_and_stake, depositAndStakeNgOnlyABI);
|
|
559
|
+
}
|
|
553
560
|
this.setContract(this.constants.ALIASES.crypto_calc, cryptoCalcZapABI);
|
|
554
561
|
this.setContract(this.constants.ALIASES.stable_calc, StableCalcZapABI);
|
|
555
562
|
// --------- POOL FACTORY ---------
|
package/lib/external-api.js
CHANGED
package/lib/interfaces.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import { _getAllGaugesFormatted } from '../external-api.js';
|
|
12
12
|
import { _getCoinAddresses, _ensureAllowance, _getUsdRate, hasAllowance, ensureAllowance, ensureAllowanceEstimateGas, BN, toBN, toStringFromBN, parseUnits, getEthIndex, fromBN, _cutZeros, _setContracts, _get_small_x, _get_price_impact, checkNumber, _getRewardsFromApi, mulBy1_3, smartNumber, DIGas, _getAddress, findAbiFunction, PERIODS, } from '../utils.js';
|
|
13
|
-
import { curve } from "../curve.js";
|
|
13
|
+
import { curve, OLD_CHAINS } from "../curve.js";
|
|
14
14
|
import ERC20Abi from '../constants/abis/ERC20.json' assert { type: 'json' };
|
|
15
15
|
import { CorePool } from "./subClasses/corePool.js";
|
|
16
16
|
import { StatsPool } from "./subClasses/statsPool.js";
|
|
@@ -1222,6 +1222,7 @@ export class PoolTemplate extends CorePool {
|
|
|
1222
1222
|
const _amounts = amounts.map((amount, i) => parseUnits(amount, decimals[i]));
|
|
1223
1223
|
const contract = curve.contracts[curve.constants.ALIASES.deposit_and_stake].contract;
|
|
1224
1224
|
const useUnderlying = isUnderlying && (this.isLending || (this.isCrypto && !this.isPlain)) && (!this.zap || this.id == 'avaxcrypto');
|
|
1225
|
+
const useDynarray = (!this.isCrypto && this.isNg && this.isPlain) || (isUnderlying && this.isMeta && (new PoolTemplate(this.basePool)).isNg);
|
|
1225
1226
|
const _expectedLpTokenAmount = isUnderlying ?
|
|
1226
1227
|
curve.parseUnits(yield this.depositAndStakeExpected(amounts)) :
|
|
1227
1228
|
curve.parseUnits(yield this.depositAndStakeWrappedExpected(amounts));
|
|
@@ -1229,12 +1230,25 @@ export class PoolTemplate extends CorePool {
|
|
|
1229
1230
|
const _minMintAmount = fromBN(minAmountBN);
|
|
1230
1231
|
const ethIndex = getEthIndex(coinAddresses);
|
|
1231
1232
|
const value = _amounts[ethIndex] || curve.parseUnits("0");
|
|
1232
|
-
|
|
1233
|
+
let _gas = BigInt(0);
|
|
1234
|
+
if (OLD_CHAINS.includes(curve.chainId)) {
|
|
1235
|
+
_gas = (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
|
|
1236
|
+
useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.constantOptions), { value })));
|
|
1237
|
+
}
|
|
1238
|
+
else {
|
|
1239
|
+
_gas = (yield contract.deposit_and_stake.estimateGas(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.constantOptions), { value })));
|
|
1240
|
+
}
|
|
1233
1241
|
if (estimateGas)
|
|
1234
1242
|
return smartNumber(_gas);
|
|
1235
1243
|
yield curve.updateFeeData();
|
|
1236
1244
|
const gasLimit = DIGas(_gas) * curve.parseUnits("200", 0) / curve.parseUnits("100", 0);
|
|
1237
|
-
|
|
1245
|
+
if (OLD_CHAINS.includes(curve.chainId)) {
|
|
1246
|
+
return (yield contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useUnderlying, // <--- DIFFERENCE
|
|
1247
|
+
useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
|
|
1248
|
+
}
|
|
1249
|
+
else {
|
|
1250
|
+
return (yield contract.deposit_and_stake(depositAddress, this.lpToken, this.gauge.address, coins.length, coinAddresses, _amounts, _minMintAmount, useDynarray, this.isMetaFactory && isUnderlying ? this.address : curve.constants.ZERO_ADDRESS, Object.assign(Object.assign({}, curve.options), { gasLimit, value }))).hash;
|
|
1251
|
+
}
|
|
1238
1252
|
});
|
|
1239
1253
|
}
|
|
1240
1254
|
// ---------------- WITHDRAW ----------------
|
package/lib/router.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import axios from "axios";
|
|
11
11
|
import memoize from "memoizee";
|
|
12
12
|
import { ethers } from "ethers";
|
|
13
|
-
import { curve } from "./curve.js";
|
|
13
|
+
import { curve, OLD_CHAINS } from "./curve.js";
|
|
14
14
|
import { _cutZeros, _get_price_impact, _get_small_x, _getCoinAddresses, _getCoinDecimals, _getUsdRate, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, ETH_ADDRESS, fromBN, getGasPriceFromL1, getTxCostsUsd, hasAllowance, isEth, parseUnits, runWorker, smartNumber, toBN, } from "./utils.js";
|
|
15
15
|
import { getPool } from "./pools/index.js";
|
|
16
16
|
import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
|
|
@@ -19,7 +19,6 @@ import { routeFinderWorker, routeFinderWorkerCode } from "./route-finder.worker.
|
|
|
19
19
|
import { routeGraphWorker, routeGraphWorkerCode } from "./route-graph.worker.js";
|
|
20
20
|
const MAX_STEPS = 5;
|
|
21
21
|
const ROUTE_LENGTH = (MAX_STEPS * 2) + 1;
|
|
22
|
-
const OLD_CHAINS = [1, 10, 56, 100, 137, 250, 1284, 2222, 8453, 42161, 42220, 43114, 1313161554]; // these chains have non-ng pools
|
|
23
22
|
const _getTVL = memoize((poolId) => __awaiter(void 0, void 0, void 0, function* () { return Number(yield (getPool(poolId)).stats.totalLiquidity()); }), {
|
|
24
23
|
promise: true,
|
|
25
24
|
maxAge: 5 * 60 * 1000, // 5m
|
package/lib/utils.js
CHANGED
|
@@ -366,7 +366,7 @@ export const _getRewardsFromApi = () => __awaiter(void 0, void 0, void 0, functi
|
|
|
366
366
|
});
|
|
367
367
|
const _usdRatesCache = {};
|
|
368
368
|
export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
369
|
-
var _f, _g, _h, _j;
|
|
369
|
+
var _f, _g, _h, _j, _k;
|
|
370
370
|
if (curve.chainId === 1 && assetId.toLowerCase() === '0x8762db106b2c2a0bccb3a80d1ed41273552616e8')
|
|
371
371
|
return 0; // RSR
|
|
372
372
|
const pricesFromApi = yield _getUsdPricesFromApi();
|
|
@@ -435,13 +435,16 @@ export const _getUsdRate = (assetId) => __awaiter(void 0, void 0, void 0, functi
|
|
|
435
435
|
if (assetId.toLowerCase() === curve.constants.ALIASES.crv) {
|
|
436
436
|
assetId = 'curve-dao-token';
|
|
437
437
|
}
|
|
438
|
-
if ((((_h =
|
|
438
|
+
if (curve.isLiteChain && assetId.toLowerCase() === ((_h = curve.constants.API_CONSTANTS) === null || _h === void 0 ? void 0 : _h.wrappedNativeTokenAddress.toLowerCase())) {
|
|
439
|
+
assetId = nativeTokenName;
|
|
440
|
+
}
|
|
441
|
+
if ((((_j = _usdRatesCache[assetId]) === null || _j === void 0 ? void 0 : _j.time) || 0) + 600000 < Date.now()) {
|
|
439
442
|
const url = [nativeTokenName, 'ethereum', 'bitcoin', 'link', 'curve-dao-token', 'stasis-eurs'].includes(assetId.toLowerCase()) ?
|
|
440
443
|
`https://api.coingecko.com/api/v3/simple/price?ids=${assetId}&vs_currencies=usd` :
|
|
441
444
|
`https://api.coingecko.com/api/v3/simple/token_price/${chainName}?contract_addresses=${assetId}&vs_currencies=usd`;
|
|
442
445
|
const response = yield axios.get(url);
|
|
443
446
|
try {
|
|
444
|
-
_usdRatesCache[assetId] = { 'rate': (
|
|
447
|
+
_usdRatesCache[assetId] = { 'rate': (_k = response.data[assetId]['usd']) !== null && _k !== void 0 ? _k : 0, 'time': Date.now() };
|
|
445
448
|
}
|
|
446
449
|
catch (err) { // TODO pay attention!
|
|
447
450
|
_usdRatesCache[assetId] = { 'rate': 0, 'time': Date.now() };
|