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

feat: add modifier for min income to make conversions easier on ethereum #68

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
40 changes: 31 additions & 9 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
.preprocess(val => BigInt(val as string), zod.bigint())
.describe(
option({
description: "Min income limit in basis points as percentage of amount",
alias: "income-limit",
}),
)
.optional()
.default(3n),
minIncomeModifier: zod
.preprocess(val => BigInt(val as string), 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.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"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.",
"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 income is positive this will accept a lower profit.",

alias: "income-modifier",
}),
)
.optional()
.default(3),
.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 @@ -188,14 +200,24 @@ export default function Convert({ options }: Props) {
amountOut,
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
Loading