Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rouzwelt committed Apr 2, 2024
1 parent ef0466a commit d486452
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 44 deletions.
87 changes: 45 additions & 42 deletions src/modes/univ2Hardcoded.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,30 +383,30 @@ async function checkArb(
} as maximum input`);
console.log(`>>> Getting best route ${modeText}`, "\n");

console.log(ethPrice);
ethPriceToSellToken = await getAmountOutFlareSwap(
signer,
config.uniV2Router02HardcodedAddress,
config.nativeWrappedToken.address,
"1" + "0".repeat(config.nativeWrappedToken.decimals),
bundledOrder.sellToken,
bundledOrder.sellTokenDecimals
);
console.log(maximumInputFixed.mul("1" + "0".repeat(config.nativeWrappedToken.decimals)).div(ethers.utils.parseEther(ethPriceToSellToken)));
if (!ethPriceToSellToken) {
continue;
}
// .000 583 605 007 789 435
const amountOut = await getAmountOutFlareSwap(
signer,
config.uniV2Router02HardcodedAddress,
config.nativeWrappedToken.address,
maximumInputFixed.mul("1" + "0".repeat(config.nativeWrappedToken.decimals)).div(ethers.utils.parseEther(ethPriceToSellToken)),
toToken.address,
toToken.decimals
);
console.log(amountOut);
if (amountOut === undefined) {
// console.log(ethPrice);
// ethPriceToSellToken = await getAmountOutFlareSwap(
// signer,
// config.uniV2Router02HardcodedAddress,
// config.nativeWrappedToken.address,
// "1" + "0".repeat(config.nativeWrappedToken.decimals),
// bundledOrder.sellToken,
// bundledOrder.sellTokenDecimals
// );
// console.log(maximumInputFixed.mul("1" + "0".repeat(config.nativeWrappedToken.decimals)).div(ethers.utils.parseEther(ethPriceToSellToken)));
// if (!ethPriceToSellToken) {
// continue;
// }
// // .000 583 605 007 789 435
// const amountOut = await getAmountOutFlareSwap(
// signer,
// config.uniV2Router02HardcodedAddress,
// config.nativeWrappedToken.address,
// maximumInputFixed.mul("1" + "0".repeat(config.nativeWrappedToken.decimals)).div(ethers.utils.parseEther(ethPriceToSellToken)),
// toToken.address,
// toToken.decimals
// );
// console.log(amountOut);
if (amountOut !== undefined) {
succesOrFailure = false;
console.log(
"\x1b[31m%s\x1b[0m",
Expand All @@ -418,29 +418,29 @@ async function checkArb(
);
}
else {
const amountOutBN = ethers.utils.parseUnits(amountOut,toToken.decimals);
const rateFixed = amountOutBN.mul(
"1" + "0".repeat(18 - bundledOrder.buyTokenDecimals)
);
const price = rateFixed.mul("1" + "0".repeat(18)).div(maximumInputFixed);
// const amountOutBN = ethers.utils.parseUnits(amountOut,toToken.decimals);
// const rateFixed = amountOutBN.mul(
// "1" + "0".repeat(18 - bundledOrder.buyTokenDecimals)
// );
// const price = rateFixed.mul("1" + "0".repeat(18)).div(maximumInputFixed);

// filter out orders that are not price match or failed eval when --max-profit is enabled
// price check is at +2% as a headroom for current block vs tx block
if (!mode && maxProfit) bundledOrder.takeOrders = bundledOrder.takeOrders.filter(
v => v.ratio !== undefined ? price.mul("102").div("100").gte(v.ratio) : false
);
// // filter out orders that are not price match or failed eval when --max-profit is enabled
// // price check is at +2% as a headroom for current block vs tx block
// if (!mode && maxProfit) bundledOrder.takeOrders = bundledOrder.takeOrders.filter(
// v => v.ratio !== undefined ? price.mul("102").div("100").gte(v.ratio) : false
// );

if (bundledOrder.takeOrders.length === 0) {
maximumInput = maximumInput.sub(obSellTokenBalance.div(2 ** j));
continue;
}

console.log(
`Current best route price for ${modeText} for this token pair:`,
`\x1b[33m${ethers.utils.formatEther(price)}\x1b[0m`,
"\n"
);
console.log("");
// console.log(
// `Current best route price for ${modeText} for this token pair:`,
// `\x1b[33m${ethers.utils.formatEther(price)}\x1b[0m`,
// "\n"
// );
// console.log("");

let routeCode;
for (let k = 0; k < config.univ20Routes?.length ?? 0; k++) {
Expand Down Expand Up @@ -475,7 +475,7 @@ async function checkArb(
const takeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput,
maximumIORatio: maxRatio ? ethers.constants.MaxUint256 : price,
maximumIORatio: ethers.constants.MaxUint256,
orders,
data: ethers.utils.defaultAbiCoder.encode(
["bytes"],
Expand Down Expand Up @@ -530,7 +530,10 @@ async function checkArb(
}
succesOrFailure = true;
if (j == 1 || j == hops) {
return {rawtx, maximumInput, gasCostInToken, takeOrdersConfigStruct, price};
return {
rawtx, maximumInput, gasCostInToken, takeOrdersConfigStruct,
price: ethers.constants.Zero
};
}
}
catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions test/univ2Hardcoded.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe("Rain Arb Bot 'univ2 hardcoded' Mode Tests", async function () {
const expConfig = {
constants: [
ethers.constants.MaxUint256.toHexString(), // max output
"5" + "0".repeat(17) // ratio 0.5, for testing purpose to ensure clearance
"2" + "0".repeat(17) // ratio 0.5, for testing purpose to ensure clearance
],
bytecode: "0x020000000c02020002010000000100000100000000"
};
Expand Down Expand Up @@ -172,7 +172,7 @@ describe("Rain Arb Bot 'univ2 hardcoded' Mode Tests", async function () {
BJ.address,
BJ_vaultId
)).toString(),
"500000000000000000"
"200000000000000000"
);
assert.equal(
(await orderbook.vaultBalance(
Expand Down

0 comments on commit d486452

Please sign in to comment.