Supply & Borrow
The lending and borrowing services cover the core money-market loop: supply assets to earn yield, post collateral, borrow against it, and repay. Both services expose buildXTx methods (unsigned transactions) alongside convenience methods that sign and submit through a wallet kit.
All amounts are human-readable; you pass the token's decimal precision so the SDK can scale to on-chain values. See Core patterns for the shared kit, withBuffer, and options conventions.
Lending service
Accessed via client.lending.
deposit
Supply assets to a pool and receive jTokens (supply shares) in your obligation.
import type { ObligationKey } from '@alula/market-sdk'
const user: ObligationKey = { user: 'GABC...', seed: undefined }
await client.lending.deposit(user, poolAddress, 100, assetDecimals, kit)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation receiving the deposit |
poolAddress | string | Target pool address |
amount | number | Human-readable amount to deposit |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildDepositTx(user, poolAddress, amount, assetDecimals).
withdraw
Redeem jTokens for the underlying asset. The amount actually withdrawn may be capped to keep the obligation healthy.
// Withdraw a specific amount
await client.lending.withdraw(user, poolAddress, 50, assetDecimals, kit, false)
// Withdraw the maximum currently available
await client.lending.withdraw(user, poolAddress, 0, assetDecimals, kit, true)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation to withdraw from |
poolAddress | string | Target pool address |
amount | number | Human-readable amount (ignored when withBuffer is true) |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
withBuffer | boolean | When true, submits the maximum and lets the contract cap it |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildWithdrawTx(user, poolAddress, amount, assetDecimals).
TIP
Call simulateWithdraw first to show the user the exact amount and fees before committing.
addCollateral
Post assets as collateral to back borrowing.
await client.lending.addCollateral(user, poolAddress, 100, assetDecimals, kit)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation receiving the collateral |
poolAddress | string | Target pool address |
amount | number | Human-readable amount to add |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildAddCollateralTx(user, poolAddress, amount, assetDecimals).
removeCollateral
Release collateral back to your balance, subject to remaining health.
// Remove a specific amount
await client.lending.removeCollateral(user, poolAddress, 25, assetDecimals, kit, false)
// Remove the maximum currently allowed
await client.lending.removeCollateral(user, poolAddress, 0, assetDecimals, kit, true)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation to remove collateral from |
poolAddress | string | Target pool address |
amount | number | Human-readable amount (ignored when withBuffer is true) |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
withBuffer | boolean | When true, submits the maximum and lets the contract cap it |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildRemoveCollateralTx(user, poolAddress, amount, assetDecimals).
Borrowing service
Accessed via client.borrowing.
borrow
Borrow an asset against collateral already posted in your obligation. Borrowing capacity is limited by collateral value, open LTV, and liability factors.
await client.borrowing.borrow(user, poolAddress, 200, assetDecimals, kit, false)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation borrowing the asset |
poolAddress | string | Pool to borrow from |
amount | number | Human-readable amount (ignored when withBuffer is true) |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
withBuffer | boolean | When true, submits the maximum borrowable |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildBorrowTx(user, poolAddress, amount, assetDecimals).
WARNING
An obligation cannot hold a deposit and a borrow in the same pool. To earn yield on an asset you are also borrowing, use a separate obligation (a different seed).
repay
Repay borrowed assets.
await client.borrowing.repay(user, poolAddress, 100, assetDecimals, kit)| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation repaying the debt |
poolAddress | string | Pool the debt is owed to |
amount | number | Human-readable amount to repay |
assetDecimals | number | Decimal precision of the pool's token |
kit | SigningKit | Wallet used to sign |
options | { debug?: boolean } | Optional; debug defaults to true |
Build-only variant: buildRepayTx(user, poolAddress, amount, assetDecimals).