npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@zerufinance/strat-utils

v1.0.1

Published

SDK with all utility functions to integrate zeru

Downloads

1

Readme

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 function!

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,
    zeroXapikey: '',
    network: "" as Network,
    lp: '0xDf2814fDFD64E2add6DAa64b03f98B89Df2592B2'
  };
  
  const { data1, data2, data3 } = await getParams(CONSTANTS.CALL.LP_OPEN_POSITION as Call, openPositionParams) as { data1: string; data2: string; data3: string; };

  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<{
    data1: string,
    data2: string,
    data3: 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_LOCAL: "UNISWAP_LOCAL",
    UNISWAP_TESTNET: "UNISWAP_TESTNET",
    UNISWAP_TESTNET_BERA: "UNISWAP_TESTNET_BERA" // for Bera bartio
}

CONSTANTS.NETWORKS = {
    ARBITRUM: "ARBITRUM",
    AVALANCHE: "AVALANCHE",
    BASE: "BASE",
    BSC: "BSC",
    CELO: "CELO",
    FANTOM: "FANTOM",
    OPTIMISM: "OPTIMISM",
    POLYGON: "POLYGON",
    ETHEREUM_MAINNET: "ETHEREUM_MAINNET",
    ETHEREUM_SEPOLIA: "ETHEREUM_SEPOLIA"
};

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,

| Parameter | Description | |----------|----------| | token0 | address of token0 | | token1 | address of token1 | | collateralToken | address of collateralToken| | collateralAmount | amount of collateral in full decimals| | debtToken | address of debtToken| | creditAmount | amount of credit in full decimals | | lowerTick | lower tick of the Uniswap position | | upperTick | upper tick of the Uniswap position | | amount0 | amount of token0 in full precision | | amount1 | amount of token1 in full precision | |leverage | leverage in 3 decimals (ex: 3000 for 3x)| | depositFromLendingPool | boolean representing whether the collatera should be deposited from lendingpool or not| | fee | fee of the Uniswap pool to which the liquidity is being added| |aggregator | one of the values of CONSTANTS.SWAP_ADAPTER representing which aggreagator to use to perform swaps | |user | address of user | | lp | address of liquidity provision | |zeruOracle | address of Zeru oracle | | rpc | rpc of network for which the calldata is being created| |deadline | deadline for Uniswap swaps in minutes (ex: 10 for 10 mins) | | zeroXapikey | 0x api key | | network | key of CONSTANTS.NETWORKS, used in case if aggregator is CONSTANTS.SWAP_ADAPTER.ZERO_X can be ommitted incase of beraBartio| |uniswapV3Adapter | address of uniswapV3Adapter of Zeru | | borrowId | borrow id of the position | | owner | owner of the position | | tokenId | tokenId of Uniswap position | | receiver | receiver address incase of liquidation | | maxi | address of maxi contract| |isShort | boolean representing whether the position is short or long |

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,
    zeroXapikey: string,
    network: Network,
    lp: 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,
    zeroXapikey: string,
    network: Network
}

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,
    zeroXapikey: string,
    network: Network,
    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,
    zeroXapikey: string,
    network: Network
}

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,
    zeroXapikey: string,
    network: Network
}

MaxiLiquidation call params (MaxiLiquidationCallParams)

{
    token: string,
    debtToken: string,
    collateralToken: string,
    borrowId: number,
    user: string,
    aggregator: SwapAdapter,
    maxi: string,
    isShort: boolean,
    rpc: string,
    deadline: number,
    zeroXapikey: string,
    network: Network,
    receiver: string
}

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

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