@curvefi/api 2.66.23 → 2.66.25
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 +1 -0
- package/lib/boosting.js +23 -1
- package/lib/external-api.js +9 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/router.js +1 -1
- package/package.json +1 -1
package/lib/boosting.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const approveEstimateGas: (amount: number | string) => Promise<nu
|
|
|
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;
|
|
17
|
+
export declare const calculateVeCrv: (amount: number | string, unlockTimestamp: number) => number;
|
|
17
18
|
export declare const createLock: (amount: number | string, days: number) => Promise<string>;
|
|
18
19
|
export declare const increaseAmountEstimateGas: (amount: number | string) => Promise<number>;
|
|
19
20
|
export declare const increaseAmount: (amount: number | string) => Promise<string>;
|
package/lib/boosting.js
CHANGED
|
@@ -8,11 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { Contract } from "ethers";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
11
12
|
import { curve } from "./curve.js";
|
|
12
13
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: 'json' };
|
|
13
14
|
import feeDistributorCrvUSDViewABI from "./constants/abis/fee_distributor_crvusd_view.json" with { type: 'json' };
|
|
14
15
|
import { _getBalances, _prepareAddresses, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, smartNumber, } from "./utils.js";
|
|
15
|
-
import { _ensureAllowance, toBN, toStringFromBN, parseUnits } from './utils.js';
|
|
16
|
+
import { _ensureAllowance, toBN, toStringFromBN, parseUnits, BN } from './utils.js';
|
|
16
17
|
import { _generateBoostingProof } from './external-api.js';
|
|
17
18
|
export const getCrv = (...addresses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
19
|
addresses = _prepareAddresses(addresses);
|
|
@@ -91,6 +92,27 @@ export const calcUnlockTime = (days, start = Date.now()) => {
|
|
|
91
92
|
const unlockTime = now + (86400 * days);
|
|
92
93
|
return Math.floor(unlockTime / week) * week * 1000;
|
|
93
94
|
};
|
|
95
|
+
export const calculateVeCrv = (amount, unlockTimestamp) => {
|
|
96
|
+
const WEEK_SECONDS = BN(7 * 86400);
|
|
97
|
+
const MAX_TIME_SECONDS = BN(4 * 365 * 86400);
|
|
98
|
+
const nowBN = BN(Math.floor(Date.now() / 1000));
|
|
99
|
+
const unlockBN = BN(unlockTimestamp);
|
|
100
|
+
const unlockRounded = unlockBN
|
|
101
|
+
.div(WEEK_SECONDS)
|
|
102
|
+
.integerValue(BigNumber.ROUND_FLOOR)
|
|
103
|
+
.times(WEEK_SECONDS);
|
|
104
|
+
let duration = unlockRounded.minus(nowBN);
|
|
105
|
+
if (duration.isNegative()) {
|
|
106
|
+
duration = BN(0);
|
|
107
|
+
}
|
|
108
|
+
else if (duration.gt(MAX_TIME_SECONDS)) {
|
|
109
|
+
duration = MAX_TIME_SECONDS;
|
|
110
|
+
}
|
|
111
|
+
const veCrvBN = BN(amount)
|
|
112
|
+
.times(duration)
|
|
113
|
+
.div(MAX_TIME_SECONDS);
|
|
114
|
+
return veCrvBN.toNumber();
|
|
115
|
+
};
|
|
94
116
|
export const createLock = (amount, days) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
117
|
const _amount = parseUnits(amount);
|
|
96
118
|
const unlockTime = Math.floor(Date.now() / 1000) + (86400 * days);
|
package/lib/external-api.js
CHANGED
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
export const _getPoolsFromApi = memoize((network_1, poolType_1, ...args_1) => __awaiter(void 0, [network_1, poolType_1, ...args_1], void 0, function* (network, poolType, isLiteChain = false) {
|
|
12
12
|
var _a;
|
|
13
|
-
const api = isLiteChain ? "https://
|
|
13
|
+
const api = isLiteChain ? "https://api-core.curve.finance/v1/" : "https://api.curve.finance/api";
|
|
14
14
|
const url = `${api}/getPools/${network}/${poolType}`;
|
|
15
15
|
return (_a = yield fetchData(url)) !== null && _a !== void 0 ? _a : { poolData: [], tvl: 0, tvlAll: 0 };
|
|
16
16
|
}), {
|
|
@@ -41,7 +41,7 @@ export const _getAllPoolsFromApi = (network_1, ...args_1) => __awaiter(void 0, [
|
|
|
41
41
|
});
|
|
42
42
|
export const _getSubgraphData = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
43
|
var _a, _b, _c;
|
|
44
|
-
const data = yield fetchData(`https://
|
|
44
|
+
const data = yield fetchData(`https://api.curve.finance/api/getSubgraphData/${network}`);
|
|
45
45
|
const poolsData = data.poolList.map((data) => ({
|
|
46
46
|
address: data.address,
|
|
47
47
|
volumeUSD: data.volumeUSD,
|
|
@@ -60,7 +60,7 @@ export const _getSubgraphData = memoize((network) => __awaiter(void 0, void 0, v
|
|
|
60
60
|
});
|
|
61
61
|
export const _getVolumes = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
62
|
var _a, _b, _c;
|
|
63
|
-
const { pools, totalVolumes } = yield fetchData(`https://
|
|
63
|
+
const { pools, totalVolumes } = yield fetchData(`https://api.curve.finance/api/getVolumes/${network}`);
|
|
64
64
|
const poolsData = pools.map((data) => ({
|
|
65
65
|
address: data.address,
|
|
66
66
|
volumeUSD: data.volumeUSD,
|
|
@@ -78,7 +78,7 @@ export const _getVolumes = memoize((network) => __awaiter(void 0, void 0, void 0
|
|
|
78
78
|
maxAge: 5 * 60 * 1000, // 5m
|
|
79
79
|
});
|
|
80
80
|
export const _getFactoryAPYs = memoize((network) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
-
const [stableData, cryptoData] = yield Promise.all(['stable', 'crypto'].map((type) => fetchData(`https://
|
|
81
|
+
const [stableData, cryptoData] = yield Promise.all(['stable', 'crypto'].map((type) => fetchData(`https://api.curve.finance/api/getFactoryAPYs/${network}/${type}`)));
|
|
82
82
|
const stableVolume = stableData.totalVolumeUsd || stableData.totalVolume || 0;
|
|
83
83
|
const cryptoVolume = cryptoData.totalVolumeUsd || cryptoData.totalVolume || 0;
|
|
84
84
|
return {
|
|
@@ -99,12 +99,12 @@ export const _getFactoryAPYs = memoize((network) => __awaiter(void 0, void 0, vo
|
|
|
99
99
|
promise: true,
|
|
100
100
|
maxAge: 5 * 60 * 1000, // 5m
|
|
101
101
|
});
|
|
102
|
-
export const _getAllGauges = memoize(() => fetchData(`https://
|
|
102
|
+
export const _getAllGauges = memoize(() => fetchData(`https://api.curve.finance/api/getAllGauges`), {
|
|
103
103
|
promise: true,
|
|
104
104
|
maxAge: 5 * 60 * 1000, // 5m
|
|
105
105
|
});
|
|
106
106
|
export const _getAllGaugesFormatted = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
107
|
-
const data = yield fetchData(`https://
|
|
107
|
+
const data = yield fetchData(`https://api.curve.finance/api/getAllGauges`);
|
|
108
108
|
const gaugesDict = {};
|
|
109
109
|
Object.values(data).forEach((d) => {
|
|
110
110
|
var _a, _b;
|
|
@@ -118,7 +118,7 @@ export const _getAllGaugesFormatted = memoize(() => __awaiter(void 0, void 0, vo
|
|
|
118
118
|
promise: true,
|
|
119
119
|
maxAge: 60 * 60 * 1000, // 60m
|
|
120
120
|
});
|
|
121
|
-
export const _getHiddenPools = memoize(() => fetchData(`https://
|
|
121
|
+
export const _getHiddenPools = memoize(() => fetchData(`https://api.curve.finance/api/getHiddenPools`), {
|
|
122
122
|
promise: true,
|
|
123
123
|
maxAge: 5 * 60 * 1000, // 5m
|
|
124
124
|
});
|
|
@@ -147,7 +147,7 @@ export const _getDaoProposal = memoize((type, id) => fetchJson(`https://api-py.l
|
|
|
147
147
|
export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
148
148
|
var _a, _b;
|
|
149
149
|
try {
|
|
150
|
-
const url = `https://
|
|
150
|
+
const url = `https://api-core.curve.finance/v1/getDeployment/${networkName}`;
|
|
151
151
|
const response = yield fetch(url);
|
|
152
152
|
const { data } = (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
|
|
153
153
|
if (response.status !== 200 || !data) {
|
|
@@ -195,7 +195,7 @@ export const _getLiteNetworksData = memoize((networkName) => __awaiter(void 0, v
|
|
|
195
195
|
});
|
|
196
196
|
export const _getCurveLiteNetworks = memoize(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
197
197
|
var _a;
|
|
198
|
-
const response = yield fetch(`https://
|
|
198
|
+
const response = yield fetch(`https://api-core.curve.finance/v1/getPlatforms`);
|
|
199
199
|
const { data } = (_a = yield response.json()) !== null && _a !== void 0 ? _a : {};
|
|
200
200
|
if (response.status !== 200 || !(data === null || data === void 0 ? void 0 : data.platforms)) {
|
|
201
201
|
console.error('Failed to fetch Curve platforms:', response);
|
package/lib/index.d.ts
CHANGED
|
@@ -208,6 +208,7 @@ declare const curve: {
|
|
|
208
208
|
claimFees: (address?: string) => Promise<string>;
|
|
209
209
|
claimableFeesCrvUSD: (address?: string) => Promise<string>;
|
|
210
210
|
claimFeesCrvUSD: (address?: string) => Promise<string>;
|
|
211
|
+
calculateVeCrv: (amount: number | string, unlockTimestamp: number) => number;
|
|
211
212
|
estimateGas: {
|
|
212
213
|
approve: (amount: number | string) => Promise<number | number[]>;
|
|
213
214
|
createLock: (amount: number | string, days: number) => Promise<number>;
|
package/lib/index.js
CHANGED
|
@@ -11,7 +11,7 @@ import { PoolTemplate, getPool } from "./pools/index.js";
|
|
|
11
11
|
import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList, getUserLiquidityUSD, getUserClaimable, } from "./pools/utils.js";
|
|
12
12
|
import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
|
|
13
13
|
import { curve as _curve } from "./curve.js";
|
|
14
|
-
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, claimFeesCrvUSDEstimateGas, claimableFeesCrvUSD, claimFeesCrvUSD, } from "./boosting.js";
|
|
14
|
+
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, claimFeesCrvUSDEstimateGas, claimableFeesCrvUSD, claimFeesCrvUSD, calculateVeCrv, } from "./boosting.js";
|
|
15
15
|
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, getGasPrice, getCurveLiteNetworks, } from "./utils.js";
|
|
16
16
|
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, getDeployedGaugeMirrorAddressByTx, deployStableNgPlainPool, deployStableNgPlainPoolEstimateGas, deployStableNgMetaPool, deployStableNgMetaPoolEstimateGas, deployTwocryptoPool, deployTwocryptoPoolEstimateGas, getDeployedTwocryptoPoolAddress, } from './factory/deploy.js';
|
|
17
17
|
import { crvSupplyStats, userCrv, userVeCrv, crvLockIsApproved, crvLockApproveEstimateGas, crvLockApprove, calcCrvUnlockTime, createCrvLockEstimateGas, createCrvLock, increaseCrvLockedAmountEstimateGas, increaseCrvLockedAmount, increaseCrvUnlockTimeEstimateGas, increaseCrvUnlockTime, withdrawLockedCrvEstimateGas as daoWithdrawLockedCrvEstimateGas, withdrawLockedCrv as daoWithdrawLockedCrv, claimableFees as daoClaimableFees, claimFeesEstimateGas as daoClaimFeesEstimateGas, claimFees as daoClaimFees, getVotingGaugeList, userGaugeVotes, voteForGaugeNextTime, voteForGaugeEstimateGas, voteForGauge, getProposalList, getProposal, userProposalVotes, voteForProposalEstimateGas, voteForProposal, executeVote, executeVoteEstimateGas, isCanVoteExecute, } from "./dao.js";
|
|
@@ -198,6 +198,7 @@ const curve = {
|
|
|
198
198
|
claimFees,
|
|
199
199
|
claimableFeesCrvUSD,
|
|
200
200
|
claimFeesCrvUSD,
|
|
201
|
+
calculateVeCrv,
|
|
201
202
|
estimateGas: {
|
|
202
203
|
approve: approveEstimateGas,
|
|
203
204
|
createLock: createLockEstimateGas,
|
package/lib/router.js
CHANGED
|
@@ -216,7 +216,7 @@ const _getBestRoute = memoize((inputCoinAddress, outputCoinAddress, amount) => _
|
|
|
216
216
|
const [gasAmounts, outputCoinUsdRate, gasData, ethUsdRate] = yield Promise.all([
|
|
217
217
|
_estimateGasForDifferentRoutes(routes.map((r) => r.route), inputCoinAddress, outputCoinAddress, _amount),
|
|
218
218
|
_getUsdRate(outputCoinAddress),
|
|
219
|
-
fetch("https://
|
|
219
|
+
fetch("https://api.curve.finance/api/getGas").then((res) => res.json()),
|
|
220
220
|
_getUsdRate(ETH_ADDRESS),
|
|
221
221
|
]);
|
|
222
222
|
const gasPrice = gasData.data.gas.standard;
|