Skip to content

Commit

Permalink
Merge pull request #43 from iqlusioninc/new_adr_impl
Browse files Browse the repository at this point in the history
New adr implementation
  • Loading branch information
zmanian authored Aug 21, 2022
2 parents 7b9b8ce + e9e413e commit 84c0f3c
Show file tree
Hide file tree
Showing 55 changed files with 2,137 additions and 2,024 deletions.
2 changes: 1 addition & 1 deletion app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
"github.com/cosmos/cosmos-sdk/x/evidence"
feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
group "github.com/cosmos/cosmos-sdk/x/group/module"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/upgrade"
"github.com/iqlusioninc/liquidity-staking-module/x/genutil"
)

func TestSimAppExportAndBlockedAddrs(t *testing.T) {
Expand Down
23 changes: 11 additions & 12 deletions app/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,19 @@ func genesisStateWithValSet(t *testing.T,
pkAny, err := codectypes.NewAnyWithValue(pk)
require.NoError(t, err)
validator := stakingtypes.Validator{
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stdstaking.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
MinSelfDelegation: sdk.ZeroInt(),
OperatorAddress: sdk.ValAddress(val.Address).String(),
ConsensusPubkey: pkAny,
Jailed: false,
Status: stdstaking.Bonded,
Tokens: bondAmt,
DelegatorShares: sdk.OneDec(),
Description: stakingtypes.Description{},
UnbondingHeight: int64(0),
UnbondingTime: time.Unix(0, 0).UTC(),
Commission: stakingtypes.NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec(), false))

}
// set validators and delegations
Expand Down
2 changes: 1 addition & 1 deletion cmd/liquidstakingd/cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"github.com/stretchr/testify/require"

svrcmd "github.com/cosmos/cosmos-sdk/server/cmd"
"github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
simapp "github.com/iqlusioninc/liquidity-staking-module/app"
"github.com/iqlusioninc/liquidity-staking-module/cmd/liquidstakingd/cmd"
"github.com/iqlusioninc/liquidity-staking-module/x/genutil/client/cli"
)

func TestInitCmd(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/liquidstakingd/cmd/genaccounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authvesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/iqlusioninc/liquidity-staking-module/x/genutil"
genutiltypes "github.com/iqlusioninc/liquidity-staking-module/x/genutil/types"
)

const (
Expand Down
4 changes: 2 additions & 2 deletions cmd/liquidstakingd/cmd/genaccounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltest "github.com/cosmos/cosmos-sdk/x/genutil/client/testutil"
simapp "github.com/iqlusioninc/liquidity-staking-module/app"
simcmd "github.com/iqlusioninc/liquidity-staking-module/cmd/liquidstakingd/cmd"
"github.com/iqlusioninc/liquidity-staking-module/x/genutil"
genutiltest "github.com/iqlusioninc/liquidity-staking-module/x/genutil/client/testutil"
)

var testMbm = module.NewBasicManager(genutil.AppModuleBasic{})
Expand Down
9 changes: 4 additions & 5 deletions cmd/liquidstakingd/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ import (
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
"github.com/iqlusioninc/liquidity-staking-module/testutil/network"
"github.com/iqlusioninc/liquidity-staking-module/x/genutil"
genutiltypes "github.com/iqlusioninc/liquidity-staking-module/x/genutil/types"
stakingtypes "github.com/iqlusioninc/liquidity-staking-module/x/staking/types"
)

