Skip to content

Commit

Permalink
Examples (#108)
Browse files Browse the repository at this point in the history
* mint example

* revert npm

* example burn

* example burn

* doc: 2 new examples

* fix: pr comments

* feat: use storage overrides for burn

* fix

* fix

* fix

* feat: prettify

* wip: check 0x

* feat: enable slippage protection

* wip: remove wallet

* fix: typo

* fixes

* fix

* fix

* fixi

* f

* integrate 0x2 into swaps

* fix route 0x

* fix: router

* feat: buy&sell swap scripts

* fix: buy & sell select issues

* fixes & auto examples

* fix: remove contract

* fix: allowance check in scripts

* fix: issue

* fix: apprive

* ref: added more logs

* fix: remove logs

* fix

* fix: indent style

---------

Co-authored-by: Gulikovskiy <[email protected]>
  • Loading branch information
jn-lp and Gulikovskiy authored Sep 13, 2024
1 parent 8af1aea commit e562064
Show file tree
Hide file tree
Showing 127 changed files with 5,798 additions and 34,173 deletions.
168 changes: 0 additions & 168 deletions .eslintrc.json

This file was deleted.

113 changes: 5 additions & 108 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ Phuture SDK is a JS library for using functionality related to defi indices made

## Installation

Use the package manager [pnpm](https://pnpm.io/) to install SDK's dependencies.

```bash
pnpm i @phuture/sdk
npm i @phuture/sdk
```

## Usage
Expand All @@ -18,7 +16,6 @@ AutoRouter package has been created to find the best deal to buy or sell an inde

```typescript
import {
Account,
AutoRouter,
Erc20,
IndexRouter,
Expand All @@ -27,94 +24,18 @@ import {
import { ethers } from 'ethers'

const amount = '1000'
const account = new Account(
new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider()),
)
const account = new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider())

const indexRouter = new IndexRouter(account)
const zeroAggregator = new ZeroExAggregator()
const erc20 = new Erc20(account, 'ERC20_TOKEN_ADDRESS')

const autoRouter = new AutoRouter(indexRouter, zeroAggregator)

// handle buy
autoRouter.autoBuy(indexTokenInterface, amount, erc20)

// handle sell
autoRouter.autoBuy(indexTokenInterface, amount, erc20)
```

### Erc20

Erc20 package has been created to wrap the usual erc20 interface to use it

```typescript
import { Erc20 } from '@phuture/sdk'
import { ethers } from 'ethers'

const account = new Account(
new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider()),
)

const erc20 = new Erc20(account, 'ERC20_TOKEN_ADDRESS')

// get token's decimals
erc20.decimals()

// get token's symbol
erc20.symbol()
```

### Index

Index package has been created to wrap the Phuture's Index interface to use it

```typescript
import { Index } from '@phuture/sdk'
import { ethers } from 'ethers'

const account = new Account(
new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider()),
)

const indexPDI = new Index(account, 'INDEX_CONTRACT')

// get amount of input tokens to set underlying tokens amount
const { amounts, amountToSell } = indexPDI.scaleAmount(10000000000)
```

### Index Router

Index Router package has been created to use methods from Phuture's IndexRouter contract such as mint, burn and others.

```typescript
import { IndexRouter } from '@phuture/sdk'
import { ethers } from 'ethers'

const account = new Account(
new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider()),
)
const mintOptions = {
index: 'INDEX_ADDRESS',
amountInBase: 100000,
recipient: 'RECIPIENT_ADDRESS',
}
const burnOptions = {
quotes: [], // can get it from 0x aggregator
}

const indexRouter = new IndexRouter(account)

// run mint transaction
const mintTx = await indexRouter.mintSwap(mintOptions, 'AMOUNT_IN_INPUT_TOKEN')

// run burn transaction
const burnTx = await indexRouter.burnSwap(
'INDEX_ADDRESS',
'AMOUNT_IN_INDEX',
'RECIPIENT_ADDRESS',
burnOptions,
)
autoRouter.autoSell(indexTokenInterface, amount, erc20)
```

### 0x Aggregator
Expand All @@ -125,10 +46,8 @@ ZeroEx Aggregator package has been created to use methods related for managing P
import { Index, ZeroExAggregator } from '@phuture/sdk'
import { ethers } from 'ethers'

const account = new Account(
new ethers.Wallet('PRIVATE_KEY', ethers.getDefaultProvider()),
)
const indexPDI = new Index(account, 'INDEX_CONTRACT')
const amount = '1000000000000000';
const indexPDI = 'INDEX_CONTRACT';

const zeroAggregator = new ZeroExAggregator()

Expand All @@ -143,25 +62,3 @@ const {
amount,
)
```

### Subgraph

Subgraph package has been created to get data related to index and users that hold the index

```typescript
import { Subgraph } from '@phuture/sdk'

const client = Subgraph.fromUrl()

// get user data
const { data } = await client.query({
query: gql`
query User($userId: ID!) {
user(id: $userId) {
id
}
}
`,
variables: { userId },
})
```
64 changes: 0 additions & 64 deletions .github/workflows/ci.yml

This file was deleted.

Loading

0 comments on commit e562064

Please sign in to comment.