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

✨ Add Spot Price In Swap Simulation Query Responses #77

Merged
merged 24 commits into from
Dec 6, 2023

Conversation

NotJeremyLiu
Copy link
Member

@NotJeremyLiu NotJeremyLiu commented Nov 29, 2023

Background

  • We want to be able to return price impact back to api callers.

This PR

  • Creates two new query endpoints for swap venue adapter contracts that return a spot price in addition to the respective asset in/out depending on the simulation request. This is implemented as separate endpoints to not increase gas costs to core contract functionality.
  • Updates deployed contracts to be of the latest deployment of swap venue contracts that expose the endpoints.

@NotJeremyLiu NotJeremyLiu changed the title Add Spot Price In Astroport Simulation Query Responses Add Spot Price In Swap Simulation Query Responses Nov 30, 2023
@NotJeremyLiu NotJeremyLiu marked this pull request as ready for review December 4, 2023 15:53
@@ -220,6 +221,22 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> ContractResult<Binary> {
asset_out,
swap_operations,
)?),
QueryMsg::SimulateSwapExactAssetInWithSpotPrice {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we are added new queries because the old query returns an Asset, and now we need to return two values.

I think there is a learning here, we should always return a "Response" object as a return value as oppose to a raw value like "Asset".

Let's change this name to "SimulateSwapExactAssetInWithMetadata", and added a

#[deprecated(since="{version}", note="please use `SimulateSwapExactAssetInWithMetadata` instead")]

to the enum for SimulateSwapExactAssetIn (similar for Out)

or just put a deprecation comment along those lines, since I think that can only be used on functions.

With the intent of removing the old queries once we update our simulation, and it feels safe to do so.

Copy link
Member Author

Choose a reason for hiding this comment

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

Re: our conversion, I believe we are on the same page that we will continue to use the non-metadata queries for the entrypoint contract, so they will not be deprecated. I assume you no longer want me to add these deprecation notices due to them staying in use.

@@ -322,6 +339,127 @@ fn query_simulate_swap_exact_asset_out(
Ok(asset_in_needed)
}

// Queries the astroport router contract to simulate a swap exact amount in with spot price
fn query_simulate_swap_exact_asset_in_with_spot_price(
Copy link
Member

Choose a reason for hiding this comment

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

Made a alteration here for how I think this code should be organzied

https://gist.github.com/zrbecker/dccb56a2a81f4fc0be6ab4fb9d931d09

If these methods are used internally, we should probably the logic into another function simulate_swap_exact_asset_in, which query_simulate_swap_exact_asset_in and this method can call.

Copy link
Member Author

Choose a reason for hiding this comment

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

completed my take of this new design here: 1c28a99

In particular, instead of always giving back all metadata fields, the metadata queries accept "include_X" boolean params that are checked and used to build up the response as needed.

@@ -322,6 +339,127 @@ fn query_simulate_swap_exact_asset_out(
Ok(asset_in_needed)
}

// Queries the astroport router contract to simulate a swap exact amount in with spot price
fn query_simulate_swap_exact_asset_in_with_spot_price(
Copy link
Member

Choose a reason for hiding this comment

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

I recommend with_metadata instead of spot price, so that we can extend this.

Copy link
Member Author

Choose a reason for hiding this comment

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

changed here: dfb4042

@@ -274,3 +291,47 @@ fn query_simulate_swap_exact_asset_out(
}
.into())
}

// Queries the osmosis poolmanager module to simulate a swap exact amount in with spot price
fn query_simulate_swap_exact_asset_in_with_spot_price(
Copy link
Member

Choose a reason for hiding this comment

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

This is doing what I had in mine for astroport, but I guess the contract extends to it better.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah for Astroport we get the spot price from the simulation responses themselves, so had initially coupled the logic together so that it had one iteration. Now with the new design of getting the responses during simulation and then iterating in the future for spot price, this gets a tad cleaner, but not as clean as the decoupled osmosis version since they actually have spot price queries.

@NotJeremyLiu
Copy link
Member Author

Ready for re-review

@NotJeremyLiu NotJeremyLiu merged commit d34d049 into main Dec 6, 2023
5 checks passed
@NotJeremyLiu NotJeremyLiu deleted the jl/spot-price branch December 6, 2023 19:13
@NotJeremyLiu NotJeremyLiu changed the title Add Spot Price In Swap Simulation Query Responses ✨ Add Spot Price In Swap Simulation Query Responses Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants