Skip to content

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.

typescript
import type { ObligationKey } from '@alula/market-sdk'

const user: ObligationKey = { user: 'GABC...', seed: undefined }

await client.lending.deposit(user, poolAddress, 100, assetDecimals, kit)
ParameterTypeDescription
userObligationKeyObligation receiving the deposit
poolAddressstringTarget pool address
amountnumberHuman-readable amount to deposit
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet 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.

typescript
// 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)
ParameterTypeDescription
userObligationKeyObligation to withdraw from
poolAddressstringTarget pool address
amountnumberHuman-readable amount (ignored when withBuffer is true)
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet used to sign
withBufferbooleanWhen 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.

typescript
await client.lending.addCollateral(user, poolAddress, 100, assetDecimals, kit)
ParameterTypeDescription
userObligationKeyObligation receiving the collateral
poolAddressstringTarget pool address
amountnumberHuman-readable amount to add
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet 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.

typescript
// 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)
ParameterTypeDescription
userObligationKeyObligation to remove collateral from
poolAddressstringTarget pool address
amountnumberHuman-readable amount (ignored when withBuffer is true)
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet used to sign
withBufferbooleanWhen 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.

typescript
await client.borrowing.borrow(user, poolAddress, 200, assetDecimals, kit, false)
ParameterTypeDescription
userObligationKeyObligation borrowing the asset
poolAddressstringPool to borrow from
amountnumberHuman-readable amount (ignored when withBuffer is true)
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet used to sign
withBufferbooleanWhen 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.

typescript
await client.borrowing.repay(user, poolAddress, 100, assetDecimals, kit)
ParameterTypeDescription
userObligationKeyObligation repaying the debt
poolAddressstringPool the debt is owed to
amountnumberHuman-readable amount to repay
assetDecimalsnumberDecimal precision of the pool's token
kitSigningKitWallet used to sign
options{ debug?: boolean }Optional; debug defaults to true

Build-only variant: buildRepayTx(user, poolAddress, amount, assetDecimals).