@gearbox-protocol/sdk 13.3.2 → 13.4.0-beta.1
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/dist/cjs/rewards/rewards/api.js +4 -124
- package/dist/cjs/rewards/rewards/extra-apy.js +5 -7
- package/dist/cjs/rewards/rewards/index.js +1 -5
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +152 -175
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +25 -30
- package/dist/cjs/sdk/accounts/multicall-utils.js +91 -0
- package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
- package/dist/esm/rewards/rewards/api.js +4 -124
- package/dist/esm/rewards/rewards/extra-apy.js +4 -6
- package/dist/esm/rewards/rewards/index.js +0 -2
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +157 -176
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +25 -30
- package/dist/esm/sdk/accounts/multicall-utils.js +69 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +6 -0
- package/dist/types/rewards/rewards/api.d.ts +5 -28
- package/dist/types/rewards/rewards/extra-apy.d.ts +1 -1
- package/dist/types/rewards/rewards/index.d.ts +0 -2
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +40 -18
- package/dist/types/sdk/accounts/multicall-utils.d.ts +39 -0
- package/dist/types/sdk/accounts/types.d.ts +24 -14
- package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +1 -0
- package/package.json +2 -1
- package/dist/cjs/rewards/rewards/apy.js +0 -177
- package/dist/esm/rewards/rewards/apy.js +0 -160
- package/dist/types/rewards/rewards/apy.d.ts +0 -44
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Address
|
|
1
|
+
import type { Address } from "viem";
|
|
2
2
|
import { type NetworkType } from "../../sdk/index.js";
|
|
3
|
-
import type { PoolData
|
|
3
|
+
import type { PoolData } from "./common.js";
|
|
4
4
|
export interface GearboxExtraMerkleLmReward {
|
|
5
5
|
pool: Address;
|
|
6
6
|
poolToken: Address;
|
|
@@ -10,40 +10,17 @@ export interface GearboxExtraMerkleLmReward {
|
|
|
10
10
|
amount: bigint;
|
|
11
11
|
type: "extraMerkle";
|
|
12
12
|
}
|
|
13
|
-
export
|
|
14
|
-
pool: Address;
|
|
15
|
-
poolToken: Address;
|
|
16
|
-
rewardTokenSymbol: string;
|
|
17
|
-
rewardTokenDecimals: number;
|
|
18
|
-
rewardToken: Address;
|
|
19
|
-
amount: bigint;
|
|
20
|
-
type: "stakedV3";
|
|
21
|
-
}
|
|
22
|
-
export type GearboxLmReward = GearboxStakedV3LmReward | GearboxExtraMerkleLmReward;
|
|
13
|
+
export type GearboxLmReward = GearboxExtraMerkleLmReward;
|
|
23
14
|
type ReportHandler = (e: unknown, description?: string) => void;
|
|
24
|
-
export interface GetLmRewardsV3Props {
|
|
25
|
-
pools: Record<`0x${string}`, PoolData>;
|
|
26
|
-
tokensList: Record<Address, TokenData>;
|
|
27
|
-
account: Address;
|
|
28
|
-
provider: PublicClient;
|
|
29
|
-
reportError?: ReportHandler;
|
|
30
|
-
}
|
|
31
15
|
export interface GetLmRewardsMerkleProps {
|
|
32
16
|
pools: Record<Address, PoolData>;
|
|
33
17
|
account: Address;
|
|
34
18
|
network: NetworkType;
|
|
35
19
|
reportError?: ReportHandler;
|
|
36
20
|
}
|
|
37
|
-
export
|
|
38
|
-
reward: GearboxStakedV3LmReward;
|
|
39
|
-
account: Address;
|
|
40
|
-
signer: WalletClient;
|
|
41
|
-
}
|
|
42
|
-
export declare class GearboxRewardsApi {
|
|
21
|
+
export declare class RewardAmountAPI {
|
|
43
22
|
private constructor();
|
|
44
|
-
static
|
|
45
|
-
static getLmRewardsMerkle({ pools, account, network, reportError, }: GetLmRewardsMerkleProps): Promise<GearboxLmReward[]>;
|
|
23
|
+
static getLmRewardsMerkle({ pools, account, network, reportError, }: GetLmRewardsMerkleProps): Promise<GearboxExtraMerkleLmReward[]>;
|
|
46
24
|
private static extractFulfilled;
|
|
47
|
-
static claimLmRewardsV3({ reward, signer, account, }: ClaimLmRewardsV3Props): Promise<`0x${string}`>;
|
|
48
25
|
}
|
|
49
26
|
export {};
|
|
@@ -20,7 +20,7 @@ export type PoolPointsBase = Record<Address, Array<{
|
|
|
20
20
|
points: bigint;
|
|
21
21
|
}>>;
|
|
22
22
|
export declare function getKeyForPoolPointsInfo(i: PoolPointsInfo<string>): string;
|
|
23
|
-
export declare class
|
|
23
|
+
export declare class PoolPointsAPI {
|
|
24
24
|
private constructor();
|
|
25
25
|
static getTotalTokensOnProtocol({ tokensToCheck, tokensList, network, }: GetTotalTokensOnProtocolProps): Promise<[`0x${string}`, PromiseSettledResult<Asset>][]>;
|
|
26
26
|
private static getTokenTotal;
|
|
@@ -2,9 +2,9 @@ import type { Address } from "viem";
|
|
|
2
2
|
import type { CreditAccountData } from "../base/index.js";
|
|
3
3
|
import { SDKConstruct } from "../base/index.js";
|
|
4
4
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { PriceUpdateV310, UpdatePriceFeedsResult } from "../market/index.js";
|
|
6
6
|
import { type Asset, type RouterCASlice } from "../router/index.js";
|
|
7
|
-
import type { MultiCall } from "../types/index.js";
|
|
7
|
+
import type { MultiCall, RawTx } from "../types/index.js";
|
|
8
8
|
import type { AccountToCheck, AddCollateralProps, ChangeDeptProps, ClaimDelayedProps, CloseCreditAccountProps, CloseCreditAccountResult, CreditAccountOperationResult, ExecuteSwapProps, FullyLiquidateProps, FullyLiquidateResult, GetConnectedBotsResult, GetConnectedMigrationBotsResult, GetCreditAccountsOptions, GetPendingWithdrawalsProps, GetPendingWithdrawalsResult, OpenCAProps, PermitResult, PrepareUpdateQuotasProps, PreviewDelayedWithdrawalProps, PreviewDelayedWithdrawalResult, PriceUpdatesOptions, Rewards, StartDelayedWithdrawalProps, UpdateQuotasProps } from "./types.js";
|
|
9
9
|
export interface CreditAccountServiceOptions {
|
|
10
10
|
batchSize?: number;
|
|
@@ -177,30 +177,52 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
177
177
|
* @param ca
|
|
178
178
|
*/
|
|
179
179
|
getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
|
|
180
|
-
/**
|
|
181
|
-
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
182
|
-
*
|
|
183
|
-
* This can be used by batch liquidator
|
|
184
|
-
* @param accounts
|
|
185
|
-
* @returns
|
|
186
|
-
*/
|
|
187
|
-
getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
|
|
188
180
|
protected getUpdateForAccount(options: PriceUpdatesOptions): Promise<UpdatePriceFeedsResult>;
|
|
189
181
|
/**
|
|
190
182
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
191
183
|
* @param options
|
|
192
184
|
* @returns
|
|
193
185
|
*/
|
|
194
|
-
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<
|
|
186
|
+
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<PriceUpdateV310[]>;
|
|
195
187
|
/**
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* @param
|
|
201
|
-
* @
|
|
188
|
+
* Analyzes a multicall array and prepends necessary on-demand price feed updates.
|
|
189
|
+
*
|
|
190
|
+
* Deduplicates existing `onDemandPriceUpdates` calls
|
|
191
|
+
*
|
|
192
|
+
* @param creditManager - Address of the credit manager
|
|
193
|
+
* @param calls - The multicall array to prepend price updates to
|
|
194
|
+
* @param ca - Credit account slice, undefined when opening a new account
|
|
195
|
+
* @param options - Optional settings for price update generation
|
|
196
|
+
* @returns A new array with a single consolidated price update call prepended,
|
|
197
|
+
* followed by the non-price-update calls in their original order
|
|
198
|
+
*/
|
|
199
|
+
protected prependPriceUpdates(creditManager: Address, calls: MultiCall[], ca?: RouterCASlice, options?: {
|
|
200
|
+
ignoreReservePrices?: boolean;
|
|
201
|
+
}): Promise<MultiCall[]>;
|
|
202
|
+
/**
|
|
203
|
+
* Executes a multicall on a credit account, automatically prepending
|
|
204
|
+
* necessary on-demand price feed updates.
|
|
205
|
+
*
|
|
206
|
+
* @param creditAccount - Credit account to execute multicall on
|
|
207
|
+
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
208
|
+
* @param options - Optional settings for price update generation
|
|
209
|
+
* @returns Raw transaction ready to be signed and sent
|
|
202
210
|
*/
|
|
203
|
-
|
|
211
|
+
multicall(creditAccount: RouterCASlice, calls: MultiCall[], options?: {
|
|
212
|
+
ignoreReservePrices?: boolean;
|
|
213
|
+
}): Promise<RawTx>;
|
|
214
|
+
/**
|
|
215
|
+
* Executes a bot multicall on a credit account, automatically prepending
|
|
216
|
+
* necessary on-demand price feed updates.
|
|
217
|
+
*
|
|
218
|
+
* @param creditAccount - Credit account to execute bot multicall on
|
|
219
|
+
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
220
|
+
* @param options - Optional settings for price update generation
|
|
221
|
+
* @returns Raw transaction ready to be signed and sent
|
|
222
|
+
*/
|
|
223
|
+
botMulticall(creditAccount: RouterCASlice, calls: MultiCall[], options?: {
|
|
224
|
+
ignoreReservePrices?: boolean;
|
|
225
|
+
}): Promise<RawTx>;
|
|
204
226
|
protected prepareDisableQuotas(ca: RouterCASlice): Array<MultiCall>;
|
|
205
227
|
protected prepareUpdateQuotas(creditFacade: Address, { averageQuota, minQuota }: PrepareUpdateQuotasProps): Array<MultiCall>;
|
|
206
228
|
protected prepareDecreaseDebt(ca: RouterCASlice): Array<MultiCall>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { PriceUpdateV310 } from "../market/pricefeeds/types.js";
|
|
2
|
+
import type { MultiCall } from "../types/index.js";
|
|
3
|
+
import { AddressSet } from "../utils/AddressSet.js";
|
|
4
|
+
/**
|
|
5
|
+
* Splits a multicall array into existing price-update data and remaining calls.
|
|
6
|
+
*
|
|
7
|
+
* All `onDemandPriceUpdates` entries are decoded and their {@link PriceUpdate}
|
|
8
|
+
* tuples are collected into a flat array. The remaining (non-price-update)
|
|
9
|
+
* calls are returned in their original order.
|
|
10
|
+
*
|
|
11
|
+
* @param calls - Array of multicall entries to split
|
|
12
|
+
* @returns Object with `priceUpdates` (decoded price update tuples) and
|
|
13
|
+
* `remainingCalls` (everything else, preserving order)
|
|
14
|
+
*/
|
|
15
|
+
export declare function extractPriceUpdates(calls: MultiCall[]): {
|
|
16
|
+
priceUpdates: PriceUpdateV310[];
|
|
17
|
+
remainingCalls: MultiCall[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Extracts token addresses from `updateQuota` calls that have a positive `quotaChange`.
|
|
21
|
+
*
|
|
22
|
+
* Only tokens whose quota is being increased (i.e. `quotaChange > 0`) are
|
|
23
|
+
* returned, since those are the tokens that require fresh price feed data.
|
|
24
|
+
*
|
|
25
|
+
* @param calls - Array of multicall entries to scan
|
|
26
|
+
* @returns Unique token addresses from positive-change quota updates
|
|
27
|
+
*/
|
|
28
|
+
export declare function extractQuotaTokens(calls: MultiCall[]): AddressSet;
|
|
29
|
+
/**
|
|
30
|
+
* Merges two {@link PriceUpdate} arrays, deduplicating by `priceFeed` address.
|
|
31
|
+
*
|
|
32
|
+
* When both arrays contain an update for the same price feed, the entry from
|
|
33
|
+
* `existing` takes priority (the caller explicitly included it).
|
|
34
|
+
*
|
|
35
|
+
* @param existing - Price updates already present in the multicall
|
|
36
|
+
* @param generated - Newly generated price updates to merge in
|
|
37
|
+
* @returns Merged array with no duplicate `priceFeed` addresses
|
|
38
|
+
*/
|
|
39
|
+
export declare function mergePriceUpdates(existing: PriceUpdateV310[], generated: PriceUpdateV310[]): PriceUpdateV310[];
|
|
@@ -3,7 +3,7 @@ import type { creditAccountCompressorAbi } from "../../abi/compressors/creditAcc
|
|
|
3
3
|
import type { iWithdrawalCompressorV310Abi } from "../../abi/IWithdrawalCompressorV310.js";
|
|
4
4
|
import type { ConnectedBotData, Construct, CreditAccountData } from "../base/index.js";
|
|
5
5
|
import type { GearboxSDK } from "../GearboxSDK.js";
|
|
6
|
-
import type { CreditSuite,
|
|
6
|
+
import type { CreditSuite, PriceUpdateV310 } from "../market/index.js";
|
|
7
7
|
import type { Asset, CreditAccountTokensSlice, RouterCASlice, RouterCloseResult } from "../router/index.js";
|
|
8
8
|
import type { MultiCall, RawTx } from "../types/index.js";
|
|
9
9
|
export type GetCreditAccountsArgs = ContractFunctionArgs<typeof creditAccountCompressorAbi, "pure" | "view", "getCreditAccounts">;
|
|
@@ -554,26 +554,36 @@ export interface ICreditAccountsService extends Construct {
|
|
|
554
554
|
* @param ca
|
|
555
555
|
*/
|
|
556
556
|
getOptimalHFForPartialLiquidation(ca: CreditAccountData): bigint;
|
|
557
|
-
/**
|
|
558
|
-
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
|
|
559
|
-
*
|
|
560
|
-
* This can be used by batch liquidator
|
|
561
|
-
* @param accounts
|
|
562
|
-
* @returns
|
|
563
|
-
*/
|
|
564
|
-
getUpdateForAccounts(accounts: Array<RouterCASlice>): Promise<UpdatePriceFeedsResult>;
|
|
565
557
|
/**
|
|
566
558
|
* Returns account price updates that can be used in credit facade multicall or liquidator calls
|
|
567
559
|
* @param options
|
|
568
560
|
* @returns
|
|
569
561
|
*/
|
|
570
|
-
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<
|
|
562
|
+
getOnDemandPriceUpdates(options: PriceUpdatesOptions): Promise<PriceUpdateV310[]>;
|
|
571
563
|
/**
|
|
572
|
-
*
|
|
573
|
-
*
|
|
574
|
-
*
|
|
564
|
+
* Executes a multicall on a credit account, automatically prepending
|
|
565
|
+
* necessary on-demand price feed updates inferred from the calls array.
|
|
566
|
+
*
|
|
567
|
+
* @param creditAccount - Credit account to execute multicall on
|
|
568
|
+
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
569
|
+
* @param options - Optional settings for price update generation
|
|
570
|
+
* @returns Raw transaction ready to be signed and sent
|
|
575
571
|
*/
|
|
576
|
-
|
|
572
|
+
multicall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
|
|
573
|
+
ignoreReservePrices?: boolean;
|
|
574
|
+
}): Promise<RawTx>;
|
|
575
|
+
/**
|
|
576
|
+
* Executes a bot multicall on a credit account, automatically prepending
|
|
577
|
+
* necessary on-demand price feed updates inferred from the calls array.
|
|
578
|
+
*
|
|
579
|
+
* @param creditAccount - Credit account to execute bot multicall on
|
|
580
|
+
* @param calls - Array of multicall operations (price updates will be inferred)
|
|
581
|
+
* @param options - Optional settings for price update generation
|
|
582
|
+
* @returns Raw transaction ready to be signed and sent
|
|
583
|
+
*/
|
|
584
|
+
botMulticall(creditAccount: RouterCASlice, calls: Array<MultiCall>, options?: {
|
|
585
|
+
ignoreReservePrices?: boolean;
|
|
586
|
+
}): Promise<RawTx>;
|
|
577
587
|
/**
|
|
578
588
|
* Withdraws a single collateral from credit account to wallet to and updates quotas;
|
|
579
589
|
* technically can withdraw several tokens at once
|
|
@@ -14,6 +14,7 @@ export declare class CreditFacadeV310Contract extends CreditFacadeV310BaseContra
|
|
|
14
14
|
liquidateCreditAccount(ca: Address, to: Address, calls: MultiCall[], lossPolicyData?: Hex): RawTx;
|
|
15
15
|
closeCreditAccount(ca: Address, calls: MultiCall[]): RawTx;
|
|
16
16
|
multicall(ca: Address, calls: MultiCall[]): RawTx;
|
|
17
|
+
botMulticall(ca: Address, calls: MultiCall[]): RawTx;
|
|
17
18
|
openCreditAccount(to: Address, calls: MultiCall[], referralCode: bigint): RawTx;
|
|
18
19
|
}
|
|
19
20
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gearbox-protocol/sdk",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.4.0-beta.1",
|
|
4
4
|
"description": "Gearbox SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/cjs/sdk/index.js",
|
|
@@ -103,6 +103,7 @@
|
|
|
103
103
|
"tsx": "^4.21.0",
|
|
104
104
|
"typescript": "^5.9.3",
|
|
105
105
|
"viem-deal": "^2.0.4",
|
|
106
|
+
"vite": "^8.0.3",
|
|
106
107
|
"vitest": "^4.1.2"
|
|
107
108
|
},
|
|
108
109
|
"peerDependencies": {
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var apy_exports = {};
|
|
20
|
-
__export(apy_exports, {
|
|
21
|
-
GearboxRewardsApy: () => GearboxRewardsApy
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(apy_exports);
|
|
24
|
-
var import_common_utils = require("../../common-utils/index.js");
|
|
25
|
-
var import_sdk = require("../../sdk/index.js");
|
|
26
|
-
const PERCENTAGE_FACTOR_1KK = import_sdk.PERCENTAGE_DECIMALS * import_sdk.PERCENTAGE_FACTOR;
|
|
27
|
-
const ONE = PERCENTAGE_FACTOR_1KK * 10n;
|
|
28
|
-
class GearboxRewardsApy {
|
|
29
|
-
constructor() {
|
|
30
|
-
}
|
|
31
|
-
static getPoolExtraAPY_V3({
|
|
32
|
-
rewardPoolsInfo,
|
|
33
|
-
stakedDieselToken,
|
|
34
|
-
...restProps
|
|
35
|
-
}) {
|
|
36
|
-
const { version } = restProps.pool;
|
|
37
|
-
const isV3 = version >= 300 && version < 400;
|
|
38
|
-
if (!isV3 || !stakedDieselToken) return [];
|
|
39
|
-
const info = rewardPoolsInfo[stakedDieselToken];
|
|
40
|
-
if (!info) return [];
|
|
41
|
-
const extra = (Array.isArray(info) ? info : [info]).map(
|
|
42
|
-
(inf) => GearboxRewardsApy.getPoolSingleExtraLmAPY_V3({
|
|
43
|
-
...restProps,
|
|
44
|
-
stakedDieselToken,
|
|
45
|
-
rewardPoolsInfo: inf
|
|
46
|
-
})
|
|
47
|
-
);
|
|
48
|
-
return extra;
|
|
49
|
-
}
|
|
50
|
-
static getPoolSingleExtraLmAPY_V3({
|
|
51
|
-
stakedDieselToken,
|
|
52
|
-
pool,
|
|
53
|
-
prices,
|
|
54
|
-
rewardPoolsInfo,
|
|
55
|
-
rewardPoolsSupply,
|
|
56
|
-
tokensList,
|
|
57
|
-
currentTimestamp
|
|
58
|
-
}) {
|
|
59
|
-
const { underlyingToken, dieselRateRay } = pool;
|
|
60
|
-
const safeSupply = rewardPoolsSupply[stakedDieselToken] ?? 0n;
|
|
61
|
-
const { decimals: underlyingDecimals = 18 } = tokensList[underlyingToken] || {};
|
|
62
|
-
const underlyingPrice = prices[underlyingToken] ?? 0n;
|
|
63
|
-
const dieselPrice = underlyingPrice * dieselRateRay / import_sdk.RAY;
|
|
64
|
-
const rewardAddress = rewardPoolsInfo?.token || "";
|
|
65
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
66
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
67
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
68
|
-
currentTimestamp,
|
|
69
|
-
info: rewardPoolsInfo,
|
|
70
|
-
supply: {
|
|
71
|
-
amount: safeSupply,
|
|
72
|
-
decimals: underlyingDecimals,
|
|
73
|
-
price: dieselPrice
|
|
74
|
-
},
|
|
75
|
-
reward: {
|
|
76
|
-
price: rewardPrice,
|
|
77
|
-
decimals: rewardDecimals
|
|
78
|
-
}
|
|
79
|
-
}) / Number(import_sdk.PERCENTAGE_FACTOR);
|
|
80
|
-
return {
|
|
81
|
-
token: stakedDieselToken,
|
|
82
|
-
balance: null,
|
|
83
|
-
apy: r,
|
|
84
|
-
rewardToken: rewardAddress,
|
|
85
|
-
rewardTokenSymbol: rewardPoolsInfo.symbol
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
static calculateAPY_V3({
|
|
89
|
-
info,
|
|
90
|
-
supply,
|
|
91
|
-
reward,
|
|
92
|
-
currentTimestamp
|
|
93
|
-
}) {
|
|
94
|
-
const finished = info.finished <= currentTimestamp;
|
|
95
|
-
if (finished) return 0;
|
|
96
|
-
if (supply.amount <= 0n) return 0;
|
|
97
|
-
if (supply.price === 0n || reward.price === 0n) return 0;
|
|
98
|
-
if (info.duration === 0n) return 0;
|
|
99
|
-
const supplyMoney = import_common_utils.PriceUtils.calcTotalPrice(
|
|
100
|
-
supply.price,
|
|
101
|
-
supply.amount,
|
|
102
|
-
supply.decimals
|
|
103
|
-
);
|
|
104
|
-
const rewardMoney = import_common_utils.PriceUtils.calcTotalPrice(
|
|
105
|
-
reward.price,
|
|
106
|
-
info.reward,
|
|
107
|
-
reward.decimals
|
|
108
|
-
);
|
|
109
|
-
const durationRatio = (0, import_sdk.toBigInt)(import_sdk.SECONDS_PER_YEAR) * import_sdk.WAD / info.duration;
|
|
110
|
-
const apyBn = rewardMoney * ONE / supplyMoney * durationRatio / import_sdk.WAD;
|
|
111
|
-
return Math.round(Number(apyBn) / 10);
|
|
112
|
-
}
|
|
113
|
-
static getCAExtraAPY_V3({
|
|
114
|
-
rewardInfo,
|
|
115
|
-
assets,
|
|
116
|
-
...restProps
|
|
117
|
-
}) {
|
|
118
|
-
const extra = assets.reduce(
|
|
119
|
-
(acc, asset) => {
|
|
120
|
-
const { token } = asset;
|
|
121
|
-
const info = rewardInfo[token || ""];
|
|
122
|
-
if (!info || info.length === 0) return acc;
|
|
123
|
-
const extra2 = info.map(
|
|
124
|
-
(inf) => GearboxRewardsApy.getCASingleExtraAPY_V3({
|
|
125
|
-
...restProps,
|
|
126
|
-
asset,
|
|
127
|
-
rewardInfo: inf
|
|
128
|
-
})
|
|
129
|
-
);
|
|
130
|
-
acc.push(...extra2);
|
|
131
|
-
return acc;
|
|
132
|
-
},
|
|
133
|
-
[]
|
|
134
|
-
);
|
|
135
|
-
return extra;
|
|
136
|
-
}
|
|
137
|
-
static getCASingleExtraAPY_V3({
|
|
138
|
-
asset,
|
|
139
|
-
prices,
|
|
140
|
-
rewardInfo,
|
|
141
|
-
supply,
|
|
142
|
-
tokensList,
|
|
143
|
-
currentTimestamp
|
|
144
|
-
}) {
|
|
145
|
-
const { token, balance } = asset;
|
|
146
|
-
const safeSupply = supply[token] ?? 0n;
|
|
147
|
-
const { decimals: tokenDecimals = 18 } = tokensList[token] || {};
|
|
148
|
-
const tokenPrice = prices[token] ?? 0n;
|
|
149
|
-
const rewardAddress = rewardInfo?.token || "";
|
|
150
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
151
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
152
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
153
|
-
currentTimestamp,
|
|
154
|
-
info: rewardInfo,
|
|
155
|
-
supply: {
|
|
156
|
-
amount: typeof safeSupply === "bigint" ? safeSupply : safeSupply.balance,
|
|
157
|
-
decimals: tokenDecimals,
|
|
158
|
-
price: tokenPrice
|
|
159
|
-
},
|
|
160
|
-
reward: {
|
|
161
|
-
price: rewardPrice,
|
|
162
|
-
decimals: rewardDecimals
|
|
163
|
-
}
|
|
164
|
-
}) / Number(import_sdk.PERCENTAGE_FACTOR);
|
|
165
|
-
return {
|
|
166
|
-
token,
|
|
167
|
-
balance,
|
|
168
|
-
apy: r,
|
|
169
|
-
rewardToken: rewardAddress,
|
|
170
|
-
rewardTokenSymbol: rewardInfo.symbol
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 && (module.exports = {
|
|
176
|
-
GearboxRewardsApy
|
|
177
|
-
});
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import { PriceUtils } from "../../common-utils/index.js";
|
|
2
|
-
import {
|
|
3
|
-
PERCENTAGE_DECIMALS,
|
|
4
|
-
PERCENTAGE_FACTOR,
|
|
5
|
-
RAY,
|
|
6
|
-
SECONDS_PER_YEAR,
|
|
7
|
-
toBigInt,
|
|
8
|
-
WAD
|
|
9
|
-
} from "../../sdk/index.js";
|
|
10
|
-
const PERCENTAGE_FACTOR_1KK = PERCENTAGE_DECIMALS * PERCENTAGE_FACTOR;
|
|
11
|
-
const ONE = PERCENTAGE_FACTOR_1KK * 10n;
|
|
12
|
-
class GearboxRewardsApy {
|
|
13
|
-
constructor() {
|
|
14
|
-
}
|
|
15
|
-
static getPoolExtraAPY_V3({
|
|
16
|
-
rewardPoolsInfo,
|
|
17
|
-
stakedDieselToken,
|
|
18
|
-
...restProps
|
|
19
|
-
}) {
|
|
20
|
-
const { version } = restProps.pool;
|
|
21
|
-
const isV3 = version >= 300 && version < 400;
|
|
22
|
-
if (!isV3 || !stakedDieselToken) return [];
|
|
23
|
-
const info = rewardPoolsInfo[stakedDieselToken];
|
|
24
|
-
if (!info) return [];
|
|
25
|
-
const extra = (Array.isArray(info) ? info : [info]).map(
|
|
26
|
-
(inf) => GearboxRewardsApy.getPoolSingleExtraLmAPY_V3({
|
|
27
|
-
...restProps,
|
|
28
|
-
stakedDieselToken,
|
|
29
|
-
rewardPoolsInfo: inf
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
return extra;
|
|
33
|
-
}
|
|
34
|
-
static getPoolSingleExtraLmAPY_V3({
|
|
35
|
-
stakedDieselToken,
|
|
36
|
-
pool,
|
|
37
|
-
prices,
|
|
38
|
-
rewardPoolsInfo,
|
|
39
|
-
rewardPoolsSupply,
|
|
40
|
-
tokensList,
|
|
41
|
-
currentTimestamp
|
|
42
|
-
}) {
|
|
43
|
-
const { underlyingToken, dieselRateRay } = pool;
|
|
44
|
-
const safeSupply = rewardPoolsSupply[stakedDieselToken] ?? 0n;
|
|
45
|
-
const { decimals: underlyingDecimals = 18 } = tokensList[underlyingToken] || {};
|
|
46
|
-
const underlyingPrice = prices[underlyingToken] ?? 0n;
|
|
47
|
-
const dieselPrice = underlyingPrice * dieselRateRay / RAY;
|
|
48
|
-
const rewardAddress = rewardPoolsInfo?.token || "";
|
|
49
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
50
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
51
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
52
|
-
currentTimestamp,
|
|
53
|
-
info: rewardPoolsInfo,
|
|
54
|
-
supply: {
|
|
55
|
-
amount: safeSupply,
|
|
56
|
-
decimals: underlyingDecimals,
|
|
57
|
-
price: dieselPrice
|
|
58
|
-
},
|
|
59
|
-
reward: {
|
|
60
|
-
price: rewardPrice,
|
|
61
|
-
decimals: rewardDecimals
|
|
62
|
-
}
|
|
63
|
-
}) / Number(PERCENTAGE_FACTOR);
|
|
64
|
-
return {
|
|
65
|
-
token: stakedDieselToken,
|
|
66
|
-
balance: null,
|
|
67
|
-
apy: r,
|
|
68
|
-
rewardToken: rewardAddress,
|
|
69
|
-
rewardTokenSymbol: rewardPoolsInfo.symbol
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
static calculateAPY_V3({
|
|
73
|
-
info,
|
|
74
|
-
supply,
|
|
75
|
-
reward,
|
|
76
|
-
currentTimestamp
|
|
77
|
-
}) {
|
|
78
|
-
const finished = info.finished <= currentTimestamp;
|
|
79
|
-
if (finished) return 0;
|
|
80
|
-
if (supply.amount <= 0n) return 0;
|
|
81
|
-
if (supply.price === 0n || reward.price === 0n) return 0;
|
|
82
|
-
if (info.duration === 0n) return 0;
|
|
83
|
-
const supplyMoney = PriceUtils.calcTotalPrice(
|
|
84
|
-
supply.price,
|
|
85
|
-
supply.amount,
|
|
86
|
-
supply.decimals
|
|
87
|
-
);
|
|
88
|
-
const rewardMoney = PriceUtils.calcTotalPrice(
|
|
89
|
-
reward.price,
|
|
90
|
-
info.reward,
|
|
91
|
-
reward.decimals
|
|
92
|
-
);
|
|
93
|
-
const durationRatio = toBigInt(SECONDS_PER_YEAR) * WAD / info.duration;
|
|
94
|
-
const apyBn = rewardMoney * ONE / supplyMoney * durationRatio / WAD;
|
|
95
|
-
return Math.round(Number(apyBn) / 10);
|
|
96
|
-
}
|
|
97
|
-
static getCAExtraAPY_V3({
|
|
98
|
-
rewardInfo,
|
|
99
|
-
assets,
|
|
100
|
-
...restProps
|
|
101
|
-
}) {
|
|
102
|
-
const extra = assets.reduce(
|
|
103
|
-
(acc, asset) => {
|
|
104
|
-
const { token } = asset;
|
|
105
|
-
const info = rewardInfo[token || ""];
|
|
106
|
-
if (!info || info.length === 0) return acc;
|
|
107
|
-
const extra2 = info.map(
|
|
108
|
-
(inf) => GearboxRewardsApy.getCASingleExtraAPY_V3({
|
|
109
|
-
...restProps,
|
|
110
|
-
asset,
|
|
111
|
-
rewardInfo: inf
|
|
112
|
-
})
|
|
113
|
-
);
|
|
114
|
-
acc.push(...extra2);
|
|
115
|
-
return acc;
|
|
116
|
-
},
|
|
117
|
-
[]
|
|
118
|
-
);
|
|
119
|
-
return extra;
|
|
120
|
-
}
|
|
121
|
-
static getCASingleExtraAPY_V3({
|
|
122
|
-
asset,
|
|
123
|
-
prices,
|
|
124
|
-
rewardInfo,
|
|
125
|
-
supply,
|
|
126
|
-
tokensList,
|
|
127
|
-
currentTimestamp
|
|
128
|
-
}) {
|
|
129
|
-
const { token, balance } = asset;
|
|
130
|
-
const safeSupply = supply[token] ?? 0n;
|
|
131
|
-
const { decimals: tokenDecimals = 18 } = tokensList[token] || {};
|
|
132
|
-
const tokenPrice = prices[token] ?? 0n;
|
|
133
|
-
const rewardAddress = rewardInfo?.token || "";
|
|
134
|
-
const { decimals: rewardDecimals = 18 } = tokensList[rewardAddress] || {};
|
|
135
|
-
const rewardPrice = prices[rewardAddress] ?? 0n;
|
|
136
|
-
const r = GearboxRewardsApy.calculateAPY_V3({
|
|
137
|
-
currentTimestamp,
|
|
138
|
-
info: rewardInfo,
|
|
139
|
-
supply: {
|
|
140
|
-
amount: typeof safeSupply === "bigint" ? safeSupply : safeSupply.balance,
|
|
141
|
-
decimals: tokenDecimals,
|
|
142
|
-
price: tokenPrice
|
|
143
|
-
},
|
|
144
|
-
reward: {
|
|
145
|
-
price: rewardPrice,
|
|
146
|
-
decimals: rewardDecimals
|
|
147
|
-
}
|
|
148
|
-
}) / Number(PERCENTAGE_FACTOR);
|
|
149
|
-
return {
|
|
150
|
-
token,
|
|
151
|
-
balance,
|
|
152
|
-
apy: r,
|
|
153
|
-
rewardToken: rewardAddress,
|
|
154
|
-
rewardTokenSymbol: rewardInfo.symbol
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
export {
|
|
159
|
-
GearboxRewardsApy
|
|
160
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { Address } from "viem";
|
|
2
|
-
import { type Asset } from "../../sdk/index.js";
|
|
3
|
-
import type { PoolData, TokenData } from "./common.js";
|
|
4
|
-
interface InnerFarmInfo {
|
|
5
|
-
symbol: string;
|
|
6
|
-
duration: bigint;
|
|
7
|
-
finished: bigint;
|
|
8
|
-
reward: bigint;
|
|
9
|
-
token: Address;
|
|
10
|
-
}
|
|
11
|
-
export interface ExtraRewardApy {
|
|
12
|
-
token: Address;
|
|
13
|
-
balance: bigint | null;
|
|
14
|
-
apy: number;
|
|
15
|
-
rewardToken: Address;
|
|
16
|
-
rewardTokenSymbol: string;
|
|
17
|
-
endTimestamp?: number;
|
|
18
|
-
}
|
|
19
|
-
interface GetPoolExtraAPY_V3Props {
|
|
20
|
-
stakedDieselToken: Address | undefined;
|
|
21
|
-
pool: PoolData;
|
|
22
|
-
prices: Record<Address, bigint>;
|
|
23
|
-
rewardPoolsInfo: Record<Address, Array<InnerFarmInfo>> | Record<Address, InnerFarmInfo>;
|
|
24
|
-
rewardPoolsSupply: Record<Address, bigint>;
|
|
25
|
-
tokensList: Record<Address, TokenData>;
|
|
26
|
-
currentTimestamp: number;
|
|
27
|
-
}
|
|
28
|
-
interface GetCAExtraAPYProps {
|
|
29
|
-
assets: Array<Asset>;
|
|
30
|
-
supply: Record<Address, bigint> | Record<Address, Asset>;
|
|
31
|
-
rewardInfo: Record<Address, Array<InnerFarmInfo>>;
|
|
32
|
-
currentTimestamp: number;
|
|
33
|
-
prices: Record<Address, bigint>;
|
|
34
|
-
tokensList: Record<Address, TokenData>;
|
|
35
|
-
}
|
|
36
|
-
export declare class GearboxRewardsApy {
|
|
37
|
-
private constructor();
|
|
38
|
-
static getPoolExtraAPY_V3({ rewardPoolsInfo, stakedDieselToken, ...restProps }: GetPoolExtraAPY_V3Props): Array<ExtraRewardApy>;
|
|
39
|
-
private static getPoolSingleExtraLmAPY_V3;
|
|
40
|
-
private static calculateAPY_V3;
|
|
41
|
-
static getCAExtraAPY_V3({ rewardInfo, assets, ...restProps }: GetCAExtraAPYProps): Array<ExtraRewardApy>;
|
|
42
|
-
private static getCASingleExtraAPY_V3;
|
|
43
|
-
}
|
|
44
|
-
export {};
|