@liquidium/client 0.2.0 → 0.2.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 +16 -4
- package/dist/index.cjs +91 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +160 -69
- package/dist/index.d.ts +160 -69
- package/dist/index.js +90 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -226,6 +226,16 @@ interface SignatureInfo {
|
|
|
226
226
|
/** Account that produced the signature, when different from the action default. */
|
|
227
227
|
account?: string;
|
|
228
228
|
}
|
|
229
|
+
/** Request submitted after a BTC PSBT has been signed. */
|
|
230
|
+
interface SignPsbtSubmitRequest {
|
|
231
|
+
/** Base64-encoded signed PSBT. */
|
|
232
|
+
signedPsbtBase64: string;
|
|
233
|
+
}
|
|
234
|
+
/** Request submitted after an ETH transaction has been sent. */
|
|
235
|
+
interface SendEthTransactionSubmitRequest {
|
|
236
|
+
/** EVM transaction hash returned by the wallet. */
|
|
237
|
+
txHash: string;
|
|
238
|
+
}
|
|
229
239
|
/** Prepared action that requires message signing before submit. */
|
|
230
240
|
interface SignMessageWalletAction<TData, TResult> {
|
|
231
241
|
/** Protocol action kind. */
|
|
@@ -260,9 +270,7 @@ interface SignPsbtWalletAction<TResult> {
|
|
|
260
270
|
/** Base64-encoded unsigned PSBT. */
|
|
261
271
|
psbtBase64: string;
|
|
262
272
|
/** Submits the signed PSBT and resolves the protocol result. */
|
|
263
|
-
submit(request:
|
|
264
|
-
signedPsbtBase64: string;
|
|
265
|
-
}): Promise<TResult>;
|
|
273
|
+
submit(request: SignPsbtSubmitRequest): Promise<TResult>;
|
|
266
274
|
}
|
|
267
275
|
/** Prepared action that requires sending an ETH transaction before submit. */
|
|
268
276
|
interface SendEthTransactionWalletAction<TResult> {
|
|
@@ -279,13 +287,25 @@ interface SendEthTransactionWalletAction<TResult> {
|
|
|
279
287
|
/** EVM transaction request to send. */
|
|
280
288
|
transaction: EthTransactionRequest;
|
|
281
289
|
/** Submits the transaction hash and resolves the protocol result. */
|
|
282
|
-
submit(request:
|
|
283
|
-
txHash: string;
|
|
284
|
-
}): Promise<TResult>;
|
|
290
|
+
submit(request: SendEthTransactionSubmitRequest): Promise<TResult>;
|
|
285
291
|
}
|
|
286
292
|
/** Any prepared action returned by SDK methods and executable by {@link executeWith}. */
|
|
287
293
|
type WalletAction<TResult> = SignMessageWalletAction<unknown, TResult> | SignPsbtWalletAction<TResult> | SendEthTransactionWalletAction<TResult>;
|
|
288
294
|
|
|
295
|
+
/** Options for preparing a profile-creation action. */
|
|
296
|
+
interface PrepareCreateProfileOptions {
|
|
297
|
+
/** Wallet address that will own the new profile. */
|
|
298
|
+
account: string;
|
|
299
|
+
}
|
|
300
|
+
/** Parameters for creating a profile through a wallet adapter. */
|
|
301
|
+
interface CreateProfileParams {
|
|
302
|
+
/** Wallet address that will own the new profile. */
|
|
303
|
+
account: string;
|
|
304
|
+
/** Chain used to sign the profile-creation message. */
|
|
305
|
+
chain: Chain;
|
|
306
|
+
/** Wallet adapter used to sign the profile-creation message. */
|
|
307
|
+
walletAdapter: WalletAdapter;
|
|
308
|
+
}
|
|
289
309
|
/** Data embedded in a prepared profile-creation action. */
|
|
290
310
|
interface CreateAccountData {
|
|
291
311
|
/** Expiry timestamp, in protocol nanoseconds, included in the signed message. */
|
|
@@ -311,14 +331,6 @@ interface CreateAccountRequest {
|
|
|
311
331
|
signatureInfo: SignatureInfo;
|
|
312
332
|
}
|
|
313
333
|
|
|
314
|
-
type PrepareCreateProfileOptions = {
|
|
315
|
-
account: string;
|
|
316
|
-
};
|
|
317
|
-
type CreateProfileParams = {
|
|
318
|
-
account: string;
|
|
319
|
-
chain: Chain;
|
|
320
|
-
walletAdapter: WalletAdapter;
|
|
321
|
-
};
|
|
322
334
|
/** Profile lifecycle and linked-wallet helpers. */
|
|
323
335
|
declare class AccountsModule {
|
|
324
336
|
private readonly canisterContext;
|
|
@@ -464,32 +476,56 @@ interface OutflowActivity extends BaseActivity {
|
|
|
464
476
|
}
|
|
465
477
|
/** Any activity returned by `activities.list` or `activities.getStatus`. */
|
|
466
478
|
type Activity = InflowActivity | OutflowActivity;
|
|
467
|
-
/**
|
|
468
|
-
|
|
479
|
+
/** Shared request fields for listing activities. */
|
|
480
|
+
interface BaseListActivitiesRequest {
|
|
469
481
|
/** Optional state filter; defaults to `all`. */
|
|
470
482
|
filter?: ActivityFilter;
|
|
471
|
-
}
|
|
483
|
+
}
|
|
484
|
+
/** Activity list request scoped to a Liquidium profile. */
|
|
485
|
+
interface ListActivitiesByProfileRequest extends BaseListActivitiesRequest {
|
|
486
|
+
/** Profile principal text to list activities for. */
|
|
472
487
|
profileId: string;
|
|
473
|
-
}
|
|
488
|
+
}
|
|
489
|
+
/** Activity list request scoped to an instant-loan short reference. */
|
|
490
|
+
interface ListActivitiesByShortRefRequest extends BaseListActivitiesRequest {
|
|
491
|
+
/** Instant-loan short reference to list activities for. */
|
|
474
492
|
shortRef: string;
|
|
475
|
-
}
|
|
476
|
-
/** Request for
|
|
477
|
-
type
|
|
493
|
+
}
|
|
494
|
+
/** Request for listing activities by profile id or instant-loan short reference. */
|
|
495
|
+
type ListActivitiesRequest = ListActivitiesByProfileRequest | ListActivitiesByShortRefRequest;
|
|
496
|
+
/** Shared request fields for an activity status lookup. */
|
|
497
|
+
interface BaseGetActivityStatusRequest {
|
|
478
498
|
/** Activity or receipt id to look up. */
|
|
479
499
|
id: string;
|
|
480
|
-
}
|
|
500
|
+
}
|
|
501
|
+
/** Activity status lookup scoped to a Liquidium profile. */
|
|
502
|
+
interface GetActivityStatusByProfileRequest extends BaseGetActivityStatusRequest {
|
|
503
|
+
/** Profile principal text that owns the activity. */
|
|
481
504
|
profileId: string;
|
|
482
|
-
}
|
|
505
|
+
}
|
|
506
|
+
/** Activity status lookup scoped to an instant-loan short reference. */
|
|
507
|
+
interface GetActivityStatusByShortRefRequest extends BaseGetActivityStatusRequest {
|
|
508
|
+
/** Instant-loan short reference that owns the activity. */
|
|
483
509
|
shortRef: string;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
type
|
|
510
|
+
}
|
|
511
|
+
/** Request for fetching one activity by id and owner identifier. */
|
|
512
|
+
type GetActivityStatusRequest = GetActivityStatusByProfileRequest | GetActivityStatusByShortRefRequest;
|
|
513
|
+
/** Successful activity status lookup result. */
|
|
514
|
+
interface ActivityStatusFoundResponse {
|
|
515
|
+
/** Indicates the activity was found. */
|
|
487
516
|
found: true;
|
|
517
|
+
/** Matched activity. */
|
|
488
518
|
activity: Activity;
|
|
489
|
-
}
|
|
519
|
+
}
|
|
520
|
+
/** Missing activity status lookup result. */
|
|
521
|
+
interface ActivityStatusNotFoundResponse {
|
|
522
|
+
/** Indicates the activity was not found. */
|
|
490
523
|
found: false;
|
|
524
|
+
/** Requested activity or receipt id. */
|
|
491
525
|
id: string;
|
|
492
|
-
}
|
|
526
|
+
}
|
|
527
|
+
/** Result of an activity status lookup. */
|
|
528
|
+
type GetActivityStatusResponse = ActivityStatusFoundResponse | ActivityStatusNotFoundResponse;
|
|
493
529
|
|
|
494
530
|
/** Receipt-oriented activity list and status helpers. */
|
|
495
531
|
declare class ActivitiesModule {
|
|
@@ -774,6 +810,29 @@ declare class HistoryModule {
|
|
|
774
810
|
getLiquidationHistory(user: string, market?: string, filters?: UserLiquidationHistoryFilters): Promise<PaginatedResponse<UserLiquidationHistoryEntry>>;
|
|
775
811
|
}
|
|
776
812
|
|
|
813
|
+
/** Wallet execution dependencies for borrow and withdraw convenience methods. */
|
|
814
|
+
interface WalletExecutionParams {
|
|
815
|
+
/** Chain used by the signing wallet. */
|
|
816
|
+
signerChain: Chain;
|
|
817
|
+
/** Wallet adapter used to execute the prepared action. */
|
|
818
|
+
signerWalletAdapter: WalletAdapter;
|
|
819
|
+
}
|
|
820
|
+
/** EVM transaction payload returned by lending transaction builders. */
|
|
821
|
+
interface EvmContractTransaction {
|
|
822
|
+
/** Contract address to call. */
|
|
823
|
+
to: string;
|
|
824
|
+
/** Hex-encoded calldata. */
|
|
825
|
+
data: string;
|
|
826
|
+
}
|
|
827
|
+
/** Parameters for an ERC-20 transfer transaction. */
|
|
828
|
+
interface CreateTransferErc20TransactionParams {
|
|
829
|
+
/** ERC-20 token contract address. */
|
|
830
|
+
tokenAddress: string;
|
|
831
|
+
/** Destination EVM address. */
|
|
832
|
+
recipientAddress: string;
|
|
833
|
+
/** Transfer amount in token base units. */
|
|
834
|
+
amount: bigint;
|
|
835
|
+
}
|
|
777
836
|
/** Destination account for a completed outflow. */
|
|
778
837
|
interface OutflowReceiver {
|
|
779
838
|
/** Destination account type reported by the protocol. */
|
|
@@ -781,6 +840,13 @@ interface OutflowReceiver {
|
|
|
781
840
|
/** Destination principal or external-chain address. */
|
|
782
841
|
account: string;
|
|
783
842
|
}
|
|
843
|
+
/** External-chain destination for a completed outflow. */
|
|
844
|
+
interface ExternalOutflowReceiver {
|
|
845
|
+
/** Destination account type reported by the protocol. */
|
|
846
|
+
type: "External";
|
|
847
|
+
/** External-chain destination address. */
|
|
848
|
+
account: string;
|
|
849
|
+
}
|
|
784
850
|
/**
|
|
785
851
|
* Receipt for a borrow or withdraw submitted to the lending canister.
|
|
786
852
|
*
|
|
@@ -804,18 +870,12 @@ interface OutflowDetails {
|
|
|
804
870
|
/** Borrow receipt with an external-chain receiver. */
|
|
805
871
|
type BorrowOutflowDetails = OutflowDetails & {
|
|
806
872
|
outflowType: "borrow";
|
|
807
|
-
receiver:
|
|
808
|
-
type: "External";
|
|
809
|
-
account: string;
|
|
810
|
-
};
|
|
873
|
+
receiver: ExternalOutflowReceiver;
|
|
811
874
|
};
|
|
812
875
|
/** Withdraw receipt with an external-chain receiver. */
|
|
813
876
|
type WithdrawOutflowDetails = OutflowDetails & {
|
|
814
877
|
outflowType: "withdraw";
|
|
815
|
-
receiver:
|
|
816
|
-
type: "External";
|
|
817
|
-
account: string;
|
|
818
|
-
};
|
|
878
|
+
receiver: ExternalOutflowReceiver;
|
|
819
879
|
};
|
|
820
880
|
/** Signature payload for submitting a prepared borrow action. */
|
|
821
881
|
interface BorrowSubmitSignatureInfo extends SignatureInfo {
|
|
@@ -1014,6 +1074,17 @@ interface EstimateInflowFeeRequest {
|
|
|
1014
1074
|
/** Chain to estimate for. */
|
|
1015
1075
|
chain: Chain;
|
|
1016
1076
|
}
|
|
1077
|
+
/** Request for an ETH stablecoin deposit address. */
|
|
1078
|
+
interface GetDepositAddressRequest {
|
|
1079
|
+
/** Liquidium profile principal text. */
|
|
1080
|
+
profileId: string;
|
|
1081
|
+
/** Pool principal text receiving the inflow. */
|
|
1082
|
+
poolId: string;
|
|
1083
|
+
/** ETH stablecoin asset. */
|
|
1084
|
+
asset: string;
|
|
1085
|
+
/** Deposit or repayment action for the inflow. */
|
|
1086
|
+
action: SupplyAction;
|
|
1087
|
+
}
|
|
1017
1088
|
/** Fee estimate for an inflow target, rounded up to the asset's fee unit. */
|
|
1018
1089
|
interface InflowFeeEstimate {
|
|
1019
1090
|
/** Estimated total fee rounded up in the asset's base units. */
|
|
@@ -1074,10 +1145,6 @@ interface EvmSupplyContext {
|
|
|
1074
1145
|
approvalStrategy: EvmSupplyApprovalStrategy;
|
|
1075
1146
|
}
|
|
1076
1147
|
|
|
1077
|
-
type WalletExecutionParams = {
|
|
1078
|
-
signerChain: Chain;
|
|
1079
|
-
signerWalletAdapter: WalletAdapter;
|
|
1080
|
-
};
|
|
1081
1148
|
/** Borrow, withdraw, supply, inflow reporting, and fee-estimation helpers. */
|
|
1082
1149
|
declare class LendingModule {
|
|
1083
1150
|
private readonly canisterContext;
|
|
@@ -1160,12 +1227,7 @@ declare class LendingModule {
|
|
|
1160
1227
|
* @param request - Profile, pool, asset, and supply action.
|
|
1161
1228
|
* @returns The EVM deposit address for the derived account.
|
|
1162
1229
|
*/
|
|
1163
|
-
getDepositAddress(request:
|
|
1164
|
-
profileId: string;
|
|
1165
|
-
poolId: string;
|
|
1166
|
-
asset: string;
|
|
1167
|
-
action: SupplyAction;
|
|
1168
|
-
}): Promise<string>;
|
|
1230
|
+
getDepositAddress(request: GetDepositAddressRequest): Promise<string>;
|
|
1169
1231
|
/**
|
|
1170
1232
|
* Estimates the network/deposit fee for an inflow target.
|
|
1171
1233
|
*
|
|
@@ -1491,14 +1553,7 @@ declare class PositionsModule {
|
|
|
1491
1553
|
}
|
|
1492
1554
|
|
|
1493
1555
|
/** Builds calldata for an ERC-20 `transfer(recipient, amount)` transaction. */
|
|
1494
|
-
declare function createTransferErc20Transaction(params:
|
|
1495
|
-
tokenAddress: string;
|
|
1496
|
-
recipientAddress: string;
|
|
1497
|
-
amount: bigint;
|
|
1498
|
-
}): {
|
|
1499
|
-
to: string;
|
|
1500
|
-
data: string;
|
|
1501
|
-
};
|
|
1556
|
+
declare function createTransferErc20Transaction(params: CreateTransferErc20TransactionParams): EvmContractTransaction;
|
|
1502
1557
|
|
|
1503
1558
|
/** Asset symbols supported by the instant-loans canister. */
|
|
1504
1559
|
type InstantLoanAsset = "BTC" | "SOL" | "USDC" | "USDT";
|
|
@@ -1626,12 +1681,18 @@ interface CreateInstantLoanRequest {
|
|
|
1626
1681
|
*/
|
|
1627
1682
|
refundDestination: string | ExternalAccount;
|
|
1628
1683
|
}
|
|
1629
|
-
/** Lookup request for loading
|
|
1630
|
-
|
|
1684
|
+
/** Lookup request for loading an instant loan by numeric canister id. */
|
|
1685
|
+
interface InstantLoanGetByIdRequest {
|
|
1686
|
+
/** Canister-assigned loan id. */
|
|
1631
1687
|
loanId: bigint;
|
|
1632
|
-
}
|
|
1688
|
+
}
|
|
1689
|
+
/** Lookup request for loading an instant loan by short user-facing reference. */
|
|
1690
|
+
interface InstantLoanGetByRefRequest {
|
|
1691
|
+
/** Short user-facing reference derived from `loanId`. */
|
|
1633
1692
|
ref: string;
|
|
1634
|
-
}
|
|
1693
|
+
}
|
|
1694
|
+
/** Lookup request for loading canonical instant-loan state. */
|
|
1695
|
+
type InstantLoanGetRequest = InstantLoanGetByIdRequest | InstantLoanGetByRefRequest;
|
|
1635
1696
|
/** Page request for direct instant-loan canister event queries. */
|
|
1636
1697
|
interface InstantLoanListEventsRequest {
|
|
1637
1698
|
/** Event id to start from. */
|
|
@@ -1667,8 +1728,8 @@ interface InstantLoanEvent {
|
|
|
1667
1728
|
}
|
|
1668
1729
|
/** Instant-loan leg used when stuck funds are withdrawn. */
|
|
1669
1730
|
type InstantLoanLeg = "Lend" | "Borrow";
|
|
1670
|
-
/**
|
|
1671
|
-
|
|
1731
|
+
/** Loan-created instant-loan event payload. */
|
|
1732
|
+
interface InstantLoanCreatedEventType {
|
|
1672
1733
|
type: "LoanCreated";
|
|
1673
1734
|
loanId: bigint;
|
|
1674
1735
|
borrowDestination: InstantLoanAccount;
|
|
@@ -1681,42 +1742,58 @@ type InstantLoanEventType = {
|
|
|
1681
1742
|
profileId: string;
|
|
1682
1743
|
borrowPoolId: string;
|
|
1683
1744
|
borrowAsset: InstantLoanAsset;
|
|
1684
|
-
}
|
|
1745
|
+
}
|
|
1746
|
+
/** Full collateral withdrawal request event payload. */
|
|
1747
|
+
interface InstantLoanFullLendWithdrawalRequestedEventType {
|
|
1685
1748
|
type: "FullLendWithdrawalRequested";
|
|
1686
1749
|
loanId: bigint;
|
|
1687
1750
|
account: InstantLoanAccount;
|
|
1688
1751
|
poolId: string;
|
|
1689
|
-
}
|
|
1752
|
+
}
|
|
1753
|
+
/** Borrow request event payload. */
|
|
1754
|
+
interface InstantLoanBorrowRequestedEventType {
|
|
1690
1755
|
type: "BorrowRequested";
|
|
1691
1756
|
loanId: bigint;
|
|
1692
1757
|
account: InstantLoanAccount;
|
|
1693
1758
|
poolId: string;
|
|
1694
1759
|
amount: bigint;
|
|
1695
|
-
}
|
|
1760
|
+
}
|
|
1761
|
+
/** Deposit timer exceeded event payload. */
|
|
1762
|
+
interface InstantLoanDepositTimerExceededEventType {
|
|
1696
1763
|
type: "DepositTimerExceeded";
|
|
1697
1764
|
loanId: bigint;
|
|
1698
|
-
}
|
|
1765
|
+
}
|
|
1766
|
+
/** Stuck funds withdrawal request event payload. */
|
|
1767
|
+
interface InstantLoanStuckFundsWithdrawalRequestedEventType {
|
|
1699
1768
|
type: "StuckFundsWithdrawalRequested";
|
|
1700
1769
|
leg: InstantLoanLeg;
|
|
1701
1770
|
loanId: bigint;
|
|
1702
1771
|
account: InstantLoanAccount;
|
|
1703
1772
|
poolId: string;
|
|
1704
1773
|
amount: bigint;
|
|
1705
|
-
}
|
|
1774
|
+
}
|
|
1775
|
+
/** Profile-warmed event payload. */
|
|
1776
|
+
interface InstantLoanProfileWarmedEventType {
|
|
1706
1777
|
type: "ProfileWarmed";
|
|
1707
1778
|
derivationIndex: Uint8Array;
|
|
1708
1779
|
warmedProfileId: bigint;
|
|
1709
1780
|
ethAddress: string;
|
|
1710
1781
|
profileId: string;
|
|
1711
|
-
}
|
|
1782
|
+
}
|
|
1783
|
+
/** Repay-complete event payload. */
|
|
1784
|
+
interface InstantLoanRepayCompleteEventType {
|
|
1712
1785
|
type: "RepayComplete";
|
|
1713
1786
|
loanId: bigint;
|
|
1714
1787
|
profileId: string;
|
|
1715
|
-
}
|
|
1788
|
+
}
|
|
1789
|
+
/** Deposit timer started event payload. */
|
|
1790
|
+
interface InstantLoanDepositTimerStartedEventType {
|
|
1716
1791
|
type: "DepositTimerStarted";
|
|
1717
1792
|
loanId: bigint;
|
|
1718
1793
|
timestamp: bigint;
|
|
1719
|
-
}
|
|
1794
|
+
}
|
|
1795
|
+
/** Direct canister event payload returned by instant-loans event queries. */
|
|
1796
|
+
type InstantLoanEventType = InstantLoanCreatedEventType | InstantLoanFullLendWithdrawalRequestedEventType | InstantLoanBorrowRequestedEventType | InstantLoanDepositTimerExceededEventType | InstantLoanStuckFundsWithdrawalRequestedEventType | InstantLoanProfileWarmedEventType | InstantLoanRepayCompleteEventType | InstantLoanDepositTimerStartedEventType;
|
|
1720
1797
|
/** Current amount to send to the repayment target to close the debt. */
|
|
1721
1798
|
interface InstantLoanRepayment {
|
|
1722
1799
|
/** Full amount to send to the repayment target, including fee and interest buffer. */
|
|
@@ -2146,6 +2223,20 @@ declare class LiquidiumClient {
|
|
|
2146
2223
|
constructor(config?: LiquidiumClientConfig);
|
|
2147
2224
|
}
|
|
2148
2225
|
|
|
2226
|
+
/** Minimum borrow amounts in each asset's base units. */
|
|
2227
|
+
declare const MIN_BORROW_AMOUNTS_BY_ASSET: {
|
|
2228
|
+
readonly BTC: 5100n;
|
|
2229
|
+
readonly USDC: 1000000n;
|
|
2230
|
+
readonly USDT: 1000000n;
|
|
2231
|
+
};
|
|
2232
|
+
type MinimumBorrowAsset = keyof typeof MIN_BORROW_AMOUNTS_BY_ASSET;
|
|
2233
|
+
/**
|
|
2234
|
+
* Returns the minimum borrow amount for an asset in base units.
|
|
2235
|
+
*
|
|
2236
|
+
* Assets without a configured product minimum return `0n`.
|
|
2237
|
+
*/
|
|
2238
|
+
declare function getMinimumBorrowAmount(asset: string): bigint;
|
|
2239
|
+
|
|
2149
2240
|
/**
|
|
2150
2241
|
* Stable string codes for {@link LiquidiumError}. Use for branching in application code.
|
|
2151
2242
|
*/
|
|
@@ -2257,4 +2348,4 @@ interface ExecuteWithOptions {
|
|
|
2257
2348
|
*/
|
|
2258
2349
|
declare function executeWith(options: ExecuteWithOptions): <TResult>(action: WalletAction<TResult>) => Promise<TResult>;
|
|
2259
2350
|
|
|
2260
|
-
export { AccountsModule, ActivitiesModule, type ActivitiesRequest, type Activity, ActivityDirection, ActivityFilter, ActivityKind, ActivityStatus, type ActivityTopUp, 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 CreateProfileParams, type CreateWithdrawData, type CreateWithdrawRequest, Environment, type EstimateInflowFeeRequest, type EthTransactionRequest, type EvmReadClient, EvmSupplyApprovalStrategy, type EvmSupplyContext, type ExecuteWithOptions, type ExternalAccount, type FindPoolQuery, type GetActivityStatusRequest, type GetActivityStatusResponse, type GetEvmSupplyContextRequest, type HealthFactor, type HistoryEntry, HistoryModule, type IcrcAccountSupplyTarget, type InflowActivity, type InflowActivityKind, type InflowActivityStatus, type InflowFeeEstimate, InflowSubmitType, type InstantLoan, type InstantLoanAccount, type InstantLoanAsset, type InstantLoanAuthorization, type InstantLoanBorrow, type InstantLoanCandidate, type InstantLoanCollateral, type InstantLoanConfig, type InstantLoanEvent, type InstantLoanEventType, type InstantLoanGetRequest, type InstantLoanInitialDeposit, type InstantLoanLeg, type InstantLoanListEventsRequest, type InstantLoanPositionSummary, type InstantLoanRepayment, InstantLoanStatus, type InstantLoanTerms, type InstantLoanWarmedProfile, InstantLoansModule, LendingModule, LiquidiumClient, type LiquidiumClientConfig, LiquidiumError, LiquidiumErrorCode, type LiquidiumErrorContext, type ListActivitiesRequest, type LtvCalculation, type ManualTransferSupplyFlowRequest, type MarketAsset, type MarketChain, MarketModule, type MaxRepayAmount, 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, PositionsModule, type PrepareCreateProfileOptions, QuoteModule, type QuoteRequest, type QuoteResult, type QuoteValidationError, QuoteValidationErrorCode, type QuoteWarning, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, type SendBtcTransactionRequest, 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 WalletExecutionParams, type WalletTransferSupplyFlowRequest, type WithdrawAction, type WithdrawOutflowDetails, type WithdrawSubmitSignatureInfo, createTransferErc20Transaction, executeWith, intFromPublicId, publicIdFromInt };
|
|
2351
|
+
export { AccountsModule, ActivitiesModule, type ActivitiesRequest, type Activity, ActivityDirection, ActivityFilter, ActivityKind, ActivityStatus, type ActivityStatusFoundResponse, type ActivityStatusNotFoundResponse, type ActivityTopUp, type ApySample, Asset, type AssetPrices, type BaseGetActivityStatusRequest, type BaseListActivitiesRequest, 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 CreateProfileParams, type CreateTransferErc20TransactionParams, type CreateWithdrawData, type CreateWithdrawRequest, Environment, type EstimateInflowFeeRequest, type EthTransactionRequest, type EvmContractTransaction, type EvmReadClient, EvmSupplyApprovalStrategy, type EvmSupplyContext, type ExecuteWithOptions, type ExternalAccount, type ExternalOutflowReceiver, type FindPoolQuery, type GetActivityStatusByProfileRequest, type GetActivityStatusByShortRefRequest, type GetActivityStatusRequest, type GetActivityStatusResponse, type GetDepositAddressRequest, type GetEvmSupplyContextRequest, type HealthFactor, type HistoryEntry, HistoryModule, type IcrcAccountSupplyTarget, type InflowActivity, type InflowActivityKind, type InflowActivityStatus, type InflowFeeEstimate, InflowSubmitType, type InstantLoan, type InstantLoanAccount, type InstantLoanAsset, type InstantLoanAuthorization, type InstantLoanBorrow, type InstantLoanBorrowRequestedEventType, type InstantLoanCandidate, type InstantLoanCollateral, type InstantLoanConfig, type InstantLoanCreatedEventType, type InstantLoanDepositTimerExceededEventType, type InstantLoanDepositTimerStartedEventType, type InstantLoanEvent, type InstantLoanEventType, type InstantLoanFullLendWithdrawalRequestedEventType, type InstantLoanGetByIdRequest, type InstantLoanGetByRefRequest, type InstantLoanGetRequest, type InstantLoanInitialDeposit, type InstantLoanLeg, type InstantLoanListEventsRequest, type InstantLoanPositionSummary, type InstantLoanProfileWarmedEventType, type InstantLoanRepayCompleteEventType, type InstantLoanRepayment, InstantLoanStatus, type InstantLoanStuckFundsWithdrawalRequestedEventType, type InstantLoanTerms, type InstantLoanWarmedProfile, InstantLoansModule, LendingModule, LiquidiumClient, type LiquidiumClientConfig, LiquidiumError, LiquidiumErrorCode, type LiquidiumErrorContext, type ListActivitiesByProfileRequest, type ListActivitiesByShortRefRequest, type ListActivitiesRequest, type LtvCalculation, MIN_BORROW_AMOUNTS_BY_ASSET, type ManualTransferSupplyFlowRequest, type MarketAsset, type MarketChain, MarketModule, type MaxRepayAmount, type MinimumBorrowAsset, 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, PositionsModule, type PrepareCreateProfileOptions, QuoteModule, type QuoteRequest, type QuoteResult, type QuoteValidationError, QuoteValidationErrorCode, type QuoteWarning, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, type SendBtcTransactionRequest, type SendEthTransactionRequest, type SendEthTransactionSubmitRequest, type SendEthTransactionWalletAction, type SignMessageRequest, type SignMessageWalletAction, type SignPsbtRequest, type SignPsbtSubmitRequest, 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 WalletExecutionParams, type WalletTransferSupplyFlowRequest, type WithdrawAction, type WithdrawOutflowDetails, type WithdrawSubmitSignatureInfo, createTransferErc20Transaction, executeWith, getMinimumBorrowAmount, intFromPublicId, publicIdFromInt };
|
package/dist/index.js
CHANGED
|
@@ -3105,6 +3105,39 @@ function assertSupportsIcrcAccountInflowTarget(asset) {
|
|
|
3105
3105
|
);
|
|
3106
3106
|
}
|
|
3107
3107
|
|
|
3108
|
+
// src/core/borrow-minimums.ts
|
|
3109
|
+
var MIN_BORROW_AMOUNTS_BY_ASSET = {
|
|
3110
|
+
BTC: 5100n,
|
|
3111
|
+
// 5,100 sats = 0.000051 BTC
|
|
3112
|
+
USDC: 1000000n,
|
|
3113
|
+
// 1 USDC
|
|
3114
|
+
USDT: 1000000n
|
|
3115
|
+
// 1 USDT
|
|
3116
|
+
};
|
|
3117
|
+
function getMinimumBorrowAmount(asset) {
|
|
3118
|
+
if (!isMinimumBorrowAsset(asset)) {
|
|
3119
|
+
return 0n;
|
|
3120
|
+
}
|
|
3121
|
+
return MIN_BORROW_AMOUNTS_BY_ASSET[asset];
|
|
3122
|
+
}
|
|
3123
|
+
function getBorrowAmountMinimumValidationError(params) {
|
|
3124
|
+
const minimumAmount = getMinimumBorrowAmount(params.asset);
|
|
3125
|
+
if (minimumAmount <= 0n || params.amount >= minimumAmount) {
|
|
3126
|
+
return null;
|
|
3127
|
+
}
|
|
3128
|
+
return {
|
|
3129
|
+
asset: params.asset,
|
|
3130
|
+
minimumAmount,
|
|
3131
|
+
message: formatMinimumBorrowAmountMessage(params.asset, minimumAmount)
|
|
3132
|
+
};
|
|
3133
|
+
}
|
|
3134
|
+
function formatMinimumBorrowAmountMessage(asset, minimumAmount) {
|
|
3135
|
+
return `Borrow amount must be at least ${minimumAmount} base units for ${asset}`;
|
|
3136
|
+
}
|
|
3137
|
+
function isMinimumBorrowAsset(asset) {
|
|
3138
|
+
return Object.hasOwn(MIN_BORROW_AMOUNTS_BY_ASSET, asset);
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3108
3141
|
// src/modules/quote/types.ts
|
|
3109
3142
|
var QuoteValidationErrorCode = /* @__PURE__ */ ((QuoteValidationErrorCode2) => {
|
|
3110
3143
|
QuoteValidationErrorCode2["INVALID_LTV"] = "INVALID_LTV";
|
|
@@ -3127,7 +3160,6 @@ var BASIS_POINTS_DENOMINATOR = 10000n;
|
|
|
3127
3160
|
var BPS_PER_PERCENT = 100n;
|
|
3128
3161
|
var MIN_LTV_BPS = 0n;
|
|
3129
3162
|
var HIGH_LTV_WARNING_THRESHOLD_BPS = 8000n;
|
|
3130
|
-
var MIN_BORROW_AMOUNT_BASE_UNITS = 5000n;
|
|
3131
3163
|
var INTERNAL_USD_DECIMAL_PLACES = 8;
|
|
3132
3164
|
var PRICE_SCALE_DECIMAL_PLACES = 8;
|
|
3133
3165
|
var QuoteModule = class {
|
|
@@ -3185,11 +3217,12 @@ var QuoteModule = class {
|
|
|
3185
3217
|
message: `Price not available for collateral asset: ${collateralPool.asset}`
|
|
3186
3218
|
});
|
|
3187
3219
|
}
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3220
|
+
const borrowAmountError = createBorrowAmountValidationError({
|
|
3221
|
+
amount: request.borrowAmount,
|
|
3222
|
+
asset: borrowPool.asset
|
|
3223
|
+
});
|
|
3224
|
+
if (borrowAmountError) {
|
|
3225
|
+
validationErrors.push(borrowAmountError);
|
|
3193
3226
|
}
|
|
3194
3227
|
if (request.collateralAmount <= 0n) {
|
|
3195
3228
|
validationErrors.push({
|
|
@@ -3311,16 +3344,12 @@ var QuoteModule = class {
|
|
|
3311
3344
|
message: `Price not available for collateral asset: ${collateralAsset}`
|
|
3312
3345
|
});
|
|
3313
3346
|
}
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
validationErrors.push({
|
|
3321
|
-
code: "BORROW_AMOUNT_TOO_LOW" /* BORROW_AMOUNT_TOO_LOW */,
|
|
3322
|
-
message: `Borrow amount must be at least ${MIN_BORROW_AMOUNT_BASE_UNITS} base units`
|
|
3323
|
-
});
|
|
3347
|
+
const borrowAmountError = createBorrowAmountValidationError({
|
|
3348
|
+
amount: borrowAmount,
|
|
3349
|
+
asset: borrowAsset
|
|
3350
|
+
});
|
|
3351
|
+
if (borrowAmountError) {
|
|
3352
|
+
validationErrors.push(borrowAmountError);
|
|
3324
3353
|
}
|
|
3325
3354
|
if (targetLtvBps <= MIN_LTV_BPS) {
|
|
3326
3355
|
validationErrors.push({
|
|
@@ -3443,6 +3472,22 @@ function createQuoteResult(params) {
|
|
|
3443
3472
|
warnings: params.warnings
|
|
3444
3473
|
};
|
|
3445
3474
|
}
|
|
3475
|
+
function createBorrowAmountValidationError(params) {
|
|
3476
|
+
if (params.amount <= 0n) {
|
|
3477
|
+
return {
|
|
3478
|
+
code: "BORROW_AMOUNT_TOO_LOW" /* BORROW_AMOUNT_TOO_LOW */,
|
|
3479
|
+
message: "Borrow amount must be greater than 0"
|
|
3480
|
+
};
|
|
3481
|
+
}
|
|
3482
|
+
const minimumBorrowAmountError = getBorrowAmountMinimumValidationError(params);
|
|
3483
|
+
if (!minimumBorrowAmountError) {
|
|
3484
|
+
return null;
|
|
3485
|
+
}
|
|
3486
|
+
return {
|
|
3487
|
+
code: "BORROW_AMOUNT_TOO_LOW" /* BORROW_AMOUNT_TOO_LOW */,
|
|
3488
|
+
message: minimumBorrowAmountError.message
|
|
3489
|
+
};
|
|
3490
|
+
}
|
|
3446
3491
|
function computeUsdInternalFromBaseUnits(params) {
|
|
3447
3492
|
const { amountBaseUnits, priceScaled, assetDecimalPlaces } = params;
|
|
3448
3493
|
const scaleDiff = INTERNAL_USD_DECIMAL_PLACES - PRICE_SCALE_DECIMAL_PLACES;
|
|
@@ -3768,7 +3813,9 @@ var InstantLoansModule = class {
|
|
|
3768
3813
|
);
|
|
3769
3814
|
}
|
|
3770
3815
|
const apiClient = this.requireApi("Instant loan address lookup");
|
|
3771
|
-
const response = await apiClient.get(
|
|
3816
|
+
const response = await apiClient.get(
|
|
3817
|
+
buildInstantLoanAddressLookupPath({ address: trimmedAddress })
|
|
3818
|
+
);
|
|
3772
3819
|
return (response.candidates ?? response.loans ?? []).map(mapCandidateWire);
|
|
3773
3820
|
}
|
|
3774
3821
|
async mapLoanRecord(record, collateralAmount) {
|
|
@@ -3789,7 +3836,9 @@ var InstantLoansModule = class {
|
|
|
3789
3836
|
}
|
|
3790
3837
|
async getCollateralAmountHint(loanId) {
|
|
3791
3838
|
const apiClient = this.requireApi("Instant loan lookup");
|
|
3792
|
-
const response = await apiClient.get(
|
|
3839
|
+
const response = await apiClient.get(
|
|
3840
|
+
buildInstantLoanCollateralHintPath({ loanId })
|
|
3841
|
+
);
|
|
3793
3842
|
return parseBigintWire(response.collateralAmountHint, "collateral amount");
|
|
3794
3843
|
}
|
|
3795
3844
|
async mapLoanWire(loan) {
|
|
@@ -4713,9 +4762,28 @@ var LendingModule = class {
|
|
|
4713
4762
|
"Borrow requires a signer account"
|
|
4714
4763
|
);
|
|
4715
4764
|
}
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4765
|
+
if (request.amount <= 0n) {
|
|
4766
|
+
throw new LiquidiumError(
|
|
4767
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
4768
|
+
"Borrow amount must be greater than 0"
|
|
4769
|
+
);
|
|
4770
|
+
}
|
|
4771
|
+
const selectedPool = await this.getPoolById(request.poolId);
|
|
4772
|
+
const selectedAsset = getVariantKey(selectedPool.asset);
|
|
4773
|
+
const minimumBorrowAmountError = getBorrowAmountMinimumValidationError({
|
|
4774
|
+
amount: request.amount,
|
|
4775
|
+
asset: selectedAsset
|
|
4776
|
+
});
|
|
4777
|
+
if (minimumBorrowAmountError) {
|
|
4778
|
+
throw new LiquidiumError(
|
|
4779
|
+
LiquidiumErrorCode.VALIDATION_ERROR,
|
|
4780
|
+
minimumBorrowAmountError.message
|
|
4781
|
+
);
|
|
4782
|
+
}
|
|
4783
|
+
const receiverAddress = normalizeExternalAddress({
|
|
4784
|
+
address: destinationAccount,
|
|
4785
|
+
asset: selectedAsset,
|
|
4786
|
+
chain: getVariantKey(selectedPool.chain)
|
|
4719
4787
|
});
|
|
4720
4788
|
const lendingActor = createLendingActor(this.canisterContext);
|
|
4721
4789
|
try {
|
|
@@ -5964,6 +6032,6 @@ function resolveEvmReadClient(config) {
|
|
|
5964
6032
|
});
|
|
5965
6033
|
}
|
|
5966
6034
|
|
|
5967
|
-
export { AccountsModule, ActivitiesModule, ActivityDirection, ActivityFilter, ActivityKind, ActivityStatus, Asset, CK_ETH_DEPOSIT_CONTRACT_ADDRESS, Chain, Environment, EvmSupplyApprovalStrategy, HistoryModule, InflowSubmitType, InstantLoanStatus, InstantLoansModule, LendingModule, LiquidiumClient, LiquidiumError, LiquidiumErrorCode, MarketModule, OutflowType, PositionsModule, QuoteModule, QuoteValidationErrorCode, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, SupplyAction, SupplyPlanType, TransferMode, USDC_CONTRACT_ADDRESS, USDT_CONTRACT_ADDRESS, UserHistoryStatus, WalletExecutionKind, createTransferErc20Transaction, executeWith, intFromPublicId, publicIdFromInt };
|
|
6035
|
+
export { AccountsModule, ActivitiesModule, ActivityDirection, ActivityFilter, ActivityKind, ActivityStatus, Asset, CK_ETH_DEPOSIT_CONTRACT_ADDRESS, Chain, Environment, EvmSupplyApprovalStrategy, HistoryModule, InflowSubmitType, InstantLoanStatus, InstantLoansModule, LendingModule, LiquidiumClient, LiquidiumError, LiquidiumErrorCode, MIN_BORROW_AMOUNTS_BY_ASSET, MarketModule, OutflowType, PositionsModule, QuoteModule, QuoteValidationErrorCode, QuoteWarningCode, RATE_DECIMALS, RATE_SCALE, SupplyAction, SupplyPlanType, TransferMode, USDC_CONTRACT_ADDRESS, USDT_CONTRACT_ADDRESS, UserHistoryStatus, WalletExecutionKind, createTransferErc20Transaction, executeWith, getMinimumBorrowAmount, intFromPublicId, publicIdFromInt };
|
|
5968
6036
|
//# sourceMappingURL=index.js.map
|
|
5969
6037
|
//# sourceMappingURL=index.js.map
|