1.0.19 • Published 9 months ago

zeru-sdk v1.0.19

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Getting started

npm i zeru-sdk

SDK is used to generate the parameters to be passed to strategy contracts, to Open, Update, Close and Liquidate positions in both Lp and Maxi. The detailed parameters info is described below the example.

There's only a single function which needs to be called to get the parameters, following example illustrates it better.

Note: all the approvals must be made, before calling the getParams function!

Note: refer tasks/test/test-misc/test_zeroXAdapter.spec.ts for detailed example for using 0x to perform swaps (branch: staging-frontend).

Ex: to get parameters to open a liquidity provision position,

// typescript
import {
    Call,
    CONSTANTS,
    getParams,
    LPOpenPositionParams,
    SwapAdapter
} from "zeru-sdk";

const RPC = process.env.RPC || '';
const ZERO_X_API_KEY = process.env.ZERO_X_API_KEY || '';

async function main() {
  var openPositionParams: LPOpenPositionParams = {
    zeruOracle: '0x95a9003EA4B9b22506D79d73D7C4af4614317645',
    rpc: 'http://127.0.0.1:8545/', // for local testing
    token0: '0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03',
    token1: '0xd6D83aF58a19Cd14eF3CF6fe848C9A4d21e5727c',
    debtToken: '0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03',
    collateralAmount: "1000000000000000000",
    creditAmount: '0',
    collateralToken: '0x0E4aaF1351de4c0264C5c7056Ef3777b41BD8e03',
    leverage: '2000',
    fee: 500,
    uniswapV3Adapter: '0xE669542184E750Ae61230c4D96D5A093F100bf5D',
    depositFromLendingPool: false,
    aggregator: CONSTANTS.SWAP_ADAPTER.UNISWAP_TESTNET_BERA as SwapAdapter,
    user: '0xd4EeD53acbdF5bEBDF34eF1fD06b4aB2eCFA97d1',
    deadline: 10,
    swapData: [],
    lp: '0xDf2814fDFD64E2add6DAa64b03f98B89Df2592B2',
    quoter: "0xEcc0a6dbC0bb4D51E4F84A315a9e5B0438cAD4f0
  };
  
  const [ data1, data2, data3 ] = await getParams(CONSTANTS.CALL.LP_OPEN_POSITION as Call, openPositionParams);

  await collateralToken.connect(user.signer).approve(controller.address, collateralAmount);

  await controller.connect(user.signer).openPosition(2, data1, data2, data3);
}

the same way, to get parameters to call other strategy positions, you just have change the call type (CONSTANTS.CALL) and params (2nd parameter) and get the parameters. The return types are as follows,

Return types

LPOPReturnType = Promise<[string, string, string]>;

LPCPReturnType = Promise<string>;

LPLCReturnType = Promise<string>;

MAXIOPReturnType = Promise<[string, string, string]>;

MAXICPReturnType = Promise<string>;

MAXILCReturnType = Promise<string>;

UPReturnType = string;

Availaible constants

CONSTANTS.SWAP_ADAPTER = {
    ZERO_X_LOCAL: "0X_LOCAL",
    ZERO_X: "0X",
    UNISWAP_TESTNET: "UNISWAP_TESTNET",
    UNISWAP_TESTNET_BERA: "UNISWAP_TESTNET_BERA" // for Bera bartio
}

CONSTANTS.CALL = {
    LP_OPEN_POSITION: "LP_OPEN_POSITION",
    LP_UPDATE_POSITION: "LP_UPDATE_POSITION",
    LP_CLOSE_POSITION: "LP_CLOSE_POSITION",
    LP_LIQUIDATION_CALL: "LP_LIQUIDATION_CALL",
    MAXI_OPEN_POSITION: "MAXI_OPEN_POSITION",
    MAXI_UPDATE_POSITION: "MAXI_UPDATE_POSITION",
    MAXI_CLOSE_POSITION: "MAXI_CLOSE_POSITION",
    MAXI_LIQUIDATION_CALL: "MAXI_LIQUIDATION_CALL"    
}

Parameters info

All the functions accepts some common parameters, which is described as follows,

ParameterDescription
token0address of token0
token1address of token1
collateralTokenaddress of collateralToken
collateralAmountamount of collateral in full decimals
debtTokenaddress of debtToken
creditAmountamount of credit in full decimals
lowerTicklower tick of the Uniswap position
upperTickupper tick of the Uniswap position
amount0amount of token0 in full precision
amount1amount of token1 in full precision
leverageleverage in 3 decimals (ex: 3000 for 3x)
depositFromLendingPoolboolean representing whether the collatera should be deposited from lendingpool or not
feefee of the Uniswap pool to which the liquidity is being added
aggregatorone of the values of CONSTANTS.SWAP_ADAPTER representing which aggreagator to use to perform swaps
useraddress of user
lpaddress of liquidity provision
zeruOracleaddress of Zeru oracle
rpcrpc of network for which the calldata is being created
deadlinedeadline for Uniswap swaps in minutes (ex: 10 for 10 mins)
zeroXapikey0x api key
networkkey of CONSTANTS.NETWORKS, used in case if aggregator is CONSTANTS.SWAP_ADAPTER.ZERO_X can be ommitted incase of beraBartio
uniswapV3Adapteraddress of uniswapV3Adapter of Zeru
borrowIdborrow id of the position
ownerowner of the position
tokenIdtokenId of Uniswap position
receiverreceiver address incase of liquidation
maxiaddress of maxi contract
isShortboolean representing whether the position is short or long
swapDataarray of swap data to perform swaps using 0x.
quoteruniswap v3 quoter contract

LiquidityProvision open position params (LPOpenPositionParams)

{
    zeruOracle: string,
    rpc: string,
    token0: string,
    token1: string,
    debtToken: string,
    collateralAmount: string,
    creditAmount: string,
    collateralToken: string,
    leverage: number,
    fee: number,
    uniswapV3Adapter: string,
    depositFromLendingPool: boolean,
    aggregator: SwapAdapter,
    user: string,
    deadline: number,
    swapData: string[],
    lp: string,
    quoter: string
}

LiquidityProvision open position params (_LPOpenPositionParams), if actual 0x is used.

    token0: string,
    token1: string,
    collateralToken: string,
    collateralAmount: string,
    debtToken: string,
    creditAmount: string,
    lowerTick: number,
    upperTick: number,
    amount0: string,
    amount1: string,
    leverage: number,
    depositFromLendingPool: boolean,
    fee: number,
    aggregator: SwapAdapter,
    user: string,
    lp: string,
    zeruOracle: string,
    rpc: string,
    deadline: number,
    swapData: string[],
    uniswapV3Adapter: string,
    quoter: string

LiquidityProvision close position params (LPClosePositionParams)

{
    token0: string,
    token1: string,
    debtToken: string,
    collateralToken: string,
    borrowId: number,
    owner: string,
    aggregator: SwapAdapter,
    lp: string,
    tokenId: number,
    rpc: string,
    deadline: number,
    swapData: string[]
}

LiquidityProvision liquidation call params (LPLiquidationCallParams)

{
    token0: string,
    token1: string,
    debtToken: string,
    collateralToken: string,
    borrowId: number,
    owner: string,
    aggregator: SwapAdapter,
    lp: string,
    tokenId: number,
    rpc: string,
    deadline: number,
    swapData: string[],
    receiver: string
}

Maxi open position params (MaxiOpenPositionParams)

{
    token: string,
    collateralToken: string,
    collateralAmount: string,
    debtToken: string,
    creditAmount: string,
    isShort: boolean,
    leverage: number,
    depositFromLendingPool: boolean,
    aggregator: SwapAdapter,
    maxi: string,
    rpc: string,
    zeruOracle: string,
    deadline: number,
    swapData: string[]
}

Maxi close position params (MaxiClosePositionParams)

{
    token: string,
    debtToken: string,
    collateralToken: string,
    borrowId: number,
    user: string,
    aggregator: SwapAdapter,
    maxi: string,
    isShort: boolean,
    rpc: string,
    deadline: number,
    swapData: string[]
}

MaxiLiquidation call params (MaxiLiquidationCallParams)

{
    token: string,
    debtToken: string,
    collateralToken: string,
    borrowId: number,
    user: string,
    aggregator: SwapAdapter,
    maxi: string,
    isShort: boolean,
    rpc: string,
    deadline: number,
    swapData: string[],
    receiver: string
}

Update position params (for both Maxi and LP, UpdatePositionParams)

{
    borrowId: string,
    collateralToken: string,
    collateralAmount: string,
    creditAmount: string,
    depositFromLendingPool: boolean,
    user: string
}
1.0.19

9 months ago

1.0.18

9 months ago

1.0.17

9 months ago

1.0.16

9 months ago

1.0.15

9 months ago

1.0.14

9 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago