Skip to content

Commit

Permalink
feat: add x/stakeibc, x/records
Browse files Browse the repository at this point in the history
  • Loading branch information
hallazzang committed May 10, 2024
1 parent efaacf8 commit 057b1c6
Show file tree
Hide file tree
Showing 210 changed files with 58,703 additions and 24 deletions.
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.2.1
github.com/cosmos/ics23/go v0.10.0
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1 // indirect
github.com/cosmos/interchain-security/v5 v5.0.0-alpha1
github.com/golang/mock v1.6.0
github.com/golang/protobuf v1.5.4
github.com/gorilla/mux v1.8.1
Expand Down Expand Up @@ -60,6 +60,8 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require github.com/Stride-Labs/ibc-rate-limiting v0.0.0-00010101000000-000000000000

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
Expand Down Expand Up @@ -269,3 +271,5 @@ replace (
github.com/cosmos/ibc-go/v8 => github.com/initia-labs/ibc-go/v8 v8.0.0-20240419124350-4275a05abe2c
github.com/skip-mev/slinky => github.com/initia-labs/slinky v0.0.0-20240418051646-d45167cc66b1
)

replace github.com/Stride-Labs/ibc-rate-limiting => github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5 h1:1QBEsR4IX53rUHE3EB4VzWiGfEyB+owTivjJU4+zYAM=
github.com/milkyway-labs/ibc-rate-limiting v0.0.0-20240509215339-45e398477ad5/go.mod h1:YAf80eEQ4bdg5qXP4EI8eCxzhhWfqwiy9DoP8JXXg60=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
Expand Down
2 changes: 1 addition & 1 deletion proto/stride/epochs/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ message QueryEpochInfoResponse {
// import "epochs/params.proto";
// // this line is used by starport scaffolding # 1

// option go_package = "github.com/Stride-Labs/stride/v22/x/epochs/types";
// option go_package = "github.com/milkyway-labs/milk/x/epochs/types";

// // Query defines the gRPC querier service.
// service Query {
Expand Down
10 changes: 10 additions & 0 deletions proto/stride/records/callbacks.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";
package stride.records;

import "stride/records/records.proto";

option go_package = "github.com/milkyway-labs/milk/x/records/types";

message TransferCallback { uint64 deposit_record_id = 1; }

message TransferLSMTokenCallback { LSMTokenDeposit deposit = 1; }
24 changes: 24 additions & 0 deletions proto/stride/records/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
syntax = "proto3";
package stride.records;

import "stride/records/params.proto";
import "stride/records/records.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/milkyway-labs/milk/x/records/types";

// GenesisState defines the records module's genesis state.
message GenesisState {
Params params = 1 [ (gogoproto.nullable) = false ];
string port_id = 2;
repeated UserRedemptionRecord user_redemption_record_list = 3
[ (gogoproto.nullable) = false ];
uint64 user_redemption_record_count = 4;
repeated EpochUnbondingRecord epoch_unbonding_record_list = 5
[ (gogoproto.nullable) = false ];
repeated DepositRecord deposit_record_list = 7
[ (gogoproto.nullable) = false ];
uint64 deposit_record_count = 8;
repeated LSMTokenDeposit lsm_token_deposit_list = 9
[ (gogoproto.nullable) = false ];
}
7 changes: 7 additions & 0 deletions proto/stride/records/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
syntax = "proto3";
package stride.records;

option go_package = "github.com/milkyway-labs/milk/x/records/types";

// Params defines the parameters for the module.
message Params {}
185 changes: 185 additions & 0 deletions proto/stride/records/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
syntax = "proto3";
package stride.records;

import "stride/records/records.proto";
import "stride/records/params.proto";

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";

option go_package = "github.com/milkyway-labs/milk/x/records/types";

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/StrideLabs/stride/records/params";
}
// Queries a UserRedemptionRecord by id.
rpc UserRedemptionRecord(QueryGetUserRedemptionRecordRequest)
returns (QueryGetUserRedemptionRecordResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/user_redemption_record/{id}";
}

