From 19e714f3b810008b19f41542c8deee33708d3d3e Mon Sep 17 00:00:00 2001 From: Maria Date: Thu, 5 Dec 2024 17:12:08 +0200 Subject: [PATCH 1/4] using the 1inch dev portal api --- src/components/Aggregator/adapters/1inch.test.ts | 2 +- src/components/Aggregator/adapters/1inch.ts | 6 ++++-- src/components/Aggregator/list.ts | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/Aggregator/adapters/1inch.test.ts b/src/components/Aggregator/adapters/1inch.test.ts index 73df5ad0..8dd06790 100644 --- a/src/components/Aggregator/adapters/1inch.test.ts +++ b/src/components/Aggregator/adapters/1inch.test.ts @@ -5,7 +5,7 @@ export async function testApprovalAddresses() { await Promise.all( Object.keys(chainToId).map(async (chain) => { const { address: tokenApprovalAddress } = await fetch( - `https://api-defillama.1inch.io/v6.0/${chainToId[chain]}/approve/spender`, + `https://api.1inch.dev/swap/v6.0/${chainToId[chain]}/approve/spender`, { headers: { 'auth-key': process.env.INCH_API_KEY! } } diff --git a/src/components/Aggregator/adapters/1inch.ts b/src/components/Aggregator/adapters/1inch.ts index 2f792457..dde6db40 100644 --- a/src/components/Aggregator/adapters/1inch.ts +++ b/src/components/Aggregator/adapters/1inch.ts @@ -47,6 +47,8 @@ export function approvalAddress(chain: string) { } const nativeToken = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE'; +const apiEndpoint = 'https://api.1inch.dev/swap/v6.0/'; + export async function getQuote(chain: string, from: string, to: string, amount: string, extra) { // ethereum = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE // amount should include decimals @@ -58,12 +60,12 @@ export async function getQuote(chain: string, from: string, to: string, amount: const [data, swapData] = await Promise.all([ fetch( - `https://api-defillama.1inch.io/v6.0/${chainToId[chain]}/quote?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&includeGas=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, + `${apiEndpoint}${chainToId[chain]}/quote?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&includeGas=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, { headers: authHeader as any } ).then((r) => r.json()), extra.userAddress !== zeroAddress ? fetch( - `https://api-defillama.1inch.io/v6.0/${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, + `${apiEndpoint}${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, { headers: authHeader as any } ).then((r) => r.json()) : null diff --git a/src/components/Aggregator/list.ts b/src/components/Aggregator/list.ts index c9c05245..8ef57a89 100644 --- a/src/components/Aggregator/list.ts +++ b/src/components/Aggregator/list.ts @@ -23,6 +23,7 @@ export const inifiniteApprovalAllowed = [matcha.name, inch.name, cowswap.name, m export const adaptersWithApiKeys = { [matcha.name]: true, - [matchaGasless.name]: true + [matchaGasless.name]: true, + [inch.name]: true, //[hashflow.name]: true }; From 9773e44b41e9fbba0aa9f78204c32c64fa2abb3a Mon Sep 17 00:00:00 2001 From: Maria Date: Fri, 13 Dec 2024 15:30:54 +0200 Subject: [PATCH 2/4] removing the pmm exception --- src/components/Aggregator/adapters/1inch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Aggregator/adapters/1inch.ts b/src/components/Aggregator/adapters/1inch.ts index dde6db40..7db5271a 100644 --- a/src/components/Aggregator/adapters/1inch.ts +++ b/src/components/Aggregator/adapters/1inch.ts @@ -60,12 +60,12 @@ export async function getQuote(chain: string, from: string, to: string, amount: const [data, swapData] = await Promise.all([ fetch( - `${apiEndpoint}${chainToId[chain]}/quote?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&includeGas=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, + `${apiEndpoint}${chainToId[chain]}/quote?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&includeGas=true`, { headers: authHeader as any } ).then((r) => r.json()), extra.userAddress !== zeroAddress ? fetch( - `${apiEndpoint}${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true&excludedProtocols=PMM1,PMM2,PMM3,PMM4,PMM2MM1,PMM9,PMM8,PMM11,PMM8_2,PMM12,PMM15,PMM17,PMM18,PMM16,PMM20,PMM22,PMM23`, + `${apiEndpoint}${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true`, { headers: authHeader as any } ).then((r) => r.json()) : null From 6ff1b99fe85c6f44eda98455b99286a47d6c19a7 Mon Sep 17 00:00:00 2001 From: Maria Date: Mon, 16 Dec 2024 14:44:38 +0200 Subject: [PATCH 3/4] added the origin field to the swap request --- src/components/Aggregator/adapters/1inch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Aggregator/adapters/1inch.ts b/src/components/Aggregator/adapters/1inch.ts index 7db5271a..30490ad3 100644 --- a/src/components/Aggregator/adapters/1inch.ts +++ b/src/components/Aggregator/adapters/1inch.ts @@ -65,7 +65,7 @@ export async function getQuote(chain: string, from: string, to: string, amount: ).then((r) => r.json()), extra.userAddress !== zeroAddress ? fetch( - `${apiEndpoint}${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true`, + `${apiEndpoint}${chainToId[chain]}/swap?src=${tokenFrom}&dst=${tokenTo}&amount=${amount}&from=${extra.userAddress}&origin=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true`, { headers: authHeader as any } ).then((r) => r.json()) : null From 67bc1072d8b55210da3fa901b0d10f33b490d8ab Mon Sep 17 00:00:00 2001 From: Maria Date: Tue, 17 Dec 2024 00:26:04 +0200 Subject: [PATCH 4/4] update authHeader --- src/components/Aggregator/adapters/1inch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Aggregator/adapters/1inch.ts b/src/components/Aggregator/adapters/1inch.ts index 30490ad3..d528af53 100644 --- a/src/components/Aggregator/adapters/1inch.ts +++ b/src/components/Aggregator/adapters/1inch.ts @@ -55,7 +55,7 @@ export async function getQuote(chain: string, from: string, to: string, amount: const tokenFrom = from === zeroAddress ? nativeToken : from; const tokenTo = to === zeroAddress ? nativeToken : to; - const authHeader = process.env.INCH_API_KEY ? { 'auth-key': process.env.INCH_API_KEY as string } : {}; + const authHeader = process.env.INCH_API_KEY ? { 'Authorization': `Bearer ${process.env.INCH_API_KEY as string}` } : {}; const tokenApprovalAddress = spenders[chain]; const [data, swapData] = await Promise.all([