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

migrated to apiv5 #5

Open
wants to merge 3 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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .env.sample → env.sample
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PK_MAINNET=
PK_POLYGON=
HTTP_PROVIDER_MAINNET=
HTTP_PROVIDER_POLYGON=
HTTP_PROVIDER_POLYGON=
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class CrossChainArbinator {
// Bot logic goes here
async run() {
const srcAmountFirst = this.normalise(
'0.05',
'0.035',
Tokens[MAINNET_NETWORK_ID]['ETH'],
);
// Get the best price for ETH -> MATIC swap in MAINNET
Expand Down
13 changes: 7 additions & 6 deletions paraswap.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const axios = require('axios');
const BigNumber = require('bignumber.js');

const ParswapURL = 'https://apiv4.paraswap.io/v2';

const ParswapURL = 'https://apiv5.paraswap.io';
let requestURL;
// https://developers.paraswap.network/
class Paraswap {
constructor(apiURL = ParswapURL) {
Expand All @@ -13,22 +13,23 @@ class Paraswap {
async getPrice(from, to, srcAmount, network) {
// TODO: Add error handling
try {
const requestURL =
`${this.apiURL}/prices/?from=${from.address}&to=${to.address}` +
`&amount=${srcAmount}&fromDecimals=${from.decimals}&toDecimals` +
requestURL =
`${this.apiURL}/prices/?srcToken=${from.address}&destToken=${to.address}` +
`&amount=${srcAmount}&srcDecimals=${from.decimals}&destDecimals` +
`=${to.decimals}&side=SELL&network=${network}`;
const { data } = await axios.get(requestURL, {
headers: {
'X-Partner': this.referrer,
},

});
return {
price: data.priceRoute.destAmount,
payload: data.priceRoute,
};
} catch (e) {
throw new Error(
`Paraswap unable to fetch price ${from.address} ${to.address} ${network} ${e.message}`,
`Paraswap unable to fetch price ${from.address} ${to.address} ${network} ${e.message} ${requestURL}`,
);
}
}
Expand Down