@liquidium/client 0.2.0 → 0.3.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 +58 -11
- package/dist/index.cjs +302 -143
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +235 -113
- package/dist/index.d.ts +235 -113
- package/dist/index.js +301 -144
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<p align="center">
|
|
15
15
|
<a href="https://liquidium-inc.github.io/liquidium-sdk/"><b>SDK Docs</b></a> ·
|
|
16
16
|
<a href="https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/instant-loans-flow"><b>Instant Loan Example</b></a> ·
|
|
17
|
-
<a href="https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/
|
|
17
|
+
<a href="https://github.com/Liquidium-Inc/liquidium-sdk/tree/main/examples/sdk-method-query"><b>SDK Method Query Example</b></a> ·
|
|
18
18
|
<a href="#core-api"><b>Core API</b></a>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
@@ -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
|
|
|
@@ -148,9 +153,9 @@ Instant-loan integrations use this sequence:
|
|
|
148
153
|
| Step | SDK call | What your app does |
|
|
149
154
|
| --- | --- | --- |
|
|
150
155
|
| Load market data | `client.market.listPools()` and `client.market.getAssetPrices()` | Show supported collateral and borrow assets |
|
|
151
|
-
| Validate amounts | `client.quote.calculateLtv(...)` | Block invalid LTV or frozen-pool input before creating a loan |
|
|
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.
|
|
@@ -168,7 +173,7 @@ Creates an accountless instant loan and returns generated transfer targets.
|
|
|
168
173
|
| `collateralAsset` | Collateral asset symbol, for example `"BTC"` |
|
|
169
174
|
| `borrowAsset` | Borrow asset symbol, for example `"USDC"` |
|
|
170
175
|
| `collateralAmount` | Intended credited collateral amount in base units, before deposit/inflow fees |
|
|
171
|
-
| `borrowAmount` | Borrow amount in base units |
|
|
176
|
+
| `borrowAmount` | Borrow amount in base units. The SDK rejects values below the asset minimum. |
|
|
172
177
|
| `ltvMaxBps` | Maximum LTV in basis points, where `6_000n` is 60% |
|
|
173
178
|
| `depositWindowSeconds` | How long the user has to send collateral |
|
|
174
179
|
| `borrowDestination` | External address that receives borrowed funds |
|
|
@@ -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
|
+
}
|
|
192
213
|
|
|
193
|
-
|
|
214
|
+
const selectedLoan = await client.instantLoans.get({ loanId: results[0].loanId });
|
|
215
|
+
```
|
|
194
216
|
|
|
195
|
-
|
|
217
|
+
Call `get(...)` when you already have an exact canister identifier and want direct canister lookup without an array:
|
|
218
|
+
|
|
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
|
|
|
@@ -200,6 +227,22 @@ Calculates implied LTV from selected pools, prices, borrow amount, and collatera
|
|
|
200
227
|
|
|
201
228
|
Use this before `client.instantLoans.create(...)` so your app can block invalid input and choose a safe `ltvMaxBps`.
|
|
202
229
|
|
|
230
|
+
### Borrow minimums
|
|
231
|
+
|
|
232
|
+
The SDK enforces product minimums before borrow creation:
|
|
233
|
+
|
|
234
|
+
| Asset | Minimum borrow amount |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| BTC | `5_100n` sats |
|
|
237
|
+
| USDC | `1_000_000n` base units |
|
|
238
|
+
| USDT | `1_000_000n` base units |
|
|
239
|
+
|
|
240
|
+
Use `getMinimumBorrowAmount(asset)` to display the same minimum that `client.quote.calculateLtv(...)`, `client.quote.getQuote(...)`, `client.instantLoans.create(...)`, and `client.lending.prepareBorrow(...)` enforce.
|
|
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
|
+
|
|
203
246
|
## Response Fields
|
|
204
247
|
|
|
205
248
|
Most instant-loan UIs show or store these fields:
|
|
@@ -211,10 +254,14 @@ Most instant-loan UIs show or store these fields:
|
|
|
211
254
|
| `loan.initialDeposit.amount` | Fee-inclusive collateral amount to send after creation or restore |
|
|
212
255
|
| `loan.initialDeposit.collateralAmount` | Intended credited collateral target used for LTV |
|
|
213
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 |
|
|
214
259
|
| `loan.repayment.amount` | Full amount to repay, including fee and interest buffer. Zero when no repayment is due |
|
|
215
260
|
| `loan.repayment.target` | Address or ICRC account where the user sends repayment |
|
|
216
261
|
| `loan.position` | Current collateral, debt, and interest state for the generated profile |
|
|
217
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
|
+
|
|
218
265
|
## Amounts
|
|
219
266
|
|
|
220
267
|
The SDK returns amount fields as `bigint` values in the asset's smallest unit.
|
|
@@ -254,8 +301,8 @@ Start browser integrations with the examples.
|
|
|
254
301
|
|
|
255
302
|
| Example | What it shows |
|
|
256
303
|
| --- | --- |
|
|
257
|
-
| [`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
|
|
258
|
-
| [`examples/
|
|
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 |
|
|
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 |
|
|
259
306
|
|
|
260
307
|
Run the instant loan example:
|
|
261
308
|
|