Skip to content

add oneInch v6 swap api #12

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

Open
wants to merge 1 commit 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
43 changes: 32 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,56 @@
"ecmaVersion": 2018,
"project": "./tsconfig.json"
},
"plugins": ["prettier"],
"plugins": [
"prettier"
],
"rules": {
"prettier/prettier": ["error"],
"semi": ["error", "always"],
"object-curly-spacing": ["error", "always"],
"prettier/prettier": [
"off",
{
"endOfLine": "auto"
}
],
"semi": [
"error",
"always"
],
"object-curly-spacing": [
"error",
"always"
],
"camelcase": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-explicit-any": 1,
"@typescript-eslint/no-inferrable-types": [
"warn",
{
"ignoreParameters": true
"ignoreParameters": true
}
],
"no-underscore-dangle": "off",
"no-shadow": "off",
"no-new": 0,
"@typescript-eslint/no-shadow": ["error"],
"@typescript-eslint/no-shadow": [
"error"
],
"@typescript-eslint/no-unused-vars": "warn",
"quotes": [2, "single", { "avoidEscape": true }],
"quotes": [
2,
"single",
{
"avoidEscape": true
}
],
"class-methods-use-this": "off",
"import/extensions": [
"error",
"ignorePackages",
{
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}
]
}
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,45 @@
"license": "Apache-2.0",
"dependencies": {
"@truffle/hdwallet-provider": "^2.0.12",
"@types/express": "^4.17.13",
"@types/express": "^4.17.21",
"@types/node": "^17.0.29",
"@types/winston": "^2.4.4",
"axios": "^0.27.2",
"axios-debug-log": "^0.8.4",
"axios-logger": "^2.6.1",
"bignumber.js": "^9.1.0",
"bignumber.js": "^9.1.2",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"express": "^4.18.1",
"express": "^4.21.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was it needed to update the dependencies ?

"helmet": "^5.0.2",
"http-status-codes": "^2.2.0",
"joi": "^17.6.0",
"qs": "^6.11.0",
"swagger-ui-express": "^5.0.1",
"truffle": "^5.5.21",
"ts-results": "^3.3.0",
"typescript": "^4.6.3",
"typescript": "^4.9.5",
"web3": "^1.7.4",
"winston": "^3.15.0"
},
"devDependencies": {
"@types/cors": "^2.8.12",
"@types/cors": "^2.8.17",
"@types/jest": "^27.4.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^5.30.4",
"@typescript-eslint/parser": "^5.30.4",
"eslint": "^8.19.0",
"eslint": "^8.57.1",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.30.1",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.1",
"husky": "^8.0.1",
"jest": "^27.5.1",
"nodemon": "^2.0.18",
"prettier": "^2.7.1",
"supertest": "^6.2.3",
"ts-jest": "^27.1.4",
"ts-node": "^10.7.0"
"prettier": "^3.3.3",
"supertest": "^6.3.4",
"ts-jest": "^27.1.5",
"ts-node": "^10.9.2"
}
}
27 changes: 16 additions & 11 deletions src/components/GetBestQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ async function getTransactionData(
),
web3.utils.toBN(100000),
),
);

);
const minAmount =
betterRoute.tradeType === TradeType.ExactInput
? web3.utils.toHex(
Expand All @@ -130,13 +129,16 @@ async function getTransactionData(
),
web3.utils.toBN(100000),
),
)
)
: web3.utils.toHex(betterRoute.buyAmount);

const aggregator = betterRoute.to;

const aggregatorData = betterRoute.data;
const adapterId = 'SwapAggregator';
logger.debug(
`${tokenFrom} ${tokenTo} ${amountFrom} ${minAmount} ${aggregator} ${aggregatorData}`,
);
const adapterData: string = web3.eth.abi.encodeParameter(
'tuple(address,address,uint256,uint256,address,bytes)',
[tokenFrom, tokenTo, amountFrom, minAmount, aggregator, aggregatorData],
Expand Down Expand Up @@ -245,8 +247,8 @@ function getNormalizedResponse(
betterRoute.sellTokenAddress ===
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
? '0x0000000000000000000000000000000000000000'
: METASWAP_ROUTER_CONTRACT_ADDRESS[chainId] ??
betterRoute.allowanceTarget,
: (METASWAP_ROUTER_CONTRACT_ADDRESS[chainId] ??
betterRoute.allowanceTarget),
tx: txData,
},
aggregatorQuote: betterRoute,
Expand All @@ -257,25 +259,28 @@ export default async function getBestQuote(
request: RequestQuote,
getGaslessQuote: boolean | undefined,
): Promise<Result<CompositeQuote, RequestError>> {
const [zeroXQuote, odosQuote] = await Promise.all([
getZeroXQuote(request),
const [oneInchQuote, odosQuote, zeroXQuote] = await Promise.all([
getOneInchQuote(request),
getOdosQuote(request),
//getOneInchQuote(request, request.skipValidation),
getZeroXQuote(request),
]);

const aggregatorQuotes: Result<AggregatorQuote, RequestError>[] = [
zeroXQuote,
// oneInchQuote, // this one is not working for now anwyway
// odosQuote,
// oneInchQuote,
];

if (getGaslessQuote === false) aggregatorQuotes.push(odosQuote);
if (getGaslessQuote === false) {
aggregatorQuotes.push(...[odosQuote, oneInchQuote]);
}

const validAggregatorQuotes = aggregatorQuotes.filter(
(quote) => quote !== undefined && quote.ok && !quote.err,
);

// check if there are no valid aggregator quotes
if (validAggregatorQuotes.length === 0) {
if (!validAggregatorQuotes || validAggregatorQuotes?.length === 0) {
return new Err({
statusCode: 500,
data: 'Aggregate Request failed',
Expand Down
1 change: 1 addition & 0 deletions src/components/compareRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function compareRoutes(
});

if (bestQuotes.length > 0) {
logger.debug('Best Quote is', bestQuotes[0].unwrap());
return bestQuotes[0];
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/getOdosQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export default async function getOdosQuote(
const assembleRequestParameters: OdosAssembleRequestParameters = {
userAddr: fromAddress,
pathId: quoteResponse.pathId,
simulate: true,
simulate: false,
};

const r2 = await instance.post(
Expand Down
Loading