MCDEX
Search…
Removing Margin
This guide shows how to remove margin from position by using the withdraw function of liquidityPool object.

Withdraw

Function

withdraw(perpetualIndex, traderAddress, amount)
parameters
type
description
perpetualIndex
number
index of perpetual in the liquidity pool
traderAddress
string
address of trader
amount
number
amount of collateral to withdraw. The amount always use decimals 18.
Notice
  • After withdrawn, trader shall at least has maintenance margin left in account.
  • Can only called when the perpetual's state is "NORMAL".

Example

Util function toWei can refer to Quick Start
1
import { LiquidityPoolFactory } from '@mcdex/mai3.js'
2
const liquidityPool = LiquidityPoolFactory.connect(liquidityPoolAddress, provider)
3
4
// withdraw 1 amount of collateral to account (withdraw amount is 18 decimal)
5
liquidityPool.withdraw(0, trader.address, toWei("1")) // please check permission of sender
6
7
// withdraw 100 amount of collateral to account (withdraw amount is 18 decimal)
8
liquidityPool.withdraw(0, trader.address, toWei("100")) // please check permission of sender
Copied!

Sample Code

Margin
Last modified 23d ago