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

maxInput headroom #288

Merged
merged 3 commits into from
Jan 1, 2025
Merged
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
8 changes: 3 additions & 5 deletions src/modes/interOrderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BaseError, PublicClient } from "viem";
import { getBountyEnsureBytecode } from "../config";
import { BigNumber, Contract, ethers } from "ethers";
import { containsNodeError, errorSnapshot } from "../error";
import { estimateProfit, scale18To, withBigintSerializer } from "../utils";
import { estimateProfit, ONE18, scale18To, withBigintSerializer } from "../utils";
import { BotConfig, BundledOrders, ViemClient, DryrunResult, SpanAttrs } from "../types";

/**
Expand Down Expand Up @@ -45,9 +45,7 @@ export async function dryrun({
const opposingMaxInput = orderPairObject.takeOrders[0].quote!.ratio.isZero()
? ethers.constants.MaxUint256
: scale18To(
maximumInputFixed
.mul(orderPairObject.takeOrders[0].quote!.ratio)
.div(`1${"0".repeat(18)}`),
maximumInputFixed.mul(orderPairObject.takeOrders[0].quote!.ratio).div(ONE18),
orderPairObject.buyTokenDecimals,
);

Expand All @@ -70,7 +68,7 @@ export async function dryrun({
]);
const takeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: ethers.utils.defaultAbiCoder.encode(
Expand Down
5 changes: 4 additions & 1 deletion src/modes/routeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export async function dryrun({
spanAttributes,
};

// determines if amount is partial derived from binary search or not
const isPartial = !orderPairObject.takeOrders[0].quote!.maxOutput.eq(maximumInputFixed);

const maximumInput = scale18To(maximumInputFixed, orderPairObject.sellTokenDecimals);
spanAttributes["amountIn"] = ethers.utils.formatUnits(maximumInputFixed);

Expand Down Expand Up @@ -135,7 +138,7 @@ export async function dryrun({

const takeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput,
maximumInput: isPartial ? maximumInput : ethers.constants.MaxUint256,
maximumIORatio: config.maxRatio ? ethers.constants.MaxUint256 : price,
orders,
data: ethers.utils.defaultAbiCoder.encode(["bytes"], [rpParams.routeCode]),
Expand Down
9 changes: 2 additions & 7 deletions test/e2e/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,8 @@ module.exports = [
"0x51cD71ec61487A3359993922A5BBac294934A628",
"0x2e574D0802F433E71F7dC91650aB2C23aDeb0D81",
],
[
LiquidityProviders.Enosys,
LiquidityProviders.BlazeSwap,
LiquidityProviders.SparkDexV2,
LiquidityProviders.SparkDexV3,
],
["1", "100", "100", "100"],
[LiquidityProviders.Enosys, LiquidityProviders.SparkDexV2, LiquidityProviders.SparkDexV3],
["1", "100", "100"],
],
[
ChainId.ETHEREUM,
Expand Down
4 changes: 2 additions & 2 deletions test/findOpp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("Test find opp", async function () {
});
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -169,7 +169,7 @@ describe("Test find opp", async function () {
]);
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: ethers.utils.defaultAbiCoder.encode(
Expand Down
6 changes: 3 additions & 3 deletions test/mode-interOrderbook.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe("Test inter-orderbook dryrun", async function () {
]);
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: ethers.utils.defaultAbiCoder.encode(
Expand Down Expand Up @@ -204,7 +204,7 @@ describe("Test inter-orderbook find opp", async function () {
]);
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: ethers.utils.defaultAbiCoder.encode(
Expand Down Expand Up @@ -295,7 +295,7 @@ describe("Test inter-orderbook find opp", async function () {
]);
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: ethers.utils.defaultAbiCoder.encode(
Expand Down
12 changes: 6 additions & 6 deletions test/mode-routeProcessor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("Test route processor dryrun", async function () {
});
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -190,7 +190,7 @@ describe("Test route processor dryrun", async function () {
} catch (error) {
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -274,7 +274,7 @@ describe("Test route processor find opp", async function () {
});
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -440,7 +440,7 @@ describe("Test route processor find opp", async function () {
} catch (error) {
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -555,7 +555,7 @@ describe("Test find opp with retries", async function () {
});
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [
orderPairObject.takeOrders[0].takeOrder,
Expand Down Expand Up @@ -638,7 +638,7 @@ describe("Test find opp with retries", async function () {
} catch (error) {
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down
4 changes: 2 additions & 2 deletions test/processPair.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ describe("Test process pair", async function () {
} catch (error) {
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down Expand Up @@ -706,7 +706,7 @@ describe("Test process pair", async function () {
} catch (error) {
const expectedTakeOrdersConfigStruct = {
minimumInput: ethers.constants.One,
maximumInput: vaultBalance,
maximumInput: ethers.constants.MaxUint256,
maximumIORatio: ethers.constants.MaxUint256,
orders: [orderPairObject.takeOrders[0].takeOrder],
data: expectedRouteData,
Expand Down
Loading