From 325f37fdc4a5cd7916db1de6f69cbbb6cf9632fd Mon Sep 17 00:00:00 2001 From: jelysn <129082781+jelysn@users.noreply.github.com> Date: Wed, 26 Jun 2024 21:50:00 +0800 Subject: [PATCH] amm hook fix when executed through leveragelp (#624) --- app/app.go | 10 +++++----- scripts/examples/leveragelp/leveragelp.sh | 4 ++-- x/masterchef/keeper/hooks_masterchef.go | 7 +++---- x/masterchef/keeper/msg_server.go | 2 ++ x/masterchef/types/events.go | 1 + 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index 7232fd4af..610f6608e 100644 --- a/app/app.go +++ b/app/app.go @@ -823,7 +823,7 @@ func NewElysApp( app.GetSubspace(masterchefmoduletypes.ModuleName), app.ParameterKeeper, app.CommitmentKeeper, - app.AmmKeeper, + &app.AmmKeeper, app.OracleKeeper, app.AssetprofileKeeper, app.AccountedPoolKeeper, @@ -844,7 +844,7 @@ func NewElysApp( app.StakingKeeper, app.AccountKeeper, app.BankKeeper, - app.AmmKeeper, + &app.AmmKeeper, app.OracleKeeper, app.AssetprofileKeeper, app.AccountedPoolKeeper, @@ -982,7 +982,7 @@ func NewElysApp( keys[perpetualmoduletypes.StoreKey], keys[perpetualmoduletypes.MemStoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String(), - app.AmmKeeper, + &app.AmmKeeper, app.BankKeeper, app.OracleKeeper, app.AssetprofileKeeper, @@ -1003,7 +1003,7 @@ func NewElysApp( keys[leveragelpmoduletypes.StoreKey], keys[leveragelpmoduletypes.MemStoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String(), - app.AmmKeeper, + &app.AmmKeeper, app.BankKeeper, app.OracleKeeper, app.StablestakeKeeper, @@ -1021,7 +1021,7 @@ func NewElysApp( app.BankKeeper, app.OracleKeeper, app.AssetprofileKeeper, - app.AmmKeeper, + &app.AmmKeeper, app.EstakingKeeper, app.MasterchefKeeper, app.CommitmentKeeper, diff --git a/scripts/examples/leveragelp/leveragelp.sh b/scripts/examples/leveragelp/leveragelp.sh index 56d7a6929..51e05e9f8 100644 --- a/scripts/examples/leveragelp/leveragelp.sh +++ b/scripts/examples/leveragelp/leveragelp.sh @@ -21,11 +21,11 @@ elysd tx gov vote 3 Yes --from=treasury --keyring-backend=test --chain-id=elyste elysd query gov proposals # Open position -elysd tx leveragelp open 5.0 uusdc 500000 1 0.0 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --fees=250uelys +elysd tx leveragelp open 5.0 uusdc 5000000 1 0.0 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --fees=250uelys elysd tx leveragelp open [leverage] [collateral-asset] [collateral-amount] [amm-pool-id] [flags] # Close position -elysd tx leveragelp close 1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd tx leveragelp close 1 500000000000000000 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 elysd tx leveragelp close [position-id] [flags] # Query rewards diff --git a/x/masterchef/keeper/hooks_masterchef.go b/x/masterchef/keeper/hooks_masterchef.go index bd74a96bb..5eac287a0 100644 --- a/x/masterchef/keeper/hooks_masterchef.go +++ b/x/masterchef/keeper/hooks_masterchef.go @@ -44,8 +44,7 @@ func (k Keeper) UpdateAccPerShare(ctx sdk.Context, poolId uint64, rewardDenom st return } poolRewardInfo.PoolAccRewardPerShare = poolRewardInfo.PoolAccRewardPerShare.Add( - math.LegacyNewDecFromInt(amount.Mul(ammtypes.OneShare)). - Quo(math.LegacyNewDecFromInt(totalCommit)), + math.LegacyNewDecFromInt(amount.Mul(ammtypes.OneShare)).QuoInt(totalCommit), ) poolRewardInfo.LastUpdatedBlock = uint64(ctx.BlockHeight()) k.SetPoolRewardInfo(ctx, poolRewardInfo) @@ -83,9 +82,9 @@ func (k Keeper) UpdateUserRewardPending(ctx sdk.Context, poolId uint64, rewardDe userRewardInfo.RewardPending = userRewardInfo.RewardPending.Add( poolRewardInfo.PoolAccRewardPerShare. - Mul(math.LegacyNewDecFromInt(userBalance)). + MulInt(userBalance). Sub(userRewardInfo.RewardDebt). - Quo(math.LegacyNewDecFromInt(ammtypes.OneShare)), + QuoInt(ammtypes.OneShare), ) k.SetUserRewardInfo(ctx, userRewardInfo) diff --git a/x/masterchef/keeper/msg_server.go b/x/masterchef/keeper/msg_server.go index 373df7873..a69937676 100644 --- a/x/masterchef/keeper/msg_server.go +++ b/x/masterchef/keeper/msg_server.go @@ -153,7 +153,9 @@ func (k Keeper) ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []u sdk.NewEvent( types.TypeEvtClaimRewards, sdk.NewAttribute(types.AttributeSender, sender.String()), + sdk.NewAttribute(types.AttributeRecipient, recipient.String()), sdk.NewAttribute(types.AttributePoolId, fmt.Sprintf("%d", poolId)), + sdk.NewAttribute(sdk.AttributeKeyAmount, coin.String()), ), }) } diff --git a/x/masterchef/types/events.go b/x/masterchef/types/events.go index 23d6d6713..5830f81ae 100644 --- a/x/masterchef/types/events.go +++ b/x/masterchef/types/events.go @@ -14,5 +14,6 @@ const ( AttributeToBlock = "to_block" AttributeAmountPerBlock = "amount_per_block" AttributeSender = "sender" + AttributeRecipient = "recipient" AttributeMultiplier = "multiplier" )