Skip to content

Commit 5a1dcfe

Browse files
authored
Update event name and emit internal swapInfo event without deducting fees (#1411)
* update event name and emit event without deducting fees * add comment
1 parent f46fcb5 commit 5a1dcfe

File tree

6 files changed

+10
-19
lines changed

6 files changed

+10
-19
lines changed

x/amm/keeper/apply_exit_pool_state_change.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ func (k Keeper) ApplyExitPoolStateChange(
106106
}
107107

108108
if exitCoins.Len() == 1 {
109+
// swapInfos contains the internal swaps without fees
109110
types.EmitSwapsInfoEvent(ctx, pool.PoolId, exiter.String(), swapInfos)
110111
}
111112

x/amm/keeper/apply_join_pool_state_change.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func (k Keeper) ApplyJoinPoolStateChange(
176176
types.EmitAddLiquidityEvent(ctx, joiner, pool.GetPoolId(), joinCoins)
177177

178178
if joinCoins.Len() == 1 {
179+
// swapInfos contains the internal swaps without fees
179180
types.EmitSwapsInfoEvent(ctx, pool.PoolId, joiner.String(), swapInfos)
180181
}
181182

x/amm/keeper/keeper_join_pool_no_swap.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (k Keeper) JoinPoolNoSwap(
7070
params := k.GetParams(ctx)
7171
takerFees := k.parameterKeeper.GetParams(ctx).GetBigDecTakerFees()
7272
snapshot := k.GetPoolWithAccountedBalance(ctx, pool.PoolId)
73-
tokensJoined, sharesOut, _, weightBalanceBonus, swapFee, takerFeesFinal, virtualSwaps, err := pool.JoinPool(ctx, snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokensIn, params, takerFees)
73+
tokensJoined, sharesOut, _, weightBalanceBonus, swapFee, takerFeesFinal, swapInfos, err := pool.JoinPool(ctx, snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokensIn, params, takerFees)
7474
if err != nil {
7575
return nil, sdkmath.ZeroInt(), err
7676
}
@@ -83,7 +83,7 @@ func (k Keeper) JoinPoolNoSwap(
8383
// slippage will be 0 as tokensIn.Len() != 1
8484
slippageCoins := sdk.Coins{}
8585

86-
err = k.ApplyJoinPoolStateChange(ctx, pool, sender, sharesOut, tokensJoined, weightBalanceBonus, takerFeesFinal, swapFee, slippageCoins, virtualSwaps)
86+
err = k.ApplyJoinPoolStateChange(ctx, pool, sender, sharesOut, tokensJoined, weightBalanceBonus, takerFeesFinal, swapFee, slippageCoins, swapInfos)
8787
if err != nil {
8888
return nil, sdkmath.Int{}, err
8989
}
@@ -100,7 +100,7 @@ func (k Keeper) JoinPoolNoSwap(
100100
takerFees := k.parameterKeeper.GetParams(ctx).GetBigDecTakerFees()
101101
// on oracle pool, full tokenInMaxs are used regardless shareOutAmount
102102
snapshot := k.GetPoolWithAccountedBalance(ctx, pool.PoolId)
103-
tokensJoined, sharesOut, slippage, weightBalanceBonus, swapFee, takerFeesFinal, virtualSwaps, err := pool.JoinPool(ctx, snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokenInMaxs, params, takerFees)
103+
tokensJoined, sharesOut, slippage, weightBalanceBonus, swapFee, takerFeesFinal, swapInfos, err := pool.JoinPool(ctx, snapshot, k.oracleKeeper, k.accountedPoolKeeper, tokenInMaxs, params, takerFees)
104104
if err != nil {
105105
return nil, sdkmath.ZeroInt(), err
106106
}
@@ -148,7 +148,7 @@ func (k Keeper) JoinPoolNoSwap(
148148
shareOutAmount, sharesOut))
149149
}
150150

151-
err = k.ApplyJoinPoolStateChange(ctx, pool, sender, sharesOut, tokensJoined, weightBalanceBonus, takerFeesFinal, swapFee, slippageCoins, virtualSwaps)
151+
err = k.ApplyJoinPoolStateChange(ctx, pool, sender, sharesOut, tokensJoined, weightBalanceBonus, takerFeesFinal, swapFee, slippageCoins, swapInfos)
152152
if err != nil {
153153
return nil, sdkmath.Int{}, err
154154
}

x/amm/types/calc_exit_pool.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func (p Pool) CalcExitPool(
151151
}
152152

153153
swapInfo := NewSwapInfo(swappedWeightedTokenIn, tokenOut)
154+
swapInfos = append(swapInfos, swapInfo)
154155

155156
// Ensure tokenPrice is not zero to avoid division by zero
156157
if tokenPrice.IsZero() {
@@ -198,17 +199,11 @@ func (p Pool) CalcExitPool(
198199

199200
takerFeesFinal = takerFees.Mul(initialWeightIn)
200201

201-
swapInfo.TokenOut.Amount = osmomath.BigDecFromSDKInt(swapInfo.TokenOut.Amount).
202-
Mul(osmomath.OneBigDec().Sub(weightBreakingFee)).
203-
Mul(osmomath.OneBigDec().Sub(swapFee.Add(takerFeesFinal))).Dec().RoundInt()
204-
205202
tokenOutAmount = (oracleOutAmount.
206203
Mul(osmomath.OneBigDec().Sub(weightBreakingFee)).
207204
Mul(osmomath.OneBigDec().Sub(swapFee.Add(takerFeesFinal)))).Dec().RoundInt()
208205
}
209206

210-
swapInfos = append(swapInfos, swapInfo)
211-
212207
return sdk.Coins{sdk.NewCoin(tokenOutDenom, tokenOutAmount)}, weightBalanceBonus, slippage, swapFee, takerFeesFinal, slippageCoins, swapInfos, nil
213208
}
214209

x/amm/types/events.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
TypeEvtUpFrontTokenSwapped = "upfront_token_swapped"
1515
TypeEvtTokenSwappedFee = "token_swapped_fee"
1616
TypeEvtSwapTokenPriceChange = "swap_token_price_change"
17-
TypeEvtVirtualSwaps = "virtual_swaps"
17+
TypeEvtInternalSwaps = "internal_swaps"
1818

1919
AttributeValueCategory = ModuleName
2020
AttributeKeyPoolId = "pool_id"
@@ -146,7 +146,7 @@ func NewRemoveLiquidityEvent(sender sdk.AccAddress, poolId uint64, liquidity sdk
146146

147147
func NewSwapInfoEvent(poolId uint64, sender string, tokensIn, tokensOut sdk.Coins) sdk.Event {
148148
return sdk.NewEvent(
149-
TypeEvtVirtualSwaps,
149+
TypeEvtInternalSwaps,
150150
sdk.NewAttribute(sdk.AttributeKeySender, sender),
151151
sdk.NewAttribute(AttributeKeyPoolId, strconv.FormatUint(poolId, 10)),
152152
sdk.NewAttribute(AttributeKeyTokensIn, tokensIn.String()),

x/amm/types/pool_join_pool.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ func (p *Pool) JoinPool(
166166
if err != nil {
167167
return sdk.NewCoins(), sdkmath.ZeroInt(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), osmomath.ZeroBigDec(), nil, err
168168
}
169+
swapsInfos = append(swapsInfos, NewSwapInfo(swappedTokenIn, secondTokenOut))
169170

170171
tvl, err := p.TVL(ctx, oracleKeeper, accountedPoolKeeper)
171172
if err != nil {
@@ -195,13 +196,6 @@ func (p *Pool) JoinPool(
195196

196197
takerFeesFinal = takerFees.Mul(initialWeightOut)
197198

198-
secondTokenOut.Amount = sdkmath.Int(osmomath.BigDecFromSDKInt(secondTokenOut.Amount).
199-
Mul(joinValueWithSlippage).Quo(tvl).
200-
Mul(osmomath.OneBigDec().Sub(weightBreakingFee)).
201-
Mul(osmomath.OneBigDec().Sub(swapFee.Add(takerFeesFinal))).Dec().RoundInt())
202-
203-
swapsInfos = append(swapsInfos, NewSwapInfo(swappedTokenIn, secondTokenOut))
204-
205199
totalShares := p.GetTotalShares()
206200
numSharesDec := osmomath.BigDecFromSDKInt(totalShares.Amount).
207201
Mul(joinValueWithSlippage).Quo(tvl).

0 commit comments

Comments
 (0)