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

Solvers solution pre/post interactions #2679

Merged
merged 14 commits into from
May 13, 2024
Merged

Conversation

squadgazzz
Copy link
Contributor

@squadgazzz squadgazzz commented Apr 30, 2024

Description

Adds the ability for solvers to provide pre and post-interactions for a solution.

How to test

TBD

Related Issues

Fixes #2636

Further implementation

  1. The same should be done for gnosis/solvers
  2. Add pre/post-interactions to the Quote response (feat: Pre/post-interactions for Quotes #2680)

@squadgazzz squadgazzz marked this pull request as ready for review April 30, 2024 15:37
@squadgazzz squadgazzz requested a review from a team as a code owner April 30, 2024 15:37
@@ -221,7 +227,11 @@ pub struct Solution {
#[serde_as(as = "HashMap<_, serialize::U256>")]
prices: HashMap<eth::H160, eth::U256>,
trades: Vec<Trade>,
#[serde(default)]
pre_interactions: Vec<Interaction>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the wrong type. It doesn't make sense for solvers to specify Liquidity interactions as pre interactions. It also doesn't make sense for those to be internalizable nor specify input/output amounts. I think they should simply be

struct {
  target: eth::H160,
  value: eth::U256,
  call_data: Vec<u8>,
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switched to InteractionData

Copy link
Contributor

@fleupold fleupold left a comment

Choose a reason for hiding this comment

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

We should note somewhere that this isn't implemented for the boundary settlement encoding (which is fine, I'm hoping to complete the transition by next week)

@@ -94,6 +98,14 @@ pub enum Interaction {
Custom(CustomInteraction),
}

#[derive(Debug, Serialize)]
#[serde(tag = "kind", rename_all = "camelCase")]
pub struct InteractionData {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: maybe

Suggested change
pub struct InteractionData {
pub struct Call {

to avoid confusion with existing Interaction struct?

It would be nice to reuse this type on the CustomInteraction struct, but it seems like that would be a breaking change 😢

@@ -357,6 +361,15 @@ pub struct CustomInteraction {
pub allowances: Vec<Allowance>,
}

/// An arbitrary ethereum interaction that is required for the settlement
/// execution.
#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Can maybe reuse this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Didn't get it. To reuse something from the driver crate in what sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

You are redifining a struct in the domain which already exists in the domain. Now, we might not want to overload structs that happen to have the same fields (generally defining new structs for different semantics is good), but here this is similar to re-defining TokenAmount (which arguably is never going to change).

@@ -357,6 +361,15 @@ pub struct CustomInteraction {
pub allowances: Vec<Allowance>,
}

/// An arbitrary ethereum interaction that is required for the settlement
/// execution.
#[derive(Debug)]
Copy link
Contributor

Choose a reason for hiding this comment

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

You are redifining a struct in the domain which already exists in the domain. Now, we might not want to overload structs that happen to have the same fields (generally defining new structs for different semantics is good), but here this is similar to re-defining TokenAmount (which arguably is never going to change).

pub interactions: Vec<Interaction>,
pub post_interactions: Vec<InteractionData>,
Copy link
Contributor

Choose a reason for hiding this comment

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

It would lead to this:

Suggested change
pub post_interactions: Vec<InteractionData>,
pub post_interactions: Vec<eth::Interaction>,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But eth::Interaction is part of the driver crate, and the solver crate should not depend on the driver, right? Do you want me to extract this type into a shared crate, like model?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, you are completely right (I missed that this was a different create). We could still add this type in the eth module of the solvers crate but not super important.

Copy link

This pull request has been marked as stale because it has been inactive a while. Please update this pull request or it will be automatically closed.

# Conflicts:
#	crates/driver/src/infra/solver/dto/solution.rs
@squadgazzz squadgazzz force-pushed the solution-pre-post-interactions branch from 8abde2c to 3059327 Compare May 13, 2024 14:30
@squadgazzz squadgazzz enabled auto-merge (squash) May 13, 2024 14:54
@squadgazzz squadgazzz merged commit 78dd28c into main May 13, 2024
10 checks passed
@squadgazzz squadgazzz deleted the solution-pre-post-interactions branch May 13, 2024 15:00
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Solver solutions pre/post-interaction support
4 participants