diff --git a/package.json b/package.json index c9eef115..7b933d03 100644 --- a/package.json +++ b/package.json @@ -48,4 +48,4 @@ "prettier": "^2.5.1", "typescript": "4.7.4" } -} +} \ No newline at end of file diff --git a/src/components/Aggregator/adapters/conveyor.ts b/src/components/Aggregator/adapters/conveyor.ts new file mode 100644 index 00000000..cb5b6cbe --- /dev/null +++ b/src/components/Aggregator/adapters/conveyor.ts @@ -0,0 +1,96 @@ +//Source: https://docs.conveyor.finance/api/ + +import BigNumber from 'bignumber.js'; +import { ethers } from 'ethers'; +import { applyArbitrumFees } from '../utils/arbitrumFees'; +import { sendTx } from '../utils/sendTx'; +import { nativeAddress } from '../constants'; + +export const name = 'Conveyor'; +export const token = null; + +const api = 'https://api.conveyor.finance/'; + +export const chainToId = { + ethereum: 1, + bsc: 56, + polygon: 137, + optimism: 10, + arbitrum: 42161, + base: 8453 +}; + +export async function getQuote(chain: string, from: string, to: string, amount: string, extra) { + const tokenFrom = from === ethers.constants.AddressZero ? nativeAddress : from; + const tokenTo = to === ethers.constants.AddressZero ? nativeAddress : to; + const receiver = extra.userAddress || ethers.constants.AddressZero; + const tokenApprovalAddress = '0xd5eC61bCa0Af24Ad06BE431585A0920142C98890'; + let payload = { + tokenIn: tokenFrom, + tokenOut: tokenTo, + tokenInDecimals: extra.fromToken?.decimals, + tokenOutDecimals: extra.toToken?.decimals, + amountIn: amount, + slippage: BigNumber(Number(extra.slippage) * 100).toString(), + chainId: chainToId[chain], + recipient: receiver, + referrer: '0' + }; + + const resp = await fetch(api, { + method: 'POST', + body: JSON.stringify(payload) + }) + .then((r) => r.json()) + .then((r) => r.body); + const estimatedGas = resp.tx.gas || 0; + + let gas = estimatedGas; + if (chain === 'arbitrum') { + gas = resp.tx.data === null ? null : await applyArbitrumFees(resp.tx.to, resp.tx.data, gas); + } + + return { + amountReturned: resp.info.amountOut, + tokenApprovalAddress, + estimatedGas: gas, + rawQuote: { + ...resp.tx, + tx: { + data: resp.tx.data, + from: receiver, + value: resp.tx.value, + gasLimit: BigNumber(1.1).times(gas).toFixed(0, 1) + } + }, + logo: '' + }; +} + +export async function swap({ signer, rawQuote, chain }) { + const txObj = { + from: rawQuote.tx.from, + to: rawQuote.to, + data: rawQuote.tx.data, + value: rawQuote.tx.value + }; + const tx = await sendTx(signer, chain, { + ...txObj, + gasLimit: rawQuote.tx.gasLimit + }); + return tx; +} + +export const getTxData = ({ rawQuote }) => rawQuote?.tx?.data; + +export const getTx = ({ rawQuote }) => { + if (rawQuote === null) { + return {}; + } + return { + from: rawQuote.tx.from, + to: rawQuote.tx.to, + data: rawQuote.tx.data, + value: rawQuote.tx.value + }; +}; diff --git a/src/components/Aggregator/list.ts b/src/components/Aggregator/list.ts index fb5a8648..ada12343 100644 --- a/src/components/Aggregator/list.ts +++ b/src/components/Aggregator/list.ts @@ -2,10 +2,11 @@ import * as matcha from './adapters/0x'; import * as inch from './adapters/1inch'; import * as cowswap from './adapters/cowswap'; import * as firebird from './adapters/firebird'; -//import * as kyberswap from './adapters/kyberswap'; +import * as kyberswap from './adapters/kyberswap'; import * as hashflow from './adapters/hashflow'; import * as openocean from './adapters/openocean'; import * as paraswap from './adapters/paraswap'; +import * as conveyor from './adapters/conveyor'; // import * as lifi from './adapters/lifi'; // import * as rango from './adapters/rango'; @@ -16,9 +17,21 @@ import * as yieldyak from './adapters/yieldyak'; import * as llamazip from './adapters/llamazip'; // import * as krystal from './adapters/krystal' -export const adapters = [matcha, inch, cowswap, openocean, yieldyak, paraswap, firebird, hashflow, llamazip]; +export const adapters = [ + matcha, + inch, + cowswap, + openocean, + yieldyak, + paraswap, + firebird, + hashflow, + llamazip, + kyberswap, + conveyor +]; -export const inifiniteApprovalAllowed = [matcha.name, inch.name, cowswap.name, paraswap.name]; +export const inifiniteApprovalAllowed = [matcha.name, inch.name, cowswap.name, paraswap.name, conveyor.name]; export const adaptersWithApiKeys = { [matcha.name]: true,