@gearbox-protocol/sdk 13.0.0-beta.1 → 13.0.0-beta.3

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.
@@ -0,0 +1,128 @@
1
+ import type { Address } from "viem";
2
+ import { type Asset } from "../index.js";
3
+ interface TokenDataSlice {
4
+ symbol: string;
5
+ decimals: number;
6
+ }
7
+ interface QuotaInfoIsActiveSlice {
8
+ isActive: boolean;
9
+ }
10
+ interface QuotaInfoTokenSlice extends QuotaInfoIsActiveSlice {
11
+ token: Address;
12
+ }
13
+ interface QuotaInfoSlice extends QuotaInfoIsActiveSlice {
14
+ rate: bigint;
15
+ }
16
+ interface AssetWithAmountInTarget extends Asset {
17
+ amountInTarget: bigint;
18
+ }
19
+ export interface CalcOverallAPYProps {
20
+ caAssets: Array<Asset>;
21
+ lpAPY: Record<Address, number> | undefined;
22
+ quotas: Record<Address, Asset>;
23
+ quotaRates: Record<Address, QuotaInfoSlice>;
24
+ feeInterest: number;
25
+ prices: Record<Address, bigint>;
26
+ totalValue: bigint | undefined;
27
+ debt: bigint | undefined;
28
+ baseRateWithFee: number;
29
+ underlyingToken: Address;
30
+ tokensList: Record<Address, TokenDataSlice>;
31
+ }
32
+ export interface CalcMaxLendingDebtProps {
33
+ assets: Array<Asset>;
34
+ prices: Record<Address, bigint>;
35
+ liquidationThresholds: Record<Address, bigint>;
36
+ underlyingToken: Address;
37
+ tokensList: Record<Address, TokenDataSlice>;
38
+ targetHF?: bigint;
39
+ }
40
+ export interface CalcHealthFactorProps {
41
+ assets: Array<Asset>;
42
+ quotas: Record<Address, Asset>;
43
+ quotasInfo: Record<Address, QuotaInfoIsActiveSlice>;
44
+ prices: Record<Address, bigint>;
45
+ liquidationThresholds: Record<Address, bigint>;
46
+ underlyingToken: Address;
47
+ debt: bigint;
48
+ tokensList: Record<Address, TokenDataSlice>;
49
+ }
50
+ export interface CalcDefaultQuotaProps {
51
+ amount: bigint;
52
+ lt: bigint;
53
+ quotaReserve: bigint;
54
+ }
55
+ export interface CalcRecommendedQuotaProps {
56
+ amount: bigint;
57
+ debt: bigint;
58
+ lt: bigint;
59
+ quotaReserve: bigint;
60
+ }
61
+ export interface CalcQuotaUpdateProps {
62
+ quotas: Record<Address, QuotaInfoTokenSlice>;
63
+ initialQuotas: Record<Address, {
64
+ quota: bigint;
65
+ }>;
66
+ liquidationThresholds: Record<Address, bigint>;
67
+ assetsAfterUpdate: Record<Address, AssetWithAmountInTarget>;
68
+ maxDebt: bigint;
69
+ calcModification?: {
70
+ type: "recommendedQuota";
71
+ debt: bigint;
72
+ };
73
+ allowedToSpend: Record<Address, object>;
74
+ allowedToObtain: Record<Address, object>;
75
+ quotaReserve: bigint;
76
+ }
77
+ interface CalcQuotaUpdateReturnType {
78
+ desiredQuota: Record<Address, Asset>;
79
+ quotaIncrease: Array<Asset>;
80
+ quotaDecrease: Array<Asset>;
81
+ }
82
+ export interface CalcQuotaBorrowRateProps {
83
+ quotas: Record<Address, Asset>;
84
+ quotaRates: Record<Address, QuotaInfoSlice>;
85
+ }
86
+ export interface CalcRelativeBaseBorrowRateProps {
87
+ debt: bigint;
88
+ baseRateWithFee: number;
89
+ assetAmountInUnderlying: bigint;
90
+ }
91
+ interface LiquidationPriceProps {
92
+ liquidationThresholds: Record<Address, bigint>;
93
+ debt: bigint;
94
+ underlyingToken: Address;
95
+ targetToken: Address;
96
+ assets: Record<Address, Asset>;
97
+ tokensList: Record<Address, TokenDataSlice>;
98
+ }
99
+ export interface TimeToLiquidationProps {
100
+ totalBorrowRate_debt: bigint;
101
+ healthFactor: number;
102
+ }
103
+ export declare class CreditAccountDataUtils {
104
+ private constructor();
105
+ static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): Array<[Address, bigint]>;
106
+ static sortAssets<T extends Asset>(balances: Array<T>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): T[];
107
+ static assetComparator<T extends Asset>(t1: T, t2: T, prices1: Record<Address, bigint> | undefined, prices2: Record<Address, bigint> | undefined, tokens1: Record<Address, TokenDataSlice> | undefined, tokens2: Record<Address, TokenDataSlice> | undefined): 1 | 0 | -1;
108
+ static tokensAbcComparator(t1?: TokenDataSlice, t2?: TokenDataSlice): 1 | 0 | -1;
109
+ static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
110
+ static calcMaxDebtIncrease(healthFactor: number, debt: bigint, underlyingLT: number, minHf?: number): bigint;
111
+ static calcMaxLendingDebt({ assets, liquidationThresholds, underlyingToken, prices, tokensList, targetHF, }: CalcMaxLendingDebtProps): bigint;
112
+ static calcOverallAPY({ caAssets, lpAPY, prices, quotas, quotaRates, feeInterest, totalValue, debt, baseRateWithFee, underlyingToken, tokensList, }: CalcOverallAPYProps): bigint | undefined;
113
+ static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList, }: CalcHealthFactorProps): number;
114
+ static roundUpQuota(quotaChange: bigint): bigint;
115
+ static calcRecommendedQuota({ amount, debt, lt, quotaReserve, }: CalcRecommendedQuotaProps): bigint;
116
+ static calcDefaultQuota({ amount, lt, quotaReserve }: CalcDefaultQuotaProps): bigint;
117
+ static calcQuotaUpdate(props: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
118
+ private static getSingleQuotaChange;
119
+ static calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
120
+ static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying, }: CalcRelativeBaseBorrowRateProps): bigint;
121
+ static liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, tokensList, }: LiquidationPriceProps): bigint;
122
+ /**
123
+ * Calculates the time remaining until liquidation for a credit account.
124
+ * @returns The time remaining until liquidation in milliseconds.
125
+ */
126
+ static getTimeToLiquidation({ healthFactor, totalBorrowRate_debt, }: TimeToLiquidationProps): bigint | null;
127
+ }
128
+ export {};
@@ -0,0 +1,19 @@
1
+ import type { Address } from "viem";
2
+ import { type NetworkType } from "../index.js";
3
+ type ChartsPriceSource = "chainlink" | "spot";
4
+ export declare class GearboxBackendApi {
5
+ private constructor();
6
+ static getChartsUrl: (url: string, chainId: number, options?: Options, priceSource?: ChartsPriceSource) => string;
7
+ static getStaticTokenUrl: () => string;
8
+ static getRewardsMerkleUrl: (network: NetworkType, root: Address, account: Address) => string;
9
+ static getNFTMerkleUrl: (network: NetworkType, root: Address) => string;
10
+ static apyAllRewards: () => string;
11
+ }
12
+ interface Options {
13
+ params?: Record<string, string | number>;
14
+ }
15
+ export declare class URLApi {
16
+ private constructor();
17
+ static getRelativeUrl: (url: string, options?: Options) => string;
18
+ }
19
+ export {};
@@ -10,3 +10,12 @@ export declare function numberWithCommas(x: number | bigint): string;
10
10
  export declare function formatDuration(seconds: number, raw?: boolean): string;
