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

amm hook fix when executed through leveragelp #624

Merged
merged 1 commit into from
Jun 26, 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
10 changes: 5 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ func NewElysApp(
app.GetSubspace(masterchefmoduletypes.ModuleName),
app.ParameterKeeper,
app.CommitmentKeeper,
app.AmmKeeper,
&app.AmmKeeper,
app.OracleKeeper,
app.AssetprofileKeeper,
app.AccountedPoolKeeper,
Expand All @@ -844,7 +844,7 @@ func NewElysApp(
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
app.AmmKeeper,
&app.AmmKeeper,
app.OracleKeeper,
app.AssetprofileKeeper,
app.AccountedPoolKeeper,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -1021,7 +1021,7 @@ func NewElysApp(
app.BankKeeper,
app.OracleKeeper,
app.AssetprofileKeeper,
app.AmmKeeper,
&app.AmmKeeper,
app.EstakingKeeper,
app.MasterchefKeeper,
app.CommitmentKeeper,
Expand Down
4 changes: 2 additions & 2 deletions scripts/examples/leveragelp/leveragelp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions x/masterchef/keeper/hooks_masterchef.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions x/masterchef/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
),
})
}
Expand Down
1 change: 1 addition & 0 deletions x/masterchef/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ const (
AttributeToBlock = "to_block"
AttributeAmountPerBlock = "amount_per_block"
AttributeSender = "sender"
AttributeRecipient = "recipient"
AttributeMultiplier = "multiplier"
)
Loading