Skip to content

Commit

Permalink
feat: add modifier for min income to make conversions easier on ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyar committed Dec 5, 2024
1 parent aee557b commit 22eeeda
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions packages/cli/source/commands/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,26 @@ export const options = zod.object({
)
.optional()
.default(false),
minIncomeBp: zod
.number()
minIncomeLimitBp: zod
.bigint()
.describe(
option({
description: "Min income limit in basis points as percentage of amount",
alias: "income-limit",
}),
)
.optional()
.default(3n),
minIncomeModifier: zod
.bigint()
.describe(
option({
description: "Min income in basis points as percentage of amount",
alias: "bp",
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(3),
.default(0n),
});

interface Props {
Expand All @@ -135,7 +145,8 @@ export default function Convert({ options }: Props) {
profitable,
loop,
debug,
minIncomeBp,
minIncomeLimitBp,
minIncomeModifier,
fixedPairs,
} = options;

Expand Down Expand Up @@ -189,13 +200,20 @@ 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 = {
Expand Down

0 comments on commit 22eeeda

Please sign in to comment.