@gearbox-protocol/sdk 14.5.10 → 14.6.0-next.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/common-utils/utils/apy/bonus-apy-from-points.js +28 -0
- package/dist/cjs/common-utils/utils/apy/calculate-effective-borrow-rate.js +35 -0
- package/dist/cjs/common-utils/utils/apy/get-complex-apy-list.js +45 -0
- package/dist/cjs/common-utils/utils/apy/get-rate-with-fee.js +31 -0
- package/dist/cjs/common-utils/utils/apy/get-single-quota-borrow-rate.js +33 -0
- package/dist/cjs/common-utils/utils/apy/index.js +32 -0
- package/dist/cjs/common-utils/utils/apy/max-apy-formula.js +40 -0
- package/dist/cjs/common-utils/utils/index.js +5 -1
- package/dist/cjs/common-utils/utils/strategies/__test-utils.js +95 -0
- package/dist/cjs/common-utils/utils/strategies/availability/check-boolean.js +33 -0
- package/dist/cjs/common-utils/utils/strategies/availability/check-degen-nft.js +35 -0
- package/dist/cjs/common-utils/utils/strategies/availability/index.js +28 -0
- package/dist/cjs/common-utils/utils/strategies/availability/validate-open-account-pool-quota-status.js +40 -0
- package/dist/cjs/common-utils/utils/strategies/availability/validate-open-account-pool-status.js +76 -0
- package/dist/cjs/common-utils/utils/strategies/index.js +28 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-loss-coefficient.js +31 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +45 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-factor-from-leverage.js +31 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/get-leverage-from-factor.js +31 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/index.js +32 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/max-leverage-threshold.js +42 -0
- package/dist/cjs/common-utils/utils/strategies/leverage/max-leverage.js +35 -0
- package/dist/cjs/common-utils/utils/strategies/sort-strategy-cms-by-availability/index.js +22 -0
- package/dist/cjs/common-utils/utils/strategies/sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.js +64 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +63 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-info.js +98 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.js +102 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/index.js +30 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/is-strategy-cm-disabled.js +33 -0
- package/dist/cjs/common-utils/utils/strategies/strategy-info/types.js +16 -0
- package/dist/esm/common-utils/utils/apy/bonus-apy-from-points.js +4 -0
- package/dist/esm/common-utils/utils/apy/calculate-effective-borrow-rate.js +11 -0
- package/dist/esm/common-utils/utils/apy/get-complex-apy-list.js +21 -0
- package/dist/esm/common-utils/utils/apy/get-rate-with-fee.js +7 -0
- package/dist/esm/common-utils/utils/apy/get-single-quota-borrow-rate.js +9 -0
- package/dist/esm/common-utils/utils/apy/index.js +6 -0
- package/dist/esm/common-utils/utils/apy/max-apy-formula.js +16 -0
- package/dist/esm/common-utils/utils/index.js +2 -0
- package/dist/esm/common-utils/utils/strategies/__test-utils.js +65 -0
- package/dist/esm/common-utils/utils/strategies/availability/check-boolean.js +9 -0
- package/dist/esm/common-utils/utils/strategies/availability/check-degen-nft.js +11 -0
- package/dist/esm/common-utils/utils/strategies/availability/index.js +4 -0
- package/dist/esm/common-utils/utils/strategies/availability/validate-open-account-pool-quota-status.js +16 -0
- package/dist/esm/common-utils/utils/strategies/availability/validate-open-account-pool-status.js +52 -0
- package/dist/esm/common-utils/utils/strategies/index.js +4 -0
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-loss-coefficient.js +7 -0
- package/dist/esm/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.js +21 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-factor-from-leverage.js +7 -0
- package/dist/esm/common-utils/utils/strategies/leverage/get-leverage-from-factor.js +7 -0
- package/dist/esm/common-utils/utils/strategies/leverage/index.js +6 -0
- package/dist/esm/common-utils/utils/strategies/leverage/max-leverage-threshold.js +18 -0
- package/dist/esm/common-utils/utils/strategies/leverage/max-leverage.js +11 -0
- package/dist/esm/common-utils/utils/strategies/sort-strategy-cms-by-availability/index.js +1 -0
- package/dist/esm/common-utils/utils/strategies/sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.js +43 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/cm-availability-condition.js +43 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-info.js +74 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.js +85 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/index.js +5 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/is-strategy-cm-disabled.js +9 -0
- package/dist/esm/common-utils/utils/strategies/strategy-info/types.js +0 -0
- package/dist/types/common-utils/utils/apy/bonus-apy-from-points.d.ts +4 -0
- package/dist/types/common-utils/utils/apy/calculate-effective-borrow-rate.d.ts +6 -0
- package/dist/types/common-utils/utils/apy/get-complex-apy-list.d.ts +5 -0
- package/dist/types/common-utils/utils/apy/get-rate-with-fee.d.ts +7 -0
- package/dist/types/common-utils/utils/apy/get-single-quota-borrow-rate.d.ts +9 -0
- package/dist/types/common-utils/utils/apy/index.d.ts +6 -0
- package/dist/types/common-utils/utils/apy/max-apy-formula.d.ts +6 -0
- package/dist/types/common-utils/utils/index.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/__test-utils.d.ts +11 -0
- package/dist/types/common-utils/utils/strategies/availability/check-boolean.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/availability/check-degen-nft.d.ts +5 -0
- package/dist/types/common-utils/utils/strategies/availability/index.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/availability/validate-open-account-pool-quota-status.d.ts +6 -0
- package/dist/types/common-utils/utils/strategies/availability/validate-open-account-pool-status.d.ts +24 -0
- package/dist/types/common-utils/utils/strategies/index.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/leverage/calculate-loss-coefficient.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/leverage/calculate-max-leverage-factor.d.ts +12 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-factor-from-leverage.d.ts +4 -0
- package/dist/types/common-utils/utils/strategies/leverage/get-leverage-from-factor.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/leverage/index.d.ts +6 -0
- package/dist/types/common-utils/utils/strategies/leverage/max-leverage-threshold.d.ts +5 -0
- package/dist/types/common-utils/utils/strategies/leverage/max-leverage.d.ts +9 -0
- package/dist/types/common-utils/utils/strategies/sort-strategy-cms-by-availability/index.d.ts +1 -0
- package/dist/types/common-utils/utils/strategies/sort-strategy-cms-by-availability/sort-strategy-cms-by-availability.d.ts +13 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/cm-availability-condition.d.ts +3 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-strategy-info.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/get-strategy-max-apy.d.ts +13 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/index.d.ts +5 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/is-strategy-cm-disabled.d.ts +2 -0
- package/dist/types/common-utils/utils/strategies/strategy-info/types.d.ts +80 -0
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./bonus-apy-from-points.js";
|
|
2
|
+
export * from "./calculate-effective-borrow-rate.js";
|
|
3
|
+
export * from "./get-complex-apy-list.js";
|
|
4
|
+
export * from "./get-rate-with-fee.js";
|
|
5
|
+
export * from "./get-single-quota-borrow-rate.js";
|
|
6
|
+
export * from "./max-apy-formula.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CreditManagerSlice, PoolSlice, QuotaSlice, TokenSlice } from "./strategy-info/types.js";
|
|
3
|
+
export declare const mockToken1: Address;
|
|
4
|
+
export declare const mockToken2: Address;
|
|
5
|
+
export declare const mockUnderlyingToken: Address;
|
|
6
|
+
export declare const mockTokenData: Record<Address, TokenSlice>;
|
|
7
|
+
export declare function buildQuota(overrides: Partial<QuotaSlice> & {
|
|
8
|
+
token: Address;
|
|
9
|
+
}): QuotaSlice;
|
|
10
|
+
export declare function buildPool(overrides?: Partial<PoolSlice>): PoolSlice;
|
|
11
|
+
export declare function buildCreditManager(overrides?: Partial<CreditManagerSlice>): CreditManagerSlice;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function checkBoolean(a: boolean, b: boolean): number;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CreditManagerSlice } from "../strategy-info/types.js";
|
|
3
|
+
export declare function validateOpenAccountPoolQuotaStatus(targetToken: Address, creditManager: CreditManagerSlice, amountToBorrow: bigint): {
|
|
4
|
+
readonly message: "insufficientQuota";
|
|
5
|
+
readonly token: `0x${string}`;
|
|
6
|
+
} | null;
|
package/dist/types/common-utils/utils/strategies/availability/validate-open-account-pool-status.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CreditManagerSlice, PoolSlice } from "../strategy-info/types.js";
|
|
3
|
+
export interface ValidateOpenAccountPoolStatusProps {
|
|
4
|
+
creditManager: CreditManagerSlice;
|
|
5
|
+
pool: PoolSlice | undefined | null;
|
|
6
|
+
debt: bigint;
|
|
7
|
+
targetToken: Address | null;
|
|
8
|
+
}
|
|
9
|
+
export declare function validateOpenAccountPoolStatus(props: ValidateOpenAccountPoolStatusProps): {
|
|
10
|
+
readonly message: "insufficientQuota";
|
|
11
|
+
readonly token: `0x${string}`;
|
|
12
|
+
} | {
|
|
13
|
+
readonly message: "insufficientDebtLimit";
|
|
14
|
+
readonly amount: bigint;
|
|
15
|
+
readonly solutionAmount: bigint | undefined;
|
|
16
|
+
} | {
|
|
17
|
+
readonly message: "insufficientPoolDebtLimit";
|
|
18
|
+
readonly amount: bigint;
|
|
19
|
+
readonly solutionAmount: bigint | undefined;
|
|
20
|
+
} | {
|
|
21
|
+
readonly message: "insufficientPoolLiquidity";
|
|
22
|
+
readonly amount: bigint;
|
|
23
|
+
readonly solutionAmount: bigint | undefined;
|
|
24
|
+
} | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function calculateLossCoefficient(slippage: number, constantLoss?: bigint): bigint;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { LeverageFactor } from "./get-factor-from-leverage.js";
|
|
3
|
+
export declare function calculateMaxLeverageFactor({ targetToken, slippage, creditManagers, constantLoss, leverageLimit, }: {
|
|
4
|
+
targetToken: Address;
|
|
5
|
+
slippage: number;
|
|
6
|
+
creditManagers: Array<{
|
|
7
|
+
liquidationThresholds: Record<Address, bigint>;
|
|
8
|
+
address: Address;
|
|
9
|
+
}>;
|
|
10
|
+
constantLoss?: bigint;
|
|
11
|
+
leverageLimit?: number;
|
|
12
|
+
}): LeverageFactor;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./calculate-loss-coefficient.js";
|
|
2
|
+
export * from "./calculate-max-leverage-factor.js";
|
|
3
|
+
export * from "./get-factor-from-leverage.js";
|
|
4
|
+
export * from "./get-leverage-from-factor.js";
|
|
5
|
+
export * from "./max-leverage.js";
|
|
6
|
+
export * from "./max-leverage-threshold.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* Max leverage factor (not leverage value) for a token across CMs.
|
|
4
|
+
* Returns a factor where leverage = factor + LEVERAGE_DECIMALS.
|
|
5
|
+
*/
|
|
6
|
+
export declare function maxLeverage(lpToken: Address, cms: Array<{
|
|
7
|
+
liquidationThresholds: Record<Address, bigint>;
|
|
8
|
+
address: Address;
|
|
9
|
+
}>, targetHF?: bigint): bigint;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./sort-strategy-cms-by-availability.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { type APYListSlice, type CreditManagerSlice, type PoolSlice } from "../strategy-info/index.js";
|
|
3
|
+
export interface SortStrategyCMsByAvailabilityProps {
|
|
4
|
+
targetToken: Address;
|
|
5
|
+
allCreditManagers: Array<CreditManagerSlice>;
|
|
6
|
+
apyListByNetwork: Record<number, APYListSlice | undefined> | undefined;
|
|
7
|
+
pools: Record<Address, PoolSlice> | undefined | null;
|
|
8
|
+
slippage: number;
|
|
9
|
+
quotaReserve: number;
|
|
10
|
+
leverageLimit: number | undefined;
|
|
11
|
+
isStrategy: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function sortStrategyCMsByAvailability({ targetToken, allCreditManagers, apyListByNetwork, pools, slippage, quotaReserve, leverageLimit, isStrategy, }: SortStrategyCMsByAvailabilityProps): Array<CreditManagerSlice>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { CreditManagerSlice, PoolSlice } from "./types.js";
|
|
3
|
+
export declare function cmAvailabilityCondition(targetToken: Address, cmA: CreditManagerSlice, cmB: CreditManagerSlice, pools: Record<Address, PoolSlice> | null | undefined): number;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { CreditManagerSlice, GetStrategyInfoArgs, StrategyInfoResult } from "./types.js";
|
|
2
|
+
export declare function getStrategyInfo<ID extends string | number, CM extends CreditManagerSlice = CreditManagerSlice>({ strategy, creditManagers, sdkStateByChain, apyListByNetwork, quotaReserve, slippage, allPricesByChain, }: GetStrategyInfoArgs<ID, CM>): StrategyInfoResult<CM> | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { APYListSlice, CreditManagerSlice } from "./types.js";
|
|
3
|
+
export declare function getStrategyMaxAPY(targetToken: Address, cm: CreditManagerSlice | undefined, apyListByNetwork: Record<number, APYListSlice | undefined> | undefined, slippage: number, quotaReserve: number, leverageLimit: number | undefined): {
|
|
4
|
+
totalMaxApy: number;
|
|
5
|
+
bonusAPY: {
|
|
6
|
+
value: number;
|
|
7
|
+
} | undefined;
|
|
8
|
+
maxAPY: number;
|
|
9
|
+
maxLeverage: bigint;
|
|
10
|
+
quotaRateMin: bigint;
|
|
11
|
+
baseBorrowRate: number;
|
|
12
|
+
totalBorrowRate: number;
|
|
13
|
+
} | undefined;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import type { PartialRecord } from "../../../../sdk/index.js";
|
|
3
|
+
export interface QuotaSlice {
|
|
4
|
+
token: Address;
|
|
5
|
+
rate: bigint;
|
|
6
|
+
quotaIncreaseFee: bigint;
|
|
7
|
+
totalQuoted: bigint;
|
|
8
|
+
limit: bigint;
|
|
9
|
+
isActive: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface CreditManagerSlice {
|
|
12
|
+
address: Address;
|
|
13
|
+
underlyingToken: Address;
|
|
14
|
+
pool: Address;
|
|
15
|
+
chainId: number;
|
|
16
|
+
baseBorrowRate: number;
|
|
17
|
+
feeInterest: number;
|
|
18
|
+
availableToBorrow: bigint;
|
|
19
|
+
minDebt: bigint;
|
|
20
|
+
maxDebt: bigint;
|
|
21
|
+
totalDebt: bigint;
|
|
22
|
+
totalDebtLimit: bigint;
|
|
23
|
+
isDegenMode: boolean;
|
|
24
|
+
degenNFT: Address;
|
|
25
|
+
liquidationThresholds: Record<Address, bigint>;
|
|
26
|
+
quotas: Record<Address, QuotaSlice | undefined>;
|
|
27
|
+
collateralTokens: readonly Address[];
|
|
28
|
+
}
|
|
29
|
+
export interface PoolSlice {
|
|
30
|
+
address: Address;
|
|
31
|
+
totalDebtLimit: bigint;
|
|
32
|
+
totalBorrowed: bigint;
|
|
33
|
+
}
|
|
34
|
+
export interface TokenSlice {
|
|
35
|
+
address: Address;
|
|
36
|
+
decimals: number;
|
|
37
|
+
title?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface StrategySlice<ID extends string | number = string> {
|
|
40
|
+
id: ID;
|
|
41
|
+
chainId: number;
|
|
42
|
+
tokenOutAddress: Address;
|
|
43
|
+
maxLeverage?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface APYListSlice {
|
|
46
|
+
apyList: Record<Address, number> | undefined;
|
|
47
|
+
extraCollateralAPYList: Record<Address, Record<Address, {
|
|
48
|
+
type: "relative" | "absolute";
|
|
49
|
+
value: number;
|
|
50
|
+
}>> | undefined;
|
|
51
|
+
}
|
|
52
|
+
export interface PricesByChainSlice {
|
|
53
|
+
[chainId: number]: {
|
|
54
|
+
prices?: Record<Address, Record<Address, bigint>> | undefined;
|
|
55
|
+
} | undefined;
|
|
56
|
+
}
|
|
57
|
+
export interface StrategyInfoResult<CM extends CreditManagerSlice = CreditManagerSlice> {
|
|
58
|
+
maxLeverage: bigint;
|
|
59
|
+
maxAPY: number | undefined;
|
|
60
|
+
bonusAPY: {
|
|
61
|
+
value: number;
|
|
62
|
+
} | undefined;
|
|
63
|
+
totalBorrowRate: number;
|
|
64
|
+
availableToBorrowMoney: bigint;
|
|
65
|
+
minCreditManager: CM;
|
|
66
|
+
}
|
|
67
|
+
export interface GetStrategyInfoArgs<ID extends string | number, CM extends CreditManagerSlice> {
|
|
68
|
+
strategy: StrategySlice<ID>;
|
|
69
|
+
creditManagers: Record<number, PartialRecord<ID, Record<Address, CM>>> | undefined;
|
|
70
|
+
sdkStateByChain: Record<number, {
|
|
71
|
+
pools?: Record<Address, PoolSlice> | undefined;
|
|
72
|
+
tokens?: {
|
|
73
|
+
tokenDataList?: Record<Address, TokenSlice> | undefined;
|
|
74
|
+
};
|
|
75
|
+
} | undefined> | undefined;
|
|
76
|
+
apyListByNetwork: Record<number, APYListSlice | undefined> | undefined;
|
|
77
|
+
quotaReserve: number;
|
|
78
|
+
slippage: number;
|
|
79
|
+
allPricesByChain: PricesByChainSlice;
|
|
80
|
+
}
|