@curvefi/api 2.71.6 → 2.72.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/lib/boosting.d.ts +9 -1
- package/lib/boosting.js +63 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -1
- package/lib/pools/PoolTemplate.d.ts +1 -1
- package/lib/pools/PoolTemplate.js +9 -22
- package/package.json +1 -1
package/lib/boosting.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { type Curve } from "./curve.js";
|
|
2
|
-
import { IChainId, IDict } from "./interfaces";
|
|
2
|
+
import { IChainId, IDict, IPoolData } from "./interfaces";
|
|
3
|
+
type BoostPool = Pick<IPoolData, "name" | "gauge_address">;
|
|
4
|
+
export declare function _getGaugeBoostStatus(this: Curve, gaugeAddress: string): {
|
|
5
|
+
hasGauge: boolean;
|
|
6
|
+
rewardsOnly: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare function _getUserBoosts(this: Curve, pools: BoostPool[], userAddress?: string, throwOnError?: boolean): Promise<(string | null)[]>;
|
|
9
|
+
export declare function getUserBoosts(this: Curve, pools: string[], userAddress?: string, throwOnError?: boolean): Promise<IDict<string | null>>;
|
|
3
10
|
export declare function getCrv(this: Curve, ...addresses: string[] | string[][]): Promise<IDict<string> | string>;
|
|
4
11
|
export declare function getLockedAmountAndUnlockTime(this: Curve, ...addresses: string[] | string[][]): Promise<IDict<{
|
|
5
12
|
lockedAmount: string;
|
|
@@ -39,3 +46,4 @@ export declare function sendBlockhashEstimateGas(this: Curve, block: number, cha
|
|
|
39
46
|
export declare function sendBlockhash(this: Curve, block: number, chainId: IChainId): Promise<string>;
|
|
40
47
|
export declare function submitProofEstimateGas(this: Curve, block: number, address?: string): Promise<number>;
|
|
41
48
|
export declare function submitProof(this: Curve, block: number, address?: string): Promise<string>;
|
|
49
|
+
export {};
|
package/lib/boosting.js
CHANGED
|
@@ -11,8 +11,70 @@ import { Contract } from "ethers";
|
|
|
11
11
|
import BigNumber from "bignumber.js";
|
|
12
12
|
import feeDistributorViewABI from "./constants/abis/fee_distributor_view.json" with { type: "json" };
|
|
13
13
|
import feeDistributorCrvUSDViewABI from "./constants/abis/fee_distributor_crvusd_view.json" with { type: "json" };
|
|
14
|
-
import { _ensureAllowance, _getBalances, _prepareAddresses, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, toStringFromBN, } from "./utils.js";
|
|
14
|
+
import { _ensureAllowance, _getAddress, _getBalances, _prepareAddresses, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, findAbiFunction, getPoolIdBySwapAddress, hasAllowance, mulBy1_3, parseUnits, smartNumber, toBN, toStringFromBN, } from "./utils.js";
|
|
15
15
|
import { _generateBoostingProof } from './external-api.js';
|
|
16
|
+
export function _getGaugeBoostStatus(gaugeAddress) {
|
|
17
|
+
const hasGauge = gaugeAddress !== this.constants.ZERO_ADDRESS;
|
|
18
|
+
// TODO remove the Kava and ZkSync exceptions
|
|
19
|
+
const rewardsOnly = this.chainId === 2222 || this.chainId === 324 ||
|
|
20
|
+
(hasGauge && !findAbiFunction(this.contracts[gaugeAddress].abi, 'inflation_rate')
|
|
21
|
+
.find((func) => ['', 'uint256'].includes(func.inputs.map((input) => `${input.type}`).join(','))));
|
|
22
|
+
return { hasGauge, rewardsOnly };
|
|
23
|
+
}
|
|
24
|
+
export function _getUserBoosts(pools_1) {
|
|
25
|
+
return __awaiter(this, arguments, void 0, function* (pools, userAddress = "", throwOnError = true) {
|
|
26
|
+
const checkedPools = pools.map((pool) => {
|
|
27
|
+
try {
|
|
28
|
+
const { hasGauge, rewardsOnly } = _getGaugeBoostStatus.call(this, pool.gauge_address);
|
|
29
|
+
if (!hasGauge)
|
|
30
|
+
throw Error(`${pool.name} doesn't have gauge`);
|
|
31
|
+
if (rewardsOnly)
|
|
32
|
+
throw Error(`${pool.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
|
|
33
|
+
return pool;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (throwOnError)
|
|
37
|
+
throw error;
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}).filter((pool) => pool !== null);
|
|
41
|
+
userAddress = _getAddress.call(this, userAddress);
|
|
42
|
+
const calls = checkedPools.flatMap((pool) => {
|
|
43
|
+
const gaugeContract = this.contracts[pool.gauge_address].multicallContract;
|
|
44
|
+
return [
|
|
45
|
+
gaugeContract.working_balances(userAddress),
|
|
46
|
+
gaugeContract.balanceOf(userAddress),
|
|
47
|
+
];
|
|
48
|
+
});
|
|
49
|
+
const response = calls.length > 0
|
|
50
|
+
? yield this.multicallProvider.all(calls)
|
|
51
|
+
: [];
|
|
52
|
+
// Creating a Map because not all pools may have a boost value, and we want to return null for those that don't.
|
|
53
|
+
const boostsByPool = new Map(checkedPools.map((pool, index) => {
|
|
54
|
+
const workingBalanceBN = toBN(response[2 * index]);
|
|
55
|
+
const balanceBN = toBN(response[(2 * index) + 1]);
|
|
56
|
+
const boostBN = balanceBN.gt(0) ? workingBalanceBN.div(0.4).div(balanceBN) : toBN(BigInt(0), 0);
|
|
57
|
+
if (boostBN.lt(1))
|
|
58
|
+
return [pool, '1.0'];
|
|
59
|
+
if (boostBN.gt(2.5))
|
|
60
|
+
return [pool, '2.5'];
|
|
61
|
+
return [pool, boostBN.toFixed(4).replace(/([0-9])0+$/, '$1')];
|
|
62
|
+
}));
|
|
63
|
+
return pools.map((pool) => { var _a; return (_a = boostsByPool.get(pool)) !== null && _a !== void 0 ? _a : null; });
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function getUserBoosts(pools_1) {
|
|
67
|
+
return __awaiter(this, arguments, void 0, function* (pools, userAddress = "", throwOnError = true) {
|
|
68
|
+
if (pools.length === 0)
|
|
69
|
+
return {};
|
|
70
|
+
const poolsData = this.getPoolsData();
|
|
71
|
+
const poolIds = pools.map((poolAddress) => getPoolIdBySwapAddress.call(this, poolAddress));
|
|
72
|
+
if (poolIds.some((poolId) => !poolId))
|
|
73
|
+
throw new Error("One or more pool addresses doesn't have pool data");
|
|
74
|
+
const boosts = yield _getUserBoosts.call(this, poolIds.map((poolId) => poolsData[poolId]), userAddress, throwOnError);
|
|
75
|
+
return Object.fromEntries(pools.map((poolAddress, index) => [poolAddress, boosts[index]]));
|
|
76
|
+
});
|
|
77
|
+
}
|
|
16
78
|
export function getCrv(...addresses) {
|
|
17
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
80
|
addresses = _prepareAddresses.call(this, addresses);
|
package/lib/index.d.ts
CHANGED
|
@@ -194,6 +194,7 @@ export declare const createCurve: () => {
|
|
|
194
194
|
};
|
|
195
195
|
boosting: {
|
|
196
196
|
getCrv: (...args: string[] | string[][]) => Promise<string | import("./interfaces.js").IDict<string>>;
|
|
197
|
+
getUserBoosts: (pools: string[], userAddress?: string | undefined, throwOnError?: boolean | undefined) => Promise<import("./interfaces.js").IDict<string | null>>;
|
|
197
198
|
getLockedAmountAndUnlockTime: (...args: string[] | string[][]) => Promise<import("./interfaces.js").IDict<{
|
|
198
199
|
lockedAmount: string;
|
|
199
200
|
unlockTime: number;
|
|
@@ -532,6 +533,7 @@ declare const _default: {
|
|
|
532
533
|
};
|
|
533
534
|
boosting: {
|
|
534
535
|
getCrv: (...args: string[] | string[][]) => Promise<string | import("./interfaces.js").IDict<string>>;
|
|
536
|
+
getUserBoosts: (pools: string[], userAddress?: string | undefined, throwOnError?: boolean | undefined) => Promise<import("./interfaces.js").IDict<string | null>>;
|
|
535
537
|
getLockedAmountAndUnlockTime: (...args: string[] | string[][]) => Promise<import("./interfaces.js").IDict<{
|
|
536
538
|
lockedAmount: string;
|
|
537
539
|
unlockTime: number;
|
package/lib/index.js
CHANGED
|
@@ -12,7 +12,7 @@ import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList
|
|
|
12
12
|
import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapPopulateApprove, swapEstimateGas, swap, populateSwap, getSwappedAmount, approveFromCalldata, approveFromCalldataEstimateGas, swapFromCalldata, swapFromCalldataEstimateGas, setRouterBlacklist, } from "./router.js";
|
|
13
13
|
import { isSupported, assertIsSupported, allowedToBridge, bridgeCost, bridgeIsApproved, bridgeApproveEstimateGas, bridgeApprove, bridgeEstimateGas, bridge, getSupportedNetworks, } from "./bridge.js";
|
|
14
14
|
import { Curve } from "./curve.js";
|
|
15
|
-
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
|
+
import { getCrv, getUserBoosts, 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";
|
|
16
16
|
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, populateApprove, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, getPoolVolumes, hasDepositAndStake, hasRouter, getBasePools, getGasPrice, getCurveLiteNetworks, } from "./utils.js";
|
|
17
17
|
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';
|
|
18
18
|
import { getTwoCryptoImplementations } from './constants/twoCryptoImplementations.js';
|
|
@@ -186,6 +186,7 @@ export const createCurve = () => {
|
|
|
186
186
|
},
|
|
187
187
|
boosting: {
|
|
188
188
|
getCrv: getCrv.bind(_curve),
|
|
189
|
+
getUserBoosts: getUserBoosts.bind(_curve),
|
|
189
190
|
getLockedAmountAndUnlockTime: getLockedAmountAndUnlockTime.bind(_curve),
|
|
190
191
|
getVeCrv: getVeCrv.bind(_curve),
|
|
191
192
|
getVeCrvPct: getVeCrvPct.bind(_curve),
|
|
@@ -89,7 +89,7 @@ export declare class PoolTemplate extends CorePool {
|
|
|
89
89
|
claimableCrv(address?: string): Promise<string>;
|
|
90
90
|
claimCrvEstimateGas(): Promise<number | number[]>;
|
|
91
91
|
claimCrv(): Promise<string>;
|
|
92
|
-
userBoost: (
|
|
92
|
+
userBoost: (userAddress?: string) => Promise<string>;
|
|
93
93
|
private _userFutureBoostAndWorkingSupply;
|
|
94
94
|
userFutureBoost: (address?: string) => Promise<string>;
|
|
95
95
|
userCrvApy: (address?: string) => Promise<number>;
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import memoize from "memoizee";
|
|
11
11
|
import { getGaugesOverview } from '../prices-api.js';
|
|
12
12
|
import { _getPoolFilters } from '../external-api.js';
|
|
13
|
+
import { _getGaugeBoostStatus, _getUserBoosts } from "../boosting.js";
|
|
13
14
|
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';
|
|
14
15
|
import { OLD_CHAINS } from "../curve.js";
|
|
15
16
|
import ERC20Abi from '../constants/abis/ERC20.json' with { type: 'json' };
|
|
@@ -178,23 +179,11 @@ export class PoolTemplate extends CorePool {
|
|
|
178
179
|
price: crvPrice,
|
|
179
180
|
};
|
|
180
181
|
});
|
|
181
|
-
this.userBoost = (...args_1) => __awaiter(this, [...args_1], void 0, function* (
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
address = _getAddress.call(this.curve, address);
|
|
187
|
-
const gaugeContract = this.curve.contracts[this.gauge.address].multicallContract;
|
|
188
|
-
const [workingBalanceBN, balanceBN] = (yield this.curve.multicallProvider.all([
|
|
189
|
-
gaugeContract.working_balances(address),
|
|
190
|
-
gaugeContract.balanceOf(address),
|
|
191
|
-
])).map((value) => toBN(value));
|
|
192
|
-
const boostBN = workingBalanceBN.div(0.4).div(balanceBN);
|
|
193
|
-
if (boostBN.lt(1))
|
|
194
|
-
return '1.0';
|
|
195
|
-
if (boostBN.gt(2.5))
|
|
196
|
-
return '2.5';
|
|
197
|
-
return boostBN.toFixed(4).replace(/([0-9])0+$/, '$1');
|
|
182
|
+
this.userBoost = (...args_1) => __awaiter(this, [...args_1], void 0, function* (userAddress = "") {
|
|
183
|
+
return (yield _getUserBoosts.call(this.curve, [{
|
|
184
|
+
name: this.name,
|
|
185
|
+
gauge_address: this.gauge.address,
|
|
186
|
+
}], userAddress, true))[0];
|
|
198
187
|
});
|
|
199
188
|
this._userFutureBoostAndWorkingSupply = (address) => __awaiter(this, void 0, void 0, function* () {
|
|
200
189
|
// Calc future working balance
|
|
@@ -591,12 +580,10 @@ export class PoolTemplate extends CorePool {
|
|
|
591
580
|
return checkVyperVulnerability(this.curve.chainId, this.id, this.implementation);
|
|
592
581
|
}
|
|
593
582
|
rewardsOnly() {
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (this.gauge.address === this.curve.constants.ZERO_ADDRESS)
|
|
583
|
+
const { hasGauge, rewardsOnly } = _getGaugeBoostStatus.call(this.curve, this.gauge.address);
|
|
584
|
+
if (!hasGauge && !rewardsOnly)
|
|
597
585
|
throw Error(`${this.name} doesn't have gauge`);
|
|
598
|
-
return
|
|
599
|
-
.find((func) => ['', 'uint256'].includes(func.inputs.map((a) => `${a.type}`).join(',')));
|
|
586
|
+
return rewardsOnly;
|
|
600
587
|
}
|
|
601
588
|
_pureCalcLpTokenAmount(_amounts_1) {
|
|
602
589
|
return __awaiter(this, arguments, void 0, function* (_amounts, isDeposit = true, useUnderlying = true) {
|