osmosis
osmosis copied to clipboard
Estimate swap
Closes: #2337
What is the purpose of the change
Change EstimateSwap
to not require assets.
Brief Changelog
- Remove field
Sender
inEstimateSwap
queries.
Testing and Verifying
This change is a trivial rework / code cleanup without any test coverage.
Documentation and Release Note
- Does this pull request introduce a new feature or user-facing behavior changes? (yes / no) no
- Is a relevant changelog entry added to the
Unreleased
section inCHANGELOG.md
? (yes / no) no - How is the feature or change documented? (not applicable / specification (
x/<module>/spec/
) / Osmosis docs repo / not documented) not applicable
I've created a PR https://github.com/osmosis-labs/bindings/pull/37 to remove sender
field. And use osmo_reflect.wasm
in this contract.
Thanks @ValarDragon @mattverse. I'll make change from your suggestion.
This absolutely needs a changelog update. @mattverse can you PR one?
Wait this code completely changed since last review, this is so much code duplication and very different. I don't think this is something we should've merged
Reverted the merged PR for now, would be committing on top of this branch for future refactoring and fixes and then re open PR for this
hey duplicate code because estimate swap have similar logic as the real swap. Should we add a boolean parameter estimate
in UpdatePoolForSwap
. Like that
func (k Keeper) updatePoolForSwap(
ctx sdk.Context,
pool types.PoolI,
sender sdk.AccAddress,
tokenIn sdk.Coin,
tokenOut sdk.Coin,
estimate bool,
) error {
tokensIn := sdk.Coins{tokenIn}
tokensOut := sdk.Coins{tokenOut}
err := k.setPool(ctx, pool)
if err != nil {
return err
}
if estimate {
err = k.bankKeeper.SendCoins(ctx, sender, pool.GetAddress(), sdk.Coins{
tokenIn,
})
if err != nil {
return err
}
err = k.bankKeeper.SendCoins(ctx, pool.GetAddress(), sender, sdk.Coins{
tokenOut,
})
if err != nil {
return err
}
events.EmitSwapEvent(ctx, sender, pool.GetId(), tokensIn, tokensOut)
k.hooks.AfterSwap(ctx, sender, pool.GetId(), tokensIn, tokensOut)
}
k.RecordTotalLiquidityIncrease(ctx, tokensIn)
k.RecordTotalLiquidityDecrease(ctx, tokensOut)
return err
}
Also add estimate
in SwapExactAmountIn
, SwapExactAmountOut
,MultihopSwapExactAmountIn
, MultihopSwapExactAmountOut
Yeah, with the scope of this PR getting big, the approach I would want to take on re-merging this PR is me shooting a secondary PR on top of this branch for further refactoring and reducing code duplication, after we merge that second PR into this branch, we can re open this PR, review and then re merge this PR
@vuong177 https://github.com/osmosis-labs/osmosis/pull/2501 would appreciate it if you could also review this :)