Expand Down Expand Up @@ -114,7 +114,7 @@ or a similar setup where each node has a manually configurable IP address.
Note, strict routability for addresses is turned off in the config file.
Example:
simd testnet init-files --v 4 --output-dir ./.testnets --starting-ip-address 192.168.10.2
liquidstakingd testnet init-files --keyring-backend=test --chain-id="liquidstaking-2" --v 4 --output-dir ./testnet --starting-ip-address 192.168.10.2
`,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
Expand Down Expand Up @@ -160,7 +160,7 @@ and generate "v" directories, populated with necessary validator configuration f
(private validator, genesis, config, etc.).
Example:
simd testnet --v 4 --output-dir ./.testnets
liquidstakingd testnet start --v 4 --output-dir ./.testnets
`,
RunE: func(cmd *cobra.Command, _ []string) error {

Expand Down Expand Up @@ -298,7 +298,6 @@ func initTestnetFiles(
sdk.NewCoin(sdk.DefaultBondDenom, valTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(sdk.OneDec(), sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
)
if err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,6 @@
"website": ""
},
"jailed": false,
"min_self_delegation": "1",
"operator_address": "cosmosvaloper1qp49fdjtlsrv6jkx3gc8urp2ncg88s6mcversm",
"status": "BOND_STATUS_BONDED",
"tokens": "11000000",
Expand Down Expand Up @@ -904,7 +903,6 @@
"website": ""
},
"jailed": false,
"min_self_delegation": "1",
"operator_address": "cosmosvaloper1yh60qk8lp0fz05zna43zjdmwj8y32wrhsq8rzj",
"status": "BOND_STATUS_BONDED",
"tokens": "100000000",
Expand Down Expand Up @@ -933,7 +931,6 @@
"website": ""
},
"jailed": false,
"min_self_delegation": "1",
"operator_address": "cosmosvaloper186luay4vll7yv8w6z6amhxjczf4k5yzr67tmgg",
"status": "BOND_STATUS_BONDED",
"tokens": "100000000",
Expand Down Expand Up @@ -962,7 +959,6 @@
"website": ""
},
"jailed": false,
"min_self_delegation": "1",
"operator_address": "cosmosvaloper1sjq7jgd4r3al0875ysvpk3yw6c7250a75uk2rs",
"status": "BOND_STATUS_BONDED",
"tokens": "100000000",
Expand Down Expand Up @@ -991,7 +987,6 @@
"website": ""
},
"jailed": false,
"min_self_delegation": "1",
"operator_address": "cosmosvaloper1jefsuvgwwt4pc0cntdwlzcjewckvdjrllh4668",
"status": "BOND_STATUS_BONDED",
"tokens": "100000000",
Expand Down
15 changes: 5 additions & 10 deletions proto/distribution/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ service Query {
// ValidatorOutstandingRewards queries rewards of a validator address.
rpc ValidatorOutstandingRewards(QueryValidatorOutstandingRewardsRequest)
returns (QueryValidatorOutstandingRewardsResponse) {
option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/"
"{validator_address}/outstanding_rewards";
option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}/outstanding_rewards";
}

// ValidatorCommission queries accumulated commission for a validator.
rpc ValidatorCommission(QueryValidatorCommissionRequest) returns (QueryValidatorCommissionResponse) {
option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/"
"{validator_address}/commission";
option (google.api.http).get = "/cosmos/distribution/v1beta1/validators/{validator_address}/commission";
}

// ValidatorSlashes queries slash events of a validator.
Expand All @@ -36,8 +34,7 @@ service Query {

// DelegationRewards queries the total rewards accrued by a delegation.
rpc DelegationRewards(QueryDelegationRewardsRequest) returns (QueryDelegationRewardsResponse) {
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/rewards/"
"{validator_address}";
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/rewards/{validator_address}";
}

// DelegationTotalRewards queries the total rewards accrued by a each
Expand All @@ -48,14 +45,12 @@ service Query {

// DelegatorValidators queries the validators of a delegator.
rpc DelegatorValidators(QueryDelegatorValidatorsRequest) returns (QueryDelegatorValidatorsResponse) {
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/"
"{delegator_address}/validators";
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/validators";
}

// DelegatorWithdrawAddress queries withdraw address of a delegator.
rpc DelegatorWithdrawAddress(QueryDelegatorWithdrawAddressRequest) returns (QueryDelegatorWithdrawAddressResponse) {
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/"
"{delegator_address}/withdraw_address";
option (google.api.http).get = "/cosmos/distribution/v1beta1/delegators/{delegator_address}/withdraw_address";
}

// CommunityPool queries the community pool coins.
Expand Down
21 changes: 17 additions & 4 deletions proto/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,15 @@ message Validator {
[(gogoproto.nullable) = false, (gogoproto.stdtime) = true, (gogoproto.moretags) = "yaml:\"unbonding_time\""];
// commission defines the commission parameters.
Commission commission = 10 [(gogoproto.nullable) = false];
// min_self_delegation is the validator's self declared minimum self delegation.
string min_self_delegation = 11 [
(gogoproto.moretags) = "yaml:\"min_self_delegation\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
// Number of shares marked_exempt_to_this_validator
string total_exempt_shares = 11[
(gogoproto.moretags) = "yaml:\"total_exempt_shares\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string total_tokenized_shares = 12[
(gogoproto.moretags) = "yaml:\"total_tokenized_shares\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
Expand Down Expand Up @@ -191,6 +196,8 @@ message Delegation {
string validator_address = 2 [(gogoproto.moretags) = "yaml:\"validator_address\""];
// shares define the delegation shares received.
string shares = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
// has this delegation been marked as exempt.
bool exempt = 4;
}

// UnbondingDelegation stores all of a single delegator's unbonding bonds
Expand Down Expand Up @@ -287,6 +294,12 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// exemption_factor is required for tokenize share and undelegation check for network safety
string exemption_factor = 7 [
(gogoproto.moretags) = "yaml:\"exemption_factor\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// DelegationResponse is equivalent to Delegation except that it contains a
Expand Down
34 changes: 20 additions & 14 deletions proto/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ service Msg {
// TokenizeShareRecord
rpc TransferTokenizeShareRecord(MsgTransferTokenizeShareRecord)
returns (MsgTransferTokenizeShareRecordResponse);

// ExemptDelegation defines a method for performing exemption of
// delegated coins from a delegator to a validator.
rpc ExemptDelegation(MsgExemptDelegation) returns (MsgExemptDelegationResponse);
}

// MsgCreateValidator defines a SDK message for creating a new validator.
Expand All @@ -58,15 +62,10 @@ message MsgCreateValidator {

Description description = 1 [(gogoproto.nullable) = false];
CommissionRates commission = 2 [(gogoproto.nullable) = false];
string min_self_delegation = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_self_delegation\"",
(gogoproto.nullable) = false
];
string delegator_address = 4 [(gogoproto.moretags) = "yaml:\"delegator_address\""];
string validator_address = 5 [(gogoproto.moretags) = "yaml:\"validator_address\""];
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false];
string delegator_address = 3 [(gogoproto.moretags) = "yaml:\"delegator_address\""];
string validator_address = 4 [(gogoproto.moretags) = "yaml:\"validator_address\""];
google.protobuf.Any pubkey = 5 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 6 [(gogoproto.nullable) = false];
}

// MsgCreateValidatorResponse defines the Msg/CreateValidator response type.
Expand All @@ -88,10 +87,6 @@ message MsgEditValidator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"commission_rate\""
];
string min_self_delegation = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.moretags) = "yaml:\"min_self_delegation\""
];
}

