@instadapp/fluid-sui-read-sdk 0.0.0-stage → 0.2.0
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/README.md +182 -2
- package/dist/chunk-15K8U1wQ.mjs +18 -0
- package/dist/index.d.mts +2152 -0
- package/dist/index.mjs +3541 -0
- package/package.json +30 -4
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,2152 @@
|
|
|
1
|
+
import { ClientWithCoreApi } from "@mysten/sui/client";
|
|
2
|
+
import { BcsType } from "@mysten/sui/bcs";
|
|
3
|
+
import { Transaction, TransactionResult } from "@mysten/sui/transactions";
|
|
4
|
+
import * as _mysten_bcs0 from "@mysten/bcs";
|
|
5
|
+
|
|
6
|
+
//#region src/types.d.ts
|
|
7
|
+
/**
|
|
8
|
+
* Public types. Field names match `@jup-ag/lend-read` one-for-one wherever the protocol
|
|
9
|
+
* concept is the same; differences:
|
|
10
|
+
* - `PublicKey` → `string` (a Sui object id, or a coin type for tokens)
|
|
11
|
+
* - `BN` → `bigint`
|
|
12
|
+
* - Solana `nftId: number` → Sui `positionId: string` (+ `capId`, the PositionOwnerCap)
|
|
13
|
+
*/
|
|
14
|
+
type RateDataV1 = {
|
|
15
|
+
token: string;
|
|
16
|
+
rateAtUtilizationZero: bigint;
|
|
17
|
+
kink: bigint;
|
|
18
|
+
rateAtUtilizationKink: bigint;
|
|
19
|
+
rateAtUtilizationMax: bigint;
|
|
20
|
+
};
|
|
21
|
+
type RateDataV2 = {
|
|
22
|
+
token: string;
|
|
23
|
+
rateAtUtilizationZero: bigint;
|
|
24
|
+
kink1: bigint;
|
|
25
|
+
rateAtUtilizationKink1: bigint;
|
|
26
|
+
kink2: bigint;
|
|
27
|
+
rateAtUtilizationKink2: bigint;
|
|
28
|
+
rateAtUtilizationMax: bigint;
|
|
29
|
+
};
|
|
30
|
+
type RateData = {
|
|
31
|
+
token: string;
|
|
32
|
+
/** 0 = unset, 1 = V1, 2 = V2 (`TokenReserve.rate_data_version`). */
|
|
33
|
+
version: number;
|
|
34
|
+
rateDataV1: RateDataV1;
|
|
35
|
+
rateDataV2: RateDataV2;
|
|
36
|
+
};
|
|
37
|
+
type RateModelAccount = {
|
|
38
|
+
mint: string;
|
|
39
|
+
version: number;
|
|
40
|
+
rateAtUtilizationZero: bigint;
|
|
41
|
+
kink?: bigint;
|
|
42
|
+
rateAtUtilizationKink?: bigint;
|
|
43
|
+
kink1?: bigint;
|
|
44
|
+
rateAtUtilizationKink1?: bigint;
|
|
45
|
+
kink2?: bigint;
|
|
46
|
+
rateAtUtilizationKink2?: bigint;
|
|
47
|
+
rateAtUtilizationMax: bigint;
|
|
48
|
+
};
|
|
49
|
+
type ExchangePricesAndConfig = {
|
|
50
|
+
supplyExchangePrice: bigint;
|
|
51
|
+
borrowExchangePrice: bigint;
|
|
52
|
+
borrowRate: bigint;
|
|
53
|
+
fee: bigint;
|
|
54
|
+
lastStoredUtilization: bigint;
|
|
55
|
+
lastUpdateTimestamp: bigint;
|
|
56
|
+
maxUtilization: bigint;
|
|
57
|
+
};
|
|
58
|
+
type TotalAmounts = {
|
|
59
|
+
supplyRawInterest: bigint;
|
|
60
|
+
supplyInterestFree: bigint;
|
|
61
|
+
borrowRawInterest: bigint;
|
|
62
|
+
borrowInterestFree: bigint;
|
|
63
|
+
/** Solana-only concept (claim accounts); always 0 on Sui. */
|
|
64
|
+
totalClaimAmount: bigint;
|
|
65
|
+
};
|
|
66
|
+
type ExchangePriceResult = {
|
|
67
|
+
supplyExchangePrice: bigint;
|
|
68
|
+
borrowExchangePrice: bigint;
|
|
69
|
+
};
|
|
70
|
+
type OverallTokenData = {
|
|
71
|
+
rateData: RateData;
|
|
72
|
+
supplyExchangePrice: bigint;
|
|
73
|
+
borrowExchangePrice: bigint;
|
|
74
|
+
borrowRate: bigint;
|
|
75
|
+
fee: bigint;
|
|
76
|
+
lastStoredUtilization: bigint;
|
|
77
|
+
lastUpdateTimestamp: bigint;
|
|
78
|
+
maxUtilization: bigint;
|
|
79
|
+
supplyRawInterest: bigint;
|
|
80
|
+
supplyInterestFree: bigint;
|
|
81
|
+
borrowRawInterest: bigint;
|
|
82
|
+
borrowInterestFree: bigint;
|
|
83
|
+
totalSupply: bigint;
|
|
84
|
+
totalBorrow: bigint;
|
|
85
|
+
revenue: bigint;
|
|
86
|
+
supplyRate: bigint;
|
|
87
|
+
};
|
|
88
|
+
type UserSupplyPositionAccount = {
|
|
89
|
+
user: string;
|
|
90
|
+
mint: string;
|
|
91
|
+
amount: bigint;
|
|
92
|
+
withdrawalLimit: bigint;
|
|
93
|
+
baseWithdrawalLimit: bigint;
|
|
94
|
+
lastUpdateTimestamp: bigint;
|
|
95
|
+
expandPercent: bigint;
|
|
96
|
+
expandDuration: bigint;
|
|
97
|
+
modeWithInterest: boolean;
|
|
98
|
+
decayAmount: bigint;
|
|
99
|
+
decayDuration: bigint;
|
|
100
|
+
/** Sui extras. */
|
|
101
|
+
configured: boolean;
|
|
102
|
+
pausedSupply: boolean;
|
|
103
|
+
pausedWithdraw: boolean;
|
|
104
|
+
};
|
|
105
|
+
type UserBorrowPositionAccount = {
|
|
106
|
+
user: string;
|
|
107
|
+
mint: string;
|
|
108
|
+
amount: bigint;
|
|
109
|
+
borrowLimit: bigint;
|
|
110
|
+
baseBorrowLimit: bigint;
|
|
111
|
+
maxBorrowLimit: bigint;
|
|
112
|
+
lastUpdateTimestamp: bigint;
|
|
113
|
+
expandPercent: bigint;
|
|
114
|
+
expandDuration: bigint;
|
|
115
|
+
modeWithInterest: boolean;
|
|
116
|
+
/** Sui extras. */
|
|
117
|
+
configured: boolean;
|
|
118
|
+
pausedBorrow: boolean;
|
|
119
|
+
pausedPayback: boolean;
|
|
120
|
+
};
|
|
121
|
+
type UserSupplyData = {
|
|
122
|
+
modeWithInterest: boolean;
|
|
123
|
+
supply: bigint;
|
|
124
|
+
withdrawalLimit: bigint;
|
|
125
|
+
lastUpdateTimestamp: bigint;
|
|
126
|
+
expandPercent: bigint;
|
|
127
|
+
expandDuration: bigint;
|
|
128
|
+
baseWithdrawalLimit: bigint;
|
|
129
|
+
withdrawableUntilLimit: bigint;
|
|
130
|
+
withdrawable: bigint;
|
|
131
|
+
decayAmount: bigint;
|
|
132
|
+
decayEndTimestamp: bigint;
|
|
133
|
+
};
|
|
134
|
+
type UserBorrowData = {
|
|
135
|
+
modeWithInterest: boolean;
|
|
136
|
+
borrow: bigint;
|
|
137
|
+
borrowLimit: bigint;
|
|
138
|
+
lastUpdateTimestamp: bigint;
|
|
139
|
+
expandPercent: bigint;
|
|
140
|
+
expandDuration: bigint;
|
|
141
|
+
baseBorrowLimit: bigint;
|
|
142
|
+
maxBorrowLimit: bigint;
|
|
143
|
+
borrowLimitUtilization: bigint;
|
|
144
|
+
borrowableUntilLimit: bigint;
|
|
145
|
+
borrowable: bigint;
|
|
146
|
+
};
|
|
147
|
+
type LiquidityAccount = {
|
|
148
|
+
id: string;
|
|
149
|
+
version: bigint;
|
|
150
|
+
revenueCollector: string;
|
|
151
|
+
/** Global pause flags (true = paused). */
|
|
152
|
+
status: {
|
|
153
|
+
supply: boolean;
|
|
154
|
+
borrow: boolean;
|
|
155
|
+
payback: boolean;
|
|
156
|
+
withdraw: boolean;
|
|
157
|
+
};
|
|
158
|
+
activeCapsTableId: string;
|
|
159
|
+
activeCapsCount: bigint;
|
|
160
|
+
};
|
|
161
|
+
/** fToken = the lending (share) token on Sui, `Coin<FToken<T>>` (Solana calls it jlToken). */
|
|
162
|
+
type FTokenDetails = {
|
|
163
|
+
/** Sui: `FToken<T>` coin type. */
|
|
164
|
+
tokenAddress: string;
|
|
165
|
+
/** Sui: the `LendingState<T>` object id. */
|
|
166
|
+
lendingStateId: string;
|
|
167
|
+
name: string;
|
|
168
|
+
symbol: string;
|
|
169
|
+
decimals: number;
|
|
170
|
+
underlyingAddress: string;
|
|
171
|
+
totalAssets: bigint;
|
|
172
|
+
totalSupply: bigint;
|
|
173
|
+
conversionRateToShares: bigint;
|
|
174
|
+
conversionRateToAssets: bigint;
|
|
175
|
+
/**
|
|
176
|
+
* RATES: every rate field is bps (1e4 = 100% per year), floored. Raw 1e12 values:
|
|
177
|
+
* `liquidityMath.supplyRateAt` / `lendingMath.currentRewardsRate`.
|
|
178
|
+
*/
|
|
179
|
+
/** Rewards rate from the active schedule, priced on the pre-accrual TVL. bps. */
|
|
180
|
+
rewardsRate: bigint;
|
|
181
|
+
/** Organic (liquidity-layer) supply rate, exact on-chain formula. bps. */
|
|
182
|
+
supplyRate: bigint;
|
|
183
|
+
/** `supplyRate + rewardsRate`. bps. */
|
|
184
|
+
totalRate: bigint;
|
|
185
|
+
rebalanceDifference: bigint;
|
|
186
|
+
userSupplyData: UserSupplyData;
|
|
187
|
+
};
|
|
188
|
+
/** @deprecated Solana name; use `FTokenDetails`. */
|
|
189
|
+
type JlTokenDetails = FTokenDetails;
|
|
190
|
+
/**
|
|
191
|
+
* Generic per-fToken lending state (`lending.getLendingStateData`). Exchange prices are 1e12;
|
|
192
|
+
* amounts are in underlying token units (no USD: every lending token is USD-pegged); every rate
|
|
193
|
+
* is bps (1e4 = 100% per year).
|
|
194
|
+
*/
|
|
195
|
+
type LendingStateData = {
|
|
196
|
+
/** `FToken<T>` coin type (the share coin is `Coin<FToken<T>>`). */
|
|
197
|
+
fTokenType: string;
|
|
198
|
+
/** Underlying coin type `T`. */
|
|
199
|
+
asset: string;
|
|
200
|
+
decimals: number;
|
|
201
|
+
lendingStateId: string;
|
|
202
|
+
/** Chain time (unix s, on-chain Clock) every "accrued" value below is computed at. */
|
|
203
|
+
timestamp: bigint;
|
|
204
|
+
/** fToken -> underlying, rewards INCLUDED, accrued to `timestamp`. */
|
|
205
|
+
tokenExchangePrice: bigint;
|
|
206
|
+
/** The underlying's liquidity-layer supply exchange price, rewards EXCLUDED, accrued to `timestamp`. */
|
|
207
|
+
liquidityExchangePrice: bigint;
|
|
208
|
+
/** As stored on LendingState at its last update (no accrual). */
|
|
209
|
+
storedTokenExchangePrice: bigint;
|
|
210
|
+
storedLiquidityExchangePrice: bigint;
|
|
211
|
+
/** LendingState last update; `timestamp - lastUpdateS` = how stale the stored prices are. */
|
|
212
|
+
lastUpdateS: bigint;
|
|
213
|
+
/** TokenReserve (liquidity layer) last update. */
|
|
214
|
+
liquidityLastUpdateS: bigint;
|
|
215
|
+
/** fToken shares outstanding. */
|
|
216
|
+
totalShares: bigint;
|
|
217
|
+
/** `totalShares` at the accrued `tokenExchangePrice`, token units (floor, = accounting::total_assets). */
|
|
218
|
+
totalAssets: bigint;
|
|
219
|
+
/** Organic liquidity supply rate (exact on-chain formula). */
|
|
220
|
+
supplyRate: bigint;
|
|
221
|
+
/** Rewards rate from the active window, priced on the pre-accrual TVL as the contract does. */
|
|
222
|
+
rewardsRate: bigint;
|
|
223
|
+
/** `supplyRate + rewardsRate`. */
|
|
224
|
+
totalRate: bigint;
|
|
225
|
+
/** Rewards schedule as stored; `null` when the pool has none. Times are unix seconds. */
|
|
226
|
+
rewards: {
|
|
227
|
+
startTvl: bigint;
|
|
228
|
+
startS: bigint;
|
|
229
|
+
endS: bigint;
|
|
230
|
+
yearlyReward: bigint;
|
|
231
|
+
nextStartS: bigint;
|
|
232
|
+
nextEndS: bigint;
|
|
233
|
+
nextYearlyReward: bigint;
|
|
234
|
+
} | null;
|
|
235
|
+
};
|
|
236
|
+
/** One wallet holding `Coin<FToken<T>>` objects. */
|
|
237
|
+
type FTokenHolder = {
|
|
238
|
+
/** Wallet address (AddressOwner or ConsensusAddressOwner). */
|
|
239
|
+
owner: string;
|
|
240
|
+
/** Sum of the wallet's Coin<FToken<T>> objects at `checkpoint` (shares). */
|
|
241
|
+
balance: bigint;
|
|
242
|
+
/** Number of coin objects summed. */
|
|
243
|
+
coins: number;
|
|
244
|
+
/** Cross-check via fullnode `getBalance` (live, after the checkpoint). Present when `verify`. */
|
|
245
|
+
rpc?: {
|
|
246
|
+
balance: bigint;
|
|
247
|
+
coinBalance: bigint;
|
|
248
|
+
addressBalance: bigint;
|
|
249
|
+
};
|
|
250
|
+
/** `rpc.coinBalance === balance && rpc.addressBalance === 0n`. A mismatch means the wallet moved
|
|
251
|
+
* shares after `checkpoint` or holds an address balance (credited without a coin object). */
|
|
252
|
+
agrees?: boolean;
|
|
253
|
+
};
|
|
254
|
+
type FTokenHolders = {
|
|
255
|
+
fTokenType: string;
|
|
256
|
+
asset: string;
|
|
257
|
+
/** Checkpoint the coin listing and `totalSupply` were read at. */
|
|
258
|
+
checkpoint: bigint;
|
|
259
|
+
/** Wallets, largest first. */
|
|
260
|
+
holders: FTokenHolder[];
|
|
261
|
+
/** Sum of `holders[].balance`. */
|
|
262
|
+
countedTotal: bigint;
|
|
263
|
+
/** LendingState total shares at `checkpoint`. */
|
|
264
|
+
totalSupply: bigint;
|
|
265
|
+
};
|
|
266
|
+
type LendingUserPosition = {
|
|
267
|
+
/** fToken shares held (`Coin<FToken<T>>` balance). */
|
|
268
|
+
fTokenShares: bigint;
|
|
269
|
+
underlyingAssets: bigint;
|
|
270
|
+
underlyingBalance: bigint;
|
|
271
|
+
};
|
|
272
|
+
type FTokenDetailsUserPosition = {
|
|
273
|
+
fTokenDetails: FTokenDetails;
|
|
274
|
+
userPosition: LendingUserPosition;
|
|
275
|
+
};
|
|
276
|
+
/** @deprecated Solana name; use `FTokenDetailsUserPosition`. */
|
|
277
|
+
type JlTokenDetailsUserPosition = FTokenDetailsUserPosition;
|
|
278
|
+
type RewardsRateModelConfig = {
|
|
279
|
+
duration: bigint;
|
|
280
|
+
startTime: bigint;
|
|
281
|
+
endTime: bigint;
|
|
282
|
+
startTvl: bigint;
|
|
283
|
+
maxRate: bigint;
|
|
284
|
+
rewardAmount: bigint;
|
|
285
|
+
/** Sui extras: the queued next schedule. `maxRate` is bps (5000 = the 50% cap). */
|
|
286
|
+
nextStartTime: bigint;
|
|
287
|
+
nextEndTime: bigint;
|
|
288
|
+
nextRewardAmount: bigint;
|
|
289
|
+
};
|
|
290
|
+
type PreviewData = {
|
|
291
|
+
previewDeposit: bigint;
|
|
292
|
+
previewMint: bigint;
|
|
293
|
+
previewWithdraw: bigint;
|
|
294
|
+
previewRedeem: bigint;
|
|
295
|
+
};
|
|
296
|
+
type FTokenInternalData = {
|
|
297
|
+
/** Sui: TokenReserve<T> id backing the pool. */
|
|
298
|
+
liquidity: string;
|
|
299
|
+
/** Sui: LendingRegistry id. */
|
|
300
|
+
lendingFactory: string;
|
|
301
|
+
/** Sui: rewards writer cap id, if one is installed. */
|
|
302
|
+
lendingRewardsRateModel: string | null;
|
|
303
|
+
liquidityBalance: bigint;
|
|
304
|
+
liquidityExchangePrice: bigint;
|
|
305
|
+
tokenExchangePrice: bigint;
|
|
306
|
+
};
|
|
307
|
+
/** @deprecated Solana name; use `FTokenInternalData`. */
|
|
308
|
+
type JlTokenInternalData = FTokenInternalData;
|
|
309
|
+
type LendingAccount = {
|
|
310
|
+
id: string;
|
|
311
|
+
mint: string;
|
|
312
|
+
fTokenMint: string;
|
|
313
|
+
decimals: number;
|
|
314
|
+
totalShares: bigint;
|
|
315
|
+
liquidityExchangePrice: bigint;
|
|
316
|
+
tokenExchangePrice: bigint;
|
|
317
|
+
lastUpdateTimestamp: bigint;
|
|
318
|
+
tokenReservesLiquidity: string;
|
|
319
|
+
rewardsWriter: string | null;
|
|
320
|
+
};
|
|
321
|
+
type ConstantViews = {
|
|
322
|
+
liquidity: string;
|
|
323
|
+
/** Collateral TokenReserve id. */
|
|
324
|
+
supply: string;
|
|
325
|
+
/** Debt TokenReserve id. */
|
|
326
|
+
borrow: string;
|
|
327
|
+
supplyToken: string;
|
|
328
|
+
borrowToken: string;
|
|
329
|
+
vaultId: number;
|
|
330
|
+
vaultType: number;
|
|
331
|
+
};
|
|
332
|
+
type Configs = {
|
|
333
|
+
supplyRateMagnifier: bigint;
|
|
334
|
+
borrowRateMagnifier: bigint;
|
|
335
|
+
collateralFactor: bigint;
|
|
336
|
+
liquidationThreshold: bigint;
|
|
337
|
+
liquidationMaxLimit: bigint;
|
|
338
|
+
withdrawalGap: bigint;
|
|
339
|
+
liquidationPenalty: bigint;
|
|
340
|
+
borrowFee: bigint;
|
|
341
|
+
oracle: string;
|
|
342
|
+
oraclePriceOperate?: bigint;
|
|
343
|
+
oraclePriceLiquidate?: bigint;
|
|
344
|
+
lastUpdateTimestamp?: bigint;
|
|
345
|
+
};
|
|
346
|
+
type ExchangePricesAndRates = {
|
|
347
|
+
lastStoredLiquiditySupplyExchangePrice: bigint;
|
|
348
|
+
lastStoredLiquidityBorrowExchangePrice: bigint;
|
|
349
|
+
lastStoredVaultSupplyExchangePrice: bigint;
|
|
350
|
+
lastStoredVaultBorrowExchangePrice: bigint;
|
|
351
|
+
liquiditySupplyExchangePrice: bigint;
|
|
352
|
+
liquidityBorrowExchangePrice: bigint;
|
|
353
|
+
vaultSupplyExchangePrice: bigint;
|
|
354
|
+
vaultBorrowExchangePrice: bigint;
|
|
355
|
+
supplyRateLiquidity: bigint;
|
|
356
|
+
borrowRateLiquidity: bigint;
|
|
357
|
+
supplyRateVault: bigint;
|
|
358
|
+
borrowRateVault: bigint;
|
|
359
|
+
rewardsOrFeeRateSupply: bigint;
|
|
360
|
+
rewardsOrFeeRateBorrow: bigint;
|
|
361
|
+
};
|
|
362
|
+
type TotalSupplyAndBorrow = {
|
|
363
|
+
totalSupplyVault: bigint;
|
|
364
|
+
totalBorrowVault: bigint;
|
|
365
|
+
totalSupplyLiquidityOrDex: bigint;
|
|
366
|
+
totalBorrowLiquidityOrDex: bigint;
|
|
367
|
+
absorbedSupply: bigint;
|
|
368
|
+
absorbedBorrow: bigint;
|
|
369
|
+
};
|
|
370
|
+
type LimitsAndAvailability = {
|
|
371
|
+
withdrawLimit: bigint;
|
|
372
|
+
withdrawableUntilLimit: bigint;
|
|
373
|
+
withdrawable: bigint;
|
|
374
|
+
borrowLimit: bigint;
|
|
375
|
+
borrowLimitUtilization: bigint;
|
|
376
|
+
borrowableUntilLimit: bigint;
|
|
377
|
+
borrowable: bigint;
|
|
378
|
+
minimumBorrowing: bigint;
|
|
379
|
+
};
|
|
380
|
+
type CurrentBranchState = {
|
|
381
|
+
/** 0 NotLiquidated · 1 Liquidated · 2 Merged · 3 Closed. */
|
|
382
|
+
status: number;
|
|
383
|
+
minimaTick: number;
|
|
384
|
+
debtFactor: bigint;
|
|
385
|
+
partials: bigint;
|
|
386
|
+
debtLiquidity: bigint;
|
|
387
|
+
baseBranchId: number;
|
|
388
|
+
baseBranchMinima: number;
|
|
389
|
+
};
|
|
390
|
+
type VaultState = {
|
|
391
|
+
topTick: number;
|
|
392
|
+
currentBranch: number;
|
|
393
|
+
totalBranch: number;
|
|
394
|
+
totalSupply: bigint;
|
|
395
|
+
totalBorrow: bigint;
|
|
396
|
+
/** Positions ever opened (EVM parity). DERIVED on Sui (no on-chain counter): events + object
|
|
397
|
+
* reads via `vault.getVaultPositionCounts`; -1 if `positionCounts: false` or endpoint down. */
|
|
398
|
+
totalPositions: number;
|
|
399
|
+
currentBranchState?: CurrentBranchState;
|
|
400
|
+
branchLiquidated: boolean;
|
|
401
|
+
absorbedDebtAmount: bigint;
|
|
402
|
+
absorbedColAmount: bigint;
|
|
403
|
+
absorbedDustDebt: bigint;
|
|
404
|
+
liquiditySupplyExchangePrice: bigint;
|
|
405
|
+
liquidityBorrowExchangePrice: bigint;
|
|
406
|
+
vaultSupplyExchangePrice: bigint;
|
|
407
|
+
vaultBorrowExchangePrice: bigint;
|
|
408
|
+
/** `totalPositions + 1`, DERIVED. Ordinal only: Sui position ids are object ids. -1 as above. */
|
|
409
|
+
nextPositionId: number;
|
|
410
|
+
/** Sui extra: seconds. */
|
|
411
|
+
lastUpdateTimestamp: bigint;
|
|
412
|
+
};
|
|
413
|
+
type VaultConfig = {
|
|
414
|
+
vaultId: number;
|
|
415
|
+
/** Sui: the VaultMarket object id. */
|
|
416
|
+
vault: string;
|
|
417
|
+
supplyRateMagnifier: number;
|
|
418
|
+
borrowRateMagnifier: number;
|
|
419
|
+
collateralFactor: number;
|
|
420
|
+
liquidationThreshold: number;
|
|
421
|
+
liquidationMaxLimit: number;
|
|
422
|
+
withdrawGap: number;
|
|
423
|
+
liquidationPenalty: number;
|
|
424
|
+
borrowFee: number;
|
|
425
|
+
oracle: string;
|
|
426
|
+
liquidityProgram: string;
|
|
427
|
+
oracleProgram: string;
|
|
428
|
+
supplyToken: string;
|
|
429
|
+
borrowToken: string;
|
|
430
|
+
vaultType: number;
|
|
431
|
+
collateralDecimals: number;
|
|
432
|
+
debtDecimals: number;
|
|
433
|
+
};
|
|
434
|
+
type VaultEntireData = {
|
|
435
|
+
vault: string;
|
|
436
|
+
isSmartCol: boolean;
|
|
437
|
+
isSmartDebt: boolean;
|
|
438
|
+
constantViews: ConstantViews;
|
|
439
|
+
configs: Configs;
|
|
440
|
+
exchangePricesAndRates: ExchangePricesAndRates;
|
|
441
|
+
limitsAndAvailability: LimitsAndAvailability;
|
|
442
|
+
liquidityUserSupplyData: UserSupplyData;
|
|
443
|
+
liquidityUserBorrowData: UserBorrowData;
|
|
444
|
+
vaultState: VaultState;
|
|
445
|
+
totalSupplyAndBorrow: TotalSupplyAndBorrow;
|
|
446
|
+
};
|
|
447
|
+
type VaultEntireDataV2 = VaultEntireData & {
|
|
448
|
+
vaultId: number;
|
|
449
|
+
vaultType: number;
|
|
450
|
+
/** No DEX on Sui yet. */
|
|
451
|
+
supplyDex: null;
|
|
452
|
+
borrowDex: null;
|
|
453
|
+
supplyDexPosition: null;
|
|
454
|
+
borrowDexPosition: null;
|
|
455
|
+
};
|
|
456
|
+
/** Raw on-chain Position (Solana `UserPosition`). */
|
|
457
|
+
type UserPosition = {
|
|
458
|
+
vaultId: number;
|
|
459
|
+
/** Sui: Position object id (Solana nftId). */
|
|
460
|
+
positionId: string;
|
|
461
|
+
/** Sui: VaultMarket object id. */
|
|
462
|
+
vault: string;
|
|
463
|
+
/** Sui: PositionOwnerCap id (Solana positionMint). */
|
|
464
|
+
positionMint: string;
|
|
465
|
+
isSupplyOnlyPosition: boolean;
|
|
466
|
+
tick: number;
|
|
467
|
+
tickId: number;
|
|
468
|
+
supplyAmount: bigint;
|
|
469
|
+
dustDebtAmount: bigint;
|
|
470
|
+
};
|
|
471
|
+
type UserPositionWithDebt = {
|
|
472
|
+
tick: number;
|
|
473
|
+
tickId: number;
|
|
474
|
+
colRaw: bigint;
|
|
475
|
+
debtRaw: bigint;
|
|
476
|
+
dustDebtRaw: bigint;
|
|
477
|
+
finalAmount: bigint;
|
|
478
|
+
isSupplyOnlyPosition: boolean;
|
|
479
|
+
userLiquidationStatus?: boolean;
|
|
480
|
+
postLiquidationBranchId?: number;
|
|
481
|
+
};
|
|
482
|
+
type NftPosition = {
|
|
483
|
+
/** Sui: Position object id. */
|
|
484
|
+
nftId: string;
|
|
485
|
+
/** Owner of the PositionOwnerCap (address, or object id when wrapped/object-owned). */
|
|
486
|
+
owner: string | null;
|
|
487
|
+
capId: string;
|
|
488
|
+
isSupplyPosition: boolean;
|
|
489
|
+
supply: bigint;
|
|
490
|
+
beforeSupply: bigint;
|
|
491
|
+
dustBorrow: bigint;
|
|
492
|
+
beforeDustBorrow: bigint;
|
|
493
|
+
tick: number;
|
|
494
|
+
tickId: number;
|
|
495
|
+
borrow: bigint;
|
|
496
|
+
beforeBorrow: bigint;
|
|
497
|
+
isLiquidated: boolean;
|
|
498
|
+
};
|
|
499
|
+
type DecodedTick = {
|
|
500
|
+
isLiquidated: boolean;
|
|
501
|
+
totalIds: number;
|
|
502
|
+
rawDebt: bigint;
|
|
503
|
+
isFullyLiquidated: boolean;
|
|
504
|
+
liquidationBranchId: number;
|
|
505
|
+
debtFactor: bigint;
|
|
506
|
+
};
|
|
507
|
+
type DecodedBranch = {
|
|
508
|
+
branchId: number;
|
|
509
|
+
status: number;
|
|
510
|
+
minimaTick: number;
|
|
511
|
+
minimaTickPartials: number;
|
|
512
|
+
debtLiquidity: bigint;
|
|
513
|
+
debtFactor: bigint;
|
|
514
|
+
connectedBranchId: number;
|
|
515
|
+
connectedMinimaTick: number;
|
|
516
|
+
};
|
|
517
|
+
type DecodedTickIdLiquidation = {
|
|
518
|
+
isFullyLiquidated: boolean;
|
|
519
|
+
liquidationBranchId: number;
|
|
520
|
+
debtFactor: bigint;
|
|
521
|
+
};
|
|
522
|
+
type PositionWithRiskRatio = NftPosition & {
|
|
523
|
+
vaultId: number;
|
|
524
|
+
/** debt / (collateral * oracle price), 1e4 scale (e.g. 7500 = 75%). */
|
|
525
|
+
riskRatio: bigint;
|
|
526
|
+
};
|
|
527
|
+
type OraclePrice = {
|
|
528
|
+
oracle: string;
|
|
529
|
+
/** Collateral-per-debt price used on operate (1e15). `null` = the operate view aborts right now (v2: a route stale/invalid). */
|
|
530
|
+
operate: bigint | null;
|
|
531
|
+
/** Price used on liquidate (1e15). `null` = the liquidate view aborts (v2: every route dead). */
|
|
532
|
+
liquidate: bigint | null;
|
|
533
|
+
/** v2: abort reason of the operate view, when `operate` is null. */
|
|
534
|
+
operateError?: string;
|
|
535
|
+
liquidateError?: string;
|
|
536
|
+
};
|
|
537
|
+
type OracleSource = {
|
|
538
|
+
/** 0x-hex 32-byte feed id. */
|
|
539
|
+
feedId: string;
|
|
540
|
+
invert: boolean;
|
|
541
|
+
provider: "redstone" | "pyth";
|
|
542
|
+
/** RedStone only: the PriceAdapter the oracle is pinned to. */
|
|
543
|
+
adapterId?: string;
|
|
544
|
+
};
|
|
545
|
+
type OracleData = {
|
|
546
|
+
id: string;
|
|
547
|
+
nonce: number;
|
|
548
|
+
main: OracleSource;
|
|
549
|
+
guard: OracleSource | null;
|
|
550
|
+
};
|
|
551
|
+
/** One route read on its own (see `Oracle.getOracleRoutes`). */
|
|
552
|
+
type OracleRoute = OracleSource & {
|
|
553
|
+
rawPrice: bigint;
|
|
554
|
+
decimals: number;
|
|
555
|
+
/** 1e15 rate this route contributes (0 when invalid). */
|
|
556
|
+
rate: bigint;
|
|
557
|
+
publishedMs: bigint;
|
|
558
|
+
/** Seconds since publish at the chain clock (-1 = timestamp in the future). */
|
|
559
|
+
ageS: bigint;
|
|
560
|
+
/** Pyth only. */
|
|
561
|
+
confidence?: bigint;
|
|
562
|
+
usableOperate: boolean;
|
|
563
|
+
usableLiquidate: boolean;
|
|
564
|
+
};
|
|
565
|
+
declare namespace liquidity_d_exports {
|
|
566
|
+
export { MathVariant, ReserveSnapshot, calcBorrowLimitBeforeOperate, calcRevenue, calcWithdrawalLimitBeforeOperate, calculateExchangePrice, emptyUserBorrowData, emptyUserSupplyData, processOverallTokenData, processUserBorrowData, processUserSupplyData, supplyRateAt, supplyRateRaw, totalAmountsOf, totalBorrowNormal, totalSupplyNormal };
|
|
567
|
+
}
|
|
568
|
+
/** The TokenReserve fields the exchange-price maths needs. */
|
|
569
|
+
type ReserveSnapshot = {
|
|
570
|
+
supplyExchangePrice: bigint;
|
|
571
|
+
borrowExchangePrice: bigint;
|
|
572
|
+
borrowRate: bigint;
|
|
573
|
+
fee: bigint;
|
|
574
|
+
lastUtilization: bigint;
|
|
575
|
+
lastUpdateTimestamp: bigint;
|
|
576
|
+
maxUtilization: bigint;
|
|
577
|
+
totalSupplyWithInterest: bigint;
|
|
578
|
+
totalSupplyInterestFree: bigint;
|
|
579
|
+
totalBorrowWithInterest: bigint;
|
|
580
|
+
totalBorrowInterestFree: bigint;
|
|
581
|
+
/** Coin balance held by the reserve. */
|
|
582
|
+
vaultBalance: bigint;
|
|
583
|
+
};
|
|
584
|
+
/**
|
|
585
|
+
* Which on-chain liquidity/lending maths a deployment runs.
|
|
586
|
+
* - "audited": fluid-packages-sui after the audit fixes (7e470fb, in 742ea21 and later): the
|
|
587
|
+
* borrow with-interest/free ratio uses the PRE-accrual borrow exchange price, the inverted
|
|
588
|
+
* supply ratio is computed at full precision, and the rewards TVL is rounded up.
|
|
589
|
+
* - "pre-audit": the 2026-09-18 staging packages (verified from deployed bytecode 2026-10-26):
|
|
590
|
+
* ratio on the accrued borrow price, inverse of the floored 1e4 ratio, rewards TVL floored.
|
|
591
|
+
*/
|
|
592
|
+
type MathVariant = "pre-audit" | "audited";
|
|
593
|
+
/**
|
|
594
|
+
* Supply rate the reserve credits for a period starting from these exchange prices, at
|
|
595
|
+
* `SUPPLY_RATE_PRECISION` (1e12 = 100% per year): exactly `borrow_rate * ratio_supply_yield * (1e4 - fee)`
|
|
596
|
+
* from `reserve::calculate_exchange_prices` (interest-free ratios on both sides, fee applied).
|
|
597
|
+
* `borrowEpForRatio` is the borrow exchange price the contract normalises the borrow ratio with.
|
|
598
|
+
*/
|
|
599
|
+
declare function supplyRateRaw(r: ReserveSnapshot, supplyExchangePrice: bigint, borrowEpForRatio: bigint, variant: MathVariant): bigint;
|
|
600
|
+
/** `reserve::calculate_exchange_prices(now)`. */
|
|
601
|
+
declare function calculateExchangePrice(r: ReserveSnapshot, now: bigint, variant?: MathVariant): ExchangePriceResult;
|
|
602
|
+
/**
|
|
603
|
+
* Instantaneous liquidity supply rate at `now` (1e12 = 100%): the rate the contract would credit
|
|
604
|
+
* for the period starting at `now`, i.e. `supplyRateRaw` on both exchange prices accrued to `now`.
|
|
605
|
+
*/
|
|
606
|
+
declare function supplyRateAt(r: ReserveSnapshot, now: bigint, variant?: MathVariant): bigint;
|
|
607
|
+
/** `liquidity_calcs::get_total_supply` (floor). */
|
|
608
|
+
declare const totalSupplyNormal: (r: ReserveSnapshot, supplyEp: bigint) => bigint;
|
|
609
|
+
/** `liquidity_calcs::get_total_borrow` (floor). */
|
|
610
|
+
declare const totalBorrowNormal: (r: ReserveSnapshot, borrowEp: bigint) => bigint;
|
|
611
|
+
/** `reserve::calc_revenue` (supply side ceiled, saturating at 0). */
|
|
612
|
+
declare function calcRevenue(r: ReserveSnapshot, supplyEp: bigint, borrowEp: bigint): bigint;
|
|
613
|
+
declare function totalAmountsOf(r: ReserveSnapshot): TotalAmounts;
|
|
614
|
+
/**
|
|
615
|
+
* Same shape as the Solana reader's `processOverallTokenData`. `supplyRate` (bps) is the exact
|
|
616
|
+
* on-chain supply rate at `now` (`supplyRateAt`, floored to bps), not the Solana approximation.
|
|
617
|
+
*/
|
|
618
|
+
declare function processOverallTokenData(r: ReserveSnapshot, rateData: RateData, now: bigint, variant?: MathVariant): OverallTokenData;
|
|
619
|
+
/** `liquidity_calcs::calc_withdrawal_limit_before_operate`. */
|
|
620
|
+
declare function calcWithdrawalLimitBeforeOperate(userAmount: bigint, lastLimit: bigint, expandPercent: bigint, expandDuration: bigint, lastUpdate: bigint, now: bigint): bigint;
|
|
621
|
+
/** `liquidity_calcs::calc_borrow_limit_before_operate`. */
|
|
622
|
+
declare function calcBorrowLimitBeforeOperate(userAmount: bigint, lastLimit: bigint, expandPercent: bigint, expandDuration: bigint, baseLimit: bigint, maxLimit: bigint, lastUpdate: bigint, now: bigint): bigint;
|
|
623
|
+
declare function emptyUserSupplyData(): UserSupplyData;
|
|
624
|
+
declare function emptyUserBorrowData(): UserBorrowData;
|
|
625
|
+
/** Solana `processUserSupplyData`, with Sui's decay fields. */
|
|
626
|
+
declare function processUserSupplyData(acc: UserSupplyPositionAccount | null, overall: OverallTokenData, liquidityBalance: bigint, now: bigint): UserSupplyData;
|
|
627
|
+
/** Solana `processUserBorrowData`. */
|
|
628
|
+
declare function processUserBorrowData(acc: UserBorrowPositionAccount | null, overall: OverallTokenData, liquidityBalance: bigint, now: bigint): UserBorrowData;
|
|
629
|
+
//#endregion
|
|
630
|
+
//#region src/config.d.ts
|
|
631
|
+
type PackageIds = {
|
|
632
|
+
/** Latest version: target of move calls (views). */
|
|
633
|
+
packageId: string;
|
|
634
|
+
/** First version: address used in type tags and derived-object keys. */
|
|
635
|
+
originalId: string;
|
|
636
|
+
};
|
|
637
|
+
type FluidReadConfig = {
|
|
638
|
+
network: string;
|
|
639
|
+
packages: {
|
|
640
|
+
library: PackageIds;
|
|
641
|
+
liquidity: PackageIds;
|
|
642
|
+
lending: PackageIds;
|
|
643
|
+
/** Optional: lending rewards package (write-SDK parity; no read views depend on it yet). */
|
|
644
|
+
lendingRewards?: PackageIds;
|
|
645
|
+
oracle: PackageIds;
|
|
646
|
+
vaults: PackageIds;
|
|
647
|
+
};
|
|
648
|
+
objects: {
|
|
649
|
+
liquidityRegistry: string;
|
|
650
|
+
lendingRegistry: string;
|
|
651
|
+
oracleRegistry: string;
|
|
652
|
+
vaultRegistry: string;
|
|
653
|
+
liquidityAuth?: string;
|
|
654
|
+
lendingAuth?: string;
|
|
655
|
+
rewardsAuth?: string;
|
|
656
|
+
oracleAuth?: string;
|
|
657
|
+
vaultAdmin?: string;
|
|
658
|
+
};
|
|
659
|
+
/** RedStone main + optional Pyth guard; provider objects the quote needs. Pyth PriceInfoObjects keyed by 0x-hex feed id. */
|
|
660
|
+
oracle?: {
|
|
661
|
+
/** RedStone adapter used when an oracle has no RedStone route (the call still takes one). */
|
|
662
|
+
redstoneAdapter: string;
|
|
663
|
+
/** Package to call RedStone views on (route transparency only). */
|
|
664
|
+
redstonePackage: string;
|
|
665
|
+
pythPriceInfoObjects: Record<string, string>;
|
|
666
|
+
/** Pyth State + Wormhole State (write-SDK parity, needed only to build a Pyth price update). */
|
|
667
|
+
pythStateId?: string;
|
|
668
|
+
wormholeStateId?: string;
|
|
669
|
+
};
|
|
670
|
+
/**
|
|
671
|
+
* Coin types seeded into token discovery. Token discovery is pure state: these, plus the
|
|
672
|
+
* collateral/debt types of every VaultMarket (vault ids 1..total_vaults from the registry).
|
|
673
|
+
* Coverage is checked against `Registry.active_caps.size`; see `Liquidity.discoverTokens`.
|
|
674
|
+
*/
|
|
675
|
+
tokens?: string[];
|
|
676
|
+
/** Fullnode endpoints, tried in order with failover. "jsonrpc+https://..." selects JSON-RPC. */
|
|
677
|
+
rpcUrls?: string[];
|
|
678
|
+
/**
|
|
679
|
+
* Type of the proposed on-chain position-index key (docs/onchain-position-index.md). A struct
|
|
680
|
+
* added in a package upgrade is defined at the upgraded package id, so set this to
|
|
681
|
+
* `<upgraded vaults package>::position_index::PositionIndexKey` once it ships. Default assumes
|
|
682
|
+
* `<vaults originalId>::position_index::PositionIndexKey`.
|
|
683
|
+
*/
|
|
684
|
+
positionIndexKeyType?: string;
|
|
685
|
+
/** GraphQL indexer endpoint. Used with `discovery: "indexer"`, holder lists and checkpoint reads. */
|
|
686
|
+
graphqlUrl?: string;
|
|
687
|
+
/**
|
|
688
|
+
* On-chain maths the deployment runs (see `MathVariant`). Default "audited" (fluid-packages-sui
|
|
689
|
+
* 742ea21 and later). The 2026-09-18 staging liquidity/lending packages run "pre-audit".
|
|
690
|
+
*/
|
|
691
|
+
mathVariant?: MathVariant;
|
|
692
|
+
};
|
|
693
|
+
/**
|
|
694
|
+
* STAGING deployment on Sui mainnet (staging deployment gist, 2026-09-30). NOT a final production
|
|
695
|
+
* deployment: ids change at the production launch. Build
|
|
696
|
+
* your own config from a deployment record with `configFromDeployment`.
|
|
697
|
+
*
|
|
698
|
+
* Fluid Sui staging-on-mainnet: library / liquidity / lending
|
|
699
|
+
* from 2026-09-18; oracle (RedStone main + Pyth guard) and vaults redeployed 2026-09-30.
|
|
700
|
+
* Vault 1 = VaultMarket<SUI, USDC> 0x3ba55ebc…72b8 on oracle nonce 1 (0x1a690d20…b279).
|
|
701
|
+
* Vault 2 = VaultMarket<SUI, USDSUI> 0x5120…0efa. fTokens: fUSDC, fUSDSUI.
|
|
702
|
+
* Ids match the write SDK (fluid-packages-sui deployments/mainnet.json @ 06828ff, 2026-10-01) and
|
|
703
|
+
* the live staging deployment (re-read on chain 2026-10-10). Alias: network "staging".
|
|
704
|
+
*/
|
|
705
|
+
declare const STAGING: FluidReadConfig;
|
|
706
|
+
/**
|
|
707
|
+
* @deprecated Misleading name kept for compatibility: this is the STAGING deployment
|
|
708
|
+
* (`STAGING`), not production. Use `STAGING` / network "staging".
|
|
709
|
+
*/
|
|
710
|
+
declare const MAINNET: FluidReadConfig;
|
|
711
|
+
declare const CONFIGS: Record<string, FluidReadConfig>;
|
|
712
|
+
/**
|
|
713
|
+
* Deployment record: per-package ids plus the shared object ids the SDK reads. The ids alone are
|
|
714
|
+
* not enough: `liquidity`, `lending`, `oracle` and `vaults` must each carry `objects.registry`
|
|
715
|
+
* (see "Deployment record shape" in the README).
|
|
716
|
+
*/
|
|
717
|
+
type DeploymentRecord = {
|
|
718
|
+
packages: Record<"library" | "liquidity" | "lending" | "oracle" | "vaults" | "lending_rewards", {
|
|
719
|
+
packageId: string;
|
|
720
|
+
originalId?: string;
|
|
721
|
+
objects?: Record<string, string>;
|
|
722
|
+
} | undefined>;
|
|
723
|
+
};
|
|
724
|
+
/**
|
|
725
|
+
* Build a read config from a deployment record instead of the built-in ids, e.g.
|
|
726
|
+
* `configFromDeployment(JSON.parse(readFileSync(path, "utf8")), { network: "mainnet", oracle })`.
|
|
727
|
+
* The record has no RedStone package or Pyth feed map, so `oracle` comes from the caller.
|
|
728
|
+
* Throws once, listing every required field the record is missing.
|
|
729
|
+
*/
|
|
730
|
+
declare function configFromDeployment(rec: DeploymentRecord, opts: Pick<FluidReadConfig, "network" | "oracle"> & Partial<Pick<FluidReadConfig, "tokens" | "rpcUrls" | "graphqlUrl" | "mathVariant">>): FluidReadConfig;
|
|
731
|
+
declare function resolveConfig(networkOrConfig: string | FluidReadConfig | undefined): FluidReadConfig;
|
|
732
|
+
//#endregion
|
|
733
|
+
//#region src/derive.d.ts
|
|
734
|
+
declare function createDerive(cfg: FluidReadConfig): {
|
|
735
|
+
/** `TokenReserve<T>`: derived from the liquidity Registry, key `ReserveKey<T>`. */
|
|
736
|
+
tokenReserveId: (coinType: string) => string;
|
|
737
|
+
/** `LendingState<T>`: derived from the LendingRegistry, key `LendingStateKey<T>`. */
|
|
738
|
+
lendingStateId: (coinType: string) => string;
|
|
739
|
+
/** `VaultMarket<Col, Debt>`: derived from the VaultRegistry, key `VaultKey(u64)`. */
|
|
740
|
+
vaultMarketId: (vaultId: number | bigint) => string;
|
|
741
|
+
/** `Position`: derived from its VaultMarket, key `PositionKey(cap id)`. */
|
|
742
|
+
positionId: (vaultMarketId: string, capId: string) => string;
|
|
743
|
+
holderKeyType: string;
|
|
744
|
+
/** Entry of `TokenReserve.supply_positions` / `borrow_positions` for `Holder::Object(id)`. */
|
|
745
|
+
holderEntryId: (tableId: string, holderObjectId: string) => string;
|
|
746
|
+
/** `RateDataKey` dynamic field on a TokenReserve. */
|
|
747
|
+
rateDataId: (reserveId: string) => string;
|
|
748
|
+
/** `RewardsKey` dynamic field on a LendingState. */
|
|
749
|
+
rewardsId: (lendingStateId: string) => string;
|
|
750
|
+
/** `VaultMarket.ticks` entry. */
|
|
751
|
+
tickEntryId: (ticksTableId: string, tick: number) => string;
|
|
752
|
+
/** `VaultMarket.branches` entry. */
|
|
753
|
+
branchEntryId: (branchesTableId: string, branchId: number | bigint | string) => string;
|
|
754
|
+
/** `VaultMarket.liq_snaps` entry. */
|
|
755
|
+
liqSnapEntryId: (snapsTableId: string, tick: number, tickId: number) => string;
|
|
756
|
+
/** `VaultMarket.tick_bitmap` word. */
|
|
757
|
+
bitmapWordId: (bitmapTableId: string, word: number) => string;
|
|
758
|
+
/**
|
|
759
|
+
* Proposed on-chain position index (docs/onchain-position-index.md): dynamic field
|
|
760
|
+
* `PositionIndexKey()` on the VaultMarket. Returns null-safe ids; absent until shipped.
|
|
761
|
+
*/
|
|
762
|
+
positionIndexKeyType: string;
|
|
763
|
+
positionIndexId: (vaultMarketId: string) => string;
|
|
764
|
+
/** Entry `n` (1-based ordinal) of the index's `caps: Table<u64, ID>`. */
|
|
765
|
+
positionIndexEntryId: (capsTableId: string, n: number | bigint) => string;
|
|
766
|
+
/** v2 `Oracle`: derived from the OracleRegistry, key `OracleKey(nonce: u16)`; nonces 1..total_oracles. */
|
|
767
|
+
oracleId: (nonce: number) => string;
|
|
768
|
+
fTokenType: (coinType: string) => string;
|
|
769
|
+
positionCapType: string;
|
|
770
|
+
};
|
|
771
|
+
type FluidDerive = ReturnType<typeof createDerive>;
|
|
772
|
+
//#endregion
|
|
773
|
+
//#region src/context.d.ts
|
|
774
|
+
/**
|
|
775
|
+
* Where time-dependent maths gets "now" from.
|
|
776
|
+
* - "chain" (default): the on-chain Clock, read alongside the state (one extra object in the read).
|
|
777
|
+
* - "local": this machine's wall clock. Only for offline/back-testing use; elapsed time and the
|
|
778
|
+
* rewards windows then depend on the server's clock.
|
|
779
|
+
* - a function: fixed or custom clock (unix seconds), e.g. a checkpoint timestamp.
|
|
780
|
+
*/
|
|
781
|
+
type ClockSource = "chain" | "local" | (() => bigint | Promise<bigint>);
|
|
782
|
+
/**
|
|
783
|
+
* How far the SDK may go beyond pure object state when it has to ENUMERATE something.
|
|
784
|
+
*
|
|
785
|
+
* - "state" (default): only reads of objects by derived id (`getObjects`) and Move view
|
|
786
|
+
* simulation. No list/scan queries of any kind. Anything that cannot be resolved this way
|
|
787
|
+
* throws `NeedsDiscoveryError` naming the on-chain change that would make it pure.
|
|
788
|
+
* - "fullnode": also the fullnode's own secondary indexes (`listDynamicFields`,
|
|
789
|
+
* `listOwnedObjects`). Same endpoint(s) as state reads, so failover covers them, but the
|
|
790
|
+
* node must run with indexing enabled.
|
|
791
|
+
* - "indexer": also the external GraphQL indexer (event scans). Last resort.
|
|
792
|
+
*/
|
|
793
|
+
type DiscoveryLevel = "state" | "fullnode" | "indexer";
|
|
794
|
+
declare class NeedsDiscoveryError extends Error {
|
|
795
|
+
readonly what: string;
|
|
796
|
+
readonly needed: DiscoveryLevel;
|
|
797
|
+
readonly onchainFix: string;
|
|
798
|
+
constructor(what: string, needed: DiscoveryLevel, onchainFix: string);
|
|
799
|
+
}
|
|
800
|
+
/** Shared state every module reads through. */
|
|
801
|
+
type ReadContext = {
|
|
802
|
+
client: ClientWithCoreApi;
|
|
803
|
+
config: FluidReadConfig;
|
|
804
|
+
derive: FluidDerive;
|
|
805
|
+
/** Clock for time-dependent maths (unix seconds). Defaults to the on-chain Clock. */
|
|
806
|
+
now: () => Promise<bigint>;
|
|
807
|
+
discovery: DiscoveryLevel;
|
|
808
|
+
allows: (level: DiscoveryLevel) => boolean;
|
|
809
|
+
/** `config.mathVariant ?? "audited"`. */
|
|
810
|
+
math: MathVariant;
|
|
811
|
+
/** Coin metadata (immutable), fetched once per coin type and cached for the client's lifetime. */
|
|
812
|
+
coinMetadata: (coinType: string) => Promise<CoinMeta | null>;
|
|
813
|
+
};
|
|
814
|
+
type CoinMeta = {
|
|
815
|
+
name: string;
|
|
816
|
+
symbol: string;
|
|
817
|
+
decimals: number;
|
|
818
|
+
};
|
|
819
|
+
//#endregion
|
|
820
|
+
//#region src/transport.d.ts
|
|
821
|
+
type FailoverOptions = {
|
|
822
|
+
network: string;
|
|
823
|
+
/** Per-call timeout before moving to the next endpoint. Default 15000 ms. */
|
|
824
|
+
timeoutMs?: number;
|
|
825
|
+
/** Full passes over the endpoint list before giving up. Default 3. */
|
|
826
|
+
rounds?: number;
|
|
827
|
+
/** Wait before the second pass; doubles every pass. Default 250 ms. */
|
|
828
|
+
backoffMs?: number;
|
|
829
|
+
/** Cap on the wait between passes. Default 4000 ms. */
|
|
830
|
+
maxBackoffMs?: number;
|
|
831
|
+
};
|
|
832
|
+
/** Wait before pass `pass` (1-based, pass >= 2): exponential, capped, +/-25% jitter. */
|
|
833
|
+
declare function backoffDelay(pass: number, base: number, cap: number): number;
|
|
834
|
+
declare class AllEndpointsFailedError extends Error {
|
|
835
|
+
readonly method: string;
|
|
836
|
+
readonly errors: {
|
|
837
|
+
endpoint: string;
|
|
838
|
+
error: unknown;
|
|
839
|
+
}[];
|
|
840
|
+
constructor(method: string, errors: {
|
|
841
|
+
endpoint: string;
|
|
842
|
+
error: unknown;
|
|
843
|
+
}[]);
|
|
844
|
+
}
|
|
845
|
+
declare function clientForEndpoint(endpoint: string, network: string): ClientWithCoreApi;
|
|
846
|
+
/**
|
|
847
|
+
* One `ClientWithCoreApi` over many endpoints. Accepts endpoint strings or ready clients
|
|
848
|
+
* (label = index). Synchronous core members (e.g. `resolveTransactionPlugin`) come from the
|
|
849
|
+
* currently preferred endpoint.
|
|
850
|
+
*/
|
|
851
|
+
declare function createFailoverClient(endpoints: readonly (string | ClientWithCoreApi)[], opts: FailoverOptions): ClientWithCoreApi & {
|
|
852
|
+
endpoints: string[];
|
|
853
|
+
preferred: () => string;
|
|
854
|
+
};
|
|
855
|
+
declare namespace bcs_d_exports {
|
|
856
|
+
export { Branch, BranchStatus, CapRecord, Field, Holder, LendingRegistry, LendingState, LiquidityRegistry, MoveTick, OracleObject, OracleRegistry, OracleSource$1 as OracleSource, OracleSourceType, PauseFlags, Position, PositionIndex$1 as PositionIndex, PositionIndexEntry, PositionIndexField, PriceQuote, PythPriceInfoObject, RateDataV1Params, RateDataV2Params, RateMagnifier, RewardsSchedule$1 as RewardsSchedule, RiskConfig, Table, TickIdLiquidation, TickIdLiquidationKey, TokenReserve, TypeName, UnitKey, UserBorrowConfig, UserBorrowPosition, UserSupplyConfig, UserSupplyPosition, VaultMarket, VaultRegistry, VaultTick, bcsId, bcsU16, bcsU256, bcsU64 };
|
|
857
|
+
}
|
|
858
|
+
declare const TypeName: _mysten_bcs0.BcsStruct<{
|
|
859
|
+
name: BcsType<string, string, "string">;
|
|
860
|
+
}, string>;
|
|
861
|
+
declare const MoveTick: _mysten_bcs0.BcsStruct<{
|
|
862
|
+
mag: BcsType<number, number, "u32">;
|
|
863
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
864
|
+
}, string>;
|
|
865
|
+
declare const Table: _mysten_bcs0.BcsStruct<{
|
|
866
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
867
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
868
|
+
}, string>;
|
|
869
|
+
declare const PauseFlags: _mysten_bcs0.BcsStruct<{
|
|
870
|
+
supply: BcsType<boolean, boolean, "bool">;
|
|
871
|
+
borrow: BcsType<boolean, boolean, "bool">;
|
|
872
|
+
payback: BcsType<boolean, boolean, "bool">;
|
|
873
|
+
withdraw: BcsType<boolean, boolean, "bool">;
|
|
874
|
+
}, string>;
|
|
875
|
+
declare const Holder: _mysten_bcs0.BcsEnum<{
|
|
876
|
+
Object: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
877
|
+
Type: _mysten_bcs0.BcsStruct<{
|
|
878
|
+
name: BcsType<string, string, "string">;
|
|
879
|
+
}, string>;
|
|
880
|
+
}, "Holder">;
|
|
881
|
+
declare const LiquidityRegistry: _mysten_bcs0.BcsStruct<{
|
|
882
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
883
|
+
version: BcsType<string, string | number | bigint, "u64">;
|
|
884
|
+
pause: _mysten_bcs0.BcsStruct<{
|
|
885
|
+
supply: BcsType<boolean, boolean, "bool">;
|
|
886
|
+
borrow: BcsType<boolean, boolean, "bool">;
|
|
887
|
+
payback: BcsType<boolean, boolean, "bool">;
|
|
888
|
+
withdraw: BcsType<boolean, boolean, "bool">;
|
|
889
|
+
}, string>;
|
|
890
|
+
revenue_collector: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
891
|
+
active_caps: _mysten_bcs0.BcsStruct<{
|
|
892
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
893
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
894
|
+
}, string>;
|
|
895
|
+
}, string>;
|
|
896
|
+
declare const TokenReserve: _mysten_bcs0.BcsStruct<{
|
|
897
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
898
|
+
pause: _mysten_bcs0.BcsStruct<{
|
|
899
|
+
supply: BcsType<boolean, boolean, "bool">;
|
|
900
|
+
borrow: BcsType<boolean, boolean, "bool">;
|
|
901
|
+
payback: BcsType<boolean, boolean, "bool">;
|
|
902
|
+
withdraw: BcsType<boolean, boolean, "bool">;
|
|
903
|
+
}, string>;
|
|
904
|
+
vault: BcsType<string, string | number | bigint, "u64">;
|
|
905
|
+
borrow_rate: BcsType<string, string | number | bigint, "u64">;
|
|
906
|
+
fee: BcsType<string, string | number | bigint, "u64">;
|
|
907
|
+
last_utilization: BcsType<string, string | number | bigint, "u64">;
|
|
908
|
+
last_update_timestamp: BcsType<string, string | number | bigint, "u64">;
|
|
909
|
+
supply_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
910
|
+
borrow_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
911
|
+
max_utilization: BcsType<string, string | number | bigint, "u64">;
|
|
912
|
+
total_supply_with_interest: BcsType<string, string | number | bigint, "u64">;
|
|
913
|
+
total_supply_interest_free: BcsType<string, string | number | bigint, "u64">;
|
|
914
|
+
total_borrow_with_interest: BcsType<string, string | number | bigint, "u64">;
|
|
915
|
+
total_borrow_interest_free: BcsType<string, string | number | bigint, "u64">;
|
|
916
|
+
rate_data_version: BcsType<number, number, "u8">;
|
|
917
|
+
supply_positions: _mysten_bcs0.BcsStruct<{
|
|
918
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
919
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
920
|
+
}, string>;
|
|
921
|
+
borrow_positions: _mysten_bcs0.BcsStruct<{
|
|
922
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
923
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
924
|
+
}, string>;
|
|
925
|
+
}, string>;
|
|
926
|
+
declare const UserSupplyConfig: _mysten_bcs0.BcsStruct<{
|
|
927
|
+
mode: BcsType<number, number, "u8">;
|
|
928
|
+
expand_percent: BcsType<string, string | number | bigint, "u64">;
|
|
929
|
+
expand_duration: BcsType<string, string | number | bigint, "u64">;
|
|
930
|
+
base_withdrawal_limit: BcsType<string, string | number | bigint, "u64">;
|
|
931
|
+
}, string>;
|
|
932
|
+
declare const UserBorrowConfig: _mysten_bcs0.BcsStruct<{
|
|
933
|
+
mode: BcsType<number, number, "u8">;
|
|
934
|
+
expand_percent: BcsType<string, string | number | bigint, "u64">;
|
|
935
|
+
expand_duration: BcsType<string, string | number | bigint, "u64">;
|
|
936
|
+
base_debt_ceiling: BcsType<string, string | number | bigint, "u64">;
|
|
937
|
+
max_debt_ceiling: BcsType<string, string | number | bigint, "u64">;
|
|
938
|
+
}, string>;
|
|
939
|
+
declare const UserSupplyPosition: _mysten_bcs0.BcsStruct<{
|
|
940
|
+
config: BcsType<{
|
|
941
|
+
mode: number;
|
|
942
|
+
expand_percent: string;
|
|
943
|
+
expand_duration: string;
|
|
944
|
+
base_withdrawal_limit: string;
|
|
945
|
+
} | null, {
|
|
946
|
+
mode: number;
|
|
947
|
+
expand_percent: string | number | bigint;
|
|
948
|
+
expand_duration: string | number | bigint;
|
|
949
|
+
base_withdrawal_limit: string | number | bigint;
|
|
950
|
+
} | null | undefined, `Option<${string}>`>;
|
|
951
|
+
paused_supply: BcsType<boolean, boolean, "bool">;
|
|
952
|
+
paused_withdraw: BcsType<boolean, boolean, "bool">;
|
|
953
|
+
amount: BcsType<string, string | number | bigint, "u64">;
|
|
954
|
+
withdrawal_limit: BcsType<string, string | number | bigint, "u64">;
|
|
955
|
+
last_update: BcsType<string, string | number | bigint, "u64">;
|
|
956
|
+
decay_amount: BcsType<string, string | number | bigint, "u64">;
|
|
957
|
+
decay_duration: BcsType<string, string | number | bigint, "u64">;
|
|
958
|
+
}, string>;
|
|
959
|
+
declare const UserBorrowPosition: _mysten_bcs0.BcsStruct<{
|
|
960
|
+
config: BcsType<{
|
|
961
|
+
mode: number;
|
|
962
|
+
expand_percent: string;
|
|
963
|
+
expand_duration: string;
|
|
964
|
+
base_debt_ceiling: string;
|
|
965
|
+
max_debt_ceiling: string;
|
|
966
|
+
} | null, {
|
|
967
|
+
mode: number;
|
|
968
|
+
expand_percent: string | number | bigint;
|
|
969
|
+
expand_duration: string | number | bigint;
|
|
970
|
+
base_debt_ceiling: string | number | bigint;
|
|
971
|
+
max_debt_ceiling: string | number | bigint;
|
|
972
|
+
} | null | undefined, `Option<${string}>`>;
|
|
973
|
+
paused_borrow: BcsType<boolean, boolean, "bool">;
|
|
974
|
+
paused_payback: BcsType<boolean, boolean, "bool">;
|
|
975
|
+
amount: BcsType<string, string | number | bigint, "u64">;
|
|
976
|
+
debt_ceiling: BcsType<string, string | number | bigint, "u64">;
|
|
977
|
+
last_update: BcsType<string, string | number | bigint, "u64">;
|
|
978
|
+
}, string>;
|
|
979
|
+
declare const RateDataV1Params: _mysten_bcs0.BcsStruct<{
|
|
980
|
+
kink: BcsType<string, string | number | bigint, "u64">;
|
|
981
|
+
rate_at_utilization_zero: BcsType<string, string | number | bigint, "u64">;
|
|
982
|
+
rate_at_utilization_kink: BcsType<string, string | number | bigint, "u64">;
|
|
983
|
+
rate_at_utilization_max: BcsType<string, string | number | bigint, "u64">;
|
|
984
|
+
}, string>;
|
|
985
|
+
declare const RateDataV2Params: _mysten_bcs0.BcsStruct<{
|
|
986
|
+
kink1: BcsType<string, string | number | bigint, "u64">;
|
|
987
|
+
kink2: BcsType<string, string | number | bigint, "u64">;
|
|
988
|
+
rate_at_utilization_zero: BcsType<string, string | number | bigint, "u64">;
|
|
989
|
+
rate_at_utilization_kink1: BcsType<string, string | number | bigint, "u64">;
|
|
990
|
+
rate_at_utilization_kink2: BcsType<string, string | number | bigint, "u64">;
|
|
991
|
+
rate_at_utilization_max: BcsType<string, string | number | bigint, "u64">;
|
|
992
|
+
}, string>;
|
|
993
|
+
declare const CapRecord: _mysten_bcs0.BcsStruct<{
|
|
994
|
+
token: _mysten_bcs0.BcsStruct<{
|
|
995
|
+
name: BcsType<string, string, "string">;
|
|
996
|
+
}, string>;
|
|
997
|
+
holder: _mysten_bcs0.BcsEnum<{
|
|
998
|
+
Object: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
999
|
+
Type: _mysten_bcs0.BcsStruct<{
|
|
1000
|
+
name: BcsType<string, string, "string">;
|
|
1001
|
+
}, string>;
|
|
1002
|
+
}, "Holder">;
|
|
1003
|
+
}, string>;
|
|
1004
|
+
declare const LendingState: _mysten_bcs0.BcsStruct<{
|
|
1005
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1006
|
+
supply: BcsType<string, string | number | bigint, "u64">;
|
|
1007
|
+
reserve_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1008
|
+
rewards_writer: BcsType<string | null, string | Uint8Array<ArrayBufferLike> | null | undefined, "Option<bytes[32]>">;
|
|
1009
|
+
token_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1010
|
+
liquidity_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1011
|
+
last_update_s: BcsType<string, string | number | bigint, "u64">;
|
|
1012
|
+
}, string>;
|
|
1013
|
+
declare const RewardsSchedule$1: _mysten_bcs0.BcsStruct<{
|
|
1014
|
+
start_tvl: BcsType<string, string | number | bigint, "u64">;
|
|
1015
|
+
start_s: BcsType<string, string | number | bigint, "u64">;
|
|
1016
|
+
end_s: BcsType<string, string | number | bigint, "u64">;
|
|
1017
|
+
yearly_reward: BcsType<string, string | number | bigint, "u64">;
|
|
1018
|
+
next_start_s: BcsType<string, string | number | bigint, "u64">;
|
|
1019
|
+
next_end_s: BcsType<string, string | number | bigint, "u64">;
|
|
1020
|
+
next_yearly_reward: BcsType<string, string | number | bigint, "u64">;
|
|
1021
|
+
}, string>;
|
|
1022
|
+
declare const LendingRegistry: _mysten_bcs0.BcsStruct<{
|
|
1023
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1024
|
+
version: BcsType<string, string | number | bigint, "u64">;
|
|
1025
|
+
}, string>;
|
|
1026
|
+
declare const RiskConfig: _mysten_bcs0.BcsStruct<{
|
|
1027
|
+
collateral_factor: BcsType<number, number, "u16">;
|
|
1028
|
+
liquidation_threshold: BcsType<number, number, "u16">;
|
|
1029
|
+
liquidation_max_limit: BcsType<number, number, "u16">;
|
|
1030
|
+
withdraw_gap: BcsType<number, number, "u16">;
|
|
1031
|
+
liquidation_penalty: BcsType<number, number, "u16">;
|
|
1032
|
+
borrow_fee: BcsType<number, number, "u8">;
|
|
1033
|
+
}, string>;
|
|
1034
|
+
declare const RateMagnifier: _mysten_bcs0.BcsStruct<{
|
|
1035
|
+
magnitude: BcsType<number, number, "u16">;
|
|
1036
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1037
|
+
}, string>;
|
|
1038
|
+
declare const VaultMarket: _mysten_bcs0.BcsStruct<{
|
|
1039
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1040
|
+
vault_id: BcsType<string, string | number | bigint, "u64">;
|
|
1041
|
+
risk: _mysten_bcs0.BcsStruct<{
|
|
1042
|
+
collateral_factor: BcsType<number, number, "u16">;
|
|
1043
|
+
liquidation_threshold: BcsType<number, number, "u16">;
|
|
1044
|
+
liquidation_max_limit: BcsType<number, number, "u16">;
|
|
1045
|
+
withdraw_gap: BcsType<number, number, "u16">;
|
|
1046
|
+
liquidation_penalty: BcsType<number, number, "u16">;
|
|
1047
|
+
borrow_fee: BcsType<number, number, "u8">;
|
|
1048
|
+
}, string>;
|
|
1049
|
+
supply_rate_magnifier: _mysten_bcs0.BcsStruct<{
|
|
1050
|
+
magnitude: BcsType<number, number, "u16">;
|
|
1051
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1052
|
+
}, string>;
|
|
1053
|
+
borrow_rate_magnifier: _mysten_bcs0.BcsStruct<{
|
|
1054
|
+
magnitude: BcsType<number, number, "u16">;
|
|
1055
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1056
|
+
}, string>;
|
|
1057
|
+
vault_type: BcsType<number, number, "u8">;
|
|
1058
|
+
oracle: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1059
|
+
liquidity_program: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1060
|
+
col_decimals: BcsType<number, number, "u8">;
|
|
1061
|
+
debt_decimals: BcsType<number, number, "u8">;
|
|
1062
|
+
branch_liquidated: BcsType<boolean, boolean, "bool">;
|
|
1063
|
+
topmost_tick: _mysten_bcs0.BcsStruct<{
|
|
1064
|
+
mag: BcsType<number, number, "u32">;
|
|
1065
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
1066
|
+
}, string>;
|
|
1067
|
+
current_branch_id: BcsType<string, string | number | bigint, "u64">;
|
|
1068
|
+
total_branch_id: BcsType<string, string | number | bigint, "u64">;
|
|
1069
|
+
total_supply: BcsType<string, string | number | bigint, "u64">;
|
|
1070
|
+
total_borrow: BcsType<string, string | number | bigint, "u64">;
|
|
1071
|
+
absorbed_debt_amount: BcsType<string, string | number | bigint, "u128">;
|
|
1072
|
+
absorbed_col_amount: BcsType<string, string | number | bigint, "u128">;
|
|
1073
|
+
absorbed_dust_debt: BcsType<string, string | number | bigint, "u64">;
|
|
1074
|
+
liquidity_supply_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1075
|
+
liquidity_borrow_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1076
|
+
vault_supply_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1077
|
+
vault_borrow_exchange_price: BcsType<string, string | number | bigint, "u64">;
|
|
1078
|
+
last_update_timestamp: BcsType<string, string | number | bigint, "u64">;
|
|
1079
|
+
ticks: _mysten_bcs0.BcsStruct<{
|
|
1080
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1081
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1082
|
+
}, string>;
|
|
1083
|
+
branches: _mysten_bcs0.BcsStruct<{
|
|
1084
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1085
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1086
|
+
}, string>;
|
|
1087
|
+
liq_snaps: _mysten_bcs0.BcsStruct<{
|
|
1088
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1089
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1090
|
+
}, string>;
|
|
1091
|
+
tick_bitmap: _mysten_bcs0.BcsStruct<{
|
|
1092
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1093
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1094
|
+
}, string>;
|
|
1095
|
+
}, string>;
|
|
1096
|
+
declare const VaultTick: _mysten_bcs0.BcsStruct<{
|
|
1097
|
+
is_liquidated: BcsType<boolean, boolean, "bool">;
|
|
1098
|
+
total_ids: BcsType<number, number, "u32">;
|
|
1099
|
+
raw_debt: BcsType<string, string | number | bigint, "u64">;
|
|
1100
|
+
is_fully_liquidated: BcsType<boolean, boolean, "bool">;
|
|
1101
|
+
liquidation_branch_id: BcsType<string, string | number | bigint, "u64">;
|
|
1102
|
+
debt_factor: BcsType<string, string | number | bigint, "u64">;
|
|
1103
|
+
}, string>;
|
|
1104
|
+
declare const TickIdLiquidation: _mysten_bcs0.BcsStruct<{
|
|
1105
|
+
is_fully_liquidated: BcsType<boolean, boolean, "bool">;
|
|
1106
|
+
liquidation_branch_id: BcsType<string, string | number | bigint, "u64">;
|
|
1107
|
+
debt_factor: BcsType<string, string | number | bigint, "u64">;
|
|
1108
|
+
}, string>;
|
|
1109
|
+
declare const TickIdLiquidationKey: _mysten_bcs0.BcsStruct<{
|
|
1110
|
+
tick: _mysten_bcs0.BcsStruct<{
|
|
1111
|
+
mag: BcsType<number, number, "u32">;
|
|
1112
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
1113
|
+
}, string>;
|
|
1114
|
+
tick_map: BcsType<number, number, "u32">;
|
|
1115
|
+
}, string>;
|
|
1116
|
+
declare const BranchStatus: _mysten_bcs0.BcsEnum<{
|
|
1117
|
+
NotLiquidated: null;
|
|
1118
|
+
Liquidated: null;
|
|
1119
|
+
Merged: null;
|
|
1120
|
+
Closed: null;
|
|
1121
|
+
}, "BranchStatus">;
|
|
1122
|
+
declare const Branch: _mysten_bcs0.BcsStruct<{
|
|
1123
|
+
status: _mysten_bcs0.BcsEnum<{
|
|
1124
|
+
NotLiquidated: null;
|
|
1125
|
+
Liquidated: null;
|
|
1126
|
+
Merged: null;
|
|
1127
|
+
Closed: null;
|
|
1128
|
+
}, "BranchStatus">;
|
|
1129
|
+
minima_tick: _mysten_bcs0.BcsStruct<{
|
|
1130
|
+
mag: BcsType<number, number, "u32">;
|
|
1131
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
1132
|
+
}, string>;
|
|
1133
|
+
minima_tick_partials: BcsType<number, number, "u32">;
|
|
1134
|
+
debt_liquidity: BcsType<string, string | number | bigint, "u64">;
|
|
1135
|
+
debt_factor: BcsType<string, string | number | bigint, "u64">;
|
|
1136
|
+
connected_branch_id: BcsType<string, string | number | bigint, "u64">;
|
|
1137
|
+
connected_minima_tick: _mysten_bcs0.BcsStruct<{
|
|
1138
|
+
mag: BcsType<number, number, "u32">;
|
|
1139
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
1140
|
+
}, string>;
|
|
1141
|
+
}, string>;
|
|
1142
|
+
declare const Position: _mysten_bcs0.BcsStruct<{
|
|
1143
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1144
|
+
vault_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1145
|
+
position_mint: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1146
|
+
is_supply_only_position: BcsType<boolean, boolean, "bool">;
|
|
1147
|
+
tick: _mysten_bcs0.BcsStruct<{
|
|
1148
|
+
mag: BcsType<number, number, "u32">;
|
|
1149
|
+
neg: BcsType<boolean, boolean, "bool">;
|
|
1150
|
+
}, string>;
|
|
1151
|
+
tick_id: BcsType<number, number, "u32">;
|
|
1152
|
+
supply_amount: BcsType<string, string | number | bigint, "u64">;
|
|
1153
|
+
dust_debt_amount: BcsType<string, string | number | bigint, "u64">;
|
|
1154
|
+
}, string>;
|
|
1155
|
+
declare const VaultRegistry: _mysten_bcs0.BcsStruct<{
|
|
1156
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1157
|
+
next_vault_id: BcsType<string, string | number | bigint, "u64">;
|
|
1158
|
+
version: BcsType<string, string | number | bigint, "u64">;
|
|
1159
|
+
}, string>;
|
|
1160
|
+
declare const OracleRegistry: _mysten_bcs0.BcsStruct<{
|
|
1161
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1162
|
+
version: BcsType<string, string | number | bigint, "u64">;
|
|
1163
|
+
total_oracles: BcsType<string, string | number | bigint, "u64">;
|
|
1164
|
+
}, string>;
|
|
1165
|
+
declare const OracleSourceType: _mysten_bcs0.BcsEnum<{
|
|
1166
|
+
Redstone: _mysten_bcs0.BcsStruct<{
|
|
1167
|
+
adapter_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1168
|
+
}, string>;
|
|
1169
|
+
Pyth: null;
|
|
1170
|
+
}, "SourceType">;
|
|
1171
|
+
declare const OracleSource$1: _mysten_bcs0.BcsStruct<{
|
|
1172
|
+
feed_id: BcsType<number[], Iterable<number> & {
|
|
1173
|
+
length: number;
|
|
1174
|
+
}, string>;
|
|
1175
|
+
invert: BcsType<boolean, boolean, "bool">;
|
|
1176
|
+
source_type: _mysten_bcs0.BcsEnum<{
|
|
1177
|
+
Redstone: _mysten_bcs0.BcsStruct<{
|
|
1178
|
+
adapter_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1179
|
+
}, string>;
|
|
1180
|
+
Pyth: null;
|
|
1181
|
+
}, "SourceType">;
|
|
1182
|
+
}, string>;
|
|
1183
|
+
/** `fluid_oracle::oracle::Oracle` derived from the registry by nonce. */
|
|
1184
|
+
declare const OracleObject: _mysten_bcs0.BcsStruct<{
|
|
1185
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1186
|
+
nonce: BcsType<number, number, "u16">;
|
|
1187
|
+
main: _mysten_bcs0.BcsStruct<{
|
|
1188
|
+
feed_id: BcsType<number[], Iterable<number> & {
|
|
1189
|
+
length: number;
|
|
1190
|
+
}, string>;
|
|
1191
|
+
invert: BcsType<boolean, boolean, "bool">;
|
|
1192
|
+
source_type: _mysten_bcs0.BcsEnum<{
|
|
1193
|
+
Redstone: _mysten_bcs0.BcsStruct<{
|
|
1194
|
+
adapter_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1195
|
+
}, string>;
|
|
1196
|
+
Pyth: null;
|
|
1197
|
+
}, "SourceType">;
|
|
1198
|
+
}, string>;
|
|
1199
|
+
guard: BcsType<{
|
|
1200
|
+
feed_id: number[];
|
|
1201
|
+
invert: boolean;
|
|
1202
|
+
source_type: _mysten_bcs0.EnumOutputShapeWithKeys<{
|
|
1203
|
+
Redstone: {
|
|
1204
|
+
adapter_id: string;
|
|
1205
|
+
};
|
|
1206
|
+
Pyth: true;
|
|
1207
|
+
}, "Redstone" | "Pyth">;
|
|
1208
|
+
} | null, {
|
|
1209
|
+
feed_id: Iterable<number> & {
|
|
1210
|
+
length: number;
|
|
1211
|
+
};
|
|
1212
|
+
invert: boolean;
|
|
1213
|
+
source_type: _mysten_bcs0.EnumInputShape<{
|
|
1214
|
+
Redstone: {
|
|
1215
|
+
adapter_id: string | Uint8Array<ArrayBufferLike>;
|
|
1216
|
+
};
|
|
1217
|
+
Pyth: boolean | object | null;
|
|
1218
|
+
}>;
|
|
1219
|
+
} | null | undefined, `Option<${string}>`>;
|
|
1220
|
+
}, string>;
|
|
1221
|
+
/** `view::PriceQuote`: each rate is optional (operate-only / liquidate-only quotes). */
|
|
1222
|
+
declare const PriceQuote: _mysten_bcs0.BcsStruct<{
|
|
1223
|
+
oracle_id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1224
|
+
rate_liquidate: BcsType<string | null, string | number | bigint | null | undefined, "Option<u128>">;
|
|
1225
|
+
rate_operate: BcsType<string | null, string | number | bigint | null | undefined, "Option<u128>">;
|
|
1226
|
+
}, string>;
|
|
1227
|
+
/** `pyth::price_info::PriceInfoObject`. */
|
|
1228
|
+
declare const PythPriceInfoObject: _mysten_bcs0.BcsStruct<{
|
|
1229
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1230
|
+
price_info: _mysten_bcs0.BcsStruct<{
|
|
1231
|
+
attestation_time: BcsType<string, string | number | bigint, "u64">;
|
|
1232
|
+
arrival_time: BcsType<string, string | number | bigint, "u64">;
|
|
1233
|
+
price_feed: _mysten_bcs0.BcsStruct<{
|
|
1234
|
+
price_identifier: _mysten_bcs0.BcsStruct<{
|
|
1235
|
+
bytes: BcsType<number[], Iterable<number> & {
|
|
1236
|
+
length: number;
|
|
1237
|
+
}, string>;
|
|
1238
|
+
}, string>;
|
|
1239
|
+
price: _mysten_bcs0.BcsStruct<{
|
|
1240
|
+
price: _mysten_bcs0.BcsStruct<{
|
|
1241
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1242
|
+
magnitude: BcsType<string, string | number | bigint, "u64">;
|
|
1243
|
+
}, string>;
|
|
1244
|
+
conf: BcsType<string, string | number | bigint, "u64">;
|
|
1245
|
+
expo: _mysten_bcs0.BcsStruct<{
|
|
1246
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1247
|
+
magnitude: BcsType<string, string | number | bigint, "u64">;
|
|
1248
|
+
}, string>;
|
|
1249
|
+
timestamp: BcsType<string, string | number | bigint, "u64">;
|
|
1250
|
+
}, string>;
|
|
1251
|
+
ema_price: _mysten_bcs0.BcsStruct<{
|
|
1252
|
+
price: _mysten_bcs0.BcsStruct<{
|
|
1253
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1254
|
+
magnitude: BcsType<string, string | number | bigint, "u64">;
|
|
1255
|
+
}, string>;
|
|
1256
|
+
conf: BcsType<string, string | number | bigint, "u64">;
|
|
1257
|
+
expo: _mysten_bcs0.BcsStruct<{
|
|
1258
|
+
negative: BcsType<boolean, boolean, "bool">;
|
|
1259
|
+
magnitude: BcsType<string, string | number | bigint, "u64">;
|
|
1260
|
+
}, string>;
|
|
1261
|
+
timestamp: BcsType<string, string | number | bigint, "u64">;
|
|
1262
|
+
}, string>;
|
|
1263
|
+
}, string>;
|
|
1264
|
+
}, string>;
|
|
1265
|
+
}, string>;
|
|
1266
|
+
/** `0x2::dynamic_field::Field<K, V>` wrapper. */
|
|
1267
|
+
declare function Field<K, KI, V, VI>(name: BcsType<K, KI>, value: BcsType<V, VI>): _mysten_bcs0.BcsStruct<{
|
|
1268
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1269
|
+
name: BcsType<K, KI, string>;
|
|
1270
|
+
value: BcsType<V, VI, string>;
|
|
1271
|
+
}, string>;
|
|
1272
|
+
declare const bcsU64: BcsType<string, string | number | bigint, "u64">;
|
|
1273
|
+
declare const bcsU16: BcsType<number, number, "u16">;
|
|
1274
|
+
declare const bcsU256: BcsType<string, string | number | bigint, "u256">;
|
|
1275
|
+
declare const bcsId: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1276
|
+
/** Unit key struct (`RateDataKey`, `RewardsKey`, ...): BCS `dummy_field: bool`. */
|
|
1277
|
+
declare const UnitKey: BcsType<boolean, boolean, "bool">;
|
|
1278
|
+
/** Proposed `fluid_vaults::position_index::PositionIndex` (docs/onchain-position-index.md). */
|
|
1279
|
+
declare const PositionIndex$1: _mysten_bcs0.BcsStruct<{
|
|
1280
|
+
next_position_id: BcsType<string, string | number | bigint, "u64">;
|
|
1281
|
+
caps: _mysten_bcs0.BcsStruct<{
|
|
1282
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1283
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1284
|
+
}, string>;
|
|
1285
|
+
ordinals: _mysten_bcs0.BcsStruct<{
|
|
1286
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1287
|
+
size: BcsType<string, string | number | bigint, "u64">;
|
|
1288
|
+
}, string>;
|
|
1289
|
+
}, string>;
|
|
1290
|
+
declare const PositionIndexField: _mysten_bcs0.BcsStruct<{
|
|
1291
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1292
|
+
name: BcsType<boolean, boolean, string>;
|
|
1293
|
+
value: BcsType<{
|
|
1294
|
+
next_position_id: string;
|
|
1295
|
+
caps: {
|
|
1296
|
+
id: string;
|
|
1297
|
+
size: string;
|
|
1298
|
+
};
|
|
1299
|
+
ordinals: {
|
|
1300
|
+
id: string;
|
|
1301
|
+
size: string;
|
|
1302
|
+
};
|
|
1303
|
+
}, {
|
|
1304
|
+
next_position_id: string | number | bigint;
|
|
1305
|
+
caps: {
|
|
1306
|
+
id: string | Uint8Array<ArrayBufferLike>;
|
|
1307
|
+
size: string | number | bigint;
|
|
1308
|
+
};
|
|
1309
|
+
ordinals: {
|
|
1310
|
+
id: string | Uint8Array<ArrayBufferLike>;
|
|
1311
|
+
size: string | number | bigint;
|
|
1312
|
+
};
|
|
1313
|
+
}, string>;
|
|
1314
|
+
}, string>;
|
|
1315
|
+
/** `caps: Table<u64, ID>` entry: ordinal -> PositionOwnerCap id. */
|
|
1316
|
+
declare const PositionIndexEntry: _mysten_bcs0.BcsStruct<{
|
|
1317
|
+
id: BcsType<string, string | Uint8Array<ArrayBufferLike>, "bytes[32]">;
|
|
1318
|
+
name: BcsType<string, string | number | bigint, string>;
|
|
1319
|
+
value: BcsType<string, string | Uint8Array<ArrayBufferLike>, string>;
|
|
1320
|
+
}, string>;
|
|
1321
|
+
//#endregion
|
|
1322
|
+
//#region src/objects.d.ts
|
|
1323
|
+
type FetchedObject = {
|
|
1324
|
+
objectId: string;
|
|
1325
|
+
type: string;
|
|
1326
|
+
content: Uint8Array;
|
|
1327
|
+
owner: unknown;
|
|
1328
|
+
};
|
|
1329
|
+
declare class ObjectNotFoundError extends Error {
|
|
1330
|
+
readonly objectId: string;
|
|
1331
|
+
readonly what: string;
|
|
1332
|
+
constructor(objectId: string, what: string);
|
|
1333
|
+
}
|
|
1334
|
+
//#endregion
|
|
1335
|
+
//#region src/liquidity.d.ts
|
|
1336
|
+
type ReserveRecord = {
|
|
1337
|
+
token: string;
|
|
1338
|
+
id: string;
|
|
1339
|
+
raw: ReturnType<typeof TokenReserve.parse>;
|
|
1340
|
+
snapshot: ReserveSnapshot;
|
|
1341
|
+
rateData: RateData;
|
|
1342
|
+
};
|
|
1343
|
+
declare class Liquidity {
|
|
1344
|
+
private readonly ctx;
|
|
1345
|
+
constructor(ctx: ReadContext);
|
|
1346
|
+
/** Object ids `loadReserves` reads: every reserve, then every reserve's rate-data field. */
|
|
1347
|
+
reserveObjectIds(tokens: readonly string[]): string[];
|
|
1348
|
+
/** Parse objects fetched for `reserveObjectIds(tokens)` (same order). */
|
|
1349
|
+
reservesFromObjects(tokens: readonly string[], objs: readonly (FetchedObject | null)[]): ReserveRecord[];
|
|
1350
|
+
/** Reserves + their rate-data fields in one batched `getObjects`. */
|
|
1351
|
+
loadReserves(tokens: readonly string[]): Promise<ReserveRecord[]>;
|
|
1352
|
+
loadReserve(token: string): Promise<ReserveRecord>;
|
|
1353
|
+
/** Supply/borrow Table entries of `holders` on `reserves` (one batched round trip). */
|
|
1354
|
+
loadUserEntries(pairs: readonly {
|
|
1355
|
+
holder: string;
|
|
1356
|
+
reserve: ReserveRecord;
|
|
1357
|
+
}[]): Promise<{
|
|
1358
|
+
supply: UserSupplyPositionAccount | null;
|
|
1359
|
+
borrow: UserBorrowPositionAccount | null;
|
|
1360
|
+
}[]>;
|
|
1361
|
+
getLiquidityAccount(): Promise<LiquidityAccount>;
|
|
1362
|
+
getRevenueCollector(): Promise<string>;
|
|
1363
|
+
/**
|
|
1364
|
+
* Protocol holders discoverable from object state alone: every VaultMarket (ids 1..total from
|
|
1365
|
+
* `VaultRegistry.next_vault_id`, derived) and every LendingState of a candidate token
|
|
1366
|
+
* (derived). Pure state, no list query.
|
|
1367
|
+
*/
|
|
1368
|
+
discoverProtocolHolders(seedTokens?: readonly string[]): Promise<{
|
|
1369
|
+
vaults: {
|
|
1370
|
+
vaultId: number;
|
|
1371
|
+
id: string;
|
|
1372
|
+
collateralType: string;
|
|
1373
|
+
debtType: string;
|
|
1374
|
+
capCount: number;
|
|
1375
|
+
}[];
|
|
1376
|
+
lendings: {
|
|
1377
|
+
token: string;
|
|
1378
|
+
id: string;
|
|
1379
|
+
}[];
|
|
1380
|
+
}>;
|
|
1381
|
+
/**
|
|
1382
|
+
* Token discovery from object state alone (default, no indexer, no list query):
|
|
1383
|
+
* seed tokens (`config.tokens`) ∪ collateral/debt types of every VaultMarket, kept if their
|
|
1384
|
+
* `TokenReserve` exists (derived id). Coverage check: every liquidity user cap is counted in
|
|
1385
|
+
* `Registry.active_caps.size`; caps held by known holders (2 per vault, 1 per LendingState)
|
|
1386
|
+
* are subtracted, and `untrackedCaps > 0` means some other holder exists that state alone
|
|
1387
|
+
* cannot name (a token listed only by a non-Fluid integrator, or a test holder).
|
|
1388
|
+
*/
|
|
1389
|
+
discoverTokens(): Promise<{
|
|
1390
|
+
tokens: string[];
|
|
1391
|
+
activeCaps: number;
|
|
1392
|
+
untrackedCaps: number;
|
|
1393
|
+
source: "state" | "state+fullnode-index";
|
|
1394
|
+
}>;
|
|
1395
|
+
/** Listed tokens (see `discoverTokens`; pure state by default). */
|
|
1396
|
+
listedTokens(): Promise<string[]>;
|
|
1397
|
+
getExchangePricesAndConfig(token: string): Promise<ExchangePricesAndConfig>;
|
|
1398
|
+
/** Pure: accrue a reserve snapshot to `now` (unix seconds; use `await ctx.now()` for chain time). */
|
|
1399
|
+
calculateExchangePrice(snapshot: ReserveSnapshot, now: bigint): ExchangePriceResult;
|
|
1400
|
+
getRateConfig(token: string): Promise<RateModelAccount | null>;
|
|
1401
|
+
getTotalAmounts(token: string): Promise<TotalAmounts>;
|
|
1402
|
+
getConfigs2(token: string): Promise<{
|
|
1403
|
+
maxUtilization: bigint;
|
|
1404
|
+
}>;
|
|
1405
|
+
getRevenue(token: string): Promise<bigint>;
|
|
1406
|
+
getTokenRateData(token: string): Promise<RateData>;
|
|
1407
|
+
getTokensRateData(tokens: readonly string[]): Promise<RateData[]>;
|
|
1408
|
+
overallFromRecord(r: ReserveRecord, now: bigint): OverallTokenData;
|
|
1409
|
+
getOverallTokenData(token: string): Promise<OverallTokenData>;
|
|
1410
|
+
getOverallTokensData(tokens: readonly string[]): Promise<OverallTokenData[]>;
|
|
1411
|
+
getAllOverallTokensData(): Promise<OverallTokenData[]>;
|
|
1412
|
+
/** Raw supply position of a holder, or `0n` when none exists (Solana returns BN 0). */
|
|
1413
|
+
getUserSupply(user: string, token: string): Promise<UserSupplyPositionAccount | bigint>;
|
|
1414
|
+
getUserBorrow(user: string, token: string): Promise<UserBorrowPositionAccount | bigint>;
|
|
1415
|
+
supplyDataFromRecords(reserve: ReserveRecord, acc: UserSupplyPositionAccount | null, now: bigint): {
|
|
1416
|
+
userSupplyData: UserSupplyData;
|
|
1417
|
+
overallTokenData: OverallTokenData;
|
|
1418
|
+
};
|
|
1419
|
+
borrowDataFromRecords(reserve: ReserveRecord, acc: UserBorrowPositionAccount | null, now: bigint): {
|
|
1420
|
+
userBorrowData: UserBorrowData;
|
|
1421
|
+
overallTokenData: OverallTokenData;
|
|
1422
|
+
};
|
|
1423
|
+
getUserSupplyData(user: string, token: string): Promise<{
|
|
1424
|
+
userSupplyData: UserSupplyData;
|
|
1425
|
+
overallTokenData: OverallTokenData;
|
|
1426
|
+
}>;
|
|
1427
|
+
getUserBorrowData(user: string, token: string): Promise<{
|
|
1428
|
+
userBorrowData: UserBorrowData;
|
|
1429
|
+
overallTokenData: OverallTokenData;
|
|
1430
|
+
}>;
|
|
1431
|
+
getUserMultipleSupplyData(user: string, tokens: readonly string[]): Promise<{
|
|
1432
|
+
userSuppliesData: UserSupplyData[];
|
|
1433
|
+
overallTokensData: OverallTokenData[];
|
|
1434
|
+
}>;
|
|
1435
|
+
getUserMultipleBorrowData(user: string, tokens: readonly string[]): Promise<{
|
|
1436
|
+
userBorrowingsData: UserBorrowData[];
|
|
1437
|
+
overallTokensData: OverallTokenData[];
|
|
1438
|
+
}>;
|
|
1439
|
+
getUserMultipleBorrowSupplyData(user: string, supplyTokens: readonly string[], borrowTokens: readonly string[]): Promise<{
|
|
1440
|
+
userSuppliesData: UserSupplyData[];
|
|
1441
|
+
overallSupplyTokensData: OverallTokenData[];
|
|
1442
|
+
userBorrowingsData: UserBorrowData[];
|
|
1443
|
+
overallBorrowTokensData: OverallTokenData[];
|
|
1444
|
+
}>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Every supply/borrow position on every listed reserve, grouped by holder.
|
|
1447
|
+
*
|
|
1448
|
+
* Default ("state"): holders = every VaultMarket + LendingState (derived), entries read by
|
|
1449
|
+
* derived Table-entry id. `untracked` = `Table.size` minus entries found, per reserve: rows of
|
|
1450
|
+
* holders that object state cannot name (non-Fluid integrators). With `discovery: "fullnode"`
|
|
1451
|
+
* the tables are listed and `untracked` is always empty.
|
|
1452
|
+
*/
|
|
1453
|
+
getAllUserPositionsDetailed(): Promise<{
|
|
1454
|
+
positions: {
|
|
1455
|
+
user: string;
|
|
1456
|
+
supply: Record<string, UserSupplyPositionAccount>;
|
|
1457
|
+
borrow: Record<string, UserBorrowPositionAccount>;
|
|
1458
|
+
}[];
|
|
1459
|
+
untracked: {
|
|
1460
|
+
token: string;
|
|
1461
|
+
supply: number;
|
|
1462
|
+
borrow: number;
|
|
1463
|
+
}[];
|
|
1464
|
+
source: "state" | "fullnode-index";
|
|
1465
|
+
}>;
|
|
1466
|
+
/** Positions only (see `getAllUserPositionsDetailed`). */
|
|
1467
|
+
getAllUserPositions(): Promise<{
|
|
1468
|
+
user: string;
|
|
1469
|
+
supply: Record<string, UserSupplyPositionAccount>;
|
|
1470
|
+
borrow: Record<string, UserBorrowPositionAccount>;
|
|
1471
|
+
}[]>;
|
|
1472
|
+
/** Fullnode-index tier: lists every Table entry. */
|
|
1473
|
+
private listAllUserPositions;
|
|
1474
|
+
}
|
|
1475
|
+
declare namespace lending_d_exports {
|
|
1476
|
+
export { LendingSnapshot, RewardsSchedule, accruedTokenExchangePrice, currentRewardsRate, previews, rateSegments, rewardsRateFor, rewardsTvl, toAssets, toShares };
|
|
1477
|
+
}
|
|
1478
|
+
type RewardsSchedule = {
|
|
1479
|
+
startTvl: bigint;
|
|
1480
|
+
startS: bigint;
|
|
1481
|
+
endS: bigint;
|
|
1482
|
+
yearlyReward: bigint;
|
|
1483
|
+
nextStartS: bigint;
|
|
1484
|
+
nextEndS: bigint;
|
|
1485
|
+
nextYearlyReward: bigint;
|
|
1486
|
+
};
|
|
1487
|
+
type LendingSnapshot = {
|
|
1488
|
+
totalShares: bigint;
|
|
1489
|
+
liquidityExchangePrice: bigint;
|
|
1490
|
+
tokenExchangePrice: bigint;
|
|
1491
|
+
lastUpdateS: bigint;
|
|
1492
|
+
rewards: RewardsSchedule | null;
|
|
1493
|
+
};
|
|
1494
|
+
declare const toShares: (assets: bigint, ep: bigint, roundUp: boolean) => bigint;
|
|
1495
|
+
declare const toAssets: (shares: bigint, ep: bigint, roundUp: boolean) => bigint;
|
|
1496
|
+
/** `lending_calcs::calc_rewards_rate` via `rewards::rate_for`. */
|
|
1497
|
+
declare function rewardsRateFor(yearlyReward: bigint, totalAssets: bigint, startTvl: bigint): bigint;
|
|
1498
|
+
/** `rewards::get_rate_segments`. */
|
|
1499
|
+
declare function rateSegments(s: RewardsSchedule, totalAssets: bigint, fromS: bigint, nowS: bigint): {
|
|
1500
|
+
rate: bigint;
|
|
1501
|
+
fromS: bigint;
|
|
1502
|
+
toS: bigint;
|
|
1503
|
+
}[];
|
|
1504
|
+
/**
|
|
1505
|
+
* TVL the contract prices rewards on: total shares at the STORED (pre-accrual) token exchange
|
|
1506
|
+
* price, as `accounting::accrued_token_exchange_price` does. Rounded up on "audited" packages
|
|
1507
|
+
* (742ea21+), floored on the 09-18 "pre-audit" packages.
|
|
1508
|
+
*/
|
|
1509
|
+
declare const rewardsTvl: (state: LendingSnapshot, variant?: MathVariant) => bigint;
|
|
1510
|
+
/**
|
|
1511
|
+
* Current rewards rate (raw, RETURN_PERCENT_PRECISION: 1e14 = 100%) at `now`, from the active schedule segment, priced on
|
|
1512
|
+
* the pre-accrual TVL (`rewardsTvl`) exactly as the contract prices the segment it will credit.
|
|
1513
|
+
* Windows are [start, end): the rate is live from `startS` and gone at `endS`.
|
|
1514
|
+
*/
|
|
1515
|
+
declare function currentRewardsRate(state: LendingSnapshot, now: bigint, variant?: MathVariant): bigint;
|
|
1516
|
+
/** `accounting::accrued_token_exchange_price`. */
|
|
1517
|
+
declare function accruedTokenExchangePrice(state: LendingSnapshot, newLiquidityExchangePrice: bigint, nowS: bigint, variant?: MathVariant): bigint;
|
|
1518
|
+
/** `accounting::preview_*` given the reserve's current liquidity (supply) exchange price. */
|
|
1519
|
+
declare function previews(state: LendingSnapshot, liquidityExchangePrice: bigint, nowS: bigint, assets: bigint, shares: bigint, variant?: MathVariant): {
|
|
1520
|
+
tokenExchangePrice: bigint;
|
|
1521
|
+
previewDeposit: bigint;
|
|
1522
|
+
previewMint: bigint;
|
|
1523
|
+
previewWithdraw: bigint;
|
|
1524
|
+
previewRedeem: bigint;
|
|
1525
|
+
};
|
|
1526
|
+
//#endregion
|
|
1527
|
+
//#region src/lending.d.ts
|
|
1528
|
+
type LendingRecord = {
|
|
1529
|
+
token: string;
|
|
1530
|
+
id: string;
|
|
1531
|
+
raw: ReturnType<typeof LendingState.parse>;
|
|
1532
|
+
snapshot: LendingSnapshot;
|
|
1533
|
+
};
|
|
1534
|
+
type Pool = {
|
|
1535
|
+
lending: LendingRecord;
|
|
1536
|
+
reserve: ReserveRecord;
|
|
1537
|
+
supplyEntry: UserSupplyPositionAccount | null;
|
|
1538
|
+
};
|
|
1539
|
+
declare class Lending {
|
|
1540
|
+
private readonly ctx;
|
|
1541
|
+
private readonly liquidity;
|
|
1542
|
+
constructor(ctx: ReadContext, liquidity: Liquidity);
|
|
1543
|
+
/** Object ids `loadLendings` reads: every LendingState, then every rewards field. */
|
|
1544
|
+
lendingObjectIds(tokens: readonly string[]): string[];
|
|
1545
|
+
/** LendingStates (+ rewards fields) for `tokens`; `null` where no pool exists. */
|
|
1546
|
+
loadLendings(tokens: readonly string[]): Promise<(LendingRecord | null)[]>;
|
|
1547
|
+
lendingsFromObjects(tokens: readonly string[], objs: readonly (FetchedObject | null)[]): (LendingRecord | null)[];
|
|
1548
|
+
/**
|
|
1549
|
+
* Everything a pool read needs in ONE `getObjects` batch (LendingState, rewards field,
|
|
1550
|
+
* TokenReserve, rate data per token; 50 ids per request, chunks in parallel), plus the chain
|
|
1551
|
+
* clock in parallel. With `withEntries`, a second batch reads each pool's liquidity supply entry.
|
|
1552
|
+
*/
|
|
1553
|
+
loadPools(tokens: readonly string[], withEntries?: boolean): Promise<{
|
|
1554
|
+
pools: Pool[];
|
|
1555
|
+
now: bigint;
|
|
1556
|
+
}>;
|
|
1557
|
+
private loadOne;
|
|
1558
|
+
getAllLendings(): Promise<LendingAccount[]>;
|
|
1559
|
+
/** Underlying coin types that have a lending pool. */
|
|
1560
|
+
getAllFTokens(): Promise<string[]>;
|
|
1561
|
+
/** @deprecated Solana name; use `getAllFTokens`. */
|
|
1562
|
+
getAllJlTokens: () => Promise<string[]>;
|
|
1563
|
+
/** Token exchange price accrued to now (`accounting::calculate_new_token_exchange_price`). */
|
|
1564
|
+
getExchangePrice(token: string): Promise<bigint>;
|
|
1565
|
+
getPreviews(token: string, assets: bigint, shares: bigint): Promise<PreviewData>;
|
|
1566
|
+
detailsFromRecords(lending: LendingRecord, reserve: ReserveRecord, supplyEntry: Parameters<Liquidity["supplyDataFromRecords"]>[1], meta: {
|
|
1567
|
+
name: string;
|
|
1568
|
+
symbol: string;
|
|
1569
|
+
decimals: number;
|
|
1570
|
+
}, now: bigint): FTokenDetails;
|
|
1571
|
+
/** fToken name/symbol/decimals (cached; falls back to the underlying's metadata). */
|
|
1572
|
+
fTokenMeta(token: string): Promise<CoinMeta>;
|
|
1573
|
+
getFTokenDetails(token: string): Promise<FTokenDetails>;
|
|
1574
|
+
/** Details for many fTokens: 2 batched object reads + the clock, metadata cached. */
|
|
1575
|
+
getFTokensDetails(tokens: readonly string[]): Promise<FTokenDetails[]>;
|
|
1576
|
+
private detailsWithPrices;
|
|
1577
|
+
/** @deprecated Solana name; use `getFTokenDetails`. */
|
|
1578
|
+
getJlTokenDetails: (token: string) => Promise<FTokenDetails>;
|
|
1579
|
+
getAllFTokenDetails(): Promise<FTokenDetails[]>;
|
|
1580
|
+
/** Underlying coin types that have a lending pool (pure state: one batched existence read). */
|
|
1581
|
+
listedLendingTokens(): Promise<string[]>;
|
|
1582
|
+
/** @deprecated Solana name; use `getAllFTokenDetails`. */
|
|
1583
|
+
getAllJlTokenDetails: () => Promise<FTokenDetails[]>;
|
|
1584
|
+
getFTokenInternalData(token: string): Promise<FTokenInternalData>;
|
|
1585
|
+
/** @deprecated Solana name; use `getFTokenInternalData`. */
|
|
1586
|
+
getJlTokenInternalData: (token: string) => Promise<FTokenInternalData>;
|
|
1587
|
+
/**
|
|
1588
|
+
* Generic lending state per fToken (identity, accrued + stored exchange prices, TVL, rates in
|
|
1589
|
+
* bps, rewards schedule) for `tokens` (underlying coin types), or every listed pool when
|
|
1590
|
+
* omitted. One batched `getObjects` for all pools + the on-chain Clock; metadata cached.
|
|
1591
|
+
*/
|
|
1592
|
+
getLendingStateData(tokens?: readonly string[]): Promise<LendingStateData[]>;
|
|
1593
|
+
/** Pure: `LendingStateData` from loaded records at `now`. */
|
|
1594
|
+
stateDataFrom(lending: LendingRecord, reserve: ReserveRecord, decimals: number, now: bigint): LendingStateData;
|
|
1595
|
+
/**
|
|
1596
|
+
* Wallet holders of `Coin<FToken<T>>` for `token` (underlying coin type), via the GraphQL
|
|
1597
|
+
* indexer (`config.graphqlUrl`; needs `discovery: "indexer"`). Lists every Coin<FToken<T>>
|
|
1598
|
+
* object by type and keeps the ones with an ADDRESS owner (AddressOwner or
|
|
1599
|
+
* ConsensusAddressOwner), aggregated by owner, all pages at one checkpoint (consistent cursors).
|
|
1600
|
+
*
|
|
1601
|
+
* LIMITS (documented, by design): coins owned by other objects, shared/immutable coins and
|
|
1602
|
+
* wrapped `Balance<FToken<T>>` (inside other protocols' objects) are NOT attributed to a wallet;
|
|
1603
|
+
* nor are address balances (funds credited to an address without a coin object), since they are
|
|
1604
|
+
* not objects and cannot be enumerated by type. `totalSupply` is returned so a caller can
|
|
1605
|
+
* compare it with the sum of the wallets. With `verify` (default true) each wallet is cross-checked against
|
|
1606
|
+
* fullnode `getBalance` (coinBalance + addressBalance), `concurrency` at a time (default 8).
|
|
1607
|
+
*/
|
|
1608
|
+
getFTokenHolders(token: string, opts?: {
|
|
1609
|
+
verify?: boolean;
|
|
1610
|
+
concurrency?: number;
|
|
1611
|
+
pageSize?: number;
|
|
1612
|
+
}): Promise<FTokenHolders>;
|
|
1613
|
+
/** `[rewards writer cap id, current rewards rate in bps]`. */
|
|
1614
|
+
getFTokenRewards(token: string): Promise<[string | null, bigint]>;
|
|
1615
|
+
/** @deprecated Solana name; use `getFTokenRewards`. */
|
|
1616
|
+
getJlTokenRewards: (token: string) => Promise<[string | null, bigint]>;
|
|
1617
|
+
getFTokenRewardsRateModelConfig(token: string): Promise<RewardsRateModelConfig | null>;
|
|
1618
|
+
/** @deprecated Solana name; use `getFTokenRewardsRateModelConfig`. */
|
|
1619
|
+
getJlTokenRewardsRateModelConfig: (token: string) => Promise<RewardsRateModelConfig | null>;
|
|
1620
|
+
getUserPosition(token: string, user: string): Promise<LendingUserPosition>;
|
|
1621
|
+
getUserPositions(user: string): Promise<FTokenDetailsUserPosition[]>;
|
|
1622
|
+
/** `lending::auth::is_admin(&Auth, addr)` via simulation. */
|
|
1623
|
+
isLendingAdmin(addr: string): Promise<boolean>;
|
|
1624
|
+
/** `lending::auth::has_role(&Auth, addr)` (any role) via simulation. */
|
|
1625
|
+
isLendingAuth(addr: string): Promise<boolean>;
|
|
1626
|
+
private authView;
|
|
1627
|
+
}
|
|
1628
|
+
//#endregion
|
|
1629
|
+
//#region src/oracle.d.ts
|
|
1630
|
+
/** Oracle rates are debt-per-collateral in the vault's internal 1e9 space, scaled by 1e15. */
|
|
1631
|
+
declare const ORACLE_RATE_PRECISION = 1000000000000000n;
|
|
1632
|
+
/** Mirrors `fluid_oracle::constants` of the deployed v2 package. */
|
|
1633
|
+
declare const ORACLE_LIMITS: {
|
|
1634
|
+
readonly rateOutputDecimals: 15;
|
|
1635
|
+
readonly maxAgeOperateS: 600n;
|
|
1636
|
+
readonly maxAgeLiquidateS: 7200n;
|
|
1637
|
+
readonly maxPythArrivalLagS: 60n;
|
|
1638
|
+
readonly confidenceScaleOperate: 50n;
|
|
1639
|
+
readonly confidenceScaleLiquidate: 25n;
|
|
1640
|
+
readonly maxPythExponent: 12n;
|
|
1641
|
+
readonly redstoneDecimals: 8;
|
|
1642
|
+
readonly maxInvertibleRate: bigint;
|
|
1643
|
+
};
|
|
1644
|
+
/** `rate::scale_and_invert`: raw provider price with `decimals` → 1e15 rate, optionally inverted. */
|
|
1645
|
+
declare function scaleAndInvert(raw: bigint, decimals: number, invert: boolean): bigint;
|
|
1646
|
+
declare class Oracle {
|
|
1647
|
+
private readonly ctx;
|
|
1648
|
+
constructor(ctx: ReadContext);
|
|
1649
|
+
private get providers();
|
|
1650
|
+
/** v2 oracle object: nonce + main / guard routes. */
|
|
1651
|
+
getOracle(oracleId: string): Promise<OracleData>;
|
|
1652
|
+
/** Provider objects the v2 views take for this oracle. */
|
|
1653
|
+
private providerArgs;
|
|
1654
|
+
private quote;
|
|
1655
|
+
/** Price exactly as vaults see it. v2: operate and liquidate simulated separately (one can abort alone). */
|
|
1656
|
+
getOraclePrice(oracleId: string): Promise<OraclePrice>;
|
|
1657
|
+
/**
|
|
1658
|
+
* Each v2 route read on its own, at the chain's clock: raw price, 1e15 rate, age, and whether it
|
|
1659
|
+
* passes the operate / liquidate checks (`*_core::reading_error`, mirrored off-chain).
|
|
1660
|
+
* Operate price = min over routes; liquidate = min over routes usable for liquidate.
|
|
1661
|
+
*/
|
|
1662
|
+
getOracleRoutes(oracleId: string): Promise<{
|
|
1663
|
+
oracle: OracleData;
|
|
1664
|
+
nowMs: bigint;
|
|
1665
|
+
main: OracleRoute;
|
|
1666
|
+
guard: OracleRoute | null;
|
|
1667
|
+
}>;
|
|
1668
|
+
/** Human price (collateral priced in debt units) from a raw 1e15 rate. */
|
|
1669
|
+
static toNumber(rate: bigint): number;
|
|
1670
|
+
}
|
|
1671
|
+
//#endregion
|
|
1672
|
+
//#region src/math/core.d.ts
|
|
1673
|
+
/** Integer helpers that mirror `fluid_library::math` (all bigint, floor unless named ceil). */
|
|
1674
|
+
declare const FOUR_DECIMALS = 10000n;
|
|
1675
|
+
declare const SECONDS_PER_YEAR = 31536000n;
|
|
1676
|
+
/** Liquidity / vault / lending exchange-price precision (1e12). */
|
|
1677
|
+
declare const EXCHANGE_PRICES_PRECISION = 1000000000000n;
|
|
1678
|
+
/** `exchange_price_rate_output_decimals` in liquidity (1e17). */
|
|
1679
|
+
declare const RATE_OUTPUT_DECIMALS = 100000000000000000n;
|
|
1680
|
+
/** Vault exchange-price scale factor (1e18). */
|
|
1681
|
+
declare const EXCHANGE_PRICE_SCALE_FACTOR = 1000000000000000000n;
|
|
1682
|
+
/** Lending return precision (1e14 = 1e12 * 100). */
|
|
1683
|
+
declare const RETURN_PERCENT_PRECISION = 100000000000000n;
|
|
1684
|
+
/**
|
|
1685
|
+
* The two raw on-chain rate scales differ, which is why every rate FIELD the SDK returns is bps
|
|
1686
|
+
* (1e4 = 100% per year, floored):
|
|
1687
|
+
* - liquidity supply rate (`reserve::calculate_exchange_prices`): 1e12 = 100% -> SUPPLY_RATE_PRECISION
|
|
1688
|
+
* - lending rewards rate (`rewards`, `lending_calcs`): 1e14 = 100% -> RETURN_PERCENT_PRECISION
|
|
1689
|
+
*/
|
|
1690
|
+
declare const SUPPLY_RATE_PRECISION = 1000000000000n;
|
|
1691
|
+
/** Raw liquidity supply rate (1e12 = 100%) -> bps, floored. */
|
|
1692
|
+
declare const supplyRateToBps: (raw: bigint) => bigint;
|
|
1693
|
+
/** Raw lending rewards rate (1e14 = 100%) -> bps, floored. */
|
|
1694
|
+
declare const rewardsRateToBps: (raw: bigint) => bigint;
|
|
1695
|
+
/** Lending max rewards rate: 50% at RETURN_PERCENT_PRECISION (1e14 = 100%). */
|
|
1696
|
+
declare const MAX_REWARDS_RATE = 50000000000000n;
|
|
1697
|
+
declare function mulDiv(a: bigint, b: bigint, c: bigint): bigint;
|
|
1698
|
+
declare function divCeil(a: bigint, b: bigint): bigint;
|
|
1699
|
+
declare function mulDivCeil(a: bigint, b: bigint, c: bigint): bigint;
|
|
1700
|
+
declare const max: (a: bigint, b: bigint) => bigint;
|
|
1701
|
+
declare const min: (a: bigint, b: bigint) => bigint;
|
|
1702
|
+
/** Current unix time in seconds (the default `now` for time-dependent reads). */
|
|
1703
|
+
declare const nowSeconds: () => bigint;
|
|
1704
|
+
//#endregion
|
|
1705
|
+
//#region src/positionIndex.d.ts
|
|
1706
|
+
type PositionSource = "state" | "fullnode-index" | "events+objects";
|
|
1707
|
+
type PositionCounts = {
|
|
1708
|
+
vaultId: number;
|
|
1709
|
+
/** Positions ever opened in this vault (EVM `totalPositions` semantics). */
|
|
1710
|
+
totalPositions: number;
|
|
1711
|
+
/** Positions whose object exists right now (verified on-chain, never from events alone). */
|
|
1712
|
+
openPositions: number;
|
|
1713
|
+
/** On-chain `next_position_id` when the index exists, else `totalPositions + 1` (ordinal). */
|
|
1714
|
+
nextPositionId: number;
|
|
1715
|
+
/** Open position object ids (index order when the on-chain index exists). */
|
|
1716
|
+
openPositionIds: string[];
|
|
1717
|
+
/** Where the enumeration came from. Only "state" is a stored on-chain value. */
|
|
1718
|
+
source: PositionSource;
|
|
1719
|
+
};
|
|
1720
|
+
type PositionIndexOptions = {
|
|
1721
|
+
/** Override `config.graphqlUrl`. */
|
|
1722
|
+
graphqlUrl?: string;
|
|
1723
|
+
pageSize?: number;
|
|
1724
|
+
retries?: number;
|
|
1725
|
+
/** Base backoff in ms (doubles per attempt). */
|
|
1726
|
+
backoffMs?: number;
|
|
1727
|
+
fetchImpl?: typeof fetch;
|
|
1728
|
+
};
|
|
1729
|
+
declare const POSITION_INDEX_FIX: string;
|
|
1730
|
+
declare class PositionIndex {
|
|
1731
|
+
private ctx;
|
|
1732
|
+
private opts;
|
|
1733
|
+
private streams;
|
|
1734
|
+
private inflight;
|
|
1735
|
+
constructor(ctx: ReadContext, opts?: PositionIndexOptions);
|
|
1736
|
+
/**
|
|
1737
|
+
* Reads the proposed on-chain index by derived ids. `null` when the vault has no index yet.
|
|
1738
|
+
* Returns ordinal -> cap id for every position ever opened, and the stored counter.
|
|
1739
|
+
*/
|
|
1740
|
+
readOnchainIndex(vaultMarketId: string): Promise<{
|
|
1741
|
+
nextPositionId: number;
|
|
1742
|
+
capIds: string[];
|
|
1743
|
+
} | null>;
|
|
1744
|
+
/** Every position id ever claimed on `vaultMarketId` (`derived_object::Claimed` fields). */
|
|
1745
|
+
claimedIds(vaultMarketId: string): Promise<string[]>;
|
|
1746
|
+
counts(vaultId: number, vaultMarketId: string): Promise<PositionCounts>;
|
|
1747
|
+
private finish;
|
|
1748
|
+
/** Lowest discovery level `counts` would need right now for this vault. */
|
|
1749
|
+
requiredLevel(vaultMarketId: string): Promise<DiscoveryLevel>;
|
|
1750
|
+
private get url();
|
|
1751
|
+
private type;
|
|
1752
|
+
private post;
|
|
1753
|
+
/** All events of `type`, resuming from the last cursor. Concurrent callers share one scan. */
|
|
1754
|
+
private sync;
|
|
1755
|
+
/** Every position id ever opened in `vaultMarketId` (event order, deduped). Indexer tier. */
|
|
1756
|
+
openedIds(vaultMarketId: string): Promise<string[]>;
|
|
1757
|
+
/** Position ids with a `LogClosePosition` for numeric `vaultId`. Indexer tier. */
|
|
1758
|
+
closedIds(vaultId: number): Promise<Set<string>>;
|
|
1759
|
+
/** Drop cached cursors (forces a full rescan next call). */
|
|
1760
|
+
reset(): void;
|
|
1761
|
+
}
|
|
1762
|
+
//#endregion
|
|
1763
|
+
//#region src/vault.d.ts
|
|
1764
|
+
/** `withOracle` (default true): oracle price via one simulation. `positionCounts` (default true):
|
|
1765
|
+
* fill `totalPositions` / `nextPositionId` from the derived position index (-1 if unreachable). */
|
|
1766
|
+
type VaultReadOpts = {
|
|
1767
|
+
withOracle?: boolean;
|
|
1768
|
+
positionCounts?: boolean;
|
|
1769
|
+
};
|
|
1770
|
+
type VaultRecord = {
|
|
1771
|
+
vaultId: number;
|
|
1772
|
+
id: string;
|
|
1773
|
+
collateralType: string;
|
|
1774
|
+
debtType: string;
|
|
1775
|
+
raw: ReturnType<typeof VaultMarket.parse>;
|
|
1776
|
+
};
|
|
1777
|
+
declare class Vault {
|
|
1778
|
+
private readonly ctx;
|
|
1779
|
+
private readonly liquidity;
|
|
1780
|
+
private readonly oracle;
|
|
1781
|
+
/** Derived per-vault position counts (no counter exists on-chain on Sui). */
|
|
1782
|
+
readonly positions: PositionIndex;
|
|
1783
|
+
constructor(ctx: ReadContext, liquidity: Liquidity, oracle: Oracle);
|
|
1784
|
+
/**
|
|
1785
|
+
* totalPositions (ever opened, EVM parity), openPositions (object exists now), nextPositionId
|
|
1786
|
+
* (stored counter once the on-chain index ships, else totalPositions + 1). Pure state when the
|
|
1787
|
+
* vault has the on-chain index; otherwise needs `discovery: "fullnode"` (derived_object claims)
|
|
1788
|
+
* or "indexer" (events), and throws `NeedsDiscoveryError` under the default "state".
|
|
1789
|
+
*/
|
|
1790
|
+
getVaultPositionCounts(vaultId: number): Promise<PositionCounts>;
|
|
1791
|
+
/** Counts for state fills: never lets an event-endpoint outage break a vault read (-1 then). */
|
|
1792
|
+
private countsOrNull;
|
|
1793
|
+
getTotalVaults(): Promise<number>;
|
|
1794
|
+
loadVaults(vaultIds: readonly number[]): Promise<VaultRecord[]>;
|
|
1795
|
+
loadVault(vaultId: number): Promise<VaultRecord>;
|
|
1796
|
+
configFromRecord(v: VaultRecord): VaultConfig;
|
|
1797
|
+
getVaultConfig(vaultId: number): Promise<VaultConfig>;
|
|
1798
|
+
batchGetTicks(vaultId: number, ticks: readonly number[]): Promise<(DecodedTick | null)[]>;
|
|
1799
|
+
private ticksOf;
|
|
1800
|
+
getTick({
|
|
1801
|
+
vaultId,
|
|
1802
|
+
tick
|
|
1803
|
+
}: {
|
|
1804
|
+
vaultId: number;
|
|
1805
|
+
tick: number;
|
|
1806
|
+
}): Promise<DecodedTick | null>;
|
|
1807
|
+
batchGetBranches(vaultId: number, branchIds: readonly number[]): Promise<(DecodedBranch | null)[]>;
|
|
1808
|
+
private branchesOf;
|
|
1809
|
+
getBranch({
|
|
1810
|
+
vaultId,
|
|
1811
|
+
branchId
|
|
1812
|
+
}: {
|
|
1813
|
+
vaultId: number;
|
|
1814
|
+
branchId: number;
|
|
1815
|
+
}): Promise<DecodedBranch | null>;
|
|
1816
|
+
/** Branches 1..total_branch_id. */
|
|
1817
|
+
getAllBranches(vaultId: number): Promise<DecodedBranch[]>;
|
|
1818
|
+
getTickIdLiquidation({
|
|
1819
|
+
vaultId,
|
|
1820
|
+
tick,
|
|
1821
|
+
tickId
|
|
1822
|
+
}: {
|
|
1823
|
+
vaultId: number;
|
|
1824
|
+
tick: number;
|
|
1825
|
+
tickId: number;
|
|
1826
|
+
}): Promise<DecodedTickIdLiquidation | null>;
|
|
1827
|
+
/** Raw `tick_bitmap` words (u256) for `words`; missing words = 0. */
|
|
1828
|
+
getTickHasDebtArray(vaultId: number, words: readonly number[]): Promise<{
|
|
1829
|
+
word: number;
|
|
1830
|
+
bitmap: bigint;
|
|
1831
|
+
}[]>;
|
|
1832
|
+
private stateFromRecord;
|
|
1833
|
+
getVaultState(vaultId: number, opts?: {
|
|
1834
|
+
positionCounts?: boolean;
|
|
1835
|
+
}): Promise<VaultState>;
|
|
1836
|
+
/** `user::get_exchange_prices`: (liqSupply, liqBorrow, vaultSupply, vaultBorrow) accrued to `now`. */
|
|
1837
|
+
exchangePricesFromRecords(v: VaultRecord, colReserve: ReserveRecord, debtReserve: ReserveRecord, now: bigint): {
|
|
1838
|
+
liquiditySupplyExchangePrice: bigint;
|
|
1839
|
+
liquidityBorrowExchangePrice: bigint;
|
|
1840
|
+
vaultSupplyExchangePrice: bigint;
|
|
1841
|
+
vaultBorrowExchangePrice: bigint;
|
|
1842
|
+
};
|
|
1843
|
+
/** Full vault view. `withOracle` (default true) adds the oracle price via one simulation. */
|
|
1844
|
+
getVaultEntireData(vaultId: number, opts?: VaultReadOpts): Promise<VaultEntireData>;
|
|
1845
|
+
getVaultEntireDataV2(vaultId: number, opts?: VaultReadOpts): Promise<VaultEntireDataV2>;
|
|
1846
|
+
getAllVaults(opts?: VaultReadOpts): Promise<VaultEntireData[]>;
|
|
1847
|
+
getAllVaultsV2(opts?: VaultReadOpts): Promise<VaultEntireDataV2[]>;
|
|
1848
|
+
getVaultByVaultId: (vaultId: number) => Promise<VaultEntireData>;
|
|
1849
|
+
private toV2;
|
|
1850
|
+
private entireDataFor;
|
|
1851
|
+
/** Raw Position object. `vaultId` is resolved from the position's VaultMarket if omitted. */
|
|
1852
|
+
getUserPosition({
|
|
1853
|
+
positionId,
|
|
1854
|
+
vaultId
|
|
1855
|
+
}: {
|
|
1856
|
+
positionId: string;
|
|
1857
|
+
vaultId?: number;
|
|
1858
|
+
}): Promise<UserPosition | null>;
|
|
1859
|
+
batchGetUserPositions(positionIds: readonly string[]): Promise<(UserPosition | null)[]>;
|
|
1860
|
+
private vaultIdOf;
|
|
1861
|
+
/** Everything `fetch_latest_position` needs for one position (tick, snapshot, branch chain). */
|
|
1862
|
+
private liquidationLookups;
|
|
1863
|
+
/** Solana `getCurrentPositionState`: raw col/debt after any liquidation, as operate would settle it. */
|
|
1864
|
+
getCurrentPositionState({
|
|
1865
|
+
vaultId,
|
|
1866
|
+
position
|
|
1867
|
+
}: {
|
|
1868
|
+
vaultId: number;
|
|
1869
|
+
position: UserPosition;
|
|
1870
|
+
}): Promise<UserPositionWithDebt>;
|
|
1871
|
+
getFinalPosition({
|
|
1872
|
+
vaultId,
|
|
1873
|
+
positionId
|
|
1874
|
+
}: {
|
|
1875
|
+
vaultId: number;
|
|
1876
|
+
positionId: string;
|
|
1877
|
+
}): Promise<UserPositionWithDebt>;
|
|
1878
|
+
/** Owner of a PositionOwnerCap (Solana `getNftOwner`). */
|
|
1879
|
+
getPositionOwner(capId: string): Promise<string | null>;
|
|
1880
|
+
getNftOwner: (capId: string) => Promise<string | null>;
|
|
1881
|
+
/** Solana `buildNftPositionFromPositionAccount` semantics, on a fetched vault context. */
|
|
1882
|
+
private buildNftPosition;
|
|
1883
|
+
/** Solana `getPositionByVaultId(vaultId, nftId)`; Sui takes the Position object id. */
|
|
1884
|
+
getPositionByVaultId(vaultId: number, positionId: string): Promise<NftPosition & {
|
|
1885
|
+
vault: VaultEntireData;
|
|
1886
|
+
}>;
|
|
1887
|
+
getPositionByVaultIdV2(vaultId: number, positionId: string): Promise<{
|
|
1888
|
+
vault: VaultEntireDataV2;
|
|
1889
|
+
nftId: string;
|
|
1890
|
+
owner: string | null;
|
|
1891
|
+
capId: string;
|
|
1892
|
+
isSupplyPosition: boolean;
|
|
1893
|
+
supply: bigint;
|
|
1894
|
+
beforeSupply: bigint;
|
|
1895
|
+
dustBorrow: bigint;
|
|
1896
|
+
beforeDustBorrow: bigint;
|
|
1897
|
+
tick: number;
|
|
1898
|
+
tickId: number;
|
|
1899
|
+
borrow: bigint;
|
|
1900
|
+
beforeBorrow: bigint;
|
|
1901
|
+
isLiquidated: boolean;
|
|
1902
|
+
}>;
|
|
1903
|
+
/**
|
|
1904
|
+
* Every position whose PositionOwnerCap `user` owns, across all vaults.
|
|
1905
|
+
*
|
|
1906
|
+
* Pure state when every vault has the on-chain position index: all cap ids come from the
|
|
1907
|
+
* index, their owners from the cap objects themselves. Otherwise needs `discovery: "fullnode"`
|
|
1908
|
+
* (`listOwnedObjects`). If the caller already knows the cap ids (a wallet does), use
|
|
1909
|
+
* `getUserPositionsByCapIds`, which is always pure state.
|
|
1910
|
+
*/
|
|
1911
|
+
getAllUserPositions(user: string): Promise<(NftPosition & {
|
|
1912
|
+
vault: VaultEntireData;
|
|
1913
|
+
})[]>;
|
|
1914
|
+
/** Positions for known PositionOwnerCap ids (pure state: derived position ids only). */
|
|
1915
|
+
getUserPositionsByCapIds(capIds: readonly string[], user?: string): Promise<(NftPosition & {
|
|
1916
|
+
vault: VaultEntireData;
|
|
1917
|
+
})[]>;
|
|
1918
|
+
getAllUserPositionsV2: (user: string) => Promise<{
|
|
1919
|
+
vault: VaultEntireDataV2;
|
|
1920
|
+
nftId: string;
|
|
1921
|
+
owner: string | null;
|
|
1922
|
+
capId: string;
|
|
1923
|
+
isSupplyPosition: boolean;
|
|
1924
|
+
supply: bigint;
|
|
1925
|
+
beforeSupply: bigint;
|
|
1926
|
+
dustBorrow: bigint;
|
|
1927
|
+
beforeDustBorrow: bigint;
|
|
1928
|
+
tick: number;
|
|
1929
|
+
tickId: number;
|
|
1930
|
+
borrow: bigint;
|
|
1931
|
+
beforeBorrow: bigint;
|
|
1932
|
+
isLiquidated: boolean;
|
|
1933
|
+
}[]>;
|
|
1934
|
+
/** Open Position ids in a vault: opened events, minus closes, verified by object existence. */
|
|
1935
|
+
getAllPositionIdsForVault(vaultId: number): Promise<string[]>;
|
|
1936
|
+
/** All open positions of a vault with `riskRatio` = debt / (col × liquidate price), 1e4 scale. */
|
|
1937
|
+
getAllPositionsWithRiskRatio(vaultId: number): Promise<PositionWithRiskRatio[]>;
|
|
1938
|
+
/** Oracle price of a vault's oracle (as vaults consume it). */
|
|
1939
|
+
getOraclePrice(vaultId: number): Promise<OraclePrice>;
|
|
1940
|
+
/** Raw vault-internal 1e9 amounts → token units (`constants::unscale_amounts`). */
|
|
1941
|
+
static unscale(amount: bigint, decimals: number): bigint;
|
|
1942
|
+
}
|
|
1943
|
+
//#endregion
|
|
1944
|
+
//#region src/client.d.ts
|
|
1945
|
+
declare const DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
1946
|
+
type ClientOptions = {
|
|
1947
|
+
/**
|
|
1948
|
+
* REQUIRED. Built-in network name ("staging") or a
|
|
1949
|
+
* full config (e.g. production from `configFromDeployment`). No default, so nobody reads
|
|
1950
|
+
* staging believing it is production.
|
|
1951
|
+
*/
|
|
1952
|
+
network: string | FluidReadConfig;
|
|
1953
|
+
/**
|
|
1954
|
+
* Clock for time-dependent maths. Default "chain": the on-chain Clock (0x6), so accrual and the
|
|
1955
|
+
* rewards windows never depend on this server's clock. "local" = wall clock; or a function
|
|
1956
|
+
* returning unix seconds.
|
|
1957
|
+
*/
|
|
1958
|
+
now?: ClockSource;
|
|
1959
|
+
/** Enumeration policy. Default "state" (no indexer, no list queries). See `DiscoveryLevel`. */
|
|
1960
|
+
discovery?: DiscoveryLevel;
|
|
1961
|
+
/** Per-call timeout before failing over to the next endpoint. Default 15000 ms. */
|
|
1962
|
+
timeoutMs?: number;
|
|
1963
|
+
/** Retry passes over the endpoints with exponential backoff (see `FailoverOptions`). Default 3 passes, 250 ms base, 4 s cap. */
|
|
1964
|
+
retry?: Pick<FailoverOptions, "rounds" | "backoffMs" | "maxBackoffMs">;
|
|
1965
|
+
};
|
|
1966
|
+
/**
|
|
1967
|
+
* Unified reader, same shape as `@jup-ag/lend-read`'s `Client`:
|
|
1968
|
+
* `client.liquidity`, `client.lending`, `client.vault` (+ `client.oracle`, Sui-only).
|
|
1969
|
+
*
|
|
1970
|
+
* @example
|
|
1971
|
+
* const client = new Client(undefined, { network: "staging" }); // staging deployment, Sui mainnet gRPC
|
|
1972
|
+
* const client = new Client("https://my-fullnode:443", { network: prodConfig });
|
|
1973
|
+
* const client = new Client(existingSuiGrpcClient, { network: "staging" });
|
|
1974
|
+
* const vault = await client.vault.getVaultEntireData(1);
|
|
1975
|
+
*/
|
|
1976
|
+
declare class Client {
|
|
1977
|
+
readonly liquidity: Liquidity;
|
|
1978
|
+
readonly lending: Lending;
|
|
1979
|
+
readonly vault: Vault;
|
|
1980
|
+
readonly oracle: Oracle;
|
|
1981
|
+
readonly context: ReadContext;
|
|
1982
|
+
constructor(rpc: string | readonly (string | ClientWithCoreApi)[] | ClientWithCoreApi | undefined, opts: ClientOptions);
|
|
1983
|
+
/**
|
|
1984
|
+
* The same reader pinned to a past `checkpoint`: every object read comes from the GraphQL service
|
|
1985
|
+
* (`config.graphqlUrl`) at that checkpoint and the clock is the checkpoint's timestamp, so
|
|
1986
|
+
* `lending.getLendingStateData()`, rates, reserves and vault state are what the chain held then.
|
|
1987
|
+
* Move views / oracle quotes / balances are not available historically (`CheckpointReadError`).
|
|
1988
|
+
* Needs `discovery: "indexer"` (it is a GraphQL read).
|
|
1989
|
+
*
|
|
1990
|
+
* @example
|
|
1991
|
+
* const past = await client.atCheckpoint(330_000_000);
|
|
1992
|
+
* const state = await past.lending.getLendingStateData();
|
|
1993
|
+
*/
|
|
1994
|
+
atCheckpoint(checkpoint: number | bigint): Promise<Client>;
|
|
1995
|
+
}
|
|
1996
|
+
/**
|
|
1997
|
+
* `$extend` form, same pattern as the write SDK's `fluid()`:
|
|
1998
|
+
* `const c = new SuiGrpcClient({...}).$extend(fluidRead()); c.fluidRead.vault...`
|
|
1999
|
+
*/
|
|
2000
|
+
declare function fluidRead(opts: ClientOptions): {
|
|
2001
|
+
name: "fluidRead";
|
|
2002
|
+
register: (client: ClientWithCoreApi) => Client;
|
|
2003
|
+
};
|
|
2004
|
+
//#endregion
|
|
2005
|
+
//#region src/view.d.ts
|
|
2006
|
+
declare class ViewCallError extends Error {
|
|
2007
|
+
readonly details?: unknown | undefined;
|
|
2008
|
+
constructor(message: string, details?: unknown | undefined);
|
|
2009
|
+
}
|
|
2010
|
+
/**
|
|
2011
|
+
* Build a PTB with `build`, simulate it, and return every command's return values as raw BCS.
|
|
2012
|
+
* `results[i][j]` = return value j of command i.
|
|
2013
|
+
*/
|
|
2014
|
+
declare function simulateView(client: ClientWithCoreApi, build: (tx: Transaction) => void | TransactionResult | unknown): Promise<Uint8Array[][]>;
|
|
2015
|
+
//#endregion
|
|
2016
|
+
//#region src/graphql.d.ts
|
|
2017
|
+
declare class GraphQLError extends Error {
|
|
2018
|
+
readonly errors?: unknown | undefined;
|
|
2019
|
+
constructor(message: string, errors?: unknown | undefined);
|
|
2020
|
+
}
|
|
2021
|
+
type GraphQLOptions = {
|
|
2022
|
+
/** Attempts in total. Default 3. */
|
|
2023
|
+
rounds?: number;
|
|
2024
|
+
backoffMs?: number;
|
|
2025
|
+
maxBackoffMs?: number;
|
|
2026
|
+
timeoutMs?: number;
|
|
2027
|
+
};
|
|
2028
|
+
/**
|
|
2029
|
+
* POST one query. Network errors, timeouts, HTTP 429/5xx are retried with backoff; a GraphQL
|
|
2030
|
+
* `errors` payload (bad query, unknown object) is NOT retried.
|
|
2031
|
+
*/
|
|
2032
|
+
declare function graphqlQuery<T>(url: string, query: string, variables?: Record<string, unknown>, opts?: GraphQLOptions): Promise<T>;
|
|
2033
|
+
//#endregion
|
|
2034
|
+
//#region src/checkpoint.d.ts
|
|
2035
|
+
declare class CheckpointReadError extends Error {
|
|
2036
|
+
constructor(method: string, checkpoint: bigint);
|
|
2037
|
+
}
|
|
2038
|
+
/** Timestamp of `checkpoint` in unix seconds (floored, as `units::from_clock` reads it). */
|
|
2039
|
+
declare function checkpointTimestampSeconds(url: string, checkpoint: bigint, opts?: GraphQLOptions): Promise<bigint>;
|
|
2040
|
+
/** Latest checkpoint the GraphQL service has indexed. */
|
|
2041
|
+
declare function latestCheckpoint(url: string, opts?: GraphQLOptions): Promise<bigint>;
|
|
2042
|
+
/**
|
|
2043
|
+
* A core client pinned to `checkpoint`: `getObjects` via GraphQL at that checkpoint,
|
|
2044
|
+
* `getCoinMetadata` from `live` (immutable data), every other core read throws.
|
|
2045
|
+
*/
|
|
2046
|
+
declare function checkpointClient(url: string, checkpoint: bigint, live: ClientWithCoreApi, opts?: GraphQLOptions): ClientWithCoreApi & {
|
|
2047
|
+
checkpoint: bigint;
|
|
2048
|
+
};
|
|
2049
|
+
declare namespace vault_d_exports {
|
|
2050
|
+
export { BRANCH_STATUS, LiquidationLookups, SignedMagnifier, currentPositionState, fetchLatestPosition, loadVaultExchangePrices, minimumDebt, needsLiquidationSettle, positionInfo, rawToNormal, unscale };
|
|
2051
|
+
}
|
|
2052
|
+
declare const BRANCH_STATUS: {
|
|
2053
|
+
readonly NotLiquidated: 0;
|
|
2054
|
+
readonly Liquidated: 1;
|
|
2055
|
+
readonly Merged: 2;
|
|
2056
|
+
readonly Closed: 3;
|
|
2057
|
+
};
|
|
2058
|
+
/** Signed rate magnifier (Move `RateMagnifier { magnitude, negative }` → signed bigint). */
|
|
2059
|
+
type SignedMagnifier = bigint;
|
|
2060
|
+
/** `exchange_price::load_exchange_prices` → `(vaultSupplyExPrice, vaultBorrowExPrice)`. */
|
|
2061
|
+
declare function loadVaultExchangePrices(p: {
|
|
2062
|
+
vaultSupplyExPrice: bigint;
|
|
2063
|
+
vaultBorrowExPrice: bigint;
|
|
2064
|
+
oldLiqSupplyExPrice: bigint;
|
|
2065
|
+
oldLiqBorrowExPrice: bigint;
|
|
2066
|
+
liqSupplyExPrice: bigint;
|
|
2067
|
+
liqBorrowExPrice: bigint;
|
|
2068
|
+
timeDiff: bigint;
|
|
2069
|
+
supplyRateMagnifier: SignedMagnifier;
|
|
2070
|
+
borrowRateMagnifier: SignedMagnifier;
|
|
2071
|
+
}): {
|
|
2072
|
+
vaultSupplyExchangePrice: bigint;
|
|
2073
|
+
vaultBorrowExchangePrice: bigint;
|
|
2074
|
+
};
|
|
2075
|
+
/** `position::get_position_info`: (colRaw, dustDebtRaw, debtRaw, tick, tickId). Debt is rounded up. */
|
|
2076
|
+
declare function positionInfo(pos: {
|
|
2077
|
+
isSupplyOnlyPosition: boolean;
|
|
2078
|
+
tick: number;
|
|
2079
|
+
tickId: number;
|
|
2080
|
+
supplyAmount: bigint;
|
|
2081
|
+
dustDebtAmount: bigint;
|
|
2082
|
+
}): {
|
|
2083
|
+
colRaw: bigint;
|
|
2084
|
+
dustDebtRaw: bigint;
|
|
2085
|
+
debtRaw: bigint;
|
|
2086
|
+
tick: number;
|
|
2087
|
+
tickId: number;
|
|
2088
|
+
};
|
|
2089
|
+
type LiquidationLookups = {
|
|
2090
|
+
tick: DecodedTick;
|
|
2091
|
+
/** Required when `tick.totalIds !== tickId` (the position's id was snapshotted). */
|
|
2092
|
+
snap?: DecodedTickIdLiquidation | null;
|
|
2093
|
+
/** Branch lookup by id; must cover every branch on the merge chain. */
|
|
2094
|
+
branch: (id: number) => DecodedBranch;
|
|
2095
|
+
};
|
|
2096
|
+
/**
|
|
2097
|
+
* `operate_utils::fetch_latest_position`: the position's debt/col after liquidations, as
|
|
2098
|
+
* `operate` would settle it. `debtRaw` is the position's pre-liquidation raw debt.
|
|
2099
|
+
*/
|
|
2100
|
+
declare function fetchLatestPosition(debtRaw: bigint, tickId: number, l: LiquidationLookups): {
|
|
2101
|
+
tick: number;
|
|
2102
|
+
colRaw: bigint;
|
|
2103
|
+
debtRaw: bigint;
|
|
2104
|
+
branchId: number;
|
|
2105
|
+
};
|
|
2106
|
+
/** Whether `operate` would run `fetch_latest_position` for this position. */
|
|
2107
|
+
declare const needsLiquidationSettle: (tick: DecodedTick, tickId: number) => boolean;
|
|
2108
|
+
/** Current raw state of a position (Solana `getCurrentPositionState`). */
|
|
2109
|
+
declare function currentPositionState(pos: {
|
|
2110
|
+
isSupplyOnlyPosition: boolean;
|
|
2111
|
+
tick: number;
|
|
2112
|
+
tickId: number;
|
|
2113
|
+
supplyAmount: bigint;
|
|
2114
|
+
dustDebtAmount: bigint;
|
|
2115
|
+
}, lookups: LiquidationLookups | null, debtDecimals?: number): UserPositionWithDebt;
|
|
2116
|
+
/** raw (internal 1e9 space) → normal (still internal space) through a vault exchange price. */
|
|
2117
|
+
declare const rawToNormal: (raw: bigint, exPrice: bigint) => bigint;
|
|
2118
|
+
/** `constants::get_minimum_debt(decimals)` in the internal 1e9 space. */
|
|
2119
|
+
declare const minimumDebt: (decimals: number) => bigint;
|
|
2120
|
+
/** Internal 1e9 space → token units (`constants::unscale_amounts`, floor). */
|
|
2121
|
+
declare const unscale: (amount: bigint, decimals: number) => bigint;
|
|
2122
|
+
declare namespace tick_d_exports {
|
|
2123
|
+
export { COLD_TICK, MAX_MASK_DEBT_FACTOR, MAX_TICK, MIN_TICK, SHIFT, TICK_SPACING, X30, ZERO_TICK_SCALED_RATIO, getRatioAtTick, mulBigNumber, mulDivNormal, tickFromMove, tickToMove };
|
|
2124
|
+
}
|
|
2125
|
+
/** Port of `fluid_library::tick_math` + `fluid_library::big_number` (the parts a reader needs). */
|
|
2126
|
+
declare const MAX_TICK = 16383;
|
|
2127
|
+
declare const MIN_TICK = -16383;
|
|
2128
|
+
/** `tick_math::cold_tick()` = { mag: 2^31, neg: true }: "no tick" (supply-only / fully liquidated). */
|
|
2129
|
+
declare const COLD_TICK = -2147483648;
|
|
2130
|
+
declare const TICK_SPACING = 10015n;
|
|
2131
|
+
declare const ZERO_TICK_SCALED_RATIO = 281474976710656n;
|
|
2132
|
+
declare const SHIFT = 48n;
|
|
2133
|
+
declare const X30 = 1073741823n;
|
|
2134
|
+
/** Move `Tick { mag, neg }` → signed number. */
|
|
2135
|
+
declare function tickFromMove(t: {
|
|
2136
|
+
mag: number;
|
|
2137
|
+
neg: boolean;
|
|
2138
|
+
}): number;
|
|
2139
|
+
/** Signed number → Move `Tick { mag, neg }` (zero is `neg: false`). */
|
|
2140
|
+
declare function tickToMove(tick: number): {
|
|
2141
|
+
mag: number;
|
|
2142
|
+
neg: boolean;
|
|
2143
|
+
};
|
|
2144
|
+
/** ratioX48 = 1.0015^tick * 2^48, bit-exact with `tick_math::get_ratio_at_tick`. */
|
|
2145
|
+
declare function getRatioAtTick(tick: number): bigint;
|
|
2146
|
+
declare const MAX_MASK_DEBT_FACTOR = 1125899906842623n;
|
|
2147
|
+
/** `big_number::mul_big_number`. */
|
|
2148
|
+
declare function mulBigNumber(a: bigint, b: bigint): bigint;
|
|
2149
|
+
/** `big_number::mul_div_normal`: normal * bn1 / bn2. */
|
|
2150
|
+
declare function mulDivNormal(normal: bigint, bn1: bigint, bn2: bigint): bigint;
|
|
2151
|
+
//#endregion
|
|
2152
|
+
export { AllEndpointsFailedError, CONFIGS, CheckpointReadError, Client, type ClientOptions, Configs, ConstantViews, CurrentBranchState, DEFAULT_RPC_URL, DecodedBranch, DecodedTick, DecodedTickIdLiquidation, type DeploymentRecord, type DiscoveryLevel, EXCHANGE_PRICES_PRECISION, EXCHANGE_PRICE_SCALE_FACTOR, ExchangePriceResult, ExchangePricesAndConfig, ExchangePricesAndRates, FOUR_DECIMALS, FTokenDetails, FTokenDetailsUserPosition, FTokenHolder, FTokenHolders, FTokenInternalData, type FailoverOptions, type FluidDerive, type FluidReadConfig, GraphQLError, type GraphQLOptions, JlTokenDetails, JlTokenDetailsUserPosition, JlTokenInternalData, Lending, LendingAccount, type LendingRecord, LendingStateData, LendingUserPosition, LimitsAndAvailability, Liquidity, LiquidityAccount, MAINNET, MAX_REWARDS_RATE, NeedsDiscoveryError, NftPosition, ORACLE_LIMITS, ORACLE_RATE_PRECISION, ObjectNotFoundError, Oracle, OracleData, OraclePrice, OracleRoute, OracleSource, OverallTokenData, POSITION_INDEX_FIX, type PackageIds, type PositionCounts, PositionIndex, type PositionIndexOptions, type PositionSource, PositionWithRiskRatio, PreviewData, RATE_OUTPUT_DECIMALS, RETURN_PERCENT_PRECISION, RateData, RateDataV1, RateDataV2, RateModelAccount, type ReadContext, type ReserveRecord, RewardsRateModelConfig, SECONDS_PER_YEAR, STAGING, SUPPLY_RATE_PRECISION, TotalAmounts, TotalSupplyAndBorrow, UserBorrowData, UserBorrowPositionAccount, UserPosition, UserPositionWithDebt, UserSupplyData, UserSupplyPositionAccount, Vault, VaultConfig, VaultEntireData, VaultEntireDataV2, type VaultReadOpts, type VaultRecord, VaultState, ViewCallError, backoffDelay, bcs_d_exports as bcsTypes, checkpointClient, checkpointTimestampSeconds, clientForEndpoint, configFromDeployment, createDerive, createFailoverClient, divCeil, fluidRead, graphqlQuery, latestCheckpoint, lending_d_exports as lendingMath, liquidity_d_exports as liquidityMath, max, min, mulDiv, mulDivCeil, nowSeconds, resolveConfig, rewardsRateToBps, scaleAndInvert, simulateView, supplyRateToBps, tick_d_exports as tickMath, vault_d_exports as vaultMath };
|