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

feat: restaking module keeper and msg server #31

Merged
merged 37 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
60e81c0
feat: add proto files
RiccardoM Jun 8, 2024
531dccc
chore: add new keeper method
RiccardoM Jun 10, 2024
481907a
feat: add genesis and params types and tests
RiccardoM Jun 10, 2024
df6ffee
feat: add messages types and tests
RiccardoM Jun 10, 2024
068810e
feat: implement pool delegation
RiccardoM Jun 10, 2024
ec0400c
chore: fix pool address field name
RiccardoM Jun 14, 2024
6399bd3
feat: add shares and tokens to pool type
RiccardoM Jun 14, 2024
1d46a48
feat: implement pool-based delegation
RiccardoM Jun 14, 2024
fdf704e
feat: add delegations-by-pool-id key
RiccardoM Jun 18, 2024
e75a7aa
feat: add alias functions and tests
RiccardoM Jun 18, 2024
c417060
feat(tests): add pool restaking tests
RiccardoM Jun 18, 2024
60b17a6
refactor: use delegations inside genesis
RiccardoM Jun 18, 2024
97d86be
refactor: implement abstract function to work with all delegation types
RiccardoM Jul 1, 2024
2164718
feat: add msg server
RiccardoM Jul 1, 2024
67c8227
feat: add operator restaking
RiccardoM Jul 1, 2024
08c13bc
feat: implement msg server for operator restaking
RiccardoM Jul 1, 2024
0a766d0
feat(tests): add operator restaking tests
RiccardoM Jul 1, 2024
83fab63
chore: add comments
RiccardoM Jul 1, 2024
94d236c
feat: add check on operator status
RiccardoM Jul 1, 2024
8c949d7
chore: improve operators comments
RiccardoM Jul 1, 2024
0472c11
feat: add service restaking keeper methods
RiccardoM Jul 1, 2024
10373b4
chore: remove param names from mockHooks
RiccardoM Jul 1, 2024
832ac1b
feat: add operator restake msg server
RiccardoM Jul 1, 2024
5e9f900
fix: fix wrong error code
RiccardoM Jul 1, 2024
f436dbf
fix(tests): fix operators restaking tests
RiccardoM Jul 1, 2024
954ea66
feat(tests): add service restaking tests
RiccardoM Jul 1, 2024
56fa295
fix(test): fixed tests
RiccardoM Jul 1, 2024
fe1529c
refactor: remove unused i
RiccardoM Jul 2, 2024
d9b1f14
refactor: use GetPoolDelegation inside alias_functions
RiccardoM Jul 2, 2024
a2dc2e4
chore: update delegation bytes variable name
RiccardoM Jul 2, 2024
60f9133
fix: update service id attribute
RiccardoM Jul 2, 2024
1b3f949
refactor: rename msg service methods names
RiccardoM Jul 2, 2024
d6b50d2
refactor: update how GetAllPoolDelegations is implemented
RiccardoM Jul 2, 2024
d89b844
chore: return nil shares if hook error is not nil
RiccardoM Jul 2, 2024
8b87a42
refactor(tests): split models tests
RiccardoM Jul 2, 2024
2eb1cc1
refactor: improve shares names
RiccardoM Jul 2, 2024
edc3df9
feat(tests): add msg server tests
RiccardoM Jul 2, 2024
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
13 changes: 13 additions & 0 deletions proto/milkyway/operators/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package milkyway.operators.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/operators/types";

Expand Down Expand Up @@ -49,4 +50,16 @@ message Operator {
// Address is the address of the account associated to the operator.
// This will be used to store tokens that are delegated to this operator.
string address = 7 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Tokens define the delegated tokens.
repeated cosmos.base.v1beta1.Coin tokens = 8 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];

