@liquidium/client 0.4.0 → 0.4.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 +12 -3
- package/dist/index.cjs +64 -58
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -74
- package/dist/index.d.ts +22 -74
- package/dist/index.js +63 -59
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -241,6 +241,18 @@ The SDK enforces product minimums before borrow creation:
|
|
|
241
241
|
|
|
242
242
|
Use `getMinimumBorrowAmount(asset)` to display the same minimum that `client.quote.calculateLtv(...)`, `client.quote.getQuote(...)`, `client.instantLoans.create(...)`, and `client.lending.prepareBorrow(...)` enforce.
|
|
243
243
|
|
|
244
|
+
### Withdraw minimums
|
|
245
|
+
|
|
246
|
+
The SDK enforces product minimums before withdraw creation:
|
|
247
|
+
|
|
248
|
+
| Asset | Minimum withdraw amount |
|
|
249
|
+
| --- | --- |
|
|
250
|
+
| BTC | `5_000n` sats |
|
|
251
|
+
| USDC | `1_000_000n` base units |
|
|
252
|
+
| USDT | `1_000_000n` base units |
|
|
253
|
+
|
|
254
|
+
Use `getMinimumWithdrawAmount(asset)` to display the same minimum that `client.lending.prepareWithdraw(...)` enforces.
|
|
255
|
+
|
|
244
256
|
### Profile full withdraw amounts
|
|
245
257
|
|
|
246
258
|
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.
|
|
@@ -327,12 +339,9 @@ Run the instant loan example:
|
|
|
327
339
|
git clone https://github.com/Liquidium-Inc/liquidium-sdk.git
|
|
328
340
|
cd liquidium-sdk
|
|
329
341
|
pnpm install
|
|
330
|
-
cp examples/instant-loans-flow/.env.example examples/instant-loans-flow/.env
|
|
331
342
|
pnpm --filter @liquidium/example-instant-loans-flow dev
|
|
332
343
|
```
|
|
333
344
|
|
|
334
|
-
Set `VITE_INFURA_API_KEY` when your flow needs Ethereum reads through Infura.
|
|
335
|
-
|
|
336
345
|
## Browser And Runtime Support
|
|
337
346
|
|
|
338
347
|
Use the SDK in browser apps and modern TypeScript runtimes.
|
package/dist/index.cjs
CHANGED
|
@@ -984,13 +984,10 @@ function getVariantKey(variant) {
|
|
|
984
984
|
|
|
985
985
|
// src/core/wallet-actions.ts
|
|
986
986
|
var TransferMode = {
|
|
987
|
-
ck: "ck",
|
|
988
987
|
native: "native"
|
|
989
988
|
};
|
|
990
989
|
var WalletExecutionKind = {
|
|
991
|
-
|
|
992
|
-
signMessage: "sign-message",
|
|
993
|
-
signPsbt: "sign-psbt"
|
|
990
|
+
signMessage: "sign-message"
|
|
994
991
|
};
|
|
995
992
|
var WalletActionKind = {
|
|
996
993
|
createAccount: "create-account",
|
|
@@ -1028,38 +1025,6 @@ function executeWith(options) {
|
|
|
1028
1025
|
account: options.account ?? action.account
|
|
1029
1026
|
});
|
|
1030
1027
|
}
|
|
1031
|
-
case WalletExecutionKind.signPsbt: {
|
|
1032
|
-
if (!options.walletAdapter.signPsbt) {
|
|
1033
|
-
throw new LiquidiumError(
|
|
1034
|
-
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
1035
|
-
"Wallet adapter does not support PSBT signing"
|
|
1036
|
-
);
|
|
1037
|
-
}
|
|
1038
|
-
const signedPsbtBase64 = await options.walletAdapter.signPsbt({
|
|
1039
|
-
chain: Chain.BTC,
|
|
1040
|
-
psbtBase64: action.psbtBase64,
|
|
1041
|
-
account: options.account ?? action.account,
|
|
1042
|
-
actionType: action.actionType,
|
|
1043
|
-
transferMode: action.transferMode
|
|
1044
|
-
});
|
|
1045
|
-
return action.submit({ signedPsbtBase64 });
|
|
1046
|
-
}
|
|
1047
|
-
case WalletExecutionKind.sendEthTransaction: {
|
|
1048
|
-
if (!options.walletAdapter.sendEthTransaction) {
|
|
1049
|
-
throw new LiquidiumError(
|
|
1050
|
-
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
1051
|
-
"Wallet adapter does not support ETH transaction sending"
|
|
1052
|
-
);
|
|
1053
|
-
}
|
|
1054
|
-
const txHash = await options.walletAdapter.sendEthTransaction({
|
|
1055
|
-
chain: Chain.ETH,
|
|
1056
|
-
transaction: action.transaction,
|
|
1057
|
-
account: options.account ?? action.account,
|
|
1058
|
-
actionType: action.actionType,
|
|
1059
|
-
transferMode: action.transferMode
|
|
1060
|
-
});
|
|
1061
|
-
return action.submit({ txHash });
|
|
1062
|
-
}
|
|
1063
1028
|
default:
|
|
1064
1029
|
throw new LiquidiumError(
|
|
1065
1030
|
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
@@ -3259,13 +3224,12 @@ function assertSupportsIcrcAccountInflowTarget(asset) {
|
|
|
3259
3224
|
}
|
|
3260
3225
|
|
|
3261
3226
|
// src/core/borrow-minimums.ts
|
|
3227
|
+
var MINIMUM_BTC_BORROW_AMOUNT_SATS = 5100n;
|
|
3228
|
+
var MINIMUM_STABLECOIN_BORROW_AMOUNT_BASE_UNITS = 1000000n;
|
|
3262
3229
|
var MIN_BORROW_AMOUNTS_BY_ASSET = {
|
|
3263
|
-
BTC:
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
// 1 USDC
|
|
3267
|
-
USDT: 1000000n
|
|
3268
|
-
// 1 USDT
|
|
3230
|
+
[Asset.BTC]: MINIMUM_BTC_BORROW_AMOUNT_SATS,
|
|
3231
|
+
[Asset.USDC]: MINIMUM_STABLECOIN_BORROW_AMOUNT_BASE_UNITS,
|
|
3232
|
+
[Asset.USDT]: MINIMUM_STABLECOIN_BORROW_AMOUNT_BASE_UNITS
|
|
3269
3233
|
};
|
|
3270
3234
|
function getMinimumBorrowAmount(asset) {
|
|
3271
3235
|
if (!isMinimumBorrowAsset(asset)) {
|
|
@@ -4763,6 +4727,38 @@ function accountTypeToString(accountType) {
|
|
|
4763
4727
|
}
|
|
4764
4728
|
}
|
|
4765
4729
|
|
|
4730
|
+
// src/core/withdraw-minimums.ts
|
|
4731
|
+
var MINIMUM_BTC_WITHDRAW_AMOUNT_SATS = 5000n;
|
|
4732
|
+
var MINIMUM_STABLECOIN_WITHDRAW_AMOUNT_BASE_UNITS = 1000000n;
|
|
4733
|
+
var MIN_WITHDRAW_AMOUNTS_BY_ASSET = {
|
|
4734
|
+
[Asset.BTC]: MINIMUM_BTC_WITHDRAW_AMOUNT_SATS,
|
|
4735
|
+
[Asset.USDC]: MINIMUM_STABLECOIN_WITHDRAW_AMOUNT_BASE_UNITS,
|
|
4736
|
+
[Asset.USDT]: MINIMUM_STABLECOIN_WITHDRAW_AMOUNT_BASE_UNITS
|
|
4737
|
+
};
|
|
4738
|
+
function getMinimumWithdrawAmount(asset) {
|
|
4739
|
+
if (!isMinimumWithdrawAsset(asset)) {
|
|
4740
|
+
return 0n;
|
|
4741
|
+
}
|
|
4742
|
+
return MIN_WITHDRAW_AMOUNTS_BY_ASSET[asset];
|
|
4743
|
+
}
|
|
4744
|
+
function getWithdrawAmountMinimumValidationError(params) {
|
|
4745
|
+
const minimumAmount = getMinimumWithdrawAmount(params.asset);
|
|
4746
|
+
if (minimumAmount <= 0n || params.amount >= minimumAmount) {
|
|
4747
|
+
return null;
|
|
4748
|
+
}
|
|
4749
|
+
return {
|
|
4750
|
+
asset: params.asset,
|
|
4751
|
+
minimumAmount,
|
|
4752
|
+
message: formatMinimumWithdrawAmountMessage(params.asset, minimumAmount)
|
|
4753
|
+
};
|
|
4754
|
+
}
|
|
4755
|
+
function formatMinimumWithdrawAmountMessage(asset, minimumAmount) {
|
|
4756
|
+
return `Withdraw amount must be at least ${minimumAmount} base units for ${asset}`;
|
|
4757
|
+
}
|
|
4758
|
+
function isMinimumWithdrawAsset(asset) {
|
|
4759
|
+
return Object.hasOwn(MIN_WITHDRAW_AMOUNTS_BY_ASSET, asset);
|
|
4760
|
+
}
|
|
4761
|
+
|
|
4766
4762
|
// src/modules/lending/_internal/inflow-fee-rounding.ts
|
|
4767
4763
|
var ETH_STABLECOIN_INFLOW_FEE_ROUND_UP_TO_NEAREST_10_CENTS = 100000n;
|
|
4768
4764
|
var BTC_INFLOW_FEE_ROUND_UP_TO_NEAREST_SATS = 500n;
|
|
@@ -5439,9 +5435,28 @@ var LendingModule = class {
|
|
|
5439
5435
|
"Withdraw requires a signer account"
|
|
5440
5436
|
);
|
|
5441
5437
|
}
|
|
5442
|
-
|
|
5443
|
-
|
|
5444
|
-
|
|
5438
|
+
if (request.amount <= 0n) {
|
|
5439
|
+
throw new LiquidiumError(
|
|
5440
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
5441
|
+
"Withdraw amount must be greater than 0"
|
|
5442
|
+
);
|
|
5443
|
+
}
|
|
5444
|
+
const selectedPool = await this.getPoolById(request.poolId);
|
|
5445
|
+
const selectedAsset = selectedPool.asset;
|
|
5446
|
+
const minimumWithdrawAmountError = getWithdrawAmountMinimumValidationError({
|
|
5447
|
+
amount: request.amount,
|
|
5448
|
+
asset: selectedAsset
|
|
5449
|
+
});
|
|
5450
|
+
if (minimumWithdrawAmountError) {
|
|
5451
|
+
throw new LiquidiumError(
|
|
5452
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
5453
|
+
minimumWithdrawAmountError.message
|
|
5454
|
+
);
|
|
5455
|
+
}
|
|
5456
|
+
const receiverAddress = normalizeExternalAddress({
|
|
5457
|
+
address: destinationAccount,
|
|
5458
|
+
asset: selectedAsset,
|
|
5459
|
+
chain: selectedPool.chain
|
|
5445
5460
|
});
|
|
5446
5461
|
const lendingActor = createLendingActor(this.canisterContext);
|
|
5447
5462
|
try {
|
|
@@ -5853,14 +5868,6 @@ var LendingModule = class {
|
|
|
5853
5868
|
}
|
|
5854
5869
|
return decodedPool;
|
|
5855
5870
|
}
|
|
5856
|
-
async normalizeOutflowReceiverAddress(params) {
|
|
5857
|
-
const selectedPool = await this.getPoolById(params.poolId);
|
|
5858
|
-
return normalizeExternalAddress({
|
|
5859
|
-
address: params.receiverAddress,
|
|
5860
|
-
asset: selectedPool.asset,
|
|
5861
|
-
chain: selectedPool.chain
|
|
5862
|
-
});
|
|
5863
|
-
}
|
|
5864
5871
|
};
|
|
5865
5872
|
function mapExpectedOutflowDetails(details, expectedOutflowType, operation) {
|
|
5866
5873
|
if (details.outflowType !== expectedOutflowType) {
|
|
@@ -5956,12 +5963,10 @@ function formatPrice(price, decimals) {
|
|
|
5956
5963
|
// src/modules/market/market.ts
|
|
5957
5964
|
var ZERO_POOL_RATE = [0n, 0n, 0n];
|
|
5958
5965
|
var MarketModule = class {
|
|
5959
|
-
constructor(canisterContext
|
|
5966
|
+
constructor(canisterContext) {
|
|
5960
5967
|
this.canisterContext = canisterContext;
|
|
5961
|
-
this.apiClient = apiClient;
|
|
5962
5968
|
}
|
|
5963
5969
|
canisterContext;
|
|
5964
|
-
apiClient;
|
|
5965
5970
|
/**
|
|
5966
5971
|
* Lists SDK-supported pools with their current rates.
|
|
5967
5972
|
*
|
|
@@ -5970,7 +5975,6 @@ var MarketModule = class {
|
|
|
5970
5975
|
* @returns Supported lending pools enriched with their current rate data.
|
|
5971
5976
|
*/
|
|
5972
5977
|
async listPools() {
|
|
5973
|
-
void this.apiClient;
|
|
5974
5978
|
try {
|
|
5975
5979
|
const flexibleActor = createFlexibleLendingActor(this.canisterContext);
|
|
5976
5980
|
const rawPools = await flexibleActor.list_pools();
|
|
@@ -6412,7 +6416,7 @@ var LiquidiumClient = class {
|
|
|
6412
6416
|
this.apiClient,
|
|
6413
6417
|
this.evmReadClient
|
|
6414
6418
|
);
|
|
6415
|
-
this.market = new MarketModule(this.canisterContext
|
|
6419
|
+
this.market = new MarketModule(this.canisterContext);
|
|
6416
6420
|
this.positions = new PositionsModule(this.canisterContext, this.market);
|
|
6417
6421
|
this.activities = new ActivitiesModule(
|
|
6418
6422
|
this.apiClient,
|
|
@@ -6459,6 +6463,7 @@ exports.LiquidiumClient = LiquidiumClient;
|
|
|
6459
6463
|
exports.LiquidiumError = LiquidiumError;
|
|
6460
6464
|
exports.LiquidiumErrorCode = LiquidiumErrorCode;
|
|
6461
6465
|
exports.MIN_BORROW_AMOUNTS_BY_ASSET = MIN_BORROW_AMOUNTS_BY_ASSET;
|
|
6466
|
+
exports.MIN_WITHDRAW_AMOUNTS_BY_ASSET = MIN_WITHDRAW_AMOUNTS_BY_ASSET;
|
|
6462
6467
|
exports.MarketModule = MarketModule;
|
|
6463
6468
|
exports.OutflowType = OutflowType;
|
|
6464
6469
|
exports.PositionsModule = PositionsModule;
|
|
@@ -6477,6 +6482,7 @@ exports.WalletExecutionKind = WalletExecutionKind;
|
|
|
6477
6482
|
exports.createTransferErc20Transaction = createTransferErc20Transaction;
|
|
6478
6483
|
exports.executeWith = executeWith;
|
|
6479
6484
|
exports.getMinimumBorrowAmount = getMinimumBorrowAmount;
|
|
6485
|
+
exports.getMinimumWithdrawAmount = getMinimumWithdrawAmount;
|
|
6480
6486
|
exports.intFromPublicId = intFromPublicId;
|
|
6481
6487
|
exports.publicIdFromInt = publicIdFromInt;
|
|
6482
6488
|
//# sourceMappingURL=index.cjs.map
|