# Marginly SDK

#### 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
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.marginly.com/protocol-architecture/marginly-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
