Skip to content

Commit

Permalink
feat: protocol-wide restaking cap
Browse files Browse the repository at this point in the history
  • Loading branch information
hallazzang committed Dec 12, 2024
1 parent fccb49b commit cd0043d
Show file tree
Hide file tree
Showing 37 changed files with 1,985 additions and 239 deletions.
206 changes: 183 additions & 23 deletions api/milkyway/restaking/v1/genesis.pulsar.go

Large diffs are not rendered by default.

633 changes: 593 additions & 40 deletions api/milkyway/restaking/v1/models.pulsar.go

Large diffs are not rendered by default.

126 changes: 104 additions & 22 deletions api/milkyway/restaking/v1/params.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,11 @@ func NewAppKeeper(
runtime.NewKVStoreService(appKeepers.keys[poolstypes.StoreKey]),
appKeepers.AccountKeeper,
)
appKeepers.AssetsKeeper = assetskeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[assetstypes.StoreKey]),
govAuthority,
)
appKeepers.RestakingKeeper = restakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[restakingtypes.StoreKey]),
Expand All @@ -518,11 +523,8 @@ func NewAppKeeper(
appKeepers.PoolsKeeper,
appKeepers.OperatorsKeeper,
appKeepers.ServicesKeeper,
govAuthority,
)
appKeepers.AssetsKeeper = assetskeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(appKeepers.keys[assetstypes.StoreKey]),
appKeepers.OracleKeeper,
appKeepers.AssetsKeeper,
govAuthority,
)
appKeepers.RewardsKeeper = rewardskeeper.NewKeeper(
Expand Down
7 changes: 7 additions & 0 deletions proto/milkyway/restaking/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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";

Expand Down Expand Up @@ -76,4 +77,10 @@ message GenesisState {
// UserPreferences represents the user preferences.
repeated UserPreferencesEntry users_preferences = 7
[ (gogoproto.nullable) = false ];

// TotalRestakedAssets represents the total restaked assets.
repeated cosmos.base.v1beta1.Coin total_restaked_assets = 8 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
}
10 changes: 10 additions & 0 deletions proto/milkyway/restaking/v1/models.proto
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,14 @@ message UserPreferences {
// accredited and non-accredited).
repeated uint32 trusted_services_ids = 3
[ (gogoproto.customname) = "TrustedServicesIDs" ];
}

// TotalRestakedAssets is a struct that contains the total amount of assets
// that have been restaked inside the chain.
message TotalRestakedAssets {
// Coins is the amount of coins that have been restaked.
repeated cosmos.base.v1beta1.Coin coins = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false
];
}
9 changes: 9 additions & 0 deletions proto/milkyway/restaking/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";
package milkyway.restaking.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";

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

Expand All @@ -17,4 +18,12 @@ message Params {
// and that will be considered when computing rewards. If no denoms are set,
// all denoms will be considered as restakable.
repeated string allowed_denoms = 2;

// RestakingCap represents the maximum USD value of overall restaked assets
// inside the chain.
string restaking_cap = 3 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
}
12 changes: 10 additions & 2 deletions x/liquidvesting/keeper/end_blocker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ func (suite *KeeperTestSuite) TestKeeper_EndBlocker() {
},
store: func(ctx sdk.Context) {
// Set the unbonding delegation time to 7 days
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(7*24*time.Hour, nil))
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(
7*24*time.Hour,
nil,
restakingtypes.DefaultRestakingCap,
))
suite.Require().NoError(err)

// Add some tokens to the user's insurance fund so they can restake the locked representation
Expand Down Expand Up @@ -117,7 +121,11 @@ func (suite *KeeperTestSuite) TestKeeper_EndBlocker() {
},
store: func(ctx sdk.Context) {
// Set the unbonding delegation time to 7 days
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(7*24*time.Hour, nil))
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(
7*24*time.Hour,
nil,
restakingtypes.DefaultRestakingCap,
))
suite.Require().NoError(err)

// Add some tokens to the user's insurance fund so they can restake
Expand Down
6 changes: 5 additions & 1 deletion x/liquidvesting/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ func (suite *KeeperTestSuite) TestKeeper_ExportGenesis() {
},
store: func(ctx sdk.Context) {
// Set the unbonding delegation time to 7 days
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(7*24*time.Hour, nil))
err = suite.rk.SetParams(ctx, restakingtypes.NewParams(
7*24*time.Hour,
nil,
restakingtypes.DefaultRestakingCap,
))
suite.Require().NoError(err)

// Fund the users' insurance fund
Expand Down
Loading

0 comments on commit cd0043d

Please sign in to comment.