0.0.14 • Published 5 months ago

@defiedge/sdk v0.0.14

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

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()

paramtypedefaultrequired
userAddressstring-true
tokenIdx0 | 1-true
amountstring | number,-true
strategyAddressstring-true
jsonProviderJsonRpcProvider-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()

paramtypedefaultrequired
userAddressstring-true
tokenIdx0 | 1-true
strategyAddressstring-true
jsonProviderJsonRpcProvider-true
amountstring | numberundefinedfalse
overridesOverridesundefinedfalse
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()

paramtypedefaultrequired
strategyAddressstring-true
jsonProviderJsonRpcProvider-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()

paramtypedefaultrequired
userAddressstring-true
amount0string | number-true
amount1string | number-true
strategyAddressstring-true
jsonProviderJsonRpcProvider-true
overridesOverridesundefinedfalse
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()

paramtypedefaultrequired
accountAddressstring-true
strategyAddressstring-true
jsonProviderJsonRpcProvider-true
rawtrueundefinedfalse
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()

paramtypedefaultrequired
userAddressstring-true
sharesstring | number-true
strategyAddressstring-true
jsonProviderJsonRpcProvider-true
overridesOverridesundefinedfalse
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()

paramtypedefaultrequired
chainIdSupportedChainId-true
strategyAddressstring-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!