@liquidium/client 0.2.1 → 0.3.1
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 +42 -7
- package/dist/index.cjs +570 -191
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +77 -46
- package/dist/index.d.ts +77 -46
- package/dist/index.js +570 -191
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -38,8 +38,8 @@ Liquidium supports two borrowing and lending integration paths:
|
|
|
38
38
|
|
|
39
39
|
| Path | Use when | Main SDK calls |
|
|
40
40
|
| --- | --- | --- |
|
|
41
|
-
| Recommended: accountless instant loans | You want a short checkout-style flow where users borrow against collateral without creating a Liquidium profile first | `client.instantLoans.create(...)`, `client.instantLoans.get(...)`, `client.activities.list(...)` |
|
|
42
|
-
| Account-based profile flows | You want users to keep a Liquidium profile, manage positions across sessions, supply funds, borrow, withdraw, or use ETH contract-interaction deposits | `client.accounts.createProfile(...)`, `client.lending.supply(...)`, `client.lending.borrow(...)`, `client.lending.withdraw(...)`, `client.positions.
|
|
41
|
+
| Recommended: accountless instant loans | You want a short checkout-style flow where users borrow against collateral without creating a Liquidium profile first | `client.instantLoans.create(...)`, `client.instantLoans.get(...)`, `client.instantLoans.find(...)`, `client.activities.list(...)` |
|
|
42
|
+
| Account-based profile flows | You want users to keep a Liquidium profile, manage positions across sessions, supply funds, borrow, withdraw, or use ETH contract-interaction deposits | `client.accounts.createProfile(...)`, `client.lending.supply(...)`, `client.lending.borrow(...)`, `client.lending.withdraw(...)`, `client.positions.listPositions(...)` |
|
|
43
43
|
|
|
44
44
|
Use accountless instant loans for new borrow flows unless you need profile-level position management. Use account-based flows when your app owns the full lending dashboard experience.
|
|
45
45
|
|
|
@@ -118,6 +118,11 @@ const activities = await client.activities.list({ shortRef: loan.ref });
|
|
|
118
118
|
|
|
119
119
|
console.log("Loan activities:", activities);
|
|
120
120
|
|
|
121
|
+
const foundLoans = await client.instantLoans.find(loan.ref);
|
|
122
|
+
|
|
123
|
+
console.log("Found loan reference:", foundLoans[0]?.ref);
|
|
124
|
+
console.log("Found loan collateral:", foundLoans[0]?.collateral.amount.toString());
|
|
125
|
+
|
|
121
126
|
function requirePool(pools: Pool[], asset: string): Pool {
|
|
122
127
|
const pool = pools.find((candidatePool) => candidatePool.asset === asset);
|
|
123
128
|
|
|
@@ -150,7 +155,7 @@ Instant-loan integrations use this sequence:
|
|
|
150
155
|
| Load market data | `client.market.listPools()` and `client.market.getAssetPrices()` | Show supported collateral and borrow assets |
|
|
151
156
|
| Validate amounts | `client.quote.calculateLtv(...)` | Block too-small borrow amounts, invalid LTV, or frozen-pool input before creating a loan |
|
|
152
157
|
| Create loan | `client.instantLoans.create(...)` | Store `loan.ref` and show `loan.initialDeposit.amount` plus `loan.initialDeposit.target` |
|
|
153
|
-
| Track loan | `client.instantLoans.get({ ref })` and `client.activities.list({ shortRef: ref })` | Reload loan state, initial deposit quote, and repayment activity |
|
|
158
|
+
| Track loan | `client.instantLoans.get({ ref })`, `client.instantLoans.find(...)`, and `client.activities.list({ shortRef: ref })` | Reload loan state, initial deposit quote, and repayment activity |
|
|
154
159
|
| Repay loan | Read `loan.repayment` | Ask the user to send `loan.repayment.amount` to `loan.repayment.target`; amount is `0n` when no repayment is due |
|
|
155
160
|
|
|
156
161
|
`client.instantLoans.create(...)` and `client.instantLoans.get(...)` return the generated Liquidium profile, current position state, an initial deposit quote with its transfer target, and a repayment quote with its transfer target. Repayment amount fields are zero when the loan has no debt. Users do not manage the generated profile.
|
|
@@ -188,11 +193,33 @@ Loads loan state by numeric canister loan id.
|
|
|
188
193
|
|
|
189
194
|
Use this when your backend stores the numeric id instead of the short reference.
|
|
190
195
|
|
|
191
|
-
### `client.instantLoans.
|
|
196
|
+
### `client.instantLoans.find(query)`
|
|
197
|
+
|
|
198
|
+
Finds instant loans by short reference, numeric canister loan id string, generated deposit or repayment address, borrow or refund destination address, or indexed transaction id/hash through the SDK API search index.
|
|
199
|
+
|
|
200
|
+
Use this for recovery and manage pages where the user may paste any loan identifier. The method returns lightweight matches because address and transaction-id lookups can match many loans. Use `client.instantLoans.get(...)` after the user selects a match.
|
|
201
|
+
|
|
202
|
+
```ts
|
|
203
|
+
const results = await client.instantLoans.find("bc1q...");
|
|
204
|
+
const byRef = await client.instantLoans.find("ABC123");
|
|
205
|
+
const byLoanId = await client.instantLoans.find("42");
|
|
206
|
+
|
|
207
|
+
for (const result of results) {
|
|
208
|
+
console.log(result.ref);
|
|
209
|
+
console.log(result.loanId);
|
|
210
|
+
console.log(result.collateral.asset, result.borrow.asset);
|
|
211
|
+
console.log(result.collateral.amount);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const selectedLoan = await client.instantLoans.get({ loanId: results[0].loanId });
|
|
215
|
+
```
|
|
192
216
|
|
|
193
|
-
|
|
217
|
+
Call `get(...)` when you already have an exact canister identifier and want direct canister lookup without an array:
|
|
194
218
|
|
|
195
|
-
|
|
219
|
+
```ts
|
|
220
|
+
const loanById = await client.instantLoans.get({ loanId: 123n });
|
|
221
|
+
const loanByRef = await client.instantLoans.get({ ref: "ABC123" });
|
|
222
|
+
```
|
|
196
223
|
|
|
197
224
|
### `client.quote.calculateLtv(request, pools, prices)`
|
|
198
225
|
|
|
@@ -212,6 +239,10 @@ The SDK enforces product minimums before borrow creation:
|
|
|
212
239
|
|
|
213
240
|
Use `getMinimumBorrowAmount(asset)` to display the same minimum that `client.quote.calculateLtv(...)`, `client.quote.getQuote(...)`, `client.instantLoans.create(...)`, and `client.lending.prepareBorrow(...)` enforce.
|
|
214
241
|
|
|
242
|
+
### Profile full withdraw amounts
|
|
243
|
+
|
|
244
|
+
For profile-based withdraw flows, call `client.positions.getFullWithdrawAmount(profileId, poolId)` before building the withdraw request. The helper returns `{ amount, decimals }`: pass `amount` to `client.lending.withdraw(...)` or `client.lending.prepareWithdraw(...)`, and use `decimals` for display formatting. Do not add `earnedInterest`; the returned amount already uses the current supplied balance.
|
|
245
|
+
|
|
215
246
|
## Response Fields
|
|
216
247
|
|
|
217
248
|
Most instant-loan UIs show or store these fields:
|
|
@@ -223,10 +254,14 @@ Most instant-loan UIs show or store these fields:
|
|
|
223
254
|
| `loan.initialDeposit.amount` | Fee-inclusive collateral amount to send after creation or restore |
|
|
224
255
|
| `loan.initialDeposit.collateralAmount` | Intended credited collateral target used for LTV |
|
|
225
256
|
| `loan.initialDeposit.target` | Address or ICRC account where the user sends collateral |
|
|
257
|
+
| `loan.initialDeposit.detectedTimestamp` | Unix timestamp in seconds when the collateral deposit was detected, or `null` before detection |
|
|
258
|
+
| `loan.initialDeposit.expiryTimestamp` | Unix timestamp in seconds when the collateral deposit window expires, or `null` before detection when unavailable |
|
|
226
259
|
| `loan.repayment.amount` | Full amount to repay, including fee and interest buffer. Zero when no repayment is due |
|
|
227
260
|
| `loan.repayment.target` | Address or ICRC account where the user sends repayment |
|
|
228
261
|
| `loan.position` | Current collateral, debt, and interest state for the generated profile |
|
|
229
262
|
|
|
263
|
+
`client.instantLoans.find(...)` returns lightweight search matches with `loanId`, `ref`, `createdAt`, `profileId`, `collateral`, and `borrow`. Use `client.instantLoans.get(...)` to load full loan fields, and use `client.activities.list(...)` separately when you need deposit, borrow, repay, or withdraw activity.
|
|
264
|
+
|
|
230
265
|
## Amounts
|
|
231
266
|
|
|
232
267
|
The SDK returns amount fields as `bigint` values in the asset's smallest unit.
|
|
@@ -266,7 +301,7 @@ Start browser integrations with the examples.
|
|
|
266
301
|
|
|
267
302
|
| Example | What it shows |
|
|
268
303
|
| --- | --- |
|
|
269
|
-
| [`examples/instant-loans-flow`](https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/instant-loans-flow) | Accountless instant loan UX with manual destination addresses, pool selection, LTV preview, loan creation, status reload, activity status, and
|
|
304
|
+
| [`examples/instant-loans-flow`](https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/instant-loans-flow) | Accountless instant loan UX with manual destination addresses, pool selection, LTV preview, loan creation, status reload, activity status, and loan recovery |
|
|
270
305
|
| [`examples/sdk-method-query`](https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/sdk-method-query) | Developer tool for calling SDK methods, including instant loan method templates |
|
|
271
306
|
|
|
272
307
|
Run the instant loan example:
|