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

@divergence-protocol/diver-sdk

v1.4.4

Published

## PositionManager

Downloads

153

Readme

Diver SDK

PositionManager

Multicall

import { PositionManager } from './positionManager'

const data1 = PositionManager.createBattleCallParameters(args1);
const data2 = PositionManager.mintCallParameters(arg2);

const {calldata, decode} = PositionManager.multicall([data1, data2])

Create battle

import {ethers} from 'ethers'
import {PositionManager} from "./PositionManager";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const positionAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const args = {
    oracle: '',
    battleKey: {
        collateralTokenAddr: '',
        underlying: '',
        periodType: PeriodType.WEEK,
        strikeValue: 0
    },
    sqrtPriceX96: '',
}
const data = PositionManager.createBattleCallParameters(args);

provider.getSiger().sendTransaction({
    from: '',
    to: positionAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Mint

import {ethers} from 'ethers'
import {PositionManager} from "./PositionManager";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const positionAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const args = {
    battleKey: {
        collateralTokenAddr: '',
        underlying: '',
        periodType: PeriodType.WEEK,
        strikeValue: 0
    },
    tickLower: 0,
    tickUpper: 0,
    collateralDelta: 0,
    amountSpearMin: 0,
    amountShieldMin: 0,
    recipient: '',
    deadline: ''
}
const data = PositionManager.mintCallParameters(args);

provider.getSiger().sendTransaction({
    from: '',
    to: positionAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Burn

import {ethers} from 'ethers'
import {PositionManager} from "./PositionManager";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const positionAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const battleKey =  {
    collateralTokenAddr: '',
    underlying: '',
    periodType: PeriodType.WEEK,
    strikeValue: 0
}
const tokenId = 0

const data = PositionManager.burnCallParameters(battleKey, tokenId);

provider.getSiger().sendTransaction({
    from: '',
    to: positionAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Withdraw

import {ethers} from 'ethers'
import {PositionManager} from "./PositionManager";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const positionAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const battleKey =  {
    collateralTokenAddr: '',
    underlying: '',
    periodType: PeriodType.WEEK,
    strikeValue: 0
}
const tokenId = 0

const data = PositionManager.withdrawObligationCallParameters(battleKey, tokenId);

provider.getSiger().sendTransaction({
    from: '',
    to: positionAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Trade

import {ethers} from 'ethers'
import {PositionManager} from "./PositionManager";
import {TradeAction} from "./enum";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const positionAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const args = {
    battleKey: {
        collateralTokenAddr: '',
        underlying: '',
        periodType: PeriodType.WEEK,
        strikeValue: 0
    },
    action: TradeAction.BUY_SHIELD,
    amountSpecified: 0,
    recipient: '',
    amountOutMin: 0,
    sqrtPriceLimitX96: '',
    deadline: ''
}
const data = PositionManager.tradeCallParameters(args);

provider.getSiger().sendTransaction({
    from: '',
    to: positionAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Battle

Claim

import {ethers} from 'ethers'
import {Battler} from "./Battle";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const address = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const data = Battle.claimCallParameters(10);

provider.getSiger().sendTransaction({
    from: '',
    to: address,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

CurrentSqrtPriceX96

import {ethers} from 'ethers'
import {Quoter} from "./Quoter";
import {Battle} from "./Battle";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const battleAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const data = Battle.currentSqrtPriceX96();

provider.call({
    to: battleAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Get user balance

import {Battle} from "./Battle";

const ri = 2
const account = ''
const data1 = Battle.spearBalanceOf(ri, account);

const data2 = Battle.shieldBalanceOf(ri, account)

Helper

// 1. get x96 sqrt price, input is shield price for collateral
getSqrtPriceX96FromPrice(0.4);
// 2. get shield price from x96 sqrt price
getPriceFromSqrtPriceX96("1000000")
// 3. get shield price from tick
getPriceFromTick(8)
// 4. get tick from shield price
getTickFromPrice(0.4)
// 5. get tick from  sqrt price x96
getTickFromSqrtPriceX96("100000000")
// 6. get sqrt price from tick
getSqrtPriceX96FromTick(8)

// 3. calculate price imapct
const currentSqrtPriceX96 = "1000000000000"
const inputAmount = "1000000"
const outputAmount = "200000000000"
const isBuy = true
const impact = calculatePriceImpact(currentSqrtPriceX96, inputAmount, outputAmount, isBuy)

Quoter

quoteExactInput

import {ethers} from 'ethers'
import {Quoter} from "./Quoter";

const provider = new ethers.providers.JsonRpcProvider('<YOUR-ENDPOINT-HERE>')

const quoterAddress = '0x8ad599c3A0ff1De082011EFDDc58f1908eb6e6D8'

const action = 0 // 0: buy spear, 1: sell spear, 2: buy shield, 3: sell shield
const price = 0.4
const amountSpecified = "100000000"
const battleAddress = ""
const data = Quoter.quoteExactInputCallParameters(action, price, amountSpecified, battleAddress);

provider.call({
    to: quoterAddress,
    data: data
}).then(res => console.log(res)).catch(e => console.error(e))

Oracle

Get round ts

import { Oracle } from './oracle'
import { PeriodType } from './enum'

const { calldata, decode } = Oracle.getRoundTS(PeriodType.BI_WEEK)

provider.call({
  to: oracleAddress,
  data: calldata
}).then(res => {
  const result = decode(res)
}).catch(e => console.error(e))