Skip to content

Commit

Permalink
feat: migrate gov proposal away from legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
javiersuweijie committed Sep 7, 2023
1 parent 46382cd commit cc98486
Show file tree
Hide file tree
Showing 7 changed files with 2,141 additions and 197 deletions.
96 changes: 96 additions & 0 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@
- [alliance/tx.proto](#alliance/tx.proto)
- [MsgClaimDelegationRewards](#alliance.MsgClaimDelegationRewards)
- [MsgClaimDelegationRewardsResponse](#alliance.MsgClaimDelegationRewardsResponse)
- [MsgCreateAlliance](#alliance.MsgCreateAlliance)
- [MsgCreateAllianceResponse](#alliance.MsgCreateAllianceResponse)
- [MsgDelegate](#alliance.MsgDelegate)
- [MsgDelegateResponse](#alliance.MsgDelegateResponse)
- [MsgDeleteAlliance](#alliance.MsgDeleteAlliance)
- [MsgDeleteAllianceResponse](#alliance.MsgDeleteAllianceResponse)
- [MsgRedelegate](#alliance.MsgRedelegate)
- [MsgRedelegateResponse](#alliance.MsgRedelegateResponse)
- [MsgUndelegate](#alliance.MsgUndelegate)
- [MsgUndelegateResponse](#alliance.MsgUndelegateResponse)
- [MsgUpdateAlliance](#alliance.MsgUpdateAlliance)
- [MsgUpdateAllianceResponse](#alliance.MsgUpdateAllianceResponse)
- [MsgUpdateParams](#alliance.MsgUpdateParams)
- [MsgUpdateParamsResponse](#alliance.MsgUpdateParamsResponse)

Expand Down Expand Up @@ -1209,6 +1215,37 @@ Params



<a name="alliance.MsgCreateAlliance"></a>

### MsgCreateAlliance



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | |
| `denom` | [string](#string) | | Denom of the asset. It could either be a native token or an IBC token |
| `reward_weight` | [string](#string) | | The reward weight specifies the ratio of rewards that will be given to each alliance asset It does not need to sum to 1. rate = weight / total_weight Native asset is always assumed to have a weight of 1. |
| `take_rate` | [string](#string) | | A positive take rate is used for liquid staking derivatives. It defines an annualized reward rate that will be redirected to the distribution rewards pool |
| `reward_change_rate` | [string](#string) | | |
| `reward_change_interval` | [google.protobuf.Duration](#google.protobuf.Duration) | | |
| `reward_weight_range` | [RewardWeightRange](#alliance.RewardWeightRange) | | set a bound of weight range to limit how much reward weights can scale. |






<a name="alliance.MsgCreateAllianceResponse"></a>

### MsgCreateAllianceResponse







<a name="alliance.MsgDelegate"></a>

### MsgDelegate
Expand Down Expand Up @@ -1236,6 +1273,32 @@ Params



<a name="alliance.MsgDeleteAlliance"></a>

### MsgDeleteAlliance



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | |
| `denom` | [string](#string) | | |






<a name="alliance.MsgDeleteAllianceResponse"></a>

### MsgDeleteAllianceResponse







<a name="alliance.MsgRedelegate"></a>

### MsgRedelegate
Expand Down Expand Up @@ -1291,6 +1354,36 @@ Params



<a name="alliance.MsgUpdateAlliance"></a>

### MsgUpdateAlliance



| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `authority` | [string](#string) | | |
| `denom` | [string](#string) | | Denom of the asset. It could either be a native token or an IBC token |
| `reward_weight` | [string](#string) | | The reward weight specifies the ratio of rewards that will be given to each alliance asset It does not need to sum to 1. rate = weight / total_weight Native asset is always assumed to have a weight of 1. |
| `take_rate` | [string](#string) | | |
| `reward_change_rate` | [string](#string) | | |
| `reward_change_interval` | [google.protobuf.Duration](#google.protobuf.Duration) | | |






<a name="alliance.MsgUpdateAllianceResponse"></a>

### MsgUpdateAllianceResponse







<a name="alliance.MsgUpdateParams"></a>

### MsgUpdateParams
Expand Down Expand Up @@ -1335,6 +1428,9 @@ Params
| `Undelegate` | [MsgUndelegate](#alliance.MsgUndelegate) | [MsgUndelegateResponse](#alliance.MsgUndelegateResponse) | | |
| `ClaimDelegationRewards` | [MsgClaimDelegationRewards](#alliance.MsgClaimDelegationRewards) | [MsgClaimDelegationRewardsResponse](#alliance.MsgClaimDelegationRewardsResponse) | | |
| `UpdateParams` | [MsgUpdateParams](#alliance.MsgUpdateParams) | [MsgUpdateParamsResponse](#alliance.MsgUpdateParamsResponse) | | |
| `CreateAlliance` | [MsgCreateAlliance](#alliance.MsgCreateAlliance) | [MsgCreateAllianceResponse](#alliance.MsgCreateAllianceResponse) | | |
| `UpdateAlliance` | [MsgUpdateAlliance](#alliance.MsgUpdateAlliance) | [MsgUpdateAllianceResponse](#alliance.MsgUpdateAllianceResponse) | | |
| `DeleteAlliance` | [MsgDeleteAlliance](#alliance.MsgDeleteAlliance) | [MsgDeleteAllianceResponse](#alliance.MsgDeleteAllianceResponse) | | |

<!-- end services -->

Expand Down
86 changes: 85 additions & 1 deletion proto/alliance/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "alliance/params.proto";
import "alliance/alliance.proto";
import "google/protobuf/duration.proto";

option go_package = "github.com/terra-money/alliance/x/alliance/types";

Expand All @@ -15,6 +17,9 @@ service Msg {
rpc Undelegate(MsgUndelegate) returns(MsgUndelegateResponse);
rpc ClaimDelegationRewards(MsgClaimDelegationRewards) returns(MsgClaimDelegationRewardsResponse);
rpc UpdateParams(MsgUpdateParams) returns(MsgUpdateParamsResponse);
rpc CreateAlliance(MsgCreateAlliance) returns(MsgCreateAllianceResponse);
rpc UpdateAlliance(MsgUpdateAlliance) returns(MsgUpdateAllianceResponse);
rpc DeleteAlliance(MsgDeleteAlliance) returns(MsgDeleteAllianceResponse);
}

message MsgDelegate {
Expand Down Expand Up @@ -84,4 +89,83 @@ message MsgUpdateParams {
Params params = 2 [(gogoproto.nullable) = false];
}

message MsgUpdateParamsResponse {}
message MsgUpdateParamsResponse {}

message MsgCreateAlliance {
option (cosmos.msg.v1.signer) = "authority";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Denom of the asset. It could either be a native token or an IBC token
string denom = 2 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// A positive take rate is used for liquid staking derivatives. It defines an annualized reward rate that
// will be redirected to the distribution rewards pool
string take_rate = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string reward_change_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration reward_change_interval = 6 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];

// set a bound of weight range to limit how much reward weights can scale.
RewardWeightRange reward_weight_range = 7 [
(gogoproto.nullable) = false
];
}

message MsgCreateAllianceResponse {}

message MsgUpdateAlliance {
option (cosmos.msg.v1.signer) = "authority";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Denom of the asset. It could either be a native token or an IBC token
string denom = 2 [(gogoproto.moretags) = "yaml:\"denom\""];
// The reward weight specifies the ratio of rewards that will be given to each alliance asset
// It does not need to sum to 1. rate = weight / total_weight
// Native asset is always assumed to have a weight of 1.
string reward_weight = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string take_rate = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string reward_change_rate = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

google.protobuf.Duration reward_change_interval = 6 [
(gogoproto.nullable) = false,
(gogoproto.stdduration) = true
];
}

message MsgUpdateAllianceResponse {}

message MsgDeleteAlliance {
option (cosmos.msg.v1.signer) = "authority";

string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string denom = 2 [(gogoproto.moretags) = "yaml:\"denom\""];
}

message MsgDeleteAllianceResponse {}
73 changes: 69 additions & 4 deletions x/alliance/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package keeper

import (
"context"

sdkerrors "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

"github.com/terra-money/alliance/x/alliance/types"

sdk "github.com/cosmos/cosmos-sdk/types"
)

type MsgServer struct {
Expand Down Expand Up @@ -152,6 +150,73 @@ func (m MsgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
return &types.MsgUpdateParamsResponse{}, nil
}

func (m MsgServer) CreateAlliance(ctx context.Context, req *types.MsgCreateAlliance) (*types.MsgCreateAllianceResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
_, found := m.GetAssetByDenom(sdkCtx, req.Denom)

if found {
return nil, types.ErrAlreadyExists
}
rewardStartTime := sdkCtx.BlockTime().Add(m.RewardDelayTime(sdkCtx))
asset := types.AllianceAsset{
Denom: req.Denom,
RewardWeight: req.RewardWeight,
RewardWeightRange: req.RewardWeightRange,
TakeRate: req.TakeRate,
TotalTokens: sdk.ZeroInt(),
TotalValidatorShares: sdk.ZeroDec(),
RewardStartTime: rewardStartTime,
RewardChangeRate: req.RewardChangeRate,
RewardChangeInterval: req.RewardChangeInterval,
LastRewardChangeTime: rewardStartTime,
}
m.SetAsset(sdkCtx, asset)
return &types.MsgCreateAllianceResponse{}, nil
}

func (m MsgServer) UpdateAlliance(ctx context.Context, req *types.MsgUpdateAlliance) (*types.MsgUpdateAllianceResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
asset, found := m.GetAssetByDenom(sdkCtx, req.Denom)

if !found {
return nil, types.ErrUnknownAsset
}
if asset.RewardWeightRange.Min.GT(req.RewardWeight) || asset.RewardWeightRange.Max.LT(req.RewardWeight) {
return nil, types.ErrRewardWeightOutOfBound
}
asset.RewardWeight = req.RewardWeight
asset.TakeRate = req.TakeRate
asset.RewardChangeRate = req.RewardChangeRate
asset.RewardChangeInterval = req.RewardChangeInterval

err := m.UpdateAllianceAsset(sdkCtx, asset)
if err != nil {
return nil, err
}

return &types.MsgUpdateAllianceResponse{}, nil
}

func (m MsgServer) DeleteAlliance(ctx context.Context, req *types.MsgDeleteAlliance) (*types.MsgDeleteAllianceResponse, error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
asset, found := m.GetAssetByDenom(sdkCtx, req.Denom)

if !found {
return nil, types.ErrUnknownAsset
}

if asset.TotalTokens.GT(math.ZeroInt()) {
return nil, types.ErrActiveDelegationsExists
}

err := m.DeleteAsset(sdkCtx, asset)
if err != nil {
return nil, err
}

return &types.MsgDeleteAllianceResponse{}, nil
}

// NewMsgServerImpl returns an implementation of the MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
Expand Down
Loading

0 comments on commit cc98486

Please sign in to comment.