@gearbox-protocol/sdk 3.0.0-next.113 → 3.0.0-next.115
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/apy/convexAPY.d.ts +5 -4
- package/lib/apy/convexAPY.js +13 -7
- package/lib/apy/curveAPY.d.ts +45 -0
- package/lib/apy/curveAPY.js +15 -1
- package/lib/apy/defiLamaAPY.js +1 -1
- package/lib/apy/lidoAPY.d.ts +2 -1
- package/lib/core/rewardConvex.js +2 -0
- package/package.json +1 -1
package/lib/apy/convexAPY.d.ts
CHANGED
|
@@ -6,9 +6,10 @@ import { CurveAPYResult } from "./curveAPY";
|
|
|
6
6
|
type GetTokenPriceCallback = (tokenAddress: string, currency?: string) => bigint;
|
|
7
7
|
export interface GetConvexAPYBulkProps {
|
|
8
8
|
getTokenPrice: GetTokenPriceCallback;
|
|
9
|
-
curveAPY: CurveAPYResult;
|
|
9
|
+
curveAPY: CurveAPYResult | undefined;
|
|
10
10
|
generated: GetConvexAPYBulkCallsReturns;
|
|
11
11
|
response: Array<BigNumberish>;
|
|
12
|
+
network: NetworkType;
|
|
12
13
|
}
|
|
13
14
|
export declare function getConvexAPYBulk(props: GetConvexAPYBulkProps): number[];
|
|
14
15
|
interface PoolInfo {
|
|
@@ -25,9 +26,9 @@ type CrvParams = CurveParams | CurveSteCRVPoolParams | CurveGEARPoolParams;
|
|
|
25
26
|
type GetConvexAPYBulkCallsReturns = ReturnType<typeof getConvexAPYBulkCalls>;
|
|
26
27
|
export interface GetConvexAPYBulkCallsProps {
|
|
27
28
|
pools: Array<ConvexPoolContract>;
|
|
28
|
-
|
|
29
|
+
network: NetworkType;
|
|
29
30
|
}
|
|
30
|
-
export declare function getConvexAPYBulkCalls({ pools,
|
|
31
|
+
export declare function getConvexAPYBulkCalls({ pools, network, }: GetConvexAPYBulkCallsProps): {
|
|
31
32
|
poolsInfo: PoolInfo[];
|
|
32
33
|
calls: [MCall<import("../types/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/IBaseRewardPool").IBaseRewardPoolInterface>, MCall<import("../types/ICurvePool").ICurvePoolInterface>, MCall<import("../types/IConvexToken").IConvexTokenInterface>, ...(MCall<import("../types/IBaseRewardPool").IBaseRewardPoolInterface> | MCall<any>)[]][];
|
|
33
34
|
};
|
|
@@ -42,7 +43,7 @@ export interface CalculateConvexAPYProps {
|
|
|
42
43
|
crvLpPrice: Array<bigint>;
|
|
43
44
|
info: PoolInfo;
|
|
44
45
|
getTokenPrice: GetTokenPriceCallback;
|
|
45
|
-
curveAPY: CurveAPYResult;
|
|
46
|
+
curveAPY: CurveAPYResult | undefined;
|
|
46
47
|
}
|
|
47
48
|
export declare function getCVXMintAmount(crvAmount: bigint, cvxTokenSupply: bigint): bigint;
|
|
48
49
|
export {};
|
package/lib/apy/convexAPY.js
CHANGED
|
@@ -7,6 +7,9 @@ const utils_1 = require("ethers/lib/utils");
|
|
|
7
7
|
const types_1 = require("../types");
|
|
8
8
|
const V2_POOLS = { 20: true };
|
|
9
9
|
function getConvexAPYBulk(props) {
|
|
10
|
+
if (props.network !== "Mainnet") {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
10
13
|
const { poolsInfo, calls } = props.generated;
|
|
11
14
|
const [parsedResponse] = calls.reduce(([acc, start], call) => {
|
|
12
15
|
const end = start + call.length;
|
|
@@ -40,12 +43,12 @@ function getConvexAPYBulk(props) {
|
|
|
40
43
|
return apyList;
|
|
41
44
|
}
|
|
42
45
|
exports.getConvexAPYBulk = getConvexAPYBulk;
|
|
43
|
-
function getPoolInfo({ pool,
|
|
44
|
-
const tokenList = token_1.tokenDataByNetwork[
|
|
45
|
-
const contractsList = sdk_gov_1.contractsByNetwork[
|
|
46
|
+
function getPoolInfo({ pool, network }) {
|
|
47
|
+
const tokenList = token_1.tokenDataByNetwork[network];
|
|
48
|
+
const contractsList = sdk_gov_1.contractsByNetwork[network];
|
|
46
49
|
const poolParams = sdk_gov_1.contractParams[pool];
|
|
47
50
|
const basePoolAddress = contractsList[pool];
|
|
48
|
-
const extraPoolAddresses = poolParams.extraRewards.map(d => d.poolAddress[
|
|
51
|
+
const extraPoolAddresses = poolParams.extraRewards.map(d => d.poolAddress[network]);
|
|
49
52
|
const stakedTokenParams = token_1.supportedTokens[poolParams.stakedToken];
|
|
50
53
|
const { underlying } = stakedTokenParams;
|
|
51
54
|
const crvParams = token_1.supportedTokens[underlying];
|
|
@@ -65,8 +68,11 @@ function getPoolInfo({ pool, networkType }) {
|
|
|
65
68
|
tokenList,
|
|
66
69
|
};
|
|
67
70
|
}
|
|
68
|
-
function getConvexAPYBulkCalls({ pools,
|
|
69
|
-
|
|
71
|
+
function getConvexAPYBulkCalls({ pools, network, }) {
|
|
72
|
+
if (network !== "Mainnet") {
|
|
73
|
+
return { poolsInfo: [], calls: [] };
|
|
74
|
+
}
|
|
75
|
+
const poolsInfo = pools.map(pool => getPoolInfo({ network, pool }));
|
|
70
76
|
const calls = poolsInfo.map(info => getPoolDataCalls(info));
|
|
71
77
|
return { poolsInfo, calls };
|
|
72
78
|
}
|
|
@@ -162,7 +168,7 @@ function calculateConvexAPY(props) {
|
|
|
162
168
|
return finished ? 0n : extraAPY;
|
|
163
169
|
});
|
|
164
170
|
const extraAPYTotal = extraAPRs.reduce((acc, apy) => acc + apy, 0n);
|
|
165
|
-
const baseApy = props.curveAPY[crvToken].base;
|
|
171
|
+
const baseApy = props.curveAPY?.[crvToken].base || 0;
|
|
166
172
|
const apyTotal = crvAPY + cvxAPY + extraAPYTotal;
|
|
167
173
|
const apyTotalInPercent = apyTotal * sdk_gov_1.PERCENTAGE_DECIMALS * sdk_gov_1.PERCENTAGE_FACTOR;
|
|
168
174
|
const r = baseApy + Math.round(Number((apyTotalInPercent * 10n) / sdk_gov_1.WAD) / 10);
|
package/lib/apy/curveAPY.d.ts
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
import { CurveLPToken } from "@gearbox-protocol/sdk-gov/lib/tokens/curveLP";
|
|
2
2
|
import { GearboxToken } from "@gearbox-protocol/sdk-gov/lib/tokens/gear";
|
|
3
|
+
interface CurvePoolData {
|
|
4
|
+
address: string;
|
|
5
|
+
amplificationCoefficient: string;
|
|
6
|
+
assetType?: string;
|
|
7
|
+
assetTypeName: string;
|
|
8
|
+
coins: Array<{
|
|
9
|
+
address: string;
|
|
10
|
+
decimals: string;
|
|
11
|
+
isBasePoolLpToken: boolean;
|
|
12
|
+
poolBalance: string;
|
|
13
|
+
symbol: string;
|
|
14
|
+
usdPrice: number;
|
|
15
|
+
}>;
|
|
16
|
+
coinsAddresses: Array<string>;
|
|
17
|
+
decimals: Array<string>;
|
|
18
|
+
gaugeAddress: string;
|
|
19
|
+
gaugeCrvApy: Array<number>;
|
|
20
|
+
gaugeRewards: Array<{
|
|
21
|
+
apy: number;
|
|
22
|
+
decimals: string;
|
|
23
|
+
gaugeAddress: string;
|
|
24
|
+
name: string;
|
|
25
|
+
symbol: string;
|
|
26
|
+
tokenAddress: string;
|
|
27
|
+
tokenPrice: number;
|
|
28
|
+
}>;
|
|
29
|
+
id: string;
|
|
30
|
+
implementation: string;
|
|
31
|
+
implementationAddress: string;
|
|
32
|
+
isMetaPool: boolean;
|
|
33
|
+
lpTokenAddress: string;
|
|
34
|
+
name: string;
|
|
35
|
+
poolUrls: {
|
|
36
|
+
deposit: Array<string>;
|
|
37
|
+
swap: Array<string>;
|
|
38
|
+
withdraw: Array<string>;
|
|
39
|
+
};
|
|
40
|
+
priceOracle: number;
|
|
41
|
+
symbol: string;
|
|
42
|
+
totalSupply: string;
|
|
43
|
+
usdTotal: number;
|
|
44
|
+
usdTotalExcludingBasePool: number;
|
|
45
|
+
virtualPrice: string;
|
|
46
|
+
}
|
|
3
47
|
type CurveAPYTokens = CurveLPToken | GearboxToken;
|
|
4
48
|
interface CurveAPY {
|
|
5
49
|
base: number;
|
|
@@ -8,4 +52,5 @@ interface CurveAPY {
|
|
|
8
52
|
}
|
|
9
53
|
export type CurveAPYResult = Record<CurveAPYTokens, CurveAPY>;
|
|
10
54
|
export declare function getCurveAPY(): Promise<CurveAPYResult>;
|
|
55
|
+
export declare function getCurveGearPool(): Promise<CurvePoolData | undefined>;
|
|
11
56
|
export {};
|
package/lib/apy/curveAPY.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getCurveAPY = void 0;
|
|
6
|
+
exports.getCurveGearPool = exports.getCurveAPY = void 0;
|
|
7
7
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
9
|
const APY_DICTIONARY = {
|
|
@@ -80,3 +80,17 @@ exports.getCurveAPY = getCurveAPY;
|
|
|
80
80
|
function curveAPYToBn(baseApy) {
|
|
81
81
|
return Math.round(baseApy * Number(sdk_gov_1.PERCENTAGE_FACTOR));
|
|
82
82
|
}
|
|
83
|
+
async function getCurveGearPool() {
|
|
84
|
+
const data = await Promise.all([
|
|
85
|
+
axios_1.default.get(CURVE_FACTORY_CRYPTO_URL),
|
|
86
|
+
]);
|
|
87
|
+
const poolDataByID = Object.fromEntries(data
|
|
88
|
+
.map(resp => {
|
|
89
|
+
const { poolData = [] } = resp?.data?.data || {};
|
|
90
|
+
return poolData.map(p => [p.id, p]);
|
|
91
|
+
})
|
|
92
|
+
.flat(1));
|
|
93
|
+
const gearPool = poolDataByID[APY_DICTIONARY.GEAR];
|
|
94
|
+
return gearPool;
|
|
95
|
+
}
|
|
96
|
+
exports.getCurveGearPool = getCurveGearPool;
|
package/lib/apy/defiLamaAPY.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getDefiLamaAPY = void 0;
|
|
7
7
|
const sdk_gov_1 = require("@gearbox-protocol/sdk-gov");
|
|
8
8
|
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const LAMA_URL = "https://
|
|
9
|
+
const LAMA_URL = "https://charts-server.fly.dev/api/defillama?ids=";
|
|
10
10
|
async function getDefiLamaAPY(networkType) {
|
|
11
11
|
try {
|
|
12
12
|
const currentNormal = NORMAL_TO_LAMA[networkType];
|
package/lib/apy/lidoAPY.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { PartialRecord } from "@gearbox-protocol/sdk-gov";
|
|
2
2
|
import { TokensWithAPY } from ".";
|
|
3
|
-
export
|
|
3
|
+
export type LidoAPYResult = PartialRecord<Extract<TokensWithAPY, "STETH" | "wstETH">, number>;
|
|
4
|
+
export declare function getLidoAPY(): Promise<LidoAPYResult>;
|
package/lib/core/rewardConvex.js
CHANGED
|
@@ -7,6 +7,8 @@ const types_1 = require("../types");
|
|
|
7
7
|
class RewardConvex {
|
|
8
8
|
static poolInterface = types_1.IBaseRewardPool__factory.createInterface();
|
|
9
9
|
static async findRewards(ca, cm, network, provider) {
|
|
10
|
+
if (network !== "Mainnet")
|
|
11
|
+
return [];
|
|
10
12
|
const { calls, distribution } = RewardConvex.prepareMultiCalls(ca.addr, cm, network);
|
|
11
13
|
const mcalls = calls;
|
|
12
14
|
mcalls.push({
|