@gearbox-protocol/sdk 13.0.0-beta.1 → 13.0.0-beta.2
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/sdk/utils/assetsMath.js +149 -0
- package/dist/cjs/sdk/utils/bigintMath.js +33 -0
- package/dist/cjs/sdk/utils/creditAccount.js +407 -0
- package/dist/cjs/sdk/utils/formatter.js +55 -2
- package/dist/cjs/sdk/utils/index.js +8 -0
- package/dist/cjs/sdk/utils/priceMath.js +35 -0
- package/dist/esm/sdk/utils/assetsMath.js +125 -0
- package/dist/esm/sdk/utils/bigintMath.js +9 -0
- package/dist/esm/sdk/utils/creditAccount.js +394 -0
- package/dist/esm/sdk/utils/formatter.js +37 -1
- package/dist/esm/sdk/utils/index.js +4 -0
- package/dist/esm/sdk/utils/priceMath.js +11 -0
- package/dist/types/sdk/utils/assetsMath.d.ts +42 -0
- package/dist/types/sdk/utils/bigintMath.d.ts +6 -0
- package/dist/types/sdk/utils/creditAccount.d.ts +127 -0
- package/dist/types/sdk/utils/formatter.d.ts +9 -0
- package/dist/types/sdk/utils/index.d.ts +4 -0
- package/dist/types/sdk/utils/priceMath.d.ts +9 -0
- package/package.json +1 -1
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Address } from "viem";
|
|
2
|
+
import { type Asset } from "../index.js";
|
|
3
|
+
interface TokenDataSlice {
|
|
4
|
+
symbol: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
}
|
|
7
|
+
export interface AssetWithView extends Asset {
|
|
8
|
+
balanceView: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AssetWithAmountInTarget extends Asset {
|
|
11
|
+
amountInTarget: bigint;
|
|
12
|
+
}
|
|
13
|
+
interface NextAssetProps<T extends Asset> {
|
|
14
|
+
allowedTokens: Array<Address>;
|
|
15
|
+
selectedAssets: Array<T>;
|
|
16
|
+
balances: Record<Address, bigint>;
|
|
17
|
+
tokensList: Record<Address, TokenDataSlice>;
|
|
18
|
+
prices?: Record<Address, bigint>;
|
|
19
|
+
}
|
|
20
|
+
export type WrapResult = [Array<Asset>, bigint, bigint];
|
|
21
|
+
export declare class AssetUtils {
|
|
22
|
+
static nextAsset<T extends Asset>({ allowedTokens, selectedAssets, balances, tokensList, prices, }: NextAssetProps<T>): Address | undefined;
|
|
23
|
+
private static getBalances;
|
|
24
|
+
static constructAssetRecord<A extends Asset>(a: Array<A>): Record<`0x${string}`, A>;
|
|
25
|
+
static memoWrap: (unwrappedAddress: Address, wrappedAddress: Address, prices: Record<Address, bigint>, tokensList: Record<Address, TokenDataSlice>) => (assets: Array<Asset>) => WrapResult;
|
|
26
|
+
/**
|
|
27
|
+
* Sums the the second assets list into the first assets list
|
|
28
|
+
* Balances cant be negative; creates new assets.
|
|
29
|
+
*/
|
|
30
|
+
static sumAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
|
|
31
|
+
/**
|
|
32
|
+
* Sums the the second assets list into the first assets list
|
|
33
|
+
* Balances cant be negative; doesn't create new assets.
|
|
34
|
+
*/
|
|
35
|
+
static addBalances<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A | B>;
|
|
36
|
+
/**
|
|
37
|
+
* Subtracts the the second assets list from the first assets list
|
|
38
|
+
* Balances cant be negative; doesn't create new assets.
|
|
39
|
+
*/
|
|
40
|
+
static subAssets<A extends Asset, B extends Asset>(a: Array<A>, b: Array<B>): Array<A>;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,127 @@
|
|
|
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, {}>;
|
|
74
|
+
allowedToObtain: Record<Address, {}>;
|
|
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
|
+
static sortBalances(balances: Record<Address, bigint>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): Array<[Address, bigint]>;
|
|
105
|
+
static sortAssets<T extends Asset>(balances: Array<T>, prices: Record<Address, bigint>, tokens: Record<Address, TokenDataSlice>): T[];
|
|
106
|
+
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;
|
|
107
|
+
static tokensAbcComparator(t1?: TokenDataSlice, t2?: TokenDataSlice): 1 | 0 | -1;
|
|
108
|
+
static amountAbcComparator(t1: bigint, t2: bigint): 1 | -1;
|
|
109
|
+
static calcMaxDebtIncrease(healthFactor: number, debt: bigint, underlyingLT: number, minHf?: number): bigint;
|
|
110
|
+
static calcMaxLendingDebt({ assets, liquidationThresholds, underlyingToken, prices, tokensList, targetHF, }: CalcMaxLendingDebtProps): bigint;
|
|
111
|
+
static calcOverallAPY({ caAssets, lpAPY, prices, quotas, quotaRates, feeInterest, totalValue, debt, baseRateWithFee, underlyingToken, tokensList, }: CalcOverallAPYProps): bigint | undefined;
|
|
112
|
+
static calcHealthFactor({ assets, quotas, quotasInfo, liquidationThresholds, underlyingToken, debt, prices, tokensList, }: CalcHealthFactorProps): number;
|
|
113
|
+
static roundUpQuota(quotaChange: bigint): bigint;
|
|
114
|
+
static calcRecommendedQuota({ amount, debt, lt, quotaReserve, }: CalcRecommendedQuotaProps): bigint;
|
|
115
|
+
static calcDefaultQuota({ amount, lt, quotaReserve }: CalcDefaultQuotaProps): bigint;
|
|
116
|
+
static calcQuotaUpdate(props: CalcQuotaUpdateProps): CalcQuotaUpdateReturnType;
|
|
117
|
+
private static getSingleQuotaChange;
|
|
118
|
+
static calcQuotaBorrowRate({ quotas, quotaRates }: CalcQuotaBorrowRateProps): bigint;
|
|
119
|
+
static calcRelativeBaseBorrowRate({ debt, baseRateWithFee, assetAmountInUnderlying, }: CalcRelativeBaseBorrowRateProps): bigint;
|
|
120
|
+
static liquidationPrice({ liquidationThresholds, debt, underlyingToken, targetToken, assets, tokensList, }: LiquidationPriceProps): bigint;
|
|
121
|
+
/**
|
|
122
|
+
* Calculates the time remaining until liquidation for a credit account.
|
|
123
|
+
* @returns The time remaining until liquidation in milliseconds.
|
|
124
|
+
*/
|
|
125
|
+
static getTimeToLiquidation({ healthFactor, totalBorrowRate_debt, }: TimeToLiquidationProps): bigint | null;
|
|
126
|
+
}
|
|
127
|
+
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,12 @@
|
|
|
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";
|
|
7
10
|
export * from "./etherscan.js";
|
|
8
11
|
export * from "./filterDust.js";
|
|
9
12
|
export * from "./formatter.js";
|
|
@@ -11,6 +14,7 @@ export * from "./hex.js";
|
|
|
11
14
|
export * from "./isDust.js";
|
|
12
15
|
export * from "./json.js";
|
|
13
16
|
export * from "./mappers.js";
|
|
17
|
+
export * from "./priceMath.js";
|
|
14
18
|
export * from "./retry.js";
|
|
15
19
|
export * from "./toAddress.js";
|
|
16
20
|
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 {};
|