-
Notifications
You must be signed in to change notification settings - Fork 52
/
query_rewards.go
35 lines (29 loc) · 1012 Bytes
/
query_rewards.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/elys-network/elys/x/leveragelp/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (k Keeper) Rewards(goCtx context.Context, req *types.QueryRewardsRequest) (*types.QueryRewardsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)
totalRewards := sdk.Coins{}
rewardInfos := []*types.RewardInfo{}
for _, id := range req.Ids {
position, err := k.GetPosition(ctx, req.Address, id)
if err != nil {
return &types.QueryRewardsResponse{}, nil
}
coins := k.masterchefKeeper.UserPoolPendingReward(ctx, position.GetPositionAddress(), position.AmmPoolId)
rewardInfos = append(rewardInfos, &types.RewardInfo{
PositionId: id,
Reward: coins,
})
totalRewards = totalRewards.Add(coins...)
}
return &types.QueryRewardsResponse{Rewards: rewardInfos, TotalRewards: totalRewards}, nil
}