Skip to content

Commit

Permalink
Merge pull request #175 from sunriselayer/fix/sunrise-lockup-account
Browse files Browse the repository at this point in the history
fix: sunrise-lockup-account
  • Loading branch information
kimurayu45z authored Jan 16, 2025
2 parents 998c2c1 + 71337a0 commit fc65121
Show file tree
Hide file tree
Showing 11 changed files with 4,216 additions and 179 deletions.
7 changes: 5 additions & 2 deletions app/app_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ var (
// this line is used by starport scaffolding # stargate/app/maccPerms

{Account: damoduletypes.ModuleName},
{Account: tokenconvertermoduletypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner, authtypes.Staking}},
{Account: tokenconvertermoduletypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
{Account: liquiditypoolmoduletypes.ModuleName, Permissions: []string{authtypes.Minter, authtypes.Burner}},
{Account: liquidityincentivemoduletypes.ModuleName, Permissions: []string{authtypes.Minter}},
{Account: swapmoduletypes.ModuleName},
Expand Down Expand Up @@ -212,9 +212,12 @@ var (
// NOTE: The genutils module must also occur after auth so that it can access the params from auth.
InitGenesis: []string{
consensustypes.ModuleName,
// <sunrise>
authtypes.ModuleName,
banktypes.ModuleName,
stakingtypes.ModuleName,
tokenconvertermoduletypes.ModuleName,
// </sunrise>
accounts.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
Expand All @@ -238,7 +241,7 @@ var (
ibcfeetypes.ModuleName,
// chain modules
damoduletypes.ModuleName,
tokenconvertermoduletypes.ModuleName,

liquiditypoolmoduletypes.ModuleName,
liquidityincentivemoduletypes.ModuleName,
swapmoduletypes.ModuleName,
Expand Down
2 changes: 1 addition & 1 deletion docs/static/openapi.json

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions proto/sunrise/accounts/self_delegatable_lockup/v1/lockup.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
syntax = "proto3";
package sunrise.accounts.self_delegatable_lockup.v1;

import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "github.com/sunriselayer/sunrise/x/accounts/self_delegatable_lockup/v1";

// Period defines a length of time and amount of coins that will be lock.
message Period {
// Period duration
google.protobuf.Duration length = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdduration) = true
];
repeated cosmos.base.v1beta1.Coin amount = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(amino.encoding) = "legacy_coins",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

message UnbondingEntries {
repeated UnbondingEntry entries = 1;
}

// UnbondingEntry defines an entry tracking the lockup account unbonding operation.
message UnbondingEntry {
int64 creation_height = 1;
// end time of entry
google.protobuf.Timestamp end_time = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdtime) = true
];
// unbond amount
cosmos.base.v1beta1.Coin amount = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
// validator address
string validator_address = 4 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}
86 changes: 86 additions & 0 deletions proto/sunrise/accounts/self_delegatable_lockup/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
syntax = "proto3";
package sunrise.accounts.self_delegatable_lockup.v1;

import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "sunrise/accounts/self_delegatable_lockup/v1/lockup.proto";

option go_package = "github.com/sunriselayer/sunrise/x/accounts/self_delegatable_lockup/v1";

// QueryLockupAccountInfoRequest get lockup account info
message QueryLockupAccountInfoRequest {}

// QueryLockupAccountInfoResponse return lockup account info
message QueryLockupAccountInfoResponse {
// original_locking defines the value of the account original locking coins.
repeated cosmos.base.v1beta1.Coin original_locking = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// delegated_free defines the value of the account free delegated amount.
repeated cosmos.base.v1beta1.Coin delegated_free = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// delegated_locking defines the value of the account locking delegated amount.
repeated cosmos.base.v1beta1.Coin delegated_locking = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// end_time defines the value of the account lockup start time.
google.protobuf.Timestamp start_time = 4 [(gogoproto.stdtime) = true];

// end_time defines the value of the account lockup end time.
google.protobuf.Timestamp end_time = 5 [(gogoproto.stdtime) = true];

// locked_coins defines the value of the account locking coins.
repeated cosmos.base.v1beta1.Coin locked_coins = 6 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// unlocked_coins defines the value of the account released coins from lockup.
repeated cosmos.base.v1beta1.Coin unlocked_coins = 7 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];

// owner defines the value of the owner of the lockup account.
string owner = 8;
}

