Skip to content

Commit 0e76e27

Browse files
committed
Merge branch 'restake-init' into master-feed
2 parents fa727f4 + f8a0af0 commit 0e76e27

36 files changed

+2276
-2840
lines changed

app/app.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,11 +428,9 @@ func NewBandApp(
428428
app.RestakeKeeper = restakekeeper.NewKeeper(
429429
appCodec,
430430
keys[restaketypes.StoreKey],
431-
authtypes.FeeCollectorName,
432431
app.AccountKeeper,
433432
app.BankKeeper,
434433
app.StakingKeeper,
435-
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
436434
)
437435

438436
// create IBC Keeper

proto/restake/v1beta1/genesis.proto

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,14 @@ package restake.v1beta1;
33

44
option go_package = "github.com/bandprotocol/chain/v2/x/restake/types";
55

6-
import "amino/amino.proto";
76
import "gogoproto/gogo.proto";
8-
import "cosmos_proto/cosmos.proto";
9-
import "cosmos/base/v1beta1/coin.proto";
107
import "restake/v1beta1/types.proto";
118

129
// GenesisState represents the initial state of the blockchain.
1310
message GenesisState {
1411
// Keys is a list of keys in the module.
1512
repeated Key keys = 1 [(gogoproto.nullable) = false];
1613

17-
// Stake is a list of stakes in the module.
18-
repeated Stake stakes = 2 [(gogoproto.nullable) = false];
19-
20-
// Rewards is a list of rewards in the module.
21-
repeated RewardGenesis rewards = 3 [(gogoproto.nullable) = false];
22-
}
23-
24-
// RewardGenesis message represents reward details for genesis state.
25-
message RewardGenesis {
26-
option (gogoproto.equal) = true;
27-
28-
// Address is the owner address of this reward.
29-
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
30-
31-
// Key is the key that this rewards belongs to.
32-
string key = 2;
33-
34-
// Amounts is a list of reward amounts for this address and key.
35-
repeated cosmos.base.v1beta1.DecCoin amounts = 3 [
36-
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
37-
(gogoproto.nullable) = false,
38-
(amino.dont_omitempty) = true
39-
];
14+
// Locks is a list of locks in the module.
15+
repeated Lock locks = 2 [(gogoproto.nullable) = false];
4016
}

proto/restake/v1beta1/query.proto

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ service Query {
1515
option (google.api.http).get = "/restake/v1beta1/keys";
1616
}
1717

18-
// Key returns a key information
18+
// Key returns a key information.
1919
rpc Key(QueryKeyRequest) returns (QueryKeyResponse) {
2020
option (google.api.http).get = "/restake/v1beta1/keys/{key}";
2121
}
2222

2323
// Rewards returns rewards for a specific address.
2424
rpc Rewards(QueryRewardsRequest) returns (QueryRewardsResponse) {
25-
option (google.api.http).get = "/restake/v1beta1/addresses/{address}/rewards";
25+
option (google.api.http).get = "/restake/v1beta1/lockers/{locker_address}/rewards";
2626
}
2727

2828
// Locks returns all lock information for a specific address.
2929
rpc Locks(QueryLocksRequest) returns (QueryLocksResponse) {
30-
option (google.api.http).get = "/restake/v1beta1/addresses/{address}/locks";
30+
option (google.api.http).get = "/restake/v1beta1/lockers/{locker_address}/locks";
3131
}
3232
}
3333