// MsgEditValidatorResponse defines the Msg/EditValidator response type.
Expand Down Expand Up @@ -203,4 +198,15 @@ message MsgTransferTokenizeShareRecord {
string new_owner = 3;
}

message MsgTransferTokenizeShareRecordResponse {}
message MsgTransferTokenizeShareRecordResponse {}

// MsgExemptDelegation defines a SDK message for performing exemption of delegated coins
// from a delegator to a validator.
message MsgExemptDelegation {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

string delegator_address = 1 [(gogoproto.moretags) = "yaml:\"delegator_address\""];
string validator_address = 2 [(gogoproto.moretags) = "yaml:\"validator_address\""];
}
message MsgExemptDelegationResponse {}
2 changes: 2 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ liquidstakingd add-genesis-account $(liquidstakingd keys show validator -a --key
liquidstakingd gentx validator 100000000stake --keyring-backend="test" --chain-id test
liquidstakingd collect-gentxs

sed -i '' 's/"exemption_factor": "-1.000000000000000000"/"exemption_factor": "10.000000000000000000"/g' ~/.simapp/config/genesis.json

liquidstakingd start
# liquidstakingd start --home=home --mode=validator
1 change: 0 additions & 1 deletion testutil/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ func New(l Logger, baseDir string, cfg Config) (*Network, error) {
sdk.NewCoin(cfg.BondDenom, cfg.BondedTokens),
stakingtypes.NewDescription(nodeDirName, "", "", "", ""),
stakingtypes.NewCommissionRates(commission, sdk.OneDec(), sdk.OneDec()),
sdk.OneInt(),
)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion x/distribution/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() {
delTokens := suite.app.StakingKeeper.TokensFromConsensusPower(suite.ctx, 2)
validator0, issuedShares := validator0.AddTokensFromDel(delTokens)
delegator := accounts[1]
delegation := stakingtypes.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares)
delegation := stakingtypes.NewDelegation(delegator.Address, validator0.GetOperator(), issuedShares, false)
suite.app.StakingKeeper.SetDelegation(suite.ctx, delegation)
suite.app.DistrKeeper.SetDelegatorStartingInfo(suite.ctx, validator0.GetOperator(), delegator.Address, distrtypes.NewDelegatorStartingInfo(2, sdk.OneDec(), 200))

Expand Down
Loading

0 comments on commit 84c0f3c

Please sign in to comment.