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 4772cb4
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions packages/cli/source/commands/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -135,7 +146,8 @@ export default function Convert({ options }: Props) {
profitable,
loop,
debug,
minIncomeBp,
minIncomeLimitBp,
minIncomeModifier,
fixedPairs,
} = options;

Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 4772cb4

Please sign in to comment.