// QueryUnbondingEntriesRequest is used to query the lockup account unbonding entries.
message QueryUnbondingEntriesRequest {
string validator_address = 1 [(cosmos_proto.scalar) = "cosmos.ValidatorAddressString"];
}

// QueryUnbondingEntriesResponse returns the lockup account unbonding entries.
message QueryUnbondingEntriesResponse {
// UnbondingEntry defines the list of unbonding entries.
repeated UnbondingEntry unbonding_entries = 1;
}

// QueryLockingPeriodsRequest is used to query the periodic lockup account locking periods.
message QueryLockingPeriodsRequest {}

// QueryLockingPeriodsResponse returns the periodic lockup account locking periods.
message QueryLockingPeriodsResponse {
// lockup_periods defines the value of the periodic lockup account locking periods.
repeated Period locking_periods = 1;
}

// QuerySpendableAmountRequest is used to query the lockup account total spendable tokens.
message QuerySpendableAmountRequest {}

// QuerySpendableAmountResponse returns lockup account total spendable tokens.
message QuerySpendableAmountResponse {
repeated cosmos.base.v1beta1.Coin spendable_tokens = 1 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}
78 changes: 72 additions & 6 deletions proto/sunrise/accounts/self_delegatable_lockup/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,19 +1,64 @@
syntax = "proto3";
package sunrise.accounts.self_delegatable_lockup.v1;

import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";
import "sunrise/accounts/self_delegatable_lockup/v1/lockup.proto";

option go_package = "github.com/sunriselayer/sunrise/x/accounts/self_delegatable_lockup/v1";

// MsgInit
message MsgInit {
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// MsgInitSelfDelegatableLockupAccount defines a message that enables creating a self-delegatable lockup account.
message MsgInitSelfDelegatableLockupAccount {
option (amino.name) = "cosmos-sdk/MsgInitLockupAccount";
option (gogoproto.equal) = true;

// owner of the vesting account
string owner = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// end_time is end of lockup
google.protobuf.Timestamp end_time = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdtime) = true
];
// start_time is start of lockup
google.protobuf.Timestamp start_time = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdtime) = true
];
}

// MsgInitResponse is the response returned after base account initialization.
// This is empty.
message MsgInitResponse {}
// MsgInitSelfDelegatableLockupAccountResponse defines the Msg/InitSelfDelegatableLockupAccount response type.
message MsgInitSelfDelegatableLockupAccountResponse {}

// MsgInitSelfDelegatablePeriodicLockingAccount defines a message that enables creating a self-delegatable periodic locking
// account.
message MsgInitSelfDelegatablePeriodicLockingAccount {
option (amino.name) = "cosmos-sdk/MsgInitPeriodLockupAccount";
option (gogoproto.equal) = false;

// owner of the lockup account
string owner = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// start of lockup
google.protobuf.Timestamp start_time = 2 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.stdtime) = true
];
repeated Period locking_periods = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}

// MsgInitSelfDelegatablePeriodicLockingAccountResponse defines the Msg/InitSelfDelegatablePeriodicLockingAccount
// response type.
message MsgInitSelfDelegatablePeriodicLockingAccountResponse {}

