Skip to content

Commit

Permalink
collect in join and exit
Browse files Browse the repository at this point in the history
  • Loading branch information
amityadav0 committed Jan 24, 2025
1 parent 8b61c90 commit 4bbb331
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
2 changes: 0 additions & 2 deletions x/amm/keeper/apply_exit_pool_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ func (k Keeper) ApplyExitPoolStateChange(ctx sdk.Context, pool types.Pool, exite
// we are multiplying here by params.WeightBreakingFeePortion as we didn't multiply in pool.Join/Exit for weight breaking fee
weightRecoveryFee := weightBalanceBonus.Abs().Mul(params.WeightBreakingFeePortion)

var weightRecoveryFeeAmounts sdk.Coins
for _, coin := range exitCoins {
weightRecoveryFeeAmount = coin.Amount.ToLegacyDec().Mul(weightRecoveryFee).RoundInt()
weightRecoveryFeeAmounts = append(weightRecoveryFeeAmounts, sdk.NewCoin(coin.Denom, weightRecoveryFeeAmount))

if weightRecoveryFeeAmount.IsPositive() {
// send weight recovery fee to rebalance treasury if weight recovery fee amount is positive¬
Expand Down
41 changes: 16 additions & 25 deletions x/amm/keeper/apply_join_pool_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,27 @@ func (k Keeper) ApplyJoinPoolStateChange(
rebalanceTreasury := sdk.MustAccAddressFromBech32(pool.GetRebalanceTreasury())
// we are multiplying here by params.WeightBreakingFeePortion as we didn't multiply in pool.Join/Exit for weight breaking fee
weightRecoveryFee := weightBalanceBonus.Abs().Mul(params.WeightBreakingFeePortion)
for _, coin := range joinCoins {
weightRecoveryFeeAmount = coin.Amount.ToLegacyDec().Mul(weightRecoveryFee).RoundInt()

if givenOut {
weightRecoveryFeeAmount = oracleInAmount.ToLegacyDec().Mul(weightRecoveryFee).RoundInt()
} else {
weightRecoveryFeeAmount = tokenIn.Amount.ToLegacyDec().Mul(weightRecoveryFee).RoundInt()
}

if weightRecoveryFeeAmount.IsPositive() {
// send weight recovery fee to rebalance treasury if weight recovery fee amount is positive¬
netWeightBreakingFeeCoins := sdk.Coins{sdk.NewCoin(tokenIn.Denom, weightRecoveryFeeAmount)}
if weightRecoveryFeeAmount.IsPositive() {
// send weight recovery fee to rebalance treasury if weight recovery fee amount is positive¬
netWeightBreakingFeeCoins := sdk.Coins{sdk.NewCoin(coin.Denom, weightRecoveryFeeAmount)}

err = k.bankKeeper.SendCoins(ctx, poolAddr, rebalanceTreasury, netWeightBreakingFeeCoins)
if err != nil {
return err
}
err := k.bankKeeper.SendCoins(ctx, poolAddr, rebalanceTreasury, netWeightBreakingFeeCoins)
if err != nil {
return err
}

Check warning on line 48 in x/amm/keeper/apply_join_pool_state_change.go

View check run for this annotation

Codecov / codecov/patch

x/amm/keeper/apply_join_pool_state_change.go#L34-L48

Added lines #L34 - L48 were not covered by tests

err = k.RemoveFromPoolBalanceAndUpdateLiquidity(ctx, &pool, sdkmath.ZeroInt(), netWeightBreakingFeeCoins)
if err != nil {
return err
}
err = k.RemoveFromPoolBalanceAndUpdateLiquidity(ctx, &pool, sdkmath.ZeroInt(), netWeightBreakingFeeCoins)
if err != nil {
return err
}

Check warning on line 53 in x/amm/keeper/apply_join_pool_state_change.go

View check run for this annotation

Codecov / codecov/patch

x/amm/keeper/apply_join_pool_state_change.go#L50-L53

Added lines #L50 - L53 were not covered by tests

// Track amount in pool
weightRecoveryFeeAmountForPool := sdkmath.ZeroInt()
weightRecoveryFeeForPool := weightBalanceBonus.Abs().Mul(sdkmath.LegacyOneDec().Sub(params.WeightBreakingFeePortion))
if givenOut {
weightRecoveryFeeAmountForPool = oracleInAmount.ToLegacyDec().Mul(weightRecoveryFeeForPool).RoundInt()
} else {
weightRecoveryFeeAmountForPool = tokenIn.Amount.ToLegacyDec().Mul(weightRecoveryFeeForPool).RoundInt()
// Track amount in pool
weightRecoveryFeeForPool := weightBalanceBonus.Abs().Mul(sdkmath.LegacyOneDec().Sub(params.WeightBreakingFeePortion))
k.TrackWeightBreakingSlippage(ctx, pool.PoolId, sdk.NewCoin(coin.Denom, sdkmath.Int(weightRecoveryFeeForPool.Mul(sdkmath.LegacyDec(weightRecoveryFeeAmount)))))

Check warning on line 57 in x/amm/keeper/apply_join_pool_state_change.go

View check run for this annotation

Codecov / codecov/patch

x/amm/keeper/apply_join_pool_state_change.go#L56-L57

Added lines #L56 - L57 were not covered by tests
}
k.TrackWeightBreakingSlippage(ctx, pool.PoolId, sdk.NewCoin(tokenIn.Denom, weightRecoveryFeeAmountForPool))
}
}

Expand Down

0 comments on commit 4bbb331

Please sign in to comment.