Skip to content

Commit

Permalink
docs: organize api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sehyunc committed Sep 10, 2024
1 parent 4a9ee13 commit 318608f
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 64 deletions.
4 changes: 4 additions & 0 deletions docs.renegade.fi/docs/technical-reference/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "Technical Reference",
"position": 4
}
34 changes: 34 additions & 0 deletions docs.renegade.fi/docs/technical-reference/contract-addresses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
sidebar_position: 1
description: Getting started with the Renegade Typescript SDK.
---

# Useful Addresses

## Contract Addresses

| Contract | Arbitrum One Address | Arbitrum Sepolia Address |
|----------|------------------------|----------------------------|
| [Darkpool](https://github.com/renegade-fi/renegade-contracts/blob/main/contracts-stylus/src/contracts/darkpool.rs) | 0x30bd8eab29181f790d7e495786d4b96d7afdc518 | 0x9af58f1ff20ab22e819e40b57ffd784d115a9ef5 |
| [Permit2](https://github.com/Uniswap/permit2) | 0x000000000022D473030F116dDEE9F6B43aC78BA3 | 0x9458198bcc289c42e460cb8ca143e5854f734442 |

## Relayer and Price Reporter Addresses

| Name | Arbitrum One Address | Arbitrum Sepolia Address |
|----------|------------------------|----------------------------|
| [Renegade](https://github.com/renegade-fi/renegade) | mainnet.cluster0.renegade.fi | testnet.cluster0.renegade.fi |
| [Price Reporter](https://github.com/renegade-fi/renegade/tree/main/workers/price-reporter) | mainnet.price-reporter.renegade.fi | testnet.price-reporter.renegade.fi |

## Whitelisted Tokens

| Arbitrum One Token Mapping | Arbitrum Sepolia Token Mapping |
|----------------------------|----------------------------|
| [View on Github](https://github.com/renegade-fi/token-mappings/blob/main/mainnet.json) | [View on Github](https://github.com/renegade-fi/token-mappings/blob/main/testnet.json) |

:::note
In the early days of the protocol, certain tokens are whitelisted.
:::

## Arbitrum public RPC endpoints

Refer to the [Arbitrum Docs](https://docs.arbitrum.io/build-decentralized-apps/reference/node-providers) for information such as the RPC endpoints, chain ID, and block explorer.
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,28 @@ To add the Renegade SDK to your project, install the required packages.
```bash
npm install @renegade-fi/node@latest @wagmi/core viem@2.x
```

This SDK is responsible for interacting with a relayer. Some actions, such as `createWallet` or `deposit`, require using your Ethereum wallet to sign messages or approve tokens. To perform these actions, we recommend using [wagmi](https://wagmi.sh/core/getting-started) and [viem](https://viem.sh/docs/getting-started).

### Create Config

Create and export a new Renegade config using `createConfig`.
Create and export a new Renegade config using `createConfig`.

```jsx
import { createConfig } from "@renegade-fi/node"
import { createPublicClient, http } from 'viem'
import { arbitrum } from 'viem/chains'

const viemClient = createPublicClient({
chain: arbitrum,
transport: http()
})

export const config = createConfig({
darkPoolAddress: "0x30bd8eab29181f790d7e495786d4b96d7afdc518",
priceReporterUrl: "mainnet.price-reporter.renegade.fi",
relayerUrl: "mainnet.cluster0.renegade.fi",
viemClient: publicClient,
viemClient,
})
```

Expand All @@ -39,16 +49,10 @@ Now, you can pass the `config` to use actions.

```jsx
import { backOfQueueWallet } from "@renegade-fi/node"
import { createConfig } from "@renegade-fi/node"

const config = createConfig({
darkPoolAddress: "0x30bd8eab29181f790d7e495786d4b96d7afdc518",
priceReporterUrl: "mainnet.price-reporter.renegade.fi",
relayerUrl: "mainnet.cluster0.renegade.fi",
viemClient: publicClient,
})

const wallet = await getBackOfQueueWallet(config)

console.log("Wallet balances: ", wallet.balances)
```

### Environment Setup
Expand All @@ -59,37 +63,96 @@ You must expose a `TOKEN_MAPPING` environment variable to use the SDK. You can d

:::

- Node Version
- We recommend using Node v22
- Typescript config
- Take a look at this [example repo](https://stackblitz.com/edit/nodets-bnycf1?file=tsconfig.json&view=editor) for a reference `tsconfig.json`.


- Helpful values to know
- Mainnet (Arbitrum One)
- Darkpool contract address: `0x30bd8eab29181f790d7e495786d4b96d7afdc518`
- Permit2 contract address: `0x000000000022D473030F116dDEE9F6B43aC78BA3`
- Chain ID: `42161`
- Chain name: `Arbitrum One`
- Chain RPC URL: [`https://arb1.arbitrum.io/rpc`](https://arb1.arbitrum.io/rpc)
- You should use your own Alchemy / Infura RPC url here instead
- Token mapping: download JSON [here](https://github.com/renegade-fi/token-mappings/raw/main/mainnet.json)
- Renegade Price Reporter: [`mainnet.price-reporter.renegade.fi`](http://mainnet.price-reporter.renegade.fi/)
- Renegade Relayer: [`mainnet.cluster0.renegade.fi`](http://mainnet.cluster0.renegade.fi/)
- Testnet (Arbitrum Sepolia)
- Darkpool contract address: `0x9af58f1ff20ab22e819e40b57ffd784d115a9ef5`
- Permit2 contract address: `0x9458198bcc289c42e460cb8ca143e5854f734442`
- Chain ID: `421614`
- Chain name: `Arbitrum Sepolia`
- Chain RPC URL: [`https://sepolia-rollup.arbitrum.io/rpc`](https://sepolia-rollup.arbitrum.io/rpc)
- You should use your own Alchemy / Infura RPC url here instead
- Token mapping: download JSON [here](https://github.com/renegade-fi/token-mappings/raw/main/testnet.json)
- Renegade Price Reporter: [`testnet.price-reporter.renegade.fi`](http://testnet.price-reporter.renegade.fi/)
- Renegade Relayer: [`testnet.cluster0.renegade.fi`](http://testnet.cluster0.renegade.fi/)
We recommend using Node v22 as it [provides a WebSocket client to Node.js](https://nodejs.org/en/blog/announcements/v22-release-announce#websocket) without external dependencies. If you are on a lower version of Node, you should provide your own WebSocket client, such as `ws`.

This SDK makes exclusive use of ES Modules. Check out [this guide](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) for more info on ESM support and Frequently Asked Questions across various tools and setups.

For Typescript configuration, check out this [example repo](https://stackblitz.com/edit/nodets-bnycf1?file=tsconfig.json&view=editor) for a reference `tsconfig.json`.

## Protocol Core Concepts

### Relayer
A relayer node is resposible for the matching and settlement of orders. Each individual relayer manages one or more wallets, meaning they are able to view the plaintext wallet but are unable to modify a wallet.

:::note
Relayers manage task queues for each wallet, which means you do not necessarily need to wait for a task to complete before creating a new task. This is why two functions exist for fetching a wallet's state: [`getWalletFromRelayer`](#getwalletfromrelayer) (current wallet state) and [`getBackOfQueueWallet`](#getbackofqueuewallet) (wallet state after current task queue is cleared).
:::

### Wallet
A wallet is a data structure that contains a user's balances, orders, and keys. To create a wallet, you must sign a message using your Ethereum wallet to generate a derivation key. This derivation key is used to derive the required fields of a wallet, such as the keychain. Learn more about keychains [here](../advanced-concepts/super-relayers.md).

## SDK Core Concepts

### Config
The `Config` object is responsible for storing Renegade wallet state and internals. Most actions require a `Config` object to be passed as the first argument, as it contains the derivation key used to derive keys used to sign API requests and wallet updates.

### Actions
This SDK exposes actions that are used to interact with a relayer, such as fetching a wallet's state or placing an order. Actions that access private wallet data require API authorization headers, which are automatically added for you when using the SDK. Browse the list of available actions [below](#actions).

### Types
This SDK provides types for various data structures used in the API.

- [`Wallet`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/wallet.ts#L34): contains a user's balances, orders, and keys
- [`Order`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/order.ts#L1): contains an order's parameters
- [`Balance`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/wallet.ts#L15): contains the amount of an ERC-20 token a user has in addition to the fee amount owed for that token.
- [`KeyChain`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/wallet.ts#L22): contains a user's key hierarchy as defined [here](../advanced-concepts/super-relayers.md).
- [`OrderMetadata`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/order.ts#L19): contains useful metadata such as the order's ID, status, creation time, and [`PartialOrderFills`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/order.ts#L27) since creation.
- [`Task`](https://github.com/renegade-fi/typescript-sdk/blob/bd7455916d3b69f35511337e2cf6b681247dd654/packages/core/src/types/task.ts#L1): contains a task's ID, status, type, and creation time.

### Token

The `Token` class is used to store ERC-20 token metadata. It encapsulates information such as the token's address, name, decimals, and ticker symbol. This metadata is sourced from the `TOKEN_MAPPING` defined in your `.env` file.

**Import**

```js
import { Token } from "@renegade-fi/node"
```

**Properties**

- `address`: The address of the ERC-20 token.
- `name`: The name of the token.
- `decimals`: The number of decimals the token uses.
- `ticker`: The ticker symbol of the token.

**Static Methods**
```js
static findByTicker(ticker: string): Token
```
**Returns**
- `Token` - The Token instance matching the given ticker.

**Throws**
- `Error` - If no token with the given ticker is found in the TOKEN_MAPPING.

```js
static findByAddress(address: `0x${string}`): Token
```
**Returns**
- `Token` - The Token instance matching the given address.

**Throws**
- `Error` - If no token with the given address is found in the TOKEN_MAPPING.


**Usage**

```jsx
import { Token } from "@renegade-fi/node"

const usdc = Token.findByTicker("USDC")

console.log("USDC address: ", usdc.address)

const weth = Token.findByAddress("0xaf88d065e77c8cc2239327c5edb3a432268e5831")

console.log("WETH address: ", weth.address)
```

## Configuration

### `createConfig`
### createConfig

**Import**

Expand Down Expand Up @@ -140,7 +203,7 @@ import { type Config } from '@renegade-fi/node'

## Actions

### `createWallet`
### createWallet

Action for starting a `create wallet` task on your connected relayer.

Expand Down Expand Up @@ -194,7 +257,7 @@ An error may be thrown if:
- a `seed` does not exist in the provided `config`
- a wallet with the same wallet ID already exists in the state of the connected relayer

### `lookupWallet`
### lookupWallet

Action for starting a `lookup wallet` task on your connected relayer.

Expand Down Expand Up @@ -242,7 +305,7 @@ An error may be thrown if:
- a wallet with the same wallet ID already exists in the state of the connected relayer
- a wallet was not able to be found on-chain

### `getWalletFromRelayer`
### getWalletFromRelayer

Action for fetching a wallet’s state from your connected relayer.

Expand Down Expand Up @@ -272,11 +335,13 @@ An error may be thrown if
- the wallet is not currently indexed by your connected relayer, in which case you should `createWallet` or `lookupWallet`
- the API request authorization is incorrect / missing

### `getBackOfQueueWallet`
### getBackOfQueueWallet

Action for fetching the back of queue wallet state from your connected relayer.

> Your connected relayer will manage a queue of tasks for you. By fetching the back of queue wallet, you are fetching your wallet state *after* all tasks in the queue have completed. If a task fails, all subsequent tasks will transition to the `Failed` state and your queue will be cleared.
:::note
Your connected relayer will manage a queue of tasks for you. By fetching the back of queue wallet, you are fetching your wallet state *after* all tasks in the queue have completed, which may not be the case. If a task fails, all subsequent tasks will transition to the `Failed` state and your queue will be cleared.
:::

**Import**

Expand Down Expand Up @@ -304,13 +369,13 @@ An error may be thrown if
- the wallet is not currently indexed by your connected relayer, in which case you should `createWallet` or `lookupWallet`
- the API request authorization is incorrect / missing

### `deposit`
### deposit

Action for starting a `deposit` task on your connected relayer.
Action for starting a `deposit` task on your connected relayer. Transfers ERC-20 tokens from your Arbitrum address to your Renegade wallet.

:::warning

You most likely want to use `executeDeposit` instead, as it will check for and execute ERC-20 allowances and permits as needed.
You most likely want to use [`executeDeposit`](#executedeposit) instead, as it will check for and execute ERC-20 allowances and permits as needed.

:::

Expand Down Expand Up @@ -371,9 +436,9 @@ An error may be thrown if:
- the Permit2 permit is incorrect / missing
- the API request authorization is incorrect / missing

### `executeDeposit`
### executeDeposit

Action for starting a `deposit` task on your connected relayer, sending a transaction to approve the ERC-20 and signing a Permit2 `permit` if needed.
Action for starting a `deposit` task on your connected relayer, sending a transaction to approve the ERC-20 and signing a Permit2 `permit` if needed. Transfers ERC-20 tokens from your Arbitrum address to your Renegade wallet.

**Import**

Expand Down Expand Up @@ -451,13 +516,13 @@ An error may be thrown if:
- the provided wagmi config is not configured properly
- the API request authorization is incorrect / missing

### `withdraw`
### withdraw

Action for starting a `withdraw` task on your connected relayer.
Action for starting a `withdraw` task on your connected relayer. Transfers ERC-20 tokens from your Renegade wallet to your Arbitrum address.

:::warning

You most likely want to use `executeWithdraw` instead, as it will check for and pay fees if needed.
You most likely want to use [`executeWithdrawal`](#executewithdrawal) instead, as it will check for and pay fees if needed.

:::

Expand Down Expand Up @@ -506,9 +571,9 @@ An error may be thrown if:
- there exist one or more balances with non-zero fees, meaning you must pay fees
- the API request authorization is incorrect / missing

### `executeWithdrawal`
### executeWithdrawal

Action for starting a `withdraw` task on your connected relayer, paying fees if needed.
Action for starting a `withdraw` task on your connected relayer, paying fees if needed. Transfers ERC-20 tokens from your Renegade wallet to your Arbitrum address.

**Import**

Expand Down Expand Up @@ -557,7 +622,7 @@ An error may be thrown if:
- the provided `amount` is less than the minimum transfer amount set by your connected relayer (currently 1 USDC)
- the API request authorization is incorrect / missing

### `payFees`
### payFees

Action for starting necessary `payFee` task(s) on your connected relayer.

Expand Down Expand Up @@ -586,7 +651,7 @@ An error may be thrown if:
- a `seed` does not exist in the provided `config`
- the API request authorization is incorrect / missing

### `createOrder`
### createOrder

Action for starting a `place order` task on your connected relayer.

Expand Down Expand Up @@ -616,7 +681,7 @@ await createOrder(config, {
- `0x${string}`
- ERC-20 contract address of the quote asset (must be USDC).
- side
- `buy | sell`
- `"buy" | "sell"`
- The side this order is for

**Return Type**
Expand All @@ -632,7 +697,7 @@ Promise that resolves to the ID of the `place order` task in the connected relay
- the provided `quote` mint does not exist in the token mapping
- the API request authorization is incorrect / missing

### `cancelOrder`
### cancelOrder

Action for starting a `cancel wallet` task on your connected relayer.

Expand Down Expand Up @@ -665,7 +730,7 @@ Promise that resolves to the ID of the `cancel order` task in the connected rela
**Error**

- a `seed` does not exist in the provided `config`
- the provided `id` mint does not exist in the wallets list of orders
- the provided `id` mint does not exist in the wallet's list of orders
- the API request authorization is incorrect / missing

## Examples
Expand Down
4 changes: 0 additions & 4 deletions docs.renegade.fi/docs/typescript-sdk/_category_.json

This file was deleted.

5 changes: 3 additions & 2 deletions docs.renegade.fi/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ const sidebars = {
},
{
type: "category",
label: "API Docs",
label: "Technical Reference",
collapsed: false,
items: [
"typescript-sdk/getting-started",
"technical-reference/contract-addresses",
"technical-reference/typescript-sdk",
],
},
],
Expand Down

0 comments on commit 318608f

Please sign in to comment.