@liquidium/client 0.1.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 +289 -0
- package/dist/index.cjs +5833 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2216 -0
- package/dist/index.d.ts +2216 -0
- package/dist/index.js +5802 -0
- package/dist/index.js.map +1 -0
- package/package.json +65 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,2216 @@
|
|
|
1
|
+
import { Identity, HttpAgent } from '@dfinity/agent';
|
|
2
|
+
import { PublicClient } from 'viem';
|
|
3
|
+
|
|
4
|
+
/** Minimal viem-compatible client shape required for SDK EVM read calls. */
|
|
5
|
+
type EvmReadClient = Pick<PublicClient, "readContract">;
|
|
6
|
+
/**
|
|
7
|
+
* Runtime options for `new LiquidiumClient(config)`.
|
|
8
|
+
*
|
|
9
|
+
* Canister-backed reads and SDK HTTP features work with `{}` defaults. Set
|
|
10
|
+
* `apiBaseUrl` only when overriding the Liquidium production API root.
|
|
11
|
+
*/
|
|
12
|
+
interface LiquidiumClientConfig {
|
|
13
|
+
/** Preset canister IDs. Only `mainnet` is bundled. */
|
|
14
|
+
environment?: Environment;
|
|
15
|
+
/** ICP replica host override (defaults follow `@dfinity/agent`). */
|
|
16
|
+
icHost?: string;
|
|
17
|
+
/** Agent identity for signed canister calls. */
|
|
18
|
+
identity?: Identity;
|
|
19
|
+
/**
|
|
20
|
+
* Base URL for the Liquidium SDK HTTP API root (e.g. `https://app.example.com/api/sdk`).
|
|
21
|
+
* Defaults to the Liquidium production API root. Endpoint versions are owned
|
|
22
|
+
* by this SDK package version.
|
|
23
|
+
*/
|
|
24
|
+
apiBaseUrl?: string;
|
|
25
|
+
/** Extra headers sent with every SDK API request. */
|
|
26
|
+
headers?: Record<string, string>;
|
|
27
|
+
/** Override individual canister principals for custom deployments. */
|
|
28
|
+
canisterIds?: Partial<CanisterIds>;
|
|
29
|
+
/** Custom `fetch` implementation for SDK API requests. */
|
|
30
|
+
fetch?: typeof fetch;
|
|
31
|
+
/** Per-request timeout for SDK API calls in milliseconds. */
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
/** Ethereum RPC URL used for public ERC-20 reads in EVM supply flows. */
|
|
34
|
+
evmRpcUrl?: string;
|
|
35
|
+
/** Optional headers for RPC providers that authenticate via HTTP headers. */
|
|
36
|
+
evmRpcHeaders?: Record<string, string>;
|
|
37
|
+
/** Existing viem public client or compatible read client for EVM reads. */
|
|
38
|
+
evmPublicClient?: EvmReadClient;
|
|
39
|
+
}
|
|
40
|
+
/** Principal text values for canisters used by the client. */
|
|
41
|
+
interface CanisterIds {
|
|
42
|
+
/** Liquidium lending canister principal. */
|
|
43
|
+
lending: string;
|
|
44
|
+
/** BTC pool canister principal. */
|
|
45
|
+
btcPool: string;
|
|
46
|
+
/** ERC-20 pool canister principal. */
|
|
47
|
+
ercPool: string;
|
|
48
|
+
/** ckETH minter deposit helper canister principal. */
|
|
49
|
+
ethDeposit: string;
|
|
50
|
+
/** Accountless instant-loans canister principal. */
|
|
51
|
+
instantLoans: string;
|
|
52
|
+
}
|
|
53
|
+
/** Supported deployment environments with bundled canister ids. */
|
|
54
|
+
declare const Environment: {
|
|
55
|
+
readonly mainnet: "mainnet";
|
|
56
|
+
};
|
|
57
|
+
/** Supported deployment environment name. */
|
|
58
|
+
type Environment = (typeof Environment)[keyof typeof Environment];
|
|
59
|
+
/** Canonical asset symbols supported by state-mutating protocol flows. */
|
|
60
|
+
declare const Asset: {
|
|
61
|
+
readonly BTC: "BTC";
|
|
62
|
+
readonly SOL: "SOL";
|
|
63
|
+
readonly USDC: "USDC";
|
|
64
|
+
readonly USDT: "USDT";
|
|
65
|
+
};
|
|
66
|
+
/** Canonical asset symbol supported by state-mutating protocol flows. */
|
|
67
|
+
type Asset = (typeof Asset)[keyof typeof Asset];
|
|
68
|
+
/** Canonical chain identifiers used by wallet and protocol actions. */
|
|
69
|
+
declare const Chain: {
|
|
70
|
+
readonly BTC: "BTC";
|
|
71
|
+
readonly ETH: "ETH";
|
|
72
|
+
};
|
|
73
|
+
/** Canonical chain identifier used by wallet and protocol actions. */
|
|
74
|
+
type Chain = (typeof Chain)[keyof typeof Chain];
|
|
75
|
+
/** Asset symbol as returned by market-data APIs, including future assets. */
|
|
76
|
+
type MarketAsset = string;
|
|
77
|
+
/** Chain name as returned by market-data APIs, including future chains. */
|
|
78
|
+
type MarketChain = string;
|
|
79
|
+
/** Inflow operation performed by a supply target. */
|
|
80
|
+
declare const SupplyAction: {
|
|
81
|
+
readonly deposit: "deposit";
|
|
82
|
+
readonly repayment: "repayment";
|
|
83
|
+
};
|
|
84
|
+
/** Inflow operation performed by a supply target. */
|
|
85
|
+
type SupplyAction = (typeof SupplyAction)[keyof typeof SupplyAction];
|
|
86
|
+
/** Outflow operation reported by the lending canister. */
|
|
87
|
+
declare const OutflowType: {
|
|
88
|
+
readonly borrow: "borrow";
|
|
89
|
+
readonly feeClaim: "feeClaim";
|
|
90
|
+
readonly withdraw: "withdraw";
|
|
91
|
+
};
|
|
92
|
+
/** Outflow operation reported by the lending canister. */
|
|
93
|
+
type OutflowType = (typeof OutflowType)[keyof typeof OutflowType];
|
|
94
|
+
/** Inflow submit type expected by the SDK API. */
|
|
95
|
+
declare const InflowSubmitType: {
|
|
96
|
+
readonly DEPOSIT: "DEPOSIT";
|
|
97
|
+
readonly REPAY: "REPAY";
|
|
98
|
+
};
|
|
99
|
+
/** Inflow submit type expected by the SDK API. */
|
|
100
|
+
type InflowSubmitType = (typeof InflowSubmitType)[keyof typeof InflowSubmitType];
|
|
101
|
+
/** Wallet address and chain pair linked to a Liquidium profile. */
|
|
102
|
+
interface Wallet {
|
|
103
|
+
/** Chain where the wallet address is valid. */
|
|
104
|
+
chain: Chain;
|
|
105
|
+
/** Wallet address as stored by the protocol. */
|
|
106
|
+
address: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface CanisterContext {
|
|
110
|
+
agent: HttpAgent;
|
|
111
|
+
canisterIds: CanisterIds;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Asset transfer path used for wallet-executed actions. */
|
|
115
|
+
declare const TransferMode: {
|
|
116
|
+
readonly ck: "ck";
|
|
117
|
+
readonly native: "native";
|
|
118
|
+
};
|
|
119
|
+
/** Asset transfer path used for wallet-executed actions. */
|
|
120
|
+
type TransferMode = (typeof TransferMode)[keyof typeof TransferMode];
|
|
121
|
+
/** Wallet capability required to execute a prepared SDK action. */
|
|
122
|
+
declare const WalletExecutionKind: {
|
|
123
|
+
readonly sendEthTransaction: "send-eth-transaction";
|
|
124
|
+
readonly signMessage: "sign-message";
|
|
125
|
+
readonly signPsbt: "sign-psbt";
|
|
126
|
+
};
|
|
127
|
+
/** Wallet capability required to execute a prepared SDK action. */
|
|
128
|
+
type WalletExecutionKind = (typeof WalletExecutionKind)[keyof typeof WalletExecutionKind];
|
|
129
|
+
/** Protocol action represented by a prepared wallet action. */
|
|
130
|
+
declare const WalletActionKind: {
|
|
131
|
+
readonly createAccount: "create-account";
|
|
132
|
+
readonly createBorrow: "create-borrow";
|
|
133
|
+
readonly createWithdraw: "create-withdraw";
|
|
134
|
+
};
|
|
135
|
+
/** Protocol action represented by a prepared wallet action. */
|
|
136
|
+
type WalletActionKind = (typeof WalletActionKind)[keyof typeof WalletActionKind];
|
|
137
|
+
/** EVM transaction request passed to wallet adapters. */
|
|
138
|
+
interface EthTransactionRequest {
|
|
139
|
+
/** Destination address or contract address. */
|
|
140
|
+
to: string;
|
|
141
|
+
/** Hex-encoded calldata for contract interactions. */
|
|
142
|
+
data?: string;
|
|
143
|
+
/** Native ETH value in wei, serialized as a decimal string. */
|
|
144
|
+
value?: string;
|
|
145
|
+
/** Optional EVM chain id for wallet implementations that require it. */
|
|
146
|
+
chainId?: number;
|
|
147
|
+
}
|
|
148
|
+
/** Message-signing request passed to wallet adapters. */
|
|
149
|
+
interface SignMessageRequest {
|
|
150
|
+
/** Chain for the signing wallet. */
|
|
151
|
+
chain: Chain;
|
|
152
|
+
/** Plaintext message to sign. */
|
|
153
|
+
message: string;
|
|
154
|
+
/** Optional account override for the signing wallet. */
|
|
155
|
+
account?: string;
|
|
156
|
+
/** SDK action type that produced this request. */
|
|
157
|
+
actionType: string;
|
|
158
|
+
/** Transfer path associated with the action. */
|
|
159
|
+
transferMode: TransferMode;
|
|
160
|
+
}
|
|
161
|
+
/** PSBT-signing request passed to BTC wallet adapters. */
|
|
162
|
+
interface SignPsbtRequest {
|
|
163
|
+
/** BTC chain discriminator. */
|
|
164
|
+
chain: Extract<Chain, "BTC">;
|
|
165
|
+
/** Base64-encoded unsigned PSBT. */
|
|
166
|
+
psbtBase64: string;
|
|
167
|
+
/** Optional BTC account override. */
|
|
168
|
+
account?: string;
|
|
169
|
+
/** SDK action type that produced this request. */
|
|
170
|
+
actionType: string;
|
|
171
|
+
/** Transfer path associated with the action. */
|
|
172
|
+
transferMode: TransferMode;
|
|
173
|
+
}
|
|
174
|
+
/** ETH transaction-sending request passed to wallet adapters. */
|
|
175
|
+
interface SendEthTransactionRequest {
|
|
176
|
+
/** ETH chain discriminator. */
|
|
177
|
+
chain: Extract<Chain, "ETH">;
|
|
178
|
+
/** Transaction payload to send. */
|
|
179
|
+
transaction: EthTransactionRequest;
|
|
180
|
+
/** Optional account override for the sending wallet. */
|
|
181
|
+
account?: string;
|
|
182
|
+
/** SDK action type that produced this request. */
|
|
183
|
+
actionType: string;
|
|
184
|
+
/** Transfer path associated with the action. */
|
|
185
|
+
transferMode: TransferMode;
|
|
186
|
+
}
|
|
187
|
+
/** BTC transaction-sending request passed to wallet adapters. */
|
|
188
|
+
interface SendBtcTransactionRequest {
|
|
189
|
+
/** BTC chain discriminator. */
|
|
190
|
+
chain: Extract<Chain, "BTC">;
|
|
191
|
+
/** Recipient BTC address. */
|
|
192
|
+
toAddress: string;
|
|
193
|
+
/** Amount in satoshis when the SDK knows the transfer amount. */
|
|
194
|
+
amountSats?: bigint;
|
|
195
|
+
/** Optional account override for the sending wallet. */
|
|
196
|
+
account?: string;
|
|
197
|
+
/** SDK action type that produced this request. */
|
|
198
|
+
actionType: string;
|
|
199
|
+
/** Transfer path associated with the action. */
|
|
200
|
+
transferMode: TransferMode;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Optional wallet capabilities. Implement only what your flow uses:
|
|
204
|
+
*
|
|
205
|
+
* - `signMessage` - account creation, borrow, withdraw
|
|
206
|
+
* - `sendBtcTransaction` / `sendEthTransaction` - automated transfer-path supply
|
|
207
|
+
* - `sendEthTransaction` - contract-interaction supply and ETH native sends
|
|
208
|
+
* - `signPsbt` - reserved for PSBT-based actions when exposed
|
|
209
|
+
*/
|
|
210
|
+
interface WalletAdapter {
|
|
211
|
+
/** Signs an SDK plaintext message and returns the wallet signature. */
|
|
212
|
+
signMessage?: (request: SignMessageRequest) => Promise<string>;
|
|
213
|
+
/** Signs an SDK-provided BTC PSBT and returns the signed PSBT as base64. */
|
|
214
|
+
signPsbt?: (request: SignPsbtRequest) => Promise<string>;
|
|
215
|
+
/** Sends an EVM transaction and returns its transaction hash. */
|
|
216
|
+
sendEthTransaction?: (request: SendEthTransactionRequest) => Promise<string>;
|
|
217
|
+
/** Sends a BTC transaction and returns its transaction id. */
|
|
218
|
+
sendBtcTransaction?: (request: SendBtcTransactionRequest) => Promise<string>;
|
|
219
|
+
}
|
|
220
|
+
/** Signature payload submitted to a sign-message action. */
|
|
221
|
+
interface SignatureInfo {
|
|
222
|
+
/** Wallet signature over the action message. */
|
|
223
|
+
signature: string;
|
|
224
|
+
/** Chain used to produce the signature. */
|
|
225
|
+
chain: Chain;
|
|
226
|
+
/** Account that produced the signature, when different from the action default. */
|
|
227
|
+
account?: string;
|
|
228
|
+
}
|
|
229
|
+
/** Prepared action that requires message signing before submit. */
|
|
230
|
+
interface SignMessageWalletAction<TData, TResult> {
|
|
231
|
+
/** Protocol action kind. */
|
|
232
|
+
kind: string;
|
|
233
|
+
/** Wallet capability required to execute the action. */
|
|
234
|
+
executionKind: typeof WalletExecutionKind.signMessage;
|
|
235
|
+
/** Adapter-facing action type. */
|
|
236
|
+
actionType: string;
|
|
237
|
+
/** Transfer path associated with the action. */
|
|
238
|
+
transferMode: TransferMode;
|
|
239
|
+
/** Default account to pass to the wallet adapter. */
|
|
240
|
+
account: string;
|
|
241
|
+
/** Plaintext message that must be signed. */
|
|
242
|
+
message: string;
|
|
243
|
+
/** Original request data needed to submit the signed action. */
|
|
244
|
+
data: TData;
|
|
245
|
+
/** Submits the signature and resolves the protocol result. */
|
|
246
|
+
submit(signatureInfo: SignatureInfo): Promise<TResult>;
|
|
247
|
+
}
|
|
248
|
+
/** Prepared action that requires BTC PSBT signing before submit. */
|
|
249
|
+
interface SignPsbtWalletAction<TResult> {
|
|
250
|
+
/** Protocol action kind. */
|
|
251
|
+
kind: string;
|
|
252
|
+
/** Wallet capability required to execute the action. */
|
|
253
|
+
executionKind: typeof WalletExecutionKind.signPsbt;
|
|
254
|
+
/** Adapter-facing action type. */
|
|
255
|
+
actionType: string;
|
|
256
|
+
/** Transfer path associated with the action. */
|
|
257
|
+
transferMode: TransferMode;
|
|
258
|
+
/** Optional default account to pass to the wallet adapter. */
|
|
259
|
+
account?: string;
|
|
260
|
+
/** Base64-encoded unsigned PSBT. */
|
|
261
|
+
psbtBase64: string;
|
|
262
|
+
/** Submits the signed PSBT and resolves the protocol result. */
|
|
263
|
+
submit(request: {
|
|
264
|
+
signedPsbtBase64: string;
|
|
265
|
+
}): Promise<TResult>;
|
|
266
|
+
}
|
|
267
|
+
/** Prepared action that requires sending an ETH transaction before submit. */
|
|
268
|
+
interface SendEthTransactionWalletAction<TResult> {
|
|
269
|
+
/** Protocol action kind. */
|
|
270
|
+
kind: string;
|
|
271
|
+
/** Wallet capability required to execute the action. */
|
|
272
|
+
executionKind: typeof WalletExecutionKind.sendEthTransaction;
|
|
273
|
+
/** Adapter-facing action type. */
|
|
274
|
+
actionType: string;
|
|
275
|
+
/** Transfer path associated with the action. */
|
|
276
|
+
transferMode: TransferMode;
|
|
277
|
+
/** Optional default account to pass to the wallet adapter. */
|
|
278
|
+
account?: string;
|
|
279
|
+
/** EVM transaction request to send. */
|
|
280
|
+
transaction: EthTransactionRequest;
|
|
281
|
+
/** Submits the transaction hash and resolves the protocol result. */
|
|
282
|
+
submit(request: {
|
|
283
|
+
txHash: string;
|
|
284
|
+
}): Promise<TResult>;
|
|
285
|
+
}
|
|
286
|
+
/** Any prepared action returned by SDK methods and executable by {@link executeWith}. */
|
|
287
|
+
type WalletAction<TResult> = SignMessageWalletAction<unknown, TResult> | SignPsbtWalletAction<TResult> | SendEthTransactionWalletAction<TResult>;
|
|
288
|
+
|
|
289
|
+
/** Data embedded in a prepared profile-creation action. */
|
|
290
|
+
interface CreateAccountData {
|
|
291
|
+
/** Expiry timestamp, in protocol nanoseconds, included in the signed message. */
|
|
292
|
+
expiryTimestamp: bigint;
|
|
293
|
+
}
|
|
294
|
+
/** Sign-message action that can be submitted after wallet signing. */
|
|
295
|
+
interface SignableAction<TData, TResult> extends SignMessageWalletAction<TData, TResult> {
|
|
296
|
+
}
|
|
297
|
+
/** Prepared action for creating a Liquidium profile. */
|
|
298
|
+
interface CreateAccountAction extends SignableAction<CreateAccountData, string> {
|
|
299
|
+
/** Protocol action kind. */
|
|
300
|
+
kind: typeof WalletActionKind.createAccount;
|
|
301
|
+
/** Required wallet capability. */
|
|
302
|
+
executionKind: typeof WalletExecutionKind.signMessage;
|
|
303
|
+
/** Adapter-facing action type. */
|
|
304
|
+
actionType: typeof WalletActionKind.createAccount;
|
|
305
|
+
}
|
|
306
|
+
/** Signed canister request used to register a new profile. */
|
|
307
|
+
interface CreateAccountRequest {
|
|
308
|
+
/** Profile-creation data that was signed. */
|
|
309
|
+
data: CreateAccountData;
|
|
310
|
+
/** Wallet signature and signer metadata. */
|
|
311
|
+
signatureInfo: SignatureInfo;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
type PrepareCreateProfileOptions = {
|
|
315
|
+
account: string;
|
|
316
|
+
};
|
|
317
|
+
type CreateProfileParams = {
|
|
318
|
+
account: string;
|
|
319
|
+
chain: Chain;
|
|
320
|
+
walletAdapter: WalletAdapter;
|
|
321
|
+
};
|
|
322
|
+
/** Profile lifecycle and linked-wallet helpers. */
|
|
323
|
+
declare class AccountsModule {
|
|
324
|
+
readonly canisterContext: CanisterContext;
|
|
325
|
+
constructor(canisterContext: CanisterContext);
|
|
326
|
+
/**
|
|
327
|
+
* Prepares a profile-creation action that can be signed and submitted later.
|
|
328
|
+
*
|
|
329
|
+
* Use this when you need direct control over the signing flow.
|
|
330
|
+
*
|
|
331
|
+
* @param options - `account` is the wallet address that will own the new profile.
|
|
332
|
+
* @returns A signable {@link CreateAccountAction} with `submit` wired to the canister.
|
|
333
|
+
*/
|
|
334
|
+
prepareCreateProfile(options: PrepareCreateProfileOptions): Promise<CreateAccountAction>;
|
|
335
|
+
/**
|
|
336
|
+
* Creates a Liquidium profile using the provided wallet adapter.
|
|
337
|
+
*
|
|
338
|
+
* This is the convenience form of `prepareCreateProfile(...)` plus execution.
|
|
339
|
+
*
|
|
340
|
+
* @param params - Wallet `account`, signing `chain`, and `walletAdapter` with `signMessage`.
|
|
341
|
+
* @returns The new profile principal as text.
|
|
342
|
+
*/
|
|
343
|
+
createProfile(params: CreateProfileParams): Promise<string>;
|
|
344
|
+
/**
|
|
345
|
+
* Resolves the Liquidium profile id linked to a wallet address.
|
|
346
|
+
*
|
|
347
|
+
* @param walletAddress - Wallet address string as registered with the protocol.
|
|
348
|
+
* @returns Profile principal text, or `null` if none exists.
|
|
349
|
+
*/
|
|
350
|
+
getProfileId(walletAddress: string): Promise<string | null>;
|
|
351
|
+
/**
|
|
352
|
+
* Returns the current nonce for a wallet address.
|
|
353
|
+
*
|
|
354
|
+
* This is mainly useful for custom signing flows built on prepared actions.
|
|
355
|
+
*
|
|
356
|
+
* @param walletAddress - Wallet address used in `get_nonce` on the lending canister.
|
|
357
|
+
* @returns The next signing nonce as a bigint.
|
|
358
|
+
*/
|
|
359
|
+
getWalletNonce(walletAddress: string): Promise<bigint>;
|
|
360
|
+
/**
|
|
361
|
+
* Lists the wallets currently linked to a profile.
|
|
362
|
+
*
|
|
363
|
+
* @param profileId - The Liquidium profile principal text.
|
|
364
|
+
* @returns The wallets currently linked to the requested profile.
|
|
365
|
+
*/
|
|
366
|
+
listLinkedWallets(profileId: string): Promise<Wallet[]>;
|
|
367
|
+
private buildCreateProfileAction;
|
|
368
|
+
private submitCreateProfile;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
interface ApiClient {
|
|
372
|
+
get<T>(path: string): Promise<T>;
|
|
373
|
+
post<TResponse, TBody>(path: string, body: TBody): Promise<TResponse>;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/** Activity list state filter. */
|
|
377
|
+
declare const ActivityFilter: {
|
|
378
|
+
readonly active: "active";
|
|
379
|
+
readonly completed: "completed";
|
|
380
|
+
readonly all: "all";
|
|
381
|
+
};
|
|
382
|
+
/** Activity list state filter. */
|
|
383
|
+
type ActivityFilter = (typeof ActivityFilter)[keyof typeof ActivityFilter];
|
|
384
|
+
/** Direction of value movement for an activity. */
|
|
385
|
+
declare const ActivityDirection: {
|
|
386
|
+
readonly inflow: "inflow";
|
|
387
|
+
readonly outflow: "outflow";
|
|
388
|
+
};
|
|
389
|
+
/** Direction of value movement for an activity. */
|
|
390
|
+
type ActivityDirection = (typeof ActivityDirection)[keyof typeof ActivityDirection];
|
|
391
|
+
/** Consumer-facing activity kind. */
|
|
392
|
+
declare const ActivityKind: {
|
|
393
|
+
readonly deposit: "deposit";
|
|
394
|
+
readonly repayment: "repayment";
|
|
395
|
+
readonly borrow: "borrow";
|
|
396
|
+
readonly withdraw: "withdraw";
|
|
397
|
+
};
|
|
398
|
+
/** Consumer-facing activity kind. */
|
|
399
|
+
type ActivityKind = (typeof ActivityKind)[keyof typeof ActivityKind];
|
|
400
|
+
/** Consumer-facing activity lifecycle status. */
|
|
401
|
+
declare const ActivityStatus: {
|
|
402
|
+
readonly requested: "requested";
|
|
403
|
+
readonly pending: "pending";
|
|
404
|
+
readonly detected: "detected";
|
|
405
|
+
readonly processing: "processing";
|
|
406
|
+
readonly sent: "sent";
|
|
407
|
+
readonly confirmed: "confirmed";
|
|
408
|
+
readonly failed: "failed";
|
|
409
|
+
};
|
|
410
|
+
/** Consumer-facing activity lifecycle status. */
|
|
411
|
+
type ActivityStatus = (typeof ActivityStatus)[keyof typeof ActivityStatus];
|
|
412
|
+
/** Fee top-up state for an inflow activity. */
|
|
413
|
+
interface ActivityTopUp {
|
|
414
|
+
/** Whether another transfer is needed before processing can continue. */
|
|
415
|
+
required: boolean;
|
|
416
|
+
/** Total same-token deposited amount counted toward the current fee. */
|
|
417
|
+
depositedAmount: bigint;
|
|
418
|
+
/** Current deposit-address processing fee. */
|
|
419
|
+
feeAmount: bigint;
|
|
420
|
+
/** Additional amount needed before processing can start. */
|
|
421
|
+
shortfallAmount: bigint;
|
|
422
|
+
}
|
|
423
|
+
/** Activity kind emitted by deposit or repayment inflows. */
|
|
424
|
+
type InflowActivityKind = typeof ActivityKind.deposit | typeof ActivityKind.repayment;
|
|
425
|
+
/** Activity kind emitted by borrow or withdraw outflows. */
|
|
426
|
+
type OutflowActivityKind = typeof ActivityKind.borrow | typeof ActivityKind.withdraw;
|
|
427
|
+
/** Lifecycle status that can appear on an inflow activity. */
|
|
428
|
+
type InflowActivityStatus = typeof ActivityStatus.requested | typeof ActivityStatus.pending | typeof ActivityStatus.detected | typeof ActivityStatus.processing | typeof ActivityStatus.confirmed | typeof ActivityStatus.failed;
|
|
429
|
+
/** Lifecycle status that can appear on an outflow activity. */
|
|
430
|
+
type OutflowActivityStatus = typeof ActivityStatus.requested | typeof ActivityStatus.pending | typeof ActivityStatus.sent | typeof ActivityStatus.confirmed | typeof ActivityStatus.failed;
|
|
431
|
+
interface BaseActivity {
|
|
432
|
+
id: string;
|
|
433
|
+
poolId: string;
|
|
434
|
+
asset: string | null;
|
|
435
|
+
chain: Chain | null;
|
|
436
|
+
amount: bigint;
|
|
437
|
+
timestampMs: number;
|
|
438
|
+
txid: string | null;
|
|
439
|
+
txids?: string[];
|
|
440
|
+
confirmations: number | null;
|
|
441
|
+
requiredConfirmations: number | null;
|
|
442
|
+
}
|
|
443
|
+
/** Deposit or repayment activity returned by the activity API. */
|
|
444
|
+
interface InflowActivity extends BaseActivity {
|
|
445
|
+
/** Direction discriminator. */
|
|
446
|
+
direction: typeof ActivityDirection.inflow;
|
|
447
|
+
/** Deposit or repayment kind. */
|
|
448
|
+
kind: InflowActivityKind;
|
|
449
|
+
/** Single consumer-facing lifecycle status. */
|
|
450
|
+
status: InflowActivityStatus;
|
|
451
|
+
/** Fee top-up state when the inflow is below the current processing fee. */
|
|
452
|
+
topUp?: ActivityTopUp;
|
|
453
|
+
}
|
|
454
|
+
/** Borrow or withdraw activity returned by the activity API. */
|
|
455
|
+
interface OutflowActivity extends BaseActivity {
|
|
456
|
+
/** Direction discriminator. */
|
|
457
|
+
direction: typeof ActivityDirection.outflow;
|
|
458
|
+
/** Borrow or withdraw kind. */
|
|
459
|
+
kind: OutflowActivityKind;
|
|
460
|
+
/** Single consumer-facing lifecycle status. */
|
|
461
|
+
status: OutflowActivityStatus;
|
|
462
|
+
/** Outflows never carry top-up state. */
|
|
463
|
+
topUp?: never;
|
|
464
|
+
}
|
|
465
|
+
/** Any activity returned by `activities.list` or `activities.getStatus`. */
|
|
466
|
+
type Activity = InflowActivity | OutflowActivity;
|
|
467
|
+
/** Request for listing activities by profile id or instant-loan short reference. */
|
|
468
|
+
type ListActivitiesRequest = {
|
|
469
|
+
/** Optional state filter; defaults to `all`. */
|
|
470
|
+
filter?: ActivityFilter;
|
|
471
|
+
} & ({
|
|
472
|
+
profileId: string;
|
|
473
|
+
} | {
|
|
474
|
+
shortRef: string;
|
|
475
|
+
});
|
|
476
|
+
/** Request for fetching one activity by id and owner identifier. */
|
|
477
|
+
type GetActivityStatusRequest = {
|
|
478
|
+
/** Activity or receipt id to look up. */
|
|
479
|
+
id: string;
|
|
480
|
+
} & ({
|
|
481
|
+
profileId: string;
|
|
482
|
+
} | {
|
|
483
|
+
shortRef: string;
|
|
484
|
+
});
|
|
485
|
+
/** Result of an activity status lookup. */
|
|
486
|
+
type GetActivityStatusResponse = {
|
|
487
|
+
found: true;
|
|
488
|
+
activity: Activity;
|
|
489
|
+
} | {
|
|
490
|
+
found: false;
|
|
491
|
+
id: string;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
/** Receipt-oriented activity list and status helpers. */
|
|
495
|
+
declare class ActivitiesModule {
|
|
496
|
+
readonly apiClient: ApiClient | undefined;
|
|
497
|
+
readonly canisterContext: CanisterContext;
|
|
498
|
+
constructor(apiClient: ApiClient | undefined, canisterContext: CanisterContext);
|
|
499
|
+
/**
|
|
500
|
+
* Lists profile activities. Defaults to all activities.
|
|
501
|
+
*
|
|
502
|
+
* Uses the Liquidium SDK API.
|
|
503
|
+
*
|
|
504
|
+
* @param request - Profile id or instant-loan short reference plus optional state filter.
|
|
505
|
+
* @returns Activities owned by the resolved profile.
|
|
506
|
+
*/
|
|
507
|
+
list(request: ListActivitiesRequest): Promise<Activity[]>;
|
|
508
|
+
/**
|
|
509
|
+
* Fetches the latest status for a single receipt/activity id.
|
|
510
|
+
*
|
|
511
|
+
* Uses the Liquidium SDK API.
|
|
512
|
+
*
|
|
513
|
+
* @param request - Activity id plus profile id or instant-loan short reference.
|
|
514
|
+
* @returns The activity when found, otherwise `{ found: false }` with the requested id.
|
|
515
|
+
*/
|
|
516
|
+
getStatus(request: GetActivityStatusRequest): Promise<GetActivityStatusResponse>;
|
|
517
|
+
private requireApi;
|
|
518
|
+
private resolveProfileId;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
/** Consumer-facing status for profile transaction history entries. */
|
|
522
|
+
declare const UserHistoryStatus: {
|
|
523
|
+
readonly requested: "requested";
|
|
524
|
+
readonly pending: "pending";
|
|
525
|
+
readonly confirmed: "confirmed";
|
|
526
|
+
readonly failed: "failed";
|
|
527
|
+
};
|
|
528
|
+
/** Consumer-facing status for profile transaction history entries. */
|
|
529
|
+
type UserHistoryStatus = (typeof UserHistoryStatus)[keyof typeof UserHistoryStatus];
|
|
530
|
+
/** Uppercase status value used by SDK API responses. */
|
|
531
|
+
type UserHistoryStatusApi = Uppercase<UserHistoryStatus>;
|
|
532
|
+
/** User transaction kinds returned by profile transaction history. */
|
|
533
|
+
type UserTransactionHistoryType = "supply" | "borrow" | "repay" | "withdraw";
|
|
534
|
+
/** User liquidation history kind. */
|
|
535
|
+
type UserLiquidationHistoryType = "liquidation";
|
|
536
|
+
/** Any user history kind returned by the history API. */
|
|
537
|
+
type UserHistoryType = UserTransactionHistoryType | UserLiquidationHistoryType;
|
|
538
|
+
interface BaseUserHistoryEntry {
|
|
539
|
+
id: string;
|
|
540
|
+
amount: bigint;
|
|
541
|
+
poolId: string;
|
|
542
|
+
timestamp: string;
|
|
543
|
+
txids?: string[];
|
|
544
|
+
}
|
|
545
|
+
/** Supply, borrow, repay, or withdraw entry in user history. */
|
|
546
|
+
interface UserTransactionHistoryEntry extends BaseUserHistoryEntry {
|
|
547
|
+
/** Transaction history kind. */
|
|
548
|
+
type: UserTransactionHistoryType;
|
|
549
|
+
/** Current lifecycle status. */
|
|
550
|
+
status: UserHistoryStatus;
|
|
551
|
+
}
|
|
552
|
+
/** Liquidation entry in user history. */
|
|
553
|
+
interface UserLiquidationHistoryEntry extends BaseUserHistoryEntry {
|
|
554
|
+
/** Liquidation kind discriminator. */
|
|
555
|
+
type: UserLiquidationHistoryType;
|
|
556
|
+
/** Liquidations are only returned once confirmed. */
|
|
557
|
+
status: typeof UserHistoryStatus.confirmed;
|
|
558
|
+
}
|
|
559
|
+
/** Any consumer-facing profile history entry. */
|
|
560
|
+
type UserHistoryEntry = UserTransactionHistoryEntry | UserLiquidationHistoryEntry;
|
|
561
|
+
/** Filters for profile transaction history requests. */
|
|
562
|
+
interface UserTransactionHistoryFilters {
|
|
563
|
+
/** Pagination cursor from a previous response. */
|
|
564
|
+
cursor?: string;
|
|
565
|
+
/** Maximum number of entries to return. */
|
|
566
|
+
limit?: number;
|
|
567
|
+
/** Market filter accepted by the SDK API. */
|
|
568
|
+
market?: string;
|
|
569
|
+
/** Pool principal text filter. */
|
|
570
|
+
poolId?: string;
|
|
571
|
+
/** Transaction kind filters. */
|
|
572
|
+
types?: UserTransactionHistoryType[];
|
|
573
|
+
/** Status filters. */
|
|
574
|
+
statuses?: UserHistoryEntry["status"][];
|
|
575
|
+
/** Inclusive start timestamp filter accepted by the SDK API. */
|
|
576
|
+
from?: string;
|
|
577
|
+
/** Inclusive end timestamp filter accepted by the SDK API. */
|
|
578
|
+
to?: string;
|
|
579
|
+
}
|
|
580
|
+
/** Filters for profile liquidation history requests. */
|
|
581
|
+
interface UserLiquidationHistoryFilters {
|
|
582
|
+
/** Pagination cursor from a previous response. */
|
|
583
|
+
cursor?: string;
|
|
584
|
+
/** Maximum number of entries to return. */
|
|
585
|
+
limit?: number;
|
|
586
|
+
/** Market filter accepted by the SDK API. */
|
|
587
|
+
market?: string;
|
|
588
|
+
/** Pool principal text filter. */
|
|
589
|
+
poolId?: string;
|
|
590
|
+
/** Inclusive start timestamp filter accepted by the SDK API. */
|
|
591
|
+
from?: string;
|
|
592
|
+
/** Inclusive end timestamp filter accepted by the SDK API. */
|
|
593
|
+
to?: string;
|
|
594
|
+
}
|
|
595
|
+
/** Backwards-compatible alias for user transaction history filters. */
|
|
596
|
+
type ActivitiesRequest = UserTransactionHistoryFilters;
|
|
597
|
+
/** Time-window and pagination options for borrow APY history. */
|
|
598
|
+
interface BorrowApyHistoryRequest {
|
|
599
|
+
/** Pagination cursor from a previous response. */
|
|
600
|
+
cursor?: string;
|
|
601
|
+
/** Maximum number of samples to return. */
|
|
602
|
+
limit?: number;
|
|
603
|
+
/** Inclusive start timestamp filter accepted by the SDK API. */
|
|
604
|
+
from?: string;
|
|
605
|
+
/** Inclusive end timestamp filter accepted by the SDK API. */
|
|
606
|
+
to?: string;
|
|
607
|
+
}
|
|
608
|
+
/** Time-window and pagination options for pool rate history. */
|
|
609
|
+
type PoolHistoryRequest = BorrowApyHistoryRequest;
|
|
610
|
+
/** Borrow APY sample returned to SDK consumers. */
|
|
611
|
+
interface ApySample {
|
|
612
|
+
/** Sample date from the SDK API. */
|
|
613
|
+
date: string;
|
|
614
|
+
/** Decimal scale for `avgRate`. */
|
|
615
|
+
rateDecimals: bigint;
|
|
616
|
+
/** Average borrow rate for the sample, scaled by `rateDecimals`. */
|
|
617
|
+
avgRate: bigint;
|
|
618
|
+
}
|
|
619
|
+
/** Wire-format user history item returned by the SDK API. */
|
|
620
|
+
interface UserHistoryEntryApiItem {
|
|
621
|
+
id: string;
|
|
622
|
+
type: UserHistoryType;
|
|
623
|
+
amount: string;
|
|
624
|
+
poolId: string;
|
|
625
|
+
timestamp: string;
|
|
626
|
+
status: UserHistoryStatusApi;
|
|
627
|
+
txids?: string[];
|
|
628
|
+
}
|
|
629
|
+
/** Wire-format user history page returned by the SDK API. */
|
|
630
|
+
interface UserHistoryResponse {
|
|
631
|
+
success: true;
|
|
632
|
+
items: UserHistoryEntryApiItem[];
|
|
633
|
+
nextCursor?: string;
|
|
634
|
+
}
|
|
635
|
+
/** Pool rate and utilization history entry returned to SDK consumers. */
|
|
636
|
+
interface PoolHistoryEntry {
|
|
637
|
+
/** Sample date from the SDK API. */
|
|
638
|
+
date: string;
|
|
639
|
+
/** Decimal scale for rate fields. */
|
|
640
|
+
rateDecimals: bigint;
|
|
641
|
+
/** Average borrow rate for the sample, scaled by `rateDecimals`. */
|
|
642
|
+
avgBorrowRate: bigint;
|
|
643
|
+
/** Average lend rate for the sample, scaled by `rateDecimals`. */
|
|
644
|
+
avgLendRate: bigint;
|
|
645
|
+
/** Average utilization rate for the sample, scaled by `rateDecimals`. */
|
|
646
|
+
avgUtilizationRate: bigint;
|
|
647
|
+
}
|
|
648
|
+
/** Wire-format pool rate history item returned by the SDK API. */
|
|
649
|
+
interface PoolHistoryEntryApiItem {
|
|
650
|
+
date: string;
|
|
651
|
+
rateDecimals: number;
|
|
652
|
+
avgBorrowRate: string;
|
|
653
|
+
avgLendRate: string;
|
|
654
|
+
avgUtilizationRate: string;
|
|
655
|
+
}
|
|
656
|
+
/** Wire-format pool rate history page returned by the SDK API. */
|
|
657
|
+
interface PoolHistoryResponse {
|
|
658
|
+
success: true;
|
|
659
|
+
items: PoolHistoryEntryApiItem[];
|
|
660
|
+
nextCursor?: string;
|
|
661
|
+
}
|
|
662
|
+
/** Pool configuration snapshot returned to SDK consumers. */
|
|
663
|
+
interface PoolConfigHistoryEntry {
|
|
664
|
+
type: "configuration_change";
|
|
665
|
+
poolId: string;
|
|
666
|
+
asset: string;
|
|
667
|
+
chain: string;
|
|
668
|
+
timestamp: string;
|
|
669
|
+
totalSupply: bigint;
|
|
670
|
+
totalDebt: bigint;
|
|
671
|
+
supplyCap?: bigint;
|
|
672
|
+
borrowCap?: bigint;
|
|
673
|
+
maxLtv: bigint;
|
|
674
|
+
liquidationThreshold: bigint;
|
|
675
|
+
liquidationBonus: bigint;
|
|
676
|
+
protocolLiquidationFee: bigint;
|
|
677
|
+
reserveFactor: bigint;
|
|
678
|
+
baseRate: bigint;
|
|
679
|
+
optimalUtilizationRate: bigint;
|
|
680
|
+
rateSlopeBefore: bigint;
|
|
681
|
+
rateSlopeAfter: bigint;
|
|
682
|
+
lendingIndex: bigint;
|
|
683
|
+
borrowIndex: bigint;
|
|
684
|
+
sameAssetBorrowing: boolean;
|
|
685
|
+
frozen: boolean;
|
|
686
|
+
}
|
|
687
|
+
/** Wire-format pool configuration history item returned by the SDK API. */
|
|
688
|
+
interface PoolConfigHistoryEntryApiItem {
|
|
689
|
+
type: "configuration_change";
|
|
690
|
+
poolId: string;
|
|
691
|
+
asset: string;
|
|
692
|
+
chain: string;
|
|
693
|
+
timestamp: string;
|
|
694
|
+
totalSupply: string;
|
|
695
|
+
totalDebt: string;
|
|
696
|
+
supplyCap?: string;
|
|
697
|
+
borrowCap?: string;
|
|
698
|
+
maxLtv: string;
|
|
699
|
+
liquidationThreshold: string;
|
|
700
|
+
liquidationBonus: string;
|
|
701
|
+
protocolLiquidationFee: string;
|
|
702
|
+
reserveFactor: string;
|
|
703
|
+
baseRate: string;
|
|
704
|
+
optimalUtilizationRate: string;
|
|
705
|
+
rateSlopeBefore: string;
|
|
706
|
+
rateSlopeAfter: string;
|
|
707
|
+
lendingIndex: string;
|
|
708
|
+
borrowIndex: string;
|
|
709
|
+
sameAssetBorrowing: boolean;
|
|
710
|
+
frozen: boolean;
|
|
711
|
+
}
|
|
712
|
+
/** Wire-format pool configuration history page returned by the SDK API. */
|
|
713
|
+
interface PoolConfigHistoryResponse {
|
|
714
|
+
success: true;
|
|
715
|
+
items: PoolConfigHistoryEntryApiItem[];
|
|
716
|
+
nextCursor?: string;
|
|
717
|
+
}
|
|
718
|
+
/** Any history entry returned by history module methods. */
|
|
719
|
+
type HistoryEntry = UserHistoryEntry | PoolHistoryEntry | PoolConfigHistoryEntry;
|
|
720
|
+
/** Generic SDK API paginated response. */
|
|
721
|
+
interface PaginatedResponse<T> {
|
|
722
|
+
/** Items in the current page. */
|
|
723
|
+
items: T[];
|
|
724
|
+
/** Cursor for the next page when more results are available. */
|
|
725
|
+
nextCursor?: string;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/** Historical pool, rate, user transaction, and liquidation data helpers. */
|
|
729
|
+
declare class HistoryModule {
|
|
730
|
+
readonly apiClient: ApiClient | undefined;
|
|
731
|
+
constructor(apiClient: ApiClient | undefined);
|
|
732
|
+
private requireApi;
|
|
733
|
+
/**
|
|
734
|
+
* Returns paginated rate and utilization history for a pool.
|
|
735
|
+
*
|
|
736
|
+
* @param poolId - The pool principal text.
|
|
737
|
+
* @param window - Optional time window with from/to timestamps and limit.
|
|
738
|
+
* @returns A page of pool rate history entries and the next cursor when more results are available.
|
|
739
|
+
*/
|
|
740
|
+
getPoolHistory(poolId: string, window?: PoolHistoryRequest): Promise<PaginatedResponse<PoolHistoryEntry>>;
|
|
741
|
+
/**
|
|
742
|
+
* Returns paginated configuration change history for a pool.
|
|
743
|
+
*
|
|
744
|
+
* @param poolId - The pool principal text.
|
|
745
|
+
* @param cursor - An optional pagination cursor from a previous response.
|
|
746
|
+
* @returns A page of pool configuration changes and the next cursor when more results are available.
|
|
747
|
+
*/
|
|
748
|
+
getPoolConfigHistory(poolId: string, cursor?: string): Promise<PaginatedResponse<PoolConfigHistoryEntry>>;
|
|
749
|
+
/**
|
|
750
|
+
* Returns borrow rate history for a pool.
|
|
751
|
+
*
|
|
752
|
+
* @param poolId - The pool principal text.
|
|
753
|
+
* @param window - Optional time window with from/to timestamps and limit.
|
|
754
|
+
* @returns Paginated APY samples.
|
|
755
|
+
*/
|
|
756
|
+
getBorrowRateHistory(poolId: string, window?: BorrowApyHistoryRequest): Promise<PaginatedResponse<ApySample>>;
|
|
757
|
+
/**
|
|
758
|
+
* Returns transaction history for a user.
|
|
759
|
+
*
|
|
760
|
+
* @param user - The Liquidium profile principal text.
|
|
761
|
+
* @param filters - Optional pool, type, status, time range, and pagination filters.
|
|
762
|
+
* @returns Paginated user history entries.
|
|
763
|
+
*/
|
|
764
|
+
getUserTransactionHistory(user: string, filters?: UserTransactionHistoryFilters): Promise<PaginatedResponse<UserTransactionHistoryEntry>>;
|
|
765
|
+
getUserTransactionHistory(user: string, market?: string, filters?: UserTransactionHistoryFilters): Promise<PaginatedResponse<UserTransactionHistoryEntry>>;
|
|
766
|
+
/**
|
|
767
|
+
* Returns liquidation history for a user.
|
|
768
|
+
*
|
|
769
|
+
* @param user - The Liquidium profile principal text.
|
|
770
|
+
* @param filters - Optional pool, time range, and pagination filters.
|
|
771
|
+
* @returns Paginated liquidation history entries.
|
|
772
|
+
*/
|
|
773
|
+
getLiquidationHistory(user: string, filters?: UserLiquidationHistoryFilters): Promise<PaginatedResponse<UserLiquidationHistoryEntry>>;
|
|
774
|
+
getLiquidationHistory(user: string, market?: string, filters?: UserLiquidationHistoryFilters): Promise<PaginatedResponse<UserLiquidationHistoryEntry>>;
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/** Destination account for a completed outflow. */
|
|
778
|
+
interface OutflowReceiver {
|
|
779
|
+
/** Destination account type reported by the protocol. */
|
|
780
|
+
type: "Native" | "External";
|
|
781
|
+
/** Destination principal or external-chain address. */
|
|
782
|
+
account: string;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Receipt for a borrow or withdraw submitted to the lending canister.
|
|
786
|
+
*
|
|
787
|
+
* `id` is the outflow reference to show users immediately. `txid` may be unset until
|
|
788
|
+
* the protocol assigns a chain transaction id. `outflowRef` is an optional protocol reference.
|
|
789
|
+
*/
|
|
790
|
+
interface OutflowDetails {
|
|
791
|
+
/** Protocol outflow id. */
|
|
792
|
+
id: string;
|
|
793
|
+
/** Borrow, withdraw, or fee-claim discriminator. */
|
|
794
|
+
outflowType: OutflowType;
|
|
795
|
+
/** Optional protocol outflow reference. */
|
|
796
|
+
outflowRef?: string;
|
|
797
|
+
/** Chain transaction id when already assigned by the protocol. */
|
|
798
|
+
txid?: string;
|
|
799
|
+
/** Outflow amount in the pool asset's base units. */
|
|
800
|
+
amount: bigint;
|
|
801
|
+
/** Outflow destination account. */
|
|
802
|
+
receiver: OutflowReceiver;
|
|
803
|
+
}
|
|
804
|
+
/** Borrow receipt with an external-chain receiver. */
|
|
805
|
+
type BorrowOutflowDetails = OutflowDetails & {
|
|
806
|
+
outflowType: "borrow";
|
|
807
|
+
receiver: {
|
|
808
|
+
type: "External";
|
|
809
|
+
account: string;
|
|
810
|
+
};
|
|
811
|
+
};
|
|
812
|
+
/** Withdraw receipt with an external-chain receiver. */
|
|
813
|
+
type WithdrawOutflowDetails = OutflowDetails & {
|
|
814
|
+
outflowType: "withdraw";
|
|
815
|
+
receiver: {
|
|
816
|
+
type: "External";
|
|
817
|
+
account: string;
|
|
818
|
+
};
|
|
819
|
+
};
|
|
820
|
+
/** Signature payload for submitting a prepared borrow action. */
|
|
821
|
+
interface BorrowSubmitSignatureInfo extends SignatureInfo {
|
|
822
|
+
}
|
|
823
|
+
/** Signature payload for submitting a prepared withdraw action. */
|
|
824
|
+
interface WithdrawSubmitSignatureInfo extends SignatureInfo {
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Fields to build a borrow request. `amount` is in the borrow pool asset's base units
|
|
828
|
+
* (e.g. satoshis, token smallest units).
|
|
829
|
+
*/
|
|
830
|
+
interface CreateBorrowRequest {
|
|
831
|
+
/** Liquidium profile principal text. */
|
|
832
|
+
profileId: string;
|
|
833
|
+
/** Borrow pool principal text. */
|
|
834
|
+
poolId: string;
|
|
835
|
+
/** Amount to borrow in the borrow asset's base units. */
|
|
836
|
+
amount: bigint;
|
|
837
|
+
/** External-chain address that receives the borrowed asset. */
|
|
838
|
+
receiverAddress: string;
|
|
839
|
+
/** Wallet address that signs the borrow authorization. */
|
|
840
|
+
signerWalletAddress: string;
|
|
841
|
+
}
|
|
842
|
+
/** Prepared borrow request data embedded in the signable action. */
|
|
843
|
+
interface CreateBorrowData extends CreateBorrowRequest {
|
|
844
|
+
/** Expiry timestamp, in protocol nanoseconds, included in the signed message. */
|
|
845
|
+
expiryTimestamp: bigint;
|
|
846
|
+
}
|
|
847
|
+
/** Prepared action for creating a borrow outflow. */
|
|
848
|
+
interface BorrowAction extends SignMessageWalletAction<CreateBorrowData, BorrowOutflowDetails> {
|
|
849
|
+
/** Protocol action kind. */
|
|
850
|
+
kind: typeof WalletActionKind.createBorrow;
|
|
851
|
+
/** Required wallet capability. */
|
|
852
|
+
executionKind: typeof WalletExecutionKind.signMessage;
|
|
853
|
+
/** Adapter-facing action type. */
|
|
854
|
+
actionType: typeof WalletActionKind.createBorrow;
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Fields to build a withdraw request. `amount` is in the pool asset's base units.
|
|
858
|
+
*/
|
|
859
|
+
interface CreateWithdrawRequest {
|
|
860
|
+
/** Liquidium profile principal text. */
|
|
861
|
+
profileId: string;
|
|
862
|
+
/** Pool principal text to withdraw from. */
|
|
863
|
+
poolId: string;
|
|
864
|
+
/** Amount to withdraw in the pool asset's base units. */
|
|
865
|
+
amount: bigint;
|
|
866
|
+
/** External-chain address that receives the withdrawn asset. */
|
|
867
|
+
receiverAddress: string;
|
|
868
|
+
/** Wallet address that signs the withdraw authorization. */
|
|
869
|
+
signerWalletAddress: string;
|
|
870
|
+
}
|
|
871
|
+
/** Prepared withdraw request data embedded in the signable action. */
|
|
872
|
+
interface CreateWithdrawData extends CreateWithdrawRequest {
|
|
873
|
+
/** Expiry timestamp, in protocol nanoseconds, included in the signed message. */
|
|
874
|
+
expiryTimestamp: bigint;
|
|
875
|
+
}
|
|
876
|
+
/** Prepared action for creating a withdraw outflow. */
|
|
877
|
+
interface WithdrawAction extends SignMessageWalletAction<CreateWithdrawData, WithdrawOutflowDetails> {
|
|
878
|
+
/** Protocol action kind. */
|
|
879
|
+
kind: typeof WalletActionKind.createWithdraw;
|
|
880
|
+
/** Required wallet capability. */
|
|
881
|
+
executionKind: typeof WalletExecutionKind.signMessage;
|
|
882
|
+
/** Adapter-facing action type. */
|
|
883
|
+
actionType: typeof WalletActionKind.createWithdraw;
|
|
884
|
+
}
|
|
885
|
+
/** Supply execution plan selected by the SDK. */
|
|
886
|
+
declare const SupplyPlanType: {
|
|
887
|
+
readonly contractInteraction: "contractInteraction";
|
|
888
|
+
readonly transfer: "transfer";
|
|
889
|
+
};
|
|
890
|
+
/** Supply execution plan selected by the SDK. */
|
|
891
|
+
type SupplyPlanType = (typeof SupplyPlanType)[keyof typeof SupplyPlanType];
|
|
892
|
+
/** External-chain address target for manual or wallet-executed transfers. */
|
|
893
|
+
interface NativeAddressSupplyTarget {
|
|
894
|
+
/** Target discriminator. */
|
|
895
|
+
type: "nativeAddress";
|
|
896
|
+
/** Pool principal text receiving the inflow. */
|
|
897
|
+
poolId: string;
|
|
898
|
+
/** Asset expected by the target. */
|
|
899
|
+
asset: MarketAsset;
|
|
900
|
+
/** Chain where the target address is valid. */
|
|
901
|
+
chain: MarketChain;
|
|
902
|
+
/** Deposit or repayment action for the inflow. */
|
|
903
|
+
action: SupplyAction;
|
|
904
|
+
/** External-chain address where funds should be sent. */
|
|
905
|
+
address: string;
|
|
906
|
+
}
|
|
907
|
+
/** ICRC account target for ck-asset or contract-interaction inflows. */
|
|
908
|
+
interface IcrcAccountSupplyTarget {
|
|
909
|
+
/** Target discriminator. */
|
|
910
|
+
type: "icrcAccount";
|
|
911
|
+
/** Pool principal text receiving the inflow. */
|
|
912
|
+
poolId: string;
|
|
913
|
+
/** Asset expected by the target. */
|
|
914
|
+
asset: MarketAsset;
|
|
915
|
+
/** Chain associated with the inflow. */
|
|
916
|
+
chain: MarketChain;
|
|
917
|
+
/** Deposit or repayment action for the inflow. */
|
|
918
|
+
action: SupplyAction;
|
|
919
|
+
/** ICRC account owner principal text. */
|
|
920
|
+
owner: string;
|
|
921
|
+
/** ICRC subaccount bytes. */
|
|
922
|
+
subaccount: Uint8Array;
|
|
923
|
+
/** Text-encoded ICRC account. */
|
|
924
|
+
account: string;
|
|
925
|
+
}
|
|
926
|
+
/** Supply destination returned by `lending.supply(...)`. */
|
|
927
|
+
type SupplyTarget = NativeAddressSupplyTarget | IcrcAccountSupplyTarget;
|
|
928
|
+
interface BaseSupplyFlowRequest {
|
|
929
|
+
profileId: string;
|
|
930
|
+
poolId: string;
|
|
931
|
+
action: SupplyAction;
|
|
932
|
+
}
|
|
933
|
+
/** Manual transfer-based `lending.supply` request. */
|
|
934
|
+
interface ManualTransferSupplyFlowRequest extends BaseSupplyFlowRequest {
|
|
935
|
+
/** Optional explicit transfer mechanism. */
|
|
936
|
+
mechanism?: typeof SupplyPlanType.transfer;
|
|
937
|
+
/** Disallowed for manual transfer flows. */
|
|
938
|
+
walletAdapter?: never;
|
|
939
|
+
/** Disallowed for manual transfer flows. */
|
|
940
|
+
account?: never;
|
|
941
|
+
/** Disallowed for manual transfer flows. */
|
|
942
|
+
amount?: never;
|
|
943
|
+
}
|
|
944
|
+
/** Wallet-executed transfer-based `lending.supply` request. */
|
|
945
|
+
interface WalletTransferSupplyFlowRequest extends BaseSupplyFlowRequest {
|
|
946
|
+
/** Optional explicit transfer mechanism. */
|
|
947
|
+
mechanism?: typeof SupplyPlanType.transfer;
|
|
948
|
+
/** Wallet adapter used to broadcast the transfer. */
|
|
949
|
+
walletAdapter: Pick<WalletAdapter, "sendBtcTransaction" | "sendEthTransaction">;
|
|
950
|
+
/** Sender wallet account. */
|
|
951
|
+
account: string;
|
|
952
|
+
/** Transfer amount in the target asset's base units. */
|
|
953
|
+
amount: bigint;
|
|
954
|
+
}
|
|
955
|
+
/** Transfer-based supply request, either manual or wallet-executed. */
|
|
956
|
+
type TransferSupplyFlowRequest = ManualTransferSupplyFlowRequest | WalletTransferSupplyFlowRequest;
|
|
957
|
+
/** Input for contract-interaction `lending.supply`, which always executes now. */
|
|
958
|
+
interface ContractInteractionSupplyFlowRequest extends BaseSupplyFlowRequest {
|
|
959
|
+
/** Contract-interaction mechanism discriminator. */
|
|
960
|
+
mechanism: typeof SupplyPlanType.contractInteraction;
|
|
961
|
+
/** ETH wallet adapter used to approve and deposit ERC-20 assets. */
|
|
962
|
+
walletAdapter: Pick<WalletAdapter, "sendEthTransaction">;
|
|
963
|
+
/** Sender EVM wallet address. */
|
|
964
|
+
account: string;
|
|
965
|
+
/** Deposit or repayment amount in token base units. */
|
|
966
|
+
amount: bigint;
|
|
967
|
+
}
|
|
968
|
+
/** Request accepted by `lending.supply(...)`. */
|
|
969
|
+
type SupplyFlowRequest = TransferSupplyFlowRequest | ContractInteractionSupplyFlowRequest;
|
|
970
|
+
/**
|
|
971
|
+
* Supply receipt returned by `lending.supply(...)`.
|
|
972
|
+
*
|
|
973
|
+
* - `txid` is populated when the SDK broadcast the transaction on your behalf
|
|
974
|
+
* (wallet-adapter path). When undefined, the caller is expected to broadcast
|
|
975
|
+
* themselves and call {@link SupplyFlow.submit} for flows that require txid
|
|
976
|
+
* registration.
|
|
977
|
+
* - `submit` registers a broadcast txid with the SDK API when needed. ETH
|
|
978
|
+
* stablecoin deposit-address transfers are indexed from ERC-20 transfer logs,
|
|
979
|
+
* so `submit` acknowledges the txid without posting it to the inflow endpoint.
|
|
980
|
+
*
|
|
981
|
+
* The SDK does not poll inflow status. When you have a `txid`, it is your
|
|
982
|
+
* responsibility to track confirmation state with your own polling.
|
|
983
|
+
*/
|
|
984
|
+
interface SupplyFlow {
|
|
985
|
+
/** Execution plan used by the supply flow. */
|
|
986
|
+
type: SupplyPlanType;
|
|
987
|
+
/** Destination where funds should be sent or were sent. */
|
|
988
|
+
target: SupplyTarget;
|
|
989
|
+
/** Transaction id when the SDK broadcast the transaction. */
|
|
990
|
+
txid?: string;
|
|
991
|
+
/** Registers a broadcast transaction id when the flow requires an indexing hint. */
|
|
992
|
+
submit(request: SubmitInflowRequest): Promise<SubmitInflowResponse>;
|
|
993
|
+
}
|
|
994
|
+
/** Body for `SupplyFlow.submit` / `lending.submitInflow`. */
|
|
995
|
+
interface SubmitInflowRequest {
|
|
996
|
+
/** Broadcast transaction id or hash. */
|
|
997
|
+
txid: string;
|
|
998
|
+
/** Chain where the transaction was broadcast, when not implied by the flow. */
|
|
999
|
+
chain?: Chain;
|
|
1000
|
+
/** Deposit or repayment submit type, when not implied by the flow. */
|
|
1001
|
+
type?: InflowSubmitType;
|
|
1002
|
+
}
|
|
1003
|
+
/** Acknowledgement from the SDK API after submitting an inflow hint. */
|
|
1004
|
+
interface SubmitInflowResponse {
|
|
1005
|
+
/** Indicates the submit request was accepted by the SDK API. */
|
|
1006
|
+
success: true;
|
|
1007
|
+
/** Transaction id accepted by the SDK API. */
|
|
1008
|
+
txid: string;
|
|
1009
|
+
}
|
|
1010
|
+
/** Request for estimating the fee needed for an inflow target. */
|
|
1011
|
+
interface EstimateInflowFeeRequest {
|
|
1012
|
+
/** Asset to estimate for. */
|
|
1013
|
+
asset: Asset;
|
|
1014
|
+
/** Chain to estimate for. */
|
|
1015
|
+
chain: Chain;
|
|
1016
|
+
}
|
|
1017
|
+
/** Fee estimate for an inflow target. */
|
|
1018
|
+
interface InflowFeeEstimate {
|
|
1019
|
+
/** Estimated total fee in the asset's base units. */
|
|
1020
|
+
totalFee: bigint;
|
|
1021
|
+
}
|
|
1022
|
+
/** Request for ERC-20 approval and deposit planning. */
|
|
1023
|
+
interface GetEvmSupplyContextRequest {
|
|
1024
|
+
/** Liquidium profile principal text. */
|
|
1025
|
+
profileId: string;
|
|
1026
|
+
/** Pool principal text receiving the inflow. */
|
|
1027
|
+
poolId: string;
|
|
1028
|
+
/** EVM wallet address that will send funds. */
|
|
1029
|
+
walletAddress: string;
|
|
1030
|
+
/** Supply amount in token base units. */
|
|
1031
|
+
amount: bigint;
|
|
1032
|
+
/** Deposit or repayment action for the inflow. */
|
|
1033
|
+
action: SupplyAction;
|
|
1034
|
+
}
|
|
1035
|
+
/** Approval strategy required before an ERC-20 deposit contract call. */
|
|
1036
|
+
declare const EvmSupplyApprovalStrategy: {
|
|
1037
|
+
readonly approveMax: "approve-max";
|
|
1038
|
+
readonly none: "none";
|
|
1039
|
+
readonly resetThenApproveMax: "reset-then-approve-max";
|
|
1040
|
+
};
|
|
1041
|
+
/** Approval strategy required before an ERC-20 deposit contract call. */
|
|
1042
|
+
type EvmSupplyApprovalStrategy = (typeof EvmSupplyApprovalStrategy)[keyof typeof EvmSupplyApprovalStrategy];
|
|
1043
|
+
/** ERC-20 supply planning data returned by `lending.getEvmSupplyContext(...)`. */
|
|
1044
|
+
interface EvmSupplyContext {
|
|
1045
|
+
/** Indicates the context was computed successfully. */
|
|
1046
|
+
success: true;
|
|
1047
|
+
/** Liquidium profile principal text. */
|
|
1048
|
+
profileId: string;
|
|
1049
|
+
/** Pool principal text receiving the inflow. */
|
|
1050
|
+
poolId: string;
|
|
1051
|
+
/** Normalized EVM wallet address. */
|
|
1052
|
+
walletAddress: string;
|
|
1053
|
+
/** Deposit or repayment action for the inflow. */
|
|
1054
|
+
action: SupplyAction;
|
|
1055
|
+
/** Supported ETH stablecoin asset. */
|
|
1056
|
+
asset: typeof Asset.USDC | typeof Asset.USDT;
|
|
1057
|
+
/** ETH chain discriminator. */
|
|
1058
|
+
chain: typeof Chain.ETH;
|
|
1059
|
+
/** Requested amount serialized in token base units. */
|
|
1060
|
+
amount: string;
|
|
1061
|
+
/** ERC-20 token contract address. */
|
|
1062
|
+
tokenAddress: string;
|
|
1063
|
+
/** Contract address that must be approved as spender. */
|
|
1064
|
+
spenderAddress: string;
|
|
1065
|
+
/** Deposit helper contract address. */
|
|
1066
|
+
depositContractAddress: string;
|
|
1067
|
+
/** Current token balance serialized in base units. */
|
|
1068
|
+
balance: string;
|
|
1069
|
+
/** Current allowance serialized in base units. */
|
|
1070
|
+
allowance: string;
|
|
1071
|
+
/** Whether an approval transaction is needed before deposit. */
|
|
1072
|
+
requiresApproval: boolean;
|
|
1073
|
+
/** Approval sequence the caller should perform. */
|
|
1074
|
+
approvalStrategy: EvmSupplyApprovalStrategy;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
type WalletExecutionParams = {
|
|
1078
|
+
signerChain: Chain;
|
|
1079
|
+
signerWalletAdapter: WalletAdapter;
|
|
1080
|
+
};
|
|
1081
|
+
/** Borrow, withdraw, supply, inflow reporting, and fee-estimation helpers. */
|
|
1082
|
+
declare class LendingModule {
|
|
1083
|
+
readonly canisterContext: CanisterContext;
|
|
1084
|
+
readonly apiClient: ApiClient | undefined;
|
|
1085
|
+
readonly evmReadClient: EvmReadClient | undefined;
|
|
1086
|
+
constructor(canisterContext: CanisterContext, apiClient: ApiClient | undefined, evmReadClient: EvmReadClient | undefined);
|
|
1087
|
+
/**
|
|
1088
|
+
* Prepares a withdraw action that can be signed and submitted later.
|
|
1089
|
+
*
|
|
1090
|
+
* Use this when you need explicit control over signing and submission.
|
|
1091
|
+
*
|
|
1092
|
+
* @param request - Profile, pool, amount (pool asset base units), outflow address, and signer wallet.
|
|
1093
|
+
* @returns A signable {@link WithdrawAction} with `submit` wired to the canister.
|
|
1094
|
+
*/
|
|
1095
|
+
prepareWithdraw(request: CreateWithdrawRequest): Promise<WithdrawAction>;
|
|
1096
|
+
private submitWithdraw;
|
|
1097
|
+
/**
|
|
1098
|
+
* Creates a withdraw outflow using the provided wallet adapter.
|
|
1099
|
+
*
|
|
1100
|
+
* This is the convenience form of `prepareWithdraw(...)` plus execution.
|
|
1101
|
+
*
|
|
1102
|
+
* @param params - Withdraw request fields plus `signerChain` and `signerWalletAdapter`.
|
|
1103
|
+
* @returns The canister {@link OutflowDetails} for the completed withdraw.
|
|
1104
|
+
*/
|
|
1105
|
+
withdraw(params: CreateWithdrawRequest & WalletExecutionParams): Promise<WithdrawOutflowDetails>;
|
|
1106
|
+
/**
|
|
1107
|
+
* Prepares a borrow action that can be signed and submitted later.
|
|
1108
|
+
*
|
|
1109
|
+
* Use this when you need explicit control over signing and submission.
|
|
1110
|
+
*
|
|
1111
|
+
* @param request - Profile, pool, amount (borrow asset base units), outflow address, and signer wallet.
|
|
1112
|
+
* @returns A signable {@link BorrowAction} with `submit` wired to the canister.
|
|
1113
|
+
*/
|
|
1114
|
+
prepareBorrow(request: CreateBorrowRequest): Promise<BorrowAction>;
|
|
1115
|
+
private submitBorrow;
|
|
1116
|
+
/**
|
|
1117
|
+
* Creates a borrow outflow using the provided wallet adapter.
|
|
1118
|
+
*
|
|
1119
|
+
* This is the convenience form of `prepareBorrow(...)` plus execution.
|
|
1120
|
+
*
|
|
1121
|
+
* @param params - Borrow request fields plus `signerChain` and `signerWalletAdapter`.
|
|
1122
|
+
* @returns The lending canister receipt as {@link OutflowDetails}.
|
|
1123
|
+
*
|
|
1124
|
+
* @remarks
|
|
1125
|
+
* `id` is always present. `txid` may be missing on the first response; the SDK does not
|
|
1126
|
+
* poll for it. Use history or app-level polling if you need the chain transaction id.
|
|
1127
|
+
*/
|
|
1128
|
+
borrow(params: CreateBorrowRequest & WalletExecutionParams): Promise<BorrowOutflowDetails>;
|
|
1129
|
+
/**
|
|
1130
|
+
* Resolves a supply target for a deposit or repayment and optionally broadcasts it.
|
|
1131
|
+
*
|
|
1132
|
+
* Transfer mode can return manual broadcast instructions when wallet fields are
|
|
1133
|
+
* omitted. Contract-interaction mode always requires `walletAdapter`, `account`,
|
|
1134
|
+
* and `amount` because it must prepare and submit approval/deposit calls.
|
|
1135
|
+
*
|
|
1136
|
+
* The SDK does not poll for inflow status. When a `txid` is returned, it is the
|
|
1137
|
+
* caller's responsibility to track confirmation state using their own polling.
|
|
1138
|
+
*
|
|
1139
|
+
* @returns A {@link SupplyFlow} receipt with `type`, `target`, `submit`, and
|
|
1140
|
+
* an optional `txid` present when the SDK broadcast for you.
|
|
1141
|
+
*/
|
|
1142
|
+
supply(request: SupplyFlowRequest): Promise<SupplyFlow>;
|
|
1143
|
+
/**
|
|
1144
|
+
* Fetches ERC-20 supply planning data with the configured EVM read client.
|
|
1145
|
+
*
|
|
1146
|
+
* Requires `evmRpcUrl` or `evmPublicClient` on the client. Used internally by
|
|
1147
|
+
* contract-interaction `supply`.
|
|
1148
|
+
*
|
|
1149
|
+
* @param request - Profile, pool, wallet, amount (token base units), and action.
|
|
1150
|
+
* @returns Locally computed {@link EvmSupplyContext} for approvals and deposit.
|
|
1151
|
+
*/
|
|
1152
|
+
getEvmSupplyContext(request: GetEvmSupplyContextRequest): Promise<EvmSupplyContext>;
|
|
1153
|
+
private getEvmSupplyContextForPool;
|
|
1154
|
+
/**
|
|
1155
|
+
* Returns the read-only deposit address for an ETH stablecoin inflow target.
|
|
1156
|
+
*
|
|
1157
|
+
* This is a query call that does not create or mutate state. Use it when you
|
|
1158
|
+
* need the deposit address without hitting the authorization-gated update path.
|
|
1159
|
+
*
|
|
1160
|
+
* @param request - Profile, pool, asset, and supply action.
|
|
1161
|
+
* @returns The EVM deposit address for the derived account.
|
|
1162
|
+
*/
|
|
1163
|
+
getDepositAddress(request: {
|
|
1164
|
+
profileId: string;
|
|
1165
|
+
poolId: string;
|
|
1166
|
+
asset: string;
|
|
1167
|
+
action: SupplyAction;
|
|
1168
|
+
}): Promise<string>;
|
|
1169
|
+
/**
|
|
1170
|
+
* Estimates the network/deposit fee for an inflow target.
|
|
1171
|
+
*
|
|
1172
|
+
* ETH stablecoin deposit-address estimates are served by the deposit-address
|
|
1173
|
+
* canister. BTC estimates are not exposed by this SDK yet and return zero.
|
|
1174
|
+
*
|
|
1175
|
+
* @param request - Asset and chain pair to estimate for.
|
|
1176
|
+
* @returns Total fee estimate in the asset's base units.
|
|
1177
|
+
*/
|
|
1178
|
+
estimateInflowFee(request: EstimateInflowFeeRequest): Promise<InflowFeeEstimate>;
|
|
1179
|
+
private sendAndSubmitNativeSupplyInflow;
|
|
1180
|
+
private submitSupplyFlowInflow;
|
|
1181
|
+
private executeContractSupply;
|
|
1182
|
+
private sendNativeSupplyTransaction;
|
|
1183
|
+
private submitInflowWithRetry;
|
|
1184
|
+
/**
|
|
1185
|
+
* Submits an inflow transaction id for faster indexing.
|
|
1186
|
+
*
|
|
1187
|
+
* Uses the Liquidium SDK API.
|
|
1188
|
+
*
|
|
1189
|
+
* @param request - Broadcast `txid` plus optional `chain` and inflow `type`.
|
|
1190
|
+
* @returns Acknowledgement including the submitted `txid`.
|
|
1191
|
+
*/
|
|
1192
|
+
submitInflow(request: SubmitInflowRequest): Promise<SubmitInflowResponse>;
|
|
1193
|
+
/**
|
|
1194
|
+
* Returns whether borrowing is currently disabled by the protocol.
|
|
1195
|
+
*
|
|
1196
|
+
* @returns `true` when the lending canister reports borrowing disabled.
|
|
1197
|
+
*/
|
|
1198
|
+
isBorrowingDisabled(): Promise<boolean>;
|
|
1199
|
+
private requireApi;
|
|
1200
|
+
private requireEvmReadClient;
|
|
1201
|
+
private getPoolById;
|
|
1202
|
+
private sendEthContractTransaction;
|
|
1203
|
+
private waitForExpectedAllowance;
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
/** Current protocol metadata and rate state for a lending pool. */
|
|
1207
|
+
interface Pool {
|
|
1208
|
+
/** Pool canister principal text. */
|
|
1209
|
+
id: string;
|
|
1210
|
+
/** Asset supplied to and borrowed from the pool. */
|
|
1211
|
+
asset: MarketAsset;
|
|
1212
|
+
/** Chain associated with the pool asset. */
|
|
1213
|
+
chain: MarketChain;
|
|
1214
|
+
/** Number of base-unit decimals for pool amounts. */
|
|
1215
|
+
decimals: bigint;
|
|
1216
|
+
/** Whether new pool activity is currently frozen. */
|
|
1217
|
+
frozen: boolean;
|
|
1218
|
+
/** Total supplied amount in base units. */
|
|
1219
|
+
totalSupply: bigint;
|
|
1220
|
+
/** Total borrowed amount in base units. */
|
|
1221
|
+
totalDebt: bigint;
|
|
1222
|
+
/** Currently available liquidity in base units. */
|
|
1223
|
+
availableLiquidity: bigint;
|
|
1224
|
+
/** Optional supply cap in base units. */
|
|
1225
|
+
supplyCap?: bigint;
|
|
1226
|
+
/** Optional borrow cap in base units. */
|
|
1227
|
+
borrowCap?: bigint;
|
|
1228
|
+
/** Maximum loan-to-value ratio, scaled by `rateDecimals`. */
|
|
1229
|
+
maxLtv: bigint;
|
|
1230
|
+
/** Liquidation threshold, scaled by `rateDecimals`. */
|
|
1231
|
+
liquidationThreshold: bigint;
|
|
1232
|
+
/** Liquidation bonus, scaled by `rateDecimals`. */
|
|
1233
|
+
liquidationBonus: bigint;
|
|
1234
|
+
/** Protocol liquidation fee, scaled by `rateDecimals`. */
|
|
1235
|
+
protocolLiquidationFee: bigint;
|
|
1236
|
+
/** Reserve factor, scaled by `rateDecimals`. */
|
|
1237
|
+
reserveFactor: bigint;
|
|
1238
|
+
/** Decimal scale used by rate and risk-ratio fields. */
|
|
1239
|
+
rateDecimals: bigint;
|
|
1240
|
+
/** Current supply APR, scaled by `rateDecimals`. */
|
|
1241
|
+
lendingRate: bigint;
|
|
1242
|
+
/** Current borrow APR, scaled by `rateDecimals`. */
|
|
1243
|
+
borrowingRate: bigint;
|
|
1244
|
+
/** Current pool utilization, scaled by `rateDecimals`. */
|
|
1245
|
+
utilizationRate: bigint;
|
|
1246
|
+
/** Base borrow rate, scaled by `rateDecimals`. */
|
|
1247
|
+
baseRate: bigint;
|
|
1248
|
+
/** Optimal utilization point, scaled by `rateDecimals`. */
|
|
1249
|
+
optimalUtilizationRate: bigint;
|
|
1250
|
+
/** Rate slope before optimal utilization, scaled by `rateDecimals`. */
|
|
1251
|
+
rateSlopeBefore: bigint;
|
|
1252
|
+
/** Rate slope after optimal utilization, scaled by `rateDecimals`. */
|
|
1253
|
+
rateSlopeAfter: bigint;
|
|
1254
|
+
/** Current lending index. */
|
|
1255
|
+
lendingIndex: bigint;
|
|
1256
|
+
/** Current borrow index. */
|
|
1257
|
+
borrowIndex: bigint;
|
|
1258
|
+
/** Whether borrowing the same asset as collateral is allowed. */
|
|
1259
|
+
sameAssetBorrowing: boolean;
|
|
1260
|
+
/** Last pool update timestamp when available. */
|
|
1261
|
+
lastUpdated?: bigint;
|
|
1262
|
+
}
|
|
1263
|
+
/** USD price map keyed by market asset symbol. */
|
|
1264
|
+
type AssetPrices = Record<string, number>;
|
|
1265
|
+
/** Asset and chain pair used to find a unique pool. */
|
|
1266
|
+
interface FindPoolQuery {
|
|
1267
|
+
/** Asset symbol to match. */
|
|
1268
|
+
asset: MarketAsset;
|
|
1269
|
+
/** Chain name to match. */
|
|
1270
|
+
chain: MarketChain;
|
|
1271
|
+
}
|
|
1272
|
+
/** Current borrow, lend, and utilization rates for a pool. */
|
|
1273
|
+
interface PoolRate {
|
|
1274
|
+
/** Decimal scale used by rate fields. */
|
|
1275
|
+
rateDecimals: bigint;
|
|
1276
|
+
/** Borrow APR scaled by `rateDecimals`. */
|
|
1277
|
+
borrowRate: bigint;
|
|
1278
|
+
/** Lend APR scaled by `rateDecimals`. */
|
|
1279
|
+
lendRate: bigint;
|
|
1280
|
+
/** Utilization rate scaled by `rateDecimals`. */
|
|
1281
|
+
utilizationRate: bigint;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
/** Pool metadata, prices, and current rate helpers. */
|
|
1285
|
+
declare class MarketModule {
|
|
1286
|
+
readonly canisterContext: CanisterContext;
|
|
1287
|
+
readonly apiClient: ApiClient | undefined;
|
|
1288
|
+
constructor(canisterContext: CanisterContext, apiClient: ApiClient | undefined);
|
|
1289
|
+
/**
|
|
1290
|
+
* Lists all pools with their current rates.
|
|
1291
|
+
*
|
|
1292
|
+
* @returns All configured lending pools enriched with their current rate data.
|
|
1293
|
+
*/
|
|
1294
|
+
listPools(): Promise<Pool[]>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Returns the latest asset prices reported by the protocol.
|
|
1297
|
+
*
|
|
1298
|
+
* @returns The latest protocol price map keyed by market asset symbol.
|
|
1299
|
+
*/
|
|
1300
|
+
getAssetPrices(): Promise<AssetPrices>;
|
|
1301
|
+
/**
|
|
1302
|
+
* Resolves a single pool for the given asset and chain pair.
|
|
1303
|
+
*
|
|
1304
|
+
* @param query - The market asset and chain pair to match.
|
|
1305
|
+
* @returns The single pool that matches the requested asset and chain.
|
|
1306
|
+
*/
|
|
1307
|
+
findPool(query: FindPoolQuery): Promise<Pool>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Returns the full pool record for the given asset and chain pair.
|
|
1310
|
+
*
|
|
1311
|
+
* Convenience wrapper over {@link MarketModule.findPool}. `listPools()` already
|
|
1312
|
+
* enriches each pool with its current rate data, so no extra canister call is made.
|
|
1313
|
+
*
|
|
1314
|
+
* @param query - The market asset and chain pair to match.
|
|
1315
|
+
* @returns The matching pool enriched with current rate data.
|
|
1316
|
+
*/
|
|
1317
|
+
getReserveData(query: FindPoolQuery): Promise<Pool>;
|
|
1318
|
+
/**
|
|
1319
|
+
* Returns the current borrow, lend, and utilization rates for a pool.
|
|
1320
|
+
*
|
|
1321
|
+
* @param poolId - The pool principal text.
|
|
1322
|
+
* @returns The borrow, lend, and utilization rates for the requested pool.
|
|
1323
|
+
*/
|
|
1324
|
+
getPoolRate(poolId: string): Promise<PoolRate>;
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
/** Current profile position in one lending pool. */
|
|
1328
|
+
interface Position {
|
|
1329
|
+
/** Pool principal text. */
|
|
1330
|
+
poolId: string;
|
|
1331
|
+
/** Pool asset symbol. */
|
|
1332
|
+
asset: MarketAsset;
|
|
1333
|
+
/** Supplied principal in base units. */
|
|
1334
|
+
deposited: bigint;
|
|
1335
|
+
/** Decimal scale for supplied amounts. */
|
|
1336
|
+
depositedDecimals: bigint;
|
|
1337
|
+
/** Borrowed principal in base units. */
|
|
1338
|
+
borrowed: bigint;
|
|
1339
|
+
/** Decimal scale for borrowed amounts. */
|
|
1340
|
+
borrowedDecimals: bigint;
|
|
1341
|
+
/** Accrued supply interest in base units. */
|
|
1342
|
+
earnedInterest: bigint;
|
|
1343
|
+
/** Accrued borrow interest in base units. */
|
|
1344
|
+
debtInterest: bigint;
|
|
1345
|
+
/** Protocol timestamp of the last position update. */
|
|
1346
|
+
lastUpdate: bigint;
|
|
1347
|
+
}
|
|
1348
|
+
/** Aggregate borrowing capacity for a profile. */
|
|
1349
|
+
interface BorrowingPower {
|
|
1350
|
+
/** Weighted maximum LTV, scaled by protocol rate decimals. */
|
|
1351
|
+
weightedMaxLtv: bigint;
|
|
1352
|
+
/** Maximum borrowable USD value, scaled by `maxBorrowableUsdDecimals`. */
|
|
1353
|
+
maxBorrowableUsd: bigint;
|
|
1354
|
+
/** Decimal scale for `maxBorrowableUsd`. */
|
|
1355
|
+
maxBorrowableUsdDecimals: bigint;
|
|
1356
|
+
}
|
|
1357
|
+
/** Aggregate debt, collateral, and liquidation stats for a profile. */
|
|
1358
|
+
interface UserStats {
|
|
1359
|
+
/** Total debt value in USD-scaled units. */
|
|
1360
|
+
debt: bigint;
|
|
1361
|
+
/** Decimal scale for `debt`. */
|
|
1362
|
+
debtDecimals: bigint;
|
|
1363
|
+
/** Total collateral value in USD-scaled units. */
|
|
1364
|
+
collateral: bigint;
|
|
1365
|
+
/** Decimal scale for `collateral`. */
|
|
1366
|
+
collateralDecimals: bigint;
|
|
1367
|
+
/** Weighted liquidation threshold, scaled by protocol rate decimals. */
|
|
1368
|
+
weightedLiquidationThreshold: bigint;
|
|
1369
|
+
/** Current borrowing capacity. */
|
|
1370
|
+
borrowingPower: BorrowingPower;
|
|
1371
|
+
}
|
|
1372
|
+
/** Health factor and supporting aggregate stats for a profile. */
|
|
1373
|
+
interface HealthFactor {
|
|
1374
|
+
/** Current health factor, scaled by protocol rate decimals. */
|
|
1375
|
+
healthFactor: bigint;
|
|
1376
|
+
/** Aggregate stats used to derive the health factor. */
|
|
1377
|
+
userStats: UserStats;
|
|
1378
|
+
}
|
|
1379
|
+
/** Derived profile-level position summary for dashboards. */
|
|
1380
|
+
interface UserPositionSummary {
|
|
1381
|
+
/** Total collateral USD value. */
|
|
1382
|
+
totalCollateralUsd: bigint;
|
|
1383
|
+
/** Total debt USD value. */
|
|
1384
|
+
totalDebtUsd: bigint;
|
|
1385
|
+
/** Available borrow capacity in USD-scaled units. */
|
|
1386
|
+
availableBorrowsUsd: bigint;
|
|
1387
|
+
/** Collateral minus debt in USD-scaled units. */
|
|
1388
|
+
netWorthUsd: bigint;
|
|
1389
|
+
/** Decimal scale for USD fields. */
|
|
1390
|
+
usdDecimals: bigint;
|
|
1391
|
+
/** Current LTV in basis points. */
|
|
1392
|
+
currentLtvBps: bigint;
|
|
1393
|
+
/** Weighted maximum LTV in basis points. */
|
|
1394
|
+
weightedMaxLtvBps: bigint;
|
|
1395
|
+
/** Weighted liquidation threshold in basis points. */
|
|
1396
|
+
weightedLiquidationThresholdBps: bigint;
|
|
1397
|
+
/** Current health factor. */
|
|
1398
|
+
healthFactor: bigint;
|
|
1399
|
+
}
|
|
1400
|
+
/** Position joined with pool metadata and current USD valuation. */
|
|
1401
|
+
interface UserReserve {
|
|
1402
|
+
/** Position data for the pool. */
|
|
1403
|
+
position: Position;
|
|
1404
|
+
/** Pool metadata and rate data. */
|
|
1405
|
+
pool: Pool;
|
|
1406
|
+
/** Current USD price for the reserve asset. */
|
|
1407
|
+
priceUsd: number;
|
|
1408
|
+
/** Supplied value in USD-scaled units. */
|
|
1409
|
+
suppliedUsd: bigint;
|
|
1410
|
+
/** Borrowed value in USD-scaled units. */
|
|
1411
|
+
borrowedUsd: bigint;
|
|
1412
|
+
/** Decimal scale for USD fields. */
|
|
1413
|
+
usdDecimals: bigint;
|
|
1414
|
+
}
|
|
1415
|
+
/** Full repayment amount for a position, including any requested buffer. */
|
|
1416
|
+
interface MaxRepayAmount {
|
|
1417
|
+
/** Amount to repay in the borrowed asset's base units. */
|
|
1418
|
+
amount: bigint;
|
|
1419
|
+
/** Decimal scale for `amount`. */
|
|
1420
|
+
decimals: bigint;
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
/** Profile position, health factor, and reserve valuation helpers. */
|
|
1424
|
+
declare class PositionsModule {
|
|
1425
|
+
readonly canisterContext: CanisterContext;
|
|
1426
|
+
readonly market: MarketModule;
|
|
1427
|
+
constructor(canisterContext: CanisterContext, market: MarketModule);
|
|
1428
|
+
/**
|
|
1429
|
+
* Returns a single position for a profile and pool.
|
|
1430
|
+
*
|
|
1431
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1432
|
+
* @param poolId - The pool principal text.
|
|
1433
|
+
* @returns The position for the requested profile and pool, or `null` when no position exists.
|
|
1434
|
+
*/
|
|
1435
|
+
getPosition(profileId: string, poolId: string): Promise<Position | null>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Lists all positions for a profile.
|
|
1438
|
+
*
|
|
1439
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1440
|
+
* @returns All positions currently associated with the requested profile.
|
|
1441
|
+
*/
|
|
1442
|
+
listPositions(profileId: string): Promise<Position[]>;
|
|
1443
|
+
/**
|
|
1444
|
+
* Returns the current health factor for a profile.
|
|
1445
|
+
*
|
|
1446
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1447
|
+
* @returns The current health factor for the requested profile.
|
|
1448
|
+
*/
|
|
1449
|
+
getHealthFactor(profileId: string): Promise<HealthFactor>;
|
|
1450
|
+
/**
|
|
1451
|
+
* Returns aggregate borrowing and collateral stats for a profile.
|
|
1452
|
+
*
|
|
1453
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1454
|
+
* @returns Aggregate debt, collateral, and borrowing power metrics for the requested profile.
|
|
1455
|
+
*/
|
|
1456
|
+
getUserStats(profileId: string): Promise<UserStats>;
|
|
1457
|
+
/**
|
|
1458
|
+
* Returns an aggregate summary of a profile's position.
|
|
1459
|
+
*
|
|
1460
|
+
* Single canister round-trip (`get_health_factor`). Derived fields:
|
|
1461
|
+
* `availableBorrowsUsd = max(0, maxBorrowableUsd - debt)`,
|
|
1462
|
+
* `netWorthUsd = collateral - debt` (may be negative if underwater),
|
|
1463
|
+
* `currentLtvBps = debt * 10_000 / collateral` (0 when collateral is 0).
|
|
1464
|
+
*
|
|
1465
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1466
|
+
* @returns Derived position summary for the requested profile.
|
|
1467
|
+
*/
|
|
1468
|
+
getUserPositionSummary(profileId: string): Promise<UserPositionSummary>;
|
|
1469
|
+
/**
|
|
1470
|
+
* Returns the per-reserve breakdown of a profile's supplies and borrows,
|
|
1471
|
+
* joined with pool metadata, rates, and current USD prices.
|
|
1472
|
+
*
|
|
1473
|
+
* USD values are scaled to {@link USD_VALUE_SCALE_DECIMALS} (27).
|
|
1474
|
+
*
|
|
1475
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1476
|
+
* @returns Per-reserve position rows joined with pool metadata and USD values.
|
|
1477
|
+
*/
|
|
1478
|
+
getUserReserves(profileId: string): Promise<UserReserve[]>;
|
|
1479
|
+
/**
|
|
1480
|
+
* Returns the full repayment amount for a position, with a small buffer to
|
|
1481
|
+
* account for interest that accrues between quote and submit.
|
|
1482
|
+
*
|
|
1483
|
+
* @param profileId - The Liquidium profile principal text.
|
|
1484
|
+
* @param poolId - The pool principal text.
|
|
1485
|
+
* @param bufferBps - Optional buffer in basis points (default 10 = 0.1%).
|
|
1486
|
+
* @returns Buffered repayment amount in the borrowed asset's base units.
|
|
1487
|
+
*/
|
|
1488
|
+
getMaxRepayAmount(profileId: string, poolId: string, bufferBps?: bigint): Promise<MaxRepayAmount>;
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
/** Builds calldata for an ERC-20 `transfer(recipient, amount)` transaction. */
|
|
1492
|
+
declare function createTransferErc20Transaction(params: {
|
|
1493
|
+
tokenAddress: string;
|
|
1494
|
+
recipientAddress: string;
|
|
1495
|
+
amount: bigint;
|
|
1496
|
+
}): {
|
|
1497
|
+
to: string;
|
|
1498
|
+
data: string;
|
|
1499
|
+
};
|
|
1500
|
+
|
|
1501
|
+
/** Asset symbols supported by the instant-loans canister. */
|
|
1502
|
+
type InstantLoanAsset = "BTC" | "SOL" | "USDC" | "USDT";
|
|
1503
|
+
/** External chain account used for borrow delivery or collateral refunds. */
|
|
1504
|
+
interface ExternalAccount {
|
|
1505
|
+
/**
|
|
1506
|
+
* Account kind discriminator.
|
|
1507
|
+
*
|
|
1508
|
+
* Use `External` for addresses outside the IC, such as BTC, Solana, or EVM
|
|
1509
|
+
* addresses. Instant-loan creation currently accepts external destinations.
|
|
1510
|
+
*/
|
|
1511
|
+
type: "External";
|
|
1512
|
+
/**
|
|
1513
|
+
* Optional chain metadata for display and caller-side validation.
|
|
1514
|
+
*
|
|
1515
|
+
* The instant-loan API only sends `address` to the canister. Include `chain`
|
|
1516
|
+
* when your UI needs to remember which network the address belongs to.
|
|
1517
|
+
*/
|
|
1518
|
+
chain?: Chain | MarketChain;
|
|
1519
|
+
/**
|
|
1520
|
+
* Destination address on the external chain.
|
|
1521
|
+
*
|
|
1522
|
+
* For `borrowDestination`, this receives the borrowed asset. For
|
|
1523
|
+
* `refundDestination`, this receives collateral refunds or withdrawals.
|
|
1524
|
+
*/
|
|
1525
|
+
address: string;
|
|
1526
|
+
}
|
|
1527
|
+
/** IC principal account returned when a canister-native destination is used. */
|
|
1528
|
+
interface NativeAccount {
|
|
1529
|
+
/** Account kind discriminator. */
|
|
1530
|
+
type: "Native";
|
|
1531
|
+
/** Principal text for the canister-native account. */
|
|
1532
|
+
principal: string;
|
|
1533
|
+
}
|
|
1534
|
+
/** Borrow destination or refund account associated with an instant loan. */
|
|
1535
|
+
type InstantLoanAccount = ExternalAccount | NativeAccount;
|
|
1536
|
+
/**
|
|
1537
|
+
* Parameters for creating an accountless instant loan.
|
|
1538
|
+
*
|
|
1539
|
+
* Use market data from `client.market.listPools()` to choose the two pool ids,
|
|
1540
|
+
* and use `client.quote.calculateLtv(...)` before creation to validate the
|
|
1541
|
+
* amount pair and choose `ltvMaxBps`.
|
|
1542
|
+
*
|
|
1543
|
+
* Amount fields are in each asset's smallest/base units. For example, BTC uses
|
|
1544
|
+
* satoshis and ERC-20 assets use token base units according to the selected
|
|
1545
|
+
* pool decimals.
|
|
1546
|
+
*/
|
|
1547
|
+
interface CreateInstantLoanRequest {
|
|
1548
|
+
/**
|
|
1549
|
+
* Principal text of the pool that receives the user's collateral deposit.
|
|
1550
|
+
*
|
|
1551
|
+
* This should be the `id` of the collateral `Pool` selected from
|
|
1552
|
+
* `client.market.listPools()`. The pool asset must match `collateralAsset`.
|
|
1553
|
+
*/
|
|
1554
|
+
collateralPoolId: string;
|
|
1555
|
+
/**
|
|
1556
|
+
* Principal text of the pool that funds the borrow.
|
|
1557
|
+
*
|
|
1558
|
+
* This should be the `id` of the borrow `Pool` selected from
|
|
1559
|
+
* `client.market.listPools()`. The pool asset must match `borrowAsset`.
|
|
1560
|
+
*/
|
|
1561
|
+
borrowPoolId: string;
|
|
1562
|
+
/**
|
|
1563
|
+
* Asset the user will deposit as collateral.
|
|
1564
|
+
*
|
|
1565
|
+
* Must match the asset for `collateralPoolId`; for example, use `"BTC"` with
|
|
1566
|
+
* a BTC collateral pool.
|
|
1567
|
+
*/
|
|
1568
|
+
collateralAsset: InstantLoanAsset;
|
|
1569
|
+
/**
|
|
1570
|
+
* Asset the user wants to borrow from the borrow pool.
|
|
1571
|
+
*
|
|
1572
|
+
* Must match the asset for `borrowPoolId`; for example, use `"USDC"` with a
|
|
1573
|
+
* USDC borrow pool.
|
|
1574
|
+
*/
|
|
1575
|
+
borrowAsset: InstantLoanAsset;
|
|
1576
|
+
/**
|
|
1577
|
+
* Amount the user is expected to deposit as collateral, in base units.
|
|
1578
|
+
*
|
|
1579
|
+
* This is used to validate LTV and initialize the loan record. For BTC, pass
|
|
1580
|
+
* satoshis. For token assets, convert the UI amount using the selected pool's
|
|
1581
|
+
* `decimals` value.
|
|
1582
|
+
*/
|
|
1583
|
+
collateralAmount: bigint;
|
|
1584
|
+
/**
|
|
1585
|
+
* Amount to borrow, in the borrow asset's base units.
|
|
1586
|
+
*
|
|
1587
|
+
* For USDC/USDT, convert the UI amount using the selected borrow pool's
|
|
1588
|
+
* `decimals` value before passing it here.
|
|
1589
|
+
*/
|
|
1590
|
+
borrowAmount: bigint;
|
|
1591
|
+
/**
|
|
1592
|
+
* Maximum allowed loan-to-value ratio in basis points.
|
|
1593
|
+
*
|
|
1594
|
+
* `6_000n` means 60%. Use `client.quote.calculateLtv(...)` to calculate the
|
|
1595
|
+
* implied LTV for the selected amounts and pass the policy value your app is
|
|
1596
|
+
* willing to accept. Creation is rejected if the requested borrow would exceed
|
|
1597
|
+
* this limit.
|
|
1598
|
+
*/
|
|
1599
|
+
ltvMaxBps: bigint;
|
|
1600
|
+
/**
|
|
1601
|
+
* Seconds allowed for the user to send collateral after loan creation.
|
|
1602
|
+
*
|
|
1603
|
+
* If the collateral deposit is not detected before this window expires, the
|
|
1604
|
+
* instant-loan flow can time out. Internally this is sent to the canister as
|
|
1605
|
+
* `ltv_timer_s`.
|
|
1606
|
+
*/
|
|
1607
|
+
depositWindowSeconds: bigint;
|
|
1608
|
+
/**
|
|
1609
|
+
* External destination that receives the borrowed asset after the loan starts.
|
|
1610
|
+
*
|
|
1611
|
+
* Pass either an address string or `{ type: "External", address }`. This is
|
|
1612
|
+
* usually the user's wallet address on the borrow asset's chain, such as an
|
|
1613
|
+
* EVM address for ETH USDC/USDT outflows.
|
|
1614
|
+
*/
|
|
1615
|
+
borrowDestination: string | ExternalAccount;
|
|
1616
|
+
/**
|
|
1617
|
+
* External destination that receives collateral refunds or withdrawals.
|
|
1618
|
+
*
|
|
1619
|
+
* Pass either an address string or `{ type: "External", address }`. This
|
|
1620
|
+
* should be an address on the collateral asset's chain, such as a BTC address
|
|
1621
|
+
* when `collateralAsset` is `"BTC"`.
|
|
1622
|
+
*/
|
|
1623
|
+
refundDestination: string | ExternalAccount;
|
|
1624
|
+
}
|
|
1625
|
+
/** Lookup request for loading canonical instant-loan state. */
|
|
1626
|
+
type InstantLoanGetRequest = {
|
|
1627
|
+
loanId: bigint;
|
|
1628
|
+
} | {
|
|
1629
|
+
ref: string;
|
|
1630
|
+
};
|
|
1631
|
+
/** Page request for direct instant-loan canister event queries. */
|
|
1632
|
+
interface InstantLoanListEventsRequest {
|
|
1633
|
+
/** Event id to start from. */
|
|
1634
|
+
start: bigint;
|
|
1635
|
+
/** Maximum number of events to return. */
|
|
1636
|
+
limit: bigint;
|
|
1637
|
+
}
|
|
1638
|
+
/** Active instant-loans canister config. */
|
|
1639
|
+
interface InstantLoanConfig {
|
|
1640
|
+
/** Principal text of the lending canister used by instant loans. */
|
|
1641
|
+
lendingCanisterId: string;
|
|
1642
|
+
}
|
|
1643
|
+
/** Authentication metadata for warmed instant-loan profiles. */
|
|
1644
|
+
interface InstantLoanAuthorization {
|
|
1645
|
+
type: "EthSignature";
|
|
1646
|
+
derivationIndex: Uint8Array;
|
|
1647
|
+
publicKey: Uint8Array;
|
|
1648
|
+
address: string;
|
|
1649
|
+
}
|
|
1650
|
+
/** Warmed profile available for a future instant loan. */
|
|
1651
|
+
interface InstantLoanWarmedProfile {
|
|
1652
|
+
id: bigint;
|
|
1653
|
+
authorization: InstantLoanAuthorization;
|
|
1654
|
+
createdAt: bigint;
|
|
1655
|
+
profileId: string;
|
|
1656
|
+
}
|
|
1657
|
+
/** Direct canister event returned by the instant-loans query API. */
|
|
1658
|
+
interface InstantLoanEvent {
|
|
1659
|
+
id: bigint;
|
|
1660
|
+
schemaVersion: number;
|
|
1661
|
+
timestamp: bigint;
|
|
1662
|
+
eventType: InstantLoanEventType;
|
|
1663
|
+
}
|
|
1664
|
+
/** Instant-loan leg used when stuck funds are withdrawn. */
|
|
1665
|
+
type InstantLoanLeg = "Lend" | "Borrow";
|
|
1666
|
+
/** Direct canister event payload returned by instant-loans event queries. */
|
|
1667
|
+
type InstantLoanEventType = {
|
|
1668
|
+
type: "LoanCreated";
|
|
1669
|
+
loanId: bigint;
|
|
1670
|
+
borrowDestination: InstantLoanAccount;
|
|
1671
|
+
collateralAsset: InstantLoanAsset;
|
|
1672
|
+
borrowAmount: bigint;
|
|
1673
|
+
collateralPoolId: string;
|
|
1674
|
+
refundDestination: InstantLoanAccount;
|
|
1675
|
+
ltvMaxBps: bigint;
|
|
1676
|
+
depositWindowSeconds: bigint;
|
|
1677
|
+
profileId: string;
|
|
1678
|
+
borrowPoolId: string;
|
|
1679
|
+
borrowAsset: InstantLoanAsset;
|
|
1680
|
+
} | {
|
|
1681
|
+
type: "FullLendWithdrawalRequested";
|
|
1682
|
+
loanId: bigint;
|
|
1683
|
+
account: InstantLoanAccount;
|
|
1684
|
+
poolId: string;
|
|
1685
|
+
} | {
|
|
1686
|
+
type: "BorrowRequested";
|
|
1687
|
+
loanId: bigint;
|
|
1688
|
+
account: InstantLoanAccount;
|
|
1689
|
+
poolId: string;
|
|
1690
|
+
amount: bigint;
|
|
1691
|
+
} | {
|
|
1692
|
+
type: "DepositTimerExceeded";
|
|
1693
|
+
loanId: bigint;
|
|
1694
|
+
} | {
|
|
1695
|
+
type: "StuckFundsWithdrawalRequested";
|
|
1696
|
+
leg: InstantLoanLeg;
|
|
1697
|
+
loanId: bigint;
|
|
1698
|
+
account: InstantLoanAccount;
|
|
1699
|
+
poolId: string;
|
|
1700
|
+
amount: bigint;
|
|
1701
|
+
} | {
|
|
1702
|
+
type: "ProfileWarmed";
|
|
1703
|
+
derivationIndex: Uint8Array;
|
|
1704
|
+
warmedProfileId: bigint;
|
|
1705
|
+
ethAddress: string;
|
|
1706
|
+
profileId: string;
|
|
1707
|
+
} | {
|
|
1708
|
+
type: "RepayComplete";
|
|
1709
|
+
loanId: bigint;
|
|
1710
|
+
profileId: string;
|
|
1711
|
+
} | {
|
|
1712
|
+
type: "DepositTimerStarted";
|
|
1713
|
+
loanId: bigint;
|
|
1714
|
+
timestamp: bigint;
|
|
1715
|
+
};
|
|
1716
|
+
/** Current amount to send to the repayment target to close the debt. */
|
|
1717
|
+
interface InstantLoanRepayment {
|
|
1718
|
+
/** Full amount to send to the repayment target, including fee and interest buffer. */
|
|
1719
|
+
amount: bigint;
|
|
1720
|
+
/** Decimal scale for `amount`. */
|
|
1721
|
+
decimals: bigint;
|
|
1722
|
+
/** Current debt in base units, before fee and interest buffer. */
|
|
1723
|
+
debtAmount: bigint;
|
|
1724
|
+
/** Additional interest buffer in base units. */
|
|
1725
|
+
interestBufferAmount: bigint;
|
|
1726
|
+
/** Seconds of interest accrual included in `interestBufferAmount`. */
|
|
1727
|
+
interestBufferSeconds: bigint;
|
|
1728
|
+
/** Inflow fee amount in base units added to the repayment transfer. Falls back to the protocol minimum when live estimation is unavailable. */
|
|
1729
|
+
inflowFeeAmount: bigint;
|
|
1730
|
+
/** Whether `inflowFeeAmount` came from a live fee estimate. */
|
|
1731
|
+
inflowFeeEstimateAvailable: boolean;
|
|
1732
|
+
/** Asset to repay. */
|
|
1733
|
+
asset: MarketAsset;
|
|
1734
|
+
/** Chain used for repayment. */
|
|
1735
|
+
chain: MarketChain;
|
|
1736
|
+
/** Address or ICRC account where the repayment should be sent. */
|
|
1737
|
+
target: SupplyTarget;
|
|
1738
|
+
}
|
|
1739
|
+
/** Current lending position backing the instant loan. */
|
|
1740
|
+
interface InstantLoanPositionSummary {
|
|
1741
|
+
/** Current collateral amount in the collateral asset's base units. */
|
|
1742
|
+
collateralAmount: bigint;
|
|
1743
|
+
/** Decimal scale for `collateralAmount`. */
|
|
1744
|
+
collateralDecimals: bigint;
|
|
1745
|
+
/** Earned interest on the collateral side in base units. */
|
|
1746
|
+
collateralInterestAmount: bigint;
|
|
1747
|
+
/** Borrowed principal in the borrow asset's base units. */
|
|
1748
|
+
borrowedAmount: bigint;
|
|
1749
|
+
/** Decimal scale for borrowed/debt amounts. */
|
|
1750
|
+
borrowedDecimals: bigint;
|
|
1751
|
+
/** Accrued borrow interest in base units. */
|
|
1752
|
+
debtInterestAmount: bigint;
|
|
1753
|
+
/** Borrowed principal plus accrued interest in base units, before repayment buffer. */
|
|
1754
|
+
totalDebtAmount: bigint;
|
|
1755
|
+
}
|
|
1756
|
+
/** Simplified lifecycle status for consumer UIs. */
|
|
1757
|
+
declare const InstantLoanStatus: {
|
|
1758
|
+
readonly awaitingDeposit: "awaiting_deposit";
|
|
1759
|
+
readonly depositDetected: "deposit_detected";
|
|
1760
|
+
readonly active: "active";
|
|
1761
|
+
readonly settling: "settling";
|
|
1762
|
+
readonly closed: "closed";
|
|
1763
|
+
};
|
|
1764
|
+
type InstantLoanStatus = (typeof InstantLoanStatus)[keyof typeof InstantLoanStatus];
|
|
1765
|
+
/** Hydrated instant-loan state plus generated deposit and repayment targets. */
|
|
1766
|
+
interface InstantLoan {
|
|
1767
|
+
/** Canister-assigned loan id. */
|
|
1768
|
+
loanId: bigint;
|
|
1769
|
+
/** Short user-facing reference derived from `loanId`. */
|
|
1770
|
+
ref: string;
|
|
1771
|
+
/** Simplified lifecycle status for display and flow control. */
|
|
1772
|
+
status: InstantLoanStatus;
|
|
1773
|
+
/** Generated lending profile principal used by the instant loan. */
|
|
1774
|
+
profileId: string;
|
|
1775
|
+
/** Maximum loan-to-value ratio in basis points. */
|
|
1776
|
+
ltvMaxBps: bigint;
|
|
1777
|
+
/** Seconds allowed for the collateral deposit before timeout. */
|
|
1778
|
+
depositWindowSeconds: bigint;
|
|
1779
|
+
/** Collateral-side pool, asset, chain, and current or requested collateral amount. */
|
|
1780
|
+
collateral: {
|
|
1781
|
+
poolId: string;
|
|
1782
|
+
asset: MarketAsset;
|
|
1783
|
+
chain: MarketChain;
|
|
1784
|
+
amount: bigint;
|
|
1785
|
+
};
|
|
1786
|
+
/** Borrow-side pool, asset, chain, requested amount, and destination. */
|
|
1787
|
+
borrow: {
|
|
1788
|
+
poolId: string;
|
|
1789
|
+
asset: MarketAsset;
|
|
1790
|
+
chain: MarketChain;
|
|
1791
|
+
amount: bigint;
|
|
1792
|
+
destination: InstantLoanAccount;
|
|
1793
|
+
};
|
|
1794
|
+
/** Destination used for collateral refunds or withdrawals. */
|
|
1795
|
+
refundDestination: InstantLoanAccount;
|
|
1796
|
+
/** Address or ICRC account where the user deposits collateral. */
|
|
1797
|
+
depositTarget: SupplyTarget;
|
|
1798
|
+
/** Address or ICRC account where the user repays debt. */
|
|
1799
|
+
repayTarget: SupplyTarget;
|
|
1800
|
+
/** Current actionable repayment quote. */
|
|
1801
|
+
repayment: InstantLoanRepayment;
|
|
1802
|
+
/** Current lending position state for the generated profile. */
|
|
1803
|
+
position: InstantLoanPositionSummary;
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* Discovery result returned by address lookup.
|
|
1807
|
+
*
|
|
1808
|
+
* Candidates are intentionally lightweight; call `instantLoans.get(...)` with
|
|
1809
|
+
* `loanId` or `ref` to load canonical canister state and transfer targets.
|
|
1810
|
+
*/
|
|
1811
|
+
interface InstantLoanCandidate {
|
|
1812
|
+
/** Canister-assigned loan id. */
|
|
1813
|
+
loanId: bigint;
|
|
1814
|
+
/** Short user-facing reference derived from `loanId`. */
|
|
1815
|
+
ref: string;
|
|
1816
|
+
/** Generated lending profile principal used by the instant loan. */
|
|
1817
|
+
profileId: string;
|
|
1818
|
+
/** API-observed creation time, if provided by the indexer. */
|
|
1819
|
+
createdAt?: Date;
|
|
1820
|
+
/** Principal text of the collateral pool. */
|
|
1821
|
+
collateralPoolId: string;
|
|
1822
|
+
/** Principal text of the borrow pool. */
|
|
1823
|
+
borrowPoolId: string;
|
|
1824
|
+
/** Collateral asset symbol. */
|
|
1825
|
+
collateralAsset: MarketAsset;
|
|
1826
|
+
/** Borrow asset symbol. */
|
|
1827
|
+
borrowAsset: MarketAsset;
|
|
1828
|
+
/** Collateral amount hint in base units. */
|
|
1829
|
+
collateralAmountHint: bigint;
|
|
1830
|
+
}
|
|
1831
|
+
|
|
1832
|
+
/** Accountless instant-loan creation, lookup, recovery, and canister query helpers. */
|
|
1833
|
+
declare class InstantLoansModule {
|
|
1834
|
+
readonly canisterContext: CanisterContext;
|
|
1835
|
+
readonly apiClient: ApiClient | undefined;
|
|
1836
|
+
readonly lending: LendingModule;
|
|
1837
|
+
readonly positions: PositionsModule;
|
|
1838
|
+
constructor(canisterContext: CanisterContext, apiClient: ApiClient | undefined, lending: LendingModule, positions: PositionsModule);
|
|
1839
|
+
/**
|
|
1840
|
+
* Creates a profileless instant loan and returns canonical canister state plus
|
|
1841
|
+
* deposit/repay targets for the generated lending profile.
|
|
1842
|
+
*
|
|
1843
|
+
* Choose `collateralPoolId` and `borrowPoolId` from
|
|
1844
|
+
* `client.market.listPools()`, convert UI amounts to base units with the
|
|
1845
|
+
* selected pool decimals, and call `client.quote.calculateLtv(...)` before
|
|
1846
|
+
* creation to block invalid LTV input.
|
|
1847
|
+
*
|
|
1848
|
+
* `borrowDestination` receives the borrowed asset after the loan starts.
|
|
1849
|
+
* `refundDestination` receives collateral refunds or withdrawals. Use
|
|
1850
|
+
* `depositWindowSeconds` for the user-facing collateral deposit timeout; the
|
|
1851
|
+
* SDK maps it to the canister's internal `ltv_timer_s` field.
|
|
1852
|
+
*
|
|
1853
|
+
* @param request - Pool ids, assets, base-unit amounts, LTV limit, timeout, and destinations.
|
|
1854
|
+
* @returns Hydrated loan state plus generated deposit and repayment targets.
|
|
1855
|
+
*/
|
|
1856
|
+
create(request: CreateInstantLoanRequest): Promise<InstantLoan>;
|
|
1857
|
+
/**
|
|
1858
|
+
* Resolves canonical canister state by loan id or short reference.
|
|
1859
|
+
*
|
|
1860
|
+
* References are decoded locally, then the corresponding loan id is loaded
|
|
1861
|
+
* from the instant-loans canister.
|
|
1862
|
+
*
|
|
1863
|
+
* @param request - Canister loan id or short public reference.
|
|
1864
|
+
* @returns Hydrated loan state plus generated deposit and repayment targets.
|
|
1865
|
+
*/
|
|
1866
|
+
get(request: InstantLoanGetRequest): Promise<InstantLoan>;
|
|
1867
|
+
/**
|
|
1868
|
+
* Returns the active instant-loans canister config via direct query.
|
|
1869
|
+
*
|
|
1870
|
+
* @returns Active canister configuration.
|
|
1871
|
+
*/
|
|
1872
|
+
getConfig(): Promise<InstantLoanConfig>;
|
|
1873
|
+
/**
|
|
1874
|
+
* Returns a single canister event by id via direct query.
|
|
1875
|
+
*
|
|
1876
|
+
* @param eventId - Event id to load.
|
|
1877
|
+
* @returns The event when found, otherwise `null`.
|
|
1878
|
+
*/
|
|
1879
|
+
getEvent(eventId: bigint): Promise<InstantLoanEvent | null>;
|
|
1880
|
+
/**
|
|
1881
|
+
* Returns a page of canister events via direct query.
|
|
1882
|
+
*
|
|
1883
|
+
* @param request - Start event id and maximum number of events to return.
|
|
1884
|
+
* @returns Canister events in ascending id order.
|
|
1885
|
+
*/
|
|
1886
|
+
listEvents(request: InstantLoanListEventsRequest): Promise<InstantLoanEvent[]>;
|
|
1887
|
+
/**
|
|
1888
|
+
* Returns principals authorized for protected update callbacks.
|
|
1889
|
+
*
|
|
1890
|
+
* @returns Principal text values on the canister access list.
|
|
1891
|
+
*/
|
|
1892
|
+
listAccessList(): Promise<string[]>;
|
|
1893
|
+
/**
|
|
1894
|
+
* Returns the current size of the warmed-profile pool via direct query.
|
|
1895
|
+
*
|
|
1896
|
+
* @returns Number of warmed profiles available on the canister.
|
|
1897
|
+
*/
|
|
1898
|
+
countWarmedProfiles(): Promise<bigint>;
|
|
1899
|
+
/**
|
|
1900
|
+
* Returns warmed profiles currently available for future instant loans.
|
|
1901
|
+
*
|
|
1902
|
+
* @returns Warmed profile records available for assignment.
|
|
1903
|
+
*/
|
|
1904
|
+
listWarmedProfiles(): Promise<InstantLoanWarmedProfile[]>;
|
|
1905
|
+
/**
|
|
1906
|
+
* Finds candidate loans associated with an address through the Liquidium SDK
|
|
1907
|
+
* API. Returns discovery candidates only; call `get(...)` to hydrate canister state.
|
|
1908
|
+
*
|
|
1909
|
+
* Candidates are useful for recovery flows where the user knows a borrow or
|
|
1910
|
+
* refund address but not the loan reference.
|
|
1911
|
+
*
|
|
1912
|
+
* @param address - Borrow or refund address to search for.
|
|
1913
|
+
* @returns Lightweight loan candidates associated with the address.
|
|
1914
|
+
*/
|
|
1915
|
+
findByAddress(address: string): Promise<InstantLoanCandidate[]>;
|
|
1916
|
+
private mapLoanRecord;
|
|
1917
|
+
private mapLoanWire;
|
|
1918
|
+
private hydrateLoan;
|
|
1919
|
+
private estimateRepaymentInflowFee;
|
|
1920
|
+
private requireApi;
|
|
1921
|
+
private validateInstantLoanLtvPolicy;
|
|
1922
|
+
private calculateInstantLoanLtv;
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
/**
|
|
1926
|
+
* Converts a canister loan id into a short user-facing reference.
|
|
1927
|
+
*
|
|
1928
|
+
* @param id - Canister loan id in the supported public-reference range.
|
|
1929
|
+
* @returns Fixed-length public reference string.
|
|
1930
|
+
*/
|
|
1931
|
+
declare function publicIdFromInt(id: bigint): string;
|
|
1932
|
+
/**
|
|
1933
|
+
* Decodes a short user-facing reference back into the canister loan id.
|
|
1934
|
+
*
|
|
1935
|
+
* @param ref - Fixed-length public reference string.
|
|
1936
|
+
* @returns Canister loan id represented by the reference.
|
|
1937
|
+
*/
|
|
1938
|
+
declare function intFromPublicId(ref: string): bigint;
|
|
1939
|
+
|
|
1940
|
+
/** Input for calculating required collateral from a target LTV. */
|
|
1941
|
+
interface QuoteRequest {
|
|
1942
|
+
/** Requested borrow amount in borrow asset base units. */
|
|
1943
|
+
borrowAmount: bigint;
|
|
1944
|
+
/** Pool principal text for the borrow side. */
|
|
1945
|
+
borrowPoolId: string;
|
|
1946
|
+
/** Pool principal text for the collateral side. */
|
|
1947
|
+
collateralPoolId: string;
|
|
1948
|
+
/** Target loan-to-value ratio in basis points. */
|
|
1949
|
+
targetLtvBps: bigint;
|
|
1950
|
+
}
|
|
1951
|
+
/** Input for calculating LTV from explicit borrow and collateral amounts. */
|
|
1952
|
+
interface CalculateLtvRequest {
|
|
1953
|
+
/** Requested borrow amount in borrow asset base units. */
|
|
1954
|
+
borrowAmount: bigint;
|
|
1955
|
+
/** Pool principal text for the borrow side. */
|
|
1956
|
+
borrowPoolId: string;
|
|
1957
|
+
/** Collateral amount in collateral asset base units. */
|
|
1958
|
+
collateralAmount: bigint;
|
|
1959
|
+
/** Pool principal text for the collateral side. */
|
|
1960
|
+
collateralPoolId: string;
|
|
1961
|
+
}
|
|
1962
|
+
/** Validation error produced by quote helpers. */
|
|
1963
|
+
interface QuoteValidationError {
|
|
1964
|
+
/** Stable machine-readable validation code. */
|
|
1965
|
+
code: QuoteValidationErrorCode;
|
|
1966
|
+
/** Human-readable validation message. */
|
|
1967
|
+
message: string;
|
|
1968
|
+
}
|
|
1969
|
+
/** Stable validation codes produced by quote helpers. */
|
|
1970
|
+
declare enum QuoteValidationErrorCode {
|
|
1971
|
+
INVALID_LTV = "INVALID_LTV",
|
|
1972
|
+
LTV_EXCEEDS_MAX = "LTV_EXCEEDS_MAX",
|
|
1973
|
+
SAME_ASSET_NOT_ALLOWED = "SAME_ASSET_NOT_ALLOWED",
|
|
1974
|
+
BORROW_AMOUNT_TOO_LOW = "BORROW_AMOUNT_TOO_LOW",
|
|
1975
|
+
PRICE_NOT_AVAILABLE = "PRICE_NOT_AVAILABLE",
|
|
1976
|
+
POOL_NOT_FOUND = "POOL_NOT_FOUND",
|
|
1977
|
+
UNKNOWN = "UNKNOWN"
|
|
1978
|
+
}
|
|
1979
|
+
/** Non-blocking warning produced by quote helpers. */
|
|
1980
|
+
interface QuoteWarning {
|
|
1981
|
+
/** Stable machine-readable warning code. */
|
|
1982
|
+
code: QuoteWarningCode;
|
|
1983
|
+
/** Human-readable warning message. */
|
|
1984
|
+
message: string;
|
|
1985
|
+
}
|
|
1986
|
+
/** Stable warning codes produced by quote helpers. */
|
|
1987
|
+
declare enum QuoteWarningCode {
|
|
1988
|
+
HIGH_LTV = "HIGH_LTV",
|
|
1989
|
+
SAME_ASSET_BORROWING = "SAME_ASSET_BORROWING"
|
|
1990
|
+
}
|
|
1991
|
+
/** Quote result for a requested borrow amount and target LTV. */
|
|
1992
|
+
interface QuoteResult {
|
|
1993
|
+
/** Requested borrow amount in borrow asset base units. */
|
|
1994
|
+
borrowAmount: bigint;
|
|
1995
|
+
/** Borrow value in internal USD units. */
|
|
1996
|
+
borrowUsd: bigint;
|
|
1997
|
+
/** Required collateral amount in collateral asset base units. */
|
|
1998
|
+
requiredCollateralAmount: bigint;
|
|
1999
|
+
/** Required collateral value in internal USD units. */
|
|
2000
|
+
requiredCollateralUsd: bigint;
|
|
2001
|
+
/** Maximum allowed LTV in basis points for the collateral pool. */
|
|
2002
|
+
maxAllowedLtvBps: bigint;
|
|
2003
|
+
/** Requested target LTV in basis points. */
|
|
2004
|
+
targetLtvBps: bigint;
|
|
2005
|
+
/** Pool principal text for the borrow side. */
|
|
2006
|
+
borrowPoolId: string;
|
|
2007
|
+
/** Pool principal text for the collateral side. */
|
|
2008
|
+
collateralPoolId: string;
|
|
2009
|
+
/** Borrow asset symbol. */
|
|
2010
|
+
borrowAsset: string;
|
|
2011
|
+
/** Collateral asset symbol. */
|
|
2012
|
+
collateralAsset: string;
|
|
2013
|
+
/** Blocking validation errors. Empty when the quote is usable. */
|
|
2014
|
+
validationErrors: QuoteValidationError[];
|
|
2015
|
+
/** Non-blocking quote warnings. */
|
|
2016
|
+
warnings: QuoteWarning[];
|
|
2017
|
+
}
|
|
2018
|
+
/** LTV calculation result for explicit borrow and collateral amounts. */
|
|
2019
|
+
interface LtvCalculation {
|
|
2020
|
+
/** Requested borrow amount in borrow asset base units. */
|
|
2021
|
+
borrowAmount: bigint;
|
|
2022
|
+
/** Collateral amount in collateral asset base units. */
|
|
2023
|
+
collateralAmount: bigint;
|
|
2024
|
+
/** Borrow value in internal USD units. */
|
|
2025
|
+
borrowUsd: bigint;
|
|
2026
|
+
/** Collateral value in internal USD units. */
|
|
2027
|
+
collateralUsd: bigint;
|
|
2028
|
+
/** Computed LTV in basis points. */
|
|
2029
|
+
ltvBps: bigint;
|
|
2030
|
+
/** Maximum allowed LTV in basis points for the collateral pool. */
|
|
2031
|
+
maxAllowedLtvBps: bigint;
|
|
2032
|
+
/** Pool principal text for the borrow side. */
|
|
2033
|
+
borrowPoolId: string;
|
|
2034
|
+
/** Pool principal text for the collateral side. */
|
|
2035
|
+
collateralPoolId: string;
|
|
2036
|
+
/** Borrow asset symbol. */
|
|
2037
|
+
borrowAsset: string;
|
|
2038
|
+
/** Collateral asset symbol. */
|
|
2039
|
+
collateralAsset: string;
|
|
2040
|
+
/** Blocking validation errors. Empty when the calculation is usable. */
|
|
2041
|
+
validationErrors: QuoteValidationError[];
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
/** Pure quote helpers for LTV and required-collateral calculations. */
|
|
2045
|
+
declare class QuoteModule {
|
|
2046
|
+
/**
|
|
2047
|
+
* Calculates current LTV from caller-supplied borrow and collateral amounts.
|
|
2048
|
+
*
|
|
2049
|
+
* Amount fields are base units. USD fields are scaled to 8 decimal places.
|
|
2050
|
+
*
|
|
2051
|
+
* @param request - Borrow and collateral pool ids plus base-unit amounts.
|
|
2052
|
+
* @param pools - Available pools, usually from `client.market.listPools()`.
|
|
2053
|
+
* @param prices - USD price map, usually from `client.market.getAssetPrices()`.
|
|
2054
|
+
* @returns LTV calculation plus validation errors when inputs are unusable.
|
|
2055
|
+
*/
|
|
2056
|
+
calculateLtv(request: CalculateLtvRequest, pools: Pool[], prices: AssetPrices): LtvCalculation;
|
|
2057
|
+
/**
|
|
2058
|
+
* Calculates a loan quote based on borrow amount, LTV, and pool selections.
|
|
2059
|
+
*
|
|
2060
|
+
* All arithmetic is performed in bigint. `requiredCollateralAmount` and
|
|
2061
|
+
* `requiredCollateralUsd` are rounded UP so the caller never under-collateralizes
|
|
2062
|
+
* due to integer truncation. `borrowUsd` is floored for display.
|
|
2063
|
+
*
|
|
2064
|
+
* @param request - Quote request parameters.
|
|
2065
|
+
* @param pools - All available pools (use MarketModule.listPools() to fetch).
|
|
2066
|
+
* @param prices - Asset prices in USD (use MarketModule.getAssetPrices() to fetch).
|
|
2067
|
+
* @returns Quote result with required collateral and validation state.
|
|
2068
|
+
*/
|
|
2069
|
+
getQuote(request: QuoteRequest, pools: Pool[], prices: AssetPrices): QuoteResult;
|
|
2070
|
+
}
|
|
2071
|
+
|
|
2072
|
+
/**
|
|
2073
|
+
* Root client for Liquidium protocol integration (canister + optional HTTP API).
|
|
2074
|
+
*
|
|
2075
|
+
* Construct with `new LiquidiumClient(config)`.
|
|
2076
|
+
*/
|
|
2077
|
+
declare class LiquidiumClient {
|
|
2078
|
+
/** Profile lifecycle: create, resolve, linked wallets. */
|
|
2079
|
+
readonly accounts: AccountsModule;
|
|
2080
|
+
/** Borrow, withdraw, supply, inflow reporting and tracking. */
|
|
2081
|
+
readonly lending: LendingModule;
|
|
2082
|
+
/** Per-pool positions, health, aggregate stats. */
|
|
2083
|
+
readonly positions: PositionsModule;
|
|
2084
|
+
/** Pool list, prices, pool rate lookups. */
|
|
2085
|
+
readonly market: MarketModule;
|
|
2086
|
+
/** Receipt-oriented activity status and activity lists. */
|
|
2087
|
+
readonly activities: ActivitiesModule;
|
|
2088
|
+
/** Pool and user history through the Liquidium SDK API. */
|
|
2089
|
+
readonly history: HistoryModule;
|
|
2090
|
+
/** Accountless instant loans backed by generated deposit/repay targets. */
|
|
2091
|
+
readonly instantLoans: InstantLoansModule;
|
|
2092
|
+
/** Pure quote helpers from market inputs. */
|
|
2093
|
+
readonly quote: QuoteModule;
|
|
2094
|
+
private readonly canisterContext;
|
|
2095
|
+
private readonly apiClient;
|
|
2096
|
+
private readonly evmReadClient;
|
|
2097
|
+
/**
|
|
2098
|
+
* Creates a Liquidium SDK client.
|
|
2099
|
+
*
|
|
2100
|
+
* @param config - Runtime transport, canister, API, identity, and EVM read options.
|
|
2101
|
+
*/
|
|
2102
|
+
constructor(config?: LiquidiumClientConfig);
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
/**
|
|
2106
|
+
* Stable string codes for {@link LiquidiumError}. Use for branching in application code.
|
|
2107
|
+
*/
|
|
2108
|
+
declare const LiquidiumErrorCode: {
|
|
2109
|
+
readonly INVALID_TARGET_PRINCIPAL: "INVALID_TARGET_PRINCIPAL";
|
|
2110
|
+
readonly INSUFFICIENT_COLLATERAL: "INSUFFICIENT_COLLATERAL";
|
|
2111
|
+
readonly SIGNATURE_EXPIRY_TOO_FAR_IN_FUTURE: "SIGNATURE_EXPIRY_TOO_FAR_IN_FUTURE";
|
|
2112
|
+
readonly MAX_LTV_EXCEEDED: "MAX_LTV_EXCEEDED";
|
|
2113
|
+
readonly SIGNATURE_EXPIRED: "SIGNATURE_EXPIRED";
|
|
2114
|
+
readonly ACCOUNT_ALREADY_LINKED: "ACCOUNT_ALREADY_LINKED";
|
|
2115
|
+
readonly ACCOUNT_NOT_FOUND: "ACCOUNT_NOT_FOUND";
|
|
2116
|
+
readonly CANNOT_REMOVE_SOLE_ACCOUNT: "CANNOT_REMOVE_SOLE_ACCOUNT";
|
|
2117
|
+
readonly PROFILE_NOT_FOUND: "PROFILE_NOT_FOUND";
|
|
2118
|
+
readonly PROFILE_ALREADY_EXISTS: "PROFILE_ALREADY_EXISTS";
|
|
2119
|
+
readonly SIGNATURE_ERROR: "SIGNATURE_ERROR";
|
|
2120
|
+
readonly POOL_NOT_FOUND: "POOL_NOT_FOUND";
|
|
2121
|
+
readonly POOL_FROZEN: "POOL_FROZEN";
|
|
2122
|
+
readonly POSITION_NOT_FOUND: "POSITION_NOT_FOUND";
|
|
2123
|
+
readonly BORROW_CAP_EXCEEDED: "BORROW_CAP_EXCEEDED";
|
|
2124
|
+
readonly SUPPLY_CAP_EXCEEDED: "SUPPLY_CAP_EXCEEDED";
|
|
2125
|
+
readonly INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS";
|
|
2126
|
+
readonly HEALTH_FACTOR_TOO_LOW: "HEALTH_FACTOR_TOO_LOW";
|
|
2127
|
+
readonly TRANSFER_FAILED: "TRANSFER_FAILED";
|
|
2128
|
+
readonly LIQUIDATION_NOT_FOUND: "LIQUIDATION_NOT_FOUND";
|
|
2129
|
+
readonly BORROWING_DISABLED: "BORROWING_DISABLED";
|
|
2130
|
+
readonly NO_LIQUIDITY: "NO_LIQUIDITY";
|
|
2131
|
+
readonly NOT_ALLOWED: "NOT_ALLOWED";
|
|
2132
|
+
readonly INVALID_ETH_SIGNATURE: "INVALID_ETH_SIGNATURE";
|
|
2133
|
+
readonly INVALID_BTC_SIGNATURE: "INVALID_BTC_SIGNATURE";
|
|
2134
|
+
readonly INVALID_ETH_ADDRESS: "INVALID_ETH_ADDRESS";
|
|
2135
|
+
readonly UNSUPPORTED_CHAIN: "UNSUPPORTED_CHAIN";
|
|
2136
|
+
readonly WITHDRAW_TOO_LOW: "WITHDRAW_TOO_LOW";
|
|
2137
|
+
readonly REPAYMENT_EXCEEDS_DEBT: "REPAYMENT_EXCEEDS_DEBT";
|
|
2138
|
+
readonly INVALID_ADDRESS: "INVALID_ADDRESS";
|
|
2139
|
+
readonly DEPOSIT_ADDRESS_ERROR: "DEPOSIT_ADDRESS_ERROR";
|
|
2140
|
+
readonly NETWORK_ERROR: "NETWORK_ERROR";
|
|
2141
|
+
readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
|
|
2142
|
+
readonly REQUEST_TIMEOUT: "REQUEST_TIMEOUT";
|
|
2143
|
+
readonly CANISTER_REJECTED: "CANISTER_REJECTED";
|
|
2144
|
+
readonly INTERNAL: "INTERNAL";
|
|
2145
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
2146
|
+
};
|
|
2147
|
+
type LiquidiumErrorCode = (typeof LiquidiumErrorCode)[keyof typeof LiquidiumErrorCode];
|
|
2148
|
+
/** Optional debug identifiers attached to mapped SDK errors. */
|
|
2149
|
+
interface LiquidiumErrorContext {
|
|
2150
|
+
/** Backend trace id for support/debugging when available. */
|
|
2151
|
+
traceId?: string;
|
|
2152
|
+
/** SDK API request id for support/debugging when available. */
|
|
2153
|
+
requestId?: string;
|
|
2154
|
+
}
|
|
2155
|
+
/**
|
|
2156
|
+
* Typed error from the SDK or mapped protocol failures.
|
|
2157
|
+
*
|
|
2158
|
+
* Prefer checking `code` over parsing `message`.
|
|
2159
|
+
*/
|
|
2160
|
+
declare class LiquidiumError extends Error {
|
|
2161
|
+
/** Machine-readable reason; compare to {@link LiquidiumErrorCode} values. */
|
|
2162
|
+
readonly code: LiquidiumErrorCode;
|
|
2163
|
+
/** Original error when the SDK wraps an underlying failure. */
|
|
2164
|
+
readonly cause?: unknown;
|
|
2165
|
+
/** Backend trace id for support/debugging when available. */
|
|
2166
|
+
readonly traceId?: string;
|
|
2167
|
+
/** SDK API request id for support/debugging when available. */
|
|
2168
|
+
readonly requestId?: string;
|
|
2169
|
+
/**
|
|
2170
|
+
* @param code - Error code from {@link LiquidiumErrorCode}.
|
|
2171
|
+
* @param message - Human-readable detail (defaults to `code` when omitted).
|
|
2172
|
+
* @param cause - Optional underlying error.
|
|
2173
|
+
* @param context - Optional backend debug identifiers.
|
|
2174
|
+
*/
|
|
2175
|
+
constructor(code: LiquidiumErrorCode, message?: string, cause?: unknown, context?: LiquidiumErrorContext);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
/** Ethereum mainnet USDC contract address. */
|
|
2179
|
+
declare const USDC_CONTRACT_ADDRESS = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
|
|
2180
|
+
/** Ethereum mainnet USDT contract address. */
|
|
2181
|
+
declare const USDT_CONTRACT_ADDRESS = "0xdac17f958d2ee523a2206206994597c13d831ec7";
|
|
2182
|
+
/** Ethereum mainnet ckETH minter ERC-20 deposit helper contract address. */
|
|
2183
|
+
declare const CK_ETH_DEPOSIT_CONTRACT_ADDRESS = "0x18901044688D3756C35Ed2b36D93e6a5B8e00E68";
|
|
2184
|
+
|
|
2185
|
+
/** Fixed-point scale used by protocol rate values. */
|
|
2186
|
+
declare const RATE_SCALE = 1000000000000000000000000000n;
|
|
2187
|
+
/** Number of decimal places represented by {@link RATE_SCALE}. */
|
|
2188
|
+
declare const RATE_DECIMALS: bigint;
|
|
2189
|
+
|
|
2190
|
+
/**
|
|
2191
|
+
* Wallet wiring for {@link executeWith}.
|
|
2192
|
+
*
|
|
2193
|
+
* `chain` and `account` override values embedded on the action when present;
|
|
2194
|
+
* message signing uses `options.account ?? action.account`.
|
|
2195
|
+
*/
|
|
2196
|
+
interface ExecuteWithOptions {
|
|
2197
|
+
/** Must expose the methods required by the action's `executionKind`. */
|
|
2198
|
+
walletAdapter: WalletAdapter;
|
|
2199
|
+
/** Required for `sign-message` actions; forwarded to the adapter and submit payload. */
|
|
2200
|
+
chain?: Chain;
|
|
2201
|
+
/** Optional signing/sending account override. */
|
|
2202
|
+
account?: string;
|
|
2203
|
+
}
|
|
2204
|
+
/**
|
|
2205
|
+
* Returns an async function that runs a {@link WalletAction} end-to-end.
|
|
2206
|
+
*
|
|
2207
|
+
* - `sign-message`: needs `walletAdapter.signMessage` and `options.chain`.
|
|
2208
|
+
* - `sign-psbt`: needs `walletAdapter.signPsbt`.
|
|
2209
|
+
* - `send-eth-transaction`: needs `walletAdapter.sendEthTransaction`.
|
|
2210
|
+
*
|
|
2211
|
+
* @param options - Adapter and optional chain/account overrides.
|
|
2212
|
+
* @returns A function that accepts a `WalletAction` and resolves with its submit result.
|
|
2213
|
+
*/
|
|
2214
|
+
declare function executeWith(options: ExecuteWithOptions): <TResult>(action: WalletAction<TResult>) => Promise<TResult>;
|
|
2215
|
+
|
|
2216
|
+
export { type ActivitiesRequest, type Activity, ActivityDirection, ActivityFilter, ActivityKind, ActivityStatus, type ApySample, Asset, type AssetPrices, type BorrowAction, type BorrowApyHistoryRequest, type BorrowOutflowDetails, type BorrowSubmitSignatureInfo, type BorrowingPower, CK_ETH_DEPOSIT_CONTRACT_ADDRESS, type CalculateLtvRequest, type CanisterIds, Chain, type ContractInteractionSupplyFlowRequest, type CreateAccountAction, type CreateAccountData, type CreateAccountRequest, type CreateBorrowData, type CreateBorrowRequest, type CreateInstantLoanRequest, type CreateWithdrawData, type CreateWithdrawRequest, Environment, type EstimateInflowFeeRequest, type EthTransactionRequest, type EvmReadClient, EvmSupplyApprovalStrategy, type EvmSupplyContext, type ExecuteWithOptions, type ExternalAccount, type GetActivityStatusRequest, type GetActivityStatusResponse, type GetEvmSupplyContextRequest, type HealthFactor, type HistoryEntry, type IcrcAccountSupplyTarget, type InflowActivity, type InflowActivityKind, type InflowActivityStatus, type InflowFeeEstimate, InflowSubmitType, type InstantLoan, type InstantLoanAccount, type InstantLoanAsset, type InstantLoanCandidate, type InstantLoanGetRequest, InstantLoanStatus, LiquidiumClient, type LiquidiumClientConfig, LiquidiumError, LiquidiumErrorCode, type ListActivitiesRequest, type LtvCalculation, type MarketAsset, type MarketChain, type NativeAccount, type NativeAddressSupplyTarget, type OutflowActivity, type OutflowActivityKind, type OutflowActivityStatus, type OutflowDetails, type OutflowReceiver, OutflowType, type PaginatedResponse, type Pool, type PoolConfigHistoryEntry, type PoolConfigHistoryEntryApiItem, type PoolConfigHistoryResponse, type PoolHistoryEntry, type PoolHistoryEntryApiItem, type PoolHistoryRequest, type PoolHistoryResponse, type PoolRate, type Position, type QuoteRequest, type QuoteResult, type QuoteValidationError, QuoteValidationErrorCode, type QuoteWarning, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, type SendEthTransactionRequest, type SendEthTransactionWalletAction, type SignMessageRequest, type SignMessageWalletAction, type SignPsbtRequest, type SignPsbtWalletAction, type SignableAction, type SignatureInfo, type SubmitInflowRequest, type SubmitInflowResponse, SupplyAction, type SupplyFlow, type SupplyFlowRequest, SupplyPlanType, type SupplyTarget, TransferMode, type TransferSupplyFlowRequest, USDC_CONTRACT_ADDRESS, USDT_CONTRACT_ADDRESS, type UserHistoryEntry, type UserHistoryEntryApiItem, type UserHistoryResponse, UserHistoryStatus, type UserHistoryStatusApi, type UserHistoryType, type UserLiquidationHistoryEntry, type UserLiquidationHistoryFilters, type UserLiquidationHistoryType, type UserPositionSummary, type UserReserve, type UserStats, type UserTransactionHistoryEntry, type UserTransactionHistoryFilters, type UserTransactionHistoryType, type Wallet, type WalletAction, type WalletAdapter, WalletExecutionKind, type WithdrawAction, type WithdrawOutflowDetails, type WithdrawSubmitSignatureInfo, createTransferErc20Transaction, executeWith, intFromPublicId, publicIdFromInt };
|