From 263a089b972fe69499760fa9ee06235a53eca9ae Mon Sep 17 00:00:00 2001
From: Matthias Kretschmann
Date: Sat, 30 Mar 2024 15:49:14 +0000
Subject: [PATCH] new quote fetching
---
app/api/quote/route.ts | 15 +++++++--------
app/page.tsx | 2 +-
components/Content/Content.tsx | 3 ++-
components/Prices.tsx | 33 ++++++++++++++-------------------
4 files changed, 24 insertions(+), 29 deletions(-)
diff --git a/app/api/quote/route.ts b/app/api/quote/route.ts
index 373d5ce..ac06e35 100644
--- a/app/api/quote/route.ts
+++ b/app/api/quote/route.ts
@@ -2,28 +2,27 @@ import { type NextRequest } from 'next/server'
export const runtime = 'edge'
-const apiUrl = 'https://api.1inch.dev/swap/v6.0/1/quote'
+const apiUrl = process.env.WEB3_API_URL
const config: RequestInit = {
headers: {
- Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`,
'content-type': 'application/json'
},
method: 'GET',
- next: { revalidate: 60 }
+ next: { revalidate: 30 }
}
export async function GET(request: NextRequest) {
const searchParams = request?.nextUrl?.searchParams
- const src = searchParams?.get('src')
- const dst = searchParams?.get('dst')
- const amount = searchParams?.get('amount')
+ const tokenIn = searchParams?.get('tokenIn')
+ const tokenOut = searchParams?.get('tokenOut')
+ const amountIn = searchParams?.get('amountIn')
- if (!src || !dst || !amount) {
+ if (!tokenIn || !tokenOut || !amountIn) {
return Response.json(null, { status: 400 })
}
- const url = `${apiUrl}/?src=${src}&dst=${dst}&amount=${amount}&includeTokensInfo=true&includeProtocols=true`
+ const url = `${apiUrl}/quote?tokenIn=${tokenIn}&tokenOut=${tokenOut}&amountIn=${amountIn}`
let data
let status
diff --git a/app/page.tsx b/app/page.tsx
index 11463b9..2c7397e 100644
--- a/app/page.tsx
+++ b/app/page.tsx
@@ -13,7 +13,7 @@ export default function Home() {
>
)
diff --git a/components/Content/Content.tsx b/components/Content/Content.tsx
index 50d17f3..398cdc7 100644
--- a/components/Content/Content.tsx
+++ b/components/Content/Content.tsx
@@ -16,7 +16,8 @@ export function Content({ prices }: Props) {
fixed ASI exchange rate
, the fluctuating fiat values fetched from Coingecko, and
- token swap quotes from 1inch.
+ token swap quotes from Uniswap v3
+ routes.
diff --git a/components/Prices.tsx b/components/Prices.tsx
index d478e5f..f6a70fe 100644
--- a/components/Prices.tsx
+++ b/components/Prices.tsx
@@ -26,16 +26,12 @@ export function Prices() {
)
const { data: dataSwapOceanToAgix } = useSWR(
- `/api/quote/?src=${tokens[0]}&dst=${tokens[2]}&amount=${
- debouncedAmountSwap * 1e18
- }`,
+ `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[2]}&amountIn=${debouncedAmountSwap}`,
fetcher
)
const { data: dataSwapOceanToFet } = useSWR(
- `/api/quote/?src=${tokens[0]}&dst=${tokens[1]}&amount=${
- debouncedAmountSwap * 1e18
- }`,
+ `/api/quote/?tokenIn=${tokens[0]}&tokenOut=${tokens[1]}&amountIn=${debouncedAmountSwap}`,
fetcher
)
@@ -66,17 +62,17 @@ export function Prices() {
tokenSymbol="AGIX"
tokenAddress="0x5b7533812759b45c2b44c19e320ba2cd2681b542"
amount={
- dataSwapOceanToAgix?.dstAmount /
- Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0
+ dataSwapOceanToAgix?.amountOut /
+ Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0
}
amountAsi={
- (dataSwapOceanToAgix?.dstAmount /
- Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
+ (dataSwapOceanToAgix?.amountOut /
+ Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
ratioAgixToAsi
}
amountFiat={
- (dataSwapOceanToAgix?.dstAmount /
- Number(`1e${dataSwapOceanToAgix?.dstToken?.decimals}`) || 0) *
+ (dataSwapOceanToAgix?.amountOut /
+ Number(`1e${dataSwapOceanToAgix?.decimals}`) || 0) *
ratioAgixToAsi *
priceAsi
}
@@ -86,18 +82,17 @@ export function Prices() {
tokenSymbol="FET"
tokenAddress="0xaea46a60368a7bd060eec7df8cba43b7ef41ad85"
amount={
- dataSwapOceanToFet?.dstAmount /
- Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0
+ dataSwapOceanToFet?.amountOut /
+ Number(`1e${dataSwapOceanToFet?.decimals}`) || 0
}
amountAsi={
- (dataSwapOceanToFet?.dstAmount /
- Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
+ (dataSwapOceanToFet?.amountOut /
+ Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) *
ratioFetToAsi
}
amountFiat={
- (dataSwapOceanToFet?.dstAmount /
- Number(`1e${dataSwapOceanToFet?.dstToken?.decimals}`) || 0) *
- priceAsi
+ (dataSwapOceanToFet?.amountOut /
+ Number(`1e${dataSwapOceanToFet?.decimals}`) || 0) * priceAsi
}
/>