# @simpleweb/simple-defi

> The Simple DeFi SDK provides a quick and easy way to interact with DeFi platforms.

Latest version **0.2.1** (published 2022-06-17) · 0 weekly downloads

## Install

```sh
npm install @simpleweb/simple-defi
pnpm add @simpleweb/simple-defi
yarn add @simpleweb/simple-defi
bun add @simpleweb/simple-defi
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2022-06-17 |
| First published | 2022-06-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 3 |
| Unpacked size | 350 KB |
| Known vulnerabilities | 0 (+24 in 1 direct dependencies) |
| Install scripts | no |
| Author | Andy Kitt |
| Maintainers | simpleweb |

## Links

- npm: https://www.npmjs.com/package/@simpleweb/simple-defi
- Repository: https://github.com/simpleweb/simple-defi
- Homepage: https://github.com/simpleweb/simple-defi#readme
- Issues: https://github.com/simpleweb/simple-defi/issues
- npm.io page: https://npm.io/package/@simpleweb/simple-defi

## Dependencies (3)

- [cors](https://npm.io/package/cors.md) ^2.8.5
- [axios](https://npm.io/package/axios.md) ^0.27.2
- [ethers](https://npm.io/package/ethers.md) ^5.6.8

## Recent versions

- 0.2.1 (latest) — 2022-06-17
- 0.2.0 — 2022-06-16
- 0.1.1 — 2022-06-16
- 0.1.0 — 2022-06-14

## README

# Simple DeFi SDK

The Simple DeFi SDK provides a quick and easy way to interact with DeFi platforms.

## Installation

You can install the SDK with NPM or Yarn.

```shell
npm install @simpleweb/simple-defi
```

```shell
yarn add @simpleweb/simple-defi
```

## Getting started

```
import { HighRiskStrategy, LowRiskStrategy, deployHighRiskStrategy } from "@simpleweb/simple-defi";
```

### Creating a high risk strategy

The `deployHighRiskStrategy()` function is used to create an instance of the Simple DeFi contract on-chain.

A signer must be passed to the function.

### Creating a signer

Create an ethers `Signer` instance with an ethers `Web3Provider` which you'd typically get from a connected wallet.

```
const provider = new ethers.providers.Web3Provider(wallet?.provider);
signer = provider.getSigner();
```

A private key can also be used to create the signer.

```const signer = new ethers.Wallet(
  '0x...', //private key here.
  new ethers.providers.JsonRpcProvider(
    'https://polygon-rpc.com'
  )
);
```

### Calling the deploy function

```
const address = await deployHighRiskStrategy(signer);
```

The `deployHighRiskStrategy()` function returns the contract address of the deployed strategy. This should be passed as the strategy argument when instanciating a HighRiskStrategy.

## Creating an instance

If the deposit and withdraw functions are required, a `Signer` must be passed when instantiating the strategy object.

```
strategy = new HighRiskStrategy(
"0x1995e722310541B9ef62c2a0B2eF8f90d2dD43ED", //pot
"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", //WMATIC
"0x2791bca1f2de4661ed88a30c99a7a9449aa84174", //USDC
signer //signer
);
```

## Interacting with the strategy

### Deposit

Deposit funds by passing the amount of tokens in ether representation. Eg 0.5. The function will handle the conversion to Wei.

```
await strategy.deposit(0.5);
```

### Withdraw

Withdraw funds from the strategy by passing the amount
of LP tokens and the recipient of the withdraw funds.

Passing 0 to the function will withdraw all of an accounts funds.

```
await strategy.withdraw(0, account);
```

#### Getting a users LP token balance

```
const balance = await strategy.getAccountBalanceLP(account);
```

### Getting information about a strategy.

Information can be retrieved about a specific strategy without a wallet being connected.

```strategy = new HighRiskStrategy(
"0x1995e722310541B9ef62c2a0B2eF8f90d2dD43ED", //pot
"0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270", //WMATIC
"0x2791bca1f2de4661ed88a30c99a7a9449aa84174" //USDC
);
```

The `getPoolData()` function will return information about a specific pair in the deployed strategy.

```
const data = await strategy.getPoolData(account);
```

**Response**

```
{
    "apr": 0.7494295629569386,
    "pair": "QLP WMATIC / USDC",
    "totalBalanceUSD": 482.4149351818978,
    "totalBalanceLP": "169634743851095",
    "totalFeesCumulativeUSD": 4.735991426659753,
    "userBalanceUSD": 482.41086462871743
}
```

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