Skip to content
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

using the 1inch dev portal api #309

Open
wants to merge 4 commits 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
2 changes: 1 addition & 1 deletion src/components/Aggregator/adapters/1inch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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! }
}
Expand Down
8 changes: 5 additions & 3 deletions src/components/Aggregator/adapters/1inch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ 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

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([
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`,
{ 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}&origin=${extra.userAddress}&slippage=${extra.slippage}&referrer=${altReferralAddress}&disableEstimate=true`,
{ headers: authHeader as any }
).then((r) => r.json())
: null
Expand Down
3 changes: 2 additions & 1 deletion src/components/Aggregator/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};