From 4772cb4bbb2c337e9fac87644a5950e424b078a9 Mon Sep 17 00:00:00 2001 From: Corey Rice Date: Thu, 5 Dec 2024 13:25:01 -0300 Subject: [PATCH] feat: add modifier for min income to make conversions easier on ethereum --- packages/cli/source/commands/convert.tsx | 39 +++++++++++++++++++----- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/packages/cli/source/commands/convert.tsx b/packages/cli/source/commands/convert.tsx index 19297c8..f529d39 100644 --- a/packages/cli/source/commands/convert.tsx +++ b/packages/cli/source/commands/convert.tsx @@ -105,16 +105,27 @@ export const options = zod.object({ ) .optional() .default(false), - minIncomeBp: zod - .number() + minIncomeLimitBp: zod + .bigint() .describe( option({ - description: "Min income in basis points as percentage of amount", - alias: "bp", + description: "Min income limit in basis points as percentage of amount", + alias: "income-limit", }), ) .optional() - .default(3), + .default(3n), + minIncomeModifier: zod + .bigint() + .describe( + option({ + description: + "Increase the min income offered to make swaps more likely to succeed. If min income is negative this will increase the amount offered in the swap. If the min the min income is positive this will accept a lower profit.", + alias: "income-modifier", + }), + ) + .optional() + .default(0n), }); interface Props { @@ -135,7 +146,8 @@ export default function Convert({ options }: Props) { profitable, loop, debug, - minIncomeBp, + minIncomeLimitBp, + minIncomeModifier, fixedPairs, } = options; @@ -189,13 +201,24 @@ export default function Convert({ options }: Props) { fixedPairs, ); - const { trade, amount, minIncome } = arbitrageArgs || { + const { + trade, + amount, + minIncome: unadjustedMinIncome, + } = arbitrageArgs || { trade: undefined, amount: 0n, minIncome: 0n, }; - const minIncomeLimit = BigInt(Number(amount) * minIncomeBp) / 10000n; + let minIncome = unadjustedMinIncome; + + if (unadjustedMinIncome < 0n && minIncomeModifier > 0) { + minIncome = (unadjustedMinIncome * (10000n + minIncomeModifier)) / 10000n; + } else { + minIncome = (unadjustedMinIncome * (10000n - minIncomeModifier)) / 10000n; + } + const minIncomeLimit = (amount * minIncomeLimitBp) / 10000n; const minIncomeUsdValue = +formatUnits(minIncome, assetOutDecimals) * +assetOutPriceUsd; const context = {