Skip to content
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
"prettier": "^2.5.1",
"typescript": "4.7.4"
}
}
}
96 changes: 96 additions & 0 deletions src/components/Aggregator/adapters/conveyor.ts
Original file line number Diff line number Diff line change
@@ -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
};
};
19 changes: 16 additions & 3 deletions src/components/Aggregator/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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,
Expand Down