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

@defiedge/sdk

v0.0.13

Published

A defiedge SDk to deposit and remove lp

Downloads

388

Readme

Deifedge Logo

@defiedge/sdk

MIT License minified gzipped size

This sdk contains collection of functions to interact with defiedge's smart contract.

Table of Contents

Installation

Install with

yarn add @defiedge/sdk

or

npm install @defiedge/sdk

Usage

Strategy

1. isStrategyTokenApproved()

| param | type | default | required | -------- | -------- | -------- | -------- | userAddress | string | - | true | tokenIdx | 0 | 1 | - | true | amount | string | number, | - | true | | strategyAddress | string | - | true | | jsonProvider | JsonRpcProvider | - | true

import { Web3Provider } from '@ethersproject/providers';
import { isToken0Approved } from '@defiedge/sdk';

const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100

const isToken0Approved: boolean = await isStrategyTokenApproved(
    accountAddress,
    0, // token idx can be 0 or 1
    amount,
    strategyAddress, 
    web3Provider
)

2. approveStrategyToken()

| param | type | default | required | -------- | -------- | -------- | -------- | userAddress | string | - | true | tokenIdx | 0 | 1 | - | true | strategyAddress | string | - | true | | jsonProvider | JsonRpcProvider | - | true | amount | string | number | undefined | false | | overrides | Overrides | undefined | false

import { Web3Provider } from '@ethersproject/providers';
import { approveStrategyToken } from '@defiedge/sdk';

const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"
const amount = 100

const txnDetails = await approveStrategyToken(
    accountAddress, 
    0, // token idx can be 0 or 1
    strategyAddress, 
    provider,
    amount // (optional)
);

await txnDetails.wait(); 

// can now deposit token0 
// ...

3. getLiquidityRatio()

| param | type | default | required | -------- | -------- | -------- | -------- | strategyAddress | string | - | true | | jsonProvider | JsonRpcProvider | - | true

import { Web3Provider } from '@ethersproject/providers';
import { getLiquidityRatio } from '@defiedge/sdk';

const provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"

const ratio = await getLiquidityRatio(
    strategyAddress, 
    web3Provider,
)

const amount0 = 100
const amount1 = amount0 * ratio

// - or - 

const amount1 = 100
const amount0 = amount1 * 1 / ratio 

4. depositLP()

| param | type | default | required | -------- | -------- | -------- | -------- | userAddress | string | - | true | amount0 | string | number | - | true | amount1 | string | number | - | true | strategyAddress | string | - | true | jsonProvider | JsonRpcProvider | - | true | overrides | Overrides | undefined | false

import { Web3Provider } from '@ethersproject/providers';
import { depositLP } from '@defiedge/sdk';

const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"

const amount0 = 100
const amount1 = amount0 * ratio // getLiquidityRatio()
 
const txnDetails = await depositLP(
    accountAddress,
    amount0, // can be 0 when only depositing amount1
    amount1, // can be 0 when only depositing amount0
    strategyAddress, 
    web3Provider
)

5. getUserDeshareBalance()

| param | type | default | required | -------- | -------- | -------- | -------- | accountAddress | string | - | true | | strategyAddress | string | - | true | | jsonProvider | JsonRpcProvider | - | true | raw | true | undefined | false |

import { Web3Provider } from '@ethersproject/providers';
import { getUserDeshareBalance } from '@defiedge/sdk';

const provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"

const deShare: string = await getUserDeshareBalance(
    strategyAddress, 
    accountAddress,
    web3Provider
)

// - or - 

const deShareBN: BigNumber = await getUserDeshareBalance(
    strategyAddress, 
    accountAddress,
    web3Provider,
    true
)

6. removeLP()

| param | type | default | required | -------- | -------- | -------- | -------- | userAddress | string | - | true | shares | string | number | - | true | strategyAddress | string | - | true | jsonProvider | JsonRpcProvider | - | true | overrides | Overrides | undefined | false

import { Web3Provider } from '@ethersproject/providers';
import { removeLP, getUserDeshareBalance } from '@defiedge/sdk';

const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
const strategyAddress = "0xc3ad...72bf9eb"
const accountAddress = "0xaaaa...aaaaaa"

const totalUserShare: string = getUserDeshareBalance(
    accountAddress,
    strategyAddress, 
    web3Provider
)

let shares = Number(totalUserShare) * 0.5 // 50% of user deshare balance

const txnDetails = await removeLP(
    accountAddress,
    shares, // de shares
    strategyAddress, 
    web3Provider
)

Metadata Information

1. getStrategyMetaData()

| param | type | default | required | -------- | -------- | -------- | -------- | chainId | SupportedChainId | - | true | | strategyAddress | string | - | true

import { getStrategyMetaData } from '@defiedge/sdk';

const strategyAddress = '0xc3ad...72bf9eb'

const strategy: Strategy = await getStrategyMetaData(
    SupportedChainId.bsc, 
    strategyAddress
)

For api detail and other functions please refer to this postman documentation.

Types

SupportedChainId

enum SupportedChainId {
  arbitrum = 42161,
  base = 8453,
  bsc = 56,
  mainnet = 1,
  mantle = 5000,
  moonbeam = 1284,
  optimism = 10,
  polygon = 137,
}

Strategy (metadata)

type Currency = 'USD' | 'BTC' | 'MATIC' | 'ETH';

interface Strategy {
  id: string;
  title: string;
  subTitle: string;
  description: string;
  updatedAt: string;
  network: string;
  sharePrice: number;
  address: string;
  aum: number;
  createdAt: string;
  feesApr: Record<Currency, number>;
  sevenDayApy: Record<Currency, number>;
  sinceInception: Record<Currency, number>;
  oneDayApy: Record<Currency, number>;
}

This version of @defiedge/sdk is still in beta, so unfortunately documentation is pretty sparse at the moment. Comments and the source code itself are the best ways to get an idea of what's going on. More thorough documentation is a priority as development continues!