Skip to content

Commit

Permalink
Leveragelp rewards fix (#598)
Browse files Browse the repository at this point in the history
* fix leveragelp rewards query and claim fix

* incremenet version

---------

Co-authored-by: jelysn <[email protected]>
  • Loading branch information
cosmic-vagabond and jelysn committed Jun 19, 2024
1 parent e2a7928 commit 5d3bfde
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.32.2
v0.32.3
12 changes: 11 additions & 1 deletion scripts/examples/leveragelp/leveragelp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ elysd tx stablestake bond 100000000 --from=treasury --keyring-backend=test --cha
elysd tx gov submit-proposal proposal.json --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx gov vote 1 Yes --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd tx gov vote 3 Yes --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000
elysd query gov proposals

# Open position
elysd tx leveragelp open 5 uusdc 500000 1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 --fees=250uelys
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 [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 [position-id] [flags]

# Query rewards
elysd query leveragelp rewards $(elysd keys show -a treasury --keyring-backend=test) 1 --output=json
# {"rewards":[{"position_id":"1","reward":[{"denom":"ueden","amount":"3086835"}]}],"total_rewards":[{"denom":"ueden","amount":"3086835"}]}

# Claim rewards
elysd tx leveragelp claim-rewards 1 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000

elysd query commitment show-commitments $(elysd keys show -a treasury --keyring-backend=test)

# Testnet
elysd query oracle show-price ATOM --node=https://rpc.testnet.elys.network:443
elysd query oracle show-price USDC --node=https://rpc.testnet.elys.network:443
Expand Down
9 changes: 1 addition & 8 deletions x/leveragelp/keeper/msg_server_claim_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,10 @@ func (k msgServer) ClaimRewards(goCtx context.Context, msg *types.MsgClaimReward
if position.Address != msg.Sender {
return nil, types.ErrPositionDoesNotExist
}
err = k.masterchefKeeper.ClaimRewards(ctx, posAddr, []uint64{position.Id})
err = k.masterchefKeeper.ClaimRewards(ctx, posAddr, []uint64{position.AmmPoolId}, sender)
if err != nil {
return nil, err
}
balances := k.bankKeeper.GetAllBalances(ctx, posAddr)
if balances.IsAllPositive() {
err := k.bankKeeper.SendCoins(ctx, posAddr, sender, balances)
if err != nil {
return nil, err
}
}
}

return &types.MsgClaimRewardsResponse{}, nil
Expand Down
6 changes: 1 addition & 5 deletions x/leveragelp/keeper/query_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (
}

ctx := sdk.UnwrapSDKContext(goCtx)
addr, err := sdk.AccAddressFromBech32(req.Address)
if err != nil {
return nil, err
}

totalRewards := sdk.Coins{}
rewardInfos := []*types.RewardInfo{}
Expand All @@ -27,7 +23,7 @@ func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (
if err != nil {
return &types.QueryRewardsResponse{}, nil
}
coins := k.masterchefKeeper.UserPoolPendingReward(ctx, addr, position.AmmPoolId)
coins := k.masterchefKeeper.UserPoolPendingReward(ctx, position.GetPositionAddress(), position.AmmPoolId)
rewardInfos = append(rewardInfos, &types.RewardInfo{
PositionId: id,
Reward: coins,
Expand Down
2 changes: 1 addition & 1 deletion x/leveragelp/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ type AssetProfileKeeper interface {

// MasterchefKeeper defines expected interface for masterchef keeper
type MasterchefKeeper interface {
ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []uint64) error
ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []uint64, recipient sdk.AccAddress) error
UserPoolPendingReward(ctx sdk.Context, user sdk.AccAddress, poolId uint64) sdk.Coins
}
6 changes: 3 additions & 3 deletions x/masterchef/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (k msgServer) AddExternalIncentive(goCtx context.Context, msg *types.MsgAdd
return &types.MsgAddExternalIncentiveResponse{}, nil
}

func (k Keeper) ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []uint64) error {
func (k Keeper) ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []uint64, recipient sdk.AccAddress) error {
coins := sdk.NewCoins()
for _, poolId := range poolIds {
k.AfterWithdraw(ctx, poolId, sender.String(), sdk.ZeroInt())
Expand All @@ -161,7 +161,7 @@ func (k Keeper) ClaimRewards(ctx sdk.Context, sender sdk.AccAddress, poolIds []u
}

// Transfer rewards (Eden/EdenB is transferred through commitment module)
err := k.cmk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, sender, coins)
err := k.cmk.SendCoinsFromModuleToAccount(ctx, types.ModuleName, recipient, coins)
if err != nil {
return err
}
Expand All @@ -180,7 +180,7 @@ func (k msgServer) ClaimRewards(goCtx context.Context, msg *types.MsgClaimReward
}
}

err := k.Keeper.ClaimRewards(ctx, sender, msg.PoolIds)
err := k.Keeper.ClaimRewards(ctx, sender, msg.PoolIds, sender)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5d3bfde

Please sign in to comment.