Multiply
The multiply service builds and unwinds leveraged looping positions in a single atomic transaction. Opening a position flash-borrows the debt asset, swaps it into collateral, posts that collateral, and borrows to repay the flash loan — all composed through the market contract's batch operations. The SDK computes the entire sequence for you and returns a preview describing the amounts, fees, slippage, and price impact before anything is signed.
For the product-level explanation of leverage, health, and risks, see the Multiply guides.
Accessed via client.multiply.
Margin asset
Positions can be opened with margin denominated in either the borrow asset or the deposit (collateral) asset, selected via marginAsset ('borrow' | 'deposit'). Opening defaults to 'borrow'; closing defaults to 'deposit'.
WARNING
Multiply does not support a referrer. Leave referrer undefined — passing a value throws.
Opening a position
calculateMultiplyMaxLeverage
Compute the maximum safe leverage multiplier for a pool's open LTV (in basis points). Use it to bound a leverage slider in your UI.
import { calculateMultiplyMaxLeverage } from '@alula/client-sdk'
const maxLeverage = calculateMultiplyMaxLeverage(openLtvBps) // e.g. 4.0getOpenPositionPreview
Compute the full open-position plan without signing. Render the returned figures — flash-loan amount, swap input/output, minimum output after slippage, final borrow amount, and price impact — before the user commits.
const preview = await client.multiply.getOpenPositionPreview({
depositPoolAddress,
borrowPoolAddress,
initialAmount: '100',
leverageMultiplier: 3,
marginAsset: 'borrow',
slippagePercent: 0.5,
swapProviderAddress,
})| Parameter | Type | Description |
|---|---|---|
depositPoolAddress | string | Pool supplying collateral |
borrowPoolAddress | string | Pool supplying the borrowed (debt) asset |
initialAmount | string | number | User's margin, in the marginAsset token |
leverageMultiplier | number | Target leverage (must be > 1 and ≤ max leverage) |
marginAsset | 'borrow' | 'deposit' | Which asset the margin is denominated in. Defaults to 'borrow' |
slippagePercent | number | Optional swap slippage tolerance. Defaults to 0.05 |
swapProviderAddress | string | Swap provider used for the debt→collateral leg |
path | string[] | Optional explicit swap path; defaults to a direct pair |
Returns a MultiplyPreview including flashBorrowAmount, flashRepaymentAmount, swapAmountIn, expectedAmountOut, minAmountOut, depositAmount, finalBorrowAmount, maxLeverageMultiplier, and priceImpactBps (depth-driven swap impact in basis points, or undefined when it cannot be measured).
openPosition
Build, sign, and submit the open-position transaction. Accepts the same parameters as the preview plus the user obligation.
await client.multiply.openPosition(
{
user,
depositPoolAddress,
borrowPoolAddress,
initialAmount: '100',
leverageMultiplier: 3,
marginAsset: 'borrow',
slippagePercent: 0.5,
swapProviderAddress,
},
kit,
)Build-only variant: buildOpenPositionTx(params) returns { preview, tx } so you can inspect the plan and transaction before signing.
Closing a position
getClosePositionPreview
Compute the unwind plan — full or partial. Reads the current position, sizes the flash loan and swap, and returns the amounts the user will receive.
const preview = await client.multiply.getClosePositionPreview({
user,
depositPoolAddress,
borrowPoolAddress,
marginAsset: 'deposit',
slippagePercent: 0.5,
swapProviderAddress,
})| Parameter | Type | Description |
|---|---|---|
user | ObligationKey | Obligation holding the position |
depositPoolAddress | string | Collateral pool |
borrowPoolAddress | string | Debt pool |
marginAsset | 'borrow' | 'deposit' | Asset to return proceeds in. Defaults to 'deposit' |
repayAmount | string | number | Optional partial repay amount; omit for a full close |
slippagePercent | number | Optional swap slippage tolerance. Defaults to 0.05 |
swapProviderAddress | string | Swap provider used for the collateral→debt leg |
path | string[] | Optional explicit swap path |
Returns a CloseMultiplyPreview including isFullClose, currentDepositAmount, currentBorrowAmount, repayAmount, withdrawAmount, estimatedReceiveAmount, maxReceivableAmount, remaining position amounts, and priceImpactBps.
closePosition
Build, sign, and submit the close transaction.
await client.multiply.closePosition(
{
user,
depositPoolAddress,
borrowPoolAddress,
marginAsset: 'deposit',
slippagePercent: 0.5,
swapProviderAddress,
},
kit,
)| Parameter | Type | Description |
|---|---|---|
(all getClosePositionPreview parameters) | ||
minReceiveAmount | string | number | Optional floor on proceeds returned to the user |
Build-only variant: buildClosePositionTx(params) returns { preview, tx, minReceiveAmount, maxAmountIn }.