Skip to content

Commit

Permalink
feat(restaking): add genesis and querier (#46)
Browse files Browse the repository at this point in the history
## Description

This PR adds the genesis and querier implementations for the
`x/restaking` module.
The CLI and invariants implementations will be left for another PR.

**Note**. I still need to add some more tests for the querier, but it's
otherwise good to go.

<!-- 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)
- [ ] 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)

---------

Co-authored-by: Hanjun Kim <[email protected]>
  • Loading branch information
RiccardoM and hallazzang authored Jul 15, 2024
1 parent f287949 commit 2c0d9bd
Show file tree
Hide file tree
Showing 28 changed files with 14,410 additions and 168 deletions.
21 changes: 19 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ import (
"github.com/milkyway-labs/milkyway/x/records"
recordskeeper "github.com/milkyway-labs/milkyway/x/records/keeper"
recordstypes "github.com/milkyway-labs/milkyway/x/records/types"
"github.com/milkyway-labs/milkyway/x/restaking"
restakingkeeper "github.com/milkyway-labs/milkyway/x/restaking/keeper"
restakingtypes "github.com/milkyway-labs/milkyway/x/restaking/types"
"github.com/milkyway-labs/milkyway/x/services"
serviceskeeper "github.com/milkyway-labs/milkyway/x/services/keeper"
servicestypes "github.com/milkyway-labs/milkyway/x/services/types"
Expand Down Expand Up @@ -289,6 +292,7 @@ type MilkyWayApp struct {
ServicesKeeper *serviceskeeper.Keeper
OperatorsKeeper *operatorskeeper.Keeper
PoolsKeeper *poolskeeper.Keeper
RestakingKeeper *restakingkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -352,7 +356,7 @@ func NewMilkyWayApp(
icacallbackstypes.StoreKey, recordstypes.StoreKey, stakeibctypes.StoreKey,

// Custom modules
servicestypes.StoreKey, operatorstypes.StoreKey, poolstypes.StoreKey,
servicestypes.StoreKey, operatorstypes.StoreKey, poolstypes.StoreKey, restakingtypes.StoreKey,
)
tkeys := storetypes.NewTransientStoreKeys(forwardingtypes.TransientStoreKey)
memKeys := storetypes.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -884,6 +888,16 @@ func NewMilkyWayApp(
keys[poolstypes.StoreKey],
app.AccountKeeper,
)
app.RestakingKeeper = restakingkeeper.NewKeeper(
app.appCodec,
keys[restakingtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
app.PoolsKeeper,
app.OperatorsKeeper,
app.ServicesKeeper,
authorityAddr,
)

/**** Module Options ****/

Expand Down Expand Up @@ -934,6 +948,7 @@ func NewMilkyWayApp(
services.NewAppModule(appCodec, app.ServicesKeeper),
operators.NewAppModule(appCodec, app.OperatorsKeeper),
pools.NewAppModule(appCodec, app.PoolsKeeper),
restaking.NewAppModule(appCodec, app.RestakingKeeper),
)

if err := app.setupIndexer(appOpts, homePath, ac, vc, appCodec); err != nil {
Expand Down Expand Up @@ -975,6 +990,7 @@ func NewMilkyWayApp(
servicestypes.ModuleName,
operatorstypes.ModuleName,
poolstypes.ModuleName,
restakingtypes.ModuleName,
)

app.ModuleManager.SetOrderEndBlockers(
Expand All @@ -992,6 +1008,7 @@ func NewMilkyWayApp(
servicestypes.ModuleName,
operatorstypes.ModuleName,
poolstypes.ModuleName,
restakingtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -1011,7 +1028,7 @@ func NewMilkyWayApp(
stakeibctypes.ModuleName, epochstypes.ModuleName, icqtypes.ModuleName,
recordstypes.ModuleName, ratelimittypes.ModuleName, icacallbackstypes.ModuleName,

servicestypes.ModuleName, operatorstypes.ModuleName, poolstypes.ModuleName,
servicestypes.ModuleName, operatorstypes.ModuleName, poolstypes.ModuleName, restakingtypes.ModuleName,
}

app.ModuleManager.SetOrderInitGenesis(genesisModuleOrder...)
Expand Down
6 changes: 3 additions & 3 deletions proto/milkyway/pools/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ option go_package = "github.com/milkyway-labs/milkyway/x/pools/types";
service Query {
// PoolById defines a gRPC query method that returns the pool by the given ID.
rpc PoolById(QueryPoolByIdRequest) returns (QueryPoolResponse) {
option (google.api.http).get = "/milkyway/pool/v1/pool/{pool_id}";
option (google.api.http).get = "/milkyway/pools/v1/pools/{pool_id}";
}

// PoolByDenom defines a gRPC query method that returns the pool by the given
// denom.
rpc PoolByDenom(QueryPoolByDenomRequest) returns (QueryPoolResponse) {
option (google.api.http).get = "/milkyway/pool/v1/pool/denom/{denom}";
option (google.api.http).get = "/milkyway/pools/v1/pool/denom/{denom}";
}

// Pools defines a gRPC query method that returns all pools.
rpc Pools(QueryPoolsRequest) returns (QueryPoolsResponse) {
option (google.api.http).get = "/milkyway/pool/v1/pools";
option (google.api.http).get = "/milkyway/pools/v1/pools";
}
}

Expand Down
47 changes: 46 additions & 1 deletion proto/milkyway/restaking/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ message PoolDelegation {
];
}

// PoolDelegationResponse is equivalent to PoolDelegation except that it
// contains a balance in addition to shares which is more suitable for client
// responses.
message PoolDelegationResponse {
option (gogoproto.equal) = false;

PoolDelegation delegation = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

cosmos.base.v1beta1.Coin balance = 2
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}

// 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.
Expand All @@ -48,6 +61,22 @@ message OperatorDelegation {
];
}

// OperatorDelegationResponse is equivalent to OperatorDelegation except that it
// contains a balance in addition to shares which is more suitable for client
// responses.
message OperatorDelegationResponse {
option (gogoproto.equal) = false;

OperatorDelegation delegation = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

repeated cosmos.base.v1beta1.Coin balance = 2 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}

// 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.
Expand All @@ -66,4 +95,20 @@ message ServiceDelegation {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}
}

// ServiceDelegationResponse is equivalent to ServiceDelegation except that it
// contains a balance in addition to shares which is more suitable for client
// responses.
message ServiceDelegationResponse {
option (gogoproto.equal) = false;

ServiceDelegation delegation = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];

repeated cosmos.base.v1beta1.Coin balance = 2 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
Loading

0 comments on commit 2c0d9bd

Please sign in to comment.