@@ -59,16 +59,16 @@ message QueryKeyResponse {
5959

6060
// QueryRewardsRequest represents the request type for the Query/Rewards RPC method.
6161
message QueryRewardsRequest {
62-
// Address is the target address to query rewards.
63-
string address = 1;
62+
// LockerAddress is the target address to query rewards.
63+
string locker_address = 1;
6464

6565
// Pagination defines optional pagination parameters.
6666
cosmos.base.query.v1beta1.PageRequest pagination = 2;
6767
}
6868

6969
// QueryRewardsResponse represents the response type for the Query/Rewards RPC method.
7070
message QueryRewardsResponse {
71-
// Rewards is a list of rewards for the address.
71+
// Rewards is a list of rewards for the locker.
7272
repeated Reward rewards = 1;
7373

7474
// Pagination defines pagination parameters in the response.
@@ -77,17 +77,17 @@ message QueryRewardsResponse {
7777

7878
// QueryLocksRequest represents the request type for the Query/Locks RPC method.
7979
message QueryLocksRequest {
80-
// Address is the target address to query locks.
81-
string address = 1;
80+
// LockerAddres is the target address to query locks.
81+
string locker_address = 1;
8282

8383
// Pagination defines optional pagination parameters.
8484
cosmos.base.query.v1beta1.PageRequest pagination = 2;
8585
}
8686

8787
// QueryLocksResponse represents the response type for the Query/Locks RPC method.
8888
message QueryLocksResponse {
89-
// Locks is a list of locks of the address.
90-
repeated Lock locks = 1;
89+
// Locks is a list of locks of the locker.
90+
repeated LockResponse locks = 1;
9191

9292
// Pagination defines pagination parameters in the response.
9393
cosmos.base.query.v1beta1.PageResponse pagination = 2;

proto/restake/v1beta1/tx.proto

Lines changed: 4 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,100 +4,26 @@ package restake.v1beta1;
44
option go_package = "github.com/bandprotocol/chain/v2/x/restake/types";
55

66
import "amino/amino.proto";
7-
import "cosmos/base/v1beta1/coin.proto";
87
import "cosmos/msg/v1/msg.proto";
98
import "cosmos_proto/cosmos.proto";
10-
import "gogoproto/gogo.proto";
119

12-
// Service definition for Msg which handles oracle related messages.
10+
// Service definition for Msg which handles restake related messages.
1311
service Msg {
1412
// RPC method for claiming rewards.
1513
rpc ClaimRewards(MsgClaimRewards) returns (MsgClaimRewardsResponse);
16-
17-
//////////////////////////////////////////
18-
// Methods below are for testing only.
19-
//////////////////////////////////////////
20-
21-
// RPC method for locking powers.
22-
rpc LockPower(MsgLockPower) returns (MsgLockPowerResponse);
23-
24-
// RPC method for adding rewards.
25-
rpc AddRewards(MsgAddRewards) returns (MsgAddRewardsResponse);
26-
27-
// RPC method for deactivating a key.
28-
rpc DeactivateKey(MsgDeactivateKey) returns (MsgDeactivateKeyResponse);
2914
}
3015

3116
// MsgClaimRewards is the request message type for claiming rewards.
3217
message MsgClaimRewards {
33-
option (cosmos.msg.v1.signer) = "address";
18+
option (cosmos.msg.v1.signer) = "locker_address";
3419
option (amino.name) = "restake/MsgClaimRewards";
3520

36-
// Address is the address that will claim the rewards.
37-
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
21+
// LockerAddress is the address that will claim the rewards.
22+
string locker_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
3823

3924
// Key is the key that want to claim rewards from.
4025
string key = 2;
4126
}
4227

4328
// MsgClaimRewardsResponse is the response message type for claiming rewards.
4429
message MsgClaimRewardsResponse {}
45-
46-
// MsgLockPower is the request message type for locking tokens.
47-
message MsgLockPower {
48-
option (cosmos.msg.v1.signer) = "address";
49-
option (amino.name) = "restake/MsgLockPower";
50-
51-
// Address is the address will be locked power.
52-
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
53-
54-
// Key is the key of the lock.
55-
string key = 2;
56-
57-
// Amount is the locked amount.
58-
string amount = 3 [
59-
(cosmos_proto.scalar) = "cosmos.Int",
60-
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
61-
(gogoproto.nullable) = false
62-
];
63-
}
64-
65-
// MsgLockPowerResponse is the response message type for locking power.
66-
message MsgLockPowerResponse {}
67-
68-
// MsgAddRewards is the request message type for adding rewards.
69-
message MsgAddRewards {
70-
option (cosmos.msg.v1.signer) = "sender";
71-
option (amino.name) = "restake/MsgAddRewards";
72-
73-
// Sender is the address that want to send rewards.
74-
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
75-
76-
// Key is the key of pool that reward will be sent to.
77-
string key = 2;
78-
79-
// Rewards is a list of rewards that will send to module.
80-
repeated cosmos.base.v1beta1.Coin rewards = 3 [
81-
(gogoproto.nullable) = false,
82-
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
83-
(gogoproto.jsontag) = "min_deposit,omitempty"
84-
];
85-
}
86-
87-
// MsgAddRewardsResponse is the response message type for adding rewards.
88-
message MsgAddRewardsResponse {}
89-
90-
// MsgDeactivateKey is the request message type for deactivating a key.
91-
message MsgDeactivateKey {
92-
option (cosmos.msg.v1.signer) = "sender";
93-
option (amino.name) = "restake/MsgDeactivateKey";
94-
95-
// Sender is the sender of the message.
96-
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
97-
98-
// Key is the key that will be deactivated.
99-
string key = 2;
100-
}
101-
102-
// MsgDeactivateKeyResponse is the response message type for deactivating a key.
103-
message MsgDeactivateKeyResponse {}

proto/restake/v1beta1/types.proto

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,49 +8,51 @@ import "amino/amino.proto";
88
import "cosmos_proto/cosmos.proto";
99
import "cosmos/base/v1beta1/coin.proto";
1010

11-
// Key message represents a key definition.
11+
// Key message is used for tracking the status and rewards of the keys.
1212
message Key {
1313
option (gogoproto.equal) = true;
1414

1515
// Name is the name of the key.
1616
string name = 1;
1717

18-
// Address is the address that holds rewards for this key.
19-
string address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
18+
// PoolAddress is the address that holds rewards for this key.
19+
string pool_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
2020

2121
// IsActive is the status of the key
2222
bool is_active = 3;
2323

24-
// RewardPerShares is a list of reward_per_share of rewards.
25-
repeated cosmos.base.v1beta1.DecCoin reward_per_shares = 4 [
24+
// RewardPerPowers is a list of reward_per_power.
25+
// new_reward_per_power = current_reward_per_power + (rewards / total_power)
26+
repeated cosmos.base.v1beta1.DecCoin reward_per_powers = 4 [
2627
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
2728
(gogoproto.nullable) = false,
2829
(amino.dont_omitempty) = true
2930
];
3031

31-
// TotalLock is the total locked power of the key.
32-
string total_lock = 5 [
32+
// TotalPower is the total locked power of the key.
33+
string total_power = 5 [
3334
(cosmos_proto.scalar) = "cosmos.Int",
3435
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
3536
(gogoproto.nullable) = false
3637
];
3738

3839
// Remainders is a list of the remainder amounts in the key.
40+
// this field is used to track remainder amount from claimings in the key pool.
3941
repeated cosmos.base.v1beta1.DecCoin remainders = 6 [
4042
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
4143
(gogoproto.nullable) = false,
4244
(amino.dont_omitempty) = true
4345
];
4446
}
4547

46-
// Stake message represents a stake detail.
47-
message Stake {
48+
// Lock message is used to store lock information of each user on each key along with their reward information.
49+
message Lock {
4850
option (gogoproto.equal) = true;
4951

50-
// Address is the owner's address of the stake.
51-
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
52+
// LockerAddress is the owner's address of the locker.
53+
string locker_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
5254

53-
// Key is the key that this stake is locked to.
55+
// Key is the key that this lock is locked to.
5456
string key = 2;
5557

5658
// Amount is the locked power amount.
@@ -62,37 +64,38 @@ message Stake {
6264

6365
// PosRewardDebts is a list of reward debt for each reward (only the positive side).
6466
// Note: Coin and DecCoin can't have negative amounts. so, we split it into two numbers.
65-
repeated cosmos.base.v1beta1.Coin pos_reward_debts = 4 [
66-
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
67+
repeated cosmos.base.v1beta1.DecCoin pos_reward_debts = 4 [
68+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
6769
(gogoproto.nullable) = false,
6870
(amino.dont_omitempty) = true
6971
];
7072

7173
// NegRewardDebts is a list of reward debt for each reward (only negative side).
72-
repeated cosmos.base.v1beta1.Coin neg_reward_debts = 5 [
73-
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
74+
repeated cosmos.base.v1beta1.DecCoin neg_reward_debts = 5 [
75+
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
7476
(gogoproto.nullable) = false,
7577
(amino.dont_omitempty) = true
7678
];
7779
}
7880

79-
// Reward message represents a reward detail.
81+
// Reward message is used as response of the query to show final rewards of the key for the user.
8082
message Reward {
8183
option (gogoproto.equal) = true;
8284

8385
// Key is the key that this reward belongs to.
8486
string key = 1;
8587

86-
// Rewards is a list of rewards.
88+
// Rewards is a list of reward.
8789
repeated cosmos.base.v1beta1.DecCoin rewards = 2 [
8890
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
8991
(gogoproto.nullable) = false,
9092
(amino.dont_omitempty) = true
9193
];
9294
}
9395

94-
// Lock message represents a lock definition.
95-
message Lock {
96+
// LockResponse message is used as response of the query to show the power amount
97+
// that is locked by the key for the user.
98+
message LockResponse {
9699
option (gogoproto.equal) = true;
97100

98101
// Key is the key that this lock belongs to.

x/restake/client/cli/query.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func GetQueryCmd() *cobra.Command {
2121
}
2222

2323
queryCmd.AddCommand(
24+
GetQueryCmdKey(),
2425
GetQueryCmdKeys(),
2526
GetQueryCmdLocks(),
2627
GetQueryCmdRewards(),
@@ -29,6 +30,34 @@ func GetQueryCmd() *cobra.Command {
2930
return queryCmd
3031
}
3132

33+
func GetQueryCmdKey() *cobra.Command {
34+
cmd := &cobra.Command{
35+
Use: "key [name]",
36+
Short: "shows information of the key",
37+
Args: cobra.ExactArgs(1),
38+
RunE: func(cmd *cobra.Command, args []string) error {
39+
clientCtx := client.GetClientContextFromCmd(cmd)
40+
queryClient := types.NewQueryClient(clientCtx)
41+
42+
res, err := queryClient.Key(
43+
context.Background(),
44+
&types.QueryKeyRequest{
45+
Key: args[0],
46+
},
47+
)
48+
if err != nil {
49+
return err
50+
}
51+
52+
return clientCtx.PrintProto(res)
53+
},
54+
}
55+
56+
flags.AddQueryFlagsToCmd(cmd)
57+
58+
return cmd
59+
}
60+
3261
func GetQueryCmdKeys() *cobra.Command {
3362
cmd := &cobra.Command{
3463
Use: "keys",
@@ -68,7 +97,7 @@ func GetQueryCmdLocks() *cobra.Command {
6897
queryClient := types.NewQueryClient(clientCtx)
6998

7099
res, err := queryClient.Locks(context.Background(), &types.QueryLocksRequest{
71-
Address: args[0],
100+
LockerAddress: args[0],
72101
})
73102
if err != nil {
74103
return err
@@ -93,7 +122,7 @@ func GetQueryCmdRewards() *cobra.Command {
93122
queryClient := types.NewQueryClient(clientCtx)
94123

95124
res, err := queryClient.Rewards(context.Background(), &types.QueryRewardsRequest{
96-
Address: args[0],
125+
LockerAddress: args[0],
97126
})
98127
if err != nil {
99128
return err

0 commit comments

Comments
 (0)