// Queries a list of UserRedemptionRecord items.
rpc UserRedemptionRecordAll(QueryAllUserRedemptionRecordRequest)
returns (QueryAllUserRedemptionRecordResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/user_redemption_record";
}

// Queries a list of UserRedemptionRecord items by chainId / userId pair.
rpc UserRedemptionRecordForUser(QueryAllUserRedemptionRecordForUserRequest)
returns (QueryAllUserRedemptionRecordForUserResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/user_redemption_record_for_user/"
"{chain_id}/{day}/{address}/{limit}";
}

// Queries a EpochUnbondingRecord by id.
rpc EpochUnbondingRecord(QueryGetEpochUnbondingRecordRequest)
returns (QueryGetEpochUnbondingRecordResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/epoch_unbonding_record/{epoch_number}";
}

// Queries a list of EpochUnbondingRecord items.
rpc EpochUnbondingRecordAll(QueryAllEpochUnbondingRecordRequest)
returns (QueryAllEpochUnbondingRecordResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/epoch_unbonding_record";
}

// Queries a DepositRecord by id.
rpc DepositRecord(QueryGetDepositRecordRequest)
returns (QueryGetDepositRecordResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/records/deposit_record/{id}";
}

// Queries a list of DepositRecord items.
rpc DepositRecordAll(QueryAllDepositRecordRequest)
returns (QueryAllDepositRecordResponse) {
option (google.api.http).get = "/Stride-Labs/stride/records/deposit_record";
}

// Queries a list of DepositRecord items for a given host zone
rpc DepositRecordByHost(QueryDepositRecordByHostRequest)
returns (QueryDepositRecordByHostResponse) {
option (google.api.http).get = "/Stride-Labs/stride/records/"
"deposit_record_by_host_zone/{host_zone_id}";
}

// Queries the existing LSMTokenDeposits for one specific deposit
rpc LSMDeposit(QueryLSMDepositRequest) returns (QueryLSMDepositResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/stakeibc/lsm_deposit/{chain_id}/{denom}";
}

