Skip to content

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.

typescript
import { calculateMultiplyMaxLeverage } from '@alula/client-sdk'

const maxLeverage = calculateMultiplyMaxLeverage(openLtvBps) // e.g. 4.0

getOpenPositionPreview ​

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.

typescript
const preview = await client.multiply.getOpenPositionPreview({
  depositPoolAddress,
  borrowPoolAddress,
  initialAmount: '100',
  leverageMultiplier: 3,
  marginAsset: 'borrow',
  slippagePercent: 0.5,
  swapProviderAddress,
})
ParameterTypeDescription
depositPoolAddressstringPool supplying collateral
borrowPoolAddressstringPool supplying the borrowed (debt) asset
initialAmountstring | numberUser's margin, in the marginAsset token
leverageMultipliernumberTarget leverage (must be > 1 and ≤ max leverage)
marginAsset'borrow' | 'deposit'Which asset the margin is denominated in. Defaults to 'borrow'
slippagePercentnumberOptional swap slippage tolerance. Defaults to 0.05
swapProviderAddressstringSwap provider used for the debt→collateral leg
pathstring[]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.

typescript
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.

typescript
const preview = await client.multiply.getClosePositionPreview({
  user,
  depositPoolAddress,
  borrowPoolAddress,
  marginAsset: 'deposit',
  slippagePercent: 0.5,
  swapProviderAddress,
})
ParameterTypeDescription
userObligationKeyObligation holding the position
depositPoolAddressstringCollateral pool
borrowPoolAddressstringDebt pool
marginAsset'borrow' | 'deposit'Asset to return proceeds in. Defaults to 'deposit'
repayAmountstring | numberOptional partial repay amount; omit for a full close
slippagePercentnumberOptional swap slippage tolerance. Defaults to 0.05
swapProviderAddressstringSwap provider used for the collateral→debt leg
pathstring[]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.

typescript
await client.multiply.closePosition(
  {
    user,
    depositPoolAddress,
    borrowPoolAddress,
    marginAsset: 'deposit',
    slippagePercent: 0.5,
    swapProviderAddress,
  },
  kit,
)
ParameterTypeDescription
(all getClosePositionPreview parameters)
minReceiveAmountstring | numberOptional floor on proceeds returned to the user

Build-only variant: buildClosePositionTx(params) returns { preview, tx, minReceiveAmount, maxAmountIn }.