// MsgSelfDelegate
message MsgSelfDelegate {
Expand Down Expand Up @@ -42,3 +87,24 @@ message MsgWithdrawSelfDelegationUnbonded {

// MsgWithdrawSelfDelegationUnbondedResponse
message MsgWithdrawSelfDelegationUnbondedResponse {}

// MsgSend defines a message that enable lockup account to execute send message
message MsgSend {
option (cosmos.msg.v1.signer) = "sender";
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
string to_address = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];
repeated cosmos.base.v1beta1.Coin amount = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(amino.encoding) = "legacy_coins",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// MsgExecuteMessagesResponse defines the response for lockup execute operations
message MsgExecuteMessagesResponse {
repeated google.protobuf.Any responses = 1;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ContinuousLockingAccount struct {
StartTime collections.Item[time.Time]
}

func (cva ContinuousLockingAccount) Init(ctx context.Context, msg *lockuptypes.MsgInitLockupAccount) (*lockuptypes.MsgInitLockupAccountResponse, error) {
func (cva ContinuousLockingAccount) Init(ctx context.Context, msg *v1.MsgInitSelfDelegatableLockupAccount) (*v1.MsgInitSelfDelegatableLockupAccountResponse, error) {
if msg.EndTime.IsZero() {
return nil, sdkerrors.ErrInvalidRequest.Wrapf("invalid end time %s", msg.EndTime.String())
}
Expand Down Expand Up @@ -70,8 +70,8 @@ func (cva ContinuousLockingAccount) Init(ctx context.Context, msg *lockuptypes.M
// return cva.BaseLockup.Delegate(ctx, msg, cva.GetLockedCoinsWithDenoms)
// }

func (cva *ContinuousLockingAccount) SendCoins(ctx context.Context, msg *lockuptypes.MsgSend) (
*lockuptypes.MsgExecuteMessagesResponse, error,
func (cva *ContinuousLockingAccount) SendCoins(ctx context.Context, msg *v1.MsgSend) (
*v1.MsgExecuteMessagesResponse, error,
) {
return cva.BaseLockup.SendCoins(ctx, msg, cva.GetLockedCoinsWithDenoms)
}
Expand Down
17 changes: 9 additions & 8 deletions x/accounts/self_delegatable_lockup/lockup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"cosmossdk.io/x/accounts/accountstd"
lockuptypes "cosmossdk.io/x/accounts/defaults/lockup/v1"
banktypes "cosmossdk.io/x/bank/types"

// distrtypes "cosmossdk.io/x/distribution/types"
stakingtypes "cosmossdk.io/x/staking/types"

Expand Down Expand Up @@ -82,8 +83,8 @@ type BaseLockup struct {
EndTime collections.Item[time.Time]
}

func (bva *BaseLockup) Init(ctx context.Context, msg *lockuptypes.MsgInitLockupAccount) (
*lockuptypes.MsgInitLockupAccountResponse, error,
func (bva *BaseLockup) Init(ctx context.Context, msg *v1.MsgInitSelfDelegatableLockupAccount) (
*v1.MsgInitSelfDelegatableLockupAccountResponse, error,
) {
owner, err := bva.addressCodec.StringToBytes(msg.Owner)
if err != nil {
Expand Down Expand Up @@ -126,7 +127,7 @@ func (bva *BaseLockup) Init(ctx context.Context, msg *lockuptypes.MsgInitLockupA
return nil, err
}

return &lockuptypes.MsgInitLockupAccountResponse{}, nil
return &v1.MsgInitSelfDelegatableLockupAccountResponse{}, nil
}

// func (bva *BaseLockup) Delegate(
Expand Down Expand Up @@ -284,9 +285,9 @@ func (bva *BaseLockup) Init(ctx context.Context, msg *lockuptypes.MsgInitLockupA
// }

func (bva *BaseLockup) SendCoins(
ctx context.Context, msg *lockuptypes.MsgSend, getLockedCoinsFunc getLockedCoinsFunc,
ctx context.Context, msg *v1.MsgSend, getLockedCoinsFunc getLockedCoinsFunc,
) (
*lockuptypes.MsgExecuteMessagesResponse, error,
*v1.MsgExecuteMessagesResponse, error,
) {
err := bva.checkSender(ctx, msg.Sender)
if err != nil {
Expand Down Expand Up @@ -324,7 +325,7 @@ func (bva *BaseLockup) SendCoins(
return nil, err
}

return &lockuptypes.MsgExecuteMessagesResponse{Responses: resp}, nil
return &v1.MsgExecuteMessagesResponse{Responses: resp}, nil
}

// <sunrise>
Expand Down Expand Up @@ -420,11 +421,11 @@ func (bva *BaseLockup) WithdrawSelfDelegationUnbonded(ctx context.Context, msg *
return nil, err
}

msgSelfDelegate := &tokenconvertertypes.MsgWithdrawSelfDelegationUnbonded{
msgWithdraw := &tokenconvertertypes.MsgWithdrawSelfDelegationUnbonded{
Sender: delegatorAddress,
Amount: msg.Amount,
}
_, err = sendMessage(ctx, msgSelfDelegate)
_, err = sendMessage(ctx, msgWithdraw)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit fc65121

Please sign in to comment.