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

dex: prelude to on-chain arb implementation #2538

Merged
merged 5 commits into from
May 11, 2023
Merged

dex: prelude to on-chain arb implementation #2538

merged 5 commits into from
May 11, 2023

Conversation

hdevalence
Copy link
Member

@hdevalence hdevalence commented May 11, 2023

This PR has changes along the way to starting an arb implementation, split out since they're all mostly finished.

We don't want to actually close the position in the ActionHandler, because
otherwise the economic effects could depend on intra-block ordering, and we'd
lose the ability to do block-scoped JIT liquidity, where a single transaction
opens and closes a position, keeping liquidity live only during that block's
batch swap execution.
@hdevalence hdevalence temporarily deployed to smoke-test May 11, 2023 06:02 — with GitHub Actions Inactive
This gives a common set of parameters for routing.
I think there's a latent bug here, in that the SwapExecution should be indexed
by a _directed_ trading pair...
@hdevalence hdevalence temporarily deployed to smoke-test May 11, 2023 07:32 — with GitHub Actions Inactive
@hdevalence hdevalence changed the title [WIP] Implement arbitrage dex: prelude to on-chain arb implementation May 11, 2023
@hdevalence hdevalence marked this pull request as ready for review May 11, 2023 07:33
Comment on lines +37 to +51
/// Clamps the spill price to the price limit and returns whether or not it was clamped.
pub fn clamp_to_limit(&self, spill_price: Option<U128x128>) -> (Option<U128x128>, bool) {
match (spill_price, self.price_limit) {
(Some(spill_price), Some(price_limit)) => {
if spill_price > price_limit {
(Some(price_limit), true)
} else {
(Some(spill_price), false)
}
}
(Some(spill_price), None) => (Some(spill_price), false),
(None, Some(price_limit)) => (Some(price_limit), true),
(None, None) => (None, false),
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I wrote this for use in distinguishing fill_route and fill_route_exact but didn't end up using it yet (and didn't end up doing that distinguishing, either), if it remains unused it could be deleted later maybe?

Comment on lines +89 to +91
// TODO: how does this work when there are trades in both directions?
// Won't that mix up the traces? Should the SwapExecution be indexed by
// the _DirectedTradingPair_?
Copy link
Member Author

Choose a reason for hiding this comment

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

@zbuc I noticed this and was a bit confused, don't we want to be recording two distinct executions for each pair per block? otherwise the traces would get mixed up between them, right? Or?

Copy link
Member

Choose a reason for hiding this comment

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

I think you're right. That does seem wrong. It seems like we need to execute a batch swap per trading direction.

@@ -164,6 +159,7 @@ trait RouteAndFillInner: StateWrite + Sized {

tracing::debug!(?path, delta_1 = ?delta_1.amount, "found path, starting to fill up to spill price");

// TODO: in what circumstances should we use fill_route_exact?
Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally we'd have one route_and_fill method that we could use for both swaps and arbitrage. I'm not sure, however, how we want to handle price limits in the two cases, relative to the changes in #2535

@hdevalence hdevalence mentioned this pull request May 11, 2023
@hdevalence hdevalence merged commit 49e6e48 into main May 11, 2023
@hdevalence hdevalence deleted the arbitrage branch May 11, 2023 19:34
@cratelyn cratelyn added the A-dex Area: Relates to the dex label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dex Area: Relates to the dex
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants