Skip to content

Commit e813a41

Browse files
committed
📦️ package: add distribution files
1 parent 1c2ccdc commit e813a41

File tree

8 files changed

+1492
-2
lines changed

8 files changed

+1492
-2
lines changed

.github/workflows/test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
- uses: foundry-rs/foundry-toolchain@v1
1919

2020
- run: pnpm install --frozen-lockfile
21-
- run: pnpm test
2221

2322
- uses: codecov/codecov-action@v4
2423
if: always()

dist/index.d.mts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
declare function accountLiquidity(data: AccountLiquidityData, timestamp?: number): {
2+
adjCollateral: bigint;
3+
adjDebt: bigint;
4+
};
5+
type AccountLiquidityData = readonly {
6+
market: string;
7+
decimals: number;
8+
usdPrice: bigint;
9+
adjustFactor: bigint;
10+
isCollateral: boolean;
11+
floatingBorrowAssets: bigint;
12+
floatingDepositAssets: bigint;
13+
fixedBorrowPositions: readonly {
14+
maturity: bigint;
15+
position: {
16+
principal: bigint;
17+
fee: bigint;
18+
};
19+
}[];
20+
penaltyRate: bigint;
21+
}[];
22+
23+
declare function borrowLimit(data: AccountLiquidityData, market: string, targetHealthFactor?: bigint, timestamp?: number): bigint;
24+
25+
declare function healthFactor(data: AccountLiquidityData, timestamp?: number): bigint;
26+
27+
declare function withdrawLimit(data: AccountLiquidityData, market: string, targetHealthFactor?: bigint, timestamp?: number): bigint;
28+
29+
declare function divWad(a: bigint, b: bigint): bigint;
30+
31+
declare function divWadUp(a: bigint, b: bigint): bigint;
32+
33+
declare function expWad(x: bigint): bigint;
34+
35+
declare function lnWad(x: bigint): bigint;
36+
37+
declare function log2(x: bigint): bigint;
38+
39+
declare const _default: bigint;
40+
41+
declare function max$1(a: bigint, b: bigint): bigint;
42+
43+
declare function min$1(a: bigint, b: bigint): bigint;
44+
45+
declare function mulDiv$1(a: bigint, b: bigint, c: bigint): bigint;
46+
47+
declare function mulDivUp$1(a: bigint, b: bigint, c: bigint): bigint;
48+
49+
declare function mulWad(a: bigint, b: bigint): bigint;
50+
51+
declare function mulWadUp(a: bigint, b: bigint): bigint;
52+
53+
declare function sqrt(x: bigint): bigint;
54+
55+
declare const WAD = 1000000000000000000n;
56+
57+
declare const SQ_WAD: bigint;
58+
declare const TWO_WAD: bigint;
59+
60+
declare const ONE_YEAR: bigint;
61+
declare function effectiveRate(totalAmount: bigint, firstMaturity: number, installments: readonly bigint[], rates: readonly bigint[], timestamp?: number, { tolerance, maxIterations }?: {
62+
tolerance?: bigint | undefined;
63+
maxIterations?: bigint | undefined;
64+
}): bigint;
65+
66+
interface IRMParameters {
67+
minRate: bigint;
68+
naturalRate: bigint;
69+
maxUtilization: bigint;
70+
naturalUtilization: bigint;
71+
growthSpeed: bigint;
72+
sigmoidSpeed: bigint;
73+
spreadFactor: bigint;
74+
maturitySpeed: bigint;
75+
timePreference: bigint;
76+
fixedAllocation: bigint;
77+
maxRate: bigint;
78+
}
79+
type IRMBaseParameters = Prettify<Pick<IRMParameters, "maxUtilization" | "naturalUtilization" | "sigmoidSpeed" | "growthSpeed"> & ((Pick<IRMParameters, "minRate" | "naturalRate"> & {
80+
curveA?: undefined;
81+
curveB?: undefined;
82+
}) | {
83+
curveA: bigint;
84+
curveB: bigint;
85+
})>;
86+
type IRMFloatingParameters = Prettify<IRMBaseParameters & Pick<IRMParameters, "maxRate">>;
87+
type Prettify<T> = {
88+
[K in keyof T]: Prettify<T[K]>;
89+
} & {};
90+
91+
declare const MATURITY_INTERVAL: number;
92+
declare function fixedRate(maturity: number, maxPools: number, uFixed: bigint, uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number, base?: bigint, z?: bigint): bigint;
93+
94+
declare function splitInstallments(totalAmount: bigint, totalAssets: bigint, firstMaturity: number, maxPools: number, uFixed: readonly bigint[], uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number, { power, scaleFactor, tolerance, maxIterations }?: {
95+
power?: bigint | undefined;
96+
scaleFactor?: bigint | undefined;
97+
tolerance?: bigint | undefined;
98+
maxIterations?: bigint | undefined;
99+
}): {
100+
amounts: bigint[];
101+
installments: bigint[];
102+
rates: bigint[];
103+
effectiveRate: bigint;
104+
};
105+
106+
declare function baseRate(uFloating: bigint, uGlobal: bigint, { maxUtilization, naturalUtilization, sigmoidSpeed, growthSpeed, ...p }: IRMBaseParameters): bigint;
107+
108+
declare function fixedRates(firstMaturity: number, maxPools: number, uFixed: readonly bigint[], uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number): void[];
109+
110+
declare function fixedUtilization(supplied: bigint, borrowed: bigint, assets: bigint): bigint;
111+
112+
declare function floatingRate(uFloating: bigint, uGlobal: bigint, parameters: IRMFloatingParameters): bigint;
113+
114+
declare function floatingUtilization(assets: bigint, debt: bigint): bigint;
115+
116+
declare function globalUtilization(assets: bigint, debt: bigint, backupBorrowed: bigint): bigint;
117+
118+
declare function floatingDepositRates(snapshots: readonly MarketSnapshot[], timestamp?: number, elapsed?: number): {
119+
market: string;
120+
rate: bigint;
121+
}[];
122+
interface MarketSnapshot {
123+
market: string;
124+
floatingDebt: bigint;
125+
floatingBackupBorrowed: bigint;
126+
pools: readonly FixedPool[];
127+
floatingAssets: bigint;
128+
treasuryFeeRate: bigint;
129+
earningsAccumulator: bigint;
130+
earningsAccumulatorSmoothFactor: bigint;
131+
lastFloatingDebtUpdate: number;
132+
lastAccumulatorAccrual: number;
133+
maxFuturePools: number;
134+
interval: bigint;
135+
totalAssets: bigint;
136+
floatingRate: bigint;
137+
}
138+
interface FixedPool {
139+
maturity: bigint;
140+
lastAccrual: bigint;
141+
unassignedEarnings: bigint;
142+
}
143+
144+
declare function abs(array: readonly bigint[]): bigint[];
145+
146+
declare function add(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
147+
148+
declare function fill(length: number, value?: bigint): bigint[];
149+
150+
declare function map2(a: readonly bigint[], b: readonly bigint[] | bigint, f: (a: bigint, b: bigint) => bigint): bigint[];
151+
declare global {
152+
interface ArrayConstructor {
153+
isArray(argument: unknown): argument is unknown[] | readonly unknown[];
154+
}
155+
}
156+
157+
declare function map3(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint, f: (a: bigint, b: bigint, c: bigint) => bigint): bigint[];
158+
declare global {
159+
interface ArrayConstructor {
160+
isArray(argument: unknown): argument is unknown[] | readonly unknown[];
161+
}
162+
}
163+
164+
declare function max(array: readonly bigint[]): bigint;
165+
166+
declare function mean(array: readonly bigint[]): bigint;
167+
168+
declare function min(array: readonly bigint[]): bigint;
169+
170+
declare function mul(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
171+
172+
declare function mulDiv(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
173+
174+
declare function mulDivUp(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
175+
176+
declare function powDiv(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
177+
178+
declare function sub(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
179+
180+
declare function sum(array: readonly bigint[]): bigint;
181+
182+
export { type IRMFloatingParameters, type IRMParameters, MATURITY_INTERVAL, _default as MAX_UINT256, ONE_YEAR, SQ_WAD, TWO_WAD, WAD, abs, accountLiquidity, add, baseRate, borrowLimit, divWad, divWadUp, effectiveRate, expWad, fill, fixedRate, fixedRates, fixedUtilization, floatingDepositRates, floatingRate, floatingUtilization, globalUtilization, healthFactor, lnWad, log2, map2, map3, max$1 as max, max as maxV, mean, min$1 as min, min as minV, mul, mulDiv$1 as mulDiv, mulDivUp$1 as mulDivUp, mulDivUp as mulDivUpV, mulDiv as mulDivV, mulWad, mulWadUp, powDiv, splitInstallments, sqrt, sub, sum, withdrawLimit };

dist/index.d.ts

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
declare function accountLiquidity(data: AccountLiquidityData, timestamp?: number): {
2+
adjCollateral: bigint;
3+
adjDebt: bigint;
4+
};
5+
type AccountLiquidityData = readonly {
6+
market: string;
7+
decimals: number;
8+
usdPrice: bigint;
9+
adjustFactor: bigint;
10+
isCollateral: boolean;
11+
floatingBorrowAssets: bigint;
12+
floatingDepositAssets: bigint;
13+
fixedBorrowPositions: readonly {
14+
maturity: bigint;
15+
position: {
16+
principal: bigint;
17+
fee: bigint;
18+
};
19+
}[];
20+
penaltyRate: bigint;
21+
}[];
22+
23+
declare function borrowLimit(data: AccountLiquidityData, market: string, targetHealthFactor?: bigint, timestamp?: number): bigint;
24+
25+
declare function healthFactor(data: AccountLiquidityData, timestamp?: number): bigint;
26+
27+
declare function withdrawLimit(data: AccountLiquidityData, market: string, targetHealthFactor?: bigint, timestamp?: number): bigint;
28+
29+
declare function divWad(a: bigint, b: bigint): bigint;
30+
31+
declare function divWadUp(a: bigint, b: bigint): bigint;
32+
33+
declare function expWad(x: bigint): bigint;
34+
35+
declare function lnWad(x: bigint): bigint;
36+
37+
declare function log2(x: bigint): bigint;
38+
39+
declare const _default: bigint;
40+
41+
declare function max$1(a: bigint, b: bigint): bigint;
42+
43+
declare function min$1(a: bigint, b: bigint): bigint;
44+
45+
declare function mulDiv$1(a: bigint, b: bigint, c: bigint): bigint;
46+
47+
declare function mulDivUp$1(a: bigint, b: bigint, c: bigint): bigint;
48+
49+
declare function mulWad(a: bigint, b: bigint): bigint;
50+
51+
declare function mulWadUp(a: bigint, b: bigint): bigint;
52+
53+
declare function sqrt(x: bigint): bigint;
54+
55+
declare const WAD = 1000000000000000000n;
56+
57+
declare const SQ_WAD: bigint;
58+
declare const TWO_WAD: bigint;
59+
60+
declare const ONE_YEAR: bigint;
61+
declare function effectiveRate(totalAmount: bigint, firstMaturity: number, installments: readonly bigint[], rates: readonly bigint[], timestamp?: number, { tolerance, maxIterations }?: {
62+
tolerance?: bigint | undefined;
63+
maxIterations?: bigint | undefined;
64+
}): bigint;
65+
66+
interface IRMParameters {
67+
minRate: bigint;
68+
naturalRate: bigint;
69+
maxUtilization: bigint;
70+
naturalUtilization: bigint;
71+
growthSpeed: bigint;
72+
sigmoidSpeed: bigint;
73+
spreadFactor: bigint;
74+
maturitySpeed: bigint;
75+
timePreference: bigint;
76+
fixedAllocation: bigint;
77+
maxRate: bigint;
78+
}
79+
type IRMBaseParameters = Prettify<Pick<IRMParameters, "maxUtilization" | "naturalUtilization" | "sigmoidSpeed" | "growthSpeed"> & ((Pick<IRMParameters, "minRate" | "naturalRate"> & {
80+
curveA?: undefined;
81+
curveB?: undefined;
82+
}) | {
83+
curveA: bigint;
84+
curveB: bigint;
85+
})>;
86+
type IRMFloatingParameters = Prettify<IRMBaseParameters & Pick<IRMParameters, "maxRate">>;
87+
type Prettify<T> = {
88+
[K in keyof T]: Prettify<T[K]>;
89+
} & {};
90+
91+
declare const MATURITY_INTERVAL: number;
92+
declare function fixedRate(maturity: number, maxPools: number, uFixed: bigint, uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number, base?: bigint, z?: bigint): bigint;
93+
94+
declare function splitInstallments(totalAmount: bigint, totalAssets: bigint, firstMaturity: number, maxPools: number, uFixed: readonly bigint[], uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number, { power, scaleFactor, tolerance, maxIterations }?: {
95+
power?: bigint | undefined;
96+
scaleFactor?: bigint | undefined;
97+
tolerance?: bigint | undefined;
98+
maxIterations?: bigint | undefined;
99+
}): {
100+
amounts: bigint[];
101+
installments: bigint[];
102+
rates: bigint[];
103+
effectiveRate: bigint;
104+
};
105+
106+
declare function baseRate(uFloating: bigint, uGlobal: bigint, { maxUtilization, naturalUtilization, sigmoidSpeed, growthSpeed, ...p }: IRMBaseParameters): bigint;
107+
108+
declare function fixedRates(firstMaturity: number, maxPools: number, uFixed: readonly bigint[], uFloating: bigint, uGlobal: bigint, parameters: IRMParameters, timestamp?: number): void[];
109+
110+
declare function fixedUtilization(supplied: bigint, borrowed: bigint, assets: bigint): bigint;
111+
112+
declare function floatingRate(uFloating: bigint, uGlobal: bigint, parameters: IRMFloatingParameters): bigint;
113+
114+
declare function floatingUtilization(assets: bigint, debt: bigint): bigint;
115+
116+
declare function globalUtilization(assets: bigint, debt: bigint, backupBorrowed: bigint): bigint;
117+
118+
declare function floatingDepositRates(snapshots: readonly MarketSnapshot[], timestamp?: number, elapsed?: number): {
119+
market: string;
120+
rate: bigint;
121+
}[];
122+
interface MarketSnapshot {
123+
market: string;
124+
floatingDebt: bigint;
125+
floatingBackupBorrowed: bigint;
126+
pools: readonly FixedPool[];
127+
floatingAssets: bigint;
128+
treasuryFeeRate: bigint;
129+
earningsAccumulator: bigint;
130+
earningsAccumulatorSmoothFactor: bigint;
131+
lastFloatingDebtUpdate: number;
132+
lastAccumulatorAccrual: number;
133+
maxFuturePools: number;
134+
interval: bigint;
135+
totalAssets: bigint;
136+
floatingRate: bigint;
137+
}
138+
interface FixedPool {
139+
maturity: bigint;
140+
lastAccrual: bigint;
141+
unassignedEarnings: bigint;
142+
}
143+
144+
declare function abs(array: readonly bigint[]): bigint[];
145+
146+
declare function add(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
147+
148+
declare function fill(length: number, value?: bigint): bigint[];
149+
150+
declare function map2(a: readonly bigint[], b: readonly bigint[] | bigint, f: (a: bigint, b: bigint) => bigint): bigint[];
151+
declare global {
152+
interface ArrayConstructor {
153+
isArray(argument: unknown): argument is unknown[] | readonly unknown[];
154+
}
155+
}
156+
157+
declare function map3(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint, f: (a: bigint, b: bigint, c: bigint) => bigint): bigint[];
158+
declare global {
159+
interface ArrayConstructor {
160+
isArray(argument: unknown): argument is unknown[] | readonly unknown[];
161+
}
162+
}
163+
164+
declare function max(array: readonly bigint[]): bigint;
165+
166+
declare function mean(array: readonly bigint[]): bigint;
167+
168+
declare function min(array: readonly bigint[]): bigint;
169+
170+
declare function mul(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
171+
172+
declare function mulDiv(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
173+
174+
declare function mulDivUp(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
175+
176+
declare function powDiv(a: readonly bigint[], b: readonly bigint[] | bigint, c: readonly bigint[] | bigint): bigint[];
177+
178+
declare function sub(a: readonly bigint[], b: readonly bigint[] | bigint): bigint[];
179+
180+
declare function sum(array: readonly bigint[]): bigint;
181+
182+
export { type IRMFloatingParameters, type IRMParameters, MATURITY_INTERVAL, _default as MAX_UINT256, ONE_YEAR, SQ_WAD, TWO_WAD, WAD, abs, accountLiquidity, add, baseRate, borrowLimit, divWad, divWadUp, effectiveRate, expWad, fill, fixedRate, fixedRates, fixedUtilization, floatingDepositRates, floatingRate, floatingUtilization, globalUtilization, healthFactor, lnWad, log2, map2, map3, max$1 as max, max as maxV, mean, min$1 as min, min as minV, mul, mulDiv$1 as mulDiv, mulDivUp$1 as mulDivUp, mulDivUp as mulDivUpV, mulDiv as mulDivV, mulWad, mulWadUp, powDiv, splitInstallments, sqrt, sub, sum, withdrawLimit };

0 commit comments

Comments
 (0)