Skip to content

feat: add apikey param, add errors to docs #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/gentle-keys-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"sushi": patch
---

ApiKey param for the swap function
21 changes: 21 additions & 0 deletions site/pages/api/errors/estimate-gas.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Estimate Gas

This problem occurs when the gas estimation fails.

Your client application did everything correctly. Unfortunately our API encountered a condition that resulted in this problem.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/estimate-gas|Estimate Gas Error|422|

**Example of an <code>estimate-gas</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/estimate-gas",
"title": "Estimate Gas Error",
"details": "string",
"status": 422,
"code": "422-02"
}
```
26 changes: 26 additions & 0 deletions site/pages/api/errors/insufficient-allowance.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Insufficient Allowance

This problem occurs when the spender doesn't have sufficient allowance.

Your client asked for an estimation of a swap in which the spender doesn't have sufficient allowance. This prevents the estimation from completing successfully.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/insufficient-allowance|Insufficient Allowance|422|

**Example of an <code>insufficient-allowance</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/insufficient-allowance",
"title": "Insufficient Allowance Error",
"details": "Spender has insufficent allowance",
"status": 422,
"code": "422-04",
"token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"spender": "0x85cd07ea01423b1e937929b44e4ad8c40bbb5e71",
"sender": "0x19b3eb3af5d93b77a5619b047de0eed7115a19e7",
"allowance": "1000000",
"amount": "5000000"
}
```
25 changes: 25 additions & 0 deletions site/pages/api/errors/insufficient-balance.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Insufficient Balance

This problem occurs when the spender doesn't have sufficient balance.

Your client asked for an estimation of a swap in which the spender doesn't have sufficient balance. This prevents the estimation from completing successfully.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/insufficient-balance|Insufficient Bllowance|422|

**Example of an <code>insufficient-balance</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/insufficient-balance",
"title": "Insufficient Balance Error",
"details": "Spender has insufficent balance",
"status": 422,
"code": "422-03",
"token": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"sender": "0x19b3eb3af5d93b77a5619b047de0eed7115a19e7",
"balance": "1000000",
"amount": "5000000"
}
```
21 changes: 21 additions & 0 deletions site/pages/api/errors/invalid-api-key.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Invalid Api Key

This problem occurs when the provided API key is invalid or missing.

Your client application tried to access a resource that requires an API key, but the key was either invalid or not provided. Please check your API key and try again. It can be provided as a query parameter or in the authorization header.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/invalid-api-key|Invalid Api Key|401|

**Example of an <code>invalid-api-key</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/invalid-api-key",
"title": "Invalid or Missing API Key",
"details": "Invalid API key",
"status": 401,
"code": "401-01",
}
```
21 changes: 21 additions & 0 deletions site/pages/api/errors/no-fresh-data.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# No Fresh Data

This problem occurs when the API does not have fresh data available.

Your client application did everything correctly. Unfortunately our API encountered a condition that resulted in this problem.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/no-fresh-data|No Fresh Data|500|

**Example of an <code>no-fresh-data</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/no-fresh-data",
"title": "No Fresh Data Error",
"details": "Network 1 data timeout",
"status": 500,
"code": "500-02",
}
```
21 changes: 21 additions & 0 deletions site/pages/api/errors/ratelimit-exceeded.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Ratelimit Exceeded

This problem occurs when the provided API key has exceeded its rate limit.

Your client application tried to access a resource that requires an API key, but the key has exceeded its rate limit. Please try again later.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/ratelimit-exceeded|Ratelimit Exceeded|429|

**Example of an <code>ratelimit-exceeded</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/ratelimit-exceeded",
"title": "Rate Limit Exceeded",
"details": "API key rate limit exceeded",
"status": 429,
"code": "429-01",
}
```
21 changes: 21 additions & 0 deletions site/pages/api/errors/unauthorized.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Unauthorized

This problem occurs when the provided API key has blacklisted / not-whitelisted your IP address or origin.

Your client application tried to access a resource that requires an API key, but the key has either blacklisted or not whitelisted your IP address or origin. Please check your API key and try again. It can be provided as a query parameter or in the authorization header.

|**Type URI**|**Title**|**Status**|
|---|---|---|
|https://docs.sushi.com/api/errors/unauthorized|Unauthorized|403|

**Example of an <code>unauthorized</code> problem details:**

```json
{
"type": "https://docs.sushi.com/api/errors/unauthorized",
"title": "Unauthorized",
"details": "IP not whitelisted",
"status": 403,
"code": "403-01",
}
```
4 changes: 4 additions & 0 deletions site/pages/api/swap.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ const maxSlippage = 0.005
// Sender
const sender = '0x' // replace with your own address

// Api Key, get yours at https://sushi.com/portal
const apiKey = "sushi_abcdefghijklmnopqr"

const { searchParams } = SWAP_API_URL
searchParams.set('tokenIn', inputCurrency)
searchParams.set('tokenOut', outputCurrency)
searchParams.set('amount', amount.toString())
searchParams.set('maxSlippage', maxSlippage.toString())
searchParams.set('sender', sender)
searchParams.set('apiKey', apiKey)

// Make call to API
console.log(SWAP_API_URL.toString())
Expand Down
3 changes: 2 additions & 1 deletion site/pages/sdk/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ If you're not using a package manager, you can also use Sushi via an ESM-compati
tokenIn: '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
tokenOut: '0x6B3595068778DD592e39A122f4f5a5cF09C90fE2',
amount: 1000000000000000000n,
maxSlippage: 0.005
maxSlippage: 0.005,
apiKey: "sushi_abcdefghijklmnopqr"
})

console.log(swap)
Expand Down
5 changes: 5 additions & 0 deletions src/api/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type SwapRequest<EnableFee extends boolean> = {
override?: boolean
facade?: boolean
validate?: boolean
apiKey?: string
}

function swapResponseSchema<Simulate extends boolean>(simulate?: Simulate) {
Expand Down Expand Up @@ -157,6 +158,10 @@ export async function getSwap<
url.searchParams.append('facade', params.facade.toString())
}

if (params.apiKey !== undefined) {
url.searchParams.append('apiKey', params.apiKey)
}

const res = await fetch(url.toString(), options)

if (!res.ok) {
Expand Down
Loading