11
11
  export declare function formatNumberToString_(value: bigint | number): string;
12
12
  export declare function formatTimestamp(timestamp: number, raw?: boolean): string;
13
+ type BigNumberish = bigint | number | string;
14
+ export declare function rayToNumber(num: BigNumberish): number;
15
+ export declare function toSignificant(num: bigint, decimals: number, precision?: number): string;
16
+ export declare function toBN(num: string, decimals: number): bigint;
17
+ export declare function shortAddress(address?: string): string;
18
+ export declare function shortHash(address?: string): string;
19
+ export declare function formatPercentage(healthFactor: number, decimals?: number): string;
20
+ export declare function formatLeverage(leverage: number, decimals?: number): string;
21
+ export {};
@@ -1,9 +1,13 @@
1
1
  export * from "./AddressMap.js";
2
2
  export * from "./AddressSet.js";
3
3
  export * from "./abi-decode.js";
4
+ export * from "./assetsMath.js";
5
+ export * from "./bigintMath.js";
4
6
  export * from "./bytes32ToString.js";
5
7
  export * from "./childLogger.js";
6
8
  export * from "./createRawTx.js";
9
+ export * from "./creditAccount.js";
10
+ export * from "./endpoints.js";
7
11
  export * from "./etherscan.js";
8
12
  export * from "./filterDust.js";
9
13
  export * from "./formatter.js";
@@ -11,6 +15,7 @@ export * from "./hex.js";
11
15
  export * from "./isDust.js";
12
16
  export * from "./json.js";
13
17
  export * from "./mappers.js";
18
+ export * from "./priceMath.js";
14
19
  export * from "./retry.js";
15
20
  export * from "./toAddress.js";
16
21
  export * from "./type-utils.js";
@@ -0,0 +1,9 @@
1
+ interface Target {
2
+ price: bigint;
3
+ decimals: number | undefined;
4
+ }
5
+ export declare class PriceUtils {
6
+ static calcTotalPrice: (price: bigint, amount: bigint, decimals?: number | undefined) => bigint;
7
+ static convertByPrice(totalMoney: bigint, { price: targetPrice, decimals: targetDecimals }: Target): bigint;
8
+ }
9
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gearbox-protocol/sdk",
3
- "version": "13.0.0-beta.1",
3
+ "version": "13.0.0-beta.3",
4
4
  "description": "Gearbox SDK",
5
5
  "license": "MIT",
6
6
  "main": "./dist/cjs/sdk/index.js",