# @defiedge/sdk

> A defiedge SDk to deposit and remove lp

Latest version **0.0.14** (published 2024-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install @defiedge/sdk
pnpm add @defiedge/sdk
yarn add @defiedge/sdk
bun add @defiedge/sdk
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2024-07-27 |
| First published | 2023-04-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 23 |
| Unpacked size | 966.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Defiedge |
| Maintainers | wrong.chain, pranavraut |
| Keywords | defiedge, sdk |

## Links

- npm: https://www.npmjs.com/package/@defiedge/sdk
- Repository: https://github.com/unbound-finance/defiedge-sdk
- Homepage: https://github.com/unbound-finance/defiedge-sdk#readme
- Issues: https://github.com/unbound-finance/defiedge-sdk/issues
- npm.io page: https://npm.io/package/@defiedge/sdk

## Dependencies (23)

- [jsbi](https://npm.io/package/jsbi.md) ^3.1.5
- [ethers](https://npm.io/package/ethers.md) ^5.6.8
- [global](https://npm.io/package/global.md) ^4.4.0
- [graphql](https://npm.io/package/graphql.md) ^16.8.1
- [typechain](https://npm.io/package/typechain.md) ^8.0.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) ^3.1.5
- [bignumber.js](https://npm.io/package/bignumber.js.md) ^9.0.1
- [@uniswap/v3-sdk](https://npm.io/package/@uniswap/v3-sdk.md) ^3.9.0
- [ethereumjs-util](https://npm.io/package/ethereumjs-util.md) ^7.1.4
- [graphql-request](https://npm.io/package/graphql-request.md) ^6.1.0
- [@uniswap/v3-core](https://npm.io/package/@uniswap/v3-core.md) ^1.0.1
- [@uniswap/sdk-core](https://npm.io/package/@uniswap/sdk-core.md) ^3.1.0
- [@ethersproject/bytes](https://npm.io/package/@ethersproject/bytes.md) ^5.6.1
- [@ethersproject/units](https://npm.io/package/@ethersproject/units.md) ^5.6.1
- [@typechain/ethers-v5](https://npm.io/package/@typechain/ethers-v5.md) ^10.0.0
- [@ethersproject/wallet](https://npm.io/package/@ethersproject/wallet.md) ^5.6.2
- [@uniswap/v3-periphery](https://npm.io/package/@uniswap/v3-periphery.md) 1.3.0
- [@ethersproject/address](https://npm.io/package/@ethersproject/address.md) ^5.6.0
- [@ethersproject/bignumber](https://npm.io/package/@ethersproject/bignumber.md) ^5.6.0
- [@ethersproject/constants](https://npm.io/package/@ethersproject/constants.md) ^5.6.0
- [@ethersproject/contracts](https://npm.io/package/@ethersproject/contracts.md) ^5.6.2
- [@ethersproject/providers](https://npm.io/package/@ethersproject/providers.md) ^5.6.5
- [@ethersproject/abstract-signer](https://npm.io/package/@ethersproject/abstract-signer.md) ^5.6.2

## Recent versions

- 0.0.14 (latest) — 2024-07-27
- 0.0.13 — 2024-05-30
- 0.0.12 — 2024-05-30
- 0.0.11 — 2023-12-04
- 0.0.10 — 2023-12-01
- 0.0.9-b — 2023-11-18
- 0.0.9-a — 2023-11-14
- 0.0.9 — 2023-11-14
- 0.0.8-c — 2023-11-08
- 0.0.8-b — 2023-11-07
- 0.0.8-a — 2023-11-06
- 0.0.8 — 2023-11-04
- 0.0.7-b — 2023-10-23
- 0.0.7-a — 2023-10-09
- 0.0.7 — 2023-09-22
- … 15 more at https://npm.io/package/@defiedge/sdk/versions

## README

![Deifedge Logo](https://app.defiedge.io/favicon.png)
# @defiedge/sdk
![MIT License](https://badgen.net/badge/license/MIT/blue) ![minified gzipped size](https://badgen.net/bundlephobia/minzip/@defiedge/sdk@0.0.1-a/)

This sdk contains collection of functions to interact with defiedge's smart contract.

## Table of Contents

* [__Installation__](#Installation)
* [__Usage__](#Usage)
     * [__Strategy Functions__](#Strategy)
        * [`isStrategyTokenApproved()`](#1-isStrategyTokenApproved)
        * [`approveStrategyToken()`](#2-approveStrategyToken)
        * [`getLiquidityRatio()`](#3-getLiquidityRatio)
        * [`depositLP()`](#4-depositLP)
        * [`getUserDeshareBalance()`](#5-getUserDeshareBalance)
        * [`removeLP()`](#6-removeLP)
    * [__Metadata Information__](#MetaInfo)
        * [`getStrategyMetaData()`](#1-getStrategyMetaData)



## Installation
Install with
```bash
yarn add @defiedge/sdk
```
or
```bash
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true

<br/>

```typescript
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
| amount   | string \| number | undefined | false | 
| overrides         | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7)  | undefined | false

<br/>

```typescript
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true

<br/>

```typescript
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
| overrides         | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7)  | undefined | false

<br/>

```typescript
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
| raw   | true | undefined | false | 

<br/>

```typescript
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](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
| overrides         | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7)  | undefined | false

<br/>

```typescript
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
)
```

<div id="MetaInfo"></div>

### Metadata Information

#### 1. `getStrategyMetaData()`
| param | type |  default | required
| -------- | -------- | -------- | --------
| chainId              | SupportedChainId | - | true |
| strategyAddress      | string | - | true

<br/>

```typescript
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](https://documenter.getpostman.com/view/16281910/2s93XvWk5h).

## Types

### SupportedChainId

```typescript
enum SupportedChainId {
  arbitrum = 42161,
  base = 8453,
  bsc = 56,
  mainnet = 1,
  mantle = 5000,
  moonbeam = 1284,
  optimism = 10,
  polygon = 137,
}
```

### Strategy (metadata)

```typescript
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!

---
_Source: https://npm.io/package/@defiedge/sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
