import { ethers } from 'ethers'
const provider = ethers.getDefaultProvider('homestead')
Get a user's position size
import { getContractReader, getAccountStorage } from '@mcdex/mai2.js'
const perpetualAddress = '0x220a9f0DD581cbc58fcFb907De0454cBF3777f76' // NOTE: this is a Perpetual address that may change in the future. Check https://github.com/mcdexio/mai-protocol-v2 for online addresses
const userAddress = '' // Paste your ETH address here
const contractReader = await getContractReader(provider)
const p = await getAccountStorage(contractReader, perpetualAddress, userAddress)
console.log(p.positionSide)
console.log(p.positionSize.toFixed())
Get a user's margin balance
import { getMarginBalance } from '@mcdex/mai2.js'
const m = await getMarginBalance(contractReader, perpetualAddress, userAddress)
console.log(m.toFixed())
Test
npm run test
mai2.js devloper only: prepare an env for unit tests