diff --git a/app/genesis_test.go b/app/genesis_test.go index f35ea7aa3..912e0ffa9 100644 --- a/app/genesis_test.go +++ b/app/genesis_test.go @@ -12,7 +12,7 @@ import ( func TestNewDefaultGenesisByDenom(t *testing.T) { // bank -> denom_metadata -> "uri":"", "uri_hash":"" - const genesisData = `{"arbitrum":{"params":{"gravity_id":"fx-arbitrum-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"500","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"auth":{"params":{"max_memo_characters":"256","tx_sig_limit":"7","tx_size_cost_per_byte":"10","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000"},"accounts":[]},"authz":{"authorization":[]},"avalanche":{"params":{"gravity_id":"fx-avalanche-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"2000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"bank":{"params":{"send_enabled":[],"default_send_enabled":true},"balances":[{"address":"cosmos1c602zv38ht8xu8u2qcmymyl55mcyvvjrzq9ur3","coins":[{"denom":"FX","amount":"378600525462891000000000000"}]}],"supply":[{"denom":"FX","amount":"378604525462891000000000000"}],"denom_metadata":[{"description":"The native staking token of the Function X","denom_units":[{"denom":"FX","exponent":0,"aliases":[]}],"base":"FX","display":"FX","name":"Function X","symbol":"FX","uri":"","uri_hash":""}]},"bsc":{"params":{"gravity_id":"fx-bsc-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"3000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"capability":{"index":"1","owners":[]},"crisis":{"constant_fee":{"denom":"FX","amount":"13333000000000000000000"}},"distribution":{"params":{"community_tax":"0.400000000000000000","base_proposer_reward":"0.010000000000000000","bonus_proposer_reward":"0.040000000000000000","withdraw_addr_enabled":true},"fee_pool":{"community_pool":[]},"delegator_withdraw_infos":[],"previous_proposer":"","outstanding_rewards":[],"validator_accumulated_commissions":[],"validator_historical_rewards":[],"validator_current_rewards":[],"delegator_starting_infos":[],"validator_slash_events":[]},"erc20":{"params":{"enable_erc20":true,"enable_evm_hook":true,"ibc_timeout":"43200s"},"token_pairs":[]},"eth":{"params":{"gravity_id":"fx-bridge-eth","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"15000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"evidence":{"evidence":[]},"evm":{"accounts":[],"params":{"evm_denom":"FX","enable_create":true,"enable_call":true,"extra_eips":[],"chain_config":{"homestead_block":"0","dao_fork_block":"0","dao_fork_support":true,"eip150_block":"0","eip150_hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155_block":"0","eip158_block":"0","byzantium_block":"0","constantinople_block":"0","petersburg_block":"0","istanbul_block":"0","muir_glacier_block":"0","berlin_block":"0","london_block":"0","arrow_glacier_block":"0","gray_glacier_block":"0","merge_netsplit_block":"0","shanghai_block":"0","cancun_block":"0"},"allow_unprotected_txs":false}},"feegrant":{"allowances":[]},"feemarket":{"params":{"no_base_fee":false,"base_fee_change_denominator":8,"elasticity_multiplier":2,"enable_height":"0","base_fee":"500000000000","min_gas_price":"500000000000.000000000000000000","min_gas_multiplier":"0.000000000000000000"},"block_gas":"0"},"fxtransfer":{},"genutil":{"gen_txs":[]},"gov":{"starting_proposal_id":"1","deposits":[],"votes":[],"proposals":[],"deposit_params":{"min_deposit":[{"denom":"FX","amount":"10000000000000000000000"}],"max_deposit_period":"1209600s"},"voting_params":{"voting_period":"1209600s"},"tally_params":{"quorum":"0.400000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"}},"ibc":{"client_genesis":{"clients":[],"clients_consensus":[],"clients_metadata":[],"params":{"allowed_clients":["07-tendermint"]},"create_localhost":false,"next_client_sequence":"0"},"connection_genesis":{"connections":[],"client_connection_paths":[],"next_connection_sequence":"0","params":{"max_expected_time_per_block":"30000000000"}},"channel_genesis":{"channels":[],"acknowledgements":[],"commitments":[],"receipts":[],"send_sequences":[],"recv_sequences":[],"ack_sequences":[],"next_channel_sequence":"0"}},"layer2":{"params":{"gravity_id":"fx-layer2-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"2000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"migrate":{},"mint":{"minter":{"inflation":"0.350000000000000000","annual_provisions":"0.000000000000000000"},"params":{"mint_denom":"FX","inflation_rate_change":"0.300000000000000000","inflation_max":"0.416762000000000000","inflation_min":"0.170000000000000000","goal_bonded":"0.510000000000000000","blocks_per_year":"6311520"}},"optimism":{"params":{"gravity_id":"fx-optimism-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"500","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"params":{},"polygon":{"params":{"gravity_id":"fx-polygon-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"2000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"slashing":{"params":{"signed_blocks_window":"20000","min_signed_per_window":"0.050000000000000000","downtime_jail_duration":"600s","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.001000000000000000"},"signing_infos":[],"missed_blocks":[]},"staking":{"params":{"unbonding_time":"1814400s","max_validators":20,"max_entries":7,"historical_entries":20000,"bond_denom":"FX","min_commission_rate":"0.000000000000000000"},"last_total_power":"0","last_validator_powers":[],"validators":[],"delegations":[],"unbonding_delegations":[],"redelegations":[],"exported":false,"allowances":[]},"transfer":{"port_id":"transfer","denom_traces":[],"params":{"send_enabled":true,"receive_enabled":true}},"tron":{"params":{"gravity_id":"fx-tron-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"3000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"upgrade":{},"vesting":{}}` + const genesisData = `{"arbitrum":{"params":{"gravity_id":"fx-arbitrum-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"500","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"auth":{"params":{"max_memo_characters":"256","tx_sig_limit":"7","tx_size_cost_per_byte":"10","sig_verify_cost_ed25519":"590","sig_verify_cost_secp256k1":"1000"},"accounts":[]},"authz":{"authorization":[]},"avalanche":{"params":{"gravity_id":"fx-avalanche-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"2000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"bank":{"params":{"send_enabled":[],"default_send_enabled":true},"balances":[{"address":"cosmos1c602zv38ht8xu8u2qcmymyl55mcyvvjrzq9ur3","coins":[{"denom":"FX","amount":"378600525462891000000000000"}]}],"supply":[{"denom":"FX","amount":"378604525462891000000000000"}],"denom_metadata":[{"description":"The native staking token of the Function X","denom_units":[{"denom":"FX","exponent":0,"aliases":[]}],"base":"FX","display":"FX","name":"Function X","symbol":"FX","uri":"","uri_hash":""}]},"bsc":{"params":{"gravity_id":"fx-bsc-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"3000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"capability":{"index":"1","owners":[]},"crisis":{"constant_fee":{"denom":"FX","amount":"13333000000000000000000"}},"distribution":{"params":{"community_tax":"0.400000000000000000","base_proposer_reward":"0.010000000000000000","bonus_proposer_reward":"0.040000000000000000","withdraw_addr_enabled":true},"fee_pool":{"community_pool":[]},"delegator_withdraw_infos":[],"previous_proposer":"","outstanding_rewards":[],"validator_accumulated_commissions":[],"validator_historical_rewards":[],"validator_current_rewards":[],"delegator_starting_infos":[],"validator_slash_events":[]},"erc20":{"params":{"enable_erc20":true,"enable_evm_hook":true,"ibc_timeout":"43200s"},"token_pairs":[]},"eth":{"params":{"gravity_id":"fx-bridge-eth","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"15000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"evidence":{"evidence":[]},"evm":{"accounts":[],"params":{"evm_denom":"FX","enable_create":true,"enable_call":true,"extra_eips":[],"chain_config":{"homestead_block":"0","dao_fork_block":"0","dao_fork_support":true,"eip150_block":"0","eip150_hash":"0x0000000000000000000000000000000000000000000000000000000000000000","eip155_block":"0","eip158_block":"0","byzantium_block":"0","constantinople_block":"0","petersburg_block":"0","istanbul_block":"0","muir_glacier_block":"0","berlin_block":"0","london_block":"0","arrow_glacier_block":"0","gray_glacier_block":"0","merge_netsplit_block":"0","shanghai_block":"0","cancun_block":"0"},"allow_unprotected_txs":false}},"feegrant":{"allowances":[]},"feemarket":{"params":{"no_base_fee":false,"base_fee_change_denominator":8,"elasticity_multiplier":2,"enable_height":"0","base_fee":"500000000000","min_gas_price":"500000000000.000000000000000000","min_gas_multiplier":"0.000000000000000000"},"block_gas":"0"},"fxtransfer":{},"genutil":{"gen_txs":[]},"gov":{"starting_proposal_id":"1","deposits":[],"votes":[],"proposals":[],"deposit_params":{"min_deposit":[{"denom":"FX","amount":"10000000000000000000000"}],"max_deposit_period":"1209600s"},"voting_params":{"voting_period":"1209600s"},"tally_params":{"quorum":"0.400000000000000000","threshold":"0.500000000000000000","veto_threshold":"0.334000000000000000"}},"ibc":{"client_genesis":{"clients":[],"clients_consensus":[],"clients_metadata":[],"params":{"allowed_clients":["07-tendermint"]},"create_localhost":false,"next_client_sequence":"0"},"connection_genesis":{"connections":[],"client_connection_paths":[],"next_connection_sequence":"0","params":{"max_expected_time_per_block":"30000000000"}},"channel_genesis":{"channels":[],"acknowledgements":[],"commitments":[],"receipts":[],"send_sequences":[],"recv_sequences":[],"ack_sequences":[],"next_channel_sequence":"0"}},"migrate":{},"mint":{"minter":{"inflation":"0.350000000000000000","annual_provisions":"0.000000000000000000"},"params":{"mint_denom":"FX","inflation_rate_change":"0.300000000000000000","inflation_max":"0.416762000000000000","inflation_min":"0.170000000000000000","goal_bonded":"0.510000000000000000","blocks_per_year":"6311520"}},"optimism":{"params":{"gravity_id":"fx-optimism-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"500","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"params":{},"polygon":{"params":{"gravity_id":"fx-polygon-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"2000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"slashing":{"params":{"signed_blocks_window":"20000","min_signed_per_window":"0.050000000000000000","downtime_jail_duration":"600s","slash_fraction_double_sign":"0.050000000000000000","slash_fraction_downtime":"0.001000000000000000"},"signing_infos":[],"missed_blocks":[]},"staking":{"params":{"unbonding_time":"1814400s","max_validators":20,"max_entries":7,"historical_entries":20000,"bond_denom":"FX","min_commission_rate":"0.000000000000000000"},"last_total_power":"0","last_validator_powers":[],"validators":[],"delegations":[],"unbonding_delegations":[],"redelegations":[],"exported":false,"allowances":[]},"transfer":{"port_id":"transfer","denom_traces":[],"params":{"send_enabled":true,"receive_enabled":true}},"tron":{"params":{"gravity_id":"fx-tron-bridge","average_block_time":"7000","external_batch_timeout":"43200000","average_external_block_time":"3000","signed_window":"30000","slash_fraction":"0.800000000000000000","oracle_set_update_power_change_percent":"0.100000000000000000","ibc_transfer_timeout_height":"20000","oracles":[],"delegate_threshold":{"denom":"FX","amount":"10000000000000000000000"},"delegate_multiple":"10"},"last_observed_event_nonce":"0","last_observed_block_height":{"external_block_height":"0","block_height":"0"},"oracles":[],"oracle_sets":[],"bridge_tokens":[],"unbatched_transfers":[],"batches":[],"oracle_set_confirms":[],"batch_confirms":[],"attestations":[],"proposal_oracle":{"oracles":[]},"last_observed_oracle_set":{"nonce":"0","members":[],"height":"0"},"last_slashed_batch_block":"0","last_slashed_oracle_set_nonce":"0"},"upgrade":{},"vesting":{}}` encodingConfig := app.MakeEncodingConfig() genAppState := app.NewDefAppGenesisByDenom(fxtypes.DefaultDenom, encodingConfig.Codec) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 676d80814..ec640feb6 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -64,7 +64,6 @@ import ( "github.com/functionx/fx-core/v6/x/erc20" erc20keeper "github.com/functionx/fx-core/v6/x/erc20/keeper" erc20types "github.com/functionx/fx-core/v6/x/erc20/types" - ethkeeper "github.com/functionx/fx-core/v6/x/eth/keeper" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" fxevmkeeper "github.com/functionx/fx-core/v6/x/evm/keeper" fxgovkeeper "github.com/functionx/fx-core/v6/x/gov/keeper" @@ -73,7 +72,6 @@ import ( fxtransfer "github.com/functionx/fx-core/v6/x/ibc/applications/transfer" fxtransferkeeper "github.com/functionx/fx-core/v6/x/ibc/applications/transfer/keeper" "github.com/functionx/fx-core/v6/x/ibc/ibcrouter" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" migratekeeper "github.com/functionx/fx-core/v6/x/migrate/keeper" migratetypes "github.com/functionx/fx-core/v6/x/migrate/types" optimismtypes "github.com/functionx/fx-core/v6/x/optimism/types" @@ -92,7 +90,6 @@ type CrossChainKeepers struct { TronKeeper tronkeeper.Keeper ArbitrumKeeper crosschainkeeper.Keeper OptimismKeeper crosschainkeeper.Keeper - Layer2Keeper crosschainkeeper.Keeper } type AppKeepers struct { @@ -414,19 +411,6 @@ func NewAppKeeper( appKeepers.AccountKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - appKeepers.Layer2Keeper = crosschainkeeper.NewKeeper( - appCodec, - layer2types.ModuleName, - appKeepers.keys[layer2types.StoreKey], - appKeepers.StakingKeeper, - stakingkeeper.NewMsgServerImpl(appKeepers.StakingKeeper.Keeper), - distrkeeper.NewMsgServerImpl(appKeepers.DistrKeeper), - appKeepers.BankKeeper, - appKeepers.IBCTransferKeeper, - appKeepers.Erc20Keeper, - appKeepers.AccountKeeper, - authtypes.NewModuleAddress(govtypes.ModuleName).String(), - ) appKeepers.TronKeeper = tronkeeper.NewKeeper(crosschainkeeper.NewKeeper( appCodec, trontypes.ModuleName, @@ -447,10 +431,9 @@ func NewAppKeeper( AddRoute(bsctypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.BscKeeper)). AddRoute(polygontypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.PolygonKeeper)). AddRoute(avalanchetypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.AvalancheKeeper)). - AddRoute(ethtypes.ModuleName, ethkeeper.NewModuleHandler(appKeepers.EthKeeper)). + AddRoute(ethtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.EthKeeper)). AddRoute(arbitrumtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.ArbitrumKeeper)). AddRoute(optimismtypes.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.OptimismKeeper)). - AddRoute(layer2types.ModuleName, crosschainkeeper.NewModuleHandler(appKeepers.Layer2Keeper)). AddRoute(trontypes.ModuleName, tronkeeper.NewModuleHandler(appKeepers.TronKeeper)) appKeepers.CrosschainKeeper = crosschainkeeper.NewRouterKeeper(crosschainRouter) @@ -494,15 +477,14 @@ func NewAppKeeper( ) ibcTransferRouter := fxtypes.NewRouter(). - AddRoute(gravitytypes.ModuleName, appKeepers.Layer2Keeper). - AddRoute(ethtypes.ModuleName, appKeepers.Layer2Keeper). + AddRoute(gravitytypes.ModuleName, appKeepers.EthKeeper). + AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper). AddRoute(bsctypes.ModuleName, appKeepers.BscKeeper). AddRoute(polygontypes.ModuleName, appKeepers.PolygonKeeper). AddRoute(trontypes.ModuleName, appKeepers.TronKeeper). AddRoute(avalanchetypes.ModuleName, appKeepers.AvalancheKeeper). AddRoute(arbitrumtypes.ModuleName, appKeepers.ArbitrumKeeper). AddRoute(optimismtypes.ModuleName, appKeepers.OptimismKeeper). - AddRoute(layer2types.ModuleName, appKeepers.Layer2Keeper). AddRoute(erc20types.ModuleName, appKeepers.Erc20Keeper) appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetRouter(*ibcTransferRouter) appKeepers.FxTransferKeeper = appKeepers.FxTransferKeeper.SetRefundHook(appKeepers.Erc20Keeper) diff --git a/app/keepers/keepers_test.go b/app/keepers/keepers_test.go index 77aefe9fb..a00f1bc5e 100644 --- a/app/keepers/keepers_test.go +++ b/app/keepers/keepers_test.go @@ -24,7 +24,6 @@ import ( bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" erc20types "github.com/functionx/fx-core/v6/x/erc20/types" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" optimismtypes "github.com/functionx/fx-core/v6/x/optimism/types" polygontypes "github.com/functionx/fx-core/v6/x/polygon/types" trontypes "github.com/functionx/fx-core/v6/x/tron/types" @@ -55,7 +54,6 @@ func TestNewAppKeeper(t *testing.T) { trontypes.ModuleName: {authtypes.Minter, authtypes.Burner}, arbitrumtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, optimismtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - layer2types.ModuleName: {authtypes.Minter, authtypes.Burner}, evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, erc20types.ModuleName: {authtypes.Minter, authtypes.Burner}, } diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 146b3be81..2aa9832b2 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -31,7 +31,6 @@ import ( ethtypes "github.com/functionx/fx-core/v6/x/eth/types" precompilescrosschain "github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain" precompilesstaking "github.com/functionx/fx-core/v6/x/evm/precompiles/staking" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" migratetypes "github.com/functionx/fx-core/v6/x/migrate/types" optimismtypes "github.com/functionx/fx-core/v6/x/optimism/types" polygontypes "github.com/functionx/fx-core/v6/x/polygon/types" @@ -48,7 +47,7 @@ func (appKeepers *AppKeepers) generateKeys() { evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, bsctypes.StoreKey, polygontypes.StoreKey, avalanchetypes.StoreKey, ethtypes.StoreKey, trontypes.StoreKey, - arbitrumtypes.ModuleName, optimismtypes.ModuleName, layer2types.ModuleName, + arbitrumtypes.ModuleName, optimismtypes.ModuleName, evmtypes.StoreKey, feemarkettypes.StoreKey, erc20types.StoreKey, migratetypes.StoreKey, ) @@ -89,14 +88,13 @@ func (appKeepers *AppKeepers) EvmPrecompiled() { // cross chain precompile transferRouter := fxtypes.NewRouter(). - // AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper). + AddRoute(ethtypes.ModuleName, appKeepers.EthKeeper). AddRoute(bsctypes.ModuleName, appKeepers.BscKeeper). AddRoute(polygontypes.ModuleName, appKeepers.PolygonKeeper). AddRoute(trontypes.ModuleName, appKeepers.TronKeeper). AddRoute(avalanchetypes.ModuleName, appKeepers.AvalancheKeeper). AddRoute(arbitrumtypes.ModuleName, appKeepers.ArbitrumKeeper). - AddRoute(optimismtypes.ModuleName, appKeepers.OptimismKeeper). - AddRoute(layer2types.ModuleName, appKeepers.Layer2Keeper) + AddRoute(optimismtypes.ModuleName, appKeepers.OptimismKeeper) precompiled[precompilescrosschain.GetAddress()] = func(ctx sdk.Context) vm.PrecompiledContract { return precompilescrosschain.NewPrecompiledContract( ctx, diff --git a/app/modules.go b/app/modules.go index 626c278e5..1a3983347 100644 --- a/app/modules.go +++ b/app/modules.go @@ -62,8 +62,6 @@ import ( fxgov "github.com/functionx/fx-core/v6/x/gov" fxibctransfer "github.com/functionx/fx-core/v6/x/ibc/applications/transfer" fxibctransfertypes "github.com/functionx/fx-core/v6/x/ibc/applications/transfer/types" - "github.com/functionx/fx-core/v6/x/layer2" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" "github.com/functionx/fx-core/v6/x/migrate" migratetypes "github.com/functionx/fx-core/v6/x/migrate/types" "github.com/functionx/fx-core/v6/x/optimism" @@ -83,7 +81,6 @@ func init() { crosschaintypes.RegisterValidateBasic(trontypes.ModuleName, trontypes.TronMsgValidate{}) crosschaintypes.RegisterValidateBasic(arbitrumtypes.ModuleName, crosschaintypes.MsgValidate{}) crosschaintypes.RegisterValidateBasic(optimismtypes.ModuleName, crosschaintypes.MsgValidate{}) - crosschaintypes.RegisterValidateBasic(layer2types.ModuleName, crosschaintypes.MsgValidate{}) } // module account permissions @@ -102,7 +99,6 @@ var maccPerms = map[string][]string{ trontypes.ModuleName: {authtypes.Minter, authtypes.Burner}, arbitrumtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, optimismtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - layer2types.ModuleName: {authtypes.Minter, authtypes.Burner}, evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, erc20types.ModuleName: {authtypes.Minter, authtypes.Burner}, } @@ -149,7 +145,6 @@ var ModuleBasics = module.NewBasicManager( tron.AppModuleBasic{}, arbitrum.AppModule{}, optimism.AppModule{}, - layer2.AppModule{}, fxevm.AppModuleBasic{}, feemarket.AppModuleBasic{}, erc20.AppModuleBasic{}, @@ -190,7 +185,6 @@ func appModules( tron.NewAppModule(app.TronKeeper, app.GetSubspace(trontypes.ModuleName)), arbitrum.NewAppModule(app.ArbitrumKeeper), optimism.NewAppModule(app.OptimismKeeper), - layer2.NewAppModule(app.Layer2Keeper), fxevm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.LegacyAmino(), app.GetKey(paramstypes.StoreKey), app.GetSubspace(evmtypes.ModuleName)), feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)), erc20.NewAppModule(app.Erc20Keeper, app.GetSubspace(erc20types.ModuleName)), @@ -229,7 +223,6 @@ func orderBeginBlockers() []string { ethtypes.ModuleName, arbitrumtypes.ModuleName, optimismtypes.ModuleName, - layer2types.ModuleName, feemarkettypes.ModuleName, // begin evmtypes.ModuleName, // begin @@ -268,7 +261,6 @@ func orderEndBlockers() []string { ethtypes.ModuleName, // end arbitrumtypes.ModuleName, // end optimismtypes.ModuleName, // end - layer2types.ModuleName, // end evmtypes.ModuleName, // end feemarkettypes.ModuleName, // end @@ -307,7 +299,6 @@ func orderInitBlockers() []string { ethtypes.ModuleName, arbitrumtypes.ModuleName, optimismtypes.ModuleName, - layer2types.ModuleName, feemarkettypes.ModuleName, evmtypes.ModuleName, diff --git a/app/upgrades/v6/constants.go b/app/upgrades/v6/constants.go index aa056ebed..e5f440987 100644 --- a/app/upgrades/v6/constants.go +++ b/app/upgrades/v6/constants.go @@ -4,25 +4,12 @@ import ( storetypes "github.com/cosmos/cosmos-sdk/store/types" "github.com/functionx/fx-core/v6/app/upgrades" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" ) -var Layer2GenesisTokenAddress = map[string]string{ - "FX": "", - "PUNDIX": "", - "USDT": "", - "WETH": "", - "LINK": "", - "WBTC": "", - "USDC": "", -} - var Upgrade = upgrades.Upgrade{ UpgradeName: "v6.0.x", CreateUpgradeHandler: CreateUpgradeHandler, StoreUpgrades: func() *storetypes.StoreUpgrades { - return &storetypes.StoreUpgrades{ - Added: []string{layer2types.ModuleName}, - } + return &storetypes.StoreUpgrades{} }, } diff --git a/app/upgrades/v6/upgrade.go b/app/upgrades/v6/upgrade.go index 944ecdcbb..df42c29c2 100644 --- a/app/upgrades/v6/upgrade.go +++ b/app/upgrades/v6/upgrade.go @@ -1,25 +1,11 @@ package v6 import ( - "fmt" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/ethereum/go-ethereum/common" "github.com/functionx/fx-core/v6/app/keepers" - crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper" - fxgovtypes "github.com/functionx/fx-core/v6/x/gov/types" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" - migratekeeper "github.com/functionx/fx-core/v6/x/migrate/keeper" - fxstakingkeeper "github.com/functionx/fx-core/v6/x/staking/keeper" ) func CreateUpgradeHandler( @@ -30,14 +16,6 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) { cacheCtx, commit := ctx.CacheContext() - if err := UpdateParams(cacheCtx, app); err != nil { - return nil, err - } - - MigrateMetadata(cacheCtx, app.BankKeeper) - MigrateLayer2Module(cacheCtx, app.Layer2Keeper) - ExportCommunityPool(cacheCtx, app.DistrKeeper, app.BankKeeper) - ctx.Logger().Info("start to run v6 migrations...", "module", "upgrade") toVM, err := mm.RunMigrations(cacheCtx, configurator, fromVM) if err != nil { @@ -49,120 +27,3 @@ func CreateUpgradeHandler( return toVM, nil } } - -func UpdateParams(cacheCtx sdk.Context, app *keepers.AppKeepers) error { - mintParams := app.MintKeeper.GetParams(cacheCtx) - mintParams.InflationMax = sdk.ZeroDec() - mintParams.InflationMin = sdk.ZeroDec() - if err := mintParams.Validate(); err != nil { - return err - } - app.MintKeeper.SetParams(cacheCtx, mintParams) - - distrParams := app.DistrKeeper.GetParams(cacheCtx) - distrParams.CommunityTax = sdk.ZeroDec() - distrParams.BaseProposerReward = sdk.ZeroDec() - distrParams.BonusProposerReward = sdk.ZeroDec() - if err := distrParams.ValidateBasic(); err != nil { - return err - } - app.DistrKeeper.SetParams(cacheCtx, distrParams) - - stakingParams := app.StakingKeeper.GetParams(cacheCtx) - stakingParams.UnbondingTime = 1 - if err := stakingParams.Validate(); err != nil { - return err - } - app.StakingKeeper.SetParams(cacheCtx, stakingParams) - - govTallyParams := app.GovKeeper.GetTallyParams(cacheCtx) - govTallyParams.Quorum = sdk.OneDec().String() // 100% - govTallyParams.Threshold = sdk.OneDec().String() // 100% - govTallyParams.VetoThreshold = sdk.OneDec().String() // 100% - app.GovKeeper.SetTallyParams(cacheCtx, govTallyParams) - - app.GovKeeper.IterateParams(cacheCtx, func(param *fxgovtypes.Params) (stop bool) { - param.Quorum = sdk.OneDec().String() // 100% - param.Threshold = sdk.OneDec().String() // 100% - param.VetoThreshold = sdk.OneDec().String() // 100% - if err := param.ValidateBasic(); err != nil { - panic(err) - } - if err := app.GovKeeper.SetParams(cacheCtx, param); err != nil { - panic(err) - } - return false - }) - return nil -} - -func ExportCommunityPool(ctx sdk.Context, distrKeeper distrkeeper.Keeper, bankKeeper bankkeeper.Keeper) sdk.Coins { - feePool := distrKeeper.GetFeePool(ctx) - truncatedCoins, changeCoins := feePool.CommunityPool.TruncateDecimal() - feePool.CommunityPool = changeCoins - distrKeeper.SetFeePool(ctx, feePool) - - if err := bankKeeper.SendCoinsFromModuleToModule(ctx, distrtypes.ModuleName, govtypes.ModuleName, truncatedCoins); err != nil { - panic(err) - } - if err := bankKeeper.BurnCoins(ctx, govtypes.ModuleName, truncatedCoins); err != nil { - panic(err) - } - ctx.Logger().Info("export community pool", "coins", truncatedCoins.String()) - return truncatedCoins -} - -func MigrateMetadata(ctx sdk.Context, bankKeeper bankkeeper.Keeper) { - bankKeeper.IterateAllDenomMetaData(ctx, func(metadata banktypes.Metadata) bool { - address, ok := Layer2GenesisTokenAddress[metadata.Symbol] - if !ok { - return false - } - if len(metadata.DenomUnits) > 0 { - metadata.DenomUnits[0].Aliases = append(metadata.DenomUnits[0].Aliases, - fmt.Sprintf("%s%s", layer2types.ModuleName, address)) - bankKeeper.SetDenomMetaData(ctx, metadata) - } - return false - }) -} - -func MigrateLayer2Module(ctx sdk.Context, layer2CrossChainKeeper crosschainkeeper.Keeper) { - for _, address := range Layer2GenesisTokenAddress { - fxTokenDenom := fmt.Sprintf("%s%s", layer2types.ModuleName, address) - layer2CrossChainKeeper.AddBridgeToken(ctx, address, fxTokenDenom) - } -} - -func AutoUndelegate(ctx sdk.Context, stakingKeeper fxstakingkeeper.Keeper) []stakingtypes.Delegation { - var delegations []stakingtypes.Delegation - stakingKeeper.IterateAllDelegations(ctx, func(delegation stakingtypes.Delegation) (stop bool) { - delegations = append(delegations, delegation) - delegator := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - valAddress, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) - if err != nil { - panic(err) - } - if delegator.Equals(valAddress) { - return false - } - if _, err := stakingKeeper.Undelegate(ctx, delegator, valAddress, delegation.Shares); err != nil { - panic(err) - } - return false - }) - return delegations -} - -func ExportDelegate(ctx sdk.Context, migrateKeeper migratekeeper.Keeper, delegations []stakingtypes.Delegation) []stakingtypes.Delegation { - for i := 0; i < len(delegations); i++ { - delegation := delegations[i] - delegator := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress) - if !migrateKeeper.HasMigratedDirectionTo(ctx, common.BytesToAddress(delegator.Bytes())) { - delegations = append(delegations[:i], delegations[i+1:]...) - i-- - continue - } - } - return delegations -} diff --git a/app/upgrades/v6/upgrade_test.go b/app/upgrades/v6/upgrade_test.go deleted file mode 100644 index 4b75fe361..000000000 --- a/app/upgrades/v6/upgrade_test.go +++ /dev/null @@ -1,122 +0,0 @@ -package v6_test - -import ( - "fmt" - "strings" - "testing" - - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/ethereum/go-ethereum/common" - "github.com/stretchr/testify/suite" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - - "github.com/functionx/fx-core/v6/app" - v6 "github.com/functionx/fx-core/v6/app/upgrades/v6" - "github.com/functionx/fx-core/v6/testutil/helpers" - fxtypes "github.com/functionx/fx-core/v6/types" - layer2types "github.com/functionx/fx-core/v6/x/layer2/types" - migratetypes "github.com/functionx/fx-core/v6/x/migrate/types" -) - -type UpgradeTestSuite struct { - suite.Suite - - app *app.App - ctx sdk.Context - valNumber int -} - -func TestUpgradeTestSuite(t *testing.T) { - suite.Run(t, new(UpgradeTestSuite)) -} - -func (s *UpgradeTestSuite) SetupTest() { - s.valNumber = tmrand.Intn(5) + 5 - valSet, valAccounts, valBalances := helpers.GenerateGenesisValidator(s.valNumber, sdk.Coins{}) - s.app = helpers.SetupWithGenesisValSet(s.T(), valSet, valAccounts, valBalances...) - s.ctx = s.app.NewContext(false, tmproto.Header{ - ChainID: fxtypes.MainnetChainId, - Height: s.app.LastBlockHeight() + 1, - ProposerAddress: valSet.Proposer.Address.Bytes(), - }) - - for symbol := range v6.Layer2GenesisTokenAddress { - v6.Layer2GenesisTokenAddress[symbol] = common.BytesToAddress(helpers.NewEthPrivKey().PubKey().Address().Bytes()).String() - } -} - -func (s *UpgradeTestSuite) CommitBlock(block int64) { - helpers.MintBlock(s.app, s.ctx, block) -} - -func (s *UpgradeTestSuite) TestUpdateParams() { - s.NoError(v6.UpdateParams(s.ctx, s.app.AppKeepers)) - s.CommitBlock(10) -} - -func (s *UpgradeTestSuite) TestExportCommunityPool() { - s.CommitBlock(10) - communityPool := v6.ExportCommunityPool(s.ctx, s.app.DistrKeeper, s.app.BankKeeper) - s.True(communityPool.IsAllPositive()) -} - -func (s *UpgradeTestSuite) TestMigrateMetadata() { - for symbol := range v6.Layer2GenesisTokenAddress { - hasDenomMetaData := s.app.BankKeeper.HasDenomMetaData(s.ctx, strings.ToLower(symbol)) - s.False(hasDenomMetaData) - - metadata := fxtypes.GetCrossChainMetadata(symbol, symbol, 18) - s.app.BankKeeper.SetDenomMetaData(s.ctx, metadata) - } - - v6.MigrateMetadata(s.ctx, s.app.BankKeeper) - - for symbol, address := range v6.Layer2GenesisTokenAddress { - metadata, found := s.app.BankKeeper.GetDenomMetaData(s.ctx, strings.ToLower(symbol)) - s.True(found) - s.True(len(metadata.DenomUnits) > 0) - s.Subset(metadata.DenomUnits[0].Aliases, []string{fmt.Sprintf("%s%s", layer2types.ModuleName, address)}) - } -} - -func (s *UpgradeTestSuite) TestMigrateLayer2Module() { - v6.MigrateLayer2Module(s.ctx, s.app.Layer2Keeper) - for _, address := range v6.Layer2GenesisTokenAddress { - bridgeToken := s.app.Layer2Keeper.GetBridgeTokenDenom(s.ctx, address) - s.Equal(bridgeToken.Token, address) - s.Equal(bridgeToken.Denom, fmt.Sprintf("%s%s", layer2types.ModuleName, address)) - } -} - -func (s *UpgradeTestSuite) TestAutoUndelegate_And_ExportDelegate() { - delPrivKey := helpers.NewPriKey() - delAddr := sdk.AccAddress(delPrivKey.PubKey().Address()) - helpers.AddTestAddr(s.app, s.ctx, delAddr, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdk.NewInt(10000)))) - account := s.app.AccountKeeper.GetAccount(s.ctx, delAddr) - s.NoError(account.SetPubKey(delPrivKey.PubKey())) - s.app.AccountKeeper.SetAccount(s.ctx, account) - - validators := s.app.StakingKeeper.GetAllValidators(s.ctx) - s.Equal(s.valNumber, len(validators)) - validator := validators[0] - - _, err := s.app.StakingKeeper.Delegate(s.ctx, delAddr, sdkmath.NewInt(100), stakingtypes.Unbonded, validator, true) - s.NoError(err) - - newPrivKey := helpers.NewEthPrivKey() - _, err = s.app.MigrateKeeper.MigrateAccount(s.ctx, &migratetypes.MsgMigrateAccount{ - From: delAddr.String(), - To: common.BytesToAddress(newPrivKey.PubKey().Address()).String(), - Signature: "", - }) - s.NoError(err) - - delegations := v6.AutoUndelegate(s.ctx, s.app.StakingKeeper) - s.Equal(s.valNumber+1, len(delegations)) - - delegations = v6.ExportDelegate(s.ctx, s.app.MigrateKeeper, delegations) - s.Equal(1, len(delegations)) -} diff --git a/x/crosschain/keeper/abci_test.go b/x/crosschain/keeper/abci_test.go index a0e31b48a..971afb726 100644 --- a/x/crosschain/keeper/abci_test.go +++ b/x/crosschain/keeper/abci_test.go @@ -25,7 +25,7 @@ func (suite *KeeperTestSuite) TestABCIEndBlockDepositClaim() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) @@ -93,7 +93,7 @@ func (suite *KeeperTestSuite) TestOracleUpdate() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -209,7 +209,7 @@ func (suite *KeeperTestSuite) TestAttestationAfterOracleUpdate() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), msgBondedOracle) @@ -407,7 +407,7 @@ func (suite *KeeperTestSuite) TestOracleDelete() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -474,7 +474,7 @@ func (suite *KeeperTestSuite) TestOracleSetSlash() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) @@ -532,7 +532,7 @@ func (suite *KeeperTestSuite) TestSlashOracle() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(10 * 1e3).MulRaw(1e18)), + DelegateAmount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(10 * 1e3).MulRaw(1e18)}, ChainName: suite.chainName, } require.NoError(suite.T(), msgBondedOracle.ValidateBasic()) diff --git a/x/crosschain/keeper/attestation_handler.go b/x/crosschain/keeper/attestation_handler.go index dbf95a55b..c16da5abc 100644 --- a/x/crosschain/keeper/attestation_handler.go +++ b/x/crosschain/keeper/attestation_handler.go @@ -62,7 +62,7 @@ func (k Keeper) AttestationHandler(ctx sdk.Context, externalClaim types.External return errorsmod.Wrap(types.ErrInvalid, "bridge token is exist") } k.Logger(ctx).Info("add bridge token claim", "symbol", claim.Symbol, "token", claim.TokenContract, "channelIbc", claim.ChannelIbc) - if claim.Symbol == types.NativeDenom { + if claim.Symbol == fxtypes.DefaultDenom { // Check if denom exists metadata, found := k.bankKeeper.GetDenomMetaData(ctx, claim.Symbol) if !found { diff --git a/x/crosschain/keeper/grpc_query_test.go b/x/crosschain/keeper/grpc_query_test.go index c10ef5147..2242a6f24 100644 --- a/x/crosschain/keeper/grpc_query_test.go +++ b/x/crosschain/keeper/grpc_query_test.go @@ -24,6 +24,7 @@ import ( "github.com/functionx/fx-core/v6/app" "github.com/functionx/fx-core/v6/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v6/types" arbitrumtypes "github.com/functionx/fx-core/v6/x/arbitrum/types" avalanchetypes "github.com/functionx/fx-core/v6/x/avalanche/types" bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" @@ -66,8 +67,8 @@ func (suite *CrossChainGrpcTestSuite) SetupTest() { types.RegisterQueryServer(queryHelper, suite.app.CrosschainKeeper) suite.queryClient = types.NewQueryClient(queryHelper) - suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(types.NewDelegateAmount(sdkmath.NewInt(300*1e3).MulRaw(1e18)))) - suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(types.NativeDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, types.MaxOracleSize, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) suite.msgServer = keeper.NewMsgServerImpl(suite.Keeper()) } diff --git a/x/crosschain/keeper/keeper.go b/x/crosschain/keeper/keeper.go index 9ee0fb744..3bf57c1cc 100644 --- a/x/crosschain/keeper/keeper.go +++ b/x/crosschain/keeper/keeper.go @@ -11,6 +11,7 @@ import ( stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/tendermint/tendermint/libs/log" + fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ) @@ -161,7 +162,7 @@ func (k Keeper) UnbondedOracleFromProposal(ctx sdk.Context, oracle types.Oracle) if err != nil { return err } - msgUndelegate := stakingtypes.NewMsgUndelegate(delegateAddr, valAddr, types.NewDelegateAmount(getOracleDelegateToken)) + msgUndelegate := stakingtypes.NewMsgUndelegate(delegateAddr, valAddr, sdk.NewCoin(fxtypes.DefaultDenom, getOracleDelegateToken)) if _, err = k.stakingMsgServer.Undelegate(sdk.WrapSDKContext(ctx), msgUndelegate); err != nil { return err } diff --git a/x/crosschain/keeper/keeper_test.go b/x/crosschain/keeper/keeper_test.go index f7a0d7476..760b2aaf3 100644 --- a/x/crosschain/keeper/keeper_test.go +++ b/x/crosschain/keeper/keeper_test.go @@ -110,8 +110,8 @@ func (suite *KeeperTestSuite) SetupTest() { ProposerAddress: valSet.Proposer.Address.Bytes(), }) - suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(types.NewDelegateAmount(sdkmath.NewInt(300*1e3).MulRaw(1e18)))) - suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(types.NativeDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.oracleAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) + suite.bridgerAddrs = helpers.AddTestAddrs(suite.app, suite.ctx, valNumber, sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(300*1e3).MulRaw(1e18)))) suite.externalPris = helpers.CreateMultiECDSA(valNumber) suite.valAddrs = make([]sdk.ValAddress, valNumber) diff --git a/x/crosschain/keeper/msg_server.go b/x/crosschain/keeper/msg_server.go index 3488bba65..1c5c91a8a 100644 --- a/x/crosschain/keeper/msg_server.go +++ b/x/crosschain/keeper/msg_server.go @@ -122,12 +122,12 @@ func (s MsgServer) AddDelegate(c context.Context, msg *types.MsgAddDelegate) (*t return nil, errorsmod.Wrapf(types.ErrInvalid, "delegate denom got %s, expected %s", msg.Amount.Denom, threshold.Denom) } - slashAmount := types.NewDelegateAmount(oracle.GetSlashAmount(s.GetSlashFraction(ctx))) + slashAmount := sdk.NewCoin(fxtypes.DefaultDenom, oracle.GetSlashAmount(s.GetSlashFraction(ctx))) if slashAmount.IsPositive() && msg.Amount.Amount.LT(slashAmount.Amount) { return nil, errorsmod.Wrap(types.ErrInvalid, "not sufficient slash amount") } - delegateCoin := types.NewDelegateAmount(msg.Amount.Amount.Sub(slashAmount.Amount)) + delegateCoin := sdk.NewCoin(fxtypes.DefaultDenom, msg.Amount.Amount.Sub(slashAmount.Amount)) oracle.DelegateAmount = oracle.DelegateAmount.Add(delegateCoin.Amount) if oracle.DelegateAmount.Sub(threshold.Amount).IsNegative() { @@ -203,7 +203,7 @@ func (s MsgServer) ReDelegate(c context.Context, msg *types.MsgReDelegate) (*typ if err != nil { return nil, err } - msgBeginRedelegate := stakingtypes.NewMsgBeginRedelegate(delegateAddr, valSrcAddress, valDstAddress, types.NewDelegateAmount(delegateToken)) + msgBeginRedelegate := stakingtypes.NewMsgBeginRedelegate(delegateAddr, valSrcAddress, valDstAddress, sdk.NewCoin(fxtypes.DefaultDenom, delegateToken)) if _, err = s.stakingMsgServer.BeginRedelegate(c, msgBeginRedelegate); err != nil { return nil, err } @@ -302,9 +302,9 @@ func (s MsgServer) UnbondedOracle(c context.Context, msg *types.MsgUnbondedOracl return nil, errorsmod.Wrap(types.ErrInvalid, "exist unbonding delegation") } balances := s.bankKeeper.GetAllBalances(ctx, delegateAddr) - slashAmount := types.NewDelegateAmount(oracle.GetSlashAmount(s.GetSlashFraction(ctx))) + slashAmount := sdk.NewCoin(fxtypes.DefaultDenom, oracle.GetSlashAmount(s.GetSlashFraction(ctx))) if slashAmount.IsPositive() { - if balances.AmountOf(slashAmount.Denom).LT(slashAmount.Amount) { + if balances.AmountOf(fxtypes.DefaultDenom).LT(slashAmount.Amount) { return nil, errorsmod.Wrap(types.ErrInvalid, "not sufficient slash amount") } if err = s.bankKeeper.SendCoinsFromAccountToModule(ctx, delegateAddr, s.moduleName, sdk.NewCoins(slashAmount)); err != nil { diff --git a/x/crosschain/keeper/msg_server_test.go b/x/crosschain/keeper/msg_server_test.go index 50a28fc5b..37ea9af1b 100644 --- a/x/crosschain/keeper/msg_server_test.go +++ b/x/crosschain/keeper/msg_server_test.go @@ -19,6 +19,7 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/functionx/fx-core/v6/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" trontypes "github.com/functionx/fx-core/v6/x/tron/types" @@ -107,8 +108,11 @@ func (suite *KeeperTestSuite) TestMsgBondedOracle() { BridgerAddress: suite.bridgerAddrs[oracleIndex].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[oracleIndex].PublicKey), ValidatorAddress: suite.valAddrs[oracleIndex].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(3) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(3) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } testCase.preRun(msg) @@ -282,8 +286,11 @@ func (suite *KeeperTestSuite) TestMsgAddDelegate() { BridgerAddress: suite.bridgerAddrs[oracleIndex].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[oracleIndex].PublicKey), ValidatorAddress: suite.valAddrs[oracleIndex].String(), - DelegateAmount: types.NewDelegateAmount(initDelegateAmount), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: initDelegateAmount, + }, + ChainName: suite.chainName, }) require.NoError(t, err) @@ -293,8 +300,8 @@ func (suite *KeeperTestSuite) TestMsgAddDelegate() { msg := &types.MsgAddDelegate{ ChainName: suite.chainName, OracleAddress: suite.oracleAddrs[oracleIndex].String(), - Amount: types.NewDelegateAmount(sdkmath.NewInt( - tmrand.Int63n(maxDelegateAmount.QuoRaw(1e18).Int64()) + 1, + Amount: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt( + tmrand.Int63n(maxDelegateAmount.QuoRaw(1e18).Int64())+1, ). MulRaw(1e18). Sub(sdkmath.NewInt(1))), @@ -348,8 +355,11 @@ func (suite *KeeperTestSuite) TestMsgEditBridger() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[i].String(), - DelegateAmount: types.NewDelegateAmount(delegateAmount), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: delegateAmount, + }, + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), bondedMsg) suite.NoError(err) @@ -426,8 +436,11 @@ func (suite *KeeperTestSuite) TestMsgSetOracleSetConfirm() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -549,8 +562,11 @@ func (suite *KeeperTestSuite) TestClaimWithOracleOnline() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -747,8 +763,11 @@ func (suite *KeeperTestSuite) TestClaimMsgGasConsumed() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), msg) require.NoError(suite.T(), err) @@ -769,8 +788,11 @@ func (suite *KeeperTestSuite) TestClaimTest() { BridgerAddress: suite.bridgerAddrs[0].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[0].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } _, err := suite.MsgServer().BondedOracle(sdk.WrapSDKContext(suite.ctx), normalMsg) require.NoError(suite.T(), err) @@ -890,8 +912,11 @@ func (suite *KeeperTestSuite) TestRequestBatchBaseFee() { BridgerAddress: suite.bridgerAddrs[i].String(), ExternalAddress: suite.PubKeyToExternalAddr(suite.externalPris[i].PublicKey), ValidatorAddress: suite.valAddrs[0].String(), - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18)), - ChainName: suite.chainName, + DelegateAmount: sdk.Coin{ + Denom: fxtypes.DefaultDenom, + Amount: sdkmath.NewInt((tmrand.Int63n(5) + 1) * 10_000).MulRaw(1e18), + }, + ChainName: suite.chainName, } if len(suite.valAddrs) > i { normalMsg.ValidatorAddress = suite.valAddrs[i].String() diff --git a/x/crosschain/keeper/params_test.go b/x/crosschain/keeper/params_test.go index a8cfd9e78..bb032b0cf 100644 --- a/x/crosschain/keeper/params_test.go +++ b/x/crosschain/keeper/params_test.go @@ -4,6 +4,7 @@ import ( sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" + fxtypes "github.com/functionx/fx-core/v6/types" "github.com/functionx/fx-core/v6/x/crosschain/types" ) @@ -25,7 +26,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -43,7 +44,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -61,7 +62,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -79,7 +80,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -115,7 +116,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 1, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -133,7 +134,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDec(2), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, @@ -151,7 +152,7 @@ func (suite *KeeperTestSuite) TestParams() { SlashFraction: sdk.NewDec(2), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: types.NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: 10, Oracles: nil, }, diff --git a/x/crosschain/keeper/pool.go b/x/crosschain/keeper/pool.go index 7a71a87e4..bc2b04cd7 100644 --- a/x/crosschain/keeper/pool.go +++ b/x/crosschain/keeper/pool.go @@ -122,7 +122,7 @@ func (k Keeper) RemoveFromOutgoingPoolAndRefund(ctx sdk.Context, txId uint64, se totalToRefund.Amount = totalToRefund.Amount.Add(tx.Fee.Amount) totalToRefundCoins := sdk.NewCoins(totalToRefund) - if bridgeToken.Denom == types.NativeDenom { + if bridgeToken.Denom == fxtypes.DefaultDenom { if err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, k.moduleName, sender, totalToRefundCoins); err != nil { return sdk.Coin{}, err } @@ -175,7 +175,7 @@ func (k Keeper) AddUnbatchedTxBridgeFee(ctx sdk.Context, txId uint64, sender sdk // If the coin is a gravity voucher, burn the coins. If not, check if there is a deployed ERC20 contract representing it. // If there is, lock the coins. - if addBridgeFee.Denom == types.NativeDenom { + if addBridgeFee.Denom == fxtypes.DefaultDenom { // lock coins in module if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, k.moduleName, sdk.NewCoins(addBridgeFee)); err != nil { return err diff --git a/x/crosschain/keeper/pool_test.go b/x/crosschain/keeper/pool_test.go index ea6c40380..9591194f0 100644 --- a/x/crosschain/keeper/pool_test.go +++ b/x/crosschain/keeper/pool_test.go @@ -8,7 +8,7 @@ import ( tmrand "github.com/tendermint/tendermint/libs/rand" "github.com/functionx/fx-core/v6/testutil/helpers" - "github.com/functionx/fx-core/v6/x/crosschain/types" + fxtypes "github.com/functionx/fx-core/v6/types" ethtypes "github.com/functionx/fx-core/v6/x/eth/types" ) @@ -46,7 +46,7 @@ func (suite *KeeperTestSuite) TestKeeper_Outgoing() { func (suite *KeeperTestSuite) TestKeeper_Outgoing2() { sender := helpers.GenerateAddress().Bytes() bridgeToken := helpers.GenerateAddress().Hex() - denom := types.NativeDenom + denom := fxtypes.DefaultDenom supply := suite.app.BankKeeper.GetSupply(suite.ctx, denom) sendAmount := sdk.NewCoin(denom, sdkmath.NewInt(int64(tmrand.Uint32()*2))) diff --git a/x/crosschain/types/msg_validator_test.go b/x/crosschain/types/msg_validator_test.go index b3777100d..935bcd2f8 100644 --- a/x/crosschain/types/msg_validator_test.go +++ b/x/crosschain/types/msg_validator_test.go @@ -16,6 +16,7 @@ import ( _ "github.com/functionx/fx-core/v6/app" "github.com/functionx/fx-core/v6/testutil/helpers" + fxtypes "github.com/functionx/fx-core/v6/types" avalanchetypes "github.com/functionx/fx-core/v6/x/avalanche/types" bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" "github.com/functionx/fx-core/v6/x/crosschain/types" @@ -162,7 +163,7 @@ func TestMsgBondedOracle_ValidateBasic(t *testing.T) { OracleAddress: normalOracleAddress, BridgerAddress: normalBridgeAddress, ExternalAddress: normalExternalAddress, - DelegateAmount: types.NewDelegateAmount(sdkmath.NewInt(1)), + DelegateAmount: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1)), }, expectPass: true, err: nil, @@ -224,7 +225,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: "", - Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), + Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, }, expectPass: false, err: errortypes.ErrInvalidAddress, @@ -235,7 +236,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: errPrefixAddress, - Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), + Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, }, expectPass: false, err: errortypes.ErrInvalidAddress, @@ -246,7 +247,18 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: normalOracleAddress, - Amount: types.NewDelegateAmount(sdkmath.NewInt(0)), + Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(0)}, + }, + expectPass: false, + err: errortypes.ErrInvalidRequest, + errReason: "invalid amount: invalid request", + }, + { + testName: "err - negative delegate amount", + msg: &types.MsgAddDelegate{ + ChainName: moduleName, + OracleAddress: normalOracleAddress, + Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(-1)}, }, expectPass: false, err: errortypes.ErrInvalidRequest, @@ -257,7 +269,7 @@ func TestMsgAddDelegate_ValidateBasic(t *testing.T) { msg: &types.MsgAddDelegate{ ChainName: moduleName, OracleAddress: normalOracleAddress, - Amount: types.NewDelegateAmount(sdkmath.NewInt(1)), + Amount: sdk.Coin{Denom: fxtypes.DefaultDenom, Amount: sdkmath.NewInt(1)}, }, expectPass: true, err: nil, @@ -1286,7 +1298,7 @@ func TestMsgIncreaseBridgeFee_ValidateBasic(t *testing.T) { ChainName: moduleName, Sender: normalFxAddress, TransactionId: 1, - AddBridgeFee: sdk.NewCoin(helpers.NewRandDenom(), sdkmath.NewInt(1)), + AddBridgeFee: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(1)), }, expectPass: true, }, diff --git a/x/crosschain/types/params.go b/x/crosschain/types/params.go index 20a690970..3f54bce1e 100644 --- a/x/crosschain/types/params.go +++ b/x/crosschain/types/params.go @@ -20,11 +20,6 @@ const ( MaxKeepEventSize = 100 ) -var ( - OracleDelegateDenom = fxtypes.DefaultDenom - NativeDenom = fxtypes.DefaultDenom -) - var ( // AttestationVotesPowerThreshold threshold of votes power to succeed AttestationVotesPowerThreshold = sdkmath.NewInt(66) @@ -75,7 +70,7 @@ func DefaultParams() Params { SlashFraction: sdk.NewDecWithPrec(8, 1), // 80% OracleSetUpdatePowerChangePercent: sdk.NewDecWithPrec(1, 1), // 10% IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: NewDelegateAmount(sdkmath.NewInt(10_000).MulRaw(1e18)), + DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), DelegateMultiple: DefaultOracleDelegateThreshold, Oracles: nil, } @@ -204,7 +199,7 @@ func validateOracleDelegateThreshold(i interface{}) error { if !c.IsValid() || !c.IsPositive() { return fmt.Errorf("invalid delegate threshold") } - if c.Denom != OracleDelegateDenom { + if c.Denom != fxtypes.DefaultDenom { return fmt.Errorf("oracle delegate denom must FX") } return nil diff --git a/x/crosschain/types/types.go b/x/crosschain/types/types.go index b0fec1c64..1e9cffe25 100644 --- a/x/crosschain/types/types.go +++ b/x/crosschain/types/types.go @@ -15,10 +15,6 @@ import ( fxtypes "github.com/functionx/fx-core/v6/types" ) -func NewDelegateAmount(amount sdkmath.Int) sdk.Coin { - return sdk.NewCoin(OracleDelegateDenom, amount) -} - // --- ERC20Token --- // func NewERC20Token(amount sdkmath.Int, contract string) ERC20Token { diff --git a/x/eth/keeper/keeper_router.go b/x/eth/keeper/keeper_router.go deleted file mode 100644 index 25ebf60dc..000000000 --- a/x/eth/keeper/keeper_router.go +++ /dev/null @@ -1,11 +0,0 @@ -package keeper - -import crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper" - -func NewModuleHandler(keeper crosschainkeeper.Keeper) *crosschainkeeper.ModuleHandler { - return &crosschainkeeper.ModuleHandler{ - QueryServer: keeper, - MsgServer: NewMsgServerImpl(keeper), - ProposalServer: keeper, - } -} diff --git a/x/eth/keeper/msg_server.go b/x/eth/keeper/msg_server.go deleted file mode 100644 index d9e7fa21e..000000000 --- a/x/eth/keeper/msg_server.go +++ /dev/null @@ -1,27 +0,0 @@ -package keeper - -import ( - "context" - - "cosmossdk.io/errors" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - - crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" -) - -var _ crosschaintypes.MsgServer = MsgServer{} - -type MsgServer struct { - crosschainkeeper.MsgServer -} - -func NewMsgServerImpl(keeper crosschainkeeper.Keeper) crosschaintypes.MsgServer { - return MsgServer{ - MsgServer: crosschainkeeper.MsgServer{Keeper: keeper}, - } -} - -func (s MsgServer) SendToExternal(_ context.Context, _ *crosschaintypes.MsgSendToExternal) (*crosschaintypes.MsgSendToExternalResponse, error) { - return nil, errors.Wrap(sdkerrors.ErrInvalidRequest, "not supported") -} diff --git a/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go b/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go index c76a0b451..e63af3e30 100644 --- a/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go +++ b/x/evm/precompiles/crosschain/cancel_sendtoexternal_test.go @@ -20,6 +20,7 @@ import ( bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" "github.com/functionx/fx-core/v6/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v6/x/eth/types" "github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain" ) @@ -139,7 +140,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() { { name: "ok - fip20 contract + evm token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) suite.Require().True(found) suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), pair.GetDenom()) @@ -159,7 +160,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() { { name: "ok - address + evm token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) @@ -210,7 +211,7 @@ func (suite *PrecompileTestSuite) TestCancelSendToExternal() { { name: "ok - address + wrapper origin token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) suite.Require().True(found) diff --git a/x/evm/precompiles/crosschain/contract_test.go b/x/evm/precompiles/crosschain/contract_test.go index 3b87c1573..349fd4d4b 100644 --- a/x/evm/precompiles/crosschain/contract_test.go +++ b/x/evm/precompiles/crosschain/contract_test.go @@ -181,7 +181,7 @@ func (suite *PrecompileTestSuite) CrossChainKeepers() map[string]CrossChainKeepe cck := value.Field(i).Interface().(CrossChainKeeper) if chainName == "bridge-eth" { // keepers["gravity"] = cck - // keepers["eth"] = cck + keepers["eth"] = cck } else { keepers[chainName] = cck } diff --git a/x/evm/precompiles/crosschain/crosschain_test.go b/x/evm/precompiles/crosschain/crosschain_test.go index 630e6c4fa..a4070d061 100644 --- a/x/evm/precompiles/crosschain/crosschain_test.go +++ b/x/evm/precompiles/crosschain/crosschain_test.go @@ -114,6 +114,111 @@ func (suite *PrecompileTestSuite) TestCrossChain() { }, result: true, }, + { + name: "ok - address - origin token", + malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { + helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), + sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)))) + + balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom) + suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String()) + moduleName := ethtypes.ModuleName + + suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) + + data, err := crosschain.GetABI().Pack( + "crossChain", + common.HexToAddress(fxtypes.EmptyEvmAddress), + helpers.GenerateAddressByModule(moduleName), + randMint, + big.NewInt(0), + fxtypes.MustStrToByte32(moduleName), + "", + ) + suite.Require().NoError(err) + + pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) + suite.Require().True(found) + + return data, &pair, randMint, moduleName, nil + }, + result: true, + }, + { + name: "ok - address - origin erc20 token", + malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { + moduleName := ethtypes.ModuleName + denomAddr := helpers.GenerateAddress().String() + alias := fmt.Sprintf("%s%s", moduleName, denomAddr) + + suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, denomAddr, alias) + + token, err := suite.DeployContract(signer.Address()) + suite.Require().NoError(err) + + suite.MintERC20Token(signer, token, signer.Address(), randMint) + balOf := suite.BalanceOf(token, signer.Address()) + suite.Require().Equal(randMint.String(), balOf.String()) + + pair, err := suite.app.Erc20Keeper.RegisterNativeERC20(suite.ctx, token, alias) + suite.Require().NoError(err) + + suite.ERC20Approve(signer, token, crosschain.GetAddress(), randMint) + + data, err := crosschain.GetABI().Pack( + "crossChain", + pair.GetERC20Contract(), + helpers.GenerateAddressByModule(moduleName), + randMint, + big.NewInt(0), + fxtypes.MustStrToByte32(moduleName), + "", + ) + suite.Require().NoError(err) + + return data, pair, big.NewInt(0), moduleName, nil + }, + result: true, + }, + { + name: "ok - address - wrapper origin token", + malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { + pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) + suite.Require().True(found) + + moduleName := ethtypes.ModuleName + suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) + + coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)) + helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(coin)) + + balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom) + suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String()) + + _, err := suite.app.Erc20Keeper.ConvertCoin(sdk.WrapSDKContext(suite.ctx), &types.MsgConvertCoin{ + Coin: coin, + Receiver: signer.Address().Hex(), + Sender: signer.AccAddress().String(), + }) + suite.Require().NoError(err) + + suite.ERC20Approve(signer, pair.GetERC20Contract(), crosschain.GetAddress(), randMint) + + data, err := crosschain.GetABI().Pack( + "crossChain", + pair.GetERC20Contract(), + helpers.GenerateAddressByModule(moduleName), + randMint, + big.NewInt(0), + fxtypes.MustStrToByte32(moduleName), + "", + ) + suite.Require().NoError(err) + + return data, &pair, big.NewInt(0), moduleName, nil + }, + result: true, + }, { name: "ok - ibc token", malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { @@ -174,7 +279,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() { helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)))) - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) data, err := crosschain.GetABI().Pack( "crossChain", @@ -326,6 +431,72 @@ func (suite *PrecompileTestSuite) TestCrossChain() { }, result: true, }, + { + name: "contract - ok - origin token", + malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { + helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), + sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)))) + + moduleName := ethtypes.ModuleName + suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) + + data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack( + "crossChain", + common.HexToAddress(fxtypes.EmptyEvmAddress), + helpers.GenerateAddressByModule(moduleName), + randMint, + big.NewInt(0), + fxtypes.MustStrToByte32(moduleName), + "", + ) + suite.Require().NoError(err) + + pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) + suite.Require().True(found) + + return data, &pair, randMint, moduleName, nil + }, + result: true, + }, + { + name: "contract - ok - address - wrapper origin token", + malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { + pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) + suite.Require().True(found) + + moduleName := ethtypes.ModuleName + suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) + + coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)) + helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(coin)) + + balance := suite.app.BankKeeper.GetBalance(suite.ctx, signer.AccAddress(), fxtypes.DefaultDenom) + suite.Require().Equal(randMint.String(), balance.Amount.BigInt().String()) + + _, err := suite.app.Erc20Keeper.ConvertCoin(sdk.WrapSDKContext(suite.ctx), &types.MsgConvertCoin{ + Coin: coin, + Receiver: signer.Address().Hex(), + Sender: signer.AccAddress().String(), + }) + suite.Require().NoError(err) + + suite.ERC20Approve(signer, pair.GetERC20Contract(), suite.crosschain, randMint) + + data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack( + "crossChain", + pair.GetERC20Contract(), + helpers.GenerateAddressByModule(moduleName), + randMint, + big.NewInt(0), + fxtypes.MustStrToByte32(moduleName), + "", + ) + suite.Require().NoError(err) + + return data, &pair, big.NewInt(0), moduleName, nil + }, + result: true, + }, { name: "contract - ok - ibc token", malleate: func(_ *types.TokenPair, _ Metadata, signer *helpers.Signer, randMint *big.Int) ([]byte, *types.TokenPair, *big.Int, string, []string) { @@ -386,7 +557,7 @@ func (suite *PrecompileTestSuite) TestCrossChain() { helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress(), sdk.NewCoins(sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)))) - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) data, err := fxtypes.MustABIJson(testcontract.CrossChainTestMetaData.ABI).Pack( "crossChain", diff --git a/x/evm/precompiles/crosschain/fip20crosschain_test.go b/x/evm/precompiles/crosschain/fip20crosschain_test.go index 31f44a230..11d7dbed3 100644 --- a/x/evm/precompiles/crosschain/fip20crosschain_test.go +++ b/x/evm/precompiles/crosschain/fip20crosschain_test.go @@ -22,6 +22,7 @@ import ( bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" "github.com/functionx/fx-core/v6/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v6/x/eth/types" "github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain" ) @@ -78,7 +79,7 @@ func (suite *PrecompileTestSuite) TestFIP20CrossChain() { coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)) helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress().Bytes(), sdk.NewCoins(coin)) - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) fee := big.NewInt(1) @@ -710,7 +711,7 @@ func (suite *PrecompileTestSuite) TestFIP20CrossChainIBC() { coin := sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewIntFromBigInt(randMint)) helpers.AddTestAddr(suite.app, suite.ctx, signer.AccAddress().Bytes(), sdk.NewCoins(coin)) - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) fee := big.NewInt(1) diff --git a/x/evm/precompiles/crosschain/increase_bridgefee_test.go b/x/evm/precompiles/crosschain/increase_bridgefee_test.go index f219a78b5..c951c8af1 100644 --- a/x/evm/precompiles/crosschain/increase_bridgefee_test.go +++ b/x/evm/precompiles/crosschain/increase_bridgefee_test.go @@ -19,6 +19,7 @@ import ( bsctypes "github.com/functionx/fx-core/v6/x/bsc/types" crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" "github.com/functionx/fx-core/v6/x/erc20/types" + ethtypes "github.com/functionx/fx-core/v6/x/eth/types" "github.com/functionx/fx-core/v6/x/evm/precompiles/crosschain" ) @@ -154,7 +155,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() { { name: "ok - fip20 contract + evm token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) suite.Require().True(found) suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), pair.GetDenom()) @@ -174,7 +175,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() { { name: "ok - address + evm token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName suite.CrossChainKeepers()[moduleName].AddBridgeToken(suite.ctx, helpers.GenerateAddress().String(), fxtypes.DefaultDenom) @@ -225,7 +226,7 @@ func (suite *PrecompileTestSuite) TestIncreaseBridgeFee() { { name: "ok - address + wrapper origin token", prepare: func(_ *types.TokenPair, _ string, signer *helpers.Signer, randMint *big.Int) (*types.TokenPair, string, string) { - moduleName := bsctypes.ModuleName + moduleName := ethtypes.ModuleName pair, found := suite.app.Erc20Keeper.GetTokenPair(suite.ctx, fxtypes.DefaultDenom) suite.Require().True(found) diff --git a/x/gov/keeper/params.go b/x/gov/keeper/params.go index 00d8c8ff4..4460bf963 100644 --- a/x/gov/keeper/params.go +++ b/x/gov/keeper/params.go @@ -9,19 +9,6 @@ import ( "github.com/functionx/fx-core/v6/x/gov/types" ) -func (keeper Keeper) IterateParams(ctx sdk.Context, cb func(param *types.Params) (stop bool)) { - store := ctx.KVStore(keeper.storeKey) - iter := sdk.KVStorePrefixIterator(store, types.FxBaseParamsKeyPrefix) - defer iter.Close() - for ; iter.Valid(); iter.Next() { - var param types.Params - keeper.cdc.MustUnmarshal(iter.Value(), ¶m) - if cb(¶m) { - break - } - } -} - // GetParams gets the gov module's parameters. func (keeper Keeper) GetParams(ctx sdk.Context, msgType string) (params types.Params) { store := ctx.KVStore(keeper.storeKey) diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 080ed5203..9c6ad112a 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -24,7 +24,9 @@ func (keeper Keeper) SubmitProposal(ctx sdk.Context, messages []sdk.Msg, fxMetad return v1.Proposal{}, errortypes.ErrInvalidRequest.Wrapf("invalid fx metadata content: %s", err) } if err := keeper.AssertFXMetadata(fxMD); err != nil { - return v1.Proposal{}, err + if err != nil { + return v1.Proposal{}, err + } } // Will hold a comma-separated string of all Msg type URLs. diff --git a/x/gravity/keeper/msg_server.go b/x/gravity/keeper/msg_server.go index a7efe6643..e398c2978 100644 --- a/x/gravity/keeper/msg_server.go +++ b/x/gravity/keeper/msg_server.go @@ -11,7 +11,7 @@ import ( ) type msgServer struct { - crosschaintypes.MsgServer + crosschainkeeper.MsgServer } func NewMsgServerImpl(keeper crosschainkeeper.Keeper) types.MsgServer { diff --git a/x/layer2/client/cli/query.go b/x/layer2/client/cli/query.go deleted file mode 100644 index 78a35977b..000000000 --- a/x/layer2/client/cli/query.go +++ /dev/null @@ -1,21 +0,0 @@ -package cli - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/spf13/cobra" - - "github.com/functionx/fx-core/v6/x/crosschain/client/cli" - "github.com/functionx/fx-core/v6/x/layer2/types" -) - -func GetQueryCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Querying commands for the layer2 module", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - cmd.AddCommand(cli.GetQuerySubCmds(types.ModuleName)...) - return cmd -} diff --git a/x/layer2/client/cli/tx.go b/x/layer2/client/cli/tx.go deleted file mode 100644 index 06619c0a7..000000000 --- a/x/layer2/client/cli/tx.go +++ /dev/null @@ -1,21 +0,0 @@ -package cli - -import ( - "github.com/cosmos/cosmos-sdk/client" - "github.com/spf13/cobra" - - "github.com/functionx/fx-core/v6/x/crosschain/client/cli" - "github.com/functionx/fx-core/v6/x/layer2/types" -) - -func GetTxCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: types.ModuleName, - Short: "Layer2 transaction subcommands", - DisableFlagParsing: true, - SuggestionsMinimumDistance: 2, - RunE: client.ValidateCmd, - } - cmd.AddCommand(cli.GetTxSubCmds(types.ModuleName)...) - return cmd -} diff --git a/x/layer2/module.go b/x/layer2/module.go deleted file mode 100644 index d1a049cf1..000000000 --- a/x/layer2/module.go +++ /dev/null @@ -1,137 +0,0 @@ -package layer2 - -import ( - "encoding/json" - "fmt" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - codectypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - "github.com/gorilla/mux" - "github.com/grpc-ecosystem/grpc-gateway/runtime" - "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" - - crosschainkeeper "github.com/functionx/fx-core/v6/x/crosschain/keeper" - crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" - "github.com/functionx/fx-core/v6/x/layer2/client/cli" - "github.com/functionx/fx-core/v6/x/layer2/types" -) - -// type check to ensure the interface is properly implemented -var ( - _ module.AppModule = AppModule{} - _ module.AppModuleBasic = AppModuleBasic{} - _ module.EndBlockAppModule = AppModule{} -) - -// ---------------------------------------------------------------------------- -// AppModuleBasic -// ---------------------------------------------------------------------------- - -// AppModuleBasic object for module implementation -type AppModuleBasic struct{} - -// Name implements app module basic -func (AppModuleBasic) Name() string { return types.ModuleName } - -// DefaultGenesis implements app module basic -func (AppModuleBasic) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage { - return cdc.MustMarshalJSON(types.DefaultGenesisState()) -} - -// ValidateGenesis implements app module basic -func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingConfig, data json.RawMessage) error { - var state crosschaintypes.GenesisState - if err := cdc.UnmarshalJSON(data, &state); err != nil { - return fmt.Errorf("failed to unmarshal %s genesis state: %w", types.ModuleName, err) - } - return state.ValidateBasic() -} - -// RegisterLegacyAminoCodec implements app module basic -func (AppModuleBasic) RegisterLegacyAminoCodec(_ *codec.LegacyAmino) {} - -// RegisterRESTRoutes implements app module basic -func (AppModuleBasic) RegisterRESTRoutes(_ client.Context, _ *mux.Router) {} - -// RegisterGRPCGatewayRoutes registers the gRPC Gateway -func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} - -// GetQueryCmd implements app module basic -func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return cli.GetQueryCmd() -} - -// GetTxCmd implements app module basic -func (AppModuleBasic) GetTxCmd() *cobra.Command { - return cli.GetTxCmd() -} - -// RegisterInterfaces implements app bmodule basic -func (AppModuleBasic) RegisterInterfaces(_ codectypes.InterfaceRegistry) {} - -// ---------------------------------------------------------------------------- -// AppModule -// ---------------------------------------------------------------------------- - -// AppModule object for module implementation -type AppModule struct { - AppModuleBasic - keeper crosschainkeeper.Keeper -} - -// NewAppModule creates a new AppModule Object -func NewAppModule(keeper crosschainkeeper.Keeper) AppModule { - return AppModule{ - AppModuleBasic: AppModuleBasic{}, - keeper: keeper, - } -} - -// RegisterInvariants implements app module -func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {} - -// Deprecated: Route returns the message routing key -func (am AppModule) Route() sdk.Route { - return sdk.Route{} -} - -// QuerierRoute implements app module -func (am AppModule) QuerierRoute() string { return "" } - -// LegacyQuerierHandler returns no sdk.Querier -func (am AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { - return nil -} - -// RegisterServices registers module services. -func (am AppModule) RegisterServices(_ module.Configurator) {} - -// InitGenesis initializes the genesis state for this module and implements app module. -func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate { - var genesisState crosschaintypes.GenesisState - cdc.MustUnmarshalJSON(data, &genesisState) - - crosschainkeeper.InitGenesis(ctx, am.keeper, &genesisState) - return []abci.ValidatorUpdate{} -} - -// ExportGenesis exports the current genesis state to a json.RawMessage -func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.RawMessage { - state := crosschainkeeper.ExportGenesis(ctx, am.keeper) - return cdc.MustMarshalJSON(state) -} - -// ConsensusVersion implements AppModule/ConsensusVersion. -func (am AppModule) ConsensusVersion() uint64 { - return 1 -} - -// EndBlock implements app module -func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { - am.keeper.EndBlocker(ctx) - return []abci.ValidatorUpdate{} -} diff --git a/x/layer2/types/genesis.go b/x/layer2/types/genesis.go deleted file mode 100644 index a900c7dd3..000000000 --- a/x/layer2/types/genesis.go +++ /dev/null @@ -1,14 +0,0 @@ -package types - -import ( - crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" -) - -func DefaultGenesisState() *crosschaintypes.GenesisState { - params := crosschaintypes.DefaultParams() - params.GravityId = "fx-layer2-bridge" - params.AverageExternalBlockTime = 2_000 - return &crosschaintypes.GenesisState{ - Params: params, - } -} diff --git a/x/layer2/types/genesis_test.go b/x/layer2/types/genesis_test.go deleted file mode 100644 index 3cfab1d94..000000000 --- a/x/layer2/types/genesis_test.go +++ /dev/null @@ -1,44 +0,0 @@ -package types - -import ( - "reflect" - "testing" - - sdkmath "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - - fxtypes "github.com/functionx/fx-core/v6/types" - crosschaintypes "github.com/functionx/fx-core/v6/x/crosschain/types" -) - -func TestDefaultGenesisState(t *testing.T) { - tests := []struct { - name string - want *crosschaintypes.GenesisState - }{ - { - name: "layer2 default genesis", - want: &crosschaintypes.GenesisState{ - Params: crosschaintypes.Params{ - GravityId: "fx-layer2-bridge", - AverageBlockTime: 7_000, - AverageExternalBlockTime: 2_000, - ExternalBatchTimeout: 12 * 3600 * 1000, - SignedWindow: 30_000, - SlashFraction: sdk.NewDec(8).Quo(sdk.NewDec(10)), - OracleSetUpdatePowerChangePercent: sdk.NewDec(1).Quo(sdk.NewDec(10)), - IbcTransferTimeoutHeight: 20_000, - DelegateThreshold: sdk.NewCoin(fxtypes.DefaultDenom, sdkmath.NewInt(10_000).MulRaw(1e18)), - DelegateMultiple: 10, - }, - }, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := DefaultGenesisState(); !reflect.DeepEqual(got, tt.want) { - t.Errorf("DefaultGenesisState() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/x/layer2/types/key.go b/x/layer2/types/key.go deleted file mode 100644 index 2d32ea032..000000000 --- a/x/layer2/types/key.go +++ /dev/null @@ -1,9 +0,0 @@ -package types - -const ( - // ModuleName is the name of the module - ModuleName = "layer2" - - // StoreKey to be used when creating the KVStore - StoreKey = ModuleName -) diff --git a/x/staking/keeper/abci.go b/x/staking/keeper/abci.go index 36625bf78..9df611abd 100644 --- a/x/staking/keeper/abci.go +++ b/x/staking/keeper/abci.go @@ -18,14 +18,6 @@ import ( ) func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { - if ctx.BlockHeight()%2000 == 0 && len(ctx.VoteInfos()) > 5 { - params := k.GetParams(ctx) - params.MaxValidators = params.MaxValidators - 1 - if params.MaxValidators >= 5 { - k.SetParams(ctx, params) - } - } - // staking EndBlocker valUpdates := staking.EndBlocker(ctx, k.Keeper) diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index c796dd194..120320577 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -11,7 +11,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/functionx/fx-core/v6/x/staking/types" @@ -211,43 +210,3 @@ func (k Keeper) iteratorEditValidator(ctx sdk.Context, validator stakingtypes.Va } return nil } - -type msgServer struct { - stakingtypes.MsgServer -} - -func NewMsgServerImpl(keeper Keeper) stakingtypes.MsgServer { - return &msgServer{MsgServer: stakingkeeper.NewMsgServerImpl(keeper.Keeper)} -} - -func (k msgServer) CreateValidator(goCtx context.Context, msg *stakingtypes.MsgCreateValidator) (*stakingtypes.MsgCreateValidatorResponse, error) { - if sdk.UnwrapSDKContext(goCtx).BlockHeight() > 1e7 { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unsupported method") - } - return k.MsgServer.CreateValidator(goCtx, msg) -} - -func (k msgServer) Delegate(goCtx context.Context, msg *stakingtypes.MsgDelegate) (*stakingtypes.MsgDelegateResponse, error) { - delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress) - if err != nil { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) - } - - valAddress, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) - if err != nil { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidAddress, err.Error()) - } - - if !delegatorAddress.Equals(valAddress) { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "only support self delegation") - } - - return k.MsgServer.Delegate(goCtx, msg) -} - -func (k msgServer) BeginRedelegate(goCtx context.Context, msg *stakingtypes.MsgBeginRedelegate) (*stakingtypes.MsgBeginRedelegateResponse, error) { - if sdk.UnwrapSDKContext(goCtx).BlockHeight() > 1e7 { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "unsupported method") - } - return k.MsgServer.BeginRedelegate(goCtx, msg) -} diff --git a/x/staking/module.go b/x/staking/module.go index 7b6c290d4..f1bcfa7f0 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -10,7 +10,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/staking" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" "github.com/spf13/cobra" abci "github.com/tendermint/tendermint/abci/types" @@ -78,8 +77,7 @@ func NewAppModule(cdc codec.Codec, keeper keeper.Keeper, ak stakingtypes.Account func (am AppModule) RegisterServices(cfg module.Configurator) { fxstakingtypes.RegisterMsgServer(cfg.MsgServer(), am.Keeper) - stakingtypes.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.Keeper)) - stakingtypes.RegisterQueryServer(cfg.QueryServer(), stakingkeeper.Querier{Keeper: am.Keeper.Keeper}) + am.AppModule.RegisterServices(cfg) } // EndBlock returns the end blocker for the staking module. It returns no validator