// DelegatorShares define the total shares issued to an operator's delegators.
repeated cosmos.base.v1beta1.DecCoin delegator_shares = 9 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}
14 changes: 14 additions & 0 deletions proto/milkyway/pools/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ message Pool {
// Address represents the address of the account that is associated with this
// pool. This will be used to store tokens that users delegate to this pool.
string address = 3 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Tokens define the delegated tokens.
string tokens = 4 [
(cosmos_proto.scalar) = "cosmos.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];

// DelegatorShares defines total shares issued to a pool's delegators.
string delegator_shares = 5 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
27 changes: 27 additions & 0 deletions proto/milkyway/restaking/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";
package milkyway.restaking.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "milkyway/restaking/v1/models.proto";
import "milkyway/restaking/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/restaking/types";

// GenesisState defines the restaking module's genesis state.
message GenesisState {
// Params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];

// PoolDelegations represents the delegations to pools.
repeated PoolDelegation pools_delegations = 2
[ (gogoproto.nullable) = false ];

// ServiceDelegations represents the delegations to services.
repeated ServiceDelegation services_delegations = 3
[ (gogoproto.nullable) = false ];

// OperatorDelegations represents the delegations to operators.
repeated OperatorDelegation operators_delegations = 4
[ (gogoproto.nullable) = false ];
}
124 changes: 124 additions & 0 deletions proto/milkyway/restaking/v1/messages.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
syntax = "proto3";
package milkyway.restaking.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/bank/v1beta1/bank.proto";
import "cosmos/msg/v1/msg.proto";
import "gogoproto/gogo.proto";
import "milkyway/restaking/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/restaking/types";

// Msg defines the restaking module's gRPC message service.
service Msg {
option (cosmos.msg.v1.service) = true;

// DelegatePool defines the operation that allows users to delegate any amount
// of an asset to a pool that can then be used to provide services with
// cryptoeconomic security.
rpc DelegatePool(MsgDelegatePool) returns (MsgDelegatePoolResponse);

// DelegateOperator defines the operation that allows users to delegate their
// assets to a specific operator.
rpc DelegateOperator(MsgDelegateOperator)
returns (MsgDelegateOperatorResponse);

// DelegateService defines the operation that allows users to delegate their
// assets to a specific service.
rpc DelegateService(MsgDelegateService) returns (MsgDelegateServiceResponse);

// UpdateParams defines a (governance) operation for updating the module
// parameters.
// The authority defaults to the x/gov module account.
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgDelegatePool defines the message structure for the DelegatePool gRPC
// service method. It allows a user to put their assets into a restaking pool
// that will later be used to provide cryptoeconomic security to services that
// choose it.
message MsgDelegatePool {
option (cosmos.msg.v1.signer) = "delegator";
option (amino.name) = "milkyway/MsgJoinRestakingPool";

// Delegator is the address of the user joining the pool
string delegator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Amount is the amount of coins to be staked
cosmos.base.v1beta1.Coin amount = 2
[ (gogoproto.customname) = "Amount", (gogoproto.nullable) = false ];
}

// MsgDelegatePoolResponse defines the return value of MsgDelegatePool.
message MsgDelegatePoolResponse {}

// MsgDelegateOperator defines the message structure for the OperatorRestake
// gRPC service method. It allows a user to delegate their assets to an
// operator.
message MsgDelegateOperator {
option (cosmos.msg.v1.signer) = "delegator";
option (amino.name) = "milkyway/MsgDelegateOperator";

// Delegator is the address of the user delegating to the operator
string delegator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// OperatorID is the ID of the operator to delegate to
uint32 operator_id = 2 [ (gogoproto.customname) = "OperatorID" ];

// Amount is the amount of coins to be delegated
repeated cosmos.base.v1beta1.Coin amount = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.customname) = "Amount",
(gogoproto.nullable) = false
];
}

// MsgDelegateOperatorResponse is the return value of MsgDelegateOperator.
message MsgDelegateOperatorResponse {}

// MsgDelegateService defines the message structure for the ServiceRestake gRPC
// service method. It allows a user to delegate their assets to a service.
message MsgDelegateService {
option (cosmos.msg.v1.signer) = "delegator";
option (amino.name) = "milkyway/MsgDelegateService";

// Delegator is the address of the user delegating to the service
string delegator = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// ServiceID is the ID of the service to delegate to
uint32 service_id = 2 [ (gogoproto.customname) = "ServiceID" ];

// Amount is the amount of coins to be delegated
repeated cosmos.base.v1beta1.Coin amount = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.customname) = "Amount",
(gogoproto.nullable) = false
];
}

