From 40d19c6433e7bcfac988320306fa3cfb1c06b041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 1 Jul 2024 13:39:58 +0200 Subject: [PATCH 01/71] Add call ethereumXcm.forceTransactAs (to create contracts from runtime) --- Cargo.lock | 90 +++++++++---------- Cargo.toml | 79 ++++++++-------- pallets/ethereum-xcm/src/lib.rs | 46 +++++++++- primitives/xcm/src/ethereum_xcm.rs | 39 +++++--- runtime/common/src/impl_xcm_evm_runner.rs | 19 ++++ runtime/moonbase/src/lib.rs | 1 + runtime/moonbase/tests/xcm_mock/parachain.rs | 1 + runtime/moonbeam/src/lib.rs | 1 + runtime/moonbeam/tests/xcm_mock/parachain.rs | 1 + runtime/moonriver/src/lib.rs | 1 + runtime/moonriver/tests/xcm_mock/parachain.rs | 1 + 11 files changed, 180 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e444ee0a26..81801e237a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,7 +634,7 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-backing-primitives" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "sp-api", "sp-consensus-slots", @@ -3212,7 +3212,7 @@ dependencies = [ [[package]] name = "evm" version = "0.41.1" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#2252d2475749be22f3b3ae1926fcd02959783f40" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#5ebf882aa99ba449ecf01ba3c29a00ab05cffb17" dependencies = [ "auto_impl", "environmental", @@ -3232,7 +3232,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#2252d2475749be22f3b3ae1926fcd02959783f40" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#5ebf882aa99ba449ecf01ba3c29a00ab05cffb17" dependencies = [ "parity-scale-codec", "primitive-types", @@ -3243,7 +3243,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#2252d2475749be22f3b3ae1926fcd02959783f40" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#5ebf882aa99ba449ecf01ba3c29a00ab05cffb17" dependencies = [ "environmental", "evm-core", @@ -3254,7 +3254,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.41.0" -source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#2252d2475749be22f3b3ae1926fcd02959783f40" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.11.0#5ebf882aa99ba449ecf01ba3c29a00ab05cffb17" dependencies = [ "auto_impl", "environmental", @@ -3372,7 +3372,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "async-trait", "fp-storage", @@ -3384,7 +3384,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "async-trait", "fp-consensus", @@ -3400,7 +3400,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "async-trait", "ethereum", @@ -3430,7 +3430,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fc-db", "fc-storage", @@ -3453,7 +3453,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "ethereum-types", @@ -3507,7 +3507,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "ethereum-types", @@ -3522,7 +3522,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "ethereum-types", @@ -3716,7 +3716,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "hex", "impl-serde 0.4.0", @@ -3734,7 +3734,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "parity-scale-codec", @@ -3745,7 +3745,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "ethereum-types", @@ -3757,7 +3757,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "evm", "frame-support", @@ -3772,7 +3772,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "ethereum", "ethereum-types", @@ -3788,7 +3788,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "frame-support", "parity-scale-codec", @@ -3800,7 +3800,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "parity-scale-codec", "serde", @@ -7625,7 +7625,7 @@ dependencies = [ [[package]] name = "nimbus-consensus" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "async-backing-primitives", "async-trait", @@ -7665,7 +7665,7 @@ dependencies = [ [[package]] name = "nimbus-primitives" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "async-trait", "frame-benchmarking", @@ -8229,7 +8229,7 @@ dependencies = [ [[package]] name = "pallet-async-backing" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8249,7 +8249,7 @@ dependencies = [ [[package]] name = "pallet-author-inherent" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "frame-benchmarking", "frame-support", @@ -8268,7 +8268,7 @@ dependencies = [ [[package]] name = "pallet-author-mapping" version = "2.0.5" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "frame-benchmarking", "frame-support", @@ -8287,7 +8287,7 @@ dependencies = [ [[package]] name = "pallet-author-slot-filter" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "frame-benchmarking", "frame-support", @@ -8648,7 +8648,7 @@ dependencies = [ [[package]] name = "pallet-emergency-para-xcm" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8691,7 +8691,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "environmental", "ethereum", @@ -8746,7 +8746,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "environmental", "evm", @@ -8771,7 +8771,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "frame-support", "frame-system", @@ -8866,7 +8866,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", ] @@ -8874,7 +8874,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "sp-core", @@ -9006,7 +9006,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "frame-support", @@ -9083,7 +9083,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "num", @@ -9318,7 +9318,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "tiny-keccak", @@ -9327,7 +9327,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "ripemd", @@ -9337,7 +9337,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-storage-cleaner" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "fp-evm", "frame-support", @@ -9352,7 +9352,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-xcm" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "cumulus-primitives-core", "evm", @@ -9604,7 +9604,7 @@ dependencies = [ [[package]] name = "pallet-maintenance-mode" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -9657,7 +9657,7 @@ dependencies = [ [[package]] name = "pallet-migrations" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "frame-benchmarking", "frame-support", @@ -9963,7 +9963,7 @@ dependencies = [ [[package]] name = "pallet-randomness" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "environmental", "frame-benchmarking", @@ -10041,7 +10041,7 @@ dependencies = [ [[package]] name = "pallet-relay-storage-roots" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -12034,7 +12034,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "derive_more", "environmental", @@ -12063,7 +12063,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#fc64fd20c256bcd7ac328750087f7ae00713c585" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" dependencies = [ "case", "num_enum 0.7.2", @@ -14776,7 +14776,7 @@ dependencies = [ [[package]] name = "session-keys-primitives" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "async-trait", "frame-support", @@ -18512,7 +18512,7 @@ dependencies = [ [[package]] name = "xcm-primitives" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" dependencies = [ "frame-support", "impl-trait-for-tuples", diff --git a/Cargo.toml b/Cargo.toml index 5e0c20fbb0..b61f9743bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -235,40 +235,39 @@ ethereum-types = { version = "0.14", default-features = false } evm = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } evm-gasometer = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } evm-runtime = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false, features = [ +fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false, features = [ "forbid-evm-reentrancy", ] } -pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false, features = [ +pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false, features = [ "forbid-evm-reentrancy", ] } -pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-bn128 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-dispatch = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-bn128 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -precompile-utils = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +precompile-utils = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } # Frontier (client) - -fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fc-db = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fc-api = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fc-mapping-sync = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fc-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", features = [ +fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-db = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-api = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-mapping-sync = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", features = [ "rpc-binary-search-estimate", ] } -fc-rpc-core = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fc-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fp-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } -fp-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-rpc-core = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fp-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fp-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } # Cumulus (wasm) @@ -326,23 +325,23 @@ westend-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", xcm-simulator = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" } # Moonkit (wasm) -async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } # Moonkit (client) -nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0" } +nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets" } # Other (wasm) async-trait = { version = "0.1.42" } diff --git a/pallets/ethereum-xcm/src/lib.rs b/pallets/ethereum-xcm/src/lib.rs index a5f20747f5..67b971e4c9 100644 --- a/pallets/ethereum-xcm/src/lib.rs +++ b/pallets/ethereum-xcm/src/lib.rs @@ -104,6 +104,8 @@ pub mod pallet { type EnsureProxy: EnsureProxy; /// The origin that is allowed to resume or suspend the XCM to Ethereum executions. type ControllerOrigin: EnsureOrigin; + /// An origin that can submit a create tx typenb + type ForceOrigin: EnsureOrigin; } #[pallet::pallet] @@ -160,7 +162,7 @@ pub mod pallet { } } ); - Self::validate_and_apply(source, xcm_transaction) + Self::validate_and_apply(source, xcm_transaction, false, None) } /// Xcm Transact an Ethereum transaction through proxy. @@ -202,7 +204,7 @@ pub mod pallet { error: sp_runtime::DispatchError::Other(e), })?; - Self::validate_and_apply(transact_as, xcm_transaction) + Self::validate_and_apply(transact_as, xcm_transaction, false, None) } /// Suspends all Ethereum executions from XCM. @@ -228,6 +230,39 @@ pub mod pallet { Ok(()) } + + /// Xcm Transact an Ethereum transaction, but allow to force the caller and create address. + /// This call should be restricted (callable only by the runtime or governance). + /// Weight: Gas limit plus the db reads involving the suspension and proxy checks + #[pallet::weight({ + let without_base_extrinsic_weight = false; + ::GasWeightMapping::gas_to_weight({ + match xcm_transaction { + EthereumXcmTransaction::V1(v1_tx) => v1_tx.gas_limit.unique_saturated_into(), + EthereumXcmTransaction::V2(v2_tx) => v2_tx.gas_limit.unique_saturated_into() + } + }, without_base_extrinsic_weight).saturating_add(T::DbWeight::get().reads(2)) + })] + pub fn force_transact_as( + origin: OriginFor, + transact_as: H160, + xcm_transaction: EthereumXcmTransaction, + force_create_address: Option, + ) -> DispatchResultWithPostInfo { + T::ForceOrigin::ensure_origin(origin)?; + ensure!( + !EthereumXcmSuspended::::get(), + DispatchErrorWithPostInfo { + error: Error::::EthereumXcmExecutionSuspended.into(), + post_info: PostDispatchInfo { + actual_weight: Some(T::DbWeight::get().reads(1)), + pays_fee: Pays::Yes + } + } + ); + + Self::validate_and_apply(transact_as, xcm_transaction, true, force_create_address) + } } } @@ -243,6 +278,8 @@ impl Pallet { fn validate_and_apply( source: H160, xcm_transaction: EthereumXcmTransaction, + allow_create: bool, + maybe_force_create_address: Option, ) -> DispatchResultWithPostInfo { // The lack of a real signature where different callers with the // same nonce are providing identical transaction payloads results in a collision and @@ -253,7 +290,7 @@ impl Pallet { let error_weight = T::DbWeight::get().reads(1); let transaction: Option = - xcm_transaction.into_transaction_v2(current_nonce, T::ChainId::get()); + xcm_transaction.into_transaction_v2(current_nonce, T::ChainId::get(), allow_create); if let Some(transaction) = transaction { let transaction_data: TransactionData = (&transaction).into(); @@ -300,7 +337,8 @@ impl Pallet { // transaction on chain - we increase the global nonce. >::put(current_nonce.saturating_add(U256::one())); - let (dispatch_info, _) = T::ValidatedTransaction::apply(source, transaction)?; + let (dispatch_info, _) = + T::ValidatedTransaction::apply(source, transaction, maybe_force_create_address)?; Ok(dispatch_info) } else { Err(sp_runtime::DispatchErrorWithPostInfo { diff --git a/primitives/xcm/src/ethereum_xcm.rs b/primitives/xcm/src/ethereum_xcm.rs index 8aee89c34a..3ead0685e4 100644 --- a/primitives/xcm/src/ethereum_xcm.rs +++ b/primitives/xcm/src/ethereum_xcm.rs @@ -79,7 +79,7 @@ pub struct EthereumXcmTransactionV1 { pub gas_limit: U256, /// Fee configuration of choice. pub fee_payment: EthereumXcmFee, - /// Either a Call (the callee, account or contract address) or Create (currently unsupported). + /// Either a Call (the callee, account or contract address) or Create (unsupported for v1). pub action: TransactionAction, /// Value to be transfered. pub value: U256, @@ -93,7 +93,7 @@ pub struct EthereumXcmTransactionV1 { pub struct EthereumXcmTransactionV2 { /// Gas limit to be consumed by EVM execution. pub gas_limit: U256, - /// Either a Call (the callee, account or contract address) or Create (currently unsupported). + /// Either a Call (the callee, account or contract address) or Create). pub action: TransactionAction, /// Value to be transfered. pub value: U256, @@ -104,20 +104,34 @@ pub struct EthereumXcmTransactionV2 { } pub trait XcmToEthereum { - fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option; + fn into_transaction_v2( + &self, + nonce: U256, + chain_id: u64, + allow_create: bool, + ) -> Option; } impl XcmToEthereum for EthereumXcmTransaction { - fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option { + fn into_transaction_v2( + &self, + nonce: U256, + chain_id: u64, + allow_create: bool, + ) -> Option { match self { - EthereumXcmTransaction::V1(v1_tx) => v1_tx.into_transaction_v2(nonce, chain_id), - EthereumXcmTransaction::V2(v2_tx) => v2_tx.into_transaction_v2(nonce, chain_id), + EthereumXcmTransaction::V1(v1_tx) => { + v1_tx.into_transaction_v2(nonce, chain_id, allow_create) + } + EthereumXcmTransaction::V2(v2_tx) => { + v2_tx.into_transaction_v2(nonce, chain_id, allow_create) + } } } } impl XcmToEthereum for EthereumXcmTransactionV1 { - fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option { + fn into_transaction_v2(&self, nonce: U256, chain_id: u64, _: bool) -> Option { // We dont support creates for now if self.action == TransactionAction::Create { return None; @@ -195,9 +209,14 @@ impl XcmToEthereum for EthereumXcmTransactionV1 { } impl XcmToEthereum for EthereumXcmTransactionV2 { - fn into_transaction_v2(&self, nonce: U256, chain_id: u64) -> Option { - // We dont support creates for now - if self.action == TransactionAction::Create { + fn into_transaction_v2( + &self, + nonce: U256, + chain_id: u64, + allow_create: bool, + ) -> Option { + if !allow_create && self.action == TransactionAction::Create { + // Create not allowed return None; } let from_tuple_to_access_list = |t: &Vec<(H160, Vec)>| -> AccessList { diff --git a/runtime/common/src/impl_xcm_evm_runner.rs b/runtime/common/src/impl_xcm_evm_runner.rs index 7eebe42d63..b71018a0ef 100644 --- a/runtime/common/src/impl_xcm_evm_runner.rs +++ b/runtime/common/src/impl_xcm_evm_runner.rs @@ -165,6 +165,25 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { unimplemented!() } + fn create_force_address( + _source: H160, + _init: Vec, + _value: U256, + _gas_limit: u64, + _max_fee_per_gas: Option, + _max_priority_fee_per_gas: Option, + _nonce: Option, + _access_list: Vec<(H160, Vec)>, + _is_transactional: bool, + _validate: bool, + _weight_limit: Option, + _transaction_len: Option, + _config: &fp_evm::Config, + _force_address: H160, + ) -> Result> { + unimplemented!() + } + fn validate( _source: H160, _target: Option, diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 25a6fd1049..ec18751f1f 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -732,6 +732,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } parameter_types! { diff --git a/runtime/moonbase/tests/xcm_mock/parachain.rs b/runtime/moonbase/tests/xcm_mock/parachain.rs index 732352952f..56271b1502 100644 --- a/runtime/moonbase/tests/xcm_mock/parachain.rs +++ b/runtime/moonbase/tests/xcm_mock/parachain.rs @@ -1058,6 +1058,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } type Block = frame_system::mocking::MockBlockU32; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 9d9c9c44f1..4a3ec5aaad 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -742,6 +742,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } parameter_types! { diff --git a/runtime/moonbeam/tests/xcm_mock/parachain.rs b/runtime/moonbeam/tests/xcm_mock/parachain.rs index 82d9ef7117..05ddbeef41 100644 --- a/runtime/moonbeam/tests/xcm_mock/parachain.rs +++ b/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -1043,6 +1043,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } type Block = frame_system::mocking::MockBlockU32; diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 73fb75ea42..1d91f33bee 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -716,6 +716,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } parameter_types! { diff --git a/runtime/moonriver/tests/xcm_mock/parachain.rs b/runtime/moonriver/tests/xcm_mock/parachain.rs index f2b3f920c9..5c567c2f3a 100644 --- a/runtime/moonriver/tests/xcm_mock/parachain.rs +++ b/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -1049,6 +1049,7 @@ impl pallet_ethereum_xcm::Config for Runtime { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } type Block = frame_system::mocking::MockBlockU32; From 7a6eac577e5099a32bb8b07da579f7a99eff3b14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 13 Jul 2024 18:48:38 +0200 Subject: [PATCH 02/71] add pallet-moonbeam-foreign-assets skeleton --- Cargo.lock | 25 ++ Cargo.toml | 5 +- pallets/moonbeam-foreign-assets/Cargo.toml | 56 +++ .../moonbeam-foreign-assets/src/benchmarks.rs | 173 +++++++++ pallets/moonbeam-foreign-assets/src/lib.rs | 355 ++++++++++++++++++ pallets/moonbeam-foreign-assets/src/mock.rs | 263 +++++++++++++ pallets/moonbeam-foreign-assets/src/tests.rs | 247 ++++++++++++ .../moonbeam-foreign-assets/src/weights.rs | 181 +++++++++ runtime/common/src/impl_xcm_evm_runner.rs | 65 +++- 9 files changed, 1353 insertions(+), 17 deletions(-) create mode 100644 pallets/moonbeam-foreign-assets/Cargo.toml create mode 100644 pallets/moonbeam-foreign-assets/src/benchmarks.rs create mode 100644 pallets/moonbeam-foreign-assets/src/lib.rs create mode 100644 pallets/moonbeam-foreign-assets/src/mock.rs create mode 100644 pallets/moonbeam-foreign-assets/src/tests.rs create mode 100644 pallets/moonbeam-foreign-assets/src/weights.rs diff --git a/Cargo.lock b/Cargo.lock index 81801e237a..7a4937dcb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9691,6 +9691,31 @@ dependencies = [ "sp-std", ] +[[package]] +name = "pallet-moonbeam-foreign-assets" +version = "0.1.0" +dependencies = [ + "environmental", + "ethereum-types", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "pallet-moonbeam-lazy-migrations" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index b61f9743bf..092cf8acef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ members = [ "pallets/asset-manager", "pallets/erc20-xcm-bridge", "pallets/ethereum-xcm", + "pallets/moonbeam-foreign-assets", "pallets/moonbeam-lazy-migrations", "pallets/moonbeam-orbiters", "pallets/moonbeam-xcm-benchmarks", @@ -74,9 +75,9 @@ moonbeam-xcm-benchmarks = { path = "pallets/moonbeam-xcm-benchmarks", default-fe pallet-asset-manager = { path = "pallets/asset-manager", default-features = false } pallet-erc20-xcm-bridge = { path = "pallets/erc20-xcm-bridge", default-features = false } pallet-ethereum-xcm = { path = "pallets/ethereum-xcm", default-features = false } - - +pallet-moonbeam-foreign-assets = { path = "pallets/moonbeam-foreign-assets", default-features = false } pallet-moonbeam-lazy-migrations = { path = "pallets/moonbeam-lazy-migrations", default-features = false } + pallet-evm-precompile-author-mapping = { path = "precompiles/author-mapping", default-features = false } pallet-evm-precompile-balances-erc20 = { path = "precompiles/balances-erc20", default-features = false } pallet-evm-precompile-batch = { path = "precompiles/batch", default-features = false } diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml new file mode 100644 index 0000000000..067b32e9cb --- /dev/null +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -0,0 +1,56 @@ +[package] +name = "pallet-moonbeam-foreign-assets" +authors = { workspace = true } +edition = "2021" +version = "0.1.0" + +[dependencies] +environmental = { workspace = true } +ethereum-types = { workspace = true } +log = { workspace = true } +serde = { workspace = true, optional = true } + +# Substrate +frame-support = { workspace = true } +frame-system = { workspace = true } +parity-scale-codec = { workspace = true, features = [ "derive" ] } +scale-info = { workspace = true, features = [ "derive" ] } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } + +# Polkadot +xcm = { workspace = true, optional = true } +xcm-executor = { workspace = true, optional = true } + +# Benchmarks +frame-benchmarking = { workspace = true, optional = true } + +[dev-dependencies] +pallet-balances = { workspace = true, features = [ "std" ] } +pallet-assets = { workspace = true, features = [ "std" ] } +sp-core = { workspace = true, features = [ "std" ] } + +[features] +default = [ "std" ] +std = [ + "frame-benchmarking/std", + "frame-support/std", + "frame-system/std", + "pallet-evm/std", + "parity-scale-codec/std", + "scale-info/std", + "serde", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "xcm/std", + "xcm-executor/std" +] + +runtime-benchmarks = [ "frame-benchmarking", "xcm"] +try-runtime = [ "frame-support/try-runtime" ] diff --git a/pallets/moonbeam-foreign-assets/src/benchmarks.rs b/pallets/moonbeam-foreign-assets/src/benchmarks.rs new file mode 100644 index 0000000000..c916c3391f --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/benchmarks.rs @@ -0,0 +1,173 @@ +// Copyright Moonsong Labs +// This file is part of Moonkit. + +// Moonkit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonkit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonkit. If not, see . + +#![cfg(feature = "runtime-benchmarks")] + +use crate::{AssetBalance, AssetId, Call, Config, Pallet}; +use frame_benchmarking::{ + account, benchmarks, impl_benchmark_test_suite, whitelisted_caller, BenchmarkError, +}; +use frame_support::traits::{fungibles, fungibles::Mutate, EnsureOrigin}; +use frame_system::RawOrigin; +use sp_arithmetic::traits::AtLeast16BitUnsigned; +use xcm::latest::prelude::*; + +#[allow(dead_code)] +pub fn create_default_minted_asset( + amount: AssetBalance, + receiver: T::AccountId, +) -> (AssetId, T::ForeignAsset) +where + T::ForeignAsset: From, + T::Fungibles: fungibles::Mutate, + AssetId: AtLeast16BitUnsigned, +{ + let (asset_id, foreign_asset) = create_default_asset::(true); + + assert!(T::Fungibles::mint_into(asset_id.clone(), &receiver, amount).is_ok()); + (asset_id, foreign_asset) +} + +#[allow(dead_code)] +fn create_default_asset(is_sufficient: bool) -> (AssetId, T::ForeignAsset) +where + T::ForeignAsset: From, + AssetId: AtLeast16BitUnsigned, +{ + let asset_id: AssetId = 1u16.into(); + let foreign_asset: T::ForeignAsset = Location::parent().into(); + let admin: T::AccountId = whitelisted_caller(); + let origin = T::ForeignAssetCreatorOrigin::try_successful_origin() + .map_err(|_| BenchmarkError::Weightless) + .expect("Not able to generate an appropriate origin to disptach the call"); + assert!(Pallet::::create_foreign_asset( + origin, + foreign_asset.clone(), + asset_id.clone(), + admin, + is_sufficient, + 1u32.into(), + ) + .is_ok()); + (asset_id, foreign_asset) +} + +benchmarks! { + // This where clause allows us to create ForeignAssetTypes + where_clause { where T::ForeignAsset: From, AssetId: AtLeast16BitUnsigned } + create_foreign_asset { + const USER_SEED: u32 = 1; + let manager = account("manager", 0, USER_SEED); + let foreign_asset = T::ForeignAsset::default(); + let amount = 1u32.into(); + let asset_id: AssetId = 1u16.into(); + + }: _(RawOrigin::Root, foreign_asset.clone(), asset_id.clone(), manager, true, amount) + verify { + assert_eq!(Pallet::::foreign_asset_for_id(asset_id), Some(foreign_asset)); + } + + change_existing_asset_type { + const USER_SEED: u32 = 1; + let manager: T::AccountId = account("manager", 0, USER_SEED); + + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); + let asset_id: AssetId = (0u16).into(); + let amount = 1u32.into(); + Pallet::::create_foreign_asset( + RawOrigin::Root.into(), + foreign_asset.clone(), + asset_id.clone(), + manager.clone(), + true, + amount, + )?; + + let new_foreign_asset = T::ForeignAsset::default(); + let asset_type_to_be_changed: T::ForeignAsset = Location::new( + 0, + [GeneralIndex((0) as u128)] + ).into(); + let asset_id_to_be_changed: AssetId = (0u16).into(); + }: _(RawOrigin::Root, asset_id_to_be_changed.clone(), new_foreign_asset.clone()) + verify { + assert_eq!(Pallet::::foreign_asset_for_id(asset_id_to_be_changed), Some(new_foreign_asset.clone())); + } + + remove_existing_asset_type { + const USER_SEED: u32 = 1; + let manager: T::AccountId = account("manager", 0, USER_SEED); + + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); + let asset_id: AssetId = 0u16.into(); + let amount = 1u32.into(); + Pallet::::create_foreign_asset( + RawOrigin::Root.into(), + foreign_asset.clone(), + asset_id.clone(), + manager.clone(), + true, + amount, + )?; + + let asset_id_to_be_removed: AssetId = 0u16.into(); + }: _(RawOrigin::Root, asset_id_to_be_removed.clone()) + verify { + assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_removed).is_none()); + } + + destroy_foreign_asset { + const USER_SEED: u32 = 1; + let manager: T::AccountId = account("manager", 0, USER_SEED); + + let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); + let asset_id: AssetId = 0u16.into(); + let amount = 1u32.into(); + Pallet::::create_foreign_asset( + RawOrigin::Root.into(), + foreign_asset.clone(), + asset_id.clone(), + manager.clone(), + true, + amount, + )?; + + let asset_id_to_be_destroyed: AssetId = 0u16.into(); + }: _(RawOrigin::Root, asset_id_to_be_destroyed.clone()) + verify { + assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_destroyed).is_none()); + } +} + +#[cfg(test)] +mod tests { + use crate::mock::Test; + use sp_io::TestExternalities; + use sp_runtime::BuildStorage; + + pub fn new_test_ext() -> TestExternalities { + let t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + TestExternalities::new(t) + } +} + +impl_benchmark_test_suite!( + Pallet, + crate::benchmarks::tests::new_test_ext(), + crate::mock::Test +); diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs new file mode 100644 index 0000000000..11596f061b --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -0,0 +1,355 @@ +// Copyright Moonsong Labs +// This file is part of Moonkit. + +// Moonkit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonkit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonkit. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +pub use pallet::*; +pub use weights::WeightInfo; + +use frame_support::pallet; + +#[cfg(any(test, feature = "runtime-benchmarks"))] +pub mod benchmarks; +#[cfg(test)] +pub mod mock; +#[cfg(test)] +pub mod tests; +pub mod weights; + +/// Trait for the OnForeignAssetRegistered hook +pub trait ForeignAssetCreatedHook { + fn on_asset_created( + foreign_asset: &ForeignAsset, + asset_id: &AssetId, + min_balance: &AssetBalance, + ); +} + +impl + ForeignAssetCreatedHook for () +{ + fn on_asset_created( + _foreign_asset: &ForeignAsset, + _asset_id: &AssetId, + _min_balance: &AssetBalance, + ) { + } +} + +/// Trait for the OnForeignAssetDeregistered hook +pub trait ForeignAssetDestroyedHook { + fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId); +} + +impl ForeignAssetDestroyedHook for () { + fn on_asset_destroyed(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} +} + +#[pallet] +pub mod pallet { + use super::*; + use ethereum_types::{H160, U256}; + use fp_evm::{ExitReason, ExitSucceed}; + use frame_support::{ + pallet_prelude::*, + traits::{ + fungibles::Destroy, + tokens::fungibles, + }, + }; + use frame_system::pallet_prelude::*; + use pallet_evm::{GasWeightMapping, Runner}; + use sp_runtime::traits::{Dispatchable, MaybeEquivalence}; + + const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 8192; + const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0x00, 0x00, 0x00, 0x00]; + const FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT: u64 = 500_000; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(PhantomData); + + #[pallet::config] + pub trait Config: frame_system::Config + pallet_evm::Config { + /// EVM runner + type EvmRunner: Runner; + + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// The Foreign Asset Kind. + type ForeignAsset: Parameter + Member + Ord + PartialOrd + Default; + + /// Origin that is allowed to create and modify asset information for foreign assets + type ForeignAssetCreatorOrigin: EnsureOrigin; + + /// Origin that is allowed to create and modify asset information for foreign assets + type ForeignAssetModifierOrigin: EnsureOrigin; + + /// Origin that is allowed to create and modify asset information for foreign assets + type ForeignAssetDestroyerOrigin: EnsureOrigin; + + type Fungibles: fungibles::Create + + fungibles::Destroy + + fungibles::Inspect; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; + + /// Hook to be called when new foreign asset is registered. + type OnForeignAssetCreated: ForeignAssetCreatedHook< + Self::ForeignAsset, + AssetId, + AssetBalance, + >; + + /// Hook to be called when foreign asset is de-registered. + type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; + } + + pub type AssetBalance = U256; + pub type AssetId = u128; + + /// An error that can occur while executing the mapping pallet's logic. + #[pallet::error] + pub enum Error { + AssetAlreadyExists, + AssetDoesNotExist, + Erc20ContractCreationFail, + } + + #[pallet::event] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] + pub enum Event { + /// New asset with the asset manager is registered + ForeignAssetCreated { + asset_id: AssetId, + foreign_asset: T::ForeignAsset, + }, + /// Changed the xcm type mapping for a given asset id + ForeignAssetTypeChanged { + asset_id: AssetId, + new_foreign_asset: T::ForeignAsset, + }, + /// Removed all information related to an assetId + ForeignAssetRemoved { + asset_id: AssetId, + foreign_asset: T::ForeignAsset, + }, + /// Removed all information related to an assetId and destroyed asset + ForeignAssetDestroyed { + asset_id: AssetId, + foreign_asset: T::ForeignAsset, + }, + } + + /// Mapping from an asset id to a Foreign asset type. + /// This is mostly used when receiving transaction specifying an asset directly, + /// like transferring an asset from this chain to another. + #[pallet::storage] + #[pallet::getter(fn foreign_asset_for_id)] + pub type AssetIdToForeignAsset = + StorageMap<_, Blake2_128Concat, AssetId, T::ForeignAsset>; + + /// Reverse mapping of AssetIdToForeignAsset. Mapping from a foreign asset to an asset id. + /// This is mostly used when receiving a multilocation XCM message to retrieve + /// the corresponding asset in which tokens should me minted. + #[pallet::storage] + #[pallet::getter(fn asset_id_for_foreign)] + pub type ForeignAssetToAssetId = + StorageMap<_, Blake2_128Concat, T::ForeignAsset, AssetId>; + + impl Pallet { + /// Deploy foreign asset erc20 contract + fn create_erc20_contract( + asset_id: AssetId, + admin: H160, + min_balance: AssetBalance, + ) -> Result<(), Error> { + // TODO generate init code + let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); + + // Compute contract address + let mut buffer = [0u8; 20]; + buffer[..4].copy_from_slice(&FOREIGN_ASSETS_PREFIX); + buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); + let contract_address = H160(buffer); + + let exec_info = T::EvmRunner::create_force_address( + admin, + init, + U256::default(), + FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT, + None, + None, + None, + Default::default(), + true, + false, + None, + None, + &::config(), + contract_address, + ) + .map_err(|_| Error::Erc20ContractCreationFail)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + Error::Erc20ContractCreationFail + ); + + Ok(()) + } + + fn start_destroy(asset_id: AssetId) -> Result<(), Error> { + todo!() + } + } + + #[pallet::call] + impl Pallet { + /// Create new asset with the ForeignAssetCreator + #[pallet::call_index(0)] + #[pallet::weight(::WeightInfo::create_foreign_asset())] + pub fn create_foreign_asset( + origin: OriginFor, + foreign_asset: T::ForeignAsset, + asset_id: AssetId, + admin: H160, + min_balance: AssetBalance, + ) -> DispatchResult { + T::ForeignAssetCreatorOrigin::ensure_origin(origin)?; + + // Ensure such an assetId does not exist + ensure!( + AssetIdToForeignAsset::::get(&asset_id).is_none(), + Error::::AssetAlreadyExists + ); + + // TODO submit create eth-xcm call + Self::create_erc20_contract(asset_id, admin, min_balance)?; + + // Insert the association assetId->foreigAsset + // Insert the association foreigAsset->assetId + AssetIdToForeignAsset::::insert(&asset_id, &foreign_asset); + ForeignAssetToAssetId::::insert(&foreign_asset, &asset_id); + + T::OnForeignAssetCreated::on_asset_created(&foreign_asset, &asset_id, &min_balance); + + Self::deposit_event(Event::ForeignAssetCreated { + asset_id, + foreign_asset, + }); + Ok(()) + } + + /// Change the xcm type mapping for a given assetId + /// We also change this if the previous units per second where pointing at the old + /// assetType + #[pallet::call_index(1)] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] + pub fn change_existing_asset_type( + origin: OriginFor, + asset_id: AssetId, + new_foreign_asset: T::ForeignAsset, + ) -> DispatchResult { + T::ForeignAssetModifierOrigin::ensure_origin(origin)?; + + let previous_foreign_asset = + AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + + // Insert new foreign asset info + AssetIdToForeignAsset::::insert(&asset_id, &new_foreign_asset); + ForeignAssetToAssetId::::insert(&new_foreign_asset, &asset_id); + + // Remove previous foreign asset info + ForeignAssetToAssetId::::remove(&previous_foreign_asset); + + Self::deposit_event(Event::ForeignAssetTypeChanged { + asset_id, + new_foreign_asset, + }); + Ok(()) + } + + /// Remove a given assetId -> foreignAsset association + #[pallet::call_index(2)] + #[pallet::weight(::WeightInfo::remove_existing_asset_type())] + pub fn remove_existing_asset_type( + origin: OriginFor, + asset_id: AssetId, + ) -> DispatchResult { + T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; + + let foreign_asset = + AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + + // Remove from AssetIdToForeignAsset + AssetIdToForeignAsset::::remove(&asset_id); + // Remove from ForeignAssetToAssetId + ForeignAssetToAssetId::::remove(&foreign_asset); + + Self::deposit_event(Event::ForeignAssetRemoved { + asset_id, + foreign_asset, + }); + Ok(()) + } + + /// Destroy a given foreign assetId + /// The weight in this case is the one returned by the trait + /// plus the db writes and reads from removing all the associated + /// data + #[pallet::call_index(3)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn destroy_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { + T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; + + let foreign_asset = + AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + + // Important: this starts the destruction process, + // making sure the assets are non-transferable anymore + // make sure the destruction process is completable by other means + Self::start_destroy(asset_id.clone())?; + + // Remove from AssetIdToForeignAsset + AssetIdToForeignAsset::::remove(&asset_id); + // Remove from ForeignAssetToAssetId + ForeignAssetToAssetId::::remove(&foreign_asset); + + T::OnForeignAssetDestroyed::on_asset_destroyed(&foreign_asset, &asset_id); + + Self::deposit_event(Event::ForeignAssetDestroyed { + asset_id, + foreign_asset, + }); + Ok(()) + } + } + + impl MaybeEquivalence for Pallet { + fn convert(foreign_asset: &T::ForeignAsset) -> Option { + Pallet::::asset_id_for_foreign(foreign_asset.clone()) + } + fn convert_back(id: &AssetId) -> Option { + Pallet::::foreign_asset_for_id(id.clone()) + } + } +} diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs new file mode 100644 index 0000000000..6ff2fcdd5e --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -0,0 +1,263 @@ +// Copyright Moonsong Labs +// This file is part of Moonkit. + +// Moonkit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonkit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonkit. If not, see . + +use super::*; +use crate as pallet_foreign_asset_creator; +use std::marker::PhantomData; + +use frame_support::{ + construct_runtime, parameter_types, storage, + traits::{ConstU32, Everything}, +}; +use frame_system::EnsureRoot; +use parity_scale_codec::{Decode, Encode}; +use sp_core::H256; +use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; +use sp_runtime::BuildStorage; +use xcm::latest::prelude::*; + +type Block = frame_system::mocking::MockBlock; + +pub type AccountId = u64; +pub type Balance = u64; + +construct_runtime!( + pub enum Test + { + System: frame_system, + Balances: pallet_balances, + ForeignAssetCreator: pallet_foreign_asset_creator, + Assets: pallet_assets, + } +); + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} +impl frame_system::Config for Test { + type BaseCallFilter = Everything; + type BlockWeights = (); + type BlockLength = (); + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type DbWeight = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; + type RuntimeTask = (); + type SingleBlockMigrations = (); + type MultiBlockMigrator = (); + type PreInherents = (); + type PostInherents = (); + type PostTransactions = (); +} + +parameter_types! { + pub const ExistentialDeposit: u64 = 1; +} + +impl pallet_balances::Config for Test { + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type RuntimeFreezeReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); +} + +parameter_types! { + pub const AssetDeposit: u64 = 0; + pub const ApprovalDeposit: u64 = 0; + pub const StringLimit: u32 = 50; + pub const MetadataDepositBase: u64 = 0; + pub const MetadataDepositPerByte: u64 = 0; +} + +type AssetId = u32; + +impl pallet_assets::Config for Test { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetIdParameter = parity_scale_codec::Compact; + type Currency = Balances; + type CreateOrigin = frame_support::traits::NeverEnsureOrigin; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type AssetAccountDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = StringLimit; + type Freezer = (); + type Extra = (); + type CallbackHandle = (); + type WeightInfo = (); + type RemoveItemsLimit = ConstU32<1000>; + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = (); + } +} + +/// Gets parameters of last `ForeignAssetCreatedHook::on_asset_created` hook invocation +pub fn get_asset_created_hook_invocation< + ForeignAsset: Decode, + AssetId: Decode, + AssetBalance: Decode, +>() -> Option<(ForeignAsset, AssetId, AssetBalance)> { + storage::unhashed::get_raw(b"____on_foreign_asset_created") + .map(|output| Decode::decode(&mut output.as_slice()).expect("Decoding should work")) +} + +/// Notes down parameters of current `ForeignAssetCreatedHook::on_asset_created` hook invocation +fn note_on_asset_created_hook_invocation< + ForeignAsset: Encode, + AssetId: Encode, + AssetBalance: Encode, +>( + foreign_asset: &ForeignAsset, + asset_id: &AssetId, + min_balance: &AssetBalance, +) { + storage::unhashed::put_raw( + b"____on_foreign_asset_created", + (foreign_asset, asset_id, min_balance).encode().as_slice(), + ); +} + +/// Gets parameters of last `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation +pub fn get_asset_destroyed_hook_invocation( +) -> Option<(ForeignAsset, AssetId)> { + storage::unhashed::get_raw(b"____on_foreign_asset_destroyed") + .map(|output| Decode::decode(&mut output.as_slice()).expect("Decoding should work")) +} + +/// Notes down parameters of current `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation +fn note_on_asset_destroyed_hook_invocation( + foreign_asset: &ForeignAsset, + asset_id: &AssetId, +) { + storage::unhashed::put_raw( + b"____on_foreign_asset_destroyed", + (foreign_asset, asset_id).encode().as_slice(), + ); +} + +/// Test hook that records the hook invocation with exact params +pub struct NoteDownHook( + PhantomData<(ForeignAsset, AssetId, AssetBalance)>, +); + +impl + ForeignAssetCreatedHook + for NoteDownHook +{ + fn on_asset_created( + foreign_asset: &ForeignAsset, + asset_id: &AssetId, + min_balance: &AssetBalance, + ) { + note_on_asset_created_hook_invocation(foreign_asset, asset_id, min_balance); + } +} + +impl + ForeignAssetDestroyedHook + for NoteDownHook +{ + fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId) { + note_on_asset_destroyed_hook_invocation(foreign_asset, asset_id); + } +} + +impl Config for Test { + type RuntimeEvent = RuntimeEvent; + type ForeignAsset = Location; + type ForeignAssetCreatorOrigin = EnsureRoot; + type ForeignAssetModifierOrigin = EnsureRoot; + type ForeignAssetDestroyerOrigin = EnsureRoot; + type Fungibles = Assets; + type WeightInfo = (); + type OnForeignAssetCreated = NoteDownHook; + type OnForeignAssetDestroyed = NoteDownHook; +} + +pub(crate) struct ExtBuilder { + // endowed accounts with balances + balances: Vec<(AccountId, Balance)>, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { balances: vec![] } + } +} + +impl ExtBuilder { + pub(crate) fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .expect("Frame system builds valid default genesis config"); + + pallet_balances::GenesisConfig:: { + balances: self.balances, + } + .assimilate_storage(&mut t) + .expect("Pallet balances storage can be assimilated"); + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext + } +} + +pub(crate) fn events() -> Vec> { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| { + if let RuntimeEvent::ForeignAssetCreator(inner) = e { + Some(inner) + } else { + None + } + }) + .collect::>() +} + +pub fn expect_events(e: Vec>) { + assert_eq!(events(), e); +} diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs new file mode 100644 index 0000000000..f475b582c3 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -0,0 +1,247 @@ +// Copyright Moonsong Labs +// This file is part of Moonkit. + +// Moonkit is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonkit is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonkit. If not, see . +use crate::*; +use mock::*; + +use frame_support::{assert_noop, assert_ok}; +use xcm::latest::prelude::*; + +#[test] +fn creating_foreign_works() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + )); + + assert_eq!( + ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + Location::parent() + ); + assert_eq!( + ForeignAssetCreator::asset_id_for_foreign(Location::parent()).unwrap(), + 1 + ); + expect_events(vec![crate::Event::ForeignAssetCreated { + asset_id: 1, + foreign_asset: Location::parent(), + }]); + + let (foreign_asset, asset_id, min_balance): (Location, u32, u64) = + get_asset_created_hook_invocation() + .expect("Decoding of invocation data should not fail"); + assert_eq!(foreign_asset, Location::parent()); + assert_eq!(asset_id, 1u32); + assert_eq!(min_balance, 1u64); + }); +} + +#[test] +fn test_asset_exists_error() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + )); + assert_eq!( + ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + Location::parent() + ); + assert_noop!( + ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + ), + Error::::AssetAlreadyExists + ); + }); +} + +#[test] +fn test_regular_user_cannot_call_extrinsics() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::signed(1), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + ), + sp_runtime::DispatchError::BadOrigin + ); + + assert_noop!( + ForeignAssetCreator::change_existing_asset_type( + RuntimeOrigin::signed(1), + 1, + Location::parent() + ), + sp_runtime::DispatchError::BadOrigin + ); + }); +} + +#[test] +fn test_root_can_change_foreign_asset_for_asset_id() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + )); + + assert_ok!(ForeignAssetCreator::change_existing_asset_type( + RuntimeOrigin::root(), + 1, + Location::here() + )); + + // New associations are stablished + assert_eq!( + ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + Location::here() + ); + assert_eq!( + ForeignAssetCreator::asset_id_for_foreign(Location::here()).unwrap(), + 1 + ); + + // Old ones are deleted + assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); + + expect_events(vec![ + crate::Event::ForeignAssetCreated { + asset_id: 1, + foreign_asset: Location::parent(), + }, + crate::Event::ForeignAssetTypeChanged { + asset_id: 1, + new_foreign_asset: Location::here(), + }, + ]) + }); +} + +#[test] +fn test_asset_id_non_existent_error() { + ExtBuilder::default().build().execute_with(|| { + assert_noop!( + ForeignAssetCreator::change_existing_asset_type( + RuntimeOrigin::root(), + 1, + Location::parent() + ), + Error::::AssetDoesNotExist + ); + }); +} + +#[test] +fn test_root_can_remove_asset_association() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + )); + + assert_ok!(ForeignAssetCreator::remove_existing_asset_type( + RuntimeOrigin::root(), + 1 + )); + + // Mappings are deleted + assert!(ForeignAssetCreator::foreign_asset_for_id(1).is_none()); + assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); + + expect_events(vec![ + crate::Event::ForeignAssetCreated { + asset_id: 1, + foreign_asset: Location::parent(), + }, + crate::Event::ForeignAssetRemoved { + asset_id: 1, + foreign_asset: Location::parent(), + }, + ]) + }); +} + +#[test] +fn test_destroy_foreign_asset_also_removes_everything() { + ExtBuilder::default().build().execute_with(|| { + assert_ok!(ForeignAssetCreator::create_foreign_asset( + RuntimeOrigin::root(), + Location::parent(), + 1u32.into(), + 1u32.into(), + true, + 1u64, + )); + + let (foreign_asset, asset_id, min_balance): (Location, u32, u64) = + get_asset_created_hook_invocation() + .expect("Decoding of invocation data should not fail"); + assert_eq!(foreign_asset, Location::parent()); + assert_eq!(asset_id, 1u32); + assert_eq!(min_balance, 1u64); + + assert_ok!(ForeignAssetCreator::destroy_foreign_asset( + RuntimeOrigin::root(), + 1 + )); + + // Mappings are deleted + assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); + assert!(ForeignAssetCreator::foreign_asset_for_id(1).is_none()); + + expect_events(vec![ + crate::Event::ForeignAssetCreated { + asset_id: 1, + foreign_asset: Location::parent(), + }, + crate::Event::ForeignAssetDestroyed { + asset_id: 1, + foreign_asset: Location::parent(), + }, + ]); + + let (foreign_asset, asset_id): (Location, u32) = get_asset_destroyed_hook_invocation() + .expect("Decoding of invocation data should not fail"); + assert_eq!(foreign_asset, Location::parent()); + assert_eq!(asset_id, 1u32); + }); +} diff --git a/pallets/moonbeam-foreign-assets/src/weights.rs b/pallets/moonbeam-foreign-assets/src/weights.rs new file mode 100644 index 0000000000..c9feeea785 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/weights.rs @@ -0,0 +1,181 @@ +// Copyright (C) Moondance Labs Ltd. +// This file is part of Tanssi. + +// Tanssi is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Tanssi is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Tanssi. If not, see + + +//! Autogenerated weights for pallet_foreign_asset_creator +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-04-09, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `girazoki-XPS-15-9530`, CPU: `13th Gen Intel(R) Core(TM) i9-13900H` +//! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/tanssi-node +// benchmark +// pallet +// --execution=wasm +// --wasm-execution=compiled +// --pallet +// pallet_foreign_asset_creator +// --extrinsic +// * +// --chain=dev +// --steps +// 50 +// --repeat +// 20 +// --template=./benchmarking/frame-weight-template.hbs +// --json-file +// raw.json +// --output +// tmp/pallet_foreign_asset_creator.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] + +use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; +use sp_std::marker::PhantomData; + +/// Weight functions needed for pallet_foreign_asset_creator. +pub trait WeightInfo { + fn create_foreign_asset() -> Weight; + fn change_existing_asset_type() -> Weight; + fn remove_existing_asset_type() -> Weight; + fn destroy_foreign_asset() -> Weight; +} + +/// Weights for pallet_foreign_asset_creator using the Substrate node and recommended hardware. +pub struct SubstrateWeight(PhantomData); +impl WeightInfo for SubstrateWeight { + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn create_foreign_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `113` + // Estimated: `3673` + // Minimum execution time: 16_738_000 picoseconds. + Weight::from_parts(17_366_000, 3673) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:2) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn change_existing_asset_type() -> Weight { + // Proof Size summary in bytes: + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 13_861_000 picoseconds. + Weight::from_parts(14_153_000, 3654) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_existing_asset_type() -> Weight { + // Proof Size summary in bytes: + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 11_698_000 picoseconds. + Weight::from_parts(12_184_000, 3654) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn destroy_foreign_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `429` + // Estimated: `3894` + // Minimum execution time: 17_797_000 picoseconds. + Weight::from_parts(18_635_000, 3894) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} + +// For backwards compatibility and tests +impl WeightInfo for () { + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn create_foreign_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `113` + // Estimated: `3673` + // Minimum execution time: 16_738_000 picoseconds. + Weight::from_parts(17_366_000, 3673) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:2) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn change_existing_asset_type() -> Weight { + // Proof Size summary in bytes: + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 13_861_000 picoseconds. + Weight::from_parts(14_153_000, 3654) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_existing_asset_type() -> Weight { + // Proof Size summary in bytes: + // Measured: `189` + // Estimated: `3654` + // Minimum execution time: 11_698_000 picoseconds. + Weight::from_parts(12_184_000, 3654) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(2_u64)) + } + /// Storage: `ForeignAssetsCreator::AssetIdToForeignAsset` (r:1 w:1) + /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ForeignAssets::Asset` (r:1 w:1) + /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) + /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) + /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn destroy_foreign_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `429` + // Estimated: `3894` + // Minimum execution time: 17_797_000 picoseconds. + Weight::from_parts(18_635_000, 3894) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(3_u64)) + } +} diff --git a/runtime/common/src/impl_xcm_evm_runner.rs b/runtime/common/src/impl_xcm_evm_runner.rs index b71018a0ef..07102147e1 100644 --- a/runtime/common/src/impl_xcm_evm_runner.rs +++ b/runtime/common/src/impl_xcm_evm_runner.rs @@ -166,22 +166,57 @@ macro_rules! impl_evm_runner_precompile_or_eth_xcm { } fn create_force_address( - _source: H160, - _init: Vec, - _value: U256, - _gas_limit: u64, - _max_fee_per_gas: Option, - _max_priority_fee_per_gas: Option, - _nonce: Option, - _access_list: Vec<(H160, Vec)>, - _is_transactional: bool, - _validate: bool, - _weight_limit: Option, - _transaction_len: Option, - _config: &fp_evm::Config, - _force_address: H160, + source: H160, + init: Vec, + value: U256, + gas_limit: u64, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + access_list: Vec<(H160, Vec)>, + is_transactional: bool, + validate: bool, + weight_limit: Option, + transaction_len: Option, + config: &fp_evm::Config, + force_address: H160, ) -> Result> { - unimplemented!() + let xcm_transaction = EthereumXcmTransaction::V2(EthereumXcmTransactionV2 { + gas_limit: gas_limit.into(), + action: pallet_ethereum_xcm::TransactionAction::Create, + value, + input: init.try_into().map_err(|_| RunnerError { + error: DispatchError::Exhausted, + weight: Default::default(), + })?, + access_list: Some(access_list), + }); + + let mut execution_info: Option = None; + pallet_ethereum::catch_exec_info(&mut execution_info, || { + CallDispatcher::dispatch( + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::force_transact_as { + transact_as: source, + xcm_transaction, + force_create_address: Some(force_address), + }), + RawOrigin::Root.into(), + ) + .map_err(|DispatchErrorWithPostInfo { error, .. }| RunnerError { + error, + weight: Default::default(), + }) + })?; + + if let Some(CallOrCreateInfo::Create(create_info))= execution_info { + Ok(create_info) + } else { + // `execution_info` must have been filled in + Err(RunnerError { + error: DispatchError::Unavailable, + weight: Default::default(), + }) + } } fn validate( From 00a14d7077a275160c976259641b6fa1d59abf98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 14 Jul 2024 13:21:10 +0200 Subject: [PATCH 03/71] inject solidity bytecode --- Cargo.lock | 1 + pallets/moonbeam-foreign-assets/Cargo.toml | 3 ++ pallets/moonbeam-foreign-assets/build.rs | 12 +++++ .../resources/foreign_erc20.sol | 54 +++++++++++++++++++ .../resources/foreign_erc20_initcode.hex | 1 + pallets/moonbeam-foreign-assets/src/lib.rs | 16 +++--- 6 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 pallets/moonbeam-foreign-assets/build.rs create mode 100644 pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol create mode 100644 pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex diff --git a/Cargo.lock b/Cargo.lock index 7a4937dcb3..fbbc8941bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9701,6 +9701,7 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "hex", "log", "pallet-assets", "pallet-balances", diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index 067b32e9cb..af53c84b06 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -30,6 +30,9 @@ xcm-executor = { workspace = true, optional = true } # Benchmarks frame-benchmarking = { workspace = true, optional = true } +[build-dependencies] +hex = { workspace = true } + [dev-dependencies] pallet-balances = { workspace = true, features = [ "std" ] } pallet-assets = { workspace = true, features = [ "std" ] } diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs new file mode 100644 index 0000000000..da3bedd7a6 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/build.rs @@ -0,0 +1,12 @@ +use std::fs::File; +use std::io::prelude::*; + +fn main() { + let bytecode = hex::decode(include_str!("resources/foreign_erc20_initcode.hex")) + .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); + + let mut file = File::create("resources/foreign_erc20_initcode.bin") + .expect("Fail to create file resources/foreign_erc20_initcode.bin"); + file.write_all(&bytecode) + .expect("fail to write bytecode in /foreign_erc20_initcode.bin"); +} diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol new file mode 100644 index 0000000000..91f3dcd091 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: MIT +// Compatible with OpenZeppelin Contracts ^5.0.0 +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts@5.0.2/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Burnable.sol"; +import "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Pausable.sol"; +import "@openzeppelin/contracts@5.0.2/access/Ownable.sol"; +import "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Permit.sol"; + +contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { + constructor(address initialOwner, uint8 tokenDecimals, string memory ticker, string memory tokenName) + ERC20(tokenName, ticker) + Ownable(initialOwner) + ERC20Permit(tokenName) + { + _decimals = tokenDecimals; + } + + uint8 private _decimals; + + function pause() public onlyOwner { + _pause(); + } + + function unpause() public onlyOwner { + _unpause(); + } + + function mintInto(address to, uint256 amount) public onlyOwner { + _mint(to, amount); + } + + function burnFrom(address from, uint256 amount) public onlyOwner { + _burn(from, amount); + } + + function burnAllFrom(address account) public onlyOwner { + _burn(account, balanceOf(account)); + } + + function decimals() public view override returns (uint8) { + return _decimals; + } + + // The following functions are overrides required by Solidity. + + function _update(address from, address to, uint256 value) + internal + override(ERC20, ERC20Pausable) + { + super._update(from, to, value); + } +} \ No newline at end of file diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex new file mode 100644 index 0000000000..20aa8cad72 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex @@ -0,0 +1 @@ +610160604052348015610010575f80fd5b50604051612ca7380380612ca7833981810160405281019061003291906105ad565b80806040518060400160405280600181526020017f3100000000000000000000000000000000000000000000000000000000000000815250868486816003908161007c9190610856565b50806004908161008c9190610856565b5050505f60055f6101000a81548160ff0219169083151502179055505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610118575f6040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260040161010f9190610934565b60405180910390fd5b610127816101f660201b60201c565b5061013c6006836102bb60201b90919060201c565b61012081815250506101586007826102bb60201b90919060201c565b6101408181525050818051906020012060e08181525050808051906020012061010081815250504660a0818152505061019561030860201b60201c565b608081815250503073ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250505050508260095f6101000a81548160ff021916908360ff16021790555050505050610ac0565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f6020835110156102dc576102d58361036260201b60201c565b9050610302565b826102ec836103c760201b60201c565b5f0190816102fa9190610856565b5060ff5f1b90505b92915050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60e051610100514630604051602001610347959493929190610974565b60405160208183030381529060405280519060200120905090565b5f80829050601f815111156103ae57826040517f305a27a90000000000000000000000000000000000000000000000000000000081526004016103a59190610a0d565b60405180910390fd5b8051816103ba90610a5a565b5f1c175f1b915050919050565b5f819050919050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61040a826103e1565b9050919050565b61041a81610400565b8114610424575f80fd5b50565b5f8151905061043581610411565b92915050565b5f60ff82169050919050565b6104508161043b565b811461045a575f80fd5b50565b5f8151905061046b81610447565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6104bf82610479565b810181811067ffffffffffffffff821117156104de576104dd610489565b5b80604052505050565b5f6104f06103d0565b90506104fc82826104b6565b919050565b5f67ffffffffffffffff82111561051b5761051a610489565b5b61052482610479565b9050602081019050919050565b8281835e5f83830152505050565b5f61055161054c84610501565b6104e7565b90508281526020810184848401111561056d5761056c610475565b5b610578848285610531565b509392505050565b5f82601f83011261059457610593610471565b5b81516105a484826020860161053f565b91505092915050565b5f805f80608085870312156105c5576105c46103d9565b5b5f6105d287828801610427565b94505060206105e38782880161045d565b935050604085015167ffffffffffffffff811115610604576106036103dd565b5b61061087828801610580565b925050606085015167ffffffffffffffff811115610631576106306103dd565b5b61063d87828801610580565b91505092959194509250565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f600282049050600182168061069757607f821691505b6020821081036106aa576106a9610653565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f6008830261070c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826106d1565b61071686836106d1565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f61075a6107556107508461072e565b610737565b61072e565b9050919050565b5f819050919050565b61077383610740565b61078761077f82610761565b8484546106dd565b825550505050565b5f90565b61079b61078f565b6107a681848461076a565b505050565b5b818110156107c9576107be5f82610793565b6001810190506107ac565b5050565b601f82111561080e576107df816106b0565b6107e8846106c2565b810160208510156107f7578190505b61080b610803856106c2565b8301826107ab565b50505b505050565b5f82821c905092915050565b5f61082e5f1984600802610813565b1980831691505092915050565b5f610846838361081f565b9150826002028217905092915050565b61085f82610649565b67ffffffffffffffff81111561087857610877610489565b5b6108828254610680565b61088d8282856107cd565b5f60209050601f8311600181146108be575f84156108ac578287015190505b6108b6858261083b565b86555061091d565b601f1984166108cc866106b0565b5f5b828110156108f3578489015182556001820191506020850194506020810190506108ce565b86831015610910578489015161090c601f89168261081f565b8355505b6001600288020188555050505b505050505050565b61092e81610400565b82525050565b5f6020820190506109475f830184610925565b92915050565b5f819050919050565b61095f8161094d565b82525050565b61096e8161072e565b82525050565b5f60a0820190506109875f830188610956565b6109946020830187610956565b6109a16040830186610956565b6109ae6060830185610965565b6109bb6080830184610925565b9695505050505050565b5f82825260208201905092915050565b5f6109df82610649565b6109e981856109c5565b93506109f9818560208601610531565b610a0281610479565b840191505092915050565b5f6020820190508181035f830152610a2581846109d5565b905092915050565b5f81519050919050565b5f819050602082019050919050565b5f610a51825161094d565b80915050919050565b5f610a6482610a2d565b82610a6e84610a37565b9050610a7981610a46565b92506020821015610ab957610ab47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026106d1565b831692505b5050919050565b60805160a05160c05160e051610100516101205161014051612196610b115f395f610f2f01525f610ef401525f61129e01525f61127d01525f610c6a01525f610cc001525f610ce901526121965ff3fe608060405234801561000f575f80fd5b5060043610610140575f3560e01c806379cc6790116100b657806395d89b411161007a57806395d89b4114610332578063a9059cbb14610350578063aab3859214610380578063d505accf1461039c578063dd62ed3e146103b8578063f2fde38b146103e857610140565b806379cc67901461029a5780637ecebe00146102b65780638456cb59146102e657806384b0196e146102f05780638da5cb5b1461031457610140565b8063313ce56711610108578063313ce567146101fc5780633644e5151461021a5780633f4ba83a146102385780635c975abb1461024257806370a0823114610260578063715018a61461029057610140565b806306fdde0314610144578063095ea7b314610162578063167db3791461019257806318160ddd146101ae57806323b872dd146101cc575b5f80fd5b61014c610404565b6040516101599190611a06565b60405180910390f35b61017c60048036038101906101779190611ab7565b610494565b6040516101899190611b0f565b60405180910390f35b6101ac60048036038101906101a79190611b28565b6104b6565b005b6101b66104d3565b6040516101c39190611b62565b60405180910390f35b6101e660048036038101906101e19190611b7b565b6104dc565b6040516101f39190611b0f565b60405180910390f35b61020461050a565b6040516102119190611be6565b60405180910390f35b61022261051f565b60405161022f9190611c17565b60405180910390f35b61024061052d565b005b61024a61053f565b6040516102579190611b0f565b60405180910390f35b61027a60048036038101906102759190611b28565b610554565b6040516102879190611b62565b60405180910390f35b610298610599565b005b6102b460048036038101906102af9190611ab7565b6105ac565b005b6102d060048036038101906102cb9190611b28565b6105c2565b6040516102dd9190611b62565b60405180910390f35b6102ee6105d3565b005b6102f86105e5565b60405161030b9796959493929190611d30565b60405180910390f35b61031c61068a565b6040516103299190611db2565b60405180910390f35b61033a6106b3565b6040516103479190611a06565b60405180910390f35b61036a60048036038101906103659190611ab7565b610743565b6040516103779190611b0f565b60405180910390f35b61039a60048036038101906103959190611ab7565b610765565b005b6103b660048036038101906103b19190611e1f565b61077b565b005b6103d260048036038101906103cd9190611ebc565b6108c0565b6040516103df9190611b62565b60405180910390f35b61040260048036038101906103fd9190611b28565b610942565b005b60606003805461041390611f27565b80601f016020809104026020016040519081016040528092919081815260200182805461043f90611f27565b801561048a5780601f106104615761010080835404028352916020019161048a565b820191905f5260205f20905b81548152906001019060200180831161046d57829003601f168201915b5050505050905090565b5f8061049e6109c6565b90506104ab8185856109cd565b600191505092915050565b6104be6109df565b6104d0816104cb83610554565b610a66565b50565b5f600254905090565b5f806104e66109c6565b90506104f3858285610ae5565b6104fe858585610b77565b60019150509392505050565b5f60095f9054906101000a900460ff16905090565b5f610528610c67565b905090565b6105356109df565b61053d610d1d565b565b5f60055f9054906101000a900460ff16905090565b5f805f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b6105a16109df565b6105aa5f610d7e565b565b6105b46109df565b6105be8282610a66565b5050565b5f6105cc82610e43565b9050919050565b6105db6109df565b6105e3610e89565b565b5f6060805f805f60606105f6610eeb565b6105fe610f26565b46305f801b5f67ffffffffffffffff81111561061d5761061c611f57565b5b60405190808252806020026020018201604052801561064b5781602001602082028036833780820191505090505b507f0f00000000000000000000000000000000000000000000000000000000000000959493929190965096509650965096509650965090919293949596565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600480546106c290611f27565b80601f01602080910402602001604051908101604052809291908181526020018280546106ee90611f27565b80156107395780601f1061071057610100808354040283529160200191610739565b820191905f5260205f20905b81548152906001019060200180831161071c57829003601f168201915b5050505050905090565b5f8061074d6109c6565b905061075a818585610b77565b600191505092915050565b61076d6109df565b6107778282610f61565b5050565b834211156107c057836040517f627913020000000000000000000000000000000000000000000000000000000081526004016107b79190611b62565b60405180910390fd5b5f7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886107ee8c610fe0565b8960405160200161080496959493929190611f84565b6040516020818303038152906040528051906020012090505f61082682611033565b90505f6108358287878761104c565b90508973ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146108a957808a6040517f4b800e460000000000000000000000000000000000000000000000000000000081526004016108a0929190611fe3565b60405180910390fd5b6108b48a8a8a6109cd565b50505050505050505050565b5f60015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905092915050565b61094a6109df565b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036109ba575f6040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016109b19190611db2565b60405180910390fd5b6109c381610d7e565b50565b5f33905090565b6109da838383600161107a565b505050565b6109e76109c6565b73ffffffffffffffffffffffffffffffffffffffff16610a0561068a565b73ffffffffffffffffffffffffffffffffffffffff1614610a6457610a286109c6565b6040517f118cdaa7000000000000000000000000000000000000000000000000000000008152600401610a5b9190611db2565b60405180910390fd5b565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610ad6575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610acd9190611db2565b60405180910390fd5b610ae1825f83611249565b5050565b5f610af084846108c0565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114610b715781811015610b62578281836040517ffb8f41b2000000000000000000000000000000000000000000000000000000008152600401610b599392919061200a565b60405180910390fd5b610b7084848484035f61107a565b5b50505050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610be7575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610bde9190611db2565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610c57575f6040517fec442f05000000000000000000000000000000000000000000000000000000008152600401610c4e9190611db2565b60405180910390fd5b610c62838383611249565b505050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff16148015610ce257507f000000000000000000000000000000000000000000000000000000000000000046145b15610d0f577f00000000000000000000000000000000000000000000000000000000000000009050610d1a565b610d17611259565b90505b90565b610d256112ee565b5f60055f6101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610d676109c6565b604051610d749190611db2565b60405180910390a1565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b610e9161132e565b600160055f6101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610ed46109c6565b604051610ee19190611db2565b60405180910390a1565b6060610f2160067f000000000000000000000000000000000000000000000000000000000000000061136f90919063ffffffff16565b905090565b6060610f5c60077f000000000000000000000000000000000000000000000000000000000000000061136f90919063ffffffff16565b905090565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610fd1575f6040517fec442f05000000000000000000000000000000000000000000000000000000008152600401610fc89190611db2565b60405180910390fd5b610fdc5f8383611249565b5050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f815480929190600101919050559050919050565b5f61104561103f610c67565b8361141c565b9050919050565b5f805f8061105c8888888861145c565b92509250925061106c8282611543565b829350505050949350505050565b5f73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16036110ea575f6040517fe602df050000000000000000000000000000000000000000000000000000000081526004016110e19190611db2565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361115a575f6040517f94280d620000000000000000000000000000000000000000000000000000000081526004016111519190611db2565b60405180910390fd5b8160015f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20819055508015611243578273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161123a9190611b62565b60405180910390a35b50505050565b6112548383836116a5565b505050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000046306040516020016112d395949392919061203f565b60405160208183030381529060405280519060200120905090565b6112f661053f565b61132c576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b61133661053f565b1561136d576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b606060ff5f1b831461138b57611384836116bd565b9050611416565b81805461139790611f27565b80601f01602080910402602001604051908101604052809291908181526020018280546113c390611f27565b801561140e5780601f106113e55761010080835404028352916020019161140e565b820191905f5260205f20905b8154815290600101906020018083116113f157829003601f168201915b505050505090505b92915050565b5f6040517f190100000000000000000000000000000000000000000000000000000000000081528360028201528260228201526042812091505092915050565b5f805f7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0845f1c1115611498575f600385925092509250611539565b5f6001888888886040515f81526020016040526040516114bb9493929190612090565b6020604051602081039080840390855afa1580156114db573d5f803e3d5ffd5b5050506020604051035190505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361152c575f60015f801b93509350935050611539565b805f805f1b935093509350505b9450945094915050565b5f6003811115611556576115556120d3565b5b826003811115611569576115686120d3565b5b03156116a15760016003811115611583576115826120d3565b5b826003811115611596576115956120d3565b5b036115cd576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600260038111156115e1576115e06120d3565b5b8260038111156115f4576115f36120d3565b5b0361163857805f1c6040517ffce698f700000000000000000000000000000000000000000000000000000000815260040161162f9190611b62565b60405180910390fd5b60038081111561164b5761164a6120d3565b5b82600381111561165e5761165d6120d3565b5b036116a057806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016116979190611c17565b60405180910390fd5b5b5050565b6116ad61132e565b6116b883838361172f565b505050565b60605f6116c983611948565b90505f602067ffffffffffffffff8111156116e7576116e6611f57565b5b6040519080825280601f01601f1916602001820160405280156117195781602001600182028036833780820191505090505b5090508181528360208201528092505050919050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361177f578060025f828254611773919061212d565b9250508190555061184d565b5f805f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905081811015611808578381836040517fe450d38c0000000000000000000000000000000000000000000000000000000081526004016117ff9392919061200a565b60405180910390fd5b8181035f808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081905550505b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611894578060025f82825403925050819055506118de565b805f808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161193b9190611b62565b60405180910390a3505050565b5f8060ff835f1c169050601f81111561198d576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80915050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6119d882611996565b6119e281856119a0565b93506119f28185602086016119b0565b6119fb816119be565b840191505092915050565b5f6020820190508181035f830152611a1e81846119ce565b905092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611a5382611a2a565b9050919050565b611a6381611a49565b8114611a6d575f80fd5b50565b5f81359050611a7e81611a5a565b92915050565b5f819050919050565b611a9681611a84565b8114611aa0575f80fd5b50565b5f81359050611ab181611a8d565b92915050565b5f8060408385031215611acd57611acc611a26565b5b5f611ada85828601611a70565b9250506020611aeb85828601611aa3565b9150509250929050565b5f8115159050919050565b611b0981611af5565b82525050565b5f602082019050611b225f830184611b00565b92915050565b5f60208284031215611b3d57611b3c611a26565b5b5f611b4a84828501611a70565b91505092915050565b611b5c81611a84565b82525050565b5f602082019050611b755f830184611b53565b92915050565b5f805f60608486031215611b9257611b91611a26565b5b5f611b9f86828701611a70565b9350506020611bb086828701611a70565b9250506040611bc186828701611aa3565b9150509250925092565b5f60ff82169050919050565b611be081611bcb565b82525050565b5f602082019050611bf95f830184611bd7565b92915050565b5f819050919050565b611c1181611bff565b82525050565b5f602082019050611c2a5f830184611c08565b92915050565b5f7fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b611c6481611c30565b82525050565b611c7381611a49565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b611cab81611a84565b82525050565b5f611cbc8383611ca2565b60208301905092915050565b5f602082019050919050565b5f611cde82611c79565b611ce88185611c83565b9350611cf383611c93565b805f5b83811015611d23578151611d0a8882611cb1565b9750611d1583611cc8565b925050600181019050611cf6565b5085935050505092915050565b5f60e082019050611d435f83018a611c5b565b8181036020830152611d5581896119ce565b90508181036040830152611d6981886119ce565b9050611d786060830187611b53565b611d856080830186611c6a565b611d9260a0830185611c08565b81810360c0830152611da48184611cd4565b905098975050505050505050565b5f602082019050611dc55f830184611c6a565b92915050565b611dd481611bcb565b8114611dde575f80fd5b50565b5f81359050611def81611dcb565b92915050565b611dfe81611bff565b8114611e08575f80fd5b50565b5f81359050611e1981611df5565b92915050565b5f805f805f805f60e0888a031215611e3a57611e39611a26565b5b5f611e478a828b01611a70565b9750506020611e588a828b01611a70565b9650506040611e698a828b01611aa3565b9550506060611e7a8a828b01611aa3565b9450506080611e8b8a828b01611de1565b93505060a0611e9c8a828b01611e0b565b92505060c0611ead8a828b01611e0b565b91505092959891949750929550565b5f8060408385031215611ed257611ed1611a26565b5b5f611edf85828601611a70565b9250506020611ef085828601611a70565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680611f3e57607f821691505b602082108103611f5157611f50611efa565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60c082019050611f975f830189611c08565b611fa46020830188611c6a565b611fb16040830187611c6a565b611fbe6060830186611b53565b611fcb6080830185611b53565b611fd860a0830184611b53565b979650505050505050565b5f604082019050611ff65f830185611c6a565b6120036020830184611c6a565b9392505050565b5f60608201905061201d5f830186611c6a565b61202a6020830185611b53565b6120376040830184611b53565b949350505050565b5f60a0820190506120525f830188611c08565b61205f6020830187611c08565b61206c6040830186611c08565b6120796060830185611b53565b6120866080830184611c6a565b9695505050505050565b5f6080820190506120a35f830187611c08565b6120b06020830186611bd7565b6120bd6040830185611c08565b6120ca6060830184611c08565b95945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61213782611a84565b915061214283611a84565b925082820190508082111561215a57612159612100565b5b9291505056fea26469706673582212200fbc0e720f4cf8c8804e8ffd05f06d46f086f3b2356e095519fac7223509253464736f6c634300081a0033 \ No newline at end of file diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 11596f061b..fcf8494829 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -65,17 +65,14 @@ pub mod pallet { use fp_evm::{ExitReason, ExitSucceed}; use frame_support::{ pallet_prelude::*, - traits::{ - fungibles::Destroy, - tokens::fungibles, - }, + traits::{fungibles::Destroy, tokens::fungibles}, }; use frame_system::pallet_prelude::*; use pallet_evm::{GasWeightMapping, Runner}; use sp_runtime::traits::{Dispatchable, MaybeEquivalence}; - const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 8192; - const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0x00, 0x00, 0x00, 0x00]; + const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 16 * 1024; + const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; const FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT: u64 = 500_000; #[pallet::pallet] @@ -179,8 +176,13 @@ pub mod pallet { admin: H160, min_balance: AssetBalance, ) -> Result<(), Error> { - // TODO generate init code + // Get init code let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); + init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); + + // Add constructor parameters + // (0x6D6f646c617373746d6E67720000000000000000, 18, MTT, MyBigToken) + //0x0000000000000000000000006d6f646c617373746d6e677200000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 // Compute contract address let mut buffer = [0u8; 20]; From 03a01ef2641d0d8ef8002357e688670754f7926e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 14 Jul 2024 14:12:39 +0200 Subject: [PATCH 04/71] add freeze/unfreeze calls --- pallets/moonbeam-foreign-assets/src/lib.rs | 181 ++++++++++++++++----- 1 file changed, 137 insertions(+), 44 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index fcf8494829..a402d0c19c 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -31,22 +31,13 @@ pub mod weights; /// Trait for the OnForeignAssetRegistered hook pub trait ForeignAssetCreatedHook { - fn on_asset_created( - foreign_asset: &ForeignAsset, - asset_id: &AssetId, - min_balance: &AssetBalance, - ); + fn on_asset_created(foreign_asset: &ForeignAsset, asset_id: &AssetId); } impl ForeignAssetCreatedHook for () { - fn on_asset_created( - _foreign_asset: &ForeignAsset, - _asset_id: &AssetId, - _min_balance: &AssetBalance, - ) { - } + fn on_asset_created(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } /// Trait for the OnForeignAssetDeregistered hook @@ -63,13 +54,10 @@ pub mod pallet { use super::*; use ethereum_types::{H160, U256}; use fp_evm::{ExitReason, ExitSucceed}; - use frame_support::{ - pallet_prelude::*, - traits::{fungibles::Destroy, tokens::fungibles}, - }; + use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use pallet_evm::{GasWeightMapping, Runner}; - use sp_runtime::traits::{Dispatchable, MaybeEquivalence}; + use sp_runtime::traits::{AccountIdConversion, MaybeEquivalence}; const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 16 * 1024; const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; @@ -79,32 +67,34 @@ pub mod pallet { #[pallet::without_storage_info] pub struct Pallet(PhantomData); + /// The moonbeam foreign assets's pallet id + pub const PALLET_ID: frame_support::PalletId = frame_support::PalletId(*b"forgasst"); + #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config { + type AccountId: Parameter + Into + IsType<::AccountId>; + /// EVM runner type EvmRunner: Runner; - /// The overarching event type. - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - /// The Foreign Asset Kind. - type ForeignAsset: Parameter + Member + Ord + PartialOrd + Default; + type ForeignAsset: Parameter + Member + Ord + PartialOrd; - /// Origin that is allowed to create and modify asset information for foreign assets + /// Origin that is allowed to create a new foreign assets type ForeignAssetCreatorOrigin: EnsureOrigin; - /// Origin that is allowed to create and modify asset information for foreign assets + /// Origin that is allowed to modify asset information for foreign assets type ForeignAssetModifierOrigin: EnsureOrigin; - /// Origin that is allowed to create and modify asset information for foreign assets - type ForeignAssetDestroyerOrigin: EnsureOrigin; + /// Origin that is allowed to freeze all tokens of a foreign asset + type ForeignAssetFreezerOrigin: EnsureOrigin; - type Fungibles: fungibles::Create - + fungibles::Destroy - + fungibles::Inspect; + /// Origin that is allowed to unfreeze all tokens of a foreign asset that was previously + /// frozen + type ForeignAssetUnfreezerOrigin: EnsureOrigin; - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; + /// Origin that is allowed to create and modify asset information for foreign assets + type ForeignAssetDestroyerOrigin: EnsureOrigin; /// Hook to be called when new foreign asset is registered. type OnForeignAssetCreated: ForeignAssetCreatedHook< @@ -115,6 +105,15 @@ pub mod pallet { /// Hook to be called when foreign asset is de-registered. type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; + + /// Maximum nulmbers of differnt foreign assets + type MaxForeignAssets: Get; + + /// The overarching event type. + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + /// Weight information for extrinsics in this pallet. + type WeightInfo: WeightInfo; } pub type AssetBalance = U256; @@ -125,7 +124,10 @@ pub mod pallet { pub enum Error { AssetAlreadyExists, AssetDoesNotExist, + AssetAlreadyFrozen, + AssetNotFrozen, Erc20ContractCreationFail, + TooManyForeignAssets, } #[pallet::event] @@ -146,6 +148,16 @@ pub mod pallet { asset_id: AssetId, foreign_asset: T::ForeignAsset, }, + // Freezes all tokens of a given asset id + ForeignAssetFrozen { + asset_id: AssetId, + foreign_asset: T::ForeignAsset, + }, + // Thawing a previously frozen asset + ForeignAssetUnfrozen { + asset_id: AssetId, + foreign_asset: T::ForeignAsset, + }, /// Removed all information related to an assetId and destroyed asset ForeignAssetDestroyed { asset_id: AssetId, @@ -159,7 +171,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn foreign_asset_for_id)] pub type AssetIdToForeignAsset = - StorageMap<_, Blake2_128Concat, AssetId, T::ForeignAsset>; + CountedStorageMap<_, Blake2_128Concat, AssetId, T::ForeignAsset, OptionQuery>; /// Reverse mapping of AssetIdToForeignAsset. Mapping from a foreign asset to an asset id. /// This is mostly used when receiving a multilocation XCM message to retrieve @@ -169,13 +181,20 @@ pub mod pallet { pub type ForeignAssetToAssetId = StorageMap<_, Blake2_128Concat, T::ForeignAsset, AssetId>; + #[pallet::storage] + #[pallet::getter(fn frozen_assets)] + pub type FrozenAssets = + StorageValue<_, BoundedVec, ValueQuery>; + impl Pallet { + /// The account ID of this pallet + pub fn account_id() -> H160 { + let account_id: ::AccountId = PALLET_ID.into_account_truncating(); + account_id.into() + } + /// Deploy foreign asset erc20 contract - fn create_erc20_contract( - asset_id: AssetId, - admin: H160, - min_balance: AssetBalance, - ) -> Result<(), Error> { + fn create_erc20_contract(asset_id: AssetId, decimals: u8) -> Result<(), Error> { // Get init code let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); @@ -191,7 +210,7 @@ pub mod pallet { let contract_address = H160(buffer); let exec_info = T::EvmRunner::create_force_address( - admin, + Self::account_id(), init, U256::default(), FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT, @@ -219,7 +238,20 @@ pub mod pallet { Ok(()) } + // Call contract selector "pause" + fn pause(asset_id: AssetId) -> Result<(), Error> { + todo!() + } + + // Call contract selector "unpause" + fn unpause(asset_id: AssetId) -> Result<(), Error> { + todo!() + } + fn start_destroy(asset_id: AssetId) -> Result<(), Error> { + // Freeze asset + Self::pause(asset_id)?; + todo!() } } @@ -233,8 +265,7 @@ pub mod pallet { origin: OriginFor, foreign_asset: T::ForeignAsset, asset_id: AssetId, - admin: H160, - min_balance: AssetBalance, + decimals: u8, ) -> DispatchResult { T::ForeignAssetCreatorOrigin::ensure_origin(origin)?; @@ -244,15 +275,20 @@ pub mod pallet { Error::::AssetAlreadyExists ); + ensure!( + AssetIdToForeignAsset::::count() < T::MaxForeignAssets::get(), + Error::::TooManyForeignAssets + ); + // TODO submit create eth-xcm call - Self::create_erc20_contract(asset_id, admin, min_balance)?; + Self::create_erc20_contract(asset_id, decimals)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId AssetIdToForeignAsset::::insert(&asset_id, &foreign_asset); ForeignAssetToAssetId::::insert(&foreign_asset, &asset_id); - T::OnForeignAssetCreated::on_asset_created(&foreign_asset, &asset_id, &min_balance); + T::OnForeignAssetCreated::on_asset_created(&foreign_asset, &asset_id); Self::deposit_event(Event::ForeignAssetCreated { asset_id, @@ -314,12 +350,69 @@ pub mod pallet { Ok(()) } - /// Destroy a given foreign assetId - /// The weight in this case is the one returned by the trait - /// plus the db writes and reads from removing all the associated - /// data + /// Freeze a given foreign assetId #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn freeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { + T::ForeignAssetFreezerOrigin::ensure_origin(origin)?; + + let foreign_asset = + AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + + let mut frozen_assets: Vec<_> = FrozenAssets::::get().into(); + let index = match frozen_assets.binary_search_by(|i| i.cmp(&asset_id)) { + Ok(_) => return Err(Error::::AssetAlreadyFrozen.into()), + Err(index) => index, + }; + + Self::pause(asset_id.clone())?; + + frozen_assets.insert(index, asset_id); + let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets + .try_into() + .map_err(|_| Error::::TooManyForeignAssets)?; + FrozenAssets::::put(frozen_assets_bounded); + + Self::deposit_event(Event::ForeignAssetFrozen { + asset_id, + foreign_asset, + }); + Ok(()) + } + + /// Freeze a given foreign assetId + #[pallet::call_index(4)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { + T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; + + let foreign_asset = + AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + + let mut frozen_assets: Vec<_> = FrozenAssets::::get().into(); + let index = match frozen_assets.binary_search_by(|i| i.cmp(&asset_id)) { + Ok(index) => index, + Err(_) => return Err(Error::::AssetNotFrozen.into()), + }; + + Self::unpause(asset_id.clone())?; + + frozen_assets.remove(index); + let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets + .try_into() + .map_err(|_| Error::::TooManyForeignAssets)?; + FrozenAssets::::put(frozen_assets_bounded); + + Self::deposit_event(Event::ForeignAssetUnfrozen { + asset_id, + foreign_asset, + }); + Ok(()) + } + + /// Destroy a given foreign assetId + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn destroy_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; From 255af2b814a0db76d7aba9458c97f635e633cfa9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 14 Jul 2024 15:52:05 +0200 Subject: [PATCH 05/71] refactor foreign assets pallet: create evm module --- pallets/moonbeam-foreign-assets/src/evm.rs | 151 +++++++++++++++++ pallets/moonbeam-foreign-assets/src/lib.rs | 182 +++++++++++++-------- 2 files changed, 261 insertions(+), 72 deletions(-) create mode 100644 pallets/moonbeam-foreign-assets/src/evm.rs diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs new file mode 100644 index 0000000000..171fc44e19 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -0,0 +1,151 @@ +// Copyright 2019-2022 PureStake Inc. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +use crate::{AssetId, Error, Pallet}; +use ethereum_types::{H160, U256}; +use fp_evm::{ExitReason, ExitSucceed}; +use frame_support::ensure; +use pallet_evm::Runner; +use sp_runtime::DispatchError; +use xcm::latest::Error as XcmError; + +const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 16 * 1024; +const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; +const FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT: u64 = 500_000; +const FOREIGN_ASSET_ERC20_TRANSFER_GAS_LIMIT: u64 = 500_000; +const FOREIGN_ASSET_ERC20_MINT_INTO_GAS_LIMIT: u64 = 500_000; +const FOREIGN_ASSET_ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; +const FOREIGN_ASSET_ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; +const FOREIGN_ASSET_ERC20_UNPAUSE_GAS_LIMIT: u64 = 500_000; + +pub(crate) enum EvmError { + ContractCreationFail, + ContractTransferFail, + ContractReturnInvalidValue, + DispatchError(DispatchError), + EvmCallFail, +} + +impl From for EvmError { + fn from(e: DispatchError) -> Self { + Self::DispatchError(e) + } +} + +impl From for XcmError { + fn from(error: EvmError) -> XcmError { + match error { + EvmError::ContractCreationFail => { + XcmError::FailedToTransactAsset("Erc20 contract transfer fail") + } + EvmError::ContractTransferFail => { + XcmError::FailedToTransactAsset("Erc20 contract transfer fail") + } + EvmError::ContractReturnInvalidValue => { + XcmError::FailedToTransactAsset("Erc20 contract return invalid value") + } + EvmError::DispatchError(err) => { + log::debug!("dispatch error: {:?}", err); + Self::FailedToTransactAsset("storage layer error") + } + EvmError::EvmCallFail => XcmError::FailedToTransactAsset("Fail to call erc20 contract"), + } + } +} + +pub(crate) struct EvmCaller(core::marker::PhantomData); + +impl EvmCaller { + /// Deploy foreign asset erc20 contract + pub(crate) fn erc20_create(asset_id: AssetId, decimals: u8) -> Result<(), Error> { + // Get init code + let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); + init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); + + // Add constructor parameters + // (0x6D6f646c617373746d6E67720000000000000000, 18, MTT, MyBigToken) + //0x0000000000000000000000006d6f646c617373746d6e677200000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 + + // Compute contract address + let mut buffer = [0u8; 20]; + buffer[..4].copy_from_slice(&FOREIGN_ASSETS_PREFIX); + buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); + let contract_address = H160(buffer); + + let exec_info = T::EvmRunner::create_force_address( + Pallet::::account_id(), + init, + U256::default(), + FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT, + None, + None, + None, + Default::default(), + true, + false, + None, + None, + &::config(), + contract_address, + ) + .map_err(|_| Error::Erc20ContractCreationFail)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + Error::Erc20ContractCreationFail + ); + + Ok(()) + } + + pub(crate) fn erc20_mint_into( + erc20_contract_address: H160, + beneficiary: H160, + amount: U256, + ) -> Result<(), EvmError> { + todo!() + } + + pub(crate) fn erc20_transfer( + erc20_contract_address: H160, + from: H160, + to: H160, + amount: U256, + ) -> Result<(), EvmError> { + todo!() + } + + pub(crate) fn erc20_burn_from( + erc20_contract_address: H160, + who: H160, + amount: U256, + ) -> Result<(), EvmError> { + todo!() + } + + // Call contract selector "pause" + pub(crate) fn erc20_pause(asset_id: AssetId) -> Result<(), Error> { + todo!() + } + + // Call contract selector "unpause" + pub(crate) fn erc20_unpause(asset_id: AssetId) -> Result<(), Error> { + todo!() + } +} diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index a402d0c19c..ed29489c98 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -16,11 +16,6 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub use pallet::*; -pub use weights::WeightInfo; - -use frame_support::pallet; - #[cfg(any(test, feature = "runtime-benchmarks"))] pub mod benchmarks; #[cfg(test)] @@ -29,6 +24,19 @@ pub mod mock; pub mod tests; pub mod weights; +mod evm; + +pub use pallet::*; +pub use weights::WeightInfo; + +use self::evm::EvmCaller; +use ethereum_types::{H160, U256}; +use frame_support::pallet; +use frame_support::pallet_prelude::*; +use frame_system::pallet_prelude::*; +use xcm::latest::{Asset, Error as XcmError, Junction, Location, Result as XcmResult, XcmContext}; +use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; + /// Trait for the OnForeignAssetRegistered hook pub trait ForeignAssetCreatedHook { fn on_asset_created(foreign_asset: &ForeignAsset, asset_id: &AssetId); @@ -49,19 +57,26 @@ impl ForeignAssetDestroyedHook for fn on_asset_destroyed(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } +pub(crate) struct ForeignAssetsMatcher( + core::marker::PhantomData, +); + +impl> MatchesFungibles + for ForeignAssetsMatcher +{ + fn matches_fungibles(asset: &Asset) -> Result<(H160, U256), MatchError> { + todo!() + } +} + #[pallet] pub mod pallet { use super::*; - use ethereum_types::{H160, U256}; - use fp_evm::{ExitReason, ExitSucceed}; - use frame_support::pallet_prelude::*; - use frame_system::pallet_prelude::*; use pallet_evm::{GasWeightMapping, Runner}; use sp_runtime::traits::{AccountIdConversion, MaybeEquivalence}; - - const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 16 * 1024; - const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; - const FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT: u64 = 500_000; + use xcm_executor::traits::ConvertLocation; + use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; + use xcm_executor::AssetsInHolding; #[pallet::pallet] #[pallet::without_storage_info] @@ -72,14 +87,21 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config { + /// the overarching AccountId type type AccountId: Parameter + Into + IsType<::AccountId>; + // Convert XCM Location to H160 + type AccountIdConverter: ConvertLocation; + /// EVM runner type EvmRunner: Runner; /// The Foreign Asset Kind. type ForeignAsset: Parameter + Member + Ord + PartialOrd; + /// Prefix of XCM location that indentify foreign assets + type ForeignAssetXcmLocationPrefix: Get; + /// Origin that is allowed to create a new foreign assets type ForeignAssetCreatorOrigin: EnsureOrigin; @@ -193,64 +215,9 @@ pub mod pallet { account_id.into() } - /// Deploy foreign asset erc20 contract - fn create_erc20_contract(asset_id: AssetId, decimals: u8) -> Result<(), Error> { - // Get init code - let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); - init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); - - // Add constructor parameters - // (0x6D6f646c617373746d6E67720000000000000000, 18, MTT, MyBigToken) - //0x0000000000000000000000006d6f646c617373746d6e677200000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 - - // Compute contract address - let mut buffer = [0u8; 20]; - buffer[..4].copy_from_slice(&FOREIGN_ASSETS_PREFIX); - buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); - let contract_address = H160(buffer); - - let exec_info = T::EvmRunner::create_force_address( - Self::account_id(), - init, - U256::default(), - FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT, - None, - None, - None, - Default::default(), - true, - false, - None, - None, - &::config(), - contract_address, - ) - .map_err(|_| Error::Erc20ContractCreationFail)?; - - ensure!( - matches!( - exec_info.exit_reason, - ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) - ), - Error::Erc20ContractCreationFail - ); - - Ok(()) - } - - // Call contract selector "pause" - fn pause(asset_id: AssetId) -> Result<(), Error> { - todo!() - } - - // Call contract selector "unpause" - fn unpause(asset_id: AssetId) -> Result<(), Error> { - todo!() - } - fn start_destroy(asset_id: AssetId) -> Result<(), Error> { // Freeze asset - Self::pause(asset_id)?; + EvmCaller::::erc20_pause(asset_id)?; todo!() } @@ -281,7 +248,7 @@ pub mod pallet { ); // TODO submit create eth-xcm call - Self::create_erc20_contract(asset_id, decimals)?; + EvmCaller::::erc20_create(asset_id, decimals)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId @@ -365,7 +332,7 @@ pub mod pallet { Err(index) => index, }; - Self::pause(asset_id.clone())?; + EvmCaller::::erc20_pause(asset_id.clone())?; frozen_assets.insert(index, asset_id); let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets @@ -395,7 +362,7 @@ pub mod pallet { Err(_) => return Err(Error::::AssetNotFrozen.into()), }; - Self::unpause(asset_id.clone())?; + EvmCaller::::erc20_unpause(asset_id.clone())?; frozen_assets.remove(index); let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets @@ -447,4 +414,75 @@ pub mod pallet { Pallet::::foreign_asset_for_id(id.clone()) } } + + impl xcm_executor::traits::TransactAsset for Pallet { + // For optimization reasons, the asset we want to deposit has not really been withdrawn, + // we have just traced from which account it should have been withdrawn. + // So we will retrieve these information and make the transfer from the origin account. + fn deposit_asset(what: &Asset, who: &Location, _context: Option<&XcmContext>) -> XcmResult { + let (contract_address, amount) = + ForeignAssetsMatcher::::matches_fungibles(what)?; + + let beneficiary = T::AccountIdConverter::convert_location(who) + .ok_or(MatchError::AccountIdConversionFailed)?; + + // We perform the evm transfers in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_mint_into(contract_address, beneficiary, amount) + })?; + + Ok(()) + } + + fn internal_transfer_asset( + asset: &Asset, + from: &Location, + to: &Location, + _context: &XcmContext, + ) -> Result { + let (contract_address, amount) = + ForeignAssetsMatcher::::matches_fungibles(asset)?; + + let from = T::AccountIdConverter::convert_location(from) + .ok_or(MatchError::AccountIdConversionFailed)?; + + let to = T::AccountIdConverter::convert_location(to) + .ok_or(MatchError::AccountIdConversionFailed)?; + + // We perform the evm transfers in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_transfer(contract_address, from, to, amount) + })?; + + Ok(asset.clone().into()) + } + + // Since we don't control the erc20 contract that manages the asset we want to withdraw, + // we can't really withdraw this asset, we can only transfer it to another account. + // It would be possible to transfer the asset to a dedicated account that would reflect + // the content of the xcm holding, but this would imply to perform two evm calls instead of + // one (1 to withdraw the asset and a second one to deposit it). + // In order to perform only one evm call, we just trace the origin of the asset, + // and then the transfer will only really be performed in the deposit instruction. + fn withdraw_asset( + what: &Asset, + who: &Location, + _context: Option<&XcmContext>, + ) -> Result { + let (contract_address, amount) = + ForeignAssetsMatcher::::matches_fungibles(what)?; + let who = T::AccountIdConverter::convert_location(who) + .ok_or(MatchError::AccountIdConversionFailed)?; + + // We perform the evm transfers in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_burn_from(contract_address, who, amount) + })?; + + Ok(what.clone().into()) + } + } } From 6c7ff351251da0bddc52491dd0ed2be670f7786d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 14 Jul 2024 18:25:02 +0200 Subject: [PATCH 06/71] implement all evm calls --- Cargo.lock | 1 + Cargo.toml | 2 + pallets/moonbeam-foreign-assets/Cargo.toml | 1 + pallets/moonbeam-foreign-assets/src/evm.rs | 250 ++++++++++++++++++--- pallets/moonbeam-foreign-assets/src/lib.rs | 93 ++++---- 5 files changed, 268 insertions(+), 79 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fbbc8941bf..41b8978e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9707,6 +9707,7 @@ dependencies = [ "pallet-balances", "pallet-evm", "parity-scale-codec", + "precompile-utils-macro", "scale-info", "serde", "sp-core", diff --git a/Cargo.toml b/Cargo.toml index 092cf8acef..4e6415d8a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -256,6 +256,8 @@ pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/f pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } precompile-utils = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +precompile-utils-macro = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } + # Frontier (client) fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index af53c84b06..b8dfc01817 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -14,6 +14,7 @@ serde = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } parity-scale-codec = { workspace = true, features = [ "derive" ] } +precompile-utils-macro = { workspace = true } scale-info = { workspace = true, features = [ "derive" ] } sp-io = { workspace = true } sp-runtime = { workspace = true } diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 171fc44e19..3d4161b6fb 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -15,28 +15,33 @@ // along with Moonbeam. If not, see . use crate::{AssetId, Error, Pallet}; -use ethereum_types::{H160, U256}; +use ethereum_types::{BigEndianHash, H160, H256, U256}; use fp_evm::{ExitReason, ExitSucceed}; use frame_support::ensure; -use pallet_evm::Runner; +use frame_support::pallet_prelude::Weight; +use pallet_evm::{GasWeightMapping, Runner}; +use precompile_utils_macro::keccak256; use sp_runtime::DispatchError; use xcm::latest::Error as XcmError; -const ERC20_CREATE_INIT_CODE_MAX_SIZE: usize = 16 * 1024; -const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; -const FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT: u64 = 500_000; -const FOREIGN_ASSET_ERC20_TRANSFER_GAS_LIMIT: u64 = 500_000; -const FOREIGN_ASSET_ERC20_MINT_INTO_GAS_LIMIT: u64 = 500_000; -const FOREIGN_ASSET_ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; -const FOREIGN_ASSET_ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; -const FOREIGN_ASSET_ERC20_UNPAUSE_GAS_LIMIT: u64 = 500_000; +const ERC20_CALL_MAX_CALLDATA_SIZE: usize = 4 + 32 + 32; // selector + address + uint256 +const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko + +// hardcoded gas limits +const ERC20_CREATE_GAS_LIMIT: u64 = 500_000; +const ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; +const ERC20_MINT_INTO_GAS_LIMIT: u64 = 50_000; +const ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; +const ERC20_TRANSFER_GAS_LIMIT: u64 = 50_000; +const ERC20_UNPAUSE_GAS_LIMIT: u64 = 500_000; pub(crate) enum EvmError { - ContractCreationFail, - ContractTransferFail, + BurnFromFail, ContractReturnInvalidValue, DispatchError(DispatchError), EvmCallFail, + MintIntoFail, + TransferFail, } impl From for EvmError { @@ -48,11 +53,8 @@ impl From for EvmError { impl From for XcmError { fn from(error: EvmError) -> XcmError { match error { - EvmError::ContractCreationFail => { - XcmError::FailedToTransactAsset("Erc20 contract transfer fail") - } - EvmError::ContractTransferFail => { - XcmError::FailedToTransactAsset("Erc20 contract transfer fail") + EvmError::BurnFromFail => { + XcmError::FailedToTransactAsset("Erc20 contract call burnFrom fail") } EvmError::ContractReturnInvalidValue => { XcmError::FailedToTransactAsset("Erc20 contract return invalid value") @@ -62,6 +64,12 @@ impl From for XcmError { Self::FailedToTransactAsset("storage layer error") } EvmError::EvmCallFail => XcmError::FailedToTransactAsset("Fail to call erc20 contract"), + EvmError::MintIntoFail => { + XcmError::FailedToTransactAsset("Erc20 contract call mintInto fail") + } + EvmError::TransferFail => { + XcmError::FailedToTransactAsset("Erc20 contract call transfer fail") + } } } } @@ -72,24 +80,18 @@ impl EvmCaller { /// Deploy foreign asset erc20 contract pub(crate) fn erc20_create(asset_id: AssetId, decimals: u8) -> Result<(), Error> { // Get init code - let mut init = Vec::with_capacity(ERC20_CREATE_INIT_CODE_MAX_SIZE); + let mut init = Vec::with_capacity(ERC20_CREATE_MAX_CALLDATA_SIZE); init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); // Add constructor parameters // (0x6D6f646c617373746d6E67720000000000000000, 18, MTT, MyBigToken) //0x0000000000000000000000006d6f646c617373746d6e677200000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 - // Compute contract address - let mut buffer = [0u8; 20]; - buffer[..4].copy_from_slice(&FOREIGN_ASSETS_PREFIX); - buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); - let contract_address = H160(buffer); - let exec_info = T::EvmRunner::create_force_address( Pallet::::account_id(), init, U256::default(), - FOREIGN_ASSET_ERC20_CREATE_GAS_LIMIT, + ERC20_CREATE_GAS_LIMIT, None, None, None, @@ -99,7 +101,7 @@ impl EvmCaller { None, None, &::config(), - contract_address, + Pallet::::contract_address_from_asset_id(asset_id), ) .map_err(|_| Error::Erc20ContractCreationFail)?; @@ -119,7 +121,44 @@ impl EvmCaller { beneficiary: H160, amount: U256, ) -> Result<(), EvmError> { - todo!() + let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); + // Selector + input.extend_from_slice(&keccak256!("mintInto(address, uint256)")[..4]); + // append beneficiary address + input.extend_from_slice(H256::from(beneficiary).as_bytes()); + // append amount to be minted + input.extend_from_slice(H256::from_uint(&amount).as_bytes()); + + let weight_limit: Weight = + T::GasWeightMapping::gas_to_weight(ERC20_MINT_INTO_GAS_LIMIT, true); + + let exec_info = T::EvmRunner::call( + Pallet::::account_id(), + erc20_contract_address, + input, + U256::default(), + ERC20_MINT_INTO_GAS_LIMIT, + None, + None, + None, + Default::default(), + false, + false, + Some(weight_limit), + Some(0), + &::config(), + ) + .map_err(|_| EvmError::EvmCallFail)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + EvmError::MintIntoFail + ); + + Ok(()) } pub(crate) fn erc20_transfer( @@ -128,7 +167,54 @@ impl EvmCaller { to: H160, amount: U256, ) -> Result<(), EvmError> { - todo!() + let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); + // Selector + input.extend_from_slice(&keccak256!("transfer(address, uint256)")[..4]); + // append receiver address + input.extend_from_slice(H256::from(to).as_bytes()); + // append amount to be transferred + input.extend_from_slice(H256::from_uint(&amount).as_bytes()); + + let weight_limit: Weight = + T::GasWeightMapping::gas_to_weight(ERC20_TRANSFER_GAS_LIMIT, true); + + let exec_info = T::EvmRunner::call( + from, + erc20_contract_address, + input, + U256::default(), + ERC20_TRANSFER_GAS_LIMIT, + None, + None, + None, + Default::default(), + false, + false, + Some(weight_limit), + Some(0), + &::config(), + ) + .map_err(|_| EvmError::EvmCallFail)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + EvmError::TransferFail + ); + + // return value is true. + let mut bytes = [0u8; 32]; + U256::from(1).to_big_endian(&mut bytes); + + // Check return value to make sure not calling on empty contracts. + ensure!( + !exec_info.value.is_empty() && exec_info.value == bytes, + EvmError::ContractReturnInvalidValue + ); + + Ok(()) } pub(crate) fn erc20_burn_from( @@ -136,16 +222,118 @@ impl EvmCaller { who: H160, amount: U256, ) -> Result<(), EvmError> { - todo!() + let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); + // Selector + input.extend_from_slice(&keccak256!("burnFrom(address, uint256)")[..4]); + // append who address + input.extend_from_slice(H256::from(who).as_bytes()); + // append amount to be burn + input.extend_from_slice(H256::from_uint(&amount).as_bytes()); + + let weight_limit: Weight = + T::GasWeightMapping::gas_to_weight(ERC20_BURN_FROM_GAS_LIMIT, true); + + let exec_info = T::EvmRunner::call( + Pallet::::account_id(), + erc20_contract_address, + input, + U256::default(), + ERC20_BURN_FROM_GAS_LIMIT, + None, + None, + None, + Default::default(), + false, + false, + Some(weight_limit), + Some(0), + &::config(), + ) + .map_err(|_| EvmError::EvmCallFail)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + EvmError::BurnFromFail + ); + + Ok(()) } // Call contract selector "pause" pub(crate) fn erc20_pause(asset_id: AssetId) -> Result<(), Error> { - todo!() + let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); + // Selector + input.extend_from_slice(&keccak256!("pause()")[..4]); + + let weight_limit: Weight = T::GasWeightMapping::gas_to_weight(ERC20_PAUSE_GAS_LIMIT, true); + + let exec_info = T::EvmRunner::call( + Pallet::::account_id(), + Pallet::::contract_address_from_asset_id(asset_id), + input, + U256::default(), + ERC20_PAUSE_GAS_LIMIT, + None, + None, + None, + Default::default(), + false, + false, + Some(weight_limit), + Some(0), + &::config(), + ) + .map_err(|_| Error::::EvmInternalError)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + Error::::EvmCallPauseFail + ); + + Ok(()) } // Call contract selector "unpause" pub(crate) fn erc20_unpause(asset_id: AssetId) -> Result<(), Error> { - todo!() + let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); + // Selector + input.extend_from_slice(&keccak256!("unpause()")[..4]); + + let weight_limit: Weight = + T::GasWeightMapping::gas_to_weight(ERC20_UNPAUSE_GAS_LIMIT, true); + + let exec_info = T::EvmRunner::call( + Pallet::::account_id(), + Pallet::::contract_address_from_asset_id(asset_id), + input, + U256::default(), + ERC20_UNPAUSE_GAS_LIMIT, + None, + None, + None, + Default::default(), + false, + false, + Some(weight_limit), + Some(0), + &::config(), + ) + .map_err(|_| Error::::EvmInternalError)?; + + ensure!( + matches!( + exec_info.exit_reason, + ExitReason::Succeed(ExitSucceed::Returned | ExitSucceed::Stopped) + ), + Error::::EvmCallUnpauseFail + ); + + Ok(()) } } diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index ed29489c98..65321740c7 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -34,9 +34,14 @@ use ethereum_types::{H160, U256}; use frame_support::pallet; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use xcm::latest::{Asset, Error as XcmError, Junction, Location, Result as XcmResult, XcmContext}; +use xcm::latest::{ + Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Junction, Location, + Result as XcmResult, XcmContext, +}; use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; +const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; + /// Trait for the OnForeignAssetRegistered hook pub trait ForeignAssetCreatedHook { fn on_asset_created(foreign_asset: &ForeignAsset, asset_id: &AssetId); @@ -57,22 +62,41 @@ impl ForeignAssetDestroyedHook for fn on_asset_destroyed(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } -pub(crate) struct ForeignAssetsMatcher( - core::marker::PhantomData, -); +pub(crate) struct ForeignAssetsMatcher(core::marker::PhantomData); -impl> MatchesFungibles - for ForeignAssetsMatcher -{ +impl MatchesFungibles for ForeignAssetsMatcher { fn matches_fungibles(asset: &Asset) -> Result<(H160, U256), MatchError> { - todo!() + let (amount, location) = match (&asset.fun, &asset.id) { + (Fungibility::Fungible(ref amount), XcmAssetId(ref location)) => (amount, location), + _ => return Err(MatchError::AssetNotHandled), + }; + + let prefix = T::ForeignAssetXcmLocationPrefix::get(); + + if prefix.parent_count() != location.parent_count() + || prefix + .interior() + .iter() + .enumerate() + .any(|(index, junction)| location.interior().at(index) != Some(junction)) + { + return Err(MatchError::AssetIdConversionFailed); + } + + match location.interior().at(prefix.interior().len()) { + Some(Junction::GeneralIndex(asset_id)) => Ok(( + Pallet::::contract_address_from_asset_id(*asset_id), + U256::from(*amount), + )), + _ => Err(MatchError::AssetIdConversionFailed), + } } } #[pallet] pub mod pallet { use super::*; - use pallet_evm::{GasWeightMapping, Runner}; + use pallet_evm::Runner; use sp_runtime::traits::{AccountIdConversion, MaybeEquivalence}; use xcm_executor::traits::ConvertLocation; use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; @@ -149,6 +173,9 @@ pub mod pallet { AssetAlreadyFrozen, AssetNotFrozen, Erc20ContractCreationFail, + EvmCallPauseFail, + EvmCallUnpauseFail, + EvmInternalError, TooManyForeignAssets, } @@ -215,11 +242,12 @@ pub mod pallet { account_id.into() } - fn start_destroy(asset_id: AssetId) -> Result<(), Error> { - // Freeze asset - EvmCaller::::erc20_pause(asset_id)?; - - todo!() + #[inline] + pub(crate) fn contract_address_from_asset_id(asset_id: AssetId) -> H160 { + let mut buffer = [0u8; 20]; + buffer[..4].copy_from_slice(&FOREIGN_ASSETS_PREFIX); + buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); + H160(buffer) } } @@ -376,34 +404,6 @@ pub mod pallet { }); Ok(()) } - - /// Destroy a given foreign assetId - #[pallet::call_index(5)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] - pub fn destroy_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { - T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; - - let foreign_asset = - AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - - // Important: this starts the destruction process, - // making sure the assets are non-transferable anymore - // make sure the destruction process is completable by other means - Self::start_destroy(asset_id.clone())?; - - // Remove from AssetIdToForeignAsset - AssetIdToForeignAsset::::remove(&asset_id); - // Remove from ForeignAssetToAssetId - ForeignAssetToAssetId::::remove(&foreign_asset); - - T::OnForeignAssetDestroyed::on_asset_destroyed(&foreign_asset, &asset_id); - - Self::deposit_event(Event::ForeignAssetDestroyed { - asset_id, - foreign_asset, - }); - Ok(()) - } } impl MaybeEquivalence for Pallet { @@ -420,8 +420,7 @@ pub mod pallet { // we have just traced from which account it should have been withdrawn. // So we will retrieve these information and make the transfer from the origin account. fn deposit_asset(what: &Asset, who: &Location, _context: Option<&XcmContext>) -> XcmResult { - let (contract_address, amount) = - ForeignAssetsMatcher::::matches_fungibles(what)?; + let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(what)?; let beneficiary = T::AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; @@ -441,8 +440,7 @@ pub mod pallet { to: &Location, _context: &XcmContext, ) -> Result { - let (contract_address, amount) = - ForeignAssetsMatcher::::matches_fungibles(asset)?; + let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(asset)?; let from = T::AccountIdConverter::convert_location(from) .ok_or(MatchError::AccountIdConversionFailed)?; @@ -471,8 +469,7 @@ pub mod pallet { who: &Location, _context: Option<&XcmContext>, ) -> Result { - let (contract_address, amount) = - ForeignAssetsMatcher::::matches_fungibles(what)?; + let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(what)?; let who = T::AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; From 26fa2450af95c7dd8896b7bf93968c5ce11112e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 14 Jul 2024 21:14:02 +0200 Subject: [PATCH 07/71] encode create args --- Cargo.lock | 1 + pallets/moonbeam-foreign-assets/Cargo.toml | 2 ++ pallets/moonbeam-foreign-assets/src/evm.rs | 29 +++++++++++++++++++--- pallets/moonbeam-foreign-assets/src/lib.rs | 9 ++++++- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 41b8978e8c..77858bdd81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9707,6 +9707,7 @@ dependencies = [ "pallet-balances", "pallet-evm", "parity-scale-codec", + "precompile-utils", "precompile-utils-macro", "scale-info", "serde", diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index b8dfc01817..60bfa58b00 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -14,6 +14,7 @@ serde = { workspace = true, optional = true } frame-support = { workspace = true } frame-system = { workspace = true } parity-scale-codec = { workspace = true, features = [ "derive" ] } +precompile-utils = { workspace = true } precompile-utils-macro = { workspace = true } scale-info = { workspace = true, features = [ "derive" ] } sp-io = { workspace = true } @@ -35,6 +36,7 @@ frame-benchmarking = { workspace = true, optional = true } hex = { workspace = true } [dev-dependencies] +hex = { workspace = true } pallet-balances = { workspace = true, features = [ "std" ] } pallet-assets = { workspace = true, features = [ "std" ] } sp-core = { workspace = true, features = [ "std" ] } diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 3d4161b6fb..715c2d1d34 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -20,6 +20,7 @@ use fp_evm::{ExitReason, ExitSucceed}; use frame_support::ensure; use frame_support::pallet_prelude::Weight; use pallet_evm::{GasWeightMapping, Runner}; +use precompile_utils::solidity::Codec; use precompile_utils_macro::keccak256; use sp_runtime::DispatchError; use xcm::latest::Error as XcmError; @@ -74,18 +75,40 @@ impl From for XcmError { } } +use precompile_utils::solidity::codec::{Address, BoundedString}; +use sp_runtime::traits::ConstU32; + +#[derive(Codec)] +struct ForeignErc20ConstructorArgs { + owner: Address, + decimals: u8, + ticker: BoundedString>, + token_name: BoundedString>, +} + pub(crate) struct EvmCaller(core::marker::PhantomData); impl EvmCaller { /// Deploy foreign asset erc20 contract - pub(crate) fn erc20_create(asset_id: AssetId, decimals: u8) -> Result<(), Error> { + pub(crate) fn erc20_create( + asset_id: AssetId, + decimals: u8, + ticker: &str, + token_name: &str, + ) -> Result<(), Error> { // Get init code let mut init = Vec::with_capacity(ERC20_CREATE_MAX_CALLDATA_SIZE); init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); // Add constructor parameters - // (0x6D6f646c617373746d6E67720000000000000000, 18, MTT, MyBigToken) - //0x0000000000000000000000006d6f646c617373746d6e677200000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 + let args = ForeignErc20ConstructorArgs { + owner: Pallet::::account_id().into(), + decimals, + ticker: ticker.into(), + token_name: token_name.into(), + }; + let encoded_args = precompile_utils::solidity::codec::Writer::new().write(args).build(); + init.extend(encoded_args); let exec_info = T::EvmRunner::create_force_address( Pallet::::account_id(), diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 65321740c7..a4910f00e8 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -176,6 +176,8 @@ pub mod pallet { EvmCallPauseFail, EvmCallUnpauseFail, EvmInternalError, + InvalidTicker, + InvalidTokenName, TooManyForeignAssets, } @@ -261,6 +263,8 @@ pub mod pallet { foreign_asset: T::ForeignAsset, asset_id: AssetId, decimals: u8, + ticker: BoundedVec>, + name: BoundedVec>, ) -> DispatchResult { T::ForeignAssetCreatorOrigin::ensure_origin(origin)?; @@ -275,8 +279,11 @@ pub mod pallet { Error::::TooManyForeignAssets ); + let ticker = core::str::from_utf8(&ticker).map_err(|_| Error::::InvalidTicker)?; + let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; + // TODO submit create eth-xcm call - EvmCaller::::erc20_create(asset_id, decimals)?; + EvmCaller::::erc20_create(asset_id, decimals, ticker, name)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId From 5ae81cf714c33484034066ba1078793fc49206b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 12:08:38 +0200 Subject: [PATCH 08/71] build contract initcode: support 0x prefix --- pallets/moonbeam-foreign-assets/build.rs | 10 ++++++++-- pallets/moonbeam-foreign-assets/src/evm.rs | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs index da3bedd7a6..c0ee41bacd 100644 --- a/pallets/moonbeam-foreign-assets/build.rs +++ b/pallets/moonbeam-foreign-assets/build.rs @@ -2,8 +2,14 @@ use std::fs::File; use std::io::prelude::*; fn main() { - let bytecode = hex::decode(include_str!("resources/foreign_erc20_initcode.hex")) - .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); + let hex_str = include_str!("resources/foreign_erc20_initcode.hex"); + let prefix_0x = hex_str.chars().nth(1) == Some('x'); + let bytecode = if prefix_0x { + hex::decode(&hex_str[2..]) + } else { + hex::decode(hex_str) + } + .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); let mut file = File::create("resources/foreign_erc20_initcode.bin") .expect("Fail to create file resources/foreign_erc20_initcode.bin"); diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 715c2d1d34..9a9abc7f2d 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -20,8 +20,10 @@ use fp_evm::{ExitReason, ExitSucceed}; use frame_support::ensure; use frame_support::pallet_prelude::Weight; use pallet_evm::{GasWeightMapping, Runner}; +use precompile_utils::solidity::codec::{Address, BoundedString}; use precompile_utils::solidity::Codec; use precompile_utils_macro::keccak256; +use sp_runtime::traits::ConstU32; use sp_runtime::DispatchError; use xcm::latest::Error as XcmError; @@ -75,9 +77,6 @@ impl From for XcmError { } } -use precompile_utils::solidity::codec::{Address, BoundedString}; -use sp_runtime::traits::ConstU32; - #[derive(Codec)] struct ForeignErc20ConstructorArgs { owner: Address, @@ -107,7 +106,9 @@ impl EvmCaller { ticker: ticker.into(), token_name: token_name.into(), }; - let encoded_args = precompile_utils::solidity::codec::Writer::new().write(args).build(); + let encoded_args = precompile_utils::solidity::codec::Writer::new() + .write(args) + .build(); init.extend(encoded_args); let exec_info = T::EvmRunner::create_force_address( From e94037f384ae132adf33284b1698cabd03d18c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 13:43:36 +0200 Subject: [PATCH 09/71] fix ethereum-xcm rust tests --- pallets/ethereum-xcm/src/mock.rs | 1 + pallets/ethereum-xcm/src/tests/v1/eip1559.rs | 2 +- pallets/ethereum-xcm/src/tests/v1/eip2930.rs | 2 +- pallets/ethereum-xcm/src/tests/v1/legacy.rs | 2 +- pallets/ethereum-xcm/src/tests/v2.rs | 2 +- primitives/xcm/src/ethereum_xcm.rs | 20 ++++++++++++++++---- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pallets/ethereum-xcm/src/mock.rs b/pallets/ethereum-xcm/src/mock.rs index 2c6260a3f0..82d87a55d6 100644 --- a/pallets/ethereum-xcm/src/mock.rs +++ b/pallets/ethereum-xcm/src/mock.rs @@ -284,6 +284,7 @@ impl crate::Config for Test { type ReservedXcmpWeight = ReservedXcmpWeight; type EnsureProxy = EthereumXcmEnsureProxy; type ControllerOrigin = EnsureRoot; + type ForceOrigin = EnsureRoot; } impl fp_self_contained::SelfContainedCall for RuntimeCall { diff --git a/pallets/ethereum-xcm/src/tests/v1/eip1559.rs b/pallets/ethereum-xcm/src/tests/v1/eip1559.rs index 6dd0103c7c..a6f62c88a3 100644 --- a/pallets/ethereum-xcm/src/tests/v1/eip1559.rs +++ b/pallets/ethereum-xcm/src/tests/v1/eip1559.rs @@ -150,7 +150,7 @@ fn test_transact_xcm_evm_call_works() { input: hex::decode(CONTRACT).unwrap(), } .sign(&alice.private_key, None); - assert_ok!(Ethereum::execute(alice.address, &t, None,)); + assert_ok!(Ethereum::execute(alice.address, &t, None, None)); let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap(); let foo = hex::decode("c2985578").unwrap(); diff --git a/pallets/ethereum-xcm/src/tests/v1/eip2930.rs b/pallets/ethereum-xcm/src/tests/v1/eip2930.rs index d061b72a0c..380373b65c 100644 --- a/pallets/ethereum-xcm/src/tests/v1/eip2930.rs +++ b/pallets/ethereum-xcm/src/tests/v1/eip2930.rs @@ -162,7 +162,7 @@ fn test_transact_xcm_evm_call_works() { input: hex::decode(CONTRACT).unwrap(), } .sign(&alice.private_key, None); - assert_ok!(Ethereum::execute(alice.address, &t, None,)); + assert_ok!(Ethereum::execute(alice.address, &t, None, None)); let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap(); let foo = hex::decode("c2985578").unwrap(); diff --git a/pallets/ethereum-xcm/src/tests/v1/legacy.rs b/pallets/ethereum-xcm/src/tests/v1/legacy.rs index 55528fc16b..de3de3d6f8 100644 --- a/pallets/ethereum-xcm/src/tests/v1/legacy.rs +++ b/pallets/ethereum-xcm/src/tests/v1/legacy.rs @@ -159,7 +159,7 @@ fn test_transact_xcm_evm_call_works() { input: hex::decode(CONTRACT).unwrap(), } .sign(&alice.private_key); - assert_ok!(Ethereum::execute(alice.address, &t, None,)); + assert_ok!(Ethereum::execute(alice.address, &t, None, None)); let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap(); let foo = hex::decode("c2985578").unwrap(); diff --git a/pallets/ethereum-xcm/src/tests/v2.rs b/pallets/ethereum-xcm/src/tests/v2.rs index 43b48fcdcf..c928f5d033 100644 --- a/pallets/ethereum-xcm/src/tests/v2.rs +++ b/pallets/ethereum-xcm/src/tests/v2.rs @@ -146,7 +146,7 @@ fn test_transact_xcm_evm_call_works() { input: hex::decode(CONTRACT).unwrap(), } .sign(&alice.private_key, None); - assert_ok!(Ethereum::execute(alice.address, &t, None,)); + assert_ok!(Ethereum::execute(alice.address, &t, None, None)); let contract_address = hex::decode("32dcab0ef3fb2de2fce1d2e0799d36239671f04a").unwrap(); let foo = hex::decode("c2985578").unwrap(); diff --git a/primitives/xcm/src/ethereum_xcm.rs b/primitives/xcm/src/ethereum_xcm.rs index 3ead0685e4..ba1e13f7d0 100644 --- a/primitives/xcm/src/ethereum_xcm.rs +++ b/primitives/xcm/src/ethereum_xcm.rs @@ -293,7 +293,10 @@ mod tests { s: H256::from_low_u64_be(1u64), })); - assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx); + assert_eq!( + xcm_transaction.into_transaction_v2(nonce, 111, false), + expected_tx + ); } #[test] @@ -321,7 +324,10 @@ mod tests { signature: TransactionSignature::new(42, rs_id(), rs_id()).unwrap(), })); - assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx); + assert_eq!( + xcm_transaction.into_transaction_v2(nonce, 111, false), + expected_tx + ); } #[test] fn test_eip_2930_v1() { @@ -363,7 +369,10 @@ mod tests { s: H256::from_low_u64_be(1u64), })); - assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx); + assert_eq!( + xcm_transaction.into_transaction_v2(nonce, 111, false), + expected_tx + ); } #[test] @@ -392,6 +401,9 @@ mod tests { s: H256::from_low_u64_be(1u64), })); - assert_eq!(xcm_transaction.into_transaction_v2(nonce, 111), expected_tx); + assert_eq!( + xcm_transaction.into_transaction_v2(nonce, 111, false), + expected_tx + ); } } From f416d5dc5782a905865c7ee06c70840d07e6d4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 14:04:48 +0200 Subject: [PATCH 10/71] pallet moonbeam-foreign-assets: prepare rust tests --- Cargo.lock | 2 +- pallets/moonbeam-foreign-assets/Cargo.toml | 2 +- pallets/moonbeam-foreign-assets/src/lib.rs | 34 ++-- pallets/moonbeam-foreign-assets/src/mock.rs | 188 ++++++++++--------- pallets/moonbeam-foreign-assets/src/tests.rs | 151 ++++++--------- 5 files changed, 171 insertions(+), 206 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77858bdd81..3d5e81f9d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9703,9 +9703,9 @@ dependencies = [ "frame-system", "hex", "log", - "pallet-assets", "pallet-balances", "pallet-evm", + "pallet-timestamp", "parity-scale-codec", "precompile-utils", "precompile-utils-macro", diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index 60bfa58b00..9f31dd031c 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -38,7 +38,7 @@ hex = { workspace = true } [dev-dependencies] hex = { workspace = true } pallet-balances = { workspace = true, features = [ "std" ] } -pallet-assets = { workspace = true, features = [ "std" ] } +pallet-timestamp = { workspace = true, features = [ "std" ] } sp-core = { workspace = true, features = [ "std" ] } [features] diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index a4910f00e8..a2a967b9c6 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -43,22 +43,20 @@ use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; /// Trait for the OnForeignAssetRegistered hook -pub trait ForeignAssetCreatedHook { +pub trait ForeignAssetCreatedHook { fn on_asset_created(foreign_asset: &ForeignAsset, asset_id: &AssetId); } -impl - ForeignAssetCreatedHook for () -{ +impl ForeignAssetCreatedHook for () { fn on_asset_created(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } /// Trait for the OnForeignAssetDeregistered hook -pub trait ForeignAssetDestroyedHook { +pub trait ForeignAssetDestroyedHook { fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId); } -impl ForeignAssetDestroyedHook for () { +impl ForeignAssetDestroyedHook for () { fn on_asset_destroyed(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } @@ -80,15 +78,21 @@ impl MatchesFungibles for ForeignAssetsMatcher .enumerate() .any(|(index, junction)| location.interior().at(index) != Some(junction)) { - return Err(MatchError::AssetIdConversionFailed); + return Err(MatchError::AssetNotHandled); } - match location.interior().at(prefix.interior().len()) { - Some(Junction::GeneralIndex(asset_id)) => Ok(( + let asset_id = match location.interior().at(prefix.interior().len()) { + Some(Junction::GeneralIndex(asset_id)) => asset_id, + _ => return Err(MatchError::AssetNotHandled), + }; + + if AssetIdToForeignAsset::::contains_key(&asset_id) { + Ok(( Pallet::::contract_address_from_asset_id(*asset_id), U256::from(*amount), - )), - _ => Err(MatchError::AssetIdConversionFailed), + )) + } else { + Err(MatchError::AssetNotHandled) } } } @@ -143,14 +147,10 @@ pub mod pallet { type ForeignAssetDestroyerOrigin: EnsureOrigin; /// Hook to be called when new foreign asset is registered. - type OnForeignAssetCreated: ForeignAssetCreatedHook< - Self::ForeignAsset, - AssetId, - AssetBalance, - >; + type OnForeignAssetCreated: ForeignAssetCreatedHook; /// Hook to be called when foreign asset is de-registered. - type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; + type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; /// Maximum nulmbers of differnt foreign assets type MaxForeignAssets: Get; diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 6ff2fcdd5e..0fd3b153ae 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -15,63 +15,63 @@ // along with Moonkit. If not, see . use super::*; -use crate as pallet_foreign_asset_creator; -use std::marker::PhantomData; +use crate as pallet_moonbeam_foreign_assets; -use frame_support::{ - construct_runtime, parameter_types, storage, - traits::{ConstU32, Everything}, -}; +use frame_support::traits::Everything; +use frame_support::{construct_runtime, pallet_prelude::*, parameter_types}; use frame_system::EnsureRoot; -use parity_scale_codec::{Decode, Encode}; -use sp_core::H256; +use pallet_evm::SubstrateBlockHashMapping; +use precompile_utils::testing::{Bob, Charlie, MockAccount}; +use sp_core::{H256, U256}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use sp_runtime::BuildStorage; -use xcm::latest::prelude::*; +use xcm::latest::Location; -type Block = frame_system::mocking::MockBlock; +pub type Balance = u128; -pub type AccountId = u64; -pub type Balance = u64; +type AccountId = MockAccount; +type Block = frame_system::mocking::MockBlock; construct_runtime!( pub enum Test { System: frame_system, Balances: pallet_balances, - ForeignAssetCreator: pallet_foreign_asset_creator, - Assets: pallet_assets, + Timestamp: pallet_timestamp, + EVM: pallet_evm, + EvmForeignAssets: pallet_moonbeam_foreign_assets, } ); parameter_types! { pub const BlockHashCount: u32 = 250; } + impl frame_system::Config for Test { type BaseCallFilter = Everything; - type BlockWeights = (); - type BlockLength = (); + type DbWeight = (); type RuntimeOrigin = RuntimeOrigin; - type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; type Nonce = u64; type Block = Block; + type RuntimeCall = RuntimeCall; type Hash = H256; type Hashing = BlakeTwo256; type AccountId = AccountId; type Lookup = IdentityLookup; type RuntimeEvent = RuntimeEvent; type BlockHashCount = BlockHashCount; - type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; + type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); type SystemWeightInfo = (); + type BlockWeights = (); + type BlockLength = (); type SS58Prefix = (); type OnSetCode = (); type MaxConsumers = frame_support::traits::ConstU32<16>; - type RuntimeTask = (); type SingleBlockMigrations = (); type MultiBlockMigrator = (); type PreInherents = (); @@ -80,94 +80,104 @@ impl frame_system::Config for Test { } parameter_types! { - pub const ExistentialDeposit: u64 = 1; + pub const ExistentialDeposit: u128 = 0; } - impl pallet_balances::Config for Test { + type MaxReserves = (); + type ReserveIdentifier = [u8; 4]; + type MaxLocks = (); type Balance = Balance; - type DustRemoval = (); type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); type ExistentialDeposit = ExistentialDeposit; type AccountStore = System; type WeightInfo = (); - type MaxLocks = (); - type MaxReserves = (); - type ReserveIdentifier = [u8; 8]; type RuntimeHoldReason = (); - type RuntimeFreezeReason = (); type FreezeIdentifier = (); type MaxFreezes = (); + type RuntimeFreezeReason = (); } parameter_types! { - pub const AssetDeposit: u64 = 0; - pub const ApprovalDeposit: u64 = 0; - pub const StringLimit: u32 = 50; - pub const MetadataDepositBase: u64 = 0; - pub const MetadataDepositPerByte: u64 = 0; + pub const MinimumPeriod: u64 = 6000 / 2; } -type AssetId = u32; +impl pallet_timestamp::Config for Test { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} -impl pallet_assets::Config for Test { - type RuntimeEvent = RuntimeEvent; - type Balance = Balance; - type AssetId = AssetId; - type AssetIdParameter = parity_scale_codec::Compact; +const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; +/// Block storage limit in bytes. Set to 40 KB. +const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024; + +parameter_types! { + pub BlockGasLimit: U256 = U256::from(u64::MAX); + pub const WeightPerGas: Weight = Weight::from_parts(1, 0); + pub GasLimitPovSizeRatio: u64 = { + let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); + block_gas_limit.saturating_div(MAX_POV_SIZE) + }; + pub GasLimitStorageGrowthRatio: u64 = { + let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); + block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT) + }; +} + +impl pallet_evm::Config for Test { + type FeeCalculator = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type CallOrigin = pallet_evm::EnsureAddressRoot; + type WithdrawOrigin = pallet_evm::EnsureAddressNever; + type AddressMapping = AccountId; type Currency = Balances; - type CreateOrigin = frame_support::traits::NeverEnsureOrigin; - type ForceOrigin = EnsureRoot; - type AssetDeposit = AssetDeposit; - type AssetAccountDeposit = AssetDeposit; - type MetadataDepositBase = MetadataDepositBase; - type MetadataDepositPerByte = MetadataDepositPerByte; - type ApprovalDeposit = ApprovalDeposit; - type StringLimit = StringLimit; - type Freezer = (); - type Extra = (); - type CallbackHandle = (); - type WeightInfo = (); - type RemoveItemsLimit = ConstU32<1000>; - pallet_assets::runtime_benchmarks_enabled! { - type BenchmarkHelper = (); - } + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = (); + type PrecompilesValue = (); + type Runner = pallet_evm::runner::stack::Runner; + type ChainId = (); + type BlockGasLimit = BlockGasLimit; + type OnChargeTransaction = (); + type FindAuthor = (); + type BlockHashMapping = SubstrateBlockHashMapping; + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; } /// Gets parameters of last `ForeignAssetCreatedHook::on_asset_created` hook invocation -pub fn get_asset_created_hook_invocation< - ForeignAsset: Decode, - AssetId: Decode, - AssetBalance: Decode, ->() -> Option<(ForeignAsset, AssetId, AssetBalance)> { +pub fn get_asset_created_hook_invocation() -> Option<(ForeignAsset, AssetId)> +{ storage::unhashed::get_raw(b"____on_foreign_asset_created") .map(|output| Decode::decode(&mut output.as_slice()).expect("Decoding should work")) } /// Notes down parameters of current `ForeignAssetCreatedHook::on_asset_created` hook invocation -fn note_on_asset_created_hook_invocation< - ForeignAsset: Encode, - AssetId: Encode, - AssetBalance: Encode, ->( +fn note_on_asset_created_hook_invocation( foreign_asset: &ForeignAsset, asset_id: &AssetId, - min_balance: &AssetBalance, ) { storage::unhashed::put_raw( b"____on_foreign_asset_created", - (foreign_asset, asset_id, min_balance).encode().as_slice(), + (foreign_asset, asset_id).encode().as_slice(), ); } /// Gets parameters of last `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation -pub fn get_asset_destroyed_hook_invocation( -) -> Option<(ForeignAsset, AssetId)> { +pub fn get_asset_destroyed_hook_invocation() -> Option<(ForeignAsset, AssetId)> +{ storage::unhashed::get_raw(b"____on_foreign_asset_destroyed") .map(|output| Decode::decode(&mut output.as_slice()).expect("Decoding should work")) } /// Notes down parameters of current `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation -fn note_on_asset_destroyed_hook_invocation( +fn note_on_asset_destroyed_hook_invocation( foreign_asset: &ForeignAsset, asset_id: &AssetId, ) { @@ -178,42 +188,36 @@ fn note_on_asset_destroyed_hook_invocation( - PhantomData<(ForeignAsset, AssetId, AssetBalance)>, -); +pub struct NoteDownHook(PhantomData); -impl - ForeignAssetCreatedHook - for NoteDownHook -{ - fn on_asset_created( - foreign_asset: &ForeignAsset, - asset_id: &AssetId, - min_balance: &AssetBalance, - ) { - note_on_asset_created_hook_invocation(foreign_asset, asset_id, min_balance); +impl ForeignAssetCreatedHook for NoteDownHook { + fn on_asset_created(foreign_asset: &ForeignAsset, asset_id: &AssetId) { + note_on_asset_created_hook_invocation(foreign_asset, asset_id); } } -impl - ForeignAssetDestroyedHook - for NoteDownHook -{ +impl ForeignAssetDestroyedHook for NoteDownHook { fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId) { note_on_asset_destroyed_hook_invocation(foreign_asset, asset_id); } } -impl Config for Test { - type RuntimeEvent = RuntimeEvent; +impl crate::Config for Test { + type AccountId = AccountId; + type AccountIdConverter = (); + type EvmRunner = pallet_evm::runner::stack::Runner; type ForeignAsset = Location; type ForeignAssetCreatorOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; + type ForeignAssetFreezerOrigin = EnsureRoot; + type ForeignAssetUnfreezerOrigin = EnsureRoot; type ForeignAssetDestroyerOrigin = EnsureRoot; - type Fungibles = Assets; + type ForeignAssetXcmLocationPrefix = (); + type OnForeignAssetCreated = NoteDownHook; + type OnForeignAssetDestroyed = NoteDownHook; + type MaxForeignAssets = ConstU32<3>; + type RuntimeEvent = RuntimeEvent; type WeightInfo = (); - type OnForeignAssetCreated = NoteDownHook; - type OnForeignAssetDestroyed = NoteDownHook; } pub(crate) struct ExtBuilder { @@ -249,7 +253,7 @@ pub(crate) fn events() -> Vec> { .into_iter() .map(|r| r.event) .filter_map(|e| { - if let RuntimeEvent::ForeignAssetCreator(inner) = e { + if let RuntimeEvent::EvmForeignAssets(inner) = e { Some(inner) } else { None diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index f475b582c3..c02949223a 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -17,26 +17,35 @@ use crate::*; use mock::*; use frame_support::{assert_noop, assert_ok}; +use precompile_utils::testing::{Bob, Charlie, MockAccount}; use xcm::latest::prelude::*; +fn encode_ticker(str_: &str) -> BoundedVec> { + BoundedVec::try_from(str_.as_bytes().to_vec()).expect("too long") +} + +fn encode_token_name(str_: &str) -> BoundedVec> { + BoundedVec::try_from(str_.as_bytes().to_vec()).expect("too long") +} + #[test] fn creating_foreign_works() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(ForeignAssetCreator::create_foreign_asset( + assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), )); assert_eq!( - ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + EvmForeignAssets::foreign_asset_for_id(1).unwrap(), Location::parent() ); assert_eq!( - ForeignAssetCreator::asset_id_for_foreign(Location::parent()).unwrap(), + EvmForeignAssets::asset_id_for_foreign(Location::parent()).unwrap(), 1 ); expect_events(vec![crate::Event::ForeignAssetCreated { @@ -44,38 +53,36 @@ fn creating_foreign_works() { foreign_asset: Location::parent(), }]); - let (foreign_asset, asset_id, min_balance): (Location, u32, u64) = - get_asset_created_hook_invocation() - .expect("Decoding of invocation data should not fail"); + let (foreign_asset, asset_id): (Location, u128) = get_asset_created_hook_invocation() + .expect("Decoding of invocation data should not fail"); assert_eq!(foreign_asset, Location::parent()); - assert_eq!(asset_id, 1u32); - assert_eq!(min_balance, 1u64); + assert_eq!(asset_id, 1u128); }); } #[test] fn test_asset_exists_error() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(ForeignAssetCreator::create_foreign_asset( + assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), )); assert_eq!( - ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + EvmForeignAssets::foreign_asset_for_id(1).unwrap(), Location::parent() ); assert_noop!( - ForeignAssetCreator::create_foreign_asset( + EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), ), Error::::AssetAlreadyExists ); @@ -86,20 +93,20 @@ fn test_asset_exists_error() { fn test_regular_user_cannot_call_extrinsics() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - ForeignAssetCreator::create_foreign_asset( - RuntimeOrigin::signed(1), + EvmForeignAssets::create_foreign_asset( + RuntimeOrigin::signed(Bob.into()), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), ), sp_runtime::DispatchError::BadOrigin ); assert_noop!( - ForeignAssetCreator::change_existing_asset_type( - RuntimeOrigin::signed(1), + EvmForeignAssets::change_existing_asset_type( + RuntimeOrigin::signed(Bob.into()), 1, Location::parent() ), @@ -111,16 +118,16 @@ fn test_regular_user_cannot_call_extrinsics() { #[test] fn test_root_can_change_foreign_asset_for_asset_id() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(ForeignAssetCreator::create_foreign_asset( + assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), )); - assert_ok!(ForeignAssetCreator::change_existing_asset_type( + assert_ok!(EvmForeignAssets::change_existing_asset_type( RuntimeOrigin::root(), 1, Location::here() @@ -128,16 +135,16 @@ fn test_root_can_change_foreign_asset_for_asset_id() { // New associations are stablished assert_eq!( - ForeignAssetCreator::foreign_asset_for_id(1).unwrap(), + EvmForeignAssets::foreign_asset_for_id(1).unwrap(), Location::here() ); assert_eq!( - ForeignAssetCreator::asset_id_for_foreign(Location::here()).unwrap(), + EvmForeignAssets::asset_id_for_foreign(Location::here()).unwrap(), 1 ); // Old ones are deleted - assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); + assert!(EvmForeignAssets::asset_id_for_foreign(Location::parent()).is_none()); expect_events(vec![ crate::Event::ForeignAssetCreated { @@ -156,7 +163,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() { fn test_asset_id_non_existent_error() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - ForeignAssetCreator::change_existing_asset_type( + EvmForeignAssets::change_existing_asset_type( RuntimeOrigin::root(), 1, Location::parent() @@ -169,23 +176,23 @@ fn test_asset_id_non_existent_error() { #[test] fn test_root_can_remove_asset_association() { ExtBuilder::default().build().execute_with(|| { - assert_ok!(ForeignAssetCreator::create_foreign_asset( + assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, + 1, + 18, + encode_ticker("MTT"), + encode_token_name("Mytoken"), )); - assert_ok!(ForeignAssetCreator::remove_existing_asset_type( + assert_ok!(EvmForeignAssets::remove_existing_asset_type( RuntimeOrigin::root(), 1 )); // Mappings are deleted - assert!(ForeignAssetCreator::foreign_asset_for_id(1).is_none()); - assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); + assert!(EvmForeignAssets::foreign_asset_for_id(1).is_none()); + assert!(EvmForeignAssets::asset_id_for_foreign(Location::parent()).is_none()); expect_events(vec![ crate::Event::ForeignAssetCreated { @@ -199,49 +206,3 @@ fn test_root_can_remove_asset_association() { ]) }); } - -#[test] -fn test_destroy_foreign_asset_also_removes_everything() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(ForeignAssetCreator::create_foreign_asset( - RuntimeOrigin::root(), - Location::parent(), - 1u32.into(), - 1u32.into(), - true, - 1u64, - )); - - let (foreign_asset, asset_id, min_balance): (Location, u32, u64) = - get_asset_created_hook_invocation() - .expect("Decoding of invocation data should not fail"); - assert_eq!(foreign_asset, Location::parent()); - assert_eq!(asset_id, 1u32); - assert_eq!(min_balance, 1u64); - - assert_ok!(ForeignAssetCreator::destroy_foreign_asset( - RuntimeOrigin::root(), - 1 - )); - - // Mappings are deleted - assert!(ForeignAssetCreator::asset_id_for_foreign(Location::parent()).is_none()); - assert!(ForeignAssetCreator::foreign_asset_for_id(1).is_none()); - - expect_events(vec![ - crate::Event::ForeignAssetCreated { - asset_id: 1, - foreign_asset: Location::parent(), - }, - crate::Event::ForeignAssetDestroyed { - asset_id: 1, - foreign_asset: Location::parent(), - }, - ]); - - let (foreign_asset, asset_id): (Location, u32) = get_asset_destroyed_hook_invocation() - .expect("Decoding of invocation data should not fail"); - assert_eq!(foreign_asset, Location::parent()); - assert_eq!(asset_id, 1u32); - }); -} From 56bf81505523cda9039d4aae1e761ea81335a054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 14:49:41 +0200 Subject: [PATCH 11/71] add pallet moonbeam-foreign-assets for moonbase runtime --- Cargo.lock | 1 + pallets/moonbeam-foreign-assets/Cargo.toml | 8 +++---- pallets/moonbeam-foreign-assets/src/evm.rs | 2 ++ pallets/moonbeam-foreign-assets/src/lib.rs | 1 + runtime/moonbase/Cargo.toml | 2 ++ runtime/moonbase/src/lib.rs | 1 + runtime/moonbase/src/xcm_config.rs | 28 ++++++++++++++++++---- runtime/moonbeam/src/lib.rs | 2 ++ runtime/moonbeam/src/xcm_config.rs | 2 +- runtime/moonriver/src/xcm_config.rs | 2 +- 10 files changed, 39 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d5e81f9d3..edfed48fca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6367,6 +6367,7 @@ dependencies = [ "pallet-maintenance-mode", "pallet-message-queue", "pallet-migrations", + "pallet-moonbeam-foreign-assets", "pallet-moonbeam-lazy-migrations", "pallet-moonbeam-orbiters", "pallet-multisig", diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index 9f31dd031c..712253fae9 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -26,14 +26,14 @@ fp-evm = { workspace = true } pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } # Polkadot -xcm = { workspace = true, optional = true } -xcm-executor = { workspace = true, optional = true } +xcm = { workspace = true } +xcm-executor = { workspace = true } # Benchmarks frame-benchmarking = { workspace = true, optional = true } [build-dependencies] -hex = { workspace = true } +hex = { workspace = true, features = [ "std" ] } [dev-dependencies] hex = { workspace = true } @@ -58,5 +58,5 @@ std = [ "xcm-executor/std" ] -runtime-benchmarks = [ "frame-benchmarking", "xcm"] +runtime-benchmarks = [ "frame-benchmarking"] try-runtime = [ "frame-support/try-runtime" ] diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 9a9abc7f2d..d40881979e 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -20,11 +20,13 @@ use fp_evm::{ExitReason, ExitSucceed}; use frame_support::ensure; use frame_support::pallet_prelude::Weight; use pallet_evm::{GasWeightMapping, Runner}; +use precompile_utils::prelude::*; use precompile_utils::solidity::codec::{Address, BoundedString}; use precompile_utils::solidity::Codec; use precompile_utils_macro::keccak256; use sp_runtime::traits::ConstU32; use sp_runtime::DispatchError; +use sp_std::vec::Vec; use xcm::latest::Error as XcmError; const ERC20_CALL_MAX_CALLDATA_SIZE: usize = 4 + 32 + 32; // selector + address + uint256 diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index a2a967b9c6..960e84eac6 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -34,6 +34,7 @@ use ethereum_types::{H160, U256}; use frame_support::pallet; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; +use sp_std::vec::Vec; use xcm::latest::{ Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Junction, Location, Result as XcmResult, XcmContext, diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 9713c61eed..3b292bcb49 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -37,6 +37,7 @@ pallet-ethereum-xcm = { workspace = true } pallet-evm-chain-id = { workspace = true } pallet-maintenance-mode = { workspace = true, features = ["xcm-support"] } pallet-migrations = { workspace = true } +pallet-moonbeam-foreign-assets = { workspace = true } pallet-moonbeam-lazy-migrations = { workspace = true } pallet-moonbeam-orbiters = { workspace = true } pallet-parachain-staking = { workspace = true } @@ -263,6 +264,7 @@ std = [ "pallet-identity/std", "pallet-maintenance-mode/std", "pallet-migrations/std", + "pallet-moonbeam-foreign-assets/std", "pallet-moonbeam-lazy-migrations/std", "pallet-moonbeam-orbiters/std", "pallet-multisig/std", diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index ec18751f1f..7e91abe345 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -1440,6 +1440,7 @@ construct_runtime! { PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 53, MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 54, EmergencyParaXcm: pallet_emergency_para_xcm::{Pallet, Call, Storage, Event} = 55, + EvmForeignAssets: pallet_moonbeam_foreign_assets::{Pallet, Call, Storage, Event} = 56, } } diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index d6ae2444ce..0ef9872d83 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -19,9 +19,9 @@ use super::{ governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees, - EmergencyParaXcm, Erc20XcmBridge, MaintenanceMode, MessageQueue, ParachainInfo, - ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, - RuntimeOrigin, Treasury, XcmpQueue, + EmergencyParaXcm, Erc20XcmBridge, EvmForeignAssets, MaintenanceMode, MessageQueue, + ParachainInfo, ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights, + RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, XcmpQueue, }; use crate::OpenTechCommitteeInstance; use moonbeam_runtime_common::weights as moonbeam_weights; @@ -169,8 +169,9 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 pub type AssetTransactors = ( LocalAssetTransactor, - ForeignFungiblesTransactor, Erc20XcmBridge, + EvmForeignAssets, + ForeignFungiblesTransactor, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, @@ -709,6 +710,25 @@ impl pallet_erc20_xcm_bridge::Config for Runtime { type EvmRunner = EvmRunnerPrecompileOrEthXcm; } +impl pallet_moonbeam_foreign_assets::Config for Runtime { + type AccountId = AccountId; + type AccountIdConverter = LocationToH160; + type EvmRunner = EvmRunnerPrecompileOrEthXcm; + type ForeignAsset = Location; + type ForeignAssetCreatorOrigin = EnsureRoot; + type ForeignAssetModifierOrigin = EnsureRoot; + type ForeignAssetFreezerOrigin = EnsureRoot; + type ForeignAssetUnfreezerOrigin = EnsureRoot; + type ForeignAssetDestroyerOrigin = EnsureRoot; + type ForeignAssetXcmLocationPrefix = (); + type OnForeignAssetCreated = (); + type OnForeignAssetDestroyed = (); + type MaxForeignAssets = ConstU32<256>; + type RuntimeEvent = RuntimeEvent; + // TODO generate weights + type WeightInfo = (); +} + #[cfg(feature = "runtime-benchmarks")] mod testing { use super::*; diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 4a3ec5aaad..905f0ce0ab 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -1454,6 +1454,8 @@ construct_runtime! { Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110, MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 111, RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112, + + // TODO should not be included in production PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 113, // Randomness diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index 7f4e304916..7731ce85db 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -158,8 +158,8 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // We use all transactors pub type AssetTransactors = ( LocalAssetTransactor, - ForeignFungiblesTransactor, Erc20XcmBridge, + ForeignFungiblesTransactor, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index 60bc065dbd..df5bf940ab 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -166,8 +166,8 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 pub type AssetTransactors = ( LocalAssetTransactor, - ForeignFungiblesTransactor, Erc20XcmBridge, + ForeignFungiblesTransactor, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, From 27903c292fb3a6ceab2e0fecbb5f8089a9e20ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 18:17:13 +0200 Subject: [PATCH 12/71] disable creation of foreign assets from pallet asset manager --- runtime/moonbase/src/asset_config.rs | 30 ++++++++-------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/runtime/moonbase/src/asset_config.rs b/runtime/moonbase/src/asset_config.rs index 27b87c4c3a..c04bd7caf4 100644 --- a/runtime/moonbase/src/asset_config.rs +++ b/runtime/moonbase/src/asset_config.rs @@ -20,7 +20,7 @@ use crate::OpenTechCommitteeInstance; use super::{ - currency, governance, xcm_config, AccountId, AssetId, AssetManager, Assets, Balance, Balances, + currency, governance, xcm_config, AccountId, AssetId, Assets, Balance, Balances, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, }; @@ -116,28 +116,14 @@ use frame_support::{pallet_prelude::DispatchResult, transactional}; impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { #[transactional] fn create_foreign_asset( - asset: AssetId, - min_balance: Balance, - metadata: AssetRegistrarMetadata, - is_sufficient: bool, + _asset: AssetId, + _min_balance: Balance, + _metadata: AssetRegistrarMetadata, + _is_sufficient: bool, ) -> DispatchResult { - Assets::force_create( - RuntimeOrigin::root(), - asset.into(), - AssetManager::account_id(), - is_sufficient, - min_balance, - )?; - - // Lastly, the metadata - Assets::force_set_metadata( - RuntimeOrigin::root(), - asset.into(), - metadata.name, - metadata.symbol, - metadata.decimals, - metadata.is_frozen, - ) + Err(sp_runtime::DispatchError::Other( + "AssetManager is deprecated, please use EvmForeignAssets instead", + )) } #[transactional] From a4b594346f253523a10c279456d7d7f9da19c77e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 15 Jul 2024 18:17:59 +0200 Subject: [PATCH 13/71] fix matcher, remove useless genericity --- pallets/moonbeam-foreign-assets/src/lib.rs | 83 ++++++++++----------- pallets/moonbeam-foreign-assets/src/mock.rs | 2 - runtime/moonbase/src/xcm_config.rs | 2 - 3 files changed, 40 insertions(+), 47 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 960e84eac6..16dd8e3b17 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -14,6 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Moonkit. If not, see . +//! # Moonbeam Foreign Assets pallet +//! +//! This pallets allow to create and manage XCM derivative assets (aka. foreign assets). +//! +//! Each asset is implemented by an evm smart contract that is deployed by this pallet +//! The evm smart contract for each asset is trusted by the runtime, and should +//! be deployed only by the runtime itself. +//! +//! This pallet made several assumptions on theses evm smarts contracts: +//! - Only this pallet should be able to mint and burn tokens +//! - The following selectors should be exposed and callable only by this pallet account: +//! - burnFrom(address, uint256) +//! - mintInto(address, uint256) +//! - pause(address, uint256) +//! - unpause(address, uint256) +//! - The smart contract should expose as weel the ERC20.transfer selector +//! +//! Each asset has a unique identifier that can never change. +//! This identifier is named "AssetId", it's an integer (u128). +//! This pallet maintain a two-way mapping beetween each AssetId the XCM Location of the asset. + #![cfg_attr(not(feature = "std"), no_std)] #[cfg(any(test, feature = "runtime-benchmarks"))] @@ -36,8 +57,8 @@ use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; use sp_std::vec::Vec; use xcm::latest::{ - Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Junction, Location, - Result as XcmResult, XcmContext, + Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Location, Result as XcmResult, + XcmContext, }; use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; @@ -70,26 +91,9 @@ impl MatchesFungibles for ForeignAssetsMatcher _ => return Err(MatchError::AssetNotHandled), }; - let prefix = T::ForeignAssetXcmLocationPrefix::get(); - - if prefix.parent_count() != location.parent_count() - || prefix - .interior() - .iter() - .enumerate() - .any(|(index, junction)| location.interior().at(index) != Some(junction)) - { - return Err(MatchError::AssetNotHandled); - } - - let asset_id = match location.interior().at(prefix.interior().len()) { - Some(Junction::GeneralIndex(asset_id)) => asset_id, - _ => return Err(MatchError::AssetNotHandled), - }; - - if AssetIdToForeignAsset::::contains_key(&asset_id) { + if let Some(asset_id) = ForeignAssetToAssetId::::get(&location) { Ok(( - Pallet::::contract_address_from_asset_id(*asset_id), + Pallet::::contract_address_from_asset_id(asset_id), U256::from(*amount), )) } else { @@ -125,12 +129,6 @@ pub mod pallet { /// EVM runner type EvmRunner: Runner; - /// The Foreign Asset Kind. - type ForeignAsset: Parameter + Member + Ord + PartialOrd; - - /// Prefix of XCM location that indentify foreign assets - type ForeignAssetXcmLocationPrefix: Get; - /// Origin that is allowed to create a new foreign assets type ForeignAssetCreatorOrigin: EnsureOrigin; @@ -148,10 +146,10 @@ pub mod pallet { type ForeignAssetDestroyerOrigin: EnsureOrigin; /// Hook to be called when new foreign asset is registered. - type OnForeignAssetCreated: ForeignAssetCreatedHook; + type OnForeignAssetCreated: ForeignAssetCreatedHook; /// Hook to be called when foreign asset is de-registered. - type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; + type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; /// Maximum nulmbers of differnt foreign assets type MaxForeignAssets: Get; @@ -188,32 +186,32 @@ pub mod pallet { /// New asset with the asset manager is registered ForeignAssetCreated { asset_id: AssetId, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, }, /// Changed the xcm type mapping for a given asset id ForeignAssetTypeChanged { asset_id: AssetId, - new_foreign_asset: T::ForeignAsset, + new_foreign_asset: Location, }, /// Removed all information related to an assetId ForeignAssetRemoved { asset_id: AssetId, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, }, // Freezes all tokens of a given asset id ForeignAssetFrozen { asset_id: AssetId, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, }, // Thawing a previously frozen asset ForeignAssetUnfrozen { asset_id: AssetId, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, }, /// Removed all information related to an assetId and destroyed asset ForeignAssetDestroyed { asset_id: AssetId, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, }, } @@ -223,15 +221,14 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn foreign_asset_for_id)] pub type AssetIdToForeignAsset = - CountedStorageMap<_, Blake2_128Concat, AssetId, T::ForeignAsset, OptionQuery>; + CountedStorageMap<_, Blake2_128Concat, AssetId, Location, OptionQuery>; /// Reverse mapping of AssetIdToForeignAsset. Mapping from a foreign asset to an asset id. /// This is mostly used when receiving a multilocation XCM message to retrieve /// the corresponding asset in which tokens should me minted. #[pallet::storage] #[pallet::getter(fn asset_id_for_foreign)] - pub type ForeignAssetToAssetId = - StorageMap<_, Blake2_128Concat, T::ForeignAsset, AssetId>; + pub type ForeignAssetToAssetId = StorageMap<_, Blake2_128Concat, Location, AssetId>; #[pallet::storage] #[pallet::getter(fn frozen_assets)] @@ -261,7 +258,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::create_foreign_asset())] pub fn create_foreign_asset( origin: OriginFor, - foreign_asset: T::ForeignAsset, + foreign_asset: Location, asset_id: AssetId, decimals: u8, ticker: BoundedVec>, @@ -308,7 +305,7 @@ pub mod pallet { pub fn change_existing_asset_type( origin: OriginFor, asset_id: AssetId, - new_foreign_asset: T::ForeignAsset, + new_foreign_asset: Location, ) -> DispatchResult { T::ForeignAssetModifierOrigin::ensure_origin(origin)?; @@ -414,11 +411,11 @@ pub mod pallet { } } - impl MaybeEquivalence for Pallet { - fn convert(foreign_asset: &T::ForeignAsset) -> Option { + impl MaybeEquivalence for Pallet { + fn convert(foreign_asset: &Location) -> Option { Pallet::::asset_id_for_foreign(foreign_asset.clone()) } - fn convert_back(id: &AssetId) -> Option { + fn convert_back(id: &AssetId) -> Option { Pallet::::foreign_asset_for_id(id.clone()) } } diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 0fd3b153ae..a349dbcab3 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -206,13 +206,11 @@ impl crate::Config for Test { type AccountId = AccountId; type AccountIdConverter = (); type EvmRunner = pallet_evm::runner::stack::Runner; - type ForeignAsset = Location; type ForeignAssetCreatorOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; type ForeignAssetDestroyerOrigin = EnsureRoot; - type ForeignAssetXcmLocationPrefix = (); type OnForeignAssetCreated = NoteDownHook; type OnForeignAssetDestroyed = NoteDownHook; type MaxForeignAssets = ConstU32<3>; diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 0ef9872d83..b10dc7f4ee 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -714,13 +714,11 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountId = AccountId; type AccountIdConverter = LocationToH160; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAsset = Location; type ForeignAssetCreatorOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; type ForeignAssetDestroyerOrigin = EnsureRoot; - type ForeignAssetXcmLocationPrefix = (); type OnForeignAssetCreated = (); type OnForeignAssetDestroyed = (); type MaxForeignAssets = ConstU32<256>; From 30f9620bd7fa4f69b42ce92c4036aeb51352a4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 16 Jul 2024 13:10:15 +0200 Subject: [PATCH 14/71] rustfmt --- runtime/moonbase/src/asset_config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/moonbase/src/asset_config.rs b/runtime/moonbase/src/asset_config.rs index c04bd7caf4..ea498463be 100644 --- a/runtime/moonbase/src/asset_config.rs +++ b/runtime/moonbase/src/asset_config.rs @@ -20,8 +20,8 @@ use crate::OpenTechCommitteeInstance; use super::{ - currency, governance, xcm_config, AccountId, AssetId, Assets, Balance, Balances, - Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + currency, governance, xcm_config, AccountId, AssetId, Assets, Balance, Balances, Runtime, + RuntimeCall, RuntimeEvent, RuntimeOrigin, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, }; use moonbeam_runtime_common::weights as moonbeam_weights; From 4726e18768e76e336b4fa5f29ff463136f4fd9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 17 Jul 2024 19:15:44 +0200 Subject: [PATCH 15/71] improve build script: support direct copy of hex calldata --- pallets/moonbeam-foreign-assets/build.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs index c0ee41bacd..e916918e96 100644 --- a/pallets/moonbeam-foreign-assets/build.rs +++ b/pallets/moonbeam-foreign-assets/build.rs @@ -1,6 +1,9 @@ use std::fs::File; use std::io::prelude::*; +// Length of encoded constructor parameters +const PARAMS_LEN: usize = 256; + fn main() { let hex_str = include_str!("resources/foreign_erc20_initcode.hex"); let prefix_0x = hex_str.chars().nth(1) == Some('x'); @@ -11,8 +14,16 @@ fn main() { } .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); + // The encoded parameters at the end of the initializer bytecode should be removed, + // (the runtime will append the constructor parameters dynamically). + let bytecode_end = if bytecode.len() > PARAMS_LEN { + bytecode.len() - PARAMS_LEN + } else { + 0 + }; + let mut file = File::create("resources/foreign_erc20_initcode.bin") .expect("Fail to create file resources/foreign_erc20_initcode.bin"); - file.write_all(&bytecode) + file.write_all(&bytecode[..bytecode_end]) .expect("fail to write bytecode in /foreign_erc20_initcode.bin"); } From 34da4cd506c4f526341ac5ca0a0f564b2ac41e2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 17 Jul 2024 19:16:44 +0200 Subject: [PATCH 16/71] improve solidity impl: disable transfer & approve when paused --- .../resources/foreign_erc20.sol | 63 +++++++++++++++---- .../resources/foreign_erc20_initcode.hex | 2 +- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol index 91f3dcd091..6ed355a974 100644 --- a/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol +++ b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol @@ -9,14 +9,15 @@ import "@openzeppelin/contracts@5.0.2/access/Ownable.sol"; import "@openzeppelin/contracts@5.0.2/token/ERC20/extensions/ERC20Permit.sol"; contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { - constructor(address initialOwner, uint8 tokenDecimals, string memory ticker, string memory tokenName) - ERC20(tokenName, ticker) - Ownable(initialOwner) - ERC20Permit(tokenName) - { - _decimals = tokenDecimals; + constructor( + address initialOwner, + uint8 tokenDecimals, + string memory ticker, + string memory tokenName + ) ERC20(tokenName, ticker) Ownable(initialOwner) ERC20Permit(tokenName) { + _decimals = tokenDecimals; } - + uint8 private _decimals; function pause() public onlyOwner { @@ -38,17 +39,53 @@ contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { function burnAllFrom(address account) public onlyOwner { _burn(account, balanceOf(account)); } - + function decimals() public view override returns (uint8) { return _decimals; } - // The following functions are overrides required by Solidity. + // override ERC20 methods that should be disabled when the asset is "paused" + + function approve(address spender, uint256 value) + public + override(ERC20) + whenNotPaused + returns (bool) + { + address owner = _msgSender(); + _approve(owner, spender, value); + return true; + } - function _update(address from, address to, uint256 value) - internal - override(ERC20, ERC20Pausable) + function transfer(address to, uint256 value) + public + override(ERC20) + whenNotPaused + returns (bool) { + address owner = _msgSender(); + _transfer(owner, to, value); + return true; + } + + function transferFrom( + address from, + address to, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { + address spender = _msgSender(); + _spendAllowance(from, spender, value); + _transfer(from, to, value); + return true; + } + + // The following functions are overrides required by Solidity. + + function _update( + address from, + address to, + uint256 value + ) internal override(ERC20, ERC20Pausable) { super._update(from, to, value); } -} \ No newline at end of file +} diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex index 20aa8cad72..798d7b5eb7 100644 --- a/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex +++ b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.hex @@ -1 +1 @@ -610160604052348015610010575f80fd5b50604051612ca7380380612ca7833981810160405281019061003291906105ad565b80806040518060400160405280600181526020017f3100000000000000000000000000000000000000000000000000000000000000815250868486816003908161007c9190610856565b50806004908161008c9190610856565b5050505f60055f6101000a81548160ff0219169083151502179055505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610118575f6040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260040161010f9190610934565b60405180910390fd5b610127816101f660201b60201c565b5061013c6006836102bb60201b90919060201c565b61012081815250506101586007826102bb60201b90919060201c565b6101408181525050818051906020012060e08181525050808051906020012061010081815250504660a0818152505061019561030860201b60201c565b608081815250503073ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250505050508260095f6101000a81548160ff021916908360ff16021790555050505050610ac0565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f6020835110156102dc576102d58361036260201b60201c565b9050610302565b826102ec836103c760201b60201c565b5f0190816102fa9190610856565b5060ff5f1b90505b92915050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60e051610100514630604051602001610347959493929190610974565b60405160208183030381529060405280519060200120905090565b5f80829050601f815111156103ae57826040517f305a27a90000000000000000000000000000000000000000000000000000000081526004016103a59190610a0d565b60405180910390fd5b8051816103ba90610a5a565b5f1c175f1b915050919050565b5f819050919050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61040a826103e1565b9050919050565b61041a81610400565b8114610424575f80fd5b50565b5f8151905061043581610411565b92915050565b5f60ff82169050919050565b6104508161043b565b811461045a575f80fd5b50565b5f8151905061046b81610447565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6104bf82610479565b810181811067ffffffffffffffff821117156104de576104dd610489565b5b80604052505050565b5f6104f06103d0565b90506104fc82826104b6565b919050565b5f67ffffffffffffffff82111561051b5761051a610489565b5b61052482610479565b9050602081019050919050565b8281835e5f83830152505050565b5f61055161054c84610501565b6104e7565b90508281526020810184848401111561056d5761056c610475565b5b610578848285610531565b509392505050565b5f82601f83011261059457610593610471565b5b81516105a484826020860161053f565b91505092915050565b5f805f80608085870312156105c5576105c46103d9565b5b5f6105d287828801610427565b94505060206105e38782880161045d565b935050604085015167ffffffffffffffff811115610604576106036103dd565b5b61061087828801610580565b925050606085015167ffffffffffffffff811115610631576106306103dd565b5b61063d87828801610580565b91505092959194509250565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f600282049050600182168061069757607f821691505b6020821081036106aa576106a9610653565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f6008830261070c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826106d1565b61071686836106d1565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f61075a6107556107508461072e565b610737565b61072e565b9050919050565b5f819050919050565b61077383610740565b61078761077f82610761565b8484546106dd565b825550505050565b5f90565b61079b61078f565b6107a681848461076a565b505050565b5b818110156107c9576107be5f82610793565b6001810190506107ac565b5050565b601f82111561080e576107df816106b0565b6107e8846106c2565b810160208510156107f7578190505b61080b610803856106c2565b8301826107ab565b50505b505050565b5f82821c905092915050565b5f61082e5f1984600802610813565b1980831691505092915050565b5f610846838361081f565b9150826002028217905092915050565b61085f82610649565b67ffffffffffffffff81111561087857610877610489565b5b6108828254610680565b61088d8282856107cd565b5f60209050601f8311600181146108be575f84156108ac578287015190505b6108b6858261083b565b86555061091d565b601f1984166108cc866106b0565b5f5b828110156108f3578489015182556001820191506020850194506020810190506108ce565b86831015610910578489015161090c601f89168261081f565b8355505b6001600288020188555050505b505050505050565b61092e81610400565b82525050565b5f6020820190506109475f830184610925565b92915050565b5f819050919050565b61095f8161094d565b82525050565b61096e8161072e565b82525050565b5f60a0820190506109875f830188610956565b6109946020830187610956565b6109a16040830186610956565b6109ae6060830185610965565b6109bb6080830184610925565b9695505050505050565b5f82825260208201905092915050565b5f6109df82610649565b6109e981856109c5565b93506109f9818560208601610531565b610a0281610479565b840191505092915050565b5f6020820190508181035f830152610a2581846109d5565b905092915050565b5f81519050919050565b5f819050602082019050919050565b5f610a51825161094d565b80915050919050565b5f610a6482610a2d565b82610a6e84610a37565b9050610a7981610a46565b92506020821015610ab957610ab47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026106d1565b831692505b5050919050565b60805160a05160c05160e051610100516101205161014051612196610b115f395f610f2f01525f610ef401525f61129e01525f61127d01525f610c6a01525f610cc001525f610ce901526121965ff3fe608060405234801561000f575f80fd5b5060043610610140575f3560e01c806379cc6790116100b657806395d89b411161007a57806395d89b4114610332578063a9059cbb14610350578063aab3859214610380578063d505accf1461039c578063dd62ed3e146103b8578063f2fde38b146103e857610140565b806379cc67901461029a5780637ecebe00146102b65780638456cb59146102e657806384b0196e146102f05780638da5cb5b1461031457610140565b8063313ce56711610108578063313ce567146101fc5780633644e5151461021a5780633f4ba83a146102385780635c975abb1461024257806370a0823114610260578063715018a61461029057610140565b806306fdde0314610144578063095ea7b314610162578063167db3791461019257806318160ddd146101ae57806323b872dd146101cc575b5f80fd5b61014c610404565b6040516101599190611a06565b60405180910390f35b61017c60048036038101906101779190611ab7565b610494565b6040516101899190611b0f565b60405180910390f35b6101ac60048036038101906101a79190611b28565b6104b6565b005b6101b66104d3565b6040516101c39190611b62565b60405180910390f35b6101e660048036038101906101e19190611b7b565b6104dc565b6040516101f39190611b0f565b60405180910390f35b61020461050a565b6040516102119190611be6565b60405180910390f35b61022261051f565b60405161022f9190611c17565b60405180910390f35b61024061052d565b005b61024a61053f565b6040516102579190611b0f565b60405180910390f35b61027a60048036038101906102759190611b28565b610554565b6040516102879190611b62565b60405180910390f35b610298610599565b005b6102b460048036038101906102af9190611ab7565b6105ac565b005b6102d060048036038101906102cb9190611b28565b6105c2565b6040516102dd9190611b62565b60405180910390f35b6102ee6105d3565b005b6102f86105e5565b60405161030b9796959493929190611d30565b60405180910390f35b61031c61068a565b6040516103299190611db2565b60405180910390f35b61033a6106b3565b6040516103479190611a06565b60405180910390f35b61036a60048036038101906103659190611ab7565b610743565b6040516103779190611b0f565b60405180910390f35b61039a60048036038101906103959190611ab7565b610765565b005b6103b660048036038101906103b19190611e1f565b61077b565b005b6103d260048036038101906103cd9190611ebc565b6108c0565b6040516103df9190611b62565b60405180910390f35b61040260048036038101906103fd9190611b28565b610942565b005b60606003805461041390611f27565b80601f016020809104026020016040519081016040528092919081815260200182805461043f90611f27565b801561048a5780601f106104615761010080835404028352916020019161048a565b820191905f5260205f20905b81548152906001019060200180831161046d57829003601f168201915b5050505050905090565b5f8061049e6109c6565b90506104ab8185856109cd565b600191505092915050565b6104be6109df565b6104d0816104cb83610554565b610a66565b50565b5f600254905090565b5f806104e66109c6565b90506104f3858285610ae5565b6104fe858585610b77565b60019150509392505050565b5f60095f9054906101000a900460ff16905090565b5f610528610c67565b905090565b6105356109df565b61053d610d1d565b565b5f60055f9054906101000a900460ff16905090565b5f805f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b6105a16109df565b6105aa5f610d7e565b565b6105b46109df565b6105be8282610a66565b5050565b5f6105cc82610e43565b9050919050565b6105db6109df565b6105e3610e89565b565b5f6060805f805f60606105f6610eeb565b6105fe610f26565b46305f801b5f67ffffffffffffffff81111561061d5761061c611f57565b5b60405190808252806020026020018201604052801561064b5781602001602082028036833780820191505090505b507f0f00000000000000000000000000000000000000000000000000000000000000959493929190965096509650965096509650965090919293949596565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600480546106c290611f27565b80601f01602080910402602001604051908101604052809291908181526020018280546106ee90611f27565b80156107395780601f1061071057610100808354040283529160200191610739565b820191905f5260205f20905b81548152906001019060200180831161071c57829003601f168201915b5050505050905090565b5f8061074d6109c6565b905061075a818585610b77565b600191505092915050565b61076d6109df565b6107778282610f61565b5050565b834211156107c057836040517f627913020000000000000000000000000000000000000000000000000000000081526004016107b79190611b62565b60405180910390fd5b5f7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886107ee8c610fe0565b8960405160200161080496959493929190611f84565b6040516020818303038152906040528051906020012090505f61082682611033565b90505f6108358287878761104c565b90508973ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146108a957808a6040517f4b800e460000000000000000000000000000000000000000000000000000000081526004016108a0929190611fe3565b60405180910390fd5b6108b48a8a8a6109cd565b50505050505050505050565b5f60015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905092915050565b61094a6109df565b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036109ba575f6040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016109b19190611db2565b60405180910390fd5b6109c381610d7e565b50565b5f33905090565b6109da838383600161107a565b505050565b6109e76109c6565b73ffffffffffffffffffffffffffffffffffffffff16610a0561068a565b73ffffffffffffffffffffffffffffffffffffffff1614610a6457610a286109c6565b6040517f118cdaa7000000000000000000000000000000000000000000000000000000008152600401610a5b9190611db2565b60405180910390fd5b565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610ad6575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610acd9190611db2565b60405180910390fd5b610ae1825f83611249565b5050565b5f610af084846108c0565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114610b715781811015610b62578281836040517ffb8f41b2000000000000000000000000000000000000000000000000000000008152600401610b599392919061200a565b60405180910390fd5b610b7084848484035f61107a565b5b50505050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610be7575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610bde9190611db2565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610c57575f6040517fec442f05000000000000000000000000000000000000000000000000000000008152600401610c4e9190611db2565b60405180910390fd5b610c62838383611249565b505050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff16148015610ce257507f000000000000000000000000000000000000000000000000000000000000000046145b15610d0f577f00000000000000000000000000000000000000000000000000000000000000009050610d1a565b610d17611259565b90505b90565b610d256112ee565b5f60055f6101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610d676109c6565b604051610d749190611db2565b60405180910390a1565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b610e9161132e565b600160055f6101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610ed46109c6565b604051610ee19190611db2565b60405180910390a1565b6060610f2160067f000000000000000000000000000000000000000000000000000000000000000061136f90919063ffffffff16565b905090565b6060610f5c60077f000000000000000000000000000000000000000000000000000000000000000061136f90919063ffffffff16565b905090565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610fd1575f6040517fec442f05000000000000000000000000000000000000000000000000000000008152600401610fc89190611db2565b60405180910390fd5b610fdc5f8383611249565b5050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f815480929190600101919050559050919050565b5f61104561103f610c67565b8361141c565b9050919050565b5f805f8061105c8888888861145c565b92509250925061106c8282611543565b829350505050949350505050565b5f73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff16036110ea575f6040517fe602df050000000000000000000000000000000000000000000000000000000081526004016110e19190611db2565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361115a575f6040517f94280d620000000000000000000000000000000000000000000000000000000081526004016111519190611db2565b60405180910390fd5b8160015f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20819055508015611243578273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9258460405161123a9190611b62565b60405180910390a35b50505050565b6112548383836116a5565b505050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f000000000000000000000000000000000000000000000000000000000000000046306040516020016112d395949392919061203f565b60405160208183030381529060405280519060200120905090565b6112f661053f565b61132c576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b61133661053f565b1561136d576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b606060ff5f1b831461138b57611384836116bd565b9050611416565b81805461139790611f27565b80601f01602080910402602001604051908101604052809291908181526020018280546113c390611f27565b801561140e5780601f106113e55761010080835404028352916020019161140e565b820191905f5260205f20905b8154815290600101906020018083116113f157829003601f168201915b505050505090505b92915050565b5f6040517f190100000000000000000000000000000000000000000000000000000000000081528360028201528260228201526042812091505092915050565b5f805f7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0845f1c1115611498575f600385925092509250611539565b5f6001888888886040515f81526020016040526040516114bb9493929190612090565b6020604051602081039080840390855afa1580156114db573d5f803e3d5ffd5b5050506020604051035190505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361152c575f60015f801b93509350935050611539565b805f805f1b935093509350505b9450945094915050565b5f6003811115611556576115556120d3565b5b826003811115611569576115686120d3565b5b03156116a15760016003811115611583576115826120d3565b5b826003811115611596576115956120d3565b5b036115cd576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600260038111156115e1576115e06120d3565b5b8260038111156115f4576115f36120d3565b5b0361163857805f1c6040517ffce698f700000000000000000000000000000000000000000000000000000000815260040161162f9190611b62565b60405180910390fd5b60038081111561164b5761164a6120d3565b5b82600381111561165e5761165d6120d3565b5b036116a057806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016116979190611c17565b60405180910390fd5b5b5050565b6116ad61132e565b6116b883838361172f565b505050565b60605f6116c983611948565b90505f602067ffffffffffffffff8111156116e7576116e6611f57565b5b6040519080825280601f01601f1916602001820160405280156117195781602001600182028036833780820191505090505b5090508181528360208201528092505050919050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff160361177f578060025f828254611773919061212d565b9250508190555061184d565b5f805f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905081811015611808578381836040517fe450d38c0000000000000000000000000000000000000000000000000000000081526004016117ff9392919061200a565b60405180910390fd5b8181035f808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081905550505b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603611894578060025f82825403925050819055506118de565b805f808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef8360405161193b9190611b62565b60405180910390a3505050565b5f8060ff835f1c169050601f81111561198d576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80915050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6119d882611996565b6119e281856119a0565b93506119f28185602086016119b0565b6119fb816119be565b840191505092915050565b5f6020820190508181035f830152611a1e81846119ce565b905092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611a5382611a2a565b9050919050565b611a6381611a49565b8114611a6d575f80fd5b50565b5f81359050611a7e81611a5a565b92915050565b5f819050919050565b611a9681611a84565b8114611aa0575f80fd5b50565b5f81359050611ab181611a8d565b92915050565b5f8060408385031215611acd57611acc611a26565b5b5f611ada85828601611a70565b9250506020611aeb85828601611aa3565b9150509250929050565b5f8115159050919050565b611b0981611af5565b82525050565b5f602082019050611b225f830184611b00565b92915050565b5f60208284031215611b3d57611b3c611a26565b5b5f611b4a84828501611a70565b91505092915050565b611b5c81611a84565b82525050565b5f602082019050611b755f830184611b53565b92915050565b5f805f60608486031215611b9257611b91611a26565b5b5f611b9f86828701611a70565b9350506020611bb086828701611a70565b9250506040611bc186828701611aa3565b9150509250925092565b5f60ff82169050919050565b611be081611bcb565b82525050565b5f602082019050611bf95f830184611bd7565b92915050565b5f819050919050565b611c1181611bff565b82525050565b5f602082019050611c2a5f830184611c08565b92915050565b5f7fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b611c6481611c30565b82525050565b611c7381611a49565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b611cab81611a84565b82525050565b5f611cbc8383611ca2565b60208301905092915050565b5f602082019050919050565b5f611cde82611c79565b611ce88185611c83565b9350611cf383611c93565b805f5b83811015611d23578151611d0a8882611cb1565b9750611d1583611cc8565b925050600181019050611cf6565b5085935050505092915050565b5f60e082019050611d435f83018a611c5b565b8181036020830152611d5581896119ce565b90508181036040830152611d6981886119ce565b9050611d786060830187611b53565b611d856080830186611c6a565b611d9260a0830185611c08565b81810360c0830152611da48184611cd4565b905098975050505050505050565b5f602082019050611dc55f830184611c6a565b92915050565b611dd481611bcb565b8114611dde575f80fd5b50565b5f81359050611def81611dcb565b92915050565b611dfe81611bff565b8114611e08575f80fd5b50565b5f81359050611e1981611df5565b92915050565b5f805f805f805f60e0888a031215611e3a57611e39611a26565b5b5f611e478a828b01611a70565b9750506020611e588a828b01611a70565b9650506040611e698a828b01611aa3565b9550506060611e7a8a828b01611aa3565b9450506080611e8b8a828b01611de1565b93505060a0611e9c8a828b01611e0b565b92505060c0611ead8a828b01611e0b565b91505092959891949750929550565b5f8060408385031215611ed257611ed1611a26565b5b5f611edf85828601611a70565b9250506020611ef085828601611a70565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680611f3e57607f821691505b602082108103611f5157611f50611efa565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60c082019050611f975f830189611c08565b611fa46020830188611c6a565b611fb16040830187611c6a565b611fbe6060830186611b53565b611fcb6080830185611b53565b611fd860a0830184611b53565b979650505050505050565b5f604082019050611ff65f830185611c6a565b6120036020830184611c6a565b9392505050565b5f60608201905061201d5f830186611c6a565b61202a6020830185611b53565b6120376040830184611b53565b949350505050565b5f60a0820190506120525f830188611c08565b61205f6020830187611c08565b61206c6040830186611c08565b6120796060830185611b53565b6120866080830184611c6a565b9695505050505050565b5f6080820190506120a35f830187611c08565b6120b06020830186611bd7565b6120bd6040830185611c08565b6120ca6060830184611c08565b95945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61213782611a84565b915061214283611a84565b925082820190508082111561215a57612159612100565b5b9291505056fea26469706673582212200fbc0e720f4cf8c8804e8ffd05f06d46f086f3b2356e095519fac7223509253464736f6c634300081a0033 \ No newline at end of file +0x610160604052348015610010575f80fd5b50604051612cbf380380612cbf833981810160405281019061003291906105ad565b80806040518060400160405280600181526020017f3100000000000000000000000000000000000000000000000000000000000000815250868486816003908161007c9190610856565b50806004908161008c9190610856565b5050505f60055f6101000a81548160ff0219169083151502179055505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610118575f6040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260040161010f9190610934565b60405180910390fd5b610127816101f660201b60201c565b5061013c6006836102bb60201b90919060201c565b61012081815250506101586007826102bb60201b90919060201c565b6101408181525050818051906020012060e08181525050808051906020012061010081815250504660a0818152505061019561030860201b60201c565b608081815250503073ffffffffffffffffffffffffffffffffffffffff1660c08173ffffffffffffffffffffffffffffffffffffffff16815250505050508260095f6101000a81548160ff021916908360ff16021790555050505050610ac0565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f6020835110156102dc576102d58361036260201b60201c565b9050610302565b826102ec836103c760201b60201c565b5f0190816102fa9190610856565b5060ff5f1b90505b92915050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f60e051610100514630604051602001610347959493929190610974565b60405160208183030381529060405280519060200120905090565b5f80829050601f815111156103ae57826040517f305a27a90000000000000000000000000000000000000000000000000000000081526004016103a59190610a0d565b60405180910390fd5b8051816103ba90610a5a565b5f1c175f1b915050919050565b5f819050919050565b5f604051905090565b5f80fd5b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f61040a826103e1565b9050919050565b61041a81610400565b8114610424575f80fd5b50565b5f8151905061043581610411565b92915050565b5f60ff82169050919050565b6104508161043b565b811461045a575f80fd5b50565b5f8151905061046b81610447565b92915050565b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6104bf82610479565b810181811067ffffffffffffffff821117156104de576104dd610489565b5b80604052505050565b5f6104f06103d0565b90506104fc82826104b6565b919050565b5f67ffffffffffffffff82111561051b5761051a610489565b5b61052482610479565b9050602081019050919050565b8281835e5f83830152505050565b5f61055161054c84610501565b6104e7565b90508281526020810184848401111561056d5761056c610475565b5b610578848285610531565b509392505050565b5f82601f83011261059457610593610471565b5b81516105a484826020860161053f565b91505092915050565b5f805f80608085870312156105c5576105c46103d9565b5b5f6105d287828801610427565b94505060206105e38782880161045d565b935050604085015167ffffffffffffffff811115610604576106036103dd565b5b61061087828801610580565b925050606085015167ffffffffffffffff811115610631576106306103dd565b5b61063d87828801610580565b91505092959194509250565b5f81519050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f600282049050600182168061069757607f821691505b6020821081036106aa576106a9610653565b5b50919050565b5f819050815f5260205f209050919050565b5f6020601f8301049050919050565b5f82821b905092915050565b5f6008830261070c7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff826106d1565b61071686836106d1565b95508019841693508086168417925050509392505050565b5f819050919050565b5f819050919050565b5f61075a6107556107508461072e565b610737565b61072e565b9050919050565b5f819050919050565b61077383610740565b61078761077f82610761565b8484546106dd565b825550505050565b5f90565b61079b61078f565b6107a681848461076a565b505050565b5b818110156107c9576107be5f82610793565b6001810190506107ac565b5050565b601f82111561080e576107df816106b0565b6107e8846106c2565b810160208510156107f7578190505b61080b610803856106c2565b8301826107ab565b50505b505050565b5f82821c905092915050565b5f61082e5f1984600802610813565b1980831691505092915050565b5f610846838361081f565b9150826002028217905092915050565b61085f82610649565b67ffffffffffffffff81111561087857610877610489565b5b6108828254610680565b61088d8282856107cd565b5f60209050601f8311600181146108be575f84156108ac578287015190505b6108b6858261083b565b86555061091d565b601f1984166108cc866106b0565b5f5b828110156108f3578489015182556001820191506020850194506020810190506108ce565b86831015610910578489015161090c601f89168261081f565b8355505b6001600288020188555050505b505050505050565b61092e81610400565b82525050565b5f6020820190506109475f830184610925565b92915050565b5f819050919050565b61095f8161094d565b82525050565b61096e8161072e565b82525050565b5f60a0820190506109875f830188610956565b6109946020830187610956565b6109a16040830186610956565b6109ae6060830185610965565b6109bb6080830184610925565b9695505050505050565b5f82825260208201905092915050565b5f6109df82610649565b6109e981856109c5565b93506109f9818560208601610531565b610a0281610479565b840191505092915050565b5f6020820190508181035f830152610a2581846109d5565b905092915050565b5f81519050919050565b5f819050602082019050919050565b5f610a51825161094d565b80915050919050565b5f610a6482610a2d565b82610a6e84610a37565b9050610a7981610a46565b92506020821015610ab957610ab47fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff836020036008026106d1565b831692505b5050919050565b60805160a05160c05160e0516101005161012051610140516121ae610b115f395f610f8801525f610f4d01525f6112f701525f6112d601525f610cc301525f610d1901525f610d4201526121ae5ff3fe608060405234801561000f575f80fd5b5060043610610140575f3560e01c806379cc6790116100b657806395d89b411161007a57806395d89b4114610332578063a9059cbb14610350578063aab3859214610380578063d505accf1461039c578063dd62ed3e146103b8578063f2fde38b146103e857610140565b806379cc67901461029a5780637ecebe00146102b65780638456cb59146102e657806384b0196e146102f05780638da5cb5b1461031457610140565b8063313ce56711610108578063313ce567146101fc5780633644e5151461021a5780633f4ba83a146102385780635c975abb1461024257806370a0823114610260578063715018a61461029057610140565b806306fdde0314610144578063095ea7b314610162578063167db3791461019257806318160ddd146101ae57806323b872dd146101cc575b5f80fd5b61014c610404565b6040516101599190611a1e565b60405180910390f35b61017c60048036038101906101779190611acf565b610494565b6040516101899190611b27565b60405180910390f35b6101ac60048036038101906101a79190611b40565b6104be565b005b6101b66104db565b6040516101c39190611b7a565b60405180910390f35b6101e660048036038101906101e19190611b93565b6104e4565b6040516101f39190611b27565b60405180910390f35b61020461051a565b6040516102119190611bfe565b60405180910390f35b61022261052f565b60405161022f9190611c2f565b60405180910390f35b61024061053d565b005b61024a61054f565b6040516102579190611b27565b60405180910390f35b61027a60048036038101906102759190611b40565b610564565b6040516102879190611b7a565b60405180910390f35b6102986105a9565b005b6102b460048036038101906102af9190611acf565b6105bc565b005b6102d060048036038101906102cb9190611b40565b6105d2565b6040516102dd9190611b7a565b60405180910390f35b6102ee6105e3565b005b6102f86105f5565b60405161030b9796959493929190611d48565b60405180910390f35b61031c61069a565b6040516103299190611dca565b60405180910390f35b61033a6106c3565b6040516103479190611a1e565b60405180910390f35b61036a60048036038101906103659190611acf565b610753565b6040516103779190611b27565b60405180910390f35b61039a60048036038101906103959190611acf565b61077d565b005b6103b660048036038101906103b19190611e37565b610793565b005b6103d260048036038101906103cd9190611ed4565b6108d8565b6040516103df9190611b7a565b60405180910390f35b61040260048036038101906103fd9190611b40565b61095a565b005b60606003805461041390611f3f565b80601f016020809104026020016040519081016040528092919081815260200182805461043f90611f3f565b801561048a5780601f106104615761010080835404028352916020019161048a565b820191905f5260205f20905b81548152906001019060200180831161046d57829003601f168201915b5050505050905090565b5f61049d6109de565b5f6104a6610a1f565b90506104b3818585610a26565b600191505092915050565b6104c6610a38565b6104d8816104d383610564565b610abf565b50565b5f600254905090565b5f6104ed6109de565b5f6104f6610a1f565b9050610503858285610b3e565b61050e858585610bd0565b60019150509392505050565b5f60095f9054906101000a900460ff16905090565b5f610538610cc0565b905090565b610545610a38565b61054d610d76565b565b5f60055f9054906101000a900460ff16905090565b5f805f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b6105b1610a38565b6105ba5f610dd7565b565b6105c4610a38565b6105ce8282610abf565b5050565b5f6105dc82610e9c565b9050919050565b6105eb610a38565b6105f3610ee2565b565b5f6060805f805f6060610606610f44565b61060e610f7f565b46305f801b5f67ffffffffffffffff81111561062d5761062c611f6f565b5b60405190808252806020026020018201604052801561065b5781602001602082028036833780820191505090505b507f0f00000000000000000000000000000000000000000000000000000000000000959493929190965096509650965096509650965090919293949596565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6060600480546106d290611f3f565b80601f01602080910402602001604051908101604052809291908181526020018280546106fe90611f3f565b80156107495780601f1061072057610100808354040283529160200191610749565b820191905f5260205f20905b81548152906001019060200180831161072c57829003601f168201915b5050505050905090565b5f61075c6109de565b5f610765610a1f565b9050610772818585610bd0565b600191505092915050565b610785610a38565b61078f8282610fba565b5050565b834211156107d857836040517f627913020000000000000000000000000000000000000000000000000000000081526004016107cf9190611b7a565b60405180910390fd5b5f7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98888886108068c611039565b8960405160200161081c96959493929190611f9c565b6040516020818303038152906040528051906020012090505f61083e8261108c565b90505f61084d828787876110a5565b90508973ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16146108c157808a6040517f4b800e460000000000000000000000000000000000000000000000000000000081526004016108b8929190611ffb565b60405180910390fd5b6108cc8a8a8a610a26565b50505050505050505050565b5f60015f8473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905092915050565b610962610a38565b5f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16036109d2575f6040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016109c99190611dca565b60405180910390fd5b6109db81610dd7565b50565b6109e661054f565b15610a1d576040517fd93c066500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b5f33905090565b610a3383838360016110d3565b505050565b610a40610a1f565b73ffffffffffffffffffffffffffffffffffffffff16610a5e61069a565b73ffffffffffffffffffffffffffffffffffffffff1614610abd57610a81610a1f565b6040517f118cdaa7000000000000000000000000000000000000000000000000000000008152600401610ab49190611dca565b60405180910390fd5b565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610b2f575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610b269190611dca565b60405180910390fd5b610b3a825f836112a2565b5050565b5f610b4984846108d8565b90507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8114610bca5781811015610bbb578281836040517ffb8f41b2000000000000000000000000000000000000000000000000000000008152600401610bb293929190612022565b60405180910390fd5b610bc984848484035f6110d3565b5b50505050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603610c40575f6040517f96c6fd1e000000000000000000000000000000000000000000000000000000008152600401610c379190611dca565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1603610cb0575f6040517fec442f05000000000000000000000000000000000000000000000000000000008152600401610ca79190611dca565b60405180910390fd5b610cbb8383836112a2565b505050565b5f7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff163073ffffffffffffffffffffffffffffffffffffffff16148015610d3b57507f000000000000000000000000000000000000000000000000000000000000000046145b15610d68577f00000000000000000000000000000000000000000000000000000000000000009050610d73565b610d706112b2565b90505b90565b610d7e611347565b5f60055f6101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610dc0610a1f565b604051610dcd9190611dca565b60405180910390a1565b5f600560019054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905081600560016101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f20549050919050565b610eea6109de565b600160055f6101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258610f2d610a1f565b604051610f3a9190611dca565b60405180910390a1565b6060610f7a60067f000000000000000000000000000000000000000000000000000000000000000061138790919063ffffffff16565b905090565b6060610fb560077f000000000000000000000000000000000000000000000000000000000000000061138790919063ffffffff16565b905090565b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff160361102a575f6040517fec442f050000000000000000000000000000000000000000000000000000000081526004016110219190611dca565b60405180910390fd5b6110355f83836112a2565b5050565b5f60085f8373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f815480929190600101919050559050919050565b5f61109e611098610cc0565b83611434565b9050919050565b5f805f806110b588888888611474565b9250925092506110c5828261155b565b829350505050949350505050565b5f73ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff1603611143575f6040517fe602df0500000000000000000000000000000000000000000000000000000000815260040161113a9190611dca565b60405180910390fd5b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16036111b3575f6040517f94280d620000000000000000000000000000000000000000000000000000000081526004016111aa9190611dca565b60405180910390fd5b8160015f8673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081905550801561129c578273ffffffffffffffffffffffffffffffffffffffff168473ffffffffffffffffffffffffffffffffffffffff167f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925846040516112939190611b7a565b60405180910390a35b50505050565b6112ad8383836116bd565b505050565b5f7f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f0000000000000000000000000000000000000000000000000000000000000000463060405160200161132c959493929190612057565b60405160208183030381529060405280519060200120905090565b61134f61054f565b611385576040517f8dfc202b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b606060ff5f1b83146113a35761139c836116d5565b905061142e565b8180546113af90611f3f565b80601f01602080910402602001604051908101604052809291908181526020018280546113db90611f3f565b80156114265780601f106113fd57610100808354040283529160200191611426565b820191905f5260205f20905b81548152906001019060200180831161140957829003601f168201915b505050505090505b92915050565b5f6040517f190100000000000000000000000000000000000000000000000000000000000081528360028201528260228201526042812091505092915050565b5f805f7f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0845f1c11156114b0575f600385925092509250611551565b5f6001888888886040515f81526020016040526040516114d394939291906120a8565b6020604051602081039080840390855afa1580156114f3573d5f803e3d5ffd5b5050506020604051035190505f73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603611544575f60015f801b93509350935050611551565b805f805f1b935093509350505b9450945094915050565b5f600381111561156e5761156d6120eb565b5b826003811115611581576115806120eb565b5b03156116b9576001600381111561159b5761159a6120eb565b5b8260038111156115ae576115ad6120eb565b5b036115e5576040517ff645eedf00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b600260038111156115f9576115f86120eb565b5b82600381111561160c5761160b6120eb565b5b0361165057805f1c6040517ffce698f70000000000000000000000000000000000000000000000000000000081526004016116479190611b7a565b60405180910390fd5b600380811115611663576116626120eb565b5b826003811115611676576116756120eb565b5b036116b857806040517fd78bce0c0000000000000000000000000000000000000000000000000000000081526004016116af9190611c2f565b60405180910390fd5b5b5050565b6116c56109de565b6116d0838383611747565b505050565b60605f6116e183611960565b90505f602067ffffffffffffffff8111156116ff576116fe611f6f565b5b6040519080825280601f01601f1916602001820160405280156117315781602001600182028036833780820191505090505b5090508181528360208201528092505050919050565b5f73ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff1603611797578060025f82825461178b9190612145565b92505081905550611865565b5f805f8573ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2054905081811015611820578381836040517fe450d38c00000000000000000000000000000000000000000000000000000000815260040161181793929190612022565b60405180910390fd5b8181035f808673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f2081905550505b5f73ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16036118ac578060025f82825403925050819055506118f6565b805f808473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020015f205f82825401925050819055505b8173ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040516119539190611b7a565b60405180910390a3505050565b5f8060ff835f1c169050601f8111156119a5576040517fb3512b0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b80915050919050565b5f81519050919050565b5f82825260208201905092915050565b8281835e5f83830152505050565b5f601f19601f8301169050919050565b5f6119f0826119ae565b6119fa81856119b8565b9350611a0a8185602086016119c8565b611a13816119d6565b840191505092915050565b5f6020820190508181035f830152611a3681846119e6565b905092915050565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f611a6b82611a42565b9050919050565b611a7b81611a61565b8114611a85575f80fd5b50565b5f81359050611a9681611a72565b92915050565b5f819050919050565b611aae81611a9c565b8114611ab8575f80fd5b50565b5f81359050611ac981611aa5565b92915050565b5f8060408385031215611ae557611ae4611a3e565b5b5f611af285828601611a88565b9250506020611b0385828601611abb565b9150509250929050565b5f8115159050919050565b611b2181611b0d565b82525050565b5f602082019050611b3a5f830184611b18565b92915050565b5f60208284031215611b5557611b54611a3e565b5b5f611b6284828501611a88565b91505092915050565b611b7481611a9c565b82525050565b5f602082019050611b8d5f830184611b6b565b92915050565b5f805f60608486031215611baa57611ba9611a3e565b5b5f611bb786828701611a88565b9350506020611bc886828701611a88565b9250506040611bd986828701611abb565b9150509250925092565b5f60ff82169050919050565b611bf881611be3565b82525050565b5f602082019050611c115f830184611bef565b92915050565b5f819050919050565b611c2981611c17565b82525050565b5f602082019050611c425f830184611c20565b92915050565b5f7fff0000000000000000000000000000000000000000000000000000000000000082169050919050565b611c7c81611c48565b82525050565b611c8b81611a61565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b611cc381611a9c565b82525050565b5f611cd48383611cba565b60208301905092915050565b5f602082019050919050565b5f611cf682611c91565b611d008185611c9b565b9350611d0b83611cab565b805f5b83811015611d3b578151611d228882611cc9565b9750611d2d83611ce0565b925050600181019050611d0e565b5085935050505092915050565b5f60e082019050611d5b5f83018a611c73565b8181036020830152611d6d81896119e6565b90508181036040830152611d8181886119e6565b9050611d906060830187611b6b565b611d9d6080830186611c82565b611daa60a0830185611c20565b81810360c0830152611dbc8184611cec565b905098975050505050505050565b5f602082019050611ddd5f830184611c82565b92915050565b611dec81611be3565b8114611df6575f80fd5b50565b5f81359050611e0781611de3565b92915050565b611e1681611c17565b8114611e20575f80fd5b50565b5f81359050611e3181611e0d565b92915050565b5f805f805f805f60e0888a031215611e5257611e51611a3e565b5b5f611e5f8a828b01611a88565b9750506020611e708a828b01611a88565b9650506040611e818a828b01611abb565b9550506060611e928a828b01611abb565b9450506080611ea38a828b01611df9565b93505060a0611eb48a828b01611e23565b92505060c0611ec58a828b01611e23565b91505092959891949750929550565b5f8060408385031215611eea57611ee9611a3e565b5b5f611ef785828601611a88565b9250506020611f0885828601611a88565b9150509250929050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602260045260245ffd5b5f6002820490506001821680611f5657607f821691505b602082108103611f6957611f68611f12565b5b50919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b5f60c082019050611faf5f830189611c20565b611fbc6020830188611c82565b611fc96040830187611c82565b611fd66060830186611b6b565b611fe36080830185611b6b565b611ff060a0830184611b6b565b979650505050505050565b5f60408201905061200e5f830185611c82565b61201b6020830184611c82565b9392505050565b5f6060820190506120355f830186611c82565b6120426020830185611b6b565b61204f6040830184611b6b565b949350505050565b5f60a08201905061206a5f830188611c20565b6120776020830187611c20565b6120846040830186611c20565b6120916060830185611b6b565b61209e6080830184611c82565b9695505050505050565b5f6080820190506120bb5f830187611c20565b6120c86020830186611bef565b6120d56040830185611c20565b6120e26060830184611c20565b95945050505050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52602160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61214f82611a9c565b915061215a83611a9c565b925082820190508082111561217257612171612118565b5b9291505056fea2646970667358221220fc84b3ecd32a8b8de7cf49f4c49cea5c61ad9148b07395762d9004f964e7b82b64736f6c634300081a003300000000000000000000000011111111111111111111111111111111111111110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000034d54540000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a4d79426967546f6b656e00000000000000000000000000000000000000000000 \ No newline at end of file From 2ec2a34ee942ef64588da1f056d5aa690b0eba94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 17 Jul 2024 19:17:21 +0200 Subject: [PATCH 17/71] refactor evm foreign pallet: create AssetStatus & rename types --- pallets/moonbeam-foreign-assets/src/lib.rs | 181 ++++++++++--------- pallets/moonbeam-foreign-assets/src/tests.rs | 37 ++-- 2 files changed, 115 insertions(+), 103 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 16dd8e3b17..2baa46a649 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -55,12 +55,11 @@ use ethereum_types::{H160, U256}; use frame_support::pallet; use frame_support::pallet_prelude::*; use frame_system::pallet_prelude::*; -use sp_std::vec::Vec; use xcm::latest::{ Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Location, Result as XcmResult, XcmContext, }; -use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; +use xcm_executor::traits::Error as MatchError; const FOREIGN_ASSETS_PREFIX: [u8; 4] = [0xff, 0xff, 0xff, 0xff]; @@ -84,17 +83,18 @@ impl ForeignAssetDestroyedHook for () { pub(crate) struct ForeignAssetsMatcher(core::marker::PhantomData); -impl MatchesFungibles for ForeignAssetsMatcher { - fn matches_fungibles(asset: &Asset) -> Result<(H160, U256), MatchError> { +impl ForeignAssetsMatcher { + fn match_asset(asset: &Asset) -> Result<(H160, U256, AssetStatus), MatchError> { let (amount, location) = match (&asset.fun, &asset.id) { (Fungibility::Fungible(ref amount), XcmAssetId(ref location)) => (amount, location), _ => return Err(MatchError::AssetNotHandled), }; - if let Some(asset_id) = ForeignAssetToAssetId::::get(&location) { + if let Some((asset_id, asset_status)) = AssetsByLocation::::get(&location) { Ok(( Pallet::::contract_address_from_asset_id(asset_id), U256::from(*amount), + asset_status, )) } else { Err(MatchError::AssetNotHandled) @@ -102,13 +102,24 @@ impl MatchesFungibles for ForeignAssetsMatcher } } +#[derive(Decode, Encode, PartialEq, TypeInfo)] +#[cfg_attr(test, derive(Debug))] +pub enum AssetStatus { + /// All operations are enabled + Active, + /// The asset is frozen, but deposit from XCM are still enabled + Frozen, + /// The asset is fully disabled, deposit from XCM will fail + Disabled, +} + #[pallet] pub mod pallet { use super::*; use pallet_evm::Runner; - use sp_runtime::traits::{AccountIdConversion, MaybeEquivalence}; + use sp_runtime::traits::AccountIdConversion; use xcm_executor::traits::ConvertLocation; - use xcm_executor::traits::{Error as MatchError, MatchesFungibles}; + use xcm_executor::traits::Error as MatchError; use xcm_executor::AssetsInHolding; #[pallet::pallet] @@ -171,6 +182,7 @@ pub mod pallet { AssetDoesNotExist, AssetAlreadyFrozen, AssetNotFrozen, + CorruptedStorageOrphanLocation, Erc20ContractCreationFail, EvmCallPauseFail, EvmCallUnpauseFail, @@ -186,32 +198,32 @@ pub mod pallet { /// New asset with the asset manager is registered ForeignAssetCreated { asset_id: AssetId, - foreign_asset: Location, + xcm_location: Location, }, /// Changed the xcm type mapping for a given asset id ForeignAssetTypeChanged { asset_id: AssetId, - new_foreign_asset: Location, + new_xcm_location: Location, }, /// Removed all information related to an assetId ForeignAssetRemoved { asset_id: AssetId, - foreign_asset: Location, + xcm_location: Location, }, // Freezes all tokens of a given asset id ForeignAssetFrozen { asset_id: AssetId, - foreign_asset: Location, + xcm_location: Location, }, // Thawing a previously frozen asset ForeignAssetUnfrozen { asset_id: AssetId, - foreign_asset: Location, + xcm_location: Location, }, /// Removed all information related to an assetId and destroyed asset ForeignAssetDestroyed { asset_id: AssetId, - foreign_asset: Location, + xcm_location: Location, }, } @@ -219,21 +231,17 @@ pub mod pallet { /// This is mostly used when receiving transaction specifying an asset directly, /// like transferring an asset from this chain to another. #[pallet::storage] - #[pallet::getter(fn foreign_asset_for_id)] - pub type AssetIdToForeignAsset = + #[pallet::getter(fn assets_by_id)] + pub type AssetsById = CountedStorageMap<_, Blake2_128Concat, AssetId, Location, OptionQuery>; - /// Reverse mapping of AssetIdToForeignAsset. Mapping from a foreign asset to an asset id. + /// Reverse mapping of AssetsById. Mapping from a foreign asset to an asset id. /// This is mostly used when receiving a multilocation XCM message to retrieve /// the corresponding asset in which tokens should me minted. #[pallet::storage] - #[pallet::getter(fn asset_id_for_foreign)] - pub type ForeignAssetToAssetId = StorageMap<_, Blake2_128Concat, Location, AssetId>; - - #[pallet::storage] - #[pallet::getter(fn frozen_assets)] - pub type FrozenAssets = - StorageValue<_, BoundedVec, ValueQuery>; + #[pallet::getter(fn assets_by_location)] + pub type AssetsByLocation = + StorageMap<_, Blake2_128Concat, Location, (AssetId, AssetStatus)>; impl Pallet { /// The account ID of this pallet @@ -258,7 +266,7 @@ pub mod pallet { #[pallet::weight(::WeightInfo::create_foreign_asset())] pub fn create_foreign_asset( origin: OriginFor, - foreign_asset: Location, + xcm_location: Location, asset_id: AssetId, decimals: u8, ticker: BoundedVec>, @@ -268,31 +276,30 @@ pub mod pallet { // Ensure such an assetId does not exist ensure!( - AssetIdToForeignAsset::::get(&asset_id).is_none(), + AssetsById::::get(&asset_id).is_none(), Error::::AssetAlreadyExists ); ensure!( - AssetIdToForeignAsset::::count() < T::MaxForeignAssets::get(), + AssetsById::::count() < T::MaxForeignAssets::get(), Error::::TooManyForeignAssets ); let ticker = core::str::from_utf8(&ticker).map_err(|_| Error::::InvalidTicker)?; let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; - // TODO submit create eth-xcm call EvmCaller::::erc20_create(asset_id, decimals, ticker, name)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId - AssetIdToForeignAsset::::insert(&asset_id, &foreign_asset); - ForeignAssetToAssetId::::insert(&foreign_asset, &asset_id); + AssetsById::::insert(&asset_id, &xcm_location); + AssetsByLocation::::insert(&xcm_location, (asset_id, AssetStatus::Active)); - T::OnForeignAssetCreated::on_asset_created(&foreign_asset, &asset_id); + T::OnForeignAssetCreated::on_asset_created(&xcm_location, &asset_id); Self::deposit_event(Event::ForeignAssetCreated { asset_id, - foreign_asset, + xcm_location, }); Ok(()) } @@ -305,23 +312,24 @@ pub mod pallet { pub fn change_existing_asset_type( origin: OriginFor, asset_id: AssetId, - new_foreign_asset: Location, + new_xcm_location: Location, ) -> DispatchResult { T::ForeignAssetModifierOrigin::ensure_origin(origin)?; - let previous_foreign_asset = - AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - - // Insert new foreign asset info - AssetIdToForeignAsset::::insert(&asset_id, &new_foreign_asset); - ForeignAssetToAssetId::::insert(&new_foreign_asset, &asset_id); + let previous_location = + AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; // Remove previous foreign asset info - ForeignAssetToAssetId::::remove(&previous_foreign_asset); + let (_asset_id, asset_status) = AssetsByLocation::::take(&previous_location) + .ok_or(Error::::CorruptedStorageOrphanLocation)?; + + // Insert new foreign asset info + AssetsById::::insert(&asset_id, &new_xcm_location); + AssetsByLocation::::insert(&new_xcm_location, (asset_id, asset_status)); Self::deposit_event(Event::ForeignAssetTypeChanged { asset_id, - new_foreign_asset, + new_xcm_location, }); Ok(()) } @@ -335,17 +343,17 @@ pub mod pallet { ) -> DispatchResult { T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; - let foreign_asset = - AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + let xcm_location = + AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - // Remove from AssetIdToForeignAsset - AssetIdToForeignAsset::::remove(&asset_id); - // Remove from ForeignAssetToAssetId - ForeignAssetToAssetId::::remove(&foreign_asset); + // Remove from AssetsById + AssetsById::::remove(&asset_id); + // Remove from AssetsByLocation + AssetsByLocation::::remove(&xcm_location); Self::deposit_event(Event::ForeignAssetRemoved { asset_id, - foreign_asset, + xcm_location, }); Ok(()) } @@ -356,26 +364,22 @@ pub mod pallet { pub fn freeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetFreezerOrigin::ensure_origin(origin)?; - let foreign_asset = - AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + let xcm_location = + AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - let mut frozen_assets: Vec<_> = FrozenAssets::::get().into(); - let index = match frozen_assets.binary_search_by(|i| i.cmp(&asset_id)) { - Ok(_) => return Err(Error::::AssetAlreadyFrozen.into()), - Err(index) => index, - }; + let (_asset_id, asset_status) = AssetsByLocation::::get(&xcm_location) + .ok_or(Error::::CorruptedStorageOrphanLocation)?; - EvmCaller::::erc20_pause(asset_id.clone())?; + ensure!( + asset_status == AssetStatus::Active, + Error::::AssetAlreadyFrozen + ); - frozen_assets.insert(index, asset_id); - let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets - .try_into() - .map_err(|_| Error::::TooManyForeignAssets)?; - FrozenAssets::::put(frozen_assets_bounded); + EvmCaller::::erc20_pause(asset_id.clone())?; Self::deposit_event(Event::ForeignAssetFrozen { asset_id, - foreign_asset, + xcm_location, }); Ok(()) } @@ -386,46 +390,47 @@ pub mod pallet { pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; - let foreign_asset = - AssetIdToForeignAsset::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; + let xcm_location = + AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - let mut frozen_assets: Vec<_> = FrozenAssets::::get().into(); - let index = match frozen_assets.binary_search_by(|i| i.cmp(&asset_id)) { - Ok(index) => index, - Err(_) => return Err(Error::::AssetNotFrozen.into()), - }; + let (_asset_id, asset_status) = AssetsByLocation::::get(&xcm_location) + .ok_or(Error::::CorruptedStorageOrphanLocation)?; - EvmCaller::::erc20_unpause(asset_id.clone())?; + ensure!( + asset_status == AssetStatus::Frozen, + Error::::AssetNotFrozen + ); - frozen_assets.remove(index); - let frozen_assets_bounded: BoundedVec<_, T::MaxForeignAssets> = frozen_assets - .try_into() - .map_err(|_| Error::::TooManyForeignAssets)?; - FrozenAssets::::put(frozen_assets_bounded); + EvmCaller::::erc20_unpause(asset_id.clone())?; Self::deposit_event(Event::ForeignAssetUnfrozen { asset_id, - foreign_asset, + xcm_location, }); Ok(()) } } - impl MaybeEquivalence for Pallet { - fn convert(foreign_asset: &Location) -> Option { - Pallet::::asset_id_for_foreign(foreign_asset.clone()) + /*impl MaybeEquivalence for Pallet { + fn convert(xcm_location: &Location) -> Option { + Pallet::::assets_by_location(xcm_location.clone()) } fn convert_back(id: &AssetId) -> Option { - Pallet::::foreign_asset_for_id(id.clone()) + Pallet::::assets_by_id(id.clone()) } - } + }*/ impl xcm_executor::traits::TransactAsset for Pallet { // For optimization reasons, the asset we want to deposit has not really been withdrawn, // we have just traced from which account it should have been withdrawn. // So we will retrieve these information and make the transfer from the origin account. fn deposit_asset(what: &Asset, who: &Location, _context: Option<&XcmContext>) -> XcmResult { - let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(what)?; + let (contract_address, amount, asset_status) = + ForeignAssetsMatcher::::match_asset(what)?; + + if let AssetStatus::Disabled = asset_status { + return Err(MatchError::AssetNotHandled.into()); + } let beneficiary = T::AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; @@ -445,7 +450,12 @@ pub mod pallet { to: &Location, _context: &XcmContext, ) -> Result { - let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(asset)?; + let (contract_address, amount, asset_status) = + ForeignAssetsMatcher::::match_asset(asset)?; + + if let AssetStatus::Disabled | AssetStatus::Frozen = asset_status { + return Err(MatchError::AssetNotHandled.into()); + } let from = T::AccountIdConverter::convert_location(from) .ok_or(MatchError::AccountIdConversionFailed)?; @@ -474,10 +484,15 @@ pub mod pallet { who: &Location, _context: Option<&XcmContext>, ) -> Result { - let (contract_address, amount) = ForeignAssetsMatcher::::matches_fungibles(what)?; + let (contract_address, amount, asset_status) = + ForeignAssetsMatcher::::match_asset(what)?; let who = T::AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; + if let AssetStatus::Disabled | AssetStatus::Frozen = asset_status { + return Err(MatchError::AssetNotHandled.into()); + } + // We perform the evm transfers in a storage transaction to ensure that if it fail // any contract storage changes are rolled back. frame_support::storage::with_storage_layer(|| { diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index c02949223a..cfc644bd1d 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -41,21 +41,21 @@ fn creating_foreign_works() { )); assert_eq!( - EvmForeignAssets::foreign_asset_for_id(1).unwrap(), + EvmForeignAssets::assets_by_id(1).unwrap(), Location::parent() ); assert_eq!( - EvmForeignAssets::asset_id_for_foreign(Location::parent()).unwrap(), - 1 + EvmForeignAssets::assets_by_location(Location::parent()).unwrap(), + (1, AssetStatus::Active), ); expect_events(vec![crate::Event::ForeignAssetCreated { asset_id: 1, - foreign_asset: Location::parent(), + xcm_location: Location::parent(), }]); - let (foreign_asset, asset_id): (Location, u128) = get_asset_created_hook_invocation() + let (xcm_location, asset_id): (Location, u128) = get_asset_created_hook_invocation() .expect("Decoding of invocation data should not fail"); - assert_eq!(foreign_asset, Location::parent()); + assert_eq!(xcm_location, Location::parent()); assert_eq!(asset_id, 1u128); }); } @@ -72,7 +72,7 @@ fn test_asset_exists_error() { encode_token_name("Mytoken"), )); assert_eq!( - EvmForeignAssets::foreign_asset_for_id(1).unwrap(), + EvmForeignAssets::assets_by_id(1).unwrap(), Location::parent() ); assert_noop!( @@ -134,26 +134,23 @@ fn test_root_can_change_foreign_asset_for_asset_id() { )); // New associations are stablished + assert_eq!(EvmForeignAssets::assets_by_id(1).unwrap(), Location::here()); assert_eq!( - EvmForeignAssets::foreign_asset_for_id(1).unwrap(), - Location::here() - ); - assert_eq!( - EvmForeignAssets::asset_id_for_foreign(Location::here()).unwrap(), - 1 + EvmForeignAssets::assets_by_location(Location::here()).unwrap(), + (1, AssetStatus::Active), ); // Old ones are deleted - assert!(EvmForeignAssets::asset_id_for_foreign(Location::parent()).is_none()); + assert!(EvmForeignAssets::assets_by_location(Location::parent()).is_none()); expect_events(vec![ crate::Event::ForeignAssetCreated { asset_id: 1, - foreign_asset: Location::parent(), + xcm_location: Location::parent(), }, crate::Event::ForeignAssetTypeChanged { asset_id: 1, - new_foreign_asset: Location::here(), + new_xcm_location: Location::here(), }, ]) }); @@ -191,17 +188,17 @@ fn test_root_can_remove_asset_association() { )); // Mappings are deleted - assert!(EvmForeignAssets::foreign_asset_for_id(1).is_none()); - assert!(EvmForeignAssets::asset_id_for_foreign(Location::parent()).is_none()); + assert!(EvmForeignAssets::assets_by_id(1).is_none()); + assert!(EvmForeignAssets::assets_by_location(Location::parent()).is_none()); expect_events(vec![ crate::Event::ForeignAssetCreated { asset_id: 1, - foreign_asset: Location::parent(), + xcm_location: Location::parent(), }, crate::Event::ForeignAssetRemoved { asset_id: 1, - foreign_asset: Location::parent(), + xcm_location: Location::parent(), }, ]) }); From 7eacdcda2e096e72b30efc3854215a9a027b5154 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Thu, 18 Jul 2024 11:53:28 +0200 Subject: [PATCH 18/71] forbid old AssetsIds (with filter) and rework freeze mechanism --- pallets/moonbeam-foreign-assets/src/lib.rs | 62 ++++++++++++++------- pallets/moonbeam-foreign-assets/src/mock.rs | 1 + runtime/moonbase/src/xcm_config.rs | 10 ++++ 3 files changed, 52 insertions(+), 21 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 2baa46a649..44575cefeb 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -54,6 +54,7 @@ use self::evm::EvmCaller; use ethereum_types::{H160, U256}; use frame_support::pallet; use frame_support::pallet_prelude::*; +use frame_support::traits::Contains; use frame_system::pallet_prelude::*; use xcm::latest::{ Asset, AssetId as XcmAssetId, Error as XcmError, Fungibility, Location, Result as XcmResult, @@ -107,10 +108,10 @@ impl ForeignAssetsMatcher { pub enum AssetStatus { /// All operations are enabled Active, - /// The asset is frozen, but deposit from XCM are still enabled - Frozen, - /// The asset is fully disabled, deposit from XCM will fail - Disabled, + /// The asset is frozen, but deposit from XCM still work + FrozenXcmDepositAllowed, + /// The asset is frozen, and deposit from XCM will fail + FrozenXcmDepositForbidden, } #[pallet] @@ -137,6 +138,9 @@ pub mod pallet { // Convert XCM Location to H160 type AccountIdConverter: ConvertLocation; + /// A filter to forbid some AssetId values, if you don't use it, put "Everything" + type AssetIdFilter: Contains; + /// EVM runner type EvmRunner: Runner; @@ -179,8 +183,9 @@ pub mod pallet { #[pallet::error] pub enum Error { AssetAlreadyExists, - AssetDoesNotExist, AssetAlreadyFrozen, + AssetDoesNotExist, + AssetIdFiltered, AssetNotFrozen, CorruptedStorageOrphanLocation, Erc20ContractCreationFail, @@ -285,6 +290,11 @@ pub mod pallet { Error::::TooManyForeignAssets ); + ensure!( + T::AssetIdFilter::contains(&asset_id), + Error::::AssetIdFiltered + ); + let ticker = core::str::from_utf8(&ticker).map_err(|_| Error::::InvalidTicker)?; let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; @@ -361,7 +371,11 @@ pub mod pallet { /// Freeze a given foreign assetId #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] - pub fn freeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { + pub fn freeze_foreign_asset( + origin: OriginFor, + asset_id: AssetId, + allow_xcm_deposit: bool, + ) -> DispatchResult { T::ForeignAssetFreezerOrigin::ensure_origin(origin)?; let xcm_location = @@ -375,7 +389,15 @@ pub mod pallet { Error::::AssetAlreadyFrozen ); - EvmCaller::::erc20_pause(asset_id.clone())?; + EvmCaller::::erc20_pause(asset_id)?; + + let new_asset_status = if allow_xcm_deposit { + AssetStatus::FrozenXcmDepositAllowed + } else { + AssetStatus::FrozenXcmDepositForbidden + }; + + AssetsByLocation::::insert(&xcm_location, (asset_id, new_asset_status)); Self::deposit_event(Event::ForeignAssetFrozen { asset_id, @@ -397,11 +419,14 @@ pub mod pallet { .ok_or(Error::::CorruptedStorageOrphanLocation)?; ensure!( - asset_status == AssetStatus::Frozen, + asset_status == AssetStatus::FrozenXcmDepositAllowed + || asset_status == AssetStatus::FrozenXcmDepositForbidden, Error::::AssetNotFrozen ); - EvmCaller::::erc20_unpause(asset_id.clone())?; + EvmCaller::::erc20_unpause(asset_id)?; + + AssetsByLocation::::insert(&xcm_location, (asset_id, AssetStatus::Active)); Self::deposit_event(Event::ForeignAssetUnfrozen { asset_id, @@ -411,15 +436,6 @@ pub mod pallet { } } - /*impl MaybeEquivalence for Pallet { - fn convert(xcm_location: &Location) -> Option { - Pallet::::assets_by_location(xcm_location.clone()) - } - fn convert_back(id: &AssetId) -> Option { - Pallet::::assets_by_id(id.clone()) - } - }*/ - impl xcm_executor::traits::TransactAsset for Pallet { // For optimization reasons, the asset we want to deposit has not really been withdrawn, // we have just traced from which account it should have been withdrawn. @@ -428,7 +444,7 @@ pub mod pallet { let (contract_address, amount, asset_status) = ForeignAssetsMatcher::::match_asset(what)?; - if let AssetStatus::Disabled = asset_status { + if let AssetStatus::FrozenXcmDepositForbidden = asset_status { return Err(MatchError::AssetNotHandled.into()); } @@ -453,7 +469,9 @@ pub mod pallet { let (contract_address, amount, asset_status) = ForeignAssetsMatcher::::match_asset(asset)?; - if let AssetStatus::Disabled | AssetStatus::Frozen = asset_status { + if let AssetStatus::FrozenXcmDepositForbidden | AssetStatus::FrozenXcmDepositAllowed = + asset_status + { return Err(MatchError::AssetNotHandled.into()); } @@ -489,7 +507,9 @@ pub mod pallet { let who = T::AccountIdConverter::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; - if let AssetStatus::Disabled | AssetStatus::Frozen = asset_status { + if let AssetStatus::FrozenXcmDepositForbidden | AssetStatus::FrozenXcmDepositAllowed = + asset_status + { return Err(MatchError::AssetNotHandled.into()); } diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index a349dbcab3..430d35fbfb 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -205,6 +205,7 @@ impl ForeignAssetDestroyedHook for NoteDownH impl crate::Config for Test { type AccountId = AccountId; type AccountIdConverter = (); + type AssetIdFilter = Everything; type EvmRunner = pallet_evm::runner::stack::Runner; type ForeignAssetCreatorOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index b10dc7f4ee..11fb7c45dd 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -710,9 +710,19 @@ impl pallet_erc20_xcm_bridge::Config for Runtime { type EvmRunner = EvmRunnerPrecompileOrEthXcm; } +pub struct EvmForeignAssetIdFilter; +impl frame_support::traits::Contains for EvmForeignAssetIdFilter { + fn contains(asset_id: &AssetId) -> bool { + use xcm_primitives::AssetTypeGetter as _; + // We should return true only if the AssetId doesn't exist in AssetManager + AssetManager::get_asset_type(*asset_id).is_none() + } +} + impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountId = AccountId; type AccountIdConverter = LocationToH160; + type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; type ForeignAssetCreatorOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; From 4b66d8a607f09b2e259a7597188777e0dc0a2237 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Thu, 18 Jul 2024 12:28:15 +0200 Subject: [PATCH 19/71] fix rust compilation for pallet-moonbeam-foreign-assets alone --- Cargo.lock | 2 -- pallets/moonbeam-foreign-assets/Cargo.toml | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edfed48fca..2d4dfffb02 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9696,7 +9696,6 @@ dependencies = [ name = "pallet-moonbeam-foreign-assets" version = "0.1.0" dependencies = [ - "environmental", "ethereum-types", "fp-evm", "frame-benchmarking", @@ -9711,7 +9710,6 @@ dependencies = [ "precompile-utils", "precompile-utils-macro", "scale-info", - "serde", "sp-core", "sp-io", "sp-runtime", diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index 712253fae9..87446c7e82 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -5,10 +5,8 @@ edition = "2021" version = "0.1.0" [dependencies] -environmental = { workspace = true } ethereum-types = { workspace = true } log = { workspace = true } -serde = { workspace = true, optional = true } # Substrate frame-support = { workspace = true } @@ -44,13 +42,15 @@ sp-core = { workspace = true, features = [ "std" ] } [features] default = [ "std" ] std = [ + "ethereum-types/std", "frame-benchmarking/std", "frame-support/std", "frame-system/std", + "precompile-utils/std", + "precompile-utils/testing", "pallet-evm/std", "parity-scale-codec/std", "scale-info/std", - "serde", "sp-io/std", "sp-runtime/std", "sp-std/std", From 67fc5bea6f104f749b5ae14519a16a50d410cb2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Thu, 18 Jul 2024 15:12:32 +0200 Subject: [PATCH 20/71] fix: calldata need hex bytecode --- pallets/moonbeam-foreign-assets/build.rs | 29 ---------------------- pallets/moonbeam-foreign-assets/src/evm.rs | 19 ++++++++++++-- 2 files changed, 17 insertions(+), 31 deletions(-) delete mode 100644 pallets/moonbeam-foreign-assets/build.rs diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs deleted file mode 100644 index e916918e96..0000000000 --- a/pallets/moonbeam-foreign-assets/build.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::fs::File; -use std::io::prelude::*; - -// Length of encoded constructor parameters -const PARAMS_LEN: usize = 256; - -fn main() { - let hex_str = include_str!("resources/foreign_erc20_initcode.hex"); - let prefix_0x = hex_str.chars().nth(1) == Some('x'); - let bytecode = if prefix_0x { - hex::decode(&hex_str[2..]) - } else { - hex::decode(hex_str) - } - .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); - - // The encoded parameters at the end of the initializer bytecode should be removed, - // (the runtime will append the constructor parameters dynamically). - let bytecode_end = if bytecode.len() > PARAMS_LEN { - bytecode.len() - PARAMS_LEN - } else { - 0 - }; - - let mut file = File::create("resources/foreign_erc20_initcode.bin") - .expect("Fail to create file resources/foreign_erc20_initcode.bin"); - file.write_all(&bytecode[..bytecode_end]) - .expect("fail to write bytecode in /foreign_erc20_initcode.bin"); -} diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index d40881979e..296a71a2f3 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -89,6 +89,10 @@ struct ForeignErc20ConstructorArgs { pub(crate) struct EvmCaller(core::marker::PhantomData); + +// Length of encoded constructor parameters +const PARAMS_LEN: usize = 256; + impl EvmCaller { /// Deploy foreign asset erc20 contract pub(crate) fn erc20_create( @@ -97,9 +101,20 @@ impl EvmCaller { ticker: &str, token_name: &str, ) -> Result<(), Error> { + // Get contract initializer code + let init_code_str = include_str!("../resources/foreign_erc20_initcode.hex"); + + // The encoded parameters at the end of the initializer bytecode should be removed, + // (the runtime will append the constructor parameters dynamically). + let init_code_end = if init_code_str.len() > PARAMS_LEN { + init_code_str.len() - PARAMS_LEN + } else { + 0 + }; + // Get init code let mut init = Vec::with_capacity(ERC20_CREATE_MAX_CALLDATA_SIZE); - init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); + init.extend_from_slice(init_code_str[..init_code_end].as_bytes()); // Add constructor parameters let args = ForeignErc20ConstructorArgs { @@ -122,7 +137,7 @@ impl EvmCaller { None, None, Default::default(), - true, + false, false, None, None, From 378c1b65f58bd5cb0dcd79db1ab39107ada75fef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Thu, 18 Jul 2024 17:14:07 +0200 Subject: [PATCH 21/71] wip --- pallets/moonbeam-foreign-assets/src/evm.rs | 11 +++++++---- pallets/moonbeam-foreign-assets/src/lib.rs | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 296a71a2f3..40423eca76 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -89,7 +89,6 @@ struct ForeignErc20ConstructorArgs { pub(crate) struct EvmCaller(core::marker::PhantomData); - // Length of encoded constructor parameters const PARAMS_LEN: usize = 256; @@ -100,7 +99,7 @@ impl EvmCaller { decimals: u8, ticker: &str, token_name: &str, - ) -> Result<(), Error> { + ) -> Result> { // Get contract initializer code let init_code_str = include_str!("../resources/foreign_erc20_initcode.hex"); @@ -128,6 +127,8 @@ impl EvmCaller { .build(); init.extend(encoded_args); + let contract_adress = Pallet::::contract_address_from_asset_id(asset_id); + let exec_info = T::EvmRunner::create_force_address( Pallet::::account_id(), init, @@ -142,10 +143,12 @@ impl EvmCaller { None, None, &::config(), - Pallet::::contract_address_from_asset_id(asset_id), + contract_adress, ) .map_err(|_| Error::Erc20ContractCreationFail)?; + //println!("exec_info: {:?}", &exec_info); + ensure!( matches!( exec_info.exit_reason, @@ -154,7 +157,7 @@ impl EvmCaller { Error::Erc20ContractCreationFail ); - Ok(()) + Ok(contract_adress) } pub(crate) fn erc20_mint_into( diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 44575cefeb..be7243fba8 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -202,6 +202,7 @@ pub mod pallet { pub enum Event { /// New asset with the asset manager is registered ForeignAssetCreated { + contract_address: H160, asset_id: AssetId, xcm_location: Location, }, @@ -271,8 +272,8 @@ pub mod pallet { #[pallet::weight(::WeightInfo::create_foreign_asset())] pub fn create_foreign_asset( origin: OriginFor, - xcm_location: Location, asset_id: AssetId, + xcm_location: Location, decimals: u8, ticker: BoundedVec>, name: BoundedVec>, @@ -298,7 +299,7 @@ pub mod pallet { let ticker = core::str::from_utf8(&ticker).map_err(|_| Error::::InvalidTicker)?; let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; - EvmCaller::::erc20_create(asset_id, decimals, ticker, name)?; + let contract_address = EvmCaller::::erc20_create(asset_id, decimals, ticker, name)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId @@ -308,6 +309,7 @@ pub mod pallet { T::OnForeignAssetCreated::on_asset_created(&xcm_location, &asset_id); Self::deposit_event(Event::ForeignAssetCreated { + contract_address, asset_id, xcm_location, }); From 826dd2ca9d94613a1f7c40a0e0549638d99b0a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 11:56:24 +0200 Subject: [PATCH 22/71] Revert "fix: calldata need hex bytecode" This reverts commit 67fc5bea6f104f749b5ae14519a16a50d410cb2f. --- pallets/moonbeam-foreign-assets/build.rs | 29 ++++++++++++++++++++++ pallets/moonbeam-foreign-assets/src/evm.rs | 16 +----------- 2 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 pallets/moonbeam-foreign-assets/build.rs diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs new file mode 100644 index 0000000000..e916918e96 --- /dev/null +++ b/pallets/moonbeam-foreign-assets/build.rs @@ -0,0 +1,29 @@ +use std::fs::File; +use std::io::prelude::*; + +// Length of encoded constructor parameters +const PARAMS_LEN: usize = 256; + +fn main() { + let hex_str = include_str!("resources/foreign_erc20_initcode.hex"); + let prefix_0x = hex_str.chars().nth(1) == Some('x'); + let bytecode = if prefix_0x { + hex::decode(&hex_str[2..]) + } else { + hex::decode(hex_str) + } + .expect("fail to decode hexadecimal string in file foreign_erc20_initcode.hex"); + + // The encoded parameters at the end of the initializer bytecode should be removed, + // (the runtime will append the constructor parameters dynamically). + let bytecode_end = if bytecode.len() > PARAMS_LEN { + bytecode.len() - PARAMS_LEN + } else { + 0 + }; + + let mut file = File::create("resources/foreign_erc20_initcode.bin") + .expect("Fail to create file resources/foreign_erc20_initcode.bin"); + file.write_all(&bytecode[..bytecode_end]) + .expect("fail to write bytecode in /foreign_erc20_initcode.bin"); +} diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 40423eca76..10ccc3031b 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -89,9 +89,6 @@ struct ForeignErc20ConstructorArgs { pub(crate) struct EvmCaller(core::marker::PhantomData); -// Length of encoded constructor parameters -const PARAMS_LEN: usize = 256; - impl EvmCaller { /// Deploy foreign asset erc20 contract pub(crate) fn erc20_create( @@ -100,20 +97,9 @@ impl EvmCaller { ticker: &str, token_name: &str, ) -> Result> { - // Get contract initializer code - let init_code_str = include_str!("../resources/foreign_erc20_initcode.hex"); - - // The encoded parameters at the end of the initializer bytecode should be removed, - // (the runtime will append the constructor parameters dynamically). - let init_code_end = if init_code_str.len() > PARAMS_LEN { - init_code_str.len() - PARAMS_LEN - } else { - 0 - }; - // Get init code let mut init = Vec::with_capacity(ERC20_CREATE_MAX_CALLDATA_SIZE); - init.extend_from_slice(init_code_str[..init_code_end].as_bytes()); + init.extend_from_slice(include_bytes!("../resources/foreign_erc20_initcode.bin")); // Add constructor parameters let args = ForeignErc20ConstructorArgs { From 10a6fdcf85145327ca2983c59eff53a63d06c3f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 12:50:41 +0200 Subject: [PATCH 23/71] recompile solidity contract with solc 0.8.26+commit8a97fa7a --- .../resources/foreign_erc20_initcode.bin | Bin 0 -> 11711 bytes .../resources/foreign_erc20_initcode.hex | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.bin diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.bin b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.bin new file mode 100644 index 0000000000000000000000000000000000000000..4ccab04d80d1ed05100a0b649cac7601eb8b2957 GIT binary patch literal 11711 zcmd5?d6*Q{wV&$heSq0}n3Yjz| zvu9wyPe>lF1fC*_`cPbWL5(ObfoL=a!3`C0dGZ7`Ebn)2RrM@%&kXucnva^hoO|xs z@3{*}npWTVOTB^$iWODglZa{c4RqvlC&@a#sgn&uLcbwpsNfgv8S*?7Pv|;8@Si($ zO)?s_sFWO0(D%=1jJ2d&3{B1$RPZ}s^2g(en6A0GKHI6sVyfm*Nh$~$O@_A5RTavl zDk@x+nej1o+P)mWkdeDtCTXamg3e^!xMz0tMH7w!2+{|ff@^H`>?@UfxST{BtP z0_E8Hxi=PLCZef^;tF#8Qz6%zDUv5T^2@|XcEuA=$#yjV#c5V0Sexqy$J(@gYE34V z=x7(nlC!3*eR1Kcy{9)Ez5e`N7q6dw(0|@mxv=PmmzOTNwDE|O>x;B44Uk2{=wq3T zs6_HPo%7~)u-)7!>_&?kDOoleGwc_Z(lfCP$kfeDOp6!|B^4wuS4<2~9y{T%rTtr_ zd_S-U2Y0hdy}=;)DKt(1-f*Q_1KQg&EDIxJ7l7WLb`Pe;|D3`$Lk>K-gC@!E#}jq~ zxvLFw7sL}rIk^wEVglm_R&pPYu9CPTGHqWL4Y_0JI@KCAq1UKu&~;9B6w}22wMdl~ zNl6YN$qUZCZE9aKQ5&_hGtSB?x_GXfbzbysYP2P@|+1eV=>!Ebye5&=2p2BcwfMP=ShAC161;CXf@j;avv5? z%!`3s@_cADTpCZzMMHhF)R1M=09jtQLSC8VO-z=zSO9x;C<(yYe!wFDe5?a}dKQ=o z>ujGF>kt+Q3lS0>h$e?Snp8EH>4tzMGo+JufubeNP1kTG~+mtKPWl$IFRIAa<5fiHQ4*|qx zgS;yk$ERuX{+S&`i#GG{T?z?KsjU|L9bT{1LWLQ**h@N@p1PL7;a`Jki7E{J&Mme~ay0e$xc&usHJ1G2s-x zSHZmor9zn{;H#Yc&njvf>^!KLtrCn2kWVz5F7Jmn=ok z?A3V55czPCoe#TDCya~nSC?2%x1}?5w#M(~M`Q&zsyoIETk;GKji3+FIJCIucPIK!g$Ov5|-NL=E z!yMi7Z1@>yslhsCr+N(kU>E!n?&Torem0&cK;IMOe%Btkmiun)F>-6y$oIJyF_YXM z+3-8|o5|(I>TmVBO1O7#cWkcV4wLsT8|HA}s(raf?l<-WgR9{=0+Jezr*9&&ZN zy5RS4FY6&NfpKY?ChJY)F3V5^`IoLmuzKq47!k#;w;>}o#X53-Y}3$WGVGZ)EE3R} z3Pu!@o8U7fNg4F&sSvTulzX zFC2V39ef_S8Ow0t85ryt(hSsvZ`i1v%P${F!hqhLWqe)2qG&-E0-_}_UlPKX8fp4X7#3$B@M^8C}J zA&Zzsd*tUf*bW-ZW803RRv-$e&fC7u2veMerNMyCXx0Mvcot!wm%+;3=VI?@w@x9*D-?86JPMP|} z^3q41Opc9cCl-BGT&&*n!*c1+l3#}wO-^4*hpuaDYa_pRHWi;7Pt3qnP$BulPC$&n zenexAUA{{GGfXO;%@&68ShKaYm5T4@>Wn-Vox2%H@Bb+JOy=`EeaPtk`Sh>i6Nt#a z1Z^Cwu{ZXwpE+};2n<$!$X~V|NloXTHFs+dr~7ICYAZJ|Q7AX}iA4URyugM7Im!#H zgFw2iPY_7pT|)#2NPz-d#oCO#vsPg-zjK=R@_xk(Kufj|<8fA?3m%tBrEoe{ype5` zF$e2~Y3CLu1uqjTXzt!}3O<7@7>O}LJ5yCM`yWgCr3z_tZ&pEH?itM7%`z1pV+nWu zi+k$&pRw@J-ZN6+DW;mD(t9jdRjF_c_N=_@W@7y&_1NSUzO0CCZQ*JKCo9bRzwS8e z(E(8Ms5pCz4)1RHh3jzWl9pAW6|sKi6-b`-N2WnY^_h%;31rZTy#;ch3K+D)ns584 zV?6z{J&5z)p4L5RH7wCq0Q-5eFD%@b+Z6H~HkV^P8+@t~>lf?j@&q8SRQd%(>N0p5 z{AKX9Pwhylvym zZ6B?ewu}a^aomRnbN<&&N_Pvy16Vx&?N7Y@KP?bj>CcdDVl~#Je3vcBiJ#2gCO!LM z^wkSSx~_kG+l>W-OIEDgbxzag@9u6o&vVa3RCH8U*hQ!8Cv4%ut_bODj2<(b;NGiw4x`EA2 z*~0_h+?2hW-Q1KPYHe=H_UyO0DaTH_ugy()VE@fc_9hGoLzUDQe+30bV+wa2QlqI2 z$5$I^M7z#ibv4;LS-Mo2GEKQJR=fGLV@6+D6J4BE!`KCtbG9Hi+x}kBzzdtiVF032 zg>7OB%EnW^(YlANuC?ye=%a3crWcV;64ifz$%j}^VL(u6oo3TrRe9_K$~`xfhOH*k}D|m zq=LoC0$zxoyLtjIN7F+#Fjagk>}%)QUvBP8{*aBE&u%RH(p)z7?}6&O9@s;J6bcnO z*h4tSRl^vU+`aYA0X!rK@%dLbpWTzdNfI+1ngp~Hd(Lz-nr_O@gacuo=kK##8`Li& z6yo#0Zs(7Ca6bkKQ|JY;v{UE}4iS~esKn+((^Lw*pQ0*_mk?aD^f=K7?E@iud!1UOG8Il?;Ckb0kL;GqE9Htru9b-pVTNk$$!%DV}+ut z$q|-@;^qSu_2c6-j*P@6V`x-KS(}WHVjE}oFXf??`)@M%azy{}s|_<0JK$Z~&<7pq z$dIrll%2xQ@~kkq-L=Q!#j=)cY>7NCHS(w{x#^q6hiX1}Y2j6WUUB8_6Xz`JJYvcJ zPI~_C(9gb|F!tMnR({1BIjXv_r!U~q1_uFM+m}+qp$xx?fMZnMFZ_39!x8(7qw7dI>$%Wd>Ef)z=MK z^$EBktJ=y=W#5num8BtjwHrR%pm61W14fDg;b?Y1a$jEo27O(R zXTrY&N?f>DG*EaJ!~%P;Ny=;D{OE_nuA`yw+8*Mh@ZYcogmH+D2s=d~jVY>~t)r&U6XtUd>Hp5rmtyBXOpxQt1 zm3Iq;O|C4{7V~8|%bAC+5ksGb7lya9L*2Q6Dc~Qg*)q}EO_pjf-ad$|-EQd|-c!4? zr}xzP4621W*pPK0OWA;|i}r#XVNf0X!SOS!P_WZ2Z8OlziRYjEtePMvAavg{P} z!A|S0&o;~#c3Njx4X{((>SGgJ*O6`D2R%B~-76YuzqcOrET+20L_^&{mKxSj-3!?U zcCpSo+vhF7A1mhCL7;9M==v;6*REbcAmYz9FbXRO{P_1gk$A87Jdvvuid;#NQp6xD zY!3u^_Su)Jtr0dAc^Dd_R0$HvrZSKeYPYO$;+@*!JMvt9X`ttc%j z3!nh;V}q#|=%Yh`9yZ1X$L~KGlq=bLFwFwP_TRC~=tu^$(MQKI6&CvJ9$Z^&4Z0eG zKrQT-qPOrMP%A3f^9gjK(r&%^5DpOiBa?2C(Cy8KrdtSC1EGWCB}NF25wiYkfcG2+C= Date: Fri, 19 Jul 2024 12:51:00 +0200 Subject: [PATCH 24/71] rust tests: fix pov ratio and storage ratio --- pallets/moonbeam-foreign-assets/src/mock.rs | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 430d35fbfb..9f8812aefc 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -109,21 +109,11 @@ impl pallet_timestamp::Config for Test { type WeightInfo = (); } -const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; -/// Block storage limit in bytes. Set to 40 KB. -const BLOCK_STORAGE_LIMIT: u64 = 40 * 1024; - parameter_types! { pub BlockGasLimit: U256 = U256::from(u64::MAX); pub const WeightPerGas: Weight = Weight::from_parts(1, 0); - pub GasLimitPovSizeRatio: u64 = { - let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); - block_gas_limit.saturating_div(MAX_POV_SIZE) - }; - pub GasLimitStorageGrowthRatio: u64 = { - let block_gas_limit = BlockGasLimit::get().min(u64::MAX.into()).low_u64(); - block_gas_limit.saturating_div(BLOCK_STORAGE_LIMIT) - }; + pub GasLimitPovSizeRatio: u64 = 16; + pub GasLimitStorageGrowthRatio: u64 = 366; } impl pallet_evm::Config for Test { From 93557c9d1c6996d090d81d6910fd9f1fae64b6f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 12:51:31 +0200 Subject: [PATCH 25/71] fix rust tests compilation --- pallets/moonbeam-foreign-assets/src/tests.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index cfc644bd1d..e12298a896 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -33,8 +33,8 @@ fn creating_foreign_works() { ExtBuilder::default().build().execute_with(|| { assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -49,6 +49,7 @@ fn creating_foreign_works() { (1, AssetStatus::Active), ); expect_events(vec![crate::Event::ForeignAssetCreated { + contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), asset_id: 1, xcm_location: Location::parent(), }]); @@ -65,8 +66,8 @@ fn test_asset_exists_error() { ExtBuilder::default().build().execute_with(|| { assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -78,8 +79,8 @@ fn test_asset_exists_error() { assert_noop!( EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -95,8 +96,8 @@ fn test_regular_user_cannot_call_extrinsics() { assert_noop!( EvmForeignAssets::create_foreign_asset( RuntimeOrigin::signed(Bob.into()), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -120,8 +121,8 @@ fn test_root_can_change_foreign_asset_for_asset_id() { ExtBuilder::default().build().execute_with(|| { assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -145,6 +146,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() { expect_events(vec![ crate::Event::ForeignAssetCreated { + contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), asset_id: 1, xcm_location: Location::parent(), }, @@ -175,8 +177,8 @@ fn test_root_can_remove_asset_association() { ExtBuilder::default().build().execute_with(|| { assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), - Location::parent(), 1, + Location::parent(), 18, encode_ticker("MTT"), encode_token_name("Mytoken"), @@ -193,6 +195,7 @@ fn test_root_can_remove_asset_association() { expect_events(vec![ crate::Event::ForeignAssetCreated { + contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), asset_id: 1, xcm_location: Location::parent(), }, From 73a05511d4b7559b4c19b8d98d12feaa319f63b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 13:00:11 +0200 Subject: [PATCH 26/71] fix constructor args encoding --- .../resources/foreign_erc20_initcode.bin | Bin 11711 -> 11455 bytes pallets/moonbeam-foreign-assets/src/evm.rs | 6 ++++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.bin b/pallets/moonbeam-foreign-assets/resources/foreign_erc20_initcode.bin index 4ccab04d80d1ed05100a0b649cac7601eb8b2957..a19de32a5759006d5e047f29f596cedcc58ac96e 100644 GIT binary patch delta 7 OcmdlVy+3lpejNZ1I|I%D delta 96 zcmdlVxj%ZtejNn{Bp`?dOfD3ZV`313Pz@030El8`VD=3O0kI}G2=aq42fJ@&NPc!| J-sFiak^oSe6cYdd diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 10ccc3031b..8bc128c2f2 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -33,7 +33,7 @@ const ERC20_CALL_MAX_CALLDATA_SIZE: usize = 4 + 32 + 32; // selector + address + const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko // hardcoded gas limits -const ERC20_CREATE_GAS_LIMIT: u64 = 500_000; +const ERC20_CREATE_GAS_LIMIT: u64 = 2_050_000; const ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; const ERC20_MINT_INTO_GAS_LIMIT: u64 = 50_000; const ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; @@ -80,6 +80,7 @@ impl From for XcmError { } #[derive(Codec)] +#[cfg_attr(test, derive(Debug))] struct ForeignErc20ConstructorArgs { owner: Address, decimals: u8, @@ -111,7 +112,8 @@ impl EvmCaller { let encoded_args = precompile_utils::solidity::codec::Writer::new() .write(args) .build(); - init.extend(encoded_args); + // Skip size of constructor args (32 bytes) + init.extend_from_slice(&encoded_args[32..]); let contract_adress = Pallet::::contract_address_from_asset_id(asset_id); From 446a1ceab9440f5a63d131d358bcb28b5bf05ac0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 13:10:30 +0200 Subject: [PATCH 27/71] test freeze/unfreeze --- pallets/moonbeam-foreign-assets/src/tests.rs | 57 +++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index e12298a896..13a6dc2e17 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -29,8 +29,9 @@ fn encode_token_name(str_: &str) -> BoundedVec> { } #[test] -fn creating_foreign_works() { +fn create_foreign_and_freeze_unfreeze() { ExtBuilder::default().build().execute_with(|| { + // create foreign asset assert_ok!(EvmForeignAssets::create_foreign_asset( RuntimeOrigin::root(), 1, @@ -58,6 +59,60 @@ fn creating_foreign_works() { .expect("Decoding of invocation data should not fail"); assert_eq!(xcm_location, Location::parent()); assert_eq!(asset_id, 1u128); + + // Check storage + assert_eq!( + EvmForeignAssets::assets_by_id(&1), + Some(Location::parent()) + ); + assert_eq!( + EvmForeignAssets::assets_by_location(&Location::parent()), + Some((1, AssetStatus::Active)) + ); + + // Unfreeze should return AssetNotFrozen error + assert_noop!( + EvmForeignAssets::unfreeze_foreign_asset( + RuntimeOrigin::root(), + 1 + ), + Error::::AssetNotFrozen + ); + + // Freeze should work + assert_ok!( + EvmForeignAssets::freeze_foreign_asset( + RuntimeOrigin::root(), + 1, + true + ), + ); + assert_eq!( + EvmForeignAssets::assets_by_location(&Location::parent()), + Some((1, AssetStatus::FrozenXcmDepositAllowed)) + ); + + // Should not be able to freeze an asset already frozen + assert_noop!( + EvmForeignAssets::freeze_foreign_asset( + RuntimeOrigin::root(), + 1, + true + ), + Error::::AssetAlreadyFrozen + ); + + // Unfreeze should work + assert_ok!( + EvmForeignAssets::unfreeze_foreign_asset( + RuntimeOrigin::root(), + 1 + ), + ); + assert_eq!( + EvmForeignAssets::assets_by_location(&Location::parent()), + Some((1, AssetStatus::Active)) + ); }); } From 470835b7fa8bd64c453c9500fa39b9282a9047af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 13:50:28 +0200 Subject: [PATCH 28/71] rewrite rust moonbase test asset_can_be_registered --- runtime/moonbase/tests/integration_test.rs | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 59fe3cf81e..7fbc8bfe67 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -39,7 +39,7 @@ use frame_support::{ use moonbase_runtime::{ asset_config::{AssetRegistrarMetadata, ForeignAssetInstance}, xcm_config::{AssetType, SelfReserve}, - AccountId, AssetId, AssetManager, Assets, Balances, CrowdloanRewards, Executive, + AccountId, AssetId, Assets, Balances, CrowdloanRewards, EvmForeignAssets, Executive, OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, TransactionPaymentAsGasPrice, TreasuryCouncilCollective, XTokens, XcmTransactor, @@ -66,7 +66,7 @@ use pallet_xcm_transactor::{Currency, CurrencyPayment, HrmpOperation, TransactWe use parity_scale_codec::Encode; use sha3::{Digest, Keccak256}; use sp_core::{crypto::UncheckedFrom, ByteArray, Pair, H160, H256, U256}; -use sp_runtime::{DispatchError, ModuleError}; +use sp_runtime::{bounded_vec, DispatchError, ModuleError}; use xcm::latest::prelude::*; type AuthorMappingPCall = @@ -1251,22 +1251,16 @@ fn update_reward_address_via_precompile() { #[test] fn asset_can_be_registered() { ExtBuilder::default().build().execute_with(|| { - let source_location = AssetType::Xcm(xcm::v3::Location::parent()); - let source_id: moonbase_runtime::AssetId = source_location.clone().into(); - let asset_metadata = AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }; - assert_ok!(AssetManager::register_foreign_asset( + let source_location = xcm::v4::Location::parent(); + assert_ok!(EvmForeignAssets::create_foreign_asset( moonbase_runtime::RuntimeOrigin::root(), + 1, source_location, - asset_metadata, - 1u128, - true, + 12, + bounded_vec![b'M', b'T'], + bounded_vec![b'M', b'y', b'T', b'o', b'k'], )); - assert!(AssetManager::asset_id_type(source_id).is_some()); + assert!(EvmForeignAssets::assets_by_id(1).is_some()); }); } From 93b903980aac40f33016825d39438dae0e0d98ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 14:12:15 +0200 Subject: [PATCH 29/71] estimate crate gas limit with manual binary search --- pallets/moonbeam-foreign-assets/src/evm.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 8bc128c2f2..9d4d13b6af 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -32,8 +32,8 @@ use xcm::latest::Error as XcmError; const ERC20_CALL_MAX_CALLDATA_SIZE: usize = 4 + 32 + 32; // selector + address + uint256 const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko -// hardcoded gas limits -const ERC20_CREATE_GAS_LIMIT: u64 = 2_050_000; +// Hardcoded gas limits (from manueal binary search) +const ERC20_CREATE_GAS_LIMIT: u64 = 3_367_000; // highest failure: 3_366_000 const ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; const ERC20_MINT_INTO_GAS_LIMIT: u64 = 50_000; const ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; From f0fb5beda0590c9635b8c5b2ef31fd8979865a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 15:34:12 +0200 Subject: [PATCH 30/71] determine gas limit for freeze/unfreeze --- pallets/moonbeam-foreign-assets/src/evm.rs | 4 +-- pallets/moonbeam-foreign-assets/src/lib.rs | 3 +- runtime/moonbase/tests/integration_test.rs | 33 ++++++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 9d4d13b6af..84796cbcf6 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -36,9 +36,9 @@ const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko const ERC20_CREATE_GAS_LIMIT: u64 = 3_367_000; // highest failure: 3_366_000 const ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; const ERC20_MINT_INTO_GAS_LIMIT: u64 = 50_000; -const ERC20_PAUSE_GAS_LIMIT: u64 = 500_000; +const ERC20_PAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 const ERC20_TRANSFER_GAS_LIMIT: u64 = 50_000; -const ERC20_UNPAUSE_GAS_LIMIT: u64 = 500_000; +const ERC20_UNPAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 pub(crate) enum EvmError { BurnFromFail, diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index be7243fba8..3faa797e62 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -103,8 +103,7 @@ impl ForeignAssetsMatcher { } } -#[derive(Decode, Encode, PartialEq, TypeInfo)] -#[cfg_attr(test, derive(Debug))] +#[derive(Decode, Debug, Encode, PartialEq, TypeInfo)] pub enum AssetStatus { /// All operations are enabled Active, diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 7fbc8bfe67..0f5e7a395f 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -61,6 +61,7 @@ use moonkit_xcm_primitives::AccountIdAssetIdConversion; use nimbus_primitives::NimbusId; use pallet_evm::PrecompileSet; use pallet_evm_precompileset_assets_erc20::{SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER}; +use pallet_moonbeam_foreign_assets::AssetStatus; use pallet_transaction_payment::Multiplier; use pallet_xcm_transactor::{Currency, CurrencyPayment, HrmpOperation, TransactWeights}; use parity_scale_codec::Encode; @@ -1249,18 +1250,44 @@ fn update_reward_address_via_precompile() { } #[test] -fn asset_can_be_registered() { +fn asset_can_be_registered_then_freeze_and_unfreeze() { ExtBuilder::default().build().execute_with(|| { let source_location = xcm::v4::Location::parent(); assert_ok!(EvmForeignAssets::create_foreign_asset( moonbase_runtime::RuntimeOrigin::root(), 1, - source_location, + source_location.clone(), 12, bounded_vec![b'M', b'T'], bounded_vec![b'M', b'y', b'T', b'o', b'k'], )); - assert!(EvmForeignAssets::assets_by_id(1).is_some()); + assert_eq!( + EvmForeignAssets::assets_by_id(1), + Some(source_location.clone()) + ); + assert_eq!( + EvmForeignAssets::assets_by_location(&source_location), + Some((1, AssetStatus::Active)) + ); + + assert_ok!(EvmForeignAssets::freeze_foreign_asset( + moonbase_runtime::RuntimeOrigin::root(), + 1, + true + )); + assert_eq!( + EvmForeignAssets::assets_by_location(&source_location), + Some((1, AssetStatus::FrozenXcmDepositAllowed)) + ); + + assert_ok!(EvmForeignAssets::unfreeze_foreign_asset( + moonbase_runtime::RuntimeOrigin::root(), + 1, + )); + assert_eq!( + EvmForeignAssets::assets_by_location(&source_location), + Some((1, AssetStatus::Active)) + ); }); } From 10e139154f3e025eedfa645d7d42412470da70d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 15:55:12 +0200 Subject: [PATCH 31/71] use branch moonbeam-polkadot-v1.11.0 --- Cargo.lock | 82 +++++++++++++++++++++++++++--------------------------- Cargo.toml | 80 ++++++++++++++++++++++++++-------------------------- 2 files changed, 81 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2d4dfffb02..4a1c2bc9f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -634,7 +634,7 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "async-backing-primitives" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "sp-api", "sp-consensus-slots", @@ -3372,7 +3372,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "async-trait", "fp-storage", @@ -3384,7 +3384,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "async-trait", "fp-consensus", @@ -3400,7 +3400,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "async-trait", "ethereum", @@ -3430,7 +3430,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fc-db", "fc-storage", @@ -3453,7 +3453,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "ethereum-types", @@ -3507,7 +3507,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "ethereum-types", @@ -3522,7 +3522,7 @@ dependencies = [ [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "ethereum-types", @@ -3716,7 +3716,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "hex", "impl-serde 0.4.0", @@ -3734,7 +3734,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "parity-scale-codec", @@ -3745,7 +3745,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "ethereum-types", @@ -3757,7 +3757,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "evm", "frame-support", @@ -3772,7 +3772,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "ethereum", "ethereum-types", @@ -3788,7 +3788,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "frame-support", "parity-scale-codec", @@ -3800,7 +3800,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "parity-scale-codec", "serde", @@ -7626,7 +7626,7 @@ dependencies = [ [[package]] name = "nimbus-consensus" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "async-backing-primitives", "async-trait", @@ -7666,7 +7666,7 @@ dependencies = [ [[package]] name = "nimbus-primitives" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "async-trait", "frame-benchmarking", @@ -8230,7 +8230,7 @@ dependencies = [ [[package]] name = "pallet-async-backing" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8250,7 +8250,7 @@ dependencies = [ [[package]] name = "pallet-author-inherent" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "frame-benchmarking", "frame-support", @@ -8269,7 +8269,7 @@ dependencies = [ [[package]] name = "pallet-author-mapping" version = "2.0.5" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "frame-benchmarking", "frame-support", @@ -8288,7 +8288,7 @@ dependencies = [ [[package]] name = "pallet-author-slot-filter" version = "0.9.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "frame-benchmarking", "frame-support", @@ -8649,7 +8649,7 @@ dependencies = [ [[package]] name = "pallet-emergency-para-xcm" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -8692,7 +8692,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "environmental", "ethereum", @@ -8747,7 +8747,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "environmental", "evm", @@ -8772,7 +8772,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "frame-support", "frame-system", @@ -8867,7 +8867,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-blake2" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", ] @@ -8875,7 +8875,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "sp-core", @@ -9007,7 +9007,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "frame-support", @@ -9084,7 +9084,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "num", @@ -9319,7 +9319,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "tiny-keccak", @@ -9328,7 +9328,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "ripemd", @@ -9338,7 +9338,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-storage-cleaner" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "fp-evm", "frame-support", @@ -9353,7 +9353,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-xcm" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "cumulus-primitives-core", "evm", @@ -9605,7 +9605,7 @@ dependencies = [ [[package]] name = "pallet-maintenance-mode" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -9658,7 +9658,7 @@ dependencies = [ [[package]] name = "pallet-migrations" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "frame-benchmarking", "frame-support", @@ -9990,7 +9990,7 @@ dependencies = [ [[package]] name = "pallet-randomness" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "environmental", "frame-benchmarking", @@ -10068,7 +10068,7 @@ dependencies = [ [[package]] name = "pallet-relay-storage-roots" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -12061,7 +12061,7 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "derive_more", "environmental", @@ -12090,7 +12090,7 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/frontier?branch=elois-native-foreign-assets#ae7bd9cf32822d0a141437b775c6de9872f22da2" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.11.0#45d16ae4c8b32e26fdab8353b704fd59ea0ddb8c" dependencies = [ "case", "num_enum 0.7.2", @@ -14803,7 +14803,7 @@ dependencies = [ [[package]] name = "session-keys-primitives" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "async-trait", "frame-support", @@ -18539,7 +18539,7 @@ dependencies = [ [[package]] name = "xcm-primitives" version = "0.1.0" -source = "git+https://github.com/Moonsong-Labs/moonkit?branch=elois-native-foreign-assets#ff23530dfa2d3ce1149d682b63ae24981d94b601" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.11.0#509c4f44bb49dab0d3dda640a936ac047e109972" dependencies = [ "frame-support", "impl-trait-for-tuples", diff --git a/Cargo.toml b/Cargo.toml index 4e6415d8a9..1adc7f7927 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -236,41 +236,41 @@ ethereum-types = { version = "0.14", default-features = false } evm = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } evm-gasometer = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } evm-runtime = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false, features = [ +fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false, features = [ "forbid-evm-reentrancy", ] } -pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false, features = [ +pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false, features = [ "forbid-evm-reentrancy", ] } -pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-bn128 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-dispatch = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-bn128 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } -precompile-utils = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } -precompile-utils-macro = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", default-features = false } +precompile-utils = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +precompile-utils-macro = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", default-features = false } # Frontier (client) -fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fc-db = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fc-api = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fc-mapping-sync = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fc-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets", features = [ +fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-db = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-api = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-mapping-sync = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0", features = [ "rpc-binary-search-estimate", ] } -fc-rpc-core = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fc-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fp-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } -fp-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "elois-native-foreign-assets" } +fc-rpc-core = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fc-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fp-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } +fp-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.11.0" } # Cumulus (wasm) @@ -328,23 +328,23 @@ westend-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", xcm-simulator = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.11.0" } # Moonkit (wasm) -async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } -session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets", default-features = false } +async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-evm-precompile-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } +session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0", default-features = false } # Moonkit (client) -nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "elois-native-foreign-assets" } +nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.11.0" } # Other (wasm) async-trait = { version = "0.1.42" } From 54e844e1138aee2290679c3c03311ce534ed73ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Fri, 19 Jul 2024 18:16:50 +0200 Subject: [PATCH 32/71] add calls force_burn and force_mint @ define gas limit for mint/burn --- pallets/moonbeam-foreign-assets/src/evm.rs | 10 +- pallets/moonbeam-foreign-assets/src/lib.rs | 102 +++++++++++++------ pallets/moonbeam-foreign-assets/src/mock.rs | 5 +- pallets/moonbeam-foreign-assets/src/tests.rs | 50 ++++----- runtime/moonbase/src/xcm_config.rs | 5 +- runtime/moonbase/tests/integration_test.rs | 22 +++- 6 files changed, 124 insertions(+), 70 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 84796cbcf6..82e0fb8d5c 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -34,8 +34,8 @@ const ERC20_CREATE_MAX_CALLDATA_SIZE: usize = 16 * 1024; // 16Ko // Hardcoded gas limits (from manueal binary search) const ERC20_CREATE_GAS_LIMIT: u64 = 3_367_000; // highest failure: 3_366_000 -const ERC20_BURN_FROM_GAS_LIMIT: u64 = 500_000; -const ERC20_MINT_INTO_GAS_LIMIT: u64 = 50_000; +const ERC20_BURN_FROM_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 +const ERC20_MINT_INTO_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 const ERC20_PAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 const ERC20_TRANSFER_GAS_LIMIT: u64 = 50_000; const ERC20_UNPAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 @@ -155,7 +155,7 @@ impl EvmCaller { ) -> Result<(), EvmError> { let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); // Selector - input.extend_from_slice(&keccak256!("mintInto(address, uint256)")[..4]); + input.extend_from_slice(&keccak256!("mintInto(address,uint256)")[..4]); // append beneficiary address input.extend_from_slice(H256::from(beneficiary).as_bytes()); // append amount to be minted @@ -201,7 +201,7 @@ impl EvmCaller { ) -> Result<(), EvmError> { let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); // Selector - input.extend_from_slice(&keccak256!("transfer(address, uint256)")[..4]); + input.extend_from_slice(&keccak256!("transfer(address,uint256)")[..4]); // append receiver address input.extend_from_slice(H256::from(to).as_bytes()); // append amount to be transferred @@ -256,7 +256,7 @@ impl EvmCaller { ) -> Result<(), EvmError> { let mut input = Vec::with_capacity(ERC20_CALL_MAX_CALLDATA_SIZE); // Selector - input.extend_from_slice(&keccak256!("burnFrom(address, uint256)")[..4]); + input.extend_from_slice(&keccak256!("burnFrom(address,uint256)")[..4]); // append who address input.extend_from_slice(H256::from(who).as_bytes()); // append amount to be burn diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 3faa797e62..5e63a2cb1d 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -146,19 +146,22 @@ pub mod pallet { /// Origin that is allowed to create a new foreign assets type ForeignAssetCreatorOrigin: EnsureOrigin; - /// Origin that is allowed to modify asset information for foreign assets - type ForeignAssetModifierOrigin: EnsureOrigin; + /// Origin that is allowed to burn foreign assets from any account + type ForeignAssetForceBurnOrigin: EnsureOrigin; + + /// Origin that is allowed to mint foreign assets from any account + type ForeignAssetForceMintOrigin: EnsureOrigin; /// Origin that is allowed to freeze all tokens of a foreign asset type ForeignAssetFreezerOrigin: EnsureOrigin; + /// Origin that is allowed to modify asset information for foreign assets + type ForeignAssetModifierOrigin: EnsureOrigin; + /// Origin that is allowed to unfreeze all tokens of a foreign asset that was previously /// frozen type ForeignAssetUnfreezerOrigin: EnsureOrigin; - /// Origin that is allowed to create and modify asset information for foreign assets - type ForeignAssetDestroyerOrigin: EnsureOrigin; - /// Hook to be called when new foreign asset is registered. type OnForeignAssetCreated: ForeignAssetCreatedHook; @@ -187,6 +190,7 @@ pub mod pallet { AssetIdFiltered, AssetNotFrozen, CorruptedStorageOrphanLocation, + Erc20ContractCallFail, Erc20ContractCreationFail, EvmCallPauseFail, EvmCallUnpauseFail, @@ -345,32 +349,8 @@ pub mod pallet { Ok(()) } - /// Remove a given assetId -> foreignAsset association - #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::remove_existing_asset_type())] - pub fn remove_existing_asset_type( - origin: OriginFor, - asset_id: AssetId, - ) -> DispatchResult { - T::ForeignAssetDestroyerOrigin::ensure_origin(origin)?; - - let xcm_location = - AssetsById::::get(&asset_id).ok_or(Error::::AssetDoesNotExist)?; - - // Remove from AssetsById - AssetsById::::remove(&asset_id); - // Remove from AssetsByLocation - AssetsByLocation::::remove(&xcm_location); - - Self::deposit_event(Event::ForeignAssetRemoved { - asset_id, - xcm_location, - }); - Ok(()) - } - /// Freeze a given foreign assetId - #[pallet::call_index(3)] + #[pallet::call_index(2)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn freeze_foreign_asset( origin: OriginFor, @@ -408,7 +388,7 @@ pub mod pallet { } /// Freeze a given foreign assetId - #[pallet::call_index(4)] + #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; @@ -435,6 +415,66 @@ pub mod pallet { }); Ok(()) } + + /// Freeze a given foreign assetId + #[pallet::call_index(4)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn force_burn_from( + origin: OriginFor, + asset_id: AssetId, + from: ::AccountId, + amount: U256, + ) -> DispatchResult { + T::ForeignAssetForceBurnOrigin::ensure_origin(origin)?; + + ensure!( + AssetsById::::contains_key(&asset_id), + Error::::AssetDoesNotExist + ); + + // We perform the evm call in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_burn_from( + Self::contract_address_from_asset_id(asset_id), + from.into(), + amount, + ) + }) + .map_err(|_| Error::::Erc20ContractCallFail)?; + + Ok(()) + } + + /// Freeze a given foreign assetId + #[pallet::call_index(5)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn force_mint_into( + origin: OriginFor, + asset_id: AssetId, + beneficiary: ::AccountId, + amount: U256, + ) -> DispatchResult { + T::ForeignAssetForceMintOrigin::ensure_origin(origin)?; + + ensure!( + AssetsById::::contains_key(&asset_id), + Error::::AssetDoesNotExist + ); + + // We perform the evm call in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_mint_into( + Self::contract_address_from_asset_id(asset_id), + beneficiary.into(), + amount, + ) + }) + .map_err(|_| Error::::Erc20ContractCallFail)?; + + Ok(()) + } } impl xcm_executor::traits::TransactAsset for Pallet { diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 9f8812aefc..5b4a87f65b 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -198,10 +198,11 @@ impl crate::Config for Test { type AssetIdFilter = Everything; type EvmRunner = pallet_evm::runner::stack::Runner; type ForeignAssetCreatorOrigin = EnsureRoot; - type ForeignAssetModifierOrigin = EnsureRoot; + type ForeignAssetForceBurnOrigin = EnsureRoot; + type ForeignAssetForceMintOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; + type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; - type ForeignAssetDestroyerOrigin = EnsureRoot; type OnForeignAssetCreated = NoteDownHook; type OnForeignAssetDestroyed = NoteDownHook; type MaxForeignAssets = ConstU32<3>; diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index 13a6dc2e17..fc6491fb96 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -50,7 +50,9 @@ fn create_foreign_and_freeze_unfreeze() { (1, AssetStatus::Active), ); expect_events(vec![crate::Event::ForeignAssetCreated { - contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + contract_address: H160([ + 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), asset_id: 1, xcm_location: Location::parent(), }]); @@ -61,10 +63,7 @@ fn create_foreign_and_freeze_unfreeze() { assert_eq!(asset_id, 1u128); // Check storage - assert_eq!( - EvmForeignAssets::assets_by_id(&1), - Some(Location::parent()) - ); + assert_eq!(EvmForeignAssets::assets_by_id(&1), Some(Location::parent())); assert_eq!( EvmForeignAssets::assets_by_location(&Location::parent()), Some((1, AssetStatus::Active)) @@ -72,21 +71,16 @@ fn create_foreign_and_freeze_unfreeze() { // Unfreeze should return AssetNotFrozen error assert_noop!( - EvmForeignAssets::unfreeze_foreign_asset( - RuntimeOrigin::root(), - 1 - ), + EvmForeignAssets::unfreeze_foreign_asset(RuntimeOrigin::root(), 1), Error::::AssetNotFrozen ); // Freeze should work - assert_ok!( - EvmForeignAssets::freeze_foreign_asset( - RuntimeOrigin::root(), - 1, - true - ), - ); + assert_ok!(EvmForeignAssets::freeze_foreign_asset( + RuntimeOrigin::root(), + 1, + true + ),); assert_eq!( EvmForeignAssets::assets_by_location(&Location::parent()), Some((1, AssetStatus::FrozenXcmDepositAllowed)) @@ -94,21 +88,15 @@ fn create_foreign_and_freeze_unfreeze() { // Should not be able to freeze an asset already frozen assert_noop!( - EvmForeignAssets::freeze_foreign_asset( - RuntimeOrigin::root(), - 1, - true - ), + EvmForeignAssets::freeze_foreign_asset(RuntimeOrigin::root(), 1, true), Error::::AssetAlreadyFrozen ); // Unfreeze should work - assert_ok!( - EvmForeignAssets::unfreeze_foreign_asset( - RuntimeOrigin::root(), - 1 - ), - ); + assert_ok!(EvmForeignAssets::unfreeze_foreign_asset( + RuntimeOrigin::root(), + 1 + ),); assert_eq!( EvmForeignAssets::assets_by_location(&Location::parent()), Some((1, AssetStatus::Active)) @@ -201,7 +189,9 @@ fn test_root_can_change_foreign_asset_for_asset_id() { expect_events(vec![ crate::Event::ForeignAssetCreated { - contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + contract_address: H160([ + 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), asset_id: 1, xcm_location: Location::parent(), }, @@ -250,7 +240,9 @@ fn test_root_can_remove_asset_association() { expect_events(vec![ crate::Event::ForeignAssetCreated { - contract_address: H160([255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]), + contract_address: H160([ + 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + ]), asset_id: 1, xcm_location: Location::parent(), }, diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 11fb7c45dd..fa6f8f256c 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -725,10 +725,11 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime { type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; type ForeignAssetCreatorOrigin = EnsureRoot; - type ForeignAssetModifierOrigin = EnsureRoot; + type ForeignAssetForceBurnOrigin = EnsureRoot; + type ForeignAssetForceMintOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; + type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; - type ForeignAssetDestroyerOrigin = EnsureRoot; type OnForeignAssetCreated = (); type OnForeignAssetDestroyed = (); type MaxForeignAssets = ConstU32<256>; diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 0f5e7a395f..dcafa92232 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -1250,9 +1250,11 @@ fn update_reward_address_via_precompile() { } #[test] -fn asset_can_be_registered_then_freeze_and_unfreeze() { +fn create_and_manipulate_foreign_asset() { ExtBuilder::default().build().execute_with(|| { let source_location = xcm::v4::Location::parent(); + + // Create foreign asset assert_ok!(EvmForeignAssets::create_foreign_asset( moonbase_runtime::RuntimeOrigin::root(), 1, @@ -1270,6 +1272,7 @@ fn asset_can_be_registered_then_freeze_and_unfreeze() { Some((1, AssetStatus::Active)) ); + // Freeze foreign asset assert_ok!(EvmForeignAssets::freeze_foreign_asset( moonbase_runtime::RuntimeOrigin::root(), 1, @@ -1280,6 +1283,7 @@ fn asset_can_be_registered_then_freeze_and_unfreeze() { Some((1, AssetStatus::FrozenXcmDepositAllowed)) ); + // Unfreeze foreign asset assert_ok!(EvmForeignAssets::unfreeze_foreign_asset( moonbase_runtime::RuntimeOrigin::root(), 1, @@ -1288,6 +1292,22 @@ fn asset_can_be_registered_then_freeze_and_unfreeze() { EvmForeignAssets::assets_by_location(&source_location), Some((1, AssetStatus::Active)) ); + + // Force mint some tokens + assert_ok!(EvmForeignAssets::force_mint_into( + moonbase_runtime::RuntimeOrigin::root(), + 1, + AccountId::from(ALICE), + U256([1_000_000, 0, 0, 0]), + )); + + // Force burn some tokens (not all the balance for worst case gas cost) + assert_ok!(EvmForeignAssets::force_burn_from( + moonbase_runtime::RuntimeOrigin::root(), + 1, + AccountId::from(ALICE), + U256([500_000, 0, 0, 0]), + )); }); } From abc15a765751001ffbeb43ba3afb23f204cbebbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 20 Jul 2024 13:07:28 +0200 Subject: [PATCH 33/71] add transfer call --- pallets/moonbeam-foreign-assets/src/evm.rs | 2 +- pallets/moonbeam-foreign-assets/src/lib.rs | 37 ++++++++++++++++++++-- runtime/moonbase/tests/integration_test.rs | 8 +++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 82e0fb8d5c..34b19ce3c7 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -37,7 +37,7 @@ const ERC20_CREATE_GAS_LIMIT: u64 = 3_367_000; // highest failure: 3_366_000 const ERC20_BURN_FROM_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 const ERC20_MINT_INTO_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 const ERC20_PAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 -const ERC20_TRANSFER_GAS_LIMIT: u64 = 50_000; +const ERC20_TRANSFER_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 const ERC20_UNPAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 pub(crate) enum EvmError { diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 5e63a2cb1d..ebe822d593 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -387,7 +387,7 @@ pub mod pallet { Ok(()) } - /// Freeze a given foreign assetId + /// Unfreeze a given foreign assetId #[pallet::call_index(3)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { @@ -416,7 +416,7 @@ pub mod pallet { Ok(()) } - /// Freeze a given foreign assetId + /// Force to burn a given foreign assetId from any account #[pallet::call_index(4)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn force_burn_from( @@ -446,7 +446,7 @@ pub mod pallet { Ok(()) } - /// Freeze a given foreign assetId + /// Force to mint a given foreign assetId into any account #[pallet::call_index(5)] #[pallet::weight(::WeightInfo::destroy_foreign_asset())] pub fn force_mint_into( @@ -475,6 +475,37 @@ pub mod pallet { Ok(()) } + + /// Transfer a given foreign asset from an account to another + #[pallet::call_index(6)] + #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + pub fn transfer( + origin: OriginFor, + asset_id: AssetId, + beneficiary: ::AccountId, + amount: U256, + ) -> DispatchResult { + let who: ::AccountId = ensure_signed(origin)?.into(); + + ensure!( + AssetsById::::contains_key(&asset_id), + Error::::AssetDoesNotExist + ); + + // We perform the evm call in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_transfer( + Self::contract_address_from_asset_id(asset_id), + who.into(), + beneficiary.into(), + amount, + ) + }) + .map_err(|_| Error::::Erc20ContractCallFail)?; + + Ok(()) + } } impl xcm_executor::traits::TransactAsset for Pallet { diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index dcafa92232..9719e90720 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -1308,6 +1308,14 @@ fn create_and_manipulate_foreign_asset() { AccountId::from(ALICE), U256([500_000, 0, 0, 0]), )); + + // transfer some tokens from Alice to Bob + assert_ok!(EvmForeignAssets::transfer( + moonbase_runtime::RuntimeOrigin::signed(AccountId::from(ALICE)), + 1, + AccountId::from(BOB), + U256([100_000, 0, 0, 0]), + )); }); } From 59d2676ecc6288d1e950e50deb119cfcf9514fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 20 Jul 2024 16:58:50 +0200 Subject: [PATCH 34/71] fix benchmarks compilation --- .../moonbeam-foreign-assets/src/benchmarks.rs | 142 +++--------------- pallets/moonbeam-foreign-assets/src/lib.rs | 50 +++--- pallets/moonbeam-foreign-assets/src/mock.rs | 11 +- pallets/moonbeam-foreign-assets/src/tests.rs | 46 +----- runtime/moonbase/src/xcm_config.rs | 11 +- 5 files changed, 71 insertions(+), 189 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/benchmarks.rs b/pallets/moonbeam-foreign-assets/src/benchmarks.rs index c916c3391f..5108e679af 100644 --- a/pallets/moonbeam-foreign-assets/src/benchmarks.rs +++ b/pallets/moonbeam-foreign-assets/src/benchmarks.rs @@ -16,139 +16,47 @@ #![cfg(feature = "runtime-benchmarks")] -use crate::{AssetBalance, AssetId, Call, Config, Pallet}; -use frame_benchmarking::{ - account, benchmarks, impl_benchmark_test_suite, whitelisted_caller, BenchmarkError, -}; -use frame_support::traits::{fungibles, fungibles::Mutate, EnsureOrigin}; +use crate::{Call, Config, Pallet}; +use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; use frame_system::RawOrigin; -use sp_arithmetic::traits::AtLeast16BitUnsigned; +use sp_runtime::traits::ConstU32; +use sp_runtime::BoundedVec; use xcm::latest::prelude::*; -#[allow(dead_code)] -pub fn create_default_minted_asset( - amount: AssetBalance, - receiver: T::AccountId, -) -> (AssetId, T::ForeignAsset) -where - T::ForeignAsset: From, - T::Fungibles: fungibles::Mutate, - AssetId: AtLeast16BitUnsigned, -{ - let (asset_id, foreign_asset) = create_default_asset::(true); - - assert!(T::Fungibles::mint_into(asset_id.clone(), &receiver, amount).is_ok()); - (asset_id, foreign_asset) -} - -#[allow(dead_code)] -fn create_default_asset(is_sufficient: bool) -> (AssetId, T::ForeignAsset) -where - T::ForeignAsset: From, - AssetId: AtLeast16BitUnsigned, -{ - let asset_id: AssetId = 1u16.into(); - let foreign_asset: T::ForeignAsset = Location::parent().into(); - let admin: T::AccountId = whitelisted_caller(); - let origin = T::ForeignAssetCreatorOrigin::try_successful_origin() - .map_err(|_| BenchmarkError::Weightless) - .expect("Not able to generate an appropriate origin to disptach the call"); - assert!(Pallet::::create_foreign_asset( - origin, - foreign_asset.clone(), - asset_id.clone(), - admin, - is_sufficient, - 1u32.into(), - ) - .is_ok()); - (asset_id, foreign_asset) +fn str_to_bv(str_: &str) -> BoundedVec> { + str_.as_bytes().to_vec().try_into().expect("too long") } benchmarks! { - // This where clause allows us to create ForeignAssetTypes - where_clause { where T::ForeignAsset: From, AssetId: AtLeast16BitUnsigned } create_foreign_asset { - const USER_SEED: u32 = 1; - let manager = account("manager", 0, USER_SEED); - let foreign_asset = T::ForeignAsset::default(); - let amount = 1u32.into(); - let asset_id: AssetId = 1u16.into(); - - }: _(RawOrigin::Root, foreign_asset.clone(), asset_id.clone(), manager, true, amount) + }: _(RawOrigin::Root, 1, Location::parent(), 18, str_to_bv("MT"), str_to_bv("Mytoken")) verify { - assert_eq!(Pallet::::foreign_asset_for_id(asset_id), Some(foreign_asset)); + assert_eq!( + Pallet::::assets_by_id(1), + Some(Location::parent()) + ); } change_existing_asset_type { - const USER_SEED: u32 = 1; - let manager: T::AccountId = account("manager", 0, USER_SEED); - - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); - let asset_id: AssetId = (0u16).into(); - let amount = 1u32.into(); Pallet::::create_foreign_asset( RawOrigin::Root.into(), - foreign_asset.clone(), - asset_id.clone(), - manager.clone(), - true, - amount, + 1, + Location::parent(), + 18, + str_to_bv("MT"), + str_to_bv("Mytoken") )?; - let new_foreign_asset = T::ForeignAsset::default(); - let asset_type_to_be_changed: T::ForeignAsset = Location::new( - 0, - [GeneralIndex((0) as u128)] - ).into(); - let asset_id_to_be_changed: AssetId = (0u16).into(); - }: _(RawOrigin::Root, asset_id_to_be_changed.clone(), new_foreign_asset.clone()) - verify { - assert_eq!(Pallet::::foreign_asset_for_id(asset_id_to_be_changed), Some(new_foreign_asset.clone())); - } - - remove_existing_asset_type { - const USER_SEED: u32 = 1; - let manager: T::AccountId = account("manager", 0, USER_SEED); - - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); - let asset_id: AssetId = 0u16.into(); - let amount = 1u32.into(); - Pallet::::create_foreign_asset( - RawOrigin::Root.into(), - foreign_asset.clone(), - asset_id.clone(), - manager.clone(), - true, - amount, - )?; - - let asset_id_to_be_removed: AssetId = 0u16.into(); - }: _(RawOrigin::Root, asset_id_to_be_removed.clone()) - verify { - assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_removed).is_none()); - } - - destroy_foreign_asset { - const USER_SEED: u32 = 1; - let manager: T::AccountId = account("manager", 0, USER_SEED); - - let foreign_asset: T::ForeignAsset = Location::new(0, [GeneralIndex(0u128)]).into(); - let asset_id: AssetId = 0u16.into(); - let amount = 1u32.into(); - Pallet::::create_foreign_asset( - RawOrigin::Root.into(), - foreign_asset.clone(), - asset_id.clone(), - manager.clone(), - true, - amount, - )?; - - let asset_id_to_be_destroyed: AssetId = 0u16.into(); - }: _(RawOrigin::Root, asset_id_to_be_destroyed.clone()) + assert_eq!( + Pallet::::assets_by_id(1), + Some(Location::parent()) + ); + }: _(RawOrigin::Root, 1, Location::here()) verify { - assert!(Pallet::::foreign_asset_for_id(asset_id_to_be_destroyed).is_none()); + assert_eq!( + Pallet::::assets_by_id(1), + Some(Location::here()) + ); } } diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index ebe822d593..aaaa44c9c4 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -117,7 +117,7 @@ pub enum AssetStatus { pub mod pallet { use super::*; use pallet_evm::Runner; - use sp_runtime::traits::AccountIdConversion; + use sp_runtime::traits::{AccountIdConversion, Convert}; use xcm_executor::traits::ConvertLocation; use xcm_executor::traits::Error as MatchError; use xcm_executor::AssetsInHolding; @@ -131,11 +131,8 @@ pub mod pallet { #[pallet::config] pub trait Config: frame_system::Config + pallet_evm::Config { - /// the overarching AccountId type - type AccountId: Parameter + Into + IsType<::AccountId>; - - // Convert XCM Location to H160 - type AccountIdConverter: ConvertLocation; + // Convert AccountId to H160 + type AccountIdToH160: Convert; /// A filter to forbid some AssetId values, if you don't use it, put "Everything" type AssetIdFilter: Contains; @@ -176,6 +173,9 @@ pub mod pallet { /// Weight information for extrinsics in this pallet. type WeightInfo: WeightInfo; + + // Convert XCM Location to H160 + type XcmLocationToH160: ConvertLocation; } pub type AssetBalance = U256; @@ -255,8 +255,8 @@ pub mod pallet { impl Pallet { /// The account ID of this pallet pub fn account_id() -> H160 { - let account_id: ::AccountId = PALLET_ID.into_account_truncating(); - account_id.into() + let account_id: T::AccountId = PALLET_ID.into_account_truncating(); + T::AccountIdToH160::convert(account_id) } #[inline] @@ -351,7 +351,7 @@ pub mod pallet { /// Freeze a given foreign assetId #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] pub fn freeze_foreign_asset( origin: OriginFor, asset_id: AssetId, @@ -389,7 +389,7 @@ pub mod pallet { /// Unfreeze a given foreign assetId #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; @@ -418,11 +418,11 @@ pub mod pallet { /// Force to burn a given foreign assetId from any account #[pallet::call_index(4)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] pub fn force_burn_from( origin: OriginFor, asset_id: AssetId, - from: ::AccountId, + from: T::AccountId, amount: U256, ) -> DispatchResult { T::ForeignAssetForceBurnOrigin::ensure_origin(origin)?; @@ -437,7 +437,7 @@ pub mod pallet { frame_support::storage::with_storage_layer(|| { EvmCaller::::erc20_burn_from( Self::contract_address_from_asset_id(asset_id), - from.into(), + T::AccountIdToH160::convert(from), amount, ) }) @@ -448,11 +448,11 @@ pub mod pallet { /// Force to mint a given foreign assetId into any account #[pallet::call_index(5)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] pub fn force_mint_into( origin: OriginFor, asset_id: AssetId, - beneficiary: ::AccountId, + beneficiary: T::AccountId, amount: U256, ) -> DispatchResult { T::ForeignAssetForceMintOrigin::ensure_origin(origin)?; @@ -467,7 +467,7 @@ pub mod pallet { frame_support::storage::with_storage_layer(|| { EvmCaller::::erc20_mint_into( Self::contract_address_from_asset_id(asset_id), - beneficiary.into(), + T::AccountIdToH160::convert(beneficiary), amount, ) }) @@ -478,14 +478,14 @@ pub mod pallet { /// Transfer a given foreign asset from an account to another #[pallet::call_index(6)] - #[pallet::weight(::WeightInfo::destroy_foreign_asset())] + #[pallet::weight(::WeightInfo::change_existing_asset_type())] pub fn transfer( origin: OriginFor, asset_id: AssetId, - beneficiary: ::AccountId, + beneficiary: T::AccountId, amount: U256, ) -> DispatchResult { - let who: ::AccountId = ensure_signed(origin)?.into(); + let who = ensure_signed(origin)?; ensure!( AssetsById::::contains_key(&asset_id), @@ -497,8 +497,8 @@ pub mod pallet { frame_support::storage::with_storage_layer(|| { EvmCaller::::erc20_transfer( Self::contract_address_from_asset_id(asset_id), - who.into(), - beneficiary.into(), + T::AccountIdToH160::convert(who), + T::AccountIdToH160::convert(beneficiary), amount, ) }) @@ -520,7 +520,7 @@ pub mod pallet { return Err(MatchError::AssetNotHandled.into()); } - let beneficiary = T::AccountIdConverter::convert_location(who) + let beneficiary = T::XcmLocationToH160::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; // We perform the evm transfers in a storage transaction to ensure that if it fail @@ -547,10 +547,10 @@ pub mod pallet { return Err(MatchError::AssetNotHandled.into()); } - let from = T::AccountIdConverter::convert_location(from) + let from = T::XcmLocationToH160::convert_location(from) .ok_or(MatchError::AccountIdConversionFailed)?; - let to = T::AccountIdConverter::convert_location(to) + let to = T::XcmLocationToH160::convert_location(to) .ok_or(MatchError::AccountIdConversionFailed)?; // We perform the evm transfers in a storage transaction to ensure that if it fail @@ -576,7 +576,7 @@ pub mod pallet { ) -> Result { let (contract_address, amount, asset_status) = ForeignAssetsMatcher::::match_asset(what)?; - let who = T::AccountIdConverter::convert_location(who) + let who = T::XcmLocationToH160::convert_location(who) .ok_or(MatchError::AccountIdConversionFailed)?; if let AssetStatus::FrozenXcmDepositForbidden | AssetStatus::FrozenXcmDepositAllowed = diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 5b4a87f65b..514265337f 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -192,9 +192,15 @@ impl ForeignAssetDestroyedHook for NoteDownH } } +pub struct AccountIdToH160; +impl sp_runtime::traits::Convert for AccountIdToH160 { + fn convert(account_id: AccountId) -> H160 { + account_id.into() + } +} + impl crate::Config for Test { - type AccountId = AccountId; - type AccountIdConverter = (); + type AccountIdToH160 = AccountIdToH160; type AssetIdFilter = Everything; type EvmRunner = pallet_evm::runner::stack::Runner; type ForeignAssetCreatorOrigin = EnsureRoot; @@ -208,6 +214,7 @@ impl crate::Config for Test { type MaxForeignAssets = ConstU32<3>; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); + type XcmLocationToH160 = (); } pub(crate) struct ExtBuilder { diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index fc6491fb96..02f3a0739e 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -41,13 +41,10 @@ fn create_foreign_and_freeze_unfreeze() { encode_token_name("Mytoken"), )); + assert_eq!(EvmForeignAssets::assets_by_id(1), Some(Location::parent())); assert_eq!( - EvmForeignAssets::assets_by_id(1).unwrap(), - Location::parent() - ); - assert_eq!( - EvmForeignAssets::assets_by_location(Location::parent()).unwrap(), - (1, AssetStatus::Active), + EvmForeignAssets::assets_by_location(Location::parent()), + Some((1, AssetStatus::Active)), ); expect_events(vec![crate::Event::ForeignAssetCreated { contract_address: H160([ @@ -216,40 +213,3 @@ fn test_asset_id_non_existent_error() { ); }); } - -#[test] -fn test_root_can_remove_asset_association() { - ExtBuilder::default().build().execute_with(|| { - assert_ok!(EvmForeignAssets::create_foreign_asset( - RuntimeOrigin::root(), - 1, - Location::parent(), - 18, - encode_ticker("MTT"), - encode_token_name("Mytoken"), - )); - - assert_ok!(EvmForeignAssets::remove_existing_asset_type( - RuntimeOrigin::root(), - 1 - )); - - // Mappings are deleted - assert!(EvmForeignAssets::assets_by_id(1).is_none()); - assert!(EvmForeignAssets::assets_by_location(Location::parent()).is_none()); - - expect_events(vec![ - crate::Event::ForeignAssetCreated { - contract_address: H160([ - 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - ]), - asset_id: 1, - xcm_location: Location::parent(), - }, - crate::Event::ForeignAssetRemoved { - asset_id: 1, - xcm_location: Location::parent(), - }, - ]) - }); -} diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index fa6f8f256c..bb76bc1d6e 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -710,6 +710,13 @@ impl pallet_erc20_xcm_bridge::Config for Runtime { type EvmRunner = EvmRunnerPrecompileOrEthXcm; } +pub struct AccountIdToH160; +impl sp_runtime::traits::Convert for AccountIdToH160 { + fn convert(account_id: AccountId) -> H160 { + account_id.into() + } +} + pub struct EvmForeignAssetIdFilter; impl frame_support::traits::Contains for EvmForeignAssetIdFilter { fn contains(asset_id: &AssetId) -> bool { @@ -720,8 +727,7 @@ impl frame_support::traits::Contains for EvmForeignAssetIdFilter { } impl pallet_moonbeam_foreign_assets::Config for Runtime { - type AccountId = AccountId; - type AccountIdConverter = LocationToH160; + type AccountIdToH160 = AccountIdToH160; type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; type ForeignAssetCreatorOrigin = EnsureRoot; @@ -736,6 +742,7 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime { type RuntimeEvent = RuntimeEvent; // TODO generate weights type WeightInfo = (); + type XcmLocationToH160 = LocationToH160; } #[cfg(feature = "runtime-benchmarks")] From d513bd2c25fcfa1b0c6463bdc314edc3f90ad55c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 20 Jul 2024 17:52:46 +0200 Subject: [PATCH 35/71] add feature insecure_zero_ed for new pallet rust tests --- pallets/moonbeam-foreign-assets/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/moonbeam-foreign-assets/Cargo.toml b/pallets/moonbeam-foreign-assets/Cargo.toml index 87446c7e82..02b6e08c66 100644 --- a/pallets/moonbeam-foreign-assets/Cargo.toml +++ b/pallets/moonbeam-foreign-assets/Cargo.toml @@ -35,7 +35,7 @@ hex = { workspace = true, features = [ "std" ] } [dev-dependencies] hex = { workspace = true } -pallet-balances = { workspace = true, features = [ "std" ] } +pallet-balances = { workspace = true, features = [ "insecure_zero_ed", "std" ] } pallet-timestamp = { workspace = true, features = [ "std" ] } sp-core = { workspace = true, features = [ "std" ] } From 3b23ece78af91b0761d0847591785e533e073c29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 20 Jul 2024 17:53:09 +0200 Subject: [PATCH 36/71] improve benchmarks: create max foreign assets for worst case scenario --- .../moonbeam-foreign-assets/src/benchmarks.rs | 74 +++++++++++++++---- 1 file changed, 60 insertions(+), 14 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/benchmarks.rs b/pallets/moonbeam-foreign-assets/src/benchmarks.rs index 5108e679af..188aff1a65 100644 --- a/pallets/moonbeam-foreign-assets/src/benchmarks.rs +++ b/pallets/moonbeam-foreign-assets/src/benchmarks.rs @@ -16,46 +16,92 @@ #![cfg(feature = "runtime-benchmarks")] -use crate::{Call, Config, Pallet}; +use crate::{AssetStatus, Call, Config, Pallet}; use frame_benchmarking::{benchmarks, impl_benchmark_test_suite}; +use frame_support::pallet_prelude::*; use frame_system::RawOrigin; use sp_runtime::traits::ConstU32; use sp_runtime::BoundedVec; use xcm::latest::prelude::*; +fn create_n_foreign_asset(n: u32) -> DispatchResult { + for i in 1..=n { + Pallet::::create_foreign_asset( + RawOrigin::Root.into(), + i as u128, + location_of(i), + 18, + str_to_bv(&format!("MT{}", i)), + str_to_bv(&format!("Mytoken{}", i)), + )?; + assert_eq!(Pallet::::assets_by_id(i as u128), Some(location_of(i))); + } + + Ok(()) +} + +fn location_of(n: u32) -> Location { + Location::new(0, [Junction::GeneralIndex(n as u128)]) +} + fn str_to_bv(str_: &str) -> BoundedVec> { str_.as_bytes().to_vec().try_into().expect("too long") } benchmarks! { + // Worst case scenario: MaxForeignAssets minus one already exists create_foreign_asset { - }: _(RawOrigin::Root, 1, Location::parent(), 18, str_to_bv("MT"), str_to_bv("Mytoken")) + create_n_foreign_asset::(T::MaxForeignAssets::get().saturating_sub(1))?; + let asset_id = T::MaxForeignAssets::get() as u128; + }: _(RawOrigin::Root, asset_id, Location::parent(), 18, str_to_bv("MT"), str_to_bv("Mytoken")) verify { assert_eq!( - Pallet::::assets_by_id(1), + Pallet::::assets_by_id(asset_id), Some(Location::parent()) ); } + // Worst case scenario: MaxForeignAssets already exists change_existing_asset_type { - Pallet::::create_foreign_asset( + create_n_foreign_asset::(T::MaxForeignAssets::get())?; + }: _(RawOrigin::Root, 1, Location::here()) + verify { + assert_eq!( + Pallet::::assets_by_id(1), + Some(Location::here()) + ); + } + + // Worst case scenario: MaxForeignAssets already exists + freeze_foreign_asset { + create_n_foreign_asset::(T::MaxForeignAssets::get())?; + }: _(RawOrigin::Root, 1, true) + verify { + assert_eq!( + Pallet::::assets_by_location(location_of(1)), + Some((1, AssetStatus::FrozenXcmDepositAllowed)) + ); + } + + // Worst case scenario: + // - MaxForeignAssets already exists + // - The asset to unfreeze is already frozen (to avoid early error) + unfreeze_foreign_asset { + create_n_foreign_asset::(T::MaxForeignAssets::get())?; + Pallet::::freeze_foreign_asset( RawOrigin::Root.into(), 1, - Location::parent(), - 18, - str_to_bv("MT"), - str_to_bv("Mytoken") + true )?; - assert_eq!( - Pallet::::assets_by_id(1), - Some(Location::parent()) + Pallet::::assets_by_location(location_of(1)), + Some((1, AssetStatus::FrozenXcmDepositAllowed)) ); - }: _(RawOrigin::Root, 1, Location::here()) + }: _(RawOrigin::Root, 1) verify { assert_eq!( - Pallet::::assets_by_id(1), - Some(Location::here()) + Pallet::::assets_by_location(location_of(1)), + Some((1, AssetStatus::Active)) ); } } From cfc76010e8b3eb7753e17a5f904d71ad30e90796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sat, 20 Jul 2024 19:14:34 +0200 Subject: [PATCH 37/71] create weight info fns for freeze/unfreeze --- pallets/moonbeam-foreign-assets/src/lib.rs | 4 ++-- .../moonbeam-foreign-assets/src/weights.rs | 19 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index aaaa44c9c4..70173351b2 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -351,7 +351,7 @@ pub mod pallet { /// Freeze a given foreign assetId #[pallet::call_index(2)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] + #[pallet::weight(::WeightInfo::freeze_foreign_asset())] pub fn freeze_foreign_asset( origin: OriginFor, asset_id: AssetId, @@ -389,7 +389,7 @@ pub mod pallet { /// Unfreeze a given foreign assetId #[pallet::call_index(3)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] + #[pallet::weight(::WeightInfo::unfreeze_foreign_asset())] pub fn unfreeze_foreign_asset(origin: OriginFor, asset_id: AssetId) -> DispatchResult { T::ForeignAssetUnfreezerOrigin::ensure_origin(origin)?; diff --git a/pallets/moonbeam-foreign-assets/src/weights.rs b/pallets/moonbeam-foreign-assets/src/weights.rs index c9feeea785..ca385eac9d 100644 --- a/pallets/moonbeam-foreign-assets/src/weights.rs +++ b/pallets/moonbeam-foreign-assets/src/weights.rs @@ -24,16 +24,15 @@ //! EXECUTION: , WASM-EXECUTION: Compiled, CHAIN: Some("dev"), DB CACHE: 1024 // Executed Command: -// ./target/release/tanssi-node +// ./target/release/moonbeam // benchmark // pallet // --execution=wasm // --wasm-execution=compiled // --pallet -// pallet_foreign_asset_creator +// pallet_moonbeam_foreign_assets // --extrinsic // * -// --chain=dev // --steps // 50 // --repeat @@ -42,7 +41,7 @@ // --json-file // raw.json // --output -// tmp/pallet_foreign_asset_creator.rs +// weights/ #![cfg_attr(rustfmt, rustfmt_skip)] #![allow(unused_parens)] @@ -55,8 +54,8 @@ use sp_std::marker::PhantomData; pub trait WeightInfo { fn create_foreign_asset() -> Weight; fn change_existing_asset_type() -> Weight; - fn remove_existing_asset_type() -> Weight; - fn destroy_foreign_asset() -> Weight; + fn freeze_foreign_asset() -> Weight; + fn unfreeze_foreign_asset() -> Weight; } /// Weights for pallet_foreign_asset_creator using the Substrate node and recommended hardware. @@ -94,7 +93,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn remove_existing_asset_type() -> Weight { + fn freeze_foreign_asset() -> Weight { // Proof Size summary in bytes: // Measured: `189` // Estimated: `3654` @@ -109,7 +108,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn destroy_foreign_asset() -> Weight { + fn unfreeze_foreign_asset() -> Weight { // Proof Size summary in bytes: // Measured: `429` // Estimated: `3894` @@ -154,7 +153,7 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn remove_existing_asset_type() -> Weight { + fn freeze_foreign_asset() -> Weight { // Proof Size summary in bytes: // Measured: `189` // Estimated: `3654` @@ -169,7 +168,7 @@ impl WeightInfo for () { /// Proof: `ForeignAssets::Asset` (`max_values`: None, `max_size`: Some(208), added: 2683, mode: `MaxEncodedLen`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:1) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn destroy_foreign_asset() -> Weight { + fn unfreeze_foreign_asset() -> Weight { // Proof Size summary in bytes: // Measured: `429` // Estimated: `3894` From 3daa8eb235fb152465d42658ca45893111f21dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 21 Jul 2024 19:34:20 +0200 Subject: [PATCH 38/71] add foreign asset migrator precompile --- precompiles/foreign-asset-migrator/Cargo.toml | 76 +++++++ precompiles/foreign-asset-migrator/src/lib.rs | 213 ++++++++++++++++++ runtime/moonbase/Cargo.toml | 1 + runtime/moonbase/src/precompiles.rs | 2 + 4 files changed, 292 insertions(+) create mode 100644 precompiles/foreign-asset-migrator/Cargo.toml create mode 100644 precompiles/foreign-asset-migrator/src/lib.rs diff --git a/precompiles/foreign-asset-migrator/Cargo.toml b/precompiles/foreign-asset-migrator/Cargo.toml new file mode 100644 index 0000000000..84f349005a --- /dev/null +++ b/precompiles/foreign-asset-migrator/Cargo.toml @@ -0,0 +1,76 @@ +[package] +name = "precompile-foreign-asset-migrator" +authors = { workspace = true } +description = "A Precompile to expose Assets pallet through an ERC20-compliant interface." +edition = "2021" +version = "0.1.0" + +[dependencies] +log = { workspace = true } +num_enum = { workspace = true } +paste = { workspace = true } + +# Moonbeam +account = { workspace = true } +pallet-asset-manager = { workspace = true } +pallet-moonbeam-foreign-assets = { workspace = true } + +# Substrate +frame-support = { workspace = true } +frame-system = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true } +pallet-timestamp = { workspace = true } +parity-scale-codec = { workspace = true, features = ["max-encoded-len"] } +scale-info = { workspace = true, features = ["derive"] } +sp-core = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } +precompile-utils = { workspace = true } + +# Moonkit +moonkit-xcm-primitives = { workspace = true } + +# Polkadot / XCM +xcm = { workspace = true } + +[dev-dependencies] +derive_more = { workspace = true } +hex-literal = { workspace = true } +libsecp256k1 = { workspace = true } +serde = { workspace = true } +sha3 = { workspace = true } + +# Moonbeam +precompile-utils = { workspace = true, features = ["std", "testing"] } +pallet-timestamp = { workspace = true, features = ["std"] } +parity-scale-codec = { workspace = true, features = ["max-encoded-len", "std"] } +scale-info = { workspace = true, features = ["derive"] } +sp-runtime = { workspace = true, features = ["std"] } + +[features] +default = ["std"] +std = [ + "fp-evm/std", + "frame-support/std", + "frame-system/std", + "moonkit-xcm-primitives/std", + "pallet-assets/std", + "pallet-balances/std", + "pallet-evm/std", + "pallet-asset-manager/std", + "pallet-moonbeam-foreign-assets/std", + "pallet-timestamp/std", + "parity-scale-codec/std", + "precompile-utils/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", + "account/std", +] diff --git a/precompiles/foreign-asset-migrator/src/lib.rs b/precompiles/foreign-asset-migrator/src/lib.rs new file mode 100644 index 0000000000..0e3b0fb353 --- /dev/null +++ b/precompiles/foreign-asset-migrator/src/lib.rs @@ -0,0 +1,213 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +#![cfg_attr(not(feature = "std"), no_std)] + +use core::fmt::Display; +use core::marker::PhantomData; +use frame_support::dispatch::{GetDispatchInfo, PostDispatchInfo}; +use frame_support::traits::OriginTrait; +use moonkit_xcm_primitives::AccountIdAssetIdConversion; +use pallet_evm::AddressMapping; +use precompile_utils::prelude::*; +use sp_core::{MaxEncodedLen, H160, U256}; +use sp_runtime::traits::{Dispatchable, StaticLookup}; +use xcm::latest::prelude::Location; + +pub type ForeignAssetInstance = (); + +/// Alias for the Balance type for old foreign assets +pub type BalanceOf = >::Balance; + +/// Alias for the Asset Id type for old foreign assets +pub type AssetIdOf = >::AssetId; + +pub struct ForeignAssetMigratorPrecompile(PhantomData); + +impl Clone for ForeignAssetMigratorPrecompile { + fn clone(&self) -> Self { + Self(PhantomData) + } +} + +impl Default for ForeignAssetMigratorPrecompile { + fn default() -> Self { + Self(PhantomData) + } +} + +impl ForeignAssetMigratorPrecompile { + pub fn new() -> Self { + Self(PhantomData) + } +} + +#[precompile_utils::precompile] +impl ForeignAssetMigratorPrecompile +where + Runtime: pallet_asset_manager::Config + + pallet_assets::Config + + pallet_evm::Config + + pallet_moonbeam_foreign_assets::Config + + frame_system::Config, + Runtime::RuntimeCall: Dispatchable + GetDispatchInfo, + Runtime::RuntimeCall: From>, + ::RuntimeOrigin: From>, + BalanceOf: TryFrom + Into + solidity::Codec, + Runtime: AccountIdAssetIdConversion>, + <::RuntimeCall as Dispatchable>::RuntimeOrigin: OriginTrait, + AssetIdOf: Display, + Runtime::AccountId: Into, + ::ForeignAssetType: Into>, +{ + #[precompile::public("migrateAccounts(address,uint32)")] + fn migrate_accounts( + handle: &mut impl PrecompileHandle, + asset_address: Address, + n: u32, + ) -> EvmResult { + let new_asset_id = Self::get_new_asset_id_with_same_xcm_location(handle, asset_address)?; + + // Account proof size for N accounts keys + // Storage item: Account + // Key1: Blake2_128(16) + AssetId(16) + // Key2: Blake2_128(16) + AccountId(20) + handle.record_db_read::(68 * n as usize)?; + + // Get N account ids + // IMPORTANT: we can't mutate storage while iterating, that's why we collect N accounts ids + // in a Vec BEFORE processing them! + let accounts_ids = + pallet_assets::pallet::Account::::iter_key_prefix( + new_asset_id, + ) + .take(n as usize) + .collect::>(); + + // Refound gas if there is less than N accounts + if accounts_ids.len() < n as usize { + let n_diff = ((n as usize) - accounts_ids.len()) as u64; + handle.refund_external_cost( + Some(n_diff * RuntimeHelper::::db_read_gas_cost()), + Some(n_diff * 68), + ); + } + + // IMPORTANT: we can't mutate storage while iterating, that's why we collect N accounts ids + // in a Vec BEFORE processing them! + let mut counter = 0; + for account_id in accounts_ids { + Self::migrate_account_inner(handle, new_asset_id, account_id.into())?; + counter += 1; + } + + Ok(U256([counter, 0, 0, 0])) + } + + #[precompile::public("migrateAccount(address,address)")] + fn migrate_account( + handle: &mut impl PrecompileHandle, + asset_address: Address, + account: Address, + ) -> EvmResult<()> { + let new_asset_id = Self::get_new_asset_id_with_same_xcm_location(handle, asset_address)?; + + Self::migrate_account_inner(handle, new_asset_id, account.into())?; + + Ok(()) + } + + fn get_new_asset_id_with_same_xcm_location( + handle: &mut impl PrecompileHandle, + asset_address: Address, + ) -> EvmResult { + let asset_address: H160 = asset_address.into(); + + let asset_address = Runtime::AddressMapping::into_account_id(asset_address); + + // compute asset id from asset address + let asset_id = match Runtime::account_to_asset_id(asset_address) { + Some((_, asset_id)) => asset_id, + None => return Err(revert("invalid asset address")), + }; + + // Storage item: AssetIdType + // key: Blake2_128(16) + AssetId(16) + // value: XCMv3 Location + handle.record_db_read::(32 + xcm::v3::Location::max_encoded_len())?; + + // Get asset XCM location + let asset_type = pallet_asset_manager::Pallet::::asset_id_type(&asset_id) + .ok_or(revert("asset id doesn't exist"))?; + let xcm_location = asset_type.into().ok_or(revert("invalid XCM Location"))?; + + // Storage item: AssetsByLocation + // key: Blake2_128(16) + XCM latest Location + // value: AssetId(16) + AssetStatus(1) + handle.record_db_read::(33 + Location::max_encoded_len())?; + + // Get new asset id + let (new_asset_id, _) = + pallet_moonbeam_foreign_assets::Pallet::::assets_by_location(&xcm_location) + .ok_or(revert("new foreign asset doesn't exist"))?; + + Ok(new_asset_id) + } + + fn migrate_account_inner( + handle: &mut impl PrecompileHandle, + new_asset_id: u128, + account: H160, + ) -> EvmResult<()> { + let account_id = Runtime::AddressMapping::into_account_id(account); + + // Storage item: Account + // Key1: Blake2_128(16) + AssetId(16) + // key2: Blake2_128(16) + AccountId(20) + // Value: AssetAccount(19 + Extra) + handle.record_db_read::( + 87 + >::Extra::max_encoded_len(), + )?; + + // Get old asset balance + let amount = pallet_assets::Pallet::::balance( + new_asset_id, + &account_id, + ); + + // Burn account balance on hold foreign asset + RuntimeHelper::::try_dispatch( + handle, + Some(pallet_asset_manager::Pallet::::account_id()).into(), + pallet_assets::Call::::burn { + id: new_asset_id.into(), + who: Runtime::Lookup::unlookup(account_id.clone()), + amount, + }, + 0, + )?; + + // Mint same balance for new asset + pallet_moonbeam_foreign_assets::Pallet::::mint_into( + new_asset_id, + account_id, + amount.into(), + ) + .map_err(|_| revert("fail to mint new foreign asset"))?; + + Ok(()) + } +} diff --git a/runtime/moonbase/Cargo.toml b/runtime/moonbase/Cargo.toml index 3b292bcb49..ee0085652e 100644 --- a/runtime/moonbase/Cargo.toml +++ b/runtime/moonbase/Cargo.toml @@ -68,6 +68,7 @@ pallet-evm-precompile-xcm-transactor = { workspace = true } pallet-evm-precompile-xcm-utils = { workspace = true } pallet-evm-precompile-xtokens = { workspace = true } pallet-evm-precompileset-assets-erc20 = { workspace = true } +precompile-foreign-asset-migrator = { workspace = true } # Moonbeam tracing evm-tracing-events = { workspace = true, optional = true } diff --git a/runtime/moonbase/src/precompiles.rs b/runtime/moonbase/src/precompiles.rs index 610adc44f0..239a6243ed 100644 --- a/runtime/moonbase/src/precompiles.rs +++ b/runtime/moonbase/src/precompiles.rs @@ -55,6 +55,7 @@ use pallet_evm_precompile_xcm_transactor::{ use pallet_evm_precompile_xcm_utils::{AllExceptXcmExecute, XcmUtilsPrecompile}; use pallet_evm_precompile_xtokens::XtokensPrecompile; use pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSet; +use precompile_foreign_asset_migrator::ForeignAssetMigratorPrecompile; use precompile_utils::precompile_set::*; use sp_std::prelude::*; use xcm_primitives::AsAssetType; @@ -268,6 +269,7 @@ type MoonbasePrecompilesAt = ( PalletXcmPrecompile, (CallableByContract, CallableByPrecompile), >, + PrecompileAt, ForeignAssetMigratorPrecompile, ()>, ); pub struct DisabledLocalAssets(sp_std::marker::PhantomData); From 4365c7f8e56868d01b65b33139ed9262f8806344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 21 Jul 2024 19:34:54 +0200 Subject: [PATCH 39/71] fix tracing compilation --- runtime/common/src/impl_moonbeam_xcm_call_tracing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs b/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs index 08d2b06f13..ffddb3b88f 100644 --- a/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs +++ b/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs @@ -78,7 +78,8 @@ macro_rules! impl_moonbeam_xcm_call_tracing { EthereumXcmTracingStatus::Transaction(traced_transaction_hash) => { let transaction_hash = xcm_transaction.into_transaction_v2( EthereumXcm::nonce(), - ::ChainId::get() + ::ChainId::get(), + false ) .expect("Invalid transaction conversion") .hash(); From 97c62669f9ea47f42d10cca097b33cfe67685b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 21 Jul 2024 19:36:01 +0200 Subject: [PATCH 40/71] add EvmForeignassets to CurrencyIdToLocation convertion --- runtime/moonbase/src/xcm_config.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index bb76bc1d6e..d1c2817b0a 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -598,7 +598,10 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdConvert = CurrencyIdToLocation>; + type CurrencyIdConvert = CurrencyIdToLocation<( + EvmForeignAssets, + AsAssetType, + )>; type XcmExecutor = XcmExecutor; type SelfLocation = SelfLocation; type Weigher = XcmWeigher; @@ -673,7 +676,10 @@ impl pallet_xcm_transactor::Config for Runtime { type SovereignAccountDispatcherOrigin = EnsureRoot; type CurrencyId = CurrencyId; type AccountIdToLocation = AccountIdToLocation; - type CurrencyIdToLocation = CurrencyIdToLocation>; + type CurrencyIdToLocation = CurrencyIdToLocation<( + EvmForeignAssets, + AsAssetType, + )>; type XcmSender = XcmRouter; type SelfLocation = SelfLocation; type Weigher = XcmWeigher; @@ -731,13 +737,10 @@ impl pallet_moonbeam_foreign_assets::Config for Runtime { type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; type ForeignAssetCreatorOrigin = EnsureRoot; - type ForeignAssetForceBurnOrigin = EnsureRoot; - type ForeignAssetForceMintOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; type OnForeignAssetCreated = (); - type OnForeignAssetDestroyed = (); type MaxForeignAssets = ConstU32<256>; type RuntimeEvent = RuntimeEvent; // TODO generate weights From e22cd3b9804cea4fdd3cbe159db1df8359e344f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Sun, 21 Jul 2024 19:36:39 +0200 Subject: [PATCH 41/71] remove useless calls and rework rust tests --- Cargo.lock | 588 ++++++++++--------- Cargo.toml | 2 + pallets/moonbeam-foreign-assets/src/evm.rs | 2 +- pallets/moonbeam-foreign-assets/src/lib.rs | 137 ++--- pallets/moonbeam-foreign-assets/src/mock.rs | 29 +- pallets/moonbeam-foreign-assets/src/tests.rs | 2 +- runtime/moonbase/tests/common/mod.rs | 51 +- runtime/moonbase/tests/integration_test.rs | 151 ++--- 8 files changed, 437 insertions(+), 525 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a1c2bc9f9..0ed7120dc4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -949,7 +949,7 @@ dependencies = [ [[package]] name = "binary-merkle-tree" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hash-db 0.16.0", "log", @@ -1182,7 +1182,7 @@ dependencies = [ [[package]] name = "bp-xcm-bridge-hub-router" version = "0.6.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -1948,7 +1948,7 @@ dependencies = [ [[package]] name = "cumulus-client-cli" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "clap", "parity-scale-codec", @@ -1965,7 +1965,7 @@ dependencies = [ [[package]] name = "cumulus-client-collator" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", @@ -1988,7 +1988,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-client-pov-recovery", @@ -2017,7 +2017,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-proposer" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "anyhow", "async-trait", @@ -2032,7 +2032,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-relay-chain" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -2055,7 +2055,7 @@ dependencies = [ [[package]] name = "cumulus-client-network" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-relay-chain-interface", @@ -2078,7 +2078,7 @@ dependencies = [ [[package]] name = "cumulus-client-parachain-inherent" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2102,7 +2102,7 @@ dependencies = [ [[package]] name = "cumulus-client-pov-recovery" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2126,7 +2126,7 @@ dependencies = [ [[package]] name = "cumulus-client-service" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-client-cli", "cumulus-client-collator", @@ -2163,7 +2163,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-dmp-queue" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "frame-benchmarking", @@ -2181,7 +2181,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bytes", "cumulus-pallet-parachain-system-proc-macro", @@ -2216,7 +2216,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system-proc-macro" version = "0.6.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -2227,7 +2227,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcm" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -2243,7 +2243,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcmp-queue" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bounded-collections", "bp-xcm-bridge-hub-router", @@ -2268,7 +2268,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-core" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "polkadot-core-primitives", @@ -2285,7 +2285,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-parachain-inherent" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2302,7 +2302,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-proof-size-hostfunction" version = "0.2.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "sp-externalities", "sp-runtime-interface", @@ -2312,7 +2312,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-timestamp" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "futures 0.3.30", @@ -2325,7 +2325,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-utility" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -2345,7 +2345,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-inprocess-interface" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2369,7 +2369,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-interface" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2387,7 +2387,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-minimal-node" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-trait", @@ -2429,7 +2429,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-rpc-interface" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2468,7 +2468,7 @@ dependencies = [ [[package]] name = "cumulus-test-relay-sproof-builder" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", @@ -3699,7 +3699,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "fork-tree" version = "12.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", ] @@ -3815,7 +3815,7 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-support-procedural", @@ -3840,7 +3840,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "32.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "Inflector", "array-bytes 6.2.2", @@ -3890,7 +3890,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -3901,7 +3901,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -3918,7 +3918,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "aquamarine 0.3.3", "frame-support", @@ -3949,7 +3949,7 @@ dependencies = [ [[package]] name = "frame-metadata-hash-extension" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "docify", @@ -3964,7 +3964,7 @@ dependencies = [ [[package]] name = "frame-support" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "aquamarine 0.5.0", "array-bytes 6.2.2", @@ -4005,7 +4005,7 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "23.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "Inflector", "cfg-expr", @@ -4024,7 +4024,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "10.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support-procedural-tools-derive", "proc-macro-crate 3.1.0", @@ -4036,7 +4036,7 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools-derive" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro2", "quote", @@ -4046,7 +4046,7 @@ dependencies = [ [[package]] name = "frame-system" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cfg-if", "docify", @@ -4066,7 +4066,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -4081,7 +4081,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "sp-api", @@ -4090,7 +4090,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "parity-scale-codec", @@ -6190,7 +6190,7 @@ dependencies = [ [[package]] name = "mmr-gadget" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "log", @@ -6209,7 +6209,7 @@ dependencies = [ [[package]] name = "mmr-rpc" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -6398,6 +6398,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-common", "polkadot-runtime-parachains", + "precompile-foreign-asset-migrator", "precompile-utils", "rlp", "scale-info", @@ -8142,7 +8143,7 @@ checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" [[package]] name = "pallet-asset-conversion" version = "10.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8181,7 +8182,7 @@ dependencies = [ [[package]] name = "pallet-asset-rate" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8196,7 +8197,7 @@ dependencies = [ [[package]] name = "pallet-asset-tx-payment" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8214,7 +8215,7 @@ dependencies = [ [[package]] name = "pallet-assets" version = "29.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8306,7 +8307,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -8322,7 +8323,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -8336,7 +8337,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8360,7 +8361,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "aquamarine 0.5.0", "docify", @@ -8382,7 +8383,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -8398,7 +8399,7 @@ dependencies = [ [[package]] name = "pallet-beefy" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -8418,7 +8419,7 @@ dependencies = [ [[package]] name = "pallet-beefy-mmr" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "binary-merkle-tree", @@ -8443,7 +8444,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8461,7 +8462,7 @@ dependencies = [ [[package]] name = "pallet-broker" version = "0.6.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "frame-benchmarking", @@ -8480,7 +8481,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8499,7 +8500,7 @@ dependencies = [ [[package]] name = "pallet-collator-selection" version = "9.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8519,7 +8520,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8536,7 +8537,7 @@ dependencies = [ [[package]] name = "pallet-conviction-voting" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "assert_matches", "frame-benchmarking", @@ -8575,7 +8576,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -8593,7 +8594,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -8616,7 +8617,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -8630,7 +8631,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9508,7 +9509,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -9527,7 +9528,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9550,7 +9551,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "enumflags2", "frame-benchmarking", @@ -9568,7 +9569,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9588,7 +9589,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9621,7 +9622,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9638,7 +9639,7 @@ dependencies = [ [[package]] name = "pallet-message-queue" version = "31.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "environmental", "frame-benchmarking", @@ -9677,7 +9678,7 @@ dependencies = [ [[package]] name = "pallet-mmr" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9761,7 +9762,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9777,7 +9778,7 @@ dependencies = [ [[package]] name = "pallet-nis" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9793,7 +9794,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "25.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -9812,7 +9813,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -9832,7 +9833,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "23.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "pallet-nomination-pools", "parity-scale-codec", @@ -9843,7 +9844,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -9860,7 +9861,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -9906,7 +9907,7 @@ dependencies = [ [[package]] name = "pallet-parameters" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -9940,7 +9941,7 @@ dependencies = [ [[package]] name = "pallet-preimage" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -9957,7 +9958,7 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10015,7 +10016,7 @@ dependencies = [ [[package]] name = "pallet-ranked-collective" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10034,7 +10035,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10049,7 +10050,7 @@ dependencies = [ [[package]] name = "pallet-referenda" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "assert_matches", "frame-benchmarking", @@ -10091,7 +10092,7 @@ dependencies = [ [[package]] name = "pallet-root-testing" version = "4.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -10106,7 +10107,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -10124,7 +10125,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -10146,7 +10147,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10163,7 +10164,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10181,7 +10182,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -10204,7 +10205,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -10215,7 +10216,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" version = "19.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "sp-arithmetic", @@ -10224,7 +10225,7 @@ dependencies = [ [[package]] name = "pallet-staking-runtime-api" version = "14.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "sp-api", @@ -10234,7 +10235,7 @@ dependencies = [ [[package]] name = "pallet-state-trie-migration" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10251,7 +10252,7 @@ dependencies = [ [[package]] name = "pallet-sudo" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -10267,7 +10268,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -10287,7 +10288,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10306,7 +10307,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -10322,7 +10323,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "30.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -10338,7 +10339,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -10350,7 +10351,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "frame-benchmarking", @@ -10369,7 +10370,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10385,7 +10386,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10400,7 +10401,7 @@ dependencies = [ [[package]] name = "pallet-whitelist" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10415,7 +10416,7 @@ dependencies = [ [[package]] name = "pallet-xcm" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bounded-collections", "frame-benchmarking", @@ -10439,7 +10440,7 @@ dependencies = [ [[package]] name = "pallet-xcm-benchmarks" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-benchmarking", "frame-support", @@ -10484,7 +10485,7 @@ dependencies = [ [[package]] name = "parachains-common" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "cumulus-primitives-utility", @@ -10832,7 +10833,7 @@ checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "polkadot-approval-distribution" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "futures 0.3.30", @@ -10852,7 +10853,7 @@ dependencies = [ [[package]] name = "polkadot-availability-bitfield-distribution" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "always-assert", "futures 0.3.30", @@ -10868,7 +10869,7 @@ dependencies = [ [[package]] name = "polkadot-availability-distribution" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "derive_more", "fatality", @@ -10891,7 +10892,7 @@ dependencies = [ [[package]] name = "polkadot-availability-recovery" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "fatality", @@ -10914,7 +10915,7 @@ dependencies = [ [[package]] name = "polkadot-cli" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cfg-if", "clap", @@ -10942,7 +10943,7 @@ dependencies = [ [[package]] name = "polkadot-collator-protocol" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "fatality", @@ -10964,7 +10965,7 @@ dependencies = [ [[package]] name = "polkadot-core-primitives" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -10976,7 +10977,7 @@ dependencies = [ [[package]] name = "polkadot-dispute-distribution" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "derive_more", "fatality", @@ -11001,7 +11002,7 @@ dependencies = [ [[package]] name = "polkadot-erasure-coding" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", @@ -11015,7 +11016,7 @@ dependencies = [ [[package]] name = "polkadot-gossip-support" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "futures-timer", @@ -11037,7 +11038,7 @@ dependencies = [ [[package]] name = "polkadot-network-bridge" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "always-assert", "async-trait", @@ -11060,7 +11061,7 @@ dependencies = [ [[package]] name = "polkadot-node-collation-generation" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "parity-scale-codec", @@ -11078,7 +11079,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-approval-voting" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "derive_more", @@ -11111,7 +11112,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-av-store" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "futures 0.3.30", @@ -11133,7 +11134,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-backing" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "fatality", @@ -11153,7 +11154,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-bitfield-signing" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "polkadot-node-subsystem", @@ -11168,7 +11169,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-candidate-validation" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -11189,7 +11190,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-api" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "polkadot-node-metrics", @@ -11203,7 +11204,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-selection" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "futures-timer", @@ -11220,7 +11221,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-dispute-coordinator" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "fatality", "futures 0.3.30", @@ -11239,7 +11240,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-parachains-inherent" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -11256,7 +11257,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-prospective-parachains" version = "6.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "fatality", @@ -11273,7 +11274,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-provisioner" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "fatality", @@ -11291,7 +11292,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "always-assert", "array-bytes 6.2.2", @@ -11320,7 +11321,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-checker" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "polkadot-node-primitives", @@ -11336,7 +11337,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-common" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cpu-time", "futures 0.3.30", @@ -11362,7 +11363,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-runtime-api" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "polkadot-node-metrics", @@ -11377,7 +11378,7 @@ dependencies = [ [[package]] name = "polkadot-node-jaeger" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "lazy_static", "log", @@ -11396,7 +11397,7 @@ dependencies = [ [[package]] name = "polkadot-node-metrics" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bs58 0.5.1", "futures 0.3.30", @@ -11415,7 +11416,7 @@ dependencies = [ [[package]] name = "polkadot-node-network-protocol" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-channel 1.9.0", "async-trait", @@ -11441,7 +11442,7 @@ dependencies = [ [[package]] name = "polkadot-node-primitives" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "bounded-vec", @@ -11464,7 +11465,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "polkadot-node-jaeger", "polkadot-node-subsystem-types", @@ -11474,7 +11475,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-types" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "bitvec", @@ -11503,7 +11504,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-util" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "derive_more", @@ -11538,7 +11539,7 @@ dependencies = [ [[package]] name = "polkadot-overseer" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -11560,7 +11561,7 @@ dependencies = [ [[package]] name = "polkadot-parachain-primitives" version = "6.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bounded-collections", "derive_more", @@ -11577,7 +11578,7 @@ dependencies = [ [[package]] name = "polkadot-primitives" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "hex-literal 0.4.1", @@ -11604,7 +11605,7 @@ dependencies = [ [[package]] name = "polkadot-rpc" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "mmr-rpc", @@ -11637,7 +11638,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-common" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitvec", "frame-benchmarking", @@ -11688,7 +11689,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-metrics" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bs58 0.5.1", "frame-benchmarking", @@ -11701,7 +11702,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-parachains" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bitflags 1.3.2", "bitvec", @@ -11750,7 +11751,7 @@ dependencies = [ [[package]] name = "polkadot-service" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "bitvec", @@ -11872,7 +11873,7 @@ dependencies = [ [[package]] name = "polkadot-statement-distribution" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "arrayvec 0.7.4", "bitvec", @@ -11895,7 +11896,7 @@ dependencies = [ [[package]] name = "polkadot-statement-table" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "polkadot-primitives", @@ -12058,6 +12059,39 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "precompile-foreign-asset-migrator" +version = "0.1.0" +dependencies = [ + "account", + "derive_more", + "fp-evm", + "frame-support", + "frame-system", + "hex-literal 0.3.4", + "libsecp256k1", + "log", + "num_enum 0.5.11", + "pallet-asset-manager", + "pallet-assets", + "pallet-balances", + "pallet-evm", + "pallet-moonbeam-foreign-assets", + "pallet-timestamp", + "parity-scale-codec", + "paste", + "precompile-utils", + "scale-info", + "serde", + "sha3", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "xcm-primitives 0.1.0", +] + [[package]] name = "precompile-utils" version = "0.1.0" @@ -12882,7 +12916,7 @@ dependencies = [ [[package]] name = "rococo-runtime" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "binary-merkle-tree", "bitvec", @@ -12983,7 +13017,7 @@ dependencies = [ [[package]] name = "rococo-runtime-constants" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "polkadot-primitives", @@ -13279,7 +13313,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "23.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "sp-core", @@ -13290,7 +13324,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -13321,7 +13355,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "futures-timer", @@ -13343,7 +13377,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "sp-api", @@ -13358,7 +13392,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "docify", @@ -13385,7 +13419,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -13396,7 +13430,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.36.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "chrono", @@ -13440,7 +13474,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "fnv", "futures 0.3.30", @@ -13467,7 +13501,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.35.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hash-db 0.16.0", "kvdb", @@ -13493,7 +13527,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -13518,7 +13552,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -13547,7 +13581,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "fork-tree", @@ -13583,7 +13617,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -13605,7 +13639,7 @@ dependencies = [ [[package]] name = "sc-consensus-beefy" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -13642,7 +13676,7 @@ dependencies = [ [[package]] name = "sc-consensus-beefy-rpc" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -13661,7 +13695,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "fork-tree", "parity-scale-codec", @@ -13674,7 +13708,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa" version = "0.19.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ahash 0.8.11", "array-bytes 6.2.2", @@ -13718,7 +13752,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa-rpc" version = "0.19.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "finality-grandpa", "futures 0.3.30", @@ -13738,7 +13772,7 @@ dependencies = [ [[package]] name = "sc-consensus-manual-seal" version = "0.35.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "assert_matches", "async-trait", @@ -13773,7 +13807,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -13796,7 +13830,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.32.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "parity-scale-codec", @@ -13820,7 +13854,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.29.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "polkavm", @@ -13834,7 +13868,7 @@ dependencies = [ [[package]] name = "sc-executor-polkavm" version = "0.29.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "polkavm", @@ -13845,7 +13879,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.29.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "anyhow", "cfg-if", @@ -13865,7 +13899,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ansi_term", "futures 0.3.30", @@ -13882,7 +13916,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "25.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "parking_lot 0.12.3", @@ -13896,7 +13930,7 @@ dependencies = [ [[package]] name = "sc-mixnet" version = "0.4.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 4.2.0", "arrayvec 0.7.4", @@ -13925,7 +13959,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -13976,7 +14010,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -13994,7 +14028,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ahash 0.8.11", "futures 0.3.30", @@ -14014,7 +14048,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -14035,7 +14069,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -14072,7 +14106,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "futures 0.3.30", @@ -14092,7 +14126,7 @@ dependencies = [ [[package]] name = "sc-network-types" version = "0.10.0-dev" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bs58 0.4.0", "libp2p-identity", @@ -14106,7 +14140,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "bytes", @@ -14141,7 +14175,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.17.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -14150,7 +14184,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -14182,7 +14216,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.33.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -14202,7 +14236,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "governor", @@ -14220,7 +14254,7 @@ dependencies = [ [[package]] name = "sc-rpc-spec-v2" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "futures 0.3.30", @@ -14252,7 +14286,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.35.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "directories", @@ -14316,7 +14350,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.30.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "log", "parity-scale-codec", @@ -14327,7 +14361,7 @@ dependencies = [ [[package]] name = "sc-storage-monitor" version = "0.16.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "clap", "fs4", @@ -14340,7 +14374,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -14359,7 +14393,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "derive_more", "futures 0.3.30", @@ -14380,7 +14414,7 @@ dependencies = [ [[package]] name = "sc-telemetry" version = "15.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "chrono", "futures 0.3.30", @@ -14400,7 +14434,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ansi_term", "chrono", @@ -14430,7 +14464,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro-crate 3.1.0", "proc-macro2", @@ -14441,7 +14475,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -14468,7 +14502,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -14484,7 +14518,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "14.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-channel 1.9.0", "futures 0.3.30", @@ -15023,7 +15057,7 @@ dependencies = [ [[package]] name = "slot-range-helper" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "enumn", "parity-scale-codec", @@ -15217,7 +15251,7 @@ dependencies = [ [[package]] name = "sp-api" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hash-db 0.16.0", "log", @@ -15239,7 +15273,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "15.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "Inflector", "blake2 0.10.6", @@ -15253,7 +15287,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "30.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15266,7 +15300,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "23.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "integer-sqrt", @@ -15299,7 +15333,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15311,7 +15345,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "sp-api", "sp-inherents", @@ -15321,7 +15355,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "log", @@ -15339,7 +15373,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.32.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "futures 0.3.30", @@ -15354,7 +15388,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.32.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "parity-scale-codec", @@ -15370,7 +15404,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.32.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "parity-scale-codec", @@ -15388,7 +15422,7 @@ dependencies = [ [[package]] name = "sp-consensus-beefy" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "lazy_static", "parity-scale-codec", @@ -15408,7 +15442,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "finality-grandpa", "log", @@ -15425,7 +15459,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.32.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15436,7 +15470,7 @@ dependencies = [ [[package]] name = "sp-core" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "bandersnatch_vrfs", @@ -15483,7 +15517,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.10.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -15503,7 +15537,7 @@ dependencies = [ [[package]] name = "sp-crypto-hashing" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "blake2b_simd", "byteorder", @@ -15516,7 +15550,7 @@ dependencies = [ [[package]] name = "sp-crypto-hashing-proc-macro" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "quote", "sp-crypto-hashing", @@ -15526,7 +15560,7 @@ dependencies = [ [[package]] name = "sp-database" version = "10.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "kvdb", "parking_lot 0.12.3", @@ -15535,7 +15569,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "proc-macro2", "quote", @@ -15545,7 +15579,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.25.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "environmental", "parity-scale-codec", @@ -15555,7 +15589,7 @@ dependencies = [ [[package]] name = "sp-genesis-builder" version = "0.8.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15567,7 +15601,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -15580,7 +15614,7 @@ dependencies = [ [[package]] name = "sp-io" version = "30.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bytes", "ed25519-dalek 2.1.1", @@ -15606,7 +15640,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "31.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "sp-core", "sp-runtime", @@ -15616,7 +15650,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.34.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "parking_lot 0.12.3", @@ -15627,7 +15661,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "thiserror", "zstd 0.12.4", @@ -15636,7 +15670,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.6.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-metadata", "parity-scale-codec", @@ -15646,7 +15680,7 @@ dependencies = [ [[package]] name = "sp-mixnet" version = "0.4.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15657,7 +15691,7 @@ dependencies = [ [[package]] name = "sp-mmr-primitives" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ckb-merkle-mountain-range", "log", @@ -15674,7 +15708,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15687,7 +15721,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "sp-api", "sp-core", @@ -15697,7 +15731,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "backtrace", "lazy_static", @@ -15707,7 +15741,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "rustc-hash", "serde", @@ -15717,7 +15751,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "31.0.1" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "docify", "either", @@ -15741,7 +15775,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "24.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -15760,7 +15794,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "17.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "Inflector", "expander 2.0.0", @@ -15773,7 +15807,7 @@ dependencies = [ [[package]] name = "sp-session" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "scale-info", @@ -15787,7 +15821,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -15800,7 +15834,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.35.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hash-db 0.16.0", "log", @@ -15820,7 +15854,7 @@ dependencies = [ [[package]] name = "sp-statement-store" version = "10.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "aes-gcm", "curve25519-dalek 4.1.2", @@ -15844,12 +15878,12 @@ dependencies = [ [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" [[package]] name = "sp-storage" version = "19.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "impl-serde 0.4.0", "parity-scale-codec", @@ -15861,7 +15895,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "parity-scale-codec", @@ -15873,7 +15907,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "16.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "tracing", @@ -15884,7 +15918,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "sp-api", "sp-runtime", @@ -15893,7 +15927,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "26.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "async-trait", "parity-scale-codec", @@ -15907,7 +15941,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "ahash 0.8.11", "hash-db 0.16.0", @@ -15930,7 +15964,7 @@ dependencies = [ [[package]] name = "sp-version" version = "29.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "impl-serde 0.4.0", "parity-scale-codec", @@ -15947,7 +15981,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "13.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "parity-scale-codec", "proc-macro2", @@ -15958,7 +15992,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "20.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -15970,7 +16004,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "bounded-collections", "parity-scale-codec", @@ -16160,7 +16194,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "staging-parachain-info" version = "0.7.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -16174,7 +16208,7 @@ dependencies = [ [[package]] name = "staging-xcm" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "bounded-collections", @@ -16192,7 +16226,7 @@ dependencies = [ [[package]] name = "staging-xcm-builder" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "frame-system", @@ -16214,7 +16248,7 @@ dependencies = [ [[package]] name = "staging-xcm-executor" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "environmental", "frame-benchmarking", @@ -16367,7 +16401,7 @@ dependencies = [ [[package]] name = "substrate-bip39" version = "0.4.7" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hmac 0.12.1", "pbkdf2 0.12.2", @@ -16392,7 +16426,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "11.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" [[package]] name = "substrate-fixed" @@ -16407,7 +16441,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "28.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.30", @@ -16426,7 +16460,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.17.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "hyper", "log", @@ -16438,7 +16472,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "27.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -16455,7 +16489,7 @@ dependencies = [ [[package]] name = "substrate-test-client" version = "2.0.1" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "async-trait", @@ -16482,7 +16516,7 @@ dependencies = [ [[package]] name = "substrate-test-runtime" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "frame-executive", @@ -16526,7 +16560,7 @@ dependencies = [ [[package]] name = "substrate-test-runtime-client" version = "2.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "futures 0.3.30", "sc-block-builder", @@ -16554,7 +16588,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "17.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "array-bytes 6.2.2", "build-helper", @@ -17145,7 +17179,7 @@ dependencies = [ [[package]] name = "tracing-gum" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "coarsetime", "polkadot-primitives", @@ -17156,7 +17190,7 @@ dependencies = [ [[package]] name = "tracing-gum-proc-macro" version = "5.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "expander 2.0.0", "proc-macro-crate 3.1.0", @@ -18015,7 +18049,7 @@ dependencies = [ [[package]] name = "westend-runtime" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "binary-merkle-tree", "bitvec", @@ -18122,7 +18156,7 @@ dependencies = [ [[package]] name = "westend-runtime-constants" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "polkadot-primitives", @@ -18524,7 +18558,7 @@ dependencies = [ [[package]] name = "xcm-fee-payment-runtime-api" version = "0.1.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "parity-scale-codec", @@ -18582,7 +18616,7 @@ dependencies = [ [[package]] name = "xcm-procedural" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "Inflector", "proc-macro2", @@ -18593,7 +18627,7 @@ dependencies = [ [[package]] name = "xcm-simulator" version = "7.0.0" -source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#a4592a4d8b6a79d17651d9803e29c0851eca2f82" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.11.0#08968b280245b53ce790f9234289960ace6bbaee" dependencies = [ "frame-support", "parity-scale-codec", diff --git a/Cargo.toml b/Cargo.toml index 1adc7f7927..1313670ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "precompiles/collective", "precompiles/conviction-voting", "precompiles/crowdloan-rewards", + "precompiles/foreign-asset-migrator", "precompiles/gmp", "precompiles/identity", "precompiles/parachain-staking", @@ -104,6 +105,7 @@ pallet-parachain-staking = { path = "pallets/parachain-staking", default-feature pallet-precompile-benchmarks = { path = "pallets/precompile-benchmarks", default-features = false } pallet-proxy-genesis-companion = { path = "pallets/proxy-genesis-companion", default-features = false } pallet-xcm-transactor = { path = "pallets/xcm-transactor", default-features = false } +precompile-foreign-asset-migrator = { path = "precompiles/foreign-asset-migrator", default-features = false } xcm-primitives = { path = "primitives/xcm", default-features = false } pallet-crowdloan-rewards = { git = "https://github.com/moonbeam-foundation/crowdloan-rewards", branch = "moonbeam-polkadot-v1.11.0", default-features = false } diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 34b19ce3c7..a2e9ce1d10 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -40,7 +40,7 @@ const ERC20_PAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 const ERC20_TRANSFER_GAS_LIMIT: u64 = 155_000; // highest failure: 154_000 const ERC20_UNPAUSE_GAS_LIMIT: u64 = 150_000; // highest failure: 149_500 -pub(crate) enum EvmError { +pub enum EvmError { BurnFromFail, ContractReturnInvalidValue, DispatchError(DispatchError), diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 70173351b2..32c855cf00 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -143,12 +143,6 @@ pub mod pallet { /// Origin that is allowed to create a new foreign assets type ForeignAssetCreatorOrigin: EnsureOrigin; - /// Origin that is allowed to burn foreign assets from any account - type ForeignAssetForceBurnOrigin: EnsureOrigin; - - /// Origin that is allowed to mint foreign assets from any account - type ForeignAssetForceMintOrigin: EnsureOrigin; - /// Origin that is allowed to freeze all tokens of a foreign asset type ForeignAssetFreezerOrigin: EnsureOrigin; @@ -162,9 +156,6 @@ pub mod pallet { /// Hook to be called when new foreign asset is registered. type OnForeignAssetCreated: ForeignAssetCreatedHook; - /// Hook to be called when foreign asset is de-registered. - type OnForeignAssetDestroyed: ForeignAssetDestroyedHook; - /// Maximum nulmbers of differnt foreign assets type MaxForeignAssets: Get; @@ -197,6 +188,7 @@ pub mod pallet { EvmInternalError, InvalidTicker, InvalidTokenName, + LocationAlreadyExists, TooManyForeignAssets, } @@ -254,11 +246,13 @@ pub mod pallet { impl Pallet { /// The account ID of this pallet + #[inline] pub fn account_id() -> H160 { let account_id: T::AccountId = PALLET_ID.into_account_truncating(); T::AccountIdToH160::convert(account_id) } + /// Compute asset contract address from asset id #[inline] pub(crate) fn contract_address_from_asset_id(asset_id: AssetId) -> H160 { let mut buffer = [0u8; 20]; @@ -266,6 +260,24 @@ pub mod pallet { buffer[4..].copy_from_slice(&asset_id.to_be_bytes()); H160(buffer) } + + /// Mint an asset into a specific account + pub fn mint_into( + asset_id: AssetId, + beneficiary: T::AccountId, + amount: U256, + ) -> Result<(), evm::EvmError> { + // We perform the evm call in a storage transaction to ensure that if it fail + // any contract storage changes are rolled back. + frame_support::storage::with_storage_layer(|| { + EvmCaller::::erc20_mint_into( + Self::contract_address_from_asset_id(asset_id), + T::AccountIdToH160::convert(beneficiary), + amount, + ) + }) + .map_err(Into::into) + } } #[pallet::call] @@ -285,10 +297,15 @@ pub mod pallet { // Ensure such an assetId does not exist ensure!( - AssetsById::::get(&asset_id).is_none(), + !AssetsById::::contains_key(&asset_id), Error::::AssetAlreadyExists ); + ensure!( + !AssetsByLocation::::contains_key(&xcm_location), + Error::::LocationAlreadyExists + ); + ensure!( AssetsById::::count() < T::MaxForeignAssets::get(), Error::::TooManyForeignAssets @@ -415,97 +432,6 @@ pub mod pallet { }); Ok(()) } - - /// Force to burn a given foreign assetId from any account - #[pallet::call_index(4)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] - pub fn force_burn_from( - origin: OriginFor, - asset_id: AssetId, - from: T::AccountId, - amount: U256, - ) -> DispatchResult { - T::ForeignAssetForceBurnOrigin::ensure_origin(origin)?; - - ensure!( - AssetsById::::contains_key(&asset_id), - Error::::AssetDoesNotExist - ); - - // We perform the evm call in a storage transaction to ensure that if it fail - // any contract storage changes are rolled back. - frame_support::storage::with_storage_layer(|| { - EvmCaller::::erc20_burn_from( - Self::contract_address_from_asset_id(asset_id), - T::AccountIdToH160::convert(from), - amount, - ) - }) - .map_err(|_| Error::::Erc20ContractCallFail)?; - - Ok(()) - } - - /// Force to mint a given foreign assetId into any account - #[pallet::call_index(5)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] - pub fn force_mint_into( - origin: OriginFor, - asset_id: AssetId, - beneficiary: T::AccountId, - amount: U256, - ) -> DispatchResult { - T::ForeignAssetForceMintOrigin::ensure_origin(origin)?; - - ensure!( - AssetsById::::contains_key(&asset_id), - Error::::AssetDoesNotExist - ); - - // We perform the evm call in a storage transaction to ensure that if it fail - // any contract storage changes are rolled back. - frame_support::storage::with_storage_layer(|| { - EvmCaller::::erc20_mint_into( - Self::contract_address_from_asset_id(asset_id), - T::AccountIdToH160::convert(beneficiary), - amount, - ) - }) - .map_err(|_| Error::::Erc20ContractCallFail)?; - - Ok(()) - } - - /// Transfer a given foreign asset from an account to another - #[pallet::call_index(6)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] - pub fn transfer( - origin: OriginFor, - asset_id: AssetId, - beneficiary: T::AccountId, - amount: U256, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - ensure!( - AssetsById::::contains_key(&asset_id), - Error::::AssetDoesNotExist - ); - - // We perform the evm call in a storage transaction to ensure that if it fail - // any contract storage changes are rolled back. - frame_support::storage::with_storage_layer(|| { - EvmCaller::::erc20_transfer( - Self::contract_address_from_asset_id(asset_id), - T::AccountIdToH160::convert(who), - T::AccountIdToH160::convert(beneficiary), - amount, - ) - }) - .map_err(|_| Error::::Erc20ContractCallFail)?; - - Ok(()) - } } impl xcm_executor::traits::TransactAsset for Pallet { @@ -594,4 +520,13 @@ pub mod pallet { Ok(what.clone().into()) } } + + impl sp_runtime::traits::MaybeEquivalence for Pallet { + fn convert(location: &Location) -> Option { + AssetsByLocation::::get(location).map(|(asset_id, _)| asset_id) + } + fn convert_back(asset_id: &AssetId) -> Option { + AssetsById::::get(asset_id) + } + } } diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index 514265337f..efc186dd90 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -21,7 +21,7 @@ use frame_support::traits::Everything; use frame_support::{construct_runtime, pallet_prelude::*, parameter_types}; use frame_system::EnsureRoot; use pallet_evm::SubstrateBlockHashMapping; -use precompile_utils::testing::{Bob, Charlie, MockAccount}; +use precompile_utils::testing::MockAccount; use sp_core::{H256, U256}; use sp_runtime::traits::{BlakeTwo256, IdentityLookup}; use sp_runtime::BuildStorage; @@ -159,24 +159,6 @@ fn note_on_asset_created_hook_invocation( ); } -/// Gets parameters of last `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation -pub fn get_asset_destroyed_hook_invocation() -> Option<(ForeignAsset, AssetId)> -{ - storage::unhashed::get_raw(b"____on_foreign_asset_destroyed") - .map(|output| Decode::decode(&mut output.as_slice()).expect("Decoding should work")) -} - -/// Notes down parameters of current `ForeignAssetDestroyedHook::on_asset_destroyed` hook invocation -fn note_on_asset_destroyed_hook_invocation( - foreign_asset: &ForeignAsset, - asset_id: &AssetId, -) { - storage::unhashed::put_raw( - b"____on_foreign_asset_destroyed", - (foreign_asset, asset_id).encode().as_slice(), - ); -} - /// Test hook that records the hook invocation with exact params pub struct NoteDownHook(PhantomData); @@ -186,12 +168,6 @@ impl ForeignAssetCreatedHook for NoteDownHoo } } -impl ForeignAssetDestroyedHook for NoteDownHook { - fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId) { - note_on_asset_destroyed_hook_invocation(foreign_asset, asset_id); - } -} - pub struct AccountIdToH160; impl sp_runtime::traits::Convert for AccountIdToH160 { fn convert(account_id: AccountId) -> H160 { @@ -204,13 +180,10 @@ impl crate::Config for Test { type AssetIdFilter = Everything; type EvmRunner = pallet_evm::runner::stack::Runner; type ForeignAssetCreatorOrigin = EnsureRoot; - type ForeignAssetForceBurnOrigin = EnsureRoot; - type ForeignAssetForceMintOrigin = EnsureRoot; type ForeignAssetFreezerOrigin = EnsureRoot; type ForeignAssetModifierOrigin = EnsureRoot; type ForeignAssetUnfreezerOrigin = EnsureRoot; type OnForeignAssetCreated = NoteDownHook; - type OnForeignAssetDestroyed = NoteDownHook; type MaxForeignAssets = ConstU32<3>; type RuntimeEvent = RuntimeEvent; type WeightInfo = (); diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index 02f3a0739e..99cb7362d1 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -17,7 +17,7 @@ use crate::*; use mock::*; use frame_support::{assert_noop, assert_ok}; -use precompile_utils::testing::{Bob, Charlie, MockAccount}; +use precompile_utils::testing::Bob; use xcm::latest::prelude::*; fn encode_ticker(str_: &str) -> BoundedVec> { diff --git a/runtime/moonbase/tests/common/mod.rs b/runtime/moonbase/tests/common/mod.rs index cd3a0cfe0c..19df108ab7 100644 --- a/runtime/moonbase/tests/common/mod.rs +++ b/runtime/moonbase/tests/common/mod.rs @@ -22,11 +22,10 @@ use frame_support::{ assert_ok, traits::{OnFinalize, OnInitialize}, }; -use moonbase_runtime::{asset_config::AssetRegistrarMetadata, xcm_config::AssetType}; pub use moonbase_runtime::{ - currency::UNIT, AccountId, AssetId, AssetManager, Assets, AsyncBacking, AuthorInherent, - Balance, Ethereum, InflationInfo, ParachainStaking, Range, Runtime, RuntimeCall, RuntimeEvent, - System, TransactionConverter, UncheckedExtrinsic, HOURS, + currency::UNIT, AccountId, AsyncBacking, AuthorInherent, Balance, Ethereum, EvmForeignAssets, + InflationInfo, ParachainStaking, Range, Runtime, RuntimeCall, RuntimeEvent, System, + TransactionConverter, UncheckedExtrinsic, HOURS, }; use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; use polkadot_parachain::primitives::HeadData; @@ -107,10 +106,12 @@ pub fn last_event() -> RuntimeEvent { // Test struct with the purpose of initializing xcm assets #[derive(Clone)] pub struct XcmAssetInitialization { - pub asset_type: AssetType, - pub metadata: AssetRegistrarMetadata, + pub asset_id: u128, + pub xcm_location: xcm::v4::Location, + pub decimals: u8, + pub name: &'static str, + pub symbol: &'static str, pub balances: Vec<(AccountId, Balance)>, - pub is_sufficient: bool, } pub struct ExtBuilder { @@ -291,23 +292,31 @@ impl ExtBuilder { ext.execute_with(|| { // If any xcm assets specified, we register them here for xcm_asset_initialization in xcm_assets { - let asset_id: AssetId = xcm_asset_initialization.asset_type.clone().into(); - AssetManager::register_foreign_asset( + let asset_id = xcm_asset_initialization.asset_id; + EvmForeignAssets::create_foreign_asset( root_origin(), - xcm_asset_initialization.asset_type, - xcm_asset_initialization.metadata, - 1, - xcm_asset_initialization.is_sufficient, + asset_id, + xcm_asset_initialization.xcm_location, + xcm_asset_initialization.decimals, + xcm_asset_initialization + .symbol + .as_bytes() + .to_vec() + .try_into() + .expect("too long"), + xcm_asset_initialization + .name + .as_bytes() + .to_vec() + .try_into() + .expect("too long"), ) - .unwrap(); + .expect("fail to create foreign asset"); + for (account, balance) in xcm_asset_initialization.balances { - Assets::mint( - origin_of(AssetManager::account_id()), - asset_id.into(), - account, - balance, - ) - .unwrap(); + if EvmForeignAssets::mint_into(asset_id, account, balance.into()).is_err() { + panic!("fail to mint foreign asset"); + } } } System::set_block_number(1); diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 9719e90720..81f1530723 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -37,9 +37,9 @@ use frame_support::{ StorageHasher, Twox128, }; use moonbase_runtime::{ - asset_config::{AssetRegistrarMetadata, ForeignAssetInstance}, + //asset_config::ForeignAssetInstance, xcm_config::{AssetType, SelfReserve}, - AccountId, AssetId, Assets, Balances, CrowdloanRewards, EvmForeignAssets, Executive, + AccountId, AssetId, Balances, CrowdloanRewards, EvmForeignAssets, Executive, OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, TransactionPaymentAsGasPrice, TreasuryCouncilCollective, XTokens, XcmTransactor, @@ -60,7 +60,7 @@ use moonbeam_xcm_benchmarks::weights::XcmWeight; use moonkit_xcm_primitives::AccountIdAssetIdConversion; use nimbus_primitives::NimbusId; use pallet_evm::PrecompileSet; -use pallet_evm_precompileset_assets_erc20::{SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER}; +//use pallet_evm_precompileset_assets_erc20::{SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER}; use pallet_moonbeam_foreign_assets::AssetStatus; use pallet_transaction_payment::Multiplier; use pallet_xcm_transactor::{Currency, CurrencyPayment, HrmpOperation, TransactWeights}; @@ -80,10 +80,10 @@ type XcmUtilsPCall = pallet_evm_precompile_xcm_utils::XcmUtilsPrecompileCall< moonbase_runtime::xcm_config::XcmExecutorConfig, >; type XtokensPCall = pallet_evm_precompile_xtokens::XtokensPrecompileCall; -type ForeignAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSetCall< +/*type ForeignAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSetCall< Runtime, ForeignAssetInstance, ->; +>;*/ type XcmTransactorV1PCall = pallet_evm_precompile_xcm_transactor::v1::XcmTransactorPrecompileV1Call; type XcmTransactorV2PCall = @@ -1292,46 +1292,22 @@ fn create_and_manipulate_foreign_asset() { EvmForeignAssets::assets_by_location(&source_location), Some((1, AssetStatus::Active)) ); - - // Force mint some tokens - assert_ok!(EvmForeignAssets::force_mint_into( - moonbase_runtime::RuntimeOrigin::root(), - 1, - AccountId::from(ALICE), - U256([1_000_000, 0, 0, 0]), - )); - - // Force burn some tokens (not all the balance for worst case gas cost) - assert_ok!(EvmForeignAssets::force_burn_from( - moonbase_runtime::RuntimeOrigin::root(), - 1, - AccountId::from(ALICE), - U256([500_000, 0, 0, 0]), - )); - - // transfer some tokens from Alice to Bob - assert_ok!(EvmForeignAssets::transfer( - moonbase_runtime::RuntimeOrigin::signed(AccountId::from(ALICE)), - 1, - AccountId::from(BOB), - U256([100_000, 0, 0, 0]), - )); }); } +// The precoompile asset-erc20 is deprecated and not used anymore for new evm foreign assets +// We don't have testing tools in rust test to call real evm smart contract, so we rely on ts tests. +/* #[test] fn xcm_asset_erc20_precompiles_supply_and_balance() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], - is_sufficient: true, }]) .with_balances(vec![ (AccountId::from(ALICE), 2_000 * UNIT), @@ -1381,15 +1357,12 @@ fn xcm_asset_erc20_precompiles_supply_and_balance() { fn xcm_asset_erc20_precompiles_transfer() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], - is_sufficient: true, }]) .with_balances(vec![ (AccountId::from(ALICE), 2_000 * UNIT), @@ -1445,15 +1418,12 @@ fn xcm_asset_erc20_precompiles_transfer() { fn xcm_asset_erc20_precompiles_approve() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], - is_sufficient: true, }]) .with_balances(vec![ (AccountId::from(ALICE), 2_000 * UNIT), @@ -1524,21 +1494,19 @@ fn xcm_asset_erc20_precompiles_approve() { .expect_no_logs() .execute_returns(U256::from(400 * UNIT)); }); -} +}*/ #[test] +#[ignore] fn xtokens_precompiles_transfer() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, - balances: vec![(AccountId::from(ALICE), 1_000_000_000_000_000)], - is_sufficient: true, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, + balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], }]) .with_balances(vec![ (AccountId::from(ALICE), 2_000 * UNIT), @@ -1586,18 +1554,16 @@ fn xtokens_precompiles_transfer() { } #[test] +#[ignore] fn xtokens_precompiles_transfer_multiasset() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, - balances: vec![(AccountId::from(ALICE), 1_000_000_000_000_000)], - is_sufficient: true, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, + balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], }]) .with_balances(vec![ (AccountId::from(ALICE), 2_000 * UNIT), @@ -1992,6 +1958,7 @@ fn total_issuance_after_evm_transaction_without_priority_fee() { } #[test] +#[ignore] fn root_can_change_default_xcm_vers() { ExtBuilder::default() .with_balances(vec![ @@ -1999,19 +1966,15 @@ fn root_can_change_default_xcm_vers() { (AccountId::from(BOB), 1_000 * UNIT), ]) .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, balances: vec![(AccountId::from(ALICE), 1_000_000_000_000_000)], - is_sufficient: true, }]) .build() .execute_with(|| { - let source_location = AssetType::Xcm(xcm::v3::Location::parent()); let dest = Location { parents: 1, interior: [AccountId32 { @@ -2020,7 +1983,7 @@ fn root_can_change_default_xcm_vers() { }] .into(), }; - let source_id: moonbase_runtime::AssetId = source_location.clone().into(); + let source_id: moonbase_runtime::AssetId = 1; // Default XCM version is not set yet, so xtokens should fail because it does not // know with which version to send assert_noop!( @@ -2029,7 +1992,7 @@ fn root_can_change_default_xcm_vers() { moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), 100_000_000_000_000, Box::new(xcm::VersionedLocation::V4(dest.clone())), - WeightLimit::Limited(4000000000.into()) + WeightLimit::Unlimited ), orml_xtokens::Error::::XcmExecutionFailed ); @@ -2037,7 +2000,7 @@ fn root_can_change_default_xcm_vers() { // Root sets the defaultXcm assert_ok!(PolkadotXcm::force_default_xcm_version( root_origin(), - Some(2) + Some(4) )); // Now transferring does not fail @@ -2046,7 +2009,7 @@ fn root_can_change_default_xcm_vers() { moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), 100_000_000_000_000, Box::new(xcm::VersionedLocation::V4(dest)), - WeightLimit::Limited(4000000000.into()) + WeightLimit::Unlimited )); }) } @@ -2059,20 +2022,16 @@ fn transactor_cannot_use_more_than_max_weight() { (AccountId::from(BOB), 1_000 * UNIT), ]) .with_xcm_assets(vec![XcmAssetInitialization { - asset_type: AssetType::Xcm(xcm::v3::Location::parent()), - metadata: AssetRegistrarMetadata { - name: b"RelayToken".to_vec(), - symbol: b"Relay".to_vec(), - decimals: 12, - is_frozen: false, - }, + asset_id: 1, + xcm_location: xcm::v4::Location::parent(), + name: "RelayToken", + symbol: "Relay", + decimals: 12, balances: vec![(AccountId::from(ALICE), 1_000_000_000_000_000)], - is_sufficient: true, }]) .build() .execute_with(|| { - let source_location = AssetType::Xcm(xcm::v3::Location::parent()); - let source_id: moonbase_runtime::AssetId = source_location.clone().into(); + let source_id: moonbase_runtime::AssetId = 1; assert_ok!(XcmTransactor::register( root_origin(), AccountId::from(ALICE), @@ -2587,7 +2546,7 @@ fn precompile_existence() { let precompile_addresses: std::collections::BTreeSet<_> = vec![ 1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 1027, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, - 2068, 2069, 2070, 2071, 2072, 2073, 2074, + 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, ] .into_iter() .map(H160::from_low_u64_be) From cb652ca3f9f86c8249306cef5c2217c9a5d81ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 10:51:37 +0200 Subject: [PATCH 42/71] rustfmt --- runtime/moonbase/tests/integration_test.rs | 29 +++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 10c111f026..ee4267e3ce 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -39,11 +39,28 @@ use frame_support::{ use moonbase_runtime::{ //asset_config::ForeignAssetInstance, xcm_config::{AssetType, SelfReserve}, - AccountId, AssetId, Balances, CrowdloanRewards, EvmForeignAssets, Executive, - OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime, - RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, - TransactionPaymentAsGasPrice, TreasuryCouncilCollective, XTokens, XcmTransactor, - FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, WEEKS, + AccountId, + AssetId, + Balances, + CrowdloanRewards, + EvmForeignAssets, + Executive, + OpenTechCommitteeCollective, + ParachainStaking, + PolkadotXcm, + Precompiles, + Runtime, + RuntimeBlockWeights, + RuntimeCall, + RuntimeEvent, + System, + TransactionPayment, + TransactionPaymentAsGasPrice, + TreasuryCouncilCollective, + XTokens, + XcmTransactor, + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + WEEKS, }; use polkadot_parachain::primitives::Sibling; use precompile_utils::testing::MockHandle; @@ -2546,7 +2563,7 @@ fn precompile_existence() { let precompile_addresses: std::collections::BTreeSet<_> = vec![ 1, 2, 3, 4, 5, 6, 7, 8, 9, 256, 1024, 1025, 1026, 1027, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, - 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075 + 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, ] .into_iter() .map(H160::from_low_u64_be) From 51e42663dfbc941440e82c9838c07036cd0ffd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 11:08:56 +0200 Subject: [PATCH 43/71] fix copyright: new code should be own by MBF --- pallets/moonbeam-foreign-assets/build.rs | 16 ++++++++++++++++ .../moonbeam-foreign-assets/src/benchmarks.rs | 10 +++++----- pallets/moonbeam-foreign-assets/src/evm.rs | 2 +- pallets/moonbeam-foreign-assets/src/lib.rs | 10 +++++----- pallets/moonbeam-foreign-assets/src/mock.rs | 10 +++++----- pallets/moonbeam-foreign-assets/src/tests.rs | 11 ++++++----- pallets/moonbeam-foreign-assets/src/weights.rs | 11 +++++------ 7 files changed, 43 insertions(+), 27 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/build.rs b/pallets/moonbeam-foreign-assets/build.rs index e916918e96..b3bb0cc3a9 100644 --- a/pallets/moonbeam-foreign-assets/build.rs +++ b/pallets/moonbeam-foreign-assets/build.rs @@ -1,3 +1,19 @@ +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + use std::fs::File; use std::io::prelude::*; diff --git a/pallets/moonbeam-foreign-assets/src/benchmarks.rs b/pallets/moonbeam-foreign-assets/src/benchmarks.rs index 188aff1a65..59619b7ba9 100644 --- a/pallets/moonbeam-foreign-assets/src/benchmarks.rs +++ b/pallets/moonbeam-foreign-assets/src/benchmarks.rs @@ -1,18 +1,18 @@ -// Copyright Moonsong Labs -// This file is part of Moonkit. +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. -// Moonkit is free software: you can redistribute it and/or modify +// Moonbeam is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Moonkit is distributed in the hope that it will be useful, +// Moonbeam is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Moonkit. If not, see . +// along with Moonbeam. If not, see . #![cfg(feature = "runtime-benchmarks")] diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index a2e9ce1d10..582ea71c06 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -1,4 +1,4 @@ -// Copyright 2019-2022 PureStake Inc. +// Copyright 2024 Moonbeam Foundation. // This file is part of Moonbeam. // Moonbeam is free software: you can redistribute it and/or modify diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 32c855cf00..c210871087 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -1,18 +1,18 @@ -// Copyright Moonsong Labs -// This file is part of Moonkit. +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. -// Moonkit is free software: you can redistribute it and/or modify +// Moonbeam is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Moonkit is distributed in the hope that it will be useful, +// Moonbeam is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Moonkit. If not, see . +// along with Moonbeam. If not, see . //! # Moonbeam Foreign Assets pallet //! diff --git a/pallets/moonbeam-foreign-assets/src/mock.rs b/pallets/moonbeam-foreign-assets/src/mock.rs index efc186dd90..4f81769a24 100644 --- a/pallets/moonbeam-foreign-assets/src/mock.rs +++ b/pallets/moonbeam-foreign-assets/src/mock.rs @@ -1,18 +1,18 @@ -// Copyright Moonsong Labs -// This file is part of Moonkit. +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. -// Moonkit is free software: you can redistribute it and/or modify +// Moonbeam is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Moonkit is distributed in the hope that it will be useful, +// Moonbeam is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Moonkit. If not, see . +// along with Moonbeam. If not, see . use super::*; use crate as pallet_moonbeam_foreign_assets; diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index 99cb7362d1..fc29eece0d 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -1,18 +1,19 @@ -// Copyright Moonsong Labs -// This file is part of Moonkit. +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. -// Moonkit is free software: you can redistribute it and/or modify +// Moonbeam is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Moonkit is distributed in the hope that it will be useful, +// Moonbeam is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Moonkit. If not, see . +// along with Moonbeam. If not, see . + use crate::*; use mock::*; diff --git a/pallets/moonbeam-foreign-assets/src/weights.rs b/pallets/moonbeam-foreign-assets/src/weights.rs index ca385eac9d..d93d78a6ce 100644 --- a/pallets/moonbeam-foreign-assets/src/weights.rs +++ b/pallets/moonbeam-foreign-assets/src/weights.rs @@ -1,19 +1,18 @@ -// Copyright (C) Moondance Labs Ltd. -// This file is part of Tanssi. +// Copyright 2024 Moonbeam Foundation. +// This file is part of Moonbeam. -// Tanssi is free software: you can redistribute it and/or modify +// Moonbeam is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// Tanssi is distributed in the hope that it will be useful, +// Moonbeam is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License -// along with Tanssi. If not, see - +// along with Moonbeam. If not, see . //! Autogenerated weights for pallet_foreign_asset_creator //! From 93a9be811f41e160a3d5f323f45e322398f9ebc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 11:56:06 +0200 Subject: [PATCH 44/71] AssetsTransactors: for some reason Erc20XcmBridge should be at the end --- runtime/moonbase/src/xcm_config.rs | 2 +- runtime/moonbase/tests/integration_test.rs | 3 --- runtime/moonbeam/src/xcm_config.rs | 2 +- runtime/moonriver/src/xcm_config.rs | 2 +- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index d1c2817b0a..46f818a925 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -169,9 +169,9 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 pub type AssetTransactors = ( LocalAssetTransactor, - Erc20XcmBridge, EvmForeignAssets, ForeignFungiblesTransactor, + Erc20XcmBridge, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index ee4267e3ce..df7b0b559d 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -1514,7 +1514,6 @@ fn xcm_asset_erc20_precompiles_approve() { }*/ #[test] -#[ignore] fn xtokens_precompiles_transfer() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { @@ -1571,7 +1570,6 @@ fn xtokens_precompiles_transfer() { } #[test] -#[ignore] fn xtokens_precompiles_transfer_multiasset() { ExtBuilder::default() .with_xcm_assets(vec![XcmAssetInitialization { @@ -1975,7 +1973,6 @@ fn total_issuance_after_evm_transaction_without_priority_fee() { } #[test] -#[ignore] fn root_can_change_default_xcm_vers() { ExtBuilder::default() .with_balances(vec![ diff --git a/runtime/moonbeam/src/xcm_config.rs b/runtime/moonbeam/src/xcm_config.rs index c66cf2183f..b47942fa11 100644 --- a/runtime/moonbeam/src/xcm_config.rs +++ b/runtime/moonbeam/src/xcm_config.rs @@ -158,8 +158,8 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // We use all transactors pub type AssetTransactors = ( LocalAssetTransactor, - Erc20XcmBridge, ForeignFungiblesTransactor, + Erc20XcmBridge, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, diff --git a/runtime/moonriver/src/xcm_config.rs b/runtime/moonriver/src/xcm_config.rs index 44f4927ea1..5d959ffdc7 100644 --- a/runtime/moonriver/src/xcm_config.rs +++ b/runtime/moonriver/src/xcm_config.rs @@ -166,8 +166,8 @@ pub type LocalAssetTransactor = XcmCurrencyAdapter< // we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 pub type AssetTransactors = ( LocalAssetTransactor, - Erc20XcmBridge, ForeignFungiblesTransactor, + Erc20XcmBridge, ); /// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, From 1c0de2192f1f1b9d13515b6d6b426c7d9dec179c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 14:25:04 +0200 Subject: [PATCH 45/71] fix moonbase rust integration tests --- runtime/moonbase/tests/integration_test.rs | 98 +++++++++++++++++++++- 1 file changed, 94 insertions(+), 4 deletions(-) diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index df7b0b559d..4e96e54219 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -38,7 +38,7 @@ use frame_support::{ }; use moonbase_runtime::{ //asset_config::ForeignAssetInstance, - xcm_config::{AssetType, SelfReserve}, + xcm_config::SelfReserve, AccountId, AssetId, Balances, @@ -85,6 +85,8 @@ use parity_scale_codec::Encode; use sha3::{Digest, Keccak256}; use sp_core::{crypto::UncheckedFrom, ByteArray, Pair, H160, H256, U256}; use sp_runtime::{bounded_vec, DispatchError, ModuleError}; +use std::cell::Cell; +use std::rc::Rc; use xcm::latest::prelude::*; type AuthorMappingPCall = @@ -1534,7 +1536,7 @@ fn xtokens_precompiles_transfer() { let xtokens_precompile_address = H160::from_low_u64_be(2052); // We have the assetId that corresponds to the relay chain registered - let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + let relay_asset_id: AssetId = 1; // Its address is let asset_precompile_address = Runtime::asset_id_to_account( @@ -1551,6 +1553,10 @@ fn xtokens_precompiles_transfer() { }], ); + let inside = Rc::new(Cell::new(false)); + let inside2 = inside.clone(); + + // We use the address of the asset as an identifier of the asset we want to transfer Precompiles::new() .prepare_test( @@ -1563,8 +1569,47 @@ fn xtokens_precompiles_transfer() { weight: 4_000_000, }, ) - .expect_cost(57639) + .expect_cost(209239) .expect_no_logs() + // We expect an evm subcall ERC20.burnFrom + .with_subcall_handle(move |subcall| { + let Subcall { + address, + transfer, + input, + target_gas: _, + is_static, + context, + } = subcall; + + assert_eq!(context.caller, EvmForeignAssets::account_id().into()); + assert_eq!( + address, + [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].into() + ); + assert_eq!(is_static, false); + + assert!(transfer.is_none()); + + assert_eq!( + context.address, + [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].into() + ); + assert_eq!(context.apparent_value, 0u8.into()); + + assert_eq!(&input[..4], &keccak256!("burnFrom(address,uint256)")[..4]); + assert_eq!(&input[4..16], &[0u8; 12]); + assert_eq!(&input[16..36], ALICE); + + inside2.set(true); + + SubcallOutput { + output: Default::default(), + cost: 149_000, + logs: vec![], + ..SubcallOutput::succeed() + } + }) .execute_returns(()) }) } @@ -1598,6 +1643,9 @@ fn xtokens_precompiles_transfer_multiasset() { }], ); + let inside = Rc::new(Cell::new(false)); + let inside2 = inside.clone(); + // This time we transfer it through TransferMultiAsset // Instead of the address, we encode directly the multilocation referencing the asset Precompiles::new() @@ -1612,9 +1660,51 @@ fn xtokens_precompiles_transfer_multiasset() { weight: 4_000_000, }, ) - .expect_cost(57639) + .expect_cost(209239) .expect_no_logs() + // We expect an evm subcall ERC20.burnFrom + .with_subcall_handle(move |subcall| { + let Subcall { + address, + transfer, + input, + target_gas: _, + is_static, + context, + } = subcall; + + assert_eq!(context.caller, EvmForeignAssets::account_id().into()); + assert_eq!( + address, + [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].into() + ); + assert_eq!(is_static, false); + + assert!(transfer.is_none()); + + assert_eq!( + context.address, + [255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1].into() + ); + assert_eq!(context.apparent_value, 0u8.into()); + + assert_eq!(&input[..4], &keccak256!("burnFrom(address,uint256)")[..4]); + assert_eq!(&input[4..16], &[0u8; 12]); + assert_eq!(&input[16..36], ALICE); + + inside2.set(true); + + SubcallOutput { + output: Default::default(), + cost: 149_000, + logs: vec![], + ..SubcallOutput::succeed() + } + }) .execute_returns(()); + + // Ensure that the subcall was actually called. + assert!(inside.get(), "subcall not called"); }) } From c9281f99f12ce216d408a63bac074054e770c96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 17:00:08 +0200 Subject: [PATCH 46/71] allow FastGeneralAdmin & 5/9 techCommittee to manage evm foreign assets --- runtime/moonbase/src/xcm_config.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/runtime/moonbase/src/xcm_config.rs b/runtime/moonbase/src/xcm_config.rs index 46f818a925..a4559b2f0d 100644 --- a/runtime/moonbase/src/xcm_config.rs +++ b/runtime/moonbase/src/xcm_config.rs @@ -732,14 +732,22 @@ impl frame_support::traits::Contains for EvmForeignAssetIdFilter { } } +pub type ForeignAssetManagerOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::FastGeneralAdmin, + >, +>; + impl pallet_moonbeam_foreign_assets::Config for Runtime { type AccountIdToH160 = AccountIdToH160; type AssetIdFilter = EvmForeignAssetIdFilter; type EvmRunner = EvmRunnerPrecompileOrEthXcm; - type ForeignAssetCreatorOrigin = EnsureRoot; - type ForeignAssetFreezerOrigin = EnsureRoot; - type ForeignAssetModifierOrigin = EnsureRoot; - type ForeignAssetUnfreezerOrigin = EnsureRoot; + type ForeignAssetCreatorOrigin = ForeignAssetManagerOrigin; + type ForeignAssetFreezerOrigin = ForeignAssetManagerOrigin; + type ForeignAssetModifierOrigin = ForeignAssetManagerOrigin; + type ForeignAssetUnfreezerOrigin = ForeignAssetManagerOrigin; type OnForeignAssetCreated = (); type MaxForeignAssets = ConstU32<256>; type RuntimeEvent = RuntimeEvent; From 75afd92d952b37fc045fdf93894ebc3c00f1b4b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 17:00:28 +0200 Subject: [PATCH 47/71] rustfmt --- runtime/moonbase/tests/integration_test.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/moonbase/tests/integration_test.rs b/runtime/moonbase/tests/integration_test.rs index 4e96e54219..2619e2c7cf 100644 --- a/runtime/moonbase/tests/integration_test.rs +++ b/runtime/moonbase/tests/integration_test.rs @@ -1556,7 +1556,6 @@ fn xtokens_precompiles_transfer() { let inside = Rc::new(Cell::new(false)); let inside2 = inside.clone(); - // We use the address of the asset as an identifier of the asset we want to transfer Precompiles::new() .prepare_test( From 5ccb161f90c15a0ffd641e536b2407f12020deb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 17:40:38 +0200 Subject: [PATCH 48/71] rename some fns/events and remove unused code --- .../moonbeam-foreign-assets/src/benchmarks.rs | 2 +- pallets/moonbeam-foreign-assets/src/lib.rs | 29 ++++--------------- pallets/moonbeam-foreign-assets/src/tests.rs | 10 ++----- .../moonbeam-foreign-assets/src/weights.rs | 6 ++-- 4 files changed, 12 insertions(+), 35 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/src/benchmarks.rs b/pallets/moonbeam-foreign-assets/src/benchmarks.rs index 59619b7ba9..81024d2819 100644 --- a/pallets/moonbeam-foreign-assets/src/benchmarks.rs +++ b/pallets/moonbeam-foreign-assets/src/benchmarks.rs @@ -62,7 +62,7 @@ benchmarks! { } // Worst case scenario: MaxForeignAssets already exists - change_existing_asset_type { + change_xcm_location { create_n_foreign_asset::(T::MaxForeignAssets::get())?; }: _(RawOrigin::Root, 1, Location::here()) verify { diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index c210871087..9de7b16d00 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -73,15 +73,6 @@ impl ForeignAssetCreatedHook for () { fn on_asset_created(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} } -/// Trait for the OnForeignAssetDeregistered hook -pub trait ForeignAssetDestroyedHook { - fn on_asset_destroyed(foreign_asset: &ForeignAsset, asset_id: &AssetId); -} - -impl ForeignAssetDestroyedHook for () { - fn on_asset_destroyed(_foreign_asset: &ForeignAsset, _asset_id: &AssetId) {} -} - pub(crate) struct ForeignAssetsMatcher(core::marker::PhantomData); impl ForeignAssetsMatcher { @@ -181,7 +172,7 @@ pub mod pallet { AssetIdFiltered, AssetNotFrozen, CorruptedStorageOrphanLocation, - Erc20ContractCallFail, + //Erc20ContractCallFail, Erc20ContractCreationFail, EvmCallPauseFail, EvmCallUnpauseFail, @@ -202,15 +193,10 @@ pub mod pallet { xcm_location: Location, }, /// Changed the xcm type mapping for a given asset id - ForeignAssetTypeChanged { + ForeignAssetXcmLocationChanged { asset_id: AssetId, new_xcm_location: Location, }, - /// Removed all information related to an assetId - ForeignAssetRemoved { - asset_id: AssetId, - xcm_location: Location, - }, // Freezes all tokens of a given asset id ForeignAssetFrozen { asset_id: AssetId, @@ -221,11 +207,6 @@ pub mod pallet { asset_id: AssetId, xcm_location: Location, }, - /// Removed all information related to an assetId and destroyed asset - ForeignAssetDestroyed { - asset_id: AssetId, - xcm_location: Location, - }, } /// Mapping from an asset id to a Foreign asset type. @@ -340,8 +321,8 @@ pub mod pallet { /// We also change this if the previous units per second where pointing at the old /// assetType #[pallet::call_index(1)] - #[pallet::weight(::WeightInfo::change_existing_asset_type())] - pub fn change_existing_asset_type( + #[pallet::weight(::WeightInfo::change_xcm_location())] + pub fn change_xcm_location( origin: OriginFor, asset_id: AssetId, new_xcm_location: Location, @@ -359,7 +340,7 @@ pub mod pallet { AssetsById::::insert(&asset_id, &new_xcm_location); AssetsByLocation::::insert(&new_xcm_location, (asset_id, asset_status)); - Self::deposit_event(Event::ForeignAssetTypeChanged { + Self::deposit_event(Event::ForeignAssetXcmLocationChanged { asset_id, new_xcm_location, }); diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index fc29eece0d..486f722953 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -147,7 +147,7 @@ fn test_regular_user_cannot_call_extrinsics() { ); assert_noop!( - EvmForeignAssets::change_existing_asset_type( + EvmForeignAssets::change_xcm_location( RuntimeOrigin::signed(Bob.into()), 1, Location::parent() @@ -169,7 +169,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() { encode_token_name("Mytoken"), )); - assert_ok!(EvmForeignAssets::change_existing_asset_type( + assert_ok!(EvmForeignAssets::change_xcm_location( RuntimeOrigin::root(), 1, Location::here() @@ -205,11 +205,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() { fn test_asset_id_non_existent_error() { ExtBuilder::default().build().execute_with(|| { assert_noop!( - EvmForeignAssets::change_existing_asset_type( - RuntimeOrigin::root(), - 1, - Location::parent() - ), + EvmForeignAssets::change_xcm_location(RuntimeOrigin::root(), 1, Location::parent()), Error::::AssetDoesNotExist ); }); diff --git a/pallets/moonbeam-foreign-assets/src/weights.rs b/pallets/moonbeam-foreign-assets/src/weights.rs index d93d78a6ce..8b270fa1c5 100644 --- a/pallets/moonbeam-foreign-assets/src/weights.rs +++ b/pallets/moonbeam-foreign-assets/src/weights.rs @@ -52,7 +52,7 @@ use sp_std::marker::PhantomData; /// Weight functions needed for pallet_foreign_asset_creator. pub trait WeightInfo { fn create_foreign_asset() -> Weight; - fn change_existing_asset_type() -> Weight; + fn change_xcm_location() -> Weight; fn freeze_foreign_asset() -> Weight; fn unfreeze_foreign_asset() -> Weight; } @@ -79,7 +79,7 @@ impl WeightInfo for SubstrateWeight { /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:2) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn change_existing_asset_type() -> Weight { + fn change_xcm_location() -> Weight { // Proof Size summary in bytes: // Measured: `189` // Estimated: `3654` @@ -139,7 +139,7 @@ impl WeightInfo for () { /// Proof: `ForeignAssetsCreator::AssetIdToForeignAsset` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ForeignAssetsCreator::ForeignAssetToAssetId` (r:0 w:2) /// Proof: `ForeignAssetsCreator::ForeignAssetToAssetId` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn change_existing_asset_type() -> Weight { + fn change_xcm_location() -> Weight { // Proof Size summary in bytes: // Measured: `189` // Estimated: `3654` From a37843e8c88cd9197dae971aae80a2aafd1c8477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Mon, 22 Jul 2024 17:46:17 +0200 Subject: [PATCH 49/71] ticker -> symbol --- .../resources/foreign_erc20.sol | 24 ++++++++----------- pallets/moonbeam-foreign-assets/src/evm.rs | 6 ++--- pallets/moonbeam-foreign-assets/src/lib.rs | 6 ++--- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol index 6ed355a974..307392cb6a 100644 --- a/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol +++ b/pallets/moonbeam-foreign-assets/resources/foreign_erc20.sol @@ -12,9 +12,9 @@ contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { constructor( address initialOwner, uint8 tokenDecimals, - string memory ticker, + string memory symbol, string memory tokenName - ) ERC20(tokenName, ticker) Ownable(initialOwner) ERC20Permit(tokenName) { + ) ERC20(tokenName, symbol) Ownable(initialOwner) ERC20Permit(tokenName) { _decimals = tokenDecimals; } @@ -46,23 +46,19 @@ contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { // override ERC20 methods that should be disabled when the asset is "paused" - function approve(address spender, uint256 value) - public - override(ERC20) - whenNotPaused - returns (bool) - { + function approve( + address spender, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { address owner = _msgSender(); _approve(owner, spender, value); return true; } - function transfer(address to, uint256 value) - public - override(ERC20) - whenNotPaused - returns (bool) - { + function transfer( + address to, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { address owner = _msgSender(); _transfer(owner, to, value); return true; diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 582ea71c06..6d41e77cf4 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -84,7 +84,7 @@ impl From for XcmError { struct ForeignErc20ConstructorArgs { owner: Address, decimals: u8, - ticker: BoundedString>, + symbol: BoundedString>, token_name: BoundedString>, } @@ -95,7 +95,7 @@ impl EvmCaller { pub(crate) fn erc20_create( asset_id: AssetId, decimals: u8, - ticker: &str, + symbol: &str, token_name: &str, ) -> Result> { // Get init code @@ -106,7 +106,7 @@ impl EvmCaller { let args = ForeignErc20ConstructorArgs { owner: Pallet::::account_id().into(), decimals, - ticker: ticker.into(), + symbol: symbol.into(), token_name: token_name.into(), }; let encoded_args = precompile_utils::solidity::codec::Writer::new() diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 9de7b16d00..90539353e4 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -271,7 +271,7 @@ pub mod pallet { asset_id: AssetId, xcm_location: Location, decimals: u8, - ticker: BoundedVec>, + symbol: BoundedVec>, name: BoundedVec>, ) -> DispatchResult { T::ForeignAssetCreatorOrigin::ensure_origin(origin)?; @@ -297,10 +297,10 @@ pub mod pallet { Error::::AssetIdFiltered ); - let ticker = core::str::from_utf8(&ticker).map_err(|_| Error::::InvalidTicker)?; + let symbol = core::str::from_utf8(&symbol).map_err(|_| Error::::InvalidTicker)?; let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; - let contract_address = EvmCaller::::erc20_create(asset_id, decimals, ticker, name)?; + let contract_address = EvmCaller::::erc20_create(asset_id, decimals, symbol, name)?; // Insert the association assetId->foreigAsset // Insert the association foreigAsset->assetId From ce19a3e791469990cbd13e696609a9a1450d8439 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Mon, 22 Jul 2024 21:28:57 +0200 Subject: [PATCH 50/71] change base implementation of registerForeignAsset() --- test/helpers/assets.ts | 23 +++++--------- test/helpers/xcm.ts | 69 ++++++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 21885f409f..eca1864ba8 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -6,6 +6,7 @@ import { blake2AsU8a, xxhashAsU8a } from "@polkadot/util-crypto"; import { KeyringPair } from "@polkadot/keyring/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; +import { registerForeignAsset } from "./xcm"; export const DUMMY_REVERT_BYTECODE = "0x60006000fd"; export const RELAY_SOURCE_LOCATION = { Xcm: { parents: 1, interior: "Here" } }; @@ -22,6 +23,7 @@ export const PARA_1001_SOURCE_LOCATION = { }; export interface AssetMetadata { + id: u128; name: string; symbol: string; decimals: bigint; @@ -29,6 +31,7 @@ export interface AssetMetadata { } export const relayAssetMetadata: AssetMetadata = { + id: 1n, name: "DOT", symbol: "DOT", decimals: 12n, @@ -41,23 +44,11 @@ export async function mockAssetBalance( assetDetails: PalletAssetsAssetDetails, sudoAccount: KeyringPair, assetId: u128, - account: string | AccountId20, - is_sufficient = false + account: string | AccountId20 ) { const api = context.polkadotJs(); // Register the asset - await context.createBlock( - api.tx.sudo - .sudo( - api.tx.assetManager.registerForeignAsset( - RELAY_SOURCE_LOCATION, - relayAssetMetadata, - new BN(1), - is_sufficient - ) - ) - .signAsync(sudoAccount) - ); + registerForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata); const assets = await api.query.assetManager.assetIdType(assetId); // make sure we created it @@ -91,8 +82,8 @@ export async function mockAssetBalance( api.tx.sudo .sudo( api.tx.system.setStorage([ - [u8aToHex(overallAccountKey), u8aToHex(assetBalance.toU8a())], - [u8aToHex(overallAssetKey), u8aToHex(assetDetails.toU8a())], + [u8aToHex(overallAccountKey), u8aToHex((assetBalance as any).toU8a())], + [u8aToHex(overallAssetKey), u8aToHex((assetBalance as any).toU8a())], [ evmCodeAssetKey, `0x${((DUMMY_REVERT_BYTECODE.length - 2) * 2) diff --git a/test/helpers/xcm.ts b/test/helpers/xcm.ts index 63675960f2..ad18a8f901 100644 --- a/test/helpers/xcm.ts +++ b/test/helpers/xcm.ts @@ -1,6 +1,7 @@ -import { DevModeContext, customDevRpcRequest } from "@moonwall/cli"; +import { DevModeContext, customDevRpcRequest, fetchCompiledContract } from "@moonwall/cli"; import { ALITH_ADDRESS } from "@moonwall/util"; -import { AssetMetadata, XcmpMessageFormat } from "@polkadot/types/interfaces"; +import { u128 } from "@polkadot/types"; +import { XcmpMessageFormat } from "@polkadot/types/interfaces"; import { CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, XcmV3JunctionNetworkId, @@ -8,7 +9,8 @@ import { } from "@polkadot/types/lookup"; import { BN, stringToU8a, u8aToHex } from "@polkadot/util"; import { xxhashAsU8a } from "@polkadot/util-crypto"; -import { RELAY_V3_SOURCE_LOCATION } from "./assets.js"; +import { AssetMetadata, RELAY_V3_SOURCE_LOCATION } from "./assets.js"; +import { ethers } from "ethers"; // Creates and returns the tx that overrides the paraHRMP existence // This needs to be inserted at every block in which you are willing to test @@ -75,46 +77,47 @@ export function mockHrmpChannelExistanceTx( export async function registerForeignAsset( context: DevModeContext, asset: any, - metadata: AssetMetadata, - unitsPerSecond?: number, - numAssetsWeightHint?: number + assetMetadata: AssetMetadata ) { - unitsPerSecond = unitsPerSecond != null ? unitsPerSecond : 0; + const { id, decimals, name, symbol } = assetMetadata; const { result } = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo( - context.polkadotJs().tx.assetManager.registerForeignAsset(asset, metadata, new BN(1), true) - ) - ); - // Look for assetId in events - const registeredAssetId = result!.events - .find(({ event: { section } }) => section.toString() === "assetManager")! - .event.data[0].toHex() - .replace(/,/g, ""); - - // setAssetUnitsPerSecond - const { result: result2 } = await context.createBlock( context .polkadotJs() .tx.sudo.sudo( context .polkadotJs() - .tx.assetManager.setAssetUnitsPerSecond(asset, unitsPerSecond, numAssetsWeightHint!) - ), - { - expectEvents: [context.polkadotJs().events.assetManager.UnitsPerSecondChanged], - allowFailures: false, - } + .tx.evmForeignAssets.createForeignAsset(id, asset, decimals, symbol, name) + ) ); - // check asset in storage - const registeredAsset = ( - (await context.polkadotJs().query.assets.asset(registeredAssetId)) as any - ).unwrap(); + + // Fetch asset id and contract address in the events + const event = (result as any).events.find( + ({ event: { method } }) => method.toString() === "ForeignAssetCreated" + )!.event; + + const contractAddress: string = event.data[0]; + const registeredAssetId: u128 = event.data[1].toString(); + + // New foreign assets design doesn't allow for new assets to pay fees. + // We can reenable this code when that is possible (probably with XCM v5). + // const { result: result2 } = await context.createBlock( + // context + // .polkadotJs() + // .tx.sudo.sudo( + // context + // .polkadotJs() + // .tx.assetManager.setAssetUnitsPerSecond(asset, unitsPerSecond, numAssetsWeightHint!) + // ), + // { + // expectEvents: [context.polkadotJs().events.assetManager.UnitsPerSecondChanged], + // allowFailures: false, + // } + // ); + return { registeredAssetId, - events: result2!.events, - registeredAsset, + contractAddress, + events: (result as any).events || [], }; } From 42085663971e12f102374c00461955a9811ef9e7 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Mon, 22 Jul 2024 21:30:07 +0200 Subject: [PATCH 51/71] re-arrange tests in test-assets (WIP) --- .../test-assets/test-assets-insufficients.ts | 10 +-- ...e-asset.ts => test-assets-remove-asset.ts} | 0 .../test-assets/test-change-existing-asset.ts | 73 ------------------ .../test-assets/test-destroy-foreign-asset.ts | 75 ------------------- .../test-assets/test-foreign-asset.ts | 34 --------- .../test-foreign-assets-change-asset-type.ts | 60 +++++++++++++++ .../test-assets/test-foreign-assets-create.ts | 56 ++++++++++++++ 7 files changed, 117 insertions(+), 191 deletions(-) rename test/suites/dev/moonbase/test-assets/{test-remove-asset.ts => test-assets-remove-asset.ts} (100%) delete mode 100644 test/suites/dev/moonbase/test-assets/test-change-existing-asset.ts delete mode 100644 test/suites/dev/moonbase/test-assets/test-destroy-foreign-asset.ts delete mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-asset.ts create mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts create mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts diff --git a/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts b/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts index 4381fa0e61..359092ed31 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts @@ -35,15 +35,7 @@ describeSuite({ minBalance: 1, }); - await mockAssetBalance( - context, - assetBalance, - assetDetails, - alith, - assetId, - ALITH_ADDRESS, - false - ); + await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); await context.createBlock(); const alithBalance = await api.query.assets.account(assetId.toU8a(), ALITH_ADDRESS); diff --git a/test/suites/dev/moonbase/test-assets/test-remove-asset.ts b/test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts similarity index 100% rename from test/suites/dev/moonbase/test-assets/test-remove-asset.ts rename to test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts diff --git a/test/suites/dev/moonbase/test-assets/test-change-existing-asset.ts b/test/suites/dev/moonbase/test-assets/test-change-existing-asset.ts deleted file mode 100644 index 7c9746e0b0..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-change-existing-asset.ts +++ /dev/null @@ -1,73 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; -import { BN, bnToHex } from "@polkadot/util"; -import { - PARA_1000_SOURCE_LOCATION, - RELAY_SOURCE_LOCATION, - registerForeignAsset, - relayAssetMetadata, - verifyLatestBlockFees, -} from "../../../../helpers"; - -const palletId = "0x6D6f646c617373746d6E67720000000000000000"; -describeSuite({ - id: "D010106", - title: "XCM - asset manager - Change existing asset", - foundationMethods: "dev", - testCases: ({ context, log, it }) => { - let assetId: string; - let api: ApiPromise; - beforeAll(async function () { - api = context.polkadotJs(); - const { registeredAssetId, events, registeredAsset } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION, - relayAssetMetadata as any, - 1 - ); - assetId = registeredAssetId; - expect(events[1].event.method.toString()).to.eq("UnitsPerSecondChanged"); - expect(events[5].event.method.toString()).to.eq("ExtrinsicSuccess"); - expect(registeredAsset.owner.toString()).to.eq(palletId); - - await verifyLatestBlockFees(context); - }); - - it({ - id: "T01", - title: "should change the asset Id", - test: async function () { - // ChangeAssetType - await context.createBlock( - api.tx.sudo.sudo( - api.tx.assetManager.changeExistingAssetType(assetId, PARA_1000_SOURCE_LOCATION, 1) - ) - ); - - // asset_type - const assetType = (await context - .polkadotJs() - .query.assetManager.assetIdType(assetId)) as object; - - // assetId - const id = (await api.query.assetManager.assetTypeId(PARA_1000_SOURCE_LOCATION)).unwrap(); - - // asset units per second changed - const assetUnitsPerSecond = ( - await api.query.assetManager.assetTypeUnitsPerSecond(PARA_1000_SOURCE_LOCATION) - ).unwrap(); - - // Supported assets - const supportedAssets = await api.query.assetManager.supportedFeePaymentAssets(); - - expect(assetUnitsPerSecond.toString()).to.eq(new BN(1).toString()); - expect(assetType.toString()).to.eq(JSON.stringify(PARA_1000_SOURCE_LOCATION).toLowerCase()); - expect(bnToHex(id)).to.eq(assetId); - expect(supportedAssets[0].toString()).to.eq( - JSON.stringify(PARA_1000_SOURCE_LOCATION).toLowerCase() - ); - }, - }); - }, -}); diff --git a/test/suites/dev/moonbase/test-assets/test-destroy-foreign-asset.ts b/test/suites/dev/moonbase/test-assets/test-destroy-foreign-asset.ts deleted file mode 100644 index d1ca7d51a5..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-destroy-foreign-asset.ts +++ /dev/null @@ -1,75 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; -import { - RELAY_SOURCE_LOCATION, - expectOk, - registerForeignAsset, - relayAssetMetadata, - verifyLatestBlockFees, -} from "../../../../helpers"; - -const palletId = "0x6D6f646c617373746d6E67720000000000000000"; - -describeSuite({ - id: "D010107", - title: "XCM - asset manager - destroy foreign asset", - foundationMethods: "dev", - testCases: ({ context, it, log }) => { - let assetId: string; - let api: ApiPromise; - beforeAll(async function () { - api = context.polkadotJs(); - // registerForeignAsset - const { registeredAssetId, events, registeredAsset } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION, - relayAssetMetadata as any, - 1 - ); - assetId = registeredAssetId; - expect(events[1].event.method.toString()).to.eq("UnitsPerSecondChanged"); - expect(events[5].event.method.toString()).to.eq("ExtrinsicSuccess"); - expect(registeredAsset.owner.toString()).to.eq(palletId); - - await verifyLatestBlockFees(context); - }); - - it({ - id: "T01", - title: "should be able to destroy a foreign asset through pallet-asset-manager", - test: async function () { - // Destroy foreign asset - await expectOk( - context.createBlock( - api.tx.sudo.sudo((api.tx.assetManager as any).destroyForeignAsset(assetId, 1)) - ) - ); - - await expectOk(context.createBlock(api.tx.assets.destroyAccounts(assetId))); - await expectOk(context.createBlock(api.tx.assets.destroyApprovals(assetId))); - await expectOk(context.createBlock(api.tx.assets.finishDestroy(assetId))); - - // assetId - const id = await api.query.assetManager.assetTypeId(RELAY_SOURCE_LOCATION); - - // asset units per second removed - const assetUnitsPerSecond = await api.query.assetManager.assetTypeUnitsPerSecond( - RELAY_SOURCE_LOCATION - ); - - // Supported assets should be 0 - const supportedAssets = await api.query.assetManager.supportedFeePaymentAssets(); - - // assetDetails should have dissapeared - const assetDetails = await api.query.assets.asset(assetId); - - expect(assetUnitsPerSecond.isNone).to.eq(true); - expect(id.isNone).to.eq(true); - expect(assetDetails.isNone).to.eq(true); - // the asset should not be supported - expect(supportedAssets.length).to.eq(0); - }, - }); - }, -}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-asset.ts b/test/suites/dev/moonbase/test-assets/test-foreign-asset.ts deleted file mode 100644 index 6df566489f..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-foreign-asset.ts +++ /dev/null @@ -1,34 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { describeSuite, expect } from "@moonwall/cli"; -import { - RELAY_SOURCE_LOCATION2, - relayAssetMetadata, - registerForeignAsset, - verifyLatestBlockFees, -} from "../../../../helpers"; - -const palletId = "0x6D6f646c617373746d6E67720000000000000000"; - -describeSuite({ - id: "D010108", - title: "XCM - asset manager - foreign asset", - foundationMethods: "dev", - testCases: ({ context, it, log }) => { - it({ - id: "T01", - title: "should be registerable and have unit per seconds set", - test: async function () { - const { events, registeredAsset } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION2, - relayAssetMetadata as any - ); - - expect(events[1].event.method.toString()).to.eq("UnitsPerSecondChanged"); - expect(events[5].event.method.toString()).to.eq("ExtrinsicSuccess"); - expect(registeredAsset.owner.toString()).to.eq(palletId); - await verifyLatestBlockFees(context); - }, - }); - }, -}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts new file mode 100644 index 0000000000..48d12cdc52 --- /dev/null +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts @@ -0,0 +1,60 @@ +import "@moonbeam-network/api-augment"; +import { beforeAll, describeSuite, expect } from "@moonwall/cli"; +import { ApiPromise } from "@polkadot/api"; +import { BN, bnToHex } from "@polkadot/util"; +import { + PARA_1000_SOURCE_LOCATION, + RELAY_SOURCE_LOCATION, + registerForeignAsset, + relayAssetMetadata, + verifyLatestBlockFees, +} from "../../../../helpers"; +import { u128 } from "@polkadot/types-codec"; +import { StagingXcmV4Location } from "@polkadot/types/lookup"; + +describeSuite({ + id: "D010106", + title: "XCM - asset manager - Change existing asset", + foundationMethods: "dev", + testCases: ({ context, log, it }) => { + let assetId: u128; + let api: ApiPromise; + beforeAll(async function () { + api = context.polkadotJs(); + const { registeredAssetId, events } = await registerForeignAsset( + context, + RELAY_SOURCE_LOCATION, + relayAssetMetadata as any + ); + assetId = registeredAssetId; + + await verifyLatestBlockFees(context); + }); + + it({ + id: "T01", + title: "should change the asset type", + test: async function () { + // ChangeAssetType + const { result } = await context.createBlock( + api.tx.sudo.sudo( + api.tx.evmForeignAssets.changeExistingAssetType(assetId, PARA_1000_SOURCE_LOCATION) + ) + ); + + const assetTypeChangedEvent = (result as any).events.find( + ({ event: { method } }) => method.toString() === "ForeignAssetTypeChanged" + )!.event; + + // asset_type + const assetType = assetTypeChangedEvent.data[1]; + + // assetId + const id: u128 = assetTypeChangedEvent.data[0]; + + expect(assetType.toString()).to.eq(JSON.stringify(PARA_1000_SOURCE_LOCATION).toLowerCase()); + expect(id).to.eq(assetId); + }, + }); + }, +}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts new file mode 100644 index 0000000000..ac5320c648 --- /dev/null +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -0,0 +1,56 @@ +import "@moonbeam-network/api-augment"; +import { describeSuite, expect } from "@moonwall/cli"; +import { + RELAY_SOURCE_LOCATION, + relayAssetMetadata, + registerForeignAsset, +} from "../../../../helpers"; + +describeSuite({ + id: "D010108", + title: "XCM - Create new foreign asset", + foundationMethods: "dev", + testCases: ({ context, it, log }) => { + it({ + id: "T01", + title: "should deploy the asset's contract", + test: async function () { + const { registeredAssetId, contractAddress, events } = await registerForeignAsset( + context, + RELAY_SOURCE_LOCATION, + relayAssetMetadata as any + ); + + expect(contractAddress).toBeDefined(); + expect(registeredAssetId).eq("1"); + + expect( + await context.readContract!({ + contractName: "MyToken", + contractAddress: contractAddress as `0x${string}`, + functionName: "name", + args: [], + }) + ).toBe("DOT"); + + expect( + await context.readContract!({ + contractName: "MyToken", + contractAddress: contractAddress as `0x${string}`, + functionName: "symbol", + args: [], + }) + ).toBe("DOT"); + + expect( + await context.readContract!({ + contractName: "MyToken", + contractAddress: contractAddress as `0x${string}`, + functionName: "decimals", + args: [], + }) + ).toBe(12); + }, + }); + }, +}); From 1b8bf022420703f9f83e08e78737af9bad38506a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 23 Jul 2024 10:26:23 +0200 Subject: [PATCH 52/71] review suggestions --- pallets/ethereum-xcm/src/lib.rs | 4 ++-- pallets/moonbeam-foreign-assets/src/evm.rs | 2 -- pallets/moonbeam-foreign-assets/src/lib.rs | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pallets/ethereum-xcm/src/lib.rs b/pallets/ethereum-xcm/src/lib.rs index 67b971e4c9..a5369b440f 100644 --- a/pallets/ethereum-xcm/src/lib.rs +++ b/pallets/ethereum-xcm/src/lib.rs @@ -104,7 +104,7 @@ pub mod pallet { type EnsureProxy: EnsureProxy; /// The origin that is allowed to resume or suspend the XCM to Ethereum executions. type ControllerOrigin: EnsureOrigin; - /// An origin that can submit a create tx typenb + /// An origin that can submit a create tx type type ForceOrigin: EnsureOrigin; } @@ -241,7 +241,7 @@ pub mod pallet { EthereumXcmTransaction::V1(v1_tx) => v1_tx.gas_limit.unique_saturated_into(), EthereumXcmTransaction::V2(v2_tx) => v2_tx.gas_limit.unique_saturated_into() } - }, without_base_extrinsic_weight).saturating_add(T::DbWeight::get().reads(2)) + }, without_base_extrinsic_weight).saturating_add(T::DbWeight::get().reads(1)) })] pub fn force_transact_as( origin: OriginFor, diff --git a/pallets/moonbeam-foreign-assets/src/evm.rs b/pallets/moonbeam-foreign-assets/src/evm.rs index 6d41e77cf4..35b9434583 100644 --- a/pallets/moonbeam-foreign-assets/src/evm.rs +++ b/pallets/moonbeam-foreign-assets/src/evm.rs @@ -135,8 +135,6 @@ impl EvmCaller { ) .map_err(|_| Error::Erc20ContractCreationFail)?; - //println!("exec_info: {:?}", &exec_info); - ensure!( matches!( exec_info.exit_reason, diff --git a/pallets/moonbeam-foreign-assets/src/lib.rs b/pallets/moonbeam-foreign-assets/src/lib.rs index 90539353e4..14d3f6da91 100644 --- a/pallets/moonbeam-foreign-assets/src/lib.rs +++ b/pallets/moonbeam-foreign-assets/src/lib.rs @@ -177,7 +177,7 @@ pub mod pallet { EvmCallPauseFail, EvmCallUnpauseFail, EvmInternalError, - InvalidTicker, + InvalidSymbol, InvalidTokenName, LocationAlreadyExists, TooManyForeignAssets, @@ -297,7 +297,7 @@ pub mod pallet { Error::::AssetIdFiltered ); - let symbol = core::str::from_utf8(&symbol).map_err(|_| Error::::InvalidTicker)?; + let symbol = core::str::from_utf8(&symbol).map_err(|_| Error::::InvalidSymbol)?; let name = core::str::from_utf8(&name).map_err(|_| Error::::InvalidTokenName)?; let contract_address = EvmCaller::::erc20_create(asset_id, decimals, symbol, name)?; From 4a6a0f4626cabb82f373d89a8f3c27862fe4965b Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Tue, 23 Jul 2024 18:21:38 +0200 Subject: [PATCH 53/71] create v4 locations for foreign assets testing --- test/helpers/assets.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index eca1864ba8..4daa5f348f 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -13,7 +13,7 @@ export const RELAY_SOURCE_LOCATION = { Xcm: { parents: 1, interior: "Here" } }; export const RELAY_SOURCE_LOCATION2 = { Xcm: { parents: 2, interior: "Here" } }; export const RELAY_V3_SOURCE_LOCATION = { V3: { parents: 1, interior: "Here" } } as any; export const PARA_1000_SOURCE_LOCATION = { - Xcm: { parents: 1, interior: { X1: { Parachain: 1000 } } }, + Xcm: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }, }; export const PARA_2000_SOURCE_LOCATION = { Xcm: { parents: 1, interior: { X1: { Parachain: 2000 } } }, @@ -22,8 +22,13 @@ export const PARA_1001_SOURCE_LOCATION = { Xcm: { parents: 1, interior: { X1: { Parachain: 1001 } } }, }; +// XCM V4 Locations +export const RELAY_SOURCE_LOCATION_V4 = { Xcm: { parents: 1, interior: { here: null } } }; +export const PARA_1000_SOURCE_LOCATION_V4 = { + Xcm: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }, +}; export interface AssetMetadata { - id: u128; + id: bigint; name: string; symbol: string; decimals: bigint; From 8b98b31ba115b3e299179426689feb2b312a5b1c Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Tue, 23 Jul 2024 18:22:14 +0200 Subject: [PATCH 54/71] basic testing for evm foreign assets pallet --- test/helpers/xcm.ts | 15 +++-- .../test-foreign-assets-change-asset-type.ts | 60 ------------------- ...test-foreign-assets-change-xcm-location.ts | 55 +++++++++++++++++ .../test-assets/test-foreign-assets-create.ts | 22 ++++--- 4 files changed, 78 insertions(+), 74 deletions(-) delete mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts create mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts diff --git a/test/helpers/xcm.ts b/test/helpers/xcm.ts index ad18a8f901..517bbc9c9d 100644 --- a/test/helpers/xcm.ts +++ b/test/helpers/xcm.ts @@ -4,6 +4,7 @@ import { u128 } from "@polkadot/types"; import { XcmpMessageFormat } from "@polkadot/types/interfaces"; import { CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, + StagingXcmV4Location, XcmV3JunctionNetworkId, XcmVersionedXcm, } from "@polkadot/types/lookup"; @@ -76,17 +77,17 @@ export function mockHrmpChannelExistanceTx( export async function registerForeignAsset( context: DevModeContext, - asset: any, - assetMetadata: AssetMetadata + xcmLocation: any, + metadata: AssetMetadata ) { - const { id, decimals, name, symbol } = assetMetadata; + const { id, decimals, name, symbol } = metadata; const { result } = await context.createBlock( context .polkadotJs() .tx.sudo.sudo( context .polkadotJs() - .tx.evmForeignAssets.createForeignAsset(id, asset, decimals, symbol, name) + .tx.evmForeignAssets.createForeignAsset(id, xcmLocation, decimals, symbol, name) ) ); @@ -95,8 +96,9 @@ export async function registerForeignAsset( ({ event: { method } }) => method.toString() === "ForeignAssetCreated" )!.event; - const contractAddress: string = event.data[0]; - const registeredAssetId: u128 = event.data[1].toString(); + const contractAddress = event.data[0].toHuman().toString(); + const registeredAssetLocation = event.data[2].toString(); + const registeredAssetId = event.data[1].toString(); // New foreign assets design doesn't allow for new assets to pay fees. // We can reenable this code when that is possible (probably with XCM v5). @@ -117,6 +119,7 @@ export async function registerForeignAsset( return { registeredAssetId, contractAddress, + registeredAssetLocation, events: (result as any).events || [], }; } diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts deleted file mode 100644 index 48d12cdc52..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-asset-type.ts +++ /dev/null @@ -1,60 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { ApiPromise } from "@polkadot/api"; -import { BN, bnToHex } from "@polkadot/util"; -import { - PARA_1000_SOURCE_LOCATION, - RELAY_SOURCE_LOCATION, - registerForeignAsset, - relayAssetMetadata, - verifyLatestBlockFees, -} from "../../../../helpers"; -import { u128 } from "@polkadot/types-codec"; -import { StagingXcmV4Location } from "@polkadot/types/lookup"; - -describeSuite({ - id: "D010106", - title: "XCM - asset manager - Change existing asset", - foundationMethods: "dev", - testCases: ({ context, log, it }) => { - let assetId: u128; - let api: ApiPromise; - beforeAll(async function () { - api = context.polkadotJs(); - const { registeredAssetId, events } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION, - relayAssetMetadata as any - ); - assetId = registeredAssetId; - - await verifyLatestBlockFees(context); - }); - - it({ - id: "T01", - title: "should change the asset type", - test: async function () { - // ChangeAssetType - const { result } = await context.createBlock( - api.tx.sudo.sudo( - api.tx.evmForeignAssets.changeExistingAssetType(assetId, PARA_1000_SOURCE_LOCATION) - ) - ); - - const assetTypeChangedEvent = (result as any).events.find( - ({ event: { method } }) => method.toString() === "ForeignAssetTypeChanged" - )!.event; - - // asset_type - const assetType = assetTypeChangedEvent.data[1]; - - // assetId - const id: u128 = assetTypeChangedEvent.data[0]; - - expect(assetType.toString()).to.eq(JSON.stringify(PARA_1000_SOURCE_LOCATION).toLowerCase()); - expect(id).to.eq(assetId); - }, - }); - }, -}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts new file mode 100644 index 0000000000..1d622e35c5 --- /dev/null +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts @@ -0,0 +1,55 @@ +import "@moonbeam-network/api-augment"; +import { beforeAll, describeSuite, expect } from "@moonwall/cli"; +import { ApiPromise } from "@polkadot/api"; +import { + PARA_1000_SOURCE_LOCATION, + RELAY_SOURCE_LOCATION_V4, + registerForeignAsset, + relayAssetMetadata, + verifyLatestBlockFees, +} from "../../../../helpers"; + +describeSuite({ + id: "D010106", + title: "XCM - Change existing asset's XCM location", + foundationMethods: "dev", + testCases: ({ context, log, it }) => { + let assetId: bigint; + let api: ApiPromise; + beforeAll(async function () { + api = context.polkadotJs(); + const { registeredAssetId } = await registerForeignAsset( + context, + RELAY_SOURCE_LOCATION_V4, + relayAssetMetadata as any + ); + assetId = registeredAssetId; + + await verifyLatestBlockFees(context); + }); + + it({ + id: "T01", + title: "should change the asset location", + test: async function () { + const { result } = await context.createBlock( + api.tx.sudo.sudo( + api.tx.evmForeignAssets.changeXcmLocation(assetId, PARA_1000_SOURCE_LOCATION.Xcm) + ) + ); + + const locationChangeEvent = (result as any).events.find( + ({ event: { method } }) => method.toString() === "ForeignAssetXcmLocationChanged" + ).event; + + const newLocation = locationChangeEvent.data[1]; + const id = locationChangeEvent.data[0]; + + expect(JSON.stringify(newLocation).toLowerCase()).to.eq( + JSON.stringify(PARA_1000_SOURCE_LOCATION.Xcm).toLowerCase() + ); + expect(BigInt(id)).to.eq(BigInt(assetId)); + }, + }); + }, +}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts index ac5320c648..efde5a004b 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -1,10 +1,12 @@ +import "@moonbeam-network/api-augment/moonbase"; import "@moonbeam-network/api-augment"; -import { describeSuite, expect } from "@moonwall/cli"; +import { describeSuite, expect, fetchCompiledContract } from "@moonwall/cli"; import { - RELAY_SOURCE_LOCATION, + RELAY_SOURCE_LOCATION_V4, relayAssetMetadata, registerForeignAsset, } from "../../../../helpers"; +import { StagingXcmV4Location } from "@polkadot/types/lookup"; describeSuite({ id: "D010108", @@ -15,20 +17,24 @@ describeSuite({ id: "T01", title: "should deploy the asset's contract", test: async function () { - const { registeredAssetId, contractAddress, events } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION, - relayAssetMetadata as any - ); + const { registeredAssetId, contractAddress, registeredAssetLocation } = + await registerForeignAsset( + context, + RELAY_SOURCE_LOCATION_V4.Xcm, + relayAssetMetadata as any + ); expect(contractAddress).toBeDefined(); expect(registeredAssetId).eq("1"); + expect(registeredAssetLocation.toString()).to.eq( + JSON.stringify(RELAY_SOURCE_LOCATION_V4.Xcm).toLowerCase() + ); expect( await context.readContract!({ contractName: "MyToken", contractAddress: contractAddress as `0x${string}`, - functionName: "name", + functionName: "symbol", args: [], }) ).toBe("DOT"); From 2088d00c4422cbb339fd805fb81370fb1a378b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Tue, 23 Jul 2024 18:39:37 +0200 Subject: [PATCH 55/71] ForeignAssetTypeChanged -> ForeignAssetXcmLocationChanged --- pallets/asset-manager/src/lib.rs | 4 ++-- pallets/asset-manager/src/tests.rs | 2 +- pallets/moonbeam-foreign-assets/src/tests.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pallets/asset-manager/src/lib.rs b/pallets/asset-manager/src/lib.rs index f72b6ac543..e7ee00c3e9 100644 --- a/pallets/asset-manager/src/lib.rs +++ b/pallets/asset-manager/src/lib.rs @@ -182,7 +182,7 @@ pub mod pallet { units_per_second: u128, }, /// Changed the xcm type mapping for a given asset id - ForeignAssetTypeChanged { + ForeignAssetXcmLocationChanged { asset_id: T::AssetId, new_asset_type: T::ForeignAssetType, }, @@ -367,7 +367,7 @@ pub mod pallet { AssetTypeUnitsPerSecond::::insert(&new_asset_type, units); } - Self::deposit_event(Event::ForeignAssetTypeChanged { + Self::deposit_event(Event::ForeignAssetXcmLocationChanged { asset_id, new_asset_type, }); diff --git a/pallets/asset-manager/src/tests.rs b/pallets/asset-manager/src/tests.rs index 71bffc3c16..dee27f5229 100644 --- a/pallets/asset-manager/src/tests.rs +++ b/pallets/asset-manager/src/tests.rs @@ -206,7 +206,7 @@ fn test_root_can_change_asset_id_type() { asset_type: MockAssetType::MockAsset(1), units_per_second: 200, }, - crate::Event::ForeignAssetTypeChanged { + crate::Event::ForeignAssetXcmLocationChanged { asset_id: 1, new_asset_type: MockAssetType::MockAsset(2), }, diff --git a/pallets/moonbeam-foreign-assets/src/tests.rs b/pallets/moonbeam-foreign-assets/src/tests.rs index 486f722953..94f45990d8 100644 --- a/pallets/moonbeam-foreign-assets/src/tests.rs +++ b/pallets/moonbeam-foreign-assets/src/tests.rs @@ -193,7 +193,7 @@ fn test_root_can_change_foreign_asset_for_asset_id() { asset_id: 1, xcm_location: Location::parent(), }, - crate::Event::ForeignAssetTypeChanged { + crate::Event::ForeignAssetXcmLocationChanged { asset_id: 1, new_xcm_location: Location::here(), }, From ac2ba340be3b22e248a87546851a0a9254bcccd1 Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Wed, 24 Jul 2024 16:01:03 +0200 Subject: [PATCH 56/71] mockAssetBalance wip --- test/contracts/src/MyToken.sol | 87 ++++++++++ test/helpers/assets.ts | 158 ++++++++++++------ test/helpers/xcm.ts | 49 ------ .../test-assets/test-foreign-assets-create.ts | 73 +++++--- 4 files changed, 245 insertions(+), 122 deletions(-) create mode 100644 test/contracts/src/MyToken.sol diff --git a/test/contracts/src/MyToken.sol b/test/contracts/src/MyToken.sol new file mode 100644 index 0000000000..84216f35bb --- /dev/null +++ b/test/contracts/src/MyToken.sol @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: MIT +// Compatible with OpenZeppelin Contracts ^5.0.0 +pragma solidity ^0.8.20; + +import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; +import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; + +contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { + constructor( + address initialOwner, + uint8 tokenDecimals, + string memory symbol, + string memory tokenName + ) ERC20(tokenName, symbol) Ownable(initialOwner) ERC20Permit(tokenName) { + _decimals = tokenDecimals; + } + + uint8 private _decimals; + + function pause() public onlyOwner { + _pause(); + } + + function unpause() public onlyOwner { + _unpause(); + } + + function mintInto(address to, uint256 amount) public onlyOwner { + _mint(to, amount); + } + + function burnFrom(address from, uint256 amount) public onlyOwner { + _burn(from, amount); + } + + function burnAllFrom(address account) public onlyOwner { + _burn(account, balanceOf(account)); + } + + function decimals() public view override returns (uint8) { + return _decimals; + } + + // override ERC20 methods that should be disabled when the asset is "paused" + + function approve( + address spender, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { + address owner = _msgSender(); + _approve(owner, spender, value); + return true; + } + + function transfer( + address to, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { + address owner = _msgSender(); + _transfer(owner, to, value); + return true; + } + + function transferFrom( + address from, + address to, + uint256 value + ) public override(ERC20) whenNotPaused returns (bool) { + address spender = _msgSender(); + _spendAllowance(from, spender, value); + _transfer(from, to, value); + return true; + } + + // The following functions are overrides required by Solidity. + + function _update( + address from, + address to, + uint256 value + ) internal override(ERC20, ERC20Pausable) { + super._update(from, to, value); + } +} diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 4daa5f348f..d20005e2ca 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -1,19 +1,20 @@ import "@moonbeam-network/api-augment/moonbase"; -import { u128 } from "@polkadot/types"; -import { BN, hexToU8a, u8aToHex } from "@polkadot/util"; -import { expect, DevModeContext } from "@moonwall/cli"; -import { blake2AsU8a, xxhashAsU8a } from "@polkadot/util-crypto"; +import { DevModeContext, deployCreateCompiledContract, fetchCompiledContract } from "@moonwall/cli"; +import { ALITH_ADDRESS } from "@moonwall/util"; import { KeyringPair } from "@polkadot/keyring/types"; -import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; -import { registerForeignAsset } from "./xcm"; +import type { AccountId20, Balance } from "@polkadot/types/interfaces/runtime"; +import { u8aToHex } from "@polkadot/util"; +import { encodeFunctionData, parseAbi } from "viem"; + +export const EVM_FOREIGN_ASSETS_PALLET_ACCOUNT = "0x6d6f646c666f7267617373740000000000000000"; +export const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; export const DUMMY_REVERT_BYTECODE = "0x60006000fd"; export const RELAY_SOURCE_LOCATION = { Xcm: { parents: 1, interior: "Here" } }; export const RELAY_SOURCE_LOCATION2 = { Xcm: { parents: 2, interior: "Here" } }; export const RELAY_V3_SOURCE_LOCATION = { V3: { parents: 1, interior: "Here" } } as any; -export const PARA_1000_SOURCE_LOCATION = { - Xcm: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }, +export const PARA_1000_SOURCE_LOCATION_V3 = { + Xcm: { parents: 1, interior: { X1: { Parachain: 1000 } } }, }; export const PARA_2000_SOURCE_LOCATION = { Xcm: { parents: 1, interior: { X1: { Parachain: 2000 } } }, @@ -28,7 +29,6 @@ export const PARA_1000_SOURCE_LOCATION_V4 = { Xcm: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }, }; export interface AssetMetadata { - id: bigint; name: string; symbol: string; decimals: bigint; @@ -36,66 +36,116 @@ export interface AssetMetadata { } export const relayAssetMetadata: AssetMetadata = { - id: 1n, name: "DOT", symbol: "DOT", decimals: 12n, isFrozen: false, }; -export async function mockAssetBalance( +export function assetContractAddress( context: DevModeContext, - assetBalance: PalletAssetsAssetAccount, - assetDetails: PalletAssetsAssetDetails, - sudoAccount: KeyringPair, - assetId: u128, - account: string | AccountId20 + assetId: bigint | string +): `0x${string}` { + const address = `0xffffffff${BigInt(assetId).toString(16)}`; + console.log("ADDR", address); + return address as `0x${string}`; + + // const address = u8aToHex( + // new Uint8Array([ + // ...new Uint8Array([255, 255, 255, 255]), + // ...context.polkadotJs().createType("u128", assetId).toU8a(), + // ]) + // ); + // console.log("ADDR", address); + // return address; +} + +/** + * This registers a foreign asset via the moonbeam-foreign-assets pallet. + * This call will deploy the contract and make the erc20 contract of the asset available + * in the following address: 0xffffffff + metadata.id + */ +export async function registerForeignAsset( + context: DevModeContext, + assetId: bigint, + xcmLocation: any, + metadata: AssetMetadata ) { - const api = context.polkadotJs(); - // Register the asset - registerForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata); + const { decimals, name, symbol } = metadata; + const { result } = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo( + context + .polkadotJs() + .tx.evmForeignAssets.createForeignAsset(assetId, xcmLocation, decimals, symbol, name) + ) + ); - const assets = await api.query.assetManager.assetIdType(assetId); - // make sure we created it - expect(assets.unwrap().asXcm.parents.toNumber()).to.equal(1); + // Fetch the relevant event + const event = (result as any).events.find( + ({ event: { method } }) => method.toString() === "ForeignAssetCreated" + )!.event; - // Get keys to modify balance - const module = xxhashAsU8a(new TextEncoder().encode("Assets"), 128); - const account_key = xxhashAsU8a(new TextEncoder().encode("Account"), 128); - const blake2concatAssetId = new Uint8Array([ - ...blake2AsU8a(assetId.toU8a(), 128), - ...assetId.toU8a(), - ]); + // Get relevant info from the asset creation event + const contractAddress = event.data[0].toHuman().toString(); + const registeredAssetLocation = event.data[2].toString(); + const registeredAssetId = event.data[1].toString(); - const blake2concatAccount = new Uint8Array([ - ...blake2AsU8a(hexToU8a(account.toString()), 128), - ...hexToU8a(account.toString()), - ]); - const overallAccountKey = new Uint8Array([ - ...module, - ...account_key, - ...blake2concatAssetId, - ...blake2concatAccount, - ]); + return { + registeredAssetId, + contractAddress, + registeredAssetLocation, + events: (result as any).events || [], + }; +} + +export async function foreignAssetBalance( + context: DevModeContext, + assetId: bigint, + account: `0x${string}` +) { + return (await context.viem().readContract({ + functionName: "balanceOf", + address: assetContractAddress(context, assetId), + args: [account], + abi: parseAbi(["function balanceOf(address account) view returns (uint256)"]), + })) as bigint; +} - // Get keys to modify total supply & dummyCode (TODO: remove once dummy code inserted by node) - const assetKey = xxhashAsU8a(new TextEncoder().encode("Asset"), 128); - const overallAssetKey = new Uint8Array([...module, ...assetKey, ...blake2concatAssetId]); - const evmCodeAssetKey = api.query.evm.accountCodes.key("0xFfFFfFff" + assetId.toHex().slice(2)); +export async function mockAssetBalance( + context: DevModeContext, + assetBalance: bigint, + assetId: bigint, + sudoAccount: KeyringPair, + account: string | AccountId20 +) { + const api = context.polkadotJs(); + // // Register the asset + // registerForeignAsset(context, assetId, RELAY_SOURCE_LOCATION, relayAssetMetadata); + const { abi } = fetchCompiledContract("MyToken"); + const encodedData = encodeFunctionData({ + abi, + functionName: "mintInto", + args: [ALITH_ADDRESS, assetBalance], + }); + console.log("encodedData", encodedData); + const xcmTransaction = { + V2: { + gas_limit: 160_000n, + action: { + Call: "0xffffffff1fcacbd218edc0eba20fc2308c778080", + }, + value: 0n, + input: encodedData, + access_list: null, + }, + }; await context.createBlock( api.tx.sudo .sudo( - api.tx.system.setStorage([ - [u8aToHex(overallAccountKey), u8aToHex((assetBalance as any).toU8a())], - [u8aToHex(overallAssetKey), u8aToHex((assetBalance as any).toU8a())], - [ - evmCodeAssetKey, - `0x${((DUMMY_REVERT_BYTECODE.length - 2) * 2) - .toString(16) - .padStart(2)}${DUMMY_REVERT_BYTECODE.slice(2)}`, - ], - ]) + api.tx.ethereumXcm.forceTransactAs(EVM_FOREIGN_ASSETS_PALLET_ACCOUNT, xcmTransaction, null) ) .signAsync(sudoAccount) ); diff --git a/test/helpers/xcm.ts b/test/helpers/xcm.ts index 517bbc9c9d..cabb89f4c2 100644 --- a/test/helpers/xcm.ts +++ b/test/helpers/xcm.ts @@ -75,55 +75,6 @@ export function mockHrmpChannelExistanceTx( .tx.system.setStorage([[u8aToHex(overallKey), u8aToHex(stateToInsert.toU8a())]]); } -export async function registerForeignAsset( - context: DevModeContext, - xcmLocation: any, - metadata: AssetMetadata -) { - const { id, decimals, name, symbol } = metadata; - const { result } = await context.createBlock( - context - .polkadotJs() - .tx.sudo.sudo( - context - .polkadotJs() - .tx.evmForeignAssets.createForeignAsset(id, xcmLocation, decimals, symbol, name) - ) - ); - - // Fetch asset id and contract address in the events - const event = (result as any).events.find( - ({ event: { method } }) => method.toString() === "ForeignAssetCreated" - )!.event; - - const contractAddress = event.data[0].toHuman().toString(); - const registeredAssetLocation = event.data[2].toString(); - const registeredAssetId = event.data[1].toString(); - - // New foreign assets design doesn't allow for new assets to pay fees. - // We can reenable this code when that is possible (probably with XCM v5). - // const { result: result2 } = await context.createBlock( - // context - // .polkadotJs() - // .tx.sudo.sudo( - // context - // .polkadotJs() - // .tx.assetManager.setAssetUnitsPerSecond(asset, unitsPerSecond, numAssetsWeightHint!) - // ), - // { - // expectEvents: [context.polkadotJs().events.assetManager.UnitsPerSecondChanged], - // allowFailures: false, - // } - // ); - - return { - registeredAssetId, - contractAddress, - registeredAssetLocation, - events: (result as any).events || [], - }; -} - export function descendOriginFromAddress20( context: DevModeContext, address: `0x${string}` = "0x0101010101010101010101010101010101010101", diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts index efde5a004b..30d2634061 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -1,39 +1,58 @@ -import "@moonbeam-network/api-augment/moonbase"; import "@moonbeam-network/api-augment"; -import { describeSuite, expect, fetchCompiledContract } from "@moonwall/cli"; +import "@moonbeam-network/api-augment/moonbase"; +import { describeSuite, expect, beforeAll } from "@moonwall/cli"; +import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { + ARBITRARY_ASSET_ID, RELAY_SOURCE_LOCATION_V4, - relayAssetMetadata, + foreignAssetBalance, + mockAssetBalance, registerForeignAsset, + relayAssetMetadata, } from "../../../../helpers"; -import { StagingXcmV4Location } from "@polkadot/types/lookup"; describeSuite({ id: "D010108", title: "XCM - Create new foreign asset", foundationMethods: "dev", testCases: ({ context, it, log }) => { + let address: string; + let assetId: bigint; + + beforeAll(async () => { + const { registeredAssetId, contractAddress, registeredAssetLocation } = + await registerForeignAsset( + context, + ARBITRARY_ASSET_ID, + RELAY_SOURCE_LOCATION_V4.Xcm, + relayAssetMetadata as any + ); + + address = contractAddress; + assetId = registeredAssetId; + expect(contractAddress).toBeDefined(); + expect(registeredAssetId).eq(ARBITRARY_ASSET_ID.toString()); + expect(registeredAssetLocation.toString()).to.eq( + JSON.stringify(RELAY_SOURCE_LOCATION_V4.Xcm).toLowerCase() + ); + }); it({ id: "T01", title: "should deploy the asset's contract", test: async function () { - const { registeredAssetId, contractAddress, registeredAssetLocation } = - await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION_V4.Xcm, - relayAssetMetadata as any - ); - - expect(contractAddress).toBeDefined(); - expect(registeredAssetId).eq("1"); - expect(registeredAssetLocation.toString()).to.eq( - JSON.stringify(RELAY_SOURCE_LOCATION_V4.Xcm).toLowerCase() - ); + expect( + await context.readContract!({ + contractName: "MyToken", + contractAddress: address as `0x${string}`, + functionName: "symbol", + args: [], + }) + ).toBe("DOT"); expect( await context.readContract!({ contractName: "MyToken", - contractAddress: contractAddress as `0x${string}`, + contractAddress: address as `0x${string}`, functionName: "symbol", args: [], }) @@ -42,7 +61,7 @@ describeSuite({ expect( await context.readContract!({ contractName: "MyToken", - contractAddress: contractAddress as `0x${string}`, + contractAddress: address as `0x${string}`, functionName: "symbol", args: [], }) @@ -51,12 +70,28 @@ describeSuite({ expect( await context.readContract!({ contractName: "MyToken", - contractAddress: contractAddress as `0x${string}`, + contractAddress: address as `0x${string}`, functionName: "decimals", args: [], }) ).toBe(12); }, }); + + it({ + id: "T02", + title: "should have empty balance", + test: async function () { + const someBalance = 100_000_000_000_000n; + + const balance = await foreignAssetBalance(context, ARBITRARY_ASSET_ID, ALITH_ADDRESS); + expect(balance).toBe(0n); + + mockAssetBalance(context, someBalance, ARBITRARY_ASSET_ID, alith, ALITH_ADDRESS); + + // const newBalance = await foreignAssetBalance(context, assetId, ALITH_ADDRESS); + // expect(newBalance).toBe(someBalance); + }, + }); }, }); From 96eb20f4287202a1707b15893526fd3b246d079b Mon Sep 17 00:00:00 2001 From: Gonza Montiel Date: Wed, 24 Jul 2024 18:32:10 +0200 Subject: [PATCH 57/71] fix mockAssetBalance --- test/helpers/assets.ts | 49 +++++-------- .../test-assets/test-assets-destroy.ts | 69 ------------------- .../test-assets/test-assets-drain-asset.ts | 42 ++++------- .../test-assets/test-assets-remove-asset.ts | 66 ------------------ .../test-foreign-assets-balances.ts | 32 +++++++++ .../test-assets/test-foreign-assets-create.ts | 18 +---- 6 files changed, 62 insertions(+), 214 deletions(-) delete mode 100644 test/suites/dev/moonbase/test-assets/test-assets-destroy.ts delete mode 100644 test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts create mode 100644 test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index d20005e2ca..1b3d4f4fab 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -1,9 +1,8 @@ import "@moonbeam-network/api-augment/moonbase"; -import { DevModeContext, deployCreateCompiledContract, fetchCompiledContract } from "@moonwall/cli"; -import { ALITH_ADDRESS } from "@moonwall/util"; +import { DevModeContext, fetchCompiledContract } from "@moonwall/cli"; import { KeyringPair } from "@polkadot/keyring/types"; -import type { AccountId20, Balance } from "@polkadot/types/interfaces/runtime"; -import { u8aToHex } from "@polkadot/util"; +import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; +import { StagingXcmV4Location } from "@polkadot/types/lookup"; import { encodeFunctionData, parseAbi } from "viem"; export const EVM_FOREIGN_ASSETS_PALLET_ACCOUNT = "0x6d6f646c666f7267617373740000000000000000"; @@ -42,22 +41,8 @@ export const relayAssetMetadata: AssetMetadata = { isFrozen: false, }; -export function assetContractAddress( - context: DevModeContext, - assetId: bigint | string -): `0x${string}` { - const address = `0xffffffff${BigInt(assetId).toString(16)}`; - console.log("ADDR", address); - return address as `0x${string}`; - - // const address = u8aToHex( - // new Uint8Array([ - // ...new Uint8Array([255, 255, 255, 255]), - // ...context.polkadotJs().createType("u128", assetId).toU8a(), - // ]) - // ); - // console.log("ADDR", address); - // return address; +export function assetContractAddress(assetId: bigint | string): `0x${string}` { + return `0xffffffff${BigInt(assetId).toString(16)}`; } /** @@ -107,7 +92,7 @@ export async function foreignAssetBalance( ) { return (await context.viem().readContract({ functionName: "balanceOf", - address: assetContractAddress(context, assetId), + address: assetContractAddress(assetId), args: [account], abi: parseAbi(["function balanceOf(address account) view returns (uint256)"]), })) as bigint; @@ -117,28 +102,28 @@ export async function mockAssetBalance( context: DevModeContext, assetBalance: bigint, assetId: bigint, + assetLocation: any, sudoAccount: KeyringPair, account: string | AccountId20 ) { const api = context.polkadotJs(); - // // Register the asset - // registerForeignAsset(context, assetId, RELAY_SOURCE_LOCATION, relayAssetMetadata); - const { abi } = fetchCompiledContract("MyToken"); - const encodedData = encodeFunctionData({ - abi, - functionName: "mintInto", - args: [ALITH_ADDRESS, assetBalance], - }); - console.log("encodedData", encodedData); + + // Register the asset first + await registerForeignAsset(context, assetId, assetLocation, relayAssetMetadata as any); + const xcmTransaction = { V2: { gas_limit: 160_000n, action: { - Call: "0xffffffff1fcacbd218edc0eba20fc2308c778080", + Call: assetContractAddress(assetId), }, value: 0n, - input: encodedData, + input: encodeFunctionData({ + abi, + functionName: "mintInto", + args: [account, assetBalance], + }), access_list: null, }, }; diff --git a/test/suites/dev/moonbase/test-assets/test-assets-destroy.ts b/test/suites/dev/moonbase/test-assets/test-assets-destroy.ts deleted file mode 100644 index c7c956eeb5..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-assets-destroy.ts +++ /dev/null @@ -1,69 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { ALITH_ADDRESS, BALTATHAR_ADDRESS, alith, baltathar } from "@moonwall/util"; -import { ApiPromise } from "@polkadot/api"; -import { u128 } from "@polkadot/types"; -import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { expectOk, mockAssetBalance } from "../../../../helpers"; - -const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; - -describeSuite({ - id: "D010101", - title: "Pallet Assets - Destruction", - foundationMethods: "dev", - testCases: ({ context, it, log }) => { - let assetId: u128; - let api: ApiPromise; - beforeAll(async () => { - api = context.polkadotJs(); - assetId = api.createType("u128", ARBITRARY_ASSET_ID); - // We need to mint units with sudo.setStorage, as we dont have xcm mocker yet - // And we need relay tokens for issuing a transaction to be executed in the relay - const balance = api.createType("Balance", 100000000000000); - const assetBalance: PalletAssetsAssetAccount = api.createType("PalletAssetsAssetAccount", { - balance: balance, - }); - - const assetDetails: PalletAssetsAssetDetails = api.createType("PalletAssetsAssetDetails", { - supply: balance, - }); - - await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); - await context.createBlock(api.tx.assets.transfer(assetId, baltathar.address, 1000)); - }); - - it({ - id: "T01", - title: "should destroy asset Balance", - test: async function () { - const metadataBefore = await context.polkadotJs().query.assets.metadata(assetId.toU8a()); - - // Name is equal to "DOT" in hex - expect(metadataBefore.name.toString()).to.eq("0x444f54"); - - // assetDetails before in non-empty - const assetDetailsBefore = await api.query.assets.asset(assetId.toU8a()); - expect(assetDetailsBefore.isNone).to.eq(false); - - // Destroy asset - await expectOk(context.createBlock(api.tx.sudo.sudo(api.tx.assets.startDestroy(assetId)))); - await expectOk(context.createBlock(api.tx.assets.destroyAccounts(assetId))); - await expectOk(context.createBlock(api.tx.assets.destroyApprovals(assetId))); - await expectOk(context.createBlock(api.tx.assets.finishDestroy(assetId))); - - // Baltathar balance is None - const baltatharBalance = await api.query.assets.account(assetId.toU8a(), BALTATHAR_ADDRESS); - expect(baltatharBalance.isNone).to.eq(true); - - // metadata is default - const metadata = await api.query.assets.metadata(assetId.toU8a()); - expect(metadata.name.toString()).to.eq("0x"); - - // assetDetails is None - const assetDetails = await api.query.assets.asset(assetId.toU8a()); - expect(assetDetails.isNone).to.eq(true); - }, - }); - }, -}); diff --git a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts b/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts index 13ad449aec..bd2f185524 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts @@ -5,7 +5,12 @@ import { ApiPromise } from "@polkadot/api"; import { u128 } from "@polkadot/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { BN } from "@polkadot/util"; -import { mockAssetBalance } from "../../../../helpers"; +import { + RELAYCHAIN_ARBITRARY_ADDRESS_1, + RELAY_SOURCE_LOCATION_V4, + foreignAssetBalance, + mockAssetBalance, +} from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; const ARBITRARY_TRANSFER_AMOUNT = 10000000000000n; @@ -15,38 +20,21 @@ describeSuite({ title: "Pallet Assets - Sufficient tests: is_sufficient to true", foundationMethods: "dev", testCases: ({ context, it, log }) => { - let assetId: u128; + let assetId: bigint; const freshAccount = generateKeyringPair(); let api: ApiPromise; beforeAll(async () => { api = context.polkadotJs(); - assetId = api.createType("u128", ARBITRARY_ASSET_ID); + assetId = ARBITRARY_ASSET_ID; // We need to mint units with sudo.setStorage, as we dont have xcm mocker yet // And we need relay tokens for issuing a transaction to be executed in the relay - const balance = new BN("100000000000000"); - const assetBalance: PalletAssetsAssetAccount = api.createType("PalletAssetsAssetAccount", { - balance: balance, - }); - - const assetDetails: PalletAssetsAssetDetails = api.createType("PalletAssetsAssetDetails", { - supply: balance, - isSufficient: true, - minBalance: 1, - }); - - await mockAssetBalance( - context, - assetBalance, - assetDetails, - alith, - assetId, - ALITH_ADDRESS, - true - ); + const balance = BigInt("100000000000000"); + const assetLocation = RELAY_SOURCE_LOCATION_V4.Xcm; + await mockAssetBalance(context, balance, assetId, assetLocation, alith, ALITH_ADDRESS); await context.createBlock(); - const alithBalance = await api.query.assets.account(assetId.toU8a(), ALITH_ADDRESS); + const alithBalance = foreignAssetBalance; expect(alithBalance.unwrap().balance.toBigInt()).to.equal(100000000000000n); }); @@ -93,12 +81,6 @@ describeSuite({ .signAsync(freshAccount) ); - const freshAccountBalance = await api.query.assets.account( - assetId.toU8a(), - freshAccount.address as string - ); - expect(freshAccountBalance.isNone).to.equal(true); - // Sufficients should go to 0 expect( (await api.query.system.account(freshAccount.address as string)).sufficients.toBigInt() diff --git a/test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts b/test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts deleted file mode 100644 index 574f7271da..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-assets-remove-asset.ts +++ /dev/null @@ -1,66 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { describeSuite, expect, beforeAll } from "@moonwall/cli"; -import { bnToHex } from "@polkadot/util"; - -import { ApiPromise } from "@polkadot/api"; - -const palletId = "0x6D6f646c617373746d6E67720000000000000000"; - -describeSuite({ - id: "D010109", - title: "XCM - asset manager - Remove asset from supported", - foundationMethods: "dev", - testCases: ({ context, log, it }) => { - let assetId: string; - let api: ApiPromise; - - beforeAll(async function () { - api = context.polkadotJs(); - const { registeredAssetId, events, registeredAsset } = await registerForeignAsset( - context, - RELAY_SOURCE_LOCATION, - relayAssetMetadata as any, - 1 - ); - assetId = registeredAssetId; - expect(events[1].event.method.toString()).to.eq("UnitsPerSecondChanged"); - expect(events[5].event.method.toString()).to.eq("ExtrinsicSuccess"); - expect(registeredAsset.owner.toString()).to.eq(palletId); - - await verifyLatestBlockFees(context); - }); - - it({ - id: "T01", - title: "should remove an asset from our supported fee payments", - test: async function () { - // ChangeAssetType - await context.createBlock( - api.tx.sudo.sudo(api.tx.assetManager.removeSupportedAsset(RELAY_SOURCE_LOCATION, 1)) - ); - - // assetId - const id = (await api.query.assetManager.assetTypeId(RELAY_SOURCE_LOCATION)).unwrap(); - - // asset units per second removed - const assetUnitsPerSecond = await api.query.assetManager.assetTypeUnitsPerSecond( - RELAY_SOURCE_LOCATION - ); - - // Supported assets should be 0 - const supportedAssets = await api.query.assetManager.supportedFeePaymentAssets(); - - expect(assetUnitsPerSecond.isNone).to.eq(true); - expect(bnToHex(id)).to.eq(assetId); - // the asset should not be supported - expect(supportedAssets.length).to.eq(0); - }, - }); - }, -}); -import { - RELAY_SOURCE_LOCATION, - relayAssetMetadata, - registerForeignAsset, - verifyLatestBlockFees, -} from "../../../../helpers"; diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts new file mode 100644 index 0000000000..bf6a4ad1b2 --- /dev/null +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts @@ -0,0 +1,32 @@ +import "@moonbeam-network/api-augment"; +import "@moonbeam-network/api-augment/moonbase"; +import { describeSuite, expect } from "@moonwall/cli"; +import { ALITH_ADDRESS, alith } from "@moonwall/util"; +import { + ARBITRARY_ASSET_ID, + RELAY_SOURCE_LOCATION_V4, + foreignAssetBalance, + mockAssetBalance, +} from "../../../../helpers"; + +describeSuite({ + id: "D010109", + title: "XCM - Create new foreign asset", + foundationMethods: "dev", + testCases: ({ context, it, log }) => { + it({ + id: "T01", + title: "should check balances consstency", + test: async function () { + const someBalance = 100_000_000_000_000n; + const assetLocation = RELAY_SOURCE_LOCATION_V4.Xcm; + const assetId = ARBITRARY_ASSET_ID; + + await mockAssetBalance(context, someBalance, assetId, assetLocation, alith, ALITH_ADDRESS); + + const newBalance = await foreignAssetBalance(context, assetId, ALITH_ADDRESS); + expect(newBalance).toBe(someBalance); + }, + }); + }, +}); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts index 30d2634061..76c53d77e0 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -1,7 +1,6 @@ import "@moonbeam-network/api-augment"; import "@moonbeam-network/api-augment/moonbase"; import { describeSuite, expect, beforeAll } from "@moonwall/cli"; -import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { ARBITRARY_ASSET_ID, RELAY_SOURCE_LOCATION_V4, @@ -36,6 +35,7 @@ describeSuite({ JSON.stringify(RELAY_SOURCE_LOCATION_V4.Xcm).toLowerCase() ); }); + it({ id: "T01", title: "should deploy the asset's contract", @@ -77,21 +77,5 @@ describeSuite({ ).toBe(12); }, }); - - it({ - id: "T02", - title: "should have empty balance", - test: async function () { - const someBalance = 100_000_000_000_000n; - - const balance = await foreignAssetBalance(context, ARBITRARY_ASSET_ID, ALITH_ADDRESS); - expect(balance).toBe(0n); - - mockAssetBalance(context, someBalance, ARBITRARY_ASSET_ID, alith, ALITH_ADDRESS); - - // const newBalance = await foreignAssetBalance(context, assetId, ALITH_ADDRESS); - // expect(newBalance).toBe(someBalance); - }, - }); }, }); From 22a0152ff8d6d4f82157292c40f93fe3542c9f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 18:43:28 +0200 Subject: [PATCH 58/71] restore old foreign asset helpers --- test/helpers/assets.ts | 124 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 123 insertions(+), 1 deletion(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 1b3d4f4fab..c1a3551b2f 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -1,8 +1,9 @@ import "@moonbeam-network/api-augment/moonbase"; import { DevModeContext, fetchCompiledContract } from "@moonwall/cli"; import { KeyringPair } from "@polkadot/keyring/types"; +import { u128 } from "@polkadot/types"; import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; -import { StagingXcmV4Location } from "@polkadot/types/lookup"; +import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { encodeFunctionData, parseAbi } from "viem"; export const EVM_FOREIGN_ASSETS_PALLET_ACCOUNT = "0x6d6f646c666f7267617373740000000000000000"; @@ -45,6 +46,54 @@ export function assetContractAddress(assetId: bigint | string): `0x${string}` { return `0xffffffff${BigInt(assetId).toString(16)}`; } +// This registers an old foreign asset via the asset-manager pallet. +// DEPRECATED: Please don't use for new tests +export async function registerOldForeignAsset( + context: DevModeContext, + asset: any, + metadata: AssetMetadata, + unitsPerSecond?: number, + numAssetsWeightHint?: number +) { + unitsPerSecond = unitsPerSecond != null ? unitsPerSecond : 0; + const { result } = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo( + context.polkadotJs().tx.assetManager.registerForeignAsset(asset, metadata, new BN(1), true) + ) + ); + // Look for assetId in events + const registeredAssetId = result!.events + .find(({ event: { section } }) => section.toString() === "assetManager")! + .event.data[0].toHex() + .replace(/,/g, ""); + + // setAssetUnitsPerSecond + const { result: result2 } = await context.createBlock( + context + .polkadotJs() + .tx.sudo.sudo( + context + .polkadotJs() + .tx.assetManager.setAssetUnitsPerSecond(asset, unitsPerSecond, numAssetsWeightHint!) + ), + { + expectEvents: [context.polkadotJs().events.assetManager.UnitsPerSecondChanged], + allowFailures: false, + } + ); + // check asset in storage + const registeredAsset = ( + (await context.polkadotJs().query.assets.asset(registeredAssetId)) as any + ).unwrap(); + return { + registeredAssetId, + events: result2!.events, + registeredAsset, + }; +} + /** * This registers a foreign asset via the moonbeam-foreign-assets pallet. * This call will deploy the contract and make the erc20 contract of the asset available @@ -136,3 +185,76 @@ export async function mockAssetBalance( ); return; } + +// Mock balance for old foreign assets +// DEPRECATED: Please don't use for new tests +export async function mockOldAssetBalance( + context: DevModeContext, + assetBalance: PalletAssetsAssetAccount, + assetDetails: PalletAssetsAssetDetails, + sudoAccount: KeyringPair, + assetId: u128, + account: string | AccountId20, + is_sufficient = false +) { + const api = context.polkadotJs(); + // Register the asset + await context.createBlock( + api.tx.sudo + .sudo( + api.tx.assetManager.registerForeignAsset( + RELAY_SOURCE_LOCATION, + relayAssetMetadata, + new BN(1), + is_sufficient + ) + ) + .signAsync(sudoAccount) + ); + + const assets = await api.query.assetManager.assetIdType(assetId); + // make sure we created it + expect(assets.unwrap().asXcm.parents.toNumber()).to.equal(1); + + // Get keys to modify balance + const module = xxhashAsU8a(new TextEncoder().encode("Assets"), 128); + const account_key = xxhashAsU8a(new TextEncoder().encode("Account"), 128); + const blake2concatAssetId = new Uint8Array([ + ...blake2AsU8a(assetId.toU8a(), 128), + ...assetId.toU8a(), + ]); + + const blake2concatAccount = new Uint8Array([ + ...blake2AsU8a(hexToU8a(account.toString()), 128), + ...hexToU8a(account.toString()), + ]); + const overallAccountKey = new Uint8Array([ + ...module, + ...account_key, + ...blake2concatAssetId, + ...blake2concatAccount, + ]); + + // Get keys to modify total supply & dummyCode (TODO: remove once dummy code inserted by node) + const assetKey = xxhashAsU8a(new TextEncoder().encode("Asset"), 128); + const overallAssetKey = new Uint8Array([...module, ...assetKey, ...blake2concatAssetId]); + const evmCodeAssetKey = api.query.evm.accountCodes.key("0xFfFFfFff" + assetId.toHex().slice(2)); + + await context.createBlock( + api.tx.sudo + .sudo( + api.tx.system.setStorage([ + [u8aToHex(overallAccountKey), u8aToHex(assetBalance.toU8a())], + [u8aToHex(overallAssetKey), u8aToHex(assetDetails.toU8a())], + [ + evmCodeAssetKey, + `0x${((DUMMY_REVERT_BYTECODE.length - 2) * 2) + .toString(16) + .padStart(2)}${DUMMY_REVERT_BYTECODE.slice(2)}`, + ], + ]) + ) + .signAsync(sudoAccount) + ); + return; +} From 7fb70f96d96a7b856b8f62804f7157968d078ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 18:44:05 +0200 Subject: [PATCH 59/71] allow creation of old foreign assets --- runtime/moonbase/src/asset_config.rs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/runtime/moonbase/src/asset_config.rs b/runtime/moonbase/src/asset_config.rs index ea498463be..8aa9e2979e 100644 --- a/runtime/moonbase/src/asset_config.rs +++ b/runtime/moonbase/src/asset_config.rs @@ -116,14 +116,28 @@ use frame_support::{pallet_prelude::DispatchResult, transactional}; impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { #[transactional] fn create_foreign_asset( - _asset: AssetId, - _min_balance: Balance, - _metadata: AssetRegistrarMetadata, - _is_sufficient: bool, + asset: AssetId, + min_balance: Balance, + metadata: AssetRegistrarMetadata, + is_sufficient: bool, ) -> DispatchResult { - Err(sp_runtime::DispatchError::Other( - "AssetManager is deprecated, please use EvmForeignAssets instead", - )) + Assets::force_create( + RuntimeOrigin::root(), + asset.into(), + crate::AssetManager::account_id(), + is_sufficient, + min_balance, + )?; + + // Lastly, the metadata + Assets::force_set_metadata( + RuntimeOrigin::root(), + asset.into(), + metadata.name, + metadata.symbol, + metadata.decimals, + metadata.is_frozen, + ) } #[transactional] From d4324e685c567c0562a0c253ae36b7c6ec9d69d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 18:53:20 +0200 Subject: [PATCH 60/71] fix imports --- test/helpers/assets.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index c1a3551b2f..7afdba205b 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -1,9 +1,11 @@ import "@moonbeam-network/api-augment/moonbase"; -import { DevModeContext, fetchCompiledContract } from "@moonwall/cli"; -import { KeyringPair } from "@polkadot/keyring/types"; import { u128 } from "@polkadot/types"; -import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; +import { BN, hexToU8a, u8aToHex } from "@polkadot/util"; +import { expect, DevModeContext } from "@moonwall/cli"; +import { blake2AsU8a, xxhashAsU8a } from "@polkadot/util-crypto"; +import { KeyringPair } from "@polkadot/keyring/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; +import type { AccountId20 } from "@polkadot/types/interfaces/runtime"; import { encodeFunctionData, parseAbi } from "viem"; export const EVM_FOREIGN_ASSETS_PALLET_ACCOUNT = "0x6d6f646c666f7267617373740000000000000000"; From 502c63271a219832e9d4b9cb711d79a85d5d75e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 18:55:16 +0200 Subject: [PATCH 61/71] use old foreign assets for xcm fees runtime api tests --- .../test-xcm-v4/test-xcm-payment-api-transact-foreign.ts | 8 ++++---- .../dev/moonbase/test-xcm-v4/test-xcm-payment-api.ts | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts index ad57f12f91..f2567e4edb 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts @@ -13,8 +13,8 @@ import { descendOriginFromAddress20, relayAssetMetadata, RELAY_SOURCE_LOCATION, - registerForeignAsset, - mockAssetBalance, + registerOldForeignAsset, + mockOldAssetBalance, } from "../../../../helpers"; // TODO: remove once we upgrade @polkadot/api to v12.1.1 @@ -115,7 +115,7 @@ describeSuite({ ...runtimeApi, }); - const { registeredAssetId } = await registerForeignAsset( + const { registeredAssetId } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any, @@ -161,7 +161,7 @@ describeSuite({ ); // Fund descendAddress with enough xcDOTs to pay XCM execution fees - await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); + await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); // We need to fund the descendAddress with both amounts. // This account takes care of paying the foreign fees and also transfering the diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api.ts index 0ad1f176bb..01febe8a7d 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api.ts @@ -2,7 +2,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { ApiPromise, WsProvider } from "@polkadot/api"; import { XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, RELAY_SOURCE_LOCATION, } from "../../../../helpers"; @@ -93,7 +93,7 @@ describeSuite({ ...runtimeApi, }); - await registerForeignAsset( + await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any, From c0a3d74f5e1e034fdd756bf4aff74bd31e4947a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 20:08:03 +0200 Subject: [PATCH 62/71] remove Mytoken.sol (fail to compile on CI) and use parseAbi instead --- test/contracts/src/MyToken.sol | 87 ------------------- test/helpers/assets.ts | 12 ++- .../test-assets/test-foreign-assets-create.ts | 32 +++---- 3 files changed, 20 insertions(+), 111 deletions(-) delete mode 100644 test/contracts/src/MyToken.sol diff --git a/test/contracts/src/MyToken.sol b/test/contracts/src/MyToken.sol deleted file mode 100644 index 84216f35bb..0000000000 --- a/test/contracts/src/MyToken.sol +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: MIT -// Compatible with OpenZeppelin Contracts ^5.0.0 -pragma solidity ^0.8.20; - -import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol"; -import "@openzeppelin/contracts/access/Ownable.sol"; -import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; - -contract MyToken is ERC20, ERC20Pausable, Ownable, ERC20Permit { - constructor( - address initialOwner, - uint8 tokenDecimals, - string memory symbol, - string memory tokenName - ) ERC20(tokenName, symbol) Ownable(initialOwner) ERC20Permit(tokenName) { - _decimals = tokenDecimals; - } - - uint8 private _decimals; - - function pause() public onlyOwner { - _pause(); - } - - function unpause() public onlyOwner { - _unpause(); - } - - function mintInto(address to, uint256 amount) public onlyOwner { - _mint(to, amount); - } - - function burnFrom(address from, uint256 amount) public onlyOwner { - _burn(from, amount); - } - - function burnAllFrom(address account) public onlyOwner { - _burn(account, balanceOf(account)); - } - - function decimals() public view override returns (uint8) { - return _decimals; - } - - // override ERC20 methods that should be disabled when the asset is "paused" - - function approve( - address spender, - uint256 value - ) public override(ERC20) whenNotPaused returns (bool) { - address owner = _msgSender(); - _approve(owner, spender, value); - return true; - } - - function transfer( - address to, - uint256 value - ) public override(ERC20) whenNotPaused returns (bool) { - address owner = _msgSender(); - _transfer(owner, to, value); - return true; - } - - function transferFrom( - address from, - address to, - uint256 value - ) public override(ERC20) whenNotPaused returns (bool) { - address spender = _msgSender(); - _spendAllowance(from, spender, value); - _transfer(from, to, value); - return true; - } - - // The following functions are overrides required by Solidity. - - function _update( - address from, - address to, - uint256 value - ) internal override(ERC20, ERC20Pausable) { - super._update(from, to, value); - } -} diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 7afdba205b..d6f62e0cb3 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -2,6 +2,7 @@ import "@moonbeam-network/api-augment/moonbase"; import { u128 } from "@polkadot/types"; import { BN, hexToU8a, u8aToHex } from "@polkadot/util"; import { expect, DevModeContext } from "@moonwall/cli"; +import { ALITH_ADDRESS } from "@moonwall/util"; import { blake2AsU8a, xxhashAsU8a } from "@polkadot/util-crypto"; import { KeyringPair } from "@polkadot/keyring/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; @@ -158,10 +159,15 @@ export async function mockAssetBalance( account: string | AccountId20 ) { const api = context.polkadotJs(); - const { abi } = fetchCompiledContract("MyToken"); + // Register the asset + registerForeignAsset(context, assetId, RELAY_SOURCE_LOCATION, relayAssetMetadata); - // Register the asset first - await registerForeignAsset(context, assetId, assetLocation, relayAssetMetadata as any); + const { abi } = parseAbi(['function mintInto(address, uint256)']); + const encodedData = encodeFunctionData({ + abi, + functionName: "mintInto", + args: [ALITH_ADDRESS, assetBalance], + }); const xcmTransaction = { V2: { diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts index 76c53d77e0..fd6e59cfff 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -4,11 +4,10 @@ import { describeSuite, expect, beforeAll } from "@moonwall/cli"; import { ARBITRARY_ASSET_ID, RELAY_SOURCE_LOCATION_V4, - foreignAssetBalance, - mockAssetBalance, registerForeignAsset, relayAssetMetadata, } from "../../../../helpers"; +import { parseAbi } from "viem"; describeSuite({ id: "D010108", @@ -41,38 +40,29 @@ describeSuite({ title: "should deploy the asset's contract", test: async function () { expect( - await context.readContract!({ - contractName: "MyToken", - contractAddress: address as `0x${string}`, - functionName: "symbol", - args: [], - }) - ).toBe("DOT"); - - expect( - await context.readContract!({ - contractName: "MyToken", - contractAddress: address as `0x${string}`, - functionName: "symbol", + await context.viem().readContract({ + address: address as `0x${string}`, + functionName: "name", args: [], + abi: parseAbi(["function name() view returns (string)"]), }) ).toBe("DOT"); expect( - await context.readContract!({ - contractName: "MyToken", - contractAddress: address as `0x${string}`, + await context.viem().readContract({ + address: address as `0x${string}`, functionName: "symbol", args: [], + abi: parseAbi(["function symbol() view returns (string)"]), }) ).toBe("DOT"); expect( - await context.readContract!({ - contractName: "MyToken", - contractAddress: address as `0x${string}`, + await context.viem().readContract({ + address: address as `0x${string}`, functionName: "decimals", args: [], + abi: parseAbi(["function decimals() view returns (uint8)"]), }) ).toBe(12); }, From c5dac78b6adfab021e591d9fba6575f98d4ef79c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 20:29:33 +0200 Subject: [PATCH 63/71] fix some ts tests --- test/helpers/assets.ts | 6 ++---- .../dev/moonbase/test-assets/test-assets-drain-asset.ts | 2 +- .../dev/moonbase/test-assets/test-assets-drain-both.ts | 4 ++-- .../dev/moonbase/test-assets/test-assets-transfer.ts | 4 ++-- .../moonbase/test-assets/test-foreign-assets-balances.ts | 2 +- .../test-assets/test-foreign-assets-change-xcm-location.ts | 7 ++++--- .../dev/moonbase/test-assets/test-foreign-assets-create.ts | 4 ++-- .../moonbase/test-maintenance/test-maintenance-filter.ts | 4 ++-- .../moonbase/test-maintenance/test-maintenance-filter2.ts | 4 ++-- .../test-precompile-assets-erc20-low-level.ts | 6 +++--- .../test-precompile/test-precompile-assets-erc20.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20a.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20b.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20c.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20d.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20e.ts | 4 ++-- .../test-precompile/test-precompile-assets-erc20f.ts | 4 ++-- .../moonbase/test-precompile/test-precompile-pallet-xcm.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor11.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor12.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor2.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor7.ts | 4 ++-- .../test-precompile/test-precompile-xcm-transactor8.ts | 4 ++-- .../dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts | 4 ++-- 25 files changed, 51 insertions(+), 52 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index d6f62e0cb3..c4bb32e7f5 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -27,10 +27,8 @@ export const PARA_1001_SOURCE_LOCATION = { }; // XCM V4 Locations -export const RELAY_SOURCE_LOCATION_V4 = { Xcm: { parents: 1, interior: { here: null } } }; -export const PARA_1000_SOURCE_LOCATION_V4 = { - Xcm: { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }, -}; +export const RELAY_SOURCE_LOCATION_V4 = { parents: 1, interior: { here: null } }; +export const PARA_1000_SOURCE_LOCATION_V4 = { parents: 1, interior: { X1: [{ Parachain: 1000 }] } }; export interface AssetMetadata { name: string; symbol: string; diff --git a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts b/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts index bd2f185524..f32ee6d091 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts @@ -30,7 +30,7 @@ describeSuite({ // We need to mint units with sudo.setStorage, as we dont have xcm mocker yet // And we need relay tokens for issuing a transaction to be executed in the relay const balance = BigInt("100000000000000"); - const assetLocation = RELAY_SOURCE_LOCATION_V4.Xcm; + const assetLocation = RELAY_SOURCE_LOCATION_V4; await mockAssetBalance(context, balance, assetId, assetLocation, alith, ALITH_ADDRESS); await context.createBlock(); diff --git a/test/suites/dev/moonbase/test-assets/test-assets-drain-both.ts b/test/suites/dev/moonbase/test-assets/test-assets-drain-both.ts index b60b3dace7..efff16e71c 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-drain-both.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-drain-both.ts @@ -5,7 +5,7 @@ import { ApiPromise } from "@polkadot/api"; import { u128 } from "@polkadot/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { BN } from "@polkadot/util"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; const ARBITRARY_TRANSFER_AMOUNT = 10000000000000n; @@ -35,7 +35,7 @@ describeSuite({ minBalance: 1, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-assets/test-assets-transfer.ts b/test/suites/dev/moonbase/test-assets/test-assets-transfer.ts index 5c3effcc85..d6f3d19c7c 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-transfer.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-transfer.ts @@ -5,7 +5,7 @@ import "@polkadot/api-augment"; import { u128 } from "@polkadot/types"; import { ApiPromise } from "@polkadot/api"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; @@ -30,7 +30,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); + await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); }); it({ diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts index bf6a4ad1b2..57bfdbedfd 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-balances.ts @@ -19,7 +19,7 @@ describeSuite({ title: "should check balances consstency", test: async function () { const someBalance = 100_000_000_000_000n; - const assetLocation = RELAY_SOURCE_LOCATION_V4.Xcm; + const assetLocation = RELAY_SOURCE_LOCATION_V4; const assetId = ARBITRARY_ASSET_ID; await mockAssetBalance(context, someBalance, assetId, assetLocation, alith, ALITH_ADDRESS); diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts index 1d622e35c5..6280d60b7f 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-change-xcm-location.ts @@ -2,7 +2,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { ApiPromise } from "@polkadot/api"; import { - PARA_1000_SOURCE_LOCATION, + PARA_1000_SOURCE_LOCATION_V4, RELAY_SOURCE_LOCATION_V4, registerForeignAsset, relayAssetMetadata, @@ -20,6 +20,7 @@ describeSuite({ api = context.polkadotJs(); const { registeredAssetId } = await registerForeignAsset( context, + BigInt(1), RELAY_SOURCE_LOCATION_V4, relayAssetMetadata as any ); @@ -34,7 +35,7 @@ describeSuite({ test: async function () { const { result } = await context.createBlock( api.tx.sudo.sudo( - api.tx.evmForeignAssets.changeXcmLocation(assetId, PARA_1000_SOURCE_LOCATION.Xcm) + api.tx.evmForeignAssets.changeXcmLocation(assetId, PARA_1000_SOURCE_LOCATION_V4) ) ); @@ -46,7 +47,7 @@ describeSuite({ const id = locationChangeEvent.data[0]; expect(JSON.stringify(newLocation).toLowerCase()).to.eq( - JSON.stringify(PARA_1000_SOURCE_LOCATION.Xcm).toLowerCase() + JSON.stringify(PARA_1000_SOURCE_LOCATION_V4).toLowerCase() ); expect(BigInt(id)).to.eq(BigInt(assetId)); }, diff --git a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts index fd6e59cfff..05b9ab2939 100644 --- a/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts +++ b/test/suites/dev/moonbase/test-assets/test-foreign-assets-create.ts @@ -22,7 +22,7 @@ describeSuite({ await registerForeignAsset( context, ARBITRARY_ASSET_ID, - RELAY_SOURCE_LOCATION_V4.Xcm, + RELAY_SOURCE_LOCATION_V4, relayAssetMetadata as any ); @@ -31,7 +31,7 @@ describeSuite({ expect(contractAddress).toBeDefined(); expect(registeredAssetId).eq(ARBITRARY_ASSET_ID.toString()); expect(registeredAssetLocation.toString()).to.eq( - JSON.stringify(RELAY_SOURCE_LOCATION_V4.Xcm).toLowerCase() + JSON.stringify(RELAY_SOURCE_LOCATION_V4).toLowerCase() ); }); diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts index 11a283c5dc..0d8bf793f5 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter.ts @@ -12,7 +12,7 @@ import { import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { hexToU8a } from "@polkadot/util"; import { generatePrivateKey, privateKeyToAccount } from "viem/accounts"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; const RELAYCHAIN_ARBITRARY_ADDRESS_1: string = @@ -128,7 +128,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter2.ts b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter2.ts index 40fad037f0..bd633b956c 100644 --- a/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter2.ts +++ b/test/suites/dev/moonbase/test-maintenance/test-maintenance-filter2.ts @@ -9,7 +9,7 @@ import { import { ALITH_ADDRESS, alith, baltathar } from "@moonwall/util"; import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { RELAY_SOURCE_LOCATION, mockAssetBalance } from "../../../../helpers"; +import { RELAY_SOURCE_LOCATION, mockOldAssetBalance } from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; @@ -38,7 +38,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20-low-level.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20-low-level.ts index 46d924e250..a6e3b4c4af 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20-low-level.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20-low-level.ts @@ -17,7 +17,7 @@ import { u128 } from "@polkadot/types"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { nToHex } from "@polkadot/util"; import { Abi, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012802", @@ -52,7 +52,7 @@ describeSuite({ contractInstanceAddress = contractAddress; contractAbi = abi; - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, @@ -62,7 +62,7 @@ describeSuite({ true ); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20.ts index 08d0c4d380..285c8d54b6 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { Abi, decodeAbiParameters, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012803", @@ -36,7 +36,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20a.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20a.ts index 3f7c1b1649..ff647f9010 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20a.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20a.ts @@ -3,7 +3,7 @@ import { beforeAll, deployCreateCompiledContract, describeSuite, expect } from " import { ALITH_ADDRESS, BALTATHAR_ADDRESS, alith, createEthersTransaction } from "@moonwall/util"; import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; import { Abi, encodeFunctionData } from "viem"; @@ -44,7 +44,7 @@ describeSuite({ }); assetId = context.polkadotJs().createType("u128", ASSET_ID); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20b.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20b.ts index 324d1116bb..01486a76f9 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20b.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20b.ts @@ -11,7 +11,7 @@ import { } from "@moonwall/util"; import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; import { Abi, encodeFunctionData } from "viem"; @@ -52,7 +52,7 @@ describeSuite({ }); assetId = context.polkadotJs().createType("u128", ASSET_ID); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20c.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20c.ts index b99565d82c..f53f0c4d19 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20c.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20c.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, BALTATHAR_ADDRESS, alith, createViemTransaction } from " import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { Abi, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012806", @@ -33,7 +33,7 @@ describeSuite({ }); assetId = context.polkadotJs().createType("u128", ASSET_ID); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts index 847dfbbdd1..60eaffb2cd 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20d.ts @@ -10,7 +10,7 @@ import { import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { Abi, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012807", @@ -54,7 +54,7 @@ describeSuite({ erc20Abi = abi; erc20InstanceAddress = contractAddress; // We fund the contract address with this test - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20e.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20e.ts index 015b25784d..1922aac4c1 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20e.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20e.ts @@ -10,7 +10,7 @@ import { import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { Abi, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012808", @@ -55,7 +55,7 @@ describeSuite({ erc20Abi = abi; // We fund Alith with this test - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20f.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20f.ts index 68afc5273c..3b35f8e576 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20f.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-assets-erc20f.ts @@ -4,7 +4,7 @@ import { BALTATHAR_ADDRESS, alith, createViemTransaction } from "@moonwall/util" import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { Abi, encodeFunctionData } from "viem"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; describeSuite({ id: "D012809", @@ -37,7 +37,7 @@ describeSuite({ erc20Abi = abi; erc20InstanceAddress = contractAddress; - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-pallet-xcm.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-pallet-xcm.ts index c20a44268d..a25642d9dc 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-pallet-xcm.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-pallet-xcm.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, BALTATHAR_ADDRESS, alith, createEthersTransaction } from import { u128 } from "@polkadot/types-codec"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { encodeFunctionData } from "viem"; -import { expectEVMResult, mockAssetBalance } from "../../../../helpers"; +import { expectEVMResult, mockOldAssetBalance } from "../../../../helpers"; const PRECOMPILE_PALLET_XCM_ADDRESS: `0x${string}` = "0x000000000000000000000000000000000000081A"; @@ -34,7 +34,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor.ts index 5a22365db6..fd8b6f1baf 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, registerXcmTransactorAndContract, } from "../../../../helpers"; @@ -103,7 +103,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor11.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor11.ts index 85b8b6a3d1..08e25c45dc 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor11.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor11.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, ALITH_PRIVATE_KEY, alith } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, expectEVMResult, registerXcmTransactorDerivativeIndex, @@ -50,7 +50,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor12.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor12.ts index ccb09a8b3c..f3806d60e0 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor12.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor12.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith, ALITH_PRIVATE_KEY } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, expectEVMResult, registerXcmTransactorDerivativeIndex, @@ -52,7 +52,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor2.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor2.ts index d2169a1238..ec081ea74a 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor2.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor2.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, expectEVMResult, registerXcmTransactorAndContract, @@ -44,7 +44,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor7.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor7.ts index 6865c069cb..99f138a814 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor7.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor7.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, expectEVMResult, registerXcmTransactorDerivativeIndex, @@ -48,7 +48,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor8.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor8.ts index 7b87fc600d..bd9f6dc11a 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor8.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor8.ts @@ -4,7 +4,7 @@ import { ALITH_ADDRESS, alith } from "@moonwall/util"; import { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { fromBytes } from "viem"; import { - mockAssetBalance, + mockOldAssetBalance, verifyLatestBlockFees, expectEVMResult, registerXcmTransactorDerivativeIndex, @@ -51,7 +51,7 @@ describeSuite({ supply: balance, }); - await mockAssetBalance( + await mockOldAssetBalance( context, assetBalance, assetDetails, diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts index ac5cd4a7be..4946055786 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts @@ -9,7 +9,7 @@ import { hexToBigInt } from "@polkadot/util"; import { Abi, encodeFunctionData } from "viem"; import { RELAY_SOURCE_LOCATION, - mockAssetBalance, + mockOldAssetBalance, relayAssetMetadata, verifyLatestBlockFees, } from "../../../../helpers/index.js"; @@ -64,7 +64,7 @@ describeSuite({ }); // Fund descend address with enough xcDOTs to pay XCM message and EVM execution fees - await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); + await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); // Deploy example contract to be called through XCM const { contractAddress, abi } = await context.deployContract!("Incrementor"); From 0f8434fd42060526e0bfc0324e21bbb9f7be63b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 20:55:10 +0200 Subject: [PATCH 64/71] fix more ts tests --- test/helpers/assets.ts | 11 ++--------- .../moonbase/test-assets/test-assets-insufficients.ts | 4 ++-- .../test-precompile-xcm-transactor10.ts | 4 ++-- .../test-precompile-xcm-transactor3.ts | 4 ++-- .../test-precompile-xcm-transactor6.ts | 4 ++-- .../test-xcm-v3/test-mock-dmp-asset-transfer.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-1.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-2.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-3.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-4.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-5.ts | 6 +++--- .../test-xcm-v3/test-mock-dmp-error-and-appendix-6.ts | 6 +++--- .../test-xcm-v3/test-mock-hrmp-asset-transfer-1.ts | 6 +++--- .../test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts | 6 +++--- .../test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts | 6 +++--- .../test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts | 10 +++++----- .../test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts | 6 +++--- .../test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-1.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-2.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-3.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-4.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-5.ts | 6 +++--- .../test-xcm-v4/test-mock-dmp-error-and-appendix-6.ts | 6 +++--- .../test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts | 6 +++--- .../test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts | 6 +++--- .../test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts | 10 +++++----- .../test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts | 6 +++--- .../dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts | 4 ++-- 29 files changed, 85 insertions(+), 92 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index c4bb32e7f5..0740548635 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -158,14 +158,7 @@ export async function mockAssetBalance( ) { const api = context.polkadotJs(); // Register the asset - registerForeignAsset(context, assetId, RELAY_SOURCE_LOCATION, relayAssetMetadata); - - const { abi } = parseAbi(['function mintInto(address, uint256)']); - const encodedData = encodeFunctionData({ - abi, - functionName: "mintInto", - args: [ALITH_ADDRESS, assetBalance], - }); + await registerForeignAsset(context, assetId, RELAY_SOURCE_LOCATION, relayAssetMetadata); const xcmTransaction = { V2: { @@ -175,7 +168,7 @@ export async function mockAssetBalance( }, value: 0n, input: encodeFunctionData({ - abi, + abi: parseAbi(['function mintInto(address, uint256)']), functionName: "mintInto", args: [account, assetBalance], }), diff --git a/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts b/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts index 359092ed31..84f7891909 100644 --- a/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts +++ b/test/suites/dev/moonbase/test-assets/test-assets-insufficients.ts @@ -5,7 +5,7 @@ import { ApiPromise } from "@polkadot/api"; import { u128 } from "@polkadot/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; import { BN } from "@polkadot/util"; -import { mockAssetBalance } from "../../../../helpers"; +import { mockOldAssetBalance } from "../../../../helpers"; const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; const ARBITRARY_TRANSFER_AMOUNT = 10000000000000n; @@ -35,7 +35,7 @@ describeSuite({ minBalance: 1, }); - await mockAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); + await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, ALITH_ADDRESS); await context.createBlock(); const alithBalance = await api.query.assets.account(assetId.toU8a(), ALITH_ADDRESS); diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor10.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor10.ts index 6a476192de..adc05655de 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor10.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor10.ts @@ -7,7 +7,7 @@ import { expectEVMResult, RELAY_SOURCE_LOCATION, relayAssetMetadata, - registerForeignAsset, + registerOldForeignAsset, registerXcmTransactorAndContract, PRECOMPILE_XCM_TRANSACTOR_V3_ADDRESS, } from "../../../../helpers"; @@ -20,7 +20,7 @@ describeSuite({ foundationMethods: "dev", testCases: ({ context, it, log }) => { beforeAll(async () => { - await registerForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); + await registerOldForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); await registerXcmTransactorAndContract(context); }); diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts index d8b78db6b2..24cd84d0cd 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts @@ -6,7 +6,7 @@ import { relayAssetMetadata, verifyLatestBlockFees, expectEVMResult, - registerForeignAsset, + registerOldForeignAsset, registerXcmTransactorAndContract, } from "../../../../helpers"; @@ -18,7 +18,7 @@ describeSuite({ foundationMethods: "dev", testCases: ({ context, it }) => { beforeAll(async () => { - await registerForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); + await registerOldForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); await registerXcmTransactorAndContract(context); }); diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor6.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor6.ts index 453e880373..9a63627389 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor6.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor6.ts @@ -6,7 +6,7 @@ import { relayAssetMetadata, verifyLatestBlockFees, expectEVMResult, - registerForeignAsset, + registerOldForeignAsset, registerXcmTransactorAndContract, } from "../../../../helpers"; @@ -18,7 +18,7 @@ describeSuite({ foundationMethods: "dev", testCases: ({ context, it, log }) => { beforeAll(async () => { - await registerForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); + await registerOldForeignAsset(context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any); await registerXcmTransactorAndContract(context); }); diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-asset-transfer.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-asset-transfer.ts index b19c518d77..dd935755c4 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-asset-transfer.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-asset-transfer.ts @@ -3,7 +3,7 @@ import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall import { alith } from "@moonwall/util"; import { RELAY_SOURCE_LOCATION, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -20,8 +20,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-1.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-1.ts index 6a0073269b..f25702e13a 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-1.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-2.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-2.ts index 69a5cb7fa8..431f70da2b 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-2.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-3.ts index 6560f9d506..8fe81b516d 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-3.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-4.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-4.ts index dc541b6390..0976776440 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-4.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-4.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-5.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-5.ts index add22b03e0..508a49fa70 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-5.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-5.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-6.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-6.ts index fcc3c0e570..599ed58484 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-dmp-error-and-appendix-6.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-1.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-1.ts index 7ac66223e6..c34723f6c1 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-1.ts @@ -1,7 +1,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, customDevRpcRequest, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { PARA_2000_SOURCE_LOCATION, registerForeignAsset } from "../../../../helpers"; +import { PARA_2000_SOURCE_LOCATION, registerOldForeignAsset } from "../../../../helpers"; const FOREIGN_TOKEN = 1_000_000_000_000n; @@ -23,8 +23,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, PARA_2000_SOURCE_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts index 97c05976b0..f55db5b495 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts @@ -4,7 +4,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -41,8 +41,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts index e83956a551..c8abe93965 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts @@ -3,7 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -42,8 +42,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts index 9545f22386..dd171c7316 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts @@ -4,7 +4,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -56,13 +56,13 @@ describeSuite({ let assetIdOne: string; beforeAll(async () => { - // registerForeignAsset 0 + // registerOldForeignAsset 0 const { registeredAssetId: registeredAssetIdZero, registeredAsset: registeredAssetZero } = - await registerForeignAsset(context, STATEMINT_LOCATION, assetMetadata); + await registerOldForeignAsset(context, STATEMINT_LOCATION, assetMetadata); assetIdZero = registeredAssetIdZero; - // registerForeignAsset 1 + // registerOldForeignAsset 1 const { registeredAssetId: registeredAssetIdOne, registeredAsset: registeredAssetOne } = - await registerForeignAsset(context, STATEMINT_ASSET_ONE_LOCATION, assetMetadata, 0, 1); + await registerOldForeignAsset(context, STATEMINT_ASSET_ONE_LOCATION, assetMetadata, 0, 1); assetIdOne = registeredAssetIdOne; expect(registeredAssetZero.owner.toHex()).to.eq(palletId.toLowerCase()); diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts index 2ac2355a7f..1f044ebf97 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts @@ -3,7 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -40,8 +40,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts index e73671a4c3..1eaff98a0b 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts @@ -11,7 +11,7 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, MultiLocation, - registerForeignAsset, + registerOldForeignAsset, weightMessage, } from "../../../../helpers/xcm.js"; @@ -66,8 +66,8 @@ describeSuite({ descendedAddress = descendOriginAddress; random = generateKeyringPair(); - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata, diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-1.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-1.ts index e4ef776a7b..9bfa872c7d 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-1.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-2.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-2.ts index 3949365ab1..49dfaa9c1b 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-2.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-3.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-3.ts index ab9892f04d..9a20c56bae 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-3.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-4.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-4.ts index 7a360425bf..3e2d85e715 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-4.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-4.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-5.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-5.ts index 39c7f1db20..b4226c91d1 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-5.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-5.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-6.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-6.ts index 54e7d80c29..a51072047e 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-dmp-error-and-appendix-6.ts @@ -5,7 +5,7 @@ import type { XcmVersionedXcm } from "@polkadot/types/lookup"; import { RELAY_SOURCE_LOCATION, XcmFragment, - registerForeignAsset, + registerOldForeignAsset, relayAssetMetadata, } from "../../../../helpers"; @@ -22,8 +22,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts index 0cd2c6e9de..0d36f8311c 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts @@ -4,7 +4,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -41,8 +41,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts index a8fd4aed4b..84e8ee94c7 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts @@ -3,7 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -42,8 +42,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts index ee27937b07..3c93427e90 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts @@ -4,7 +4,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -56,13 +56,13 @@ describeSuite({ let assetIdOne: string; beforeAll(async () => { - // registerForeignAsset 0 + // registerOldForeignAsset 0 const { registeredAssetId: registeredAssetIdZero, registeredAsset: registeredAssetZero } = - await registerForeignAsset(context, STATEMINT_LOCATION, assetMetadata); + await registerOldForeignAsset(context, STATEMINT_LOCATION, assetMetadata); assetIdZero = registeredAssetIdZero; - // registerForeignAsset 1 + // registerOldForeignAsset 1 const { registeredAssetId: registeredAssetIdOne, registeredAsset: registeredAssetOne } = - await registerForeignAsset(context, STATEMINT_ASSET_ONE_LOCATION, assetMetadata, 0, 1); + await registerOldForeignAsset(context, STATEMINT_ASSET_ONE_LOCATION, assetMetadata, 0, 1); assetIdOne = registeredAssetIdOne; expect(registeredAssetZero.owner.toHex()).to.eq(palletId.toLowerCase()); diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts index 455df2c6dc..3ec134ba64 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts @@ -3,7 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerForeignAsset, + registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, @@ -40,8 +40,8 @@ describeSuite({ let assetId: string; beforeAll(async () => { - // registerForeignAsset - const { registeredAssetId, registeredAsset } = await registerForeignAsset( + // registerOldForeignAsset + const { registeredAssetId, registeredAsset } = await registerOldForeignAsset( context, STATEMINT_LOCATION, assetMetadata diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts index 4946055786..a049d9da07 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts @@ -10,6 +10,7 @@ import { Abi, encodeFunctionData } from "viem"; import { RELAY_SOURCE_LOCATION, mockOldAssetBalance, + registerOldForeignAsset, relayAssetMetadata, verifyLatestBlockFees, } from "../../../../helpers/index.js"; @@ -19,7 +20,6 @@ import { XcmFragmentConfig, descendOriginFromAddress20, injectHrmpMessageAndSeal, - registerForeignAsset, } from "../../../../helpers/xcm.js"; describeSuite({ @@ -40,7 +40,7 @@ describeSuite({ api = context.polkadotJs(); // Register DOT as foreign asset, obtaining xcDOTs - const { registeredAssetId } = await registerForeignAsset( + const { registeredAssetId } = await registerOldForeignAsset( context, RELAY_SOURCE_LOCATION, relayAssetMetadata as any, From 6c79e6ec765f1eff3e45dd72f56635c022b24c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 20:55:50 +0200 Subject: [PATCH 65/71] remove test specific to substrate assets mechanism (is_sufficient) --- .../test-assets/test-assets-drain-asset.ts | 105 ------------------ 1 file changed, 105 deletions(-) delete mode 100644 test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts diff --git a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts b/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts deleted file mode 100644 index f32ee6d091..0000000000 --- a/test/suites/dev/moonbase/test-assets/test-assets-drain-asset.ts +++ /dev/null @@ -1,105 +0,0 @@ -import "@moonbeam-network/api-augment"; -import { beforeAll, describeSuite, expect } from "@moonwall/cli"; -import { ALITH_ADDRESS, alith, baltathar, generateKeyringPair } from "@moonwall/util"; -import { ApiPromise } from "@polkadot/api"; -import { u128 } from "@polkadot/types"; -import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; -import { BN } from "@polkadot/util"; -import { - RELAYCHAIN_ARBITRARY_ADDRESS_1, - RELAY_SOURCE_LOCATION_V4, - foreignAssetBalance, - mockAssetBalance, -} from "../../../../helpers"; - -const ARBITRARY_ASSET_ID = 42259045809535163221576417993425387648n; -const ARBITRARY_TRANSFER_AMOUNT = 10000000000000n; - -describeSuite({ - id: "D010102", - title: "Pallet Assets - Sufficient tests: is_sufficient to true", - foundationMethods: "dev", - testCases: ({ context, it, log }) => { - let assetId: bigint; - const freshAccount = generateKeyringPair(); - let api: ApiPromise; - - beforeAll(async () => { - api = context.polkadotJs(); - assetId = ARBITRARY_ASSET_ID; - // We need to mint units with sudo.setStorage, as we dont have xcm mocker yet - // And we need relay tokens for issuing a transaction to be executed in the relay - const balance = BigInt("100000000000000"); - const assetLocation = RELAY_SOURCE_LOCATION_V4; - await mockAssetBalance(context, balance, assetId, assetLocation, alith, ALITH_ADDRESS); - - await context.createBlock(); - const alithBalance = foreignAssetBalance; - expect(alithBalance.unwrap().balance.toBigInt()).to.equal(100000000000000n); - }); - - it({ - id: "T01", - title: "Send MOVR and assets to an account, then drain assets, dont drain MOVR", - test: async function () { - // We are going to use a fresh account here, since we mocked the asset balance - // We transfer Assets to freshAccount, which should increase sufficients - - await context.createBlock( - api.tx.assets.transfer(assetId, freshAccount.address, ARBITRARY_TRANSFER_AMOUNT) - ); - - expect( - (await api.query.system.account(freshAccount.address as string)).sufficients.toBigInt() - ).to.eq(1n); - // Providers should still be 0 - expect( - (await api.query.system.account(freshAccount.address as string)).providers.toBigInt() - ).to.eq(0n); - - // Lets transfer it the native token. We want to transfer enough to cover for a future fee. - const fee = ( - await api.tx.assets - .transfer(assetId, baltathar.address, ARBITRARY_TRANSFER_AMOUNT) - .paymentInfo(freshAccount) - ).partialFee.toBigInt(); - - await context.createBlock(api.tx.balances.transferAllowDeath(freshAccount.address, fee)); - - expect( - (await api.query.system.account(freshAccount.address as string)).sufficients.toBigInt() - ).to.eq(1n); - // Providers should now be 1 - expect( - (await api.query.system.account(freshAccount.address as string)).providers.toBigInt() - ).to.eq(1n); - - // When we execute transaction, both MOVR and Assets should be drained - await context.createBlock( - api.tx.assets - .transfer(assetId, baltathar.address, ARBITRARY_TRANSFER_AMOUNT) - .signAsync(freshAccount) - ); - - // Sufficients should go to 0 - expect( - (await api.query.system.account(freshAccount.address as string)).sufficients.toBigInt() - ).to.eq(0n); - // Providers should be 1 - expect( - (await api.query.system.account(freshAccount.address as string)).providers.toBigInt() - ).to.eq(1n); - - // Nonce should be 1 - expect( - (await api.query.system.account(freshAccount.address as string)).providers.toBigInt() - ).to.eq(1n); - - // But balance of MOVR should be 0 - expect( - (await api.query.system.account(freshAccount.address as string)).data.free.toBigInt() > 0n - ).to.eq(true); - }, - }); - }, -}); From 77582c15b33c0f13bcb45899fd97b13679f9108e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:12:39 +0200 Subject: [PATCH 66/71] fix ts imports --- test/helpers/xcm.ts | 1 - .../moonbase/test-precompile/test-precompile-xcm-transactor3.ts | 2 +- .../dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts | 2 +- .../dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts | 2 +- .../dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts | 2 +- .../dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts | 2 +- .../moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts | 2 +- .../dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts | 2 +- .../dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts | 2 +- .../dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts | 2 +- .../dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts | 2 +- 11 files changed, 10 insertions(+), 11 deletions(-) diff --git a/test/helpers/xcm.ts b/test/helpers/xcm.ts index cabb89f4c2..5555bd210f 100644 --- a/test/helpers/xcm.ts +++ b/test/helpers/xcm.ts @@ -1,6 +1,5 @@ import { DevModeContext, customDevRpcRequest, fetchCompiledContract } from "@moonwall/cli"; import { ALITH_ADDRESS } from "@moonwall/util"; -import { u128 } from "@polkadot/types"; import { XcmpMessageFormat } from "@polkadot/types/interfaces"; import { CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, diff --git a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts index 24cd84d0cd..267824090c 100644 --- a/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts +++ b/test/suites/dev/moonbase/test-precompile/test-precompile-xcm-transactor3.ts @@ -6,8 +6,8 @@ import { relayAssetMetadata, verifyLatestBlockFees, expectEVMResult, - registerOldForeignAsset, registerXcmTransactorAndContract, + registerOldForeignAsset, } from "../../../../helpers"; const ADDRESS_RELAY_ASSETS = "0xffffffff1fcacbd218edc0eba20fc2308c778080"; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts index f55db5b495..808d5c4f5d 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts @@ -4,11 +4,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; const statemint_para_id = 1001; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts index c8abe93965..ada7a84d5b 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts @@ -3,11 +3,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts index dd171c7316..1acd022024 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts @@ -4,11 +4,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts index 1f044ebf97..b92b5716ce 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts @@ -3,11 +3,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; const statemint_para_id = 1001; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts index 1eaff98a0b..c9a034ed50 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-transact-ethereum-3.ts @@ -11,9 +11,9 @@ import { injectHrmpMessageAndSeal, descendOriginFromAddress20, MultiLocation, - registerOldForeignAsset, weightMessage, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; describeSuite({ id: "D014025", diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts index 0d36f8311c..83bb3e1b36 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts @@ -4,11 +4,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; const statemint_para_id = 1001; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts index 84e8ee94c7..ac9418f6e6 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts @@ -3,11 +3,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts index 3c93427e90..e5bfdd4577 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts @@ -4,11 +4,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts index 3ec134ba64..360a5b954a 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts @@ -3,11 +3,11 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; import { - registerOldForeignAsset, XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal, } from "../../../../helpers/xcm.js"; +import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; const statemint_para_id = 1001; From e94f2c970d92e433f4f8d66de3d55091397fe578 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:18:03 +0200 Subject: [PATCH 67/71] prettier --- .../test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts | 6 +----- .../test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts | 6 +----- .../test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts | 6 +----- .../test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts | 6 +----- .../dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts | 9 ++++++++- .../test-xcm-v4/test-xcm-payment-api-transact-foreign.ts | 9 ++++++++- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts index 83bb3e1b36..e0ecd5541f 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-1.ts @@ -3,11 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts index ac9418f6e6..baa872080c 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-2.ts @@ -2,11 +2,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts index e5bfdd4577..932210d05c 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-5.ts @@ -3,11 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts index 360a5b954a..d890717115 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-mock-hrmp-asset-transfer-6.ts @@ -2,11 +2,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts index a049d9da07..19f3a5c10c 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-evm-with-dot.ts @@ -64,7 +64,14 @@ describeSuite({ }); // Fund descend address with enough xcDOTs to pay XCM message and EVM execution fees - await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); + await mockOldAssetBalance( + context, + assetBalance, + assetDetails, + alith, + assetId, + descendAddress + ); // Deploy example contract to be called through XCM const { contractAddress, abi } = await context.deployContract!("Incrementor"); diff --git a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts index f2567e4edb..68cbdbc898 100644 --- a/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts +++ b/test/suites/dev/moonbase/test-xcm-v4/test-xcm-payment-api-transact-foreign.ts @@ -161,7 +161,14 @@ describeSuite({ ); // Fund descendAddress with enough xcDOTs to pay XCM execution fees - await mockOldAssetBalance(context, assetBalance, assetDetails, alith, assetId, descendAddress); + await mockOldAssetBalance( + context, + assetBalance, + assetDetails, + alith, + assetId, + descendAddress + ); // We need to fund the descendAddress with both amounts. // This account takes care of paying the foreign fees and also transfering the From 01c1c5cf5e273fddbdc9b6f8eff72fd6a99d046f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:44:52 +0200 Subject: [PATCH 68/71] remove unused imports --- test/helpers/assets.ts | 1 - test/helpers/xcm.ts | 6 ++---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 0740548635..83a51e2635 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -2,7 +2,6 @@ import "@moonbeam-network/api-augment/moonbase"; import { u128 } from "@polkadot/types"; import { BN, hexToU8a, u8aToHex } from "@polkadot/util"; import { expect, DevModeContext } from "@moonwall/cli"; -import { ALITH_ADDRESS } from "@moonwall/util"; import { blake2AsU8a, xxhashAsU8a } from "@polkadot/util-crypto"; import { KeyringPair } from "@polkadot/keyring/types"; import type { PalletAssetsAssetAccount, PalletAssetsAssetDetails } from "@polkadot/types/lookup"; diff --git a/test/helpers/xcm.ts b/test/helpers/xcm.ts index 5555bd210f..12bedafe88 100644 --- a/test/helpers/xcm.ts +++ b/test/helpers/xcm.ts @@ -1,16 +1,14 @@ -import { DevModeContext, customDevRpcRequest, fetchCompiledContract } from "@moonwall/cli"; +import { DevModeContext, customDevRpcRequest } from "@moonwall/cli"; import { ALITH_ADDRESS } from "@moonwall/util"; import { XcmpMessageFormat } from "@polkadot/types/interfaces"; import { CumulusPalletParachainSystemRelayStateSnapshotMessagingStateSnapshot, - StagingXcmV4Location, XcmV3JunctionNetworkId, XcmVersionedXcm, } from "@polkadot/types/lookup"; import { BN, stringToU8a, u8aToHex } from "@polkadot/util"; import { xxhashAsU8a } from "@polkadot/util-crypto"; -import { AssetMetadata, RELAY_V3_SOURCE_LOCATION } from "./assets.js"; -import { ethers } from "ethers"; +import { RELAY_V3_SOURCE_LOCATION } from "./assets.js"; // Creates and returns the tx that overrides the paraHRMP existence // This needs to be inserted at every block in which you are willing to test From 4e585f71e674ee152a762ff3ffcfbe367d285f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:45:07 +0200 Subject: [PATCH 69/71] prettier again --- .../moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts | 6 +----- .../moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts | 6 +----- .../moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts index 808d5c4f5d..1cecd5eca4 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-2.ts @@ -3,11 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { BN } from "@polkadot/util"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts index 1acd022024..3ca5568b4e 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-6.ts @@ -3,11 +3,7 @@ import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n; diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts index b92b5716ce..dff1c29645 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-8.ts @@ -2,11 +2,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const palletId = "0x6D6f646c617373746d6E67720000000000000000"; From 5c28efc28a7bce318078402749b3d68ca36a09e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:48:09 +0200 Subject: [PATCH 70/71] prettier --- test/helpers/assets.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/helpers/assets.ts b/test/helpers/assets.ts index 83a51e2635..c4b47f6a7b 100644 --- a/test/helpers/assets.ts +++ b/test/helpers/assets.ts @@ -167,7 +167,7 @@ export async function mockAssetBalance( }, value: 0n, input: encodeFunctionData({ - abi: parseAbi(['function mintInto(address, uint256)']), + abi: parseAbi(["function mintInto(address, uint256)"]), functionName: "mintInto", args: [account, assetBalance], }), From 42c6e15274fa8e808489abc673812f61f806e020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lo=C3=AFs?= Date: Wed, 24 Jul 2024 21:56:36 +0200 Subject: [PATCH 71/71] prettier --- .../moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts index ada7a84d5b..01f8c8bebf 100644 --- a/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts +++ b/test/suites/dev/moonbase/test-xcm-v3/test-mock-hrmp-asset-transfer-3.ts @@ -2,11 +2,7 @@ import "@moonbeam-network/api-augment"; import { beforeAll, describeSuite, expect } from "@moonwall/cli"; import { alith } from "@moonwall/util"; -import { - XcmFragment, - RawXcmMessage, - injectHrmpMessageAndSeal, -} from "../../../../helpers/xcm.js"; +import { XcmFragment, RawXcmMessage, injectHrmpMessageAndSeal } from "../../../../helpers/xcm.js"; import { registerOldForeignAsset } from "../../../../helpers/assets.js"; const FOREIGN_TOKEN = 1_000_000_000_000n;