Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(assets): load genesis state #25

Merged
merged 16 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/rs/cors v1.9.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,8 @@ golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
4 changes: 2 additions & 2 deletions precompiles/delegation/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@ func (s *DelegationPrecompileSuite) TestRunDelegateToThroughClientChain() {
returnBytes []byte
}{
{
name: "fail - delegateToThroughClientChain transaction will fail because the exocoreLzAppAddress haven't been stored",
name: "fail - delegateToThroughClientChain transaction will fail because the exocoreLzAppAddress is mismatched",
malleate: func() (common.Address, []byte) {
return commonMalleate()
},
readOnly: false,
expPass: false,
errContains: assetstype.ErrNoParamsKey.Error(),
errContains: assetstype.ErrNotEqualToLzAppAddr.Error(),
},
{
name: "fail - delegateToThroughClientChain transaction will fail because the contract caller isn't the exoCoreLzAppAddr",
Expand Down
4 changes: 2 additions & 2 deletions precompiles/deposit/deposit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (s *DepositPrecompileSuite) TestRunDepositTo() {
returnBytes []byte
}{
{
name: "fail - depositTo transaction will fail because the exocoreLzAppAddress haven't been stored",
name: "fail - depositTo transaction will fail because the exocoreLzAppAddress is mismatched",
malleate: func() (common.Address, []byte) {
return commonMalleate()
},
readOnly: false,
expPass: false,
errContains: assetstype.ErrNoParamsKey.Error(),
errContains: assetstype.ErrNotEqualToLzAppAddr.Error(),
},
{
name: "fail - depositTo transaction will fail because the contract caller isn't the exoCoreLzAppAddr",
Expand Down
51 changes: 44 additions & 7 deletions proto/exocore/assets/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,17 +1,54 @@
syntax = "proto3";
package exocore.assets.v1;

import "gogoproto/gogo.proto";

import "exocore/assets/v1/params.proto";
import "exocore/assets/v1/tx.proto";

option go_package = "github.com/ExocoreNetwork/exocore/x/assets/types";

// GenesisState defines the assets module's genesis state.
// GenesisState defines the assets module's state. It needs to encompass
// all of the state that is required to start the chain from the genesis
// or in the event of a restart. At this point, it is only built with
// the former in mind.
// TODO: make this state exportable for the case of chain restarts.
message GenesisState {
// default_supported_client_chains is the list of supported client chains,
// that are supported by default.
repeated ClientChainInfo default_supported_client_chains = 1;
// default_supported_client_chain_tokens is the list of supported client chain tokens,
// that are supported by default.
repeated AssetInfo default_supported_client_chain_tokens = 2;
// params defines all the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];

Check failure on line 18 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" with name "params" on message "GenesisState" changed option "json_name" from "defaultSupportedClientChains" to "params".

Check failure on line 18 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "GenesisState" changed label from "repeated" to "optional".

Check failure on line 18 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "GenesisState" changed type from "exocore.assets.v1.ClientChainInfo" to "exocore.assets.v1.Params".

Check failure on line 18 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "GenesisState" changed name from "default_supported_client_chains" to "params".
// client_chains is the list of supported client chains,
// that are supported at chain genesis (or restart).
repeated ClientChainInfo client_chains = 2 [(gogoproto.nullable) = false];

Check failure on line 21 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" with name "client_chains" on message "GenesisState" changed option "json_name" from "defaultSupportedClientChainTokens" to "clientChains".

Check failure on line 21 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" on message "GenesisState" changed type from "exocore.assets.v1.AssetInfo" to "exocore.assets.v1.ClientChainInfo".

Check failure on line 21 in proto/exocore/assets/v1/genesis.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "2" on message "GenesisState" changed name from "default_supported_client_chain_tokens" to "client_chains".
// tokens is the list of supported client chain tokens and total staked amount
// that are supported at chain genesis (or restart).
repeated StakingAssetInfo tokens = 3 [(gogoproto.nullable) = false];
// deposits is the list of deposits, indexed by staker address and
// then the asset id. The struct is the `StakerAssetInfo`
// which contains deposits, withdrawable and unbonding amount.
// at genesis (not chain restart), the unbonding amount must be 0.
repeated DepositsByStaker deposits = 4 [(gogoproto.nullable) = false];
}

// DepositByStaker is a helper struct to be used in the genesis state.
// It is used to store the staker address and its deposits for each asset ID.
message DepositsByStaker {
// staker is the address of the staker.
string staker = 1 [ (gogoproto.customname) = "StakerID" ];
// deposits is the list of deposits, indexed by the asset id.
// The struct is the `StakerAssetInfo` which contains deposits,
// withdrawable and unbonding amount.
repeated DepositByAsset deposits = 2 [(gogoproto.nullable) = false];
}

// DepositByAsset is a helper struct to be used in the genesis state.
// It is used to store the asset id and its info for an staker.
// The info contains the deposit amount, the withdrawable amount
// and the amount currently unbonding.
// It is named DepositByAsset (since it is indexed by the assetID)
// and not Deposit to prevent conflict with CrossChainOpType.
message DepositByAsset {
// asset_id is the id of the asset.
string asset_id = 1 [ (gogoproto.customname) = "AssetID" ];
// info is the asset info.
StakerAssetInfo info = 2 [(gogoproto.nullable) = false];
}
2 changes: 1 addition & 1 deletion proto/exocore/assets/v1/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ option go_package = "github.com/ExocoreNetwork/exocore/x/assets/types";

// GenesisState defines the deposit module's genesis state.
message Params {
// exocore_lz_app_address is the address of the exocore lz app.
// exocore_lz_app_address is the address of ExocoreGateway.sol.
string exocore_lz_app_address = 1
[(gogoproto.customname) = "ExocoreLzAppAddress"];
// exocore_lz_app_event_topic is the topic of the exocore lz app event.
Expand Down
14 changes: 7 additions & 7 deletions proto/exocore/assets/v1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto3";

Check failure on line 1 in proto/exocore/assets/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present message "OperatorAllAssetsInfo" was deleted from file.

Check failure on line 1 in proto/exocore/assets/v1/tx.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present message "OperatorAllAssetsInfo.AllAssetsStateEntry" was deleted from file.
package exocore.assets.v1;

import "amino/amino.proto";
Expand Down Expand Up @@ -50,7 +50,7 @@
// meta_info is at Exocore's discretion to deter,ome
string meta_info = 2;
// chain_id is used as the primary key
string chain_id = 3;
string chain_id = 3 [(gogoproto.customname) = "ChainID"];
// exocore_chain_index is the index of the chain in exocore, so far unused
uint64 exocore_chain_index = 4;
}
Expand Down Expand Up @@ -172,12 +172,12 @@
];
}

// OperatorAllAssetsInfo defines the information for all assets of an operator,
// indexed by the asset_id.
message OperatorAllAssetsInfo {
// all_assets_state is the state of all assets of the operator.
map<string, OperatorAssetInfo> all_assets_state = 1;
}
// // OperatorAllAssetsInfo defines the information for all assets of an operator,
// // indexed by the asset_id.
// message OperatorAllAssetsInfo {
// // all_assets_state is the state of all assets of the operator.
// map<string, OperatorAssetInfo> all_assets_state = 1;
// }

// MsgSetExoCoreAddr defines the MsgSetExoCoreAddr message used to set the
// exocore address of the staker.
Expand Down
35 changes: 35 additions & 0 deletions testutil/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"time"

"cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
Expand All @@ -16,6 +17,7 @@ import (

exocoreapp "github.com/ExocoreNetwork/exocore/app"
"github.com/ExocoreNetwork/exocore/utils"
assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types"
abci "github.com/cometbft/cometbft/abci/types"
"github.com/cometbft/cometbft/crypto/tmhash"
tmtypes "github.com/cometbft/cometbft/types"
Expand Down Expand Up @@ -82,6 +84,39 @@ func (suite *BaseTestSuite) SetupWithGenesisValSet(valSet *tmtypes.ValidatorSet,
authGenesis := authtypes.NewGenesisState(authtypes.DefaultParams(), genAccs)
genesisState[authtypes.ModuleName] = app.AppCodec().MustMarshalJSON(authGenesis)

// set genesis staking assets
ethClientChain := assetstypes.ClientChainInfo{
Name: "ethereum",
MetaInfo: "ethereum blockchain",
ChainId: 1,
FinalizationBlocks: 10,
LayerZeroChainID: 101,
AddressLength: 20,
}
usdtClientChainAsset := assetstypes.AssetInfo{
Name: "Tether USD",
Symbol: "USDT",
Address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
Decimals: 6,
LayerZeroChainID: ethClientChain.LayerZeroChainID,
MetaInfo: "Tether USD token",
}
{
totalSupply, _ := sdk.NewIntFromString("40022689732746729")
usdtClientChainAsset.TotalSupply = totalSupply
}
stakingInfo := assetstypes.StakingAssetInfo{
AssetBasicInfo: &usdtClientChainAsset,
StakingTotalAmount: math.NewInt(0),
}
assetsGenesis := assetstypes.NewGenesis(
assetstypes.DefaultParams(),
[]assetstypes.ClientChainInfo{ethClientChain},
[]assetstypes.StakingAssetInfo{stakingInfo},
[]assetstypes.DepositsByStaker{},
)
genesisState[assetstypes.ModuleName] = app.AppCodec().MustMarshalJSON(assetsGenesis)

validators := make([]stakingtypes.Validator, 0, len(valSet.Validators))
delegations := make([]stakingtypes.Delegation, 0, len(valSet.Validators))

Expand Down
112 changes: 0 additions & 112 deletions x/assets/genesis.go

This file was deleted.

Loading
Loading