// MsgDelegateServiceResponse is the return value of MsgDelegateService.
message MsgDelegateServiceResponse {}

// MsgDeactivateService defines the message structure for the UpdateParams gRPC
// service method. It allows the authority to update the module parameters.
message MsgUpdateParams {
option (cosmos.msg.v1.signer) = "authority";
option (amino.name) = "milkyway/x/restaking/MsgUpdateParams";

// Authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [
(gogoproto.moretags) = "yaml:\"authority\"",
(cosmos_proto.scalar) = "cosmos.AddressString"
];

// Params define the parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
}

// MsgDeactivateServiceResponse is the return value of MsgUpdateParams.
message MsgUpdateParamsResponse {}
69 changes: 69 additions & 0 deletions proto/milkyway/restaking/v1/models.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
syntax = "proto3";
package milkyway.restaking.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/restaking/types";

// PoolDelegation represents the bond with tokens held by an account with a
// given pool. It is owned by one delegator, and is associated with a pool.
message PoolDelegation {
hallazzang marked this conversation as resolved.
Show resolved Hide resolved
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// UserAddress is the encoded address of the user.
string user_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// PoolID is the id of the pool.
uint32 pool_id = 2 [ (gogoproto.customname) = "PoolID" ];

// Shares define the delegation shares received.
string shares = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}

// OperatorDelegation represents the bond with tokens held by an account with a
// given operator. It is owned by one delegator, and is associated with a
// operator.
message OperatorDelegation {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// UserAddress is the encoded address of the user.
string user_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// OperatorID is the id of the operator.
uint32 operator_id = 2 [ (gogoproto.customname) = "OperatorID" ];

// Shares define the delegation shares received.
repeated cosmos.base.v1beta1.DecCoin shares = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}

// ServiceDelegation represents the bond with tokens held by an account with a
// given service. It is owned by one delegator, and is associated with a
// service.
message ServiceDelegation {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

// UserAddress is the encoded address of the user.
string user_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// ServiceID is the id of the service.
uint32 service_id = 2 [ (gogoproto.customname) = "ServiceID" ];

// Shares define the delegation shares received.
repeated cosmos.base.v1beta1.DecCoin shares = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}
17 changes: 17 additions & 0 deletions proto/milkyway/restaking/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
syntax = "proto3";
package milkyway.restaking.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/restaking/types";

// Params defines the parameters for the module.
message Params {

// UnbondingTime represents the time that will take for assets to be unbonded
// after the user initiates an unbonding request. This will be applied to all
// types of restaking: pool, operator and service restaking.
int64 unbonding_time = 1 [ (gogoproto.stdduration) = true ];
}
14 changes: 13 additions & 1 deletion proto/milkyway/services/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package milkyway.services.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/milkyway-labs/milkyway/x/services/types";

Expand Down Expand Up @@ -48,9 +49,20 @@ message Service {
// PictureURL is the URL of the picture of the service
string picture_url = 7 [ (gogoproto.customname) = "PictureURL" ];


// Address is the address of the account associated with the service.
// This will be used in order to store all the tokens that are delegated to
// this service by various users.
string address = 8 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];

// Tokens define the delegated tokens.
repeated cosmos.base.v1beta1.Coin tokens = 9 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];

// DelegatorShares define the total shares issued to an operator's delegators.
repeated cosmos.base.v1beta1.DecCoin delegator_shares = 10 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}
2 changes: 2 additions & 0 deletions x/operators/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ var (
ErrInvalidGenesis = errors.Register(ModuleName, 1, "invalid genesis state")
ErrInvalidDeactivationTime = errors.Register(ModuleName, 2, "invalid deactivation time")
ErrOperatorNotFound = errors.Register(ModuleName, 3, "operator not found")
ErrOperatorNotActive = errors.Register(ModuleName, 4, "operator not active")
ErrInsufficientShares = errors.Register(ModuleName, 5, "insufficient delegation shares")
)
Loading
Loading