From fd3f811f8eb2c12b83202cb5f8e9947d62411c66 Mon Sep 17 00:00:00 2001 From: Jeremy Liu <31809888+NotJeremyLiu@users.noreply.github.com> Date: Fri, 26 May 2023 11:17:05 -0400 Subject: [PATCH] Jl/add in and out coins to cl swap listener (#4950) * Add input and output - Follows gamm module patterns such as 1) naming convention and 2) providing tokens (sdk.Coins) even though it's currently expected to be a single token in or out (sdk.Coin). * Update modules that use hook * add changelog entry --- CHANGELOG.md | 1 + x/concentrated-liquidity/clmocks/listeners.go | 2 +- x/concentrated-liquidity/swaps.go | 2 +- x/concentrated-liquidity/types/listeners.go | 6 +++--- x/pool-incentives/keeper/hooks.go | 2 +- x/twap/listeners.go | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 771185234da..f7279f83599 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * [#5239](https://github.com/osmosis-labs/osmosis/pull/5239) Implement `GetTotalPoolShares` public keeper function for GAMM. * [#5261](https://github.com/osmosis-labs/osmosis/pull/5261) Allows `UpdateFeeTokenProposal` to take in multiple fee tokens instead of just one. * [#5265](https://github.com/osmosis-labs/osmosis/pull/5265) Ensure a lock cannot point to multiple synthetic locks. Deprecates `SyntheticLockupsByLockupID` in favor of `SyntheticLockupByLockupID`. + * [#4950] (https://github.com/osmosis-labs/osmosis/pull/4950) Add in/out tokens to Concentrated Liquidity's AfterConcentratedPoolSwap hook ### API breaks diff --git a/x/concentrated-liquidity/clmocks/listeners.go b/x/concentrated-liquidity/clmocks/listeners.go index 45d8aa19cf6..82af37a6db5 100644 --- a/x/concentrated-liquidity/clmocks/listeners.go +++ b/x/concentrated-liquidity/clmocks/listeners.go @@ -27,6 +27,6 @@ func (l *ConcentratedLiquidityListenerMock) AfterLastPoolPositionRemoved(ctx sdk l.AfterLastPoolPositionRemovedCallCount += 1 } -func (l *ConcentratedLiquidityListenerMock) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) { +func (l *ConcentratedLiquidityListenerMock) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) { l.AfterConcentratedPoolSwapCallCount += 1 } diff --git a/x/concentrated-liquidity/swaps.go b/x/concentrated-liquidity/swaps.go index 189b583d8d7..4805a31687a 100644 --- a/x/concentrated-liquidity/swaps.go +++ b/x/concentrated-liquidity/swaps.go @@ -740,7 +740,7 @@ func (k Keeper) updatePoolForSwap( return err } - k.listeners.AfterConcentratedPoolSwap(ctx, sender, poolId) + k.listeners.AfterConcentratedPoolSwap(ctx, sender, poolId, sdk.Coins{tokenIn}, sdk.Coins{tokenOut}) // TODO: move this to poolmanager and remove from here. // Also, remove from gamm. diff --git a/x/concentrated-liquidity/types/listeners.go b/x/concentrated-liquidity/types/listeners.go index 48d38696912..2660a60ab5b 100644 --- a/x/concentrated-liquidity/types/listeners.go +++ b/x/concentrated-liquidity/types/listeners.go @@ -12,7 +12,7 @@ type ConcentratedLiquidityListener interface { // liquidity pool. AfterLastPoolPositionRemoved(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) // AfterConcentratedPoolSwap is called after a swap in a concentrated liquidity pool. - AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) + AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) } type ConcentratedLiquidityListeners []ConcentratedLiquidityListener @@ -37,9 +37,9 @@ func (l ConcentratedLiquidityListeners) AfterLastPoolPositionRemoved(ctx sdk.Con } } -func (l ConcentratedLiquidityListeners) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) { +func (l ConcentratedLiquidityListeners) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) { for i := range l { - l[i].AfterConcentratedPoolSwap(ctx, sender, poolId) + l[i].AfterConcentratedPoolSwap(ctx, sender, poolId, input, output) } } diff --git a/x/pool-incentives/keeper/hooks.go b/x/pool-incentives/keeper/hooks.go index f57e40bee70..fe3d5494154 100644 --- a/x/pool-incentives/keeper/hooks.go +++ b/x/pool-incentives/keeper/hooks.go @@ -78,5 +78,5 @@ func (h Hooks) AfterLastPoolPositionRemoved(ctx sdk.Context, sender sdk.AccAddre } // AfterConcentratedPoolSwap is a noop. -func (h Hooks) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) { +func (h Hooks) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) { } diff --git a/x/twap/listeners.go b/x/twap/listeners.go index 1b462781cfa..e2a55f0ce5a 100644 --- a/x/twap/listeners.go +++ b/x/twap/listeners.go @@ -80,6 +80,6 @@ func (l *concentratedLiquidityListener) AfterLastPoolPositionRemoved(ctx sdk.Con l.k.trackChangedPool(ctx, poolId) } -func (l *concentratedLiquidityListener) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64) { +func (l *concentratedLiquidityListener) AfterConcentratedPoolSwap(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) { l.k.trackChangedPool(ctx, poolId) }