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

fix: missing swap event for cw pool #7938

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#7855](https://github.com/osmosis-labs/osmosis/pull/7855) Whitelist address parameter for setting fee tokens
* [#7857](https://github.com/osmosis-labs/osmosis/pull/7857) SuperfluidDelegationsByValidatorDenom query now returns equivalent staked amount
* [#7912](https://github.com/osmosis-labs/osmosis/pull/7912) Default timeoutCommit to 2s
* [#7938](https://github.com/osmosis-labs/osmosis/pull/7938) Add missing swap events for missing swap event for cw pools.

### SDK

Expand Down
6 changes: 4 additions & 2 deletions x/concentrated-liquidity/swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,10 @@ func (k Keeper) updatePoolForSwap(

k.listeners.AfterConcentratedPoolSwap(ctx, swapDetails.Sender, poolId, sdk.Coins{swapDetails.TokenIn}, sdk.Coins{swapDetails.TokenOut})

// TODO: move this to poolmanager and remove from here.
// Also, remove from gamm.
// Emit swap event. Note that we emit these at the layer of each pool module rather than the poolmanager module
// since poolmanager has many swap wrapper APIs that we would need to consider.
// Search for references to this function to see where else it is used.
// Each new pool module will have to emit this event separately
p0mvn marked this conversation as resolved.
Show resolved Hide resolved
events.EmitSwapEvent(ctx, swapDetails.Sender, pool.GetId(), sdk.Coins{swapDetails.TokenIn}, sdk.Coins{swapDetails.TokenOut})

return err
Expand Down
13 changes: 13 additions & 0 deletions x/cosmwasmpool/pool_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/osmosis-labs/osmosis/v24/x/cosmwasmpool/cosmwasm/msg"
"github.com/osmosis-labs/osmosis/v24/x/cosmwasmpool/model"
"github.com/osmosis-labs/osmosis/v24/x/cosmwasmpool/types"
"github.com/osmosis-labs/osmosis/v24/x/poolmanager/events"
poolmanagertypes "github.com/osmosis-labs/osmosis/v24/x/poolmanager/types"

"github.com/osmosis-labs/osmosis/osmoutils/cosmwasm"
Expand Down Expand Up @@ -242,6 +243,12 @@ func (k Keeper) SwapExactAmountIn(
return osmomath.Int{}, err
}

// Emit swap event. Note that we emit these at the layer of each pool module rather than the poolmanager module
// since poolmanager has many swap wrapper APIs that we would need to consider.
// Search for references to this function to see where else it is used.
// Each new pool module will have to emit this event separately
events.EmitSwapEvent(ctx, sender, pool.GetId(), sdk.Coins{tokenIn}, sdk.Coins{sdk.Coin{Denom: tokenOutDenom, Amount: response.TokenOutAmount}})

return response.TokenOutAmount, nil
}

Expand Down Expand Up @@ -343,6 +350,12 @@ func (k Keeper) SwapExactAmountOut(
}
}

// Emit swap event. Note that we emit these at the layer of each pool module rather than the poolmanager module
// since poolmanager has many swap wrapper APIs that we would need to consider.
// Search for references to this function to see where else it is used.
// Each new pool module will have to emit this event separately
events.EmitSwapEvent(ctx, sender, pool.GetId(), sdk.Coins{sdk.Coin{Denom: tokenInDenom, Amount: response.TokenInAmount}}, sdk.Coins{tokenOut})

return response.TokenInAmount, nil
}

Expand Down
4 changes: 4 additions & 0 deletions x/gamm/keeper/swap.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ func (k Keeper) updatePoolForSwap(
return err
}

// Emit swap event. Note that we emit these at the layer of each pool module rather than the poolmanager module
// since poolmanager has many swap wrapper APIs that we would need to consider.
// Search for references to this function to see where else it is used.
// Each new pool module will have to emit this event separately
events.EmitSwapEvent(ctx, sender, pool.GetId(), tokensIn, tokensOut)
k.hooks.AfterCFMMSwap(ctx, sender, pool.GetId(), tokensIn, tokensOut)
k.RecordTotalLiquidityIncrease(ctx, tokensIn)
Expand Down
4 changes: 4 additions & 0 deletions x/poolmanager/events/emit.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/osmosis-labs/osmosis/v24/x/gamm/types"
)

// Emit swap event. Note that we emit these at the layer of each pool module rather than the poolmanager module
// since poolmanager has many swap wrapper APIs that we would need to consider.
// Search for references to this function to see where else it is used.
// Each new pool module will have to emit this event separately
func EmitSwapEvent(ctx sdk.Context, sender sdk.AccAddress, poolId uint64, input sdk.Coins, output sdk.Coins) {
ctx.EventManager().EmitEvents(sdk.Events{
newSwapEvent(sender, poolId, input, output),
Expand Down