MCDEX
Search…
Adding Margin
This guide shows how to add margin into position by using the deposit function of liquidityPool object.

Deposit

Function

deposit(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 deposit. The amount always use decimals 18.
Notice
  • 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
// deposit 1 amount of collateral to account (deposit amount is 18 decimal)
5
liquidityPool.deposit(0, trader.address, toWei("1")) // please check permission of sender
6
7
// deposit 100 amount of collateral to account (deposit amount is 18 decimal)
8
liquidityPool.deposit(0, trader.address, toWei("100")) // please check permission of sender
Copied!

Sample Code

Margin
Last modified 23d ago