Skip to content

Commit

Permalink
feat: restaking module keeper and msg server (#31)
Browse files Browse the repository at this point in the history
## Description

This PR implements the write operations of the `x/restaking` module. In
particular, it contains the `Keeper` and `MsgServer` methods to execute
the various restaking-related messages.

All queries and read operations are not present inside this PR, neither
are the module registration inside the `App`, nor clients
implementations. All of this will be implemented with other PRs in the
future. This guarantees that the files changed here are less and easier
to review.

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is
not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR
Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building
modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [x] included the necessary unit and integration
[tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go
code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable
and please add
your handle next to the items reviewed if you only reviewed selected
items.*

I have...

- [ ] confirmed the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored Jul 4, 2024
1 parent 7d4316d commit 9427193
Show file tree
Hide file tree
Showing 52 changed files with 9,414 additions and 185 deletions.
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 {
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

0 comments on commit 9427193

Please sign in to comment.