LogoLogo
  • Introduction
  • App
    • How to
      • Connect a wallet
      • Swap
      • Approve Spending
      • Open a Long Position
      • Open a Short Position
      • Withdraw Funds
      • Add Funds
      • Close Position
      • Increase Leverage
      • Pay Off Debt
      • Deposit Liquidity
      • Withdraw Liquidity
      • Add Liquidity
    • Smart contract addresses
      • Arbitrum
      • Blast
    • FAQ
  • Protocol mechanics
    • Providing Liquidity
    • Trading
    • Marginly MAX leverage specifics
  • Protocol architecture
    • Overview
    • Pools
      • Pool variables
      • Pool parameters
      • User positions
      • User actions
      • Pool Factory API
      • Pool API
    • TWAP oracle
    • Loan pricing
    • Errors
    • Marginly SDK
  • Router
    • Router architecture
    • Adapters
      • ApeSwapAdapter
      • BalancerAdapter
      • CamelotAdapter
      • KyberSwapClassicAdapter
      • KyberSwapElasticAdapter
      • UniswapV2Adapter
      • UniswapV3Adapter
      • WooFiAdapter
  • Risk Management
    • Risk Management Overview
    • Keeper service and smart contract description
    • Keeper contract architecture
    • Liquidations and Deleveraging
    • Volatility as risk proxy
    • Insurance pool
    • Shutdown mode
  • Economics
    • Marginly economics
  • Future plans
    • Beyond Marginly v1
    • Some ideas for Marginly v2
  • Trading Contest FAQ
  • Github
  • Audit
Powered by GitBook
On this page
  1. Protocol architecture

Marginly SDK

Allows to biuld contract calls and use math calculations for applications on top of Marginly.

MarginlyPoolExecute

Contains an abstract class with methods to generate calls input for Marginly contracts.

import { BigNumber, parseUnits } from 'ethers';
import { convertPriceHumanToX96, MarginlyPoolExecute } from '@eq-lab/marginly-sdk';

const wethDecimals = BigNumber.from(18);
const usdcDecimals = BigNumber.from(6);

const depositBaseAmount = parseUnits('1', wethDecimals);
const longAmount = parseUnits('10', wethDecimals);
const limitPriceX96 = convertPriceHumanToX96(
    BigNumber.from(2000), 
    wethDecimals, 
    usdcDecimals
);

const { method, args, value } = MarginlyPoolExecute.depositBaseAndLong(
    depositBaseAmount, 
    longAmount, 
    limitPriceX96
);

MarginlyPoolPosition

This class is used to construct a Marginly position representation with real values from pools inner discounted ones. Moreover it contains methods for position characteristics calculations such as:

  • leverage

  • liquidation price

  • available withdraw amounts

MarginlyPoolMath

Contains low level math, used in contract calculations and other modules of sdk including:

  • FP96 math

  • discounted-to-real values conversions

  • X96 price conversions

  • low level position/pool parameters calculations (e.g. leverage, liquidation price)

Tests

Run tests

yarn test
PreviousErrorsNextRouter architecture

Last updated 1 year ago