// Queries the existing LSMTokenDeposits for all which match filters
// intended use:
// ...stakeibc/lsm_deposits?chain_id=X&validator_address=Y&status=Z
rpc LSMDeposits(QueryLSMDepositsRequest) returns (QueryLSMDepositsResponse) {
option (google.api.http).get = "/Stride-Labs/stride/stakeibc/lsm_deposits";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryGetDepositRecordRequest { uint64 id = 1; }

message QueryGetDepositRecordResponse {
DepositRecord deposit_record = 1 [ (gogoproto.nullable) = false ];
}

message QueryAllDepositRecordRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllDepositRecordResponse {
repeated DepositRecord deposit_record = 1 [ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryDepositRecordByHostRequest { string host_zone_id = 1; }

message QueryDepositRecordByHostResponse {
repeated DepositRecord deposit_record = 1 [ (gogoproto.nullable) = false ];
}

message QueryGetUserRedemptionRecordRequest { string id = 1; }

message QueryGetUserRedemptionRecordResponse {
UserRedemptionRecord user_redemption_record = 1
[ (gogoproto.nullable) = false ];
}

message QueryAllUserRedemptionRecordRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllUserRedemptionRecordResponse {
repeated UserRedemptionRecord user_redemption_record = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// Query UserRedemptionRecords by chainId / userId pair
message QueryAllUserRedemptionRecordForUserRequest {
string chain_id = 1;
uint64 day = 2;
string address = 3;
uint64 limit = 4;
cosmos.base.query.v1beta1.PageRequest pagination = 5;
}

message QueryAllUserRedemptionRecordForUserResponse {
repeated UserRedemptionRecord user_redemption_record = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryGetEpochUnbondingRecordRequest { uint64 epoch_number = 1; }

message QueryGetEpochUnbondingRecordResponse {
EpochUnbondingRecord epoch_unbonding_record = 1
[ (gogoproto.nullable) = false ];
}

message QueryAllEpochUnbondingRecordRequest {
cosmos.base.query.v1beta1.PageRequest pagination = 1;
}

message QueryAllEpochUnbondingRecordResponse {
repeated EpochUnbondingRecord epoch_unbonding_record = 1
[ (gogoproto.nullable) = false ];
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

message QueryLSMDepositRequest {
string chain_id = 1;
string denom = 2;
}

message QueryLSMDepositResponse {
LSMTokenDeposit deposit = 1 [ (gogoproto.nullable) = false ];
}

message QueryLSMDepositsRequest {
string chain_id = 1;
string validator_address = 2;
string status = 3;
}

message QueryLSMDepositsResponse {
repeated LSMTokenDeposit deposits = 1 [ (gogoproto.nullable) = false ];
}
111 changes: 111 additions & 0 deletions proto/stride/records/records.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
syntax = "proto3";
package stride.records;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/milkyway-labs/milk/x/records/types";

message UserRedemptionRecord {
string id = 1; // {chain_id}.{epoch}.{receiver}
string receiver = 3;
string native_token_amount = 4 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string denom = 5;
string host_zone_id = 6;
uint64 epoch_number = 7;
bool claim_is_pending = 8;
reserved 2;
string st_token_amount = 9 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
}

message DepositRecord {
uint64 id = 1;
string amount = 2 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string denom = 3;
string host_zone_id = 4;
enum Status {
// in transfer queue to be sent to the delegation ICA
TRANSFER_QUEUE = 0;
// transfer in progress (IBC packet sent, ack not received)
TRANSFER_IN_PROGRESS = 2;
// in staking queue on delegation ICA
DELEGATION_QUEUE = 1;
// staking in progress (ICA packet sent, ack not received)
DELEGATION_IN_PROGRESS = 3;
}
enum Source {
STRIDE = 0;
WITHDRAWAL_ICA = 1;
}
Status status = 6;
uint64 deposit_epoch_number = 7;
Source source = 8;

reserved 5;
}

message HostZoneUnbonding {
enum Status {
// tokens bonded on delegate account
UNBONDING_QUEUE = 0;
UNBONDING_IN_PROGRESS = 3;
// unbonding completed on delegate account
EXIT_TRANSFER_QUEUE = 1;
EXIT_TRANSFER_IN_PROGRESS = 4;
// transfer success
CLAIMABLE = 2;
}
string st_token_amount = 1 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string native_token_amount = 2 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
string denom = 3;
string host_zone_id = 4;
uint64 unbonding_time = 5;
Status status = 6;
repeated string user_redemption_records = 7;
}

message EpochUnbondingRecord {
uint64 epoch_number = 1;
repeated HostZoneUnbonding host_zone_unbondings = 3;
reserved 2;
}

message LSMTokenDeposit {
enum Status {
DEPOSIT_PENDING = 0;
TRANSFER_QUEUE = 1;
TRANSFER_IN_PROGRESS = 2;
TRANSFER_FAILED = 3;
DETOKENIZATION_QUEUE = 4;
DETOKENIZATION_IN_PROGRESS = 5;
DETOKENIZATION_FAILED = 6;
}

string deposit_id = 1;
string chain_id = 2;
string denom = 3;
string ibc_denom = 4;
string staker_address = 5;
string validator_address = 6;
string amount = 7 [
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.Coin st_token = 8 [ (gogoproto.nullable) = false ];
Status status = 9;
}
5 changes: 5 additions & 0 deletions proto/stride/stakeibc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Some of the data structures used in this module were inspired by Quicksilver.

Specifically, we used their modeling of interchain accounts and zones (although the implementation has since diverged) for the following data structures
- Icaaccount
- HostZone
Loading

0 comments on commit 057b1c6

Please sign in to comment.