diff --git a/scripts/build-tracing-runtime.sh b/scripts/build-tracing-runtime.sh index eded7785..4b330294 100755 --- a/scripts/build-tracing-runtime.sh +++ b/scripts/build-tracing-runtime.sh @@ -65,3 +65,5 @@ done # Move back to git repository root cd ../../../.. +# cleanup +rm -rf tmp diff --git a/srtool-digest/moonbase-runtime-2902-substitute-tracing.json b/srtool-digest/moonbase-runtime-2902-substitute-tracing.json new file mode 100644 index 00000000..b54e3f08 --- /dev/null +++ b/srtool-digest/moonbase-runtime-2902-substitute-tracing.json @@ -0,0 +1 @@ +{"gen":"srtool v0.13.0","src":"zip","version":"0.8.4","commit":"","tag":"","branch":"","rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonbase-runtime","tmsp":"2024-04-18T22:25:10Z","size":"2100518","prop":"0x8fd756ae93fb46c9e5e28ed209d07bf5865673064d8e11833ae619b3e7c7b16b","authorize_upgrade_prop":"0x7effd145f8052e3774142e45c8543c560e2d2482c8db4feaf9513cfdee241d45","ipfs":"QmVnzgSA6nSfS599atGok4cSRxYeeog6NTXxuPBZDJJYoW","sha256":"0x60353ce1cb79df9632504fde3d839f6966ebcca5e219601ff392615f014734c8","wasm":"runtime/moonbase/target/srtool/release/wbuild/moonbase-runtime/moonbase_runtime.compact.compressed.wasm","info":{"generator":{"name":"srtool","version":"0.13.0"},"src":"zip","version":"0.8.4","git":{"commit":"","tag":"","branch":""},"rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonbase-runtime","profile":"release"},"context":{"package":"moonbase-runtime","runtime_dir":"runtime/moonbase","docker":{"image":"paritytech/srtool","tag":"1.74.0"},"profile":"release"},"runtimes":{"compact":{"tmsp":"2024-04-18T22:24:53Z","size":"10267052","prop":"0x789f74327e420739cef262e2b7b5aab33841b94f7ac7481b4703caa45ab355be","authorize_upgrade_prop":"0xa653d34950aa7103469ea417baac2e17a159eee8134307e0772ba39b06913ebf","blake2_256":"0x262ef77b1d9a8f862f37c04da977e73a7bfdea3ebd9c6b4451322cba79ae850d","ipfs":"Qme3mH3QYmkQzzez6RgHE74J2oy6uT3jtxq3wybiNE6Paa","sha256":"0xdc2efe981d5c376418bb9bbf21c2a6cd4eefa7ca87ef7ddfbba00ae20910ec99","wasm":"runtime/moonbase/target/srtool/release/wbuild/moonbase-runtime/moonbase_runtime.compact.wasm","subwasm":{"size":10267052,"compression":{"size_compressed":10267052,"size_decompressed":10267052,"compressed":false},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonbase","implName":"moonbase","authoringVersion":4,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0x789f74327e420739cef262e2b7b5aab33841b94f7ac7481b4703caa45ab355be","parachain_authorize_upgrade_hash":"0xa653d34950aa7103469ea417baac2e17a159eee8134307e0772ba39b06913ebf","ipfs_hash":"Qme3mH3QYmkQzzez6RgHE74J2oy6uT3jtxq3wybiNE6Paa","blake2_256":"0x262ef77b1d9a8f862f37c04da977e73a7bfdea3ebd9c6b4451322cba79ae850d"}},"compressed":{"tmsp":"2024-04-18T22:21:40Z","size":"2100518","prop":"0x8fd756ae93fb46c9e5e28ed209d07bf5865673064d8e11833ae619b3e7c7b16b","authorize_upgrade_prop":"0x7effd145f8052e3774142e45c8543c560e2d2482c8db4feaf9513cfdee241d45","blake2_256":"0xf10e6fa3bb61b6b91859e4b761aa31660e5fb8d928c47c0d73e7507a6ca9e71e","ipfs":"QmVnzgSA6nSfS599atGok4cSRxYeeog6NTXxuPBZDJJYoW","sha256":"0x60353ce1cb79df9632504fde3d839f6966ebcca5e219601ff392615f014734c8","wasm":"runtime/moonbase/target/srtool/release/wbuild/moonbase-runtime/moonbase_runtime.compact.compressed.wasm","subwasm":{"size":2100518,"compression":{"size_compressed":2100518,"size_decompressed":10267052,"compressed":true},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonbase","implName":"moonbase","authoringVersion":4,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0x8fd756ae93fb46c9e5e28ed209d07bf5865673064d8e11833ae619b3e7c7b16b","parachain_authorize_upgrade_hash":"0x7effd145f8052e3774142e45c8543c560e2d2482c8db4feaf9513cfdee241d45","ipfs_hash":"QmVnzgSA6nSfS599atGok4cSRxYeeog6NTXxuPBZDJJYoW","blake2_256":"0xf10e6fa3bb61b6b91859e4b761aa31660e5fb8d928c47c0d73e7507a6ca9e71e"}}}} diff --git a/srtool-digest/moonbeam-runtime-2902-substitute-tracing.json b/srtool-digest/moonbeam-runtime-2902-substitute-tracing.json new file mode 100644 index 00000000..e282b6e1 --- /dev/null +++ b/srtool-digest/moonbeam-runtime-2902-substitute-tracing.json @@ -0,0 +1 @@ +{"gen":"srtool v0.13.0","src":"zip","version":"0.8.4","commit":"","tag":"","branch":"","rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonbeam-runtime","tmsp":"2024-04-18T22:37:28Z","size":"2090338","prop":"0x9332fd45f25cbf6d84f6147d38dcae9118e822e08ae8139fd495974b72a20fea","authorize_upgrade_prop":"0x466558f4953d633b55245fc103a9f5a1de60c0663eedae408dc89d3c974fc546","ipfs":"QmewHBxwwk6m3yyXczNv8zSEqcmPDU4EzqntthQEPnZN1a","sha256":"0x31cf410fe82f0c35cee4d950c282a6e8f8a1cccf77ec9e2cf745913e5ab6d854","wasm":"runtime/moonbeam/target/srtool/release/wbuild/moonbeam-runtime/moonbeam_runtime.compact.compressed.wasm","info":{"generator":{"name":"srtool","version":"0.13.0"},"src":"zip","version":"0.8.4","git":{"commit":"","tag":"","branch":""},"rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonbeam-runtime","profile":"release"},"context":{"package":"moonbeam-runtime","runtime_dir":"runtime/moonbeam","docker":{"image":"paritytech/srtool","tag":"1.74.0"},"profile":"release"},"runtimes":{"compact":{"tmsp":"2024-04-18T22:37:11Z","size":"10137577","prop":"0x3e82d3689bef41df0526a817f12ad2ebf22fde76e9681e96724479b331639579","authorize_upgrade_prop":"0x1f0f283d7c8c452381ed85034ebf7366d317d9778ce4bfb019c8992b56eec8a8","blake2_256":"0x7124142a514a567d392f5afb7d6db5950854d800b3b685024c90e90eba867589","ipfs":"Qmac5NHzQPh71iSetU8gHAzKqSfBbGSQWatb6et5RHHixJ","sha256":"0x4b92e065a7b3382f515773192c4f902aa0ef9f18fcb572e7d0f802eadff2fc08","wasm":"runtime/moonbeam/target/srtool/release/wbuild/moonbeam-runtime/moonbeam_runtime.compact.wasm","subwasm":{"size":10137577,"compression":{"size_compressed":10137577,"size_decompressed":10137577,"compressed":false},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonbeam","implName":"moonbeam","authoringVersion":3,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0x3e82d3689bef41df0526a817f12ad2ebf22fde76e9681e96724479b331639579","parachain_authorize_upgrade_hash":"0x1f0f283d7c8c452381ed85034ebf7366d317d9778ce4bfb019c8992b56eec8a8","ipfs_hash":"Qmac5NHzQPh71iSetU8gHAzKqSfBbGSQWatb6et5RHHixJ","blake2_256":"0x7124142a514a567d392f5afb7d6db5950854d800b3b685024c90e90eba867589"}},"compressed":{"tmsp":"2024-04-18T22:33:56Z","size":"2090338","prop":"0x9332fd45f25cbf6d84f6147d38dcae9118e822e08ae8139fd495974b72a20fea","authorize_upgrade_prop":"0x466558f4953d633b55245fc103a9f5a1de60c0663eedae408dc89d3c974fc546","blake2_256":"0x3232cf4bec1b80d882c0ddd3c218257b6e935821794b6db3ad8ede3c26cee7b7","ipfs":"QmewHBxwwk6m3yyXczNv8zSEqcmPDU4EzqntthQEPnZN1a","sha256":"0x31cf410fe82f0c35cee4d950c282a6e8f8a1cccf77ec9e2cf745913e5ab6d854","wasm":"runtime/moonbeam/target/srtool/release/wbuild/moonbeam-runtime/moonbeam_runtime.compact.compressed.wasm","subwasm":{"size":2090338,"compression":{"size_compressed":2090338,"size_decompressed":10137577,"compressed":true},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonbeam","implName":"moonbeam","authoringVersion":3,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0x9332fd45f25cbf6d84f6147d38dcae9118e822e08ae8139fd495974b72a20fea","parachain_authorize_upgrade_hash":"0x466558f4953d633b55245fc103a9f5a1de60c0663eedae408dc89d3c974fc546","ipfs_hash":"QmewHBxwwk6m3yyXczNv8zSEqcmPDU4EzqntthQEPnZN1a","blake2_256":"0x3232cf4bec1b80d882c0ddd3c218257b6e935821794b6db3ad8ede3c26cee7b7"}}}} diff --git a/srtool-digest/moonriver-runtime-2902-substitute-tracing.json b/srtool-digest/moonriver-runtime-2902-substitute-tracing.json new file mode 100644 index 00000000..d39eee1b --- /dev/null +++ b/srtool-digest/moonriver-runtime-2902-substitute-tracing.json @@ -0,0 +1 @@ +{"gen":"srtool v0.13.0","src":"zip","version":"0.8.4","commit":"","tag":"","branch":"","rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonriver-runtime","tmsp":"2024-04-18T22:31:17Z","size":"2088287","prop":"0x59264c951c0f79a23d7fd579c80547d803c51bf8c6c5c1add3b9f4826c914aef","authorize_upgrade_prop":"0x3ff8260ca8efbde9a72e7228f6858ea0aac126a3bd004d0c02491864a76d334d","ipfs":"QmbPGXkHk9iyon2iKjGncTZFwyE5qhqYNaHa1dBvouhj3V","sha256":"0x10b599c13190cce9a97fc4fa9a82bded42e177b56b78c97820bdcd2696217bfe","wasm":"runtime/moonriver/target/srtool/release/wbuild/moonriver-runtime/moonriver_runtime.compact.compressed.wasm","info":{"generator":{"name":"srtool","version":"0.13.0"},"src":"zip","version":"0.8.4","git":{"commit":"","tag":"","branch":""},"rustc":"rustc 1.74.0 (79e9716c9 2023-11-13)","pkg":"moonriver-runtime","profile":"release"},"context":{"package":"moonriver-runtime","runtime_dir":"runtime/moonriver","docker":{"image":"paritytech/srtool","tag":"1.74.0"},"profile":"release"},"runtimes":{"compact":{"tmsp":"2024-04-18T22:30:59Z","size":"10170523","prop":"0xb8b8e02b6bcac2379e7a71fc36285a88a89e15ad51f55412ffaa6facad9da584","authorize_upgrade_prop":"0x322688170c10e590979e01aab361ae5a2ea947c501300d11d88130ad4c7865fc","blake2_256":"0x2aaca74d1c510fd2e758ee36c866b405f45640af57736df6f74ca37d3c61166f","ipfs":"QmfCpENjL8HPfrQepvvGM8MmvE4EMkUCHg5RydSa5KHsX6","sha256":"0x68c85725575a88e579977a3cdfd0287f647e618581f489673230abf6f2231337","wasm":"runtime/moonriver/target/srtool/release/wbuild/moonriver-runtime/moonriver_runtime.compact.wasm","subwasm":{"size":10170523,"compression":{"size_compressed":10170523,"size_decompressed":10170523,"compressed":false},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonriver","implName":"moonriver","authoringVersion":3,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0xb8b8e02b6bcac2379e7a71fc36285a88a89e15ad51f55412ffaa6facad9da584","parachain_authorize_upgrade_hash":"0x322688170c10e590979e01aab361ae5a2ea947c501300d11d88130ad4c7865fc","ipfs_hash":"QmfCpENjL8HPfrQepvvGM8MmvE4EMkUCHg5RydSa5KHsX6","blake2_256":"0x2aaca74d1c510fd2e758ee36c866b405f45640af57736df6f74ca37d3c61166f"}},"compressed":{"tmsp":"2024-04-18T22:27:50Z","size":"2088287","prop":"0x59264c951c0f79a23d7fd579c80547d803c51bf8c6c5c1add3b9f4826c914aef","authorize_upgrade_prop":"0x3ff8260ca8efbde9a72e7228f6858ea0aac126a3bd004d0c02491864a76d334d","blake2_256":"0x0a4257613d8d28a492154a8d95b3062c127b0e2d53785999338ff1fea0b87656","ipfs":"QmbPGXkHk9iyon2iKjGncTZFwyE5qhqYNaHa1dBvouhj3V","sha256":"0x10b599c13190cce9a97fc4fa9a82bded42e177b56b78c97820bdcd2696217bfe","wasm":"runtime/moonriver/target/srtool/release/wbuild/moonriver-runtime/moonriver_runtime.compact.compressed.wasm","subwasm":{"size":2088287,"compression":{"size_compressed":2088287,"size_decompressed":10170523,"compressed":true},"reserved_meta":[109,101,116,97],"reserved_meta_valid":true,"metadata_version":14,"core_version":{"specName":"moonriver","implName":"moonriver","authoringVersion":3,"specVersion":2902,"implVersion":0,"apis":[["0xd2bc9897eed08f15",3],["0xd0399cd053adda2b",1],["0xdf6acb689907609b",4],["0x37e397fc7c91f5e4",2],["0x40fe3ad401f8959a",6],["0xf78b278be53f454c",2],["0xab3c0572291feb8b",1],["0xfbc577b9d747efd6",1],["0xbc9d89904f5b923f",1],["0xbd78255d4feeea1f",5],["0xa33d43f58731ad84",2],["0x582211f65bb14b89",5],["0xe65b00e46cedd0aa",2],["0x37c8bb1350a9a2a8",4],["0x2aa62120049dd2d2",1],["0xea93e3f16f3d6962",2],["0xba8173bf23b2e6f8",1]],"transactionVersion":2,"stateVersion":0},"proposal_hash":"0x59264c951c0f79a23d7fd579c80547d803c51bf8c6c5c1add3b9f4826c914aef","parachain_authorize_upgrade_hash":"0x3ff8260ca8efbde9a72e7228f6858ea0aac126a3bd004d0c02491864a76d334d","ipfs_hash":"QmbPGXkHk9iyon2iKjGncTZFwyE5qhqYNaHa1dBvouhj3V","blake2_256":"0x0a4257613d8d28a492154a8d95b3062c127b0e2d53785999338ff1fea0b87656"}}}} diff --git a/tracing/2902/Cargo.lock b/tracing/2902/Cargo.lock new file mode 100644 index 00000000..ed24ed58 --- /dev/null +++ b/tracing/2902/Cargo.lock @@ -0,0 +1,8484 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "account" +version = "0.1.1" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "blake2-rfc", + "impl-serde 0.3.2", + "libsecp256k1", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sha3", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface", + "sp-std", +] + +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli 0.27.3", +] + +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli 0.28.1", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aead" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d122413f284cf2d62fb1b7db97e02edb8cda96d769b16e443a4f6195e35662b0" +dependencies = [ + "crypto-common", + "generic-array", +] + +[[package]] +name = "affix" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e7ea84d3fa2009f355f8429a0b418a96849135a4188fadf384f59127d5d4bc" +dependencies = [ + "convert_case 0.5.0", +] + +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom 0.2.14", + "once_cell", + "version_check", +] + +[[package]] +name = "ahash" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +dependencies = [ + "cfg-if", + "getrandom 0.2.14", + "once_cell", + "version_check", + "zerocopy", +] + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi", +] + +[[package]] +name = "anyhow" +version = "1.0.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" + +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "aquamarine" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21cc1548309245035eb18aa7f0967da6bc65587005170c56e6ef2788a4cf3f4e" +dependencies = [ + "include_dir", + "itertools", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "ark-bls12-377" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb00293ba84f51ce3bd026bd0de55899c4e68f0a39a5728cebae3a73ffdc0a4f" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bls12-377-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20c7021f180a0cbea0380eba97c2af3c57074cdaffe0eef7e840e1c9f2841e55" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-models-ext", + "ark-std", +] + +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-bls12-381-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1dc4b3d08f19e8ec06e949712f95b8361e43f1391d94f65e4234df03480631c" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-models-ext", + "ark-serialize", + "ark-std", +] + +[[package]] +name = "ark-bw6-761" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e0605daf0cc5aa2034b78d008aaf159f56901d92a52ee4f6ecdfdac4f426700" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-bw6-761-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccee5fba47266f460067588ee1bf070a9c760bf2050c1c509982c5719aadb4f2" +dependencies = [ + "ark-bw6-761", + "ark-ec", + "ark-ff", + "ark-models-ext", + "ark-std", +] + +[[package]] +name = "ark-ec" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ed-on-bls12-377" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b10d901b9ac4b38f9c32beacedfadcdd64e46f8d7f8e88c1ae1060022cf6f6c6" +dependencies = [ + "ark-bls12-377", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-ed-on-bls12-377-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524a4fb7540df2e1a8c2e67a83ba1d1e6c3947f4f9342cc2359fc2e789ad731d" +dependencies = [ + "ark-ec", + "ark-ed-on-bls12-377", + "ark-ff", + "ark-models-ext", + "ark-std", +] + +[[package]] +name = "ark-ed-on-bls12-381-bandersnatch" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cde0f2aa063a2a5c28d39b47761aa102bda7c13c84fc118a61b87c7b2f785c" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-std", +] + +[[package]] +name = "ark-ed-on-bls12-381-bandersnatch-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d15185f1acb49a07ff8cbe5f11a1adc5a93b19e211e325d826ae98e98e124346" +dependencies = [ + "ark-ec", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ff", + "ark-models-ext", + "ark-std", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools", + "num-bigint", + "num-traits", + "paste", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-models-ext" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e9eab5d4b5ff2f228b763d38442adc9b084b0a465409b059fac5c2308835ec2" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-scale" +version = "0.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f69c00b3b529be29528a6f2fd5fa7b1790f8bed81b9cdca17e326538545a179" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "ark-secret-scalar" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=e9782f9#e9782f938629c90f3adb3fff2358bc8d1386af3e" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", + "ark-transcript", + "digest 0.10.7", + "getrandom_or_panic", + "zeroize", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", + "rayon", +] + +[[package]] +name = "ark-transcript" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=e9782f9#e9782f938629c90f3adb3fff2358bc8d1386af3e" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "digest 0.10.7", + "rand_core 0.6.4", + "sha3", +] + +[[package]] +name = "array-bytes" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f840fb7195bcfc5e17ea40c26e5ce6d5b9ce5d584466e17703209657e459ae0" + +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + +[[package]] +name = "arrayvec" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9" +dependencies = [ + "nodrop", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "assert_matches" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" + +[[package]] +name = "async-backing-primitives" +version = "0.9.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "sp-api", + "sp-consensus-slots", +] + +[[package]] +name = "async-trait" +version = "0.1.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "backtrace" +version = "0.3.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d" +dependencies = [ + "addr2line 0.21.0", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object 0.32.2", + "rustc-demangle", +] + +[[package]] +name = "bandersnatch_vrfs" +version = "0.0.4" +source = "git+https://github.com/w3f/ring-vrf?rev=e9782f9#e9782f938629c90f3adb3fff2358bc8d1386af3e" +dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ff", + "ark-serialize", + "ark-std", + "dleq_vrf", + "fflonk", + "merlin", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "ring", + "sha2 0.10.8", + "sp-ark-bls12-381", + "sp-ark-ed-on-bls12-381-bandersnatch", + "zeroize", +] + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + +[[package]] +name = "bip39" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f2635620bf0b9d4576eb7bb9a38a55df78bd1205d26fa994b25911a69f212f" +dependencies = [ + "bitcoin_hashes", + "rand 0.8.5", + "rand_core 0.6.4", + "serde", + "unicode-normalization", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90064b8dee6815a6470d60bad07bbbaee885c0e12d04177138fa3291a01b7bc4" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "serde", + "tap", + "wyz", +] + +[[package]] +name = "blake2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46502ad458c9a52b69d4d4d32775c788b7a1b85e8bc9d482d92250fc0e3f8efe" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "blake2-rfc" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" +dependencies = [ + "arrayvec 0.4.12", + "constant_time_eq 0.1.5", +] + +[[package]] +name = "blake2b_simd" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23285ad32269793932e830392f2fe2f83e26488fd3ec778883a93c8323735780" +dependencies = [ + "arrayref", + "arrayvec 0.7.4", + "constant_time_eq 0.3.0", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bounded-collections" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32385ecb91a31bddaf908e8dcf4a15aef1bcd3913cc03ebfad02ff6d568abc1" +dependencies = [ + "log", + "parity-scale-codec", + "scale-info", + "serde", +] + +[[package]] +name = "bp-xcm-bridge-hub-router" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "build-helper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdce191bf3fa4995ce948c8c83b4640a1745457a149e73c6db75b4ffe36aad5f" +dependencies = [ + "semver 0.6.0", +] + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "bytemuck" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d6d68c57235a3a081186990eca2867354726650f42f7516ca50c28d6281fd15" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" + +[[package]] +name = "camino" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59e92b5a388f549b863a7bea62612c09f24c8393560709a54558a9abdfb3b9c" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24b1f0365a6c6bb4020cd05806fd0d33c44d38046b8bd7f0e40814b9763cabfc" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +dependencies = [ + "camino", + "cargo-platform", + "semver 1.0.22", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "case" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6c0e7b807d60291f42f33f58480c0bfafe28ed08286446f45e463728cf9c1c" + +[[package]] +name = "cc" +version = "1.0.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +dependencies = [ + "jobserver", + "libc", +] + +[[package]] +name = "cfg-expr" +version = "0.15.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa50868b64a9a6fda9d593ce778849ea8715cd2a3d2cc17ffdb4a2f2f2f1961d" +dependencies = [ + "smallvec", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "num-traits", + "windows-targets 0.52.4", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "common" +version = "0.1.0" +source = "git+https://github.com/w3f/ring-proof#b273d33f9981e2bb3375ab45faeb537f7ee35224" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "fflonk", + "getrandom_or_panic", + "merlin", + "rand_chacha 0.3.1", +] + +[[package]] +name = "common-path" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2382f75942f4b3be3690fe4f86365e9c853c1587d6ee58212cebf6e2a9ccd101" + +[[package]] +name = "console" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.52.0", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "const-random" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" +dependencies = [ + "const-random-macro", +] + +[[package]] +name = "const-random-macro" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" +dependencies = [ + "getrandom 0.2.14", + "once_cell", + "tiny-keccak", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "constant_time_eq" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7144d30dcf0fafbce74250a3963025d8d52177934239851c917d29f1df280c2" + +[[package]] +name = "constcat" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd7e35aee659887cbfb97aaf227ac12cad1a9d7c71e55ff3376839ed4e282d08" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "convert_case" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a24b1aaf0fd0ce8b45161144d6f42cd91677fd5940fd431183eb023b3a2b8" + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpp_demangle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eeaa953eaad386a53111e47172c2fedba671e5684c8dd601a5f474f4f118710f" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "cranelift-entity" +version = "0.95.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40099d38061b37e505e63f89bab52199037a72b931ad4868d9089ff7268660b0" +dependencies = [ + "serde", +] + +[[package]] +name = "crc32fast" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3855a8a784b474f333699ef2bbca9db2c4a1f6d9088a90a2d25b1eb53111eaa" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "typenum", +] + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "crypto-mac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25fab6889090c8133f3deb8f73ba3c65a7f456f66436fc012a1b1e272b1e103e" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "cumulus-pallet-dmp-queue" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", +] + +[[package]] +name = "cumulus-pallet-parachain-system" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bytes", + "cumulus-pallet-parachain-system-proc-macro", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-primitives-proof-size-hostfunction", + "environmental", + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-message-queue", + "parity-scale-codec", + "polkadot-parachain-primitives", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-externalities", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "sp-version", + "staging-xcm", + "trie-db", +] + +[[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.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "cumulus-pallet-xcm" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", +] + +[[package]] +name = "cumulus-pallet-xcmp-queue" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bounded-collections", + "bp-xcm-bridge-hub-router", + "cumulus-primitives-core", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-message-queue", + "parity-scale-codec", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "cumulus-primitives-core" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-primitives", + "scale-info", + "sp-api", + "sp-runtime", + "sp-std", + "sp-trie", + "staging-xcm", +] + +[[package]] +name = "cumulus-primitives-parachain-inherent" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "async-trait", + "cumulus-primitives-core", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-inherents", + "sp-std", + "sp-trie", +] + +[[package]] +name = "cumulus-primitives-proof-size-hostfunction" +version = "0.2.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "sp-externalities", + "sp-runtime-interface", + "sp-trie", +] + +[[package]] +name = "cumulus-primitives-timestamp" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "futures", + "parity-scale-codec", + "sp-inherents", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "cumulus-primitives-utility" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "log", + "pallet-asset-conversion", + "pallet-xcm-benchmarks", + "parity-scale-codec", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek" +version = "4.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "cxx" +version = "1.0.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21db378d04296a84d8b7d047c36bb3954f0b46529db725d7e62fb02f9ba53ccc" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e5262a7fa3f0bae2a55b767c223ba98032d7c328f5c13fa5cdc980b77fc0658" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn 2.0.58", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be8dcadd2e2fb4a501e1d9e93d6e88e6ea494306d8272069c92d5a9edf8855c0" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.121" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad08a837629ad949b73d032c637653d069e909cffe4ee7870b02301939ce39cc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive-syn-parse" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e79116f119dd1dba1abf1f3405f03b9b0e79a27a3883864bfebded8a3dc768cd" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive-syn-parse" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d65d7ce8132b7c0e54497a4d9a55a1c2a0912a0d786cf894472ba818fba45762" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dleq_vrf" +version = "0.0.2" +source = "git+https://github.com/w3f/ring-vrf?rev=e9782f9#e9782f938629c90f3adb3fff2358bc8d1386af3e" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-scale", + "ark-secret-scalar", + "ark-serialize", + "ark-std", + "ark-transcript", + "arrayvec 0.7.4", + "zeroize", +] + +[[package]] +name = "docify" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a2f138ad521dc4a2ced1a4576148a6a610b4c5923933b062a263130a6802ce" +dependencies = [ + "docify_macros", +] + +[[package]] +name = "docify_macros" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a081e51fb188742f5a7a1164ad752121abcb22874b21e2c3b0dd040c515fdad" +dependencies = [ + "common-path", + "derive-syn-parse 0.2.0", + "once_cell", + "proc-macro2", + "quote", + "regex", + "syn 2.0.58", + "termcolor", + "toml", + "walkdir", +] + +[[package]] +name = "dyn-clonable" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e9232f0e607a262ceb9bd5141a3dfb3e4db6994b31989bbfd845878cba59fd4" +dependencies = [ + "dyn-clonable-impl", + "dyn-clone", +] + +[[package]] +name = "dyn-clonable-impl" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "558e40ea573c374cf53507fd240b7ee2f5477df7cfebdb97323ec61c719399c5" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "dyn-clone" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature 2.2.0", + "spki", +] + +[[package]] +name = "ed25519" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +dependencies = [ + "signature 1.6.4", +] + +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature 2.2.0", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek 3.2.0", + "ed25519 1.5.3", + "rand 0.7.3", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek 4.1.2", + "ed25519 2.2.3", + "serde", + "sha2 0.10.8", + "subtle", + "zeroize", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek 3.2.0", + "hashbrown 0.12.3", + "hex", + "rand_core 0.6.4", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "either" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "enumflags2" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3278c9d5fb675e0a51dabcf4c0d355f692b064171535ba72361be1528a9d8e8d" +dependencies = [ + "enumflags2_derive", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c785274071b1b420972453b306eeca06acf4633829db4223b58a2a8c5953bc4" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "enumn" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "environmental" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e48c92028aaa870e83d51c64e5d4e0b6981b360c522198c23959f219a4e1b15b" + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "ethbloom" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c22d4b5885b6aa2fe5e8b9329fb8d232bf739e434e6b87347c63bdd00c120f60" +dependencies = [ + "crunchy", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde 0.4.0", + "scale-info", + "tiny-keccak", +] + +[[package]] +name = "ethereum" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e04d24d20b8ff2235cffbf242d5092de3aa45f77c5270ddbfadd2778ca13fea" +dependencies = [ + "bytes", + "ethereum-types", + "hash-db", + "hash256-std-hasher", + "parity-scale-codec", + "rlp", + "scale-info", + "serde", + "sha3", + "trie-root", +] + +[[package]] +name = "ethereum-types" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d215cbf040552efcbe99a38372fe80ab9d00268e20012b79fcd0f073edd8ee" +dependencies = [ + "ethbloom", + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde 0.4.0", + "primitive-types", + "scale-info", + "uint", +] + +[[package]] +name = "evm" +version = "0.41.1" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +dependencies = [ + "auto_impl", + "environmental", + "ethereum", + "evm-core", + "evm-gasometer", + "evm-runtime", + "log", + "parity-scale-codec", + "primitive-types", + "rlp", + "scale-info", + "serde", + "sha3", +] + +[[package]] +name = "evm-core" +version = "0.41.0" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +dependencies = [ + "parity-scale-codec", + "primitive-types", + "scale-info", + "serde", +] + +[[package]] +name = "evm-gasometer" +version = "0.41.0" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +dependencies = [ + "environmental", + "evm-core", + "evm-runtime", + "primitive-types", +] + +[[package]] +name = "evm-runtime" +version = "0.41.0" +source = "git+https://github.com/moonbeam-foundation/evm?branch=moonbeam-polkadot-v1.7.2#d8991ec727ad0fb64fe9957a3cd307387a6701e4" +dependencies = [ + "auto_impl", + "environmental", + "evm-core", + "primitive-types", + "sha3", +] + +[[package]] +name = "evm-tracing-events" +version = "0.1.0" +dependencies = [ + "environmental", + "ethereum", + "ethereum-types", + "evm", + "evm-gasometer", + "evm-runtime", + "parity-scale-codec", + "sp-runtime-interface", +] + +[[package]] +name = "expander" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f86a749cf851891866c10515ef6c299b5c69661465e9c3bbe7e07a2b77fb0f7" +dependencies = [ + "blake2", + "fs-err", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "fallible-iterator" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" + +[[package]] +name = "faster-hex" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "51e2ce894d53b295cf97b05685aa077950ff3e8541af83217fc720a6437169f8" + +[[package]] +name = "fastrand" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "fflonk" +version = "0.1.0" +source = "git+https://github.com/w3f/fflonk#1e854f35e9a65d08b11a86291405cdc95baa0a35" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "merlin", +] + +[[package]] +name = "fiat-crypto" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys 0.52.0", +] + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fp-account" +version = "1.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "hex", + "impl-serde 0.4.0", + "libsecp256k1", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface", + "sp-std", +] + +[[package]] +name = "fp-consensus" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "ethereum", + "parity-scale-codec", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fp-ethereum" +version = "1.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "frame-support", + "parity-scale-codec", + "sp-std", +] + +[[package]] +name = "fp-evm" +version = "3.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "evm", + "frame-support", + "num_enum 0.7.2", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fp-rpc" +version = "3.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-evm", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-runtime", + "sp-state-machine", + "sp-std", +] + +[[package]] +name = "fp-self-contained" +version = "1.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-runtime", +] + +[[package]] +name = "fp-storage" +version = "2.0.0" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "parity-scale-codec", + "serde", +] + +[[package]] +name = "frame-benchmarking" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-support-procedural", + "frame-system", + "linregress", + "log", + "parity-scale-codec", + "paste", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-core", + "sp-io", + "sp-runtime", + "sp-runtime-interface", + "sp-std", + "sp-storage", + "static_assertions", +] + +[[package]] +name = "frame-election-provider-solution-type" +version = "13.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "frame-election-provider-support" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-election-provider-solution-type", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-npos-elections", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "frame-executive" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "frame-try-runtime", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", +] + +[[package]] +name = "frame-metadata" +version = "16.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cf1549fba25a6fcac22785b61698317d958e96cac72a59102ea45b9ae64692" +dependencies = [ + "cfg-if", + "parity-scale-codec", + "scale-info", + "serde", +] + +[[package]] +name = "frame-support" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "aquamarine", + "array-bytes", + "bitflags 1.3.2", + "docify", + "environmental", + "frame-metadata", + "frame-support-procedural", + "impl-trait-for-tuples", + "k256", + "log", + "macro_magic", + "parity-scale-codec", + "paste", + "scale-info", + "serde", + "serde_json", + "smallvec", + "sp-api", + "sp-arithmetic", + "sp-core", + "sp-crypto-hashing-proc-macro", + "sp-debug-derive", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-metadata-ir", + "sp-runtime", + "sp-staking", + "sp-state-machine", + "sp-std", + "sp-tracing", + "sp-weights", + "static_assertions", + "tt-call", +] + +[[package]] +name = "frame-support-procedural" +version = "23.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "Inflector", + "cfg-expr", + "derive-syn-parse 0.1.5", + "expander", + "frame-support-procedural-tools", + "itertools", + "macro_magic", + "proc-macro-warning", + "proc-macro2", + "quote", + "sp-crypto-hashing", + "syn 2.0.58", +] + +[[package]] +name = "frame-support-procedural-tools" +version = "10.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support-procedural-tools-derive", + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "frame-support-procedural-tools-derive" +version = "11.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "frame-system" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cfg-if", + "docify", + "frame-support", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-version", + "sp-weights", +] + +[[package]] +name = "frame-system-benchmarking" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "frame-system-rpc-runtime-api" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "sp-api", +] + +[[package]] +name = "frame-try-runtime" +version = "0.34.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "fs-err" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88a41f105fe1d5b6b34b2055e3dc59bb79b46b48b2040b9e6c7b4b5de097aa41" +dependencies = [ + "autocfg", +] + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "futures" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" + +[[package]] +name = "futures-executor" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", + "num_cpus", +] + +[[package]] +name = "futures-io" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" + +[[package]] +name = "futures-macro" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "futures-sink" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" + +[[package]] +name = "futures-task" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" + +[[package]] +name = "futures-util" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom_or_panic" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea1015b5a70616b688dc230cfe50c8af89d972cb132d5a622814d29773b10b9" +dependencies = [ + "rand 0.8.5", + "rand_core 0.6.4", +] + +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" +dependencies = [ + "fallible-iterator", + "indexmap 1.9.3", + "stable_deref_trait", +] + +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hash-db" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e7d7786361d7425ae2fe4f9e407eb0efaa0840f5212d109cc018c40c35c6ab4" + +[[package]] +name = "hash256-std-hasher" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92c171d55b98633f4ed3860808f004099b36c1cc29c42cfc53aa8591b21efcf2" +dependencies = [ + "crunchy", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash 0.7.8", +] + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" +dependencies = [ + "ahash 0.8.11", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "hex-literal" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebdb29d2ea9ed0083cd8cece49bbd968021bd99b0849edb4a9a7ee0fdf6a4e0" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hmac" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" +dependencies = [ + "crypto-mac 0.8.0", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac 0.11.0", + "digest 0.9.0", +] + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "hmac-drbg" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" +dependencies = [ + "digest 0.9.0", + "generic-array", + "hmac 0.8.1", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-rlp" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f28220f89297a075ddc7245cd538076ee98b01f2a9c23a53a4f1105d5a322808" +dependencies = [ + "rlp", +] + +[[package]] +name = "impl-serde" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4551f042f3438e64dbd6226b20527fc84a6e1fe65688b58746a2f53623f25f5c" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-serde" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc88fc67028ae3db0c853baa36269d398d5f45b6982f95549ff5def78c935cd" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "include_dir" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18762faeff7122e89e0857b02f7ce6fcc0d101d5e9ad2ad7846cc01d61b7f19e" +dependencies = [ + "include_dir_macros", +] + +[[package]] +name = "include_dir_macros" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b139284b5cf57ecfa712bcc66950bb635b31aff41c188e8a4cfc758eca374a3f" +dependencies = [ + "proc-macro2", + "quote", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + +[[package]] +name = "integer-sqrt" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "276ec31bcb4a9ee45f58bec6f9ec700ae4cf4f4f8f2fa7e06cb406bd5ffdd770" +dependencies = [ + "num-traits", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi", + "libc", + "windows-sys 0.48.0", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "jobserver" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +dependencies = [ + "libc", +] + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.8", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libsecp256k1" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95b09eff1b35ed3b33b877ced3a691fc7a481919c7e29c53c906226fcf55e2a1" +dependencies = [ + "arrayref", + "base64", + "digest 0.9.0", + "hmac-drbg", + "libsecp256k1-core", + "libsecp256k1-gen-ecmult", + "libsecp256k1-gen-genmult", + "rand 0.8.5", + "serde", + "sha2 0.9.9", + "typenum", +] + +[[package]] +name = "libsecp256k1-core" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5be9b9bb642d8522a44d533eab56c16c738301965504753b03ad1de3425d5451" +dependencies = [ + "crunchy", + "digest 0.9.0", + "subtle", +] + +[[package]] +name = "libsecp256k1-gen-ecmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3038c808c55c87e8a172643a7d87187fc6c4174468159cb3090659d55bcb4809" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "libsecp256k1-gen-genmult" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3db8d6ba2cec9eacc40e6e8ccc98931840301f1006e95647ceb2dd5c3aa06f7c" +dependencies = [ + "libsecp256k1-core", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d240c6f7e1ba3a28b0249f774e6a9dd0175054b52dfbb61b16eb8505c3785c9" +dependencies = [ + "cc", +] + +[[package]] +name = "linregress" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4de04dcecc58d366391f9920245b85ffa684558a5ef6e7736e754347c3aea9c2" +dependencies = [ + "nalgebra", +] + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "mach" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" +dependencies = [ + "libc", +] + +[[package]] +name = "macro_magic" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e03844fc635e92f3a0067e25fa4bf3e3dbf3f2927bf3aa01bb7bc8f1c428949d" +dependencies = [ + "macro_magic_core", + "macro_magic_macros", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "macro_magic_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "468155613a44cfd825f1fb0ffa532b018253920d404e6fca1e8d43155198a46d" +dependencies = [ + "const-random", + "derive-syn-parse 0.1.5", + "macro_magic_core_macros", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "macro_magic_core_macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ea73aa640dc01d62a590d48c0c3521ed739d53b27f919b25c3551e233481654" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "macro_magic_macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef9d79ae96aaba821963320eb2b6e34d17df1e5a83d8a1985c29cc5be59577b3" +dependencies = [ + "macro_magic_core", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata 0.1.10", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" +dependencies = [ + "autocfg", + "rawpointer", +] + +[[package]] +name = "memchr" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" + +[[package]] +name = "memfd" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" +dependencies = [ + "rustix 0.38.32", +] + +[[package]] +name = "memoffset" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d61c719bcfbcf5d62b3a09efa6088de8c54bc0bfcd3ea7ae39fcc186108b8de1" +dependencies = [ + "autocfg", +] + +[[package]] +name = "memory-db" +version = "0.32.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808b50db46293432a45e63bc15ea51e0ab4c0a1647b8eb114e31a3e698dd6fbe" +dependencies = [ + "hash-db", +] + +[[package]] +name = "merlin" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58c38e2799fc0978b65dfff8023ec7843e2330bb462f19198840b34b6582397d" +dependencies = [ + "byteorder", + "keccak", + "rand_core 0.6.4", + "zeroize", +] + +[[package]] +name = "miniz_oxide" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d811f3e15f28568be3407c8e7fdb6514c1cda3cb30683f15b6a1a1dc4ea14a7" +dependencies = [ + "adler", +] + +[[package]] +name = "moonbase-runtime" +version = "0.8.4" +dependencies = [ + "account", + "async-backing-primitives", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "evm-tracing-events", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal 0.3.4", + "log", + "moonbeam-core-primitives", + "moonbeam-evm-tracer", + "moonbeam-relay-encoder", + "moonbeam-rpc-primitives-debug", + "moonbeam-rpc-primitives-txpool", + "moonbeam-runtime-common 0.8.0-dev", + "moonbeam-xcm-benchmarks", + "nimbus-primitives", + "num_enum 0.5.11", + "orml-traits", + "orml-xcm-support", + "orml-xtokens", + "pallet-asset-manager", + "pallet-assets", + "pallet-async-backing", + "pallet-author-inherent", + "pallet-author-mapping", + "pallet-author-slot-filter", + "pallet-balances", + "pallet-collective", + "pallet-conviction-voting", + "pallet-crowdloan-rewards", + "pallet-emergency-para-xcm", + "pallet-erc20-xcm-bridge", + "pallet-ethereum", + "pallet-ethereum-xcm", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-evm-precompile-author-mapping", + "pallet-evm-precompile-balances-erc20", + "pallet-evm-precompile-batch", + "pallet-evm-precompile-blake2", + "pallet-evm-precompile-bn128", + "pallet-evm-precompile-call-permit", + "pallet-evm-precompile-collective", + "pallet-evm-precompile-conviction-voting", + "pallet-evm-precompile-crowdloan-rewards", + "pallet-evm-precompile-dispatch", + "pallet-evm-precompile-gmp", + "pallet-evm-precompile-identity", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-parachain-staking", + "pallet-evm-precompile-preimage", + "pallet-evm-precompile-proxy", + "pallet-evm-precompile-randomness", + "pallet-evm-precompile-referenda", + "pallet-evm-precompile-registry", + "pallet-evm-precompile-relay-encoder", + "pallet-evm-precompile-relay-verifier", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", + "pallet-evm-precompile-storage-cleaner", + "pallet-evm-precompile-xcm-transactor", + "pallet-evm-precompile-xcm-utils", + "pallet-evm-precompile-xtokens", + "pallet-evm-precompileset-assets-erc20", + "pallet-identity", + "pallet-maintenance-mode", + "pallet-message-queue", + "pallet-migrations", + "pallet-moonbeam-lazy-migrations", + "pallet-moonbeam-orbiters", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompile-benchmarks", + "pallet-preimage", + "pallet-proxy", + "pallet-proxy-genesis-companion", + "pallet-randomness", + "pallet-referenda", + "pallet-relay-storage-roots", + "pallet-root-testing", + "pallet-scheduler", + "pallet-society", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "pallet-xcm-benchmarks", + "pallet-xcm-transactor", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "precompile-utils 0.1.1", + "rlp", + "scale-info", + "serde", + "session-keys-primitives", + "sha3", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-slots", + "sp-core", + "sp-debug-derive", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "sp-weights", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "strum", + "strum_macros", + "substrate-wasm-builder", + "xcm-primitives 0.1.0", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonbeam-core-primitives" +version = "0.1.1" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "account", + "fp-self-contained", + "hex-literal 0.3.4", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "moonbeam-evm-tracer" +version = "0.1.0" +dependencies = [ + "ethereum-types", + "evm", + "evm-gasometer", + "evm-runtime", + "evm-tracing-events", + "fp-evm", + "moonbeam-primitives-ext", + "pallet-evm", + "parity-scale-codec", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "moonbeam-primitives-ext" +version = "0.1.0" +dependencies = [ + "ethereum-types", + "evm-tracing-events", + "parity-scale-codec", + "sp-externalities", + "sp-runtime-interface", + "sp-std", +] + +[[package]] +name = "moonbeam-relay-encoder" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "frame-system", + "pallet-evm-precompile-relay-encoder", + "pallet-staking", + "pallet-xcm-transactor", + "parity-scale-codec", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonbeam-rpc-primitives-debug" +version = "0.1.0" +dependencies = [ + "environmental", + "ethereum", + "ethereum-types", + "hex", + "parity-scale-codec", + "serde", + "sp-api", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "moonbeam-rpc-primitives-txpool" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "ethereum", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "moonbeam-runtime" +version = "0.8.4" +dependencies = [ + "account", + "async-backing-primitives", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "evm-tracing-events", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal 0.3.4", + "log", + "moonbeam-core-primitives", + "moonbeam-evm-tracer", + "moonbeam-relay-encoder", + "moonbeam-rpc-primitives-debug", + "moonbeam-rpc-primitives-txpool", + "moonbeam-runtime-common 0.8.0-dev", + "moonbeam-xcm-benchmarks", + "nimbus-primitives", + "num_enum 0.5.11", + "orml-traits", + "orml-xcm-support", + "orml-xtokens", + "pallet-asset-manager", + "pallet-assets", + "pallet-author-inherent", + "pallet-author-mapping", + "pallet-author-slot-filter", + "pallet-balances", + "pallet-collective", + "pallet-conviction-voting", + "pallet-crowdloan-rewards", + "pallet-erc20-xcm-bridge", + "pallet-ethereum", + "pallet-ethereum-xcm", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-evm-precompile-author-mapping", + "pallet-evm-precompile-balances-erc20", + "pallet-evm-precompile-batch", + "pallet-evm-precompile-blake2", + "pallet-evm-precompile-bn128", + "pallet-evm-precompile-call-permit", + "pallet-evm-precompile-collective", + "pallet-evm-precompile-conviction-voting", + "pallet-evm-precompile-crowdloan-rewards", + "pallet-evm-precompile-dispatch", + "pallet-evm-precompile-gmp", + "pallet-evm-precompile-identity", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-parachain-staking", + "pallet-evm-precompile-preimage", + "pallet-evm-precompile-proxy", + "pallet-evm-precompile-randomness", + "pallet-evm-precompile-referenda", + "pallet-evm-precompile-registry", + "pallet-evm-precompile-relay-encoder", + "pallet-evm-precompile-relay-verifier", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", + "pallet-evm-precompile-xcm-transactor", + "pallet-evm-precompile-xcm-utils", + "pallet-evm-precompile-xtokens", + "pallet-evm-precompileset-assets-erc20", + "pallet-identity", + "pallet-maintenance-mode", + "pallet-message-queue", + "pallet-migrations", + "pallet-moonbeam-lazy-migrations", + "pallet-moonbeam-orbiters", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompile-benchmarks", + "pallet-preimage", + "pallet-proxy", + "pallet-proxy-genesis-companion", + "pallet-randomness", + "pallet-referenda", + "pallet-relay-storage-roots", + "pallet-root-testing", + "pallet-scheduler", + "pallet-society", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "pallet-xcm-benchmarks", + "pallet-xcm-transactor", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "precompile-utils 0.1.1", + "rlp", + "scale-info", + "serde", + "session-keys-primitives", + "sha3", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-slots", + "sp-core", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "sp-weights", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "strum", + "strum_macros", + "substrate-wasm-builder", + "xcm-primitives 0.1.0", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonbeam-runtime-common" +version = "0.8.0-dev" +dependencies = [ + "account", + "cumulus-pallet-xcmp-queue", + "fp-ethereum", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "frame-try-runtime", + "hex-literal 0.3.4", + "impl-trait-for-tuples", + "log", + "moonbeam-xcm-benchmarks", + "nimbus-primitives", + "pallet-asset-manager", + "pallet-assets", + "pallet-async-backing", + "pallet-author-inherent", + "pallet-author-mapping", + "pallet-author-slot-filter", + "pallet-balances", + "pallet-collective", + "pallet-conviction-voting", + "pallet-crowdloan-rewards", + "pallet-ethereum-xcm", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-identity", + "pallet-migrations", + "pallet-moonbeam-lazy-migrations", + "pallet-moonbeam-orbiters", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompile-benchmarks", + "pallet-preimage", + "pallet-proxy", + "pallet-randomness", + "pallet-referenda", + "pallet-relay-storage-roots", + "pallet-scheduler", + "pallet-sudo", + "pallet-timestamp", + "pallet-treasury", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "pallet-xcm-transactor", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-api", + "sp-consensus-slots", + "sp-core", + "sp-genesis-builder", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonbeam-runtime-common" +version = "0.8.0-dev" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "account", + "cumulus-pallet-xcmp-queue", + "fp-ethereum", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "frame-try-runtime", + "hex-literal 0.3.4", + "impl-trait-for-tuples", + "log", + "moonbeam-xcm-benchmarks", + "nimbus-primitives", + "pallet-asset-manager", + "pallet-assets", + "pallet-async-backing", + "pallet-author-inherent", + "pallet-author-mapping", + "pallet-author-slot-filter", + "pallet-balances", + "pallet-collective", + "pallet-conviction-voting", + "pallet-crowdloan-rewards", + "pallet-ethereum-xcm", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-identity", + "pallet-migrations", + "pallet-moonbeam-lazy-migrations", + "pallet-moonbeam-orbiters", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompile-benchmarks", + "pallet-preimage", + "pallet-proxy", + "pallet-randomness", + "pallet-referenda", + "pallet-relay-storage-roots", + "pallet-scheduler", + "pallet-sudo", + "pallet-timestamp", + "pallet-treasury", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "pallet-xcm-transactor", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-api", + "sp-consensus-slots", + "sp-core", + "sp-genesis-builder", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonbeam-xcm-benchmarks" +version = "0.2.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-erc20-xcm-bridge", + "pallet-xcm-benchmarks", + "parity-scale-codec", + "scale-info", + "serde", + "sp-std", + "staging-xcm", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "moonriver-runtime" +version = "0.8.4" +dependencies = [ + "account", + "async-backing-primitives", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "evm-tracing-events", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal 0.3.4", + "log", + "moonbeam-core-primitives", + "moonbeam-evm-tracer", + "moonbeam-relay-encoder", + "moonbeam-rpc-primitives-debug", + "moonbeam-rpc-primitives-txpool", + "moonbeam-runtime-common 0.8.0-dev", + "moonbeam-xcm-benchmarks", + "nimbus-primitives", + "num_enum 0.5.11", + "orml-traits", + "orml-xcm-support", + "orml-xtokens", + "pallet-asset-manager", + "pallet-assets", + "pallet-author-inherent", + "pallet-author-mapping", + "pallet-author-slot-filter", + "pallet-balances", + "pallet-collective", + "pallet-conviction-voting", + "pallet-crowdloan-rewards", + "pallet-erc20-xcm-bridge", + "pallet-ethereum", + "pallet-ethereum-xcm", + "pallet-evm", + "pallet-evm-chain-id", + "pallet-evm-precompile-author-mapping", + "pallet-evm-precompile-balances-erc20", + "pallet-evm-precompile-batch", + "pallet-evm-precompile-blake2", + "pallet-evm-precompile-bn128", + "pallet-evm-precompile-call-permit", + "pallet-evm-precompile-collective", + "pallet-evm-precompile-conviction-voting", + "pallet-evm-precompile-crowdloan-rewards", + "pallet-evm-precompile-dispatch", + "pallet-evm-precompile-gmp", + "pallet-evm-precompile-identity", + "pallet-evm-precompile-modexp", + "pallet-evm-precompile-parachain-staking", + "pallet-evm-precompile-preimage", + "pallet-evm-precompile-proxy", + "pallet-evm-precompile-randomness", + "pallet-evm-precompile-referenda", + "pallet-evm-precompile-registry", + "pallet-evm-precompile-relay-encoder", + "pallet-evm-precompile-relay-verifier", + "pallet-evm-precompile-sha3fips", + "pallet-evm-precompile-simple", + "pallet-evm-precompile-xcm-transactor", + "pallet-evm-precompile-xcm-utils", + "pallet-evm-precompile-xtokens", + "pallet-evm-precompileset-assets-erc20", + "pallet-identity", + "pallet-maintenance-mode", + "pallet-message-queue", + "pallet-migrations", + "pallet-moonbeam-lazy-migrations", + "pallet-moonbeam-orbiters", + "pallet-multisig", + "pallet-parachain-staking", + "pallet-precompile-benchmarks", + "pallet-preimage", + "pallet-proxy", + "pallet-proxy-genesis-companion", + "pallet-randomness", + "pallet-referenda", + "pallet-relay-storage-roots", + "pallet-root-testing", + "pallet-scheduler", + "pallet-society", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-utility", + "pallet-whitelist", + "pallet-xcm", + "pallet-xcm-benchmarks", + "pallet-xcm-transactor", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "precompile-utils 0.1.1", + "rlp", + "scale-info", + "serde", + "session-keys-primitives", + "sha3", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-slots", + "sp-core", + "sp-debug-derive", + "sp-genesis-builder", + "sp-inherents", + "sp-io", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "sp-weights", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "strum", + "strum_macros", + "substrate-wasm-builder", + "xcm-primitives 0.1.0", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "nalgebra" +version = "0.32.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ea4908d4f23254adda3daa60ffef0f1ac7b8c3e9a864cf3cc154b251908a2ef" +dependencies = [ + "approx", + "matrixmultiply", + "nalgebra-macros", + "num-complex", + "num-rational", + "num-traits", + "simba", + "typenum", +] + +[[package]] +name = "nalgebra-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "nimbus-primitives" +version = "0.9.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "async-trait", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + +[[package]] +name = "nohash-hasher" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451" + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23c6602fda94a57c990fe0df199a035d83576b496aa29f4e634a8ac6004e68a6" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec 0.7.4", + "itoa", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d869c01cc0c455284163fd0092f1f93835385ccab5a98a0dcc497b2f8bf055a9" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "num_enum" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +dependencies = [ + "num_enum_derive 0.5.11", +] + +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive 0.7.2", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "object" +version = "0.30.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03b4680b86d9cfafba8fc491dc9b6df26b68cf40e9e6cd73909194759a63c385" +dependencies = [ + "crc32fast", + "hashbrown 0.13.2", + "indexmap 1.9.3", + "memchr", +] + +[[package]] +name = "object" +version = "0.32.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "opaque-debug" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" + +[[package]] +name = "orml-traits" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.7.2#f90f4de88986571e24ea3c027b9c09a4b732ee1f" +dependencies = [ + "frame-support", + "impl-trait-for-tuples", + "num-traits", + "orml-utilities", + "parity-scale-codec", + "paste", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", +] + +[[package]] +name = "orml-utilities" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.7.2#f90f4de88986571e24ea3c027b9c09a4b732ee1f" +dependencies = [ + "frame-support", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "orml-xcm-support" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.7.2#f90f4de88986571e24ea3c027b9c09a4b732ee1f" +dependencies = [ + "frame-support", + "orml-traits", + "parity-scale-codec", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "orml-xtokens" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/open-runtime-module-library?branch=moonbeam-polkadot-v1.7.2#f90f4de88986571e24ea3c027b9c09a4b732ee1f" +dependencies = [ + "frame-support", + "frame-system", + "log", + "orml-traits", + "orml-xcm-support", + "pallet-xcm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "pallet-asset-conversion" +version = "10.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-asset-manager" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-asset-rate" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-asset-tx-payment" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-transaction-payment", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-assets" +version = "29.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-async-backing" +version = "0.9.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "cumulus-pallet-parachain-system", + "cumulus-primitives-core", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-consensus-slots", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-author-inherent" +version = "0.9.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-author-mapping" +version = "2.0.5" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "serde", + "session-keys-primitives", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-author-slot-filter" +version = "0.9.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-authority-discovery" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "pallet-session", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-authority-discovery", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-authorship" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-babe" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-application-crypto", + "sp-consensus-babe", + "sp-core", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-balances" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-broker" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bitvec", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-collator-selection" +version = "9.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "rand 0.8.5", + "scale-info", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-collective" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-conviction-voting" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "assert_matches", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-crowdloan-rewards" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/crowdloan-rewards?branch=moonbeam-polkadot-v1.7.2#0803fcfe6abdb966b989fd9ef8c22f007e24a232" +dependencies = [ + "ed25519-dalek 1.0.1", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "pallet-utility", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-trie", +] + +[[package]] +name = "pallet-election-provider-multi-phase" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-election-provider-support-benchmarking", + "parity-scale-codec", + "rand 0.8.5", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-npos-elections", + "sp-runtime", + "sp-std", + "strum", +] + +[[package]] +name = "pallet-election-provider-support-benchmarking" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-system", + "parity-scale-codec", + "sp-npos-elections", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-emergency-para-xcm" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "cumulus-pallet-parachain-system", + "cumulus-primitives-core", + "frame-support", + "frame-system", + "log", + "pallet-message-queue", + "parity-scale-codec", + "polkadot-parachain-primitives", + "scale-info", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.0", +] + +[[package]] +name = "pallet-erc20-xcm-bridge" +version = "1.0.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "environmental", + "ethereum-types", + "fp-evm", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "pallet-ethereum" +version = "4.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "environmental", + "ethereum", + "ethereum-types", + "evm", + "fp-consensus", + "fp-ethereum", + "fp-evm", + "fp-rpc", + "fp-storage", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-ethereum-xcm" +version = "1.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "ethereum", + "ethereum-types", + "fp-ethereum", + "fp-evm", + "fp-rpc", + "fp-self-contained", + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "rlp", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm" +version = "6.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "environmental", + "evm", + "fp-account", + "fp-evm", + "frame-benchmarking", + "frame-support", + "frame-system", + "hash-db", + "hex", + "hex-literal 0.4.1", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "rlp", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-chain-id" +version = "1.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "pallet-evm-precompile-author-mapping" +version = "0.2.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "num_enum 0.5.11", + "pallet-author-mapping", + "pallet-evm", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-balances-erc20" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "slices", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-batch" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "slices", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-blake2" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", +] + +[[package]] +name = "pallet-evm-precompile-bn128" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "sp-core", + "substrate-bn", +] + +[[package]] +name = "pallet-evm-precompile-call-permit" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "slices", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-collective" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-collective", + "pallet-evm", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "slices", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompile-conviction-voting" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-conviction-voting", + "pallet-evm", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-crowdloan-rewards" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-crowdloan-rewards", + "pallet-evm", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-dispatch" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "frame-support", + "pallet-evm", + "parity-scale-codec", + "sp-runtime", +] + +[[package]] +name = "pallet-evm-precompile-gmp" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "orml-traits", + "orml-xtokens", + "pallet-evm", + "pallet-xcm", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "slices", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompile-identity" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "enumflags2", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "pallet-evm", + "pallet-identity", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-modexp" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "num", +] + +[[package]] +name = "pallet-evm-precompile-parachain-staking" +version = "1.0.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-parachain-staking", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-consensus-slots", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-preimage" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-preimage", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-proxy" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-balances", + "pallet-evm", + "pallet-proxy", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-randomness" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "num_enum 0.5.11", + "pallet-evm", + "pallet-randomness", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-referenda" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-referenda", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-registry" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "pallet-evm", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-relay-encoder" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-staking", + "pallet-xcm-transactor", + "parity-scale-codec", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompile-relay-verifier" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "fp-evm", + "frame-support", + "frame-system", + "moonbeam-runtime-common 0.8.0-dev (git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902)", + "pallet-evm", + "pallet-precompile-benchmarks", + "pallet-relay-storage-roots", + "parity-scale-codec", + "precompile-utils 0.1.1", + "scale-info", + "sp-core", + "sp-std", + "storage-proof-primitives", +] + +[[package]] +name = "pallet-evm-precompile-sha3fips" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "tiny-keccak", +] + +[[package]] +name = "pallet-evm-precompile-simple" +version = "2.0.0-dev" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "ripemd", + "sp-io", +] + +[[package]] +name = "pallet-evm-precompile-storage-cleaner" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "pallet-evm", + "parity-scale-codec", + "precompile-utils 0.1.0", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-evm-precompile-xcm-transactor" +version = "0.2.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-evm", + "pallet-xcm-transactor", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompile-xcm-utils" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "num_enum 0.5.11", + "pallet-evm", + "pallet-xcm", + "parity-scale-codec", + "precompile-utils 0.1.1", + "sp-core", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompile-xtokens" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "orml-xtokens", + "pallet-evm", + "precompile-utils 0.1.1", + "rustc-hex", + "sp-core", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "pallet-evm-precompileset-assets-erc20" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "fp-evm", + "frame-support", + "frame-system", + "log", + "num_enum 0.5.11", + "pallet-assets", + "pallet-balances", + "pallet-evm", + "pallet-timestamp", + "parity-scale-codec", + "paste", + "precompile-utils 0.1.1", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-fast-unstake" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-identity" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "enumflags2", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-maintenance-mode" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.0", +] + +[[package]] +name = "pallet-message-queue" +version = "31.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "environmental", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", +] + +[[package]] +name = "pallet-migrations" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "xcm-primitives 0.1.0", +] + +[[package]] +name = "pallet-moonbeam-lazy-migrations" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-assets", + "pallet-balances", + "pallet-evm", + "pallet-scheduler", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-moonbeam-orbiters" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-multisig" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-parachain-staking" +version = "3.0.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "serde", + "sp-consensus-slots", + "sp-runtime", + "sp-std", + "substrate-fixed", +] + +[[package]] +name = "pallet-precompile-benchmarks" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "frame-benchmarking", + "frame-support", + "frame-system", + "pallet-relay-storage-roots", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-std", + "storage-proof-primitives", +] + +[[package]] +name = "pallet-preimage" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-proxy" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-proxy-genesis-companion" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "frame-support", + "frame-system", + "pallet-proxy", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-randomness" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "environmental", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "schnorrkel", + "serde", + "session-keys-primitives", + "sp-consensus-babe", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-referenda" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "assert_matches", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-relay-storage-roots" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "cumulus-pallet-parachain-system", + "cumulus-primitives-core", + "environmental", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex", + "log", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-root-testing" +version = "4.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-scheduler" +version = "29.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", +] + +[[package]] +name = "pallet-session" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-timestamp", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-state-machine", + "sp-std", + "sp-trie", +] + +[[package]] +name = "pallet-society" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "rand_chacha 0.2.2", + "scale-info", + "sp-arithmetic", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-staking" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "log", + "pallet-authorship", + "pallet-session", + "parity-scale-codec", + "rand_chacha 0.2.2", + "scale-info", + "serde", + "sp-application-crypto", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "pallet-staking-reward-fn" +version = "19.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "log", + "sp-arithmetic", +] + +[[package]] +name = "pallet-sudo" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-timestamp" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-inherents", + "sp-io", + "sp-runtime", + "sp-std", + "sp-storage", + "sp-timestamp", +] + +[[package]] +name = "pallet-transaction-payment" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[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.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "pallet-transaction-payment", + "parity-scale-codec", + "sp-api", + "sp-runtime", + "sp-weights", +] + +[[package]] +name = "pallet-treasury" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-utility" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-vesting" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-whitelist" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "pallet-xcm" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bounded-collections", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "pallet-balances", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "pallet-xcm-benchmarks" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "parity-scale-codec", + "scale-info", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "pallet-xcm-transactor" +version = "0.2.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "frame-benchmarking", + "frame-support", + "frame-system", + "log", + "orml-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-primitives 0.1.1", +] + +[[package]] +name = "parachains-common" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "cumulus-primitives-utility", + "frame-support", + "frame-system", + "log", + "pallet-asset-tx-payment", + "pallet-assets", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-message-queue", + "pallet-xcm", + "parity-scale-codec", + "polkadot-primitives", + "scale-info", + "sp-consensus-aura", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-executor", + "substrate-wasm-builder", +] + +[[package]] +name = "parity-scale-codec" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "881331e34fa842a2fb61cc2db9643a8fedc615e47cfcc52597d1af0db9a7e8fe" +dependencies = [ + "arrayvec 0.7.4", + "bitvec", + "byte-slice-cast", + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be30eaf4b0a9fba5336683b38de57bb86d179a35862ba6bfcf57625d006bde5b" +dependencies = [ + "proc-macro-crate 2.0.0", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "parity-wasm" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1ad0aff30c1da14b1254fcb2af73e1fa9a28670e584a626f53a369d0e157304" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-targets 0.48.5", +] + +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + +[[package]] +name = "pbkdf2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d95f5254224e617595d2cc3cc73ff0a5eaf2637519e25f03388154e9378b6ffa" +dependencies = [ + "crypto-mac 0.11.0", +] + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "pin-project-lite" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "pkg-config" +version = "0.3.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" + +[[package]] +name = "platforms" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" + +[[package]] +name = "polkadot-core-primitives" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "polkadot-parachain-primitives" +version = "6.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bounded-collections", + "derive_more", + "parity-scale-codec", + "polkadot-core-primitives", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", + "sp-weights", +] + +[[package]] +name = "polkadot-primitives" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bitvec", + "hex-literal 0.4.1", + "log", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-authority-discovery", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "polkadot-runtime-common" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bitvec", + "frame-benchmarking", + "frame-election-provider-support", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "libsecp256k1", + "log", + "pallet-asset-rate", + "pallet-authorship", + "pallet-babe", + "pallet-balances", + "pallet-broker", + "pallet-election-provider-multi-phase", + "pallet-fast-unstake", + "pallet-identity", + "pallet-session", + "pallet-staking", + "pallet-staking-reward-fn", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-treasury", + "pallet-vesting", + "pallet-xcm-benchmarks", + "parity-scale-codec", + "polkadot-primitives", + "polkadot-runtime-parachains", + "rustc-hex", + "scale-info", + "serde", + "serde_derive", + "slot-range-helper", + "sp-api", + "sp-core", + "sp-inherents", + "sp-io", + "sp-npos-elections", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "static_assertions", +] + +[[package]] +name = "polkadot-runtime-metrics" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bs58", + "frame-benchmarking", + "parity-scale-codec", + "polkadot-primitives", + "sp-std", + "sp-tracing", +] + +[[package]] +name = "polkadot-runtime-parachains" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bitflags 1.3.2", + "bitvec", + "derive_more", + "frame-benchmarking", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-authority-discovery", + "pallet-authorship", + "pallet-babe", + "pallet-balances", + "pallet-broker", + "pallet-message-queue", + "pallet-session", + "pallet-staking", + "pallet-timestamp", + "pallet-vesting", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-primitives", + "polkadot-runtime-metrics", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rustc-hex", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-arithmetic", + "sp-core", + "sp-inherents", + "sp-io", + "sp-keystore", + "sp-runtime", + "sp-session", + "sp-staking", + "sp-std", + "staging-xcm", + "staging-xcm-executor", + "static_assertions", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precompile-utils" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "environmental", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "hex", + "impl-trait-for-tuples", + "log", + "num_enum 0.7.2", + "pallet-evm", + "parity-scale-codec", + "precompile-utils-macro 0.1.0", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", +] + +[[package]] +name = "precompile-utils" +version = "0.1.1" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "affix", + "environmental", + "evm", + "fp-evm", + "frame-support", + "frame-system", + "hex", + "impl-trait-for-tuples", + "log", + "num_enum 0.5.11", + "pallet-evm", + "parity-scale-codec", + "paste", + "precompile-utils-macro 0.1.1", + "sha3", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", +] + +[[package]] +name = "precompile-utils-macro" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/frontier?branch=moonbeam-polkadot-v1.7.2#5d6bf0c78d1d325d4eea6f9593e9a11da18a1ea8" +dependencies = [ + "case", + "num_enum 0.7.2", + "prettyplease 0.2.17", + "proc-macro2", + "quote", + "sp-core-hashing", + "syn 1.0.109", +] + +[[package]] +name = "precompile-utils-macro" +version = "0.1.1" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "case", + "num_enum 0.5.11", + "prettyplease 0.1.25", + "proc-macro2", + "quote", + "sha3", + "syn 1.0.109", +] + +[[package]] +name = "prettyplease" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86" +dependencies = [ + "proc-macro2", + "syn 1.0.109", +] + +[[package]] +name = "prettyplease" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3928fb5db768cb86f891ff014f0144589297e3c6a1aba6ed7cecfdace270c7" +dependencies = [ + "proc-macro2", + "syn 2.0.58", +] + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "impl-rlp", + "impl-serde 0.4.0", + "scale-info", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit 0.20.7", +] + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit 0.21.1", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro-warning" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "834da187cfe638ae8abb0203f0b33e5ccdb02a28e7199f2f47b3e2754f50edca" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.14", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "ref-cast" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4846d4c50d1721b1a3bef8af76924eef20d5e723647333798c1b519b3a9473f" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fddb4f8d99b0a2ebafc65a87a69a7b9875e4b1ae1f00db265d300ef7f28bccc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata 0.4.6", + "regex-syntax 0.8.3", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", +] + +[[package]] +name = "regex-automata" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax 0.8.3", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac 0.12.1", + "subtle", +] + +[[package]] +name = "ring" +version = "0.1.0" +source = "git+https://github.com/w3f/ring-proof#b273d33f9981e2bb3375ab45faeb537f7ee35224" +dependencies = [ + "ark-ec", + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "blake2", + "common", + "fflonk", + "merlin", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rlp-derive", + "rustc-hex", +] + +[[package]] +name = "rlp-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e33d7b2abe0c340d8797fe2907d3f20d3b5ea5908683618bfe80df7f621f672a" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.22", +] + +[[package]] +name = "rustix" +version = "0.36.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "305efbd14fde4139eb501df5f136994bb520b033fa9fbdce287507dc23b8c7ed" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + +[[package]] +name = "rustix" +version = "0.38.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +dependencies = [ + "bitflags 2.5.0", + "errno", + "libc", + "linux-raw-sys 0.4.13", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustversion" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" + +[[package]] +name = "ryu" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" + +[[package]] +name = "safe_arch" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f398075ce1e6a179b46f51bd88d0598b92b00d3551f1a2d4ac49e771b56ac354" +dependencies = [ + "bytemuck", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "scale-info" +version = "2.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c453e59a955f81fb62ee5d596b450383d699f152d350e9d23a0db2adb78e4c0" +dependencies = [ + "bitvec", + "cfg-if", + "derive_more", + "parity-scale-codec", + "scale-info-derive", + "serde", +] + +[[package]] +name = "scale-info-derive" +version = "2.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18cf6c6447f813ef19eb450e985bcce6705f9ce7660db221b59093d15c79c4b7" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "schnellru" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772575a524feeb803e5b0fcbc6dd9f367e579488197c94c6e4023aad2305774d" +dependencies = [ + "ahash 0.8.11", + "cfg-if", + "hashbrown 0.13.2", +] + +[[package]] +name = "schnorrkel" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de18f6d8ba0aad7045f5feae07ec29899c1112584a38509a84ad7b04451eaa0" +dependencies = [ + "aead", + "arrayref", + "arrayvec 0.7.4", + "curve25519-dalek 4.1.2", + "getrandom_or_panic", + "merlin", + "rand_core 0.6.4", + "serde_bytes", + "sha2 0.10.8", + "subtle", + "zeroize", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "scratch" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3cf7c11c38cb994f3d40e8a8cde3bbd1f72a435e4c49e85d6553d8312306152" + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "secp256k1" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d24b59d129cdadea20aea4fb2352fa053712e5d713eee47d700cd4b2bc002f10" +dependencies = [ + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d1746aae42c19d583c3c1a8c646bfad910498e2051c551a7f2e3c0c9fbb7eb" +dependencies = [ + "cc", +] + +[[package]] +name = "secrecy" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bd1c54ea06cfd2f6b63219704de0b9b4f72dcc2b8fdef820be6cd799780e91e" +dependencies = [ + "zeroize", +] + +[[package]] +name = "semver" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +dependencies = [ + "serde", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_bytes" +version = "0.11.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "serde_json" +version = "1.0.115" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_spanned" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +dependencies = [ + "serde", +] + +[[package]] +name = "session-keys-primitives" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "async-trait", + "frame-support", + "nimbus-primitives", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-consensus-babe", + "sp-core", + "sp-inherents", + "sp-keystore", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "simba" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "061507c94fc6ab4ba1c9a0305018408e312e17c041eb63bef8aa726fa33aceae" +dependencies = [ + "approx", + "num-complex", + "num-traits", + "paste", + "wide", +] + +[[package]] +name = "simple-mermaid" +version = "0.1.0" +source = "git+https://github.com/kianenigma/simple-mermaid.git?rev=e48b187bcfd5cc75111acd9d241f1bd36604344b#e48b187bcfd5cc75111acd9d241f1bd36604344b" + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "slices" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2086e458a369cdca838e9f6ed04b4cc2e3ce636d99abb80c9e2eada107749cf" +dependencies = [ + "faster-hex", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "slot-range-helper" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "enumn", + "parity-scale-codec", + "paste", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "sp-api" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec", + "scale-info", + "sp-api-proc-macro", + "sp-core", + "sp-externalities", + "sp-metadata-ir", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", + "sp-version", + "thiserror", +] + +[[package]] +name = "sp-api-proc-macro" +version = "15.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "Inflector", + "blake2", + "expander", + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "sp-application-crypto" +version = "30.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-std", +] + +[[package]] +name = "sp-arithmetic" +version = "23.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "integer-sqrt", + "num-traits", + "parity-scale-codec", + "scale-info", + "serde", + "sp-std", + "static_assertions", +] + +[[package]] +name = "sp-ark-bls12-381" +version = "0.4.2" +source = "git+https://github.com/paritytech/arkworks-substrate#caa2eed74beb885dd07c7db5f916f2281dad818f" +dependencies = [ + "ark-bls12-381-ext", + "sp-crypto-ec-utils", +] + +[[package]] +name = "sp-ark-ed-on-bls12-381-bandersnatch" +version = "0.4.2" +source = "git+https://github.com/paritytech/arkworks-substrate#caa2eed74beb885dd07c7db5f916f2281dad818f" +dependencies = [ + "ark-ed-on-bls12-381-bandersnatch-ext", + "sp-crypto-ec-utils", +] + +[[package]] +name = "sp-authority-discovery" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-block-builder" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "sp-api", + "sp-inherents", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-consensus-aura" +version = "0.32.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "async-trait", + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-application-crypto", + "sp-consensus-slots", + "sp-inherents", + "sp-runtime", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "sp-consensus-babe" +version = "0.32.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "async-trait", + "parity-scale-codec", + "scale-info", + "serde", + "sp-api", + "sp-application-crypto", + "sp-consensus-slots", + "sp-core", + "sp-inherents", + "sp-runtime", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "sp-consensus-slots" +version = "0.32.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-std", + "sp-timestamp", +] + +[[package]] +name = "sp-core" +version = "28.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "array-bytes", + "bandersnatch_vrfs", + "bip39", + "bitflags 1.3.2", + "blake2", + "bounded-collections", + "bs58", + "dyn-clonable", + "ed25519-zebra", + "futures", + "hash-db", + "hash256-std-hasher", + "impl-serde 0.4.0", + "itertools", + "libsecp256k1", + "log", + "merlin", + "parity-scale-codec", + "parking_lot", + "paste", + "primitive-types", + "rand 0.8.5", + "scale-info", + "schnorrkel", + "secp256k1", + "secrecy", + "serde", + "sp-crypto-hashing", + "sp-debug-derive", + "sp-externalities", + "sp-runtime-interface", + "sp-std", + "sp-storage", + "ss58-registry", + "substrate-bip39", + "thiserror", + "tracing", + "w3f-bls", + "zeroize", +] + +[[package]] +name = "sp-core-hashing" +version = "15.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "sp-crypto-hashing", +] + +[[package]] +name = "sp-crypto-ec-utils" +version = "0.10.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "ark-bls12-377", + "ark-bls12-377-ext", + "ark-bls12-381", + "ark-bls12-381-ext", + "ark-bw6-761", + "ark-bw6-761-ext", + "ark-ec", + "ark-ed-on-bls12-377", + "ark-ed-on-bls12-377-ext", + "ark-ed-on-bls12-381-bandersnatch", + "ark-ed-on-bls12-381-bandersnatch-ext", + "ark-scale", + "sp-runtime-interface", + "sp-std", +] + +[[package]] +name = "sp-crypto-hashing" +version = "0.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "blake2b_simd", + "byteorder", + "digest 0.10.7", + "sha2 0.10.8", + "sha3", + "twox-hash", +] + +[[package]] +name = "sp-crypto-hashing-proc-macro" +version = "0.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "quote", + "sp-crypto-hashing", + "syn 2.0.58", +] + +[[package]] +name = "sp-debug-derive" +version = "14.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "sp-externalities" +version = "0.25.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "environmental", + "parity-scale-codec", + "sp-std", + "sp-storage", +] + +[[package]] +name = "sp-genesis-builder" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "serde_json", + "sp-api", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-inherents" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "async-trait", + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", + "thiserror", +] + +[[package]] +name = "sp-io" +version = "30.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bytes", + "ed25519-dalek 2.1.1", + "libsecp256k1", + "log", + "parity-scale-codec", + "rustversion", + "secp256k1", + "sp-core", + "sp-crypto-hashing", + "sp-externalities", + "sp-keystore", + "sp-runtime-interface", + "sp-state-machine", + "sp-std", + "sp-tracing", + "sp-trie", + "tracing", + "tracing-core", +] + +[[package]] +name = "sp-keystore" +version = "0.34.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "parking_lot", + "sp-core", + "sp-externalities", + "thiserror", +] + +[[package]] +name = "sp-maybe-compressed-blob" +version = "11.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "thiserror", + "zstd", +] + +[[package]] +name = "sp-metadata-ir" +version = "0.6.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-metadata", + "parity-scale-codec", + "scale-info", + "sp-std", +] + +[[package]] +name = "sp-npos-elections" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "serde", + "sp-arithmetic", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-offchain" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "sp-api", + "sp-core", + "sp-runtime", +] + +[[package]] +name = "sp-panic-handler" +version = "13.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "backtrace", + "lazy_static", + "regex", +] + +[[package]] +name = "sp-runtime" +version = "31.0.1" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "docify", + "either", + "hash256-std-hasher", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "paste", + "rand 0.8.5", + "scale-info", + "serde", + "simple-mermaid", + "sp-application-crypto", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-std", + "sp-weights", +] + +[[package]] +name = "sp-runtime-interface" +version = "24.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bytes", + "impl-trait-for-tuples", + "parity-scale-codec", + "primitive-types", + "sp-externalities", + "sp-runtime-interface-proc-macro", + "sp-std", + "sp-storage", + "sp-tracing", + "sp-wasm-interface", + "static_assertions", +] + +[[package]] +name = "sp-runtime-interface-proc-macro" +version = "17.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "Inflector", + "expander", + "proc-macro-crate 3.1.0", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "sp-session" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-api", + "sp-core", + "sp-keystore", + "sp-runtime", + "sp-staking", + "sp-std", +] + +[[package]] +name = "sp-staking" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "impl-trait-for-tuples", + "parity-scale-codec", + "scale-info", + "serde", + "sp-core", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "sp-state-machine" +version = "0.35.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "hash-db", + "log", + "parity-scale-codec", + "parking_lot", + "rand 0.8.5", + "smallvec", + "sp-core", + "sp-externalities", + "sp-panic-handler", + "sp-std", + "sp-trie", + "thiserror", + "tracing", + "trie-db", +] + +[[package]] +name = "sp-std" +version = "14.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" + +[[package]] +name = "sp-storage" +version = "19.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "impl-serde 0.4.0", + "parity-scale-codec", + "ref-cast", + "serde", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "sp-timestamp" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "async-trait", + "parity-scale-codec", + "sp-inherents", + "sp-runtime", + "sp-std", + "thiserror", +] + +[[package]] +name = "sp-tracing" +version = "16.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "sp-std", + "tracing", + "tracing-core", + "tracing-subscriber", +] + +[[package]] +name = "sp-transaction-pool" +version = "26.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "sp-api", + "sp-runtime", +] + +[[package]] +name = "sp-trie" +version = "29.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "ahash 0.8.11", + "hash-db", + "lazy_static", + "memory-db", + "nohash-hasher", + "parity-scale-codec", + "parking_lot", + "rand 0.8.5", + "scale-info", + "schnellru", + "sp-core", + "sp-externalities", + "sp-std", + "thiserror", + "tracing", + "trie-db", + "trie-root", +] + +[[package]] +name = "sp-version" +version = "29.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "impl-serde 0.4.0", + "parity-scale-codec", + "parity-wasm", + "scale-info", + "serde", + "sp-crypto-hashing-proc-macro", + "sp-runtime", + "sp-std", + "sp-version-proc-macro", + "thiserror", +] + +[[package]] +name = "sp-version-proc-macro" +version = "13.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "parity-scale-codec", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "sp-wasm-interface" +version = "20.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "anyhow", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "sp-std", + "wasmtime", +] + +[[package]] +name = "sp-weights" +version = "27.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "bounded-collections", + "parity-scale-codec", + "scale-info", + "serde", + "smallvec", + "sp-arithmetic", + "sp-debug-derive", + "sp-std", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "ss58-registry" +version = "1.47.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4743ce898933fbff7bbf414f497c459a782d496269644b3d650a398ae6a487ba" +dependencies = [ + "Inflector", + "num-format", + "proc-macro2", + "quote", + "serde", + "serde_json", + "unicode-xid", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "staging-parachain-info" +version = "0.7.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "frame-system", + "parity-scale-codec", + "scale-info", + "sp-runtime", + "sp-std", +] + +[[package]] +name = "staging-xcm" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "array-bytes", + "bounded-collections", + "derivative", + "environmental", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "scale-info", + "serde", + "sp-weights", + "xcm-procedural", +] + +[[package]] +name = "staging-xcm-builder" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "log", + "pallet-transaction-payment", + "parity-scale-codec", + "polkadot-parachain-primitives", + "scale-info", + "sp-arithmetic", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", + "staging-xcm-executor", +] + +[[package]] +name = "staging-xcm-executor" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "environmental", + "frame-benchmarking", + "frame-support", + "impl-trait-for-tuples", + "log", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "sp-weights", + "staging-xcm", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "storage-proof-primitives" +version = "0.1.0" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "frame-support", + "sp-core", + "sp-runtime", + "sp-state-machine", + "sp-std", + "sp-trie", +] + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn 1.0.109", +] + +[[package]] +name = "substrate-bip39" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a7590dc041b9bc2825e52ce5af8416c73dbe9d0654402bfd4b4941938b94d8f" +dependencies = [ + "hmac 0.11.0", + "pbkdf2", + "schnorrkel", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "substrate-bn" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b5bbfa79abbae15dd642ea8176a21a635ff3c00059961d1ea27ad04e5b441c" +dependencies = [ + "byteorder", + "crunchy", + "lazy_static", + "rand 0.8.5", + "rustc-hex", +] + +[[package]] +name = "substrate-fixed" +version = "0.5.9" +source = "git+https://github.com/encointer/substrate-fixed#879c58bcc6fd676a74315dcd38b598f28708b0b5" +dependencies = [ + "parity-scale-codec", + "scale-info", + "substrate-typenum", +] + +[[package]] +name = "substrate-typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f0091e93c2c75b233ae39424c52cb8a662c0811fb68add149e20e5d7e8a788" +dependencies = [ + "parity-scale-codec", + "scale-info", +] + +[[package]] +name = "substrate-wasm-builder" +version = "17.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "build-helper", + "cargo_metadata", + "console", + "filetime", + "parity-wasm", + "sp-maybe-compressed-blob", + "strum", + "tempfile", + "toml", + "walkdir", + "wasm-opt", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "target-lexicon" +version = "0.12.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" + +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix 0.38.32", + "windows-sys 0.52.0", +] + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "thread_local" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" +dependencies = [ + "cfg-if", + "once_cell", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "toml" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit 0.22.9", +] + +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap 2.2.6", + "toml_datetime", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.22.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +dependencies = [ + "indexmap 2.2.6", + "serde", + "serde_spanned", + "toml_datetime", + "winnow 0.6.5", +] + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f751112709b4e791d8ce53e32c4ed2d353565a795ce84da2285393f41557bdf2" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-serde" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" +dependencies = [ + "serde", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" +dependencies = [ + "ansi_term", + "chrono", + "lazy_static", + "matchers", + "regex", + "serde", + "serde_json", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", + "tracing-serde", +] + +[[package]] +name = "trie-db" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff28e0f815c2fea41ebddf148e008b077d2faddb026c9555b29696114d602642" +dependencies = [ + "hash-db", + "hashbrown 0.13.2", + "log", + "rustc-hex", + "smallvec", +] + +[[package]] +name = "trie-root" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4ed310ef5ab98f5fa467900ed906cb9232dd5376597e00fd4cba2a449d06c0b" +dependencies = [ + "hash-db", +] + +[[package]] +name = "tt-call" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f195fd851901624eee5a58c4bb2b4f06399148fcd0ed336e6f1cb60a9881df" + +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "digest 0.10.7", + "rand 0.7.3", + "static_assertions", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "w3f-bls" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7335e4c132c28cc43caef6adb339789e599e39adbe78da0c4d547fad48cbc331" +dependencies = [ + "ark-bls12-377", + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-serialize-derive", + "arrayref", + "constcat", + "digest 0.10.7", + "rand 0.8.5", + "rand_chacha 0.3.1", + "rand_core 0.6.4", + "sha2 0.10.8", + "sha3", + "thiserror", + "zeroize", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.58", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "wasm-opt" +version = "0.116.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fd87a4c135535ffed86123b6fb0f0a5a0bc89e50416c942c5f0662c645f679c" +dependencies = [ + "anyhow", + "libc", + "strum", + "strum_macros", + "tempfile", + "thiserror", + "wasm-opt-cxx-sys", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-cxx-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c57b28207aa724318fcec6575fe74803c23f6f266fce10cbc9f3f116762f12e" +dependencies = [ + "anyhow", + "cxx", + "cxx-build", + "wasm-opt-sys", +] + +[[package]] +name = "wasm-opt-sys" +version = "0.116.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a1cce564dc768dacbdb718fc29df2dba80bd21cb47d8f77ae7e3d95ceb98cbe" +dependencies = [ + "anyhow", + "cc", + "cxx", + "cxx-build", +] + +[[package]] +name = "wasmparser" +version = "0.102.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48134de3d7598219ab9eaf6b91b15d8e50d31da76b8519fe4ecfcec2cf35104b" +dependencies = [ + "indexmap 1.9.3", + "url", +] + +[[package]] +name = "wasmtime" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f907fdead3153cb9bfb7a93bbd5b62629472dc06dee83605358c64c52ed3dda9" +dependencies = [ + "anyhow", + "bincode", + "cfg-if", + "indexmap 1.9.3", + "libc", + "log", + "object 0.30.4", + "once_cell", + "paste", + "psm", + "serde", + "target-lexicon", + "wasmparser", + "wasmtime-environ", + "wasmtime-jit", + "wasmtime-runtime", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-asm-macros" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3b9daa7c14cd4fa3edbf69de994408d5f4b7b0959ac13fa69d465f6597f810d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "wasmtime-environ" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a990198cee4197423045235bf89d3359e69bd2ea031005f4c2d901125955c949" +dependencies = [ + "anyhow", + "cranelift-entity", + "gimli 0.27.3", + "indexmap 1.9.3", + "log", + "object 0.30.4", + "serde", + "target-lexicon", + "thiserror", + "wasmparser", + "wasmtime-types", +] + +[[package]] +name = "wasmtime-jit" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de48df552cfca1c9b750002d3e07b45772dd033b0b206d5c0968496abf31244" +dependencies = [ + "addr2line 0.19.0", + "anyhow", + "bincode", + "cfg-if", + "cpp_demangle", + "gimli 0.27.3", + "log", + "object 0.30.4", + "rustc-demangle", + "serde", + "target-lexicon", + "wasmtime-environ", + "wasmtime-jit-icache-coherence", + "wasmtime-runtime", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-jit-debug" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e0554b84c15a27d76281d06838aed94e13a77d7bf604bbbaf548aa20eb93846" +dependencies = [ + "once_cell", +] + +[[package]] +name = "wasmtime-jit-icache-coherence" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecae978b13f7f67efb23bd827373ace4578f2137ec110bbf6a4a7cde4121bbd" +dependencies = [ + "cfg-if", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-runtime" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658cf6f325232b6760e202e5255d823da5e348fdea827eff0a2a22319000b441" +dependencies = [ + "anyhow", + "cc", + "cfg-if", + "indexmap 1.9.3", + "libc", + "log", + "mach", + "memfd", + "memoffset", + "paste", + "rand 0.8.5", + "rustix 0.36.17", + "wasmtime-asm-macros", + "wasmtime-environ", + "wasmtime-jit-debug", + "windows-sys 0.45.0", +] + +[[package]] +name = "wasmtime-types" +version = "8.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4f6fffd2a1011887d57f07654dd112791e872e3ff4a2e626aee8059ee17f06f" +dependencies = [ + "cranelift-entity", + "serde", + "thiserror", + "wasmparser", +] + +[[package]] +name = "wide" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89beec544f246e679fc25490e3f8e08003bc4bf612068f325120dad4cea02c1c" +dependencies = [ + "bytemuck", + "safe_arch", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.4", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm 0.52.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "xcm-primitives" +version = "0.1.0" +source = "git+https://github.com/Moonsong-Labs/moonkit?branch=moonbeam-polkadot-v1.7.2#bca9e28b36008609860bf7970d5d7b8d361588b3" +dependencies = [ + "sp-runtime", +] + +[[package]] +name = "xcm-primitives" +version = "0.1.1" +source = "git+https://github.com/moonbeam-foundation/moonbeam?rev=runtime-2902#1a6658926de9d27441cf1e25e22cc39b805f9e67" +dependencies = [ + "cumulus-primitives-core", + "ethereum", + "ethereum-types", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex", + "impl-trait-for-tuples", + "log", + "orml-traits", + "pallet-staking", + "parity-scale-codec", + "polkadot-runtime-common", + "scale-info", + "serde", + "sha3", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", +] + +[[package]] +name = "xcm-procedural" +version = "7.0.0" +source = "git+https://github.com/moonbeam-foundation/polkadot-sdk?branch=moonbeam-polkadot-v1.7.2#2073906e7994ca069f7f68120b05474f7565b8d2" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "zerocopy" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.58", +] + +[[package]] +name = "zstd" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a27595e173641171fc74a1232b7b1c7a7cb6e18222c11e9dfb9888fa424c53c" +dependencies = [ + "zstd-safe", +] + +[[package]] +name = "zstd-safe" +version = "6.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee98ffd0b48ee95e6c5168188e44a54550b1564d9d530ee21d5f0eaed1069581" +dependencies = [ + "libc", + "zstd-sys", +] + +[[package]] +name = "zstd-sys" +version = "2.0.10+zstd.1.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" +dependencies = [ + "cc", + "pkg-config", +] diff --git a/tracing/2902/Cargo.toml b/tracing/2902/Cargo.toml new file mode 100644 index 00000000..d0d357dc --- /dev/null +++ b/tracing/2902/Cargo.toml @@ -0,0 +1,444 @@ +[workspace] +members = [ + "runtime/moonbase", + "runtime/moonbeam", + "runtime/moonriver", +] +resolver = "2" + +[workspace.package] +authors = ["PureStake"] +repository = "https://github.com/PureStake/moonbeam" + +[workspace.dependencies] +# Dependencies are split into 2 groups: wasm and client. +# - "wasm" dependencies requires to be no_std compatible, which often requires +# `default-features = false`. When used in a client-side crate the "std" feature should be enabled +# there if it exists. +# - "client" dependencies are only used in the client, and thus don't need to be no_std compatible. + +# Moonbeam (wasm) +account = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +evm-tracing-events = { path = "shared/primitives/rpc/evm-tracing-events", default-features = false , features = ["runtime-1600"] } +moonbeam-core-primitives = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-primitives-ext = { path = "shared/primitives/ext", default-features = false } +moonbeam-rpc-primitives-debug = { path = "shared/primitives/rpc/debug", default-features = false, features = [ + "runtime-2900", +] } +moonbeam-rpc-primitives-txpool = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +storage-proof-primitives = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } + +moonbeam-evm-tracer = { path = "shared/runtime/evm_tracer", default-features = false } +moonbeam-relay-encoder = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-runtime-common = { path = "runtime/common", default-features = false } + +moonbeam-xcm-benchmarks = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-asset-manager = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-erc20-xcm-bridge = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-ethereum-xcm = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } + +pallet-evm-precompile-author-mapping = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-balances-erc20 = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-batch = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-call-permit = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-collective = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-conviction-voting = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-crowdloan-rewards = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-gmp = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-identity = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-parachain-staking = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-preimage = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-proxy = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-randomness = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-referenda = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-registry = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-relay-encoder = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-relay-verifier = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-xcm-transactor = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-xcm-utils = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompile-xtokens = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-evm-precompileset-assets-erc20 = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-moonbeam-orbiters = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-parachain-staking = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-precompile-benchmarks = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-proxy-genesis-companion = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-xcm-transactor = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +pallet-moonbeam-lazy-migrations = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +precompile-utils = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +xcm-primitives = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } + +pallet-crowdloan-rewards = { git = "https://github.com/moonbeam-foundation/crowdloan-rewards", branch = "moonbeam-polkadot-v1.7.2", default-features = false } + +# Moonbeam (client) +moonbeam-cli = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-cli-opt = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-service = { default-features = false , git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } + +manual-xcm-rpc = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-client-evm-tracing = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-finality-rpc = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-core-debug = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-core-trace = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-core-txpool = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-core-types = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-debug = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-trace = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-rpc-txpool = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } +moonbeam-vrf = { git = "https://github.com/moonbeam-foundation/moonbeam", rev = "runtime-2902" } + +moonbase-runtime = { path = "runtime/moonbase" } +moonbeam-runtime = { path = "runtime/moonbeam" } +moonriver-runtime = { path = "runtime/moonriver" } + +frame-benchmarking = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-executive = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-support = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-system = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-system-benchmarking = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-system-rpc-runtime-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +frame-try-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-assets = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-balances = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-collective = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-conviction-voting = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-identity = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-message-queue = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-multisig = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-preimage = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-proxy = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-referenda = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-root-testing = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-scheduler = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-society = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-staking = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-sudo = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-timestamp = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-transaction-payment = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-treasury = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-utility = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-whitelist = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +parity-scale-codec = { version = "3.2.2", default-features = false, features = [ + "derive", +] } +scale-info = { version = "2.0", default-features = false, features = [ + "derive", +] } +sp-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-application-crypto = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-block-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-consensus-babe = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-consensus-slots = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-core = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-debug-derive = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-externalities = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-inherents = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-io = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-keystore = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-offchain = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-runtime-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-session = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-std = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-state-machine = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-transaction-pool = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-trie = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-version = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-weights = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +sp-genesis-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +substrate-fixed = { git = "https://github.com/encointer/substrate-fixed", default-features = false } + +# Substrate (client) +frame-benchmarking-cli = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +pallet-transaction-payment-rpc = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-basic-authorship = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-block-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-chain-spec = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-cli = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-client-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-client-db = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-consensus = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-consensus-grandpa = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-consensus-manual-seal = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-executor = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-informant = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-network = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-network-common = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-network-sync = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-offchain = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-rpc = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-rpc-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-service = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-sysinfo = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-telemetry = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-tracing = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-transaction-pool = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-transaction-pool-api = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sc-utils = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sp-blockchain = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sp-consensus = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sp-storage = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sp-timestamp = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +sp-wasm-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-build-script-utils = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-frame-rpc-system = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-prometheus-endpoint = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-test-client = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-test-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-test-runtime-client = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +substrate-wasm-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +try-runtime-cli = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } + +# Frontier (wasm) +ethereum = { version = "0.15.0", default-features = false, features = [ + "with-codec", +] } +ethereum-types = { version = "0.14", default-features = false } +evm = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +evm-gasometer = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +evm-runtime = { git = "https://github.com/moonbeam-foundation/evm", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +fp-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +fp-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +fp-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +fp-self-contained = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-ethereum = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false, features = [ + "forbid-evm-reentrancy", +] } +pallet-evm = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false, features = [ + "forbid-evm-reentrancy", +] } +pallet-evm-chain-id = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-blake2 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-bn128 = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-evm-precompile-storage-cleaner = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", default-features = false } + +# Frontier (client) +fc-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fc-db = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fc-api = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fc-mapping-sync = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fc-rpc = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2", features = [ + "rpc-binary-search-estimate", +] } +fc-rpc-core = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fc-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fp-consensus = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } +fp-storage = { git = "https://github.com/moonbeam-foundation/frontier", branch = "moonbeam-polkadot-v1.7.2" } + +# Cumulus (wasm) +cumulus-pallet-dmp-queue = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-pallet-parachain-system = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false, features = [ + "parameterized-consensus-hook", +] } +cumulus-pallet-xcm = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-pallet-xcmp-queue = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-primitives-core = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-primitives-parachain-inherent = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-primitives-timestamp = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-primitives-utility = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +cumulus-test-relay-sproof-builder = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +parachain-info = { package = "staging-parachain-info", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +parachains-common = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } + +# Cumulus (client) +cumulus-client-cli = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-collator = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-consensus-common = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-consensus-proposer = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-consensus-relay-chain = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-network = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-service = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-client-parachain-inherent = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-relay-chain-inprocess-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-relay-chain-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-relay-chain-minimal-node = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +cumulus-relay-chain-rpc-interface = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } + +# Polkadot / XCM (wasm) +orml-traits = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +orml-xcm-support = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +orml-xtokens = { git = "https://github.com/moonbeam-foundation/open-runtime-module-library", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-xcm = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-xcm-benchmarks = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +polkadot-core-primitives = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +polkadot-parachain = { package = "polkadot-parachain-primitives", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +polkadot-runtime-common = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +polkadot-runtime-parachains = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +xcm = { package = "staging-xcm", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +xcm-builder = { package = "staging-xcm-builder", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +xcm-executor = { package = "staging-xcm-executor", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2", default-features = false } + +# Polkadot / XCM (client) +#kusama-runtime = { package = "staging-kusama-runtime", git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +polkadot-cli = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +polkadot-primitives = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +#polkadot-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +polkadot-service = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +rococo-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +westend-runtime = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } +xcm-simulator = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } + +# Moonkit (wasm) +async-backing-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +moonkit-xcm-primitives = { package = "xcm-primitives", git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +nimbus-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-async-backing = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-author-inherent = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-author-mapping = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-author-slot-filter = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-emergency-para-xcm = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-maintenance-mode = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-migrations = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-randomness = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +pallet-relay-storage-roots = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } +session-keys-primitives = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2", default-features = false } + +# Moonkit (client) +nimbus-consensus = { git = "https://github.com/Moonsong-Labs/moonkit", branch = "moonbeam-polkadot-v1.7.2" } + +# Other (wasm) +affix = "0.1.2" +async-trait = { version = "0.1.42" } +blake2-rfc = { version = "0.2.18", default-features = false } +derive_more = "0.99" +environmental = { version = "1.1.2", default-features = false } +frame-metadata = { version = "16.0.0", default-features = false, features = [ + "current", +] } +hex = { version = "0.4.3", default-features = false } +hex-literal = { version = "0.3.4" } +impl-serde = { version = "0.3.1", default-features = false } +impl-trait-for-tuples = "0.2.1" +libsecp256k1 = { version = "0.7", default-features = false } +log = { version = "0.4", default-features = false } +num_enum = { version = "0.5.3", default-features = false } +paste = "1.0.6" +rlp = { version = "0.5", default-features = false } +rustc-hex = { version = "2.0.1", default-features = false } +serde = { version = "1.0.101", default-features = false } +sha3 = { version = "0.10", default-features = false } +slices = "0.2.0" +smallvec = "1.8.0" +strum = { version = "0.24", default-features = false, features = ["derive"] } +strum_macros = "0.24" + +# Other (client) + +ansi_term = "0.12.1" +assert_cmd = "2.0.10" +async-io = "1.3" +bip32 = { version = "0.5.1", default-features = false, features = ["bip39"] } +clap = { version = "4.0.9", features = ["derive"] } +clap-num = "=1.1.1" +exit-future = "0.2" +flume = "0.10.9" +futures = { version = "0.3.21" } +jsonrpsee = { version = "0.20.3", default-features = false } +maplit = "1.0.2" +nix = "0.23" +parking_lot = "0.12.0" +primitive-types = "0.12.0" +prometheus = { version = "0.13.0", default-features = false } +rand = "0.7.3" +serde_json = { version = "1.0" } +similar-asserts = "1.1.0" +tempfile = "3.2.0" +tiny-bip39 = { version = "0.8", default-features = false } +schnorrkel = { version = "0.11.4", default-features = false, features = [ + "preaudit_deprecated", +] } +tokio = { version = "1.36" } +tracing = "0.1.34" +tracing-core = "0.1.29" +trie-root = "0.15.2" +url = "2.2.2" + +# The list of dependencies below (which can be both direct and indirect dependencies) are crates +# that are suspected to be CPU-intensive, and that are unlikely to require debugging (as some of +# their debug info might be missing) or to require to be frequently recompiled. We compile these +# dependencies with `opt-level=3` even in "dev" mode in order to make "dev" mode more usable. +# The majority of these crates are cryptographic libraries. +# +# Note that this does **not** affect crates that depend on Moonbeam. In other words, if you add +# a dependency on Moonbeam, you have to copy-paste this list in your own `Cargo.toml` (assuming +# that you want the same list). This list is only relevant when running `cargo build` from within +# the Moonbeam workspace. +# +# If you see an error mentioning "profile package spec ... did not match any packages", it +# probably concerns this list. +# +# This list is ordered alphabetically. +[profile.dev.package] +blake2 = { opt-level = 3 } +blake2b_simd = { opt-level = 3 } +chacha20poly1305 = { opt-level = 3 } +cranelift-codegen = { opt-level = 3 } +cranelift-wasm = { opt-level = 3 } +crc32fast = { opt-level = 3 } +crossbeam-deque = { opt-level = 3 } +crypto-mac = { opt-level = 3 } +curve25519-dalek = { opt-level = 3 } +ed25519-zebra = { opt-level = 3 } +flate2 = { opt-level = 3 } +futures-channel = { opt-level = 3 } +hash-db = { opt-level = 3 } +hashbrown = { opt-level = 3 } +hmac = { opt-level = 3 } +httparse = { opt-level = 3 } +integer-sqrt = { opt-level = 3 } +k256 = { opt-level = 3 } +keccak = { opt-level = 3 } +libm = { opt-level = 3 } +librocksdb-sys = { opt-level = 3 } +libsecp256k1 = { opt-level = 3 } +libz-sys = { opt-level = 3 } +mio = { opt-level = 3 } +nalgebra = { opt-level = 3 } +num-bigint = { opt-level = 3 } +parking_lot = { opt-level = 3 } +parking_lot_core = { opt-level = 3 } +percent-encoding = { opt-level = 3 } +primitive-types = { opt-level = 3 } +ring = { opt-level = 3 } +rustls = { opt-level = 3 } +secp256k1 = { opt-level = 3 } +sha2 = { opt-level = 3 } +sha3 = { opt-level = 3 } +smallvec = { opt-level = 3 } +snow = { opt-level = 3 } +twox-hash = { opt-level = 3 } +uint = { opt-level = 3 } +wasmi = { opt-level = 3 } +x25519-dalek = { opt-level = 3 } +yamux = { opt-level = 3 } +zeroize = { opt-level = 3 } + +# make sure dev builds with backtrace do +# not slow us down +[profile.dev.package.backtrace] +inherits = "release" + +[profile.production] +codegen-units = 1 +incremental = false +inherits = "release" +lto = true + +[profile.release] +debug-assertions = true # Enable debug-assert! for non-production profiles +opt-level = 3 +# Moonbeam runtime requires unwinding. +panic = "unwind" + +[profile.testnet] +debug = 1 # debug symbols are useful for profilers +debug-assertions = true # Enable debug-assert! for non-production profiles +inherits = "release" +overflow-checks = true + +[patch."https://github.com/paritytech/polkadot-sdk"] +sp-crypto-ec-utils = { git = "https://github.com/moonbeam-foundation/polkadot-sdk", branch = "moonbeam-polkadot-v1.7.2" } diff --git a/tracing/2902/runtime/common/Cargo.toml b/tracing/2902/runtime/common/Cargo.toml new file mode 100644 index 00000000..309b6700 --- /dev/null +++ b/tracing/2902/runtime/common/Cargo.toml @@ -0,0 +1,146 @@ +[package] +authors = { workspace = true } +description = "Common code shared between runtimes" +edition = "2021" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +name = "moonbeam-runtime-common" +version = "0.8.0-dev" + +[dependencies] +hex-literal = "0.3.4" +impl-trait-for-tuples = "0.2.1" +log = "0.4" + +# Moonbeam +moonbeam-xcm-benchmarks = { workspace = true } +pallet-asset-manager = { workspace = true } +pallet-author-mapping = { workspace = true } +pallet-conviction-voting = { workspace = true } +pallet-ethereum-xcm = { workspace = true } +pallet-migrations = { workspace = true } +pallet-moonbeam-lazy-migrations = { workspace = true } +pallet-parachain-staking = { workspace = true } +pallet-precompile-benchmarks = { workspace = true } +pallet-randomness = { workspace = true } +pallet-relay-storage-roots = { workspace = true } +pallet-xcm-transactor = { workspace = true } +precompile-utils = { workspace = true } +xcm-primitives = { workspace = true } + +# Substrate +cumulus-pallet-xcmp-queue = { workspace = true } +frame-benchmarking = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true } +pallet-collective = { workspace = true } +pallet-crowdloan-rewards = { workspace = true } +pallet-identity = { workspace = true } +pallet-moonbeam-orbiters = { workspace = true } +pallet-multisig = { workspace = true } +pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } +pallet-referenda = { workspace = true } +pallet-scheduler = { workspace = true } +pallet-sudo = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-treasury = { workspace = true } +pallet-utility = { workspace = true } +pallet-whitelist = { workspace = true } +pallet-xcm = { workspace = true } +sp-api = { workspace = true } +sp-consensus-slots = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +sp-genesis-builder = { workspace = true } +frame-try-runtime = { workspace = true } + +# Frontier +fp-ethereum = { workspace = true } +fp-evm = { workspace = true } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm-chain-id = { workspace = true } + +# Moonkit +nimbus-primitives = { workspace = true } +pallet-async-backing = { workspace = true } +pallet-author-inherent = { workspace = true } +pallet-author-slot-filter = { workspace = true } + +# Polkadot +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Parity +parity-scale-codec = { workspace = true } + +account = { workspace = true } + +[features] +std = [ + "fp-ethereum/std", + "fp-evm/std", + "frame-support/std", + "pallet-asset-manager/std", + "pallet-async-backing/std", + "pallet-author-inherent/std", + "pallet-author-mapping/std", + "pallet-ethereum-xcm/std", + "pallet-evm/std", + "pallet-migrations/std", + "pallet-parachain-staking/std", + "pallet-randomness/std", + "pallet-referenda/std", + "pallet-scheduler/std", + "pallet-xcm-transactor/std", + "pallet-moonbeam-lazy-migrations/std", + "pallet-identity/std", + "parity-scale-codec/std", + "precompile-utils/std", + "sp-consensus-slots/std", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", + "sp-genesis-builder/std", + "xcm-executor/std", + "xcm/std", + "account/std", +] +runtime-benchmarks = [ + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "pallet-asset-manager/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-author-inherent/runtime-benchmarks", + "pallet-author-mapping/runtime-benchmarks", + "pallet-author-slot-filter/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", + "pallet-crowdloan-rewards/runtime-benchmarks", + "pallet-ethereum-xcm/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-moonbeam-orbiters/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-parachain-staking/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-randomness/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "pallet-moonbeam-lazy-migrations/runtime-benchmarks", + "moonbeam-xcm-benchmarks/runtime-benchmarks", +] +try-runtime = ["frame-support/try-runtime", "pallet-migrations/try-runtime"] diff --git a/tracing/2902/runtime/common/src/apis.rs b/tracing/2902/runtime/common/src/apis.rs new file mode 100644 index 00000000..eef538c2 --- /dev/null +++ b/tracing/2902/runtime/common/src/apis.rs @@ -0,0 +1,939 @@ +// 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 . + +#[macro_export] +macro_rules! impl_runtime_apis_plus_common { + {$($custom:tt)*} => { + + #[cfg(feature = "evm-tracing")] + // Helper function to replay the "on_idle" hook for all pallets, we need this for + // evm-tracing because some ethereum-xcm transactions might be executed at on_idle. + // + // We need to make sure that we replay on_idle exactly the same way as the + // original block execution, but unfortunatly frame executive diosn't provide a function + // to replay only on_idle, so we need to copy here some code inside frame executive. + fn replay_on_idle() { + use frame_system::pallet_prelude::BlockNumberFor; + use frame_support::traits::OnIdle; + + let weight = >::block_weight(); + let max_weight = < + ::BlockWeights as + frame_support::traits::Get<_> + >::get().max_block; + let remaining_weight = max_weight.saturating_sub(weight.total()); + if remaining_weight.all_gt(Weight::zero()) { + let _ = >>::on_idle( + >::block_number(), + remaining_weight, + ); + } + } + + impl_runtime_apis! { + $($custom)* + + impl sp_api::Core for Runtime { + fn version() -> RuntimeVersion { + VERSION + } + + fn execute_block(block: Block) { + Executive::execute_block(block) + } + + fn initialize_block(header: &::Header) { + Executive::initialize_block(header) + } + } + + impl sp_api::Metadata for Runtime { + fn metadata() -> OpaqueMetadata { + OpaqueMetadata::new(Runtime::metadata().into()) + } + + fn metadata_at_version(version: u32) -> Option { + Runtime::metadata_at_version(version) + } + + fn metadata_versions() -> Vec { + Runtime::metadata_versions() + } + } + + impl sp_block_builder::BlockBuilder for Runtime { + fn apply_extrinsic(extrinsic: ::Extrinsic) -> ApplyExtrinsicResult { + Executive::apply_extrinsic(extrinsic) + } + + fn finalize_block() -> ::Header { + Executive::finalize_block() + } + + fn inherent_extrinsics( + data: sp_inherents::InherentData, + ) -> Vec<::Extrinsic> { + data.create_extrinsics() + } + + fn check_inherents( + block: Block, + data: sp_inherents::InherentData, + ) -> sp_inherents::CheckInherentsResult { + data.check_extrinsics(&block) + } + } + + impl sp_offchain::OffchainWorkerApi for Runtime { + fn offchain_worker(header: &::Header) { + Executive::offchain_worker(header) + } + } + + impl sp_session::SessionKeys for Runtime { + fn decode_session_keys( + encoded: Vec, + ) -> Option, sp_core::crypto::KeyTypeId)>> { + opaque::SessionKeys::decode_into_raw_public_keys(&encoded) + } + + fn generate_session_keys(seed: Option>) -> Vec { + opaque::SessionKeys::generate(seed) + } + } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + frame_support::genesis_builder_helper::create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + frame_support::genesis_builder_helper::build_config::(config) + } + } + + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Index { + System::account_nonce(account) + } + } + + impl moonbeam_rpc_primitives_debug::DebugRuntimeApi for Runtime { + fn trace_transaction( + extrinsics: Vec<::Extrinsic>, + traced_transaction: &EthereumTransaction, + header: &::Header, + ) -> Result< + (), + sp_runtime::DispatchError, + > { + #[cfg(feature = "evm-tracing")] + { + use moonbeam_evm_tracer::tracer::EvmTracer; + use xcm_primitives::{ + ETHEREUM_XCM_TRACING_STORAGE_KEY, + EthereumXcmTracingStatus + }; + use frame_support::storage::unhashed; + use frame_system::pallet_prelude::BlockNumberFor; + + // Tell the CallDispatcher we are tracing a specific Transaction. + unhashed::put::( + ETHEREUM_XCM_TRACING_STORAGE_KEY, + &EthereumXcmTracingStatus::Transaction(traced_transaction.hash()), + ); + + // Initialize block: calls the "on_initialize" hook on every pallet + // in AllPalletsWithSystem. + // After pallet message queue was introduced, this must be done only after + // enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY + // in the storage + Executive::initialize_block(header); + + // Apply the a subset of extrinsics: all the substrate-specific or ethereum + // transactions that preceded the requested transaction. + for ext in extrinsics.into_iter() { + let _ = match &ext.0.function { + RuntimeCall::Ethereum(transact { transaction }) => { + if transaction == traced_transaction { + EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); + return Ok(()); + } else { + Executive::apply_extrinsic(ext) + } + } + _ => Executive::apply_extrinsic(ext), + }; + if let Some(EthereumXcmTracingStatus::TransactionExited) = unhashed::get( + ETHEREUM_XCM_TRACING_STORAGE_KEY + ) { + return Ok(()); + } + } + + if let Some(EthereumXcmTracingStatus::Transaction(_)) = unhashed::get( + ETHEREUM_XCM_TRACING_STORAGE_KEY + ) { + // If the transaction was not found, it might be + // an eth-xcm transaction that was executed at on_idle + replay_on_idle(); + } + + if let Some(EthereumXcmTracingStatus::TransactionExited) = unhashed::get( + ETHEREUM_XCM_TRACING_STORAGE_KEY + ) { + // The transaction was found + Ok(()) + } else { + // The transaction was not-found + Err(sp_runtime::DispatchError::Other( + "Failed to find Ethereum transaction among the extrinsics.", + )) + } + } + #[cfg(not(feature = "evm-tracing"))] + Err(sp_runtime::DispatchError::Other( + "Missing `evm-tracing` compile time feature flag.", + )) + } + + fn trace_block( + extrinsics: Vec<::Extrinsic>, + known_transactions: Vec, + header: &::Header, + ) -> Result< + (), + sp_runtime::DispatchError, + > { + #[cfg(feature = "evm-tracing")] + { + use moonbeam_evm_tracer::tracer::EvmTracer; + use frame_system::pallet_prelude::BlockNumberFor; + use xcm_primitives::EthereumXcmTracingStatus; + + // Tell the CallDispatcher we are tracing a full Block. + frame_support::storage::unhashed::put::( + xcm_primitives::ETHEREUM_XCM_TRACING_STORAGE_KEY, + &EthereumXcmTracingStatus::Block, + ); + + let mut config = ::config().clone(); + config.estimate = true; + + // Initialize block: calls the "on_initialize" hook on every pallet + // in AllPalletsWithSystem. + // After pallet message queue was introduced, this must be done only after + // enabling XCM tracing by setting ETHEREUM_XCM_TRACING_STORAGE_KEY + // in the storage + Executive::initialize_block(header); + + // Apply all extrinsics. Ethereum extrinsics are traced. + for ext in extrinsics.into_iter() { + match &ext.0.function { + RuntimeCall::Ethereum(transact { transaction }) => { + if known_transactions.contains(&transaction.hash()) { + // Each known extrinsic is a new call stack. + EvmTracer::emit_new(); + EvmTracer::new().trace(|| Executive::apply_extrinsic(ext)); + } else { + let _ = Executive::apply_extrinsic(ext); + } + } + _ => { + let _ = Executive::apply_extrinsic(ext); + } + }; + } + + // Replay on_idle + // Some XCM messages with eth-xcm transaction might be executed at on_idle + replay_on_idle(); + + Ok(()) + } + #[cfg(not(feature = "evm-tracing"))] + Err(sp_runtime::DispatchError::Other( + "Missing `evm-tracing` compile time feature flag.", + )) + } + } + + impl moonbeam_rpc_primitives_txpool::TxPoolRuntimeApi for Runtime { + fn extrinsic_filter( + xts_ready: Vec<::Extrinsic>, + xts_future: Vec<::Extrinsic>, + ) -> TxPoolResponse { + TxPoolResponse { + ready: xts_ready + .into_iter() + .filter_map(|xt| match xt.0.function { + RuntimeCall::Ethereum(transact { transaction }) => Some(transaction), + _ => None, + }) + .collect(), + future: xts_future + .into_iter() + .filter_map(|xt| match xt.0.function { + RuntimeCall::Ethereum(transact { transaction }) => Some(transaction), + _ => None, + }) + .collect(), + } + } + } + + impl fp_rpc::EthereumRuntimeRPCApi for Runtime { + fn chain_id() -> u64 { + ::ChainId::get() + } + + fn account_basic(address: H160) -> EVMAccount { + let (account, _) = EVM::account_basic(&address); + account + } + + fn gas_price() -> U256 { + let (gas_price, _) = ::FeeCalculator::min_gas_price(); + gas_price + } + + fn account_code_at(address: H160) -> Vec { + pallet_evm::AccountCodes::::get(address) + } + + fn author() -> H160 { + >::find_author() + } + + fn storage_at(address: H160, index: U256) -> H256 { + let mut tmp = [0u8; 32]; + index.to_big_endian(&mut tmp); + pallet_evm::AccountStorages::::get(address, H256::from_slice(&tmp[..])) + } + + fn call( + from: H160, + to: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; + let is_transactional = false; + let validate = true; + + // Estimated encoded transaction size must be based on the heaviest transaction + // type (EIP1559Transaction) to be compatible with all transaction types. + let mut estimated_transaction_len = data.len() + + // pallet ethereum index: 1 + // transact call index: 1 + // Transaction enum variant: 1 + // chain_id 8 bytes + // nonce: 32 + // max_priority_fee_per_gas: 32 + // max_fee_per_gas: 32 + // gas_limit: 32 + // action: 21 (enum varianrt + call address) + // value: 32 + // access_list: 1 (empty vec size) + // 65 bytes signature + 258; + + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = gas_limit.min(u64::MAX.into()).low_u64(); + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + + ::Runner::call( + from, + to, + data, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + config.as_ref().unwrap_or(::config()), + ).map_err(|err| err.error.into()) + } + + fn create( + from: H160, + data: Vec, + value: U256, + gas_limit: U256, + max_fee_per_gas: Option, + max_priority_fee_per_gas: Option, + nonce: Option, + estimate: bool, + access_list: Option)>>, + ) -> Result { + let config = if estimate { + let mut config = ::config().clone(); + config.estimate = true; + Some(config) + } else { + None + }; + let is_transactional = false; + let validate = true; + + let mut estimated_transaction_len = data.len() + + // from: 20 + // value: 32 + // gas_limit: 32 + // nonce: 32 + // 1 byte transaction action variant + // chain id 8 bytes + // 65 bytes signature + 190; + + if max_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if max_priority_fee_per_gas.is_some() { + estimated_transaction_len += 32; + } + if access_list.is_some() { + estimated_transaction_len += access_list.encoded_size(); + } + + let gas_limit = if gas_limit > U256::from(u64::MAX) { + u64::MAX + } else { + gas_limit.low_u64() + }; + let without_base_extrinsic_weight = true; + + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + gas_limit, + without_base_extrinsic_weight + ) { + weight_limit if weight_limit.proof_size() > 0 => { + (Some(weight_limit), Some(estimated_transaction_len as u64)) + } + _ => (None, None), + }; + + #[allow(clippy::or_fun_call)] // suggestion not helpful here + ::Runner::create( + from, + data, + value, + gas_limit, + max_fee_per_gas, + max_priority_fee_per_gas, + nonce, + access_list.unwrap_or_default(), + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + config.as_ref().unwrap_or(::config()), + ).map_err(|err| err.error.into()) + } + + fn current_transaction_statuses() -> Option> { + pallet_ethereum::CurrentTransactionStatuses::::get() + } + + fn current_block() -> Option { + pallet_ethereum::CurrentBlock::::get() + } + + fn current_receipts() -> Option> { + pallet_ethereum::CurrentReceipts::::get() + } + + fn current_all() -> ( + Option, + Option>, + Option>, + ) { + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentReceipts::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get(), + ) + } + + fn extrinsic_filter( + xts: Vec<::Extrinsic>, + ) -> Vec { + xts.into_iter().filter_map(|xt| match xt.0.function { + RuntimeCall::Ethereum(transact { transaction }) => Some(transaction), + _ => None + }).collect::>() + } + + fn elasticity() -> Option { + None + } + + fn gas_limit_multiplier_support() {} + + fn pending_block( + xts: Vec<::Extrinsic> + ) -> ( + Option, Option> + ) { + for ext in xts.into_iter() { + let _ = Executive::apply_extrinsic(ext); + } + + Ethereum::on_finalize(System::block_number() + 1); + + ( + pallet_ethereum::CurrentBlock::::get(), + pallet_ethereum::CurrentTransactionStatuses::::get() + ) + } + + fn initialize_pending_block(header: &::Header) { + pallet_randomness::vrf::using_fake_vrf(|| Executive::initialize_block(header)) + } + } + + impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { + fn convert_transaction( + transaction: pallet_ethereum::Transaction + ) -> ::Extrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } + } + + impl pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi + for Runtime { + fn query_info( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment_rpc_runtime_api::RuntimeDispatchInfo { + TransactionPayment::query_info(uxt, len) + } + + fn query_fee_details( + uxt: ::Extrinsic, + len: u32, + ) -> pallet_transaction_payment::FeeDetails { + TransactionPayment::query_fee_details(uxt, len) + } + + fn query_weight_to_fee(weight: Weight) -> Balance { + TransactionPayment::weight_to_fee(weight) + } + + fn query_length_to_fee(length: u32) -> Balance { + TransactionPayment::length_to_fee(length) + } + } + + impl nimbus_primitives::NimbusApi for Runtime { + fn can_author( + author: nimbus_primitives::NimbusId, + slot: u32, + parent_header: &::Header + ) -> bool { + use pallet_parachain_staking::Config as PalletParachainStakingConfig; + + let block_number = parent_header.number + 1; + + // The Moonbeam runtimes use an entropy source that needs to do some accounting + // work during block initialization. Therefore we initialize it here to match + // the state it will be in when the next block is being executed. + use frame_support::traits::OnInitialize; + System::initialize( + &block_number, + &parent_header.hash(), + &parent_header.digest, + ); + + // Because the staking solution calculates the next staking set at the beginning + // of the first block in the new round, the only way to accurately predict the + // authors is to compute the selection during prediction. + if pallet_parachain_staking::Pallet::::round() + .should_update(block_number) { + // get author account id + use nimbus_primitives::AccountLookup; + let author_account_id = if let Some(account) = + pallet_author_mapping::Pallet::::lookup_account(&author) { + account + } else { + // return false if author mapping not registered like in can_author impl + return false + }; + let candidates = pallet_parachain_staking::Pallet::::compute_top_candidates(); + if candidates.is_empty() { + // If there are zero selected candidates, we use the same eligibility + // as the previous round + return AuthorInherent::can_author(&author, &slot); + } + + // predict eligibility post-selection by computing selection results now + let (eligible, _) = + pallet_author_slot_filter::compute_pseudo_random_subset::( + candidates, + &slot + ); + eligible.contains(&author_account_id) + } else { + AuthorInherent::can_author(&author, &slot) + } + } + } + + impl cumulus_primitives_core::CollectCollationInfo for Runtime { + fn collect_collation_info( + header: &::Header + ) -> cumulus_primitives_core::CollationInfo { + ParachainSystem::collect_collation_info(header) + } + } + + impl session_keys_primitives::VrfApi for Runtime { + fn get_last_vrf_output() -> Option<::Hash> { + // TODO: remove in future runtime upgrade along with storage item + if pallet_randomness::Pallet::::not_first_block().is_none() { + return None; + } + pallet_randomness::Pallet::::local_vrf_output() + } + fn vrf_key_lookup( + nimbus_id: nimbus_primitives::NimbusId + ) -> Option { + use session_keys_primitives::KeysLookup; + AuthorMapping::lookup_keys(&nimbus_id) + } + } + + #[cfg(feature = "runtime-benchmarks")] + impl frame_benchmarking::Benchmark for Runtime { + + fn benchmark_metadata(extra: bool) -> ( + Vec, + Vec, + ) { + use frame_benchmarking::{list_benchmark, Benchmarking, BenchmarkList}; + use moonbeam_xcm_benchmarks::generic::benchmarking as MoonbeamXcmBenchmarks; + use frame_support::traits::StorageInfoTrait; + use MoonbeamXcmBenchmarks::XcmGenericBenchmarks as MoonbeamXcmGenericBench; + + use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark; + + let mut list = Vec::::new(); + list_benchmarks!(list, extra); + + let storage_info = AllPalletsWithSystem::storage_info(); + + return (list, storage_info) + } + + fn dispatch_benchmark( + config: frame_benchmarking::BenchmarkConfig, + ) -> Result, sp_runtime::RuntimeString> { + use frame_benchmarking::{add_benchmark, BenchmarkBatch, Benchmarking}; + use frame_support::traits::TrackedStorageKey; + use cumulus_primitives_core::ParaId; + + use xcm::latest::prelude::{ + GeneralIndex, Junction, Junctions, Location, Response, NetworkId, AssetId, + Assets as XcmAssets, Fungible, Asset, ParentThen, Parachain, Parent + }; + use frame_benchmarking::BenchmarkError; + + use frame_system_benchmarking::Pallet as SystemBench; + impl frame_system_benchmarking::Config for Runtime {} + + impl moonbeam_xcm_benchmarks::Config for Runtime {} + impl moonbeam_xcm_benchmarks::generic::Config for Runtime {} + + use pallet_asset_manager::Config as PalletAssetManagerConfig; + + use pallet_xcm::benchmarking::Pallet as PalletXcmExtrinsiscsBenchmark; + type ExistentialDeposit = ConstU128<0>; + parameter_types! { + pub const RandomParaId: ParaId = ParaId::new(43211234); + } + + impl pallet_xcm::benchmarking::Config for Runtime { + fn reachable_dest() -> Option { + Some(Parent.into()) + } + + fn teleportable_asset_and_dest() -> Option<(Asset, Location)> { + // Relay/native token can be teleported between AH and Relay. + Some(( + Asset { + fun: Fungible(ExistentialDeposit::get()), + id: AssetId(Parent.into()) + }, + Parent.into(), + )) + } + + fn reserve_transferable_asset_and_dest() -> Option<(Asset, Location)> { + Some(( + Asset { + fun: Fungible(ExistentialDeposit::get()), + id: AssetId(Parent.into()) + }, + // AH can reserve transfer native token to some random parachain. + ParentThen(Parachain(RandomParaId::get().into()).into()).into(), + )) + } + } + + impl pallet_xcm_benchmarks::Config for Runtime { + type XcmConfig = xcm_config::XcmExecutorConfig; + type AccountIdConverter = xcm_config::LocationToAccountId; + type DeliveryHelper = (); + fn valid_destination() -> Result { + Ok(Location::parent()) + } + fn worst_case_holding(_depositable_count: u32) -> XcmAssets { + // 100 fungibles + const HOLDING_FUNGIBLES: u32 = 100; + let fungibles_amount: u128 = 100; + let assets = (0..HOLDING_FUNGIBLES).map(|i| { + let location: Location = GeneralIndex(i as u128).into(); + Asset { + id: AssetId(location), + fun: Fungible(fungibles_amount * i as u128), + } + .into() + }) + .chain( + core::iter::once( + Asset { + id: AssetId(Location::parent()), + fun: Fungible(u128::MAX) + } + ) + ) + .collect::>(); + + + for (i, asset) in assets.iter().enumerate() { + if let Asset { + id: AssetId(location), + fun: Fungible(_) + } = asset { + ::AssetId, + ::ForeignAssetType> + >::set_asset_type_asset_id( + location.clone().try_into().expect("convert to v3"), + i as u128 + ); + // set 1-1 + ::ForeignAssetType> + >::set_units_per_second( + location.clone().try_into().expect("convert to v3"), + 1_000_000_000_000u128 + ); + } + } + assets.into() + } + } + + impl pallet_xcm_benchmarks::generic::Config for Runtime { + type RuntimeCall = RuntimeCall; + type TransactAsset = Balances; + + fn worst_case_response() -> (u64, Response) { + (0u64, Response::Version(Default::default())) + } + + fn worst_case_asset_exchange() + -> Result<(XcmAssets, XcmAssets), BenchmarkError> { + Err(BenchmarkError::Skip) + } + + fn universal_alias() -> Result<(Location, Junction), BenchmarkError> { + Err(BenchmarkError::Skip) + } + + fn export_message_origin_and_destination() + -> Result<(Location, NetworkId, Junctions), BenchmarkError> { + Err(BenchmarkError::Skip) + } + + fn transact_origin_and_runtime_call() + -> Result<(Location, RuntimeCall), BenchmarkError> { + Ok((Location::parent(), frame_system::Call::remark_with_event { + remark: vec![] + }.into())) + } + + fn subscribe_origin() -> Result { + Ok(Location::parent()) + } + + fn claimable_asset() + -> Result<(Location, Location, XcmAssets), BenchmarkError> { + let origin = Location::parent(); + let assets: XcmAssets = (AssetId(Location::parent()), 1_000u128) + .into(); + let ticket = Location { parents: 0, interior: [].into() /* Here */ }; + Ok((origin, ticket, assets)) + } + + fn fee_asset() -> Result { + Err(BenchmarkError::Skip) + } + + fn unlockable_asset() + -> Result<(Location, Location, Asset), BenchmarkError> { + Err(BenchmarkError::Skip) + } + + fn alias_origin() -> Result<(Location, Location), BenchmarkError> { + Err(BenchmarkError::Skip) + } + } + + let whitelist: Vec = vec![ + // Block Number + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "02a5c1b19ab7a04f536c519aca4983ac") + .to_vec().into(), + // Total Issuance + hex_literal::hex!( "c2261276cc9d1f8598ea4b6a74b15c2f" + "57c875e4cff74148e4628f264b974c80") + .to_vec().into(), + // Execution Phase + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "ff553b5a9862a516939d82b3d3d8661a") + .to_vec().into(), + // Event Count + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "0a98fdbe9ce6c55837576c60c7af3850") + .to_vec().into(), + // System Events + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "80d41e5e16056765bc8461851072c9d7") + .to_vec().into(), + // System BlockWeight + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "34abf5cb34d6244378cddbf18e849d96") + .to_vec().into(), + // ParachainStaking Round + hex_literal::hex!( "a686a3043d0adcf2fa655e57bc595a78" + "13792e785168f725b60e2969c7fc2552") + .to_vec().into(), + // Treasury Account (py/trsry) + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "b99d880ec681799c0cf30e8886371da9" + "7be2919ac397ba499ea5e57132180ec6" + "6d6f646c70792f747273727900000000" + "00000000" + ).to_vec().into(), + // Treasury Account (pc/trsry) + hex_literal::hex!( "26aa394eea5630e07c48ae0c9558cef7" + "b99d880ec681799c0cf30e8886371da9" + "7be2919ac397ba499ea5e57132180ec6" + "6d6f646c70632f747273727900000000" + "00000000" + ).to_vec().into(), + // ParachainInfo ParachainId + hex_literal::hex!( "0d715f2646c8f85767b5d2764bb27826" + "04a74d81251e398fd8a0a4d55023bb3f") + .to_vec().into(), + + ]; + + let mut batches = Vec::::new(); + let params = (&config, &whitelist); + + add_benchmarks!(params, batches); + + if batches.is_empty() { + return Err("Benchmark not found for this pallet.".into()); + } + Ok(batches) + } + } + + #[cfg(feature = "try-runtime")] + impl frame_try_runtime::TryRuntime for Runtime { + fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) { + log::info!("try-runtime::on_runtime_upgrade()"); + // NOTE: intentional expect: we don't want to propagate the error backwards, + // and want to have a backtrace here. If any of the pre/post migration checks + // fail, we shall stop right here and right now. + let weight = Executive::try_runtime_upgrade(checks) + .expect("runtime upgrade logic *must* be infallible"); + (weight, RuntimeBlockWeights::get().max_block) + } + + fn execute_block( + block: Block, + state_root_check: bool, + signature_check: bool, + select: frame_try_runtime::TryStateSelect + ) -> Weight { + log::info!( + "try-runtime: executing block {:?} / root checks: {:?} / try-state-select: {:?}", + block.header.hash(), + state_root_check, + select, + ); + // NOTE: intentional unwrap: we don't want to propagate the error backwards, + // and want to have a backtrace here. + Executive::try_execute_block( + block, + state_root_check, + signature_check, + select, + ).expect("execute-block failed") + } + } + } + }; +} diff --git a/tracing/2902/runtime/common/src/benchmarking.rs b/tracing/2902/runtime/common/src/benchmarking.rs new file mode 100644 index 00000000..b6985b5b --- /dev/null +++ b/tracing/2902/runtime/common/src/benchmarking.rs @@ -0,0 +1,30 @@ +// Copyright 2019-2023 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 account::AccountId20; +use pallet_treasury::ArgumentsFactory; + +pub struct BenchmarkHelper; + +impl ArgumentsFactory<(), AccountId20> for BenchmarkHelper { + fn create_asset_kind(_seed: u32) -> () { + () + } + + fn create_beneficiary(seed: [u8; 32]) -> AccountId20 { + AccountId20::from(seed) + } +} diff --git a/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call.rs b/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call.rs new file mode 100644 index 00000000..112c457c --- /dev/null +++ b/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call.rs @@ -0,0 +1,51 @@ +// 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 . + +#[macro_export] +macro_rules! impl_moonbeam_xcm_call { + {} => { + + pub struct MoonbeamCall; + impl CallDispatcher for MoonbeamCall { + fn dispatch( + call: RuntimeCall, + origin: RuntimeOrigin, + ) -> Result< + PostDispatchInfoOf, + DispatchErrorWithPostInfo> + > { + if let Ok(raw_origin) = TryInto::>::try_into(origin.clone().caller) { + match (call.clone(), raw_origin) { + ( + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact { .. }) | + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact_through_proxy { .. }), + RawOrigin::Signed(account_id) + ) => { + return RuntimeCall::dispatch( + call, + pallet_ethereum_xcm::Origin::XcmEthereumTransaction( + account_id.into() + ).into() + ); + }, + _ => {} + } + } + RuntimeCall::dispatch(call, origin) + } + } + } +} diff --git a/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs b/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs new file mode 100644 index 00000000..08d2b06f --- /dev/null +++ b/tracing/2902/runtime/common/src/impl_moonbeam_xcm_call_tracing.rs @@ -0,0 +1,118 @@ +// 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 . + +#[macro_export] +macro_rules! impl_moonbeam_xcm_call_tracing { + {} => { + + type CallResult = + Result< + PostDispatchInfoOf, + DispatchErrorWithPostInfo> + >; + + pub struct MoonbeamCall; + impl CallDispatcher for MoonbeamCall { + fn dispatch( + call: RuntimeCall, + origin: RuntimeOrigin, + ) -> CallResult { + if let Ok(raw_origin) = TryInto::>::try_into(origin.clone().caller) { + match (call.clone(), raw_origin) { + ( + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact { xcm_transaction }) | + RuntimeCall::EthereumXcm(pallet_ethereum_xcm::Call::transact_through_proxy { + xcm_transaction, .. + }), + RawOrigin::Signed(account_id) + ) => { + use crate::EthereumXcm; + use moonbeam_evm_tracer::tracer::EvmTracer; + use xcm_primitives::{ + XcmToEthereum, + EthereumXcmTracingStatus, + ETHEREUM_XCM_TRACING_STORAGE_KEY + }; + use frame_support::storage::unhashed; + use frame_support::traits::Get; + + let dispatch_call = || { + RuntimeCall::dispatch( + call, + pallet_ethereum_xcm::Origin::XcmEthereumTransaction( + account_id.into() + ).into() + ) + }; + + return match unhashed::get( + ETHEREUM_XCM_TRACING_STORAGE_KEY + ) { + // This runtime instance is used for tracing. + Some(tracing_status) => match tracing_status { + // Tracing a block, all calls are done using environmental. + EthereumXcmTracingStatus::Block => { + // Each known extrinsic is a new call stack. + EvmTracer::emit_new(); + let mut res: Option = None; + EvmTracer::new().trace(|| { + res = Some(dispatch_call()); + }); + res.expect("Invalid dispatch result") + }, + // Tracing a transaction, the one matching the trace request + // is done using environmental, the rest dispatched normally. + EthereumXcmTracingStatus::Transaction(traced_transaction_hash) => { + let transaction_hash = xcm_transaction.into_transaction_v2( + EthereumXcm::nonce(), + ::ChainId::get() + ) + .expect("Invalid transaction conversion") + .hash(); + if transaction_hash == traced_transaction_hash { + let mut res: Option = None; + EvmTracer::new().trace(|| { + res = Some(dispatch_call()); + }); + // Tracing runtime work is done, just signal instance exit. + unhashed::put::( + xcm_primitives::ETHEREUM_XCM_TRACING_STORAGE_KEY, + &EthereumXcmTracingStatus::TransactionExited, + ); + return res.expect("Invalid dispatch result"); + } + dispatch_call() + }, + // Tracing a transaction that has already been found and + // executed. There's no need to dispatch the rest of the + // calls. + EthereumXcmTracingStatus::TransactionExited => Ok(crate::PostDispatchInfo { + actual_weight: None, + pays_fee: frame_support::pallet_prelude::Pays::No, + }), + }, + // This runtime instance is importing a block. + None => dispatch_call() + }; + }, + _ => {} + } + } + RuntimeCall::dispatch(call, origin) + } + } + } +} diff --git a/tracing/2902/runtime/common/src/impl_on_charge_evm_transaction.rs b/tracing/2902/runtime/common/src/impl_on_charge_evm_transaction.rs new file mode 100644 index 00000000..619b11c8 --- /dev/null +++ b/tracing/2902/runtime/common/src/impl_on_charge_evm_transaction.rs @@ -0,0 +1,62 @@ +// 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 . + +#[macro_export] +macro_rules! impl_on_charge_evm_transaction { + {} => { + type FungibleAccountId = ::AccountId; + + type BalanceFor = + <::Currency as Inspect>>::Balance; + + pub struct OnChargeEVMTransaction(sp_std::marker::PhantomData); + + impl OnChargeEVMTransactionT for OnChargeEVMTransaction + where + T: pallet_evm::Config, + T::Currency: Balanced, + OU: OnUnbalanced>, + U256: UniqueSaturatedInto> + { + type LiquidityInfo = Option>; + + fn withdraw_fee(who: &H160, fee: U256) -> Result> { + EVMFungibleAdapter::<::Currency, ()>::withdraw_fee(who, fee) + } + + fn can_withdraw(who: &H160, amount: U256) -> Result<(), pallet_evm::Error> { + EVMFungibleAdapter::<::Currency, ()>::can_withdraw(who, amount) + } + + fn correct_and_deposit_fee( + who: &H160, + corrected_fee: U256, + base_fee: U256, + already_withdrawn: Self::LiquidityInfo, + ) -> Result> { + ::Currency, OU> as OnChargeEVMTransactionT< + T, + >>::correct_and_deposit_fee(who, corrected_fee, base_fee, already_withdrawn) + } + + fn pay_priority_fee(tip: Self::LiquidityInfo) { + if let Some(tip) = tip { + OU::on_unbalanced(tip); + } + } + } + } +} diff --git a/tracing/2902/runtime/common/src/impl_self_contained_call.rs b/tracing/2902/runtime/common/src/impl_self_contained_call.rs new file mode 100644 index 00000000..0dbce052 --- /dev/null +++ b/tracing/2902/runtime/common/src/impl_self_contained_call.rs @@ -0,0 +1,78 @@ +// 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 . + +#[macro_export] +macro_rules! impl_self_contained_call { + {} => { + impl fp_self_contained::SelfContainedCall for RuntimeCall { + type SignedInfo = H160; + + fn is_self_contained(&self) -> bool { + match self { + RuntimeCall::Ethereum(call) => call.is_self_contained(), + _ => false, + } + } + + fn check_self_contained( + &self + ) -> Option> { + match self { + RuntimeCall::Ethereum(call) => call.check_self_contained(), + _ => None, + } + } + + fn validate_self_contained( + &self, + signed_info: &Self::SignedInfo, + dispatch_info: &DispatchInfoOf, + len: usize, + ) -> Option { + match self { + RuntimeCall::Ethereum(call) => call.validate_self_contained(signed_info, dispatch_info, len), + _ => None, + } + } + + fn pre_dispatch_self_contained( + &self, + info: &Self::SignedInfo, + dispatch_info: &DispatchInfoOf, + len: usize, + ) -> Option> { + match self { + RuntimeCall::Ethereum(call) => call.pre_dispatch_self_contained(info, dispatch_info, len), + _ => None, + } + } + + fn apply_self_contained( + self, + info: Self::SignedInfo, + ) -> Option>> { + match self { + call @ RuntimeCall::Ethereum(pallet_ethereum::Call::transact { .. }) => Some( + call.dispatch(RuntimeOrigin::from( + pallet_ethereum::RawOrigin::EthereumTransaction(info) + )) + ), + _ => None, + } + } + } + } +} diff --git a/tracing/2902/runtime/common/src/impl_xcm_evm_runner.rs b/tracing/2902/runtime/common/src/impl_xcm_evm_runner.rs new file mode 100644 index 00000000..7eebe42d --- /dev/null +++ b/tracing/2902/runtime/common/src/impl_xcm_evm_runner.rs @@ -0,0 +1,188 @@ +// 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 . + +#[macro_export] +macro_rules! impl_evm_runner_precompile_or_eth_xcm { + {} => { + use fp_evm::{CallInfo, CallOrCreateInfo, Context, Transfer}; + use frame_support::dispatch::CallableCallFor; + use pallet_evm::{Runner, RunnerError}; + use precompile_utils::{prelude::*, evm::handle::with_precompile_handle}; + use sp_core::U256; + use sp_runtime::DispatchError; + use sp_std::vec::Vec; + use xcm_primitives::{EthereumXcmTransaction, EthereumXcmTransactionV2}; + + pub struct EvmRunnerPrecompileOrEthXcm( + core::marker::PhantomData<(CallDispatcher, Runtime)>, + ); + + impl Runner + for EvmRunnerPrecompileOrEthXcm + where + CallDispatcher: xcm_executor::traits::CallDispatcher, + Runtime: pallet_evm::Config + pallet_ethereum_xcm::Config, + Runtime::RuntimeOrigin: From, + { + type Error = DispatchError; + + fn call( + source: H160, + target: H160, + input: 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, + ) -> Result> { + // The `with_precompile_handle` function will execute the closure (and return the + // result in a Some) if and only if there is an available EVM context. Otherwise, + // it will return None. + if let Some((exit_reason, value)) = with_precompile_handle(|precompile_handle| { + let transfer = if value.is_zero() { + None + } else { + Some(Transfer { + source, + target, + value, + }) + }; + + precompile_handle.call( + target, + transfer, + input.clone(), + Some(gas_limit), + false, + &Context { + address: target, + caller: source, + apparent_value: value, + }, + ) + }) { + Ok(CallInfo { + exit_reason, + value, + used_gas: fp_evm::UsedGas { + standard: U256::default(), + effective: U256::default(), + }, + logs: Default::default(), + weight_info: None, + }) + } else { + let xcm_transaction = EthereumXcmTransaction::V2(EthereumXcmTransactionV2 { + gas_limit: gas_limit.into(), + action: pallet_ethereum_xcm::TransactionAction::Call(target), + value, + input: input.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::transact { xcm_transaction }), + RawOrigin::Signed(source.into()).into(), + ) + .map_err(|DispatchErrorWithPostInfo { error, .. }| RunnerError { + error, + weight: Default::default(), + }) + })?; + + if let Some(CallOrCreateInfo::Call(call_info))= execution_info { + Ok(call_info) + } else { + // `execution_info` must have been filled in + Err(RunnerError { + error: DispatchError::Unavailable, + weight: Default::default(), + }) + } + } + } + + fn create( + _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, + ) -> Result> { + unimplemented!() + } + + fn create2( + _source: H160, + _init: Vec, + _salt: H256, + _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, + ) -> Result> { + unimplemented!() + } + + fn validate( + _source: H160, + _target: Option, + _input: 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, + _weight_limit: Option, + _transaction_len: Option, + _evm_config: &fp_evm::Config, + ) -> Result<(), RunnerError> { + unimplemented!() + } + } + + } +} diff --git a/tracing/2902/runtime/common/src/lib.rs b/tracing/2902/runtime/common/src/lib.rs new file mode 100644 index 00000000..a905eb57 --- /dev/null +++ b/tracing/2902/runtime/common/src/lib.rs @@ -0,0 +1,29 @@ +// 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 . + +#![cfg_attr(not(feature = "std"), no_std)] + +mod apis; +mod impl_moonbeam_xcm_call; +mod impl_moonbeam_xcm_call_tracing; +mod impl_on_charge_evm_transaction; +mod impl_self_contained_call; +mod impl_xcm_evm_runner; +pub mod migrations; +pub mod weights; + +#[cfg(feature = "runtime-benchmarks")] +pub mod benchmarking; diff --git a/tracing/2902/runtime/common/src/migrations.rs b/tracing/2902/runtime/common/src/migrations.rs new file mode 100644 index 00000000..6b5d20f6 --- /dev/null +++ b/tracing/2902/runtime/common/src/migrations.rs @@ -0,0 +1,405 @@ +// 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 . + +//! # Migrations +//! +//! This module acts as a registry where each migration is defined. Each migration should implement +//! the "Migration" trait declared in the pallet-migrations crate. + +use frame_support::{ + parameter_types, + storage::unhashed::{clear_prefix, contains_prefixed_key}, + traits::OnRuntimeUpgrade, + weights::Weight, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use pallet_author_slot_filter::Config as AuthorSlotFilterConfig; +use pallet_migrations::{GetMigrations, Migration}; +use pallet_parachain_staking::migrations::MigrateRoundWithFirstSlot; +use sp_core::Get; +use sp_std::{marker::PhantomData, prelude::*, vec}; + +pub struct PalletStakingRoundMigration(PhantomData); +impl Migration for PalletStakingRoundMigration +where + Runtime: pallet_parachain_staking::Config, + BlockNumberFor: Into, +{ + fn friendly_name(&self) -> &str { + "MM_MigrateRoundWithFirstSlot" + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + MigrateRoundWithFirstSlot::::pre_upgrade() + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + MigrateRoundWithFirstSlot::::on_runtime_upgrade() + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, state: Vec) -> Result<(), sp_runtime::DispatchError> { + MigrateRoundWithFirstSlot::::post_upgrade(state) + } +} + +/// Moonbeam has 134 keys to be migrated +/// Moonriver has 117 keys to be migrated +/// Moonbase has 172 keys to be migrated +pub const PALLET_IDENTITY_MIGRATION_KEY_LIMIT: u64 = 500; + +pub struct PalletIdentityMigrateV0ToV1(PhantomData); +impl Migration for PalletIdentityMigrateV0ToV1 +where + Runtime: pallet_identity::Config, +{ + fn friendly_name(&self) -> &str { + "MM_PalletIdentityMigrateV0ToV1" + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + pallet_identity::migration::versioned::V0ToV1::::pre_upgrade() + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + pallet_identity::migration::versioned::V0ToV1::::on_runtime_upgrade() + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, state: Vec) -> Result<(), sp_runtime::DispatchError> { + pallet_identity::migration::versioned::V0ToV1::::post_upgrade(state) + } +} + +parameter_types! { + pub const DemocracyPalletName: &'static str = "Democracy"; +} + +pub struct RemovePalletDemocracy(pub PhantomData); +impl Migration for RemovePalletDemocracy +where + Runtime: frame_system::Config, +{ + fn friendly_name(&self) -> &str { + "MM_RemoveDemocracyPallet" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + log::info!("Removing pallet democracy"); + + // Democracy: f2794c22e353e9a839f12faab03a911b + // VotingOf: e470c6afbbbc027eb288ade7595953c2 + let prefix = + hex_literal::hex!("f2794c22e353e9a839f12faab03a911be470c6afbbbc027eb288ade7595953c2"); + if contains_prefixed_key(&prefix) { + // PoV failsafe: do not execute the migration if there are VotingOf keys + // that have not been cleaned up + log::info!("Found keys for Democracy.VotingOf pre-removal - skipping migration",); + return Weight::zero(); + }; + frame_support::migrations::RemovePallet::< + DemocracyPalletName, + ::DbWeight, + >::on_runtime_upgrade() + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + let _ = frame_support::migrations::RemovePallet::< + DemocracyPalletName, + ::DbWeight, + >::pre_upgrade(); + + Ok(vec![]) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, _state: Vec) -> Result<(), sp_runtime::DispatchError> { + let _ = frame_support::migrations::RemovePallet::< + DemocracyPalletName, + ::DbWeight, + >::post_upgrade(_state); + + Ok(()) + } +} + +pub struct RemoveCollectivesAddresses(pub PhantomData); +impl Migration for RemoveCollectivesAddresses +where + Runtime: frame_system::Config, +{ + fn friendly_name(&self) -> &str { + "MM_RemoveCollectivesAddresses" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + log::info!("Removing gov v1 collective addresses storage"); + + // CouncilCollective: d59b9be6f0a7187ca6630c1d0a9bb045 + let prefix = hex_literal::hex!("d59b9be6f0a7187ca6630c1d0a9bb045"); + let result = clear_prefix(&prefix, Some(10), None); + log::info!("Removed {} CouncilCollective keys", result.unique); + + // record how many records have been deleted + let mut writes = result.unique; + + // TechCommitteeCollective: a06bfb73a86f8f98d5c5dc14e20e8a03 + let prefix = hex_literal::hex!("a06bfb73a86f8f98d5c5dc14e20e8a03"); + let result = clear_prefix(&prefix, Some(10), None); + log::info!("Removed {} TechCommitteeCollective", result.unique); + + // Account for weight + writes = writes.saturating_add(result.unique); + let reads = writes.saturating_add(2); + + let w = Runtime::DbWeight::get(); + w.reads_writes(reads.into(), writes.into()) + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + // CouncilCollective: d59b9be6f0a7187ca6630c1d0a9bb045 + let prefix = hex_literal::hex!("d59b9be6f0a7187ca6630c1d0a9bb045"); + match contains_prefixed_key(&prefix) { + true => log::info!("Found keys for CouncilCollective (pre-removal"), + false => log::warn!("No keys found for CouncilCollective (pre-removal)"), + }; + + // TechCommitteeCollective: a06bfb73a86f8f98d5c5dc14e20e8a03 + let prefix = hex_literal::hex!("a06bfb73a86f8f98d5c5dc14e20e8a03"); + match contains_prefixed_key(&prefix) { + true => log::info!("Found keys for TechCommitteeCollective (pre-removal)"), + false => log::warn!("No keys found for TechCommitteeCollective (pre-removal)"), + }; + + Ok(sp_std::vec::Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, _state: Vec) -> Result<(), sp_runtime::DispatchError> { + // CouncilCollective: d59b9be6f0a7187ca6630c1d0a9bb045 + let prefix = hex_literal::hex!("d59b9be6f0a7187ca6630c1d0a9bb045"); + match contains_prefixed_key(&prefix) { + true => log::info!("Found keys for CouncilCollective (post-removal) ⚠️"), + false => log::warn!("No keys found for CouncilCollective (post-removal) ✅"), + }; + + // TechCommitteeCollective: a06bfb73a86f8f98d5c5dc14e20e8a03 + let prefix = hex_literal::hex!("a06bfb73a86f8f98d5c5dc14e20e8a03"); + match contains_prefixed_key(&prefix) { + true => log::info!("Found keys for TechCommitteeCollective (post-removal) ⚠️"), + false => log::warn!("No keys found for TechCommitteeCollective (post-removal) ✅"), + }; + Ok(()) + } +} + +pub struct MigrateToLatestXcmVersion(PhantomData); +impl Migration for MigrateToLatestXcmVersion +where + pallet_xcm::migration::MigrateToLatestXcmVersion: OnRuntimeUpgrade, +{ + fn friendly_name(&self) -> &str { + "MM_MigrateToLatestXcmVersion" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + pallet_xcm::migration::MigrateToLatestXcmVersion::::on_runtime_upgrade() + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade(&self) -> Result, sp_runtime::DispatchError> { + pallet_xcm::migration::MigrateToLatestXcmVersion::::pre_upgrade() + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(&self, state: Vec) -> Result<(), sp_runtime::DispatchError> { + pallet_xcm::migration::MigrateToLatestXcmVersion::::post_upgrade(state) + } +} + +pub struct CommonMigrations(PhantomData); + +impl GetMigrations for CommonMigrations +where + Runtime: pallet_author_mapping::Config, + Runtime: pallet_parachain_staking::Config, + Runtime: pallet_scheduler::Config, + Runtime: AuthorSlotFilterConfig, + Runtime: pallet_preimage::Config, + Runtime: pallet_asset_manager::Config, + Runtime: pallet_xcm_transactor::Config, + Runtime: pallet_moonbeam_orbiters::Config, + Runtime: pallet_balances::Config, + Runtime: pallet_referenda::Config, + Runtime: pallet_xcm::Config, + Runtime::AccountId: Default, + BlockNumberFor: Into, + Runtime: pallet_identity::Config, +{ + fn get_migrations() -> Vec> { + // let migration_author_mapping_twox_to_blake = AuthorMappingTwoXToBlake:: { + // 0: Default::default(), + // }; + + // let migration_parachain_staking_purge_stale_storage = + // ParachainStakingPurgeStaleStorage::(Default::default()); + // let migration_parachain_staking_manual_exits = + // ParachainStakingManualExits::(Default::default()); + // let migration_parachain_staking_increase_max_delegations_per_candidate = + // ParachainStakingIncreaseMaxDelegationsPerCandidate::(Default::default()); + // let migration_parachain_staking_split_candidate_state = + // ParachainStakingSplitCandidateState::(Default::default()); + // let migration_parachain_staking_patch_incorrect_delegation_sums = + // ParachainStakingPatchIncorrectDelegationSums::(Default::default()); + + // let migration_scheduler_v3 = SchedulerMigrationV3::(Default::default()); + + // let migration_base_fee = MigrateBaseFeePerGas::(Default::default()); + + // TODO: this is a lot of allocation to do upon every get() call. this *should* be avoided + // except when pallet_migrations undergoes a runtime upgrade -- but TODO: review + + // let migration_author_slot_filter_eligible_ratio_to_eligibility_count = + // AuthorSlotFilterEligibleRatioToEligiblityCount::(Default::default()); + // let migration_author_mapping_add_keys_to_registration_info = + // AuthorMappingAddKeysToRegistrationInfo::(Default::default()); + // let staking_delegator_state_requests = + // ParachainStakingSplitDelegatorStateIntoDelegationScheduledRequests::( + // Default::default(), + // ); + // let migration_author_mapping_add_account_id_to_nimbus_lookup = + // AuthorMappingAddAccountIdToNimbusLookup::(Default::default()); + + // let xcm_transactor_max_weight = + // XcmTransactorMaxTransactWeight::(Default::default()); + + // let asset_manager_units_with_asset_type = + // AssetManagerUnitsWithAssetType::(Default::default()); + + // let asset_manager_populate_asset_type_id_storage = + // AssetManagerPopulateAssetTypeIdStorage::(Default::default()); + + // let asset_manager_change_statemine_prefixes = AssetManagerChangeStateminePrefixes::< + // Runtime, + // StatemineParaIdInfo, + // StatemineAssetsInstanceInfo, + // >(Default::default()); + + // let xcm_supported_assets = XcmPaymentSupportedAssets::(Default::default()); + + // let migration_elasticity = MigrateBaseFeeElasticity::(Default::default()); + //let staking_at_stake_auto_compound = + // ParachainStakingMigrateAtStakeAutoCompound::(Default::default()); + + //let scheduler_to_v4 = SchedulerMigrationV4::(Default::default()); + //let democracy_migration_hash_to_bounded_call = + // DemocracryMigrationHashToBoundedCall::(Default::default()); + //let preimage_migration_hash_to_bounded_call = + // PreimageMigrationHashToBoundedCall::(Default::default()); + //let asset_manager_to_xcm_v3 = + // PalletAssetManagerMigrateXcmV2ToV3::(Default::default()); + //let xcm_transactor_to_xcm_v3 = + // PalletXcmTransactorMigrateXcmV2ToV3::(Default::default()); + //let remove_min_bond_for_old_orbiter_collators = + // RemoveMinBondForOrbiterCollators::(Default::default()); + // let missing_balances_migrations = MissingBalancesMigrations::(Default::default()); + // let fix_pallet_versions = + // FixIncorrectPalletVersions::(Default::default()); + // let pallet_referenda_migrate_v0_to_v1 = + // PalletReferendaMigrateV0ToV1::(Default::default()); + //let pallet_collective_drop_gov_v1_collectives = + // PalletCollectiveDropGovV1Collectives::(Default::default()); + //let pallet_staking_round = PalletStakingRoundMigration::(Default::default()); + let remove_pallet_democracy = RemovePalletDemocracy::(Default::default()); + let remove_collectives_addresses = + RemoveCollectivesAddresses::(Default::default()); + // This migration can be removed in RT3000 + let migrate_pallet_identity = PalletIdentityMigrateV0ToV1::< + Runtime, + { PALLET_IDENTITY_MIGRATION_KEY_LIMIT }, + >(Default::default()); + + vec![ + // completed in runtime 800 + // Box::new(migration_author_mapping_twox_to_blake), + // completed in runtime 900 + // completed in runtime 1000 + // Box::new(migration_parachain_staking_purge_stale_storage), + // completed in runtime 1000 + // Box::new(migration_parachain_staking_manual_exits), + // completed in runtime 1101 + // Box::new(migration_parachain_staking_increase_max_delegations_per_candidate), + // completed in runtime 1201 + // Box::new(migration_parachain_staking_split_candidate_state), + // completed in runtime 1201 + // Box::new(xcm_transactor_max_weight), + // completed in runtime 1201 + // Box::new(asset_manager_units_with_asset_type), + // completed in runtime 1201 + // Box::new(asset_manager_change_statemine_prefixes), + // completed in runtime 1201 + // Box::new(asset_manager_populate_asset_type_id_storage), + // completed in runtime 1300 + // Box::new(migration_scheduler_v3), + // completed in runtime 1300 + // Box::new(migration_parachain_staking_patch_incorrect_delegation_sums), + // completed in runtime 1300 + // Box::new(migration_base_fee), + // completed in runtime 1300 + // Box::new(xcm_supported_assets), + // completed in runtime 1500 + // Box::new(migration_author_slot_filter_eligible_ratio_to_eligibility_count), + // Box::new(migration_author_mapping_add_keys_to_registration_info), + // Box::new(staking_delegator_state_requests), + // completed in runtime 1600 + // Box::new(migration_author_mapping_add_account_id_to_nimbus_lookup), + // completed in runtime 1600 + // Box::new(xcm_transactor_transact_signed), + // completed in runtime 1700 + //Box::new(migration_elasticity), + // completed in runtime 1900 + //Box::new(staking_at_stake_auto_compound), + // completed in runtime 2000 + //Box::new(scheduler_to_v4), + //Box::new(democracy_migration_hash_to_bounded_call), + //Box::new(preimage_migration_hash_to_bounded_call), + // completed in runtime 2100 + //Box::new(asset_manager_to_xcm_v3), + //Box::new(xcm_transactor_to_xcm_v3), + // completed in runtime 2600 + //Box::new(remove_min_bond_for_old_orbiter_collators), + // completed in runtime 2700 + // Box::new(missing_balances_migrations), + // Box::new(fix_pallet_versions), + // Box::new(pallet_referenda_migrate_v0_to_v1), + // completed in runtime 2800 + //Box::new(pallet_collective_drop_gov_v1_collectives), + // completed in runtime 2801 + // Box::new(pallet_staking_round), + // Box::new(pallet_collective_drop_gov_v1_collectives), + // completed in runtime 2900 + Box::new(remove_pallet_democracy), + Box::new(remove_collectives_addresses), + Box::new(migrate_pallet_identity), + // permanent migrations + Box::new(MigrateToLatestXcmVersion::(Default::default())), + ] + } +} diff --git a/tracing/2902/runtime/common/src/weights/cumulus_pallet_xcmp_queue.rs b/tracing/2902/runtime/common/src/weights/cumulus_pallet_xcmp_queue.rs new file mode 100644 index 00000000..fcc7db95 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/cumulus_pallet_xcmp_queue.rs @@ -0,0 +1,154 @@ +// 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 . + +//! Autogenerated weights for `cumulus_pallet_xcmp_queue` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=cumulus_pallet_xcmp_queue +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `cumulus_pallet_xcmp_queue`. +pub struct WeightInfo(PhantomData); +impl cumulus_pallet_xcmp_queue::WeightInfo for WeightInfo { + /// Storage: `XcmpQueue::QueueConfig` (r:1 w:1) + /// Proof: `XcmpQueue::QueueConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_config_with_u32() -> Weight { + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `1627` + // Minimum execution time: 4_599_000 picoseconds. + Weight::from_parts(4_823_000, 1627) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmpQueue::QueueConfig` (r:1 w:0) + /// Proof: `XcmpQueue::QueueConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::InboundXcmpSuspended` (r:1 w:0) + /// Proof: `XcmpQueue::InboundXcmpSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(134193), added: 136668, mode: `MaxEncodedLen`) + fn enqueue_xcmp_message() -> Weight { + // Proof Size summary in bytes: + // Measured: `148` + // Estimated: `3517` + // Minimum execution time: 11_813_000 picoseconds. + Weight::from_parts(12_241_000, 3517) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn suspend_channel() -> Weight { + // Proof Size summary in bytes: + // Measured: `142` + // Estimated: `1627` + // Minimum execution time: 2_901_000 picoseconds. + Weight::from_parts(3_040_000, 1627) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn resume_channel() -> Weight { + // Proof Size summary in bytes: + // Measured: `177` + // Estimated: `1662` + // Minimum execution time: 3_742_000 picoseconds. + Weight::from_parts(3_848_000, 1662) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn take_first_concatenated_xcm() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_580_000 picoseconds. + Weight::from_parts(7_910_000, 0) + } + /// Storage: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6b345d8e88afa015075c945637c07e8f20` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6b345d8e88afa015075c945637c07e8f20` (r:1 w:1) + /// Storage: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6bedc49980ba3aa32b0a189290fd036649` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6bedc49980ba3aa32b0a189290fd036649` (r:1 w:1) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::QueueConfig` (r:1 w:0) + /// Proof: `XcmpQueue::QueueConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::InboundXcmpSuspended` (r:1 w:0) + /// Proof: `XcmpQueue::InboundXcmpSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(134193), added: 136668, mode: `MaxEncodedLen`) + fn on_idle_good_msg() -> Weight { + // Proof Size summary in bytes: + // Measured: `134385` + // Estimated: `137850` + // Minimum execution time: 190_319_000 picoseconds. + Weight::from_parts(193_537_000, 137850) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6b345d8e88afa015075c945637c07e8f20` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6b345d8e88afa015075c945637c07e8f20` (r:1 w:1) + /// Storage: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6bedc49980ba3aa32b0a189290fd036649` (r:1 w:1) + /// Proof: UNKNOWN KEY `0x7b3237373ffdfeb1cab4222e3b520d6bedc49980ba3aa32b0a189290fd036649` (r:1 w:1) + /// Storage: `MessageQueue::BookStateFor` (r:1 w:1) + /// Proof: `MessageQueue::BookStateFor` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + /// Storage: `MessageQueue::ServiceHead` (r:1 w:1) + /// Proof: `MessageQueue::ServiceHead` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::QueueConfig` (r:1 w:0) + /// Proof: `XcmpQueue::QueueConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::InboundXcmpSuspended` (r:1 w:0) + /// Proof: `XcmpQueue::InboundXcmpSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MessageQueue::Pages` (r:0 w:1) + /// Proof: `MessageQueue::Pages` (`max_values`: None, `max_size`: Some(134193), added: 136668, mode: `MaxEncodedLen`) + fn on_idle_large_msg() -> Weight { + // Proof Size summary in bytes: + // Measured: `65782` + // Estimated: `69247` + // Minimum execution time: 103_908_000 picoseconds. + Weight::from_parts(105_455_000, 69247) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/mod.rs b/tracing/2902/runtime/common/src/weights/mod.rs new file mode 100644 index 00000000..48b83715 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/mod.rs @@ -0,0 +1,48 @@ +// 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 . + +//! Moonbeam common weights. + +pub mod cumulus_pallet_xcmp_queue; +pub mod pallet_asset_manager; +pub mod pallet_assets; +pub mod pallet_author_inherent; +pub mod pallet_author_mapping; +pub mod pallet_author_slot_filter; +pub mod pallet_balances; +pub mod pallet_collective; +pub mod pallet_conviction_voting; +pub mod pallet_crowdloan_rewards; +pub mod pallet_evm; +pub mod pallet_identity; +pub mod pallet_moonbeam_lazy_migrations; +pub mod pallet_moonbeam_orbiters; +pub mod pallet_multisig; +pub mod pallet_parachain_staking; +pub mod pallet_precompile_benchmarks; +pub mod pallet_preimage; +pub mod pallet_proxy; +pub mod pallet_randomness; +pub mod pallet_referenda; +pub mod pallet_relay_storage_roots; +pub mod pallet_scheduler; +pub mod pallet_sudo; +pub mod pallet_timestamp; +pub mod pallet_treasury; +pub mod pallet_utility; +pub mod pallet_whitelist; +pub mod pallet_xcm; +pub mod pallet_xcm_transactor; diff --git a/tracing/2902/runtime/common/src/weights/pallet_asset_manager.rs b/tracing/2902/runtime/common/src/weights/pallet_asset_manager.rs new file mode 100644 index 00000000..248c113b --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_asset_manager.rs @@ -0,0 +1,144 @@ +// 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 . + +//! Autogenerated weights for `pallet_asset_manager` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_asset_manager +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_asset_manager`. +pub struct WeightInfo(PhantomData); +impl pallet_asset_manager::WeightInfo for WeightInfo { + /// Storage: `AssetManager::AssetIdType` (r:1 w:1) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:1) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + /// Storage: `AssetManager::AssetTypeId` (r:0 w:1) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn register_foreign_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `82` + // Estimated: `3639` + // Minimum execution time: 29_830_000 picoseconds. + Weight::from_parts(30_736_000, 3639) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) + /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) + /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[5, 100]`. + fn set_asset_units_per_second(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `611 + x * (9 ±0)` + // Estimated: `4000 + x * (10 ±0)` + // Minimum execution time: 19_988_000 picoseconds. + Weight::from_parts(19_458_970, 4000) + // Standard Error: 2_974 + .saturating_add(Weight::from_parts(773_359, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) + } + /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) + /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetIdType` (r:1 w:1) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:1 w:2) + /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeId` (r:0 w:2) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[5, 100]`. + fn change_existing_asset_type(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `926 + x * (13 ±0)` + // Estimated: `4309 + x * (15 ±0)` + // Minimum execution time: 30_076_000 picoseconds. + Weight::from_parts(30_892_465, 4309) + // Standard Error: 4_039 + .saturating_add(Weight::from_parts(852_893, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + .saturating_add(Weight::from_parts(0, 15).saturating_mul(x.into())) + } + /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) + /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) + /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[5, 100]`. + fn remove_supported_asset(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `196 + x * (5 ±0)` + // Estimated: `1678 + x * (5 ±0)` + // Minimum execution time: 15_396_000 picoseconds. + Weight::from_parts(13_998_856, 1678) + // Standard Error: 2_734 + .saturating_add(Weight::from_parts(706_945, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 5).saturating_mul(x.into())) + } + /// Storage: `AssetManager::SupportedFeePaymentAssets` (r:1 w:1) + /// Proof: `AssetManager::SupportedFeePaymentAssets` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetIdType` (r:1 w:1) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeUnitsPerSecond` (r:0 w:1) + /// Proof: `AssetManager::AssetTypeUnitsPerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeId` (r:0 w:1) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[5, 100]`. + fn remove_existing_asset_type(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `482 + x * (10 ±0)` + // Estimated: `3955 + x * (10 ±0)` + // Minimum execution time: 21_743_000 picoseconds. + Weight::from_parts(21_130_966, 3955) + // Standard Error: 3_157 + .saturating_add(Weight::from_parts(727_255, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(Weight::from_parts(0, 10).saturating_mul(x.into())) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_assets.rs b/tracing/2902/runtime/common/src/weights/pallet_assets.rs new file mode 100644 index 00000000..1bc42148 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_assets.rs @@ -0,0 +1,485 @@ +// 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 . + +//! Autogenerated weights for `pallet_assets` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_assets +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_assets`. +pub struct WeightInfo(PhantomData); +impl pallet_assets::WeightInfo for WeightInfo { + fn create() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 0_000 picoseconds. + Weight::from_parts(0, 0) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn force_create() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `3639` + // Minimum execution time: 9_311_000 picoseconds. + Weight::from_parts(9_640_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn start_destroy() -> Weight { + // Proof Size summary in bytes: + // Measured: `241` + // Estimated: `3639` + // Minimum execution time: 10_710_000 picoseconds. + Weight::from_parts(11_184_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:657 w:656) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:656 w:656) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `c` is `[0, 656]`. + fn destroy_accounts(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1359 + c * (183 ±0)` + // Estimated: `3639 + c * (2597 ±0)` + // Minimum execution time: 15_240_000 picoseconds. + Weight::from_parts(15_481_000, 3639) + // Standard Error: 9_062 + .saturating_add(Weight::from_parts(15_791_127, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(c.into()))) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(c.into()))) + .saturating_add(Weight::from_parts(0, 2597).saturating_mul(c.into())) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Approvals` (r:657 w:656) + /// Proof: `Assets::Approvals` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 656]`. + fn destroy_approvals(a: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `313 + a * (74 ±0)` + // Estimated: `3639 + a * (2611 ±0)` + // Minimum execution time: 16_051_000 picoseconds. + Weight::from_parts(16_294_000, 3639) + // Standard Error: 6_449 + .saturating_add(Weight::from_parts(8_360_355, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(a.into()))) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(a.into()))) + .saturating_add(Weight::from_parts(0, 2611).saturating_mul(a.into())) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:0) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + fn finish_destroy() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 11_619_000 picoseconds. + Weight::from_parts(11_886_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + fn mint() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 20_717_000 picoseconds. + Weight::from_parts(21_127_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + fn burn() -> Weight { + // Proof Size summary in bytes: + // Measured: `315` + // Estimated: `3639` + // Minimum execution time: 28_139_000 picoseconds. + Weight::from_parts(28_640_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `420` + // Estimated: `6184` + // Minimum execution time: 40_122_000 picoseconds. + Weight::from_parts(40_528_000, 6184) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer_keep_alive() -> Weight { + // Proof Size summary in bytes: + // Measured: `420` + // Estimated: `6184` + // Minimum execution time: 35_519_000 picoseconds. + Weight::from_parts(36_732_000, 6184) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn force_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `420` + // Estimated: `6184` + // Minimum execution time: 39_819_000 picoseconds. + Weight::from_parts(40_611_000, 6184) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + fn freeze() -> Weight { + // Proof Size summary in bytes: + // Measured: `315` + // Estimated: `3639` + // Minimum execution time: 14_292_000 picoseconds. + Weight::from_parts(14_764_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + fn thaw() -> Weight { + // Proof Size summary in bytes: + // Measured: `315` + // Estimated: `3639` + // Minimum execution time: 14_173_000 picoseconds. + Weight::from_parts(14_628_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn freeze_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `241` + // Estimated: `3639` + // Minimum execution time: 10_270_000 picoseconds. + Weight::from_parts(10_712_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn thaw_asset() -> Weight { + // Proof Size summary in bytes: + // Measured: `241` + // Estimated: `3639` + // Minimum execution time: 10_229_000 picoseconds. + Weight::from_parts(10_596_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:0) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + fn transfer_ownership() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 12_033_000 picoseconds. + Weight::from_parts(12_335_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn set_team() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 10_454_000 picoseconds. + Weight::from_parts(10_743_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:1) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + /// The range of component `n` is `[0, 50]`. + /// The range of component `s` is `[0, 50]`. + fn set_metadata(n: u32, s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 25_352_000 picoseconds. + Weight::from_parts(26_355_659, 3639) + // Standard Error: 538 + .saturating_add(Weight::from_parts(955, 0).saturating_mul(n.into())) + // Standard Error: 538 + .saturating_add(Weight::from_parts(1_407, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:1) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + fn clear_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `383` + // Estimated: `3639` + // Minimum execution time: 26_449_000 picoseconds. + Weight::from_parts(26_877_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:1) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + /// The range of component `n` is `[0, 50]`. + /// The range of component `s` is `[0, 50]`. + fn force_set_metadata(n: u32, s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `94` + // Estimated: `3639` + // Minimum execution time: 10_953_000 picoseconds. + Weight::from_parts(11_548_090, 3639) + // Standard Error: 283 + .saturating_add(Weight::from_parts(1_176, 0).saturating_mul(n.into())) + // Standard Error: 283 + .saturating_add(Weight::from_parts(586, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Metadata` (r:1 w:1) + /// Proof: `Assets::Metadata` (`max_values`: None, `max_size`: Some(152), added: 2627, mode: `MaxEncodedLen`) + fn force_clear_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `383` + // Estimated: `3639` + // Minimum execution time: 25_835_000 picoseconds. + Weight::from_parts(26_847_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn force_asset_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 9_865_000 picoseconds. + Weight::from_parts(10_151_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Approvals` (r:1 w:1) + /// Proof: `Assets::Approvals` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + fn approve_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `241` + // Estimated: `3639` + // Minimum execution time: 16_508_000 picoseconds. + Weight::from_parts(16_834_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Approvals` (r:1 w:1) + /// Proof: `Assets::Approvals` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:2 w:2) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer_approved() -> Weight { + // Proof Size summary in bytes: + // Measured: `513` + // Estimated: `6184` + // Minimum execution time: 48_917_000 picoseconds. + Weight::from_parts(49_824_000, 6184) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Approvals` (r:1 w:1) + /// Proof: `Assets::Approvals` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + fn cancel_approval() -> Weight { + // Proof Size summary in bytes: + // Measured: `399` + // Estimated: `3639` + // Minimum execution time: 18_226_000 picoseconds. + Weight::from_parts(18_762_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Approvals` (r:1 w:1) + /// Proof: `Assets::Approvals` (`max_values`: None, `max_size`: Some(136), added: 2611, mode: `MaxEncodedLen`) + fn force_cancel_approval() -> Weight { + // Proof Size summary in bytes: + // Measured: `399` + // Estimated: `3639` + // Minimum execution time: 18_655_000 picoseconds. + Weight::from_parts(19_074_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn set_min_balance() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 11_033_000 picoseconds. + Weight::from_parts(11_236_000, 3639) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn touch() -> Weight { + // Proof Size summary in bytes: + // Measured: `435` + // Estimated: `3639` + // Minimum execution time: 30_611_000 picoseconds. + Weight::from_parts(31_492_000, 3639) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn touch_other() -> Weight { + // Proof Size summary in bytes: + // Measured: `207` + // Estimated: `3639` + // Minimum execution time: 28_482_000 picoseconds. + Weight::from_parts(29_498_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn refund() -> Weight { + // Proof Size summary in bytes: + // Measured: `561` + // Estimated: `3639` + // Minimum execution time: 30_261_000 picoseconds. + Weight::from_parts(31_050_000, 3639) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + /// Storage: `Assets::Asset` (r:1 w:1) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn refund_other() -> Weight { + // Proof Size summary in bytes: + // Measured: `353` + // Estimated: `3639` + // Minimum execution time: 27_945_000 picoseconds. + Weight::from_parts(28_808_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + /// Storage: `Assets::Account` (r:1 w:1) + /// Proof: `Assets::Account` (`max_values`: None, `max_size`: Some(122), added: 2597, mode: `MaxEncodedLen`) + fn block() -> Weight { + // Proof Size summary in bytes: + // Measured: `315` + // Estimated: `3639` + // Minimum execution time: 14_179_000 picoseconds. + Weight::from_parts(14_486_000, 3639) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_author_inherent.rs b/tracing/2902/runtime/common/src/weights/pallet_author_inherent.rs new file mode 100644 index 00000000..ab09ba88 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_author_inherent.rs @@ -0,0 +1,70 @@ +// 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 . + +//! Autogenerated weights for `pallet_author_inherent` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_author_inherent +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_author_inherent`. +pub struct WeightInfo(PhantomData); +impl pallet_author_inherent::WeightInfo for WeightInfo { + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AuthorInherent::Author` (r:1 w:0) + /// Proof: `AuthorInherent::Author` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::SelectedCandidates` (r:1 w:0) + /// Proof: `ParachainStaking::SelectedCandidates` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AuthorFilter::EligibleCount` (r:1 w:0) + /// Proof: `AuthorFilter::EligibleCount` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::PreviousLocalVrfOutput` (r:1 w:0) + /// Proof: `Randomness::PreviousLocalVrfOutput` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AuthorInherent::InherentIncluded` (r:0 w:1) + /// Proof: `AuthorInherent::InherentIncluded` (`max_values`: Some(1), `max_size`: Some(1), added: 496, mode: `MaxEncodedLen`) + fn kick_off_authorship_validation() -> Weight { + // Proof Size summary in bytes: + // Measured: `372` + // Estimated: `1857` + // Minimum execution time: 17_417_000 picoseconds. + Weight::from_parts(17_809_000, 1857) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_author_mapping.rs b/tracing/2902/runtime/common/src/weights/pallet_author_mapping.rs new file mode 100644 index 00000000..691b9bf6 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_author_mapping.rs @@ -0,0 +1,122 @@ +// 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 . + +//! Autogenerated weights for `pallet_author_mapping` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_author_mapping +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_author_mapping`. +pub struct WeightInfo(PhantomData); +impl pallet_author_mapping::WeightInfo for WeightInfo { + /// Storage: `AuthorMapping::MappingWithDeposit` (r:1 w:1) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `AuthorMapping::NimbusLookup` (r:0 w:1) + /// Proof: `AuthorMapping::NimbusLookup` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn add_association() -> Weight { + // Proof Size summary in bytes: + // Measured: `376` + // Estimated: `3841` + // Minimum execution time: 27_782_000 picoseconds. + Weight::from_parts(28_609_000, 3841) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `AuthorMapping::MappingWithDeposit` (r:2 w:2) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AuthorMapping::NimbusLookup` (r:0 w:1) + /// Proof: `AuthorMapping::NimbusLookup` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn update_association() -> Weight { + // Proof Size summary in bytes: + // Measured: `325` + // Estimated: `6265` + // Minimum execution time: 17_725_000 picoseconds. + Weight::from_parts(18_140_000, 6265) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `AuthorMapping::MappingWithDeposit` (r:1 w:1) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `AuthorMapping::NimbusLookup` (r:0 w:1) + /// Proof: `AuthorMapping::NimbusLookup` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn clear_association() -> Weight { + // Proof Size summary in bytes: + // Measured: `453` + // Estimated: `3918` + // Minimum execution time: 28_560_000 picoseconds. + Weight::from_parts(29_318_000, 3918) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `AuthorMapping::NimbusLookup` (r:1 w:1) + /// Proof: `AuthorMapping::NimbusLookup` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AuthorMapping::MappingWithDeposit` (r:1 w:1) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn remove_keys() -> Weight { + // Proof Size summary in bytes: + // Measured: `547` + // Estimated: `4012` + // Minimum execution time: 34_779_000 picoseconds. + Weight::from_parts(35_685_000, 4012) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `AuthorMapping::NimbusLookup` (r:1 w:1) + /// Proof: `AuthorMapping::NimbusLookup` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AuthorMapping::MappingWithDeposit` (r:1 w:1) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn set_keys() -> Weight { + // Proof Size summary in bytes: + // Measured: `432` + // Estimated: `3897` + // Minimum execution time: 30_704_000 picoseconds. + Weight::from_parts(31_832_000, 3897) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_author_slot_filter.rs b/tracing/2902/runtime/common/src/weights/pallet_author_slot_filter.rs new file mode 100644 index 00000000..1d7842fe --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_author_slot_filter.rs @@ -0,0 +1,59 @@ +// 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 . + +//! Autogenerated weights for `pallet_author_slot_filter` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_author_slot_filter +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_author_slot_filter`. +pub struct WeightInfo(PhantomData); +impl pallet_author_slot_filter::WeightInfo for WeightInfo { + /// Storage: `AuthorFilter::EligibleCount` (r:0 w:1) + /// Proof: `AuthorFilter::EligibleCount` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_eligible() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_543_000 picoseconds. + Weight::from_parts(4_833_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_balances.rs b/tracing/2902/runtime/common/src/weights/pallet_balances.rs new file mode 100644 index 00000000..71120250 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_balances.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 . + +//! Autogenerated weights for `pallet_balances` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_balances +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_balances`. +pub struct WeightInfo(PhantomData); +impl pallet_balances::WeightInfo for WeightInfo { + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer_allow_death() -> Weight { + // Proof Size summary in bytes: + // Measured: `72` + // Estimated: `3581` + // Minimum execution time: 41_684_000 picoseconds. + Weight::from_parts(42_289_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer_keep_alive() -> Weight { + // Proof Size summary in bytes: + // Measured: `72` + // Estimated: `3581` + // Minimum execution time: 40_145_000 picoseconds. + Weight::from_parts(40_934_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn force_set_balance_creating() -> Weight { + // Proof Size summary in bytes: + // Measured: `195` + // Estimated: `3581` + // Minimum execution time: 15_448_000 picoseconds. + Weight::from_parts(15_726_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn force_set_balance_killing() -> Weight { + // Proof Size summary in bytes: + // Measured: `195` + // Estimated: `3581` + // Minimum execution time: 16_390_000 picoseconds. + Weight::from_parts(16_702_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn force_transfer() -> Weight { + // Proof Size summary in bytes: + // Measured: `267` + // Estimated: `6172` + // Minimum execution time: 44_041_000 picoseconds. + Weight::from_parts(44_655_000, 6172) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn transfer_all() -> Weight { + // Proof Size summary in bytes: + // Measured: `72` + // Estimated: `3581` + // Minimum execution time: 44_316_000 picoseconds. + Weight::from_parts(45_153_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn force_unreserve() -> Weight { + // Proof Size summary in bytes: + // Measured: `195` + // Estimated: `3581` + // Minimum execution time: 18_223_000 picoseconds. + Weight::from_parts(18_633_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:999 w:999) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `u` is `[1, 1000]`. + fn upgrade_accounts(u: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1137 + u * (123 ±0)` + // Estimated: `990 + u * (2591 ±0)` + // Minimum execution time: 16_981_000 picoseconds. + Weight::from_parts(17_151_000, 990) + // Standard Error: 10_657 + .saturating_add(Weight::from_parts(13_838_684, 0).saturating_mul(u.into())) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(u.into()))) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(u.into()))) + .saturating_add(Weight::from_parts(0, 2591).saturating_mul(u.into())) + } + /// Storage: `Balances::InactiveIssuance` (r:1 w:0) + /// Proof: `Balances::InactiveIssuance` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + fn force_adjust_total_issuance() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `1501` + // Minimum execution time: 6_481_000 picoseconds. + Weight::from_parts(6_671_000, 1501) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_collective.rs b/tracing/2902/runtime/common/src/weights/pallet_collective.rs new file mode 100644 index 00000000..5c70e97f --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_collective.rs @@ -0,0 +1,308 @@ +// 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 . +//! Autogenerated weights for `pallet_collective` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2023-11-01, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/release/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_collective +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --output=./runtime/common/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_collective`. +pub struct WeightInfo(PhantomData); +impl pallet_collective::WeightInfo for WeightInfo { + /// Storage: CouncilCollective Members (r:1 w:1) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:0) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Voting (r:100 w:100) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Prime (r:0 w:1) + /// Proof Skipped: CouncilCollective Prime (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `m` is `[0, 100]`. + /// The range of component `n` is `[0, 100]`. + /// The range of component `p` is `[0, 100]`. + fn set_members(m: u32, _n: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0 + m * (2021 ±0) + p * (2026 ±0)` + // Estimated: `12238 + m * (1231 ±14) + p * (3660 ±14)` + // Minimum execution time: 13_785_000 picoseconds. + Weight::from_parts(14_085_000, 0) + .saturating_add(Weight::from_parts(0, 12238)) + // Standard Error: 34_315 + .saturating_add(Weight::from_parts(2_414_144, 0).saturating_mul(m.into())) + // Standard Error: 34_315 + .saturating_add(Weight::from_parts(5_345_562, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(T::DbWeight::get().writes(2)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) + .saturating_add(Weight::from_parts(0, 1231).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 3660).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: MaintenanceMode MaintenanceMode (r:1 w:0) + /// Proof Skipped: MaintenanceMode MaintenanceMode (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `b` is `[2, 1024]`. + /// The range of component `m` is `[1, 100]`. + fn execute(b: u32, m: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `149 + m * (20 ±0)` + // Estimated: `1634 + m * (20 ±0)` + // Minimum execution time: 12_726_000 picoseconds. + Weight::from_parts(12_294_605, 0) + .saturating_add(Weight::from_parts(0, 1634)) + // Standard Error: 18 + .saturating_add(Weight::from_parts(910, 0).saturating_mul(b.into())) + // Standard Error: 192 + .saturating_add(Weight::from_parts(13_235, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(Weight::from_parts(0, 20).saturating_mul(m.into())) + } + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:1 w:0) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// Storage: MaintenanceMode MaintenanceMode (r:1 w:0) + /// Proof Skipped: MaintenanceMode MaintenanceMode (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `b` is `[2, 1024]`. + /// The range of component `m` is `[1, 100]`. + fn propose_execute(b: u32, m: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `149 + m * (20 ±0)` + // Estimated: `3614 + m * (20 ±0)` + // Minimum execution time: 14_722_000 picoseconds. + Weight::from_parts(14_487_427, 0) + .saturating_add(Weight::from_parts(0, 3614)) + // Standard Error: 20 + .saturating_add(Weight::from_parts(944, 0).saturating_mul(b.into())) + // Standard Error: 215 + .saturating_add(Weight::from_parts(25_619, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(Weight::from_parts(0, 20).saturating_mul(m.into())) + } + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:1 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalCount (r:1 w:1) + /// Proof Skipped: CouncilCollective ProposalCount (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Voting (r:0 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// The range of component `b` is `[2, 1024]`. + /// The range of component `m` is `[2, 100]`. + /// The range of component `p` is `[1, 100]`. + fn propose_proposed(b: u32, m: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `395 + m * (20 ±0) + p * (36 ±0)` + // Estimated: `3789 + m * (21 ±0) + p * (36 ±0)` + // Minimum execution time: 17_107_000 picoseconds. + Weight::from_parts(15_172_014, 0) + .saturating_add(Weight::from_parts(0, 3789)) + // Standard Error: 104 + .saturating_add(Weight::from_parts(3_191, 0).saturating_mul(b.into())) + // Standard Error: 1_090 + .saturating_add(Weight::from_parts(31_145, 0).saturating_mul(m.into())) + // Standard Error: 1_077 + .saturating_add(Weight::from_parts(131_855, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(4)) + .saturating_add(Weight::from_parts(0, 21).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 36).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Voting (r:1 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// The range of component `m` is `[5, 100]`. + fn vote(m: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `870 + m * (40 ±0)` + // Estimated: `4334 + m * (40 ±0)` + // Minimum execution time: 21_423_000 picoseconds. + Weight::from_parts(22_311_906, 0) + .saturating_add(Weight::from_parts(0, 4334)) + // Standard Error: 415 + .saturating_add(Weight::from_parts(32_990, 0).saturating_mul(m.into())) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + .saturating_add(Weight::from_parts(0, 40).saturating_mul(m.into())) + } + /// Storage: CouncilCollective Voting (r:1 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:0 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// The range of component `m` is `[4, 100]`. + /// The range of component `p` is `[1, 100]`. + fn close_early_disapproved(m: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `447 + m * (40 ±0) + p * (36 ±0)` + // Estimated: `3892 + m * (41 ±0) + p * (36 ±0)` + // Minimum execution time: 20_010_000 picoseconds. + Weight::from_parts(20_008_777, 0) + .saturating_add(Weight::from_parts(0, 3892)) + // Standard Error: 1_391 + .saturating_add(Weight::from_parts(39_960, 0).saturating_mul(m.into())) + // Standard Error: 1_356 + .saturating_add(Weight::from_parts(126_447, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 41).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 36).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Voting (r:1 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:1 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// Storage: MaintenanceMode MaintenanceMode (r:1 w:0) + /// Proof Skipped: MaintenanceMode MaintenanceMode (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `b` is `[2, 1024]`. + /// The range of component `m` is `[4, 100]`. + /// The range of component `p` is `[1, 100]`. + fn close_early_approved(b: u32, m: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `791 + b * (1 ±0) + m * (40 ±0) + p * (40 ±0)` + // Estimated: `4108 + b * (1 ±0) + m * (42 ±0) + p * (40 ±0)` + // Minimum execution time: 30_647_000 picoseconds. + Weight::from_parts(30_084_699, 0) + .saturating_add(Weight::from_parts(0, 4108)) + // Standard Error: 123 + .saturating_add(Weight::from_parts(2_876, 0).saturating_mul(b.into())) + // Standard Error: 1_307 + .saturating_add(Weight::from_parts(31_661, 0).saturating_mul(m.into())) + // Standard Error: 1_274 + .saturating_add(Weight::from_parts(154_567, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(0, 42).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 40).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Voting (r:1 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Prime (r:1 w:0) + /// Proof Skipped: CouncilCollective Prime (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:0 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// The range of component `m` is `[4, 100]`. + /// The range of component `p` is `[1, 100]`. + fn close_disapproved(m: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `516 + m * (30 ±0) + p * (36 ±0)` + // Estimated: `3958 + m * (31 ±0) + p * (36 ±0)` + // Minimum execution time: 20_735_000 picoseconds. + Weight::from_parts(22_649_363, 0) + .saturating_add(Weight::from_parts(0, 3958)) + // Standard Error: 1_082 + .saturating_add(Weight::from_parts(32_331, 0).saturating_mul(m.into())) + // Standard Error: 1_055 + .saturating_add(Weight::from_parts(122_034, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 31).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 36).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Voting (r:1 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective Members (r:1 w:0) + /// Proof Skipped: CouncilCollective Members (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Prime (r:1 w:0) + /// Proof Skipped: CouncilCollective Prime (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:1 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// Storage: MaintenanceMode MaintenanceMode (r:1 w:0) + /// Proof Skipped: MaintenanceMode MaintenanceMode (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// The range of component `b` is `[2, 1024]`. + /// The range of component `m` is `[4, 100]`. + /// The range of component `p` is `[1, 100]`. + fn close_approved(b: u32, m: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `811 + b * (1 ±0) + m * (40 ±0) + p * (40 ±0)` + // Estimated: `4128 + b * (1 ±0) + m * (42 ±0) + p * (40 ±0)` + // Minimum execution time: 32_927_000 picoseconds. + Weight::from_parts(32_086_367, 0) + .saturating_add(Weight::from_parts(0, 4128)) + // Standard Error: 122 + .saturating_add(Weight::from_parts(2_962, 0).saturating_mul(b.into())) + // Standard Error: 1_299 + .saturating_add(Weight::from_parts(32_167, 0).saturating_mul(m.into())) + // Standard Error: 1_266 + .saturating_add(Weight::from_parts(154_131, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(b.into())) + .saturating_add(Weight::from_parts(0, 42).saturating_mul(m.into())) + .saturating_add(Weight::from_parts(0, 40).saturating_mul(p.into())) + } + /// Storage: CouncilCollective Proposals (r:1 w:1) + /// Proof Skipped: CouncilCollective Proposals (max_values: Some(1), max_size: None, mode: Measured) + /// Storage: CouncilCollective Voting (r:0 w:1) + /// Proof Skipped: CouncilCollective Voting (max_values: None, max_size: None, mode: Measured) + /// Storage: CouncilCollective ProposalOf (r:0 w:1) + /// Proof Skipped: CouncilCollective ProposalOf (max_values: None, max_size: None, mode: Measured) + /// The range of component `p` is `[1, 100]`. + fn disapprove_proposal(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `264 + p * (32 ±0)` + // Estimated: `1749 + p * (32 ±0)` + // Minimum execution time: 10_334_000 picoseconds. + Weight::from_parts(11_413_201, 0) + .saturating_add(Weight::from_parts(0, 1749)) + // Standard Error: 1_033 + .saturating_add(Weight::from_parts(95_458, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(3)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(p.into())) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_conviction_voting.rs b/tracing/2902/runtime/common/src/weights/pallet_conviction_voting.rs new file mode 100644 index 00000000..b64f16db --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_conviction_voting.rs @@ -0,0 +1,184 @@ +// 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 . + +//! Autogenerated weights for `pallet_conviction_voting` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_conviction_voting +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_conviction_voting`. +pub struct WeightInfo(PhantomData); +impl pallet_conviction_voting::WeightInfo for WeightInfo { + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::VotingFor` (r:1 w:1) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::ClassLocksFor` (r:1 w:1) + /// Proof: `ConvictionVoting::ClassLocksFor` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn vote_new() -> Weight { + // Proof Size summary in bytes: + // Measured: `1961` + // Estimated: `42428` + // Minimum execution time: 63_255_000 picoseconds. + Weight::from_parts(65_721_000, 42428) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::VotingFor` (r:1 w:1) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::ClassLocksFor` (r:1 w:1) + /// Proof: `ConvictionVoting::ClassLocksFor` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn vote_existing() -> Weight { + // Proof Size summary in bytes: + // Measured: `2262` + // Estimated: `83866` + // Minimum execution time: 83_134_000 picoseconds. + Weight::from_parts(85_859_000, 83866) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(6_u64)) + } + /// Storage: `ConvictionVoting::VotingFor` (r:1 w:1) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn remove_vote() -> Weight { + // Proof Size summary in bytes: + // Measured: `1840` + // Estimated: `83866` + // Minimum execution time: 55_539_000 picoseconds. + Weight::from_parts(57_196_000, 83866) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `ConvictionVoting::VotingFor` (r:1 w:1) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + fn remove_other_vote() -> Weight { + // Proof Size summary in bytes: + // Measured: `1384` + // Estimated: `4617` + // Minimum execution time: 20_722_000 picoseconds. + Weight::from_parts(21_199_000, 4617) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ConvictionVoting::VotingFor` (r:2 w:2) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:20 w:20) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::ClassLocksFor` (r:1 w:1) + /// Proof: `ConvictionVoting::ClassLocksFor` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// The range of component `r` is `[0, 20]`. + fn delegate(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1620 + r * (248 ±0)` + // Estimated: `83866 + r * (3387 ±0)` + // Minimum execution time: 44_300_000 picoseconds. + Weight::from_parts(39_609_524, 83866) + // Standard Error: 80_179 + .saturating_add(Weight::from_parts(24_498_559, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) + .saturating_add(T::DbWeight::get().writes(6_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) + .saturating_add(Weight::from_parts(0, 3387).saturating_mul(r.into())) + } + /// Storage: `ConvictionVoting::VotingFor` (r:2 w:2) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:20 w:20) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// The range of component `r` is `[0, 20]`. + fn undelegate(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1339 + r * (248 ±0)` + // Estimated: `83866 + r * (3387 ±0)` + // Minimum execution time: 20_213_000 picoseconds. + Weight::from_parts(11_563_375, 83866) + // Standard Error: 81_737 + .saturating_add(Weight::from_parts(24_404_856, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(r.into()))) + .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(r.into()))) + .saturating_add(Weight::from_parts(0, 3387).saturating_mul(r.into())) + } + /// Storage: `ConvictionVoting::VotingFor` (r:1 w:1) + /// Proof: `ConvictionVoting::VotingFor` (`max_values`: None, `max_size`: Some(1152), added: 3627, mode: `MaxEncodedLen`) + /// Storage: `ConvictionVoting::ClassLocksFor` (r:1 w:1) + /// Proof: `ConvictionVoting::ClassLocksFor` (`max_values`: None, `max_size`: Some(137), added: 2612, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + fn unlock() -> Weight { + // Proof Size summary in bytes: + // Measured: `1228` + // Estimated: `4752` + // Minimum execution time: 47_709_000 picoseconds. + Weight::from_parts(48_634_000, 4752) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_crowdloan_rewards.rs b/tracing/2902/runtime/common/src/weights/pallet_crowdloan_rewards.rs new file mode 100644 index 00000000..de7fec94 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_crowdloan_rewards.rs @@ -0,0 +1,163 @@ +// 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 . + +//! Autogenerated weights for `pallet_crowdloan_rewards` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_crowdloan_rewards +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_crowdloan_rewards`. +pub struct WeightInfo(PhantomData); +impl pallet_crowdloan_rewards::WeightInfo for WeightInfo { + /// Storage: `CrowdloanRewards::Initialized` (r:1 w:0) + /// Proof: `CrowdloanRewards::Initialized` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::InitializedRewardAmount` (r:1 w:1) + /// Proof: `CrowdloanRewards::InitializedRewardAmount` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::TotalContributors` (r:1 w:1) + /// Proof: `CrowdloanRewards::TotalContributors` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:501 w:501) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `CrowdloanRewards::ClaimedRelayChainIds` (r:500 w:500) + /// Proof: `CrowdloanRewards::ClaimedRelayChainIds` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::UnassociatedContributions` (r:500 w:0) + /// Proof: `CrowdloanRewards::UnassociatedContributions` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::AccountsPayable` (r:500 w:500) + /// Proof: `CrowdloanRewards::AccountsPayable` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 500]`. + fn initialize_reward_vec(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `75971 + x * (659 ±0)` + // Estimated: `66133 + x * (3161 ±5)` + // Minimum execution time: 110_884_000 picoseconds. + Weight::from_parts(147_336_064, 66133) + // Standard Error: 40_142 + .saturating_add(Weight::from_parts(54_050_188, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 3161).saturating_mul(x.into())) + } + /// Storage: `CrowdloanRewards::Initialized` (r:1 w:1) + /// Proof: `CrowdloanRewards::Initialized` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::InitRelayBlock` (r:1 w:0) + /// Proof: `CrowdloanRewards::InitRelayBlock` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::InitializedRewardAmount` (r:1 w:0) + /// Proof: `CrowdloanRewards::InitializedRewardAmount` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `CrowdloanRewards::TotalContributors` (r:1 w:0) + /// Proof: `CrowdloanRewards::TotalContributors` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::EndRelayBlock` (r:0 w:1) + /// Proof: `CrowdloanRewards::EndRelayBlock` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn complete_initialization() -> Weight { + // Proof Size summary in bytes: + // Measured: `579` + // Estimated: `3581` + // Minimum execution time: 15_351_000 picoseconds. + Weight::from_parts(15_735_000, 3581) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `CrowdloanRewards::Initialized` (r:1 w:0) + /// Proof: `CrowdloanRewards::Initialized` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::AccountsPayable` (r:1 w:1) + /// Proof: `CrowdloanRewards::AccountsPayable` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::InitRelayBlock` (r:1 w:0) + /// Proof: `CrowdloanRewards::InitRelayBlock` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::EndRelayBlock` (r:1 w:0) + /// Proof: `CrowdloanRewards::EndRelayBlock` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn claim() -> Weight { + // Proof Size summary in bytes: + // Measured: `1100` + // Estimated: `6172` + // Minimum execution time: 62_595_000 picoseconds. + Weight::from_parts(63_760_000, 6172) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `CrowdloanRewards::AccountsPayable` (r:2 w:2) + /// Proof: `CrowdloanRewards::AccountsPayable` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn update_reward_address() -> Weight { + // Proof Size summary in bytes: + // Measured: `397` + // Estimated: `6337` + // Minimum execution time: 17_926_000 picoseconds. + Weight::from_parts(18_219_000, 6337) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `CrowdloanRewards::UnassociatedContributions` (r:1 w:1) + /// Proof: `CrowdloanRewards::UnassociatedContributions` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::ClaimedRelayChainIds` (r:1 w:1) + /// Proof: `CrowdloanRewards::ClaimedRelayChainIds` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `CrowdloanRewards::AccountsPayable` (r:1 w:1) + /// Proof: `CrowdloanRewards::AccountsPayable` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn associate_native_identity() -> Weight { + // Proof Size summary in bytes: + // Measured: `934` + // Estimated: `6172` + // Minimum execution time: 122_312_000 picoseconds. + Weight::from_parts(124_403_000, 6172) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: `CrowdloanRewards::AccountsPayable` (r:2 w:2) + /// Proof: `CrowdloanRewards::AccountsPayable` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 500]`. + fn change_association_with_relay_keys(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `366 + x * (32 ±0)` + // Estimated: `6306 + x * (32 ±0)` + // Minimum execution time: 76_926_000 picoseconds. + Weight::from_parts(77_278_000, 6306) + // Standard Error: 11_622 + .saturating_add(Weight::from_parts(57_377_263, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 32).saturating_mul(x.into())) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_evm.rs b/tracing/2902/runtime/common/src/weights/pallet_evm.rs new file mode 100644 index 00000000..5a506cbd --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_evm.rs @@ -0,0 +1,78 @@ +// 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 . + +//! Autogenerated weights for `pallet_evm` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_evm +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_evm`. +pub struct WeightInfo(PhantomData); +impl pallet_evm::WeightInfo for WeightInfo { + /// Storage: `TransactionPayment::NextFeeMultiplier` (r:1 w:0) + /// Proof: `TransactionPayment::NextFeeMultiplier` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `EthereumChainId::ChainId` (r:1 w:0) + /// Proof: `EthereumChainId::ChainId` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + /// Storage: `EVM::AccountCodes` (r:2 w:0) + /// Proof: `EVM::AccountCodes` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `EVM::AccountStorages` (r:1 w:0) + /// Proof: `EVM::AccountStorages` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 10000000]`. + fn runner_execute(_x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1574` + // Estimated: `7514` + // Minimum execution time: 25_094_983_000 picoseconds. + Weight::from_parts(25_279_087_568, 7514) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + fn withdraw() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 1_878_000 picoseconds. + Weight::from_parts(2_005_000, 0) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_identity.rs b/tracing/2902/runtime/common/src/weights/pallet_identity.rs new file mode 100644 index 00000000..66abc430 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_identity.rs @@ -0,0 +1,411 @@ +// 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 . + +//! Autogenerated weights for `pallet_identity` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_identity +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_identity`. +pub struct WeightInfo(PhantomData); +impl pallet_identity::WeightInfo for WeightInfo { + /// Storage: `Identity::Registrars` (r:1 w:1) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 19]`. + fn add_registrar(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `32 + r * (45 ±0)` + // Estimated: `2386` + // Minimum execution time: 8_498_000 picoseconds. + Weight::from_parts(9_024_352, 2386) + // Standard Error: 1_263 + .saturating_add(Weight::from_parts(86_602, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 20]`. + fn set_identity(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `6966 + r * (5 ±0)` + // Estimated: `11025` + // Minimum execution time: 112_680_000 picoseconds. + Weight::from_parts(115_285_152, 11025) + // Standard Error: 5_277 + .saturating_add(Weight::from_parts(190_684, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:100 w:100) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 100]`. + fn set_subs_new(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `89` + // Estimated: `11025 + s * (2565 ±0)` + // Minimum execution time: 9_044_000 picoseconds. + Weight::from_parts(22_565_890, 11025) + // Standard Error: 4_822 + .saturating_add(Weight::from_parts(3_282_830, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(s.into()))) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) + .saturating_add(Weight::from_parts(0, 2565).saturating_mul(s.into())) + } + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:0 w:100) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 100]`. + fn set_subs_old(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `169 + p * (20 ±0)` + // Estimated: `11025` + // Minimum execution time: 9_038_000 picoseconds. + Weight::from_parts(22_528_876, 11025) + // Standard Error: 3_237 + .saturating_add(Weight::from_parts(1_326_320, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(p.into()))) + } + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:0 w:100) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 20]`. + /// The range of component `s` is `[0, 100]`. + fn clear_identity(r: u32, s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `7046 + r * (5 ±0) + s * (20 ±0)` + // Estimated: `11025` + // Minimum execution time: 57_176_000 picoseconds. + Weight::from_parts(57_333_594, 11025) + // Standard Error: 7_257 + .saturating_add(Weight::from_parts(195_450, 0).saturating_mul(r.into())) + // Standard Error: 1_416 + .saturating_add(Weight::from_parts(1_326_826, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) + } + /// Storage: `Identity::Registrars` (r:1 w:0) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 20]`. + fn request_judgement(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `6956 + r * (45 ±0)` + // Estimated: `11025` + // Minimum execution time: 78_701_000 picoseconds. + Weight::from_parts(80_440_545, 11025) + // Standard Error: 3_857 + .saturating_add(Weight::from_parts(129_413, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 20]`. + fn cancel_request(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `6987` + // Estimated: `11025` + // Minimum execution time: 76_445_000 picoseconds. + Weight::from_parts(77_426_259, 11025) + // Standard Error: 3_373 + .saturating_add(Weight::from_parts(127_374, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::Registrars` (r:1 w:1) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 19]`. + fn set_fee(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `77 + r * (45 ±0)` + // Estimated: `2386` + // Minimum execution time: 6_225_000 picoseconds. + Weight::from_parts(6_559_852, 2386) + // Standard Error: 923 + .saturating_add(Weight::from_parts(70_556, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::Registrars` (r:1 w:1) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 19]`. + fn set_account_id(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `77 + r * (45 ±0)` + // Estimated: `2386` + // Minimum execution time: 6_252_000 picoseconds. + Weight::from_parts(6_559_957, 2386) + // Standard Error: 855 + .saturating_add(Weight::from_parts(69_177, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::Registrars` (r:1 w:1) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 19]`. + fn set_fields(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `77 + r * (45 ±0)` + // Estimated: `2386` + // Minimum execution time: 6_183_000 picoseconds. + Weight::from_parts(6_528_283, 2386) + // Standard Error: 732 + .saturating_add(Weight::from_parts(65_415, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::Registrars` (r:1 w:0) + /// Proof: `Identity::Registrars` (`max_values`: Some(1), `max_size`: Some(901), added: 1396, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 19]`. + fn provide_judgement(r: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `7022 + r * (45 ±0)` + // Estimated: `11025` + // Minimum execution time: 99_700_000 picoseconds. + Weight::from_parts(101_176_078, 11025) + // Standard Error: 4_582 + .saturating_add(Weight::from_parts(114_818, 0).saturating_mul(r.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:0 w:100) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// The range of component `r` is `[1, 20]`. + /// The range of component `s` is `[0, 100]`. + fn kill_identity(r: u32, s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `7313 + r * (5 ±0) + s * (20 ±0)` + // Estimated: `11025` + // Minimum execution time: 77_872_000 picoseconds. + Weight::from_parts(77_876_810, 11025) + // Standard Error: 8_973 + .saturating_add(Weight::from_parts(244_712, 0).saturating_mul(r.into())) + // Standard Error: 1_751 + .saturating_add(Weight::from_parts(1_336_482, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(s.into()))) + } + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:1 w:1) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 99]`. + fn add_sub(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `536 + s * (23 ±0)` + // Estimated: `11025` + // Minimum execution time: 26_168_000 picoseconds. + Weight::from_parts(30_873_268, 11025) + // Standard Error: 1_061 + .saturating_add(Weight::from_parts(70_656, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:1 w:1) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// The range of component `s` is `[1, 100]`. + fn rename_sub(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `615 + s * (4 ±0)` + // Estimated: `11025` + // Minimum execution time: 12_535_000 picoseconds. + Weight::from_parts(15_886_319, 11025) + // Standard Error: 1_341 + .saturating_add(Weight::from_parts(60_303, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::SuperOf` (r:1 w:1) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// The range of component `s` is `[1, 100]`. + fn remove_sub(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `647 + s * (24 ±0)` + // Estimated: `11025` + // Minimum execution time: 29_877_000 picoseconds. + Weight::from_parts(34_605_810, 11025) + // Standard Error: 1_261 + .saturating_add(Weight::from_parts(87_624, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Identity::SuperOf` (r:1 w:1) + /// Proof: `Identity::SuperOf` (`max_values`: None, `max_size`: Some(90), added: 2565, mode: `MaxEncodedLen`) + /// Storage: `Identity::SubsOf` (r:1 w:1) + /// Proof: `Identity::SubsOf` (`max_values`: None, `max_size`: Some(2046), added: 4521, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 99]`. + fn quit_sub(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `620 + s * (24 ±0)` + // Estimated: `5511` + // Minimum execution time: 22_763_000 picoseconds. + Weight::from_parts(24_456_476, 5511) + // Standard Error: 1_256 + .saturating_add(Weight::from_parts(103_277, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Identity::UsernameAuthorities` (r:0 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + fn add_username_authority() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_045_000 picoseconds. + Weight::from_parts(6_504_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::UsernameAuthorities` (r:1 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + fn remove_username_authority() -> Weight { + // Proof Size summary in bytes: + // Measured: `67` + // Estimated: `3505` + // Minimum execution time: 9_372_000 picoseconds. + Weight::from_parts(9_591_000, 3505) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::UsernameAuthorities` (r:1 w:1) + /// Proof: `Identity::UsernameAuthorities` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Identity::AccountOfUsername` (r:1 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::PendingUsernames` (r:1 w:0) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + fn set_username_for() -> Weight { + // Proof Size summary in bytes: + // Measured: `67` + // Estimated: `11025` + // Minimum execution time: 69_326_000 picoseconds. + Weight::from_parts(70_625_000, 11025) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Identity::PendingUsernames` (r:1 w:1) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + /// Storage: `Identity::AccountOfUsername` (r:0 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + fn accept_username() -> Weight { + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `11025` + // Minimum execution time: 20_230_000 picoseconds. + Weight::from_parts(20_655_000, 11025) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Identity::PendingUsernames` (r:1 w:1) + /// Proof: `Identity::PendingUsernames` (`max_values`: None, `max_size`: Some(73), added: 2548, mode: `MaxEncodedLen`) + fn remove_expired_approval() -> Weight { + // Proof Size summary in bytes: + // Measured: `101` + // Estimated: `3538` + // Minimum execution time: 13_416_000 picoseconds. + Weight::from_parts(13_914_000, 3538) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::AccountOfUsername` (r:1 w:0) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:1) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + fn set_primary_username() -> Weight { + // Proof Size summary in bytes: + // Measured: `232` + // Estimated: `11025` + // Minimum execution time: 16_426_000 picoseconds. + Weight::from_parts(16_697_000, 11025) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Identity::AccountOfUsername` (r:1 w:1) + /// Proof: `Identity::AccountOfUsername` (`max_values`: None, `max_size`: Some(69), added: 2544, mode: `MaxEncodedLen`) + /// Storage: `Identity::IdentityOf` (r:1 w:0) + /// Proof: `Identity::IdentityOf` (`max_values`: None, `max_size`: Some(7560), added: 10035, mode: `MaxEncodedLen`) + fn remove_dangling_username() -> Weight { + // Proof Size summary in bytes: + // Measured: `86` + // Estimated: `11025` + // Minimum execution time: 11_743_000 picoseconds. + Weight::from_parts(12_016_000, 11025) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_moonbeam_lazy_migrations.rs b/tracing/2902/runtime/common/src/weights/pallet_moonbeam_lazy_migrations.rs new file mode 100644 index 00000000..7be5b3c4 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_moonbeam_lazy_migrations.rs @@ -0,0 +1,77 @@ +// 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 . + +//! Autogenerated weights for `pallet_moonbeam_lazy_migrations` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_moonbeam_lazy_migrations +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_moonbeam_lazy_migrations`. +pub struct WeightInfo(PhantomData); +impl pallet_moonbeam_lazy_migrations::WeightInfo for WeightInfo { + /// Storage: `EVM::Suicided` (r:100 w:0) + /// Proof: `EVM::Suicided` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `EVM::AccountCodes` (r:100 w:0) + /// Proof: `EVM::AccountCodes` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `EVM::AccountStorages` (r:1000 w:900) + /// Proof: `EVM::AccountStorages` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamLazyMigrations::SuicidedContractsRemoved` (r:1 w:1) + /// Proof: `MoonbeamLazyMigrations::SuicidedContractsRemoved` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// The range of component `a` is `[1, 100]`. + /// The range of component `l` is `[1, 1000]`. + fn clear_suicided_storage(a: u32, l: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `4155 + a * (11 ±0) + l * (84 ±0)` + // Estimated: `37723 + a * (2228 ±19) + l * (2536 ±1)` + // Minimum execution time: 47_583_000 picoseconds. + Weight::from_parts(47_755_000, 37723) + // Standard Error: 2_582_851 + .saturating_add(Weight::from_parts(42_961_979, 0).saturating_mul(a.into())) + // Standard Error: 258_009 + .saturating_add(Weight::from_parts(27_276_989, 0).saturating_mul(l.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(a.into()))) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(l.into()))) + .saturating_add(T::DbWeight::get().writes(41_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(l.into()))) + .saturating_add(Weight::from_parts(0, 2228).saturating_mul(a.into())) + .saturating_add(Weight::from_parts(0, 2536).saturating_mul(l.into())) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_moonbeam_orbiters.rs b/tracing/2902/runtime/common/src/weights/pallet_moonbeam_orbiters.rs new file mode 100644 index 00000000..dc60e4b4 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_moonbeam_orbiters.rs @@ -0,0 +1,203 @@ +// 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 . + +//! Autogenerated weights for `pallet_moonbeam_orbiters` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_moonbeam_orbiters +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_moonbeam_orbiters`. +pub struct WeightInfo(PhantomData); +impl pallet_moonbeam_orbiters::WeightInfo for WeightInfo { + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Reserves` (r:1 w:0) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1037), added: 3512, mode: `MaxEncodedLen`) + fn collator_add_orbiter() -> Weight { + // Proof Size summary in bytes: + // Measured: `562` + // Estimated: `4502` + // Minimum execution time: 20_069_000 picoseconds. + Weight::from_parts(20_744_000, 4502) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn collator_remove_orbiter() -> Weight { + // Proof Size summary in bytes: + // Measured: `366` + // Estimated: `3831` + // Minimum execution time: 15_654_000 picoseconds. + Weight::from_parts(16_327_000, 3831) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn orbiter_leave_collator_pool() -> Weight { + // Proof Size summary in bytes: + // Measured: `366` + // Estimated: `3831` + // Minimum execution time: 15_840_000 picoseconds. + Weight::from_parts(16_363_000, 3831) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `MoonbeamOrbiters::MinOrbiterDeposit` (r:1 w:0) + /// Proof: `MoonbeamOrbiters::MinOrbiterDeposit` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Reserves` (r:1 w:1) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1037), added: 3512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `MoonbeamOrbiters::RegisteredOrbiter` (r:0 w:1) + /// Proof: `MoonbeamOrbiters::RegisteredOrbiter` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn orbiter_register() -> Weight { + // Proof Size summary in bytes: + // Measured: `282` + // Estimated: `4502` + // Minimum execution time: 30_234_000 picoseconds. + Weight::from_parts(30_911_000, 4502) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `MoonbeamOrbiters::CounterForCollatorsPool` (r:1 w:0) + /// Proof: `MoonbeamOrbiters::CounterForCollatorsPool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:101 w:0) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Reserves` (r:1 w:1) + /// Proof: `Balances::Reserves` (`max_values`: None, `max_size`: Some(1037), added: 3512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `MoonbeamOrbiters::RegisteredOrbiter` (r:0 w:1) + /// Proof: `MoonbeamOrbiters::RegisteredOrbiter` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `n` is `[0, 100]`. + fn orbiter_unregister(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `391 + n * (48 ±0)` + // Estimated: `4502 + n * (2524 ±0)` + // Minimum execution time: 37_436_000 picoseconds. + Weight::from_parts(37_712_989, 4502) + // Standard Error: 7_879 + .saturating_add(Weight::from_parts(7_381_630, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(n.into()))) + .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(Weight::from_parts(0, 2524).saturating_mul(n.into())) + } + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::CounterForCollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CounterForCollatorsPool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn add_collator() -> Weight { + // Proof Size summary in bytes: + // Measured: `82` + // Estimated: `3547` + // Minimum execution time: 11_002_000 picoseconds. + Weight::from_parts(11_373_000, 3547) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::CounterForCollatorsPool` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::CounterForCollatorsPool` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `MoonbeamOrbiters::AccountLookupOverride` (r:0 w:9) + /// Proof: `MoonbeamOrbiters::AccountLookupOverride` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_collator() -> Weight { + // Proof Size summary in bytes: + // Measured: `366` + // Estimated: `3831` + // Minimum execution time: 23_018_000 picoseconds. + Weight::from_parts(23_690_000, 3831) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(11_u64)) + } + /// Storage: `MoonbeamOrbiters::CurrentRound` (r:1 w:0) + /// Proof: `MoonbeamOrbiters::CurrentRound` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::OrbiterPerRound` (r:100 w:100) + /// Proof: `MoonbeamOrbiters::OrbiterPerRound` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 100]`. + fn on_initialize(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `140 + x * (61 ±0)` + // Estimated: `1624 + x * (2537 ±0)` + // Minimum execution time: 6_769_000 picoseconds. + Weight::from_parts(6_649_109, 1624) + // Standard Error: 1_243 + .saturating_add(Weight::from_parts(860_679, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 2537).saturating_mul(x.into())) + } + /// Storage: `MoonbeamOrbiters::OrbiterPerRound` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::OrbiterPerRound` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn distribute_rewards() -> Weight { + // Proof Size summary in bytes: + // Measured: `298` + // Estimated: `3763` + // Minimum execution time: 21_346_000 picoseconds. + Weight::from_parts(21_697_000, 3763) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `MoonbeamOrbiters::ForceRotation` (r:1 w:1) + /// Proof: `MoonbeamOrbiters::ForceRotation` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::CollatorsPool` (r:2 w:1) + /// Proof: `MoonbeamOrbiters::CollatorsPool` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::OrbiterPerRound` (r:0 w:3) + /// Proof: `MoonbeamOrbiters::OrbiterPerRound` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::AccountLookupOverride` (r:0 w:3) + /// Proof: `MoonbeamOrbiters::AccountLookupOverride` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::CurrentRound` (r:0 w:1) + /// Proof: `MoonbeamOrbiters::CurrentRound` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn on_new_round() -> Weight { + // Proof Size summary in bytes: + // Measured: `256` + // Estimated: `6196` + // Minimum execution time: 29_700_000 picoseconds. + Weight::from_parts(30_769_000, 6196) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(9_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_multisig.rs b/tracing/2902/runtime/common/src/weights/pallet_multisig.rs new file mode 100644 index 00000000..77c0b5d0 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_multisig.rs @@ -0,0 +1,160 @@ +// 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 . + +//! Autogenerated weights for `pallet_multisig` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_multisig +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_multisig`. +pub struct WeightInfo(PhantomData); +impl pallet_multisig::WeightInfo for WeightInfo { + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `z` is `[0, 10000]`. + fn as_multi_threshold_1(z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 15_050_000 picoseconds. + Weight::from_parts(15_716_040, 1527) + // Standard Error: 2 + .saturating_add(Weight::from_parts(508, 0).saturating_mul(z.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// The range of component `s` is `[2, 100]`. + /// The range of component `z` is `[0, 10000]`. + fn as_multi_create(s: u32, z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `304` + // Estimated: `5587` + // Minimum execution time: 41_040_000 picoseconds. + Weight::from_parts(31_041_570, 5587) + // Standard Error: 1_531 + .saturating_add(Weight::from_parts(111_181, 0).saturating_mul(s.into())) + // Standard Error: 15 + .saturating_add(Weight::from_parts(1_470, 0).saturating_mul(z.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// The range of component `s` is `[3, 100]`. + /// The range of component `z` is `[0, 10000]`. + fn as_multi_approve(s: u32, z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `312` + // Estimated: `5587` + // Minimum execution time: 25_982_000 picoseconds. + Weight::from_parts(17_347_712, 5587) + // Standard Error: 413 + .saturating_add(Weight::from_parts(96_686, 0).saturating_mul(s.into())) + // Standard Error: 4 + .saturating_add(Weight::from_parts(1_423, 0).saturating_mul(z.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `s` is `[2, 100]`. + /// The range of component `z` is `[0, 10000]`. + fn as_multi_complete(s: u32, z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `475 + s * (20 ±0)` + // Estimated: `5587 + s * (20 ±0)` + // Minimum execution time: 49_756_000 picoseconds. + Weight::from_parts(37_536_364, 5587) + // Standard Error: 732 + .saturating_add(Weight::from_parts(134_613, 0).saturating_mul(s.into())) + // Standard Error: 7 + .saturating_add(Weight::from_parts(1_463, 0).saturating_mul(z.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 20).saturating_mul(s.into())) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// The range of component `s` is `[2, 100]`. + fn approve_as_multi_create(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `304` + // Estimated: `5587` + // Minimum execution time: 29_297_000 picoseconds. + Weight::from_parts(30_042_055, 5587) + // Standard Error: 758 + .saturating_add(Weight::from_parts(105_815, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// The range of component `s` is `[2, 100]`. + fn approve_as_multi_approve(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `312` + // Estimated: `5587` + // Minimum execution time: 15_306_000 picoseconds. + Weight::from_parts(15_795_893, 5587) + // Standard Error: 464 + .saturating_add(Weight::from_parts(95_884, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Multisig::Multisigs` (r:1 w:1) + /// Proof: `Multisig::Multisigs` (`max_values`: None, `max_size`: Some(2122), added: 4597, mode: `MaxEncodedLen`) + /// The range of component `s` is `[2, 100]`. + fn cancel_as_multi(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `474` + // Estimated: `5587` + // Minimum execution time: 30_377_000 picoseconds. + Weight::from_parts(31_017_956, 5587) + // Standard Error: 645 + .saturating_add(Weight::from_parts(104_927, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_parachain_staking.rs b/tracing/2902/runtime/common/src/weights/pallet_parachain_staking.rs new file mode 100644 index 00000000..407880f7 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_parachain_staking.rs @@ -0,0 +1,864 @@ +// 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 . + +//! Autogenerated weights for `pallet_parachain_staking` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_parachain_staking +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_parachain_staking`. +pub struct WeightInfo(PhantomData); +impl pallet_parachain_staking::WeightInfo for WeightInfo { + /// Storage: `ParachainStaking::InflationConfig` (r:1 w:1) + /// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_staking_expectations() -> Weight { + // Proof Size summary in bytes: + // Measured: `88` + // Estimated: `1573` + // Minimum execution time: 8_423_000 picoseconds. + Weight::from_parts(8_775_000, 1573) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::InflationConfig` (r:1 w:1) + /// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_inflation() -> Weight { + // Proof Size summary in bytes: + // Measured: `88` + // Estimated: `1573` + // Minimum execution time: 36_410_000 picoseconds. + Weight::from_parts(37_149_000, 1573) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::ParachainBondInfo` (r:1 w:1) + /// Proof: `ParachainStaking::ParachainBondInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_parachain_bond_account() -> Weight { + // Proof Size summary in bytes: + // Measured: `7` + // Estimated: `1492` + // Minimum execution time: 7_299_000 picoseconds. + Weight::from_parts(7_659_000, 1492) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::ParachainBondInfo` (r:1 w:1) + /// Proof: `ParachainStaking::ParachainBondInfo` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_parachain_bond_reserve_percent() -> Weight { + // Proof Size summary in bytes: + // Measured: `7` + // Estimated: `1492` + // Minimum execution time: 7_208_000 picoseconds. + Weight::from_parts(7_443_000, 1492) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::TotalSelected` (r:1 w:1) + /// Proof: `ParachainStaking::TotalSelected` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_total_selected() -> Weight { + // Proof Size summary in bytes: + // Measured: `28` + // Estimated: `1513` + // Minimum execution time: 7_838_000 picoseconds. + Weight::from_parts(8_123_000, 1513) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::CollatorCommission` (r:1 w:1) + /// Proof: `ParachainStaking::CollatorCommission` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_collator_commission() -> Weight { + // Proof Size summary in bytes: + // Measured: `27` + // Estimated: `1512` + // Minimum execution time: 7_417_000 picoseconds. + Weight::from_parts(7_833_000, 1512) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::TotalSelected` (r:1 w:0) + /// Proof: `ParachainStaking::TotalSelected` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::InflationConfig` (r:1 w:1) + /// Proof: `ParachainStaking::InflationConfig` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_blocks_per_round() -> Weight { + // Proof Size summary in bytes: + // Measured: `116` + // Estimated: `1601` + // Minimum execution time: 39_491_000 picoseconds. + Weight::from_parts(39_898_000, 1601) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:0) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:0 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:0 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[3, 200]`. + fn join_candidates(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1417 + x * (38 ±0)` + // Estimated: `4752 + x * (41 ±0)` + // Minimum execution time: 47_716_000 picoseconds. + Weight::from_parts(57_234_897, 4752) + // Standard Error: 1_674 + .saturating_add(Weight::from_parts(86_593, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(7_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(Weight::from_parts(0, 41).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[3, 200]`. + fn schedule_leave_candidates(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `665 + x * (37 ±0)` + // Estimated: `4023 + x * (38 ±0)` + // Minimum execution time: 16_081_000 picoseconds. + Weight::from_parts(21_529_015, 4023) + // Standard Error: 923 + .saturating_add(Weight::from_parts(62_703, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 38).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegatorState` (r:349 w:349) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:350 w:350) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:350 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:350 w:350) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[2, 350]`. + fn execute_leave_candidates_worst_case(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1562 + x * (431 ±0)` + // Estimated: `4842 + x * (3762 ±0)` + // Minimum execution time: 97_318_000 picoseconds. + Weight::from_parts(99_043_000, 4842) + // Standard Error: 74_692 + .saturating_add(Weight::from_parts(35_574_906, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 3762).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegatorState` (r:349 w:349) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:350 w:350) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:350 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:350 w:350) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[2, 350]`. + /// The range of component `y` is `[2, 350]`. + fn execute_leave_candidates_ideal(x: u32, _y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1556 + x * (431 ±0)` + // Estimated: `4808 + x * (3762 ±0)` + // Minimum execution time: 90_086_000 picoseconds. + Weight::from_parts(91_574_000, 4808) + // Standard Error: 30_540 + .saturating_add(Weight::from_parts(36_983_808, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(T::DbWeight::get().writes((3_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 3762).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[3, 200]`. + fn cancel_leave_candidates(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `633 + x * (37 ±0)` + // Estimated: `3991 + x * (38 ±0)` + // Minimum execution time: 15_188_000 picoseconds. + Weight::from_parts(20_439_228, 3991) + // Standard Error: 855 + .saturating_add(Weight::from_parts(58_850, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 38).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + fn go_offline(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `530 + x * (38 ±0)` + // Estimated: `3931 + x * (39 ±0)` + // Minimum execution time: 14_671_000 picoseconds. + Weight::from_parts(19_424_558, 3931) + // Standard Error: 931 + .saturating_add(Weight::from_parts(64_169, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 39).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + fn go_online(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `494 + x * (38 ±0)` + // Estimated: `3895 + x * (39 ±0)` + // Minimum execution time: 14_489_000 picoseconds. + Weight::from_parts(19_202_303, 3895) + // Standard Error: 941 + .saturating_add(Weight::from_parts(63_608, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 39).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + fn candidate_bond_more(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1233 + x * (42 ±0)` + // Estimated: `4752 + x * (44 ±0)` + // Minimum execution time: 42_764_000 picoseconds. + Weight::from_parts(50_891_582, 4752) + // Standard Error: 1_584 + .saturating_add(Weight::from_parts(93_002, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(Weight::from_parts(0, 44).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn schedule_candidate_bond_less() -> Weight { + // Proof Size summary in bytes: + // Measured: `171` + // Estimated: `3636` + // Minimum execution time: 13_196_000 picoseconds. + Weight::from_parts(13_600_000, 3636) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + fn execute_candidate_bond_less(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1322 + x * (42 ±0)` + // Estimated: `4752 + x * (43 ±0)` + // Minimum execution time: 46_535_000 picoseconds. + Weight::from_parts(54_211_512, 4752) + // Standard Error: 1_417 + .saturating_add(Weight::from_parts(68_025, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(Weight::from_parts(0, 43).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 200]`. + fn set_candidate_bond_to_zero(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1302 + x * (42 ±0)` + // Estimated: `4752 + x * (43 ±0)` + // Minimum execution time: 43_747_000 picoseconds. + Weight::from_parts(48_740_388, 4752) + // Standard Error: 1_109 + .saturating_add(Weight::from_parts(74_397, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + .saturating_add(Weight::from_parts(0, 43).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn cancel_candidate_bond_less() -> Weight { + // Proof Size summary in bytes: + // Measured: `191` + // Estimated: `3656` + // Minimum execution time: 11_711_000 picoseconds. + Weight::from_parts(12_297_000, 3656) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[3, 100]`. + /// The range of component `y` is `[2, 300]`. + fn delegate(x: u32, y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2461 + x * (79 ±0) + y * (38 ±0)` + // Estimated: `5710 + x * (81 ±0) + y * (39 ±0)` + // Minimum execution time: 87_413_000 picoseconds. + Weight::from_parts(78_118_122, 5710) + // Standard Error: 2_180 + .saturating_add(Weight::from_parts(139_900, 0).saturating_mul(x.into())) + // Standard Error: 715 + .saturating_add(Weight::from_parts(44_970, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(Weight::from_parts(0, 81).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 39).saturating_mul(y.into())) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 349]`. + fn schedule_revoke_delegation(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `567 + x * (42 ±0)` + // Estimated: `4013 + x * (43 ±0)` + // Minimum execution time: 15_923_000 picoseconds. + Weight::from_parts(22_402_960, 4013) + // Standard Error: 698 + .saturating_add(Weight::from_parts(68_223, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 43).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:0) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 349]`. + fn delegator_bond_more(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `2029 + x * (79 ±0)` + // Estimated: `5425 + x * (79 ±0)` + // Minimum execution time: 60_083_000 picoseconds. + Weight::from_parts(75_619_654, 5425) + // Standard Error: 1_349 + .saturating_add(Weight::from_parts(112_362, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(7_u64)) + .saturating_add(Weight::from_parts(0, 79).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 349]`. + fn schedule_delegator_bond_less(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `567 + x * (42 ±0)` + // Estimated: `4013 + x * (43 ±0)` + // Minimum execution time: 16_270_000 picoseconds. + Weight::from_parts(22_794_243, 4013) + // Standard Error: 721 + .saturating_add(Weight::from_parts(71_247, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 43).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:0) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn execute_revoke_delegation() -> Weight { + // Proof Size summary in bytes: + // Measured: `998` + // Estimated: `4752` + // Minimum execution time: 72_795_000 picoseconds. + Weight::from_parts(75_139_000, 4752) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn execute_delegator_revoke_delegation_worst() -> Weight { + // Proof Size summary in bytes: + // Measured: `37342` + // Estimated: `40807` + // Minimum execution time: 135_013_000 picoseconds. + Weight::from_parts(138_816_000, 40807) + .saturating_add(T::DbWeight::get().reads(11_u64)) + .saturating_add(T::DbWeight::get().writes(10_u64)) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn execute_delegator_bond_less_worst() -> Weight { + // Proof Size summary in bytes: + // Measured: `29964` + // Estimated: `33429` + // Minimum execution time: 115_091_000 picoseconds. + Weight::from_parts(120_774_000, 33429) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(9_u64)) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 349]`. + fn cancel_delegation_request(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `664 + x * (42 ±0)` + // Estimated: `4093 + x * (43 ±0)` + // Minimum execution time: 19_716_000 picoseconds. + Weight::from_parts(28_122_355, 4093) + // Standard Error: 844 + .saturating_add(Weight::from_parts(59_741, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 43).saturating_mul(x.into())) + } + /// Storage: `ParachainStaking::Points` (r:1 w:0) + /// Proof: `ParachainStaking::Points` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn prepare_staking_payouts() -> Weight { + // Proof Size summary in bytes: + // Measured: `3` + // Estimated: `3468` + // Minimum execution time: 3_034_000 picoseconds. + Weight::from_parts(3_101_000, 3468) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:0) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:0) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `y` is `[0, 100]`. + fn get_rewardable_delegators(y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `73 + y * (36 ±0)` + // Estimated: `3537 + y * (36 ±0)` + // Minimum execution time: 6_387_000 picoseconds. + Weight::from_parts(7_916_133, 3537) + // Standard Error: 621 + .saturating_add(Weight::from_parts(53_996, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(Weight::from_parts(0, 36).saturating_mul(y.into())) + } + /// Storage: `ParachainStaking::TotalSelected` (r:1 w:0) + /// Proof: `ParachainStaking::TotalSelected` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:0) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:51 w:0) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:51 w:0) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:51 w:0) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:51 w:0) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::SelectedCandidates` (r:0 w:1) + /// Proof: `ParachainStaking::SelectedCandidates` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AtStake` (r:0 w:51) + /// Proof: `ParachainStaking::AtStake` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 50]`. + /// The range of component `y` is `[0, 100]`. + fn select_top_candidates(x: u32, y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0 + x * (3816 ±0) + y * (1800 ±0)` + // Estimated: `3693 + x * (3975 ±39) + y * (639 ±19)` + // Minimum execution time: 20_027_000 picoseconds. + Weight::from_parts(20_584_000, 3693) + // Standard Error: 78_348 + .saturating_add(Weight::from_parts(16_329_365, 0).saturating_mul(x.into())) + // Standard Error: 39_070 + .saturating_add(Weight::from_parts(1_389_236, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(6_u64)) + .saturating_add(T::DbWeight::get().reads((4_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(x.into()))) + .saturating_add(Weight::from_parts(0, 3975).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 639).saturating_mul(y.into())) + } + /// Storage: `System::Account` (r:349 w:349) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegatorState` (r:349 w:349) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:0) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:349 w:349) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:349 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 349]`. + /// The range of component `y` is `[0, 349]`. + /// The range of component `z` is `[0, 349]`. + fn pay_one_collator_reward_best(x: u32, y: u32, z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0 + x * (396 ±0) + y * (156 ±0) + z * (41 ±0)` + // Estimated: `126334 + x * (2591 ±1) + y * (2234 ±1) + z * (28 ±0)` + // Minimum execution time: 259_000 picoseconds. + Weight::from_parts(283_000, 126334) + // Standard Error: 505_065 + .saturating_add(Weight::from_parts(48_122_269, 0).saturating_mul(x.into())) + // Standard Error: 505_065 + .saturating_add(Weight::from_parts(29_215_314, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().reads((2_u64).saturating_mul(y.into()))) + .saturating_add(T::DbWeight::get().writes((2_u64).saturating_mul(x.into()))) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(y.into()))) + .saturating_add(Weight::from_parts(0, 2591).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 2234).saturating_mul(y.into())) + .saturating_add(Weight::from_parts(0, 28).saturating_mul(z.into())) + } + /// Storage: `ParachainStaking::DelayedPayouts` (r:1 w:0) + /// Proof: `ParachainStaking::DelayedPayouts` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Points` (r:1 w:0) + /// Proof: `ParachainStaking::Points` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AtStake` (r:2 w:1) + /// Proof: `ParachainStaking::AtStake` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AwardedPts` (r:1 w:1) + /// Proof: `ParachainStaking::AwardedPts` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:0) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::OrbiterPerRound` (r:1 w:0) + /// Proof: `MoonbeamOrbiters::OrbiterPerRound` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:301 w:301) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `y` is `[0, 300]`. + fn pay_one_collator_reward(y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1632 + y * (161 ±0)` + // Estimated: `7342 + y * (2591 ±0)` + // Minimum execution time: 47_848_000 picoseconds. + Weight::from_parts(45_087_022, 7342) + // Standard Error: 4_616 + .saturating_add(Weight::from_parts(14_463_358, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(y.into()))) + .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(T::DbWeight::get().writes((1_u64).saturating_mul(y.into()))) + .saturating_add(Weight::from_parts(0, 2591).saturating_mul(y.into())) + } + fn base_on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 792_000 picoseconds. + Weight::from_parts(840_000, 0) + } + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:0) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 300]`. + /// The range of component `y` is `[0, 100]`. + fn set_auto_compound(x: u32, y: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `672 + x * (22 ±0) + y * (36 ±0)` + // Estimated: `4028 + x * (23 ±0) + y * (36 ±0)` + // Minimum execution time: 24_649_000 picoseconds. + Weight::from_parts(24_852_289, 4028) + // Standard Error: 395 + .saturating_add(Weight::from_parts(40_606, 0).saturating_mul(x.into())) + // Standard Error: 1_185 + .saturating_add(Weight::from_parts(41_268, 0).saturating_mul(y.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(Weight::from_parts(0, 23).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 36).saturating_mul(y.into())) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegatorState` (r:1 w:1) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:1 w:1) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:1 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[0, 350]`. + /// The range of component `y` is `[0, 349]`. + /// The range of component `z` is `[0, 99]`. + fn delegate_with_auto_compound(x: u32, y: u32, z: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0 + x * (60 ±0) + y * (21 ±0) + z * (78 ±0)` + // Estimated: `26217 + x * (44 ±0) + y * (19 ±0) + z * (76 ±0)` + // Minimum execution time: 95_653_000 picoseconds. + Weight::from_parts(79_711_783, 26217) + // Standard Error: 1_052 + .saturating_add(Weight::from_parts(110_031, 0).saturating_mul(x.into())) + // Standard Error: 3_716 + .saturating_add(Weight::from_parts(184_852, 0).saturating_mul(z.into())) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(8_u64)) + .saturating_add(Weight::from_parts(0, 44).saturating_mul(x.into())) + .saturating_add(Weight::from_parts(0, 19).saturating_mul(y.into())) + .saturating_add(Weight::from_parts(0, 76).saturating_mul(z.into())) + } + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegatorState` (r:2 w:2) + /// Proof: `ParachainStaking::DelegatorState` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AutoCompoundingDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::AutoCompoundingDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TopDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::TopDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::BottomDelegations` (r:1 w:1) + /// Proof: `ParachainStaking::BottomDelegations` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Balances::Locks` (r:2 w:2) + /// Proof: `Balances::Locks` (`max_values`: None, `max_size`: Some(1287), added: 3762, mode: `MaxEncodedLen`) + /// Storage: `Balances::Freezes` (r:2 w:0) + /// Proof: `Balances::Freezes` (`max_values`: None, `max_size`: Some(37), added: 2512, mode: `MaxEncodedLen`) + /// Storage: `ParachainStaking::DelegationScheduledRequests` (r:1 w:1) + /// Proof: `ParachainStaking::DelegationScheduledRequests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::Total` (r:1 w:1) + /// Proof: `ParachainStaking::Total` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn delegate_with_auto_compound_worst() -> Weight { + // Proof Size summary in bytes: + // Measured: `48131` + // Estimated: `54071` + // Minimum execution time: 213_168_000 picoseconds. + Weight::from_parts(215_021_000, 54071) + .saturating_add(T::DbWeight::get().reads(15_u64)) + .saturating_add(T::DbWeight::get().writes(13_u64)) + } + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn mint_collator_reward() -> Weight { + // Proof Size summary in bytes: + // Measured: `128` + // Estimated: `3581` + // Minimum execution time: 16_105_000 picoseconds. + Weight::from_parts(16_522_000, 3581) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `ParachainStaking::EnableMarkingOffline` (r:1 w:0) + /// Proof: `ParachainStaking::EnableMarkingOffline` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::TotalSelected` (r:1 w:0) + /// Proof: `ParachainStaking::TotalSelected` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::SelectedCandidates` (r:1 w:0) + /// Proof: `ParachainStaking::SelectedCandidates` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AtStake` (r:2 w:0) + /// Proof: `ParachainStaking::AtStake` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::AwardedPts` (r:2 w:0) + /// Proof: `ParachainStaking::AwardedPts` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `MoonbeamOrbiters::OrbiterPerRound` (r:1 w:0) + /// Proof: `MoonbeamOrbiters::OrbiterPerRound` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidateInfo` (r:1 w:1) + /// Proof: `ParachainStaking::CandidateInfo` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainStaking::CandidatePool` (r:1 w:1) + /// Proof: `ParachainStaking::CandidatePool` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn notify_inactive_collator() -> Weight { + // Proof Size summary in bytes: + // Measured: `11566` + // Estimated: `17506` + // Minimum execution time: 69_389_000 picoseconds. + Weight::from_parts(70_737_000, 17506) + .saturating_add(T::DbWeight::get().reads(10_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_precompile_benchmarks.rs b/tracing/2902/runtime/common/src/weights/pallet_precompile_benchmarks.rs new file mode 100644 index 00000000..96ec49fd --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_precompile_benchmarks.rs @@ -0,0 +1,69 @@ +// 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 . + +//! Autogenerated weights for `pallet_precompile_benchmarks` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_precompile_benchmarks +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_precompile_benchmarks`. +pub struct WeightInfo(PhantomData); +impl pallet_precompile_benchmarks::WeightInfo for WeightInfo { + /// The range of component `x` is `[100, 2000]`. + fn verify_entry(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 75_902_000 picoseconds. + Weight::from_parts(76_529_000, 0) + // Standard Error: 2_414 + .saturating_add(Weight::from_parts(667_294, 0).saturating_mul(x.into())) + } + /// Storage: `RelayStorageRoots::RelayStorageRootKeys` (r:1 w:0) + /// Proof: `RelayStorageRoots::RelayStorageRootKeys` (`max_values`: Some(1), `max_size`: Some(121), added: 616, mode: `MaxEncodedLen`) + fn latest_relay_block() -> Weight { + // Proof Size summary in bytes: + // Measured: `227` + // Estimated: `1606` + // Minimum execution time: 4_691_000 picoseconds. + Weight::from_parts(4_871_000, 1606) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_preimage.rs b/tracing/2902/runtime/common/src/weights/pallet_preimage.rs new file mode 100644 index 00000000..00d48781 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_preimage.rs @@ -0,0 +1,251 @@ +// 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 . + +//! Autogenerated weights for `pallet_preimage` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_preimage +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_preimage`. +pub struct WeightInfo(PhantomData); +impl pallet_preimage::WeightInfo for WeightInfo { + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(55), added: 2530, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 4194304]`. + fn note_preimage(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `3544` + // Minimum execution time: 46_791_000 picoseconds. + Weight::from_parts(47_593_000, 3544) + // Standard Error: 7 + .saturating_add(Weight::from_parts(2_265, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 4194304]`. + fn note_requested_preimage(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3544` + // Minimum execution time: 15_130_000 picoseconds. + Weight::from_parts(15_406_000, 3544) + // Standard Error: 4 + .saturating_add(Weight::from_parts(2_230, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 4194304]`. + fn note_no_deposit_preimage(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3544` + // Minimum execution time: 14_306_000 picoseconds. + Weight::from_parts(14_766_000, 3544) + // Standard Error: 4 + .saturating_add(Weight::from_parts(2_229, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1 w:1) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(55), added: 2530, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + fn unnote_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `220` + // Estimated: `3544` + // Minimum execution time: 49_118_000 picoseconds. + Weight::from_parts(50_474_000, 3544) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + fn unnote_no_deposit_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `144` + // Estimated: `3544` + // Minimum execution time: 21_773_000 picoseconds. + Weight::from_parts(22_501_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn request_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `176` + // Estimated: `3544` + // Minimum execution time: 17_577_000 picoseconds. + Weight::from_parts(18_107_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn request_no_deposit_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `144` + // Estimated: `3544` + // Minimum execution time: 12_826_000 picoseconds. + Weight::from_parts(13_152_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn request_unnoted_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `3544` + // Minimum execution time: 15_147_000 picoseconds. + Weight::from_parts(16_469_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn request_requested_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3544` + // Minimum execution time: 10_434_000 picoseconds. + Weight::from_parts(10_732_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:0 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `MaxEncodedLen`) + fn unrequest_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `144` + // Estimated: `3544` + // Minimum execution time: 18_677_000 picoseconds. + Weight::from_parts(19_164_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn unrequest_unnoted_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3544` + // Minimum execution time: 10_197_000 picoseconds. + Weight::from_parts(10_613_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn unrequest_multi_referenced_preimage() -> Weight { + // Proof Size summary in bytes: + // Measured: `106` + // Estimated: `3544` + // Minimum execution time: 10_107_000 picoseconds. + Weight::from_parts(10_496_000, 3544) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Preimage::StatusFor` (r:1023 w:1023) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1023 w:1023) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Balances::Holds` (r:1023 w:1023) + /// Proof: `Balances::Holds` (`max_values`: None, `max_size`: Some(55), added: 2530, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:0 w:1023) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 1024]`. + fn ensure_updated(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `1325 + n * (203 ±0)` + // Estimated: `990 + n * (2591 ±0)` + // Minimum execution time: 54_379_000 picoseconds. + Weight::from_parts(55_099_000, 990) + // Standard Error: 28_761 + .saturating_add(Weight::from_parts(53_321_985, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads((3_u64).saturating_mul(n.into()))) + .saturating_add(T::DbWeight::get().writes((4_u64).saturating_mul(n.into()))) + .saturating_add(Weight::from_parts(0, 2591).saturating_mul(n.into())) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_proxy.rs b/tracing/2902/runtime/common/src/weights/pallet_proxy.rs new file mode 100644 index 00000000..1b9557f2 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_proxy.rs @@ -0,0 +1,217 @@ +// 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 . + +//! Autogenerated weights for `pallet_proxy` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_proxy +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_proxy`. +pub struct WeightInfo(PhantomData); +impl pallet_proxy::WeightInfo for WeightInfo { + /// Storage: `Proxy::Proxies` (r:1 w:0) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `p` is `[1, 31]`. + fn proxy(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `191 + p * (25 ±0)` + // Estimated: `4310 + p * (25 ±0)` + // Minimum execution time: 14_996_000 picoseconds. + Weight::from_parts(15_655_775, 4310) + // Standard Error: 971 + .saturating_add(Weight::from_parts(32_864, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(Weight::from_parts(0, 25).saturating_mul(p.into())) + // 1 DB read that happen when filtering the proxy call transaction + .saturating_add(T::DbWeight::get().reads(1)) + } + /// Storage: `Proxy::Proxies` (r:1 w:0) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// Storage: `Proxy::Announcements` (r:1 w:1) + /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(1837), added: 4312, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `a` is `[0, 31]`. + /// The range of component `p` is `[1, 31]`. + fn proxy_announced(a: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `441 + a * (56 ±0) + p * (25 ±0)` + // Estimated: `5302 + a * (60 ±0) + p * (22 ±0)` + // Minimum execution time: 38_376_000 picoseconds. + Weight::from_parts(38_873_739, 5302) + // Standard Error: 2_130 + .saturating_add(Weight::from_parts(148_768, 0).saturating_mul(a.into())) + // Standard Error: 2_201 + .saturating_add(Weight::from_parts(18_553, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 60).saturating_mul(a.into())) + .saturating_add(Weight::from_parts(0, 22).saturating_mul(p.into())) + } + /// Storage: `Proxy::Announcements` (r:1 w:1) + /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(1837), added: 4312, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 31]`. + /// The range of component `p` is `[1, 31]`. + fn remove_announcement(a: u32, _p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `329 + a * (56 ±0)` + // Estimated: `5302` + // Minimum execution time: 22_494_000 picoseconds. + Weight::from_parts(23_762_783, 5302) + // Standard Error: 4_665 + .saturating_add(Weight::from_parts(172_490, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Proxy::Announcements` (r:1 w:1) + /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(1837), added: 4312, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 31]`. + /// The range of component `p` is `[1, 31]`. + fn reject_announcement(a: u32, _p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `329 + a * (56 ±0)` + // Estimated: `5302` + // Minimum execution time: 22_352_000 picoseconds. + Weight::from_parts(23_872_044, 5302) + // Standard Error: 4_564 + .saturating_add(Weight::from_parts(171_997, 0).saturating_mul(a.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:0) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// Storage: `Proxy::Announcements` (r:1 w:1) + /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(1837), added: 4312, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// The range of component `a` is `[0, 31]`. + /// The range of component `p` is `[1, 31]`. + fn announce(a: u32, p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `343 + a * (56 ±0) + p * (25 ±0)` + // Estimated: `5302` + // Minimum execution time: 29_508_000 picoseconds. + Weight::from_parts(32_411_876, 5302) + // Standard Error: 2_224 + .saturating_add(Weight::from_parts(161_492, 0).saturating_mul(a.into())) + // Standard Error: 2_298 + .saturating_add(Weight::from_parts(19_882, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:1) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// The range of component `p` is `[1, 31]`. + fn add_proxy(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `149 + p * (25 ±0)` + // Estimated: `4310` + // Minimum execution time: 22_057_000 picoseconds. + Weight::from_parts(22_782_046, 4310) + // Standard Error: 1_051 + .saturating_add(Weight::from_parts(35_662, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:1) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// The range of component `p` is `[1, 31]`. + fn remove_proxy(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `149 + p * (25 ±0)` + // Estimated: `4310` + // Minimum execution time: 21_604_000 picoseconds. + Weight::from_parts(22_877_238, 4310) + // Standard Error: 1_680 + .saturating_add(Weight::from_parts(31_231, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:1) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// The range of component `p` is `[1, 31]`. + fn remove_proxies(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `149 + p * (25 ±0)` + // Estimated: `4310` + // Minimum execution time: 21_184_000 picoseconds. + Weight::from_parts(22_024_457, 4310) + // Standard Error: 1_120 + .saturating_add(Weight::from_parts(34_085, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:1) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// The range of component `p` is `[1, 31]`. + fn create_pure(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `161` + // Estimated: `4310` + // Minimum execution time: 23_011_000 picoseconds. + Weight::from_parts(24_057_173, 4310) + // Standard Error: 1_110 + .saturating_add(Weight::from_parts(11_499, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Proxy::Proxies` (r:1 w:1) + /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(845), added: 3320, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 30]`. + fn kill_pure(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `174 + p * (25 ±0)` + // Estimated: `4310` + // Minimum execution time: 21_882_000 picoseconds. + Weight::from_parts(22_687_947, 4310) + // Standard Error: 938 + .saturating_add(Weight::from_parts(30_922, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_randomness.rs b/tracing/2902/runtime/common/src/weights/pallet_randomness.rs new file mode 100644 index 00000000..d2f4d60b --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_randomness.rs @@ -0,0 +1,162 @@ +// 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 . + +//! Autogenerated weights for `pallet_randomness` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_randomness +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_randomness`. +pub struct WeightInfo(PhantomData); +impl pallet_randomness::WeightInfo for WeightInfo { + /// Storage: `Randomness::RelayEpoch` (r:1 w:1) + /// Proof: `Randomness::RelayEpoch` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::RelayStateProof` (r:1 w:0) + /// Proof: `ParachainSystem::RelayStateProof` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:1) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::InherentIncluded` (r:0 w:1) + /// Proof: `Randomness::InherentIncluded` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn set_babe_randomness_results() -> Weight { + // Proof Size summary in bytes: + // Measured: `297` + // Estimated: `3762` + // Minimum execution time: 13_127_000 picoseconds. + Weight::from_parts(13_446_000, 3762) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Randomness::NotFirstBlock` (r:1 w:0) + /// Proof: `Randomness::NotFirstBlock` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Digest` (r:1 w:0) + /// Proof: `System::Digest` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AuthorMapping::MappingWithDeposit` (r:1 w:0) + /// Proof: `AuthorMapping::MappingWithDeposit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::LocalVrfOutput` (r:1 w:1) + /// Proof: `Randomness::LocalVrfOutput` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:1) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn on_initialize() -> Weight { + // Proof Size summary in bytes: + // Measured: `719` + // Estimated: `4184` + // Minimum execution time: 512_629_000 picoseconds. + Weight::from_parts(514_922_000, 4184) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Randomness::RequestCount` (r:1 w:1) + /// Proof: `Randomness::RequestCount` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:1) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::Requests` (r:0 w:1) + /// Proof: `Randomness::Requests` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn request_randomness() -> Weight { + // Proof Size summary in bytes: + // Measured: `549` + // Estimated: `6172` + // Minimum execution time: 54_291_000 picoseconds. + Weight::from_parts(55_178_000, 6172) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(5_u64)) + } + /// Storage: `Randomness::Requests` (r:1 w:0) + /// Proof: `Randomness::Requests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:0) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// The range of component `x` is `[1, 100]`. + fn prepare_fulfillment(x: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `412` + // Estimated: `3877` + // Minimum execution time: 9_589_000 picoseconds. + Weight::from_parts(10_126_652, 3877) + // Standard Error: 301 + .saturating_add(Weight::from_parts(262_389, 0).saturating_mul(x.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + } + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:1) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Randomness::Requests` (r:0 w:1) + /// Proof: `Randomness::Requests` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn finish_fulfillment() -> Weight { + // Proof Size summary in bytes: + // Measured: `739` + // Estimated: `6172` + // Minimum execution time: 50_250_000 picoseconds. + Weight::from_parts(51_170_000, 6172) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Randomness::Requests` (r:1 w:1) + /// Proof: `Randomness::Requests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn increase_fee() -> Weight { + // Proof Size summary in bytes: + // Measured: `825` + // Estimated: `6172` + // Minimum execution time: 46_960_000 picoseconds. + Weight::from_parts(47_761_000, 6172) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Randomness::Requests` (r:1 w:1) + /// Proof: `Randomness::Requests` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Randomness::RandomnessResults` (r:1 w:1) + /// Proof: `Randomness::RandomnessResults` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn execute_request_expiration() -> Weight { + // Proof Size summary in bytes: + // Measured: `868` + // Estimated: `6172` + // Minimum execution time: 54_447_000 picoseconds. + Weight::from_parts(55_170_000, 6172) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_referenda.rs b/tracing/2902/runtime/common/src/weights/pallet_referenda.rs new file mode 100644 index 00000000..4a0459b5 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_referenda.rs @@ -0,0 +1,469 @@ +// 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 . + +//! Autogenerated weights for `pallet_referenda` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_referenda +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_referenda`. +pub struct WeightInfo(PhantomData); +impl pallet_referenda::WeightInfo for WeightInfo { + /// Storage: `Referenda::ReferendumCount` (r:1 w:1) + /// Proof: `Referenda::ReferendumCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:0 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + fn submit() -> Weight { + // Proof Size summary in bytes: + // Measured: `269` + // Estimated: `42428` + // Minimum execution time: 32_827_000 picoseconds. + Weight::from_parts(33_549_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn place_decision_deposit_preparing() -> Weight { + // Proof Size summary in bytes: + // Measured: `510` + // Estimated: `83866` + // Minimum execution time: 42_052_000 picoseconds. + Weight::from_parts(43_028_000, 83866) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:0) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn place_decision_deposit_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `3303` + // Estimated: `42428` + // Minimum execution time: 58_526_000 picoseconds. + Weight::from_parts(60_058_000, 42428) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:0) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn place_decision_deposit_not_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `3323` + // Estimated: `42428` + // Minimum execution time: 58_289_000 picoseconds. + Weight::from_parts(59_858_000, 42428) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:1) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn place_decision_deposit_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `510` + // Estimated: `83866` + // Minimum execution time: 53_199_000 picoseconds. + Weight::from_parts(54_655_000, 83866) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:1) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn place_decision_deposit_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `510` + // Estimated: `83866` + // Minimum execution time: 48_847_000 picoseconds. + Weight::from_parts(49_711_000, 83866) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + fn refund_decision_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `453` + // Estimated: `4377` + // Minimum execution time: 27_623_000 picoseconds. + Weight::from_parts(28_687_000, 4377) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + fn refund_submission_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `378` + // Estimated: `4377` + // Minimum execution time: 27_406_000 picoseconds. + Weight::from_parts(28_129_000, 4377) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn cancel() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `83866` + // Minimum execution time: 28_691_000 picoseconds. + Weight::from_parts(29_412_000, 83866) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Referenda::MetadataOf` (r:1 w:0) + /// Proof: `Referenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn kill() -> Weight { + // Proof Size summary in bytes: + // Measured: `884` + // Estimated: `83866` + // Minimum execution time: 95_480_000 picoseconds. + Weight::from_parts(97_420_000, 83866) + .saturating_add(T::DbWeight::get().reads(5_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Referenda::TrackQueue` (r:1 w:0) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:1) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + fn one_fewer_deciding_queue_empty() -> Weight { + // Proof Size summary in bytes: + // Measured: `102` + // Estimated: `5477` + // Minimum execution time: 9_372_000 picoseconds. + Weight::from_parts(9_658_000, 5477) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn one_fewer_deciding_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `3090` + // Estimated: `42428` + // Minimum execution time: 41_452_000 picoseconds. + Weight::from_parts(42_664_000, 42428) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn one_fewer_deciding_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `3090` + // Estimated: `42428` + // Minimum execution time: 43_157_000 picoseconds. + Weight::from_parts(44_712_000, 42428) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + fn nudge_referendum_requeued_insertion() -> Weight { + // Proof Size summary in bytes: + // Measured: `2915` + // Estimated: `5477` + // Minimum execution time: 23_193_000 picoseconds. + Weight::from_parts(24_048_000, 5477) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + fn nudge_referendum_requeued_slide() -> Weight { + // Proof Size summary in bytes: + // Measured: `2915` + // Estimated: `5477` + // Minimum execution time: 22_963_000 picoseconds. + Weight::from_parts(23_854_000, 5477) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:0) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + fn nudge_referendum_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `2919` + // Estimated: `5477` + // Minimum execution time: 27_080_000 picoseconds. + Weight::from_parts(27_852_000, 5477) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:0) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Referenda::TrackQueue` (r:1 w:1) + /// Proof: `Referenda::TrackQueue` (`max_values`: None, `max_size`: Some(2012), added: 4487, mode: `MaxEncodedLen`) + fn nudge_referendum_not_queued() -> Weight { + // Proof Size summary in bytes: + // Measured: `2939` + // Estimated: `5477` + // Minimum execution time: 27_082_000 picoseconds. + Weight::from_parts(27_867_000, 5477) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_no_deposit() -> Weight { + // Proof Size summary in bytes: + // Measured: `249` + // Estimated: `42428` + // Minimum execution time: 19_614_000 picoseconds. + Weight::from_parts(20_158_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_preparing() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `42428` + // Minimum execution time: 20_156_000 picoseconds. + Weight::from_parts(20_537_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + fn nudge_referendum_timed_out() -> Weight { + // Proof Size summary in bytes: + // Measured: `194` + // Estimated: `4377` + // Minimum execution time: 12_796_000 picoseconds. + Weight::from_parts(13_096_000, 4377) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:1) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_deciding_failing() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `42428` + // Minimum execution time: 26_036_000 picoseconds. + Weight::from_parts(26_786_000, 42428) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::DecidingCount` (r:1 w:1) + /// Proof: `Referenda::DecidingCount` (`max_values`: None, `max_size`: Some(14), added: 2489, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_deciding_passing() -> Weight { + // Proof Size summary in bytes: + // Measured: `285` + // Estimated: `42428` + // Minimum execution time: 27_742_000 picoseconds. + Weight::from_parts(28_339_000, 42428) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_begin_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `338` + // Estimated: `42428` + // Minimum execution time: 22_841_000 picoseconds. + Weight::from_parts(23_443_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_end_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `321` + // Estimated: `42428` + // Minimum execution time: 23_140_000 picoseconds. + Weight::from_parts(23_618_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_continue_not_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `338` + // Estimated: `42428` + // Minimum execution time: 21_869_000 picoseconds. + Weight::from_parts(22_501_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_continue_confirming() -> Weight { + // Proof Size summary in bytes: + // Measured: `342` + // Estimated: `42428` + // Minimum execution time: 21_447_000 picoseconds. + Weight::from_parts(21_862_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:2 w:2) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn nudge_referendum_approved() -> Weight { + // Proof Size summary in bytes: + // Measured: `342` + // Estimated: `83866` + // Minimum execution time: 32_823_000 picoseconds. + Weight::from_parts(33_860_000, 83866) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(4_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:1) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + fn nudge_referendum_rejected() -> Weight { + // Proof Size summary in bytes: + // Measured: `338` + // Estimated: `42428` + // Minimum execution time: 22_972_000 picoseconds. + Weight::from_parts(23_681_000, 42428) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:0) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Referenda::MetadataOf` (r:0 w:1) + /// Proof: `Referenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn set_some_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `338` + // Estimated: `4377` + // Minimum execution time: 18_814_000 picoseconds. + Weight::from_parts(19_354_000, 4377) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Referenda::ReferendumInfoFor` (r:1 w:0) + /// Proof: `Referenda::ReferendumInfoFor` (`max_values`: None, `max_size`: Some(912), added: 3387, mode: `MaxEncodedLen`) + /// Storage: `Referenda::MetadataOf` (r:1 w:1) + /// Proof: `Referenda::MetadataOf` (`max_values`: None, `max_size`: Some(52), added: 2527, mode: `MaxEncodedLen`) + fn clear_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `271` + // Estimated: `4377` + // Minimum execution time: 14_836_000 picoseconds. + Weight::from_parts(15_234_000, 4377) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_relay_storage_roots.rs b/tracing/2902/runtime/common/src/weights/pallet_relay_storage_roots.rs new file mode 100644 index 00000000..c41982ae --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_relay_storage_roots.rs @@ -0,0 +1,64 @@ +// 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 . + +//! Autogenerated weights for `pallet_relay_storage_roots` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_relay_storage_roots +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_relay_storage_roots`. +pub struct WeightInfo(PhantomData); +impl pallet_relay_storage_roots::WeightInfo for WeightInfo { + /// Storage: `ParachainSystem::ValidationData` (r:1 w:0) + /// Proof: `ParachainSystem::ValidationData` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `RelayStorageRoots::RelayStorageRoot` (r:1 w:2) + /// Proof: `RelayStorageRoots::RelayStorageRoot` (`max_values`: None, `max_size`: Some(44), added: 2519, mode: `MaxEncodedLen`) + /// Storage: `RelayStorageRoots::RelayStorageRootKeys` (r:1 w:1) + /// Proof: `RelayStorageRoots::RelayStorageRootKeys` (`max_values`: Some(1), `max_size`: Some(121), added: 616, mode: `MaxEncodedLen`) + fn set_relay_storage_root() -> Weight { + // Proof Size summary in bytes: + // Measured: `972` + // Estimated: `3509` + // Minimum execution time: 17_372_000 picoseconds. + Weight::from_parts(17_813_000, 3509) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_scheduler.rs b/tracing/2902/runtime/common/src/weights/pallet_scheduler.rs new file mode 100644 index 00000000..2863e317 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_scheduler.rs @@ -0,0 +1,196 @@ +// 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 . + +//! Autogenerated weights for `pallet_scheduler` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_scheduler +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_scheduler`. +pub struct WeightInfo(PhantomData); +impl pallet_scheduler::WeightInfo for WeightInfo { + /// Storage: `Scheduler::IncompleteSince` (r:1 w:1) + /// Proof: `Scheduler::IncompleteSince` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + fn service_agendas_base() -> Weight { + // Proof Size summary in bytes: + // Measured: `31` + // Estimated: `1489` + // Minimum execution time: 3_104_000 picoseconds. + Weight::from_parts(3_295_000, 1489) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 50]`. + fn service_agenda_base(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `78 + s * (177 ±0)` + // Estimated: `42428` + // Minimum execution time: 3_587_000 picoseconds. + Weight::from_parts(6_435_444, 42428) + // Standard Error: 1_351 + .saturating_add(Weight::from_parts(345_330, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn service_task_base() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_225_000 picoseconds. + Weight::from_parts(3_398_000, 0) + } + /// Storage: `Preimage::PreimageFor` (r:1 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `Measured`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// The range of component `s` is `[128, 4194304]`. + fn service_task_fetched(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `179 + s * (1 ±0)` + // Estimated: `3644 + s * (1 ±0)` + // Minimum execution time: 17_780_000 picoseconds. + Weight::from_parts(18_049_000, 3644) + // Standard Error: 4 + .saturating_add(Weight::from_parts(1_218, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(s.into())) + } + /// Storage: `Scheduler::Lookup` (r:0 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + fn service_task_named() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 4_829_000 picoseconds. + Weight::from_parts(5_019_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn service_task_periodic() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 3_171_000 picoseconds. + Weight::from_parts(3_408_000, 0) + } + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn execute_dispatch_signed() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 4_346_000 picoseconds. + Weight::from_parts(4_595_000, 1527) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn execute_dispatch_unsigned() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_129_000 picoseconds. + Weight::from_parts(2_298_000, 0) + } + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 49]`. + fn schedule(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `78 + s * (177 ±0)` + // Estimated: `42428` + // Minimum execution time: 10_293_000 picoseconds. + Weight::from_parts(12_886_613, 42428) + // Standard Error: 1_265 + .saturating_add(Weight::from_parts(373_933, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Lookup` (r:0 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// The range of component `s` is `[1, 50]`. + fn cancel(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `78 + s * (177 ±0)` + // Estimated: `42428` + // Minimum execution time: 13_648_000 picoseconds. + Weight::from_parts(13_302_568, 42428) + // Standard Error: 911 + .saturating_add(Weight::from_parts(578_580, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// The range of component `s` is `[0, 49]`. + fn schedule_named(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `255 + s * (185 ±0)` + // Estimated: `42428` + // Minimum execution time: 13_612_000 picoseconds. + Weight::from_parts(16_943_772, 42428) + // Standard Error: 2_062 + .saturating_add(Weight::from_parts(406_396, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Scheduler::Lookup` (r:1 w:1) + /// Proof: `Scheduler::Lookup` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) + /// Storage: `Scheduler::Agenda` (r:1 w:1) + /// Proof: `Scheduler::Agenda` (`max_values`: None, `max_size`: Some(38963), added: 41438, mode: `MaxEncodedLen`) + /// The range of component `s` is `[1, 50]`. + fn cancel_named(s: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `281 + s * (185 ±0)` + // Estimated: `42428` + // Minimum execution time: 15_726_000 picoseconds. + Weight::from_parts(16_031_966, 42428) + // Standard Error: 1_907 + .saturating_add(Weight::from_parts(621_828, 0).saturating_mul(s.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_sudo.rs b/tracing/2902/runtime/common/src/weights/pallet_sudo.rs new file mode 100644 index 00000000..560d1f3d --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_sudo.rs @@ -0,0 +1,91 @@ +// 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 . + +//! Autogenerated weights for `pallet_sudo` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_sudo +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_sudo`. +pub struct WeightInfo(PhantomData); +impl pallet_sudo::WeightInfo for WeightInfo { + /// Storage: `Sudo::Key` (r:1 w:1) + /// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn set_key() -> Weight { + // Proof Size summary in bytes: + // Measured: `153` + // Estimated: `1505` + // Minimum execution time: 9_134_000 picoseconds. + Weight::from_parts(9_369_000, 1505) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Sudo::Key` (r:1 w:0) + /// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn sudo() -> Weight { + // Proof Size summary in bytes: + // Measured: `153` + // Estimated: `1505` + // Minimum execution time: 9_886_000 picoseconds. + Weight::from_parts(10_411_000, 1505) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `Sudo::Key` (r:1 w:0) + /// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn sudo_as() -> Weight { + // Proof Size summary in bytes: + // Measured: `153` + // Estimated: `1505` + // Minimum execution time: 9_917_000 picoseconds. + Weight::from_parts(10_293_000, 1505) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `Sudo::Key` (r:1 w:1) + /// Proof: `Sudo::Key` (`max_values`: Some(1), `max_size`: Some(20), added: 515, mode: `MaxEncodedLen`) + fn remove_key() -> Weight { + // Proof Size summary in bytes: + // Measured: `153` + // Estimated: `1505` + // Minimum execution time: 8_231_000 picoseconds. + Weight::from_parts(8_704_000, 1505) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_timestamp.rs b/tracing/2902/runtime/common/src/weights/pallet_timestamp.rs new file mode 100644 index 00000000..5c4ece73 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_timestamp.rs @@ -0,0 +1,67 @@ +// 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 . + +//! Autogenerated weights for `pallet_timestamp` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_timestamp +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_timestamp`. +pub struct WeightInfo(PhantomData); +impl pallet_timestamp::WeightInfo for WeightInfo { + /// Storage: `Timestamp::Now` (r:1 w:1) + /// Proof: `Timestamp::Now` (`max_values`: Some(1), `max_size`: Some(8), added: 503, mode: `MaxEncodedLen`) + fn set() -> Weight { + // Proof Size summary in bytes: + // Measured: `6` + // Estimated: `1493` + // Minimum execution time: 4_623_000 picoseconds. + Weight::from_parts(4_903_000, 1493) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + fn on_finalize() -> Weight { + // Proof Size summary in bytes: + // Measured: `57` + // Estimated: `0` + // Minimum execution time: 3_322_000 picoseconds. + Weight::from_parts(3_492_000, 0) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_treasury.rs b/tracing/2902/runtime/common/src/weights/pallet_treasury.rs new file mode 100644 index 00000000..5e350e55 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_treasury.rs @@ -0,0 +1,187 @@ +// 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 . + +//! Autogenerated weights for `pallet_treasury` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_treasury +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_treasury`. +pub struct WeightInfo(PhantomData); +impl pallet_treasury::WeightInfo for WeightInfo { + /// Storage: `Treasury::ProposalCount` (r:1 w:1) + /// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:0 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + fn spend_local() -> Weight { + // Proof Size summary in bytes: + // Measured: `147` + // Estimated: `1887` + // Minimum execution time: 11_763_000 picoseconds. + Weight::from_parts(12_162_000, 1887) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Treasury::ProposalCount` (r:1 w:1) + /// Proof: `Treasury::ProposalCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:0 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + fn propose_spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `446` + // Estimated: `1489` + // Minimum execution time: 25_433_000 picoseconds. + Weight::from_parts(26_250_000, 1489) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Treasury::Proposals` (r:1 w:1) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn reject_proposal() -> Weight { + // Proof Size summary in bytes: + // Measured: `619` + // Estimated: `6172` + // Minimum execution time: 47_079_000 picoseconds. + Weight::from_parts(48_432_000, 6172) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Treasury::Proposals` (r:1 w:0) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 99]`. + fn approve_proposal(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `575 + p * (8 ±0)` + // Estimated: `3549` + // Minimum execution time: 8_884_000 picoseconds. + Weight::from_parts(11_714_738, 3549) + // Standard Error: 1_462 + .saturating_add(Weight::from_parts(78_570, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + fn remove_approval() -> Weight { + // Proof Size summary in bytes: + // Measured: `232` + // Estimated: `1887` + // Minimum execution time: 7_051_000 picoseconds. + Weight::from_parts(7_284_000, 1887) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `System::Account` (r:1 w:0) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Deactivated` (r:1 w:0) + /// Proof: `Treasury::Deactivated` (`max_values`: Some(1), `max_size`: Some(16), added: 511, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Approvals` (r:1 w:1) + /// Proof: `Treasury::Approvals` (`max_values`: Some(1), `max_size`: Some(402), added: 897, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Proposals` (r:99 w:0) + /// Proof: `Treasury::Proposals` (`max_values`: None, `max_size`: Some(84), added: 2559, mode: `MaxEncodedLen`) + /// The range of component `p` is `[0, 99]`. + fn on_initialize_proposals(p: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `356 + p * (97 ±0)` + // Estimated: `3581 + p * (2559 ±0)` + // Minimum execution time: 16_123_000 picoseconds. + Weight::from_parts(16_106_571, 3581) + // Standard Error: 6_320 + .saturating_add(Weight::from_parts(3_350_601, 0).saturating_mul(p.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().reads((1_u64).saturating_mul(p.into()))) + .saturating_add(T::DbWeight::get().writes(1_u64)) + .saturating_add(Weight::from_parts(0, 2559).saturating_mul(p.into())) + } + /// Storage: `Treasury::SpendCount` (r:1 w:1) + /// Proof: `Treasury::SpendCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Treasury::Spends` (r:0 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) + fn spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `147` + // Estimated: `1489` + // Minimum execution time: 10_468_000 picoseconds. + Weight::from_parts(11_009_000, 1489) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(116), added: 2591, mode: `MaxEncodedLen`) + fn payout() -> Weight { + // Proof Size summary in bytes: + // Measured: `553` + // Estimated: `6172` + // Minimum execution time: 52_510_000 picoseconds. + Weight::from_parts(53_515_000, 6172) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) + fn check_status() -> Weight { + // Proof Size summary in bytes: + // Measured: `253` + // Estimated: `3522` + // Minimum execution time: 12_219_000 picoseconds. + Weight::from_parts(12_408_000, 3522) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `Treasury::Spends` (r:1 w:1) + /// Proof: `Treasury::Spends` (`max_values`: None, `max_size`: Some(57), added: 2532, mode: `MaxEncodedLen`) + fn void_spend() -> Weight { + // Proof Size summary in bytes: + // Measured: `253` + // Estimated: `3522` + // Minimum execution time: 10_891_000 picoseconds. + Weight::from_parts(11_255_000, 3522) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_utility.rs b/tracing/2902/runtime/common/src/weights/pallet_utility.rs new file mode 100644 index 00000000..8bb2ed9b --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_utility.rs @@ -0,0 +1,105 @@ +// 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 . + +//! Autogenerated weights for `pallet_utility` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_utility +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_utility`. +pub struct WeightInfo(PhantomData); +impl pallet_utility::WeightInfo for WeightInfo { + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 1000]`. + fn batch(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 4_486_000 picoseconds. + Weight::from_parts(6_860_468, 1527) + // Standard Error: 3_965 + .saturating_add(Weight::from_parts(4_026_122, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn as_derivative() -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 6_909_000 picoseconds. + Weight::from_parts(7_328_000, 1527) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 1000]`. + fn batch_all(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 4_548_000 picoseconds. + Weight::from_parts(4_273_693, 1527) + // Standard Error: 3_802 + .saturating_add(Weight::from_parts(4_263_522, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } + fn dispatch_as() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_579_000 picoseconds. + Weight::from_parts(6_808_000, 0) + } + /// Storage: `MaintenanceMode::MaintenanceMode` (r:1 w:0) + /// Proof: `MaintenanceMode::MaintenanceMode` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// The range of component `c` is `[0, 1000]`. + fn force_batch(c: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `42` + // Estimated: `1527` + // Minimum execution time: 4_440_000 picoseconds. + Weight::from_parts(4_897_102, 1527) + // Standard Error: 4_345 + .saturating_add(Weight::from_parts(4_032_053, 0).saturating_mul(c.into())) + .saturating_add(T::DbWeight::get().reads(1_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_whitelist.rs b/tracing/2902/runtime/common/src/weights/pallet_whitelist.rs new file mode 100644 index 00000000..f3fd82aa --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_whitelist.rs @@ -0,0 +1,118 @@ +// 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 . + +//! Autogenerated weights for `pallet_whitelist` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_whitelist +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_whitelist`. +pub struct WeightInfo(PhantomData); +impl pallet_whitelist::WeightInfo for WeightInfo { + /// Storage: `Whitelist::WhitelistedCall` (r:1 w:1) + /// Proof: `Whitelist::WhitelistedCall` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn whitelist_call() -> Weight { + // Proof Size summary in bytes: + // Measured: `46` + // Estimated: `3544` + // Minimum execution time: 16_848_000 picoseconds. + Weight::from_parts(17_387_000, 3544) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Whitelist::WhitelistedCall` (r:1 w:1) + /// Proof: `Whitelist::WhitelistedCall` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + fn remove_whitelisted_call() -> Weight { + // Proof Size summary in bytes: + // Measured: `175` + // Estimated: `3544` + // Minimum execution time: 16_154_000 picoseconds. + Weight::from_parts(16_777_000, 3544) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `Whitelist::WhitelistedCall` (r:1 w:1) + /// Proof: `Whitelist::WhitelistedCall` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Preimage::PreimageFor` (r:1 w:1) + /// Proof: `Preimage::PreimageFor` (`max_values`: None, `max_size`: Some(4194344), added: 4196819, mode: `Measured`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 4194294]`. + fn dispatch_whitelisted_call(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `251 + n * (1 ±0)` + // Estimated: `3715 + n * (1 ±0)` + // Minimum execution time: 27_084_000 picoseconds. + Weight::from_parts(27_353_000, 3715) + // Standard Error: 4 + .saturating_add(Weight::from_parts(1_230, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(4_u64)) + .saturating_add(T::DbWeight::get().writes(3_u64)) + .saturating_add(Weight::from_parts(0, 1).saturating_mul(n.into())) + } + /// Storage: `Whitelist::WhitelistedCall` (r:1 w:1) + /// Proof: `Whitelist::WhitelistedCall` (`max_values`: None, `max_size`: Some(40), added: 2515, mode: `MaxEncodedLen`) + /// Storage: `Preimage::StatusFor` (r:1 w:0) + /// Proof: `Preimage::StatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// Storage: `Preimage::RequestStatusFor` (r:1 w:1) + /// Proof: `Preimage::RequestStatusFor` (`max_values`: None, `max_size`: Some(79), added: 2554, mode: `MaxEncodedLen`) + /// The range of component `n` is `[1, 10000]`. + fn dispatch_whitelisted_call_with_preimage(n: u32, ) -> Weight { + // Proof Size summary in bytes: + // Measured: `175` + // Estimated: `3544` + // Minimum execution time: 20_164_000 picoseconds. + Weight::from_parts(20_913_813, 3544) + // Standard Error: 2 + .saturating_add(Weight::from_parts(1_382, 0).saturating_mul(n.into())) + .saturating_add(T::DbWeight::get().reads(3_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_xcm.rs b/tracing/2902/runtime/common/src/weights/pallet_xcm.rs new file mode 100644 index 00000000..80d9f5f9 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_xcm.rs @@ -0,0 +1,318 @@ +// 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 . +//! Autogenerated weights for `pallet_xcm` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev +//! DATE: 2024-02-22, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("moonbase-dev")`, DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_xcm +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --output=./runtime/common/src/weights/ + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::Weight}; +use core::marker::PhantomData; + +/// Weight functions for `pallet_xcm`. +pub struct WeightInfo(PhantomData); +impl pallet_xcm::WeightInfo for WeightInfo { + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn send() -> Weight { + // Proof Size summary in bytes: + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 23_849_000 picoseconds. + Weight::from_parts(24_416_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `Benchmark::Override` (r:0 w:0) + /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn teleport_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn reserve_transfer_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `76` + // Estimated: `3541` + // Minimum execution time: 27_460_000 picoseconds. + Weight::from_parts(28_098_000, 0) + .saturating_add(Weight::from_parts(0, 3541)) + .saturating_add(T::DbWeight::get().reads(1)) + } + fn execute() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_970_000 picoseconds. + Weight::from_parts(8_200_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: `PolkadotXcm::SupportedVersion` (r:0 w:1) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn force_xcm_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 8_023_000 picoseconds. + Weight::from_parts(8_437_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:0 w:1) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn force_default_xcm_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_570_000 picoseconds. + Weight::from_parts(2_861_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `PolkadotXcm::VersionNotifiers` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::QueryCounter` (r:1 w:1) + /// Proof: `PolkadotXcm::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::Queries` (r:0 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn force_subscribe_version_notify() -> Weight { + // Proof Size summary in bytes: + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 26_700_000 picoseconds. + Weight::from_parts(27_526_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: `PolkadotXcm::VersionNotifiers` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::Queries` (r:0 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn force_unsubscribe_version_notify() -> Weight { + // Proof Size summary in bytes: + // Measured: `328` + // Estimated: `3793` + // Minimum execution time: 28_689_000 picoseconds. + Weight::from_parts(29_471_000, 0) + .saturating_add(Weight::from_parts(0, 3793)) + .saturating_add(T::DbWeight::get().reads(6)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `PolkadotXcm::XcmExecutionSuspended` (r:0 w:1) + /// Proof: `PolkadotXcm::XcmExecutionSuspended` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn force_suspension() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 2_629_000 picoseconds. + Weight::from_parts(2_840_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `PolkadotXcm::SupportedVersion` (r:4 w:2) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn migrate_supported_version() -> Weight { + // Proof Size summary in bytes: + // Measured: `167` + // Estimated: `11057` + // Minimum execution time: 24_006_000 picoseconds. + Weight::from_parts(24_516_000, 0) + .saturating_add(Weight::from_parts(0, 11057)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `PolkadotXcm::VersionNotifiers` (r:4 w:2) + /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn migrate_version_notifiers() -> Weight { + // Proof Size summary in bytes: + // Measured: `171` + // Estimated: `11061` + // Minimum execution time: 23_352_000 picoseconds. + Weight::from_parts(24_140_000, 0) + .saturating_add(Weight::from_parts(0, 11061)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:0) + /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn already_notified_target() -> Weight { + // Proof Size summary in bytes: + // Measured: `178` + // Estimated: `13543` + // Minimum execution time: 28_644_000 picoseconds. + Weight::from_parts(29_377_000, 0) + .saturating_add(Weight::from_parts(0, 13543)) + .saturating_add(T::DbWeight::get().reads(5)) + } + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:2 w:1) + /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn notify_current_targets() -> Weight { + // Proof Size summary in bytes: + // Measured: `212` + // Estimated: `6152` + // Minimum execution time: 27_677_000 picoseconds. + Weight::from_parts(28_668_000, 0) + .saturating_add(Weight::from_parts(0, 6152)) + .saturating_add(T::DbWeight::get().reads(7)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:3 w:0) + /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn notify_target_migration_fail() -> Weight { + // Proof Size summary in bytes: + // Measured: `172` + // Estimated: `8587` + // Minimum execution time: 15_050_000 picoseconds. + Weight::from_parts(15_377_000, 0) + .saturating_add(Weight::from_parts(0, 8587)) + .saturating_add(T::DbWeight::get().reads(3)) + } + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn migrate_version_notify_targets() -> Weight { + // Proof Size summary in bytes: + // Measured: `178` + // Estimated: `11068` + // Minimum execution time: 24_211_000 picoseconds. + Weight::from_parts(24_757_000, 0) + .saturating_add(Weight::from_parts(0, 11068)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn migrate_and_notify_old_targets() -> Weight { + // Proof Size summary in bytes: + // Measured: `254` + // Estimated: `11144` + // Minimum execution time: 39_443_000 picoseconds. + Weight::from_parts(40_030_000, 0) + .saturating_add(Weight::from_parts(0, 11144)) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(4)) + } + /// Storage: `Benchmark::Override` (r:0 w:0) + /// Proof: `Benchmark::Override` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn transfer_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 18_446_744_073_709_551_000 picoseconds. + Weight::from_parts(18_446_744_073_709_551_000, 0) + .saturating_add(Weight::from_parts(0, 0)) + } + /// Storage: `PolkadotXcm::QueryCounter` (r:1 w:1) + /// Proof: `PolkadotXcm::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::Queries` (r:0 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn new_query() -> Weight { + // Proof Size summary in bytes: + // Measured: `69` + // Estimated: `1554` + // Minimum execution time: 4_000_000 picoseconds. + Weight::from_parts(5_000_000, 0) + .saturating_add(Weight::from_parts(0, 1554)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(2)) + } + /// Storage: `PolkadotXcm::Queries` (r:1 w:1) + /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn take_response() -> Weight { + // Proof Size summary in bytes: + // Measured: `7706` + // Estimated: `11171` + // Minimum execution time: 29_000_000 picoseconds. + Weight::from_parts(31_000_000, 0) + .saturating_add(Weight::from_parts(0, 11171)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/tracing/2902/runtime/common/src/weights/pallet_xcm_transactor.rs b/tracing/2902/runtime/common/src/weights/pallet_xcm_transactor.rs new file mode 100644 index 00000000..b357ce64 --- /dev/null +++ b/tracing/2902/runtime/common/src/weights/pallet_xcm_transactor.rs @@ -0,0 +1,192 @@ +// 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 . + +//! Autogenerated weights for `pallet_xcm_transactor` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-04-10, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `ip-10-0-0-176`, CPU: `Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz` +//! WASM-EXECUTION: Compiled, CHAIN: Some("moonbase-dev"), DB CACHE: 1024 + +// Executed Command: +// ./target/production/moonbeam +// benchmark +// pallet +// --chain=moonbase-dev +// --steps=50 +// --repeat=20 +// --pallet=pallet_xcm_transactor +// --extrinsic=* +// --wasm-execution=compiled +// --header=./file_header.txt +// --template=./benchmarking/frame-weight-template.hbs +// --output=./runtime/common/src/weights/ + +#![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; + +/// Weights for `pallet_xcm_transactor`. +pub struct WeightInfo(PhantomData); +impl pallet_xcm_transactor::WeightInfo for WeightInfo { + /// Storage: `XcmTransactor::IndexToAccount` (r:1 w:1) + /// Proof: `XcmTransactor::IndexToAccount` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn register() -> Weight { + // Proof Size summary in bytes: + // Measured: `114` + // Estimated: `3579` + // Minimum execution time: 9_646_000 picoseconds. + Weight::from_parts(9_987_000, 3579) + .saturating_add(T::DbWeight::get().reads(1_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmTransactor::IndexToAccount` (r:0 w:1) + /// Proof: `XcmTransactor::IndexToAccount` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn deregister() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 5_810_000 picoseconds. + Weight::from_parts(5_995_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:0 w:1) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn set_transact_info() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 7_207_000 picoseconds. + Weight::from_parts(7_399_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:0 w:1) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_transact_info() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_469_000 picoseconds. + Weight::from_parts(6_698_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `XcmTransactor::DestinationAssetFeePerSecond` (r:0 w:1) + /// Proof: `XcmTransactor::DestinationAssetFeePerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn set_fee_per_second() -> Weight { + // Proof Size summary in bytes: + // Measured: `0` + // Estimated: `0` + // Minimum execution time: 6_491_000 picoseconds. + Weight::from_parts(6_877_000, 0) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } + /// Storage: `AssetManager::AssetIdType` (r:1 w:0) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::IndexToAccount` (r:1 w:0) + /// Proof: `XcmTransactor::IndexToAccount` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::RelayIndices` (r:1 w:0) + /// Proof: `XcmTransactor::RelayIndices` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:1 w:0) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::DestinationAssetFeePerSecond` (r:1 w:0) + /// Proof: `XcmTransactor::DestinationAssetFeePerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn transact_through_derivative() -> Weight { + // Proof Size summary in bytes: + // Measured: `489` + // Estimated: `3954` + // Minimum execution time: 30_621_000 picoseconds. + Weight::from_parts(31_185_000, 3954) + .saturating_add(T::DbWeight::get().reads(7_u64)) + } + /// Storage: `AssetManager::AssetIdType` (r:1 w:0) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:1 w:0) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::DestinationAssetFeePerSecond` (r:1 w:0) + /// Proof: `XcmTransactor::DestinationAssetFeePerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetTypeId` (r:1 w:0) + /// Proof: `AssetManager::AssetTypeId` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `Assets::Asset` (r:1 w:0) + /// Proof: `Assets::Asset` (`max_values`: None, `max_size`: Some(174), added: 2649, mode: `MaxEncodedLen`) + fn transact_through_sovereign() -> Weight { + // Proof Size summary in bytes: + // Measured: `423` + // Estimated: `3888` + // Minimum execution time: 22_815_000 picoseconds. + Weight::from_parts(23_179_000, 3888) + .saturating_add(T::DbWeight::get().reads(5_u64)) + } + /// Storage: `AssetManager::AssetIdType` (r:1 w:0) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:1 w:0) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::DestinationAssetFeePerSecond` (r:1 w:0) + /// Proof: `XcmTransactor::DestinationAssetFeePerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn transact_through_signed() -> Weight { + // Proof Size summary in bytes: + // Measured: `467` + // Estimated: `3932` + // Minimum execution time: 38_105_000 picoseconds. + Weight::from_parts(38_977_000, 3932) + .saturating_add(T::DbWeight::get().reads(8_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } + /// Storage: `XcmTransactor::RelayIndices` (r:1 w:0) + /// Proof: `XcmTransactor::RelayIndices` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `AssetManager::AssetIdType` (r:1 w:0) + /// Proof: `AssetManager::AssetIdType` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::TransactInfoWithWeightLimit` (r:1 w:0) + /// Proof: `XcmTransactor::TransactInfoWithWeightLimit` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `XcmTransactor::DestinationAssetFeePerSecond` (r:1 w:0) + /// Proof: `XcmTransactor::DestinationAssetFeePerSecond` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SupportedVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::VersionDiscoveryQueue` (r:1 w:1) + /// Proof: `PolkadotXcm::VersionDiscoveryQueue` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `PolkadotXcm::SafeXcmVersion` (r:1 w:0) + /// Proof: `PolkadotXcm::SafeXcmVersion` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::HostConfiguration` (r:1 w:0) + /// Proof: `ParachainSystem::HostConfiguration` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `ParachainSystem::PendingUpwardMessages` (r:1 w:1) + /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn hrmp_manage() -> Weight { + // Proof Size summary in bytes: + // Measured: `471` + // Estimated: `3936` + // Minimum execution time: 40_787_000 picoseconds. + Weight::from_parts(41_832_000, 3936) + .saturating_add(T::DbWeight::get().reads(9_u64)) + .saturating_add(T::DbWeight::get().writes(2_u64)) + } +} diff --git a/tracing/2902/runtime/moonbase/Cargo.toml b/tracing/2902/runtime/moonbase/Cargo.toml new file mode 100644 index 00000000..8536ea54 --- /dev/null +++ b/tracing/2902/runtime/moonbase/Cargo.toml @@ -0,0 +1,420 @@ +[package] +authors = { workspace = true } +build = "build.rs" +description = "Moonbase Runtime" +edition = "2021" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +name = "moonbase-runtime" +version = "0.8.4" + +[dependencies] +hex-literal = { workspace = true, optional = true } +log = { workspace = true } +num_enum = { workspace = true } +rlp = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +sha3 = { workspace = true, optional = true } +smallvec = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } + +# Moonbeam +account = { workspace = true } +moonbeam-core-primitives = { workspace = true } +moonbeam-relay-encoder = { workspace = true } +moonbeam-runtime-common = { workspace = true } +precompile-utils = { workspace = true } +session-keys-primitives = { workspace = true } +xcm-primitives = { workspace = true } + +# Moonbeam pallets +moonbeam-xcm-benchmarks = { workspace = true } +pallet-asset-manager = { workspace = true } +pallet-author-mapping = { workspace = true } +pallet-crowdloan-rewards = { workspace = true } +pallet-erc20-xcm-bridge = { workspace = true } +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-lazy-migrations = { workspace = true } +pallet-moonbeam-orbiters = { workspace = true } +pallet-parachain-staking = { workspace = true } +pallet-precompile-benchmarks = { workspace = true } +pallet-proxy-genesis-companion = { workspace = true } +pallet-randomness = { workspace = true } +pallet-xcm-transactor = { workspace = true } + +# Moonbeam precompiles +pallet-evm-precompile-author-mapping = { workspace = true } +pallet-evm-precompile-balances-erc20 = { workspace = true } +pallet-evm-precompile-batch = { workspace = true } +pallet-evm-precompile-call-permit = { workspace = true } +pallet-evm-precompile-collective = { workspace = true } +pallet-evm-precompile-conviction-voting = { workspace = true } +pallet-evm-precompile-crowdloan-rewards = { workspace = true } +pallet-evm-precompile-gmp = { workspace = true } +pallet-evm-precompile-identity = { workspace = true } +pallet-evm-precompile-parachain-staking = { workspace = true } +pallet-evm-precompile-preimage = { workspace = true } +pallet-evm-precompile-proxy = { workspace = true } +pallet-evm-precompile-randomness = { workspace = true } +pallet-evm-precompile-referenda = { workspace = true } +pallet-evm-precompile-registry = { workspace = true } +pallet-evm-precompile-relay-encoder = { workspace = true } +pallet-evm-precompile-relay-verifier = { workspace = true } +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 } + +# Moonbeam tracing +evm-tracing-events = { workspace = true, optional = true } +moonbeam-evm-tracer = { workspace = true, optional = true } +moonbeam-rpc-primitives-debug = { workspace = true } +moonbeam-rpc-primitives-txpool = { workspace = true } + +# Substrate +frame-executive = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +frame-system-rpc-runtime-api = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true, features = ["insecure_zero_ed"] } +pallet-collective = { workspace = true } +pallet-conviction-voting = { workspace = true } +pallet-identity = { workspace = true } +pallet-multisig = { workspace = true } +pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } +pallet-referenda = { workspace = true } +pallet-root-testing = { workspace = true } +pallet-scheduler = { workspace = true } +pallet-society = { workspace = true } +pallet-sudo = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-transaction-payment = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-treasury = { workspace = true } +pallet-utility = { workspace = true } +pallet-whitelist = { workspace = true } +parity-scale-codec = { workspace = true, features = [ + "derive", + "max-encoded-len", + "chain-error", +] } +scale-info = { workspace = true, features = ["derive"] } +sp-api = { workspace = true } +sp-block-builder = { workspace = true } +sp-consensus-slots = { workspace = true } +sp-core = { workspace = true } +sp-debug-derive = { workspace = true } +sp-inherents = { workspace = true } +sp-io = { workspace = true, features = ["improved_panic_error_reporting"] } +sp-offchain = { workspace = true } +sp-runtime = { workspace = true } +sp-session = { workspace = true } +sp-std = { workspace = true } +sp-transaction-pool = { workspace = true } +sp-version = { workspace = true } +sp-weights = { workspace = true } +sp-genesis-builder = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +fp-rpc = { workspace = true } +fp-self-contained = { workspace = true, features = ["serde"] } +pallet-ethereum = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm-precompile-blake2 = { workspace = true } +pallet-evm-precompile-bn128 = { workspace = true } +pallet-evm-precompile-dispatch = { workspace = true } +pallet-evm-precompile-modexp = { workspace = true } +pallet-evm-precompile-sha3fips = { workspace = true } +pallet-evm-precompile-simple = { workspace = true } +pallet-evm-precompile-storage-cleaner = { workspace = true } + + +# Polkadot / XCM +orml-traits = { workspace = true } +orml-xcm-support = { workspace = true } +orml-xtokens = { workspace = true } +pallet-xcm = { workspace = true } +pallet-xcm-benchmarks = { workspace = true, optional = true } +pallet-message-queue = { workspace = true } +polkadot-core-primitives = { workspace = true } +polkadot-parachain = { workspace = true } +polkadot-runtime-common = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Cumulus +cumulus-pallet-dmp-queue = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-xcm = { workspace = true } +cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-core = { workspace = true } +cumulus-primitives-timestamp = { workspace = true } +cumulus-primitives-utility = { workspace = true } +parachain-info = { workspace = true } +parachains-common = { workspace = true } + +# Moonkit +async-backing-primitives = { workspace = true } +moonkit-xcm-primitives = { workspace = true } +nimbus-primitives = { workspace = true } +pallet-async-backing = { workspace = true } +pallet-author-inherent = { workspace = true } +pallet-author-slot-filter = { workspace = true } +pallet-emergency-para-xcm = { workspace = true } +pallet-relay-storage-roots = { workspace = true } + +# Benchmarking +frame-benchmarking = { workspace = true, optional = true } +frame-system-benchmarking = { workspace = true, optional = true } +frame-try-runtime = { workspace = true, optional = true } + +[build-dependencies] +substrate-wasm-builder = { workspace = true } + +[features] +default = ["std", "evm-tracing"] +std = [ + "account/std", + "async-backing-primitives/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "evm-tracing-events/std", + "fp-evm/std", + "fp-rpc/std", + "fp-self-contained/std", + "frame-benchmarking/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "moonbeam-core-primitives/std", + "moonbeam-evm-tracer/std", + "moonbeam-relay-encoder/std", + "moonbeam-rpc-primitives-debug/std", + "moonbeam-rpc-primitives-txpool/std", + "moonbeam-runtime-common/std", + "moonkit-xcm-primitives/std", + "nimbus-primitives/std", + "orml-xtokens/std", + "pallet-asset-manager/std", + "pallet-assets/std", + "pallet-async-backing/std", + "pallet-author-inherent/std", + "pallet-author-mapping/std", + "pallet-author-slot-filter/std", + "pallet-balances/std", + "pallet-collective/std", + "pallet-conviction-voting/std", + "pallet-crowdloan-rewards/std", + "pallet-emergency-para-xcm/std", + "pallet-erc20-xcm-bridge/std", + "pallet-evm-chain-id/std", + "pallet-ethereum-xcm/std", + "pallet-ethereum/std", + "pallet-evm-precompile-author-mapping/std", + "pallet-evm-precompile-balances-erc20/std", + "pallet-evm-precompile-batch/std", + "pallet-evm-precompile-call-permit/std", + "pallet-evm-precompile-collective/std", + "pallet-evm-precompile-conviction-voting/std", + "pallet-evm-precompile-parachain-staking/std", + "pallet-evm-precompile-preimage/std", + "pallet-evm-precompile-randomness/std", + "pallet-evm-precompile-referenda/std", + "pallet-evm-precompile-registry/std", + "pallet-evm-precompile-relay-verifier/std", + "pallet-evm-precompile-xcm-transactor/std", + "pallet-evm-precompile-xcm-utils/std", + "pallet-evm-precompile-xtokens/std", + "pallet-evm-precompileset-assets-erc20/std", + "pallet-evm-precompile-storage-cleaner/std", + "pallet-evm/std", + "pallet-identity/std", + "pallet-maintenance-mode/std", + "pallet-migrations/std", + "pallet-moonbeam-lazy-migrations/std", + "pallet-moonbeam-orbiters/std", + "pallet-multisig/std", + "pallet-parachain-staking/std", + "pallet-precompile-benchmarks/std", + "pallet-preimage/std", + "pallet-proxy-genesis-companion/std", + "pallet-proxy/std", + "pallet-randomness/std", + "pallet-referenda/std", + "pallet-relay-storage-roots/std", + "pallet-root-testing/std", + "pallet-scheduler/std", + "pallet-society/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "pallet-utility/std", + "pallet-whitelist/std", + "pallet-xcm-transactor/std", + "pallet-xcm/std", + "parachain-info/std", + "parachains-common/std", + "parity-scale-codec/std", + "precompile-utils/std", + "scale-info/std", + "session-keys-primitives/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-slots/std", + "sp-core/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-genesis-builder/std", + "strum/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm-primitives/std", + "xcm/std", +] + +# Must be enabled for tracing runtimes only +evm-tracing = ["evm-tracing-events", "moonbeam-evm-tracer", "rlp", "sha3"] + +# Allow to print logs details (no wasm:stripped) +force-debug = ["sp-debug-derive/force-debug"] + +# Will be enabled by the `wasm-builder` when building the runtime for WASM. +runtime-wasm = [] + +# A feature that should be enabled when the runtime should be build for on-chain +# deployment. This will disable stuff that shouldn't be part of the on-chain wasm +# to make it smaller like logging for example. +on-chain-release-build = ["sp-api/disable-logging"] + +runtime-benchmarks = [ + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "moonbeam-relay-encoder/runtime-benchmarks", + "moonbeam-runtime-common/runtime-benchmarks", + "moonbeam-xcm-benchmarks/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "pallet-asset-manager/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-author-inherent/runtime-benchmarks", + "pallet-author-mapping/runtime-benchmarks", + "pallet-author-slot-filter/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", + "pallet-crowdloan-rewards/runtime-benchmarks", + "pallet-ethereum-xcm/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", + "pallet-moonbeam-lazy-migrations/runtime-benchmarks", + "pallet-moonbeam-orbiters/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-parachain-staking/runtime-benchmarks", + "pallet-precompile-benchmarks/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-randomness/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-relay-storage-roots/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "session-keys-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", +] + +try-runtime = [ + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "fp-self-contained/try-runtime", + "frame-executive/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime", + "moonbeam-runtime-common/try-runtime", + "pallet-asset-manager/try-runtime", + "pallet-author-mapping/try-runtime", + "pallet-author-slot-filter/try-runtime", + "pallet-balances/try-runtime", + "pallet-collective/try-runtime", + "pallet-conviction-voting/try-runtime", + "pallet-emergency-para-xcm/try-runtime", + "pallet-maintenance-mode/try-runtime", + "pallet-migrations/try-runtime", + "pallet-moonbeam-lazy-migrations/try-runtime", + "pallet-parachain-staking/try-runtime", + "pallet-preimage/try-runtime", + "pallet-referenda/try-runtime", + "pallet-relay-storage-roots/try-runtime", + "pallet-root-testing/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-society/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-xcm/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-utility/try-runtime", + "pallet-sudo/try-runtime", + "pallet-transaction-payment/try-runtime", + "parachain-info/try-runtime", + "pallet-evm-chain-id/try-runtime", + "parachain-info/try-runtime", + "pallet-evm/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-treasury/try-runtime", + "pallet-author-inherent/try-runtime", + "pallet-crowdloan-rewards/try-runtime", + "pallet-proxy/try-runtime", + "pallet-identity/try-runtime", + "orml-xtokens/try-runtime", + "pallet-assets/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-proxy-genesis-companion/try-runtime", + "pallet-moonbeam-orbiters/try-runtime", + "pallet-ethereum-xcm/try-runtime", + "pallet-randomness/try-runtime", + "pallet-whitelist/try-runtime", + "pallet-erc20-xcm-bridge/try-runtime", + "pallet-multisig/try-runtime", + "pallet-async-backing/try-runtime", + "pallet-precompile-benchmarks/try-runtime", +] + +moonbase-runtime-benchmarks = [] diff --git a/tracing/2902/runtime/moonbase/build.rs b/tracing/2902/runtime/moonbase/build.rs new file mode 100644 index 00000000..3934b9c5 --- /dev/null +++ b/tracing/2902/runtime/moonbase/build.rs @@ -0,0 +1,25 @@ +// 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 substrate_wasm_builder::WasmBuilder; + +fn main() { + WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() +} diff --git a/tracing/2902/runtime/moonbase/src/asset_config.rs b/tracing/2902/runtime/moonbase/src/asset_config.rs new file mode 100644 index 00000000..9040423e --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/asset_config.rs @@ -0,0 +1,221 @@ +// 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 . + +//! Asset configuration for Moonbase. +//! + +use crate::OpenTechCommitteeInstance; + +use super::{ + currency, governance, xcm_config, AccountId, AssetId, AssetManager, Assets, Balance, Balances, + Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; + +use frame_support::{ + dispatch::GetDispatchInfo, + parameter_types, + traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, EitherOfDiverse}, + weights::Weight, +}; + +use frame_system::{EnsureNever, EnsureRoot}; +use parity_scale_codec::{Compact, Decode, Encode}; +use scale_info::TypeInfo; +use sp_core::H160; + +use sp_std::{ + convert::{From, Into}, + prelude::*, +}; + +// Number of items that can be destroyed with our configured max extrinsic proof size. +// x = (a - b) / c where: +// a: maxExtrinsic proof size +// b: base proof size for destroy_accounts in pallet_assets weights +// c: proof size for each item +// 656.87 = (3_407_872 - 8232) / 5180 +const REMOVE_ITEMS_LIMIT: u32 = 656; + +// Not to disrupt the previous asset instance, we assign () to Foreign +pub type ForeignAssetInstance = (); + +// For foreign assets, these parameters dont matter much +// as this will only be called by root with the forced arguments +// No deposit is substracted with those methods +parameter_types! { + pub const AssetDeposit: Balance = 100 * currency::UNIT * currency::SUPPLY_FACTOR; + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = currency::deposit(1,68); + pub const MetadataDepositPerByte: Balance = currency::deposit(0, 1); +} + +/// We allow Root and General Admin to execute privileged asset operations. +pub type AssetsForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +// Foreign assets +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = AssetsForceOrigin; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = ConstU128<{ currency::deposit(1, 18) }>; + type WeightInfo = moonbeam_weights::pallet_assets::WeightInfo; + type RemoveItemsLimit = ConstU32<{ REMOVE_ITEMS_LIMIT }>; + type AssetIdParameter = Compact; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +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, + ) -> 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, + ) + } + + #[transactional] + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + // For us both of them (Foreign and Local) have the same annotated weight for a given + // witness + // We need to take the dispatch info from the destroy call, which is already annotated in + // the assets pallet + + // This is the dispatch info of destroy + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetRegistrarMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, + pub is_frozen: bool, +} + +pub type ForeignAssetModifierOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::GeneralAdmin, + >, +>; + +pub type LocalAssetModifierOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetRegistrarMetadata; + type ForeignAssetType = xcm_config::AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = ForeignAssetModifierOrigin; + type WeightInfo = moonbeam_weights::pallet_asset_manager::WeightInfo; +} + +// Instruct how to go from an H160 to an AssetID +// We just take the lowest 128 bits +impl AccountIdAssetIdConversion for Runtime { + /// The way to convert an account to assetId is by ensuring that the prefix is 0XFFFFFFFF + /// and by taking the lowest 128 bits as the assetId + fn account_to_asset_id(account: AccountId) -> Option<(Vec, AssetId)> { + let h160_account: H160 = account.into(); + let mut data = [0u8; 16]; + let (prefix_part, id_part) = h160_account.as_fixed_bytes().split_at(4); + if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX { + data.copy_from_slice(id_part); + let asset_id: AssetId = u128::from_be_bytes(data).into(); + Some((prefix_part.to_vec(), asset_id)) + } else { + None + } + } + + // The opposite conversion + fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> AccountId { + let mut data = [0u8; 20]; + data[0..4].copy_from_slice(prefix); + data[4..20].copy_from_slice(&asset_id.to_be_bytes()); + AccountId::from(data) + } +} diff --git a/tracing/2902/runtime/moonbase/src/governance/councils.rs b/tracing/2902/runtime/moonbase/src/governance/councils.rs new file mode 100644 index 00000000..d6addeae --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/governance/councils.rs @@ -0,0 +1,62 @@ +// 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 . + +//! Councils for Gov1 and Gov2 + +use super::*; +use moonbeam_runtime_common::weights as moonbeam_weights; + +pub type TreasuryCouncilInstance = pallet_collective::Instance3; +pub type OpenTechCommitteeInstance = pallet_collective::Instance4; + +parameter_types! { + // TODO: Check value of this parameter + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * BlockWeights::get().max_block; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for treasury council members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 3 * DAYS }>; + /// The maximum number of proposals that can be open in the treasury council at once. + type MaxProposals = ConstU32<20>; + /// The maximum number of treasury council members. + type MaxMembers = ConstU32<9>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for technical committee members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 14 * DAYS }>; + /// The maximum number of proposals that can be open in the technical committee at once. + type MaxProposals = ConstU32<100>; + /// The maximum number of technical committee members. + type MaxMembers = ConstU32<100>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} diff --git a/tracing/2902/runtime/moonbase/src/governance/mod.rs b/tracing/2902/runtime/moonbase/src/governance/mod.rs new file mode 100644 index 00000000..36a2c6be --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/governance/mod.rs @@ -0,0 +1,29 @@ +// 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 . + +//! Governance configurations + +pub mod councils; +pub mod referenda; + +use super::*; + +mod origins; +pub use origins::{ + custom_origins, GeneralAdmin, ReferendumCanceller, ReferendumKiller, WhitelistedCaller, +}; +mod tracks; +pub use tracks::TracksInfo; diff --git a/tracing/2902/runtime/moonbase/src/governance/origins.rs b/tracing/2902/runtime/moonbase/src/governance/origins.rs new file mode 100644 index 00000000..e8de3c35 --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/governance/origins.rs @@ -0,0 +1,83 @@ +// 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. + +//! Custom origins for governance interventions. +pub use custom_origins::*; + +#[frame_support::pallet] +pub mod custom_origins { + use frame_support::pallet_prelude::*; + use strum_macros::EnumString; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[derive( + PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug, EnumString, + )] + #[strum(serialize_all = "snake_case")] + #[pallet::origin] + pub enum Origin { + /// Origin able to dispatch a whitelisted call. + WhitelistedCaller, + /// General admin + GeneralAdmin, + /// Origin able to cancel referenda. + ReferendumCanceller, + /// Origin able to kill referenda. + ReferendumKiller, + /// Fast General Admin + FastGeneralAdmin, + } + + macro_rules! decl_unit_ensures { + ( $name:ident: $success_type:ty = $success:expr ) => { + pub struct $name; + impl> + From> + EnsureOrigin for $name + { + type Success = $success_type; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::$name => Ok($success), + r => Err(O::from(r)), + }) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::$name)) + } + } + }; + ( $name:ident ) => { decl_unit_ensures! { $name : () = () } }; + ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => { + decl_unit_ensures! { $name: $success_type = $success } + decl_unit_ensures! { $( $rest )* } + }; + ( $name:ident, $( $rest:tt )* ) => { + decl_unit_ensures! { $name } + decl_unit_ensures! { $( $rest )* } + }; + () => {} + } + decl_unit_ensures!( + ReferendumCanceller, + ReferendumKiller, + WhitelistedCaller, + GeneralAdmin, + FastGeneralAdmin, + ); +} diff --git a/tracing/2902/runtime/moonbase/src/governance/referenda.rs b/tracing/2902/runtime/moonbase/src/governance/referenda.rs new file mode 100644 index 00000000..96bb3628 --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/governance/referenda.rs @@ -0,0 +1,101 @@ +// 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 . + +//! # Gov2 config +//! Includes runtime configs for these substrate pallets: +//! 1. pallet-conviction-voting +//! 2. pallet-whitelist +//! 3. pallet-referenda + +use super::*; +use crate::currency::*; +use frame_support::traits::{EitherOf, MapSuccess}; +use frame_system::EnsureRootWithSuccess; +use moonbeam_runtime_common::weights as moonbeam_weights; +use sp_runtime::traits::Replace; + +parameter_types! { + pub const VoteLockingPeriod: BlockNumber = 1 * DAYS; +} + +impl pallet_conviction_voting::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_conviction_voting::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type Polls = Referenda; + type MaxTurnout = frame_support::traits::TotalIssuanceOf; + // Maximum number of concurrent votes an account may have + type MaxVotes = ConstU32<20>; + // Minimum period of vote locking + type VoteLockingPeriod = VoteLockingPeriod; +} + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 10 * UNIT * SUPPLY_FACTOR; + pub const UndecidingTimeout: BlockNumber = 21 * DAYS; +} + +pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; + +/// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; + +impl custom_origins::Config for Runtime {} + +// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch +// origin corresponds to the Gov2 Whitelist track. +impl pallet_whitelist::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_whitelist::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WhitelistOrigin = EitherOf< + EnsureRootWithSuccess>, + MapSuccess< + pallet_collective::EnsureProportionAtLeast< + Self::AccountId, + OpenTechCommitteeInstance, + 5, + 9, + >, + Replace>, + >, + >; + type DispatchWhitelistedOrigin = EitherOf, WhitelistedCaller>; + type Preimages = Preimage; +} + +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); + +impl pallet_referenda::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_referenda::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = frame_system::EnsureSigned; + type CancelOrigin = EitherOf, ReferendumCanceller>; + type KillOrigin = EitherOf, ReferendumKiller>; + type Slash = Treasury; + type Votes = pallet_conviction_voting::VotesOf; + type Tally = pallet_conviction_voting::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = TracksInfo; + type Preimages = Preimage; +} diff --git a/tracing/2902/runtime/moonbase/src/governance/tracks.rs b/tracing/2902/runtime/moonbase/src/governance/tracks.rs new file mode 100644 index 00000000..72e18b9f --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/governance/tracks.rs @@ -0,0 +1,193 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Track configurations for governance. + +use super::*; +use crate::currency::{KILOUNIT, SUPPLY_FACTOR, UNIT}; +use sp_std::str::FromStr; + +const fn percent(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 100) +} +const fn permill(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 1000) +} + +use pallet_referenda::Curve; +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 6] = [ + ( + 0, + pallet_referenda::TrackInfo { + // Name of this track. + name: "root", + // A limit for the number of referenda on this track that can be being decided at once. + // For Root origin this should generally be just one. + max_deciding: 5, + // Amount that must be placed on deposit before a decision can be made. + decision_deposit: 100 * KILOUNIT * SUPPLY_FACTOR, + // Amount of time this must be submitted for before a decision can be made. + prepare_period: 1 * DAYS, + // Amount of time that a decision may take to be approved prior to cancellation. + decision_period: 14 * DAYS, + // Amount of time that the approval criteria must hold before it can be approved. + confirm_period: 1 * DAYS, + // Minimum amount of time that an approved proposal must be in the dispatch queue. + min_enactment_period: 1 * DAYS, + // Minimum aye votes as percentage of overall conviction-weighted votes needed for + // approval as a function of time into decision period. + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + // Minimum pre-conviction aye-votes ("support") as percentage of overall population that + // is needed for approval as a function of time into decision period. + min_support: Curve::make_linear(14, 14, permill(5), percent(25)), + }, + ), + ( + 1, + pallet_referenda::TrackInfo { + name: "whitelisted_caller", + max_deciding: 100, + decision_deposit: 10 * KILOUNIT * SUPPLY_FACTOR, + prepare_period: 10 * MINUTES, + decision_period: 14 * DAYS, + confirm_period: 10 * MINUTES, + min_enactment_period: 30 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14 * 24, percent(1), percent(0), percent(2)), + }, + ), + ( + 2, + pallet_referenda::TrackInfo { + name: "general_admin", + max_deciding: 10, + decision_deposit: 500 * UNIT * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 1 * DAYS, + min_enactment_period: 1 * DAYS, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(7, 14, percent(10), percent(0), percent(50)), + }, + ), + ( + 3, + pallet_referenda::TrackInfo { + name: "referendum_canceller", + max_deciding: 20, + decision_deposit: 10 * KILOUNIT * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(50)), + }, + ), + ( + 4, + pallet_referenda::TrackInfo { + name: "referendum_killer", + max_deciding: 100, + decision_deposit: 20 * KILOUNIT * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), + }, + ), + ( + 5, + pallet_referenda::TrackInfo { + name: "fast_general_admin", + max_deciding: 10, + decision_deposit: 500 * UNIT * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(5, 14, percent(1), percent(0), percent(50)), + }, + ), +]; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + &TRACKS_DATA[..] + } + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => { + if let Some((track_id, _)) = Self::tracks() + .into_iter() + .find(|(_, track)| track.name == "root") + { + Ok(*track_id) + } else { + Err(()) + } + } + _ => Err(()), + } + } else if let Ok(custom_origin) = custom_origins::Origin::try_from(id.clone()) { + if let Some((track_id, _)) = Self::tracks().into_iter().find(|(_, track)| { + if let Ok(track_custom_origin) = custom_origins::Origin::from_str(track.name) { + track_custom_origin == custom_origin + } else { + false + } + }) { + Ok(*track_id) + } else { + Err(()) + } + } else { + Err(()) + } + } +} + +#[test] +/// To ensure voters are always locked into their vote +fn vote_locking_always_longer_than_enactment_period() { + for (_, track) in TRACKS_DATA { + assert!( + ::VoteLockingPeriod::get() + >= track.min_enactment_period, + "Track {} has enactment period {} < vote locking period {}", + track.name, + track.min_enactment_period, + ::VoteLockingPeriod::get(), + ); + } +} + +#[test] +fn all_tracks_have_origins() { + for (_, track) in TRACKS_DATA { + // check name.into() is successful either converts into "root" or custom origin + let track_is_root = track.name == "root"; + let track_has_custom_origin = custom_origins::Origin::from_str(track.name).is_ok(); + assert!(track_is_root || track_has_custom_origin); + } +} diff --git a/tracing/2902/runtime/moonbase/src/lib.rs b/tracing/2902/runtime/moonbase/src/lib.rs new file mode 100644 index 00000000..61b72192 --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/lib.rs @@ -0,0 +1,1804 @@ +// 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 . + +//! The Moonbase Runtime. +//! +//! Primary features of this runtime include: +//! * Ethereum compatibility +//! * Moonbase tokenomics + +#![cfg_attr(not(feature = "std"), no_std)] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. +#![recursion_limit = "512"] + +// Make the WASM binary available. +#[cfg(feature = "std")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +pub mod asset_config; +pub mod governance; +pub mod timestamp; +pub mod xcm_config; + +mod migrations; +mod precompiles; + +// Re-export required by get! macro. +#[cfg(feature = "std")] +pub use fp_evm::GenesisAccount; +pub use frame_support::traits::Get; +pub use moonbeam_core_primitives::{ + AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header, + Index, Signature, +}; +pub use pallet_author_slot_filter::EligibilityValue; +pub use pallet_parachain_staking::{weights::WeightInfo, InflationInfo, Range}; +pub use precompiles::{ + MoonbasePrecompiles, PrecompileName, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +use account::AccountId20; +use cumulus_pallet_parachain_system::{RelayChainStateProof, RelaychainDataProvider}; +use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin}; +use fp_rpc::TransactionStatus; +use frame_support::{ + construct_runtime, + dispatch::{DispatchClass, GetDispatchInfo, PostDispatchInfo}, + ensure, + pallet_prelude::DispatchResult, + parameter_types, + traits::{ + fungible::{Balanced, Credit, HoldConsideration, Inspect}, + tokens::imbalance::ResolveTo, + tokens::{PayFromAccount, UnityAssetBalanceConversion}, + ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, + EqualPrivilegeOnly, FindAuthor, Imbalance, InstanceFilter, LinearStoragePrice, OnFinalize, + OnUnbalanced, + }, + weights::{ + constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, + ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }, + PalletId, +}; + +use frame_system::{EnsureRoot, EnsureSigned}; +use governance::councils::*; +use moonbeam_rpc_primitives_txpool::TxPoolResponse; +use moonbeam_runtime_common::weights as moonbeam_weights; +use nimbus_primitives::CanAuthor; +use pallet_ethereum::Call::transact; +use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; +use pallet_evm::{ + Account as EVMAccount, EVMFungibleAdapter, EnsureAddressNever, EnsureAddressRoot, + FeeCalculator, GasWeightMapping, IdentityAddressMapping, + OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner, +}; +use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment}; +use pallet_treasury::TreasuryAccountId; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; +use sp_api::impl_runtime_apis; +use sp_consensus_slots::Slot; +use sp_core::{OpaqueMetadata, H160, H256, U256}; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{ + BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, IdentityLookup, + PostDispatchInfoOf, UniqueSaturatedInto, Zero, + }, + transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, + }, + ApplyExtrinsicResult, DispatchErrorWithPostInfo, FixedPointNumber, Perbill, Permill, + Perquintill, +}; +use sp_std::{ + convert::{From, Into}, + prelude::*, +}; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +use smallvec::smallvec; +use sp_runtime::serde::{Deserialize, Serialize}; + +#[cfg(any(feature = "std", test))] +pub use sp_runtime::BuildStorage; + +pub type Precompiles = MoonbasePrecompiles; + +/// UNIT, the native token, uses 18 decimals of precision. +pub mod currency { + use super::Balance; + + // Provide a common factor between runtimes based on a supply of 10_000_000 tokens. + pub const SUPPLY_FACTOR: Balance = 1; + + pub const WEI: Balance = 1; + pub const KILOWEI: Balance = 1_000; + pub const MEGAWEI: Balance = 1_000_000; + pub const GIGAWEI: Balance = 1_000_000_000; + pub const MICROUNIT: Balance = 1_000_000_000_000; + pub const MILLIUNIT: Balance = 1_000_000_000_000_000; + pub const UNIT: Balance = 1_000_000_000_000_000_000; + pub const KILOUNIT: Balance = 1_000_000_000_000_000_000_000; + + pub const TRANSACTION_BYTE_FEE: Balance = 1 * GIGAWEI * SUPPLY_FACTOR; + pub const STORAGE_BYTE_FEE: Balance = 100 * MICROUNIT * SUPPLY_FACTOR; + pub const WEIGHT_FEE: Balance = 50 * KILOWEI * SUPPLY_FACTOR; + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 1 * UNIT * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE + } +} + +/// Maximum weight per block +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX) + .saturating_mul(2) + .set_proof_size(relay_chain::MAX_POV_SIZE as u64); + +pub const MILLISECS_PER_BLOCK: u64 = 6_000; +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; +pub const WEEKS: BlockNumber = DAYS * 7; +/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know +/// the specifics of the runtime. They can then be made to be agnostic over specific formats +/// of data like extrinsics, allowing for them to continue syncing the network through upgrades +/// to even the core data structures. +pub mod opaque { + use super::*; + + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + pub type Block = generic::Block; + + impl_opaque_keys! { + pub struct SessionKeys { + pub nimbus: AuthorInherent, + pub vrf: session_keys_primitives::VrfSessionKey, + } + } +} + +/// This runtime version. +/// The spec_version is composed of 2x2 digits. The first 2 digits represent major changes +/// that can't be skipped, such as data migration upgrades. The last 2 digits represent minor +/// changes which can be skipped. +#[sp_version::runtime_version] +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: create_runtime_str!("moonbase"), + impl_name: create_runtime_str!("moonbase"), + authoring_version: 4, + spec_version: 2902, + impl_version: 0, + apis: RUNTIME_API_VERSIONS, + transaction_version: 2, + state_version: 0, +}; + +/// The version information used to identify this runtime when compiled natively. +#[cfg(feature = "std")] +pub fn native_version() -> NativeVersion { + NativeVersion { + runtime_version: VERSION, + can_author_with: Default::default(), + } +} + +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +pub const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4); +// Here we assume Ethereum's base fee of 21000 gas and convert to weight, but we +// subtract roughly the cost of a balance transfer from it (about 1/3 the cost) +// and some cost to account for per-byte-fee. +// TODO: we should use benchmarking's overhead feature to measure this +pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_GAS, 0); + +pub struct RuntimeBlockWeights; +impl Get for RuntimeBlockWeights { + fn get() -> frame_system::limits::BlockWeights { + frame_system::limits::BlockWeights::builder() + .for_class(DispatchClass::Normal, |weights| { + weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT; + weights.max_total = NORMAL_WEIGHT.into(); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = MAXIMUM_BLOCK_WEIGHT.into(); + weights.reserved = (MAXIMUM_BLOCK_WEIGHT - NORMAL_WEIGHT).into(); + }) + .avg_block_initialization(Perbill::from_percent(10)) + .build() + .expect("Provided BlockWeight definitions are valid, qed") + } +} + +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + /// TODO: this is left here so that `impl_runtime_apis_plus_common` will find the same type for + /// `BlockWeights` in all runtimes. It can probably be removed once the custom + /// `RuntimeBlockWeights` has been pushed to each runtime. + pub BlockWeights: frame_system::limits::BlockWeights = RuntimeBlockWeights::get(); + /// We allow for 5 MB blocks. + pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength + ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); +} + +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// The index type for storing how many extrinsics an account has signed. + type Nonce = Index; + /// The index type for blocks. + type Block = Block; + /// The type for hashing blocks and tries. + type Hash = Hash; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// The aggregated RuntimeTask type. + type RuntimeTask = RuntimeTask; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = ConstU32<256>; + /// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok. + type BlockWeights = RuntimeBlockWeights; + /// Maximum size of all encoded transactions (in bytes) that are allowed in one block. + type BlockLength = BlockLength; + /// Runtime version. + type Version = Version; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = RocksDbWeight; + type BaseCallFilter = MaintenanceMode; + type SystemWeightInfo = (); + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = ConstU16<1287>; + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = moonbeam_weights::pallet_utility::WeightInfo; +} + +impl pallet_timestamp::Config for Runtime { + /// A timestamp: milliseconds since the unix epoch. + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<3000>; + type WeightInfo = moonbeam_weights::pallet_timestamp::WeightInfo; +} + +impl pallet_balances::Config for Runtime { + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 4]; + type MaxLocks = ConstU32<50>; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<0>; + type AccountStore = System; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type WeightInfo = moonbeam_weights::pallet_balances::WeightInfo; +} + +pub struct DealWithFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> for DealWithFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ + // this seems to be called for substrate-based transactions + fn on_unbalanceds( + mut fees_then_tips: impl Iterator>>, + ) { + if let Some(fees) = fees_then_tips.next() { + // for fees, 80% are burned, 20% to the treasury + let (_, to_treasury) = fees.ration(80, 20); + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + + // handle tip if there is one + if let Some(tip) = fees_then_tips.next() { + // for now we use the same burn/treasury strategy used for regular fees + let (_, to_treasury) = tip.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + } + } + } + + // this is called from pallet_evm for Ethereum-based transactions + // (technically, it calls on_unbalanced, which calls this when non-zero) + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let (_, to_treasury) = amount.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); + } +} + +pub struct LengthToFee; +impl WeightToFeePolynomial for LengthToFee { + type Balance = Balance; + + fn polynomial() -> WeightToFeeCoefficients { + smallvec![ + WeightToFeeCoefficient { + degree: 1, + coeff_frac: Perbill::zero(), + coeff_integer: currency::TRANSACTION_BYTE_FEE, + negative: false, + }, + WeightToFeeCoefficient { + degree: 3, + coeff_frac: Perbill::zero(), + coeff_integer: 1 * currency::SUPPLY_FACTOR, + negative: false, + }, + ] + } +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = FungibleAdapter>; + type OperationalFeeMultiplier = ConstU8<5>; + type WeightToFee = ConstantMultiplier>; + type LengthToFee = LengthToFee; + type FeeMultiplierUpdate = FastAdjustingFeeUpdate; +} + +impl pallet_sudo::Config for Runtime { + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type WeightInfo = moonbeam_weights::pallet_sudo::WeightInfo; +} + +impl pallet_evm_chain_id::Config for Runtime {} + +/// Current approximation of the gas/s consumption considering +/// EVM execution over compiled WASM (on 4.4Ghz CPU). +/// Given the 2 sec Weight, from which 75% only are used for transactions, +/// the total EVM execution gas limit is: GAS_PER_SECOND * 2 * 0.75 ~= 60_000_000. +pub const GAS_PER_SECOND: u64 = 40_000_000; + +/// Approximate ratio of the amount of Weight per Gas. +/// u64 works for approximations because Weight is a very small unit compared to gas. +pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND; +/// The highest amount of new storage that can be created in a block (160KB). +pub const BLOCK_STORAGE_LIMIT: u64 = 160 * 1024; +parameter_types! { + pub BlockGasLimit: U256 + = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS); + /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less + /// than this will decrease the weight and more will increase. + pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(50); + /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to + /// change the fees more rapidly. This fast multiplier responds by doubling/halving in + /// approximately one hour at extreme block congestion levels. + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000); + /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure + /// that combined with `AdjustmentVariable`, we can recover from the minimum. + /// See `multiplier_can_grow_from_zero` in integration_tests.rs. + pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 10); + /// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act + /// as a safety net. + pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128); + pub PrecompilesValue: MoonbasePrecompiles = MoonbasePrecompiles::<_>::new(); + pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per pov. A ratio of 16 if we convert ref_time to gas and we compare + /// it with the pov_size for a block. E.g. + /// ceil( + /// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS + /// ) + /// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value + pub const GasLimitPovSizeRatio: u64 = 16; + /// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT + /// (60_000_000 / 160 kb) + pub GasLimitStorageGrowthRatio: u64 = 366; +} + +pub struct TransactionPaymentAsGasPrice; +impl FeeCalculator for TransactionPaymentAsGasPrice { + fn min_gas_price() -> (U256, Weight) { + // TODO: transaction-payment differs from EIP-1559 in that its tip and length fees are not + // scaled by the multiplier, which means its multiplier will be overstated when + // applied to an ethereum transaction + // note: transaction-payment uses both a congestion modifier (next_fee_multiplier, which is + // updated once per block in on_finalize) and a 'WeightToFee' implementation. Our + // runtime implements this as a 'ConstantModifier', so we can get away with a simple + // multiplication here. + // It is imperative that `saturating_mul_int` be performed as late as possible in the + // expression since it involves fixed point multiplication with a division by a fixed + // divisor. This leads to truncation and subsequent precision loss if performed too early. + // This can lead to min_gas_price being same across blocks even if the multiplier changes. + // There's still some precision loss when the final `gas_price` (used_gas * min_gas_price) + // is computed in frontier, but that's currently unavoidable. + let min_gas_price = TransactionPayment::next_fee_multiplier() + .saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128)); + ( + min_gas_price.into(), + ::DbWeight::get().reads(1), + ) + } +} + +/// A "Fast" TargetedFeeAdjustment. Parameters chosen based on model described here: +/// https://research.web3.foundation/en/latest/polkadot/overview/2-token-economics.html#-1.-fast-adjusting-mechanism // editorconfig-checker-disable-line +/// +/// The adjustment algorithm boils down to: +/// +/// diff = (previous_block_weight - target) / maximum_block_weight +/// next_multiplier = prev_multiplier * (1 + (v * diff) + ((v * diff)^2 / 2)) +/// assert(next_multiplier > min) +/// where: v is AdjustmentVariable +/// target is TargetBlockFullness +/// min is MinimumMultiplier +pub type FastAdjustingFeeUpdate = TargetedFeeAdjustment< + R, + TargetBlockFullness, + AdjustmentVariable, + MinimumMultiplier, + MaximumMultiplier, +>; + +/// The author inherent provides an AccountId, but pallet evm needs an H160. +/// This simple adapter makes the conversion for any types T, U such that T: Into +pub struct FindAuthorAdapter(sp_std::marker::PhantomData<(T, U, Inner)>); + +impl FindAuthor for FindAuthorAdapter +where + T: Into, + Inner: FindAuthor, +{ + fn find_author<'a, I>(digests: I) -> Option + where + I: 'a + IntoIterator, + { + Inner::find_author(digests).map(Into::into) + } +} + +moonbeam_runtime_common::impl_on_charge_evm_transaction!(); + +impl pallet_evm::Config for Runtime { + type FeeCalculator = TransactionPaymentAsGasPrice; + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; + type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; + type AddressMapping = IdentityAddressMapping; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type Runner = pallet_evm::runner::stack::Runner; + type PrecompilesType = MoonbasePrecompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = EthereumChainId; + type OnChargeTransaction = OnChargeEVMTransaction>; + type BlockGasLimit = BlockGasLimit; + type FindAuthor = FindAuthorAdapter; + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = crate::timestamp::RelayTimestamp; + type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo; +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block; + pub const NoPreimagePostponement: Option = Some(10); +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = ConstU32<50>; + type WeightInfo = moonbeam_weights::pallet_scheduler::WeightInfo; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type Preimages = Preimage; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = 5 * currency::UNIT * currency::SUPPLY_FACTOR ; + pub const PreimageByteDeposit: Balance = currency::STORAGE_BYTE_FEE; + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_preimage::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const TreasuryId: PalletId = PalletId(*b"pc/trsry"); + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +type TreasuryApproveOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionAtLeast, +>; + +type TreasuryRejectOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionMoreThan, +>; + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + // At least three-fifths majority of the council is required (or root) to approve a proposal + type ApproveOrigin = TreasuryApproveOrigin; + // More than half of the council is required (or root) to reject a proposal + type RejectOrigin = TreasuryRejectOrigin; + type RuntimeEvent = RuntimeEvent; + // If spending proposal rejected, transfer proposer bond to treasury + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ConstU128<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type SpendPeriod = ConstU32<{ 6 * DAYS }>; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = ConstU32<100>; + type WeightInfo = moonbeam_weights::pallet_treasury::WeightInfo; + type SpendFunds = (); + type ProposalBondMaximum = (); + #[cfg(not(feature = "runtime-benchmarks"))] + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending + #[cfg(feature = "runtime-benchmarks")] + type SpendOrigin = + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<{ 30 * DAYS }>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper; +} + +parameter_types! { + pub const MaxSubAccounts: u32 = 100; + pub const MaxAdditionalFields: u32 = 100; + pub const MaxRegistrars: u32 = 20; + pub const PendingUsernameExpiration: u32 = 7 * DAYS; + pub const MaxSuffixLength: u32 = 7; + pub const MaxUsernameLength: u32 = 32; +} + +type IdentityForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type IdentityRegistrarOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_identity::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + // Add one item in storage and take 258 bytes + type BasicDeposit = ConstU128<{ currency::deposit(1, 258) }>; + // Does not add any item to the storage but takes 1 bytes + type ByteDeposit = ConstU128<{ currency::deposit(0, 1) }>; + // Add one item in storage and take 53 bytes + type SubAccountDeposit = ConstU128<{ currency::deposit(1, 53) }>; + type MaxSubAccounts = MaxSubAccounts; + type IdentityInformation = pallet_identity::legacy::IdentityInfo; + type MaxRegistrars = MaxRegistrars; + type Slashed = Treasury; + type ForceOrigin = IdentityForceOrigin; + type RegistrarOrigin = IdentityRegistrarOrigin; + type OffchainSignature = Signature; + type SigningPublicKey = ::Signer; + type UsernameAuthorityOrigin = EnsureRoot; + type PendingUsernameExpiration = PendingUsernameExpiration; + type MaxSuffixLength = MaxSuffixLength; + type MaxUsernameLength = MaxUsernameLength; + type WeightInfo = moonbeam_weights::pallet_identity::WeightInfo; +} + +pub struct TransactionConverter; + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } +} + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction( + &self, + transaction: pallet_ethereum::Transaction, + ) -> opaque::UncheckedExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will immediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +/// Maximum number of blocks simultaneously accepted by the Runtime, not yet included +/// into the relay chain. +const UNINCLUDED_SEGMENT_CAPACITY: u32 = 3; +/// How many parachain blocks are processed by the relay chain per parent. Limits the +/// number of blocks authored per slot. +const BLOCK_PROCESSING_VELOCITY: u32 = 1; + +type ConsensusHook = pallet_async_backing::consensus_hook::FixedVelocityConsensusHook< + Runtime, + BLOCK_PROCESSING_VELOCITY, + UNINCLUDED_SEGMENT_CAPACITY, +>; + +impl cumulus_pallet_parachain_system::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnSystemEvent = (); + type SelfParaId = ParachainInfo; + type ReservedDmpWeight = ReservedDmpWeight; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = EmergencyParaXcm; + type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = EmergencyParaXcm; + type ConsensusHook = crate::timestamp::ConsensusHookWrapperForRelayTimestamp; + type DmpQueue = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; +} + +impl parachain_info::Config for Runtime {} + +pub struct OnNewRound; +impl pallet_parachain_staking::OnNewRound for OnNewRound { + fn on_new_round(round_index: pallet_parachain_staking::RoundIndex) -> Weight { + MoonbeamOrbiters::on_new_round(round_index) + } +} +pub struct PayoutCollatorOrOrbiterReward; +impl pallet_parachain_staking::PayoutCollatorReward for PayoutCollatorOrOrbiterReward { + fn payout_collator_reward( + for_round: pallet_parachain_staking::RoundIndex, + collator_id: AccountId, + amount: Balance, + ) -> Weight { + let extra_weight = + if MoonbeamOrbiters::is_collator_pool_with_active_orbiter(for_round, collator_id) { + MoonbeamOrbiters::distribute_rewards(for_round, collator_id, amount) + } else { + ParachainStaking::mint_collator_reward(for_round, collator_id, amount) + }; + + ::DbWeight::get() + .reads(1) + .saturating_add(extra_weight) + } +} + +pub struct OnInactiveCollator; +impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollator { + fn on_inactive_collator( + collator_id: AccountId, + round: pallet_parachain_staking::RoundIndex, + ) -> Result> { + let extra_weight = if !MoonbeamOrbiters::is_collator_pool_with_active_orbiter( + round, + collator_id.clone(), + ) { + ParachainStaking::go_offline_inner(collator_id)?; + ::WeightInfo::go_offline( + pallet_parachain_staking::MAX_CANDIDATES, + ) + } else { + Weight::zero() + }; + + Ok(::DbWeight::get() + .reads(1) + .saturating_add(extra_weight)) + } +} + +type MonetaryGovernanceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +pub struct RelayChainSlotProvider; +impl Get for RelayChainSlotProvider { + fn get() -> Slot { + let slot_info = pallet_async_backing::pallet::Pallet::::slot_info(); + slot_info.unwrap_or_default().0 + } +} + +impl pallet_parachain_staking::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MonetaryGovernanceOrigin = MonetaryGovernanceOrigin; + /// Minimum round length is 2 minutes (10 * 12 second block times) + type MinBlocksPerRound = ConstU32<10>; + /// If a collator doesn't produce any block on this number of rounds, it is notified as inactive + type MaxOfflineRounds = ConstU32<2>; + /// Rounds before the collator leaving the candidates request can be executed + type LeaveCandidatesDelay = ConstU32<2>; + /// Rounds before the candidate bond increase/decrease can be executed + type CandidateBondLessDelay = ConstU32<2>; + /// Rounds before the delegator exit can be executed + type LeaveDelegatorsDelay = ConstU32<2>; + /// Rounds before the delegator revocation can be executed + type RevokeDelegationDelay = ConstU32<2>; + /// Rounds before the delegator bond increase/decrease can be executed + type DelegationBondLessDelay = ConstU32<2>; + /// Rounds before the reward is paid + type RewardPaymentDelay = ConstU32<2>; + /// Minimum collators selected per round, default at genesis and minimum forever after + type MinSelectedCandidates = ConstU32<8>; + /// Maximum top delegations per candidate + type MaxTopDelegationsPerCandidate = ConstU32<300>; + /// Maximum bottom delegations per candidate + type MaxBottomDelegationsPerCandidate = ConstU32<50>; + /// Maximum delegations per delegator + type MaxDelegationsPerDelegator = ConstU32<100>; + /// Minimum stake required to be reserved to be a candidate + type MinCandidateStk = ConstU128<{ 500 * currency::UNIT * currency::SUPPLY_FACTOR }>; + /// Minimum stake required to be reserved to be a delegator + type MinDelegation = ConstU128<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type BlockAuthor = AuthorInherent; + type OnCollatorPayout = (); + type PayoutCollatorReward = PayoutCollatorOrOrbiterReward; + type OnInactiveCollator = OnInactiveCollator; + type OnNewRound = OnNewRound; + type SlotProvider = RelayChainSlotProvider; + type WeightInfo = moonbeam_weights::pallet_parachain_staking::WeightInfo; + type MaxCandidates = ConstU32<200>; + type SlotDuration = ConstU64<6_000>; + type BlockTime = ConstU64<6_000>; +} + +impl pallet_author_inherent::Config for Runtime { + type SlotBeacon = RelaychainDataProvider; + type AccountLookup = MoonbeamOrbiters; + type CanAuthor = AuthorFilter; + type AuthorId = AccountId; + type WeightInfo = moonbeam_weights::pallet_author_inherent::WeightInfo; +} + +#[cfg(test)] +mod mock { + use super::*; + pub struct MockRandomness; + impl frame_support::traits::Randomness for MockRandomness { + fn random(subject: &[u8]) -> (H256, BlockNumber) { + (H256(sp_io::hashing::blake2_256(subject)), 0) + } + } +} + +impl pallet_author_slot_filter::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + #[cfg(not(test))] + type RandomnessSource = Randomness; + #[cfg(test)] + type RandomnessSource = mock::MockRandomness; + type PotentialAuthors = ParachainStaking; + type WeightInfo = moonbeam_weights::pallet_author_slot_filter::WeightInfo; +} + +impl pallet_async_backing::Config for Runtime { + type AllowMultipleBlocksPerSlot = ConstBool; + type GetAndVerifySlot = pallet_async_backing::RelaySlot; + type ExpectedBlockTime = ConstU64<6000>; +} + +parameter_types! { + pub const InitializationPayment: Perbill = Perbill::from_percent(30); + pub const RelaySignaturesThreshold: Perbill = Perbill::from_percent(100); + pub const SignatureNetworkIdentifier: &'static [u8] = b"moonbase-"; + +} + +impl pallet_crowdloan_rewards::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Initialized = ConstBool; + type InitializationPayment = InitializationPayment; + type MaxInitContributors = ConstU32<500>; + // TODO to be revisited + type MinimumReward = ConstU128<0>; + type RewardCurrency = Balances; + type RelayChainAccountId = [u8; 32]; + type RewardAddressAssociateOrigin = EnsureSigned; + type RewardAddressChangeOrigin = EnsureSigned; + type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; + type SignatureNetworkIdentifier = SignatureNetworkIdentifier; + type VestingBlockNumber = relay_chain::BlockNumber; + type VestingBlockProvider = RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_crowdloan_rewards::WeightInfo; +} + +// This is a simple session key manager. It should probably either work with, or be replaced +// entirely by pallet sessions +impl pallet_author_mapping::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DepositCurrency = Balances; + type DepositAmount = ConstU128<{ 100 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type Keys = session_keys_primitives::VrfId; + type WeightInfo = moonbeam_weights::pallet_author_mapping::WeightInfo; +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + Debug, + MaxEncodedLen, + TypeInfo, + Serialize, + Deserialize, +)] +pub enum ProxyType { + /// All calls can be proxied. This is the trivial/most permissive filter. + Any = 0, + /// Only extrinsics that do not transfer funds. + NonTransfer = 1, + /// Only extrinsics related to governance (democracy and collectives). + Governance = 2, + /// Only extrinsics related to staking. + Staking = 3, + /// Allow to veto an announced proxy call. + CancelProxy = 4, + /// Allow extrinsic related to Balances. + Balances = 5, + /// Allow extrinsic related to AuthorMapping. + AuthorMapping = 6, + /// Allow extrinsic related to IdentityJudgement. + IdentityJudgement = 7, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +fn is_governance_precompile(precompile_name: &precompiles::PrecompileName) -> bool { + matches!( + precompile_name, + PrecompileName::TreasuryCouncilInstance + | PrecompileName::ReferendaPrecompile + | PrecompileName::ConvictionVotingPrecompile + | PrecompileName::PreimagePrecompile + | PrecompileName::OpenTechCommitteeInstance, + ) +} + +// Be careful: Each time this filter is modified, the substrate filter must also be modified +// consistently. +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { + fn is_evm_proxy_call_allowed( + &self, + call: &pallet_evm_precompile_proxy::EvmSubCall, + recipient_has_code: bool, + gas: u64, + ) -> precompile_utils::EvmResult { + Ok(match self { + ProxyType::Any => true, + ProxyType::NonTransfer => { + call.value == U256::zero() + && match PrecompileName::from_address(call.to.0) { + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::IdentityPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } + } + ProxyType::Governance => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(ref precompile) if is_governance_precompile(precompile) + ) + } + ProxyType::Staking => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile + ) + ) + } + // The proxy precompile does not contain method cancel_proxy + ProxyType::CancelProxy => false, + ProxyType::Balances => { + // Allow only "simple" accounts as recipient (no code nor precompile). + // Note: Checking the presence of the code is not enough because some precompiles + // have no code. + !recipient_has_code + && !precompile_utils::precompile_set::is_precompile_or_fail::( + call.to.0, gas, + )? + } + ProxyType::AuthorMapping => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(PrecompileName::AuthorMappingPrecompile) + ) + } + // There is no identity precompile + ProxyType::IdentityJudgement => false, + }) + } +} + +// Be careful: Each time this filter is modified, the EVM filter must also be modified consistently. +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => { + matches!( + c, + RuntimeCall::System(..) + | RuntimeCall::ParachainSystem(..) + | RuntimeCall::Timestamp(..) + | RuntimeCall::ParachainStaking(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Identity(..) + | RuntimeCall::Utility(..) + | RuntimeCall::Proxy(..) | RuntimeCall::AuthorMapping(..) + | RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::claim { .. } + ) + ) + } + ProxyType::Governance => matches!( + c, + RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Utility(..) + ), + ProxyType::Staking => matches!( + c, + RuntimeCall::ParachainStaking(..) + | RuntimeCall::Utility(..) + | RuntimeCall::AuthorMapping(..) + | RuntimeCall::MoonbeamOrbiters(..) + ), + ProxyType::CancelProxy => matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => { + matches!(c, RuntimeCall::Balances(..) | RuntimeCall::Utility(..)) + } + ProxyType::AuthorMapping => matches!(c, RuntimeCall::AuthorMapping(..)), + ProxyType::IdentityJudgement => matches!( + c, + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) + ), + } + } + + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + // One storage item; key size 32, value size 8 + type ProxyDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 21 bytes (20 bytes AccountId + 1 byte sizeof(ProxyType)). + type ProxyDepositFactor = ConstU128<{ currency::deposit(0, 21) }>; + type MaxProxies = ConstU32<32>; + type WeightInfo = moonbeam_weights::pallet_proxy::WeightInfo; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 56 bytes: + // - 20 bytes AccountId + // - 32 bytes Hasher (Blake2256) + // - 4 bytes BlockNumber (u32) + type AnnouncementDepositFactor = ConstU128<{ currency::deposit(0, 56) }>; +} + +impl pallet_migrations::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + // TODO wire up our correct list of migrations here. Maybe this shouldn't be in + // `moonbeam_runtime_common`. + type MigrationsList = ( + moonbeam_runtime_common::migrations::CommonMigrations, + migrations::MoonbaseMigrations, + ); + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_moonbeam_lazy_migrations::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_moonbeam_lazy_migrations::WeightInfo; +} + +/// Maintenance mode Call filter +pub struct MaintenanceFilter; +impl Contains for MaintenanceFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(_) => false, + RuntimeCall::Balances(_) => false, + RuntimeCall::CrowdloanRewards(_) => false, + RuntimeCall::Ethereum(_) => false, + RuntimeCall::EVM(_) => false, + RuntimeCall::Identity(_) => false, + RuntimeCall::XTokens(_) => false, + RuntimeCall::ParachainStaking(_) => false, + RuntimeCall::MoonbeamOrbiters(_) => false, + RuntimeCall::PolkadotXcm(_) => false, + RuntimeCall::Treasury(_) => false, + RuntimeCall::XcmTransactor(_) => false, + RuntimeCall::EthereumXcm(_) => false, + _ => true, + } + } +} + +/// Normal Call Filter +/// We dont allow to create nor mint assets, this for now is disabled +/// We only allow transfers. For now creation of assets will go through +/// asset-manager, while minting/burning only happens through xcm messages +/// This can change in the future +pub struct NormalFilter; +impl Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(method) => match method { + pallet_assets::Call::transfer { .. } => true, + pallet_assets::Call::transfer_keep_alive { .. } => true, + pallet_assets::Call::approve_transfer { .. } => true, + pallet_assets::Call::transfer_approved { .. } => true, + pallet_assets::Call::cancel_approval { .. } => true, + pallet_assets::Call::destroy_accounts { .. } => true, + pallet_assets::Call::destroy_approvals { .. } => true, + pallet_assets::Call::finish_destroy { .. } => true, + _ => false, + }, + // We filter anonymous proxy as they make "reserve" inconsistent + // See: https://github.com/paritytech/substrate/blob/37cca710eed3dadd4ed5364c7686608f5175cce1/frame/proxy/src/lib.rs#L270 // editorconfig-checker-disable-line + RuntimeCall::Proxy(method) => match method { + pallet_proxy::Call::create_pure { .. } => false, + pallet_proxy::Call::kill_pure { .. } => false, + pallet_proxy::Call::proxy { real, .. } => { + !pallet_evm::AccountCodes::::contains_key(H160::from(*real)) + } + _ => true, + }, + // Filtering the EVM prevents possible re-entrancy from the precompiles which could + // lead to unexpected scenarios. + // See https://github.com/PureStake/sr-moonbeam/issues/30 + // Note: It is also assumed that EVM calls are only allowed through `Origin::Root` so + // this can be seen as an additional security + RuntimeCall::EVM(_) => false, + RuntimeCall::Treasury( + pallet_treasury::Call::spend { .. } + | pallet_treasury::Call::payout { .. } + | pallet_treasury::Call::check_status { .. } + | pallet_treasury::Call::void_spend { .. }, + ) => false, + _ => true, + } + } +} + +pub struct XcmExecutionManager; +impl moonkit_xcm_primitives::PauseXcmExecution for XcmExecutionManager { + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(RuntimeOrigin::root()) + } + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(RuntimeOrigin::root()) + } +} + +impl pallet_maintenance_mode::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type NormalCallFilter = NormalFilter; + type MaintenanceCallFilter = MaintenanceFilter; + type MaintenanceOrigin = + pallet_collective::EnsureProportionAtLeast; + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_proxy_genesis_companion::Config for Runtime { + type ProxyType = ProxyType; +} + +parameter_types! { + pub OrbiterReserveIdentifier: [u8; 4] = [b'o', b'r', b'b', b'i']; +} + +type AddCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type DelCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_moonbeam_orbiters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AccountLookup = AuthorMapping; + type AddCollatorOrigin = AddCollatorOrigin; + type Currency = Balances; + type DelCollatorOrigin = DelCollatorOrigin; + /// Maximum number of orbiters per collator + type MaxPoolSize = ConstU32<8>; + /// Maximum number of round to keep on storage + type MaxRoundArchive = ConstU32<4>; + type OrbiterReserveIdentifier = OrbiterReserveIdentifier; + type RotatePeriod = ConstU32<3>; + /// Round index type. + type RoundIndex = pallet_parachain_staking::RoundIndex; + type WeightInfo = moonbeam_weights::pallet_moonbeam_orbiters::WeightInfo; +} + +/// Only callable after `set_validation_data` is called which forms this proof the same way +fn relay_chain_state_proof() -> RelayChainStateProof { + let relay_storage_root = ParachainSystem::validation_data() + .expect("set in `set_validation_data`") + .relay_parent_storage_root; + let relay_chain_state = + ParachainSystem::relay_state_proof().expect("set in `set_validation_data`"); + RelayChainStateProof::new(ParachainInfo::get(), relay_storage_root, relay_chain_state) + .expect("Invalid relay chain state proof, already constructed in `set_validation_data`") +} + +pub struct BabeDataGetter; +impl pallet_randomness::GetBabeData> for BabeDataGetter { + // Tolerate panic here because only ever called in inherent (so can be omitted) + fn get_epoch_index() -> u64 { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + const BENCHMARKING_NEW_EPOCH: u64 = 10u64; + return BENCHMARKING_NEW_EPOCH; + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::EPOCH_INDEX) + .ok() + .flatten() + .expect("expected to be able to read epoch index from relay chain state proof") + } + fn get_epoch_randomness() -> Option { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + let benchmarking_babe_output = Hash::default(); + return Some(benchmarking_babe_output); + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::ONE_EPOCH_AGO_RANDOMNESS) + .ok() + .flatten() + } +} + +impl pallet_randomness::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddressMapping = sp_runtime::traits::ConvertInto; + type Currency = Balances; + type BabeDataGetter = BabeDataGetter; + type VrfKeyLookup = AuthorMapping; + type Deposit = ConstU128<{ 1 * currency::UNIT * currency::SUPPLY_FACTOR }>; + type MaxRandomWords = ConstU8<100>; + type MinBlockDelay = ConstU32<2>; + type MaxBlockDelay = ConstU32<2_000>; + type BlockExpirationDelay = ConstU32<10_000>; + type EpochExpirationDelay = ConstU64<10_000>; + type WeightInfo = moonbeam_weights::pallet_randomness::WeightInfo; +} + +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +parameter_types! { + // One storage item; key size is 32 + 20; value is size 4+4+16+20 bytes = 44 bytes. + pub const DepositBase: Balance = currency::deposit(1, 96); + // Additional storage item size of 20 bytes. + pub const DepositFactor: Balance = currency::deposit(0, 20); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type WeightInfo = moonbeam_weights::pallet_multisig::WeightInfo; +} + +impl pallet_relay_storage_roots::Config for Runtime { + type MaxStorageRoots = ConstU32<30>; + type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_relay_storage_roots::WeightInfo; +} + +impl pallet_precompile_benchmarks::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo; +} + +construct_runtime! { + pub enum Runtime + { + System: frame_system::{Pallet, Call, Storage, Config, Event} = 0, + Utility: pallet_utility::{Pallet, Call, Event} = 1, + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 2, + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 3, + Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 4, + // Previously 5: pallet_randomness_collective_flip + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 6, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Config, Event} = 7, + ParachainInfo: parachain_info::{Pallet, Storage, Config} = 8, + EthereumChainId: pallet_evm_chain_id::{Pallet, Storage, Config} = 9, + EVM: pallet_evm::{Pallet, Config, Call, Storage, Event} = 10, + Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Origin, Config} = 11, + ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event, Config} = 12, + Scheduler: pallet_scheduler::{Pallet, Storage, Event, Call} = 13, + // Previously 14: pallet_democracy::{Pallet, Storage, Config, Event, Call} = 14, + // Previously 15: CouncilCollective: pallet_collective:: + // Previously 16: TechCommitteeCollective: pallet_collective:: + Treasury: pallet_treasury::{Pallet, Storage, Config, Event, Call} = 17, + AuthorInherent: pallet_author_inherent::{Pallet, Call, Storage, Inherent} = 18, + AuthorFilter: pallet_author_slot_filter::{Pallet, Call, Storage, Event, Config} = 19, + CrowdloanRewards: pallet_crowdloan_rewards::{Pallet, Call, Config, Storage, Event} = 20, + AuthorMapping: pallet_author_mapping::{Pallet, Call, Config, Storage, Event} = 21, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 22, + MaintenanceMode: pallet_maintenance_mode::{Pallet, Call, Config, Storage, Event} = 23, + Identity: pallet_identity::{Pallet, Call, Storage, Event} = 24, + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event} = 25, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 26, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 27, + PolkadotXcm: pallet_xcm::{Pallet, Call, Storage, Event, Origin, Config} = 28, + Assets: pallet_assets::{Pallet, Call, Storage, Event} = 29, + XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 30, + AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 31, + Migrations: pallet_migrations::{Pallet, Storage, Config, Event} = 32, + XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Config, Storage, Event} = 33, + ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 34, + // Previously 35: BaseFee + // Previously 36: pallet_assets:: + MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event, Config} = 37, + EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin} = 38, + Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 39, + TreasuryCouncilCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 40, + ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event} = 41, + Referenda: pallet_referenda::{Pallet, Call, Storage, Event} = 42, + Origins: governance::custom_origins::{Origin} = 43, + Preimage: pallet_preimage::{Pallet, Call, Storage, Event, HoldReason} = 44, + Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event} = 45, + OpenTechCommitteeCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 46, + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 47, + Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 48, + Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 49, + AsyncBacking: pallet_async_backing::{Pallet, Storage} = 50, + MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 51, + RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 52, + 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, + } +} + +/// Block type as expected by this runtime. +pub type Block = generic::Block; +/// A Block signed with a Justification +pub type SignedBlock = generic::SignedBlock; +/// BlockId type as expected by this runtime. +pub type BlockId = generic::BlockId; + +/// The SignedExtension to the basic transaction logic. +pub type SignedExtra = ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, +); +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + fp_self_contained::UncheckedExtrinsic; +/// Extrinsic type that has already been checked. +pub type CheckedExtrinsic = + fp_self_contained::CheckedExtrinsic; +/// Executive: handles dispatch to the various pallets. +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllPalletsWithSystem, +>; + +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +mod benches { + frame_support::parameter_types! { + pub const MaxBalance: crate::Balance = crate::Balance::max_value(); + } + + frame_benchmarking::define_benchmarks!( + [pallet_utility, Utility] + [pallet_timestamp, Timestamp] + [pallet_balances, Balances] + [pallet_sudo, Sudo] + [pallet_evm, EVM] + [pallet_assets, Assets] + [pallet_parachain_staking, ParachainStaking] + [pallet_scheduler, Scheduler] + [pallet_treasury, Treasury] + [pallet_author_inherent, AuthorInherent] + [pallet_author_slot_filter, AuthorFilter] + [pallet_crowdloan_rewards, CrowdloanRewards] + [pallet_author_mapping, AuthorMapping] + [pallet_proxy, Proxy] + [pallet_identity, Identity] + [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] + [pallet_asset_manager, AssetManager] + [pallet_xcm_transactor, XcmTransactor] + [pallet_moonbeam_orbiters, MoonbeamOrbiters] + [pallet_randomness, Randomness] + [pallet_conviction_voting, ConvictionVoting] + [pallet_referenda, Referenda] + [pallet_preimage, Preimage] + [pallet_whitelist, Whitelist] + [pallet_multisig, Multisig] + [pallet_relay_storage_roots, RelayStorageRoots] + [pallet_precompile_benchmarks, PrecompileBenchmarks] + [pallet_moonbeam_lazy_migrations, MoonbeamLazyMigrations] + ); +} + +// All of our runtimes share most of their Runtime API implementations. +// We use a macro to implement this common part and add runtime-specific additional implementations. +// This macro expands to : +// ``` +// impl_runtime_apis! { +// // All impl blocks shared between all runtimes. +// +// // Specific impls provided to the `impl_runtime_apis_plus_common!` macro. +// } +// ``` +moonbeam_runtime_common::impl_runtime_apis_plus_common! { + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + xt: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + // Filtered calls should not enter the tx pool as they'll fail if inserted. + // If this call is not allowed, we return early. + if !::BaseCallFilter::contains(&xt.0.function) { + return InvalidTransaction::Call.into(); + } + + // This runtime uses Substrate's pallet transaction payment. This + // makes the chain feel like a standard Substrate chain when submitting + // frame transactions and using Substrate ecosystem tools. It has the downside that + // transaction are not prioritized by gas_price. The following code reprioritizes + // transactions to overcome this. + // + // A more elegant, ethereum-first solution is + // a pallet that replaces pallet transaction payment, and allows users + // to directly specify a gas price rather than computing an effective one. + // #HopefullySomeday + + // First we pass the transactions to the standard FRAME executive. This calculates all the + // necessary tags, longevity and other properties that we will leave unchanged. + // This also assigns some priority that we don't care about and will overwrite next. + let mut intermediate_valid = Executive::validate_transaction(source, xt.clone(), block_hash)?; + + let dispatch_info = xt.get_dispatch_info(); + + // If this is a pallet ethereum transaction, then its priority is already set + // according to effective priority fee from pallet ethereum. If it is any other kind of + // transaction, we modify its priority. The goal is to arrive at a similar metric used + // by pallet ethereum, which means we derive a fee-per-gas from the txn's tip and + // weight. + Ok(match &xt.0.function { + RuntimeCall::Ethereum(transact { .. }) => intermediate_valid, + _ if dispatch_info.class != DispatchClass::Normal => intermediate_valid, + _ => { + let tip = match xt.0.signature { + None => 0, + Some((_, _, ref signed_extra)) => { + // Yuck, this depends on the index of charge transaction in Signed Extra + let charge_transaction = &signed_extra.7; + charge_transaction.tip() + } + }; + + let effective_gas = + ::GasWeightMapping::weight_to_gas( + dispatch_info.weight + ); + let tip_per_gas = if effective_gas > 0 { + tip.saturating_div(effective_gas as u128) + } else { + 0 + }; + + // Overwrite the original prioritization with this ethereum one + intermediate_valid.priority = tip_per_gas as u64; + intermediate_valid + } + }) + } + } + + impl async_backing_primitives::UnincludedSegmentApi for Runtime { + fn can_build_upon( + included_hash: ::Hash, + slot: async_backing_primitives::Slot, + ) -> bool { + ConsensusHook::can_build_upon(included_hash, slot) + } + } +} + +struct CheckInherents; + +// Parity has decided to depreciate this trait, but does not offer a satisfactory replacement, +// see issue: https://github.com/paritytech/polkadot-sdk/issues/2841 +#[allow(deprecated)] +impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { + fn check_inherents( + block: &Block, + relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, + ) -> sp_inherents::CheckInherentsResult { + let relay_chain_slot = relay_state_proof + .read_slot() + .expect("Could not read the relay chain slot from the proof"); + let inherent_data = + cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( + relay_chain_slot, + sp_std::time::Duration::from_secs(6), + ) + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); + inherent_data.check_extrinsics(block) + } +} + +// Nimbus's Executive wrapper allows relay validators to verify the seal digest +cumulus_pallet_parachain_system::register_validate_block!( + Runtime = Runtime, + BlockExecutor = pallet_author_inherent::BlockExecutor::, + CheckInherents = CheckInherents, +); + +moonbeam_runtime_common::impl_self_contained_call!(); + +// Shorthand for a Get field of a pallet Config. +#[macro_export] +macro_rules! get { + ($pallet:ident, $name:ident, $type:ty) => { + <<$crate::Runtime as $pallet::Config>::$name as $crate::Get<$type>>::get() + }; +} + +#[cfg(test)] +mod tests { + use super::{currency::*, *}; + + #[test] + // Helps us to identify a Pallet Call in case it exceeds the 1kb limit. + // Hint: this should be a rare case. If that happens, one or more of the dispatchable arguments + // need to be Boxed. + fn call_max_size() { + const CALL_ALIGN: u32 = 1024; + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + } + + #[test] + fn currency_constants_are_correct() { + assert_eq!(SUPPLY_FACTOR, 1); + + // txn fees + assert_eq!(TRANSACTION_BYTE_FEE, Balance::from(1 * GIGAWEI)); + assert_eq!( + get!(pallet_transaction_payment, OperationalFeeMultiplier, u8), + 5_u8 + ); + assert_eq!(STORAGE_BYTE_FEE, Balance::from(100 * MICROUNIT)); + + // treasury minimums + assert_eq!( + get!(pallet_treasury, ProposalBondMinimum, u128), + Balance::from(1 * UNIT) + ); + + // pallet_identity deposits + assert_eq!( + get!(pallet_identity, BasicDeposit, u128), + Balance::from(1 * UNIT + 25800 * MICROUNIT) + ); + assert_eq!( + get!(pallet_identity, ByteDeposit, u128), + Balance::from(100 * MICROUNIT) + ); + assert_eq!( + get!(pallet_identity, SubAccountDeposit, u128), + Balance::from(1 * UNIT + 5300 * MICROUNIT) + ); + + // staking minimums + assert_eq!( + get!(pallet_parachain_staking, MinCandidateStk, u128), + Balance::from(500 * UNIT) + ); + assert_eq!( + get!(pallet_parachain_staking, MinDelegation, u128), + Balance::from(1 * UNIT) + ); + + // crowdloan min reward + assert_eq!( + get!(pallet_crowdloan_rewards, MinimumReward, u128), + Balance::from(0u128) + ); + + // deposit for AuthorMapping + assert_eq!( + get!(pallet_author_mapping, DepositAmount, u128), + Balance::from(100 * UNIT) + ); + + // proxy deposits + assert_eq!( + get!(pallet_proxy, ProxyDepositBase, u128), + Balance::from(1 * UNIT + 800 * MICROUNIT) + ); + assert_eq!( + get!(pallet_proxy, ProxyDepositFactor, u128), + Balance::from(2100 * MICROUNIT) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositBase, u128), + Balance::from(1 * UNIT + 800 * MICROUNIT) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositFactor, u128), + Balance::from(5600 * MICROUNIT) + ); + } + + #[test] + fn max_offline_rounds_lower_or_eq_than_reward_payment_delay() { + assert!( + get!(pallet_parachain_staking, MaxOfflineRounds, u32) + <= get!(pallet_parachain_staking, RewardPaymentDelay, u32) + ); + } + + #[test] + // Required migration is + // pallet_parachain_staking::migrations::IncreaseMaxTopDelegationsPerCandidate + // Purpose of this test is to remind of required migration if constant is ever changed + fn updating_maximum_delegators_per_candidate_requires_configuring_required_migration() { + assert_eq!( + get!(pallet_parachain_staking, MaxTopDelegationsPerCandidate, u32), + 300 + ); + assert_eq!( + get!( + pallet_parachain_staking, + MaxBottomDelegationsPerCandidate, + u32 + ), + 50 + ); + } + + #[test] + fn test_proxy_type_can_be_decoded_from_valid_values() { + let test_cases = vec![ + // (input, expected) + (0u8, ProxyType::Any), + (1, ProxyType::NonTransfer), + (2, ProxyType::Governance), + (3, ProxyType::Staking), + (4, ProxyType::CancelProxy), + (5, ProxyType::Balances), + (6, ProxyType::AuthorMapping), + (7, ProxyType::IdentityJudgement), + ]; + + for (input, expected) in test_cases { + let actual = ProxyType::decode(&mut input.to_le_bytes().as_slice()); + assert_eq!( + Ok(expected), + actual, + "failed decoding ProxyType for value '{}'", + input + ); + } + } + + #[test] + fn configured_base_extrinsic_weight_is_evm_compatible() { + let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000; + let base_extrinsic = ::BlockWeights::get() + .get(frame_support::dispatch::DispatchClass::Normal) + .base_extrinsic; + assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time()); + } + + #[test] + fn test_storage_growth_ratio_is_correct() { + let expected_storage_growth_ratio = BlockGasLimit::get() + .low_u64() + .saturating_div(BLOCK_STORAGE_LIMIT); + let actual_storage_growth_ratio = + ::GasLimitStorageGrowthRatio::get(); + assert_eq!( + expected_storage_growth_ratio, actual_storage_growth_ratio, + "Storage growth ratio is not correct" + ); + } +} diff --git a/tracing/2902/runtime/moonbase/src/migrations.rs b/tracing/2902/runtime/moonbase/src/migrations.rs new file mode 100644 index 00000000..693f813e --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/migrations.rs @@ -0,0 +1,43 @@ +// Copyright 2024 Moonbeam Foundation 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 . + +//! # Moonbase specific Migrations + +use crate::Runtime; +use frame_support::{traits::OnRuntimeUpgrade, weights::Weight}; +use pallet_migrations::{GetMigrations, Migration}; +use pallet_parachain_staking::migrations::MultiplyRoundLenBy2; +use sp_std::{prelude::*, vec}; + +pub struct MoonbaseMigrations; + +impl GetMigrations for MoonbaseMigrations { + fn get_migrations() -> Vec> { + vec![Box::new(PalletStakingMultiplyRoundLenBy2)] + } +} + +// This migration should only be applied to runtimes with async backing enabled +pub struct PalletStakingMultiplyRoundLenBy2; +impl Migration for PalletStakingMultiplyRoundLenBy2 { + fn friendly_name(&self) -> &str { + "MM_MultiplyRoundLenBy2" + } + + fn migrate(&self, _available_weight: Weight) -> Weight { + MultiplyRoundLenBy2::::on_runtime_upgrade() + } +} diff --git a/tracing/2902/runtime/moonbase/src/precompiles.rs b/tracing/2902/runtime/moonbase/src/precompiles.rs new file mode 100644 index 00000000..6ca3a0ae --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/precompiles.rs @@ -0,0 +1,312 @@ +// 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::{ + asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance, + TreasuryCouncilInstance, +}; +use crate::{AssetId, H160}; +use frame_support::parameter_types; +use pallet_evm_precompile_author_mapping::AuthorMappingPrecompile; +use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata}; +use pallet_evm_precompile_batch::BatchPrecompile; +use pallet_evm_precompile_blake2::Blake2F; +use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; +use pallet_evm_precompile_call_permit::CallPermitPrecompile; +use pallet_evm_precompile_collective::CollectivePrecompile; +use pallet_evm_precompile_conviction_voting::ConvictionVotingPrecompile; +use pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompile; +use pallet_evm_precompile_gmp::GmpPrecompile; +use pallet_evm_precompile_identity::IdentityPrecompile; +use pallet_evm_precompile_modexp::Modexp; +use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile; +use pallet_evm_precompile_preimage::PreimagePrecompile; +use pallet_evm_precompile_proxy::{OnlyIsProxyAndProxy, ProxyPrecompile}; +use pallet_evm_precompile_randomness::RandomnessPrecompile; +use pallet_evm_precompile_referenda::ReferendaPrecompile; +use pallet_evm_precompile_registry::PrecompileRegistry; +use pallet_evm_precompile_relay_encoder::RelayEncoderPrecompile; +use pallet_evm_precompile_relay_verifier::RelayDataVerifierPrecompile; +use pallet_evm_precompile_sha3fips::Sha3FIPS256; +use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_storage_cleaner::StorageCleanerPrecompile; +use pallet_evm_precompile_xcm_transactor::{ + v1::XcmTransactorPrecompileV1, v2::XcmTransactorPrecompileV2, v3::XcmTransactorPrecompileV3, +}; +use pallet_evm_precompile_xcm_utils::{AllExceptXcmExecute, XcmUtilsPrecompile}; +use pallet_evm_precompile_xtokens::XtokensPrecompile; +use pallet_evm_precompileset_assets_erc20::{AccountIdAssetIdConversion, Erc20AssetsPrecompileSet}; +use precompile_utils::precompile_set::*; +use sp_std::prelude::*; + +/// ERC20 metadata for the native token. +pub struct NativeErc20Metadata; + +impl Erc20Metadata for NativeErc20Metadata { + /// Returns the name of the token. + fn name() -> &'static str { + "DEV token" + } + + /// Returns the symbol of the token. + fn symbol() -> &'static str { + "DEV" + } + + /// Returns the decimals places of the token. + fn decimals() -> u8 { + 18 + } + + /// Must return `true` only if it represents the main native currency of + /// the network. It must be the currency used in `pallet_evm`. + fn is_native_currency() -> bool { + true + } +} + +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as foreign +pub const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as local +pub const LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8, 255u8, 255u8, 254u8]; + +parameter_types! { + pub ForeignAssetPrefix: &'static [u8] = FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX; + pub LocalAssetPrefix: &'static [u8] = LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX; +} + +type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile); + +#[precompile_utils::precompile_name_from_address] +type MoonbasePrecompilesAt = ( + // Ethereum precompiles: + // We allow DELEGATECALL to stay compliant with Ethereum behavior. + PrecompileAt, ECRecover, EthereumPrecompilesChecks>, + PrecompileAt, Sha256, EthereumPrecompilesChecks>, + PrecompileAt, Ripemd160, EthereumPrecompilesChecks>, + PrecompileAt, Identity, EthereumPrecompilesChecks>, + PrecompileAt, Modexp, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Add, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Mul, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Pairing, EthereumPrecompilesChecks>, + PrecompileAt, Blake2F, EthereumPrecompilesChecks>, + // Non-Moonbeam specific nor Ethereum precompiles : + PrecompileAt, Sha3FIPS256, (CallableByContract, CallableByPrecompile)>, + RemovedPrecompileAt>, // Dispatch + PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, StorageCleanerPrecompile, CallableByPrecompile>, + // Moonbeam specific precompiles: + PrecompileAt< + AddressU64<2048>, + ParachainStakingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2049>, + CrowdloanRewardsPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2050>, + Erc20BalancesPrecompile, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompileAt>, // DemocracyPrecompile + PrecompileAt< + AddressU64<2052>, + XtokensPrecompile, + ( + SubcallWithMaxNesting<1>, + CallableByContract, + CallableByPrecompile, + ), + >, + PrecompileAt< + AddressU64<2053>, + RelayEncoderPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2054>, + XcmTransactorPrecompileV1, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2055>, + AuthorMappingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2056>, + BatchPrecompile, + ( + SubcallWithMaxNesting<2>, + // Batch is the only precompile allowed to call Batch. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2057>, + RandomnessPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2058>, + CallPermitPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2059>, + ProxyPrecompile, + ( + CallableByContract>, + SubcallWithMaxNesting<0>, + // Batch is the only precompile allowed to call Proxy. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2060>, + XcmUtilsPrecompile, + CallableByContract>, + >, + PrecompileAt< + AddressU64<2061>, + XcmTransactorPrecompileV2, + (CallableByContract, CallableByPrecompile), + >, + // CouncilCollective precompile + RemovedPrecompileAt>, + // TechCommitteeCollective precompile + RemovedPrecompileAt>, + PrecompileAt< + AddressU64<2064>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2065>, + ReferendaPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2066>, + ConvictionVotingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2067>, + PreimagePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2068>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2069>, + PrecompileRegistry, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt, GmpPrecompile, SubcallWithMaxNesting<0>>, + PrecompileAt< + AddressU64<2071>, + XcmTransactorPrecompileV3, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2072>, + IdentityPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2073>, + RelayDataVerifierPrecompile, + (CallableByContract, CallableByPrecompile), + >, +); + +pub struct DisabledLocalAssets(sp_std::marker::PhantomData); + +impl sp_core::Get> for DisabledLocalAssets +where + Runtime: frame_system::Config, + Runtime::AccountId: Into, + Runtime: AccountIdAssetIdConversion, +{ + fn get() -> Vec { + vec![ + // https://moonbase.subscan.io/extrinsic/5245322-6?event=5245322-22 + 182085191673801920759598290391359780050u128, + // https://moonbase.subscan.io/extrinsic/3244752-4?event=3244752-9 + 282223684955665977914983262584256755878u128, + // https://moonbase.subscan.io/extrinsic/3158280-4?event=3158280-9 + 235962050501460763853961856666389569138u128, + // https://moonbase.subscan.io/block/3045900?tab=event&&event=3045900-4 + 45350527686064227409532032051821627910u128, + // https://moonbase.subscan.io/extrinsic/3024306-4?event=3024306-9 + 199439015574556113723291251263369885338u128, + // https://moonbase.subscan.io/extrinsic/2921640-4?event=2921640-9 + 236426850287284823323011839750645103615u128, + // https://moonbase.subscan.io/extrinsic/2748867-4?event=2748867-9 + 14626673838203901761839010613793775004u128, + // https://moonbase.subscan.io/extrinsic/2709788-4?event=2709788-9 + 95328064580428769161981851380106820590u128, + // https://moonbase.subscan.io/extrinsic/2670844-4?event=2670844-9 + 339028723712074529056817184013808486301u128, + // https://moonbase.subscan.io/extrinsic/2555083-4?event=2555083-9 + 100481493116602214283160747599845770751u128, + // https://moonbase.subscan.io/extrinsic/2473880-3?event=2473880-8 + 319515966007349957795820176952936446433u128, + // https://moonbase.subscan.io/extrinsic/2346438-3?event=2346438-6 + 337110116006454532607322340792629567158u128, + // https://moonbase.subscan.io/extrinsic/2239102-3?event=2239102-6 + 255225902946708983196362678630947296516u128, + // https://moonbase.subscan.io/extrinsic/2142964-4?event=2142964-12 + 3356866138193769031598374869367363824u128, + // https://moonbase.subscan.io/extrinsic/1967538-6?event=1967538-28 + 144992676743556815849525085098140609495u128, + ] + .iter() + .map(|id| Runtime::asset_id_to_account(LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX, *id).into()) + .collect() + } +} + +/// The PrecompileSet installed in the Moonbase runtime. +/// We include the nine Istanbul precompiles +/// (https://github.com/ethereum/go-ethereum/blob/3c46f557/core/vm/contracts.go#L69) +/// The following distribution has been decided for the precompiles +/// 0-1023: Ethereum Mainnet Precompiles +/// 1024-2047 Precompiles that are not in Ethereum Mainnet but are neither Moonbeam specific +/// 2048-4095 Moonbeam specific precompiles +pub type MoonbasePrecompiles = PrecompileSetBuilder< + R, + ( + // Skip precompiles if out of range. + PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<4095>), MoonbasePrecompilesAt>, + // Prefixed precompile sets (XC20) + PrecompileSetStartingWith< + ForeignAssetPrefix, + Erc20AssetsPrecompileSet, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompilesAt>, + ), +>; diff --git a/tracing/2902/runtime/moonbase/src/timestamp.rs b/tracing/2902/runtime/moonbase/src/timestamp.rs new file mode 100644 index 00000000..4df4eca6 --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/timestamp.rs @@ -0,0 +1,87 @@ +// 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 . + +//! A way to get a relyable timestamp + +use crate::Runtime; +use cumulus_pallet_parachain_system::{ + consensus_hook::UnincludedSegmentCapacity, + relay_state_snapshot::{self, ReadEntryErr}, + ConsensusHook, RelayChainStateProof, +}; +use frame_support::pallet_prelude::*; +use frame_support::storage::types::{StorageValue, ValueQuery}; +use frame_support::traits::{StorageInstance, Time}; +pub use moonbeam_core_primitives::well_known_relay_keys; + +/// Get the relay timestamp. +/// Noe that the relay timestamp is populated at the parachain system inherent. +/// If you fetch the timestamp before, you will get the timestamp of the parent block. +pub struct RelayTimestamp; +impl Time for RelayTimestamp { + type Moment = u64; + + fn now() -> Self::Moment { + RelayTimestampNow::get() + } +} + +/// A wrapper around the consensus hook to get the relay timlestmap from the relay storage proof +pub struct ConsensusHookWrapperForRelayTimestamp(core::marker::PhantomData); +impl ConsensusHook for ConsensusHookWrapperForRelayTimestamp { + fn on_state_proof(state_proof: &RelayChainStateProof) -> (Weight, UnincludedSegmentCapacity) { + let relay_timestamp: u64 = + match state_proof.read_entry(well_known_relay_keys::TIMESTAMP_NOW, None) { + Ok(relay_timestamp) => relay_timestamp, + // Log the read entry error + Err(relay_state_snapshot::Error::ReadEntry(ReadEntryErr::Proof)) => { + log::error!("Invalid relay storage proof: fail to read key TIMESTAMP_NOW"); + panic!("Invalid realy storage proof: fail to read key TIMESTAMP_NOW"); + } + Err(relay_state_snapshot::Error::ReadEntry(ReadEntryErr::Decode)) => { + log::error!("Corrupted relay storage: fail to decode value TIMESTAMP_NOW"); + panic!("Corrupted relay storage: fail to decode value TIMESTAMP_NOW"); + } + Err(relay_state_snapshot::Error::ReadEntry(ReadEntryErr::Absent)) => { + log::error!("Corrupted relay storage: value TIMESTAMP_NOW is absent!"); + panic!("Corrupted relay storage: value TIMESTAMP_NOW is absent!"); + } + // Can't return another kind of error, the blokc is invalid anyway, so we should panic + _ => unreachable!(), + }; + + let wrapper_weight = ::DbWeight::get().writes(1); + + RelayTimestampNow::put(relay_timestamp); + + let (weight, capacity) = Inner::on_state_proof(state_proof); + + (weight.saturating_add(wrapper_weight), capacity) + } +} + +// Prefix for storage value RelayTimestampNow +struct RelayTimestampNowPrefix; +impl StorageInstance for RelayTimestampNowPrefix { + const STORAGE_PREFIX: &'static str = "RelayTimestampNow"; + + fn pallet_prefix() -> &'static str { + "runtime" + } +} + +// Storage type used to store the last current relay timestamp +type RelayTimestampNow = StorageValue; diff --git a/tracing/2902/runtime/moonbase/src/xcm_config.rs b/tracing/2902/runtime/moonbase/src/xcm_config.rs new file mode 100644 index 00000000..17c2ccc6 --- /dev/null +++ b/tracing/2902/runtime/moonbase/src/xcm_config.rs @@ -0,0 +1,732 @@ +// 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 . + +//! XCM configuration for Moonbase. +//! + +use super::{ + governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees, + EmergencyParaXcm, Erc20XcmBridge, MaintenanceMode, MessageQueue, ParachainInfo, + ParachainSystem, Perbill, PolkadotXcm, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, + RuntimeOrigin, Treasury, XcmpQueue, +}; +use crate::OpenTechCommitteeInstance; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; +use sp_runtime::{ + traits::{Hash as THash, MaybeEquivalence, PostDispatchInfoOf}, + DispatchErrorWithPostInfo, +}; + +use frame_support::{ + parameter_types, + traits::{EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin}, +}; + +use frame_system::{EnsureRoot, RawOrigin}; +use sp_core::{ConstU32, H160, H256}; +use sp_weights::Weight; +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, DescribeAllTerminal, DescribeFamily, + EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription, + NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin, +}; + +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; + +use xcm::latest::prelude::{ + Asset, GlobalConsensus, InteriorLocation, Junction, Location, NetworkId, PalletInstance, + Parachain, +}; +use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; + +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use orml_xcm_support::MultiNativeAsset; +use xcm_primitives::{ + AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, + FirstAssetTrader, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact, +}; + +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; + +use sp_core::Get; +use sp_std::{ + convert::{From, Into, TryFrom}, + prelude::*, +}; + +use orml_traits::parameter_type_with_key; + +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; + +parameter_types! { + // The network Id of the relay + pub const RelayNetwork: NetworkId = NetworkId::Westend; + // The relay chain Origin type + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // The universal location within the global consensus system + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); + + + // Self Reserve location, defines the multilocation identifiying the self-reserve currency + // This is used to match it also against our Balances pallet when we receive such + // a Location: (Self Balances pallet index) + // We use the RELATIVE multilocation + pub SelfReserve: Location = Location { + parents: 0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // If we receive a Location of type AccountKey20, just generate a native account + AccountKey20Aliases, + // Generate remote accounts according to polkadot standards + HashedDescription>, +); + +/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`. +pub struct LocationToH160; +impl ConvertLocation for LocationToH160 { + fn convert_location(location: &Location) -> Option { + >::convert_location(location) + .map(Into::into) + } +} + +// The non-reserve fungible transactor type +// It will use pallet-assets, and the Id will be matched against AsAssetType +// This is intended to match FOREIGN ASSETS +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + super::Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId20 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +/// The transactor for our own chain currency. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + xcm_builder::IsConcrete, + // We can convert the MultiLocations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// We use all transactors +// These correspond to +// SelfReserve asset, both pre and post 0.9.16 +// Foreign assets +// We can remove the Old reanchor once +// we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 +pub type AssetTransactors = ( + LocalAssetTransactor, + ForeignFungiblesTransactor, + Erc20XcmBridge, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + // Xcm Origins defined by a Multilocation of type AccountKey20 can be converted to a 20 byte- + // account local origin + SignedAccountKey20AsNative, +); + +parameter_types! { + /// Maximum number of instructions in a single XCM fragment. A sanity check against + /// weight caculations getting too crazy. + pub MaxInstructions: u32 = 100; +} + +/// Xcm Weigher shared between multiple Xcm-related configs. +pub type XcmWeigher = WeightInfoBounds< + moonbeam_xcm_benchmarks::weights::XcmWeight, + RuntimeCall, + MaxInstructions, +>; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +/// We do not burn anything because we want to mimic exactly what +/// the sovereign account has +pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount< + super::Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +// Our implementation of the Moonbeam Call +// Attachs the right origin in case the call is made to pallet-ethereum-xcm +#[cfg(not(feature = "evm-tracing"))] +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); +#[cfg(feature = "evm-tracing")] +moonbeam_runtime_common::impl_moonbeam_xcm_call_tracing!(); + +moonbeam_runtime_common::impl_evm_runner_precompile_or_eth_xcm!(); + +pub struct SafeCallFilter; +impl frame_support::traits::Contains for SafeCallFilter { + fn contains(_call: &RuntimeCall) -> bool { + // TODO review + // This needs to be addressed at EVM level + true + } +} + +parameter_types! { + pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS; +} + +pub struct XcmExecutorConfig; +impl xcm_executor::Config for XcmExecutorConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + // Filter to the reserve withdraw operations + // Whenever the reserve matches the relative or absolute value + // of our chain, we always return the relative reserve + type IsReserve = MultiNativeAsset>; + type IsTeleporter = (); // No teleport + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = XcmWeigher; + // We use two traders + // When we receive the relative representation of the self-reserve asset, + // we use UsingComponents and the local way of handling fees + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + UsingComponents< + ::WeightToFee, + SelfReserve, + AccountId, + Balances, + DealWithFees, + >, + FirstAssetTrader, + ); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = pallet_erc20_xcm_bridge::AssetTrapWrapper; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type PalletInstancesInfo = crate::AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = SafeCallFilter; + type Aliasers = Nothing; + type TransactionalProcessor = xcm_builder::FrameTransactionalProcessor; +} + +// Converts a Signed Local Origin into a Location +pub type LocalOriginToLocation = SignedToAccountId20; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = ( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +); + +type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper< + XcmExecutorConfig, + xcm_executor::XcmExecutor, +>; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Everything; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + // TODO pallet-xcm weights + type WeightInfo = moonbeam_weights::pallet_xcm::WeightInfo; + type AdminOrigin = EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ChannelInfo = ParachainSystem; + type VersionWrapper = PolkadotXcm; + type XcmpQueue = TransformOrigin; + type MaxInboundSuspended = sp_core::ConstU32<1_000>; + type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type WeightInfo = moonbeam_weights::cumulus_pallet_xcmp_queue::WeightInfo; + type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery< + cumulus_primitives_core::ParaId, + >; +} + +parameter_types! { + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +// TODO: This pallet can be removed after the lazy migration is done and +// event `Completed` is emitted. +// https://github.com/paritytech/polkadot-sdk/pull/1246 +impl cumulus_pallet_dmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DmpSink = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; +} + +parameter_types! { + /// The amount of weight (if any) which should be provided to the message queue for + /// servicing enqueued items. + /// + /// This may be legitimately `None` in the case that you will call + /// `ServiceQueues::service_queues` manually. + pub MessageQueueServiceWeight: Weight = + Perbill::from_percent(25) * RuntimeBlockWeights::get().max_block; + /// The maximum number of stale pages (i.e. of overweight messages) allowed before culling + /// can happen. Once there are more stale pages than this, then historical pages may be + /// dropped, even if they contain unprocessed overweight messages. + pub const MessageQueueMaxStale: u32 = 8; + /// The size of the page; this implies the maximum message size which can be sent. + /// + /// A good value depends on the expected message sizes, their weights, the weight that is + /// available for processing them and the maximal needed message size. The maximal message + /// size is slightly lower than this as defined by [`MaxMessageLenOf`]. + pub const MessageQueueHeapSize: u32 = 128 * 1048; +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + #[cfg(feature = "runtime-benchmarks")] + type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor< + cumulus_primitives_core::AggregateMessageOrigin, + >; + #[cfg(not(feature = "runtime-benchmarks"))] + type MessageProcessor = + xcm_builder::ProcessXcmMessage; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: + type QueueChangeHandler = NarrowOriginToSibling; + // NarrowOriginToSibling calls XcmpQueue's is_paused if Origin is sibling. Allows all other origins + type QueuePausedQuery = EmergencyParaXcm; + type WeightInfo = pallet_message_queue::weights::SubstrateWeight; +} + +impl pallet_emergency_para_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type CheckAssociatedRelayNumber = + cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases; + type QueuePausedQuery = (MaintenanceMode, NarrowOriginToSibling); + type XcmpMessageHandler = XcmpQueue; + type PausedThreshold = ConstU32<300>; + type FastAuthorizeUpgradeOrigin = + pallet_collective::EnsureProportionAtLeast; + type PausedToNormalOrigin = + pallet_collective::EnsureProportionAtLeast; +} + +// Our AssetType. For now we only handle Xcm Assets +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum AssetType { + Xcm(xcm::v3::Location), +} +impl Default for AssetType { + fn default() -> Self { + Self::Xcm(xcm::v3::Location::here()) + } +} + +impl From for AssetType { + fn from(location: xcm::v3::Location) -> Self { + Self::Xcm(location) + } +} + +// This can be removed once we fully adopt xcm::v4 everywhere +impl TryFrom for AssetType { + type Error = (); + fn try_from(location: Location) -> Result { + Ok(Self::Xcm(location.try_into()?)) + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => Some(location), + } + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => xcm_builder::V4V3LocationConverter::convert_back(&location), + } + } +} + +// Implementation on how to retrieve the AssetId from an AssetType +// We take it +impl From for AssetId { + fn from(asset: AssetType) -> AssetId { + match asset { + AssetType::Xcm(id) => { + let mut result: [u8; 16] = [0u8; 16]; + let hash: H256 = id.using_encoded(::Hashing::hash); + result.copy_from_slice(&hash.as_fixed_bytes()[0..16]); + u128::from_le_bytes(result) + } + } + } +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + // Our native token + SelfReserve, + // Assets representing other chains native tokens + ForeignAsset(AssetId), + // Erc20 token + Erc20 { contract_address: H160 }, +} + +impl AccountIdToCurrencyId for Runtime { + fn account_to_currency_id(account: AccountId) -> Option { + Some(match account { + // the self-reserve currency is identified by the pallet-balances address + a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve, + // the rest of the currencies, by their corresponding erc20 address + _ => match Runtime::account_to_asset_id(account) { + // A foreign asset + Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id), + // If no known prefix is identified, we consider that it's a "real" erc20 token + // (i.e. managed by a real smart contract) + None => CurrencyId::Erc20 { + contract_address: account.into(), + }, + }, + }) + } +} + +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + CurrencyId::Erc20 { contract_address } => { + let mut location = Erc20XcmBridgePalletLocation::get(); + location + .push_interior(Junction::AccountKey20 { + key: contract_address.0, + network: None, + }) + .ok(); + Some(location) + } + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight + = Weight::from_parts(200_000_000u64, 0); + pub const MaxAssetsForTransfer: usize = 2; + // This is how we are going to detect whether the asset is a Reserve asset + // This however is the chain part only + pub SelfLocation: Location = Location::here(); + // We need this to be able to catch when someone is trying to execute a non- + // cross-chain transfer in xtokens through the absolute path way + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(ParachainInfo::parachain_id().into()) + ].into() + }; + +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + // AssetHub fee + (1, Some(Parachain(1001u32))) => Some(50_000_000u128), + _ => None, + } + }; +} + +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdConvert = CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = AbsoluteAndRelativeReserve; +} + +// 1 WND/ROC should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +// For now we only allow to transact in the relay, although this might change in the future +// Transactors just defines the chains in which we allow transactions to be issued through +// xcm +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum Transactors { + Relay, +} + +// Default for benchmarking +#[cfg(feature = "runtime-benchmarks")] +impl Default for Transactors { + fn default() -> Self { + Transactors::Relay + } +} + +impl TryFrom for Transactors { + type Error = (); + fn try_from(value: u8) -> Result { + match value { + 0u8 => Ok(Transactors::Relay), + _ => Err(()), + } + } +} + +impl UtilityEncodeCall for Transactors { + fn encode_call(self, call: UtilityAvailableCalls) -> Vec { + match self { + Transactors::Relay => pallet_xcm_transactor::Pallet::::encode_call( + pallet_xcm_transactor::Pallet(sp_std::marker::PhantomData::), + call, + ), + } + } +} + +impl XcmTransact for Transactors { + fn destination(self) -> Location { + match self { + Transactors::Relay => Location::parent(), + } + } +} + +pub type DerivativeAddressRegistrationOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = Transactors; + type DerivativeAddressRegistrationOrigin = DerivativeAddressRegistrationOrigin; + type SovereignAccountDispatcherOrigin = EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdToLocation = CurrencyIdToLocation>; + type XcmSender = XcmRouter; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = AbsoluteAndRelativeReserve; + type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; + type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + // This is the relative view of erc20 assets. + // Identified by this prefix + AccountKey20(contractAddress) + // We use the RELATIVE multilocation + pub Erc20XcmBridgePalletLocation: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + + // To be able to support almost all erc20 implementations, + // we provide a sufficiently hight gas limit. + pub Erc20XcmBridgeTransferGasLimit: u64 = 800_000; +} + +impl pallet_erc20_xcm_bridge::Config for Runtime { + type AccountIdConverter = LocationToH160; + type Erc20MultilocationPrefix = Erc20XcmBridgePalletLocation; + type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit; + type EvmRunner = EvmRunnerPrecompileOrEthXcm; +} + +#[cfg(feature = "runtime-benchmarks")] +mod testing { + use super::*; + use xcm_builder::V4V3LocationConverter; + + /// This From exists for benchmarking purposes. It has the potential side-effect of calling + /// AssetManager::set_asset_type_asset_id() and should NOT be used in any production code. + impl From for CurrencyId { + fn from(location: Location) -> CurrencyId { + use xcm_primitives::AssetTypeGetter; + + // If it does not exist, for benchmarking purposes, we create the association + let asset_id = if let Some(asset_id) = + AsAssetType::::convert_location(&location) + { + asset_id + } else { + let asset_type = AssetType::Xcm( + V4V3LocationConverter::convert(&location).expect("convert to v3"), + ); + let asset_id: AssetId = asset_type.clone().into(); + AssetManager::set_asset_type_asset_id(asset_type, asset_id); + asset_id + }; + + CurrencyId::ForeignAsset(asset_id) + } + } +} diff --git a/tracing/2902/runtime/moonbase/tests/common/mod.rs b/tracing/2902/runtime/moonbase/tests/common/mod.rs new file mode 100644 index 00000000..416e9a00 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/common/mod.rs @@ -0,0 +1,394 @@ +// 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 . + +#![allow(dead_code)] + +use cumulus_primitives_parachain_inherent::ParachainInherentData; +use fp_evm::GenesisAccount; +use frame_support::{ + assert_ok, + traits::{OnFinalize, OnInitialize}, +}; +use moonbase_runtime::{asset_config::AssetRegistrarMetadata, xcm_config::AssetType}; +pub use moonbase_runtime::{ + currency::{GIGAWEI, SUPPLY_FACTOR, UNIT, WEI}, + AccountId, AssetId, AssetManager, Assets, AsyncBacking, AuthorInherent, Balance, Balances, + CrowdloanRewards, Ethereum, Executive, Header, InflationInfo, ParachainStaking, + ParachainSystem, Range, Runtime, RuntimeCall, RuntimeEvent, System, TransactionConverter, + TransactionPaymentAsGasPrice, UncheckedExtrinsic, HOURS, WEEKS, +}; +use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; +use polkadot_parachain::primitives::HeadData; +use sp_consensus_slots::Slot; +use sp_core::{Encode, H160}; +use sp_runtime::{traits::Dispatchable, BuildStorage, Digest, DigestItem, Perbill, Percent}; + +use std::collections::BTreeMap; + +use fp_rpc::ConvertTransaction; +use pallet_transaction_payment::Multiplier; + +// A valid signed Alice transfer. +pub const VALID_ETH_TX: &str = + "02f86d8205018085174876e80085e8d4a5100082520894f24ff3a9cf04c71dbc94d0b566f7a27b9456\ + 6cac8080c001a0e1094e1a52520a75c0255db96132076dd0f1263089f838bea548cbdbfc64a4d19f031c\ + 92a8cb04e2d68d20a6158d542a07ac440cc8d07b6e36af02db046d92df"; + +// An invalid signed Alice transfer with a gas limit artifically set to 0. +pub const INVALID_ETH_TX: &str = + "f86180843b9aca00809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ca00e28ba2dd3c5a\ + 3fd467d4afd7aefb4a34b373314fff470bb9db743a84d674a0aa06e5994f2d07eafe1c37b4ce5471ca\ + ecec29011f6f5bf0b1a552c55ea348df35f"; + +pub fn rpc_run_to_block(n: u32) { + while System::block_number() < n { + Ethereum::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + Ethereum::on_initialize(System::block_number()); + } +} + +/// Utility function that advances the chain to the desired block number. +/// If an author is provided, that author information is injected to all the blocks in the meantime. +pub fn run_to_block(n: u32, author: Option) { + // Finalize the first block + Ethereum::on_finalize(System::block_number()); + while System::block_number() < n { + // Set the new block number and author + match author { + Some(ref author) => { + let pre_digest = Digest { + logs: vec![DigestItem::PreRuntime(NIMBUS_ENGINE_ID, author.encode())], + }; + System::reset_events(); + System::initialize( + &(System::block_number() + 1), + &System::parent_hash(), + &pre_digest, + ); + } + None => { + System::set_block_number(System::block_number() + 1); + } + } + + increase_last_relay_slot_number(1); + + // Initialize the new block + AuthorInherent::on_initialize(System::block_number()); + ParachainStaking::on_initialize(System::block_number()); + Ethereum::on_initialize(System::block_number()); + + // Finalize the block + Ethereum::on_finalize(System::block_number()); + ParachainStaking::on_finalize(System::block_number()); + } +} + +pub fn last_event() -> RuntimeEvent { + System::events().pop().expect("Event expected").event +} + +// Test struct with the purpose of initializing xcm assets +#[derive(Clone)] +pub struct XcmAssetInitialization { + pub asset_type: AssetType, + pub metadata: AssetRegistrarMetadata, + pub balances: Vec<(AccountId, Balance)>, + pub is_sufficient: bool, +} + +pub struct ExtBuilder { + // endowed accounts with balances + balances: Vec<(AccountId, Balance)>, + // [collator, amount] + collators: Vec<(AccountId, Balance)>, + // [delegator, collator, nomination_amount] + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + // per-round inflation config + inflation: InflationInfo, + // AuthorId -> AccoutId mappings + mappings: Vec<(NimbusId, AccountId)>, + // Crowdloan fund + crowdloan_fund: Balance, + // Chain id + chain_id: u64, + // EVM genesis accounts + evm_accounts: BTreeMap, + // [assettype, metadata, Vec] + xcm_assets: Vec, + safe_xcm_version: Option, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { + balances: vec![], + delegations: vec![], + collators: vec![], + inflation: InflationInfo { + expect: Range { + min: 100_000 * UNIT, + ideal: 200_000 * UNIT, + max: 500_000 * UNIT, + }, + // not used + annual: Range { + min: Perbill::from_percent(50), + ideal: Perbill::from_percent(50), + max: Perbill::from_percent(50), + }, + // unrealistically high parameterization, only for testing + round: Range { + min: Perbill::from_percent(5), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }, + }, + mappings: vec![], + crowdloan_fund: 0, + chain_id: CHAIN_ID, + evm_accounts: BTreeMap::new(), + xcm_assets: vec![], + safe_xcm_version: None, + } + } +} + +impl ExtBuilder { + pub fn with_evm_accounts(mut self, accounts: BTreeMap) -> Self { + self.evm_accounts = accounts; + self + } + + pub fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn with_collators(mut self, collators: Vec<(AccountId, Balance)>) -> Self { + self.collators = collators; + self + } + + pub fn with_delegations(mut self, delegations: Vec<(AccountId, AccountId, Balance)>) -> Self { + self.delegations = delegations + .into_iter() + .map(|d| (d.0, d.1, d.2, Percent::zero())) + .collect(); + self + } + + pub fn with_xcm_assets(mut self, xcm_assets: Vec) -> Self { + self.xcm_assets = xcm_assets; + self + } + + pub fn with_crowdloan_fund(mut self, crowdloan_fund: Balance) -> Self { + self.crowdloan_fund = crowdloan_fund; + self + } + + pub fn with_mappings(mut self, mappings: Vec<(NimbusId, AccountId)>) -> Self { + self.mappings = mappings; + self + } + + pub fn with_safe_xcm_version(mut self, safe_xcm_version: u32) -> Self { + self.safe_xcm_version = Some(safe_xcm_version); + self + } + + #[allow(dead_code)] + pub fn with_inflation(mut self, inflation: InflationInfo) -> Self { + self.inflation = inflation; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: self.balances, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_parachain_staking::GenesisConfig:: { + candidates: self.collators, + delegations: self.delegations, + inflation_config: self.inflation, + collator_commission: Perbill::from_percent(20), + parachain_bond_reserve_percent: Percent::from_percent(30), + blocks_per_round: 2 * HOURS, + num_selected_candidates: 8, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_crowdloan_rewards::GenesisConfig:: { + funded_amount: self.crowdloan_fund, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_author_mapping::GenesisConfig:: { + mappings: self.mappings, + } + .assimilate_storage(&mut t) + .unwrap(); + + let genesis_config = pallet_evm_chain_id::GenesisConfig:: { + chain_id: self.chain_id, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: self.evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_ethereum::GenesisConfig:: { + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_xcm::GenesisConfig:: { + safe_xcm_version: self.safe_xcm_version, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_transaction_payment::GenesisConfig:: { + multiplier: Multiplier::from(8u128), + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + + let xcm_assets = self.xcm_assets.clone(); + + 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( + root_origin(), + xcm_asset_initialization.asset_type, + xcm_asset_initialization.metadata, + 1, + xcm_asset_initialization.is_sufficient, + ) + .unwrap(); + for (account, balance) in xcm_asset_initialization.balances { + Assets::mint( + origin_of(AssetManager::account_id()), + asset_id.into(), + account, + balance, + ) + .unwrap(); + } + } + System::set_block_number(1); + }); + ext + } +} + +pub const CHAIN_ID: u64 = 1281; +pub const ALICE: [u8; 20] = [4u8; 20]; +pub const ALICE_NIMBUS: [u8; 32] = [4u8; 32]; +pub const BOB: [u8; 20] = [5u8; 20]; +pub const CHARLIE: [u8; 20] = [6u8; 20]; +pub const DAVE: [u8; 20] = [7u8; 20]; +pub const EVM_CONTRACT: [u8; 20] = [8u8; 20]; + +pub fn origin_of(account_id: AccountId) -> ::RuntimeOrigin { + ::RuntimeOrigin::signed(account_id) +} + +pub fn inherent_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::none() +} + +pub fn root_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::root() +} + +pub fn unchecked_eth_tx(raw_hex_tx: &str) -> UncheckedExtrinsic { + let converter = TransactionConverter; + converter.convert_transaction(ethereum_transaction(raw_hex_tx)) +} + +pub fn ethereum_transaction(raw_hex_tx: &str) -> pallet_ethereum::Transaction { + let bytes = hex::decode(raw_hex_tx).expect("Transaction bytes."); + let transaction = ethereum::EnvelopedDecodable::decode(&bytes[..]); + assert!(transaction.is_ok()); + transaction.unwrap() +} + +/// Mock the inherent that sets validation data in ParachainSystem, which +/// contains the `relay_chain_block_number`, which is used in `author-filter` as a +/// source of randomness to filter valid authors at each block. +pub fn set_parachain_inherent_data() { + use cumulus_primitives_core::PersistedValidationData; + use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; + + let mut relay_sproof = RelayStateSproofBuilder::default(); + relay_sproof.para_id = 100u32.into(); + relay_sproof.included_para_head = Some(HeadData(vec![1, 2, 3])); + + let additional_key_values = vec![( + moonbeam_core_primitives::well_known_relay_keys::TIMESTAMP_NOW.to_vec(), + sp_timestamp::Timestamp::default().encode(), + )]; + + relay_sproof.additional_key_values = additional_key_values; + + let (relay_parent_storage_root, relay_chain_state) = relay_sproof.into_state_root_and_proof(); + + let vfp = PersistedValidationData { + relay_parent_number: 1u32, + relay_parent_storage_root, + ..Default::default() + }; + let parachain_inherent_data = ParachainInherentData { + validation_data: vfp, + relay_chain_state: relay_chain_state, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + }; + assert_ok!(RuntimeCall::ParachainSystem( + cumulus_pallet_parachain_system::Call::::set_validation_data { + data: parachain_inherent_data + } + ) + .dispatch(inherent_origin())); +} + +pub(crate) fn increase_last_relay_slot_number(amount: u64) { + let last_relay_slot = u64::from(AsyncBacking::slot_info().unwrap_or_default().0); + frame_support::storage::unhashed::put( + &frame_support::storage::storage_prefix(b"AsyncBacking", b"SlotInfo"), + &((Slot::from(last_relay_slot + amount), 0)), + ); +} diff --git a/tracing/2902/runtime/moonbase/tests/evm_tracing.rs b/tracing/2902/runtime/moonbase/tests/evm_tracing.rs new file mode 100644 index 00000000..6c8b4c79 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/evm_tracing.rs @@ -0,0 +1,110 @@ +// 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 . + +//! Moonbase EVM tracing Integration Tests + +mod common; + +#[cfg(test)] +#[cfg(feature = "evm-tracing")] +mod tests { + use super::common::*; + + use pallet_evm::AddressMapping; + use sp_core::H160; + + use moonbeam_rpc_primitives_debug::runtime_decl_for_debug_runtime_api::DebugRuntimeApi; + use std::str::FromStr; + + #[test] + fn debug_runtime_api_trace_transaction() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * UNIT), + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * UNIT, + } + .into(), + ); + let transaction = ethereum_transaction(VALID_ETH_TX); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_transaction( + vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()], + &transaction, + &block + ) + .is_ok()); + }); + } + + #[test] + fn debug_runtime_api_trace_block() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * UNIT), + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * UNIT, + } + .into(), + ); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let eth_tx = ethereum_transaction(VALID_ETH_TX); + let eth_extrinsic_hash = eth_tx.hash(); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_block( + vec![non_eth_uxt.clone(), eth_uxt.clone(), non_eth_uxt, eth_uxt], + vec![eth_extrinsic_hash, eth_extrinsic_hash], + &block + ) + .is_ok()); + }); + } +} diff --git a/tracing/2902/runtime/moonbase/tests/integration_test.rs b/tracing/2902/runtime/moonbase/tests/integration_test.rs new file mode 100644 index 00000000..8d0831c1 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/integration_test.rs @@ -0,0 +1,3004 @@ +// 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 . + +//! Moonbase Runtime Integration Tests + +mod common; +use common::*; + +use precompile_utils::{ + precompile_set::{is_precompile_or_fail, IsActivePrecompile}, + prelude::*, + testing::*, +}; + +use fp_evm::{Context, IsPrecompileResult}; +use frame_support::{ + assert_noop, assert_ok, + dispatch::DispatchClass, + traits::{ + fungible::Inspect, Currency as CurrencyT, EnsureOrigin, PalletInfo, StorageInfo, + StorageInfoTrait, + }, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + StorageHasher, Twox128, +}; +use moonbase_runtime::{ + asset_config::{AssetRegistrarMetadata, ForeignAssetInstance}, + xcm_config::{AssetType, SelfReserve}, + AccountId, AssetId, AssetManager, Assets, Balances, CrowdloanRewards, + OpenTechCommitteeCollective, ParachainStaking, PolkadotXcm, Precompiles, Runtime, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, TransactionPayment, + TreasuryCouncilCollective, XTokens, XcmTransactor, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; +use polkadot_parachain::primitives::Sibling; +use precompile_utils::testing::MockHandle; +use sp_runtime::{ + traits::{Convert as XcmConvert, Dispatchable}, + BuildStorage, +}; +use std::str::from_utf8; +use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}; +use xcm_executor::traits::ConvertLocation; + +use moonbeam_xcm_benchmarks::weights::XcmWeight; +use nimbus_primitives::NimbusId; +use pallet_evm::PrecompileSet; +use pallet_evm_precompileset_assets_erc20::{ + AccountIdAssetIdConversion, SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER, +}; +use pallet_transaction_payment::Multiplier; +use pallet_xcm_transactor::{Currency, CurrencyPayment, HrmpOperation, TransactWeights}; +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 xcm::latest::prelude::*; + +type AuthorMappingPCall = + pallet_evm_precompile_author_mapping::AuthorMappingPrecompileCall; +type BatchPCall = pallet_evm_precompile_batch::BatchPrecompileCall; +type CrowdloanRewardsPCall = + pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompileCall; +type XcmUtilsPCall = pallet_evm_precompile_xcm_utils::XcmUtilsPrecompileCall< + Runtime, + moonbase_runtime::xcm_config::XcmExecutorConfig, +>; +type XtokensPCall = pallet_evm_precompile_xtokens::XtokensPrecompileCall; +type ForeignAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSetCall< + Runtime, + ForeignAssetInstance, +>; +type XcmTransactorV1PCall = + pallet_evm_precompile_xcm_transactor::v1::XcmTransactorPrecompileV1Call; +type XcmTransactorV2PCall = + pallet_evm_precompile_xcm_transactor::v2::XcmTransactorPrecompileV2Call; + +// TODO: can we construct a const U256...? +const BASE_FEE_GENISIS: u128 = 10 * GIGAWEI; + +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + +#[test] +fn verify_pallet_prefixes() { + fn is_pallet_prefix(name: &str) { + // Compares the unhashed pallet prefix in the `StorageInstance` implementation by every + // storage item in the pallet P. This pallet prefix is used in conjunction with the + // item name to get the unique storage key: hash(PalletPrefix) + hash(StorageName) + // https://github.com/paritytech/substrate/blob/master/frame/support/procedural/src/pallet/ + // expand/storage.rs#L389-L401 + assert_eq!( + ::PalletInfo::name::

(), + Some(name) + ); + } + // TODO: use StorageInfoTrait from https://github.com/paritytech/substrate/pull/9246 + // This is now available with polkadot-v0.9.9 dependencies + is_pallet_prefix::("System"); + is_pallet_prefix::("Utility"); + is_pallet_prefix::("ParachainSystem"); + is_pallet_prefix::("TransactionPayment"); + is_pallet_prefix::("ParachainInfo"); + is_pallet_prefix::("EthereumChainId"); + is_pallet_prefix::("EVM"); + is_pallet_prefix::("Ethereum"); + is_pallet_prefix::("ParachainStaking"); + is_pallet_prefix::("Scheduler"); + is_pallet_prefix::("Treasury"); + is_pallet_prefix::( + "OpenTechCommitteeCollective", + ); + is_pallet_prefix::("AuthorInherent"); + is_pallet_prefix::("AuthorFilter"); + is_pallet_prefix::("CrowdloanRewards"); + is_pallet_prefix::("AuthorMapping"); + is_pallet_prefix::("MaintenanceMode"); + is_pallet_prefix::("Identity"); + is_pallet_prefix::("XcmpQueue"); + is_pallet_prefix::("CumulusXcm"); + is_pallet_prefix::("DmpQueue"); + is_pallet_prefix::("PolkadotXcm"); + is_pallet_prefix::("Assets"); + is_pallet_prefix::("XTokens"); + is_pallet_prefix::("AssetManager"); + is_pallet_prefix::("Migrations"); + is_pallet_prefix::("XcmTransactor"); + is_pallet_prefix::("ProxyGenesisCompanion"); + is_pallet_prefix::("MoonbeamOrbiters"); + is_pallet_prefix::("EthereumXcm"); + is_pallet_prefix::("Randomness"); + is_pallet_prefix::("TreasuryCouncilCollective"); + is_pallet_prefix::("MoonbeamLazyMigrations"); + is_pallet_prefix::("RelayStorageRoots"); + + let prefix = |pallet_name, storage_name| { + let mut res = [0u8; 32]; + res[0..16].copy_from_slice(&Twox128::hash(pallet_name)); + res[16..32].copy_from_slice(&Twox128::hash(storage_name)); + res.to_vec() + }; + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"TotalIssuance".to_vec(), + prefix: prefix(b"Balances", b"TotalIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"InactiveIssuance".to_vec(), + prefix: prefix(b"Balances", b"InactiveIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Account".to_vec(), + prefix: prefix(b"Balances", b"Account"), + max_values: None, + max_size: Some(100), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Locks".to_vec(), + prefix: prefix(b"Balances", b"Locks"), + max_values: None, + max_size: Some(1287), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Reserves".to_vec(), + prefix: prefix(b"Balances", b"Reserves"), + max_values: None, + max_size: Some(1037), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Holds".to_vec(), + prefix: prefix(b"Balances", b"Holds"), + max_values: None, + max_size: Some(55), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Freezes".to_vec(), + prefix: prefix(b"Balances", b"Freezes"), + max_values: None, + max_size: Some(37), + }, + ] + ); + assert_eq!( + ::storage_info(), + vec![StorageInfo { + pallet_name: b"Sudo".to_vec(), + storage_name: b"Key".to_vec(), + prefix: prefix(b"Sudo", b"Key"), + max_values: Some(1), + max_size: Some(20), + }] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Proxies".to_vec(), + prefix: prefix(b"Proxy", b"Proxies"), + max_values: None, + max_size: Some(845), + }, + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Announcements".to_vec(), + prefix: prefix(b"Proxy", b"Announcements"), + max_values: None, + max_size: Some(1837), + } + ] + ); + assert_eq!( + ::storage_info(), + vec![StorageInfo { + pallet_name: b"MaintenanceMode".to_vec(), + storage_name: b"MaintenanceMode".to_vec(), + prefix: prefix(b"MaintenanceMode", b"MaintenanceMode"), + max_values: Some(1), + max_size: None, + },] + ); + + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRoot".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRoot"), + max_values: None, + max_size: Some(44), + }, + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRootKeys".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRootKeys"), + max_values: Some(1), + max_size: Some(121), + }, + ] + ); +} + +#[test] +fn test_collectives_storage_item_prefixes() { + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"TreasuryCouncilCollective".to_vec()); + } + + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"OpenTechCommitteeCollective".to_vec()); + } +} + +#[test] +fn collective_set_members_root_origin_works() { + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert_ok!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + // OpenTechCommitteeCollective + assert_ok!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + }); +} + +#[test] +fn collective_set_members_general_admin_origin_works() { + use moonbase_runtime::{ + governance::custom_origins::Origin as CustomOrigin, OriginCaller, Utility, + }; + + ExtBuilder::default().build().execute_with(|| { + let root_caller = ::RuntimeOrigin::root(); + let alice = AccountId::from(ALICE); + + // TreasuryCouncilCollective + let _ = Utility::dispatch_as( + root_caller.clone(), + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + // OpenTechCommitteeCollective + let _ = Utility::dispatch_as( + root_caller, + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + + assert_eq!( + System::events() + .into_iter() + .filter_map(|r| { + match r.event { + RuntimeEvent::Utility(pallet_utility::Event::DispatchedAs { result }) + if result.is_ok() => + { + Some(true) + } + _ => None, + } + }) + .collect::>() + .len(), + 2 + ) + }); +} + +#[test] +fn collective_set_members_signed_origin_does_not_work() { + let alice = AccountId::from(ALICE); + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + // OpenTechCommitteeCollective + assert!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + }); +} + +#[test] +fn verify_pallet_indices() { + fn is_pallet_index(index: usize) { + assert_eq!( + ::PalletInfo::index::

(), + Some(index) + ); + } + is_pallet_index::(0); + is_pallet_index::(1); + is_pallet_index::(3); + is_pallet_index::(4); + is_pallet_index::(6); + is_pallet_index::(7); + is_pallet_index::(8); + is_pallet_index::(9); + is_pallet_index::(10); + is_pallet_index::(11); + is_pallet_index::(12); + is_pallet_index::(13); + //is_pallet_index::(14); Removed + is_pallet_index::(17); + is_pallet_index::(18); + is_pallet_index::(19); + is_pallet_index::(20); + is_pallet_index::(21); + is_pallet_index::(22); + is_pallet_index::(23); + is_pallet_index::(24); + is_pallet_index::(25); + is_pallet_index::(26); + is_pallet_index::(27); + is_pallet_index::(28); + is_pallet_index::(29); + is_pallet_index::(30); + is_pallet_index::(31); + is_pallet_index::(32); + is_pallet_index::(33); + is_pallet_index::(34); + is_pallet_index::(37); + is_pallet_index::(38); + is_pallet_index::(39); + is_pallet_index::(40); + is_pallet_index::(46); + is_pallet_index::(51); +} + +#[test] +fn verify_reserved_indices() { + use frame_metadata::*; + let metadata = moonbase_runtime::Runtime::metadata(); + let metadata = match metadata.1 { + RuntimeMetadata::V14(metadata) => metadata, + _ => panic!("metadata has been bumped, test needs to be updated"), + }; + // 35: BaseFee + // 36: pallet_assets:: + let reserved = vec![35, 36]; + let existing = metadata + .pallets + .iter() + .map(|p| p.index) + .collect::>(); + assert!(reserved.iter().all(|index| !existing.contains(index))); +} + +#[test] +fn verify_proxy_type_indices() { + assert_eq!(moonbase_runtime::ProxyType::Any as u8, 0); + assert_eq!(moonbase_runtime::ProxyType::NonTransfer as u8, 1); + assert_eq!(moonbase_runtime::ProxyType::Governance as u8, 2); + assert_eq!(moonbase_runtime::ProxyType::Staking as u8, 3); + assert_eq!(moonbase_runtime::ProxyType::CancelProxy as u8, 4); + assert_eq!(moonbase_runtime::ProxyType::Balances as u8, 5); + assert_eq!(moonbase_runtime::ProxyType::AuthorMapping as u8, 6); + assert_eq!(moonbase_runtime::ProxyType::IdentityJudgement as u8, 7); +} + +#[test] +fn join_collator_candidates() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 2_000 * UNIT), + (AccountId::from(CHARLIE), 1_100 * UNIT), + (AccountId::from(DAVE), 1_000 * UNIT), + ]) + .with_collators(vec![ + (AccountId::from(ALICE), 1_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_delegations(vec![ + (AccountId::from(CHARLIE), AccountId::from(ALICE), 50 * UNIT), + (AccountId::from(CHARLIE), AccountId::from(BOB), 50 * UNIT), + ]) + .build() + .execute_with(|| { + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(ALICE)), + 1_000 * UNIT, + 2u32 + ), + pallet_parachain_staking::Error::::CandidateExists + ); + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 1_000 * UNIT, + 2u32 + ), + pallet_parachain_staking::Error::::DelegatorExists + ); + assert!(System::events().is_empty()); + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(DAVE)), + 1_000 * UNIT, + 2u32 + )); + assert_eq!( + last_event(), + RuntimeEvent::ParachainStaking( + pallet_parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 1_000 * UNIT, + new_total_amt_locked: 3_100 * UNIT + } + ) + ); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(ALICE)); + assert_eq!(candidates.0[0].amount, 1_050 * UNIT); + assert_eq!(candidates.0[1].owner, AccountId::from(BOB)); + assert_eq!(candidates.0[1].amount, 1_050 * UNIT); + assert_eq!(candidates.0[2].owner, AccountId::from(DAVE)); + assert_eq!(candidates.0[2].amount, 1_000 * UNIT); + }); +} + +#[test] +fn transfer_through_evm_to_stake() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * UNIT)]) + .build() + .execute_with(|| { + // Charlie has no balance => fails to stake + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 1_000 * UNIT, + 0u32 + ), + DispatchError::Module(ModuleError { + index: 12, + error: [8, 0, 0, 0], + message: Some("InsufficientBalance") + }) + ); + + // Alice transfer from free balance 2000 UNIT to Bob + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 2_000 * UNIT, + )); + assert_eq!(Balances::free_balance(AccountId::from(BOB)), 2_000 * UNIT); + + let gas_limit = 100000u64; + // Bob transfers 1000 UNIT to Charlie via EVM + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(CHARLIE), + input: Vec::new(), + value: (1_000 * UNIT).into(), + gas_limit, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: None, + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + assert_eq!( + Balances::free_balance(AccountId::from(CHARLIE)), + 1_000 * UNIT, + ); + + // Charlie can stake now + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 1_000 * UNIT, + 0u32, + ),); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(CHARLIE)); + assert_eq!(candidates.0[0].amount, 1_000 * UNIT); + }); +} + +#[test] +fn reward_block_authors() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 100 extra tokens for her mapping deposit + (AccountId::from(ALICE), 2_100 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + increase_last_relay_slot_number(1); + // Just before round 3 + run_to_block(2399, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // no rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 1_100 * UNIT, + ); + assert_eq!(Balances::usable_balance(AccountId::from(BOB)), 500 * UNIT,); + run_to_block(2401, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 1213666666584000000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 541333333292000000000, + ); + }); +} + +#[test] +fn reward_block_authors_with_parachain_bond_reserved() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 100 extra tokens for her mapping deposit + (AccountId::from(ALICE), 2_100 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + (AccountId::from(CHARLIE), UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + increase_last_relay_slot_number(1); + assert_ok!(ParachainStaking::set_parachain_bond_account( + root_origin(), + AccountId::from(CHARLIE), + ),); + + // Stop just before round 2 + run_to_block(1199, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + // no rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 1_100 * UNIT, + ); + assert_eq!(Balances::usable_balance(AccountId::from(BOB)), 500 * UNIT,); + assert_eq!(Balances::usable_balance(AccountId::from(CHARLIE)), UNIT,); + + // Go to round 2 + run_to_block(1201, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + // 30% reserved for parachain bond + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 47515000000000000000, + ); + + // Go to round 3 + run_to_block(2401, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 1182693333281650000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 525841666640825000000, + ); + // 30% again reserved for parachain bond + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 94727725000000000000, + ); + }); +} + +#[test] +fn initialize_crowdloan_addresses_with_batch_and_pay() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 450_000 * UNIT); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 450_000 * UNIT); + let expected = RuntimeEvent::Utility(pallet_utility::Event::BatchCompleted); + assert_eq!(last_event(), expected); + // This one should fail, as we already filled our data + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch { + calls: vec![RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![([4u8; 32].into(), Some(AccountId::from(ALICE)), 432000)] + } + )] + }) + .dispatch(root_origin()) + ); + let expected_fail = RuntimeEvent::Utility(pallet_utility::Event::BatchInterrupted { + index: 0, + error: DispatchError::Module(ModuleError { + index: 20, + error: [8, 0, 0, 0], + message: None, + }), + }); + assert_eq!(last_event(), expected_fail); + // Claim 1 block. + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(CHARLIE)))); + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(DAVE)))); + + let vesting_period = 4 * WEEKS as u128; + let per_block = (1_050_000 * UNIT) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (450_000 * UNIT) + per_block + ); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (450_000 * UNIT) + per_block + ); + // The total claimed reward should be equal to the account balance at this point. + assert_eq!( + Balances::balance(&AccountId::from(CHARLIE)), + (450_000 * UNIT) + per_block + ); + assert_eq!( + Balances::balance(&AccountId::from(DAVE)), + (450_000 * UNIT) + per_block + ); + assert_noop!( + CrowdloanRewards::claim(origin_of(AccountId::from(ALICE))), + pallet_crowdloan_rewards::Error::::NoAssociatedClaim + ); + }); +} + +#[test] +fn initialize_crowdloan_address_and_change_with_relay_key_sig() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + + let (pair1, _) = sp_core::sr25519::Pair::generate(); + let (pair2, _) = sp_core::sr25519::Pair::generate(); + + let public1 = pair1.public(); + let public2 = pair2.public(); + + // signature: + // WRAP_BYTES|| NetworkIdentifier|| new_account || previous_account || WRAP_BYTES + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut b"moonbase-".to_vec()); + message.append(&mut AccountId::from(DAVE).encode()); + message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); + + let signature1 = pair1.sign(&message); + let signature2 = pair2.sign(&message); + + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + // two relay accounts pointing at the same reward account + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public1.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public2.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 900_000 * UNIT); + + // this should fail, as we are only providing one signature + assert_noop!( + CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![(public1.into(), signature1.clone().into())] + ), + pallet_crowdloan_rewards::Error::::InsufficientNumberOfValidProofs + ); + + // this should be valid + assert_ok!(CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![ + (public1.into(), signature1.into()), + (public2.into(), signature2.into()) + ] + )); + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (900_000 * UNIT) + ); + }); +} + +#[test] +fn claim_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 450_000 * UNIT); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 450_000 * UNIT); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Alice uses the crowdloan precompile to claim through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENISIS.into(); + + // Construct the call data (selector, amount) + let mut call_data = Vec::::from([0u8; 4]); + call_data[0..4].copy_from_slice(&Keccak256::digest(b"claim()")[0..4]); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let vesting_period = 4 * WEEKS as u128; + let per_block = (1_050_000 * UNIT) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (450_000 * UNIT) + per_block + ); + }) +} + +#[test] +fn is_contributor_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Assert precompile reports Bob is not a contributor + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(BOB.into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(false); + + // Assert precompile reports Charlie is a nominator + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(CHARLIE.into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(true); + }) +} + +#[test] +fn reward_info_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + let expected_total: U256 = (1_500_000 * UNIT).into(); + let expected_claimed: U256 = (450_000 * UNIT).into(); + + // Assert precompile reports correct Charlie reward info. + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::reward_info { + contributor: Address(AccountId::from(CHARLIE).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns((expected_total, expected_claimed)); + }) +} + +#[test] +fn update_reward_address_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * UNIT) + .build() + .execute_with(|| { + // set parachain inherent data + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * UNIT + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Charlie uses the crowdloan precompile to update address through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENISIS.into(); + + // Construct the input data to check if Bob is a contributor + let mut call_data = Vec::::from([0u8; 36]); + call_data[0..4] + .copy_from_slice(&Keccak256::digest(b"update_reward_address(address)")[0..4]); + call_data[16..36].copy_from_slice(&ALICE); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + assert!(CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)).is_none()); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(ALICE)) + .unwrap() + .claimed_reward, + (450_000 * UNIT) + ); + }) +} + +#[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( + moonbase_runtime::RuntimeOrigin::root(), + source_location, + asset_metadata, + 1u128, + true, + )); + assert!(AssetManager::asset_id_type(source_id).is_some()); + }); +} + +#[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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Assert the asset has been created with the correct supply + assert_eq!(Assets::total_supply(relay_asset_id), 1_000 * UNIT); + + // Access totalSupply through precompile. Important that the context is correct + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::total_supply {}, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * UNIT)); + + // Access balanceOf through precompile + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(ALICE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * UNIT)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Transfer tokens from Alice to Bob, 400 UNIT. + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::transfer { + to: Address(BOB.into()), + value: { 400 * UNIT }.into(), + }, + ) + .expect_cost(24377) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * UNIT)), + )) + .execute_returns(true); + + // Make sure BOB has 400 UNIT + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(BOB.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * UNIT)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * UNIT)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Aprove Bob for spending 400 UNIT from Alice + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::approve { + spender: Address(BOB.into()), + value: { 400 * UNIT }.into(), + }, + ) + .expect_cost(14429) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_APPROVAL, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * UNIT)), + )) + .execute_returns(true); + + // Transfer tokens from Alice to Charlie by using BOB as origin + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::transfer_from { + from: Address(ALICE.into()), + to: Address(CHARLIE.into()), + value: { 400 * UNIT }.into(), + }, + ) + .expect_cost(29748) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(CHARLIE), + solidity::encode_event_data(U256::from(400 * UNIT)), + )) + .execute_returns(true); + + // Make sure CHARLIE has 400 UNIT + Precompiles::new() + .prepare_test( + CHARLIE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(CHARLIE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * UNIT)); + }); +} + +#[test] +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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + 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(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // We use the address of the asset as an identifier of the asset we want to transfer + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer { + currency_address: Address(asset_precompile_address.into()), + amount: 500_000_000_000_000u128.into(), + destination, + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()) + }) +} + +#[test] +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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let xtokens_precompile_address = H160::from_low_u64_be(2052); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // This time we transfer it through TransferMultiAsset + // Instead of the address, we encode directly the multilocation referencing the asset + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer_multiasset { + // We want to transfer the relay token + asset: Location::parent(), + amount: 500_000_000_000_000u128.into(), + destination, + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()); + }) +} + +#[test] +fn xtokens_precompiles_transfer_native() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let xtokens_precompile_address = H160::from_low_u64_be(2052); + + // Its address is + let asset_precompile_address = H160::from_low_u64_be(2050); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // We use the address of the asset as an identifier of the asset we want to transfer + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer { + currency_address: Address(asset_precompile_address), + amount: { 500 * UNIT }.into(), + destination: destination.clone(), + weight: 4_000_000, + }, + ) + .expect_cost(16000) + .expect_no_logs() + .execute_returns(()); + }) +} + +fn run_with_system_weight(w: Weight, mut assertions: F) +where + F: FnMut() -> (), +{ + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); +} + +#[test] +#[rustfmt::skip] +fn length_fee_is_sensible() { + use sp_runtime::testing::TestXt; + + // tests that length fee is sensible for a few hypothetical transactions + ExtBuilder::default().build().execute_with(|| { + let call = frame_system::Call::remark:: { remark: vec![] }; + let uxt: TestXt<_, ()> = TestXt::new(call, Some((1u64, ()))); + + let calc_fee = |len: u32| -> Balance { + moonbase_runtime::TransactionPayment::query_fee_details(uxt.clone(), len) + .inclusion_fee + .expect("fee should be calculated") + .len_fee + }; + + // editorconfig-checker-disable + // left: cost of length fee, right: size in bytes + // /------------- proportional component: O(N * 1B) + // | /- exponential component: O(N ** 3) + // | | + assert_eq!( 1_000_000_001, calc_fee(1)); + assert_eq!( 10_000_001_000, calc_fee(10)); + assert_eq!( 100_001_000_000, calc_fee(100)); + assert_eq!( 1_001_000_000_000, calc_fee(1_000)); + assert_eq!( 11_000_000_000_000, calc_fee(10_000)); // inflection point + assert_eq!( 1_100_000_000_000_000, calc_fee(100_000)); + assert_eq!( 1_001_000_000_000_000_000, calc_fee(1_000_000)); // one UNIT, ~ 1MB + assert_eq!( 1_000_010_000_000_000_000_000, calc_fee(10_000_000)); + assert_eq!(1_000_000_100_000_000_000_000_000, calc_fee(100_000_000)); + // editorconfig-checker-enable + }); +} + +#[test] +fn multiplier_can_grow_from_zero() { + use frame_support::traits::Get; + + let minimum_multiplier = moonbase_runtime::MinimumMultiplier::get(); + let target = moonbase_runtime::TargetBlockFullness::get() + * RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = moonbase_runtime::FastAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) +} + +#[test] +fn ethereum_invalid_transaction() { + ExtBuilder::default().build().execute_with(|| { + // Ensure an extrinsic not containing enough gas limit to store the transaction + // on chain is rejected. + assert_eq!( + Executive::apply_extrinsic(unchecked_eth_tx(INVALID_ETH_TX)), + Err( + sp_runtime::transaction_validity::TransactionValidityError::Invalid( + sp_runtime::transaction_validity::InvalidTransaction::Custom(0u8) + ) + ) + ); + }); +} + +#[test] +fn transfer_ed_0_substrate() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), (1 * UNIT) + (1 * WEI)), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // Substrate transfer + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 1 * UNIT, + )); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI); + }); +} + +#[test] +fn initial_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + + ExtBuilder::default().build().execute_with(|| { + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(8u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 10_000_000_000u128.into(), + Weight::from_parts(25_000_000u64, 0) + ) + ); + }); +} + +#[test] +fn transfer_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * UNIT) + (21_000 * BASE_FEE_GENISIS)) + (1 * WEI), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * UNIT).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI,); + }); +} + +#[test] +fn refund_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * UNIT) + (21_777 * BASE_FEE_GENISIS)), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer that zeroes ALICE + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * UNIT).into(), + gas_limit: 21_777u64, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // ALICE is refunded + assert_eq!( + Balances::free_balance(AccountId::from(ALICE)), + 777 * BASE_FEE_GENISIS, + ); + }); +} + +#[test] +fn author_does_not_receive_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * UNIT) + (21_000 * (500 * GIGAWEI)), + )]) + .build() + .execute_with(|| { + // Some block author as seen by pallet-evm. + let author = AccountId::from(>::find_author()); + // Currently the default impl of the evm uses `deposit_into_existing`. + // If we were to use this implementation, and for an author to receive eventual tips, + // the account needs to be somehow initialized, otherwise the deposit would fail. + Balances::make_free_balance_be(&author, 100 * UNIT); + + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * UNIT).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(300 * GIGAWEI), + max_priority_fee_per_gas: Some(U256::from(200 * GIGAWEI)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // Author free balance didn't change. + assert_eq!(Balances::free_balance(author), 100 * UNIT,); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_with_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS)), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * UNIT).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(2 * BASE_FEE_GENISIS), + max_priority_fee_per_gas: Some(U256::from(BASE_FEE_GENISIS)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + // Fee is 1 * base_fee + tip. + let fee = ((2 * BASE_FEE_GENISIS) * 21_000) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonbase_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_without_priority_fee() { + use fp_evm::FeeCalculator; + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * UNIT) + (21_000 * (2 * BASE_FEE_GENISIS)), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * UNIT).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + // Fee is 1 GWEI base fee. + let base_fee = TransactionPaymentAsGasPrice::min_gas_price().0; + assert_eq!(base_fee.as_u128(), BASE_FEE_GENISIS); // hint in case following asserts fail + let fee = (base_fee.as_u128() * 21_000u128) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonbase_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn root_can_change_default_xcm_vers() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (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, + }, + 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 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let source_id: moonbase_runtime::AssetId = source_location.clone().into(); + // Default XCM version is not set yet, so xtokens should fail because it does not + // know with which version to send + assert_noop!( + XTokens::transfer( + origin_of(AccountId::from(ALICE)), + moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest.clone())), + WeightLimit::Limited(4000000000.into()) + ), + orml_xtokens::Error::::XcmExecutionFailed + ); + + // Root sets the defaultXcm + assert_ok!(PolkadotXcm::force_default_xcm_version( + root_origin(), + Some(2) + )); + + // Now transferring does not fail + assert_ok!(XTokens::transfer( + origin_of(AccountId::from(ALICE)), + moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest)), + WeightLimit::Limited(4000000000.into()) + )); + }) +} + +#[test] +fn transactor_cannot_use_more_than_max_weight() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (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, + }, + 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(); + assert_ok!(XcmTransactor::register( + root_origin(), + AccountId::from(ALICE), + 0, + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + 1, + )); + + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonbase_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + vec![], + // 20000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonbase_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsCurrencyId( + moonbase_runtime::xcm_config::CurrencyId::ForeignAsset(source_id) + ), + fee_amount: None + }, + vec![], + // 20000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + }) +} + +#[test] +fn root_can_use_hrmp_manage() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .build() + .execute_with(|| { + // It fails sending, because the router does not work in test mode + // But all rest checks pass + assert_noop!( + XcmTransactor::hrmp_manage( + root_origin(), + HrmpOperation::Accept { + para_id: 2000u32.into() + }, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(10000) + }, + // 20000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: Some(Limited(20000.into())) + } + ), + pallet_xcm_transactor::Error::::ErrorValidating + ); + }) +} + +#[test] +fn transact_through_signed_precompile_works_v1() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::parent(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let xcm_transactor_v1_precompile_address = H160::from_low_u64_be(2054); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + Weight::from_parts(200_000, (xcm_primitives::DEFAULT_PROOF_SIZE) + 4000), + Some(4000.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + 1, + )); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v1_precompile_address, + XcmTransactorV1PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 15000, + call: bytes.into(), + }, + ) + .expect_cost(17559) + .expect_no_logs() + .execute_returns(()); + }); +} + +#[test] +fn transact_through_signed_precompile_works_v2() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::parent(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .expect_cost(17559) + .expect_no_logs() + .execute_returns(()); + }); +} + +#[test] +fn transact_through_signed_cannot_send_to_local_chain() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::here(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .execute_reverts(|output| { + from_utf8(&output) + .unwrap() + .contains("Dispatched call failed with error:") + && from_utf8(&output).unwrap().contains("ErrorValidating") + }); + }); +} + +// Test to ensure we can use either in crowdloan rewards without worrying for migrations +#[test] +fn account_id_32_encodes_like_32_byte_u8_slice() { + let account_as_account_id_32: sp_runtime::AccountId32 = [1u8; 32].into(); + let account_as_slice = [1u8; 32]; + assert_eq!(account_as_account_id_32.encode(), account_as_slice.encode()); +} + +#[test] +fn author_mapping_precompile_associate_update_and_clear() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .build() + .execute_with(|| { + let author_mapping_precompile_address = H160::from_low_u64_be(2055); + let first_nimbus_id: NimbusId = + sp_core::sr25519::Public::unchecked_from([1u8; 32]).into(); + let first_vrf_id: session_keys_primitives::VrfId = + sp_core::sr25519::Public::unchecked_from([1u8; 32]).into(); + let second_nimbus_id: NimbusId = + sp_core::sr25519::Public::unchecked_from([2u8; 32]).into(); + let second_vrf_id: session_keys_primitives::VrfId = + sp_core::sr25519::Public::unchecked_from([2u8; 32]).into(); + + // Associate it + Precompiles::new() + .prepare_test( + ALICE, + author_mapping_precompile_address, + AuthorMappingPCall::add_association { + nimbus_id: [1u8; 32].into(), + }, + ) + .expect_cost(15144) + .expect_no_logs() + .execute_returns(()); + + let expected_associate_event = + RuntimeEvent::AuthorMapping(pallet_author_mapping::Event::KeysRegistered { + nimbus_id: first_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + keys: first_vrf_id.clone(), + }); + assert_eq!(last_event(), expected_associate_event); + + // Update it + Precompiles::new() + .prepare_test( + ALICE, + author_mapping_precompile_address, + AuthorMappingPCall::update_association { + old_nimbus_id: [1u8; 32].into(), + new_nimbus_id: [2u8; 32].into(), + }, + ) + .expect_cost(14725) + .expect_no_logs() + .execute_returns(()); + + let expected_update_event = + RuntimeEvent::AuthorMapping(pallet_author_mapping::Event::KeysRotated { + new_nimbus_id: second_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + new_keys: second_vrf_id.clone(), + }); + assert_eq!(last_event(), expected_update_event); + + // Clear it + Precompiles::new() + .prepare_test( + ALICE, + author_mapping_precompile_address, + AuthorMappingPCall::clear_association { + nimbus_id: [2u8; 32].into(), + }, + ) + .expect_cost(15172) + .expect_no_logs() + .execute_returns(()); + + let expected_clear_event = + RuntimeEvent::AuthorMapping(pallet_author_mapping::Event::KeysRemoved { + nimbus_id: second_nimbus_id, + account_id: AccountId::from(ALICE), + keys: second_vrf_id, + }); + assert_eq!(last_event(), expected_clear_event); + }); +} + +#[test] +fn author_mapping_register_and_set_keys() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .build() + .execute_with(|| { + let author_mapping_precompile_address = H160::from_low_u64_be(2055); + let first_nimbus_id: NimbusId = + sp_core::sr25519::Public::unchecked_from([1u8; 32]).into(); + let first_vrf_key: session_keys_primitives::VrfId = + sp_core::sr25519::Public::unchecked_from([3u8; 32]).into(); + let second_nimbus_id: NimbusId = + sp_core::sr25519::Public::unchecked_from([2u8; 32]).into(); + let second_vrf_key: session_keys_primitives::VrfId = + sp_core::sr25519::Public::unchecked_from([4u8; 32]).into(); + + // Associate it + Precompiles::new() + .prepare_test( + ALICE, + author_mapping_precompile_address, + AuthorMappingPCall::set_keys { + keys: solidity::encode_arguments(( + H256::from([1u8; 32]), + H256::from([3u8; 32]), + )) + .into(), + }, + ) + .expect_cost(16273) + .expect_no_logs() + .execute_returns(()); + + let expected_associate_event = + RuntimeEvent::AuthorMapping(pallet_author_mapping::Event::KeysRegistered { + nimbus_id: first_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + keys: first_vrf_key.clone(), + }); + assert_eq!(last_event(), expected_associate_event); + + // Update it + Precompiles::new() + .prepare_test( + ALICE, + author_mapping_precompile_address, + AuthorMappingPCall::set_keys { + keys: solidity::encode_arguments(( + H256::from([2u8; 32]), + H256::from([4u8; 32]), + )) + .into(), + }, + ) + .expect_cost(16273) + .expect_no_logs() + .execute_returns(()); + + let expected_update_event = + RuntimeEvent::AuthorMapping(pallet_author_mapping::Event::KeysRotated { + new_nimbus_id: second_nimbus_id.clone(), + account_id: AccountId::from(ALICE), + new_keys: second_vrf_key.clone(), + }); + assert_eq!(last_event(), expected_update_event); + }); +} + +#[test] +fn test_xcm_utils_ml_tp_account() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_address_parent: H160 = + ParentIsPreset::::convert_location(&Location::parent()) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: Location::parent(), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parent)); + + let parachain_2000_multilocation = Location::new(1, [Parachain(2000)]); + let expected_address_parachain: H160 = + SiblingParachainConvertsVia::::convert_location( + ¶chain_2000_multilocation, + ) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: parachain_2000_multilocation, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parachain)); + + let alice_in_parachain_2000_multilocation = Location::new( + 1, + [ + Parachain(2000), + AccountKey20 { + network: None, + key: ALICE, + }, + ], + ); + let expected_address_alice_in_parachain_2000 = + xcm_builder::HashedDescription::< + AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&alice_in_parachain_2000_multilocation) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: alice_in_parachain_2000_multilocation, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_alice_in_parachain_2000)); + }); +} + +#[test] +fn test_xcm_utils_weight_message() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_weight = + XcmWeight::::clear_origin().ref_time(); + + let message: Vec = xcm::VersionedXcm::<()>::V4(Xcm(vec![ClearOrigin])).encode(); + + let input = XcmUtilsPCall::weight_message { + message: message.into(), + }; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(0) + .expect_no_logs() + .execute_returns(expected_weight); + }); +} + +#[test] +fn test_xcm_utils_get_units_per_second() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let location = SelfReserve::get(); + + let input = XcmUtilsPCall::get_units_per_second { location }; + + let expected_units = + WEIGHT_REF_TIME_PER_SECOND as u128 * moonbase_runtime::currency::WEIGHT_FEE; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(expected_units); + }); +} + +#[test] +fn precompile_existence() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + 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, + ] + .into_iter() + .map(H160::from_low_u64_be) + .collect(); + + for i in 0..3000 { + let address = H160::from_low_u64_be(i); + + if precompile_addresses.contains(&address) { + assert!( + is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return true", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_some(), + "execute({},..) should return Some(_)", + i + ); + } else { + assert!( + !is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return false", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_none(), + "execute({},..) should return None", + i + ); + } + } + }); +} + +#[test] +fn removed_precompiles() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + let removed_precompiles = [1025, 2051, 2062, 2063]; + + for i in 1..3000 { + let address = H160::from_low_u64_be(i); + + if !is_precompile_or_fail::(address, 100_000u64).expect("to be ok") { + continue; + } + + if !removed_precompiles.contains(&i) { + assert!( + match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} should be an active precompile" + ); + continue; + } + + assert!( + !match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} shouldn't be an active precompile" + ); + + precompiles + .prepare_test(Alice, address, []) + .execute_reverts(|out| out == b"Removed precompile"); + } + }) +} + +#[test] +fn substrate_based_fees_zero_txn_costs_only_base_extrinsic() { + use frame_support::dispatch::{DispatchInfo, Pays}; + use moonbase_runtime::{currency, EXTRINSIC_BASE_WEIGHT}; + + ExtBuilder::default().build().execute_with(|| { + let size_bytes = 0; + let tip = 0; + let dispatch_info = DispatchInfo { + weight: Weight::zero(), + class: DispatchClass::Normal, + pays_fee: Pays::Yes, + }; + + assert_eq!( + TransactionPayment::compute_fee(size_bytes, &dispatch_info, tip), + EXTRINSIC_BASE_WEIGHT.ref_time() as u128 * currency::WEIGHT_FEE, + ); + }); +} + +#[test] +fn deal_with_fees_handles_tip() { + use frame_support::traits::OnUnbalanced; + use moonbase_runtime::{DealWithFees, Treasury}; + + ExtBuilder::default().build().execute_with(|| { + // This test checks the functionality of the `DealWithFees` trait implementation in the runtime. + // It simulates a scenario where a fee and a tip are issued to an account and ensures that the + // treasury receives the correct amount (20% of the total), and the rest is burned (80%). + // + // The test follows these steps: + // 1. It issues a fee of 100 and a tip of 1000. + // 2. It checks the total supply before the fee and tip are dealt with, which should be 1_100. + // 3. It checks that the treasury's balance is initially 0. + // 4. It calls `DealWithFees::on_unbalanceds` with the fee and tip. + // 5. It checks that the treasury's balance is now 220 (20% of the fee and tip). + // 6. It checks that the total supply has decreased by 880 (80% of the fee and tip), indicating + // that this amount was burned. + let fee = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(100); + let tip = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(1000); + + let total_supply_before = Balances::total_issuance(); + assert_eq!(total_supply_before, 1_100); + assert_eq!(Balances::free_balance(&Treasury::account_id()), 0); + + DealWithFees::on_unbalanceds(vec![fee, tip].into_iter()); + + // treasury should have received 20% + assert_eq!(Balances::free_balance(&Treasury::account_id()), 220); + + // verify 80% burned + let total_supply_after = Balances::total_issuance(); + assert_eq!(total_supply_before - total_supply_after, 880); + }); +} + +#[test] +fn evm_revert_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + // Batch a transfer followed by an invalid call to batch. + // Thus BatchAll will revert the transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + input: BatchPCall::batch_all { + to: vec![Address(BOB.into()), Address(batch_precompile_address)].into(), + value: vec![U256::from(1 * UNIT), U256::zero()].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 0, "there should be no transfer event"); + }); +} + +#[test] +fn evm_success_keeps_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + input: BatchPCall::batch_all { + to: vec![Address(BOB.into())].into(), + value: vec![U256::from(1 * UNIT)].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: U256::from(BASE_FEE_GENISIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 1, "there should be 1 transfer event"); + }); +} + +#[test] +fn validate_transaction_fails_on_filtered_call() { + use sp_runtime::transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidityError, + }; + use sp_transaction_pool::runtime_api::runtime_decl_for_tagged_transaction_queue::TaggedTransactionQueueV3; // editorconfig-checker-disable-line + + ExtBuilder::default().build().execute_with(|| { + let xt = UncheckedExtrinsic::new_unsigned( + pallet_evm::Call::::call { + source: Default::default(), + target: H160::default(), + input: Vec::new(), + value: Default::default(), + gas_limit: Default::default(), + max_fee_per_gas: Default::default(), + max_priority_fee_per_gas: Default::default(), + nonce: Default::default(), + access_list: Default::default(), + } + .into(), + ); + + assert_eq!( + Runtime::validate_transaction(TransactionSource::External, xt, Default::default(),), + Err(TransactionValidityError::Invalid(InvalidTransaction::Call)), + ); + }); +} + +#[cfg(test)] +mod fee_tests { + use super::*; + use fp_evm::FeeCalculator; + use frame_support::{ + traits::{ConstU128, OnFinalize}, + weights::{ConstantMultiplier, WeightToFee}, + }; + use moonbase_runtime::{ + currency, BlockWeights, FastAdjustingFeeUpdate, LengthToFee, MinimumMultiplier, + TargetBlockFullness, NORMAL_WEIGHT, WEIGHT_PER_GAS, + }; + use sp_runtime::{BuildStorage, FixedPointNumber, Perbill}; + + fn run_with_system_weight(w: Weight, mut assertions: F) + where + F: FnMut() -> (), + { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); + } + + #[test] + fn test_multiplier_can_grow_from_zero() { + let minimum_multiplier = MinimumMultiplier::get(); + let target = TargetBlockFullness::get() + * BlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = FastAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) + } + + #[test] + fn test_fee_calculation() { + let base_extrinsic = BlockWeights::get() + .get(DispatchClass::Normal) + .base_extrinsic; + let multiplier = sp_runtime::FixedU128::from_float(0.999000000000000000); + let extrinsic_len = 100u32; + let extrinsic_weight = 5_000u64; + let tip = 42u128; + type WeightToFeeImpl = + ConstantMultiplier>; + type LengthToFeeImpl = LengthToFee; + + // base_fee + (multiplier * extrinsic_weight_fee) + extrinsic_length_fee + tip + let expected_fee = + WeightToFeeImpl::weight_to_fee(&base_extrinsic) + + multiplier.saturating_mul_int(WeightToFeeImpl::weight_to_fee( + &Weight::from_parts(extrinsic_weight, 1), + )) + LengthToFeeImpl::weight_to_fee(&Weight::from_parts(extrinsic_len as u64, 1)) + + tip; + + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); + let actual_fee = TransactionPayment::compute_fee( + extrinsic_len, + &frame_support::dispatch::DispatchInfo { + class: DispatchClass::Normal, + pays_fee: frame_support::dispatch::Pays::Yes, + weight: Weight::from_parts(extrinsic_weight, 1), + }, + tip, + ); + + assert_eq!( + expected_fee, + actual_fee, + "The actual fee did not match the expected fee, diff {}", + actual_fee - expected_fee + ); + }); + } + + #[test] + fn test_min_gas_price_is_deterministic() { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + let multiplier = sp_runtime::FixedU128::from_u32(1); + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); + let actual = TransactionPaymentAsGasPrice::min_gas_price().0; + let expected: U256 = multiplier + .saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128)) + .into(); + + assert_eq!(expected, actual); + }); + } + + #[test] + fn test_min_gas_price_has_no_precision_loss_from_saturating_mul_int() { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + let multiplier_1 = sp_runtime::FixedU128::from_float(0.999593900000000000); + let multiplier_2 = sp_runtime::FixedU128::from_float(0.999593200000000000); + + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier_1); + let a = TransactionPaymentAsGasPrice::min_gas_price(); + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier_2); + let b = TransactionPaymentAsGasPrice::min_gas_price(); + + assert_ne!( + a, b, + "both gas prices were equal, unexpected precision loss incurred" + ); + }); + } + + #[test] + fn test_fee_scenarios() { + use sp_runtime::FixedU128; + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + let weight_fee_per_gas = currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128); + let sim = |start_gas_price: u128, fullness: Perbill, num_blocks: u64| -> U256 { + let start_multiplier = + FixedU128::from_rational(start_gas_price, weight_fee_per_gas); + pallet_transaction_payment::NextFeeMultiplier::::set(start_multiplier); + + let block_weight = NORMAL_WEIGHT * fullness; + + for i in 0..num_blocks { + System::set_block_number(i as u32); + System::set_block_consumed_resources(block_weight, 0); + TransactionPayment::on_finalize(i as u32); + } + + TransactionPaymentAsGasPrice::min_gas_price().0 + }; + + // The expected values are the ones observed during test execution, + // they are expected to change when parameters that influence + // the fee calculation are changed, and should be updated accordingly. + // If a test fails when nothing specific to fees has changed, + // it may indicate an unexpected collateral effect and should be investigated + + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(0), 1), + U256::from(998_002_000), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(25), 1), + U256::from(999_000_500), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(50), 1), + U256::from(1_000_000_000), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(100), 1), + U256::from(1_002_002_000), + ); + + // 1 "real" hour (at 12-second blocks) + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(0), 300), + U256::from(548_811_855), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(25), 300), + U256::from(740_818_257), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(50), 300), + U256::from(1_000_000_000), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(100), 300), + U256::from(1_822_118_072u128), + ); + + // 1 "real" day (at 12-second blocks) + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(0), 7200), + U256::from(125_000_000), // lower bound enforced + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(25), 7200), + U256::from(125_000_000), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(50), 7200), + U256::from(1_000_000_000u128), + ); + assert_eq!( + sim(1_000_000_000, Perbill::from_percent(100), 7200), + U256::from(125_000_000_000_000u128), // upper bound enforced + ); + }); + } +} diff --git a/tracing/2902/runtime/moonbase/tests/runtime_apis.rs b/tracing/2902/runtime/moonbase/tests/runtime_apis.rs new file mode 100644 index 00000000..9ed29655 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/runtime_apis.rs @@ -0,0 +1,392 @@ +// 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 . + +//! Moonbase Runtime Api Integration Tests + +mod common; +use common::*; + +use fp_evm::GenesisAccount; +use frame_support::assert_ok; +use nimbus_primitives::NimbusId; +use pallet_evm::{Account as EVMAccount, AddressMapping, FeeCalculator}; +use sp_core::{ByteArray, H160, H256, U256}; + +use fp_rpc::runtime_decl_for_ethereum_runtime_rpc_api::EthereumRuntimeRPCApi; +use moonbeam_rpc_primitives_txpool::runtime_decl_for_tx_pool_runtime_api::TxPoolRuntimeApi; +use nimbus_primitives::runtime_decl_for_nimbus_api::NimbusApi; +use std::{collections::BTreeMap, str::FromStr}; + +#[test] +fn ethereum_runtime_rpc_api_chain_id() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!(Runtime::chain_id(), CHAIN_ID); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_basic() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * UNIT)]) + .build() + .execute_with(|| { + assert_eq!( + Runtime::account_basic(H160::from(ALICE)), + EVMAccount { + balance: U256::from(2_000 * UNIT), + nonce: U256::zero() + } + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_gas_price() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!( + Runtime::gas_price(), + TransactionPaymentAsGasPrice::min_gas_price().0 + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_code_at() { + let address = H160::from(EVM_CONTRACT); + let code: Vec = vec![1, 2, 3, 4, 5]; + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: code.clone(), + nonce: Default::default(), + storage: Default::default(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::account_code_at(address), code); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_author() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .build() + .execute_with(|| { + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + assert_eq!(Runtime::author(), H160::from(ALICE)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_storage_at() { + let address = H160::from(EVM_CONTRACT); + let mut key = [0u8; 32]; + key[31..32].copy_from_slice(&[6u8][..]); + let mut value = [0u8; 32]; + value[31..32].copy_from_slice(&[7u8][..]); + let item = H256::from_slice(&key[..]); + let mut storage: BTreeMap = BTreeMap::new(); + storage.insert(H256::from_slice(&key[..]), item); + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: Vec::new(), + nonce: Default::default(), + storage: storage.clone(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::storage_at(address, U256::from(6)), item); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_call() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 2_000 * UNIT), + ]) + .build() + .execute_with(|| { + let execution_result = Runtime::call( + H160::from(ALICE), // from + H160::from(BOB), // to + Vec::new(), // data + U256::from(1000u64), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_create() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * UNIT)]) + .build() + .execute_with(|| { + let execution_result = Runtime::create( + H160::from(ALICE), // from + vec![0, 1, 1, 0], // data + U256::zero(), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_transaction_statuses() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24ff3a9cf04c71dbc94d0b566f7a27b94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 2_000 * UNIT), + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .build() + .execute_with(|| { + let _result = Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)); + rpc_run_to_block(2); + let statuses = + Runtime::current_transaction_statuses().expect("Transaction statuses result."); + assert_eq!(statuses.len(), 1); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_block() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .build() + .execute_with(|| { + rpc_run_to_block(2); + let block = Runtime::current_block().expect("Block result."); + assert_eq!(block.header.number, U256::from(1u8)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_receipts() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24ff3a9cf04c71dbc94d0b566f7a27b94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 2_000 * UNIT), + (AccountId::from(ALICE), 2_000 * UNIT), + (AccountId::from(BOB), 1_000 * UNIT), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * UNIT, + )]) + .build() + .execute_with(|| { + let _result = Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)); + rpc_run_to_block(2); + let receipts = Runtime::current_receipts().expect("Receipts result."); + assert_eq!(receipts.len(), 1); + }); +} + +#[test] +fn txpool_runtime_api_extrinsic_filter() { + ExtBuilder::default().build().execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * UNIT, + } + .into(), + ); + + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let txpool = >::extrinsic_filter( + vec![eth_uxt.clone(), non_eth_uxt.clone()], + vec![unchecked_eth_tx(VALID_ETH_TX), non_eth_uxt], + ); + assert_eq!(txpool.ready.len(), 1); + assert_eq!(txpool.future.len(), 1); + }); +} + +#[test] +fn can_author_when_selected_is_empty() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 20_000_000 * UNIT), + (AccountId::from(BOB), 10_000_000 * UNIT), + ]) + .with_collators(vec![(AccountId::from(ALICE), 2_000_000 * UNIT)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 1); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: Default::default(), + parent_hash: Default::default(), + state_root: Default::default(), + }; + + // Base case: ALICE can author blocks when she is the only candidate + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Remove ALICE from candidate pool, leaving the candidate_pool empty + assert_ok!(ParachainStaking::go_offline(origin_of(AccountId::from( + ALICE + )))); + + // Need to fast forward to right before the next session, which is when selected candidates + // will be updated. We want to test the creation of the first block of the next session. + run_to_block(1799, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1799, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Check that it works as expected after session update + run_to_block(1800, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1800, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + }); +} + +// Some Priority-related test ideas +// 1. Eth balance transfer with various gas prices. Priority == gas price +// 2. Eth contract call with various gas prices. Priority == gas price +// 3. System remark with no tip -> calculate expected priority from gas weight mapping +// 4. System remark with tip. +// 5. Operational dispatch has higher priority than normal for otherwise same transactions diff --git a/tracing/2902/runtime/moonbase/tests/xcm_mock/mod.rs b/tracing/2902/runtime/moonbase/tests/xcm_mock/mod.rs new file mode 100644 index 00000000..f556bc47 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/xcm_mock/mod.rs @@ -0,0 +1,272 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +pub mod parachain; +pub mod relay_chain; +pub mod statemint_like; +use cumulus_primitives_core::ParaId; +use pallet_xcm_transactor::relay_indices::*; +use sp_runtime::traits::AccountIdConversion; +use sp_runtime::{AccountId32, BuildStorage}; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +use polkadot_runtime_parachains::configuration::{ + GenesisConfig as ConfigurationGenesisConfig, HostConfiguration, +}; +use polkadot_runtime_parachains::paras::{ + GenesisConfig as ParasGenesisConfig, ParaGenesisArgs, ParaKind, +}; + +use sp_core::{H160, U256}; +use std::{collections::BTreeMap, str::FromStr}; + +pub const PARAALICE: [u8; 20] = [1u8; 20]; +pub const RELAYALICE: AccountId32 = AccountId32::new([0u8; 32]); +pub const RELAYBOB: AccountId32 = AccountId32::new([2u8; 32]); + +pub fn para_a_account() -> AccountId32 { + ParaId::from(1).into_account_truncating() +} + +pub fn para_b_account() -> AccountId32 { + ParaId::from(2).into_account_truncating() +} + +pub fn para_a_account_20() -> parachain::AccountId { + ParaId::from(1).into_account_truncating() +} + +pub fn evm_account() -> H160 { + H160::from_str("1000000000000000000000000000000000000001").unwrap() +} + +pub fn mock_para_genesis_info() -> ParaGenesisArgs { + ParaGenesisArgs { + genesis_head: vec![1u8].into(), + validation_code: vec![1u8].into(), + para_kind: ParaKind::Parachain, + } +} + +pub fn mock_relay_config() -> HostConfiguration { + HostConfiguration:: { + hrmp_channel_max_capacity: u32::MAX, + hrmp_channel_max_total_size: u32::MAX, + hrmp_max_parachain_inbound_channels: 10, + hrmp_max_parachain_outbound_channels: 10, + hrmp_channel_max_message_size: u32::MAX, + // Changed to avoid aritmetic errors within hrmp_close + max_downward_message_size: 100_000u32, + ..Default::default() + } +} + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(2), + } +} + +decl_test_parachain! { + pub struct ParaC { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(3), + } +} + +decl_test_parachain! { + pub struct Statemint { + Runtime = statemint_like::Runtime, + XcmpMessageHandler = statemint_like::MsgQueue, + DmpMessageHandler = statemint_like::MsgQueue, + new_ext = statemint_ext(4), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + RuntimeCall = relay_chain::RuntimeCall, + RuntimeEvent = relay_chain::RuntimeEvent, + XcmConfig = relay_chain::XcmConfig, + MessageQueue = relay_chain::MessageQueue, + System = relay_chain::System, + new_ext = relay_ext(vec![1, 2, 3, 4]), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + (3, ParaC), + (4, Statemint), + ], + } +} + +pub const INITIAL_BALANCE: u128 = 10_000_000_000_000_000; + +pub const INITIAL_EVM_BALANCE: u128 = 0; +pub const INITIAL_EVM_NONCE: u32 = 1; + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(PARAALICE.into(), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_xcm_transactor::GenesisConfig:: { + // match relay runtime construct_runtime order in xcm_mock::relay_chain + relay_indices: RelayChainIndices { + hrmp: 6u8, + init_open_channel: 0u8, + accept_open_channel: 1u8, + close_channel: 2u8, + cancel_open_request: 6u8, + ..Default::default() + }, + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); + + // EVM accounts are self-sufficient. + let mut evm_accounts = BTreeMap::new(); + evm_accounts.insert( + evm_account(), + fp_evm::GenesisAccount { + nonce: U256::from(INITIAL_EVM_NONCE), + balance: U256::from(INITIAL_EVM_BALANCE), + storage: Default::default(), + code: vec![ + 0x00, // STOP + ], + }, + ); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn statemint_ext(para_id: u32) -> sp_io::TestExternalities { + use statemint_like::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (RELAYALICE.into(), INITIAL_BALANCE), + (RELAYBOB.into(), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext(paras: Vec) -> sp_io::TestExternalities { + use relay_chain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(RELAYALICE, INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let para_genesis: Vec<(ParaId, ParaGenesisArgs)> = paras + .iter() + .map(|¶_id| (para_id.into(), mock_para_genesis_info())) + .collect(); + + let genesis_config = ConfigurationGenesisConfig:: { + config: mock_relay_config(), + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = ParasGenesisConfig:: { + paras: para_genesis, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + }); + ext +} +pub type RelayChainPalletXcm = pallet_xcm::Pallet; +pub type Hrmp = polkadot_runtime_parachains::hrmp::Pallet; + +pub type StatemintBalances = pallet_balances::Pallet; +pub type StatemintChainPalletXcm = pallet_xcm::Pallet; +pub type StatemintAssets = pallet_assets::Pallet; + +pub type ParachainPalletXcm = pallet_xcm::Pallet; +pub type Assets = pallet_assets::Pallet; + +pub type Treasury = pallet_treasury::Pallet; +pub type AssetManager = pallet_asset_manager::Pallet; +pub type XTokens = orml_xtokens::Pallet; +pub type RelayBalances = pallet_balances::Pallet; +pub type ParaBalances = pallet_balances::Pallet; +pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/tracing/2902/runtime/moonbase/tests/xcm_mock/parachain.rs b/tracing/2902/runtime/moonbase/tests/xcm_mock/parachain.rs new file mode 100644 index 00000000..20c6d4d4 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/xcm_mock/parachain.rs @@ -0,0 +1,1129 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use frame_support::{ + construct_runtime, + dispatch::GetDispatchInfo, + ensure, parameter_types, + traits::{ + AsEnsureOriginWithArg, ConstU32, Everything, Get, InstanceFilter, Nothing, PalletInfoAccess, + }, + weights::Weight, + PalletId, +}; + +use frame_system::{pallet_prelude::BlockNumberFor, EnsureNever, EnsureRoot}; +use pallet_xcm::migration::v1::VersionUncheckedMigrateToV1; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use sp_core::H256; +use sp_runtime::{ + traits::{BlakeTwo256, Hash, IdentityLookup, MaybeEquivalence, Zero}, + Permill, +}; +use sp_std::{convert::TryFrom, prelude::*}; +use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; + +use cumulus_primitives_core::relay_chain::HrmpChannelId; +use orml_traits::parameter_type_with_key; +use pallet_ethereum::PostLogContent; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain::primitives::{Id as ParaId, Sibling}; +use xcm::latest::{ + AssetId as XcmAssetId, Error as XcmError, ExecuteXcm, + Junction::{PalletInstance, Parachain}, + Location, NetworkId, Outcome, Xcm, +}; +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, IsConcrete, + NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, WithComputedOrigin, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; + +pub use moonbase_runtime::xcm_config::AssetType; +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; +use scale_info::TypeInfo; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; + +pub type AccountId = moonbeam_core_primitives::AccountId; +pub type Balance = u128; +pub type AssetId = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 0; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +pub type ForeignAssetInstance = (); +pub type LocalAssetInstance = pallet_assets::Instance1; + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 10; // Does not really matter as this will be only called by root + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + AccountKey20Aliases, + // The rest of multilocations convert via hashing it + xcm_builder::HashedDescription< + AccountId, + xcm_builder::DescribeFamily, + >, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + SignedAccountKey20AsNative, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1u64, 1u64); + pub MaxInstructions: u32 = 100; +} + +// Instructing how incoming xcm assets will be handled +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId32 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +/// The transactor for our own chain currency. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + IsConcrete, + // We can convert the Locations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// These will be our transactors +// We use both transactors +pub type AssetTransactors = (LocalAssetTransactor, ForeignFungiblesTransactor); + +pub type XcmRouter = super::ParachainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +pub type XcmFeesToAccount_ = xcm_primitives::XcmFeesToAccount< + Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +parameter_types! { + // We cannot skip the native trader for some specific tests, so we will have to work with + // a native trader that charges same number of units as weight + // We use both the old and new anchoring logics + pub ParaTokensPerSecond: (XcmAssetId, u128, u128) = ( + AssetId(SelfReserve::get()), + 1000000000000, + 0, + ); +} + +parameter_types! { + pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + + // New Self Reserve location, defines the multilocation identifiying the self-reserve currency + // This is used to match it also against our Balances pallet when we receive such + // a Location: (Self Balances pallet index) + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +use frame_system::RawOrigin; +use sp_runtime::traits::PostDispatchInfoOf; +use sp_runtime::DispatchErrorWithPostInfo; +use xcm_executor::traits::CallDispatcher; +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = orml_xcm_support::MultiNativeAsset< + xcm_primitives::AbsoluteAndRelativeReserve, + >; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + // We use three traders + // When we receive either representation of the self-reserve asset, + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + FixedRateOfFungible, + xcm_primitives::FirstAssetTrader, + ); + + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + SelfReserve, + ForeignAsset(AssetId), +} + +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + // For now and until Xtokens is adapted to handle 0.9.16 version we use + // the old anchoring here + // This is not a problem in either cases, since the view of the destination + // chain does not change + // TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxAssetsForTransfer: usize = 2; + pub SelfLocation: Location = Location::here(); + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(MsgQueue::parachain_id().into()) + ].into() + }; +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + (1, Some(Parachain(4u32))) => Some(50u128), + _ => None, + } + }; +} + +// The XCM message wrapper wrapper +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdConvert = + CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const ProposalBondMinimum: Balance = 0; + pub const SpendPeriod: u32 = 0; + pub const TreasuryId: PalletId = PalletId(*b"pc/trsry"); + pub const MaxApprovals: u32 = 100; + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = MaxApprovals; + type WeightInfo = (); + type SpendFunds = (); + type ProposalBondMaximum = (); + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Same as Polkadot + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<0>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = ArgumentsBenchmarkHelper; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} + +// Pallet to provide the version, used to test runtime upgrade version changes +#[frame_support::pallet] +pub mod mock_version_changer { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_version)] + pub(super) type CurrentVersion = StorageValue<_, XcmVersion, ValueQuery>; + + impl Get for Pallet { + fn get() -> XcmVersion { + Self::current_version() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + VersionChanged(XcmVersion), + } + + impl Pallet { + pub fn set_version(version: XcmVersion) { + CurrentVersion::::put(version); + Self::deposit_event(Event::VersionChanged(version)); + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl mock_version_changer::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +pub type LocalOriginToLocation = + xcm_primitives::SignedToAccountId20; + +parameter_types! { + pub MatcherLocation: Location = Location::here(); +} + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = frame_support::traits::Nothing; + type XcmExecutor = XcmExecutor; + // Do not allow teleports + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // We use a custom one to test runtime ugprades + type AdvertisedXcmVersion = XcmVersioner; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +use frame_support::pallet_prelude::DispatchResult; +impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { + fn create_foreign_asset( + asset: AssetId, + min_balance: Balance, + metadata: AssetMetadata, + is_sufficient: bool, + ) -> DispatchResult { + Assets::force_create( + RuntimeOrigin::root(), + asset, + AssetManager::account_id(), + is_sufficient, + min_balance, + )?; + + Assets::force_set_metadata( + RuntimeOrigin::root(), + asset, + metadata.name, + metadata.symbol, + metadata.decimals, + false, + ) + } + + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into())?; + + Ok(()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, +} + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetMetadata; + type ForeignAssetType = AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = EnsureRoot; + type WeightInfo = (); +} + +// 1 ROC/WND should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = MockTransactors; + type DerivativeAddressRegistrationOrigin = EnsureRoot; + type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdToLocation = + CurrencyIdToLocation>; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type XcmSender = XcmRouter; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; + type WeightInfo = (); + type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1000; +} +impl pallet_timestamp::Config for Runtime { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +use sp_core::U256; + +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 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 = + BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT); +} + +impl pallet_evm::Config for Runtime { + type FeeCalculator = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + + type CallOrigin = pallet_evm::EnsureAddressRoot; + type WithdrawOrigin = pallet_evm::EnsureAddressNever; + + type AddressMapping = pallet_evm::IdentityAddressMapping; + type Currency = Balances; + type Runner = pallet_evm::runner::stack::Runner; + + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = (); + type PrecompilesValue = (); + type ChainId = (); + type BlockGasLimit = BlockGasLimit; + type OnChargeTransaction = (); + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type FindAuthor = (); + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; +} + +pub struct NormalFilter; +impl frame_support::traits::Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + _ => true, + } + } +} + +// We need to use the encoding from the relay mock runtime +#[derive(Encode, Decode)] +pub enum RelayCall { + #[codec(index = 5u8)] + // the index should match the position of the module in `construct_runtime!` + Utility(UtilityCall), + #[codec(index = 6u8)] + // the index should match the position of the module in `construct_runtime!` + Hrmp(HrmpCall), +} + +#[derive(Encode, Decode)] +pub enum UtilityCall { + #[codec(index = 1u8)] + AsDerivative(u16), +} + +// HRMP call encoding, needed for xcm transactor pallet +#[derive(Encode, Decode)] +pub enum HrmpCall { + #[codec(index = 0u8)] + InitOpenChannel(ParaId, u32, u32), + #[codec(index = 1u8)] + AcceptOpenChannel(ParaId), + #[codec(index = 2u8)] + CloseChannel(HrmpChannelId), + #[codec(index = 6u8)] + CancelOpenRequest(HrmpChannelId, u32), +} + +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum MockTransactors { + Relay, +} + +impl xcm_primitives::XcmTransact for MockTransactors { + fn destination(self) -> Location { + match self { + MockTransactors::Relay => Location::parent(), + } + } +} + +impl xcm_primitives::UtilityEncodeCall for MockTransactors { + fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { + match self { + MockTransactors::Relay => match call { + xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => { + let mut call = + RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode(); + call.append(&mut b.clone()); + call + } + }, + } + } +} + +pub struct MockHrmpEncoder; +impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder { + fn hrmp_encode_call( + call: xcm_primitives::HrmpAvailableCalls, + ) -> Result, xcm::latest::Error> { + match call { + xcm_primitives::HrmpAvailableCalls::InitOpenChannel(a, b, c) => Ok(RelayCall::Hrmp( + HrmpCall::InitOpenChannel(a.clone(), b.clone(), c.clone()), + ) + .encode()), + xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::AcceptOpenChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => { + Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode()) + } + } + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} +parameter_types! { + pub ReservedXcmpWeight: Weight = Weight::from_parts(u64::max_value(), 0); +} + +#[derive( + Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo, +)] +pub enum ProxyType { + NotAllowed = 0, + Any = 1, +} + +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType {} + +impl InstanceFilter for ProxyType { + fn filter(&self, _c: &RuntimeCall) -> bool { + match self { + ProxyType::NotAllowed => false, + ProxyType::Any => true, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + +impl Default for ProxyType { + fn default() -> Self { + Self::NotAllowed + } +} + +parameter_types! { + pub const ProxyCost: u64 = 1; +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyCost; + type ProxyDepositFactor = ProxyCost; + type MaxProxies = ConstU32<32>; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ProxyCost; + type AnnouncementDepositFactor = ProxyCost; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will iMmediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlockU32; + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + XcmVersioner: mock_version_changer, + + PolkadotXcm: pallet_xcm, + Assets: pallet_assets, + CumulusXcm: cumulus_pallet_xcm, + XTokens: orml_xtokens, + AssetManager: pallet_asset_manager, + XcmTransactor: pallet_xcm_transactor, + Treasury: pallet_treasury, + LocalAssets: pallet_assets::, + Proxy: pallet_proxy, + + Timestamp: pallet_timestamp, + EVM: pallet_evm, + Ethereum: pallet_ethereum, + EthereumXcm: pallet_ethereum_xcm, + } +); + +pub(crate) fn para_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion}; +use frame_support::traits::{OnFinalize, OnInitialize, OnRuntimeUpgrade}; +pub(crate) fn on_runtime_upgrade() { + VersionUncheckedMigrateToV1::::on_runtime_upgrade(); +} + +pub(crate) fn para_roll_to(n: BlockNumber) { + while System::block_number() < n { + PolkadotXcm::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + PolkadotXcm::on_initialize(System::block_number()); + } +} diff --git a/tracing/2902/runtime/moonbase/tests/xcm_mock/relay_chain.rs b/tracing/2902/runtime/moonbase/tests/xcm_mock/relay_chain.rs new file mode 100644 index 00000000..40bff5e1 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/xcm_mock/relay_chain.rs @@ -0,0 +1,412 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{Everything, Nothing, ProcessMessage, ProcessMessageError}, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, IdentityLookup}, + AccountId32, +}; + +use frame_support::weights::{Weight, WeightMeter}; +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{ + configuration, dmp, hrmp, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, paras, shared, +}; +use sp_runtime::transaction_validity::TransactionPriority; +use sp_runtime::Permill; +use xcm::latest::prelude::*; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, + ChildSystemParachainAsSuperuser, FixedRateOfFungible, FixedWeightBounds, + FungibleAdapter as XcmCurrencyAdapter, IsConcrete, ProcessXcmMessage, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + WithComputedOrigin, +}; +use xcm_executor::{Config, XcmExecutor}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = (); + type PalletsOrigin = OriginCaller; +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub KsmLocation: Location = Here.into(); + pub const KusamaNetwork: NetworkId = NetworkId::Kusama; + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorLocation = Here; +} + +pub type SovereignAccountOf = ( + ChildParachainConvertsVia, + AccountId32Aliases, + // Not enabled in the relay per se, but we enable it to test + // the transact_through_signed extrinsic + Account32Hash, +); + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1000u64, 1000u64); + pub KsmPerSecond: (AssetId, u128, u128) = (AssetId(KsmLocation::get()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub MatcherLocation: Location = Location::here(); +} + +pub type XcmRouter = super::RelayChainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) }); + pub Statemine: Location = Parachain(4).into(); + pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get()); +} + +pub type TrustedTeleporters = xcm_builder::Case; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +parameter_types! { + pub const ParasUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); +} + +/// A very dumb implementation of `EstimateNextSessionRotation`. At the moment of writing, this +/// is more to satisfy type requirements rather than to test anything. +pub struct TestNextSessionRotation; + +impl frame_support::traits::EstimateNextSessionRotation for TestNextSessionRotation { + fn average_session_length() -> u32 { + 10 + } + + fn estimate_current_session_progress(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } + + fn estimate_next_session_rotation(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } +} + +impl paras::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = paras::TestWeightInfo; + type UnsignedPriority = ParasUnsignedPriority; + type NextSessionRotation = TestNextSessionRotation; + type QueueFootprinter = (); + type OnNewHead = (); + type AssignCoretime = (); +} + +impl dmp::Config for Runtime {} + +impl hrmp::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type WeightInfo = TestHrmpWeightInfo; + type ChannelManager = frame_system::EnsureRoot; +} + +impl frame_system::offchain::SendTransactionTypes for Runtime +where + RuntimeCall: From, +{ + type Extrinsic = UncheckedExtrinsic; + type OverarchingCall = RuntimeCall; +} + +impl origin::Config for Runtime {} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlockU32; + +parameter_types! { + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +pub struct MessageProcessor; +impl ProcessMessage for MessageProcessor { + type Origin = AggregateMessageOrigin; + + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + let para = match origin { + AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, + }; + ProcessXcmMessage::, RuntimeCall>::process_message( + message, + Junction::Parachain(para.into()), + meter, + id, + ) + } +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type MessageProcessor = MessageProcessor; + type QueueChangeHandler = (); + type WeightInfo = (); + type QueuePausedQuery = (); +} + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + MessageQueue: pallet_message_queue, + XcmPallet: pallet_xcm, + Utility: pallet_utility, + Hrmp: hrmp, + Dmp: dmp, + Paras: paras, + Configuration: configuration, + } +); + +pub(crate) fn relay_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::{OnFinalize, OnInitialize}; +pub(crate) fn relay_roll_to(n: BlockNumber) { + while System::block_number() < n { + XcmPallet::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + XcmPallet::on_initialize(System::block_number()); + } +} + +/// A weight info that is only suitable for testing. +pub struct TestHrmpWeightInfo; + +impl hrmp::WeightInfo for TestHrmpWeightInfo { + fn hrmp_accept_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn force_clean_hrmp(_: u32, _: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_close(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_open(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_cancel_open_request(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_close_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_init_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn clean_open_channel_requests(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_open_hrmp_channel(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn establish_system_channel() -> Weight { + Weight::from_parts(1, 0) + } + + fn poke_channel_deposits() -> Weight { + Weight::from_parts(1, 0) + } +} diff --git a/tracing/2902/runtime/moonbase/tests/xcm_mock/statemint_like.rs b/tracing/2902/runtime/moonbase/tests/xcm_mock/statemint_like.rs new file mode 100644 index 00000000..a3da2c21 --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/xcm_mock/statemint_like.rs @@ -0,0 +1,575 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{AsEnsureOriginWithArg, Contains, Everything, Nothing}, + weights::Weight, +}; +use frame_system::{EnsureRoot, EnsureSigned}; + +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, Hash, IdentityLookup}, + AccountId32, +}; + +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; + +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_parachain::primitives::Sibling; +use sp_std::convert::TryFrom; +use xcm::latest::prelude::*; +use xcm::VersionedXcm; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungibleAdapter, + FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type AssetId = u128; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 0; // 1 UNIT deposit to create asset + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) + // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const ExecutiveBody: BodyId = BodyId::Executive; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = (); + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub Local: Location = Here.into(); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub KsmPerSecond: (xcm::latest::prelude::AssetId, u128, u128) = + (AssetId(KsmLocation::get()), 1, 1); +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, +); + +/// Means for transacting the native currency on this chain. +pub type CurrencyTransactor = FungibleAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Balances`. + (), +>; + +/// Means for transacting assets besides the native currency on this chain. +pub type FungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ConvertedConcreteId< + AssetId, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We only want to allow teleports of known assets. We use non-zero issuance as an indication + // that this asset is known. + NoChecking, + // The account to use for tracking teleports. + CheckingAccount, +>; +/// Means for transacting assets on this chain. +pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `RuntimeOrigin::signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxInstructions: u32 = 100; +} + +pub struct ParentOrParentsExecutivePlurality; +impl Contains for ParentOrParentsExecutivePlurality { + fn contains(location: &Location) -> bool { + matches!( + location.unpack(), + (1, []) + | ( + 1, + [Plurality { + id: BodyId::Executive, + .. + }] + ) + ) + } +} + +pub struct ParentOrSiblings; +impl Contains for ParentOrSiblings { + fn contains(location: &Location) -> bool { + matches!(location.unpack(), (1, []) | (1, [_])) + } +} + +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +parameter_types! { + pub MatcherLocation: Location = Location::here(); + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = + orml_xcm_support::MultiNativeAsset; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId32; + +pub type XcmRouter = super::ParachainXcmRouter; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831 +#[frame_support::pallet] +pub mod mock_statemint_prefix { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_prefix)] + pub(super) type CurrentPrefix = StorageValue<_, Location, ValueQuery>; + + impl Get for Pallet { + fn get() -> Location { + Self::current_prefix() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // Changed Prefix + PrefixChanged(Location), + } + + impl Pallet { + pub fn set_prefix(prefix: Location) { + CurrentPrefix::::put(&prefix); + Self::deposit_event(Event::PrefixChanged(prefix)); + } + } +} + +impl mock_statemint_prefix::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +type Block = frame_system::mocking::MockBlockU32; +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + PolkadotXcm: pallet_xcm, + CumulusXcm: cumulus_pallet_xcm, + MsgQueue: mock_msg_queue, + Assets: pallet_assets, + PrefixChanger: mock_statemint_prefix, + + } +); diff --git a/tracing/2902/runtime/moonbase/tests/xcm_tests.rs b/tracing/2902/runtime/moonbase/tests/xcm_tests.rs new file mode 100644 index 00000000..f11ebf2c --- /dev/null +++ b/tracing/2902/runtime/moonbase/tests/xcm_tests.rs @@ -0,0 +1,3970 @@ +// 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 . + +//! Moonbase Runtime Xcm Tests + +mod xcm_mock; +use frame_support::{ + assert_ok, + traits::{ConstU32, PalletInfo, PalletInfoAccess}, + weights::constants::WEIGHT_REF_TIME_PER_SECOND, + weights::Weight, + BoundedVec, +}; +use pallet_xcm_transactor::{ + Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, +}; +use sp_runtime::traits::MaybeEquivalence; +use sp_std::boxed::Box; +use xcm::latest::prelude::{ + AccountId32, AccountKey20, All, BuyExecution, ClearOrigin, DepositAsset, GeneralIndex, + Junction, Junctions, Limited, Location, OriginKind, PalletInstance, Parachain, QueryResponse, + Reanchorable, Response, WeightLimit, WithdrawAsset, Xcm, +}; +use xcm::{VersionedLocation, WrapVersion}; +use xcm_executor::traits::ConvertLocation; +use xcm_mock::*; +use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; +use xcm_simulator::TestExt; +mod common; +use cumulus_primitives_core::relay_chain::HrmpChannelId; +// Send a relay asset (like DOT) to a parachain A +#[test] +fn receive_relay_asset_from_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + // Verify that parachain received the asset + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +// Send relay asset (like DOT) back from Parachain A to relaychain +#[test] +fn send_relay_asset_to_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register relay asset in paraA + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // Free execution + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // First send relay chain asset to Parachain like in previous test + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Lets gather the balance before sending back money + let mut balance_before_sending = 0; + Relay::execute_with(|| { + balance_before_sending = RelayBalances::free_balance(&RELAYALICE); + }); + + // We now send back some money to the relay + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: RELAYALICE.into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 123, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The balances in paraAlice should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); + + // Balances in the relay should have been received + Relay::execute_with(|| { + // Free execution,x full amount received + assert!(RelayBalances::free_balance(&RELAYALICE) > balance_before_sending); + }); +} + +#[test] +fn send_relay_asset_to_para_b() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register asset in paraA. Free execution + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // First send relay chain asset to Parachain A like in previous test + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Now send relay asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 23); + }); + + // Para B balances should have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_to_para_b() { + MockNet::reset(); + + // this represents the asset in paraA + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Native token is substracted in paraA + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Asset is minted in paraB + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_from_para_b_to_para_c() { + MockNet::reset(); + + // Represents para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in parachain B. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register para A asset in parachain C. Free execution + ParaC::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send para A asset from para B to para C + let dest = Location { + parents: 1, + interior: [ + Parachain(3), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The message passed through parachainA so we needed to pay since its the native token + ParaC::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 96); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_and_back_to_para_a() { + MockNet::reset(); + + // Para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in para B + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send back para A asset to para A + let dest = Location { + parents: 1, + interior: [ + Parachain(1), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // Weight used is 4 + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 4 + ); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A asset has been credited + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // This time we will force the new reanchoring by manually sending the + // Message through polkadotXCM pallet + + let dest = Location { + parents: 1, + interior: [Parachain(1)].into(), + }; + + let reanchored_para_a_balances = Location::new(0, [PalletInstance(1u8)]); + + let message = xcm::VersionedXcm::<()>::V4(Xcm(vec![ + WithdrawAsset((reanchored_para_a_balances.clone(), 100).into()), + ClearOrigin, + BuyExecution { + fees: (reanchored_para_a_balances, 100).into(), + weight_limit: Limited(80.into()), + }, + DepositAsset { + assets: All.into(), + beneficiary: Location::new( + 0, + [AccountKey20 { + network: None, + key: PARAALICE, + }], + ), + }, + ])); + ParaB::execute_with(|| { + // Send a message to the sovereign account in ParaA to withdraw + // and deposit asset + assert_ok!(ParachainPalletXcm::send( + parachain::RuntimeOrigin::root(), + Box::new(dest.into()), + Box::new(message), + )); + }); + + ParaA::execute_with(|| { + // Weight used is 4 + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 4 + ); + }); +} + +#[test] +fn receive_relay_asset_with_trader() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // We are sending 100 tokens from relay. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Therefore with no refund, we should receive 10 tokens less + // Native trader fails for this, and we use the asset trader + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 100).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // non-free execution, not full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // In destination chain, we only need 4 weight + // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // We are sending 100 tokens from para A. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Since we set 10 weight in destination chain, 25 will be charged upfront + // 15 of those will be refunded, while 10 will go to treasury as the true weight used + // will be 4 + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader_and_fee() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // With these units per second, 80K weight convrets to 1 asset unit + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 12500000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // we use transfer_with_fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_with_fee( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + 1, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // 100 tokens transferred plus 1 taken from fees + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 - 1 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received because trully the xcm instruction does not cost + // what it is specified + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 101); + }); +} + +#[test] +fn error_when_not_paying_enough() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + // We are sending 100 tokens from relay. + // If we set the dest weight to be 1e7, we know the buy_execution will spend 1e7*1e6/1e12 = 10 + // Therefore with no refund, we should receive 10 tokens less + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 5).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // amount not received as it is not paying enough + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); +} + +#[test] +fn transact_through_derivative_multilocation() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + // 4000000000 + 3000 we should have taken out 4000003000 tokens from the caller + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000003000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + // 4000000000 + 3000 we should have taken out 4000003000 tokens from the caller + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + false + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 9000 correspond to 4000009000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn transact_through_sovereign() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_fee_payer_none() { + MockNet::reset(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let derivative_address = derivative_account_id(para_a_account(), 0); + + Relay::execute_with(|| { + // Transfer 100 tokens to derivative_address on the relay + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derivative_address.clone(), + 100u128 + )); + + // Transfer the XCM execution fee amount to ParaA's sovereign account + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 4000003000u128 + )); + }); + + // Check balances before the transact call + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000003000); + assert_eq!(RelayBalances::free_balance(&derivative_address), 100); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 0); + }); + + // Encode the call. Balances transfer of 100 relay tokens to RELAYBOB + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: RELAYBOB, + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + // The final call will be an AsDerivative using index 0 + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + // No fee_payer here. The sovereign account will pay the fees on destination. + None, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + // Check balances after the transact call are correct + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 0); + assert_eq!(RelayBalances::free_balance(&derivative_address), 0); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 100); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000003000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000009000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn test_automatic_versioning_on_runtime_upgrade_with_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A and set XCM version to 1 + ParaA::execute_with(|| { + parachain::XcmVersioner::set_version(1); + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let response = Response::Version(2); + let querier: Location = [].into(); + + // This is irrelevant, nothing will be done with this message, + // but we need to pass a message as an argument to trigger the storage change + let mock_message: Xcm<()> = Xcm(vec![QueryResponse { + query_id: 0, + response, + max_weight: Weight::zero(), + querier: Some(querier), + }]); + // The router is mocked, and we cannot use WrapVersion in ChildParachainRouter. So we will force + // it directly here + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + Relay::execute_with(|| { + // This sets the default version, for not known destinations + assert_ok!(RelayChainPalletXcm::force_default_xcm_version( + relay_chain::RuntimeOrigin::root(), + Some(2) + )); + + // Wrap version, which sets VersionedStorage + // This is necessary because the mock router does not use wrap_version, but + // this is not necessary in prod + assert_ok!(::wrap_version( + &Parachain(1).into(), + mock_message + )); + + // Transfer assets. Since it is an unknown destination, it will query for version + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 123).into()), + 0, + )); + + // Let's advance the relay. This should trigger the subscription message + relay_chain::relay_roll_to(2); + + // queries should have been updated + assert!(RelayChainPalletXcm::query(0).is_some()); + }); + + let expected_supported_version: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 1, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the version change + assert!(relay_chain::relay_events().contains(&expected_supported_version)); + }); + + // ParaA changes version to 2, and calls on_runtime_upgrade. This should notify the targets + // of the new version change + ParaA::execute_with(|| { + // Set version + parachain::XcmVersioner::set_version(2); + // Do runtime upgrade + parachain::on_runtime_upgrade(); + // Initialize block, to call on_initialize and notify targets + parachain::para_roll_to(2); + // Expect the event in the parachain + assert!(parachain::para_events().iter().any(|e| matches!( + e, + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::VersionChangeNotified { + result: 2, + .. + }) + ))); + }); + + // This event should have been seen in the relay + let expected_supported_version_2: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 2, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the new version change + assert!(relay_chain::relay_events().contains(&expected_supported_version_2)); + }); +} + +#[test] +fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + let response = Response::Version(2); + let querier: Location = [].into(); + + // This is irrelevant, nothing will be done with this message, + // but we need to pass a message as an argument to trigger the storage change + let mock_message: Xcm<()> = Xcm(vec![QueryResponse { + query_id: 0, + response, + max_weight: Weight::zero(), + querier: Some(querier), + }]); + + ParaA::execute_with(|| { + // advertised version + parachain::XcmVersioner::set_version(2); + }); + + ParaB::execute_with(|| { + // Let's try with v0 + parachain::XcmVersioner::set_version(0); + + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + ParaA::execute_with(|| { + // This sets the default version, for not known destinations + assert_ok!(ParachainPalletXcm::force_default_xcm_version( + parachain::RuntimeOrigin::root(), + Some(2) + )); + // Wrap version, which sets VersionedStorage + assert_ok!(::wrap_version( + &Location::new(1, [Parachain(2)]).into(), + mock_message + )); + + parachain::para_roll_to(2); + + // queries should have been updated + assert!(ParachainPalletXcm::query(0).is_some()); + }); + + let expected_supported_version: parachain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 1, + interior: [Parachain(2)].into(), + }, + version: 0, + } + .into(); + + ParaA::execute_with(|| { + // Assert that the events vector contains the version change + assert!(parachain::para_events().contains(&expected_supported_version)); + }); + + // Let's ensure talking in v0 works + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + } + .into(); + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // ParaB changes version to 2, and calls on_runtime_upgrade. This should notify the targets + // of the new version change + ParaB::execute_with(|| { + // Set version + parachain::XcmVersioner::set_version(2); + // Do runtime upgrade + parachain::on_runtime_upgrade(); + // Initialize block, to call on_initialize and notify targets + parachain::para_roll_to(2); + // Expect the event in the parachain + assert!(parachain::para_events().iter().any(|e| matches!( + e, + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::VersionChangeNotified { + result: 2, + .. + }) + ))); + }); + + // This event should have been seen in para A + let expected_supported_version_2: parachain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 1, + interior: [Parachain(2)].into(), + }, + version: 2, + } + .into(); + + // Para A should have received the version change + ParaA::execute_with(|| { + // Assert that the events vector contains the new version change + assert!(parachain::para_events().contains(&expected_supported_version_2)); + }); +} + +#[test] +fn receive_asset_with_no_sufficients_not_possible_if_non_existent_account() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + // parachain should not have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 0); + }); + + // Send native token to fresh_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + fresh_account.into(), + 100 + )); + }); + + // Re-send tokens + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn receive_assets_with_sufficients_true_allows_non_funded_account_to_receive_assets() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn evm_account_receiving_assets_should_handle_sufficients_ref_count() { + MockNet::reset(); + + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + // Evm account is self sufficient + ParaA::execute_with(|| { + assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + // Evm account sufficient ref count increased by 1. + ParaA::execute_with(|| { + // TODO: since the suicided logic was introduced the data of the smart contract is not + // removed, it will have to be updated in a future release when there is the ability to + // remove contract data + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 2); + }); + + ParaA::execute_with(|| { + // Remove the account from the evm context. + parachain::EVM::remove_account(&evm_account()); + // Evm account sufficient ref count decreased by 1. + // TODO: since the suicided logic was introduced the data of the smart contract is not + // removed, it will have to be updated in a future release when there is the ability to + // remove contract data + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); +} + +#[test] +fn empty_account_should_not_be_reset() { + MockNet::reset(); + + // Test account has nonce 1 on genesis. + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send native token to evm_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + evm_account_id, + 100 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([], 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Empty the assets from the account. + // As this makes the account go below the `min_balance`, the account is considered dead + // at eyes of pallet-assets, and the consumer reference is decreased by 1 and is now Zero. + assert_ok!(parachain::Assets::transfer( + parachain::RuntimeOrigin::signed(evm_account_id), + source_id, + PARAALICE.into(), + 123 + )); + // Verify account asset balance is Zero. + assert_eq!( + parachain::Assets::balance(source_id, &evm_account_id.into()), + 0 + ); + // Because we no longer have consumer references, we can set the balance to Zero. + // This would reset the account if our ED were to be > than Zero. + assert_ok!(ParaBalances::force_set_balance( + parachain::RuntimeOrigin::root(), + evm_account_id, + 0, + )); + // Verify account native balance is Zero. + assert_eq!(ParaBalances::free_balance(&evm_account_id), 0); + // Remove the account from the evm context. + // This decreases the sufficients reference by 1 and now is Zero. + parachain::EVM::remove_account(&evm_account()); + // Verify reference count. + let account = parachain::System::account(evm_account_id); + // TODO: after introducing the suicided fix the value for account.sufficients will remain 1 + // until the storage is not completely removed, it will have to be decreased to 0 once the + // storage can be fully removed + assert_eq!(account.sufficients, 1); + assert_eq!(account.consumers, 0); + assert_eq!(account.providers, 1); + // We expect the account to be alive in a Zero ED context. + // TODO: after introducing the suicided fix the nonce is increased by 1 + // until the storage is not completely removed, it will have to be decreased to 1 once the + // storage can be fully removed + assert_eq!(parachain::System::account_nonce(evm_account_id), 2); + }); +} + +#[test] +fn test_statemint_like() { + MockNet::reset(); + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemint_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + let statemint_asset_a_balances = Location::new( + 1, + [ + Parachain(4), + PalletInstance(5), + xcm::latest::prelude::GeneralIndex(0u128), + ], + ); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemint_asset_a_balances) + .expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"StatemintToken".to_vec(), + symbol: b"StatemintToken".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + Statemint::execute_with(|| { + // Set new prefix + statemint_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + assert_ok!(StatemintAssets::create( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 1 + )); + + assert_ok!(StatemintAssets::mint( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 300000000000000 + )); + + // This is needed, since the asset is created as non-sufficient + assert_ok!(StatemintBalances::transfer_allow_death( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send asset with previous prefix + assert_ok!(StatemintChainPalletXcm::reserve_transfer_assets( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + xcm::latest::prelude::GeneralIndex(0), + ], + 123 + ) + .into() + ), + 0, + )); + }); + + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +#[test] +fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { + MockNet::reset(); + + // Relay asset + let relay_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_relay_id: parachain::AssetId = relay_location.clone().into(); + + let relay_asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Statemint asset + let statemint_asset = Location::new( + 1, + [Parachain(4u32), PalletInstance(5u8), GeneralIndex(10u128)], + ); + let statemint_location_asset = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemint_asset).expect("convert to v3"), + ); + let source_statemint_asset_id: parachain::AssetId = statemint_location_asset.clone().into(); + + let asset_metadata_statemint_asset = parachain::AssetMetadata { + name: b"USDC".to_vec(), + symbol: b"USDC".to_vec(), + decimals: 12, + }; + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemint_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + relay_location.clone(), + relay_asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + relay_location, + 0u128, + 0 + )); + + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + statemint_location_asset.clone(), + asset_metadata_statemint_asset, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + statemint_location_asset, + 0u128, + 1 + )); + }); + + let parachain_beneficiary_from_relay: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send relay chain asset to Alice in Parachain A + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_relay) + .clone() + .into() + ), + Box::new(([], 200).into()), + 0, + )); + }); + + Statemint::execute_with(|| { + // Set new prefix + statemint_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + + assert_ok!(StatemintAssets::create( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 1 + )); + + assert_ok!(StatemintAssets::mint( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 300000000000000 + )); + + // Send some native statemint tokens to sovereign for fees. + // We can't pay fees with USDC as the asset is minted as non-sufficient. + assert_ok!(StatemintBalances::transfer_allow_death( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Send statemint USDC asset to Alice in Parachain A + let parachain_beneficiary_from_statemint: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send with new prefix + assert_ok!(StatemintChainPalletXcm::reserve_transfer_assets( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_statemint) + .clone() + .into() + ), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + GeneralIndex(10), + ], + 125 + ) + .into() + ), + 0, + )); + }); + + let statemint_beneficiary = Location { + parents: 1, + interior: [ + Parachain(4), + AccountId32 { + network: None, + id: RELAYBOB.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + // Alice has received 125 USDC + assert_eq!( + Assets::balance(source_statemint_asset_id, &PARAALICE.into()), + 125 + ); + + // Alice has received 200 Relay assets + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 200); + }); + + Statemint::execute_with(|| { + // Check that BOB's balance is empty before the transfer + assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![]); + }); + + // Transfer USDC from Parachain A to Statemint using Relay asset as fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_multicurrencies( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + vec![ + ( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100 + ), + (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) + ], + 1, + Box::new(VersionedLocation::V4(statemint_beneficiary)), + WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) + )); + }); + + ParaA::execute_with(|| { + // Alice has 100 USDC less + assert_eq!( + Assets::balance(source_statemint_asset_id, &PARAALICE.into()), + 25 + ); + + // Alice has 100 relay asset less + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 100); + }); + + Statemint::execute_with(|| { + // Check that BOB received 100 USDC on statemint + assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![(10, 100)]); + }); +} + +#[test] +fn transact_through_signed_multilocation() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4000.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000004000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // 100 transferred + assert_eq!(RelayBalances::free_balance(¶_a_account()), 100); + + // 4000005186 refunded + assert_eq!(RelayBalances::free_balance(&derived), 4000005186); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_multilocation + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + assert!(ParaBalances::free_balance(&derived) == 0); + + assert!(ParaBalances::free_balance(¶_a_account_20()) == 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_multilocation + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: Some(overall_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + }); + + ParaB::execute_with(|| { + // Check the derived account was refunded + assert_eq!(ParaBalances::free_balance(&derived), 8993); + + // Check the transfer was executed + assert_eq!(ParaBalances::free_balance(¶_a_account_20()), 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_multilocation + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact { + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer went through + assert!( + ParaBalances::free_balance(&PARAALICE.into()) + == parachain_b_alice_balances_before + 100 + ); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_multilocation + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer wasn't executed + assert!(ParaBalances::free_balance(&PARAALICE.into()) == parachain_b_alice_balances_before); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_multilocation + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + let transfer_recipient = evm_account(); + let mut transfer_recipient_balance_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + transfer_recipient_balance_before = ParaBalances::free_balance(&transfer_recipient.into()); + + // Add proxy ALICE -> derived + let _ = parachain::Proxy::add_proxy_delegate( + &PARAALICE.into(), + derived, + parachain::ProxyType::Any, + 0, + ); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V2(xcm_primitives::EthereumXcmTransactionV2 { + gas_limit: U256::from(21000), + action: pallet_ethereum::TransactionAction::Call(transfer_recipient.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer was executed + assert!( + ParaBalances::free_balance(&transfer_recipient.into()) + == transfer_recipient_balance_before + 100 + ); + }); +} + +#[test] +fn hrmp_init_accept_through_root() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_b_account(), + 1000u128 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp init channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::InitOpen(HrmpInitParams { + para_id: 2u32.into(), + proposed_max_capacity: 1, + proposed_max_message_size: 1 + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelRequested { + sender: 1u32.into(), + recipient: 2u32.into(), + proposed_max_capacity: 1u32, + proposed_max_message_size: 1u32, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); + ParaB::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp accept channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Accept { + para_id: 1u32.into() + }, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelAccepted { + sender: 1u32.into(), + recipient: 2u32.into(), + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +#[test] +fn hrmp_close_works() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(Hrmp::force_open_hrmp_channel( + relay_chain::RuntimeOrigin::root(), + 1u32.into(), + 2u32.into(), + 1u32, + 1u32 + )); + assert_ok!(Hrmp::force_process_hrmp_open( + relay_chain::RuntimeOrigin::root(), + 1u32 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Close(HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into() + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::ChannelClosed { + by_parachain: 1u32.into(), + channel_id: HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into(), + }, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +use parity_scale_codec::{Decode, Encode}; +use sp_io::hashing::blake2_256; + +// Helper to derive accountIds +pub fn derivative_account_id(who: sp_runtime::AccountId32, index: u16) -> sp_runtime::AccountId32 { + let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); + sp_runtime::AccountId32::decode(&mut &entropy[..]).expect("valid account id") +} diff --git a/tracing/2902/runtime/moonbeam/Cargo.toml b/tracing/2902/runtime/moonbeam/Cargo.toml new file mode 100644 index 00000000..96cb372b --- /dev/null +++ b/tracing/2902/runtime/moonbeam/Cargo.toml @@ -0,0 +1,401 @@ +[package] +authors = { workspace = true } +build = "build.rs" +description = "Moonbeam Runtime" +edition = "2021" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +name = "moonbeam-runtime" +version = "0.8.4" + +[dependencies] +hex-literal = { workspace = true, optional = true } +log = { workspace = true } +num_enum = { workspace = true } +rlp = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +sha3 = { workspace = true, optional = true } +smallvec = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } + +# Moonbeam +account = { workspace = true } +moonbeam-core-primitives = { workspace = true } +moonbeam-relay-encoder = { workspace = true } +moonbeam-runtime-common = { workspace = true } +precompile-utils = { workspace = true } +session-keys-primitives = { workspace = true } +xcm-primitives = { workspace = true } + +# Moonbeam pallets +moonbeam-xcm-benchmarks = { workspace = true } +pallet-asset-manager = { workspace = true } +pallet-author-mapping = { workspace = true } +pallet-crowdloan-rewards = { workspace = true } +pallet-erc20-xcm-bridge = { workspace = true } +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-lazy-migrations = { workspace = true } +pallet-moonbeam-orbiters = { workspace = true } +pallet-parachain-staking = { workspace = true } +pallet-precompile-benchmarks = { workspace = true } +pallet-proxy-genesis-companion = { workspace = true } +pallet-randomness = { workspace = true } +pallet-xcm-transactor = { workspace = true } + +# Moonbeam precompiles +pallet-evm-precompile-author-mapping = { workspace = true } +pallet-evm-precompile-balances-erc20 = { workspace = true } +pallet-evm-precompile-batch = { workspace = true } +pallet-evm-precompile-call-permit = { workspace = true } +pallet-evm-precompile-collective = { workspace = true } +pallet-evm-precompile-conviction-voting = { workspace = true } +pallet-evm-precompile-crowdloan-rewards = { workspace = true } +pallet-evm-precompile-gmp = { workspace = true } +pallet-evm-precompile-identity = { workspace = true } +pallet-evm-precompile-parachain-staking = { workspace = true } +pallet-evm-precompile-preimage = { workspace = true } +pallet-evm-precompile-proxy = { workspace = true } +pallet-evm-precompile-randomness = { workspace = true } +pallet-evm-precompile-referenda = { workspace = true } +pallet-evm-precompile-registry = { workspace = true } +pallet-evm-precompile-relay-encoder = { workspace = true } +pallet-evm-precompile-relay-verifier = { workspace = true } +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 } + +# Moonbeam tracing +evm-tracing-events = { workspace = true, optional = true } +moonbeam-evm-tracer = { workspace = true, optional = true } +moonbeam-rpc-primitives-debug = { workspace = true } +moonbeam-rpc-primitives-txpool = { workspace = true } + +# Substrate +frame-executive = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +frame-system-rpc-runtime-api = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true, features = ["insecure_zero_ed"] } +pallet-collective = { workspace = true } +pallet-conviction-voting = { workspace = true } +pallet-identity = { workspace = true } +pallet-multisig = { workspace = true } +pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } +pallet-referenda = { workspace = true } +pallet-root-testing = { workspace = true } +pallet-scheduler = { workspace = true } +pallet-society = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-transaction-payment = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-treasury = { workspace = true } +pallet-utility = { workspace = true } +pallet-whitelist = { workspace = true } +parity-scale-codec = { workspace = true, features = [ + "derive", + "max-encoded-len", + "chain-error", +] } +scale-info = { workspace = true, features = ["derive"] } +sp-api = { workspace = true } +sp-block-builder = { workspace = true } +sp-consensus-slots = { workspace = true } +sp-core = { workspace = true } +sp-inherents = { workspace = true } +sp-io = { workspace = true, features = ["improved_panic_error_reporting"] } +sp-offchain = { workspace = true } +sp-runtime = { workspace = true } +sp-session = { workspace = true } +sp-std = { workspace = true } +sp-transaction-pool = { workspace = true } +sp-version = { workspace = true } +sp-weights = { workspace = true } +sp-genesis-builder = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +fp-rpc = { workspace = true } +fp-self-contained = { workspace = true, features = ["serde"] } +pallet-ethereum = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm-precompile-blake2 = { workspace = true } +pallet-evm-precompile-bn128 = { workspace = true } +pallet-evm-precompile-dispatch = { workspace = true } +pallet-evm-precompile-modexp = { workspace = true } +pallet-evm-precompile-sha3fips = { workspace = true } +pallet-evm-precompile-simple = { workspace = true } + +# Polkadot / XCM +orml-traits = { workspace = true } +orml-xcm-support = { workspace = true } +orml-xtokens = { workspace = true } +pallet-xcm = { workspace = true } +pallet-xcm-benchmarks = { workspace = true, optional = true } +pallet-message-queue = { workspace = true } +polkadot-core-primitives = { workspace = true } +polkadot-runtime-common = { workspace = true } +polkadot-parachain = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } + +# Cumulus +cumulus-pallet-dmp-queue = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-xcm = { workspace = true } +cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-core = { workspace = true } +cumulus-primitives-timestamp = { workspace = true } +cumulus-primitives-utility = { workspace = true } +parachain-info = { workspace = true } +parachains-common = { workspace = true } + +# Moonkit +async-backing-primitives = { workspace = true } +moonkit-xcm-primitives = { workspace = true } +nimbus-primitives = { workspace = true } +pallet-author-inherent = { workspace = true } +pallet-author-slot-filter = { workspace = true } +pallet-relay-storage-roots = { workspace = true } + +# Benchmarking +frame-benchmarking = { workspace = true, optional = true } +frame-system-benchmarking = { workspace = true, optional = true } +frame-try-runtime = { workspace = true, optional = true } + +[build-dependencies] +substrate-wasm-builder = { workspace = true } + +[features] +default = ["std", "evm-tracing"] +std = [ + "account/std", + "async-backing-primitives/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "evm-tracing-events/std", + "fp-evm/std", + "fp-rpc/std", + "fp-self-contained/std", + "frame-benchmarking/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "moonbeam-core-primitives/std", + "moonbeam-evm-tracer/std", + "moonbeam-relay-encoder/std", + "moonbeam-rpc-primitives-debug/std", + "moonbeam-rpc-primitives-txpool/std", + "moonbeam-runtime-common/std", + "moonbeam-xcm-benchmarks/std", + "moonkit-xcm-primitives/std", + "nimbus-primitives/std", + "orml-xtokens/std", + "pallet-asset-manager/std", + "pallet-assets/std", + "pallet-author-inherent/std", + "pallet-author-mapping/std", + "pallet-author-slot-filter/std", + "pallet-balances/std", + "pallet-collective/std", + "pallet-conviction-voting/std", + "pallet-crowdloan-rewards/std", + "pallet-erc20-xcm-bridge/std", + "pallet-evm-chain-id/std", + "pallet-ethereum-xcm/std", + "pallet-ethereum/std", + "pallet-evm-precompile-author-mapping/std", + "pallet-evm-precompile-balances-erc20/std", + "pallet-evm-precompile-batch/std", + "pallet-evm-precompile-call-permit/std", + "pallet-evm-precompile-collective/std", + "pallet-evm-precompile-conviction-voting/std", + "pallet-evm-precompile-parachain-staking/std", + "pallet-evm-precompile-preimage/std", + "pallet-evm-precompile-randomness/std", + "pallet-evm-precompile-referenda/std", + "pallet-evm-precompile-relay-encoder/std", + "pallet-evm-precompile-relay-verifier/std", + "pallet-evm-precompile-xcm-transactor/std", + "pallet-evm-precompile-xcm-utils/std", + "pallet-evm-precompile-xtokens/std", + "pallet-evm-precompileset-assets-erc20/std", + "pallet-evm/std", + "pallet-identity/std", + "pallet-maintenance-mode/std", + "pallet-migrations/std", + "pallet-moonbeam-lazy-migrations/std", + "pallet-moonbeam-orbiters/std", + "pallet-multisig/std", + "pallet-parachain-staking/std", + "pallet-precompile-benchmarks/std", + "pallet-preimage/std", + "pallet-proxy-genesis-companion/std", + "pallet-proxy/std", + "pallet-randomness/std", + "pallet-referenda/std", + "pallet-relay-storage-roots/std", + "pallet-root-testing/std", + "pallet-scheduler/std", + "pallet-society/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "pallet-utility/std", + "pallet-whitelist/std", + "pallet-xcm-transactor/std", + "pallet-xcm/std", + "parachain-info/std", + "parachains-common/std", + "parity-scale-codec/std", + "precompile-utils/std", + "scale-info/std", + "session-keys-primitives/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-slots/std", + "sp-core/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-genesis-builder/std", + "strum/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm-primitives/std", + "xcm/std", +] +evm-tracing = ["evm-tracing-events", "moonbeam-evm-tracer", "rlp", "sha3"] + +# Will be enabled by the `wasm-builder` when building the runtime for WASM. +runtime-wasm = [] + +# A feature that should be enabled when the runtime should be build for on-chain +# deployment. This will disable stuff that shouldn't be part of the on-chain wasm +# to make it smaller like logging for example. +on-chain-release-build = ["sp-api/disable-logging"] + +runtime-benchmarks = [ + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "moonbeam-relay-encoder/runtime-benchmarks", + "moonbeam-runtime-common/runtime-benchmarks", + "moonbeam-xcm-benchmarks/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "pallet-asset-manager/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-author-inherent/runtime-benchmarks", + "pallet-author-mapping/runtime-benchmarks", + "pallet-author-slot-filter/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", + "pallet-crowdloan-rewards/runtime-benchmarks", + "pallet-ethereum-xcm/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", + "pallet-moonbeam-lazy-migrations/runtime-benchmarks", + "pallet-moonbeam-orbiters/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-parachain-staking/runtime-benchmarks", + "pallet-precompile-benchmarks/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-randomness/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-relay-storage-roots/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "session-keys-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", +] + +try-runtime = [ + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "fp-self-contained/try-runtime", + "frame-executive/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime", + "moonbeam-runtime-common/try-runtime", + "pallet-asset-manager/try-runtime", + "pallet-author-mapping/try-runtime", + "pallet-author-slot-filter/try-runtime", + "pallet-balances/try-runtime", + "pallet-collective/try-runtime", + "pallet-conviction-voting/try-runtime", + "pallet-maintenance-mode/try-runtime", + "pallet-migrations/try-runtime", + "pallet-moonbeam-lazy-migrations/try-runtime", + "pallet-parachain-staking/try-runtime", + "pallet-precompile-benchmarks/try-runtime", + "pallet-preimage/try-runtime", + "pallet-referenda/try-runtime", + "pallet-relay-storage-roots/try-runtime", + "pallet-root-testing/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-society/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-whitelist/try-runtime", + "pallet-xcm/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-utility/try-runtime", + "pallet-transaction-payment/try-runtime", + "parachain-info/try-runtime", + "pallet-evm-chain-id/try-runtime", + "parachain-info/try-runtime", + "pallet-evm/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-treasury/try-runtime", + "pallet-author-inherent/try-runtime", + "pallet-crowdloan-rewards/try-runtime", + "pallet-proxy/try-runtime", + "pallet-identity/try-runtime", + "orml-xtokens/try-runtime", + "pallet-assets/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-proxy-genesis-companion/try-runtime", + "pallet-moonbeam-orbiters/try-runtime", + "pallet-ethereum-xcm/try-runtime", + "pallet-randomness/try-runtime", + "pallet-whitelist/try-runtime", + "pallet-erc20-xcm-bridge/try-runtime", + "pallet-multisig/try-runtime", +] diff --git a/tracing/2902/runtime/moonbeam/build.rs b/tracing/2902/runtime/moonbeam/build.rs new file mode 100644 index 00000000..3934b9c5 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/build.rs @@ -0,0 +1,25 @@ +// 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 substrate_wasm_builder::WasmBuilder; + +fn main() { + WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() +} diff --git a/tracing/2902/runtime/moonbeam/src/asset_config.rs b/tracing/2902/runtime/moonbeam/src/asset_config.rs new file mode 100644 index 00000000..439b7c05 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/asset_config.rs @@ -0,0 +1,219 @@ +// 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 . + +//! Asset configuration for Moonbase. +//! + +use super::{ + currency, governance, xcm_config, AccountId, AssetId, AssetManager, Assets, Balance, Balances, + OpenTechCommitteeInstance, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +use frame_support::{ + dispatch::GetDispatchInfo, + parameter_types, + traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, EitherOfDiverse}, + weights::Weight, +}; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; + +use frame_system::{EnsureNever, EnsureRoot}; +use sp_core::H160; + +use parity_scale_codec::{Compact, Decode, Encode}; +use scale_info::TypeInfo; + +use sp_std::{ + convert::{From, Into}, + prelude::*, +}; + +// Number of items that can be destroyed with our configured max extrinsic proof size. +// x = (a - b) / c where: +// a: maxExtrinsic proof size +// b: base proof size for destroy_accounts in pallet_assets weights +// c: proof size for each item +// 656.87 = (3_407_872 - 8232) / 5180 +const REMOVE_ITEMS_LIMIT: u32 = 656; + +// Not to disrupt the previous asset instance, we assign () to Foreign +pub type ForeignAssetInstance = (); + +// For foreign assets, these parameters dont matter much +// as this will only be called by root with the forced arguments +// No deposit is substracted with those methods +parameter_types! { + pub const AssetDeposit: Balance = 100 * currency::GLMR * currency::SUPPLY_FACTOR; + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = currency::deposit(1,68); + pub const MetadataDepositPerByte: Balance = currency::deposit(0, 1); +} + +/// We allow Root and General Admin to execute privileged asset operations. +pub type AssetsForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +// Foreign assets +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = AssetsForceOrigin; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = ConstU128<{ currency::deposit(1, 18) }>; + type WeightInfo = moonbeam_weights::pallet_assets::WeightInfo; + type RemoveItemsLimit = ConstU32<{ REMOVE_ITEMS_LIMIT }>; + type AssetIdParameter = Compact; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +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, + ) -> 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, + ) + } + + #[transactional] + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + // For us both of them (Foreign and Local) have the same annotated weight for a given + // witness + // We need to take the dispatch info from the destroy call, which is already annotated in + // the assets pallet + + // This is the dispatch info of destroy + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetRegistrarMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, + pub is_frozen: bool, +} +pub type ForeignAssetModifierOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::GeneralAdmin, + >, +>; + +pub type LocalAssetModifierOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetRegistrarMetadata; + type ForeignAssetType = xcm_config::AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = ForeignAssetModifierOrigin; + type WeightInfo = moonbeam_weights::pallet_asset_manager::WeightInfo; +} + +// Instruct how to go from an H160 to an AssetID +// We just take the lowest 128 bits +impl AccountIdAssetIdConversion for Runtime { + /// The way to convert an account to assetId is by ensuring that the prefix is 0XFFFFFFFF + /// and by taking the lowest 128 bits as the assetId + fn account_to_asset_id(account: AccountId) -> Option<(Vec, AssetId)> { + let h160_account: H160 = account.into(); + let mut data = [0u8; 16]; + let (prefix_part, id_part) = h160_account.as_fixed_bytes().split_at(4); + if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX { + data.copy_from_slice(id_part); + let asset_id: AssetId = u128::from_be_bytes(data).into(); + Some((prefix_part.to_vec(), asset_id)) + } else { + None + } + } + + // The opposite conversion + fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> AccountId { + let mut data = [0u8; 20]; + data[0..4].copy_from_slice(prefix); + data[4..20].copy_from_slice(&asset_id.to_be_bytes()); + AccountId::from(data) + } +} diff --git a/tracing/2902/runtime/moonbeam/src/governance/councils.rs b/tracing/2902/runtime/moonbeam/src/governance/councils.rs new file mode 100644 index 00000000..c8cc1ca3 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/governance/councils.rs @@ -0,0 +1,61 @@ +// Copyright 2019-2023 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 . + +//! Councils for Gov1 and Gov2 + +use super::*; + +pub type TreasuryCouncilInstance = pallet_collective::Instance3; +pub type OpenTechCommitteeInstance = pallet_collective::Instance4; + +parameter_types! { + // TODO: Check value of this parameter + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for treasury council members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 3 * DAYS }>; + /// The maximum number of proposals that can be open in the treasury council at once. + type MaxProposals = ConstU32<20>; + /// The maximum number of treasury council members. + type MaxMembers = ConstU32<9>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for technical committee members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 14 * DAYS }>; + /// The maximum number of proposals that can be open in the technical committee at once. + type MaxProposals = ConstU32<100>; + /// The maximum number of technical committee members. + type MaxMembers = ConstU32<100>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} diff --git a/tracing/2902/runtime/moonbeam/src/governance/mod.rs b/tracing/2902/runtime/moonbeam/src/governance/mod.rs new file mode 100644 index 00000000..bfe3def3 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/governance/mod.rs @@ -0,0 +1,29 @@ +// Copyright 2019-2023 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 . + +//! Governance configurations + +pub mod councils; +pub mod referenda; + +use super::*; + +mod origins; +pub use origins::{ + custom_origins, GeneralAdmin, ReferendumCanceller, ReferendumKiller, WhitelistedCaller, +}; +mod tracks; +pub use tracks::TracksInfo; diff --git a/tracing/2902/runtime/moonbeam/src/governance/origins.rs b/tracing/2902/runtime/moonbeam/src/governance/origins.rs new file mode 100644 index 00000000..48154cd1 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/governance/origins.rs @@ -0,0 +1,85 @@ +// Copyright 2019-2023 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. + +//! Custom origins for governance interventions. +#![cfg_attr(not(feature = "std"), no_std)] + +pub use custom_origins::*; + +#[frame_support::pallet] +pub mod custom_origins { + use frame_support::pallet_prelude::*; + use strum_macros::EnumString; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[derive( + PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug, EnumString, + )] + #[strum(serialize_all = "snake_case")] + #[pallet::origin] + pub enum Origin { + /// Origin able to dispatch a whitelisted call. + WhitelistedCaller, + /// General admin + GeneralAdmin, + /// Origin able to cancel referenda. + ReferendumCanceller, + /// Origin able to kill referenda. + ReferendumKiller, + /// Fast General Admin + FastGeneralAdmin, + } + + macro_rules! decl_unit_ensures { + ( $name:ident: $success_type:ty = $success:expr ) => { + pub struct $name; + impl> + From> + EnsureOrigin for $name + { + type Success = $success_type; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::$name => Ok($success), + r => Err(O::from(r)), + }) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::$name)) + } + } + }; + ( $name:ident ) => { decl_unit_ensures! { $name : () = () } }; + ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => { + decl_unit_ensures! { $name: $success_type = $success } + decl_unit_ensures! { $( $rest )* } + }; + ( $name:ident, $( $rest:tt )* ) => { + decl_unit_ensures! { $name } + decl_unit_ensures! { $( $rest )* } + }; + () => {} + } + decl_unit_ensures!( + ReferendumCanceller, + ReferendumKiller, + WhitelistedCaller, + GeneralAdmin, + FastGeneralAdmin, + ); +} diff --git a/tracing/2902/runtime/moonbeam/src/governance/referenda.rs b/tracing/2902/runtime/moonbeam/src/governance/referenda.rs new file mode 100644 index 00000000..62720a0d --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/governance/referenda.rs @@ -0,0 +1,100 @@ +// Copyright 2019-2023 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 . + +//! # Gov2 config +//! Includes runtime configs for these substrate pallets: +//! 1. pallet-conviction-voting +//! 2. pallet-whitelist +//! 3. pallet-referenda + +use super::*; +use crate::currency::{GLMR, SUPPLY_FACTOR}; +use frame_support::traits::{EitherOf, MapSuccess}; +use frame_system::EnsureRootWithSuccess; +use sp_runtime::traits::Replace; + +parameter_types! { + pub const VoteLockingPeriod: BlockNumber = 1 * DAYS; +} + +impl pallet_conviction_voting::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_conviction_voting::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type Polls = Referenda; + type MaxTurnout = frame_support::traits::TotalIssuanceOf; + // Maximum number of concurrent votes an account may have + type MaxVotes = ConstU32<20>; + // Minimum period of vote locking + type VoteLockingPeriod = VoteLockingPeriod; +} + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 10 * GLMR * SUPPLY_FACTOR; + pub const UndecidingTimeout: BlockNumber = 21 * DAYS; +} + +// Origin for general admin or root +pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; +// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; + +impl custom_origins::Config for Runtime {} + +// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch +// origin corresponds to the Gov2 Whitelist track. +impl pallet_whitelist::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_whitelist::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WhitelistOrigin = EitherOf< + EnsureRootWithSuccess>, + MapSuccess< + pallet_collective::EnsureProportionAtLeast< + Self::AccountId, + OpenTechCommitteeInstance, + 5, + 9, + >, + Replace>, + >, + >; + type DispatchWhitelistedOrigin = EitherOf, WhitelistedCaller>; + type Preimages = Preimage; +} + +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); + +impl pallet_referenda::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_referenda::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = frame_system::EnsureSigned; + type CancelOrigin = EitherOf, ReferendumCanceller>; + type KillOrigin = EitherOf, ReferendumKiller>; + type Slash = Treasury; + type Votes = pallet_conviction_voting::VotesOf; + type Tally = pallet_conviction_voting::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = TracksInfo; + type Preimages = Preimage; +} diff --git a/tracing/2902/runtime/moonbeam/src/governance/tracks.rs b/tracing/2902/runtime/moonbeam/src/governance/tracks.rs new file mode 100644 index 00000000..a69cd645 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/governance/tracks.rs @@ -0,0 +1,193 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Track configurations for governance. + +use super::*; +use crate::currency::{GLMR, KILOGLMR, SUPPLY_FACTOR}; +use sp_std::str::FromStr; + +const fn percent(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 100) +} +const fn permill(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 1000) +} + +use pallet_referenda::Curve; +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 6] = [ + ( + 0, + pallet_referenda::TrackInfo { + // Name of this track. + name: "root", + // A limit for the number of referenda on this track that can be being decided at once. + // For Root origin this should generally be just one. + max_deciding: 5, + // Amount that must be placed on deposit before a decision can be made. + decision_deposit: 20 * KILOGLMR * SUPPLY_FACTOR, + // Amount of time this must be submitted for before a decision can be made. + prepare_period: 1 * DAYS, + // Amount of time that a decision may take to be approved prior to cancellation. + decision_period: 14 * DAYS, + // Amount of time that the approval criteria must hold before it can be approved. + confirm_period: 1 * DAYS, + // Minimum amount of time that an approved proposal must be in the dispatch queue. + min_enactment_period: 1 * DAYS, + // Minimum aye votes as percentage of overall conviction-weighted votes needed for + // approval as a function of time into decision period. + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + // Minimum pre-conviction aye-votes ("support") as percentage of overall population that + // is needed for approval as a function of time into decision period. + min_support: Curve::make_linear(14, 14, permill(5), percent(25)), + }, + ), + ( + 1, + pallet_referenda::TrackInfo { + name: "whitelisted_caller", + max_deciding: 100, + decision_deposit: 2 * KILOGLMR * SUPPLY_FACTOR, + prepare_period: 10 * MINUTES, + decision_period: 14 * DAYS, + confirm_period: 10 * MINUTES, + min_enactment_period: 30 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14 * 24, percent(1), percent(0), percent(2)), + }, + ), + ( + 2, + pallet_referenda::TrackInfo { + name: "general_admin", + max_deciding: 10, + decision_deposit: 100 * GLMR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 1 * DAYS, + min_enactment_period: 1 * DAYS, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(7, 14, percent(10), percent(0), percent(50)), + }, + ), + ( + 3, + pallet_referenda::TrackInfo { + name: "referendum_canceller", + max_deciding: 20, + decision_deposit: 2 * KILOGLMR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), + }, + ), + ( + 4, + pallet_referenda::TrackInfo { + name: "referendum_killer", + max_deciding: 100, + decision_deposit: 4 * KILOGLMR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), + }, + ), + ( + 5, + pallet_referenda::TrackInfo { + name: "fast_general_admin", + max_deciding: 10, + decision_deposit: 100 * GLMR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(5, 14, percent(1), percent(0), percent(50)), + }, + ), +]; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + &TRACKS_DATA[..] + } + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => { + if let Some((track_id, _)) = Self::tracks() + .into_iter() + .find(|(_, track)| track.name == "root") + { + Ok(*track_id) + } else { + Err(()) + } + } + _ => Err(()), + } + } else if let Ok(custom_origin) = custom_origins::Origin::try_from(id.clone()) { + if let Some((track_id, _)) = Self::tracks().into_iter().find(|(_, track)| { + if let Ok(track_custom_origin) = custom_origins::Origin::from_str(track.name) { + track_custom_origin == custom_origin + } else { + false + } + }) { + Ok(*track_id) + } else { + Err(()) + } + } else { + Err(()) + } + } +} + +#[test] +/// To ensure voters are always locked into their vote +fn vote_locking_always_longer_than_enactment_period() { + for (_, track) in TRACKS_DATA { + assert!( + ::VoteLockingPeriod::get() + >= track.min_enactment_period, + "Track {} has enactment period {} < vote locking period {}", + track.name, + track.min_enactment_period, + ::VoteLockingPeriod::get(), + ); + } +} + +#[test] +fn all_tracks_have_origins() { + for (_, track) in TRACKS_DATA { + // check name.into() is successful either converts into "root" or custom origin + let track_is_root = track.name == "root"; + let track_has_custom_origin = custom_origins::Origin::from_str(track.name).is_ok(); + assert!(track_is_root || track_has_custom_origin); + } +} diff --git a/tracing/2902/runtime/moonbeam/src/lib.rs b/tracing/2902/runtime/moonbeam/src/lib.rs new file mode 100644 index 00000000..8dabb586 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/lib.rs @@ -0,0 +1,1789 @@ +// 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 . + +//! The Moonbeam Runtime. +//! +//! Primary features of this runtime include: +//! * Ethereum compatibility +//! * Moonbeam tokenomics + +#![cfg_attr(not(feature = "std"), no_std)] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. +#![recursion_limit = "256"] + +// Make the WASM binary available. +#[cfg(feature = "std")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +use account::AccountId20; +use cumulus_pallet_parachain_system::{RelayChainStateProof, RelaychainDataProvider}; +use fp_rpc::TransactionStatus; + +use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin}; +#[cfg(feature = "std")] +pub use fp_evm::GenesisAccount; +pub use frame_support::traits::Get; +use frame_support::{ + construct_runtime, + dispatch::{DispatchClass, GetDispatchInfo, PostDispatchInfo}, + ensure, + pallet_prelude::DispatchResult, + parameter_types, + traits::{ + fungible::{Balanced, Credit, HoldConsideration, Inspect}, + tokens::imbalance::ResolveTo, + tokens::{PayFromAccount, UnityAssetBalanceConversion}, + ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, + EqualPrivilegeOnly, Imbalance, InstanceFilter, LinearStoragePrice, OnFinalize, + OnUnbalanced, + }, + weights::{ + constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, + ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }, + PalletId, +}; +use frame_system::{EnsureRoot, EnsureSigned}; +pub use moonbeam_core_primitives::{ + AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header, + Index, Signature, +}; +use moonbeam_rpc_primitives_txpool::TxPoolResponse; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_ethereum::Call::transact; +use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; +use pallet_evm::{ + Account as EVMAccount, EVMFungibleAdapter, EnsureAddressNever, EnsureAddressRoot, + FeeCalculator, GasWeightMapping, IdentityAddressMapping, + OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner, +}; +pub use pallet_parachain_staking::{weights::WeightInfo, InflationInfo, Range}; +use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment}; +use pallet_treasury::TreasuryAccountId; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; +use serde::{Deserialize, Serialize}; +use smallvec::smallvec; +use sp_api::impl_runtime_apis; +use sp_consensus_slots::Slot; +use sp_core::{OpaqueMetadata, H160, H256, U256}; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + traits::{ + BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, IdentityLookup, + PostDispatchInfoOf, UniqueSaturatedInto, Zero, + }, + transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, + }, + ApplyExtrinsicResult, DispatchErrorWithPostInfo, FixedPointNumber, Perbill, Permill, + Perquintill, SaturatedConversion, +}; +use sp_std::{convert::TryFrom, prelude::*}; + +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +use nimbus_primitives::CanAuthor; + +mod precompiles; +pub use precompiles::{ + MoonbeamPrecompiles, PrecompileName, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +#[cfg(any(feature = "std", test))] +pub use sp_runtime::BuildStorage; + +pub type Precompiles = MoonbeamPrecompiles; + +pub mod asset_config; +pub mod governance; +pub mod xcm_config; +use governance::councils::*; + +/// GLMR, the native token, uses 18 decimals of precision. +pub mod currency { + use super::Balance; + + // Provide a common factor between runtimes based on a supply of 10_000_000 tokens. + pub const SUPPLY_FACTOR: Balance = 100; + + pub const WEI: Balance = 1; + pub const KILOWEI: Balance = 1_000; + pub const MEGAWEI: Balance = 1_000_000; + pub const GIGAWEI: Balance = 1_000_000_000; + pub const MICROGLMR: Balance = 1_000_000_000_000; + pub const MILLIGLMR: Balance = 1_000_000_000_000_000; + pub const GLMR: Balance = 1_000_000_000_000_000_000; + pub const KILOGLMR: Balance = 1_000_000_000_000_000_000_000; + + pub const TRANSACTION_BYTE_FEE: Balance = 1 * GIGAWEI * SUPPLY_FACTOR; + pub const STORAGE_BYTE_FEE: Balance = 100 * MICROGLMR * SUPPLY_FACTOR; + pub const WEIGHT_FEE: Balance = 50 * KILOWEI * SUPPLY_FACTOR; + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 100 * MILLIGLMR * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE + } +} + +/// Maximum weight per block +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX) + .saturating_div(2) + .set_proof_size(relay_chain::MAX_POV_SIZE as u64); + +pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; +pub const WEEKS: BlockNumber = DAYS * 7; +pub const MONTHS: BlockNumber = DAYS * 30; +/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know +/// the specifics of the runtime. They can then be made to be agnostic over specific formats +/// of data like extrinsics, allowing for them to continue syncing the network through upgrades +/// to even the core datastructures. +pub mod opaque { + use super::*; + + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + pub type Block = generic::Block; + + impl_opaque_keys! { + pub struct SessionKeys { + pub nimbus: AuthorInherent, + pub vrf: session_keys_primitives::VrfSessionKey, + } + } +} + +/// This runtime version. +/// The spec_version is composed of 2x2 digits. The first 2 digits represent major changes +/// that can't be skipped, such as data migration upgrades. The last 2 digits represent minor +/// changes which can be skipped. +#[sp_version::runtime_version] +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: create_runtime_str!("moonbeam"), + impl_name: create_runtime_str!("moonbeam"), + authoring_version: 3, + spec_version: 2902, + impl_version: 0, + apis: RUNTIME_API_VERSIONS, + transaction_version: 2, + state_version: 0, +}; + +/// The version information used to identify this runtime when compiled natively. +#[cfg(feature = "std")] +pub fn native_version() -> NativeVersion { + NativeVersion { + runtime_version: VERSION, + can_author_with: Default::default(), + } +} + +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4); +// Here we assume Ethereum's base fee of 21000 gas and convert to weight, but we +// subtract roughly the cost of a balance transfer from it (about 1/3 the cost) +// and some cost to account for per-byte-fee. +// TODO: we should use benchmarking's overhead feature to measure this +pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_GAS, 0); + +pub struct RuntimeBlockWeights; +impl Get for RuntimeBlockWeights { + fn get() -> frame_system::limits::BlockWeights { + frame_system::limits::BlockWeights::builder() + .for_class(DispatchClass::Normal, |weights| { + weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT; + weights.max_total = NORMAL_WEIGHT.into(); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = MAXIMUM_BLOCK_WEIGHT.into(); + weights.reserved = (MAXIMUM_BLOCK_WEIGHT - NORMAL_WEIGHT).into(); + }) + .avg_block_initialization(Perbill::from_percent(10)) + .build() + .expect("Provided BlockWeight definitions are valid, qed") + } +} + +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + /// We allow for 5 MB blocks. + pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength + ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); +} + +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// The index type for storing how many extrinsics an account has signed. + type Nonce = Index; + /// The index type for blocks. + type Block = Block; + /// The type for hashing blocks and tries. + type Hash = Hash; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// The aggregated RuntimeTask type. + type RuntimeTask = RuntimeTask; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = ConstU32<256>; + /// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok. + type BlockWeights = RuntimeBlockWeights; + /// Maximum size of all encoded transactions (in bytes) that are allowed in one block. + type BlockLength = BlockLength; + /// Runtime version. + type Version = Version; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = RocksDbWeight; + type BaseCallFilter = MaintenanceMode; + type SystemWeightInfo = (); + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = ConstU16<1284>; + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = moonbeam_weights::pallet_utility::WeightInfo; +} + +impl pallet_timestamp::Config for Runtime { + /// A timestamp: milliseconds since the unix epoch. + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<6000>; + type WeightInfo = moonbeam_weights::pallet_timestamp::WeightInfo; +} + +impl pallet_balances::Config for Runtime { + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 4]; + type MaxLocks = ConstU32<50>; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<0>; + type AccountStore = System; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type WeightInfo = moonbeam_weights::pallet_balances::WeightInfo; +} + +pub struct DealWithFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> for DealWithFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ + // this seems to be called for substrate-based transactions + fn on_unbalanceds( + mut fees_then_tips: impl Iterator>>, + ) { + if let Some(fees) = fees_then_tips.next() { + // for fees, 80% are burned, 20% to the treasury + let (_, to_treasury) = fees.ration(80, 20); + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + + // handle tip if there is one + if let Some(tip) = fees_then_tips.next() { + // for now we use the same burn/treasury strategy used for regular fees + let (_, to_treasury) = tip.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + } + } + } + + // this is called from pallet_evm for Ethereum-based transactions + // (technically, it calls on_unbalanced, which calls this when non-zero) + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let (_, to_treasury) = amount.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); + } +} + +pub struct LengthToFee; +impl WeightToFeePolynomial for LengthToFee { + type Balance = Balance; + + fn polynomial() -> WeightToFeeCoefficients { + smallvec![ + WeightToFeeCoefficient { + degree: 1, + coeff_frac: Perbill::zero(), + coeff_integer: currency::TRANSACTION_BYTE_FEE, + negative: false, + }, + WeightToFeeCoefficient { + degree: 3, + coeff_frac: Perbill::zero(), + coeff_integer: 1 * currency::SUPPLY_FACTOR, + negative: false, + }, + ] + } +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = FungibleAdapter>; + type OperationalFeeMultiplier = ConstU8<5>; + type WeightToFee = ConstantMultiplier>; + type LengthToFee = LengthToFee; + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; +} + +impl pallet_evm_chain_id::Config for Runtime {} + +/// Current approximation of the gas/s consumption considering +/// EVM execution over compiled WASM (on 4.4Ghz CPU). +/// Given the 500ms Weight, from which 75% only are used for transactions, +/// the total EVM execution gas limit is: GAS_PER_SECOND * 0.500 * 0.75 ~= 15_000_000. +pub const GAS_PER_SECOND: u64 = 40_000_000; + +/// Approximate ratio of the amount of Weight per Gas. +/// u64 works for approximations because Weight is a very small unit compared to gas. +pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND; + +parameter_types! { + pub BlockGasLimit: U256 + = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS); + /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less + /// than this will decrease the weight and more will increase. + pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(50); + /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to + /// change the fees more rapidly. This low value causes changes to occur slowly over time. + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000); + /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure + /// that combined with `AdjustmentVariable`, we can recover from the minimum. + /// See `multiplier_can_grow_from_zero` in integration_tests.rs. + /// This value is currently only used by pallet-transaction-payment as an assertion that the + /// next multiplier is always > min value. + pub MinimumMultiplier: Multiplier = Multiplier::from(1u128); + /// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act + /// as a safety net. + pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128); + pub PrecompilesValue: MoonbeamPrecompiles = MoonbeamPrecompiles::<_>::new(); + pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per pov. A ratio of 4 if we convert ref_time to gas and we compare + /// it with the pov_size for a block. E.g. + /// ceil( + /// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS + /// ) + /// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value + pub const GasLimitPovSizeRatio: u64 = 4; + /// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT + /// The current definition of BLOCK_STORAGE_LIMIT is 40 KB, resulting in a value of 366. + pub GasLimitStorageGrowthRatio: u64 = 366; +} + +pub struct TransactionPaymentAsGasPrice; +impl FeeCalculator for TransactionPaymentAsGasPrice { + fn min_gas_price() -> (U256, Weight) { + // note: transaction-payment differs from EIP-1559 in that its tip and length fees are not + // scaled by the multiplier, which means its multiplier will be overstated when + // applied to an ethereum transaction + // note: transaction-payment uses both a congestion modifier (next_fee_multiplier, which is + // updated once per block in on_finalize) and a 'WeightToFee' implementation. Our + // runtime implements this as a 'ConstantModifier', so we can get away with a simple + // multiplication here. + // It is imperative that `saturating_mul_int` be performed as late as possible in the + // expression since it involves fixed point multiplication with a division by a fixed + // divisor. This leads to truncation and subsequent precision loss if performed too early. + // This can lead to min_gas_price being same across blocks even if the multiplier changes. + // There's still some precision loss when the final `gas_price` (used_gas * min_gas_price) + // is computed in frontier, but that's currently unavoidable. + let min_gas_price = TransactionPayment::next_fee_multiplier() + .saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128)); + ( + min_gas_price.into(), + ::DbWeight::get().reads(1), + ) + } +} + +/// Parameterized slow adjusting fee updated based on +/// https://w3f-research.readthedocs.io/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism // editorconfig-checker-disable-line +/// +/// The adjustment algorithm boils down to: +/// +/// diff = (previous_block_weight - target) / maximum_block_weight +/// next_multiplier = prev_multiplier * (1 + (v * diff) + ((v * diff)^2 / 2)) +/// assert(next_multiplier > min) +/// where: v is AdjustmentVariable +/// target is TargetBlockFullness +/// min is MinimumMultiplier +pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment< + R, + TargetBlockFullness, + AdjustmentVariable, + MinimumMultiplier, + MaximumMultiplier, +>; + +use frame_support::traits::FindAuthor; +//TODO It feels like this shold be able to work for any T: H160, but I tried for +// embarassingly long and couldn't figure that out. + +/// The author inherent provides a AccountId20, but pallet evm needs an H160. +/// This simple adapter makes the conversion. +pub struct FindAuthorAdapter(sp_std::marker::PhantomData); + +impl FindAuthor for FindAuthorAdapter +where + Inner: FindAuthor, +{ + fn find_author<'a, I>(digests: I) -> Option + where + I: 'a + IntoIterator, + { + Inner::find_author(digests).map(Into::into) + } +} + +moonbeam_runtime_common::impl_on_charge_evm_transaction!(); + +impl pallet_evm::Config for Runtime { + type FeeCalculator = TransactionPaymentAsGasPrice; + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; + type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; + type AddressMapping = IdentityAddressMapping; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type Runner = pallet_evm::runner::stack::Runner; + type PrecompilesType = MoonbeamPrecompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = EthereumChainId; + type OnChargeTransaction = OnChargeEVMTransaction>; + type BlockGasLimit = BlockGasLimit; + type FindAuthor = FindAuthorAdapter; + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo; +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block; +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = ConstU32<50>; + type WeightInfo = moonbeam_weights::pallet_scheduler::WeightInfo; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type Preimages = Preimage; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = 5 * currency::GLMR * currency::SUPPLY_FACTOR ; + pub const PreimageByteDeposit: Balance = currency::STORAGE_BYTE_FEE; + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_preimage::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const TreasuryId: PalletId = PalletId(*b"py/trsry"); + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +type TreasuryApproveOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionAtLeast, +>; + +type TreasuryRejectOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionMoreThan, +>; + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + // At least three-fifths majority of the council is required (or root) to approve a proposal + type ApproveOrigin = TreasuryApproveOrigin; + // More than half of the council is required (or root) to reject a proposal + type RejectOrigin = TreasuryRejectOrigin; + type RuntimeEvent = RuntimeEvent; + // If spending proposal rejected, transfer proposer bond to treasury + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ConstU128<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>; + type SpendPeriod = ConstU32<{ 6 * DAYS }>; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = ConstU32<100>; + type WeightInfo = moonbeam_weights::pallet_treasury::WeightInfo; + type SpendFunds = (); + type ProposalBondMaximum = (); + #[cfg(not(feature = "runtime-benchmarks"))] + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending + #[cfg(feature = "runtime-benchmarks")] + type SpendOrigin = + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<{ 30 * DAYS }>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper; +} + +parameter_types! { + pub const MaxSubAccounts: u32 = 100; + pub const MaxAdditionalFields: u32 = 100; + pub const MaxRegistrars: u32 = 20; + pub const PendingUsernameExpiration: u32 = 7 * DAYS; + pub const MaxSuffixLength: u32 = 7; + pub const MaxUsernameLength: u32 = 32; +} + +type IdentityForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type IdentityRegistrarOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_identity::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + // Add one item in storage and take 258 bytes + type BasicDeposit = ConstU128<{ currency::deposit(1, 258) }>; + // Does not add any item to the storage but takes 1 bytes + type ByteDeposit = ConstU128<{ currency::deposit(0, 1) }>; + // Add one item in storage and take 53 bytes + type SubAccountDeposit = ConstU128<{ currency::deposit(1, 53) }>; + type MaxSubAccounts = MaxSubAccounts; + type IdentityInformation = pallet_identity::legacy::IdentityInfo; + type MaxRegistrars = MaxRegistrars; + type Slashed = Treasury; + type ForceOrigin = IdentityForceOrigin; + type RegistrarOrigin = IdentityRegistrarOrigin; + type OffchainSignature = Signature; + type SigningPublicKey = ::Signer; + type UsernameAuthorityOrigin = EnsureRoot; + type PendingUsernameExpiration = PendingUsernameExpiration; + type MaxSuffixLength = MaxSuffixLength; + type MaxUsernameLength = MaxUsernameLength; + type WeightInfo = moonbeam_weights::pallet_identity::WeightInfo; +} + +pub struct TransactionConverter; + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } +} + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction( + &self, + transaction: pallet_ethereum::Transaction, + ) -> opaque::UncheckedExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnSystemEvent = (); + type SelfParaId = ParachainInfo; + type ReservedDmpWeight = ReservedDmpWeight; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = XcmpQueue; + type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; + type ConsensusHook = cumulus_pallet_parachain_system::ExpectParentIncluded; + type DmpQueue = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will immediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +impl parachain_info::Config for Runtime {} + +pub struct OnNewRound; +impl pallet_parachain_staking::OnNewRound for OnNewRound { + fn on_new_round(round_index: pallet_parachain_staking::RoundIndex) -> Weight { + MoonbeamOrbiters::on_new_round(round_index) + } +} +pub struct PayoutCollatorOrOrbiterReward; +impl pallet_parachain_staking::PayoutCollatorReward for PayoutCollatorOrOrbiterReward { + fn payout_collator_reward( + for_round: pallet_parachain_staking::RoundIndex, + collator_id: AccountId, + amount: Balance, + ) -> Weight { + let extra_weight = + if MoonbeamOrbiters::is_collator_pool_with_active_orbiter(for_round, collator_id) { + MoonbeamOrbiters::distribute_rewards(for_round, collator_id, amount) + } else { + ParachainStaking::mint_collator_reward(for_round, collator_id, amount) + }; + + ::DbWeight::get() + .reads(1) + .saturating_add(extra_weight) + } +} + +pub struct OnInactiveCollator; +impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollator { + fn on_inactive_collator( + collator_id: AccountId, + round: pallet_parachain_staking::RoundIndex, + ) -> Result> { + let extra_weight = if !MoonbeamOrbiters::is_collator_pool_with_active_orbiter( + round, + collator_id.clone(), + ) { + ParachainStaking::go_offline_inner(collator_id)?; + ::WeightInfo::go_offline( + pallet_parachain_staking::MAX_CANDIDATES, + ) + } else { + Weight::zero() + }; + + Ok(::DbWeight::get() + .reads(1) + .saturating_add(extra_weight)) + } +} +type MonetaryGovernanceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +/// TODO: +/// Temporary type that we should replace by RelayChainSlotProvider once async backing is enabled. +pub struct StakingRoundSlotProvider; +impl Get for StakingRoundSlotProvider { + fn get() -> Slot { + let block_number: u64 = frame_system::pallet::Pallet::::block_number().into(); + Slot::from(block_number) + } +} + +impl pallet_parachain_staking::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MonetaryGovernanceOrigin = MonetaryGovernanceOrigin; + /// Minimum round length is 2 minutes (10 * 12 second block times) + type MinBlocksPerRound = ConstU32<10>; + /// If a collator doesn't produce any block on this number of rounds, it is notified as inactive + type MaxOfflineRounds = ConstU32<1>; + /// Rounds before the collator leaving the candidates request can be executed + type LeaveCandidatesDelay = ConstU32<{ 4 * 7 }>; + /// Rounds before the candidate bond increase/decrease can be executed + type CandidateBondLessDelay = ConstU32<{ 4 * 7 }>; + /// Rounds before the delegator exit can be executed + type LeaveDelegatorsDelay = ConstU32<{ 4 * 7 }>; + /// Rounds before the delegator revocation can be executed + type RevokeDelegationDelay = ConstU32<{ 4 * 7 }>; + /// Rounds before the delegator bond increase/decrease can be executed + type DelegationBondLessDelay = ConstU32<{ 4 * 7 }>; + /// Rounds before the reward is paid + type RewardPaymentDelay = ConstU32<2>; + /// Minimum collators selected per round, default at genesis and minimum forever after + type MinSelectedCandidates = ConstU32<8>; + /// Maximum top delegations per candidate + type MaxTopDelegationsPerCandidate = ConstU32<300>; + /// Maximum bottom delegations per candidate + type MaxBottomDelegationsPerCandidate = ConstU32<50>; + /// Maximum delegations per delegator + type MaxDelegationsPerDelegator = ConstU32<100>; + /// Minimum stake required to be reserved to be a candidate + type MinCandidateStk = ConstU128<{ 20_000 * currency::GLMR * currency::SUPPLY_FACTOR }>; + /// Minimum stake required to be reserved to be a delegator + type MinDelegation = ConstU128<{ 500 * currency::MILLIGLMR * currency::SUPPLY_FACTOR }>; + type BlockAuthor = AuthorInherent; + type OnCollatorPayout = (); + type PayoutCollatorReward = PayoutCollatorOrOrbiterReward; + type OnInactiveCollator = OnInactiveCollator; + type OnNewRound = OnNewRound; + type SlotProvider = StakingRoundSlotProvider; + type WeightInfo = moonbeam_weights::pallet_parachain_staking::WeightInfo; + type MaxCandidates = ConstU32<200>; + type SlotDuration = ConstU64<12_000>; + type BlockTime = ConstU64<12_000>; +} + +impl pallet_author_inherent::Config for Runtime { + type SlotBeacon = RelaychainDataProvider; + type AccountLookup = MoonbeamOrbiters; + type CanAuthor = AuthorFilter; + type AuthorId = AccountId; + type WeightInfo = moonbeam_weights::pallet_author_inherent::WeightInfo; +} + +impl pallet_author_slot_filter::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RandomnessSource = Randomness; + type PotentialAuthors = ParachainStaking; + type WeightInfo = moonbeam_weights::pallet_author_slot_filter::WeightInfo; +} + +parameter_types! { + pub const InitializationPayment: Perbill = Perbill::from_percent(30); + pub const RelaySignaturesThreshold: Perbill = Perbill::from_percent(100); + pub const SignatureNetworkIdentifier: &'static [u8] = b"moonbeam-"; +} + +impl pallet_crowdloan_rewards::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Initialized = ConstBool; + type InitializationPayment = InitializationPayment; + type MaxInitContributors = ConstU32<500>; + type MinimumReward = ConstU128<0>; + type RewardCurrency = Balances; + type RelayChainAccountId = [u8; 32]; + type RewardAddressAssociateOrigin = EnsureSigned; + type RewardAddressChangeOrigin = EnsureSigned; + type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; + type SignatureNetworkIdentifier = SignatureNetworkIdentifier; + type VestingBlockNumber = relay_chain::BlockNumber; + type VestingBlockProvider = RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_crowdloan_rewards::WeightInfo; +} + +// This is a simple session key manager. It should probably either work with, or be replaced +// entirely by pallet sessions +impl pallet_author_mapping::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DepositCurrency = Balances; + type DepositAmount = ConstU128<{ 100 * currency::GLMR * currency::SUPPLY_FACTOR }>; + type Keys = session_keys_primitives::VrfId; + type WeightInfo = moonbeam_weights::pallet_author_mapping::WeightInfo; +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + Debug, + MaxEncodedLen, + TypeInfo, + Serialize, + Deserialize, +)] +pub enum ProxyType { + /// All calls can be proxied. This is the trivial/most permissive filter. + Any = 0, + /// Only extrinsics that do not transfer funds. + NonTransfer = 1, + /// Only extrinsics related to governance (democracy and collectives). + Governance = 2, + /// Only extrinsics related to staking. + Staking = 3, + /// Allow to veto an announced proxy call. + CancelProxy = 4, + /// Allow extrinsic related to Balances. + Balances = 5, + /// Allow extrinsic related to AuthorMapping. + AuthorMapping = 6, + /// Allow extrinsic related to IdentityJudgement. + IdentityJudgement = 7, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +fn is_governance_precompile(precompile_name: &precompiles::PrecompileName) -> bool { + matches!( + precompile_name, + PrecompileName::ConvictionVotingPrecompile + | PrecompileName::PreimagePrecompile + | PrecompileName::ReferendaPrecompile + | PrecompileName::OpenTechCommitteeInstance + | PrecompileName::TreasuryCouncilInstance + ) +} + +// Be careful: Each time this filter is modified, the substrate filter must also be modified +// consistently. +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { + fn is_evm_proxy_call_allowed( + &self, + call: &pallet_evm_precompile_proxy::EvmSubCall, + recipient_has_code: bool, + gas: u64, + ) -> precompile_utils::EvmResult { + Ok(match self { + ProxyType::Any => { + match PrecompileName::from_address(call.to.0) { + // Any precompile that can execute a subcall should be forbidden here, + // to ensure that unauthorized smart contract can't be called + // indirectly. + // To be safe, we only allow the precompiles we need. + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + // All non-whitelisted precompiles are forbidden + Some(_) => false, + // Allow evm transfer to "simple" account (no code nor precompile) + // For the moment, no smart contract other than precompiles is allowed. + // In the future, we may create a dynamic whitelist to authorize some audited + // smart contracts through governance. + None => { + // If the address is not recognized, allow only evm transfert to "simple" + // accounts (no code nor precompile). + // Note: Checking the presence of the code is not enough because some + // precompiles have no code. + !recipient_has_code + && precompile_utils::precompile_set::is_precompile_or_fail::( + call.to.0, gas, + )? + } + } + } + ProxyType::NonTransfer => { + call.value == U256::zero() + && match PrecompileName::from_address(call.to.0) { + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } + } + ProxyType::Governance => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(ref precompile) if is_governance_precompile(precompile) + ) + } + ProxyType::Staking => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile + ) + ) + } + // The proxy precompile does not contain method cancel_proxy + ProxyType::CancelProxy => false, + ProxyType::Balances => { + // Allow only "simple" accounts as recipient (no code nor precompile). + // Note: Checking the presence of the code is not enough because some precompiles + // have no code. + !recipient_has_code + && !precompile_utils::precompile_set::is_precompile_or_fail::( + call.to.0, gas, + )? + } + ProxyType::AuthorMapping => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(PrecompileName::AuthorMappingPrecompile) + ) + } + // There is no identity precompile + ProxyType::IdentityJudgement => false, + }) + } +} + +// Be careful: Each time this filter is modified, the EVM filter must also be modified consistently. +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => { + matches!( + c, + RuntimeCall::System(..) + | RuntimeCall::ParachainSystem(..) + | RuntimeCall::Timestamp(..) + | RuntimeCall::ParachainStaking(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Identity(..) + | RuntimeCall::Utility(..) + | RuntimeCall::Proxy(..) | RuntimeCall::AuthorMapping(..) + | RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::claim { .. } + ) + ) + } + ProxyType::Governance => matches!( + c, + RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Utility(..) + ), + ProxyType::Staking => matches!( + c, + RuntimeCall::ParachainStaking(..) + | RuntimeCall::Utility(..) + | RuntimeCall::AuthorMapping(..) + | RuntimeCall::MoonbeamOrbiters(..) + ), + ProxyType::CancelProxy => matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => { + matches!(c, RuntimeCall::Balances(..) | RuntimeCall::Utility(..)) + } + ProxyType::AuthorMapping => matches!(c, RuntimeCall::AuthorMapping(..)), + ProxyType::IdentityJudgement => matches!( + c, + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) + ), + } + } + + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + // One storage item; key size 32, value size 8 + type ProxyDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 21 bytes (20 bytes AccountId + 1 byte sizeof(ProxyType)). + type ProxyDepositFactor = ConstU128<{ currency::deposit(0, 21) }>; + type MaxProxies = ConstU32<32>; + type WeightInfo = moonbeam_weights::pallet_proxy::WeightInfo; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 56 bytes: + // - 20 bytes AccountId + // - 32 bytes Hasher (Blake2256) + // - 4 bytes BlockNumber (u32) + type AnnouncementDepositFactor = ConstU128<{ currency::deposit(0, 56) }>; +} + +impl pallet_migrations::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MigrationsList = (moonbeam_runtime_common::migrations::CommonMigrations,); + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_moonbeam_lazy_migrations::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_moonbeam_lazy_migrations::WeightInfo; +} + +/// Maintenance mode Call filter +pub struct MaintenanceFilter; +impl Contains for MaintenanceFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(_) => false, + RuntimeCall::Balances(_) => false, + RuntimeCall::CrowdloanRewards(_) => false, + RuntimeCall::Ethereum(_) => false, + RuntimeCall::EVM(_) => false, + RuntimeCall::Identity(_) => false, + RuntimeCall::XTokens(_) => false, + RuntimeCall::ParachainStaking(_) => false, + RuntimeCall::MoonbeamOrbiters(_) => false, + RuntimeCall::PolkadotXcm(_) => false, + RuntimeCall::Treasury(_) => false, + RuntimeCall::XcmTransactor(_) => false, + RuntimeCall::EthereumXcm(_) => false, + _ => true, + } + } +} + +/// Normal Call Filter +/// We dont allow to create nor mint assets, this for now is disabled +/// We only allow transfers. For now creation of assets will go through +/// asset-manager, while minting/burning only happens through xcm messages +/// This can change in the future +pub struct NormalFilter; +impl Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(method) => match method { + pallet_assets::Call::transfer { .. } => true, + pallet_assets::Call::transfer_keep_alive { .. } => true, + pallet_assets::Call::approve_transfer { .. } => true, + pallet_assets::Call::transfer_approved { .. } => true, + pallet_assets::Call::cancel_approval { .. } => true, + pallet_assets::Call::destroy_accounts { .. } => true, + pallet_assets::Call::destroy_approvals { .. } => true, + pallet_assets::Call::finish_destroy { .. } => true, + _ => false, + }, + // We just want to enable this in case of live chains, since the default version + // is populated at genesis + RuntimeCall::PolkadotXcm(method) => match method { + pallet_xcm::Call::force_default_xcm_version { .. } => true, + _ => false, + }, + // We filter anonymous proxy as they make "reserve" inconsistent + // See: https://github.com/paritytech/substrate/blob/37cca710eed3dadd4ed5364c7686608f5175cce1/frame/proxy/src/lib.rs#L270 // editorconfig-checker-disable-line + RuntimeCall::Proxy(method) => match method { + pallet_proxy::Call::create_pure { .. } => false, + pallet_proxy::Call::kill_pure { .. } => false, + pallet_proxy::Call::proxy { real, .. } => { + !pallet_evm::AccountCodes::::contains_key(H160::from(*real)) + } + _ => true, + }, + // Filtering the EVM prevents possible re-entrancy from the precompiles which could + // lead to unexpected scenarios. + // See https://github.com/PureStake/sr-moonbeam/issues/30 + // Note: It is also assumed that EVM calls are only allowed through `Origin::Root` so + // this can be seen as an additional security + RuntimeCall::EVM(_) => false, + RuntimeCall::Treasury( + pallet_treasury::Call::spend { .. } + | pallet_treasury::Call::payout { .. } + | pallet_treasury::Call::check_status { .. } + | pallet_treasury::Call::void_spend { .. }, + ) => false, + _ => true, + } + } +} + +pub struct XcmExecutionManager; +impl moonkit_xcm_primitives::PauseXcmExecution for XcmExecutionManager { + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(RuntimeOrigin::root()) + } + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(RuntimeOrigin::root()) + } +} + +impl pallet_maintenance_mode::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type NormalCallFilter = NormalFilter; + type MaintenanceCallFilter = MaintenanceFilter; + type MaintenanceOrigin = + pallet_collective::EnsureProportionAtLeast; + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_proxy_genesis_companion::Config for Runtime { + type ProxyType = ProxyType; +} + +parameter_types! { + pub OrbiterReserveIdentifier: [u8; 4] = [b'o', b'r', b'b', b'i']; +} + +type AddCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type DelCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_moonbeam_orbiters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AccountLookup = AuthorMapping; + type AddCollatorOrigin = AddCollatorOrigin; + type Currency = Balances; + type DelCollatorOrigin = DelCollatorOrigin; + /// Maximum number of orbiters per collator + type MaxPoolSize = ConstU32<8>; + /// Maximum number of round to keep on storage + type MaxRoundArchive = ConstU32<4>; + type OrbiterReserveIdentifier = OrbiterReserveIdentifier; + type RotatePeriod = ConstU32<1>; + /// Round index type. + type RoundIndex = pallet_parachain_staking::RoundIndex; + type WeightInfo = moonbeam_weights::pallet_moonbeam_orbiters::WeightInfo; +} + +/// Only callable after `set_validation_data` is called which forms this proof the same way +fn relay_chain_state_proof() -> RelayChainStateProof { + let relay_storage_root = ParachainSystem::validation_data() + .expect("set in `set_validation_data`") + .relay_parent_storage_root; + let relay_chain_state = + ParachainSystem::relay_state_proof().expect("set in `set_validation_data`"); + RelayChainStateProof::new(ParachainInfo::get(), relay_storage_root, relay_chain_state) + .expect("Invalid relay chain state proof, already constructed in `set_validation_data`") +} + +pub struct BabeDataGetter; +impl pallet_randomness::GetBabeData> for BabeDataGetter { + // Tolerate panic here because only ever called in inherent (so can be omitted) + fn get_epoch_index() -> u64 { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + const BENCHMARKING_NEW_EPOCH: u64 = 10u64; + return BENCHMARKING_NEW_EPOCH; + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::EPOCH_INDEX) + .ok() + .flatten() + .expect("expected to be able to read epoch index from relay chain state proof") + } + fn get_epoch_randomness() -> Option { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + let benchmarking_babe_output = Hash::default(); + return Some(benchmarking_babe_output); + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::ONE_EPOCH_AGO_RANDOMNESS) + .ok() + .flatten() + } +} + +impl pallet_randomness::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddressMapping = sp_runtime::traits::ConvertInto; + type Currency = Balances; + type BabeDataGetter = BabeDataGetter; + type VrfKeyLookup = AuthorMapping; + type Deposit = ConstU128<{ 1 * currency::GLMR * currency::SUPPLY_FACTOR }>; + type MaxRandomWords = ConstU8<100>; + type MinBlockDelay = ConstU32<2>; + type MaxBlockDelay = ConstU32<2_000>; + type BlockExpirationDelay = ConstU32<10_000>; + type EpochExpirationDelay = ConstU64<10_000>; + type WeightInfo = moonbeam_weights::pallet_randomness::WeightInfo; +} + +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +parameter_types! { + // One storage item; key size is 32 + 20; value is size 4+4+16+20 bytes = 44 bytes. + pub const DepositBase: Balance = currency::deposit(1, 96); + // Additional storage item size of 20 bytes. + pub const DepositFactor: Balance = currency::deposit(0, 20); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type WeightInfo = moonbeam_weights::pallet_multisig::WeightInfo; +} + +impl pallet_relay_storage_roots::Config for Runtime { + type MaxStorageRoots = ConstU32<30>; + type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_relay_storage_roots::WeightInfo; +} + +impl pallet_precompile_benchmarks::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo; +} + +construct_runtime! { + pub enum Runtime + { + // System support stuff. + System: frame_system::{Pallet, Call, Storage, Config, Event} = 0, + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 1, + // Previously 2: pallet_randomness_collective_flip + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3, + ParachainInfo: parachain_info::{Pallet, Storage, Config} = 4, + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 5, + + // Monetary stuff. + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Config, Event} = 11, + + // Consensus support. + ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event, Config} = 20, + AuthorInherent: pallet_author_inherent::{Pallet, Call, Storage, Inherent} = 21, + AuthorFilter: pallet_author_slot_filter::{Pallet, Call, Storage, Event, Config} = 22, + AuthorMapping: pallet_author_mapping::{Pallet, Call, Config, Storage, Event} = 23, + MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event} = 24, + + // Handy utilities. + Utility: pallet_utility::{Pallet, Call, Event} = 30, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 31, + MaintenanceMode: pallet_maintenance_mode::{Pallet, Call, Config, Storage, Event} = 32, + Identity: pallet_identity::{Pallet, Call, Storage, Event} = 33, + Migrations: pallet_migrations::{Pallet, Storage, Config, Event} = 34, + ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, + Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, + MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + + // Has been permanently removed for safety reasons. + // Sudo: pallet_sudo::{Pallet, Call, Config, Storage, Event} = 40, + + // Ethereum compatibility. + EthereumChainId: pallet_evm_chain_id::{Pallet, Storage, Config} = 50, + EVM: pallet_evm::{Pallet, Config, Call, Storage, Event} = 51, + Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Origin, Config} = 52, + + // Governance stuff. + Scheduler: pallet_scheduler::{Pallet, Storage, Event, Call} = 60, + // Democracy: 61, + Preimage: pallet_preimage::{Pallet, Call, Storage, Event, HoldReason} = 62, + ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event} = 63, + Referenda: pallet_referenda::{Pallet, Call, Storage, Event} = 64, + Origins: governance::custom_origins::{Origin} = 65, + Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event} = 66, + + // Council stuff. + // CouncilCollective: 70 + // TechCommitteeCollective: 71 + TreasuryCouncilCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 72, + OpenTechCommitteeCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 73, + + // Treasury stuff. + Treasury: pallet_treasury::{Pallet, Storage, Config, Event, Call} = 80, + + // Crowdloan stuff. + CrowdloanRewards: pallet_crowdloan_rewards::{Pallet, Call, Config, Storage, Event} = 90, + + // XCM + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Storage, Event} = 100, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 101, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 102, + PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, + Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, + AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, + XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, + // Previously 108: pallet_assets:: + EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin} = 109, + Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110, + MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 111, + RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112, + PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 113, + + // Randomness + Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, + } +} + +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +mod benches { + frame_support::parameter_types! { + pub const MaxBalance: crate::Balance = crate::Balance::max_value(); + } + + frame_benchmarking::define_benchmarks!( + [pallet_utility, Utility] + [pallet_timestamp, Timestamp] + [pallet_balances, Balances] + [pallet_evm, EVM] + [pallet_assets, Assets] + [pallet_parachain_staking, ParachainStaking] + [pallet_scheduler, Scheduler] + [pallet_treasury, Treasury] + [pallet_author_inherent, AuthorInherent] + [pallet_author_slot_filter, AuthorFilter] + [pallet_crowdloan_rewards, CrowdloanRewards] + [pallet_author_mapping, AuthorMapping] + [pallet_proxy, Proxy] + [pallet_identity, Identity] + [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] + [pallet_asset_manager, AssetManager] + [pallet_xcm_transactor, XcmTransactor] + [pallet_moonbeam_orbiters, MoonbeamOrbiters] + [pallet_randomness, Randomness] + [pallet_conviction_voting, ConvictionVoting] + [pallet_referenda, Referenda] + [pallet_preimage, Preimage] + [pallet_whitelist, Whitelist] + [pallet_multisig, Multisig] + [pallet_moonbeam_lazy_migrations, MoonbeamLazyMigrations] + [pallet_relay_storage_roots, RelayStorageRoots] + ); +} + +/// Block type as expected by this runtime. +pub type Block = generic::Block; +/// A Block signed with a Justification +pub type SignedBlock = generic::SignedBlock; +/// BlockId type as expected by this runtime. +pub type BlockId = generic::BlockId; + +/// The SignedExtension to the basic transaction logic. +pub type SignedExtra = ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, +); +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + fp_self_contained::UncheckedExtrinsic; +/// Extrinsic type that has already been checked. +pub type CheckedExtrinsic = + fp_self_contained::CheckedExtrinsic; +/// Executive: handles dispatch to the various pallets. +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllPalletsWithSystem, +>; + +// All of our runtimes share most of their Runtime API implementations. +// We use a macro to implement this common part and add runtime-specific additional implementations. +// This macro expands to : +// ``` +// impl_runtime_apis! { +// // All impl blocks shared between all runtimes. +// +// // Specific impls provided to the `impl_runtime_apis_plus_common!` macro. +// } +// ``` +moonbeam_runtime_common::impl_runtime_apis_plus_common! { + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + xt: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + // Filtered calls should not enter the tx pool as they'll fail if inserted. + // If this call is not allowed, we return early. + if !::BaseCallFilter::contains(&xt.0.function) { + return InvalidTransaction::Call.into(); + } + + // This runtime uses Substrate's pallet transaction payment. This + // makes the chain feel like a standard Substrate chain when submitting + // frame transactions and using Substrate ecosystem tools. It has the downside that + // transaction are not prioritized by gas_price. The following code reprioritizes + // transactions to overcome this. + // + // A more elegant, ethereum-first solution is + // a pallet that replaces pallet transaction payment, and allows users + // to directly specify a gas price rather than computing an effective one. + // #HopefullySomeday + + // First we pass the transactions to the standard FRAME executive. This calculates all the + // necessary tags, longevity and other properties that we will leave unchanged. + // This also assigns some priority that we don't care about and will overwrite next. + let mut intermediate_valid = Executive::validate_transaction(source, xt.clone(), block_hash)?; + + let dispatch_info = xt.get_dispatch_info(); + + // If this is a pallet ethereum transaction, then its priority is already set + // according to gas price from pallet ethereum. If it is any other kind of transaction, + // we modify its priority. + Ok(match &xt.0.function { + RuntimeCall::Ethereum(transact { .. }) => intermediate_valid, + _ if dispatch_info.class != DispatchClass::Normal => intermediate_valid, + _ => { + let tip = match xt.0.signature { + None => 0, + Some((_, _, ref signed_extra)) => { + // Yuck, this depends on the index of charge transaction in Signed Extra + let charge_transaction = &signed_extra.7; + charge_transaction.tip() + } + }; + + // Calculate the fee that will be taken by pallet transaction payment + let fee: u64 = TransactionPayment::compute_fee( + xt.encode().len() as u32, + &dispatch_info, + tip, + ).saturated_into(); + + // Calculate how much gas this effectively uses according to the existing mapping + let effective_gas = + ::GasWeightMapping::weight_to_gas( + dispatch_info.weight + ); + + // Here we calculate an ethereum-style effective gas price using the + // current fee of the transaction. Because the weight -> gas conversion is + // lossy, we have to handle the case where a very low weight maps to zero gas. + let effective_gas_price = if effective_gas > 0 { + fee / effective_gas + } else { + // If the effective gas was zero, we just act like it was 1. + fee + }; + + // Overwrite the original prioritization with this ethereum one + intermediate_valid.priority = effective_gas_price; + intermediate_valid + } + }) + } + } + + impl async_backing_primitives::UnincludedSegmentApi for Runtime { + fn can_build_upon( + _included_hash: ::Hash, + _slot: async_backing_primitives::Slot, + ) -> bool { + // This runtime API can be called only when asynchronous backing is enabled client-side + // We return false here to force the client to not use async backing in moonbeam. + false + } + } +} + +struct CheckInherents; + +// Parity has decided to depreciate this trait, but does not offer a satisfactory replacement, +// see issue: https://github.com/paritytech/polkadot-sdk/issues/2841 +#[allow(deprecated)] +impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { + fn check_inherents( + block: &Block, + relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, + ) -> sp_inherents::CheckInherentsResult { + let relay_chain_slot = relay_state_proof + .read_slot() + .expect("Could not read the relay chain slot from the proof"); + let inherent_data = + cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( + relay_chain_slot, + sp_std::time::Duration::from_secs(6), + ) + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); + inherent_data.check_extrinsics(block) + } +} + +// Nimbus's Executive wrapper allows relay validators to verify the seal digest +cumulus_pallet_parachain_system::register_validate_block!( + Runtime = Runtime, + BlockExecutor = pallet_author_inherent::BlockExecutor::, + CheckInherents = CheckInherents, +); + +moonbeam_runtime_common::impl_self_contained_call!(); + +// Shorthand for a Get field of a pallet Config. +#[macro_export] +macro_rules! get { + ($pallet:ident, $name:ident, $type:ty) => { + <<$crate::Runtime as $pallet::Config>::$name as $crate::Get<$type>>::get() + }; +} + +#[cfg(test)] +mod tests { + use super::{currency::*, *}; + + #[test] + // Helps us to identify a Pallet Call in case it exceeds the 1kb limit. + // Hint: this should be a rare case. If that happens, one or more of the dispatchable arguments + // need to be Boxed. + fn call_max_size() { + const CALL_ALIGN: u32 = 1024; + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + } + + #[test] + fn currency_constants_are_correct() { + assert_eq!(SUPPLY_FACTOR, 100); + + // txn fees + assert_eq!(TRANSACTION_BYTE_FEE, Balance::from(100 * GIGAWEI)); + assert_eq!( + get!(pallet_transaction_payment, OperationalFeeMultiplier, u8), + 5_u8 + ); + assert_eq!(STORAGE_BYTE_FEE, Balance::from(10 * MILLIGLMR)); + + // treasury minimums + assert_eq!( + get!(pallet_treasury, ProposalBondMinimum, u128), + Balance::from(100 * GLMR) + ); + + // pallet_identity deposits + assert_eq!( + get!(pallet_identity, BasicDeposit, u128), + Balance::from(10 * GLMR + 2580 * MILLIGLMR) + ); + assert_eq!( + get!(pallet_identity, ByteDeposit, u128), + Balance::from(10 * MILLIGLMR) + ); + assert_eq!( + get!(pallet_identity, SubAccountDeposit, u128), + Balance::from(10 * GLMR + 530 * MILLIGLMR) + ); + + // staking minimums + assert_eq!( + get!(pallet_parachain_staking, MinCandidateStk, u128), + Balance::from(2_000_000 * GLMR) + ); + assert_eq!( + get!(pallet_parachain_staking, MinDelegation, u128), + Balance::from(50 * GLMR) + ); + + // crowdloan min reward + assert_eq!( + get!(pallet_crowdloan_rewards, MinimumReward, u128), + Balance::from(0u128) + ); + + // deposit for AuthorMapping + assert_eq!( + get!(pallet_author_mapping, DepositAmount, u128), + Balance::from(10 * KILOGLMR) + ); + + // proxy deposits + assert_eq!( + get!(pallet_proxy, ProxyDepositBase, u128), + Balance::from(10 * GLMR + 80 * MILLIGLMR) + ); + assert_eq!( + get!(pallet_proxy, ProxyDepositFactor, u128), + Balance::from(210 * MILLIGLMR) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositBase, u128), + Balance::from(10 * GLMR + 80 * MILLIGLMR) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositFactor, u128), + Balance::from(560 * MILLIGLMR) + ); + } + + #[test] + fn max_offline_rounds_lower_or_eq_than_reward_payment_delay() { + assert!( + get!(pallet_parachain_staking, MaxOfflineRounds, u32) + <= get!(pallet_parachain_staking, RewardPaymentDelay, u32) + ); + } + + #[test] + // Required migration is + // pallet_parachain_staking::migrations::IncreaseMaxTopDelegationsPerCandidate + // Purpose of this test is to remind of required migration if constant is ever changed + fn updating_maximum_delegators_per_candidate_requires_configuring_required_migration() { + assert_eq!( + get!(pallet_parachain_staking, MaxTopDelegationsPerCandidate, u32), + 300 + ); + assert_eq!( + get!( + pallet_parachain_staking, + MaxBottomDelegationsPerCandidate, + u32 + ), + 50 + ); + } + + #[test] + fn configured_base_extrinsic_weight_is_evm_compatible() { + let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000; + let base_extrinsic = ::BlockWeights::get() + .get(frame_support::dispatch::DispatchClass::Normal) + .base_extrinsic; + assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time()); + } + + #[test] + fn test_storage_growth_ratio_is_correct() { + // This is the highest amount of new storage that can be created in a block 40 KB + let block_storage_limit = 40 * 1024; + let expected_storage_growth_ratio = BlockGasLimit::get() + .low_u64() + .saturating_div(block_storage_limit); + let actual_storage_growth_ratio = + ::GasLimitStorageGrowthRatio::get(); + assert_eq!( + expected_storage_growth_ratio, actual_storage_growth_ratio, + "Storage growth ratio is not correct" + ); + } +} diff --git a/tracing/2902/runtime/moonbeam/src/precompiles.rs b/tracing/2902/runtime/moonbeam/src/precompiles.rs new file mode 100644 index 00000000..d0098d0d --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/precompiles.rs @@ -0,0 +1,285 @@ +// 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::{ + asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance, + TreasuryCouncilInstance, +}; +use crate::{AssetId, H160}; +use frame_support::parameter_types; +use pallet_evm_precompile_author_mapping::AuthorMappingPrecompile; +use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata}; +use pallet_evm_precompile_batch::BatchPrecompile; +use pallet_evm_precompile_blake2::Blake2F; +use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; +use pallet_evm_precompile_call_permit::CallPermitPrecompile; +use pallet_evm_precompile_collective::CollectivePrecompile; +use pallet_evm_precompile_conviction_voting::ConvictionVotingPrecompile; +use pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompile; +use pallet_evm_precompile_gmp::GmpPrecompile; +use pallet_evm_precompile_identity::IdentityPrecompile; +use pallet_evm_precompile_modexp::Modexp; +use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile; +use pallet_evm_precompile_preimage::PreimagePrecompile; +use pallet_evm_precompile_proxy::{OnlyIsProxyAndProxy, ProxyPrecompile}; +use pallet_evm_precompile_randomness::RandomnessPrecompile; +use pallet_evm_precompile_referenda::ReferendaPrecompile; +use pallet_evm_precompile_registry::PrecompileRegistry; +use pallet_evm_precompile_relay_encoder::RelayEncoderPrecompile; +use pallet_evm_precompile_relay_verifier::RelayDataVerifierPrecompile; +use pallet_evm_precompile_sha3fips::Sha3FIPS256; +use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_xcm_transactor::{ + v1::XcmTransactorPrecompileV1, v2::XcmTransactorPrecompileV2, v3::XcmTransactorPrecompileV3, +}; +use pallet_evm_precompile_xcm_utils::XcmUtilsPrecompile; +use pallet_evm_precompile_xtokens::XtokensPrecompile; +use pallet_evm_precompileset_assets_erc20::{AccountIdAssetIdConversion, Erc20AssetsPrecompileSet}; +use precompile_utils::precompile_set::*; +use sp_std::prelude::*; + +pub struct NativeErc20Metadata; + +/// ERC20 metadata for the native token. +impl Erc20Metadata for NativeErc20Metadata { + /// Returns the name of the token. + fn name() -> &'static str { + "GLMR token" + } + + /// Returns the symbol of the token. + fn symbol() -> &'static str { + "GLMR" + } + + /// Returns the decimals places of the token. + fn decimals() -> u8 { + 18 + } + + /// Must return `true` only if it represents the main native currency of + /// the network. It must be the currency used in `pallet_evm`. + fn is_native_currency() -> bool { + true + } +} + +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as foreign +pub const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as local +pub const LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8, 255u8, 255u8, 254u8]; + +parameter_types! { + pub ForeignAssetPrefix: &'static [u8] = FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX; + pub LocalAssetPrefix: &'static [u8] = LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX; +} + +type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile); + +#[precompile_utils::precompile_name_from_address] +type MoonbeamPrecompilesAt = ( + // Ethereum precompiles: + // We allow DELEGATECALL to stay compliant with Ethereum behavior. + PrecompileAt, ECRecover, EthereumPrecompilesChecks>, + PrecompileAt, Sha256, EthereumPrecompilesChecks>, + PrecompileAt, Ripemd160, EthereumPrecompilesChecks>, + PrecompileAt, Identity, EthereumPrecompilesChecks>, + PrecompileAt, Modexp, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Add, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Mul, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Pairing, EthereumPrecompilesChecks>, + PrecompileAt, Blake2F, EthereumPrecompilesChecks>, + // Non-Moonbeam specific nor Ethereum precompiles : + PrecompileAt, Sha3FIPS256, (CallableByContract, CallableByPrecompile)>, + RemovedPrecompileAt>, // Dispatch + PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, + // Moonbeam specific precompiles: + PrecompileAt< + AddressU64<2048>, + ParachainStakingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2049>, + CrowdloanRewardsPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2050>, + Erc20BalancesPrecompile, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompileAt>, // Democracy + PrecompileAt< + AddressU64<2052>, + XtokensPrecompile, + ( + SubcallWithMaxNesting<1>, + CallableByContract, + CallableByPrecompile, + ), + >, + PrecompileAt< + AddressU64<2053>, + RelayEncoderPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2054>, + XcmTransactorPrecompileV1, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2055>, + AuthorMappingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2056>, + BatchPrecompile, + ( + SubcallWithMaxNesting<2>, + // Batch is the only precompile allowed to call Batch. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2057>, + RandomnessPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2058>, + CallPermitPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2059>, + ProxyPrecompile, + ( + CallableByContract>, + SubcallWithMaxNesting<0>, + // Batch is the only precompile allowed to call Proxy. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2060>, + XcmUtilsPrecompile, + CallableByContract< + pallet_evm_precompile_xcm_utils::AllExceptXcmExecute, + >, + >, + PrecompileAt< + AddressU64<2061>, + XcmTransactorPrecompileV2, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompileAt>, //CouncilInstance + RemovedPrecompileAt>, // TechCommitteeInstance + PrecompileAt< + AddressU64<2064>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2065>, + ReferendaPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2066>, + ConvictionVotingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2067>, + PreimagePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2068>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2069>, + PrecompileRegistry, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt, GmpPrecompile, SubcallWithMaxNesting<0>>, + PrecompileAt< + AddressU64<2071>, + XcmTransactorPrecompileV3, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2072>, + IdentityPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2073>, + RelayDataVerifierPrecompile, + (CallableByContract, CallableByPrecompile), + >, +); + +pub struct DisabledLocalAssets(sp_std::marker::PhantomData); + +impl sp_core::Get> for DisabledLocalAssets +where + Runtime: frame_system::Config, + Runtime::AccountId: Into, + Runtime: AccountIdAssetIdConversion, +{ + fn get() -> Vec { + vec![ + 337110116006454532607322340792629567158u128, + 278750993613512357835566279094880339619, + 228256396637196286254896220398224702687, + 270195117769614861929703564202131636628, + ] + .iter() + .map(|id| Runtime::asset_id_to_account(LOCAL_ASSET_PRECOMPILE_ADDRESS_PREFIX, *id).into()) + .collect() + } +} + +/// The PrecompileSet installed in the Moonbeam runtime. +/// We include the nine Istanbul precompiles +/// (https://github.com/ethereum/go-ethereum/blob/3c46f557/core/vm/contracts.go#L69) +/// as well as a special precompile for dispatching Substrate extrinsics +/// The following distribution has been decided for the precompiles +/// 0-1023: Ethereum Mainnet Precompiles +/// 1024-2047 Precompiles that are not in Ethereum Mainnet but are neither Moonbeam specific +/// 2048-4095 Moonbeam specific precompiles +pub type MoonbeamPrecompiles = PrecompileSetBuilder< + R, + ( + // Skip precompiles if out of range. + PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<4095>), MoonbeamPrecompilesAt>, + // Prefixed precompile sets (XC20) + PrecompileSetStartingWith< + ForeignAssetPrefix, + Erc20AssetsPrecompileSet, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompilesAt>, + ), +>; diff --git a/tracing/2902/runtime/moonbeam/src/xcm_config.rs b/tracing/2902/runtime/moonbeam/src/xcm_config.rs new file mode 100644 index 00000000..7042ac8f --- /dev/null +++ b/tracing/2902/runtime/moonbeam/src/xcm_config.rs @@ -0,0 +1,709 @@ +// 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 . + +//! XCM configuration for Moonbase. +//! + +use super::{ + governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees, Erc20XcmBridge, + MaintenanceMode, MessageQueue, ParachainInfo, ParachainSystem, Perbill, PolkadotXcm, Runtime, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, XcmpQueue, +}; + +use frame_support::{ + parameter_types, + traits::{EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin}, +}; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; +use sp_runtime::{ + traits::{Hash as THash, MaybeEquivalence, PostDispatchInfoOf}, + DispatchErrorWithPostInfo, +}; +use sp_weights::Weight; + +use frame_system::{EnsureRoot, RawOrigin}; +use sp_core::{ConstU32, H160, H256}; + +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, DescribeAllTerminal, DescribeFamily, + EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription, + NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin, +}; + +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use xcm::latest::prelude::{ + Asset, GlobalConsensus, InteriorLocation, Junction, Location, NetworkId, PalletInstance, + Parachain, +}; +use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; + +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use orml_xcm_support::MultiNativeAsset; +use xcm_primitives::{ + AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, + FirstAssetTrader, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact, +}; + +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; + +use sp_core::Get; +use sp_std::{ + convert::{From, Into, TryFrom}, + prelude::*, +}; + +use orml_traits::parameter_type_with_key; + +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; + +parameter_types! { + // The network Id of the relay + pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + // The relay chain Origin type + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); + // Self Reserve location, defines the multilocation identifiying the self-reserve currency + // This is used to match it also against our Balances pallet when we receive such + // a Location: (Self Balances pallet index) + // We use the RELATIVE multilocation + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // If we receive a Location of type AccountKey20, just generate a native account + AccountKey20Aliases, + // Generate remote accounts according to polkadot standards + HashedDescription>, +); + +/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`. +pub struct LocationToH160; +impl ConvertLocation for LocationToH160 { + fn convert_location(location: &Location) -> Option { + >::convert_location(location) + .map(Into::into) + } +} + +// The non-reserve fungible transactor type +// It will use pallet-assets, and the Id will be matched against AsAssetType +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + super::Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId20 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +/// The transactor for our own chain currency. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + xcm_builder::IsConcrete, + // We can convert the MultiLocations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// We use all transactors +pub type AssetTransactors = ( + LocalAssetTransactor, + ForeignFungiblesTransactor, + Erc20XcmBridge, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + // Xcm Origins defined by a Multilocation of type AccountKey20 can be converted to a 20 byte- + // account local origin + SignedAccountKey20AsNative, +); + +parameter_types! { + /// The amount of weight an XCM operation takes. This is safe overestimate. + pub UnitWeightCost: Weight = Weight::from_parts(200_000_000u64, 0); + /// Maximum number of instructions in a single XCM fragment. A sanity check against + /// weight caculations getting too crazy. + pub MaxInstructions: u32 = 100; +} + +/// Xcm Weigher shared between multiple Xcm-related configs. +pub type XcmWeigher = WeightInfoBounds< + moonbeam_xcm_benchmarks::weights::XcmWeight, + RuntimeCall, + MaxInstructions, +>; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +/// We do not burn anything because we want to mimic exactly what +/// the sovereign account has +pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount< + super::Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +pub struct SafeCallFilter; +impl frame_support::traits::Contains for SafeCallFilter { + fn contains(_call: &RuntimeCall) -> bool { + // TODO review + // This needs to be addressed at EVM level + true + } +} + +parameter_types! { + pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS; +} + +// Our implementation of the Moonbeam Call +// Attachs the right origin in case the call is made to pallet-ethereum-xcm +#[cfg(not(feature = "evm-tracing"))] +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); +#[cfg(feature = "evm-tracing")] +moonbeam_runtime_common::impl_moonbeam_xcm_call_tracing!(); + +moonbeam_runtime_common::impl_evm_runner_precompile_or_eth_xcm!(); + +pub struct XcmExecutorConfig; +impl xcm_executor::Config for XcmExecutorConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + // Filter to the reserve withdraw operations + // Whenever the reserve matches the relative or absolute value + // of our chain, we always return the relative reserve + type IsReserve = MultiNativeAsset>; + type IsTeleporter = (); // No teleport + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = XcmWeigher; + // We use two traders + // When we receive the relative representation of the self-reserve asset, + // we use UsingComponents and the local way of handling fees + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + UsingComponents< + ::WeightToFee, + SelfReserve, + AccountId, + Balances, + DealWithFees, + >, + FirstAssetTrader, + ); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = pallet_erc20_xcm_bridge::AssetTrapWrapper; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type PalletInstancesInfo = crate::AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = SafeCallFilter; + type Aliasers = Nothing; + type TransactionalProcessor = xcm_builder::FrameTransactionalProcessor; +} + +type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper< + XcmExecutorConfig, + xcm_executor::XcmExecutor, +>; + +// Converts a Signed Local Origin into a Location +pub type LocalOriginToLocation = SignedToAccountId20; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = ( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +); + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + // TODO pallet-xcm weights + type WeightInfo = moonbeam_weights::pallet_xcm::WeightInfo; + type AdminOrigin = EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ChannelInfo = ParachainSystem; + type VersionWrapper = PolkadotXcm; + type XcmpQueue = TransformOrigin; + type MaxInboundSuspended = sp_core::ConstU32<1_000>; + type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type WeightInfo = moonbeam_weights::cumulus_pallet_xcmp_queue::WeightInfo; + type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery< + cumulus_primitives_core::ParaId, + >; +} + +parameter_types! { + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +// TODO: This pallet can be removed after the lazy migration is done and +// event `Completed` is emitted. +// https://github.com/paritytech/polkadot-sdk/pull/1246 +impl cumulus_pallet_dmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DmpSink = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; +} + +parameter_types! { + /// The amount of weight (if any) which should be provided to the message queue for + /// servicing enqueued items. + /// + /// This may be legitimately `None` in the case that you will call + /// `ServiceQueues::service_queues` manually. + pub MessageQueueServiceWeight: Weight = + Perbill::from_percent(25) * RuntimeBlockWeights::get().max_block; + /// The maximum number of stale pages (i.e. of overweight messages) allowed before culling + /// can happen. Once there are more stale pages than this, then historical pages may be + /// dropped, even if they contain unprocessed overweight messages. + pub const MessageQueueMaxStale: u32 = 8; + /// The size of the page; this implies the maximum message size which can be sent. + /// + /// A good value depends on the expected message sizes, their weights, the weight that is + /// available for processing them and the maximal needed message size. The maximal message + /// size is slightly lower than this as defined by [`MaxMessageLenOf`]. + pub const MessageQueueHeapSize: u32 = 128 * 1048; +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + #[cfg(feature = "runtime-benchmarks")] + type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor< + cumulus_primitives_core::AggregateMessageOrigin, + >; + #[cfg(not(feature = "runtime-benchmarks"))] + type MessageProcessor = + xcm_builder::ProcessXcmMessage; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: + type QueueChangeHandler = NarrowOriginToSibling; + // NarrowOriginToSibling calls XcmpQueue's is_paused if Origin is sibling. Allows all other origins + type QueuePausedQuery = (MaintenanceMode, NarrowOriginToSibling); + type WeightInfo = pallet_message_queue::weights::SubstrateWeight; +} + +// Our AssetType. For now we only handle Xcm Assets +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum AssetType { + Xcm(xcm::v3::Location), +} +impl Default for AssetType { + fn default() -> Self { + Self::Xcm(xcm::v3::Location::here()) + } +} + +impl From for AssetType { + fn from(location: xcm::v3::Location) -> Self { + Self::Xcm(location) + } +} + +// This can be removed once we fully adopt xcm::v4 everywhere +impl TryFrom for AssetType { + type Error = (); + fn try_from(location: Location) -> Result { + Ok(Self::Xcm(location.try_into()?)) + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => Some(location), + } + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => xcm_builder::V4V3LocationConverter::convert_back(&location), + } + } +} + +// Implementation on how to retrieve the AssetId from an AssetType +// We simply hash the AssetType and take the lowest 128 bits +impl From for AssetId { + fn from(asset: AssetType) -> AssetId { + match asset { + AssetType::Xcm(id) => { + let mut result: [u8; 16] = [0u8; 16]; + let hash: H256 = id.using_encoded(::Hashing::hash); + result.copy_from_slice(&hash.as_fixed_bytes()[0..16]); + u128::from_le_bytes(result) + } + } + } +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + // Our native token + SelfReserve, + // Assets representing other chains native tokens + ForeignAsset(AssetId), + // Erc20 token + Erc20 { contract_address: H160 }, +} + +impl AccountIdToCurrencyId for Runtime { + fn account_to_currency_id(account: AccountId) -> Option { + Some(match account { + // the self-reserve currency is identified by the pallet-balances address + a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve, + // the rest of the currencies, by their corresponding erc20 address + _ => match Runtime::account_to_asset_id(account) { + // We distinguish by prefix, and depending on it we create either + // Foreign or Local + Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id), + // If no known prefix is identified, we consider that it's a "real" erc20 token + // (i.e. managed by a real smart contract) + None => CurrencyId::Erc20 { + contract_address: account.into(), + }, + }, + }) + } +} +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: sp_runtime::traits::MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + CurrencyId::Erc20 { contract_address } => { + let mut location = Erc20XcmBridgePalletLocation::get(); + location + .push_interior(Junction::AccountKey20 { + key: contract_address.0, + network: None, + }) + .ok(); + Some(location) + } + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(200_000_000u64, 0); + pub const MaxAssetsForTransfer: usize = 2; + + // This is how we are going to detect whether the asset is a Reserve asset + // This however is the chain part only + pub SelfLocation: Location = Location::here(); + // We need this to be able to catch when someone is trying to execute a non- + // cross-chain transfer in xtokens through the absolute path way + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(ParachainInfo::parachain_id().into()) + ].into() + }; +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + // Polkadot AssetHub fee + (1, Some(Parachain(1000u32))) => Some(50_000_000u128), + _ => None, + } + }; +} + +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdConvert = CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = AbsoluteAndRelativeReserve; +} + +// 1 DOT should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +// For now we only allow to transact in the relay, although this might change in the future +// Transactors just defines the chains in which we allow transactions to be issued through +// xcm +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum Transactors { + Relay, +} + +// Default for benchmarking +#[cfg(feature = "runtime-benchmarks")] +impl Default for Transactors { + fn default() -> Self { + Transactors::Relay + } +} + +impl TryFrom for Transactors { + type Error = (); + fn try_from(value: u8) -> Result { + match value { + 0u8 => Ok(Transactors::Relay), + _ => Err(()), + } + } +} + +impl UtilityEncodeCall for Transactors { + fn encode_call(self, call: UtilityAvailableCalls) -> Vec { + match self { + Transactors::Relay => pallet_xcm_transactor::Pallet::::encode_call( + pallet_xcm_transactor::Pallet(sp_std::marker::PhantomData::), + call, + ), + } + } +} + +impl XcmTransact for Transactors { + fn destination(self) -> Location { + match self { + Transactors::Relay => Location::parent(), + } + } +} + +pub type DerivativeAddressRegistrationOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = Transactors; + type DerivativeAddressRegistrationOrigin = DerivativeAddressRegistrationOrigin; + type SovereignAccountDispatcherOrigin = EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdToLocation = CurrencyIdToLocation>; + type XcmSender = XcmRouter; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = AbsoluteAndRelativeReserve; + type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; + type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + // This is the relative view of erc20 assets. + // Identified by this prefix + AccountKey20(contractAddress) + // We use the RELATIVE multilocation + pub Erc20XcmBridgePalletLocation: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + + // To be able to support almost all erc20 implementations, + // we provide a sufficiently hight gas limit. + pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000; +} + +impl pallet_erc20_xcm_bridge::Config for Runtime { + type AccountIdConverter = LocationToH160; + type Erc20MultilocationPrefix = Erc20XcmBridgePalletLocation; + type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit; + type EvmRunner = EvmRunnerPrecompileOrEthXcm; +} + +#[cfg(feature = "runtime-benchmarks")] +mod testing { + use super::*; + use xcm_builder::V4V3LocationConverter; + + /// This From exists for benchmarking purposes. It has the potential side-effect of calling + /// AssetManager::set_asset_type_asset_id() and should NOT be used in any production code. + impl From for CurrencyId { + fn from(location: Location) -> CurrencyId { + use xcm_primitives::AssetTypeGetter; + + // If it does not exist, for benchmarking purposes, we create the association + let asset_id = if let Some(asset_id) = + AsAssetType::::convert_location(&location) + { + asset_id + } else { + let asset_type = AssetType::Xcm( + V4V3LocationConverter::convert(&location).expect("convert to v3"), + ); + let asset_id: AssetId = asset_type.clone().into(); + AssetManager::set_asset_type_asset_id(asset_type, asset_id); + asset_id + }; + + CurrencyId::ForeignAsset(asset_id) + } + } +} diff --git a/tracing/2902/runtime/moonbeam/tests/common/mod.rs b/tracing/2902/runtime/moonbeam/tests/common/mod.rs new file mode 100644 index 00000000..9b382cf4 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/common/mod.rs @@ -0,0 +1,373 @@ +// 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 . + +#![allow(dead_code)] + +use cumulus_primitives_parachain_inherent::ParachainInherentData; +use fp_evm::GenesisAccount; +use frame_support::{ + assert_ok, + traits::{OnFinalize, OnInitialize}, +}; +pub use moonbeam_runtime::{ + asset_config::AssetRegistrarMetadata, + currency::{GIGAWEI, GLMR, SUPPLY_FACTOR, WEI}, + xcm_config::AssetType, + AccountId, AssetId, AssetManager, AuthorInherent, Balance, Balances, CrowdloanRewards, + Ethereum, Executive, Header, InflationInfo, ParachainStaking, Range, Runtime, RuntimeCall, + RuntimeEvent, System, TransactionConverter, TransactionPaymentAsGasPrice, UncheckedExtrinsic, + HOURS, WEEKS, +}; +use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; +use sp_core::{Encode, H160}; +use sp_runtime::{traits::Dispatchable, BuildStorage, Digest, DigestItem, Perbill, Percent}; + +use std::collections::BTreeMap; + +use fp_rpc::ConvertTransaction; + +// A valid signed Alice transfer. +pub const VALID_ETH_TX: &str = + "02f869820501808085e8d4a51000825208943cd0a705a2dc65e5b1e1205896baa2be8a07c6e00180c\ + 001a061087911e877a5802142a89a40d231d50913db399eb50839bb2d04e612b22ec8a01aa313efdf2\ + 793bea76da6813bda611444af16a6207a8cfef2d9c8aa8f8012f7"; + +// An invalid signed Alice transfer with a gas limit artifically set to 0. +pub const INVALID_ETH_TX: &str = + "f8628085174876e800809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ba011110796057\ + 0e2d49fcc2afbc582e1abd3eeb027242b92abcebcec7cdefab63ea001732f6fac84acdd5b096554230\ + 75003e7f07430652c3d6722e18f50b3d34e29"; + +pub fn rpc_run_to_block(n: u32) { + while System::block_number() < n { + Ethereum::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + Ethereum::on_initialize(System::block_number()); + } +} + +/// Utility function that advances the chain to the desired block number. +/// If an author is provided, that author information is injected to all the blocks in the meantime. +pub fn run_to_block(n: u32, author: Option) { + // Finalize the first block + Ethereum::on_finalize(System::block_number()); + while System::block_number() < n { + // Set the new block number and author + match author { + Some(ref author) => { + let pre_digest = Digest { + logs: vec![DigestItem::PreRuntime(NIMBUS_ENGINE_ID, author.encode())], + }; + System::reset_events(); + System::initialize( + &(System::block_number() + 1), + &System::parent_hash(), + &pre_digest, + ); + } + None => { + System::set_block_number(System::block_number() + 1); + } + } + + // Initialize the new block + AuthorInherent::on_initialize(System::block_number()); + ParachainStaking::on_initialize(System::block_number()); + Ethereum::on_initialize(System::block_number()); + + // Finalize the block + Ethereum::on_finalize(System::block_number()); + ParachainStaking::on_finalize(System::block_number()); + } +} + +pub fn last_event() -> RuntimeEvent { + System::events().pop().expect("Event expected").event +} + +// Helper function to give a simple evm context suitable for tests. +// We can remove this once https://github.com/rust-blockchain/evm/pull/35 +// is in our dependency graph. +pub fn evm_test_context() -> fp_evm::Context { + fp_evm::Context { + address: Default::default(), + caller: Default::default(), + apparent_value: From::from(0), + } +} + +// Test struct with the purpose of initializing xcm assets +#[derive(Clone)] +pub struct XcmAssetInitialization { + pub asset_type: AssetType, + pub metadata: AssetRegistrarMetadata, + pub balances: Vec<(AccountId, Balance)>, + pub is_sufficient: bool, +} + +pub struct ExtBuilder { + // endowed accounts with balances + balances: Vec<(AccountId, Balance)>, + // [collator, amount] + collators: Vec<(AccountId, Balance)>, + // [delegator, collator, nomination_amount] + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + // per-round inflation config + inflation: InflationInfo, + // AuthorId -> AccountId mappings + mappings: Vec<(NimbusId, AccountId)>, + // Crowdloan fund + crowdloan_fund: Balance, + // Chain id + chain_id: u64, + // EVM genesis accounts + evm_accounts: BTreeMap, + // [assettype, metadata, Vec, is_sufficient] + xcm_assets: Vec, + safe_xcm_version: Option, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { + balances: vec![], + delegations: vec![], + collators: vec![], + inflation: InflationInfo { + expect: Range { + min: 100_000 * GLMR, + ideal: 200_000 * GLMR, + max: 500_000 * GLMR, + }, + // not used + annual: Range { + min: Perbill::from_percent(50), + ideal: Perbill::from_percent(50), + max: Perbill::from_percent(50), + }, + // unrealistically high parameterization, only for testing + round: Range { + min: Perbill::from_percent(5), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }, + }, + mappings: vec![], + crowdloan_fund: 0, + chain_id: CHAIN_ID, + evm_accounts: BTreeMap::new(), + xcm_assets: vec![], + safe_xcm_version: None, + } + } +} + +impl ExtBuilder { + pub fn with_evm_accounts(mut self, accounts: BTreeMap) -> Self { + self.evm_accounts = accounts; + self + } + + pub fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn with_collators(mut self, collators: Vec<(AccountId, Balance)>) -> Self { + self.collators = collators; + self + } + + pub fn with_delegations(mut self, delegations: Vec<(AccountId, AccountId, Balance)>) -> Self { + self.delegations = delegations + .into_iter() + .map(|d| (d.0, d.1, d.2, Percent::zero())) + .collect(); + self + } + + pub fn with_crowdloan_fund(mut self, crowdloan_fund: Balance) -> Self { + self.crowdloan_fund = crowdloan_fund; + self + } + + pub fn with_mappings(mut self, mappings: Vec<(NimbusId, AccountId)>) -> Self { + self.mappings = mappings; + self + } + + pub fn with_xcm_assets(mut self, xcm_assets: Vec) -> Self { + self.xcm_assets = xcm_assets; + self + } + + pub fn with_safe_xcm_version(mut self, safe_xcm_version: u32) -> Self { + self.safe_xcm_version = Some(safe_xcm_version); + self + } + + #[allow(dead_code)] + pub fn with_inflation(mut self, inflation: InflationInfo) -> Self { + self.inflation = inflation; + self + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: self.balances, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_parachain_staking::GenesisConfig:: { + candidates: self.collators, + delegations: self.delegations, + inflation_config: self.inflation, + collator_commission: Perbill::from_percent(20), + parachain_bond_reserve_percent: Percent::from_percent(30), + blocks_per_round: 6 * HOURS, + num_selected_candidates: 8, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_crowdloan_rewards::GenesisConfig:: { + funded_amount: self.crowdloan_fund, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_author_mapping::GenesisConfig:: { + mappings: self.mappings, + } + .assimilate_storage(&mut t) + .unwrap(); + + let genesis_config = pallet_evm_chain_id::GenesisConfig:: { + chain_id: self.chain_id, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: self.evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_ethereum::GenesisConfig:: { + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_xcm::GenesisConfig:: { + safe_xcm_version: self.safe_xcm_version, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + let xcm_assets = self.xcm_assets.clone(); + 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( + root_origin(), + xcm_asset_initialization.asset_type, + xcm_asset_initialization.metadata, + 1, + xcm_asset_initialization.is_sufficient, + ) + .unwrap(); + for (account, balance) in xcm_asset_initialization.balances { + moonbeam_runtime::Assets::mint( + origin_of(AssetManager::account_id()), + asset_id.into(), + account, + balance, + ) + .unwrap(); + } + } + System::set_block_number(1); + }); + ext + } +} + +pub const CHAIN_ID: u64 = 1281; +pub const ALICE: [u8; 20] = [4u8; 20]; +pub const ALICE_NIMBUS: [u8; 32] = [4u8; 32]; +pub const BOB: [u8; 20] = [5u8; 20]; +pub const CHARLIE: [u8; 20] = [6u8; 20]; +pub const DAVE: [u8; 20] = [7u8; 20]; +pub const EVM_CONTRACT: [u8; 20] = [8u8; 20]; + +pub fn origin_of(account_id: AccountId) -> ::RuntimeOrigin { + ::RuntimeOrigin::signed(account_id) +} + +pub fn inherent_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::none() +} + +pub fn root_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::root() +} + +/// Mock the inherent that sets validation data in ParachainSystem, which +/// contains the `relay_chain_block_number`, which is used in `author-filter` as a +/// source of randomness to filter valid authors at each block. +pub fn set_parachain_inherent_data() { + use cumulus_primitives_core::PersistedValidationData; + use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; + let (relay_parent_storage_root, relay_chain_state) = + RelayStateSproofBuilder::default().into_state_root_and_proof(); + let vfp = PersistedValidationData { + relay_parent_number: 1u32, + relay_parent_storage_root, + ..Default::default() + }; + let parachain_inherent_data = ParachainInherentData { + validation_data: vfp, + relay_chain_state: relay_chain_state, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + }; + assert_ok!(RuntimeCall::ParachainSystem( + cumulus_pallet_parachain_system::Call::::set_validation_data { + data: parachain_inherent_data + } + ) + .dispatch(inherent_origin())); +} + +pub fn unchecked_eth_tx(raw_hex_tx: &str) -> UncheckedExtrinsic { + let converter = TransactionConverter; + converter.convert_transaction(ethereum_transaction(raw_hex_tx)) +} + +pub fn ethereum_transaction(raw_hex_tx: &str) -> pallet_ethereum::Transaction { + let bytes = hex::decode(raw_hex_tx).expect("Transaction bytes."); + let transaction = ethereum::EnvelopedDecodable::decode(&bytes[..]); + assert!(transaction.is_ok()); + transaction.unwrap() +} diff --git a/tracing/2902/runtime/moonbeam/tests/evm_tracing.rs b/tracing/2902/runtime/moonbeam/tests/evm_tracing.rs new file mode 100644 index 00000000..144dae00 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/evm_tracing.rs @@ -0,0 +1,110 @@ +// 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 . + +//! Moonbeam EVM tracing Integration Tests + +mod common; + +#[cfg(test)] +#[cfg(feature = "evm-tracing")] +mod tests { + use super::common::*; + + use pallet_evm::AddressMapping; + use sp_core::H160; + + use moonbeam_rpc_primitives_debug::runtime_decl_for_debug_runtime_api::DebugRuntimeApi; + use std::str::FromStr; + + #[test] + fn debug_runtime_api_trace_transaction() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * GLMR), + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * GLMR, + } + .into(), + ); + let transaction = ethereum_transaction(VALID_ETH_TX); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_transaction( + vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()], + &transaction, + &block + ) + .is_ok()); + }); + } + + #[test] + fn debug_runtime_api_trace_block() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * GLMR), + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * GLMR, + } + .into(), + ); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let eth_tx = ethereum_transaction(VALID_ETH_TX); + let eth_extrinsic_hash = eth_tx.hash(); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_block( + vec![non_eth_uxt.clone(), eth_uxt.clone(), non_eth_uxt, eth_uxt], + vec![eth_extrinsic_hash, eth_extrinsic_hash], + &block + ) + .is_ok()); + }); + } +} diff --git a/tracing/2902/runtime/moonbeam/tests/integration_test.rs b/tracing/2902/runtime/moonbeam/tests/integration_test.rs new file mode 100644 index 00000000..127663cc --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/integration_test.rs @@ -0,0 +1,2762 @@ +// 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 . + +//! Moonbeam Runtime Integration Tests + +#![cfg(test)] + +mod common; +use common::*; + +use fp_evm::{Context, IsPrecompileResult}; +use frame_support::{ + assert_noop, assert_ok, + dispatch::DispatchClass, + traits::{ + fungible::Inspect, Currency as CurrencyT, EnsureOrigin, PalletInfo, StorageInfo, + StorageInfoTrait, + }, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + StorageHasher, Twox128, +}; +use moonbeam_runtime::{ + asset_config::ForeignAssetInstance, + currency::GLMR, + xcm_config::{CurrencyId, SelfReserve}, + AccountId, Balances, CrowdloanRewards, OpenTechCommitteeCollective, ParachainStaking, + PolkadotXcm, Precompiles, Runtime, RuntimeBlockWeights, RuntimeCall, RuntimeEvent, System, + TransactionPayment, TreasuryCouncilCollective, XTokens, XcmTransactor, + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; +use moonbeam_xcm_benchmarks::weights::XcmWeight; +use nimbus_primitives::NimbusId; +use pallet_evm::PrecompileSet; +use pallet_evm_precompileset_assets_erc20::{ + AccountIdAssetIdConversion, SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER, +}; +use pallet_transaction_payment::Multiplier; +use pallet_xcm_transactor::{Currency, CurrencyPayment, TransactWeights}; +use parity_scale_codec::Encode; +use polkadot_parachain::primitives::Sibling; +use precompile_utils::{ + precompile_set::{is_precompile_or_fail, IsActivePrecompile}, + prelude::*, + testing::*, +}; +use sha3::{Digest, Keccak256}; +use sp_core::{ByteArray, Pair, H160, U256}; +use sp_runtime::{ + traits::{Convert, Dispatchable}, + BuildStorage, DispatchError, ModuleError, +}; +use std::str::from_utf8; +use xcm::latest::prelude::*; +use xcm::{VersionedAsset, VersionedAssets, VersionedLocation}; +use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}; +use xcm_executor::traits::ConvertLocation; + +type BatchPCall = pallet_evm_precompile_batch::BatchPrecompileCall; +type CrowdloanRewardsPCall = + pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompileCall; +type XcmUtilsPCall = pallet_evm_precompile_xcm_utils::XcmUtilsPrecompileCall< + Runtime, + moonbeam_runtime::xcm_config::XcmExecutorConfig, +>; +type XtokensPCall = pallet_evm_precompile_xtokens::XtokensPrecompileCall; +type ForeignAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSetCall< + Runtime, + ForeignAssetInstance, +>; +type XcmTransactorV2PCall = + pallet_evm_precompile_xcm_transactor::v2::XcmTransactorPrecompileV2Call; + +const BASE_FEE_GENESIS: u128 = 10000 * GIGAWEI; + +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + +#[test] +fn verify_pallet_prefixes() { + fn is_pallet_prefix(name: &str) { + // Compares the unhashed pallet prefix in the `StorageInstance` implementation by every + // storage item in the pallet P. This pallet prefix is used in conjunction with the + // item name to get the unique storage key: hash(PalletPrefix) + hash(StorageName) + // https://github.com/paritytech/substrate/blob/master/frame/support/procedural/src/pallet/ + // expand/storage.rs#L389-L401 + assert_eq!( + ::PalletInfo::name::

(), + Some(name) + ); + } + // TODO: use StorageInfoTrait once https://github.com/paritytech/substrate/pull/9246 + // is pulled in substrate deps. + is_pallet_prefix::("System"); + is_pallet_prefix::("Utility"); + is_pallet_prefix::("ParachainSystem"); + is_pallet_prefix::("TransactionPayment"); + is_pallet_prefix::("ParachainInfo"); + is_pallet_prefix::("EthereumChainId"); + is_pallet_prefix::("EVM"); + is_pallet_prefix::("Ethereum"); + is_pallet_prefix::("ParachainStaking"); + is_pallet_prefix::("Scheduler"); + is_pallet_prefix::( + "OpenTechCommitteeCollective", + ); + is_pallet_prefix::("Treasury"); + is_pallet_prefix::("AuthorInherent"); + is_pallet_prefix::("AuthorFilter"); + is_pallet_prefix::("CrowdloanRewards"); + is_pallet_prefix::("AuthorMapping"); + is_pallet_prefix::("MaintenanceMode"); + is_pallet_prefix::("Identity"); + is_pallet_prefix::("XcmpQueue"); + is_pallet_prefix::("CumulusXcm"); + is_pallet_prefix::("DmpQueue"); + is_pallet_prefix::("PolkadotXcm"); + is_pallet_prefix::("Assets"); + is_pallet_prefix::("XTokens"); + is_pallet_prefix::("AssetManager"); + is_pallet_prefix::("Migrations"); + is_pallet_prefix::("XcmTransactor"); + is_pallet_prefix::("ProxyGenesisCompanion"); + is_pallet_prefix::("MoonbeamOrbiters"); + is_pallet_prefix::("TreasuryCouncilCollective"); + is_pallet_prefix::("MoonbeamLazyMigrations"); + is_pallet_prefix::("RelayStorageRoots"); + + let prefix = |pallet_name, storage_name| { + let mut res = [0u8; 32]; + res[0..16].copy_from_slice(&Twox128::hash(pallet_name)); + res[16..32].copy_from_slice(&Twox128::hash(storage_name)); + res.to_vec() + }; + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Timestamp".to_vec(), + storage_name: b"Now".to_vec(), + prefix: prefix(b"Timestamp", b"Now"), + max_values: Some(1), + max_size: Some(8), + }, + StorageInfo { + pallet_name: b"Timestamp".to_vec(), + storage_name: b"DidUpdate".to_vec(), + prefix: prefix(b"Timestamp", b"DidUpdate"), + max_values: Some(1), + max_size: Some(1), + } + ] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"TotalIssuance".to_vec(), + prefix: prefix(b"Balances", b"TotalIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"InactiveIssuance".to_vec(), + prefix: prefix(b"Balances", b"InactiveIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Account".to_vec(), + prefix: prefix(b"Balances", b"Account"), + max_values: None, + max_size: Some(100), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Locks".to_vec(), + prefix: prefix(b"Balances", b"Locks"), + max_values: None, + max_size: Some(1287), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Reserves".to_vec(), + prefix: prefix(b"Balances", b"Reserves"), + max_values: None, + max_size: Some(1037), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Holds".to_vec(), + prefix: prefix(b"Balances", b"Holds"), + max_values: None, + max_size: Some(55), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Freezes".to_vec(), + prefix: prefix(b"Balances", b"Freezes"), + max_values: None, + max_size: Some(37), + }, + ] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Proxies".to_vec(), + prefix: prefix(b"Proxy", b"Proxies"), + max_values: None, + max_size: Some(845), + }, + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Announcements".to_vec(), + prefix: prefix(b"Proxy", b"Announcements"), + max_values: None, + max_size: Some(1837), + } + ] + ); + assert_eq!( + ::storage_info(), + vec![StorageInfo { + pallet_name: b"MaintenanceMode".to_vec(), + storage_name: b"MaintenanceMode".to_vec(), + prefix: prefix(b"MaintenanceMode", b"MaintenanceMode"), + max_values: Some(1), + max_size: None, + },] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRoot".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRoot"), + max_values: None, + max_size: Some(44), + }, + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRootKeys".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRootKeys"), + max_values: Some(1), + max_size: Some(121), + }, + ] + ); +} + +#[test] +fn test_collectives_storage_item_prefixes() { + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"TreasuryCouncilCollective".to_vec()); + } + + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"OpenTechCommitteeCollective".to_vec()); + } +} + +#[test] +fn collective_set_members_root_origin_works() { + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert_ok!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + // OpenTechCommitteeCollective + assert_ok!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + }); +} + +#[test] +fn collective_set_members_general_admin_origin_works() { + use moonbeam_runtime::{ + governance::custom_origins::Origin as CustomOrigin, OriginCaller, Utility, + }; + + ExtBuilder::default().build().execute_with(|| { + let root_caller = ::RuntimeOrigin::root(); + let alice = AccountId::from(ALICE); + + // TreasuryCouncilCollective + let _ = Utility::dispatch_as( + root_caller.clone(), + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + // OpenTechCommitteeCollective + let _ = Utility::dispatch_as( + root_caller, + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + + assert_eq!( + System::events() + .into_iter() + .filter_map(|r| { + match r.event { + RuntimeEvent::Utility(pallet_utility::Event::DispatchedAs { result }) + if result.is_ok() => + { + Some(true) + } + _ => None, + } + }) + .collect::>() + .len(), + 2 + ) + }); +} + +#[test] +fn collective_set_members_signed_origin_does_not_work() { + let alice = AccountId::from(ALICE); + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + // OpenTechCommitteeCollective + assert!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + }); +} + +#[test] +fn verify_pallet_indices() { + fn is_pallet_index(index: usize) { + assert_eq!( + ::PalletInfo::index::

(), + Some(index) + ); + } + + // System support + is_pallet_index::(0); + is_pallet_index::(1); + is_pallet_index::(3); + is_pallet_index::(4); + // Monetary + is_pallet_index::(10); + is_pallet_index::(11); + // Consensus support + is_pallet_index::(20); + is_pallet_index::(21); + is_pallet_index::(22); + is_pallet_index::(23); + is_pallet_index::(24); + // Handy utilities + is_pallet_index::(30); + is_pallet_index::(31); + is_pallet_index::(32); + is_pallet_index::(33); + is_pallet_index::(34); + is_pallet_index::(35); + is_pallet_index::(37); + // Ethereum compatibility + is_pallet_index::(50); + is_pallet_index::(51); + is_pallet_index::(52); + // Governance + is_pallet_index::(60); + // is_pallet_index::(61); Removed + // Council + // is_pallet_index::(70); Removed + // is_pallet_index::(71); Removed + is_pallet_index::(72); + is_pallet_index::(73); + // Treasury + is_pallet_index::(80); + // Crowdloan + is_pallet_index::(90); + // XCM Stuff + is_pallet_index::(100); + is_pallet_index::(101); + is_pallet_index::(102); + is_pallet_index::(103); + is_pallet_index::(104); + is_pallet_index::(105); + is_pallet_index::(106); + is_pallet_index::(107); +} + +#[test] +fn verify_reserved_indices() { + use frame_metadata::*; + let metadata = moonbeam_runtime::Runtime::metadata(); + let metadata = match metadata.1 { + RuntimeMetadata::V14(metadata) => metadata, + _ => panic!("metadata has been bumped, test needs to be updated"), + }; + // 40: Sudo + // 53: BaseFee + // 108: pallet_assets:: + let reserved = vec![40, 53, 108]; + let existing = metadata + .pallets + .iter() + .map(|p| p.index) + .collect::>(); + assert!(reserved.iter().all(|index| !existing.contains(index))); +} + +#[test] +fn verify_proxy_type_indices() { + assert_eq!(moonbeam_runtime::ProxyType::Any as u8, 0); + assert_eq!(moonbeam_runtime::ProxyType::NonTransfer as u8, 1); + assert_eq!(moonbeam_runtime::ProxyType::Governance as u8, 2); + assert_eq!(moonbeam_runtime::ProxyType::Staking as u8, 3); + assert_eq!(moonbeam_runtime::ProxyType::CancelProxy as u8, 4); + assert_eq!(moonbeam_runtime::ProxyType::Balances as u8, 5); + assert_eq!(moonbeam_runtime::ProxyType::AuthorMapping as u8, 6); + assert_eq!(moonbeam_runtime::ProxyType::IdentityJudgement as u8, 7); +} + +#[test] +fn join_collator_candidates() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 10_000_000 * GLMR), + (AccountId::from(BOB), 10_000_000 * GLMR), + (AccountId::from(CHARLIE), 10_000_000 * GLMR), + (AccountId::from(DAVE), 10_000_000 * GLMR), + ]) + .with_collators(vec![ + (AccountId::from(ALICE), 2_000_000 * GLMR), + (AccountId::from(BOB), 2_000_000 * GLMR), + ]) + .with_delegations(vec![ + ( + AccountId::from(CHARLIE), + AccountId::from(ALICE), + 5_000 * GLMR, + ), + (AccountId::from(CHARLIE), AccountId::from(BOB), 5_000 * GLMR), + ]) + .build() + .execute_with(|| { + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(ALICE)), + 2_000_000 * GLMR, + 2u32 + ), + pallet_parachain_staking::Error::::CandidateExists + ); + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 2_000_000 * GLMR, + 2u32 + ), + pallet_parachain_staking::Error::::DelegatorExists + ); + assert!(System::events().is_empty()); + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(DAVE)), + 2_000_000 * GLMR, + 2u32 + )); + assert_eq!( + last_event(), + RuntimeEvent::ParachainStaking( + pallet_parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 2_000_000 * GLMR, + new_total_amt_locked: 6_010_000 * GLMR + } + ) + ); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(ALICE)); + assert_eq!(candidates.0[0].amount, 2_005_000 * GLMR); + assert_eq!(candidates.0[1].owner, AccountId::from(BOB)); + assert_eq!(candidates.0[1].amount, 2_005_000 * GLMR); + assert_eq!(candidates.0[2].owner, AccountId::from(DAVE)); + assert_eq!(candidates.0[2].amount, 2_000_000 * GLMR); + }); +} + +#[test] +fn transfer_through_evm_to_stake() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 10_000_000 * GLMR)]) + .build() + .execute_with(|| { + // Charlie has no balance => fails to stake + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 2_000_000 * GLMR, + 2u32 + ), + DispatchError::Module(ModuleError { + index: 20, + error: [8, 0, 0, 0], + message: Some("InsufficientBalance") + }) + ); + // Alice transfer from free balance 3_000_000 GLMR to Bob + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 3_000_000 * GLMR, + )); + assert_eq!( + Balances::free_balance(AccountId::from(BOB)), + 3_000_000 * GLMR + ); + + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + // Bob transfers 2_000_000 GLMR to Charlie via EVM + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(CHARLIE), + input: vec![], + value: (2_000_000 * GLMR).into(), + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + assert_eq!( + Balances::free_balance(AccountId::from(CHARLIE)), + 2_000_000 * GLMR, + ); + + // Charlie can stake now + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 2_000_000 * GLMR, + 2u32 + ),); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(CHARLIE)); + assert_eq!(candidates.0[0].amount, 2_000_000 * GLMR); + }); +} + +#[test] +fn reward_block_authors() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 10k extra tokens for her mapping deposit + (AccountId::from(ALICE), 10_010_000 * GLMR), + (AccountId::from(BOB), 10_000_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 2_000_000 * GLMR)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + for x in 2..3599 { + run_to_block(x, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + } + // no rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 8_010_000 * GLMR, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9_950_000 * GLMR, + ); + run_to_block(3601, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 8990978048702400000000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9969521950497200000000000, + ); + }); +} + +#[test] +fn reward_block_authors_with_parachain_bond_reserved() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 10k extra tokens for her mapping deposit + (AccountId::from(ALICE), 10_010_000 * GLMR), + (AccountId::from(BOB), 10_000_000 * GLMR), + (AccountId::from(CHARLIE), 10_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 2_000_000 * GLMR)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + assert_ok!(ParachainStaking::set_parachain_bond_account( + root_origin(), + AccountId::from(CHARLIE), + ),); + + // Stop just before round 3 + run_to_block(3599, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // no collators rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 8_010_000 * GLMR, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9_950_000 * GLMR, + ); + // 30% reserved for parachain bond + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 310300000000000000000000, + ); + + // Go to round 3 + run_to_block(3601, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + // collators rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 8698492682878000000000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9962207316621500000000000, + ); + // 30% reserved for parachain bond again + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 615104500000000000000000, + ); + }); +} + +#[test] +fn initialize_crowdloan_addresses_with_batch_and_pay() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(300_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 150_000_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 150_000_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!( + Balances::balance(&AccountId::from(CHARLIE)), + 45_000_000 * GLMR + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 45_000_000 * GLMR); + let expected = RuntimeEvent::Utility(pallet_utility::Event::BatchCompleted); + assert_eq!(last_event(), expected); + // This one should fail, as we already filled our data + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch { + calls: vec![RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(ALICE)), + 43_200_000 + )] + } + )] + }) + .dispatch(root_origin()) + ); + let expected_fail = RuntimeEvent::Utility(pallet_utility::Event::BatchInterrupted { + index: 0, + error: DispatchError::Module(ModuleError { + index: 90, + error: [8, 0, 0, 0], + message: None, + }), + }); + assert_eq!(last_event(), expected_fail); + // Claim 1 block. + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(CHARLIE)))); + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(DAVE)))); + + let vesting_period = 4 * WEEKS as u128; + let per_block = (105_000_000 * GLMR) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (45_000_000 * GLMR) + per_block + ); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (45_000_000 * GLMR) + per_block + ); + // The total claimed reward should be equal to the account balance at this point. + assert_eq!( + Balances::balance(&AccountId::from(CHARLIE)), + (45_000_000 * GLMR) + per_block + ); + assert_eq!( + Balances::balance(&AccountId::from(DAVE)), + (45_000_000 * GLMR) + per_block + ); + assert_noop!( + CrowdloanRewards::claim(origin_of(AccountId::from(ALICE))), + pallet_crowdloan_rewards::Error::::NoAssociatedClaim + ); + }); +} + +#[test] +fn initialize_crowdloan_address_and_change_with_relay_key_sig() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + + let (pair1, _) = sp_core::sr25519::Pair::generate(); + let (pair2, _) = sp_core::sr25519::Pair::generate(); + + let public1 = pair1.public(); + let public2 = pair2.public(); + + // signature is new_account || previous_account + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut b"moonbeam-".to_vec()); + message.append(&mut AccountId::from(DAVE).encode()); + message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); + let signature1 = pair1.sign(&message); + let signature2 = pair2.sign(&message); + + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + // two relay accounts pointing at the same reward account + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public1.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public2.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 900_000 * GLMR); + + // this should fail, as we are only providing one signature + assert_noop!( + CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![(public1.into(), signature1.clone().into())] + ), + pallet_crowdloan_rewards::Error::::InsufficientNumberOfValidProofs + ); + + // this should be valid + assert_ok!(CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![ + (public1.into(), signature1.into()), + (public2.into(), signature2.into()) + ] + )); + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (900_000 * GLMR) + ); + }); +} + +#[test] +fn claim_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + assert!(CrowdloanRewards::initialized()); + + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 450_000 * GLMR); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 450_000 * GLMR); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Alice uses the crowdloan precompile to claim through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + + // Construct the call data (selector, amount) + let mut call_data = Vec::::from([0u8; 4]); + call_data[0..4].copy_from_slice(&Keccak256::digest(b"claim()")[0..4]); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let vesting_period = 4 * WEEKS as u128; + let per_block = (1_050_000 * GLMR) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (450_000 * GLMR) + per_block + ); + }) +} + +#[test] +fn is_contributor_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Assert precompile reports Bob is not a contributor + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(AccountId::from(BOB).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(false); + + // Assert precompile reports Charlie is a nominator + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(AccountId::from(CHARLIE).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(true); + }) +} + +#[test] +fn reward_info_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + let expected_total: U256 = (1_500_000 * GLMR).into(); + let expected_claimed: U256 = (450_000 * GLMR).into(); + + // Assert precompile reports correct Charlie reward info. + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::reward_info { + contributor: Address(AccountId::from(CHARLIE).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns((expected_total, expected_claimed)); + }) +} + +#[test] +fn update_reward_address_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * GLMR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * GLMR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Charlie uses the crowdloan precompile to update address through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + + // Construct the input data to check if Bob is a contributor + let mut call_data = Vec::::from([0u8; 36]); + call_data[0..4] + .copy_from_slice(&Keccak256::digest(b"update_reward_address(address)")[0..4]); + call_data[16..36].copy_from_slice(&ALICE); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + assert!(CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)).is_none()); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(ALICE)) + .unwrap() + .claimed_reward, + (450_000 * GLMR) + ); + }) +} + +fn run_with_system_weight(w: Weight, mut assertions: F) +where + F: FnMut() -> (), +{ + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); +} + +#[test] +#[rustfmt::skip] +fn length_fee_is_sensible() { + use sp_runtime::testing::TestXt; + + // tests that length fee is sensible for a few hypothetical transactions + ExtBuilder::default().build().execute_with(|| { + let call = frame_system::Call::remark:: { remark: vec![] }; + let uxt: TestXt<_, ()> = TestXt::new(call, Some((1u64, ()))); + + let calc_fee = |len: u32| -> Balance { + moonbeam_runtime::TransactionPayment::query_fee_details(uxt.clone(), len) + .inclusion_fee + .expect("fee should be calculated") + .len_fee + }; + + // editorconfig-checker-disable + // left: cost of length fee, right: size in bytes + // /------------- proportional component: O(N * 1B) + // | /- exponential component: O(N ** 3) + // | | + assert_eq!( 100_000_000_100, calc_fee(1)); + assert_eq!( 1_000_000_100_000, calc_fee(10)); + assert_eq!( 10_000_100_000_000, calc_fee(100)); + assert_eq!( 100_100_000_000_000, calc_fee(1_000)); + assert_eq!( 1_100_000_000_000_000, calc_fee(10_000)); // inflection point + assert_eq!( 110_000_000_000_000_000, calc_fee(100_000)); + assert_eq!( 100_100_000_000_000_000_000, calc_fee(1_000_000)); // 100 GLMR, ~ 1MB + assert_eq!( 100_001_000_000_000_000_000_000, calc_fee(10_000_000)); + assert_eq!(100_000_010_000_000_000_000_000_000, calc_fee(100_000_000)); + // editorconfig-checker-enable + }); +} + +#[test] +fn multiplier_can_grow_from_zero() { + use frame_support::traits::Get; + + let minimum_multiplier = moonbeam_runtime::MinimumMultiplier::get(); + let target = moonbeam_runtime::TargetBlockFullness::get() + * RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = moonbeam_runtime::SlowAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) +} + +#[test] +fn ethereum_invalid_transaction() { + ExtBuilder::default().build().execute_with(|| { + // Ensure an extrinsic not containing enough gas limit to store the transaction + // on chain is rejected. + assert_eq!( + Executive::apply_extrinsic(unchecked_eth_tx(INVALID_ETH_TX)), + Err( + sp_runtime::transaction_validity::TransactionValidityError::Invalid( + sp_runtime::transaction_validity::InvalidTransaction::Custom(0u8) + ) + ) + ); + }); +} + +#[test] +fn initial_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + + ExtBuilder::default().build().execute_with(|| { + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(1u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 125_000_000_000u128.into(), + Weight::from_parts(25_000_000u64, 0) + ) + ); + }); +} + +#[test] +fn min_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + use frame_support::traits::Hooks; + + ExtBuilder::default().build().execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::put(Multiplier::from(0)); + TransactionPayment::on_finalize(System::block_number()); // should trigger min to kick in + + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(1u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 125_000_000_000u128.into(), + Weight::from_parts(25_000_000u64, 0) + ) + ); + }); +} + +#[test] +fn transfer_ed_0_substrate() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), (1 * GLMR) + (1 * WEI)), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // Substrate transfer + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 1 * GLMR, + )); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI); + }); +} + +#[test] +fn transfer_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * GLMR) + (21_000 * BASE_FEE_GENESIS)) + (1 * WEI), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * GLMR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI,); + }); +} + +#[test] +fn refund_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * GLMR) + (21_777 * BASE_FEE_GENESIS)), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer that zeroes ALICE + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * GLMR).into(), + gas_limit: 21_777u64, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // ALICE is refunded + assert_eq!( + Balances::free_balance(AccountId::from(ALICE)), + 777 * BASE_FEE_GENESIS, + ); + }); +} + +#[test] +fn author_does_not_receive_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * GLMR) + (21_000 * (500 * GIGAWEI)), + )]) + .build() + .execute_with(|| { + // Some block author as seen by pallet-evm. + let author = AccountId::from(>::find_author()); + // Currently the default impl of the evm uses `deposit_into_existing`. + // If we were to use this implementation, and for an author to receive eventual tips, + // the account needs to be somehow initialized, otherwise the deposit would fail. + Balances::make_free_balance_be(&author, 100 * GLMR); + + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * GLMR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(300 * GIGAWEI), + max_priority_fee_per_gas: Some(U256::from(200 * GIGAWEI)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // Author free balance didn't change. + assert_eq!(Balances::free_balance(author), 100 * GLMR,); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_with_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * GLMR) + (21_000 * (200 * GIGAWEI)), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * GLMR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(200 * GIGAWEI), + max_priority_fee_per_gas: Some(U256::from(100 * GIGAWEI)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + // Fee is 100 GWEI base fee + 100 GWEI tip. + let fee = ((200 * GIGAWEI) * 21_000) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonbeam_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_without_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * GLMR) + (21_000 * BASE_FEE_GENESIS), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * GLMR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: Some(BASE_FEE_GENESIS.into()), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + // Fee is 100 GWEI base fee. + let fee = (BASE_FEE_GENESIS * 21_000) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonbeam_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn root_can_change_default_xcm_vers() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let source_id: moonbeam_runtime::AssetId = source_location.clone().into(); + // Default XCM version is not set yet, so xtokens should fail because it does not + // know with which version to send + assert_noop!( + XTokens::transfer( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest.clone())), + WeightLimit::Limited(4000000000.into()) + ), + orml_xtokens::Error::::XcmExecutionFailed + ); + + // Root sets the defaultXcm + assert_ok!(PolkadotXcm::force_default_xcm_version( + root_origin(), + Some(2) + )); + + // Now transferring does not fail + assert_ok!(XTokens::transfer( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest)), + WeightLimit::Limited(4000000000.into()) + )); + }) +} + +#[test] +fn asset_can_be_registered() { + ExtBuilder::default().build().execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: moonbeam_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( + moonbeam_runtime::RuntimeOrigin::root(), + source_location, + asset_metadata, + 1u128, + true + )); + assert!(AssetManager::asset_id_type(source_id).is_some()); + }); +} + +#[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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * GLMR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: moonbeam_runtime::AssetId = + AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Assert the asset has been created with the correct supply + assert_eq!( + moonbeam_runtime::Assets::total_supply(relay_asset_id), + 1_000 * GLMR + ); + + // Access totalSupply through precompile. Important that the context is correct + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::total_supply {}, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * GLMR)); + + // Access balanceOf through precompile + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(ALICE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * GLMR)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * GLMR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: moonbeam_runtime::AssetId = + AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Transfer tokens from Aice to Bob, 400 GLMR. + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::transfer { + to: Address(BOB.into()), + value: { 400 * GLMR }.into(), + }, + ) + .expect_cost(24377) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * GLMR)), + )) + .execute_returns(true); + + // Make sure BOB has 400 GLMR + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(BOB.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * GLMR)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * GLMR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: moonbeam_runtime::AssetId = + AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Aprove Bob for spending 400 GLMR from Alice + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::approve { + spender: Address(BOB.into()), + value: { 400 * GLMR }.into(), + }, + ) + .expect_cost(14429) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_APPROVAL, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * GLMR)), + )) + .execute_returns(true); + + // Transfer tokens from Alice to Charlie by using BOB as origin + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::transfer_from { + from: Address(ALICE.into()), + to: Address(CHARLIE.into()), + value: { 400 * GLMR }.into(), + }, + ) + .expect_cost(29748) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(CHARLIE), + solidity::encode_event_data(U256::from(400 * GLMR)), + )) + .execute_returns(true); + + // Make sure CHARLIE has 400 GLMR + Precompiles::new() + .prepare_test( + CHARLIE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(CHARLIE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * GLMR)); + }); +} + +#[test] +fn xtokens_precompile_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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + 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: moonbeam_runtime::AssetId = + AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // We use the address of the asset as an identifier of the asset we want to transfer + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer { + currency_address: Address(asset_precompile_address.into()), + amount: 500_000_000_000_000u128.into(), + destination: destination.clone(), + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()) + }) +} + +#[test] +fn xtokens_precompile_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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let xtokens_precompile_address = H160::from_low_u64_be(2052); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // This time we transfer it through TransferMultiAsset + // Instead of the address, we encode directly the multilocation referencing the asset + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer_multiasset { + // We want to transfer the relay token + asset: Location::parent(), + amount: 500_000_000_000_000u128.into(), + destination: destination.clone(), + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()); + }) +} + +#[test] +fn make_sure_glmr_can_be_transferred_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + assert_ok!(XTokens::transfer_multiasset( + origin_of(AccountId::from(ALICE)), + Box::new(VersionedAsset::V4(Asset { + id: AssetId(moonbeam_runtime::xcm_config::SelfReserve::get()), + fun: Fungible(1000) + })), + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(40000.into()) + )); + }); +} + +#[test] +fn make_sure_glmr_can_be_transferred() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + assert_ok!(XTokens::transfer( + origin_of(AccountId::from(ALICE)), + CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(40000.into()) + )); + }); +} + +#[test] +fn make_sure_polkadot_xcm_cannot_be_called() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let assets: Assets = [Asset { + id: AssetId(moonbeam_runtime::xcm_config::SelfLocation::get()), + fun: Fungible(1000), + }] + .to_vec() + .into(); + assert_noop!( + RuntimeCall::PolkadotXcm(pallet_xcm::Call::::reserve_transfer_assets { + dest: Box::new(VersionedLocation::V4(dest.clone())), + beneficiary: Box::new(VersionedLocation::V4(dest)), + assets: Box::new(VersionedAssets::V4(assets)), + fee_asset_item: 0, + }) + .dispatch(::RuntimeOrigin::signed( + AccountId::from(ALICE) + )), + frame_system::Error::::CallFiltered + ); + }); +} + +#[test] +fn transact_through_signed_precompile_works_v2() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::parent(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .expect_cost(17559) + .expect_no_logs() + .execute_returns(()); + }); +} + +#[test] +fn transact_through_signed_cannot_send_to_local_chain() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::here(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .execute_reverts(|output| { + from_utf8(&output) + .unwrap() + .contains("Dispatched call failed with error:") + && from_utf8(&output).unwrap().contains("ErrorValidating") + }); + }); +} + +#[test] +fn transactor_cannot_use_more_than_max_weight() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: moonbeam_runtime::AssetId = source_location.clone().into(); + assert_ok!(XcmTransactor::register( + root_origin(), + AccountId::from(ALICE), + 0, + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000.into(), + None + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + 1, + )); + + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonbeam_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + vec![], + // 2000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonbeam_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsCurrencyId(CurrencyId::ForeignAsset(source_id)), + fee_amount: None + }, + vec![], + // 20000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + }) +} + +#[test] +fn call_xtokens_with_fee() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 1_000 * GLMR), + ]) + .with_safe_xcm_version(2) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let source_id: moonbeam_runtime::AssetId = source_location.clone().into(); + + let before_balance = + moonbeam_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); + + // We are able to transfer with fee + assert_ok!(XTokens::transfer_with_fee( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + 100, + Box::new(xcm::VersionedLocation::V4(dest.clone())), + WeightLimit::Limited(4000000000.into()) + )); + + let after_balance = + moonbeam_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); + // At least these much (plus fees) should have been charged + assert_eq!(before_balance - 100_000_000_000_000 - 100, after_balance); + }); +} + +#[test] +fn test_xcm_utils_ml_tp_account() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_address_parent: H160 = + ParentIsPreset::::convert_location(&Location::parent()) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: Location::parent(), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parent)); + + let parachain_2000_location = Location::new(1, [Parachain(2000)]); + let expected_address_parachain: H160 = + SiblingParachainConvertsVia::::convert_location( + ¶chain_2000_location, + ) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: parachain_2000_location, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parachain)); + + let alice_in_parachain_2000_location = Location::new( + 1, + [ + Parachain(2000), + AccountKey20 { + network: None, + key: ALICE, + }, + ], + ); + let expected_address_alice_in_parachain_2000 = + xcm_builder::HashedDescription::< + AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&alice_in_parachain_2000_location) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: alice_in_parachain_2000_location, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_alice_in_parachain_2000)); + }); +} + +#[test] +fn test_xcm_utils_weight_message() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_weight = + XcmWeight::::clear_origin().ref_time(); + + let message: Vec = xcm::VersionedXcm::<()>::V4(Xcm(vec![ClearOrigin])).encode(); + + let input = XcmUtilsPCall::weight_message { + message: message.into(), + }; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(0) + .expect_no_logs() + .execute_returns(expected_weight); + }); +} + +#[test] +fn test_xcm_utils_get_units_per_second() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let location = SelfReserve::get(); + + let input = XcmUtilsPCall::get_units_per_second { location }; + + let expected_units = + WEIGHT_REF_TIME_PER_SECOND as u128 * moonbeam_runtime::currency::WEIGHT_FEE; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(expected_units); + }); +} + +#[test] +fn precompile_existence() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + let precompile_addresses: std::collections::BTreeSet<_> = vec![ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 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, + ] + .into_iter() + .map(H160::from_low_u64_be) + .collect(); + + for i in 0..3000 { + let address = H160::from_low_u64_be(i); + + if precompile_addresses.contains(&address) { + assert!( + is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return true", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_some(), + "execute({},..) should return Some(_)", + i + ); + } else { + assert!( + !is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return false", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_none(), + "execute({},..) should return None", + i + ); + } + } + }); +} + +#[test] +fn removed_precompiles() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + let removed_precompiles = [1025, 2051, 2062, 2063]; + + for i in 1..3000 { + let address = H160::from_low_u64_be(i); + + if !is_precompile_or_fail::(address, 100_000u64).expect("to be ok") { + continue; + } + + if !removed_precompiles.contains(&i) { + assert!( + match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} should be an active precompile" + ); + continue; + } + + assert!( + !match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} shouldn't be an active precompile" + ); + + precompiles + .prepare_test(Alice, address, []) + .execute_reverts(|out| out == b"Removed precompile"); + } + }) +} + +#[test] +fn deal_with_fees_handles_tip() { + use frame_support::traits::OnUnbalanced; + use moonbeam_runtime::{DealWithFees, Treasury}; + + ExtBuilder::default().build().execute_with(|| { + // This test checks the functionality of the `DealWithFees` trait implementation in the runtime. + // It simulates a scenario where a fee and a tip are issued to an account and ensures that the + // treasury receives the correct amount (20% of the total), and the rest is burned (80%). + // + // The test follows these steps: + // 1. It issues a fee of 100 and a tip of 1000. + // 2. It checks the total supply before the fee and tip are dealt with, which should be 1_100. + // 3. It checks that the treasury's balance is initially 0. + // 4. It calls `DealWithFees::on_unbalanceds` with the fee and tip. + // 5. It checks that the treasury's balance is now 220 (20% of the fee and tip). + // 6. It checks that the total supply has decreased by 880 (80% of the fee and tip), indicating + // that this amount was burned. + let fee = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(100); + let tip = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(1000); + + let total_supply_before = Balances::total_issuance(); + assert_eq!(total_supply_before, 1_100); + assert_eq!(Balances::free_balance(&Treasury::account_id()), 0); + + DealWithFees::on_unbalanceds(vec![fee, tip].into_iter()); + + // treasury should have received 20% + assert_eq!(Balances::free_balance(&Treasury::account_id()), 220); + + // verify 80% burned + let total_supply_after = Balances::total_issuance(); + assert_eq!(total_supply_before - total_supply_after, 880); + }); +} + +#[test] +fn evm_revert_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + // Batch a transfer followed by an invalid call to batch. + // Thus BatchAll will revert the transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + + input: BatchPCall::batch_all { + to: vec![Address(BOB.into()), Address(batch_precompile_address)].into(), + value: vec![U256::from(1 * GLMR), U256::zero()].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 0, "there should be no transfer event"); + }); +} + +#[test] +fn evm_success_keeps_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + input: BatchPCall::batch_all { + to: vec![Address(BOB.into())].into(), + value: vec![U256::from(1 * GLMR)].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: BASE_FEE_GENESIS.into(), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 1, "there should be 1 transfer event"); + }); +} + +#[cfg(test)] +mod fee_tests { + use super::*; + use frame_support::{ + traits::ConstU128, + weights::{ConstantMultiplier, WeightToFee}, + }; + use moonbeam_runtime::{ + currency, LengthToFee, MinimumMultiplier, RuntimeBlockWeights, SlowAdjustingFeeUpdate, + TargetBlockFullness, TransactionPayment, + }; + use sp_core::Get; + use sp_runtime::FixedPointNumber; + + fn run_with_system_weight(w: Weight, mut assertions: F) + where + F: FnMut() -> (), + { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); + } + + #[test] + fn test_multiplier_can_grow_from_zero() { + let minimum_multiplier = MinimumMultiplier::get(); + let target = TargetBlockFullness::get() + * RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) + } + + #[test] + fn test_fee_calculation() { + let base_extrinsic = RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .base_extrinsic; + let multiplier = sp_runtime::FixedU128::from_float(0.999000000000000000); + let extrinsic_len = 100u32; + let extrinsic_weight = 5_000u64; + let tip = 42u128; + type WeightToFeeImpl = ConstantMultiplier>; + type LengthToFeeImpl = LengthToFee; + + // base_fee + (multiplier * extrinsic_weight_fee) + extrinsic_length_fee + tip + let expected_fee = + WeightToFeeImpl::weight_to_fee(&base_extrinsic) + + multiplier.saturating_mul_int(WeightToFeeImpl::weight_to_fee( + &Weight::from_parts(extrinsic_weight, 1), + )) + LengthToFeeImpl::weight_to_fee(&Weight::from_parts(extrinsic_len as u64, 1)) + + tip; + + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); + let actual_fee = TransactionPayment::compute_fee( + extrinsic_len, + &frame_support::dispatch::DispatchInfo { + class: DispatchClass::Normal, + pays_fee: frame_support::dispatch::Pays::Yes, + weight: Weight::from_parts(extrinsic_weight, 1), + }, + tip, + ); + + assert_eq!( + expected_fee, + actual_fee, + "The actual fee did not match the expected fee, diff {}", + actual_fee - expected_fee + ); + }); + } +} diff --git a/tracing/2902/runtime/moonbeam/tests/runtime_apis.rs b/tracing/2902/runtime/moonbeam/tests/runtime_apis.rs new file mode 100644 index 00000000..26609076 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/runtime_apis.rs @@ -0,0 +1,393 @@ +// 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 . + +//! Moonbeam Runtime Api Integration Tests + +mod common; +use common::*; + +use fp_evm::GenesisAccount; +use frame_support::assert_ok; +use nimbus_primitives::NimbusId; +use pallet_evm::{Account as EVMAccount, AddressMapping, FeeCalculator}; +use sp_core::{ByteArray, H160, H256, U256}; + +use fp_rpc::runtime_decl_for_ethereum_runtime_rpc_api::EthereumRuntimeRPCApi; +use moonbeam_rpc_primitives_txpool::runtime_decl_for_tx_pool_runtime_api::TxPoolRuntimeApi; +use nimbus_primitives::runtime_decl_for_nimbus_api::NimbusApi; +use std::{collections::BTreeMap, str::FromStr}; + +#[test] +fn ethereum_runtime_rpc_api_chain_id() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!(Runtime::chain_id(), CHAIN_ID); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_basic() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * GLMR)]) + .build() + .execute_with(|| { + assert_eq!( + Runtime::account_basic(H160::from(ALICE)), + EVMAccount { + balance: U256::from(2_000 * GLMR), + nonce: U256::zero() + } + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_gas_price() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!( + Runtime::gas_price(), + TransactionPaymentAsGasPrice::min_gas_price().0 + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_code_at() { + let address = H160::from(EVM_CONTRACT); + let code: Vec = vec![1, 2, 3, 4, 5]; + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: code.clone(), + nonce: Default::default(), + storage: Default::default(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::account_code_at(address), code); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_author() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + assert_eq!(Runtime::author(), H160::from(ALICE)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_storage_at() { + let address = H160::from(EVM_CONTRACT); + let mut key = [0u8; 32]; + key[31..32].copy_from_slice(&[6u8][..]); + let mut value = [0u8; 32]; + value[31..32].copy_from_slice(&[7u8][..]); + let item = H256::from_slice(&key[..]); + let mut storage: BTreeMap = BTreeMap::new(); + storage.insert(H256::from_slice(&key[..]), item); + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: Vec::new(), + nonce: Default::default(), + storage: storage.clone(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::storage_at(address, U256::from(6)), item); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_call() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * GLMR), + (AccountId::from(BOB), 2_000 * GLMR), + ]) + .build() + .execute_with(|| { + let execution_result = Runtime::call( + H160::from(ALICE), // from + H160::from(BOB), // to + Vec::new(), // data + U256::from(1000u64), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_create() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * GLMR)]) + .build() + .execute_with(|| { + let execution_result = Runtime::create( + H160::from(ALICE), // from + vec![0, 1, 1, 0], // data + U256::zero(), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_transaction_statuses() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 200_000 * GLMR), + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + + let _result = Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)); + + rpc_run_to_block(2); + let statuses = + Runtime::current_transaction_statuses().expect("Transaction statuses result."); + assert_eq!(statuses.len(), 1); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_block() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + rpc_run_to_block(2); + let block = Runtime::current_block().expect("Block result."); + assert_eq!(block.header.number, U256::from(1u8)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_receipts() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 100_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 200_000 * GLMR), + (AccountId::from(ALICE), 200_000 * GLMR), + (AccountId::from(BOB), 100_000 * GLMR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 50_000 * GLMR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + + let _result = Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)); + + rpc_run_to_block(2); + let receipts = Runtime::current_receipts().expect("Receipts result."); + assert_eq!(receipts.len(), 1); + }); +} + +#[test] +fn txpool_runtime_api_extrinsic_filter() { + ExtBuilder::default().build().execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * GLMR, + } + .into(), + ); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let txpool = >::extrinsic_filter( + vec![eth_uxt.clone(), non_eth_uxt.clone()], + vec![unchecked_eth_tx(VALID_ETH_TX), non_eth_uxt], + ); + assert_eq!(txpool.ready.len(), 1); + assert_eq!(txpool.future.len(), 1); + }); +} + +#[test] +fn can_author_when_selected_is_empty() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 20_000_000 * GLMR), + (AccountId::from(BOB), 10_000_000 * GLMR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 2_000_000 * GLMR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 1); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: Default::default(), + parent_hash: Default::default(), + state_root: Default::default(), + }; + + // Base case: ALICE can author blocks when she is the only candidate + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Remove ALICE from candidate pool, leaving the candidate_pool empty + assert_ok!(ParachainStaking::go_offline(origin_of(AccountId::from( + ALICE + )))); + + // Need to fast forward to right before the next session, which is when selected candidates + // will be updated. We want to test the creation of the first block of the next session. + run_to_block(1799, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1799, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Check that it works as expected after session update + run_to_block(1800, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1800, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + }); +} diff --git a/tracing/2902/runtime/moonbeam/tests/xcm_mock/mod.rs b/tracing/2902/runtime/moonbeam/tests/xcm_mock/mod.rs new file mode 100644 index 00000000..d52700b8 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/xcm_mock/mod.rs @@ -0,0 +1,271 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +pub mod parachain; +pub mod relay_chain; +pub mod statemint_like; + +use cumulus_primitives_core::ParaId; +use pallet_xcm_transactor::relay_indices::*; +use sp_runtime::traits::AccountIdConversion; +use sp_runtime::{AccountId32, BuildStorage}; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +use polkadot_runtime_parachains::configuration::{ + GenesisConfig as ConfigurationGenesisConfig, HostConfiguration, +}; +use polkadot_runtime_parachains::paras::{ + GenesisConfig as ParasGenesisConfig, ParaGenesisArgs, ParaKind, +}; +use sp_core::{H160, U256}; +use std::{collections::BTreeMap, str::FromStr}; + +pub const PARAALICE: [u8; 20] = [1u8; 20]; +pub const RELAYALICE: AccountId32 = AccountId32::new([0u8; 32]); +pub const RELAYBOB: AccountId32 = AccountId32::new([2u8; 32]); + +pub fn para_a_account() -> AccountId32 { + ParaId::from(1).into_account_truncating() +} + +pub fn para_b_account() -> AccountId32 { + ParaId::from(2).into_account_truncating() +} + +pub fn para_a_account_20() -> parachain::AccountId { + ParaId::from(1).into_account_truncating() +} + +pub fn evm_account() -> H160 { + H160::from_str("1000000000000000000000000000000000000001").unwrap() +} + +pub fn mock_para_genesis_info() -> ParaGenesisArgs { + ParaGenesisArgs { + genesis_head: vec![1u8].into(), + validation_code: vec![1u8].into(), + para_kind: ParaKind::Parachain, + } +} + +pub fn mock_relay_config() -> HostConfiguration { + HostConfiguration:: { + hrmp_channel_max_capacity: u32::MAX, + hrmp_channel_max_total_size: u32::MAX, + hrmp_max_parachain_inbound_channels: 10, + hrmp_max_parachain_outbound_channels: 10, + hrmp_channel_max_message_size: u32::MAX, + // Changed to avoid aritmetic errors within hrmp_close + max_downward_message_size: 100_000u32, + ..Default::default() + } +} + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(2), + } +} + +decl_test_parachain! { + pub struct ParaC { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(3), + } +} + +decl_test_parachain! { + pub struct Statemint { + Runtime = statemint_like::Runtime, + XcmpMessageHandler = statemint_like::MsgQueue, + DmpMessageHandler = statemint_like::MsgQueue, + new_ext = statemint_ext(4), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + RuntimeCall = relay_chain::RuntimeCall, + RuntimeEvent = relay_chain::RuntimeEvent, + XcmConfig = relay_chain::XcmConfig, + MessageQueue = relay_chain::MessageQueue, + System = relay_chain::System, + new_ext = relay_ext(vec![1, 2, 3, 4]), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + (3, ParaC), + (4, Statemint), + ], + } +} + +pub const INITIAL_BALANCE: u128 = 10_000_000_000_000_000; + +pub const INITIAL_EVM_BALANCE: u128 = 0; +pub const INITIAL_EVM_NONCE: u32 = 1; + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(PARAALICE.into(), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_xcm_transactor::GenesisConfig:: { + // match relay runtime construct_runtime order in xcm_mock::relay_chain + relay_indices: RelayChainIndices { + hrmp: 6u8, + init_open_channel: 0u8, + accept_open_channel: 1u8, + close_channel: 2u8, + cancel_open_request: 6u8, + ..Default::default() + }, + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); + + // EVM accounts are self-sufficient. + let mut evm_accounts = BTreeMap::new(); + evm_accounts.insert( + evm_account(), + fp_evm::GenesisAccount { + nonce: U256::from(INITIAL_EVM_NONCE), + balance: U256::from(INITIAL_EVM_BALANCE), + storage: Default::default(), + code: vec![ + 0x00, // STOP + ], + }, + ); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn statemint_ext(para_id: u32) -> sp_io::TestExternalities { + use statemint_like::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (RELAYALICE.into(), INITIAL_BALANCE), + (RELAYBOB.into(), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext(paras: Vec) -> sp_io::TestExternalities { + use relay_chain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(RELAYALICE, INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let para_genesis: Vec<(ParaId, ParaGenesisArgs)> = paras + .iter() + .map(|¶_id| (para_id.into(), mock_para_genesis_info())) + .collect(); + + let genesis_config = ConfigurationGenesisConfig:: { + config: mock_relay_config(), + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = ParasGenesisConfig:: { + paras: para_genesis, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + }); + ext +} + +pub type RelayChainPalletXcm = pallet_xcm::Pallet; +pub type Hrmp = polkadot_runtime_parachains::hrmp::Pallet; + +pub type StatemintBalances = pallet_balances::Pallet; +pub type StatemintChainPalletXcm = pallet_xcm::Pallet; +pub type StatemintAssets = pallet_assets::Pallet; + +pub type Assets = pallet_assets::Pallet; +pub type Treasury = pallet_treasury::Pallet; +pub type AssetManager = pallet_asset_manager::Pallet; +pub type XTokens = orml_xtokens::Pallet; +pub type RelayBalances = pallet_balances::Pallet; +pub type ParaBalances = pallet_balances::Pallet; +pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/tracing/2902/runtime/moonbeam/tests/xcm_mock/parachain.rs b/tracing/2902/runtime/moonbeam/tests/xcm_mock/parachain.rs new file mode 100644 index 00000000..3ed310da --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/xcm_mock/parachain.rs @@ -0,0 +1,1088 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use frame_support::{ + construct_runtime, + dispatch::GetDispatchInfo, + ensure, parameter_types, + traits::{ + AsEnsureOriginWithArg, ConstU32, Everything, Get, InstanceFilter, Nothing, PalletInfoAccess, + }, + weights::Weight, + PalletId, +}; +pub use moonbeam_runtime::xcm_config::AssetType; + +use frame_system::{pallet_prelude::BlockNumberFor, EnsureNever, EnsureRoot}; +use pallet_xcm::migration::v1::VersionUncheckedMigrateToV1; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use sp_core::H256; +use sp_runtime::{ + traits::{BlakeTwo256, Hash, IdentityLookup, MaybeEquivalence, Zero}, + Permill, +}; +use sp_std::{convert::TryFrom, prelude::*}; +use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; + +use cumulus_primitives_core::relay_chain::HrmpChannelId; +use orml_traits::parameter_type_with_key; +use pallet_ethereum::PostLogContent; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain::primitives::{Id as ParaId, Sibling}; +use xcm::latest::{ + AssetId as XcmAssetId, Error as XcmError, ExecuteXcm, + Junction::{PalletInstance, Parachain}, + Location, NetworkId, Outcome, Xcm, +}; +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, IsConcrete, + NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, WithComputedOrigin, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; + +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; +use scale_info::TypeInfo; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; + +pub type AccountId = moonbeam_core_primitives::AccountId; +pub type Balance = u128; +pub type AssetId = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 0; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +pub type ForeignAssetInstance = (); + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 1; // Does not really matter as this will be only called by root + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + AccountKey20Aliases, + // Generate remote accounts according to polkadot standards + xcm_builder::HashedDescription< + AccountId, + xcm_builder::DescribeFamily, + >, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + SignedAccountKey20AsNative, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1u64, 1u64); + pub MaxInstructions: u32 = 100; +} + +// Instructing how incoming xcm assets will be handled +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId32 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + IsConcrete, + // We can convert the Locations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// We use all transactors +pub type AssetTransactors = (LocalAssetTransactor, ForeignFungiblesTransactor); +pub type XcmRouter = super::ParachainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +pub type XcmFeesToAccount_ = xcm_primitives::XcmFeesToAccount< + Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +parameter_types! { + // We cannot skip the native trader for some specific tests, so we will have to work with + // a native trader that charges same number of units as weight + pub ParaTokensPerSecond: (XcmAssetId, u128, u128) = ( + AssetId(SelfReserve::get()), + 1000000000000, + 0, + ); +} + +parameter_types! { + pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +use frame_system::RawOrigin; +use sp_runtime::traits::PostDispatchInfoOf; +use sp_runtime::DispatchErrorWithPostInfo; +use xcm_executor::traits::CallDispatcher; +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = orml_xcm_support::MultiNativeAsset< + xcm_primitives::AbsoluteAndRelativeReserve, + >; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + // We use two traders + // When we receive the self-reserve asset, + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + FixedRateOfFungible, + xcm_primitives::FirstAssetTrader, + ); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + SelfReserve, + ForeignAsset(AssetId), +} + +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxAssetsForTransfer: usize = 2; + pub SelfLocation: Location = Location::here(); + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(MsgQueue::parachain_id().into()) + ].into() + }; +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + (1, Some(Parachain(4u32))) => Some(50u128), + _ => None, + } + }; +} + +// The XCM message wrapper wrapper +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdConvert = + CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const ProposalBondMinimum: Balance = 0; + pub const SpendPeriod: u32 = 0; + pub const TreasuryId: PalletId = PalletId(*b"pc/trsry"); + pub const MaxApprovals: u32 = 100; + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = MaxApprovals; + type WeightInfo = (); + type SpendFunds = (); + type ProposalBondMaximum = (); + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Same as Polkadot + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<0>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = ArgumentsBenchmarkHelper; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} + +// Pallet to provide the version, used to test runtime upgrade version changes +#[frame_support::pallet] +pub mod mock_version_changer { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_version)] + pub(super) type CurrentVersion = StorageValue<_, XcmVersion, ValueQuery>; + + impl Get for Pallet { + fn get() -> XcmVersion { + Self::current_version() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + VersionChanged(XcmVersion), + } + + impl Pallet { + pub fn set_version(version: XcmVersion) { + CurrentVersion::::put(version); + Self::deposit_event(Event::VersionChanged(version)); + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl mock_version_changer::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +pub type LocalOriginToLocation = + xcm_primitives::SignedToAccountId20; + +parameter_types! { + pub MatcherLocation: Location = Location::here(); +} + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = frame_support::traits::Nothing; + type XcmExecutor = XcmExecutor; + // Do not allow teleports + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // We use a custom one to test runtime ugprades + type AdvertisedXcmVersion = XcmVersioner; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +use frame_support::pallet_prelude::DispatchResult; +impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { + fn create_foreign_asset( + asset: AssetId, + min_balance: Balance, + metadata: AssetMetadata, + is_sufficient: bool, + ) -> DispatchResult { + Assets::force_create( + RuntimeOrigin::root(), + asset, + AssetManager::account_id(), + is_sufficient, + min_balance, + )?; + + Assets::force_set_metadata( + RuntimeOrigin::root(), + asset, + metadata.name, + metadata.symbol, + metadata.decimals, + false, + ) + } + + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into())?; + + Ok(()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, +} + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetMetadata; + type ForeignAssetType = AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = EnsureRoot; + type WeightInfo = (); +} + +// 1 DOT should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = MockTransactors; + type DerivativeAddressRegistrationOrigin = EnsureRoot; + type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdToLocation = + CurrencyIdToLocation>; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type XcmSender = XcmRouter; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; + type WeightInfo = (); + type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1000; +} +impl pallet_timestamp::Config for Runtime { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +use sp_core::U256; + +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 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 = + BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT); +} + +impl pallet_evm::Config for Runtime { + type FeeCalculator = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + + type CallOrigin = pallet_evm::EnsureAddressRoot; + type WithdrawOrigin = pallet_evm::EnsureAddressNever; + + type AddressMapping = pallet_evm::IdentityAddressMapping; + type Currency = Balances; + type Runner = pallet_evm::runner::stack::Runner; + + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = (); + type PrecompilesValue = (); + type ChainId = (); + type BlockGasLimit = BlockGasLimit; + type OnChargeTransaction = (); + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type FindAuthor = (); + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; +} + +pub struct NormalFilter; +impl frame_support::traits::Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + _ => true, + } + } +} + +// We need to use the encoding from the relay mock runtime +#[derive(Encode, Decode)] +pub enum RelayCall { + #[codec(index = 5u8)] + // the index should match the position of the module in `construct_runtime!` + Utility(UtilityCall), + #[codec(index = 6u8)] + // the index should match the position of the module in `construct_runtime!` + Hrmp(HrmpCall), +} + +#[derive(Encode, Decode)] +pub enum UtilityCall { + #[codec(index = 1u8)] + AsDerivative(u16), +} + +// HRMP call encoding, needed for xcm transactor pallet +#[derive(Encode, Decode)] +pub enum HrmpCall { + #[codec(index = 0u8)] + InitOpenChannel(ParaId, u32, u32), + #[codec(index = 1u8)] + AcceptOpenChannel(ParaId), + #[codec(index = 2u8)] + CloseChannel(HrmpChannelId), + #[codec(index = 6u8)] + CancelOpenRequest(HrmpChannelId, u32), +} + +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum MockTransactors { + Relay, +} + +impl xcm_primitives::XcmTransact for MockTransactors { + fn destination(self) -> Location { + match self { + MockTransactors::Relay => Location::parent(), + } + } +} + +impl xcm_primitives::UtilityEncodeCall for MockTransactors { + fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { + match self { + MockTransactors::Relay => match call { + xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => { + let mut call = + RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode(); + call.append(&mut b.clone()); + call + } + }, + } + } +} + +pub struct MockHrmpEncoder; +impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder { + fn hrmp_encode_call( + call: xcm_primitives::HrmpAvailableCalls, + ) -> Result, xcm::latest::Error> { + match call { + xcm_primitives::HrmpAvailableCalls::InitOpenChannel(a, b, c) => Ok(RelayCall::Hrmp( + HrmpCall::InitOpenChannel(a.clone(), b.clone(), c.clone()), + ) + .encode()), + xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::AcceptOpenChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => { + Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode()) + } + } + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} +parameter_types! { + pub ReservedXcmpWeight: Weight = Weight::from_parts(u64::max_value(), 0); +} + +#[derive( + Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo, +)] +pub enum ProxyType { + NotAllowed = 0, + Any = 1, +} + +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType {} + +impl InstanceFilter for ProxyType { + fn filter(&self, _c: &RuntimeCall) -> bool { + match self { + ProxyType::NotAllowed => false, + ProxyType::Any => true, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + +impl Default for ProxyType { + fn default() -> Self { + Self::NotAllowed + } +} + +parameter_types! { + pub const ProxyCost: u64 = 1; +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyCost; + type ProxyDepositFactor = ProxyCost; + type MaxProxies = ConstU32<32>; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ProxyCost; + type AnnouncementDepositFactor = ProxyCost; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will iMmediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlockU32; + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + XcmVersioner: mock_version_changer, + + PolkadotXcm: pallet_xcm, + Assets: pallet_assets, + CumulusXcm: cumulus_pallet_xcm, + XTokens: orml_xtokens, + AssetManager: pallet_asset_manager, + XcmTransactor: pallet_xcm_transactor, + Treasury: pallet_treasury, + Proxy: pallet_proxy, + + Timestamp: pallet_timestamp, + EVM: pallet_evm, + Ethereum: pallet_ethereum, + EthereumXcm: pallet_ethereum_xcm, + } +); + +pub(crate) fn para_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion}; +use frame_support::traits::{OnFinalize, OnInitialize, OnRuntimeUpgrade}; +pub(crate) fn on_runtime_upgrade() { + VersionUncheckedMigrateToV1::::on_runtime_upgrade(); +} + +pub(crate) fn para_roll_to(n: BlockNumber) { + while System::block_number() < n { + PolkadotXcm::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + PolkadotXcm::on_initialize(System::block_number()); + } +} diff --git a/tracing/2902/runtime/moonbeam/tests/xcm_mock/relay_chain.rs b/tracing/2902/runtime/moonbeam/tests/xcm_mock/relay_chain.rs new file mode 100644 index 00000000..40bff5e1 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/xcm_mock/relay_chain.rs @@ -0,0 +1,412 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{Everything, Nothing, ProcessMessage, ProcessMessageError}, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, IdentityLookup}, + AccountId32, +}; + +use frame_support::weights::{Weight, WeightMeter}; +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{ + configuration, dmp, hrmp, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, paras, shared, +}; +use sp_runtime::transaction_validity::TransactionPriority; +use sp_runtime::Permill; +use xcm::latest::prelude::*; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, + ChildSystemParachainAsSuperuser, FixedRateOfFungible, FixedWeightBounds, + FungibleAdapter as XcmCurrencyAdapter, IsConcrete, ProcessXcmMessage, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + WithComputedOrigin, +}; +use xcm_executor::{Config, XcmExecutor}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = (); + type PalletsOrigin = OriginCaller; +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub KsmLocation: Location = Here.into(); + pub const KusamaNetwork: NetworkId = NetworkId::Kusama; + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorLocation = Here; +} + +pub type SovereignAccountOf = ( + ChildParachainConvertsVia, + AccountId32Aliases, + // Not enabled in the relay per se, but we enable it to test + // the transact_through_signed extrinsic + Account32Hash, +); + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1000u64, 1000u64); + pub KsmPerSecond: (AssetId, u128, u128) = (AssetId(KsmLocation::get()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub MatcherLocation: Location = Location::here(); +} + +pub type XcmRouter = super::RelayChainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) }); + pub Statemine: Location = Parachain(4).into(); + pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get()); +} + +pub type TrustedTeleporters = xcm_builder::Case; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +parameter_types! { + pub const ParasUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); +} + +/// A very dumb implementation of `EstimateNextSessionRotation`. At the moment of writing, this +/// is more to satisfy type requirements rather than to test anything. +pub struct TestNextSessionRotation; + +impl frame_support::traits::EstimateNextSessionRotation for TestNextSessionRotation { + fn average_session_length() -> u32 { + 10 + } + + fn estimate_current_session_progress(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } + + fn estimate_next_session_rotation(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } +} + +impl paras::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = paras::TestWeightInfo; + type UnsignedPriority = ParasUnsignedPriority; + type NextSessionRotation = TestNextSessionRotation; + type QueueFootprinter = (); + type OnNewHead = (); + type AssignCoretime = (); +} + +impl dmp::Config for Runtime {} + +impl hrmp::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type WeightInfo = TestHrmpWeightInfo; + type ChannelManager = frame_system::EnsureRoot; +} + +impl frame_system::offchain::SendTransactionTypes for Runtime +where + RuntimeCall: From, +{ + type Extrinsic = UncheckedExtrinsic; + type OverarchingCall = RuntimeCall; +} + +impl origin::Config for Runtime {} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlockU32; + +parameter_types! { + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +pub struct MessageProcessor; +impl ProcessMessage for MessageProcessor { + type Origin = AggregateMessageOrigin; + + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + let para = match origin { + AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, + }; + ProcessXcmMessage::, RuntimeCall>::process_message( + message, + Junction::Parachain(para.into()), + meter, + id, + ) + } +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type MessageProcessor = MessageProcessor; + type QueueChangeHandler = (); + type WeightInfo = (); + type QueuePausedQuery = (); +} + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + MessageQueue: pallet_message_queue, + XcmPallet: pallet_xcm, + Utility: pallet_utility, + Hrmp: hrmp, + Dmp: dmp, + Paras: paras, + Configuration: configuration, + } +); + +pub(crate) fn relay_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::{OnFinalize, OnInitialize}; +pub(crate) fn relay_roll_to(n: BlockNumber) { + while System::block_number() < n { + XcmPallet::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + XcmPallet::on_initialize(System::block_number()); + } +} + +/// A weight info that is only suitable for testing. +pub struct TestHrmpWeightInfo; + +impl hrmp::WeightInfo for TestHrmpWeightInfo { + fn hrmp_accept_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn force_clean_hrmp(_: u32, _: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_close(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_open(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_cancel_open_request(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_close_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_init_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn clean_open_channel_requests(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_open_hrmp_channel(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn establish_system_channel() -> Weight { + Weight::from_parts(1, 0) + } + + fn poke_channel_deposits() -> Weight { + Weight::from_parts(1, 0) + } +} diff --git a/tracing/2902/runtime/moonbeam/tests/xcm_mock/statemint_like.rs b/tracing/2902/runtime/moonbeam/tests/xcm_mock/statemint_like.rs new file mode 100644 index 00000000..a3da2c21 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/xcm_mock/statemint_like.rs @@ -0,0 +1,575 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{AsEnsureOriginWithArg, Contains, Everything, Nothing}, + weights::Weight, +}; +use frame_system::{EnsureRoot, EnsureSigned}; + +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, Hash, IdentityLookup}, + AccountId32, +}; + +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; + +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_parachain::primitives::Sibling; +use sp_std::convert::TryFrom; +use xcm::latest::prelude::*; +use xcm::VersionedXcm; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungibleAdapter, + FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type AssetId = u128; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 0; // 1 UNIT deposit to create asset + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) + // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const ExecutiveBody: BodyId = BodyId::Executive; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = (); + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub Local: Location = Here.into(); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub KsmPerSecond: (xcm::latest::prelude::AssetId, u128, u128) = + (AssetId(KsmLocation::get()), 1, 1); +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, +); + +/// Means for transacting the native currency on this chain. +pub type CurrencyTransactor = FungibleAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Balances`. + (), +>; + +/// Means for transacting assets besides the native currency on this chain. +pub type FungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ConvertedConcreteId< + AssetId, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We only want to allow teleports of known assets. We use non-zero issuance as an indication + // that this asset is known. + NoChecking, + // The account to use for tracking teleports. + CheckingAccount, +>; +/// Means for transacting assets on this chain. +pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `RuntimeOrigin::signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxInstructions: u32 = 100; +} + +pub struct ParentOrParentsExecutivePlurality; +impl Contains for ParentOrParentsExecutivePlurality { + fn contains(location: &Location) -> bool { + matches!( + location.unpack(), + (1, []) + | ( + 1, + [Plurality { + id: BodyId::Executive, + .. + }] + ) + ) + } +} + +pub struct ParentOrSiblings; +impl Contains for ParentOrSiblings { + fn contains(location: &Location) -> bool { + matches!(location.unpack(), (1, []) | (1, [_])) + } +} + +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +parameter_types! { + pub MatcherLocation: Location = Location::here(); + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = + orml_xcm_support::MultiNativeAsset; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId32; + +pub type XcmRouter = super::ParachainXcmRouter; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831 +#[frame_support::pallet] +pub mod mock_statemint_prefix { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_prefix)] + pub(super) type CurrentPrefix = StorageValue<_, Location, ValueQuery>; + + impl Get for Pallet { + fn get() -> Location { + Self::current_prefix() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // Changed Prefix + PrefixChanged(Location), + } + + impl Pallet { + pub fn set_prefix(prefix: Location) { + CurrentPrefix::::put(&prefix); + Self::deposit_event(Event::PrefixChanged(prefix)); + } + } +} + +impl mock_statemint_prefix::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +type Block = frame_system::mocking::MockBlockU32; +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + PolkadotXcm: pallet_xcm, + CumulusXcm: cumulus_pallet_xcm, + MsgQueue: mock_msg_queue, + Assets: pallet_assets, + PrefixChanger: mock_statemint_prefix, + + } +); diff --git a/tracing/2902/runtime/moonbeam/tests/xcm_tests.rs b/tracing/2902/runtime/moonbeam/tests/xcm_tests.rs new file mode 100644 index 00000000..20e55146 --- /dev/null +++ b/tracing/2902/runtime/moonbeam/tests/xcm_tests.rs @@ -0,0 +1,3689 @@ +// 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 . + +//! Moonbeam Runtime Xcm Tests + +mod xcm_mock; + +use cumulus_primitives_core::relay_chain::HrmpChannelId; +use frame_support::{ + assert_ok, + traits::{PalletInfo, PalletInfoAccess}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + BoundedVec, +}; +use pallet_xcm_transactor::{ + Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, +}; +use sp_core::ConstU32; +use sp_runtime::traits::MaybeEquivalence; +use xcm::latest::prelude::{ + AccountId32, AccountKey20, GeneralIndex, Junction, Junctions, Limited, Location, OriginKind, + PalletInstance, Parachain, QueryResponse, Reanchorable, Response, WeightLimit, Xcm, +}; +use xcm::{VersionedLocation, WrapVersion}; +use xcm_executor::traits::ConvertLocation; +use xcm_mock::parachain; +use xcm_mock::relay_chain; +use xcm_mock::*; +use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; +use xcm_simulator::TestExt; + +// Send a relay asset (like DOT) to a parachain A +#[test] +fn receive_relay_asset_from_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register relay asset in paraA + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // First send relay chain asset to Parachain + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // Verify that parachain received the asset + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +// Send relay asset (like DOT) back from Parachain A to relaychain +#[test] +fn send_relay_asset_to_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register relay asset in paraA + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // Free execution + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // First send relay chain asset to Parachain like in previous test + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Lets gather the balance before sending back money + let mut balance_before_sending = 0; + Relay::execute_with(|| { + balance_before_sending = RelayBalances::free_balance(&RELAYALICE); + }); + + // We now send back some money to the relay + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: RELAYALICE.into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 123, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The balances in paraAlice should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); + + // Balances in the relay should have been received + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(&RELAYALICE) > balance_before_sending); + }); +} + +#[test] +fn send_relay_asset_to_para_b() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register asset in paraA. Free execution + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Now send relay asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 23); + }); + + // Para B balances should have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_to_para_b() { + MockNet::reset(); + + // This represents the asset in paraA + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // Native token is substracted in paraA + ParaA::execute_with(|| { + // Free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Asset is minted in paraB + ParaB::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_from_para_b_to_para_c() { + MockNet::reset(); + + // Represents para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in parachain B. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register para A asset in parachain C. Free execution + ParaC::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send para A asset from para B to para C + let dest = Location { + parents: 1, + interior: [ + Parachain(3), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The message passed through parachainA so we needed to pay since its the native token + ParaC::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 96); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_and_back_to_para_a() { + MockNet::reset(); + + // para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in para B + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send back para A asset to para A + let dest = Location { + parents: 1, + interior: [ + Parachain(1), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // Weight used is 4 + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 4 + ); + }); +} + +#[test] +fn receive_relay_asset_with_trader() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // We are sending 100 tokens from relay. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Therefore with no refund, we should receive 10 tokens less + // Native trader fails for this, and we use the asset trader + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 100).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // non-free execution, not full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // In destination chain, we only need 4 weight + // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // We are sending 100 tokens from para A. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Since we set 10 weight in destination chain, 25 will be charged upfront + // 15 of those will be refunded, while 10 will go to treasury as the true weight used + // will be 4 + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader_and_fee() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // With these units per second, 80K weight convrets to 1 asset unit + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 12500000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // we use transfer_with_fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_with_fee( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + 1, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // 100 tokens transferred plus 1 taken from fees + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 - 1 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received because trully the xcm instruction does not cost + // what it is specified + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 101); + }); +} + +#[test] +fn error_when_not_paying_enough() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + // We are sending 100 tokens from relay. + // If we set the dest weight to be 1e7, we know the buy_execution will spend 1e7*1e6/1e12 = 10 + // Therefore with no refund, we should receive 10 tokens less + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 5).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // amount not received as it is not paying enough + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); +} + +#[test] +fn transact_through_derivative_multilocation() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + encoded, + // 400000000 + 3000 we should have taken out 4000003000 tokens from the caller + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000003000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + // 4000000000 + 3000 we should have taken out 4000003000 tokens from the caller + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + false + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 9000 correspond to 4000009000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn transact_through_sovereign() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_fee_payer_none() { + MockNet::reset(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let derivative_address = derivative_account_id(para_a_account(), 0); + + Relay::execute_with(|| { + // Transfer 100 tokens to derivative_address on the relay + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derivative_address.clone(), + 100u128 + )); + + // Transfer the XCM execution fee amount to ParaA's sovereign account + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 4000003000u128 + )); + }); + + // Check balances before the transact call + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000003000); + assert_eq!(RelayBalances::free_balance(&derivative_address), 100); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 0); + }); + + // Encode the call. Balances transfer of 100 relay tokens to RELAYBOB + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: RELAYBOB, + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + // The final call will be an AsDerivative using index 0 + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + // No fee_payer here. The sovereign account will pay the fees on destination. + None, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + // Check balances after the transact call are correct + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 0); + assert_eq!(RelayBalances::free_balance(&derivative_address), 0); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 100); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000003000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000009000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn test_automatic_versioning_on_runtime_upgrade_with_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A and set XCM version to 1 + ParaA::execute_with(|| { + parachain::XcmVersioner::set_version(1); + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let response = Response::Version(2); + let querier: Location = ([]/* Here */).into(); + + // This is irrelevant, nothing will be done with this message, + // but we need to pass a message as an argument to trigger the storage change + let mock_message: Xcm<()> = Xcm(vec![QueryResponse { + query_id: 0, + response, + max_weight: Weight::zero(), + querier: Some(querier), + }]); + // The router is mocked, and we cannot use WrapVersion in ChildParachainRouter. So we will force + // it directly here + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + Relay::execute_with(|| { + // This sets the default version, for not known destinations + assert_ok!(RelayChainPalletXcm::force_default_xcm_version( + relay_chain::RuntimeOrigin::root(), + Some(2) + )); + + // Wrap version, which sets VersionedStorage + // This is necessary because the mock router does not use wrap_version, but + // this is not necessary in prod + assert_ok!(::wrap_version( + &Parachain(1).into(), + mock_message + )); + + // Transfer assets. Since it is an unknown destination, it will query for version + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + + // Let's advance the relay. This should trigger the subscription message + relay_chain::relay_roll_to(2); + + // queries should have been updated + assert!(RelayChainPalletXcm::query(0).is_some()); + }); + + let expected_supported_version: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 1, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the version change + assert!(relay_chain::relay_events().contains(&expected_supported_version)); + }); + + // ParaA changes version to 2, and calls on_runtime_upgrade. This should notify the targets + // of the new version change + ParaA::execute_with(|| { + // Set version + parachain::XcmVersioner::set_version(2); + // Do runtime upgrade + parachain::on_runtime_upgrade(); + // Initialize block, to call on_initialize and notify targets + parachain::para_roll_to(2); + // Expect the event in the parachain + assert!(parachain::para_events().iter().any(|e| matches!( + e, + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::VersionChangeNotified { + result: 2, + .. + }) + ))); + }); + + // This event should have been seen in the relay + let expected_supported_version_2: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 2, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the new version change + assert!(relay_chain::relay_events().contains(&expected_supported_version_2)); + }); +} + +#[test] +fn receive_asset_with_no_sufficients_not_possible_if_non_existent_account() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should not have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 0); + }); + + // Send native token to fresh_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + fresh_account.into(), + 100 + )); + }); + + // Re-send tokens + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn receive_assets_with_sufficients_true_allows_non_funded_account_to_receive_assets() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn evm_account_receiving_assets_should_handle_sufficients_ref_count() { + MockNet::reset(); + + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + // Evm account is self sufficient + ParaA::execute_with(|| { + assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // Evm account sufficient ref count increased by 1. + ParaA::execute_with(|| { + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 2); + }); + + ParaA::execute_with(|| { + // Remove the account from the evm context. + parachain::EVM::remove_account(&evm_account()); + // Evm account sufficient ref count decreased by 1. + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); +} + +#[test] +fn empty_account_should_not_be_reset() { + MockNet::reset(); + + // Test account has nonce 1 on genesis. + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send native token to evm_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + evm_account_id, + 100 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Empty the assets from the account. + // As this makes the account go below the `min_balance`, the account is considered dead + // at eyes of pallet-assets, and the consumer reference is decreased by 1 and is now Zero. + assert_ok!(parachain::Assets::transfer( + parachain::RuntimeOrigin::signed(evm_account_id), + source_id, + PARAALICE.into(), + 123 + )); + // Verify account asset balance is Zero. + assert_eq!( + parachain::Assets::balance(source_id, &evm_account_id.into()), + 0 + ); + // Because we no longer have consumer references, we can set the balance to Zero. + // This would reset the account if our ED were to be > than Zero. + assert_ok!(ParaBalances::force_set_balance( + parachain::RuntimeOrigin::root(), + evm_account_id, + 0, + )); + // Verify account native balance is Zero. + assert_eq!(ParaBalances::free_balance(&evm_account_id), 0); + // Remove the account from the evm context. + // This decreases the sufficients reference by 1 and now is Zero. + parachain::EVM::remove_account(&evm_account()); + // Verify reference count. + let account = parachain::System::account(evm_account_id); + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // account.sufficients shall be 0 + assert_eq!(account.sufficients, 1); + assert_eq!(account.consumers, 0); + assert_eq!(account.providers, 1); + // We expect the account to be alive in a Zero ED context. + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // this shall be changed to 1 + assert_eq!(parachain::System::account_nonce(evm_account_id), 2); + }); +} + +#[test] +fn test_statemint_like() { + MockNet::reset(); + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemint_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + let statemint_asset_a_balances = Location::new( + 1, + [ + Parachain(4), + PalletInstance(5), + xcm::latest::prelude::GeneralIndex(0u128), + ], + ); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemint_asset_a_balances) + .expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"StatemintToken".to_vec(), + symbol: b"StatemintToken".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + Statemint::execute_with(|| { + // Set new prefix + statemint_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + + assert_ok!(StatemintAssets::create( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 1 + )); + + assert_ok!(StatemintAssets::mint( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 300000000000000 + )); + + // This is needed, since the asset is created as non-sufficient + assert_ok!(StatemintBalances::transfer_allow_death( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send with new prefix + assert_ok!(StatemintChainPalletXcm::reserve_transfer_assets( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + xcm::latest::prelude::GeneralIndex(0), + ], + 123 + ) + .into() + ), + 0, + )); + }); + + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +#[test] +fn send_statemint_asset_from_para_a_to_statemint_with_relay_fee() { + MockNet::reset(); + + // Relay asset + let relay_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_relay_id: parachain::AssetId = relay_location.clone().into(); + + let relay_asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Statemint asset + let statemint_asset = Location::new( + 1, + [Parachain(4u32), PalletInstance(5u8), GeneralIndex(10u128)], + ); + let statemint_location_asset = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemint_asset).expect("convert to v3"), + ); + let source_statemint_asset_id: parachain::AssetId = statemint_location_asset.clone().into(); + + let asset_metadata_statemint_asset = parachain::AssetMetadata { + name: b"USDC".to_vec(), + symbol: b"USDC".to_vec(), + decimals: 12, + }; + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemint_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + relay_location.clone(), + relay_asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + relay_location, + 0u128, + 0 + )); + + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + statemint_location_asset.clone(), + asset_metadata_statemint_asset, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + statemint_location_asset, + 0u128, + 1 + )); + }); + + let parachain_beneficiary_from_relay: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send relay chain asset to Alice in Parachain A + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_relay) + .clone() + .into() + ), + Box::new(([] /* Here */, 200).into()), + 0, + )); + }); + + Statemint::execute_with(|| { + // Set new prefix + statemint_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + + assert_ok!(StatemintAssets::create( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 1 + )); + + assert_ok!(StatemintAssets::mint( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 300000000000000 + )); + + // Send some native statemint tokens to sovereign for fees. + // We can't pay fees with USDC as the asset is minted as non-sufficient. + assert_ok!(StatemintBalances::transfer_allow_death( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Send statemint USDC asset to Alice in Parachain A + let parachain_beneficiary_from_statemint: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send with new prefix + assert_ok!(StatemintChainPalletXcm::reserve_transfer_assets( + statemint_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_statemint) + .clone() + .into() + ), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + GeneralIndex(10), + ], + 125 + ) + .into() + ), + 0, + )); + }); + + let statemint_beneficiary = Location { + parents: 1, + interior: [ + Parachain(4), + AccountId32 { + network: None, + id: RELAYBOB.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + // Alice has received 125 USDC + assert_eq!( + Assets::balance(source_statemint_asset_id, &PARAALICE.into()), + 125 + ); + + // Alice has received 200 Relay assets + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 200); + }); + + Statemint::execute_with(|| { + // Check that BOB's balance is empty before the transfer + assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![]); + }); + + // Transfer USDC from Parachain A to Statemint using Relay asset as fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_multicurrencies( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + vec![ + ( + parachain::CurrencyId::ForeignAsset(source_statemint_asset_id), + 100 + ), + (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) + ], + 1, + Box::new(VersionedLocation::V4(statemint_beneficiary)), + WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) + )); + }); + + ParaA::execute_with(|| { + // Alice has 100 USDC less + assert_eq!( + Assets::balance(source_statemint_asset_id, &PARAALICE.into()), + 25 + ); + + // Alice has 100 relay asset less + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 100); + }); + + Statemint::execute_with(|| { + println!("STATEMINT EVENTS: {:?}", parachain::para_events()); + // Check that BOB received 100 USDC on statemint + assert_eq!(StatemintAssets::account_balances(RELAYBOB), vec![(10, 100)]); + }); +} + +#[test] +fn transact_through_signed_multilocation() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4000.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000004000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // 100 transferred + assert_eq!(RelayBalances::free_balance(¶_a_account()), 100); + + // 4000005186 refunded + assert_eq!(RelayBalances::free_balance(&derived), 4000005186); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + assert!(ParaBalances::free_balance(&derived) == 0); + + assert!(ParaBalances::free_balance(¶_a_account_20()) == 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: Some(overall_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + }); + + ParaB::execute_with(|| { + // Check the derived account was refunded + assert_eq!(ParaBalances::free_balance(&derived), 8993); + + // Check the transfer was executed + assert_eq!(ParaBalances::free_balance(¶_a_account_20()), 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact { + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer went through + assert!( + ParaBalances::free_balance(&PARAALICE.into()) + == parachain_b_alice_balances_before + 100 + ); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer wasn't executed + assert!(ParaBalances::free_balance(&PARAALICE.into()) == parachain_b_alice_balances_before); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let transfer_recipient = evm_account(); + let mut transfer_recipient_balance_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + transfer_recipient_balance_before = ParaBalances::free_balance(&transfer_recipient.into()); + + // Add proxy ALICE -> derived + let _ = parachain::Proxy::add_proxy_delegate( + &PARAALICE.into(), + derived, + parachain::ProxyType::Any, + 0, + ); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V2(xcm_primitives::EthereumXcmTransactionV2 { + gas_limit: U256::from(21000), + action: pallet_ethereum::TransactionAction::Call(transfer_recipient.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer was executed + assert!( + ParaBalances::free_balance(&transfer_recipient.into()) + == transfer_recipient_balance_before + 100 + ); + }); +} + +#[test] +fn hrmp_init_accept_through_root() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_b_account(), + 1000u128 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp init channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::InitOpen(HrmpInitParams { + para_id: 2u32.into(), + proposed_max_capacity: 1, + proposed_max_message_size: 1 + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelRequested { + sender: 1u32.into(), + recipient: 2u32.into(), + proposed_max_capacity: 1u32, + proposed_max_message_size: 1u32, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); + ParaB::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp accept channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Accept { + para_id: 1u32.into() + }, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelAccepted { + sender: 1u32.into(), + recipient: 2u32.into(), + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +#[test] +fn hrmp_close_works() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(Hrmp::force_open_hrmp_channel( + relay_chain::RuntimeOrigin::root(), + 1u32.into(), + 2u32.into(), + 1u32, + 1u32 + )); + assert_ok!(Hrmp::force_process_hrmp_open( + relay_chain::RuntimeOrigin::root(), + 1u32 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp close + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Close(HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into() + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::ChannelClosed { + by_parachain: 1u32.into(), + channel_id: HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into(), + }, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +use parity_scale_codec::{Decode, Encode}; +use sp_io::hashing::blake2_256; + +// Helper to derive accountIds +pub fn derivative_account_id(who: sp_runtime::AccountId32, index: u16) -> sp_runtime::AccountId32 { + let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); + sp_runtime::AccountId32::decode(&mut &entropy[..]).expect("valid account id") +} diff --git a/tracing/2902/runtime/moonriver/Cargo.toml b/tracing/2902/runtime/moonriver/Cargo.toml new file mode 100644 index 00000000..42e5f0ea --- /dev/null +++ b/tracing/2902/runtime/moonriver/Cargo.toml @@ -0,0 +1,406 @@ +[package] +authors = { workspace = true } +build = "build.rs" +description = "Moonriver Runtime" +edition = "2021" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +name = "moonriver-runtime" +version = "0.8.4" + +[dependencies] +hex-literal = { workspace = true, optional = true } +log = { workspace = true } +num_enum = { workspace = true } +rlp = { workspace = true, optional = true } +serde = { workspace = true, features = ["derive"] } +sha3 = { workspace = true, optional = true } +smallvec = { workspace = true } +strum = { workspace = true } +strum_macros = { workspace = true } + +# Moonbeam +account = { workspace = true } +moonbeam-core-primitives = { workspace = true } +moonbeam-relay-encoder = { workspace = true } +moonbeam-runtime-common = { workspace = true } +precompile-utils = { workspace = true } +session-keys-primitives = { workspace = true } +xcm-primitives = { workspace = true } + +# Moonbeam pallets +moonbeam-xcm-benchmarks = { workspace = true } +pallet-asset-manager = { workspace = true } +pallet-author-mapping = { workspace = true } +pallet-crowdloan-rewards = { workspace = true } +pallet-erc20-xcm-bridge = { workspace = true } +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-lazy-migrations = { workspace = true } +pallet-moonbeam-orbiters = { workspace = true } +pallet-parachain-staking = { workspace = true } +pallet-precompile-benchmarks = { workspace = true } +pallet-proxy-genesis-companion = { workspace = true } +pallet-randomness = { workspace = true } +pallet-xcm-transactor = { workspace = true } + +# Moonbeam precompiles +pallet-evm-precompile-author-mapping = { workspace = true } +pallet-evm-precompile-balances-erc20 = { workspace = true } +pallet-evm-precompile-batch = { workspace = true } +pallet-evm-precompile-call-permit = { workspace = true } +pallet-evm-precompile-collective = { workspace = true } +pallet-evm-precompile-conviction-voting = { workspace = true } +pallet-evm-precompile-crowdloan-rewards = { workspace = true } +pallet-evm-precompile-gmp = { workspace = true } +pallet-evm-precompile-identity = { workspace = true } +pallet-evm-precompile-parachain-staking = { workspace = true } +pallet-evm-precompile-preimage = { workspace = true } +pallet-evm-precompile-proxy = { workspace = true } +pallet-evm-precompile-randomness = { workspace = true } +pallet-evm-precompile-referenda = { workspace = true } +pallet-evm-precompile-registry = { workspace = true } +pallet-evm-precompile-relay-encoder = { workspace = true } +pallet-evm-precompile-relay-verifier = { workspace = true } +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 } + +# Moonbeam tracing +evm-tracing-events = { workspace = true, optional = true } +moonbeam-evm-tracer = { workspace = true, optional = true } +moonbeam-rpc-primitives-debug = { workspace = true } +moonbeam-rpc-primitives-txpool = { workspace = true } + +# Substrate +frame-executive = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +frame-system-rpc-runtime-api = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true, features = ["insecure_zero_ed"] } +pallet-collective = { workspace = true } +pallet-conviction-voting = { workspace = true } +pallet-identity = { workspace = true } +pallet-multisig = { workspace = true } +pallet-preimage = { workspace = true } +pallet-proxy = { workspace = true } +pallet-referenda = { workspace = true } +pallet-root-testing = { workspace = true } +pallet-scheduler = { workspace = true } +pallet-society = { workspace = true } +pallet-timestamp = { workspace = true } +pallet-transaction-payment = { workspace = true } +pallet-transaction-payment-rpc-runtime-api = { workspace = true } +pallet-treasury = { workspace = true } +pallet-utility = { workspace = true } +pallet-whitelist = { workspace = true } +parity-scale-codec = { workspace = true, features = [ + "derive", + "max-encoded-len", + "chain-error", +] } +scale-info = { workspace = true, features = ["derive"] } +sp-api = { workspace = true } +sp-block-builder = { workspace = true } +sp-consensus-slots = { workspace = true } +sp-core = { workspace = true } +sp-debug-derive = { workspace = true } +sp-inherents = { workspace = true } +sp-io = { workspace = true, features = ["improved_panic_error_reporting"] } +sp-offchain = { workspace = true } +sp-runtime = { workspace = true } +sp-session = { workspace = true } +sp-std = { workspace = true } +sp-transaction-pool = { workspace = true } +sp-version = { workspace = true } +sp-weights = { workspace = true } +sp-genesis-builder = { workspace = true } + +# Frontier +fp-evm = { workspace = true } +fp-rpc = { workspace = true } +fp-self-contained = { workspace = true, features = ["serde"] } +pallet-ethereum = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm = { workspace = true, features = ["forbid-evm-reentrancy"] } +pallet-evm-precompile-blake2 = { workspace = true } +pallet-evm-precompile-bn128 = { workspace = true } +pallet-evm-precompile-dispatch = { workspace = true } +pallet-evm-precompile-modexp = { workspace = true } +pallet-evm-precompile-sha3fips = { workspace = true } +pallet-evm-precompile-simple = { workspace = true } + +# Polkadot / XCM +orml-traits = { workspace = true } +orml-xcm-support = { workspace = true } +orml-xtokens = { workspace = true } +pallet-xcm = { workspace = true } +pallet-xcm-benchmarks = { workspace = true, optional = true } +polkadot-core-primitives = { workspace = true } +polkadot-parachain = { workspace = true } +polkadot-runtime-common = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } +pallet-message-queue = { workspace = true } + +# Cumulus +cumulus-pallet-dmp-queue = { workspace = true } +cumulus-pallet-parachain-system = { workspace = true } +cumulus-pallet-xcm = { workspace = true } +cumulus-pallet-xcmp-queue = { workspace = true } +cumulus-primitives-core = { workspace = true } +cumulus-primitives-timestamp = { workspace = true } +cumulus-primitives-utility = { workspace = true } +parachain-info = { workspace = true } +parachains-common = { workspace = true } + +# Moonkit +async-backing-primitives = { workspace = true } +moonkit-xcm-primitives = { workspace = true } +nimbus-primitives = { workspace = true } +pallet-author-inherent = { workspace = true } +pallet-author-slot-filter = { workspace = true } +pallet-relay-storage-roots = { workspace = true } + +# Benchmarking +frame-benchmarking = { workspace = true, optional = true } +frame-system-benchmarking = { workspace = true, optional = true } +frame-try-runtime = { workspace = true, optional = true } + +[build-dependencies] +substrate-wasm-builder = { workspace = true } + +[features] +default = ["std", "evm-tracing"] +std = [ + "account/std", + "async-backing-primitives/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "evm-tracing-events/std", + "fp-evm/std", + "fp-rpc/std", + "fp-self-contained/std", + "frame-benchmarking/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "moonbeam-core-primitives/std", + "moonbeam-evm-tracer/std", + "moonbeam-relay-encoder/std", + "moonbeam-rpc-primitives-debug/std", + "moonbeam-rpc-primitives-txpool/std", + "moonbeam-runtime-common/std", + "moonbeam-xcm-benchmarks/std", + "moonkit-xcm-primitives/std", + "nimbus-primitives/std", + "orml-xtokens/std", + "pallet-asset-manager/std", + "pallet-assets/std", + "pallet-author-inherent/std", + "pallet-author-mapping/std", + "pallet-author-slot-filter/std", + "pallet-balances/std", + "pallet-collective/std", + "pallet-conviction-voting/std", + "pallet-crowdloan-rewards/std", + "pallet-erc20-xcm-bridge/std", + "pallet-evm-chain-id/std", + "pallet-ethereum-xcm/std", + "pallet-ethereum/std", + "pallet-evm-precompile-author-mapping/std", + "pallet-evm-precompile-balances-erc20/std", + "pallet-evm-precompile-batch/std", + "pallet-evm-precompile-call-permit/std", + "pallet-evm-precompile-collective/std", + "pallet-evm-precompile-conviction-voting/std", + "pallet-evm-precompile-parachain-staking/std", + "pallet-evm-precompile-preimage/std", + "pallet-evm-precompile-randomness/std", + "pallet-evm-precompile-referenda/std", + "pallet-evm-precompile-relay-encoder/std", + "pallet-evm-precompile-relay-verifier/std", + "pallet-evm-precompile-xcm-transactor/std", + "pallet-evm-precompile-xcm-utils/std", + "pallet-evm-precompile-xtokens/std", + "pallet-evm/std", + "pallet-identity/std", + "pallet-maintenance-mode/std", + "pallet-migrations/std", + "pallet-moonbeam-lazy-migrations/std", + "pallet-moonbeam-orbiters/std", + "pallet-multisig/std", + "pallet-parachain-staking/std", + "pallet-precompile-benchmarks/std", + "pallet-preimage/std", + "pallet-proxy-genesis-companion/std", + "pallet-proxy/std", + "pallet-randomness/std", + "pallet-referenda/std", + "pallet-relay-storage-roots/std", + "pallet-root-testing/std", + "pallet-scheduler/std", + "pallet-society/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-treasury/std", + "pallet-utility/std", + "pallet-whitelist/std", + "pallet-xcm-transactor/std", + "pallet-xcm/std", + "parachain-info/std", + "parachains-common/std", + "parity-scale-codec/std", + "precompile-utils/std", + "scale-info/std", + "session-keys-primitives/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-slots/std", + "sp-core/std", + "sp-inherents/std", + "sp-io/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "sp-genesis-builder/std", + "strum/std", + "xcm-builder/std", + "xcm-executor/std", + "xcm-primitives/std", + "xcm/std", +] + +# Must be enabled for tracing runtimes only +evm-tracing = ["evm-tracing-events", "moonbeam-evm-tracer", "rlp", "sha3"] + +# Allow to print logs details (no wasm:stripped) +force-debug = ["sp-debug-derive/force-debug"] + +# Will be enabled by the `wasm-builder` when building the runtime for WASM. +runtime-wasm = [] + +# A feature that should be enabled when the runtime should be build for on-chain +# deployment. This will disable stuff that shouldn't be part of the on-chain wasm +# to make it smaller like logging for example. +on-chain-release-build = ["sp-api/disable-logging"] + +runtime-benchmarks = [ + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-primitives-core/runtime-benchmarks", + "frame-benchmarking", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "moonbeam-relay-encoder/runtime-benchmarks", + "moonbeam-runtime-common/runtime-benchmarks", + "moonbeam-xcm-benchmarks/runtime-benchmarks", + "parachains-common/runtime-benchmarks", + "pallet-asset-manager/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "pallet-author-inherent/runtime-benchmarks", + "pallet-author-mapping/runtime-benchmarks", + "pallet-author-slot-filter/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collective/runtime-benchmarks", + "pallet-conviction-voting/runtime-benchmarks", + "pallet-crowdloan-rewards/runtime-benchmarks", + "pallet-ethereum-xcm/runtime-benchmarks", + "pallet-ethereum/runtime-benchmarks", + "pallet-evm/runtime-benchmarks", + "pallet-identity/runtime-benchmarks", + "pallet-migrations/runtime-benchmarks", + "pallet-moonbeam-lazy-migrations/runtime-benchmarks", + "pallet-moonbeam-orbiters/runtime-benchmarks", + "pallet-multisig/runtime-benchmarks", + "pallet-parachain-staking/runtime-benchmarks", + "pallet-precompile-benchmarks/runtime-benchmarks", + "pallet-preimage/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-randomness/runtime-benchmarks", + "pallet-referenda/runtime-benchmarks", + "pallet-relay-storage-roots/runtime-benchmarks", + "pallet-scheduler/runtime-benchmarks", + "pallet-society/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-treasury/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", + "pallet-whitelist/runtime-benchmarks", + "pallet-xcm-benchmarks/runtime-benchmarks", + "pallet-xcm-transactor/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "session-keys-primitives/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", +] +try-runtime = [ + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "fp-self-contained/try-runtime", + "frame-executive/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime", + "moonbeam-runtime-common/try-runtime", + "pallet-asset-manager/try-runtime", + "pallet-author-mapping/try-runtime", + "pallet-author-slot-filter/try-runtime", + "pallet-balances/try-runtime", + "pallet-collective/try-runtime", + "pallet-conviction-voting/try-runtime", + "pallet-maintenance-mode/try-runtime", + "pallet-migrations/try-runtime", + "pallet-moonbeam-lazy-migrations/try-runtime", + "pallet-parachain-staking/try-runtime", + "pallet-precompile-benchmarks/try-runtime", + "pallet-preimage/try-runtime", + "pallet-referenda/try-runtime", + "pallet-relay-storage-roots/try-runtime", + "pallet-root-testing/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-society/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-whitelist/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-xcm/try-runtime", + "pallet-message-queue/try-runtime", + "pallet-utility/try-runtime", + "pallet-transaction-payment/try-runtime", + "parachain-info/try-runtime", + "pallet-evm-chain-id/try-runtime", + "parachain-info/try-runtime", + "pallet-evm/try-runtime", + "pallet-ethereum/try-runtime", + "pallet-treasury/try-runtime", + "pallet-author-inherent/try-runtime", + "pallet-crowdloan-rewards/try-runtime", + "pallet-proxy/try-runtime", + "pallet-identity/try-runtime", + "orml-xtokens/try-runtime", + "pallet-assets/try-runtime", + "pallet-xcm-transactor/try-runtime", + "pallet-proxy-genesis-companion/try-runtime", + "pallet-moonbeam-orbiters/try-runtime", + "pallet-ethereum-xcm/try-runtime", + "pallet-randomness/try-runtime", + "pallet-whitelist/try-runtime", + "pallet-erc20-xcm-bridge/try-runtime", + "pallet-multisig/try-runtime", +] diff --git a/tracing/2902/runtime/moonriver/build.rs b/tracing/2902/runtime/moonriver/build.rs new file mode 100644 index 00000000..3934b9c5 --- /dev/null +++ b/tracing/2902/runtime/moonriver/build.rs @@ -0,0 +1,25 @@ +// 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 substrate_wasm_builder::WasmBuilder; + +fn main() { + WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() +} diff --git a/tracing/2902/runtime/moonriver/src/asset_config.rs b/tracing/2902/runtime/moonriver/src/asset_config.rs new file mode 100644 index 00000000..ca1cce4d --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/asset_config.rs @@ -0,0 +1,219 @@ +// 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 . + +//! Asset configuration for Moonbase. +//! + +use super::{ + currency, governance, xcm_config, AccountId, AssetId, AssetManager, Assets, Balance, Balances, + OpenTechCommitteeInstance, Runtime, RuntimeCall, RuntimeEvent, RuntimeOrigin, + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; + +use frame_support::{ + dispatch::GetDispatchInfo, + parameter_types, + traits::{AsEnsureOriginWithArg, ConstU128, ConstU32, EitherOfDiverse}, + weights::Weight, +}; +use frame_system::{EnsureNever, EnsureRoot}; +use sp_core::H160; + +use parity_scale_codec::{Compact, Decode, Encode}; +use scale_info::TypeInfo; + +use sp_std::{ + convert::{From, Into}, + prelude::*, +}; + +// Number of items that can be destroyed with our configured max extrinsic proof size. +// x = (a - b) / c where: +// a: maxExtrinsic proof size +// b: base proof size for destroy_accounts in pallet_assets weights +// c: proof size for each item +// 656.87 = (3_407_872 - 8232) / 5180 +const REMOVE_ITEMS_LIMIT: u32 = 656; + +// Not to disrupt the previous asset instance, we assign () to Foreign +pub type ForeignAssetInstance = (); + +// For foreign assets, these parameters dont matter much +// as this will only be called by root with the forced arguments +// No deposit is substracted with those methods +parameter_types! { + pub const AssetDeposit: Balance = 100 * currency::MOVR * currency::SUPPLY_FACTOR; + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = currency::deposit(1,68); + pub const MetadataDepositPerByte: Balance = currency::deposit(0, 1); +} + +/// We allow Root and General Admin to execute privileged asset operations. +pub type AssetsForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +// Foreign assets +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = AssetsForceOrigin; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = ConstU128<{ currency::deposit(1, 18) }>; + type WeightInfo = moonbeam_weights::pallet_assets::WeightInfo; + type RemoveItemsLimit = ConstU32<{ REMOVE_ITEMS_LIMIT }>; + type AssetIdParameter = Compact; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +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, + ) -> 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, + ) + } + + #[transactional] + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + // For us both of them (Foreign and Local) have the same annotated weight for a given + // witness + // We need to take the dispatch info from the destroy call, which is already annotated in + // the assets pallet + + // This is the dispatch info of destroy + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetRegistrarMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, + pub is_frozen: bool, +} + +pub type ForeignAssetModifierOrigin = EitherOfDiverse< + EnsureRoot, + EitherOfDiverse< + pallet_collective::EnsureProportionMoreThan, + governance::custom_origins::GeneralAdmin, + >, +>; +pub type LocalAssetModifierOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetRegistrarMetadata; + type ForeignAssetType = xcm_config::AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = ForeignAssetModifierOrigin; + type WeightInfo = moonbeam_weights::pallet_asset_manager::WeightInfo; +} + +// Instruct how to go from an H160 to an AssetID +// We just take the lowest 128 bits +impl AccountIdAssetIdConversion for Runtime { + /// The way to convert an account to assetId is by ensuring that the prefix is 0XFFFFFFFF + /// and by taking the lowest 128 bits as the assetId + fn account_to_asset_id(account: AccountId) -> Option<(Vec, AssetId)> { + let h160_account: H160 = account.into(); + let mut data = [0u8; 16]; + let (prefix_part, id_part) = h160_account.as_fixed_bytes().split_at(4); + if prefix_part == FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX { + data.copy_from_slice(id_part); + let asset_id: AssetId = u128::from_be_bytes(data).into(); + Some((prefix_part.to_vec(), asset_id)) + } else { + None + } + } + + // The opposite conversion + fn asset_id_to_account(prefix: &[u8], asset_id: AssetId) -> AccountId { + let mut data = [0u8; 20]; + data[0..4].copy_from_slice(prefix); + data[4..20].copy_from_slice(&asset_id.to_be_bytes()); + AccountId::from(data) + } +} diff --git a/tracing/2902/runtime/moonriver/src/governance/councils.rs b/tracing/2902/runtime/moonriver/src/governance/councils.rs new file mode 100644 index 00000000..1c51423e --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/governance/councils.rs @@ -0,0 +1,61 @@ +// 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 . + +//! Councils for Gov1 and Gov2 + +use super::*; + +pub type TreasuryCouncilInstance = pallet_collective::Instance3; +pub type OpenTechCommitteeInstance = pallet_collective::Instance4; + +parameter_types! { + // TODO: Check value of this parameter + pub MaxProposalWeight: Weight = Perbill::from_percent(50) * RuntimeBlockWeights::get().max_block; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for treasury council members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 3 * DAYS }>; + /// The maximum number of proposals that can be open in the treasury council at once. + type MaxProposals = ConstU32<20>; + /// The maximum number of treasury council members. + type MaxMembers = ConstU32<9>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} + +impl pallet_collective::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Proposal = RuntimeCall; + /// The maximum amount of time (in blocks) for technical committee members to vote on motions. + /// Motions may end in fewer blocks if enough votes are cast to determine the result. + type MotionDuration = ConstU32<{ 14 * DAYS }>; + /// The maximum number of proposals that can be open in the technical committee at once. + type MaxProposals = ConstU32<100>; + /// The maximum number of technical committee members. + type MaxMembers = ConstU32<100>; + type DefaultVote = pallet_collective::MoreThanMajorityThenPrimeDefaultVote; + type WeightInfo = moonbeam_weights::pallet_collective::WeightInfo; + type SetMembersOrigin = referenda::GeneralAdminOrRoot; + type MaxProposalWeight = MaxProposalWeight; +} diff --git a/tracing/2902/runtime/moonriver/src/governance/mod.rs b/tracing/2902/runtime/moonriver/src/governance/mod.rs new file mode 100644 index 00000000..36a2c6be --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/governance/mod.rs @@ -0,0 +1,29 @@ +// 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 . + +//! Governance configurations + +pub mod councils; +pub mod referenda; + +use super::*; + +mod origins; +pub use origins::{ + custom_origins, GeneralAdmin, ReferendumCanceller, ReferendumKiller, WhitelistedCaller, +}; +mod tracks; +pub use tracks::TracksInfo; diff --git a/tracing/2902/runtime/moonriver/src/governance/origins.rs b/tracing/2902/runtime/moonriver/src/governance/origins.rs new file mode 100644 index 00000000..ef4675d6 --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/governance/origins.rs @@ -0,0 +1,84 @@ +// 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. + +//! Custom origins for governance interventions. +#![cfg_attr(not(feature = "std"), no_std)] +pub use custom_origins::*; + +#[frame_support::pallet] +pub mod custom_origins { + use frame_support::pallet_prelude::*; + use strum_macros::EnumString; + + #[pallet::config] + pub trait Config: frame_system::Config {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[derive( + PartialEq, Eq, Clone, MaxEncodedLen, Encode, Decode, TypeInfo, RuntimeDebug, EnumString, + )] + #[strum(serialize_all = "snake_case")] + #[pallet::origin] + pub enum Origin { + /// Origin able to dispatch a whitelisted call. + WhitelistedCaller, + /// General admin + GeneralAdmin, + /// Origin able to cancel referenda. + ReferendumCanceller, + /// Origin able to kill referenda. + ReferendumKiller, + /// Fast General Admin + FastGeneralAdmin, + } + + macro_rules! decl_unit_ensures { + ( $name:ident: $success_type:ty = $success:expr ) => { + pub struct $name; + impl> + From> + EnsureOrigin for $name + { + type Success = $success_type; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + Origin::$name => Ok($success), + r => Err(O::from(r)), + }) + } + #[cfg(feature = "runtime-benchmarks")] + fn try_successful_origin() -> Result { + Ok(O::from(Origin::$name)) + } + } + }; + ( $name:ident ) => { decl_unit_ensures! { $name : () = () } }; + ( $name:ident: $success_type:ty = $success:expr, $( $rest:tt )* ) => { + decl_unit_ensures! { $name: $success_type = $success } + decl_unit_ensures! { $( $rest )* } + }; + ( $name:ident, $( $rest:tt )* ) => { + decl_unit_ensures! { $name } + decl_unit_ensures! { $( $rest )* } + }; + () => {} + } + decl_unit_ensures!( + ReferendumCanceller, + ReferendumKiller, + WhitelistedCaller, + GeneralAdmin, + FastGeneralAdmin, + ); +} diff --git a/tracing/2902/runtime/moonriver/src/governance/referenda.rs b/tracing/2902/runtime/moonriver/src/governance/referenda.rs new file mode 100644 index 00000000..8177e88e --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/governance/referenda.rs @@ -0,0 +1,100 @@ +// 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 . + +//! # Gov2 config +//! Includes runtime configs for these substrate pallets: +//! 1. pallet-conviction-voting +//! 2. pallet-whitelist +//! 3. pallet-referenda + +use super::*; +use crate::currency::*; +use frame_support::traits::{EitherOf, MapSuccess}; +use frame_system::EnsureRootWithSuccess; +use sp_runtime::traits::Replace; + +parameter_types! { + pub const VoteLockingPeriod: BlockNumber = 1 * DAYS; +} + +impl pallet_conviction_voting::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_conviction_voting::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type Polls = Referenda; + type MaxTurnout = frame_support::traits::TotalIssuanceOf; + // Maximum number of concurrent votes an account may have + type MaxVotes = ConstU32<20>; + // Minimum period of vote locking + type VoteLockingPeriod = VoteLockingPeriod; +} + +parameter_types! { + pub const AlarmInterval: BlockNumber = 1; + pub const SubmissionDeposit: Balance = 10 * MOVR * SUPPLY_FACTOR; + pub const UndecidingTimeout: BlockNumber = 21 * DAYS; +} + +// Origin for general admin or root +pub type GeneralAdminOrRoot = EitherOf, origins::GeneralAdmin>; +// The policy allows for Root or FastGeneralAdmin. +pub type FastGeneralAdminOrRoot = EitherOf, origins::FastGeneralAdmin>; + +impl custom_origins::Config for Runtime {} + +// The purpose of this pallet is to queue calls to be dispatched as by root later => the Dispatch +// origin corresponds to the Gov2 Whitelist track. +impl pallet_whitelist::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_whitelist::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WhitelistOrigin = EitherOf< + EnsureRootWithSuccess>, + MapSuccess< + pallet_collective::EnsureProportionAtLeast< + Self::AccountId, + OpenTechCommitteeInstance, + 5, + 9, + >, + Replace>, + >, + >; + type DispatchWhitelistedOrigin = EitherOf, WhitelistedCaller>; + type Preimages = Preimage; +} + +pallet_referenda::impl_tracksinfo_get!(TracksInfo, Balance, BlockNumber); + +impl pallet_referenda::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_referenda::WeightInfo; + type RuntimeCall = RuntimeCall; + type RuntimeEvent = RuntimeEvent; + type Scheduler = Scheduler; + type Currency = Balances; + type SubmitOrigin = frame_system::EnsureSigned; + type CancelOrigin = EitherOf, ReferendumCanceller>; + type KillOrigin = EitherOf, ReferendumKiller>; + type Slash = Treasury; + type Votes = pallet_conviction_voting::VotesOf; + type Tally = pallet_conviction_voting::TallyOf; + type SubmissionDeposit = SubmissionDeposit; + type MaxQueued = ConstU32<100>; + type UndecidingTimeout = UndecidingTimeout; + type AlarmInterval = AlarmInterval; + type Tracks = TracksInfo; + type Preimages = Preimage; +} diff --git a/tracing/2902/runtime/moonriver/src/governance/tracks.rs b/tracing/2902/runtime/moonriver/src/governance/tracks.rs new file mode 100644 index 00000000..8dddbeca --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/governance/tracks.rs @@ -0,0 +1,193 @@ +// Copyright 2022 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Track configurations for governance. + +use super::*; +use crate::currency::{KILOMOVR, MOVR, SUPPLY_FACTOR}; +use sp_std::str::FromStr; + +const fn percent(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 100) +} +const fn permill(x: i32) -> sp_runtime::FixedI64 { + sp_runtime::FixedI64::from_rational(x as u128, 1000) +} + +use pallet_referenda::Curve; +const TRACKS_DATA: [(u16, pallet_referenda::TrackInfo); 6] = [ + ( + 0, + pallet_referenda::TrackInfo { + // Name of this track. + name: "root", + // A limit for the number of referenda on this track that can be being decided at once. + // For Root origin this should generally be just one. + max_deciding: 5, + // Amount that must be placed on deposit before a decision can be made. + decision_deposit: 100 * KILOMOVR * SUPPLY_FACTOR, + // Amount of time this must be submitted for before a decision can be made. + prepare_period: 1 * DAYS, + // Amount of time that a decision may take to be approved prior to cancellation. + decision_period: 14 * DAYS, + // Amount of time that the approval criteria must hold before it can be approved. + confirm_period: 1 * DAYS, + // Minimum amount of time that an approved proposal must be in the dispatch queue. + min_enactment_period: 1 * DAYS, + // Minimum aye votes as percentage of overall conviction-weighted votes needed for + // approval as a function of time into decision period. + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + // Minimum pre-conviction aye-votes ("support") as percentage of overall population that + // is needed for approval as a function of time into decision period. + min_support: Curve::make_linear(14, 14, permill(5), percent(25)), + }, + ), + ( + 1, + pallet_referenda::TrackInfo { + name: "whitelisted_caller", + max_deciding: 100, + decision_deposit: 10 * KILOMOVR * SUPPLY_FACTOR, + prepare_period: 10 * MINUTES, + decision_period: 14 * DAYS, + confirm_period: 10 * MINUTES, + min_enactment_period: 30 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14 * 24, percent(1), percent(0), percent(2)), + }, + ), + ( + 2, + pallet_referenda::TrackInfo { + name: "general_admin", + max_deciding: 10, + decision_deposit: 500 * MOVR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 1 * DAYS, + min_enactment_period: 1 * DAYS, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(7, 14, percent(10), percent(0), percent(50)), + }, + ), + ( + 3, + pallet_referenda::TrackInfo { + name: "referendum_canceller", + max_deciding: 20, + decision_deposit: 10 * KILOMOVR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), + }, + ), + ( + 4, + pallet_referenda::TrackInfo { + name: "referendum_killer", + max_deciding: 100, + decision_deposit: 20 * KILOMOVR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(1, 14, percent(96), percent(50), percent(100)), + min_support: Curve::make_reciprocal(1, 14, percent(1), percent(0), percent(10)), + }, + ), + ( + 5, + pallet_referenda::TrackInfo { + name: "fast_general_admin", + max_deciding: 10, + decision_deposit: 500 * MOVR * SUPPLY_FACTOR, + prepare_period: 1 * HOURS, + decision_period: 14 * DAYS, + confirm_period: 3 * HOURS, + min_enactment_period: 10 * MINUTES, + min_approval: Curve::make_reciprocal(4, 14, percent(80), percent(50), percent(100)), + min_support: Curve::make_reciprocal(5, 14, percent(1), percent(0), percent(50)), + }, + ), +]; + +pub struct TracksInfo; +impl pallet_referenda::TracksInfo for TracksInfo { + type Id = u16; + type RuntimeOrigin = ::PalletsOrigin; + fn tracks() -> &'static [(Self::Id, pallet_referenda::TrackInfo)] { + &TRACKS_DATA[..] + } + fn track_for(id: &Self::RuntimeOrigin) -> Result { + if let Ok(system_origin) = frame_system::RawOrigin::try_from(id.clone()) { + match system_origin { + frame_system::RawOrigin::Root => { + if let Some((track_id, _)) = Self::tracks() + .into_iter() + .find(|(_, track)| track.name == "root") + { + Ok(*track_id) + } else { + Err(()) + } + } + _ => Err(()), + } + } else if let Ok(custom_origin) = custom_origins::Origin::try_from(id.clone()) { + if let Some((track_id, _)) = Self::tracks().into_iter().find(|(_, track)| { + if let Ok(track_custom_origin) = custom_origins::Origin::from_str(track.name) { + track_custom_origin == custom_origin + } else { + false + } + }) { + Ok(*track_id) + } else { + Err(()) + } + } else { + Err(()) + } + } +} + +#[test] +/// To ensure voters are always locked into their vote +fn vote_locking_always_longer_than_enactment_period() { + for (_, track) in TRACKS_DATA { + assert!( + ::VoteLockingPeriod::get() + >= track.min_enactment_period, + "Track {} has enactment period {} < vote locking period {}", + track.name, + track.min_enactment_period, + ::VoteLockingPeriod::get(), + ); + } +} + +#[test] +fn all_tracks_have_origins() { + for (_, track) in TRACKS_DATA { + // check name.into() is successful either converts into "root" or custom origin + let track_is_root = track.name == "root"; + let track_has_custom_origin = custom_origins::Origin::from_str(track.name).is_ok(); + assert!(track_is_root || track_has_custom_origin); + } +} diff --git a/tracing/2902/runtime/moonriver/src/lib.rs b/tracing/2902/runtime/moonriver/src/lib.rs new file mode 100644 index 00000000..4dab7ad4 --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/lib.rs @@ -0,0 +1,1791 @@ +// 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 . + +//! The Moonriver Runtime. +//! +//! Primary features of this runtime include: +//! * Ethereum compatibility +//! * Moonriver tokenomics + +#![cfg_attr(not(feature = "std"), no_std)] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. +#![recursion_limit = "256"] + +// Make the WASM binary available. +#[cfg(feature = "std")] +include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); + +use account::AccountId20; +use cumulus_pallet_parachain_system::{RelayChainStateProof, RelaychainDataProvider}; +use fp_rpc::TransactionStatus; + +// Re-export required by get! macro. +use cumulus_primitives_core::{relay_chain, AggregateMessageOrigin}; +#[cfg(feature = "std")] +pub use fp_evm::GenesisAccount; +pub use frame_support::traits::Get; +use frame_support::{ + construct_runtime, + dispatch::{DispatchClass, GetDispatchInfo, PostDispatchInfo}, + ensure, + pallet_prelude::DispatchResult, + parameter_types, + traits::{ + fungible::{Balanced, Credit, HoldConsideration, Inspect}, + tokens::imbalance::ResolveTo, + tokens::{PayFromAccount, UnityAssetBalanceConversion}, + ConstBool, ConstU128, ConstU16, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, + EqualPrivilegeOnly, Imbalance, InstanceFilter, LinearStoragePrice, OnFinalize, + OnUnbalanced, + }, + weights::{ + constants::{RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND}, + ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, + WeightToFeePolynomial, + }, + PalletId, +}; +use frame_system::{EnsureRoot, EnsureSigned}; +pub use moonbeam_core_primitives::{ + AccountId, AccountIndex, Address, AssetId, Balance, BlockNumber, DigestItem, Hash, Header, + Index, Signature, +}; +use moonbeam_rpc_primitives_txpool::TxPoolResponse; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_ethereum::Call::transact; +use pallet_ethereum::{PostLogContent, Transaction as EthereumTransaction}; +use pallet_evm::{ + Account as EVMAccount, EVMFungibleAdapter, EnsureAddressNever, EnsureAddressRoot, + FeeCalculator, GasWeightMapping, IdentityAddressMapping, + OnChargeEVMTransaction as OnChargeEVMTransactionT, Runner, +}; +pub use pallet_parachain_staking::{weights::WeightInfo, InflationInfo, Range}; +use pallet_transaction_payment::{FungibleAdapter, Multiplier, TargetedFeeAdjustment}; +use pallet_treasury::TreasuryAccountId; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use scale_info::TypeInfo; +use sp_api::impl_runtime_apis; +use sp_consensus_slots::Slot; +use sp_core::{OpaqueMetadata, H160, H256, U256}; +use sp_runtime::{ + create_runtime_str, generic, impl_opaque_keys, + serde::{Deserialize, Serialize}, + traits::{ + BlakeTwo256, Block as BlockT, DispatchInfoOf, Dispatchable, IdentityLookup, + PostDispatchInfoOf, UniqueSaturatedInto, Zero, + }, + transaction_validity::{ + InvalidTransaction, TransactionSource, TransactionValidity, TransactionValidityError, + }, + ApplyExtrinsicResult, DispatchErrorWithPostInfo, FixedPointNumber, Perbill, Permill, + Perquintill, SaturatedConversion, +}; +use sp_std::{convert::TryFrom, prelude::*}; + +use smallvec::smallvec; +#[cfg(feature = "std")] +use sp_version::NativeVersion; +use sp_version::RuntimeVersion; + +use nimbus_primitives::CanAuthor; + +mod precompiles; +pub use precompiles::{ + MoonriverPrecompiles, PrecompileName, FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; + +#[cfg(any(feature = "std", test))] +pub use sp_runtime::BuildStorage; + +pub type Precompiles = MoonriverPrecompiles; + +pub mod asset_config; +pub mod governance; +pub mod xcm_config; + +pub use governance::councils::*; + +/// MOVR, the native token, uses 18 decimals of precision. +pub mod currency { + use super::Balance; + + // Provide a common factor between runtimes based on a supply of 10_000_000 tokens. + pub const SUPPLY_FACTOR: Balance = 1; + + pub const WEI: Balance = 1; + pub const KILOWEI: Balance = 1_000; + pub const MEGAWEI: Balance = 1_000_000; + pub const GIGAWEI: Balance = 1_000_000_000; + pub const MICROMOVR: Balance = 1_000_000_000_000; + pub const MILLIMOVR: Balance = 1_000_000_000_000_000; + pub const MOVR: Balance = 1_000_000_000_000_000_000; + pub const KILOMOVR: Balance = 1_000_000_000_000_000_000_000; + + pub const TRANSACTION_BYTE_FEE: Balance = 1 * GIGAWEI * SUPPLY_FACTOR; + pub const STORAGE_BYTE_FEE: Balance = 100 * MICROMOVR * SUPPLY_FACTOR; + pub const WEIGHT_FEE: Balance = 50 * KILOWEI * SUPPLY_FACTOR; + + pub const fn deposit(items: u32, bytes: u32) -> Balance { + items as Balance * 1 * MOVR * SUPPLY_FACTOR + (bytes as Balance) * STORAGE_BYTE_FEE + } +} + +/// Maximum weight per block +pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND, u64::MAX) + .saturating_div(2) + .set_proof_size(relay_chain::MAX_POV_SIZE as u64); + +pub const MILLISECS_PER_BLOCK: u64 = 12000; +pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); +pub const HOURS: BlockNumber = MINUTES * 60; +pub const DAYS: BlockNumber = HOURS * 24; +pub const WEEKS: BlockNumber = DAYS * 7; +/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know +/// the specifics of the runtime. They can then be made to be agnostic over specific formats +/// of data like extrinsics, allowing for them to continue syncing the network through upgrades +/// to even the core datastructures. +pub mod opaque { + use super::*; + + pub use sp_runtime::OpaqueExtrinsic as UncheckedExtrinsic; + pub type Block = generic::Block; + + impl_opaque_keys! { + pub struct SessionKeys { + pub nimbus: AuthorInherent, + pub vrf: session_keys_primitives::VrfSessionKey, + } + } +} + +/// This runtime version. +/// The spec_version is composed of 2x2 digits. The first 2 digits represent major changes +/// that can't be skipped, such as data migration upgrades. The last 2 digits represent minor +/// changes which can be skipped. +#[sp_version::runtime_version] +pub const VERSION: RuntimeVersion = RuntimeVersion { + spec_name: create_runtime_str!("moonriver"), + impl_name: create_runtime_str!("moonriver"), + authoring_version: 3, + spec_version: 2902, + impl_version: 0, + apis: RUNTIME_API_VERSIONS, + transaction_version: 2, + state_version: 0, +}; + +/// The version information used to identify this runtime when compiled natively. +#[cfg(feature = "std")] +pub fn native_version() -> NativeVersion { + NativeVersion { + runtime_version: VERSION, + can_author_with: Default::default(), + } +} + +const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); +pub const NORMAL_WEIGHT: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_mul(3).saturating_div(4); +// Here we assume Ethereum's base fee of 21000 gas and convert to weight, but we +// subtract roughly the cost of a balance transfer from it (about 1/3 the cost) +// and some cost to account for per-byte-fee. +// TODO: we should use benchmarking's overhead feature to measure this +pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_GAS, 0); + +pub struct RuntimeBlockWeights; +impl Get for RuntimeBlockWeights { + fn get() -> frame_system::limits::BlockWeights { + frame_system::limits::BlockWeights::builder() + .for_class(DispatchClass::Normal, |weights| { + weights.base_extrinsic = EXTRINSIC_BASE_WEIGHT; + weights.max_total = NORMAL_WEIGHT.into(); + }) + .for_class(DispatchClass::Operational, |weights| { + weights.max_total = MAXIMUM_BLOCK_WEIGHT.into(); + weights.reserved = (MAXIMUM_BLOCK_WEIGHT - NORMAL_WEIGHT).into(); + }) + .avg_block_initialization(Perbill::from_percent(10)) + .build() + .expect("Provided BlockWeight definitions are valid, qed") + } +} + +parameter_types! { + pub const Version: RuntimeVersion = VERSION; + /// We allow for 5 MB blocks. + pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength + ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO); +} + +impl frame_system::Config for Runtime { + /// The identifier used to distinguish between accounts. + type AccountId = AccountId; + /// The aggregated dispatch type that is available for extrinsics. + type RuntimeCall = RuntimeCall; + /// The lookup mechanism to get account ID from whatever is passed in dispatchers. + type Lookup = IdentityLookup; + /// The index type for storing how many extrinsics an account has signed. + type Nonce = Index; + /// The index type for blocks. + type Block = Block; + /// The hashing algorithm used. + type Hashing = BlakeTwo256; + /// The output of the `Hashing` function. + type Hash = H256; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + /// The ubiquitous origin type. + type RuntimeOrigin = RuntimeOrigin; + /// The aggregated RuntimeTask type. + type RuntimeTask = RuntimeTask; + /// Maximum number of block number to block hash mappings to keep (oldest pruned first). + type BlockHashCount = ConstU32<256>; + /// Maximum weight of each block. With a default weight system of 1byte == 1weight, 4mb is ok. + type BlockWeights = RuntimeBlockWeights; + /// Maximum size of all encoded transactions (in bytes) that are allowed in one block. + type BlockLength = BlockLength; + /// Runtime version. + type Version = Version; + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = RocksDbWeight; + type BaseCallFilter = MaintenanceMode; + type SystemWeightInfo = (); + /// This is used as an identifier of the chain. 42 is the generic substrate prefix. + type SS58Prefix = ConstU16<1285>; + type OnSetCode = cumulus_pallet_parachain_system::ParachainSetCode; + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type PalletsOrigin = OriginCaller; + type WeightInfo = moonbeam_weights::pallet_utility::WeightInfo; +} + +impl pallet_timestamp::Config for Runtime { + /// A timestamp: milliseconds since the unix epoch. + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = ConstU64<6000>; + type WeightInfo = moonbeam_weights::pallet_timestamp::WeightInfo; +} + +impl pallet_balances::Config for Runtime { + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 4]; + type MaxLocks = ConstU32<50>; + /// The type for recording an account's balance. + type Balance = Balance; + /// The ubiquitous event type. + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<0>; + type AccountStore = System; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type WeightInfo = moonbeam_weights::pallet_balances::WeightInfo; +} + +pub struct DealWithFees(sp_std::marker::PhantomData); +impl OnUnbalanced>> for DealWithFees +where + R: pallet_balances::Config + pallet_treasury::Config, +{ + // this seems to be called for substrate-based transactions + fn on_unbalanceds( + mut fees_then_tips: impl Iterator>>, + ) { + if let Some(fees) = fees_then_tips.next() { + // for fees, 80% are burned, 20% to the treasury + let (_, to_treasury) = fees.ration(80, 20); + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + + // handle tip if there is one + if let Some(tip) = fees_then_tips.next() { + // for now we use the same burn/treasury strategy used for regular fees + let (_, to_treasury) = tip.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced( + to_treasury, + ); + } + } + } + + // this is called from pallet_evm for Ethereum-based transactions + // (technically, it calls on_unbalanced, which calls this when non-zero) + fn on_nonzero_unbalanced(amount: Credit>) { + // Balances pallet automatically burns dropped Credits by decreasing + // total_supply accordingly + let (_, to_treasury) = amount.ration(80, 20); + ResolveTo::, pallet_balances::Pallet>::on_unbalanced(to_treasury); + } +} + +pub struct LengthToFee; +impl WeightToFeePolynomial for LengthToFee { + type Balance = Balance; + + fn polynomial() -> WeightToFeeCoefficients { + smallvec![ + WeightToFeeCoefficient { + degree: 1, + coeff_frac: Perbill::zero(), + coeff_integer: currency::TRANSACTION_BYTE_FEE, + negative: false, + }, + WeightToFeeCoefficient { + degree: 3, + coeff_frac: Perbill::zero(), + coeff_integer: 1 * currency::SUPPLY_FACTOR, + negative: false, + }, + ] + } +} + +impl pallet_transaction_payment::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnChargeTransaction = FungibleAdapter>; + type OperationalFeeMultiplier = ConstU8<5>; + type WeightToFee = ConstantMultiplier>; + type LengthToFee = LengthToFee; + type FeeMultiplierUpdate = SlowAdjustingFeeUpdate; +} + +impl pallet_evm_chain_id::Config for Runtime {} + +/// Current approximation of the gas/s consumption considering +/// EVM execution over compiled WASM (on 4.4Ghz CPU). +/// Given the 500ms Weight, from which 75% only are used for transactions, +/// the total EVM execution gas limit is: GAS_PER_SECOND * 0.500 * 0.75 ~= 15_000_000. +pub const GAS_PER_SECOND: u64 = 40_000_000; + +/// Approximate ratio of the amount of Weight per Gas. +/// u64 works for approximations because Weight is a very small unit compared to gas. +pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND; + +parameter_types! { + pub BlockGasLimit: U256 + = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS); + /// The portion of the `NORMAL_DISPATCH_RATIO` that we adjust the fees with. Blocks filled less + /// than this will decrease the weight and more will increase. + pub const TargetBlockFullness: Perquintill = Perquintill::from_percent(50); + /// The adjustment variable of the runtime. Higher values will cause `TargetBlockFullness` to + /// change the fees more rapidly. This low value causes changes to occur slowly over time. + pub AdjustmentVariable: Multiplier = Multiplier::saturating_from_rational(4, 1_000); + /// Minimum amount of the multiplier. This value cannot be too low. A test case should ensure + /// that combined with `AdjustmentVariable`, we can recover from the minimum. + /// See `multiplier_can_grow_from_zero` in integration_tests.rs. + /// This value is currently only used by pallet-transaction-payment as an assertion that the + /// next multiplier is always > min value. + pub MinimumMultiplier: Multiplier = Multiplier::from(1u128); + /// Maximum multiplier. We pick a value that is expensive but not impossibly so; it should act + /// as a safety net. + pub MaximumMultiplier: Multiplier = Multiplier::from(100_000u128); + pub PrecompilesValue: MoonriverPrecompiles = MoonriverPrecompiles::<_>::new(); + pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); + /// The amount of gas per pov. A ratio of 4 if we convert ref_time to gas and we compare + /// it with the pov_size for a block. E.g. + /// ceil( + /// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_PER_GAS + /// ) + /// We should re-check `xcm_config::Erc20XcmBridgeTransferGasLimit` when changing this value + pub const GasLimitPovSizeRatio: u64 = 4; + /// The amount of gas per storage (in bytes): BLOCK_GAS_LIMIT / BLOCK_STORAGE_LIMIT + /// The current definition of BLOCK_STORAGE_LIMIT is 40 KB, resulting in a value of 366. + pub GasLimitStorageGrowthRatio: u64 = 366; +} + +pub struct TransactionPaymentAsGasPrice; +impl FeeCalculator for TransactionPaymentAsGasPrice { + fn min_gas_price() -> (U256, Weight) { + // note: transaction-payment differs from EIP-1559 in that its tip and length fees are not + // scaled by the multiplier, which means its multiplier will be overstated when + // applied to an ethereum transaction + // note: transaction-payment uses both a congestion modifier (next_fee_multiplier, which is + // updated once per block in on_finalize) and a 'WeightToFee' implementation. Our + // runtime implements this as a 'ConstantModifier', so we can get away with a simple + // multiplication here. + // It is imperative that `saturating_mul_int` be performed as late as possible in the + // expression since it involves fixed point multiplication with a division by a fixed + // divisor. This leads to truncation and subsequent precision loss if performed too early. + // This can lead to min_gas_price being same across blocks even if the multiplier changes. + // There's still some precision loss when the final `gas_price` (used_gas * min_gas_price) + // is computed in frontier, but that's currently unavoidable. + let min_gas_price = TransactionPayment::next_fee_multiplier() + .saturating_mul_int(currency::WEIGHT_FEE.saturating_mul(WEIGHT_PER_GAS as u128)); + ( + min_gas_price.into(), + ::DbWeight::get().reads(1), + ) + } +} + +/// Parameterized slow adjusting fee updated based on +/// https://w3f-research.readthedocs.io/en/latest/polkadot/overview/2-token-economics.html#-2.-slow-adjusting-mechanism // editorconfig-checker-disable-line +/// +/// The adjustment algorithm boils down to: +/// +/// diff = (previous_block_weight - target) / maximum_block_weight +/// next_multiplier = prev_multiplier * (1 + (v * diff) + ((v * diff)^2 / 2)) +/// assert(next_multiplier > min) +/// where: v is AdjustmentVariable +/// target is TargetBlockFullness +/// min is MinimumMultiplier +pub type SlowAdjustingFeeUpdate = TargetedFeeAdjustment< + R, + TargetBlockFullness, + AdjustmentVariable, + MinimumMultiplier, + MaximumMultiplier, +>; + +use frame_support::traits::FindAuthor; +//TODO It feels like this shold be able to work for any T: H160, but I tried for +// embarassingly long and couldn't figure that out. + +/// The author inherent provides a AccountId20, but pallet evm needs an H160. +/// This simple adapter makes the conversion. +pub struct FindAuthorAdapter(sp_std::marker::PhantomData); + +impl FindAuthor for FindAuthorAdapter +where + Inner: FindAuthor, +{ + fn find_author<'a, I>(digests: I) -> Option + where + I: 'a + IntoIterator, + { + Inner::find_author(digests).map(Into::into) + } +} + +moonbeam_runtime_common::impl_on_charge_evm_transaction!(); + +impl pallet_evm::Config for Runtime { + type FeeCalculator = TransactionPaymentAsGasPrice; + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + type BlockHashMapping = pallet_ethereum::EthereumBlockHashMapping; + type CallOrigin = EnsureAddressRoot; + type WithdrawOrigin = EnsureAddressNever; + type AddressMapping = IdentityAddressMapping; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type Runner = pallet_evm::runner::stack::Runner; + type PrecompilesType = MoonriverPrecompiles; + type PrecompilesValue = PrecompilesValue; + type ChainId = EthereumChainId; + type OnChargeTransaction = OnChargeEVMTransaction>; + type BlockGasLimit = BlockGasLimit; + type FindAuthor = FindAuthorAdapter; + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = moonbeam_weights::pallet_evm::WeightInfo; +} + +parameter_types! { + pub MaximumSchedulerWeight: Weight = NORMAL_DISPATCH_RATIO * RuntimeBlockWeights::get().max_block; +} + +impl pallet_scheduler::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type PalletsOrigin = OriginCaller; + type RuntimeCall = RuntimeCall; + type MaximumWeight = MaximumSchedulerWeight; + type ScheduleOrigin = EnsureRoot; + type MaxScheduledPerBlock = ConstU32<50>; + type WeightInfo = moonbeam_weights::pallet_scheduler::WeightInfo; + type OriginPrivilegeCmp = EqualPrivilegeOnly; + type Preimages = Preimage; +} + +parameter_types! { + pub const PreimageBaseDeposit: Balance = 5 * currency::MOVR * currency::SUPPLY_FACTOR ; + pub const PreimageByteDeposit: Balance = currency::STORAGE_BYTE_FEE; + pub const PreimageHoldReason: RuntimeHoldReason = + RuntimeHoldReason::Preimage(pallet_preimage::HoldReason::Preimage); +} + +impl pallet_preimage::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_preimage::WeightInfo; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type ManagerOrigin = EnsureRoot; + type Consideration = HoldConsideration< + AccountId, + Balances, + PreimageHoldReason, + LinearStoragePrice, + >; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const TreasuryId: PalletId = PalletId(*b"py/trsry"); + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +type TreasuryApproveOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionAtLeast, +>; + +type TreasuryRejectOrigin = EitherOfDiverse< + EnsureRoot, + pallet_collective::EnsureProportionMoreThan, +>; + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + // At least three-fifths majority of the council is required (or root) to approve a proposal + type ApproveOrigin = TreasuryApproveOrigin; + // More than half of the council is required (or root) to reject a proposal + type RejectOrigin = TreasuryRejectOrigin; + type RuntimeEvent = RuntimeEvent; + // If spending proposal rejected, transfer proposer bond to treasury + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ConstU128<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type SpendPeriod = ConstU32<{ 6 * DAYS }>; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = ConstU32<100>; + type WeightInfo = moonbeam_weights::pallet_treasury::WeightInfo; + type SpendFunds = (); + type ProposalBondMaximum = (); + #[cfg(not(feature = "runtime-benchmarks"))] + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Disabled, no spending + #[cfg(feature = "runtime-benchmarks")] + type SpendOrigin = + frame_system::EnsureWithSuccess, AccountId, benches::MaxBalance>; + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<{ 30 * DAYS }>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = BenchmarkHelper; +} + +parameter_types! { + pub const MaxSubAccounts: u32 = 100; + pub const MaxAdditionalFields: u32 = 100; + pub const MaxRegistrars: u32 = 20; + pub const PendingUsernameExpiration: u32 = 7 * DAYS; + pub const MaxSuffixLength: u32 = 7; + pub const MaxUsernameLength: u32 = 32; +} + +type IdentityForceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type IdentityRegistrarOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_identity::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + // Add one item in storage and take 258 bytes + type BasicDeposit = ConstU128<{ currency::deposit(1, 258) }>; + // Does not add any item to the storage but takes 1 bytes + type ByteDeposit = ConstU128<{ currency::deposit(0, 1) }>; + // Add one item in storage and take 53 bytes + type SubAccountDeposit = ConstU128<{ currency::deposit(1, 53) }>; + type MaxSubAccounts = MaxSubAccounts; + type IdentityInformation = pallet_identity::legacy::IdentityInfo; + type MaxRegistrars = MaxRegistrars; + type Slashed = Treasury; + type ForceOrigin = IdentityForceOrigin; + type RegistrarOrigin = IdentityRegistrarOrigin; + type OffchainSignature = Signature; + type SigningPublicKey = ::Signer; + type UsernameAuthorityOrigin = EnsureRoot; + type PendingUsernameExpiration = PendingUsernameExpiration; + type MaxSuffixLength = MaxSuffixLength; + type MaxUsernameLength = MaxUsernameLength; + type WeightInfo = moonbeam_weights::pallet_identity::WeightInfo; +} + +pub struct TransactionConverter; + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction(&self, transaction: pallet_ethereum::Transaction) -> UncheckedExtrinsic { + UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ) + } +} + +impl fp_rpc::ConvertTransaction for TransactionConverter { + fn convert_transaction( + &self, + transaction: pallet_ethereum::Transaction, + ) -> opaque::UncheckedExtrinsic { + let extrinsic = UncheckedExtrinsic::new_unsigned( + pallet_ethereum::Call::::transact { transaction }.into(), + ); + let encoded = extrinsic.encode(); + opaque::UncheckedExtrinsic::decode(&mut &encoded[..]) + .expect("Encoded extrinsic is always valid") + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will immediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const ReservedDmpWeight: Weight = MAXIMUM_BLOCK_WEIGHT.saturating_div(4); + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +impl cumulus_pallet_parachain_system::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type OnSystemEvent = (); + type SelfParaId = ParachainInfo; + type ReservedDmpWeight = ReservedDmpWeight; + type OutboundXcmpMessageSource = XcmpQueue; + type XcmpMessageHandler = XcmpQueue; + type ReservedXcmpWeight = ReservedXcmpWeight; + type CheckAssociatedRelayNumber = cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases; + type ConsensusHook = cumulus_pallet_parachain_system::ExpectParentIncluded; + type DmpQueue = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_parachain_system::weights::SubstrateWeight; +} + +impl parachain_info::Config for Runtime {} + +pub struct OnNewRound; +impl pallet_parachain_staking::OnNewRound for OnNewRound { + fn on_new_round(round_index: pallet_parachain_staking::RoundIndex) -> Weight { + MoonbeamOrbiters::on_new_round(round_index) + } +} +pub struct PayoutCollatorOrOrbiterReward; +impl pallet_parachain_staking::PayoutCollatorReward for PayoutCollatorOrOrbiterReward { + fn payout_collator_reward( + for_round: pallet_parachain_staking::RoundIndex, + collator_id: AccountId, + amount: Balance, + ) -> Weight { + let extra_weight = + if MoonbeamOrbiters::is_collator_pool_with_active_orbiter(for_round, collator_id) { + MoonbeamOrbiters::distribute_rewards(for_round, collator_id, amount) + } else { + ParachainStaking::mint_collator_reward(for_round, collator_id, amount) + }; + + ::DbWeight::get() + .reads(1) + .saturating_add(extra_weight) + } +} + +pub struct OnInactiveCollator; +impl pallet_parachain_staking::OnInactiveCollator for OnInactiveCollator { + fn on_inactive_collator( + collator_id: AccountId, + round: pallet_parachain_staking::RoundIndex, + ) -> Result> { + let extra_weight = if !MoonbeamOrbiters::is_collator_pool_with_active_orbiter( + round, + collator_id.clone(), + ) { + ParachainStaking::go_offline_inner(collator_id)?; + ::WeightInfo::go_offline( + pallet_parachain_staking::MAX_CANDIDATES, + ) + } else { + Weight::zero() + }; + + Ok(::DbWeight::get() + .reads(1) + .saturating_add(extra_weight)) + } +} + +type MonetaryGovernanceOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +/// TODO: +/// Temporary type that we should replace by RelayChainSlotProvider once async backing is enabled. +pub struct StakingRoundSlotProvider; +impl Get for StakingRoundSlotProvider { + fn get() -> Slot { + let block_number: u64 = frame_system::pallet::Pallet::::block_number().into(); + Slot::from(block_number) + } +} + +impl pallet_parachain_staking::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MonetaryGovernanceOrigin = MonetaryGovernanceOrigin; + /// Minimum round length is 2 minutes (10 * 12 second block times) + type MinBlocksPerRound = ConstU32<10>; + /// If a collator doesn't produce any block on this number of rounds, it is notified as inactive + type MaxOfflineRounds = ConstU32<2>; + /// Rounds before the collator leaving the candidates request can be executed + type LeaveCandidatesDelay = ConstU32<24>; + /// Rounds before the candidate bond increase/decrease can be executed + type CandidateBondLessDelay = ConstU32<24>; + /// Rounds before the delegator exit can be executed + type LeaveDelegatorsDelay = ConstU32<24>; + /// Rounds before the delegator revocation can be executed + type RevokeDelegationDelay = ConstU32<24>; + /// Rounds before the delegator bond increase/decrease can be executed + type DelegationBondLessDelay = ConstU32<24>; + /// Rounds before the reward is paid + type RewardPaymentDelay = ConstU32<2>; + /// Minimum collators selected per round, default at genesis and minimum forever after + type MinSelectedCandidates = ConstU32<8>; + /// Maximum top delegations per candidate + type MaxTopDelegationsPerCandidate = ConstU32<300>; + /// Maximum bottom delegations per candidate + type MaxBottomDelegationsPerCandidate = ConstU32<50>; + /// Maximum delegations per delegator + type MaxDelegationsPerDelegator = ConstU32<100>; + /// Minimum stake required to be reserved to be a candidate + type MinCandidateStk = ConstU128<{ 500 * currency::MOVR * currency::SUPPLY_FACTOR }>; + /// Minimum stake required to be reserved to be a delegator + type MinDelegation = ConstU128<{ 5 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type BlockAuthor = AuthorInherent; + type OnCollatorPayout = (); + type PayoutCollatorReward = PayoutCollatorOrOrbiterReward; + type OnInactiveCollator = OnInactiveCollator; + type OnNewRound = OnNewRound; + type SlotProvider = StakingRoundSlotProvider; + type WeightInfo = moonbeam_weights::pallet_parachain_staking::WeightInfo; + type MaxCandidates = ConstU32<200>; + type SlotDuration = ConstU64<12_000>; + type BlockTime = ConstU64<12_000>; +} + +impl pallet_author_inherent::Config for Runtime { + type SlotBeacon = RelaychainDataProvider; + type AccountLookup = MoonbeamOrbiters; + type CanAuthor = AuthorFilter; + type AuthorId = AccountId; + type WeightInfo = moonbeam_weights::pallet_author_inherent::WeightInfo; +} + +impl pallet_author_slot_filter::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RandomnessSource = Randomness; + type PotentialAuthors = ParachainStaking; + type WeightInfo = moonbeam_weights::pallet_author_slot_filter::WeightInfo; +} + +parameter_types! { + pub const InitializationPayment: Perbill = Perbill::from_percent(30); + pub const RelaySignaturesThreshold: Perbill = Perbill::from_percent(100); + pub const SignatureNetworkIdentifier: &'static [u8] = b"moonriver-"; + +} + +impl pallet_crowdloan_rewards::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Initialized = ConstBool; + type InitializationPayment = InitializationPayment; + type MaxInitContributors = ConstU32<500>; + type MinimumReward = ConstU128<0>; + type RewardCurrency = Balances; + type RelayChainAccountId = [u8; 32]; + type RewardAddressAssociateOrigin = EnsureSigned; + type RewardAddressChangeOrigin = EnsureSigned; + type RewardAddressRelayVoteThreshold = RelaySignaturesThreshold; + type SignatureNetworkIdentifier = SignatureNetworkIdentifier; + type VestingBlockNumber = relay_chain::BlockNumber; + type VestingBlockProvider = RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_crowdloan_rewards::WeightInfo; +} + +// This is a simple session key manager. It should probably either work with, or be replaced +// entirely by pallet sessions +impl pallet_author_mapping::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DepositCurrency = Balances; + type DepositAmount = ConstU128<{ 100 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type Keys = session_keys_primitives::VrfId; + type WeightInfo = moonbeam_weights::pallet_author_mapping::WeightInfo; +} + +/// The type used to represent the kinds of proxying allowed. +#[derive( + Copy, + Clone, + Eq, + PartialEq, + Ord, + PartialOrd, + Encode, + Decode, + Debug, + MaxEncodedLen, + TypeInfo, + Serialize, + Deserialize, +)] +pub enum ProxyType { + /// All calls can be proxied. This is the trivial/most permissive filter. + Any = 0, + /// Only extrinsics that do not transfer funds. + NonTransfer = 1, + /// Only extrinsics related to governance (democracy and collectives). + Governance = 2, + /// Only extrinsics related to staking. + Staking = 3, + /// Allow to veto an announced proxy call. + CancelProxy = 4, + /// Allow extrinsic related to Balances. + Balances = 5, + /// Allow extrinsic related to AuthorMapping. + AuthorMapping = 6, + /// Allow extrinsic related to IdentityJudgement. + IdentityJudgement = 7, +} + +impl Default for ProxyType { + fn default() -> Self { + Self::Any + } +} + +fn is_governance_precompile(precompile_name: &precompiles::PrecompileName) -> bool { + matches!( + precompile_name, + PrecompileName::TreasuryCouncilInstance + | PrecompileName::PreimagePrecompile + | PrecompileName::ReferendaPrecompile + | PrecompileName::ConvictionVotingPrecompile + | PrecompileName::OpenTechCommitteeInstance + ) +} + +// Be careful: Each time this filter is modified, the substrate filter must also be modified +// consistently. +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType { + fn is_evm_proxy_call_allowed( + &self, + call: &pallet_evm_precompile_proxy::EvmSubCall, + recipient_has_code: bool, + gas: u64, + ) -> precompile_utils::EvmResult { + Ok(match self { + ProxyType::Any => { + match PrecompileName::from_address(call.to.0) { + // Any precompile that can execute a subcall should be forbidden here, + // to ensure that unauthorized smart contract can't be called + // indirectly. + // To be safe, we only allow the precompiles we need. + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + // All non-whitelisted precompiles are forbidden + Some(_) => false, + // Allow evm transfer to "simple" account (no code nor precompile) + // For the moment, no smart contract other than precompiles is allowed. + // In the future, we may create a dynamic whitelist to authorize some audited + // smart contracts through governance. + None => { + // If the address is not recognized, allow only evm transfert to "simple" + // accounts (no code nor precompile). + // Note: Checking the presence of the code is not enough because some + // precompiles have no code. + !recipient_has_code + && !precompile_utils::precompile_set::is_precompile_or_fail::( + call.to.0, gas, + )? + } + } + } + ProxyType::NonTransfer => { + call.value == U256::zero() + && match PrecompileName::from_address(call.to.0) { + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile, + ) => true, + Some(ref precompile) if is_governance_precompile(precompile) => true, + _ => false, + } + } + ProxyType::Governance => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(ref precompile) if is_governance_precompile(precompile) + ) + } + ProxyType::Staking => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some( + PrecompileName::AuthorMappingPrecompile + | PrecompileName::ParachainStakingPrecompile + ) + ) + } + // The proxy precompile does not contain method cancel_proxy + ProxyType::CancelProxy => false, + ProxyType::Balances => { + // Allow only "simple" accounts as recipient (no code nor precompile). + // Note: Checking the presence of the code is not enough because some precompiles + // have no code. + !recipient_has_code + && !precompile_utils::precompile_set::is_precompile_or_fail::( + call.to.0, gas, + )? + } + ProxyType::AuthorMapping => { + call.value == U256::zero() + && matches!( + PrecompileName::from_address(call.to.0), + Some(PrecompileName::AuthorMappingPrecompile) + ) + } + // There is no identity precompile + ProxyType::IdentityJudgement => false, + }) + } +} + +// Be careful: Each time this filter is modified, the EVM filter must also be modified consistently. +impl InstanceFilter for ProxyType { + fn filter(&self, c: &RuntimeCall) -> bool { + match self { + ProxyType::Any => true, + ProxyType::NonTransfer => { + matches!( + c, + RuntimeCall::System(..) + | RuntimeCall::ParachainSystem(..) + | RuntimeCall::Timestamp(..) + | RuntimeCall::ParachainStaking(..) + | RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Identity(..) + | RuntimeCall::Utility(..) + | RuntimeCall::Proxy(..) | RuntimeCall::AuthorMapping(..) + | RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::claim { .. } + ) + ) + } + ProxyType::Governance => matches!( + c, + RuntimeCall::Referenda(..) + | RuntimeCall::Preimage(..) + | RuntimeCall::ConvictionVoting(..) + | RuntimeCall::TreasuryCouncilCollective(..) + | RuntimeCall::OpenTechCommitteeCollective(..) + | RuntimeCall::Utility(..) + ), + ProxyType::Staking => matches!( + c, + RuntimeCall::ParachainStaking(..) + | RuntimeCall::Utility(..) + | RuntimeCall::AuthorMapping(..) + | RuntimeCall::MoonbeamOrbiters(..) + ), + ProxyType::CancelProxy => matches!( + c, + RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }) + ), + ProxyType::Balances => { + matches!(c, RuntimeCall::Balances(..) | RuntimeCall::Utility(..)) + } + ProxyType::AuthorMapping => matches!(c, RuntimeCall::AuthorMapping(..)), + ProxyType::IdentityJudgement => matches!( + c, + RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) + | RuntimeCall::Utility(..) + ), + } + } + + fn is_superset(&self, o: &Self) -> bool { + match (self, o) { + (x, y) if x == y => true, + (ProxyType::Any, _) => true, + (_, ProxyType::Any) => false, + _ => false, + } + } +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + // One storage item; key size 32, value size 8 + type ProxyDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 21 bytes (20 bytes AccountId + 1 byte sizeof(ProxyType)). + type ProxyDepositFactor = ConstU128<{ currency::deposit(0, 21) }>; + type MaxProxies = ConstU32<32>; + type WeightInfo = moonbeam_weights::pallet_proxy::WeightInfo; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ConstU128<{ currency::deposit(1, 8) }>; + // Additional storage item size of 56 bytes: + // - 20 bytes AccountId + // - 32 bytes Hasher (Blake2256) + // - 4 bytes BlockNumber (u32) + type AnnouncementDepositFactor = ConstU128<{ currency::deposit(0, 56) }>; +} + +impl pallet_migrations::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MigrationsList = (moonbeam_runtime_common::migrations::CommonMigrations,); + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_moonbeam_lazy_migrations::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_moonbeam_lazy_migrations::WeightInfo; +} + +/// Maintenance mode Call filter +pub struct MaintenanceFilter; +impl Contains for MaintenanceFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(_) => false, + RuntimeCall::Balances(_) => false, + RuntimeCall::CrowdloanRewards(_) => false, + RuntimeCall::Ethereum(_) => false, + RuntimeCall::EVM(_) => false, + RuntimeCall::Identity(_) => false, + RuntimeCall::XTokens(_) => false, + RuntimeCall::ParachainStaking(_) => false, + RuntimeCall::MoonbeamOrbiters(_) => false, + RuntimeCall::PolkadotXcm(_) => false, + RuntimeCall::Treasury(_) => false, + RuntimeCall::XcmTransactor(_) => false, + RuntimeCall::EthereumXcm(_) => false, + _ => true, + } + } +} + +/// Normal Call Filter +/// We dont allow to create nor mint assets, this for now is disabled +/// We only allow transfers. For now creation of assets will go through +/// asset-manager, while minting/burning only happens through xcm messages +/// This can change in the future +pub struct NormalFilter; +impl Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + RuntimeCall::Assets(method) => match method { + pallet_assets::Call::transfer { .. } => true, + pallet_assets::Call::transfer_keep_alive { .. } => true, + pallet_assets::Call::approve_transfer { .. } => true, + pallet_assets::Call::transfer_approved { .. } => true, + pallet_assets::Call::cancel_approval { .. } => true, + pallet_assets::Call::destroy_accounts { .. } => true, + pallet_assets::Call::destroy_approvals { .. } => true, + pallet_assets::Call::finish_destroy { .. } => true, + _ => false, + }, + // We just want to enable this in case of live chains, since the default version + // is populated at genesis + RuntimeCall::PolkadotXcm(method) => match method { + pallet_xcm::Call::force_default_xcm_version { .. } => true, + _ => false, + }, + // We filter anonymous proxy as they make "reserve" inconsistent + // See: https://github.com/paritytech/substrate/blob/37cca710eed3dadd4ed5364c7686608f5175cce1/frame/proxy/src/lib.rs#L270 // editorconfig-checker-disable-line + RuntimeCall::Proxy(method) => match method { + pallet_proxy::Call::create_pure { .. } => false, + pallet_proxy::Call::kill_pure { .. } => false, + pallet_proxy::Call::proxy { real, .. } => { + !pallet_evm::AccountCodes::::contains_key(H160::from(*real)) + } + _ => true, + }, + // Filtering the EVM prevents possible re-entrancy from the precompiles which could + // lead to unexpected scenarios. + // See https://github.com/PureStake/sr-moonbeam/issues/30 + // Note: It is also assumed that EVM calls are only allowed through `Origin::Root` so + // this can be seen as an additional security + RuntimeCall::EVM(_) => false, + RuntimeCall::Treasury( + pallet_treasury::Call::spend { .. } + | pallet_treasury::Call::payout { .. } + | pallet_treasury::Call::check_status { .. } + | pallet_treasury::Call::void_spend { .. }, + ) => false, + _ => true, + } + } +} + +pub struct XcmExecutionManager; +impl moonkit_xcm_primitives::PauseXcmExecution for XcmExecutionManager { + fn suspend_xcm_execution() -> DispatchResult { + XcmpQueue::suspend_xcm_execution(RuntimeOrigin::root()) + } + fn resume_xcm_execution() -> DispatchResult { + XcmpQueue::resume_xcm_execution(RuntimeOrigin::root()) + } +} + +impl pallet_maintenance_mode::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type NormalCallFilter = NormalFilter; + type MaintenanceCallFilter = MaintenanceFilter; + type MaintenanceOrigin = + pallet_collective::EnsureProportionAtLeast; + type XcmExecutionManager = XcmExecutionManager; +} + +impl pallet_proxy_genesis_companion::Config for Runtime { + type ProxyType = ProxyType; +} + +parameter_types! { + pub OrbiterReserveIdentifier: [u8; 4] = [b'o', b'r', b'b', b'i']; +} + +type AddCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; +type DelCollatorOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_moonbeam_orbiters::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AccountLookup = AuthorMapping; + type AddCollatorOrigin = AddCollatorOrigin; + type Currency = Balances; + type DelCollatorOrigin = DelCollatorOrigin; + /// Maximum number of orbiters per collator + type MaxPoolSize = ConstU32<8>; + /// Maximum number of round to keep on storage + type MaxRoundArchive = ConstU32<4>; + type OrbiterReserveIdentifier = OrbiterReserveIdentifier; + type RotatePeriod = ConstU32<3>; + /// Round index type. + type RoundIndex = pallet_parachain_staking::RoundIndex; + type WeightInfo = moonbeam_weights::pallet_moonbeam_orbiters::WeightInfo; +} + +/// Only callable after `set_validation_data` is called which forms this proof the same way +fn relay_chain_state_proof() -> RelayChainStateProof { + let relay_storage_root = ParachainSystem::validation_data() + .expect("set in `set_validation_data`") + .relay_parent_storage_root; + let relay_chain_state = + ParachainSystem::relay_state_proof().expect("set in `set_validation_data`"); + RelayChainStateProof::new(ParachainInfo::get(), relay_storage_root, relay_chain_state) + .expect("Invalid relay chain state proof, already constructed in `set_validation_data`") +} + +pub struct BabeDataGetter; +impl pallet_randomness::GetBabeData> for BabeDataGetter { + // Tolerate panic here because only ever called in inherent (so can be omitted) + fn get_epoch_index() -> u64 { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + const BENCHMARKING_NEW_EPOCH: u64 = 10u64; + return BENCHMARKING_NEW_EPOCH; + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::EPOCH_INDEX) + .ok() + .flatten() + .expect("expected to be able to read epoch index from relay chain state proof") + } + fn get_epoch_randomness() -> Option { + if cfg!(feature = "runtime-benchmarks") { + // storage reads as per actual reads + let _relay_storage_root = ParachainSystem::validation_data(); + let _relay_chain_state = ParachainSystem::relay_state_proof(); + let benchmarking_babe_output = Hash::default(); + return Some(benchmarking_babe_output); + } + relay_chain_state_proof() + .read_optional_entry(relay_chain::well_known_keys::ONE_EPOCH_AGO_RANDOMNESS) + .ok() + .flatten() + } +} + +impl pallet_randomness::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type AddressMapping = sp_runtime::traits::ConvertInto; + type Currency = Balances; + type BabeDataGetter = BabeDataGetter; + type VrfKeyLookup = AuthorMapping; + type Deposit = ConstU128<{ 1 * currency::MOVR * currency::SUPPLY_FACTOR }>; + type MaxRandomWords = ConstU8<100>; + type MinBlockDelay = ConstU32<2>; + type MaxBlockDelay = ConstU32<2_000>; + type BlockExpirationDelay = ConstU32<10_000>; + type EpochExpirationDelay = ConstU64<10_000>; + type WeightInfo = moonbeam_weights::pallet_randomness::WeightInfo; +} + +impl pallet_root_testing::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +parameter_types! { + // One storage item; key size is 32 + 20; value is size 4+4+16+20 bytes = 44 bytes. + pub const DepositBase: Balance = currency::deposit(1, 96); + // Additional storage item size of 20 bytes. + pub const DepositFactor: Balance = currency::deposit(0, 20); + pub const MaxSignatories: u32 = 100; +} + +impl pallet_multisig::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type DepositBase = DepositBase; + type DepositFactor = DepositFactor; + type MaxSignatories = MaxSignatories; + type WeightInfo = moonbeam_weights::pallet_multisig::WeightInfo; +} + +impl pallet_relay_storage_roots::Config for Runtime { + type MaxStorageRoots = ConstU32<30>; + type RelaychainStateProvider = cumulus_pallet_parachain_system::RelaychainDataProvider; + type WeightInfo = moonbeam_weights::pallet_relay_storage_roots::WeightInfo; +} + +impl pallet_precompile_benchmarks::Config for Runtime { + type WeightInfo = moonbeam_weights::pallet_precompile_benchmarks::WeightInfo; +} + +construct_runtime! { + pub enum Runtime + { + // System support stuff. + System: frame_system::{Pallet, Call, Storage, Config, Event} = 0, + ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Storage, Inherent, Event} = 1, + // Previously 2: pallet_randomness_collective_flip + Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 3, + ParachainInfo: parachain_info::{Pallet, Storage, Config} = 4, + RootTesting: pallet_root_testing::{Pallet, Call, Storage, Event} = 5, + + // Monetary stuff. + Balances: pallet_balances::{Pallet, Call, Storage, Config, Event} = 10, + TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Config, Event} = 11, + + // Consensus support. + ParachainStaking: pallet_parachain_staking::{Pallet, Call, Storage, Event, Config} = 20, + AuthorInherent: pallet_author_inherent::{Pallet, Call, Storage, Inherent} = 21, + AuthorFilter: pallet_author_slot_filter::{Pallet, Call, Storage, Event, Config} = 22, + AuthorMapping: pallet_author_mapping::{Pallet, Call, Config, Storage, Event} = 23, + MoonbeamOrbiters: pallet_moonbeam_orbiters::{Pallet, Call, Storage, Event} = 24, + + // Handy utilities. + Utility: pallet_utility::{Pallet, Call, Event} = 30, + Proxy: pallet_proxy::{Pallet, Call, Storage, Event} = 31, + MaintenanceMode: pallet_maintenance_mode::{Pallet, Call, Config, Storage, Event} = 32, + Identity: pallet_identity::{Pallet, Call, Storage, Event} = 33, + Migrations: pallet_migrations::{Pallet, Storage, Config, Event} = 34, + ProxyGenesisCompanion: pallet_proxy_genesis_companion::{Pallet, Config} = 35, + Multisig: pallet_multisig::{Pallet, Call, Storage, Event} = 36, + MoonbeamLazyMigrations: pallet_moonbeam_lazy_migrations::{Pallet, Call, Storage} = 37, + + // Sudo was previously index 40 + + // Ethereum compatibility + EthereumChainId: pallet_evm_chain_id::{Pallet, Storage, Config} = 50, + EVM: pallet_evm::{Pallet, Config, Call, Storage, Event} = 51, + Ethereum: pallet_ethereum::{Pallet, Call, Storage, Event, Origin, Config} = 52, + + // Governance stuff. + Scheduler: pallet_scheduler::{Pallet, Storage, Event, Call} = 60, + // Democracy: 61, + Preimage: pallet_preimage::{Pallet, Call, Storage, Event, HoldReason} = 62, + ConvictionVoting: pallet_conviction_voting::{Pallet, Call, Storage, Event} = 63, + Referenda: pallet_referenda::{Pallet, Call, Storage, Event} = 64, + Origins: governance::custom_origins::{Origin} = 65, + Whitelist: pallet_whitelist::{Pallet, Call, Storage, Event} = 66, + + // Council stuff. + // CouncilCollective: 70 + // TechCommitteeCollective: 71, + TreasuryCouncilCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 72, + OpenTechCommitteeCollective: + pallet_collective::::{Pallet, Call, Storage, Event, Origin, Config} = 73, + + // Treasury stuff. + Treasury: pallet_treasury::{Pallet, Storage, Config, Event, Call} = 80, + + // Crowdloan stuff. + CrowdloanRewards: pallet_crowdloan_rewards::{Pallet, Call, Config, Storage, Event} = 90, + + // XCM Stuff + XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Storage, Event} = 100, + CumulusXcm: cumulus_pallet_xcm::{Pallet, Event, Origin} = 101, + DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event} = 102, + PolkadotXcm: pallet_xcm::{Pallet, Storage, Call, Event, Origin, Config} = 103, + Assets: pallet_assets::{Pallet, Call, Storage, Event} = 104, + AssetManager: pallet_asset_manager::{Pallet, Call, Storage, Event} = 105, + XTokens: orml_xtokens::{Pallet, Call, Storage, Event} = 106, + XcmTransactor: pallet_xcm_transactor::{Pallet, Call, Storage, Event} = 107, + // Previously 108: pallet_assets:: + EthereumXcm: pallet_ethereum_xcm::{Pallet, Call, Storage, Origin} = 109, + Erc20XcmBridge: pallet_erc20_xcm_bridge::{Pallet} = 110, + MessageQueue: pallet_message_queue::{Pallet, Call, Storage, Event} = 111, + RelayStorageRoots: pallet_relay_storage_roots::{Pallet, Storage} = 112, + PrecompileBenchmarks: pallet_precompile_benchmarks::{Pallet} = 113, + + // Randomness + Randomness: pallet_randomness::{Pallet, Call, Storage, Event, Inherent} = 120, + } +} + +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper; +#[cfg(feature = "runtime-benchmarks")] +mod benches { + frame_support::parameter_types! { + pub const MaxBalance: crate::Balance = crate::Balance::max_value(); + } + + frame_benchmarking::define_benchmarks!( + [pallet_utility, Utility] + [pallet_timestamp, Timestamp] + [pallet_balances, Balances] + [pallet_evm, EVM] + [pallet_assets, Assets] + [pallet_parachain_staking, ParachainStaking] + [pallet_scheduler, Scheduler] + [pallet_treasury, Treasury] + [pallet_author_inherent, AuthorInherent] + [pallet_author_slot_filter, AuthorFilter] + [pallet_crowdloan_rewards, CrowdloanRewards] + [pallet_author_mapping, AuthorMapping] + [pallet_proxy, Proxy] + [pallet_identity, Identity] + [cumulus_pallet_xcmp_queue, XcmpQueue] + [pallet_xcm, PalletXcmExtrinsiscsBenchmark::] + [pallet_asset_manager, AssetManager] + [pallet_xcm_transactor, XcmTransactor] + [pallet_moonbeam_orbiters, MoonbeamOrbiters] + [pallet_randomness, Randomness] + [pallet_conviction_voting, ConvictionVoting] + [pallet_referenda, Referenda] + [pallet_preimage, Preimage] + [pallet_whitelist, Whitelist] + [pallet_multisig, Multisig] + [pallet_moonbeam_lazy_migrations, MoonbeamLazyMigrations] + [pallet_relay_storage_roots, RelayStorageRoots] + ); +} + +/// Block type as expected by this runtime. +pub type Block = generic::Block; +/// A Block signed with a Justification +pub type SignedBlock = generic::SignedBlock; +/// BlockId type as expected by this runtime. +pub type BlockId = generic::BlockId; + +/// The SignedExtension to the basic transaction logic. +pub type SignedExtra = ( + frame_system::CheckNonZeroSender, + frame_system::CheckSpecVersion, + frame_system::CheckTxVersion, + frame_system::CheckGenesis, + frame_system::CheckEra, + frame_system::CheckNonce, + frame_system::CheckWeight, + pallet_transaction_payment::ChargeTransactionPayment, +); +/// Unchecked extrinsic type as expected by this runtime. +pub type UncheckedExtrinsic = + fp_self_contained::UncheckedExtrinsic; +/// Extrinsic type that has already been checked. +pub type CheckedExtrinsic = + fp_self_contained::CheckedExtrinsic; +/// Executive: handles dispatch to the various pallets. +pub type Executive = frame_executive::Executive< + Runtime, + Block, + frame_system::ChainContext, + Runtime, + AllPalletsWithSystem, +>; + +// All of our runtimes share most of their Runtime API implementations. +// We use a macro to implement this common part and add runtime-specific additional implementations. +// This macro expands to : +// ``` +// impl_runtime_apis! { +// // All impl blocks shared between all runtimes. +// +// // Specific impls provided to the `impl_runtime_apis_plus_common!` macro. +// } +// ``` +moonbeam_runtime_common::impl_runtime_apis_plus_common! { + impl sp_transaction_pool::runtime_api::TaggedTransactionQueue for Runtime { + fn validate_transaction( + source: TransactionSource, + xt: ::Extrinsic, + block_hash: ::Hash, + ) -> TransactionValidity { + // Filtered calls should not enter the tx pool as they'll fail if inserted. + // If this call is not allowed, we return early. + if !::BaseCallFilter::contains(&xt.0.function) { + return InvalidTransaction::Call.into(); + } + + // This runtime uses Substrate's pallet transaction payment. This + // makes the chain feel like a standard Substrate chain when submitting + // frame transactions and using Substrate ecosystem tools. It has the downside that + // transaction are not prioritized by gas_price. The following code reprioritizes + // transactions to overcome this. + // + // A more elegant, ethereum-first solution is + // a pallet that replaces pallet transaction payment, and allows users + // to directly specify a gas price rather than computing an effective one. + // #HopefullySomeday + + // First we pass the transactions to the standard FRAME executive. This calculates all the + // necessary tags, longevity and other properties that we will leave unchanged. + // This also assigns some priority that we don't care about and will overwrite next. + let mut intermediate_valid = Executive::validate_transaction(source, xt.clone(), block_hash)?; + + let dispatch_info = xt.get_dispatch_info(); + + // If this is a pallet ethereum transaction, then its priority is already set + // according to gas price from pallet ethereum. If it is any other kind of transaction, + // we modify its priority. + Ok(match &xt.0.function { + RuntimeCall::Ethereum(transact { .. }) => intermediate_valid, + _ if dispatch_info.class != DispatchClass::Normal => intermediate_valid, + _ => { + let tip = match xt.0.signature { + None => 0, + Some((_, _, ref signed_extra)) => { + // Yuck, this depends on the index of charge transaction in Signed Extra + let charge_transaction = &signed_extra.7; + charge_transaction.tip() + } + }; + + // Calculate the fee that will be taken by pallet transaction payment + let fee: u64 = TransactionPayment::compute_fee( + xt.encode().len() as u32, + &dispatch_info, + tip, + ).saturated_into(); + + // Calculate how much gas this effectively uses according to the existing mapping + let effective_gas = + ::GasWeightMapping::weight_to_gas( + dispatch_info.weight + ); + + // Here we calculate an ethereum-style effective gas price using the + // current fee of the transaction. Because the weight -> gas conversion is + // lossy, we have to handle the case where a very low weight maps to zero gas. + let effective_gas_price = if effective_gas > 0 { + fee / effective_gas + } else { + // If the effective gas was zero, we just act like it was 1. + fee + }; + + // Overwrite the original prioritization with this ethereum one + intermediate_valid.priority = effective_gas_price; + intermediate_valid + } + }) + } + } + + impl async_backing_primitives::UnincludedSegmentApi for Runtime { + fn can_build_upon( + _included_hash: ::Hash, + _slot: async_backing_primitives::Slot, + ) -> bool { + // This runtime API can be called only when asynchronous backing is enabled client-side + // We return false here to force the client to not use async backing in moonriver. + false + } + } +} + +struct CheckInherents; + +// Parity has decided to depreciate this trait, but does not offer a satisfactory replacement, +// see issue: https://github.com/paritytech/polkadot-sdk/issues/2841 +#[allow(deprecated)] +impl cumulus_pallet_parachain_system::CheckInherents for CheckInherents { + fn check_inherents( + block: &Block, + relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof, + ) -> sp_inherents::CheckInherentsResult { + let relay_chain_slot = relay_state_proof + .read_slot() + .expect("Could not read the relay chain slot from the proof"); + let inherent_data = + cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration( + relay_chain_slot, + sp_std::time::Duration::from_secs(6), + ) + .create_inherent_data() + .expect("Could not create the timestamp inherent data"); + inherent_data.check_extrinsics(block) + } +} + +// Nimbus's Executive wrapper allows relay validators to verify the seal digest +cumulus_pallet_parachain_system::register_validate_block!( + Runtime = Runtime, + BlockExecutor = pallet_author_inherent::BlockExecutor::, + CheckInherents = CheckInherents, +); + +moonbeam_runtime_common::impl_self_contained_call!(); + +// Shorthand for a Get field of a pallet Config. +#[macro_export] +macro_rules! get { + ($pallet:ident, $name:ident, $type:ty) => { + <<$crate::Runtime as $pallet::Config>::$name as $crate::Get<$type>>::get() + }; +} + +#[cfg(test)] +mod tests { + use super::{currency::*, *}; + + #[test] + // Helps us to identify a Pallet Call in case it exceeds the 1kb limit. + // Hint: this should be a rare case. If that happens, one or more of the dispatchable arguments + // need to be Boxed. + fn call_max_size() { + const CALL_ALIGN: u32 = 1024; + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() <= CALL_ALIGN as usize + ); + assert!(std::mem::size_of::>() <= CALL_ALIGN as usize); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + assert!( + std::mem::size_of::>() + <= CALL_ALIGN as usize + ); + } + + #[test] + fn currency_constants_are_correct() { + assert_eq!(SUPPLY_FACTOR, 1); + + // txn fees + assert_eq!(TRANSACTION_BYTE_FEE, Balance::from(1 * GIGAWEI)); + assert_eq!( + get!(pallet_transaction_payment, OperationalFeeMultiplier, u8), + 5_u8 + ); + assert_eq!(STORAGE_BYTE_FEE, Balance::from(100 * MICROMOVR)); + + // treasury minimums + assert_eq!( + get!(pallet_treasury, ProposalBondMinimum, u128), + Balance::from(1 * MOVR) + ); + + // pallet_identity deposits + assert_eq!( + get!(pallet_identity, BasicDeposit, u128), + Balance::from(1 * MOVR + 25800 * MICROMOVR) + ); + assert_eq!( + get!(pallet_identity, ByteDeposit, u128), + Balance::from(100 * MICROMOVR) + ); + assert_eq!( + get!(pallet_identity, SubAccountDeposit, u128), + Balance::from(1 * MOVR + 5300 * MICROMOVR) + ); + + // staking minimums + assert_eq!( + get!(pallet_parachain_staking, MinCandidateStk, u128), + Balance::from(500 * MOVR) + ); + assert_eq!( + get!(pallet_parachain_staking, MinDelegation, u128), + Balance::from(5 * MOVR) + ); + + // crowdloan min reward + assert_eq!( + get!(pallet_crowdloan_rewards, MinimumReward, u128), + Balance::from(0u128) + ); + + // deposit for AuthorMapping + assert_eq!( + get!(pallet_author_mapping, DepositAmount, u128), + Balance::from(100 * MOVR) + ); + + // proxy deposits + assert_eq!( + get!(pallet_proxy, ProxyDepositBase, u128), + Balance::from(1 * MOVR + 800 * MICROMOVR) + ); + assert_eq!( + get!(pallet_proxy, ProxyDepositFactor, u128), + Balance::from(2100 * MICROMOVR) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositBase, u128), + Balance::from(1 * MOVR + 800 * MICROMOVR) + ); + assert_eq!( + get!(pallet_proxy, AnnouncementDepositFactor, u128), + Balance::from(5600 * MICROMOVR) + ); + } + + #[test] + fn max_offline_rounds_lower_or_eq_than_reward_payment_delay() { + assert!( + get!(pallet_parachain_staking, MaxOfflineRounds, u32) + <= get!(pallet_parachain_staking, RewardPaymentDelay, u32) + ); + } + + #[test] + // Required migration is + // pallet_parachain_staking::migrations::IncreaseMaxTopDelegationsPerCandidate + // Purpose of this test is to remind of required migration if constant is ever changed + fn updating_maximum_delegators_per_candidate_requires_configuring_required_migration() { + assert_eq!( + get!(pallet_parachain_staking, MaxTopDelegationsPerCandidate, u32), + 300 + ); + assert_eq!( + get!( + pallet_parachain_staking, + MaxBottomDelegationsPerCandidate, + u32 + ), + 50 + ); + } + + #[test] + fn configured_base_extrinsic_weight_is_evm_compatible() { + let min_ethereum_transaction_weight = WeightPerGas::get() * 21_000; + let base_extrinsic = ::BlockWeights::get() + .get(frame_support::dispatch::DispatchClass::Normal) + .base_extrinsic; + assert!(base_extrinsic.ref_time() <= min_ethereum_transaction_weight.ref_time()); + } + + #[test] + fn test_storage_growth_ratio_is_correct() { + // This is the highest amount of new storage that can be created in a block 40 KB + let block_storage_limit = 40 * 1024; + let expected_storage_growth_ratio = BlockGasLimit::get() + .low_u64() + .saturating_div(block_storage_limit); + let actual_storage_growth_ratio = + ::GasLimitStorageGrowthRatio::get(); + assert_eq!( + expected_storage_growth_ratio, actual_storage_growth_ratio, + "Storage growth ratio is not correct" + ); + } +} diff --git a/tracing/2902/runtime/moonriver/src/precompiles.rs b/tracing/2902/runtime/moonriver/src/precompiles.rs new file mode 100644 index 00000000..6af007a2 --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/precompiles.rs @@ -0,0 +1,259 @@ +// 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::{ + asset_config::ForeignAssetInstance, xcm_config::XcmExecutorConfig, OpenTechCommitteeInstance, + TreasuryCouncilInstance, +}; +use frame_support::parameter_types; +use pallet_evm_precompile_author_mapping::AuthorMappingPrecompile; +use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata}; +use pallet_evm_precompile_batch::BatchPrecompile; +use pallet_evm_precompile_blake2::Blake2F; +use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; +use pallet_evm_precompile_call_permit::CallPermitPrecompile; +use pallet_evm_precompile_collective::CollectivePrecompile; +use pallet_evm_precompile_conviction_voting::ConvictionVotingPrecompile; +use pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompile; +use pallet_evm_precompile_gmp::GmpPrecompile; +use pallet_evm_precompile_identity::IdentityPrecompile; +use pallet_evm_precompile_modexp::Modexp; +use pallet_evm_precompile_parachain_staking::ParachainStakingPrecompile; +use pallet_evm_precompile_preimage::PreimagePrecompile; +use pallet_evm_precompile_proxy::{OnlyIsProxyAndProxy, ProxyPrecompile}; +use pallet_evm_precompile_randomness::RandomnessPrecompile; +use pallet_evm_precompile_referenda::ReferendaPrecompile; +use pallet_evm_precompile_registry::PrecompileRegistry; +use pallet_evm_precompile_relay_encoder::RelayEncoderPrecompile; +use pallet_evm_precompile_relay_verifier::RelayDataVerifierPrecompile; +use pallet_evm_precompile_sha3fips::Sha3FIPS256; +use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; +use pallet_evm_precompile_xcm_transactor::{ + v1::XcmTransactorPrecompileV1, v2::XcmTransactorPrecompileV2, v3::XcmTransactorPrecompileV3, +}; +use pallet_evm_precompile_xcm_utils::XcmUtilsPrecompile; +use pallet_evm_precompile_xtokens::XtokensPrecompile; +use pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSet; +use precompile_utils::precompile_set::*; + +pub struct NativeErc20Metadata; + +/// ERC20 metadata for the native token. +impl Erc20Metadata for NativeErc20Metadata { + /// Returns the name of the token. + fn name() -> &'static str { + "MOVR token" + } + + /// Returns the symbol of the token. + fn symbol() -> &'static str { + "MOVR" + } + + /// Returns the decimals places of the token. + fn decimals() -> u8 { + 18 + } + + /// Must return `true` only if it represents the main native currency of + /// the network. It must be the currency used in `pallet_evm`. + fn is_native_currency() -> bool { + true + } +} + +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as foreign +pub const FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; + +parameter_types! { + pub ForeignAssetPrefix: &'static [u8] = FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX; +} + +type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile); + +#[precompile_utils::precompile_name_from_address] +type MoonriverPrecompilesAt = ( + // Ethereum precompiles: + // We allow DELEGATECALL to stay compliant with Ethereum behavior. + PrecompileAt, ECRecover, EthereumPrecompilesChecks>, + PrecompileAt, Sha256, EthereumPrecompilesChecks>, + PrecompileAt, Ripemd160, EthereumPrecompilesChecks>, + PrecompileAt, Identity, EthereumPrecompilesChecks>, + PrecompileAt, Modexp, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Add, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Mul, EthereumPrecompilesChecks>, + PrecompileAt, Bn128Pairing, EthereumPrecompilesChecks>, + PrecompileAt, Blake2F, EthereumPrecompilesChecks>, + // Non-Moonbeam specific nor Ethereum precompiles : + PrecompileAt, Sha3FIPS256, (CallableByContract, CallableByPrecompile)>, + RemovedPrecompileAt>, // Dispatch + PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, + // Moonbeam specific precompiles: + PrecompileAt< + AddressU64<2048>, + ParachainStakingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2049>, + CrowdloanRewardsPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2050>, + Erc20BalancesPrecompile, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompileAt>, // DemocracyPrecompile + PrecompileAt< + AddressU64<2052>, + XtokensPrecompile, + ( + SubcallWithMaxNesting<1>, + CallableByContract, + CallableByPrecompile, + ), + >, + PrecompileAt< + AddressU64<2053>, + RelayEncoderPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2054>, + XcmTransactorPrecompileV1, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2055>, + AuthorMappingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2056>, + BatchPrecompile, + ( + SubcallWithMaxNesting<2>, + // Batch is the only precompile allowed to call Batch. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2057>, + RandomnessPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2058>, + CallPermitPrecompile, + (SubcallWithMaxNesting<0>, CallableByContract), + >, + PrecompileAt< + AddressU64<2059>, + ProxyPrecompile, + ( + CallableByContract>, + SubcallWithMaxNesting<0>, + // Batch is the only precompile allowed to call Proxy. + CallableByPrecompile>>, + ), + >, + PrecompileAt< + AddressU64<2060>, + XcmUtilsPrecompile, + CallableByContract< + pallet_evm_precompile_xcm_utils::AllExceptXcmExecute, + >, + >, + PrecompileAt< + AddressU64<2061>, + XcmTransactorPrecompileV2, + (CallableByContract, CallableByPrecompile), + >, + RemovedPrecompileAt>, //CouncilInstance + RemovedPrecompileAt>, // TechCommitteeInstance + PrecompileAt< + AddressU64<2064>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2065>, + ReferendaPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2066>, + ConvictionVotingPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2067>, + PreimagePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2068>, + CollectivePrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2069>, + PrecompileRegistry, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt, GmpPrecompile, SubcallWithMaxNesting<0>>, + PrecompileAt< + AddressU64<2071>, + XcmTransactorPrecompileV3, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2072>, + IdentityPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt< + AddressU64<2073>, + RelayDataVerifierPrecompile, + (CallableByContract, CallableByPrecompile), + >, +); + +/// The PrecompileSet installed in the Moonriver runtime. +/// We include the nine Istanbul precompiles +/// (https://github.com/ethereum/go-ethereum/blob/3c46f557/core/vm/contracts.go#L69) +/// The following distribution has been decided for the precompiles +/// 0-1023: Ethereum Mainnet Precompiles +/// 1024-2047 Precompiles that are not in Ethereum Mainnet but are neither Moonbeam specific +/// 2048-4095 Moonbeam specific precompiles +pub type MoonriverPrecompiles = PrecompileSetBuilder< + R, + ( + // Skip precompiles if out of range. + PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<4095>), MoonriverPrecompilesAt>, + // Prefixed precompile sets (XC20) + PrecompileSetStartingWith< + ForeignAssetPrefix, + Erc20AssetsPrecompileSet, + CallableByContract, + >, + // Moonriver never had any local assets (No blacklist needed + // https://moonriver.subscan.io/event?module=localassets&event_id=created + // https://moonriver.subscan.io/event?module=localassets&event_id=forcecreated + ), +>; diff --git a/tracing/2902/runtime/moonriver/src/xcm_config.rs b/tracing/2902/runtime/moonriver/src/xcm_config.rs new file mode 100644 index 00000000..58cc41b3 --- /dev/null +++ b/tracing/2902/runtime/moonriver/src/xcm_config.rs @@ -0,0 +1,722 @@ +// 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 . + +//! XCM configuration for Moonbase. +//! + +use super::{ + governance, AccountId, AssetId, AssetManager, Balance, Balances, DealWithFees, Erc20XcmBridge, + MaintenanceMode, MessageQueue, ParachainInfo, ParachainSystem, Perbill, PolkadotXcm, Runtime, + RuntimeBlockWeights, RuntimeCall, RuntimeEvent, RuntimeOrigin, Treasury, XcmpQueue, +}; + +use frame_support::{ + parameter_types, + traits::{EitherOfDiverse, Everything, Nothing, PalletInfoAccess, TransformOrigin}, +}; +use moonbeam_runtime_common::weights as moonbeam_weights; +use pallet_evm_precompileset_assets_erc20::AccountIdAssetIdConversion; +use sp_runtime::{ + traits::{Hash as THash, MaybeEquivalence, PostDispatchInfoOf}, + DispatchErrorWithPostInfo, +}; +use sp_weights::Weight; + +use frame_system::{EnsureRoot, RawOrigin}; +use sp_core::{ConstU32, H160, H256}; + +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, DescribeAllTerminal, DescribeFamily, + EnsureXcmOrigin, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, HashedDescription, + NoChecking, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, UsingComponents, WeightInfoBounds, WithComputedOrigin, +}; + +use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use xcm::latest::prelude::{ + Asset, GlobalConsensus, InteriorLocation, Junction, Location, NetworkId, PalletInstance, + Parachain, +}; +use xcm_executor::traits::{CallDispatcher, ConvertLocation, JustTry}; + +use cumulus_primitives_core::{AggregateMessageOrigin, ParaId}; +use orml_xcm_support::MultiNativeAsset; +use xcm_primitives::{ + AbsoluteAndRelativeReserve, AccountIdToCurrencyId, AccountIdToLocation, AsAssetType, + FirstAssetTrader, SignedToAccountId20, UtilityAvailableCalls, UtilityEncodeCall, XcmTransact, +}; + +use parity_scale_codec::{Decode, Encode}; +use scale_info::TypeInfo; + +use sp_core::Get; +use sp_std::{ + convert::{From, Into, TryFrom}, + prelude::*, +}; + +use orml_traits::parameter_type_with_key; + +use crate::governance::referenda::{FastGeneralAdminOrRoot, GeneralAdminOrRoot}; + +parameter_types! { + // The network Id of the relay + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + // The relay chain Origin type + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + // The universal location within the global consensus system + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); + + // Self Reserve location, defines the multilocation identifiying the self-reserve currency + // This is used to match it also against our Balances pallet when we receive such + // a Location: (Self Balances pallet index) + // We use the RELATIVE multilocation + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // If we receive a Location of type AccountKey20, just generate a native account + AccountKey20Aliases, + // Generate remote accounts according to polkadot standards + HashedDescription>, +); + +/// Wrapper type around `LocationToAccountId` to convert an `AccountId` to type `H160`. +pub struct LocationToH160; +impl ConvertLocation for LocationToH160 { + fn convert_location(location: &Location) -> Option { + >::convert_location(location) + .map(Into::into) + } +} + +// The non-reserve fungible transactor type +// It will use pallet-assets, and the Id will be matched against AsAssetType +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + super::Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId20 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +/// The transactor for our own chain currency. +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + xcm_builder::IsConcrete, + // We can convert the MultiLocations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// We use all transactors +// These correspond to +// SelfReserve asset, both pre and post 0.9.16 +// Foreign assets +// Local assets, both pre and post 0.9.16 +// We can remove the Old reanchor once +// we import https://github.com/open-web3-stack/open-runtime-module-library/pull/708 +pub type AssetTransactors = ( + LocalAssetTransactor, + ForeignFungiblesTransactor, + Erc20XcmBridge, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + // Xcm Origins defined by a Multilocation of type AccountKey20 can be converted to a 20 byte- + // account local origin + SignedAccountKey20AsNative, +); + +parameter_types! { + /// The amount of weight an XCM operation takes. This is safe overestimate. + pub UnitWeightCost: Weight = Weight::from_parts(200_000_000u64, 0); + /// Maximum number of instructions in a single XCM fragment. A sanity check against + /// weight caculations getting too crazy. + pub MaxInstructions: u32 = 100; +} + +/// Xcm Weigher shared between multiple Xcm-related configs. +pub type XcmWeigher = WeightInfoBounds< + moonbeam_xcm_benchmarks::weights::XcmWeight, + RuntimeCall, + MaxInstructions, +>; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +/// We do not burn anything because we want to mimic exactly what +/// the sovereign account has +pub type XcmFeesToAccount = xcm_primitives::XcmFeesToAccount< + super::Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +pub struct SafeCallFilter; +impl frame_support::traits::Contains for SafeCallFilter { + fn contains(_call: &RuntimeCall) -> bool { + // TODO review + // This needs to be addressed at EVM level + true + } +} + +parameter_types! { + pub const MaxAssetsIntoHolding: u32 = xcm_primitives::MAX_ASSETS; +} + +// Our implementation of the Moonbeam Call +// Attachs the right origin in case the call is made to pallet-ethereum-xcm +#[cfg(not(feature = "evm-tracing"))] +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); +#[cfg(feature = "evm-tracing")] +moonbeam_runtime_common::impl_moonbeam_xcm_call_tracing!(); + +moonbeam_runtime_common::impl_evm_runner_precompile_or_eth_xcm!(); + +pub struct XcmExecutorConfig; +impl xcm_executor::Config for XcmExecutorConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + // How to withdraw and deposit an asset. + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + // Filter to the reserve withdraw operations + // Whenever the reserve matches the relative or absolute value + // of our chain, we always return the relative reserve + type IsReserve = MultiNativeAsset>; + type IsTeleporter = (); // No teleport + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = XcmWeigher; + // We use two traders + // When we receive the relative representation of the self-reserve asset, + // we use UsingComponents and the local way of handling fees + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + UsingComponents< + ::WeightToFee, + SelfReserve, + AccountId, + Balances, + DealWithFees, + >, + FirstAssetTrader, + ); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = pallet_erc20_xcm_bridge::AssetTrapWrapper; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type PalletInstancesInfo = crate::AllPalletsWithSystem; + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type AssetLocker = (); + type AssetExchanger = (); + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = SafeCallFilter; + type Aliasers = Nothing; + type TransactionalProcessor = xcm_builder::FrameTransactionalProcessor; +} + +type XcmExecutor = pallet_erc20_xcm_bridge::XcmExecutorWrapper< + XcmExecutorConfig, + xcm_executor::XcmExecutor, +>; + +// Converts a Signed Local Origin into a Location +pub type LocalOriginToLocation = SignedToAccountId20; + +/// The means for routing XCM messages which are not for local execution into the right message +/// queues. +pub type XcmRouter = ( + // Two routers - use UMP to communicate with the relay chain: + cumulus_primitives_utility::ParentAsUmp, + // ..and XCMP to communicate with the sibling chains. + XcmpQueue, +); + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + // TODO pallet-xcm weights + type WeightInfo = moonbeam_weights::pallet_xcm::WeightInfo; + type AdminOrigin = EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl cumulus_pallet_xcmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ChannelInfo = ParachainSystem; + type VersionWrapper = PolkadotXcm; + type XcmpQueue = TransformOrigin; + type MaxInboundSuspended = sp_core::ConstU32<1_000>; + type ControllerOrigin = EnsureRoot; + type ControllerOriginConverter = XcmOriginToTransactDispatchOrigin; + type WeightInfo = moonbeam_weights::cumulus_pallet_xcmp_queue::WeightInfo; + type PriceForSiblingDelivery = polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery< + cumulus_primitives_core::ParaId, + >; +} + +parameter_types! { + pub const RelayOrigin: AggregateMessageOrigin = AggregateMessageOrigin::Parent; +} + +// TODO: This pallet can be removed after the lazy migration is done and +// event `Completed` is emitted. +// https://github.com/paritytech/polkadot-sdk/pull/1246 +impl cumulus_pallet_dmp_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type DmpSink = frame_support::traits::EnqueueWithOrigin; + type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; +} + +parameter_types! { + /// The amount of weight (if any) which should be provided to the message queue for + /// servicing enqueued items. + /// + /// This may be legitimately `None` in the case that you will call + /// `ServiceQueues::service_queues` manually. + pub MessageQueueServiceWeight: Weight = + Perbill::from_percent(25) * RuntimeBlockWeights::get().max_block; + /// The maximum number of stale pages (i.e. of overweight messages) allowed before culling + /// can happen. Once there are more stale pages than this, then historical pages may be + /// dropped, even if they contain unprocessed overweight messages. + pub const MessageQueueMaxStale: u32 = 8; + /// The size of the page; this implies the maximum message size which can be sent. + /// + /// A good value depends on the expected message sizes, their weights, the weight that is + /// available for processing them and the maximal needed message size. The maximal message + /// size is slightly lower than this as defined by [`MaxMessageLenOf`]. + pub const MessageQueueHeapSize: u32 = 128 * 1048; +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + #[cfg(feature = "runtime-benchmarks")] + type MessageProcessor = pallet_message_queue::mock_helpers::NoopMessageProcessor< + cumulus_primitives_core::AggregateMessageOrigin, + >; + #[cfg(not(feature = "runtime-benchmarks"))] + type MessageProcessor = + xcm_builder::ProcessXcmMessage; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + // The XCMP queue pallet is only ever able to handle the `Sibling(ParaId)` origin: + type QueueChangeHandler = NarrowOriginToSibling; + // NarrowOriginToSibling calls XcmpQueue's is_paused if Origin is sibling. Allows all other origins + type QueuePausedQuery = (MaintenanceMode, NarrowOriginToSibling); + type WeightInfo = pallet_message_queue::weights::SubstrateWeight; +} + +// Our AssetType. For now we only handle Xcm Assets +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum AssetType { + Xcm(xcm::v3::Location), +} +impl Default for AssetType { + fn default() -> Self { + Self::Xcm(xcm::v3::Location::here()) + } +} + +impl From for AssetType { + fn from(location: xcm::v3::Location) -> Self { + Self::Xcm(location) + } +} + +// This can be removed once we fully adopt xcm::v4 everywhere +impl TryFrom for AssetType { + type Error = (); + fn try_from(location: Location) -> Result { + Ok(Self::Xcm(location.try_into()?)) + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => Some(location), + } + } +} + +impl Into> for AssetType { + fn into(self) -> Option { + match self { + Self::Xcm(location) => xcm_builder::V4V3LocationConverter::convert_back(&location), + } + } +} + +// Implementation on how to retrieve the AssetId from an AssetType +// We simply hash the AssetType and take the lowest 128 bits +impl From for AssetId { + fn from(asset: AssetType) -> AssetId { + match asset { + AssetType::Xcm(id) => { + let mut result: [u8; 16] = [0u8; 16]; + let hash: H256 = id.using_encoded(::Hashing::hash); + result.copy_from_slice(&hash.as_fixed_bytes()[0..16]); + u128::from_le_bytes(result) + } + } + } +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + // Our native token + SelfReserve, + // Assets representing other chains native tokens + ForeignAsset(AssetId), + // Erc20 token + Erc20 { contract_address: H160 }, +} + +impl AccountIdToCurrencyId for Runtime { + fn account_to_currency_id(account: AccountId) -> Option { + Some(match account { + // the self-reserve currency is identified by the pallet-balances address + a if a == H160::from_low_u64_be(2050).into() => CurrencyId::SelfReserve, + // the rest of the currencies, by their corresponding erc20 address + _ => match Runtime::account_to_asset_id(account) { + // A foreign asset + Some((_prefix, asset_id)) => CurrencyId::ForeignAsset(asset_id), + // If no known prefix is identified, we consider that it's a "real" erc20 token + // (i.e. managed by a real smart contract) + None => CurrencyId::Erc20 { + contract_address: account.into(), + }, + }, + }) + } +} + +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + // For now and until Xtokens is adapted to handle 0.9.16 version we use + // the old anchoring here + // This is not a problem in either cases, since the view of the destination + // chain does not change + // TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it + CurrencyId::SelfReserve => { + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + CurrencyId::Erc20 { contract_address } => { + let mut location = Erc20XcmBridgePalletLocation::get(); + location + .push_interior(Junction::AccountKey20 { + key: contract_address.0, + network: None, + }) + .ok(); + Some(location) + } + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(200_000_000u64, 0); + pub const MaxAssetsForTransfer: usize = 2; + + // This is how we are going to detect whether the asset is a Reserve asset + // This however is the chain part only + pub SelfLocation: Location = Location::here(); + // We need this to be able to catch when someone is trying to execute a non- + // cross-chain transfer in xtokens through the absolute path way + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(ParachainInfo::parachain_id().into()) + ].into() + }; +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + // Kusama AssetHub fee + (1, Some(Parachain(1000u32))) => Some(50_000_000u128), + _ => None, + } + }; +} + +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdConvert = CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = AbsoluteAndRelativeReserve; +} + +// 1 KSM should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +// For now we only allow to transact in the relay, although this might change in the future +// Transactors just defines the chains in which we allow transactions to be issued through +// xcm +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum Transactors { + Relay, +} + +// Default for benchmarking +#[cfg(feature = "runtime-benchmarks")] +impl Default for Transactors { + fn default() -> Self { + Transactors::Relay + } +} + +impl TryFrom for Transactors { + type Error = (); + fn try_from(value: u8) -> Result { + match value { + 0u8 => Ok(Transactors::Relay), + _ => Err(()), + } + } +} + +impl UtilityEncodeCall for Transactors { + fn encode_call(self, call: UtilityAvailableCalls) -> Vec { + match self { + Transactors::Relay => pallet_xcm_transactor::Pallet::::encode_call( + pallet_xcm_transactor::Pallet(sp_std::marker::PhantomData::), + call, + ), + } + } +} + +impl XcmTransact for Transactors { + fn destination(self) -> Location { + match self { + Transactors::Relay => Location::parent(), + } + } +} + +pub type DerivativeAddressRegistrationOrigin = + EitherOfDiverse, governance::custom_origins::GeneralAdmin>; + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = Transactors; + type DerivativeAddressRegistrationOrigin = DerivativeAddressRegistrationOrigin; + type SovereignAccountDispatcherOrigin = EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = AccountIdToLocation; + type CurrencyIdToLocation = CurrencyIdToLocation>; + type XcmSender = XcmRouter; + type SelfLocation = SelfLocation; + type Weigher = XcmWeigher; + type UniversalLocation = UniversalLocation; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = AbsoluteAndRelativeReserve; + type WeightInfo = moonbeam_weights::pallet_xcm_transactor::WeightInfo; + type HrmpManipulatorOrigin = GeneralAdminOrRoot; + type HrmpOpenOrigin = FastGeneralAdminOrRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + // This is the relative view of erc20 assets. + // Identified by this prefix + AccountKey20(contractAddress) + // We use the RELATIVE multilocation + pub Erc20XcmBridgePalletLocation: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + + // To be able to support almost all erc20 implementations, + // we provide a sufficiently hight gas limit. + pub Erc20XcmBridgeTransferGasLimit: u64 = 200_000; +} + +impl pallet_erc20_xcm_bridge::Config for Runtime { + type AccountIdConverter = LocationToH160; + type Erc20MultilocationPrefix = Erc20XcmBridgePalletLocation; + type Erc20TransferGasLimit = Erc20XcmBridgeTransferGasLimit; + type EvmRunner = EvmRunnerPrecompileOrEthXcm; +} + +#[cfg(feature = "runtime-benchmarks")] +mod testing { + use super::*; + use xcm_builder::V4V3LocationConverter; + + /// This From exists for benchmarking purposes. It has the potential side-effect of calling + /// AssetManager::set_asset_type_asset_id() and should NOT be used in any production code. + impl From for CurrencyId { + fn from(location: Location) -> CurrencyId { + use xcm_primitives::AssetTypeGetter; + + // If it does not exist, for benchmarking purposes, we create the association + let asset_id = if let Some(asset_id) = + AsAssetType::::convert_location(&location) + { + asset_id + } else { + let asset_type = AssetType::Xcm( + V4V3LocationConverter::convert(&location).expect("convert to v3"), + ); + let asset_id: AssetId = asset_type.clone().into(); + AssetManager::set_asset_type_asset_id(asset_type, asset_id); + asset_id + }; + + CurrencyId::ForeignAsset(asset_id) + } + } +} diff --git a/tracing/2902/runtime/moonriver/tests/common/mod.rs b/tracing/2902/runtime/moonriver/tests/common/mod.rs new file mode 100644 index 00000000..2fbe1236 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/common/mod.rs @@ -0,0 +1,380 @@ +// 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 . + +#![allow(dead_code)] + +use cumulus_primitives_parachain_inherent::ParachainInherentData; +use fp_evm::GenesisAccount; +use frame_support::{ + assert_ok, + traits::{OnFinalize, OnInitialize}, +}; +pub use moonriver_runtime::{ + asset_config::AssetRegistrarMetadata, + currency::{GIGAWEI, MOVR, SUPPLY_FACTOR, WEI}, + xcm_config::AssetType, + AccountId, AssetId, AssetManager, AuthorInherent, Balance, Balances, CrowdloanRewards, + Ethereum, Executive, Header, InflationInfo, ParachainStaking, Range, Runtime, RuntimeCall, + RuntimeEvent, System, TransactionConverter, TransactionPaymentAsGasPrice, UncheckedExtrinsic, + HOURS, WEEKS, +}; +use nimbus_primitives::{NimbusId, NIMBUS_ENGINE_ID}; +use sp_core::{Encode, H160}; +use sp_runtime::{traits::Dispatchable, BuildStorage, Digest, DigestItem, Perbill, Percent}; + +use std::collections::BTreeMap; + +use fp_rpc::ConvertTransaction; +use pallet_transaction_payment::Multiplier; + +// A valid signed Alice transfer. +pub const VALID_ETH_TX: &str = + "02f86d8205018085174876e80085e8d4a5100082520894f24ff3a9cf04c71dbc94d0b566f7a27b9456\ + 6cac8080c001a0e1094e1a52520a75c0255db96132076dd0f1263089f838bea548cbdbfc64a4d19f031c\ + 92a8cb04e2d68d20a6158d542a07ac440cc8d07b6e36af02db046d92df"; + +// An invalid signed Alice transfer with a gas limit artifically set to 0. +pub const INVALID_ETH_TX: &str = + "f86180843b9aca00809412cb274aad8251c875c0bf6872b67d9983e53fdd01801ca00e28ba2dd3c5a\ + 3fd467d4afd7aefb4a34b373314fff470bb9db743a84d674a0aa06e5994f2d07eafe1c37b4ce5471ca\ + ecec29011f6f5bf0b1a552c55ea348df35f"; + +pub fn rpc_run_to_block(n: u32) { + while System::block_number() < n { + Ethereum::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + Ethereum::on_initialize(System::block_number()); + } +} + +/// Utility function that advances the chain to the desired block number. +/// If an author is provided, that author information is injected to all the blocks in the meantime. +pub fn run_to_block(n: u32, author: Option) { + // Finalize the first block + Ethereum::on_finalize(System::block_number()); + while System::block_number() < n { + // Set the new block number and author + match author { + Some(ref author) => { + let pre_digest = Digest { + logs: vec![DigestItem::PreRuntime(NIMBUS_ENGINE_ID, author.encode())], + }; + System::reset_events(); + System::initialize( + &(System::block_number() + 1), + &System::parent_hash(), + &pre_digest, + ); + } + None => { + System::set_block_number(System::block_number() + 1); + } + } + + // Initialize the new block + AuthorInherent::on_initialize(System::block_number()); + ParachainStaking::on_initialize(System::block_number()); + Ethereum::on_initialize(System::block_number()); + + // Finalize the block + Ethereum::on_finalize(System::block_number()); + ParachainStaking::on_finalize(System::block_number()); + } +} + +pub fn last_event() -> RuntimeEvent { + System::events().pop().expect("Event expected").event +} + +// Helper function to give a simple evm context suitable for tests. +// We can remove this once https://github.com/rust-blockchain/evm/pull/35 +// is in our dependency graph. +pub fn evm_test_context() -> fp_evm::Context { + fp_evm::Context { + address: Default::default(), + caller: Default::default(), + apparent_value: From::from(0), + } +} + +// Test struct with the purpose of initializing xcm assets +#[derive(Clone)] +pub struct XcmAssetInitialization { + pub asset_type: AssetType, + pub metadata: AssetRegistrarMetadata, + pub balances: Vec<(AccountId, Balance)>, + pub is_sufficient: bool, +} + +pub struct ExtBuilder { + // endowed accounts with balances + balances: Vec<(AccountId, Balance)>, + // [collator, amount] + collators: Vec<(AccountId, Balance)>, + // [delegator, collator, nomination_amount] + delegations: Vec<(AccountId, AccountId, Balance, Percent)>, + // per-round inflation config + inflation: InflationInfo, + // AuthorId -> AccoutId mappings + mappings: Vec<(NimbusId, AccountId)>, + // Crowdloan fund + crowdloan_fund: Balance, + // Chain id + chain_id: u64, + // EVM genesis accounts + evm_accounts: BTreeMap, + // [assettype, metadata, Vec, is_sufficient] + xcm_assets: Vec, + safe_xcm_version: Option, +} + +impl Default for ExtBuilder { + fn default() -> ExtBuilder { + ExtBuilder { + balances: vec![], + delegations: vec![], + collators: vec![], + inflation: InflationInfo { + expect: Range { + min: 100_000 * MOVR, + ideal: 200_000 * MOVR, + max: 500_000 * MOVR, + }, + // not used + annual: Range { + min: Perbill::from_percent(50), + ideal: Perbill::from_percent(50), + max: Perbill::from_percent(50), + }, + // unrealistically high parameterization, only for testing + round: Range { + min: Perbill::from_percent(5), + ideal: Perbill::from_percent(5), + max: Perbill::from_percent(5), + }, + }, + mappings: vec![], + crowdloan_fund: 0, + chain_id: CHAIN_ID, + evm_accounts: BTreeMap::new(), + xcm_assets: vec![], + safe_xcm_version: None, + } + } +} + +impl ExtBuilder { + pub fn with_evm_accounts(mut self, accounts: BTreeMap) -> Self { + self.evm_accounts = accounts; + self + } + + pub fn with_balances(mut self, balances: Vec<(AccountId, Balance)>) -> Self { + self.balances = balances; + self + } + + pub fn with_collators(mut self, collators: Vec<(AccountId, Balance)>) -> Self { + self.collators = collators; + self + } + + pub fn with_delegations(mut self, delegations: Vec<(AccountId, AccountId, Balance)>) -> Self { + self.delegations = delegations + .into_iter() + .map(|d| (d.0, d.1, d.2, Percent::zero())) + .collect(); + self + } + + pub fn with_crowdloan_fund(mut self, crowdloan_fund: Balance) -> Self { + self.crowdloan_fund = crowdloan_fund; + self + } + + pub fn with_mappings(mut self, mappings: Vec<(NimbusId, AccountId)>) -> Self { + self.mappings = mappings; + self + } + + #[allow(dead_code)] + pub fn with_inflation(mut self, inflation: InflationInfo) -> Self { + self.inflation = inflation; + self + } + + pub fn with_xcm_assets(mut self, xcm_assets: Vec) -> Self { + self.xcm_assets = xcm_assets; + self + } + + pub fn with_safe_xcm_version(mut self, safe_xcm_version: u32) -> Self { + self.safe_xcm_version = Some(safe_xcm_version); + self + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: self.balances, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_parachain_staking::GenesisConfig:: { + candidates: self.collators, + delegations: self.delegations, + inflation_config: self.inflation, + collator_commission: Perbill::from_percent(20), + parachain_bond_reserve_percent: Percent::from_percent(30), + blocks_per_round: 2 * HOURS, + num_selected_candidates: 8, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_crowdloan_rewards::GenesisConfig:: { + funded_amount: self.crowdloan_fund, + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_author_mapping::GenesisConfig:: { + mappings: self.mappings, + } + .assimilate_storage(&mut t) + .unwrap(); + + let genesis_config = pallet_evm_chain_id::GenesisConfig:: { + chain_id: self.chain_id, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: self.evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_ethereum::GenesisConfig:: { + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_xcm::GenesisConfig:: { + safe_xcm_version: self.safe_xcm_version, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = pallet_transaction_payment::GenesisConfig:: { + multiplier: Multiplier::from(10u128), + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + let xcm_assets = self.xcm_assets.clone(); + 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( + root_origin(), + xcm_asset_initialization.asset_type, + xcm_asset_initialization.metadata, + 1, + xcm_asset_initialization.is_sufficient, + ) + .unwrap(); + for (account, balance) in xcm_asset_initialization.balances { + moonriver_runtime::Assets::mint( + origin_of(AssetManager::account_id()), + asset_id.into(), + account, + balance, + ) + .unwrap(); + } + } + System::set_block_number(1); + }); + ext + } +} + +pub const CHAIN_ID: u64 = 1281; +pub const ALICE: [u8; 20] = [4u8; 20]; +pub const ALICE_NIMBUS: [u8; 32] = [4u8; 32]; +pub const BOB: [u8; 20] = [5u8; 20]; +pub const CHARLIE: [u8; 20] = [6u8; 20]; +pub const DAVE: [u8; 20] = [7u8; 20]; +pub const EVM_CONTRACT: [u8; 20] = [8u8; 20]; + +pub fn origin_of(account_id: AccountId) -> ::RuntimeOrigin { + ::RuntimeOrigin::signed(account_id) +} + +pub fn inherent_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::none() +} + +pub fn root_origin() -> ::RuntimeOrigin { + ::RuntimeOrigin::root() +} + +/// Mock the inherent that sets validation data in ParachainSystem, which +/// contains the `relay_chain_block_number`, which is used in `author-filter` as a +/// source of randomness to filter valid authors at each block. +pub fn set_parachain_inherent_data() { + use cumulus_primitives_core::PersistedValidationData; + use cumulus_test_relay_sproof_builder::RelayStateSproofBuilder; + let (relay_parent_storage_root, relay_chain_state) = + RelayStateSproofBuilder::default().into_state_root_and_proof(); + let vfp = PersistedValidationData { + relay_parent_number: 1u32, + relay_parent_storage_root, + ..Default::default() + }; + let parachain_inherent_data = ParachainInherentData { + validation_data: vfp, + relay_chain_state: relay_chain_state, + downward_messages: Default::default(), + horizontal_messages: Default::default(), + }; + assert_ok!(RuntimeCall::ParachainSystem( + cumulus_pallet_parachain_system::Call::::set_validation_data { + data: parachain_inherent_data + } + ) + .dispatch(inherent_origin())); +} + +pub fn unchecked_eth_tx(raw_hex_tx: &str) -> UncheckedExtrinsic { + let converter = TransactionConverter; + converter.convert_transaction(ethereum_transaction(raw_hex_tx)) +} + +pub fn ethereum_transaction(raw_hex_tx: &str) -> pallet_ethereum::Transaction { + let bytes = hex::decode(raw_hex_tx).expect("Transaction bytes."); + let transaction = ethereum::EnvelopedDecodable::decode(&bytes[..]); + assert!(transaction.is_ok()); + transaction.unwrap() +} diff --git a/tracing/2902/runtime/moonriver/tests/evm_tracing.rs b/tracing/2902/runtime/moonriver/tests/evm_tracing.rs new file mode 100644 index 00000000..86aaab37 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/evm_tracing.rs @@ -0,0 +1,110 @@ +// 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 . + +//! Moonriver EVM tracing Integration Tests + +mod common; + +#[cfg(test)] +#[cfg(feature = "evm-tracing")] +mod tests { + use super::common::*; + + use pallet_evm::AddressMapping; + use sp_core::H160; + + use moonbeam_rpc_primitives_debug::runtime_decl_for_debug_runtime_api::DebugRuntimeApi; + use std::str::FromStr; + + #[test] + fn debug_runtime_api_trace_transaction() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * MOVR), + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * MOVR, + } + .into(), + ); + let transaction = ethereum_transaction(VALID_ETH_TX); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_transaction( + vec![non_eth_uxt.clone(), eth_uxt, non_eth_uxt.clone()], + &transaction, + &block + ) + .is_ok()); + }); + } + + #[test] + fn debug_runtime_api_trace_block() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("6be02d1d3665660d22ff9624b7be0551ee1ac91b") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_balances(vec![ + (alith, 2_000 * MOVR), + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .build() + .execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * MOVR, + } + .into(), + ); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let eth_tx = ethereum_transaction(VALID_ETH_TX); + let eth_extrinsic_hash = eth_tx.hash(); + let block = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1, + parent_hash: Default::default(), + state_root: Default::default(), + }; + assert!(Runtime::trace_block( + vec![non_eth_uxt.clone(), eth_uxt.clone(), non_eth_uxt, eth_uxt], + vec![eth_extrinsic_hash, eth_extrinsic_hash], + &block + ) + .is_ok()); + }); + } +} diff --git a/tracing/2902/runtime/moonriver/tests/integration_test.rs b/tracing/2902/runtime/moonriver/tests/integration_test.rs new file mode 100644 index 00000000..f3b32732 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/integration_test.rs @@ -0,0 +1,2664 @@ +// 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 . + +//! Moonriver Runtime Integration Tests + +#![cfg(test)] + +mod common; +use common::*; + +use fp_evm::{Context, IsPrecompileResult}; +use frame_support::{ + assert_noop, assert_ok, + dispatch::DispatchClass, + traits::{ + fungible::Inspect, Currency as CurrencyT, EnsureOrigin, PalletInfo, StorageInfo, + StorageInfoTrait, + }, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + StorageHasher, Twox128, +}; +use moonbeam_xcm_benchmarks::weights::XcmWeight; +use moonriver_runtime::{ + asset_config::ForeignAssetInstance, + xcm_config::{CurrencyId, SelfReserve}, + AssetId, OpenTechCommitteeCollective, PolkadotXcm, Precompiles, RuntimeBlockWeights, + TransactionPayment, TreasuryCouncilCollective, XTokens, XcmTransactor, + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, +}; +use nimbus_primitives::NimbusId; +use pallet_evm::PrecompileSet; +use pallet_evm_precompileset_assets_erc20::{ + AccountIdAssetIdConversion, SELECTOR_LOG_APPROVAL, SELECTOR_LOG_TRANSFER, +}; +use pallet_transaction_payment::Multiplier; +use pallet_xcm_transactor::{Currency, CurrencyPayment, TransactWeights}; +use parity_scale_codec::Encode; +use polkadot_parachain::primitives::Sibling; +use precompile_utils::{ + precompile_set::{is_precompile_or_fail, IsActivePrecompile}, + prelude::*, + testing::*, +}; +use sha3::{Digest, Keccak256}; +use sp_core::{ByteArray, Pair, H160, U256}; +use sp_runtime::{ + traits::{Convert, Dispatchable}, + BuildStorage, DispatchError, ModuleError, +}; +use std::str::from_utf8; +use xcm::latest::prelude::*; +use xcm::{VersionedAssets, VersionedLocation}; +use xcm_builder::{ParentIsPreset, SiblingParachainConvertsVia}; +use xcm_executor::traits::ConvertLocation; + +type BatchPCall = pallet_evm_precompile_batch::BatchPrecompileCall; +type CrowdloanRewardsPCall = + pallet_evm_precompile_crowdloan_rewards::CrowdloanRewardsPrecompileCall; +type XcmUtilsPCall = pallet_evm_precompile_xcm_utils::XcmUtilsPrecompileCall< + Runtime, + moonriver_runtime::xcm_config::XcmExecutorConfig, +>; +type XtokensPCall = pallet_evm_precompile_xtokens::XtokensPrecompileCall; +type ForeignAssetsPCall = pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSetCall< + Runtime, + ForeignAssetInstance, +>; +type XcmTransactorV2PCall = + pallet_evm_precompile_xcm_transactor::v2::XcmTransactorPrecompileV2Call; + +const BASE_FEE_GENESIS: u128 = 100 * GIGAWEI; + +#[test] +fn xcmp_queue_controller_origin_is_root() { + // important for the XcmExecutionManager impl of PauseExecution which uses root origin + // to suspend/resume XCM execution in xcmp_queue::on_idle + assert_ok!( + ::ControllerOrigin::ensure_origin(root_origin()) + ); +} + +#[test] +fn verify_pallet_prefixes() { + fn is_pallet_prefix(name: &str) { + // Compares the unhashed pallet prefix in the `StorageInstance` implementation by every + // storage item in the pallet P. This pallet prefix is used in conjunction with the + // item name to get the unique storage key: hash(PalletPrefix) + hash(StorageName) + // https://github.com/paritytech/substrate/blob/master/frame/support/procedural/src/pallet/ + // expand/storage.rs#L389-L401 + assert_eq!( + ::PalletInfo::name::

(), + Some(name) + ); + } + // TODO: use StorageInfoTrait from https://github.com/paritytech/substrate/pull/9246 + // This is now available with polkadot-v0.9.9 dependencies + is_pallet_prefix::("System"); + is_pallet_prefix::("Utility"); + is_pallet_prefix::("ParachainSystem"); + is_pallet_prefix::("TransactionPayment"); + is_pallet_prefix::("ParachainInfo"); + is_pallet_prefix::("EthereumChainId"); + is_pallet_prefix::("EVM"); + is_pallet_prefix::("Ethereum"); + is_pallet_prefix::("ParachainStaking"); + is_pallet_prefix::("MaintenanceMode"); + is_pallet_prefix::("Scheduler"); + is_pallet_prefix::( + "OpenTechCommitteeCollective", + ); + is_pallet_prefix::("Treasury"); + is_pallet_prefix::("AuthorInherent"); + is_pallet_prefix::("AuthorFilter"); + is_pallet_prefix::("CrowdloanRewards"); + is_pallet_prefix::("AuthorMapping"); + is_pallet_prefix::("Identity"); + is_pallet_prefix::("XcmpQueue"); + is_pallet_prefix::("CumulusXcm"); + is_pallet_prefix::("DmpQueue"); + is_pallet_prefix::("PolkadotXcm"); + is_pallet_prefix::("Assets"); + is_pallet_prefix::("XTokens"); + is_pallet_prefix::("AssetManager"); + is_pallet_prefix::("Migrations"); + is_pallet_prefix::("XcmTransactor"); + is_pallet_prefix::("ProxyGenesisCompanion"); + is_pallet_prefix::("MoonbeamOrbiters"); + is_pallet_prefix::("TreasuryCouncilCollective"); + is_pallet_prefix::("MoonbeamLazyMigrations"); + is_pallet_prefix::("RelayStorageRoots"); + + let prefix = |pallet_name, storage_name| { + let mut res = [0u8; 32]; + res[0..16].copy_from_slice(&Twox128::hash(pallet_name)); + res[16..32].copy_from_slice(&Twox128::hash(storage_name)); + res.to_vec() + }; + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Timestamp".to_vec(), + storage_name: b"Now".to_vec(), + prefix: prefix(b"Timestamp", b"Now"), + max_values: Some(1), + max_size: Some(8), + }, + StorageInfo { + pallet_name: b"Timestamp".to_vec(), + storage_name: b"DidUpdate".to_vec(), + prefix: prefix(b"Timestamp", b"DidUpdate"), + max_values: Some(1), + max_size: Some(1), + } + ] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"TotalIssuance".to_vec(), + prefix: prefix(b"Balances", b"TotalIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"InactiveIssuance".to_vec(), + prefix: prefix(b"Balances", b"InactiveIssuance"), + max_values: Some(1), + max_size: Some(16), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Account".to_vec(), + prefix: prefix(b"Balances", b"Account"), + max_values: None, + max_size: Some(100), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Locks".to_vec(), + prefix: prefix(b"Balances", b"Locks"), + max_values: None, + max_size: Some(1287), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Reserves".to_vec(), + prefix: prefix(b"Balances", b"Reserves"), + max_values: None, + max_size: Some(1037), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Holds".to_vec(), + prefix: prefix(b"Balances", b"Holds"), + max_values: None, + max_size: Some(55), + }, + StorageInfo { + pallet_name: b"Balances".to_vec(), + storage_name: b"Freezes".to_vec(), + prefix: prefix(b"Balances", b"Freezes"), + max_values: None, + max_size: Some(37), + }, + ] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Proxies".to_vec(), + prefix: prefix(b"Proxy", b"Proxies"), + max_values: None, + max_size: Some(845), + }, + StorageInfo { + pallet_name: b"Proxy".to_vec(), + storage_name: b"Announcements".to_vec(), + prefix: prefix(b"Proxy", b"Announcements"), + max_values: None, + max_size: Some(1837), + } + ] + ); + assert_eq!( + ::storage_info(), + vec![StorageInfo { + pallet_name: b"MaintenanceMode".to_vec(), + storage_name: b"MaintenanceMode".to_vec(), + prefix: prefix(b"MaintenanceMode", b"MaintenanceMode"), + max_values: Some(1), + max_size: None, + },] + ); + assert_eq!( + ::storage_info(), + vec![ + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRoot".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRoot"), + max_values: None, + max_size: Some(44), + }, + StorageInfo { + pallet_name: b"RelayStorageRoots".to_vec(), + storage_name: b"RelayStorageRootKeys".to_vec(), + prefix: prefix(b"RelayStorageRoots", b"RelayStorageRootKeys"), + max_values: Some(1), + max_size: Some(121), + }, + ] + ); +} + +#[test] +fn test_collectives_storage_item_prefixes() { + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"TreasuryCouncilCollective".to_vec()); + } + + for StorageInfo { pallet_name, .. } in + ::storage_info() + { + assert_eq!(pallet_name, b"OpenTechCommitteeCollective".to_vec()); + } +} + +#[test] +fn collective_set_members_root_origin_works() { + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert_ok!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + // OpenTechCommitteeCollective + assert_ok!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::root(), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + )); + }); +} + +#[test] +fn collective_set_members_general_admin_origin_works() { + use moonriver_runtime::{ + governance::custom_origins::Origin as CustomOrigin, OriginCaller, Utility, + }; + + ExtBuilder::default().build().execute_with(|| { + let root_caller = ::RuntimeOrigin::root(); + let alice = AccountId::from(ALICE); + + // TreasuryCouncilCollective + let _ = Utility::dispatch_as( + root_caller.clone(), + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + // OpenTechCommitteeCollective + let _ = Utility::dispatch_as( + root_caller, + Box::new(OriginCaller::Origins(CustomOrigin::GeneralAdmin)), + Box::new( + pallet_collective::Call::::set_members { + new_members: vec![alice, AccountId::from(BOB)], + prime: Some(alice), + old_count: 2, + } + .into(), + ), + ); + + assert_eq!( + System::events() + .into_iter() + .filter_map(|r| { + match r.event { + RuntimeEvent::Utility(pallet_utility::Event::DispatchedAs { result }) + if result.is_ok() => + { + Some(true) + } + _ => None, + } + }) + .collect::>() + .len(), + 2 + ) + }); +} + +#[test] +fn collective_set_members_signed_origin_does_not_work() { + let alice = AccountId::from(ALICE); + ExtBuilder::default().build().execute_with(|| { + // TreasuryCouncilCollective + assert!(TreasuryCouncilCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + // OpenTechCommitteeCollective + assert!(OpenTechCommitteeCollective::set_members( + ::RuntimeOrigin::signed(alice), + vec![AccountId::from(ALICE), AccountId::from(BOB)], + Some(AccountId::from(ALICE)), + 2 + ) + .is_err()); + }); +} + +#[test] +fn verify_pallet_indices() { + fn is_pallet_index(index: usize) { + assert_eq!( + ::PalletInfo::index::

(), + Some(index) + ); + } + // System support + is_pallet_index::(0); + is_pallet_index::(1); + is_pallet_index::(3); + is_pallet_index::(4); + // Monetary + is_pallet_index::(10); + is_pallet_index::(11); + // Consensus support + is_pallet_index::(20); + is_pallet_index::(21); + is_pallet_index::(22); + is_pallet_index::(23); + is_pallet_index::(24); + // Handy utilities + is_pallet_index::(30); + is_pallet_index::(31); + is_pallet_index::(32); + is_pallet_index::(33); + is_pallet_index::(34); + is_pallet_index::(35); + is_pallet_index::(37); + // Ethereum compatibility + is_pallet_index::(50); + is_pallet_index::(51); + is_pallet_index::(52); + // Governance + is_pallet_index::(60); + // is_pallet_index::(61); Removed + // Council + // is_pallet_index::(70); Removed + // is_pallet_index::(71); Removed + is_pallet_index::(72); + is_pallet_index::(73); + // Treasury + is_pallet_index::(80); + // Crowdloan + is_pallet_index::(90); + // XCM Stuff + is_pallet_index::(100); + is_pallet_index::(101); + is_pallet_index::(102); + is_pallet_index::(103); + is_pallet_index::(104); + is_pallet_index::(105); + is_pallet_index::(106); + is_pallet_index::(107); +} + +#[test] +fn verify_reserved_indices() { + use frame_metadata::*; + let metadata = moonriver_runtime::Runtime::metadata(); + let metadata = match metadata.1 { + RuntimeMetadata::V14(metadata) => metadata, + _ => panic!("metadata has been bumped, test needs to be updated"), + }; + // 40: Sudo + // 53: BaseFee + // 108: pallet_assets:: + let reserved = vec![40, 53, 108]; + let existing = metadata + .pallets + .iter() + .map(|p| p.index) + .collect::>(); + assert!(reserved.iter().all(|index| !existing.contains(index))); +} + +#[test] +fn verify_proxy_type_indices() { + assert_eq!(moonriver_runtime::ProxyType::Any as u8, 0); + assert_eq!(moonriver_runtime::ProxyType::NonTransfer as u8, 1); + assert_eq!(moonriver_runtime::ProxyType::Governance as u8, 2); + assert_eq!(moonriver_runtime::ProxyType::Staking as u8, 3); + assert_eq!(moonriver_runtime::ProxyType::CancelProxy as u8, 4); + assert_eq!(moonriver_runtime::ProxyType::Balances as u8, 5); + assert_eq!(moonriver_runtime::ProxyType::AuthorMapping as u8, 6); + assert_eq!(moonriver_runtime::ProxyType::IdentityJudgement as u8, 7); +} + +#[test] +fn join_collator_candidates() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 20_000 * MOVR), + (AccountId::from(BOB), 20_000 * MOVR), + (AccountId::from(CHARLIE), 10_100 * MOVR), + (AccountId::from(DAVE), 10_000 * MOVR), + ]) + .with_collators(vec![ + (AccountId::from(ALICE), 10_000 * MOVR), + (AccountId::from(BOB), 10_000 * MOVR), + ]) + .with_delegations(vec![ + (AccountId::from(CHARLIE), AccountId::from(ALICE), 50 * MOVR), + (AccountId::from(CHARLIE), AccountId::from(BOB), 50 * MOVR), + ]) + .build() + .execute_with(|| { + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(ALICE)), + 10_000 * MOVR, + 2u32 + ), + pallet_parachain_staking::Error::::CandidateExists + ); + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 10_000 * MOVR, + 2u32 + ), + pallet_parachain_staking::Error::::DelegatorExists + ); + assert!(System::events().is_empty()); + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(DAVE)), + 10_000 * MOVR, + 2u32 + )); + assert_eq!( + last_event(), + RuntimeEvent::ParachainStaking( + pallet_parachain_staking::Event::JoinedCollatorCandidates { + account: AccountId::from(DAVE), + amount_locked: 10_000 * MOVR, + new_total_amt_locked: 30_100 * MOVR + } + ) + ); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(ALICE)); + assert_eq!(candidates.0[0].amount, 10_050 * MOVR); + assert_eq!(candidates.0[1].owner, AccountId::from(BOB)); + assert_eq!(candidates.0[1].amount, 10_050 * MOVR); + assert_eq!(candidates.0[2].owner, AccountId::from(DAVE)); + assert_eq!(candidates.0[2].amount, 10_000 * MOVR); + }); +} + +#[test] +fn transfer_through_evm_to_stake() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 20_000 * MOVR)]) + .build() + .execute_with(|| { + // Charlie has no balance => fails to stake + assert_noop!( + ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 10_000 * MOVR, + 2u32 + ), + DispatchError::Module(ModuleError { + index: 20, + error: [8, 0, 0, 0], + message: Some("InsufficientBalance") + }) + ); + // Alice transfer from free balance 20000 MOVR to Bob + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 20_000 * MOVR, + )); + assert_eq!(Balances::free_balance(AccountId::from(BOB)), 20_000 * MOVR); + + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + // Bob transfers 10000 MOVR to Charlie via EVM + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(CHARLIE), + input: vec![], + value: (10_000 * MOVR).into(), + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + assert_eq!( + Balances::free_balance(AccountId::from(CHARLIE)), + 10_000 * MOVR, + ); + + // Charlie can stake now + assert_ok!(ParachainStaking::join_candidates( + origin_of(AccountId::from(CHARLIE)), + 10_000 * MOVR, + 2u32, + ),); + let candidates = ParachainStaking::candidate_pool(); + assert_eq!(candidates.0[0].owner, AccountId::from(CHARLIE)); + assert_eq!(candidates.0[0].amount, 10_000 * MOVR); + }); +} + +#[test] +fn reward_block_authors() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 100 extra tokens for her mapping deposit + (AccountId::from(ALICE), 20_100 * MOVR), + (AccountId::from(BOB), 10_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 10_000 * MOVR)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + for x in 2..1199 { + run_to_block(x, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + } + // no rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 10_100 * MOVR, + ); + assert_eq!(Balances::usable_balance(AccountId::from(BOB)), 9500 * MOVR,); + run_to_block(1201, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 11547666666208000000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9557333332588000000000, + ); + }); +} + +#[test] +fn reward_block_authors_with_parachain_bond_reserved() { + ExtBuilder::default() + .with_balances(vec![ + // Alice gets 100 extra tokens for her mapping deposit + (AccountId::from(ALICE), 20_100 * MOVR), + (AccountId::from(BOB), 10_000 * MOVR), + (AccountId::from(CHARLIE), MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 10_000 * MOVR)]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + assert_ok!(ParachainStaking::set_parachain_bond_account( + root_origin(), + AccountId::from(CHARLIE), + ),); + + run_to_block(1199, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + // no collator rewards doled out yet + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 10_100 * MOVR, + ); + assert_eq!(Balances::usable_balance(AccountId::from(BOB)), 9500 * MOVR,); + + // 30% reserved for parachain bond + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 452515000000000000000, + ); + + run_to_block(1201, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + // rewards minted and distributed + assert_eq!( + Balances::usable_balance(AccountId::from(ALICE)), + 11117700475903800000000, + ); + assert_eq!( + Balances::usable_balance(AccountId::from(BOB)), + 9535834523343675000000, + ); + // 30% reserved for parachain bond again + assert_eq!( + Balances::usable_balance(AccountId::from(CHARLIE)), + 910802725000000000000, + ); + }); +} + +#[test] +fn initialize_crowdloan_addresses_with_batch_and_pay() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 48 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 450_000 * MOVR); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 450_000 * MOVR); + let expected = RuntimeEvent::Utility(pallet_utility::Event::BatchCompleted); + assert_eq!(last_event(), expected); + // This one should fail, as we already filled our data + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch { + calls: vec![RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![([4u8; 32].into(), Some(AccountId::from(ALICE)), 432000)] + } + )] + }) + .dispatch(root_origin()) + ); + let expected_fail = RuntimeEvent::Utility(pallet_utility::Event::BatchInterrupted { + index: 0, + error: DispatchError::Module(ModuleError { + index: 90, + error: [8, 0, 0, 0], + message: None, + }), + }); + assert_eq!(last_event(), expected_fail); + // Claim 1 block. + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(CHARLIE)))); + assert_ok!(CrowdloanRewards::claim(origin_of(AccountId::from(DAVE)))); + + let vesting_period = 48 * WEEKS as u128; + let per_block = (1_050_000 * MOVR) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (450_000 * MOVR) + per_block + ); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (450_000 * MOVR) + per_block + ); + // The total claimed reward should be equal to the account balance at this point. + assert_eq!( + Balances::balance(&AccountId::from(CHARLIE)), + (450_000 * MOVR) + per_block + ); + assert_eq!( + Balances::balance(&AccountId::from(DAVE)), + (450_000 * MOVR) + per_block + ); + assert_noop!( + CrowdloanRewards::claim(origin_of(AccountId::from(ALICE))), + pallet_crowdloan_rewards::Error::::NoAssociatedClaim + ); + }); +} + +#[test] +fn initialize_crowdloan_address_and_change_with_relay_key_sig() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + + let (pair1, _) = sp_core::sr25519::Pair::generate(); + let (pair2, _) = sp_core::sr25519::Pair::generate(); + + let public1 = pair1.public(); + let public2 = pair2.public(); + + // signature: + // WRAP_BYTES|| NetworkIdentifier|| new_account || previous_account || WRAP_BYTES + let mut message = pallet_crowdloan_rewards::WRAPPED_BYTES_PREFIX.to_vec(); + message.append(&mut b"moonriver-".to_vec()); + message.append(&mut AccountId::from(DAVE).encode()); + message.append(&mut AccountId::from(CHARLIE).encode()); + message.append(&mut pallet_crowdloan_rewards::WRAPPED_BYTES_POSTFIX.to_vec()); + let signature1 = pair1.sign(&message); + let signature2 = pair2.sign(&message); + + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + // two relay accounts pointing at the same reward account + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public1.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + public2.into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 900_000 * MOVR); + + // this should fail, as we are only providing one signature + assert_noop!( + CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![(public1.into(), signature1.clone().into())] + ), + pallet_crowdloan_rewards::Error::::InsufficientNumberOfValidProofs + ); + + // this should be valid + assert_ok!(CrowdloanRewards::change_association_with_relay_keys( + origin_of(AccountId::from(CHARLIE)), + AccountId::from(DAVE), + AccountId::from(CHARLIE), + vec![ + (public1.into(), signature1.into()), + (public2.into(), signature2.into()) + ] + )); + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(DAVE)) + .unwrap() + .claimed_reward, + (900_000 * MOVR) + ); + }); +} + +#[test] +fn claim_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + assert!(CrowdloanRewards::initialized()); + + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(CHARLIE)), 450_000 * MOVR); + // 30 percent initial payout + assert_eq!(Balances::balance(&AccountId::from(DAVE)), 450_000 * MOVR); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Alice uses the crowdloan precompile to claim through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + + // Construct the call data (selector, amount) + let mut call_data = Vec::::from([0u8; 4]); + call_data[0..4].copy_from_slice(&Keccak256::digest(b"claim()")[0..4]); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let vesting_period = 4 * WEEKS as u128; + let per_block = (1_050_000 * MOVR) / vesting_period; + + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)) + .unwrap() + .claimed_reward, + (450_000 * MOVR) + per_block + ); + }) +} + +#[test] +fn is_contributor_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Assert precompile reports Bob is not a contributor + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(AccountId::from(BOB).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(false); + + // Assert precompile reports Charlie is a nominator + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::is_contributor { + contributor: Address(AccountId::from(CHARLIE).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(true); + }) +} + +#[test] +fn reward_info_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + let expected_total: U256 = (1_500_000 * MOVR).into(); + let expected_claimed: U256 = (450_000 * MOVR).into(); + + // Assert precompile reports correct Charlie reward info. + Precompiles::new() + .prepare_test( + ALICE, + crowdloan_precompile_address, + CrowdloanRewardsPCall::reward_info { + contributor: Address(AccountId::from(CHARLIE).into()), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns((expected_total, expected_claimed)); + }) +} + +#[test] +fn update_reward_address_via_precompile() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_crowdloan_fund(3_000_000 * MOVR) + .build() + .execute_with(|| { + // set parachain inherent data + set_parachain_inherent_data(); + let init_block = CrowdloanRewards::init_vesting_block(); + // This matches the previous vesting + let end_block = init_block + 4 * WEEKS; + // Batch calls always succeed. We just need to check the inner event + assert_ok!( + RuntimeCall::Utility(pallet_utility::Call::::batch_all { + calls: vec![ + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [4u8; 32].into(), + Some(AccountId::from(CHARLIE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::initialize_reward_vec { + rewards: vec![( + [5u8; 32].into(), + Some(AccountId::from(DAVE)), + 1_500_000 * MOVR + )] + } + ), + RuntimeCall::CrowdloanRewards( + pallet_crowdloan_rewards::Call::::complete_initialization { + lease_ending_block: end_block + } + ) + ] + }) + .dispatch(root_origin()) + ); + + let crowdloan_precompile_address = H160::from_low_u64_be(2049); + + // Charlie uses the crowdloan precompile to update address through the EVM + let gas_limit = 100000u64; + let gas_price: U256 = BASE_FEE_GENESIS.into(); + + // Construct the input data to check if Bob is a contributor + let mut call_data = Vec::::from([0u8; 36]); + call_data[0..4] + .copy_from_slice(&Keccak256::digest(b"update_reward_address(address)")[0..4]); + call_data[16..36].copy_from_slice(&ALICE); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(CHARLIE), + target: crowdloan_precompile_address, + input: call_data, + value: U256::zero(), // No value sent in EVM + gas_limit, + max_fee_per_gas: gas_price, + max_priority_fee_per_gas: None, + nonce: None, // Use the next nonce + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + assert!(CrowdloanRewards::accounts_payable(&AccountId::from(CHARLIE)).is_none()); + assert_eq!( + CrowdloanRewards::accounts_payable(&AccountId::from(ALICE)) + .unwrap() + .claimed_reward, + (450_000 * MOVR) + ); + }) +} + +fn run_with_system_weight(w: Weight, mut assertions: F) +where + F: FnMut() -> (), +{ + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); +} + +#[test] +#[rustfmt::skip] +fn length_fee_is_sensible() { + use sp_runtime::testing::TestXt; + + // tests that length fee is sensible for a few hypothetical transactions + ExtBuilder::default().build().execute_with(|| { + let call = frame_system::Call::remark:: { remark: vec![] }; + let uxt: TestXt<_, ()> = TestXt::new(call, Some((1u64, ()))); + + let calc_fee = |len: u32| -> Balance { + moonriver_runtime::TransactionPayment::query_fee_details(uxt.clone(), len) + .inclusion_fee + .expect("fee should be calculated") + .len_fee + }; + + // editorconfig-checker-disable + // left: cost of length fee, right: size in bytes + // /------------- proportional component: O(N * 1B) + // | /- exponential component: O(N ** 3) + // | | + assert_eq!( 1_000_000_001, calc_fee(1)); + assert_eq!( 10_000_001_000, calc_fee(10)); + assert_eq!( 100_001_000_000, calc_fee(100)); + assert_eq!( 1_001_000_000_000, calc_fee(1_000)); + assert_eq!( 11_000_000_000_000, calc_fee(10_000)); // inflection point + assert_eq!( 1_100_000_000_000_000, calc_fee(100_000)); + assert_eq!( 1_001_000_000_000_000_000, calc_fee(1_000_000)); // one MOVR, ~ 1MB + assert_eq!( 1_000_010_000_000_000_000_000, calc_fee(10_000_000)); + assert_eq!(1_000_000_100_000_000_000_000_000, calc_fee(100_000_000)); + // editorconfig-checker-enable + }); +} + +#[test] +fn multiplier_can_grow_from_zero() { + use frame_support::traits::Get; + + let minimum_multiplier = moonriver_runtime::MinimumMultiplier::get(); + let target = moonriver_runtime::TargetBlockFullness::get() + * RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = + moonriver_runtime::SlowAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) +} + +#[test] +fn ethereum_invalid_transaction() { + ExtBuilder::default().build().execute_with(|| { + // Ensure an extrinsic not containing enough gas limit to store the transaction + // on chain is rejected. + assert_eq!( + Executive::apply_extrinsic(unchecked_eth_tx(INVALID_ETH_TX)), + Err( + sp_runtime::transaction_validity::TransactionValidityError::Invalid( + sp_runtime::transaction_validity::InvalidTransaction::Custom(0u8) + ) + ) + ); + }); +} + +#[test] +fn initial_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + + ExtBuilder::default().build().execute_with(|| { + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(10u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 12_500_000_000u128.into(), + Weight::from_parts(25_000_000u64, 0) + ) + ); + }); +} + +#[test] +fn min_gas_fee_is_correct() { + use fp_evm::FeeCalculator; + use frame_support::traits::Hooks; + + ExtBuilder::default().build().execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::put(Multiplier::from(0)); + TransactionPayment::on_finalize(System::block_number()); // should trigger min to kick in + + let multiplier = TransactionPayment::next_fee_multiplier(); + assert_eq!(multiplier, Multiplier::from(1u128)); + + assert_eq!( + TransactionPaymentAsGasPrice::min_gas_price(), + ( + 1_250_000_000u128.into(), + Weight::from_parts(25_000_000u64, 0) + ) + ); + }); +} + +#[test] +fn transfer_ed_0_substrate() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), (1 * MOVR) + (1 * WEI)), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // Substrate transfer + assert_ok!(Balances::transfer_allow_death( + origin_of(AccountId::from(ALICE)), + AccountId::from(BOB), + 1 * MOVR, + )); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI); + }); +} + +#[test] +fn transfer_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * MOVR) + (21_000 * BASE_FEE_GENESIS)) + (1 * WEI), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * MOVR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(BASE_FEE_GENESIS), + max_priority_fee_per_gas: Some(U256::from(BASE_FEE_GENESIS)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // 1 WEI is left in the account + assert_eq!(Balances::free_balance(AccountId::from(ALICE)), 1 * WEI,); + }); +} + +#[test] +fn refund_ed_0_evm() { + ExtBuilder::default() + .with_balances(vec![ + ( + AccountId::from(ALICE), + ((1 * MOVR) + (21_777 * BASE_FEE_GENESIS)), + ), + (AccountId::from(BOB), 0), + ]) + .build() + .execute_with(|| { + // EVM transfer that zeroes ALICE + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(ALICE), + target: H160::from(BOB), + input: Vec::new(), + value: (1 * MOVR).into(), + gas_limit: 21_777u64, + max_fee_per_gas: U256::from(BASE_FEE_GENESIS), + max_priority_fee_per_gas: Some(U256::from(BASE_FEE_GENESIS)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // ALICE is refunded + assert_eq!( + Balances::free_balance(AccountId::from(ALICE)), + 777 * BASE_FEE_GENESIS, + ); + }); +} + +#[test] +fn author_does_not_receive_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * MOVR) + (21_000 * (500 * GIGAWEI)), + )]) + .build() + .execute_with(|| { + // Some block author as seen by pallet-evm. + let author = AccountId::from(>::find_author()); + // Currently the default impl of the evm uses `deposit_into_existing`. + // If we were to use this implementation, and for an author to receive eventual tips, + // the account needs to be somehow initialized, otherwise the deposit would fail. + Balances::make_free_balance_be(&author, 100 * MOVR); + + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * MOVR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(300 * GIGAWEI), + max_priority_fee_per_gas: Some(U256::from(200 * GIGAWEI)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + // Author free balance didn't change. + assert_eq!(Balances::free_balance(author), 100 * MOVR,); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_with_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * MOVR) + (21_000 * (2 * BASE_FEE_GENESIS)), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * MOVR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(2u128 * BASE_FEE_GENESIS), + max_priority_fee_per_gas: Some(U256::from(2u128 * BASE_FEE_GENESIS)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + let fee = ((2 * BASE_FEE_GENESIS) * 21_000) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonriver_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn total_issuance_after_evm_transaction_without_priority_fee() { + ExtBuilder::default() + .with_balances(vec![( + AccountId::from(BOB), + (1 * MOVR) + (21_000 * (2 * BASE_FEE_GENESIS)), + )]) + .build() + .execute_with(|| { + let issuance_before = ::Currency::total_issuance(); + // EVM transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::::call { + source: H160::from(BOB), + target: H160::from(ALICE), + input: Vec::new(), + value: (1 * MOVR).into(), + gas_limit: 21_000u64, + max_fee_per_gas: U256::from(BASE_FEE_GENESIS), + max_priority_fee_per_gas: Some(U256::from(BASE_FEE_GENESIS)), + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let issuance_after = ::Currency::total_issuance(); + let fee = ((1 * BASE_FEE_GENESIS) * 21_000) as f64; + // 80% was burned. + let expected_burn = (fee * 0.8) as u128; + assert_eq!(issuance_after, issuance_before - expected_burn,); + // 20% was sent to treasury. + let expected_treasury = (fee * 0.2) as u128; + assert_eq!(moonriver_runtime::Treasury::pot(), expected_treasury); + }); +} + +#[test] +fn root_can_change_default_xcm_vers() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let source_id: moonriver_runtime::AssetId = source_location.clone().into(); + // Default XCM version is not set yet, so xtokens should fail because it does not + // know with which version to send + assert_noop!( + XTokens::transfer( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest.clone())), + WeightLimit::Limited(4000000000.into()) + ), + orml_xtokens::Error::::XcmExecutionFailed + ); + + // Root sets the defaultXcm + assert_ok!(PolkadotXcm::force_default_xcm_version( + root_origin(), + Some(2) + )); + + // Now transferring does not fail + assert_ok!(XTokens::transfer( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + Box::new(xcm::VersionedLocation::V4(dest)), + WeightLimit::Limited(4000000000.into()) + )); + }) +} + +#[test] +fn asset_can_be_registered() { + ExtBuilder::default().build().execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: moonriver_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( + moonriver_runtime::RuntimeOrigin::root(), + source_location, + asset_metadata, + 1u128, + true + )); + assert!(AssetManager::asset_id_type(source_id).is_some()); + }); +} + +#[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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * MOVR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Assert the asset has been created with the correct supply + assert_eq!( + moonriver_runtime::Assets::total_supply(relay_asset_id), + 1_000 * MOVR + ); + + // Access totalSupply through precompile. Important that the context is correct + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::total_supply {}, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * MOVR)); + + // Access balanceOf through precompile + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(ALICE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(1000 * MOVR)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * MOVR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Transfer tokens from Aice to Bob, 400 MOVR. + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::transfer { + to: Address(BOB.into()), + value: { 400 * MOVR }.into(), + }, + ) + .expect_cost(24377) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * MOVR)), + )) + .execute_returns(true); + + // Make sure BOB has 400 MOVR + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(BOB.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * MOVR)); + }); +} + +#[test] +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, + }, + balances: vec![(AccountId::from(ALICE), 1_000 * MOVR)], + is_sufficient: true, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .build() + .execute_with(|| { + // We have the assetId that corresponds to the relay chain registered + let relay_asset_id: AssetId = AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Aprove Bob for spending 400 MOVR from Alice + Precompiles::new() + .prepare_test( + ALICE, + asset_precompile_address, + ForeignAssetsPCall::approve { + spender: Address(BOB.into()), + value: { 400 * MOVR }.into(), + }, + ) + .expect_cost(14429) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_APPROVAL, + H160::from(ALICE), + H160::from(BOB), + solidity::encode_event_data(U256::from(400 * MOVR)), + )) + .execute_returns(true); + + // Transfer tokens from Alice to Charlie by using BOB as origin + Precompiles::new() + .prepare_test( + BOB, + asset_precompile_address, + ForeignAssetsPCall::transfer_from { + from: Address(ALICE.into()), + to: Address(CHARLIE.into()), + value: { 400 * MOVR }.into(), + }, + ) + .expect_cost(29748) + .expect_log(log3( + asset_precompile_address, + SELECTOR_LOG_TRANSFER, + H160::from(ALICE), + H160::from(CHARLIE), + solidity::encode_event_data(U256::from(400 * MOVR)), + )) + .execute_returns(true); + + // Make sure CHARLIE has 400 MOVR + Precompiles::new() + .prepare_test( + CHARLIE, + asset_precompile_address, + ForeignAssetsPCall::balance_of { + who: Address(CHARLIE.into()), + }, + ) + .expect_cost(2000) + .expect_no_logs() + .execute_returns(U256::from(400 * MOVR)); + }); +} + +#[test] +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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + 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: moonriver_runtime::AssetId = + AssetType::Xcm(xcm::v3::Location::parent()).into(); + + // Its address is + let asset_precompile_address = Runtime::asset_id_to_account( + FOREIGN_ASSET_PRECOMPILE_ADDRESS_PREFIX, + relay_asset_id, + ); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // We use the address of the asset as an identifier of the asset we want to transferS + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer { + currency_address: Address(asset_precompile_address.into()), + amount: 500_000_000_000_000u128.into(), + destination: destination.clone(), + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()) + }) +} + +#[test] +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, + }]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + let xtokens_precompile_address = H160::from_low_u64_be(2052); + + // Alice has 1000 tokens. She should be able to send through precompile + let destination = Location::new( + 1, + [Junction::AccountId32 { + network: None, + id: [1u8; 32], + }], + ); + + // This time we transfer it through TransferMultiAsset + // Instead of the address, we encode directly the multilocation referencing the asset + Precompiles::new() + .prepare_test( + ALICE, + xtokens_precompile_address, + XtokensPCall::transfer_multiasset { + // We want to transfer the relay token + asset: Location::parent(), + amount: 500_000_000_000_000u128.into(), + destination, + weight: 4_000_000, + }, + ) + .expect_cost(57639) + .expect_no_logs() + .execute_returns(()); + }) +} + +#[test] +fn make_sure_polkadot_xcm_cannot_be_called() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let assets: Assets = [Asset { + id: AssetId(moonriver_runtime::xcm_config::SelfLocation::get()), + fun: Fungible(1000), + }] + .to_vec() + .into(); + assert_noop!( + RuntimeCall::PolkadotXcm(pallet_xcm::Call::::reserve_transfer_assets { + dest: Box::new(VersionedLocation::V4(dest.clone())), + beneficiary: Box::new(VersionedLocation::V4(dest)), + assets: Box::new(VersionedAssets::V4(assets)), + fee_asset_item: 0, + }) + .dispatch(::RuntimeOrigin::signed( + AccountId::from(ALICE) + )), + frame_system::Error::::CallFiltered + ); + }); +} + +#[test] +fn transactor_cannot_use_more_than_max_weight() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: moonriver_runtime::AssetId = source_location.clone().into(); + assert_ok!(XcmTransactor::register( + root_origin(), + AccountId::from(ALICE), + 0, + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000.into(), + None + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + root_origin(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + 1 + )); + + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonriver_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + vec![], + // 2000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + assert_noop!( + XcmTransactor::transact_through_derivative( + origin_of(AccountId::from(ALICE)), + moonriver_runtime::xcm_config::Transactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsCurrencyId(CurrencyId::ForeignAsset(source_id)), + fee_amount: None + }, + vec![], + // 20000 is the max + TransactWeights { + transact_required_weight_at_most: 17001.into(), + overall_weight: None + }, + false + ), + pallet_xcm_transactor::Error::::MaxWeightTransactReached + ); + }) +} + +#[test] +fn transact_through_signed_precompile_works_v2() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::parent(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .expect_cost(17559) + .expect_no_logs() + .execute_returns(()); + }); +} + +#[test] +fn transact_through_signed_cannot_send_to_local_chain() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_safe_xcm_version(2) + .build() + .execute_with(|| { + // Destination + let dest = Location::here(); + + let fee_payer_asset = Location::parent(); + + let bytes = vec![1u8, 2u8, 3u8]; + + let total_weight = 1_000_000_000u64; + + let xcm_transactor_v2_precompile_address = H160::from_low_u64_be(2061); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_transactor_v2_precompile_address, + XcmTransactorV2PCall::transact_through_signed_multilocation { + dest, + fee_asset: fee_payer_asset, + weight: 4_000_000, + call: bytes.into(), + fee_amount: u128::from(total_weight).into(), + overall_weight: total_weight, + }, + ) + .execute_reverts(|output| { + from_utf8(&output) + .unwrap() + .contains("Dispatched call failed with error:") + && from_utf8(&output).unwrap().contains("ErrorValidating") + }); + }); +} + +#[test] +fn call_xtokens_with_fee() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_safe_xcm_version(2) + .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, + }]) + .build() + .execute_with(|| { + let source_location = AssetType::Xcm(xcm::v3::Location::parent()); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: [1u8; 32], + }] + .into(), + }; + let source_id: moonriver_runtime::AssetId = source_location.clone().into(); + + let before_balance = + moonriver_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); + + // We are able to transfer with fee + assert_ok!(XTokens::transfer_with_fee( + origin_of(AccountId::from(ALICE)), + CurrencyId::ForeignAsset(source_id), + 100_000_000_000_000, + 100, + Box::new(xcm::VersionedLocation::V4(dest.clone())), + WeightLimit::Limited(4000000000.into()) + ),); + + let after_balance = + moonriver_runtime::Assets::balance(source_id, &AccountId::from(ALICE)); + // At least these much (plus fees) should have been charged + assert_eq!(before_balance - 100_000_000_000_000 - 100, after_balance); + }); +} + +#[test] +fn test_xcm_utils_ml_tp_account() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_address_parent: H160 = + ParentIsPreset::::convert_location(&Location::parent()) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: Location::parent(), + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parent)); + + let parachain_2000_multilocation = Location::new(1, [Parachain(2000)]); + let expected_address_parachain: H160 = + SiblingParachainConvertsVia::::convert_location( + ¶chain_2000_multilocation, + ) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: parachain_2000_multilocation, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_parachain)); + + let alice_in_parachain_2000_location = Location::new( + 1, + [ + Parachain(2000), + AccountKey20 { + network: None, + key: ALICE, + }, + ], + ); + let expected_address_alice_in_parachain_2000 = + xcm_builder::HashedDescription::< + AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&alice_in_parachain_2000_location) + .unwrap() + .into(); + + Precompiles::new() + .prepare_test( + ALICE, + xcm_utils_precompile_address, + XcmUtilsPCall::multilocation_to_address { + location: alice_in_parachain_2000_location, + }, + ) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(Address(expected_address_alice_in_parachain_2000)); + }); +} + +#[test] +fn test_xcm_utils_weight_message() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let expected_weight = + XcmWeight::::clear_origin().ref_time(); + + let message: Vec = xcm::VersionedXcm::<()>::V4(Xcm(vec![ClearOrigin])).encode(); + + let input = XcmUtilsPCall::weight_message { + message: message.into(), + }; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(0) + .expect_no_logs() + .execute_returns(expected_weight); + }); +} + +#[test] +fn test_xcm_utils_get_units_per_second() { + ExtBuilder::default().build().execute_with(|| { + let xcm_utils_precompile_address = H160::from_low_u64_be(2060); + let location = SelfReserve::get(); + + let input = XcmUtilsPCall::get_units_per_second { location }; + + let expected_units = + WEIGHT_REF_TIME_PER_SECOND as u128 * moonriver_runtime::currency::WEIGHT_FEE; + + Precompiles::new() + .prepare_test(ALICE, xcm_utils_precompile_address, input) + .expect_cost(1000) + .expect_no_logs() + .execute_returns(expected_units); + }); +} + +#[test] +fn precompile_existence() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + let precompile_addresses: std::collections::BTreeSet<_> = vec![ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 1024, 1025, 1026, 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, + ] + .into_iter() + .map(H160::from_low_u64_be) + .collect(); + + for i in 0..3000 { + let address = H160::from_low_u64_be(i); + + if precompile_addresses.contains(&address) { + assert!( + is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return true", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_some(), + "execute({},..) should return Some(_)", + i + ); + } else { + assert!( + !is_precompile_or_fail::(address, 100_000u64).expect("to be ok"), + "is_precompile({}) should return false", + i + ); + + assert!( + precompiles + .execute(&mut MockHandle::new( + address, + Context { + address, + caller: H160::zero(), + apparent_value: U256::zero() + } + ),) + .is_none(), + "execute({},..) should return None", + i + ); + } + } + }); +} + +#[test] +fn removed_precompiles() { + ExtBuilder::default().build().execute_with(|| { + let precompiles = Precompiles::new(); + let removed_precompiles = [1025, 2051, 2062, 2063]; + + for i in 1..3000 { + let address = H160::from_low_u64_be(i); + + if !is_precompile_or_fail::(address, 100_000u64).expect("to be ok") { + continue; + } + + if !removed_precompiles.contains(&i) { + assert!( + match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} should be an active precompile" + ); + continue; + } + + assert!( + !match precompiles.is_active_precompile(address, 100_000u64) { + IsPrecompileResult::Answer { is_precompile, .. } => is_precompile, + _ => false, + }, + "{i} shouldn't be an active precompile" + ); + + precompiles + .prepare_test(Alice, address, []) + .execute_reverts(|out| out == b"Removed precompile"); + } + }) +} + +#[test] +fn deal_with_fees_handles_tip() { + use frame_support::traits::OnUnbalanced; + use moonriver_runtime::{DealWithFees, Treasury}; + + ExtBuilder::default().build().execute_with(|| { + // This test checks the functionality of the `DealWithFees` trait implementation in the runtime. + // It simulates a scenario where a fee and a tip are issued to an account and ensures that the + // treasury receives the correct amount (20% of the total), and the rest is burned (80%). + // + // The test follows these steps: + // 1. It issues a fee of 100 and a tip of 1000. + // 2. It checks the total supply before the fee and tip are dealt with, which should be 1_100. + // 3. It checks that the treasury's balance is initially 0. + // 4. It calls `DealWithFees::on_unbalanceds` with the fee and tip. + // 5. It checks that the treasury's balance is now 220 (20% of the fee and tip). + // 6. It checks that the total supply has decreased by 880 (80% of the fee and tip), indicating + // that this amount was burned. + let fee = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(100); + let tip = as frame_support::traits::fungible::Balanced< + AccountId, + >>::issue(1000); + + let total_supply_before = Balances::total_issuance(); + assert_eq!(total_supply_before, 1_100); + assert_eq!(Balances::free_balance(&Treasury::account_id()), 0); + + DealWithFees::on_unbalanceds(vec![fee, tip].into_iter()); + + // treasury should have received 20% + assert_eq!(Balances::free_balance(&Treasury::account_id()), 220); + + // verify 80% burned + let total_supply_after = Balances::total_issuance(); + assert_eq!(total_supply_before - total_supply_after, 880); + }); +} + +#[test] +fn evm_revert_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + // Batch a transfer followed by an invalid call to batch. + // Thus BatchAll will revert the transfer. + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + input: BatchPCall::batch_all { + to: vec![Address(BOB.into()), Address(batch_precompile_address)].into(), + value: vec![U256::from(1 * MOVR), U256::zero()].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: U256::from(BASE_FEE_GENESIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 0, "there should be no transfer event"); + }); +} + +#[test] +fn evm_success_keeps_substrate_events() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .build() + .execute_with(|| { + let batch_precompile_address = H160::from_low_u64_be(2056); + + assert_ok!(RuntimeCall::EVM(pallet_evm::Call::call { + source: ALICE.into(), + target: batch_precompile_address, + input: BatchPCall::batch_all { + to: vec![Address(BOB.into())].into(), + value: vec![U256::from(1 * MOVR)].into(), + call_data: vec![].into(), + gas_limit: vec![].into() + } + .into(), + value: U256::zero(), // No value sent in EVM + gas_limit: 500_000, + max_fee_per_gas: U256::from(BASE_FEE_GENESIS), + max_priority_fee_per_gas: None, + nonce: Some(U256::from(0)), + access_list: Vec::new(), + }) + .dispatch(::RuntimeOrigin::root())); + + let transfer_count = System::events() + .iter() + .filter(|r| match r.event { + RuntimeEvent::Balances(pallet_balances::Event::Transfer { .. }) => true, + _ => false, + }) + .count(); + + assert_eq!(transfer_count, 1, "there should be 1 transfer event"); + }); +} + +#[cfg(test)] +mod fee_tests { + use super::*; + use frame_support::{ + traits::ConstU128, + weights::{ConstantMultiplier, WeightToFee}, + }; + use moonriver_runtime::{ + currency, LengthToFee, MinimumMultiplier, RuntimeBlockWeights, SlowAdjustingFeeUpdate, + TargetBlockFullness, TransactionPayment, + }; + use sp_core::Get; + use sp_runtime::FixedPointNumber; + + fn run_with_system_weight(w: Weight, mut assertions: F) + where + F: FnMut() -> (), + { + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + System::set_block_consumed_resources(w, 0); + assertions() + }); + } + + #[test] + fn test_multiplier_can_grow_from_zero() { + let minimum_multiplier = MinimumMultiplier::get(); + let target = TargetBlockFullness::get() + * RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .max_total + .unwrap(); + // if the min is too small, then this will not change, and we are doomed forever. + // the weight is 1/100th bigger than target. + run_with_system_weight(target * 101 / 100, || { + let next = SlowAdjustingFeeUpdate::::convert(minimum_multiplier); + assert!( + next > minimum_multiplier, + "{:?} !>= {:?}", + next, + minimum_multiplier + ); + }) + } + + #[test] + fn test_fee_calculation() { + let base_extrinsic = RuntimeBlockWeights::get() + .get(DispatchClass::Normal) + .base_extrinsic; + let multiplier = sp_runtime::FixedU128::from_float(0.999000000000000000); + let extrinsic_len = 100u32; + let extrinsic_weight = Weight::from_parts(5_000u64, 1); + let tip = 42u128; + type WeightToFeeImpl = ConstantMultiplier>; + type LengthToFeeImpl = LengthToFee; + + // base_fee + (multiplier * extrinsic_weight_fee) + extrinsic_length_fee + tip + let expected_fee = WeightToFeeImpl::weight_to_fee(&base_extrinsic) + + multiplier.saturating_mul_int(WeightToFeeImpl::weight_to_fee(&extrinsic_weight)) + + LengthToFeeImpl::weight_to_fee(&(Weight::from_parts(extrinsic_len as u64, 1))) + + tip; + + let mut t: sp_io::TestExternalities = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap() + .into(); + t.execute_with(|| { + pallet_transaction_payment::NextFeeMultiplier::::set(multiplier); + let actual_fee = TransactionPayment::compute_fee( + extrinsic_len, + &frame_support::dispatch::DispatchInfo { + class: DispatchClass::Normal, + pays_fee: frame_support::dispatch::Pays::Yes, + weight: extrinsic_weight, + }, + tip, + ); + + assert_eq!( + expected_fee, + actual_fee, + "The actual fee did not match the expected fee, diff {}", + actual_fee - expected_fee + ); + }); + } +} diff --git a/tracing/2902/runtime/moonriver/tests/runtime_apis.rs b/tracing/2902/runtime/moonriver/tests/runtime_apis.rs new file mode 100644 index 00000000..020ae32f --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/runtime_apis.rs @@ -0,0 +1,396 @@ +// 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 . + +//! Moonriver Runtime Api Integration Tests + +mod common; +use common::*; + +use fp_evm::GenesisAccount; +use frame_support::assert_ok; +use nimbus_primitives::NimbusId; +use pallet_evm::{Account as EVMAccount, AddressMapping, FeeCalculator}; +use sp_core::{ByteArray, H160, H256, U256}; + +use fp_rpc::runtime_decl_for_ethereum_runtime_rpc_api::EthereumRuntimeRPCApi; +use moonbeam_rpc_primitives_txpool::runtime_decl_for_tx_pool_runtime_api::TxPoolRuntimeApi; +use nimbus_primitives::runtime_decl_for_nimbus_api::NimbusApi; +use std::{collections::BTreeMap, str::FromStr}; + +#[test] +fn ethereum_runtime_rpc_api_chain_id() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!(Runtime::chain_id(), CHAIN_ID); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_basic() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * MOVR)]) + .build() + .execute_with(|| { + assert_eq!( + Runtime::account_basic(H160::from(ALICE)), + EVMAccount { + balance: U256::from(2_000 * MOVR), + nonce: U256::zero() + } + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_gas_price() { + ExtBuilder::default().build().execute_with(|| { + assert_eq!( + Runtime::gas_price(), + TransactionPaymentAsGasPrice::min_gas_price().0 + ); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_account_code_at() { + let address = H160::from(EVM_CONTRACT); + let code: Vec = vec![1, 2, 3, 4, 5]; + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: code.clone(), + nonce: Default::default(), + storage: Default::default(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::account_code_at(address), code); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_author() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + assert_eq!(Runtime::author(), H160::from(ALICE)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_storage_at() { + let address = H160::from(EVM_CONTRACT); + let mut key = [0u8; 32]; + key[31..32].copy_from_slice(&[6u8][..]); + let mut value = [0u8; 32]; + value[31..32].copy_from_slice(&[7u8][..]); + let item = H256::from_slice(&key[..]); + let mut storage: BTreeMap = BTreeMap::new(); + storage.insert(H256::from_slice(&key[..]), item); + ExtBuilder::default() + .with_evm_accounts({ + let mut map = BTreeMap::new(); + map.insert( + address, + GenesisAccount { + balance: U256::zero(), + code: Vec::new(), + nonce: Default::default(), + storage: storage.clone(), + }, + ); + map + }) + .build() + .execute_with(|| { + assert_eq!(Runtime::storage_at(address, U256::from(6)), item); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_call() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 2_000 * MOVR), + ]) + .build() + .execute_with(|| { + let execution_result = Runtime::call( + H160::from(ALICE), // from + H160::from(BOB), // to + Vec::new(), // data + U256::from(1000u64), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_create() { + ExtBuilder::default() + .with_balances(vec![(AccountId::from(ALICE), 2_000 * MOVR)]) + .build() + .execute_with(|| { + let execution_result = Runtime::create( + H160::from(ALICE), // from + vec![0, 1, 1, 0], // data + U256::zero(), // value + U256::from(100000u64), // gas_limit + None, // max_fee_per_gas + None, // max_priority_fee_per_gas + None, // nonce + false, // estimate + None, // access_list + ); + assert!(execution_result.is_ok()); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_transaction_statuses() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24ff3a9cf04c71dbc94d0b566f7a27b94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 2_000 * MOVR), + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + // set_author(NimbusId::from_slice(&ALICE_NIMBUS)); + let result = + Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)).expect("Apply result."); + assert_eq!(result, Ok(())); + rpc_run_to_block(2); + let statuses = + Runtime::current_transaction_statuses().expect("Transaction statuses result."); + assert_eq!(statuses.len(), 1); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_block() { + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + // set_author(NimbusId::from_slice(&ALICE_NIMBUS)); + rpc_run_to_block(2); + let block = Runtime::current_block().expect("Block result."); + assert_eq!(block.header.number, U256::from(1u8)); + }); +} + +#[test] +fn ethereum_runtime_rpc_api_current_receipts() { + let alith = ::AddressMapping::into_account_id( + H160::from_str("f24ff3a9cf04c71dbc94d0b566f7a27b94566cac") + .expect("internal H160 is valid; qed"), + ); + ExtBuilder::default() + .with_collators(vec![(AccountId::from(ALICE), 1_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .with_balances(vec![ + (alith, 2_000 * MOVR), + (AccountId::from(ALICE), 2_000 * MOVR), + (AccountId::from(BOB), 1_000 * MOVR), + ]) + .with_delegations(vec![( + AccountId::from(BOB), + AccountId::from(ALICE), + 500 * MOVR, + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + // set_author(NimbusId::from_slice(&ALICE_NIMBUS)); + let result = + Executive::apply_extrinsic(unchecked_eth_tx(VALID_ETH_TX)).expect("Apply result."); + assert_eq!(result, Ok(())); + rpc_run_to_block(2); + let receipts = Runtime::current_receipts().expect("Receipts result."); + assert_eq!(receipts.len(), 1); + }); +} + +#[test] +fn txpool_runtime_api_extrinsic_filter() { + ExtBuilder::default().build().execute_with(|| { + let non_eth_uxt = UncheckedExtrinsic::new_unsigned( + pallet_balances::Call::::transfer_allow_death { + dest: AccountId::from(BOB), + value: 1 * MOVR, + } + .into(), + ); + let eth_uxt = unchecked_eth_tx(VALID_ETH_TX); + let txpool = >::extrinsic_filter( + vec![eth_uxt.clone(), non_eth_uxt.clone()], + vec![unchecked_eth_tx(VALID_ETH_TX), non_eth_uxt], + ); + assert_eq!(txpool.ready.len(), 1); + assert_eq!(txpool.future.len(), 1); + }); +} + +#[test] +fn can_author_when_selected_is_empty() { + ExtBuilder::default() + .with_balances(vec![ + (AccountId::from(ALICE), 20_000_000 * MOVR), + (AccountId::from(BOB), 10_000_000 * MOVR), + ]) + .with_collators(vec![(AccountId::from(ALICE), 2_000_000 * MOVR)]) + .with_mappings(vec![( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + AccountId::from(ALICE), + )]) + .build() + .execute_with(|| { + set_parachain_inherent_data(); + run_to_block(2, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 1); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: Default::default(), + parent_hash: Default::default(), + state_root: Default::default(), + }; + + // Base case: ALICE can author blocks when she is the only candidate + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Remove ALICE from candidate pool, leaving the candidate_pool empty + assert_ok!(ParachainStaking::go_offline(origin_of(AccountId::from( + ALICE + )))); + + // Need to fast forward to right before the next session, which is when selected candidates + // will be updated. We want to test the creation of the first block of the next session. + run_to_block(1799, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1799, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + + // Check that it works as expected after session update + run_to_block(1800, Some(NimbusId::from_slice(&ALICE_NIMBUS).unwrap())); + + assert_eq!(ParachainStaking::candidate_pool().0.len(), 0); + + let slot_number = 0; + let parent = Header { + digest: Default::default(), + extrinsics_root: Default::default(), + number: 1800, + parent_hash: Default::default(), + state_root: Default::default(), + }; + + let can_author_block = Runtime::can_author( + NimbusId::from_slice(&ALICE_NIMBUS).unwrap(), + slot_number, + &parent, + ); + + assert!(can_author_block); + }); +} diff --git a/tracing/2902/runtime/moonriver/tests/xcm_mock/mod.rs b/tracing/2902/runtime/moonriver/tests/xcm_mock/mod.rs new file mode 100644 index 00000000..8d5d6e8c --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/xcm_mock/mod.rs @@ -0,0 +1,273 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +pub mod parachain; +pub mod relay_chain; +pub mod statemine_like; + +use cumulus_primitives_core::ParaId; +use pallet_xcm_transactor::relay_indices::*; +use sp_runtime::traits::AccountIdConversion; +use sp_runtime::{AccountId32, BuildStorage}; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +use polkadot_runtime_parachains::configuration::{ + GenesisConfig as ConfigurationGenesisConfig, HostConfiguration, +}; +use polkadot_runtime_parachains::paras::{ + GenesisConfig as ParasGenesisConfig, ParaGenesisArgs, ParaKind, +}; +use sp_core::{H160, U256}; +use std::{collections::BTreeMap, str::FromStr}; + +pub const PARAALICE: [u8; 20] = [1u8; 20]; +pub const RELAYALICE: AccountId32 = AccountId32::new([0u8; 32]); +pub const RELAYBOB: AccountId32 = AccountId32::new([2u8; 32]); + +pub fn para_a_account() -> AccountId32 { + ParaId::from(1).into_account_truncating() +} + +pub fn para_b_account() -> AccountId32 { + ParaId::from(2).into_account_truncating() +} + +pub fn para_a_account_20() -> parachain::AccountId { + ParaId::from(1).into_account_truncating() +} + +pub fn evm_account() -> H160 { + H160::from_str("1000000000000000000000000000000000000001").unwrap() +} + +pub fn mock_para_genesis_info() -> ParaGenesisArgs { + ParaGenesisArgs { + genesis_head: vec![1u8].into(), + validation_code: vec![1u8].into(), + para_kind: ParaKind::Parachain, + } +} + +pub fn mock_relay_config() -> HostConfiguration { + HostConfiguration:: { + hrmp_channel_max_capacity: u32::MAX, + hrmp_channel_max_total_size: u32::MAX, + hrmp_max_parachain_inbound_channels: 10, + hrmp_max_parachain_outbound_channels: 10, + hrmp_channel_max_message_size: u32::MAX, + // Changed to avoid aritmetic errors within hrmp_close + max_downward_message_size: 100_000u32, + ..Default::default() + } +} + +decl_test_parachain! { + pub struct ParaA { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(1), + } +} + +decl_test_parachain! { + pub struct ParaB { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(2), + } +} + +decl_test_parachain! { + pub struct ParaC { + Runtime = parachain::Runtime, + XcmpMessageHandler = parachain::MsgQueue, + DmpMessageHandler = parachain::MsgQueue, + new_ext = para_ext(3), + } +} + +decl_test_parachain! { + pub struct Statemine { + Runtime = statemine_like::Runtime, + XcmpMessageHandler = statemine_like::MsgQueue, + DmpMessageHandler = statemine_like::MsgQueue, + new_ext = statemine_ext(4), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relay_chain::Runtime, + RuntimeCall = relay_chain::RuntimeCall, + RuntimeEvent = relay_chain::RuntimeEvent, + XcmConfig = relay_chain::XcmConfig, + MessageQueue = relay_chain::MessageQueue, + System = relay_chain::System, + new_ext = relay_ext(vec![1, 2, 3, 4]), + } +} + +decl_test_network! { + pub struct MockNet { + relay_chain = Relay, + parachains = vec![ + (1, ParaA), + (2, ParaB), + (3, ParaC), + (4, Statemine), + ], + } +} + +pub const INITIAL_BALANCE: u128 = 10_000_000_000_000_000; + +pub const INITIAL_EVM_BALANCE: u128 = 0; +pub const INITIAL_EVM_NONCE: u32 = 1; + +pub fn para_ext(para_id: u32) -> sp_io::TestExternalities { + use parachain::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(PARAALICE.into(), INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + pallet_xcm_transactor::GenesisConfig:: { + // match relay runtime construct_runtime order in xcm_mock::relay_chain + relay_indices: RelayChainIndices { + hrmp: 6u8, + init_open_channel: 0u8, + accept_open_channel: 1u8, + close_channel: 2u8, + cancel_open_request: 6u8, + ..Default::default() + }, + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); + + // EVM accounts are self-sufficient. + let mut evm_accounts = BTreeMap::new(); + evm_accounts.insert( + evm_account(), + fp_evm::GenesisAccount { + nonce: U256::from(INITIAL_EVM_NONCE), + balance: U256::from(INITIAL_EVM_BALANCE), + storage: Default::default(), + code: vec![ + 0x00, // STOP + ], + }, + ); + + let genesis_config = pallet_evm::GenesisConfig:: { + accounts: evm_accounts, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn statemine_ext(para_id: u32) -> sp_io::TestExternalities { + use statemine_like::{MsgQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![ + (RELAYALICE.into(), INITIAL_BALANCE), + (RELAYBOB.into(), INITIAL_BALANCE), + ], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MsgQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext(paras: Vec) -> sp_io::TestExternalities { + use relay_chain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default() + .build_storage() + .unwrap(); + + pallet_balances::GenesisConfig:: { + balances: vec![(RELAYALICE, INITIAL_BALANCE)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let para_genesis: Vec<(ParaId, ParaGenesisArgs)> = paras + .iter() + .map(|¶_id| (para_id.into(), mock_para_genesis_info())) + .collect(); + + let genesis_config = ConfigurationGenesisConfig:: { + config: mock_relay_config(), + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let genesis_config = ParasGenesisConfig:: { + paras: para_genesis, + ..Default::default() + }; + genesis_config.assimilate_storage(&mut t).unwrap(); + + let mut ext = sp_io::TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + }); + ext +} + +pub type RelayChainPalletXcm = pallet_xcm::Pallet; +pub type Hrmp = polkadot_runtime_parachains::hrmp::Pallet; + +pub type StatemineBalances = pallet_balances::Pallet; +pub type StatemineChainPalletXcm = pallet_xcm::Pallet; +pub type StatemineAssets = pallet_assets::Pallet; + +pub type ParachainPalletXcm = pallet_xcm::Pallet; +pub type Assets = pallet_assets::Pallet; + +pub type Treasury = pallet_treasury::Pallet; +pub type AssetManager = pallet_asset_manager::Pallet; +pub type XTokens = orml_xtokens::Pallet; +pub type RelayBalances = pallet_balances::Pallet; +pub type ParaBalances = pallet_balances::Pallet; +pub type XcmTransactor = pallet_xcm_transactor::Pallet; diff --git a/tracing/2902/runtime/moonriver/tests/xcm_mock/parachain.rs b/tracing/2902/runtime/moonriver/tests/xcm_mock/parachain.rs new file mode 100644 index 00000000..201b4796 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/xcm_mock/parachain.rs @@ -0,0 +1,1094 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Parachain runtime mock. + +use frame_support::{ + construct_runtime, + dispatch::GetDispatchInfo, + ensure, parameter_types, + traits::{ + AsEnsureOriginWithArg, ConstU32, Everything, Get, InstanceFilter, Nothing, PalletInfoAccess, + }, + weights::Weight, + PalletId, +}; +use frame_system::{pallet_prelude::BlockNumberFor, EnsureNever, EnsureRoot}; +use pallet_xcm::migration::v1::VersionUncheckedMigrateToV1; +use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; +use sp_core::H256; +use sp_runtime::{ + traits::{BlakeTwo256, Hash, IdentityLookup, MaybeEquivalence, Zero}, + Permill, +}; +use sp_std::{convert::TryFrom, prelude::*}; +use xcm::{latest::prelude::*, Version as XcmVersion, VersionedXcm}; + +use cumulus_primitives_core::relay_chain::HrmpChannelId; +use orml_traits::parameter_type_with_key; +use pallet_ethereum::PostLogContent; +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; +use polkadot_parachain::primitives::{Id as ParaId, Sibling}; +use xcm::latest::{ + AssetId as XcmAssetId, Error as XcmError, ExecuteXcm, + Junction::{PalletInstance, Parachain}, + Location, NetworkId, Outcome, Xcm, +}; +use xcm_builder::{ + AccountKey20Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FungibleAdapter as XcmCurrencyAdapter, FungiblesAdapter, IsConcrete, + NoChecking, ParentAsSuperuser, ParentIsPreset, RelayChainAsNative, SiblingParachainAsNative, + SiblingParachainConvertsVia, SignedAccountKey20AsNative, SovereignSignedViaLocation, + TakeWeightCredit, WithComputedOrigin, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; + +#[cfg(feature = "runtime-benchmarks")] +use moonbeam_runtime_common::benchmarking::BenchmarkHelper as ArgumentsBenchmarkHelper; +pub use moonriver_runtime::xcm_config::AssetType; +use scale_info::TypeInfo; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; + +pub type AccountId = moonbeam_core_primitives::AccountId; +pub type Balance = u128; +pub type AssetId = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 0; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +pub type ForeignAssetInstance = (); + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 1; // Does not really matter as this will be only called by root + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = pallet_assets::weights::SubstrateWeight; + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + AccountKey20Aliases, + // Generate remote accounts according to polkadot standards + xcm_builder::HashedDescription< + AccountId, + xcm_builder::DescribeFamily, + >, +); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will converts to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, + SignedAccountKey20AsNative, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1u64, 1u64); + pub MaxInstructions: u32 = 100; +} + +// Instructing how incoming xcm assets will be handled +pub type ForeignFungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + // Do a simple punn to convert an AccountId32 Location into a native chain account ID: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleports. + NoChecking, + // We dont track any teleports + (), +>; + +pub type LocalAssetTransactor = XcmCurrencyAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching any of the locations in + // SelfReserveRepresentations + IsConcrete, + // We can convert the Locations with our converter above: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We dont allow teleport + (), +>; + +// We use both transactors +pub type AssetTransactors = (LocalAssetTransactor, ForeignFungiblesTransactor); + +pub type XcmRouter = super::ParachainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + /// Xcm fees will go to the treasury account + pub XcmFeesAccount: AccountId = Treasury::account_id(); +} + +/// This is the struct that will handle the revenue from xcm fees +pub type XcmFeesToAccount_ = xcm_primitives::XcmFeesToAccount< + Assets, + ( + ConvertedConcreteId< + AssetId, + Balance, + xcm_primitives::AsAssetType, + JustTry, + >, + ), + AccountId, + XcmFeesAccount, +>; + +parameter_types! { + // We cannot skip the native trader for some specific tests, so we will have to work with + // a native trader that charges same number of units as weight + pub ParaTokensPerSecond: (XcmAssetId, u128, u128) = ( + AssetId(SelfReserve::get()), + 1000000000000, + 0, + ); +} + +parameter_types! { + pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub SelfReserve: Location = Location { + parents:0, + interior: [ + PalletInstance(::index() as u8) + ].into() + }; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +use frame_system::RawOrigin; +use sp_runtime::traits::PostDispatchInfoOf; +use sp_runtime::DispatchErrorWithPostInfo; +use xcm_executor::traits::CallDispatcher; +moonbeam_runtime_common::impl_moonbeam_xcm_call!(); + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = orml_xcm_support::MultiNativeAsset< + xcm_primitives::AbsoluteAndRelativeReserve, + >; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + // We use three traders + // When we receive either representation of the self-reserve asset, + // When we receive a non-reserve asset, we use AssetManager to fetch how many + // units per second we should charge + type Trader = ( + FixedRateOfFungible, + xcm_primitives::FirstAssetTrader, + ); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type CallDispatcher = MoonbeamCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Our currencyId. We distinguish for now between SelfReserve, and Others, defined by their Id. +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum CurrencyId { + SelfReserve, + ForeignAsset(AssetId), +} + +// How to convert from CurrencyId to Location +pub struct CurrencyIdToLocation(sp_std::marker::PhantomData); +impl sp_runtime::traits::Convert> + for CurrencyIdToLocation +where + AssetXConverter: MaybeEquivalence, +{ + fn convert(currency: CurrencyId) -> Option { + match currency { + CurrencyId::SelfReserve => { + // For now and until Xtokens is adapted to handle 0.9.16 version we use + // the old anchoring here + // This is not a problem in either cases, since the view of the destination + // chain does not change + // TODO! change this to NewAnchoringSelfReserve once xtokens is adapted for it + let multi: Location = SelfReserve::get(); + Some(multi) + } + CurrencyId::ForeignAsset(asset) => AssetXConverter::convert_back(&asset), + } + } +} + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxAssetsForTransfer: usize = 2; + pub SelfLocation: Location = Location::here(); + pub SelfLocationAbsolute: Location = Location { + parents:1, + interior: [ + Parachain(MsgQueue::parachain_id().into()) + ].into() + }; +} + +parameter_type_with_key! { + pub ParachainMinFee: |location: Location| -> Option { + match (location.parents, location.first_interior()) { + (1, Some(Parachain(4u32))) => Some(50u128), + _ => None, + } + }; +} + +// The XCM message wrapper wrapper +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdConvert = + CurrencyIdToLocation>; + type XcmExecutor = XcmExecutor; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; +} + +parameter_types! { + pub const ProposalBond: Permill = Permill::from_percent(5); + pub const ProposalBondMinimum: Balance = 0; + pub const SpendPeriod: u32 = 0; + pub const TreasuryId: PalletId = PalletId(*b"pc/trsry"); + pub const MaxApprovals: u32 = 100; + pub TreasuryAccount: AccountId = Treasury::account_id(); +} + +impl pallet_treasury::Config for Runtime { + type PalletId = TreasuryId; + type Currency = Balances; + type ApproveOrigin = EnsureRoot; + type RejectOrigin = EnsureRoot; + type RuntimeEvent = RuntimeEvent; + type OnSlash = Treasury; + type ProposalBond = ProposalBond; + type ProposalBondMinimum = ProposalBondMinimum; + type SpendPeriod = SpendPeriod; + type Burn = (); + type BurnDestination = (); + type MaxApprovals = MaxApprovals; + type WeightInfo = (); + type SpendFunds = (); + type ProposalBondMaximum = (); + type SpendOrigin = frame_support::traits::NeverEnsureOrigin; // Same as Polkadot + type AssetKind = (); + type Beneficiary = AccountId; + type BeneficiaryLookup = IdentityLookup; + type Paymaster = PayFromAccount; + type BalanceConverter = UnityAssetBalanceConversion; + type PayoutPeriod = ConstU32<0>; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = ArgumentsBenchmarkHelper; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} + +// Pallet to provide the version, used to test runtime upgrade version changes +#[frame_support::pallet] +pub mod mock_version_changer { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_version)] + pub(super) type CurrentVersion = StorageValue<_, XcmVersion, ValueQuery>; + + impl Get for Pallet { + fn get() -> XcmVersion { + Self::current_version() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + VersionChanged(XcmVersion), + } + + impl Pallet { + pub fn set_version(version: XcmVersion) { + CurrentVersion::::put(version); + Self::deposit_event(Event::VersionChanged(version)); + } + } +} + +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +impl mock_version_changer::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +pub type LocalOriginToLocation = + xcm_primitives::SignedToAccountId20; + +parameter_types! { + pub MatcherLocation: Location = Location::here(); +} + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = frame_support::traits::Nothing; + type XcmExecutor = XcmExecutor; + // Do not allow teleports + type XcmTeleportFilter = Nothing; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + // We use a custom one to test runtime ugprades + type AdvertisedXcmVersion = XcmVersioner; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +// We instruct how to register the Assets +// In this case, we tell it to Create an Asset in pallet-assets +pub struct AssetRegistrar; +use frame_support::pallet_prelude::DispatchResult; +impl pallet_asset_manager::AssetRegistrar for AssetRegistrar { + fn create_foreign_asset( + asset: AssetId, + min_balance: Balance, + metadata: AssetMetadata, + is_sufficient: bool, + ) -> DispatchResult { + Assets::force_create( + RuntimeOrigin::root(), + asset, + AssetManager::account_id(), + is_sufficient, + min_balance, + )?; + + Assets::force_set_metadata( + RuntimeOrigin::root(), + asset, + metadata.name, + metadata.symbol, + metadata.decimals, + false, + ) + } + + fn destroy_foreign_asset(asset: AssetId) -> DispatchResult { + // Mark the asset as destroying + Assets::start_destroy(RuntimeOrigin::root(), asset.into())?; + + Ok(()) + } + + fn destroy_asset_dispatch_info_weight(asset: AssetId) -> Weight { + RuntimeCall::Assets( + pallet_assets::Call::::start_destroy { + id: asset.into(), + }, + ) + .get_dispatch_info() + .weight + } +} + +#[derive(Clone, Default, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub struct AssetMetadata { + pub name: Vec, + pub symbol: Vec, + pub decimals: u8, +} + +impl pallet_asset_manager::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetRegistrarMetadata = AssetMetadata; + type ForeignAssetType = AssetType; + type AssetRegistrar = AssetRegistrar; + type ForeignAssetModifierOrigin = EnsureRoot; + type WeightInfo = (); +} + +// 1 KSM should be enough +parameter_types! { + pub MaxHrmpRelayFee: Asset = (Location::parent(), 1_000_000_000_000u128).into(); +} + +impl pallet_xcm_transactor::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Transactor = MockTransactors; + type DerivativeAddressRegistrationOrigin = EnsureRoot; + type SovereignAccountDispatcherOrigin = frame_system::EnsureRoot; + type CurrencyId = CurrencyId; + type AccountIdToLocation = xcm_primitives::AccountIdToLocation; + type CurrencyIdToLocation = + CurrencyIdToLocation>; + type SelfLocation = SelfLocation; + type Weigher = xcm_builder::FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type XcmSender = XcmRouter; + type BaseXcmWeight = BaseXcmWeight; + type AssetTransactor = AssetTransactors; + type ReserveProvider = xcm_primitives::AbsoluteAndRelativeReserve; + type WeightInfo = (); + type HrmpManipulatorOrigin = EnsureRoot; + type HrmpOpenOrigin = EnsureRoot; + type MaxHrmpFee = xcm_builder::Case; +} + +parameter_types! { + pub const MinimumPeriod: u64 = 1000; +} +impl pallet_timestamp::Config for Runtime { + type Moment = u64; + type OnTimestampSet = (); + type MinimumPeriod = MinimumPeriod; + type WeightInfo = (); +} + +use sp_core::U256; + +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 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 = + BlockGasLimit::get().min(u64::MAX.into()).low_u64().saturating_div(BLOCK_STORAGE_LIMIT); +} + +impl pallet_evm::Config for Runtime { + type FeeCalculator = (); + type GasWeightMapping = pallet_evm::FixedGasWeightMapping; + type WeightPerGas = WeightPerGas; + + type CallOrigin = pallet_evm::EnsureAddressRoot; + type WithdrawOrigin = pallet_evm::EnsureAddressNever; + + type AddressMapping = pallet_evm::IdentityAddressMapping; + type Currency = Balances; + type Runner = pallet_evm::runner::stack::Runner; + + type RuntimeEvent = RuntimeEvent; + type PrecompilesType = (); + type PrecompilesValue = (); + type ChainId = (); + type BlockGasLimit = BlockGasLimit; + type OnChargeTransaction = (); + type BlockHashMapping = pallet_evm::SubstrateBlockHashMapping; + type FindAuthor = (); + type OnCreate = (); + type GasLimitPovSizeRatio = GasLimitPovSizeRatio; + type SuicideQuickClearLimit = ConstU32<0>; + type GasLimitStorageGrowthRatio = GasLimitStorageGrowthRatio; + type Timestamp = Timestamp; + type WeightInfo = pallet_evm::weights::SubstrateWeight; +} + +pub struct NormalFilter; +impl frame_support::traits::Contains for NormalFilter { + fn contains(c: &RuntimeCall) -> bool { + match c { + _ => true, + } + } +} + +// We need to use the encoding from the relay mock runtime +#[derive(Encode, Decode)] +pub enum RelayCall { + #[codec(index = 5u8)] + // the index should match the position of the module in `construct_runtime!` + Utility(UtilityCall), + #[codec(index = 6u8)] + // the index should match the position of the module in `construct_runtime!` + Hrmp(HrmpCall), +} + +#[derive(Encode, Decode)] +pub enum UtilityCall { + #[codec(index = 1u8)] + AsDerivative(u16), +} + +// HRMP call encoding, needed for xcm transactor pallet +#[derive(Encode, Decode)] +pub enum HrmpCall { + #[codec(index = 0u8)] + InitOpenChannel(ParaId, u32, u32), + #[codec(index = 1u8)] + AcceptOpenChannel(ParaId), + #[codec(index = 2u8)] + CloseChannel(HrmpChannelId), + #[codec(index = 6u8)] + CancelOpenRequest(HrmpChannelId, u32), +} + +#[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] +pub enum MockTransactors { + Relay, +} + +impl xcm_primitives::XcmTransact for MockTransactors { + fn destination(self) -> Location { + match self { + MockTransactors::Relay => Location::parent(), + } + } +} + +impl xcm_primitives::UtilityEncodeCall for MockTransactors { + fn encode_call(self, call: xcm_primitives::UtilityAvailableCalls) -> Vec { + match self { + MockTransactors::Relay => match call { + xcm_primitives::UtilityAvailableCalls::AsDerivative(a, b) => { + let mut call = + RelayCall::Utility(UtilityCall::AsDerivative(a.clone())).encode(); + call.append(&mut b.clone()); + call + } + }, + } + } +} + +pub struct MockHrmpEncoder; +impl xcm_primitives::HrmpEncodeCall for MockHrmpEncoder { + fn hrmp_encode_call( + call: xcm_primitives::HrmpAvailableCalls, + ) -> Result, xcm::latest::Error> { + match call { + xcm_primitives::HrmpAvailableCalls::InitOpenChannel(a, b, c) => Ok(RelayCall::Hrmp( + HrmpCall::InitOpenChannel(a.clone(), b.clone(), c.clone()), + ) + .encode()), + xcm_primitives::HrmpAvailableCalls::AcceptOpenChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::AcceptOpenChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CloseChannel(a) => { + Ok(RelayCall::Hrmp(HrmpCall::CloseChannel(a.clone())).encode()) + } + xcm_primitives::HrmpAvailableCalls::CancelOpenRequest(a, b) => { + Ok(RelayCall::Hrmp(HrmpCall::CancelOpenRequest(a.clone(), b.clone())).encode()) + } + } + } +} + +parameter_types! { + pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; +} + +impl pallet_ethereum::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type StateRoot = pallet_ethereum::IntermediateStateRoot; + type PostLogContent = PostBlockAndTxnHashes; + type ExtraDataLength = ConstU32<30>; +} + +parameter_types! { + pub ReservedXcmpWeight: Weight = Weight::from_parts(u64::max_value(), 0); +} + +#[derive( + Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, Debug, MaxEncodedLen, TypeInfo, +)] +pub enum ProxyType { + NotAllowed = 0, + Any = 1, +} + +impl pallet_evm_precompile_proxy::EvmProxyCallFilter for ProxyType {} + +impl InstanceFilter for ProxyType { + fn filter(&self, _c: &RuntimeCall) -> bool { + match self { + ProxyType::NotAllowed => false, + ProxyType::Any => true, + } + } + fn is_superset(&self, _o: &Self) -> bool { + false + } +} + +impl Default for ProxyType { + fn default() -> Self { + Self::NotAllowed + } +} + +parameter_types! { + pub const ProxyCost: u64 = 1; +} + +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type Currency = Balances; + type ProxyType = ProxyType; + type ProxyDepositBase = ProxyCost; + type ProxyDepositFactor = ProxyCost; + type MaxProxies = ConstU32<32>; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; + type MaxPending = ConstU32<32>; + type CallHasher = BlakeTwo256; + type AnnouncementDepositBase = ProxyCost; + type AnnouncementDepositFactor = ProxyCost; +} + +pub struct EthereumXcmEnsureProxy; +impl xcm_primitives::EnsureProxy for EthereumXcmEnsureProxy { + fn ensure_ok(delegator: AccountId, delegatee: AccountId) -> Result<(), &'static str> { + // The EVM implicitely contains an Any proxy, so we only allow for "Any" proxies + let def: pallet_proxy::ProxyDefinition = + pallet_proxy::Pallet::::find_proxy( + &delegator, + &delegatee, + Some(ProxyType::Any), + ) + .map_err(|_| "proxy error: expected `ProxyType::Any`")?; + // We only allow to use it for delay zero proxies, as the call will iMmediatly be executed + ensure!(def.delay.is_zero(), "proxy delay is Non-zero`"); + Ok(()) + } +} + +impl pallet_ethereum_xcm::Config for Runtime { + type InvalidEvmTransactionError = pallet_ethereum::InvalidTransactionWrapper; + type ValidatedTransaction = pallet_ethereum::ValidatedTransaction; + type XcmEthereumOrigin = pallet_ethereum_xcm::EnsureXcmEthereumTransaction; + type ReservedXcmpWeight = ReservedXcmpWeight; + type EnsureProxy = EthereumXcmEnsureProxy; + type ControllerOrigin = EnsureRoot; +} + +type Block = frame_system::mocking::MockBlockU32; + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + MsgQueue: mock_msg_queue, + XcmVersioner: mock_version_changer, + + PolkadotXcm: pallet_xcm, + Assets: pallet_assets, + CumulusXcm: cumulus_pallet_xcm, + XTokens: orml_xtokens, + AssetManager: pallet_asset_manager, + XcmTransactor: pallet_xcm_transactor, + Treasury: pallet_treasury, + Proxy: pallet_proxy, + + Timestamp: pallet_timestamp, + EVM: pallet_evm, + Ethereum: pallet_ethereum, + EthereumXcm: pallet_ethereum_xcm, + } +); + +pub(crate) fn para_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::tokens::{PayFromAccount, UnityAssetBalanceConversion}; +use frame_support::traits::{OnFinalize, OnInitialize, OnRuntimeUpgrade}; +pub(crate) fn on_runtime_upgrade() { + VersionUncheckedMigrateToV1::::on_runtime_upgrade(); +} + +pub(crate) fn para_roll_to(n: BlockNumber) { + while System::block_number() < n { + PolkadotXcm::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + PolkadotXcm::on_initialize(System::block_number()); + } +} diff --git a/tracing/2902/runtime/moonriver/tests/xcm_mock/relay_chain.rs b/tracing/2902/runtime/moonriver/tests/xcm_mock/relay_chain.rs new file mode 100644 index 00000000..40bff5e1 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/xcm_mock/relay_chain.rs @@ -0,0 +1,412 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{Everything, Nothing, ProcessMessage, ProcessMessageError}, +}; +use frame_system::pallet_prelude::BlockNumberFor; +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, IdentityLookup}, + AccountId32, +}; + +use frame_support::weights::{Weight, WeightMeter}; +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_runtime_parachains::{ + configuration, dmp, hrmp, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, paras, shared, +}; +use sp_runtime::transaction_validity::TransactionPriority; +use sp_runtime::Permill; +use xcm::latest::prelude::*; +use xcm_builder::{ + Account32Hash, AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, ChildParachainConvertsVia, + ChildSystemParachainAsSuperuser, FixedRateOfFungible, FixedWeightBounds, + FungibleAdapter as XcmCurrencyAdapter, IsConcrete, ProcessXcmMessage, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + WithComputedOrigin, +}; +use xcm_executor::{Config, XcmExecutor}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type BlockNumber = BlockNumberFor; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + type WeightInfo = (); + type PalletsOrigin = OriginCaller; +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub KsmLocation: Location = Here.into(); + pub const KusamaNetwork: NetworkId = NetworkId::Kusama; + pub const AnyNetwork: Option = None; + pub UniversalLocation: InteriorLocation = Here; +} + +pub type SovereignAccountOf = ( + ChildParachainConvertsVia, + AccountId32Aliases, + // Not enabled in the relay per se, but we enable it to test + // the transact_through_signed extrinsic + Account32Hash, +); + +pub type LocalAssetTransactor = + XcmCurrencyAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, + ChildSystemParachainAsSuperuser, +); + +parameter_types! { + pub const BaseXcmWeight: Weight = Weight::from_parts(1000u64, 1000u64); + pub KsmPerSecond: (AssetId, u128, u128) = (AssetId(KsmLocation::get()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; + pub MatcherLocation: Location = Location::here(); +} + +pub type XcmRouter = super::RelayChainXcmRouter; + +pub type XcmBarrier = ( + // Weight that is paid for may be consumed. + TakeWeightCredit, + // Expected responses are OK. + AllowKnownQueryResponses, + WithComputedOrigin< + ( + // If the message is one that immediately attemps to pay for execution, then allow it. + AllowTopLevelPaidExecutionFrom, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, + ), + UniversalLocation, + ConstU32<8>, + >, +); + +parameter_types! { + pub Kusama: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(KsmLocation::get()) }); + pub Statemine: Location = Parachain(4).into(); + pub KusamaForStatemine: (AssetFilter, Location) = (Kusama::get(), Statemine::get()); +} + +pub type TrustedTeleporters = xcm_builder::Case; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = LocalAssetTransactor; + type OriginConverter = LocalOriginConverter; + type IsReserve = (); + type IsTeleporter = TrustedTeleporters; + type UniversalLocation = UniversalLocation; + type Barrier = XcmBarrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = XcmPallet; + type AssetTrap = XcmPallet; + type AssetClaims = XcmPallet; + type SubscriptionService = XcmPallet; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = (); +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmRouter = XcmRouter; + // Anyone can execute XCM messages locally... + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +parameter_types! { + pub const FirstMessageFactorPercent: u64 = 100; +} + +parameter_types! { + pub const ParasUnsignedPriority: TransactionPriority = TransactionPriority::max_value(); +} + +/// A very dumb implementation of `EstimateNextSessionRotation`. At the moment of writing, this +/// is more to satisfy type requirements rather than to test anything. +pub struct TestNextSessionRotation; + +impl frame_support::traits::EstimateNextSessionRotation for TestNextSessionRotation { + fn average_session_length() -> u32 { + 10 + } + + fn estimate_current_session_progress(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } + + fn estimate_next_session_rotation(_now: u32) -> (Option, Weight) { + (None, Weight::zero()) + } +} + +impl paras::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type WeightInfo = paras::TestWeightInfo; + type UnsignedPriority = ParasUnsignedPriority; + type NextSessionRotation = TestNextSessionRotation; + type QueueFootprinter = (); + type OnNewHead = (); + type AssignCoretime = (); +} + +impl dmp::Config for Runtime {} + +impl hrmp::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type WeightInfo = TestHrmpWeightInfo; + type ChannelManager = frame_system::EnsureRoot; +} + +impl frame_system::offchain::SendTransactionTypes for Runtime +where + RuntimeCall: From, +{ + type Extrinsic = UncheckedExtrinsic; + type OverarchingCall = RuntimeCall; +} + +impl origin::Config for Runtime {} + +type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; +type Block = frame_system::mocking::MockBlockU32; + +parameter_types! { + pub MessageQueueServiceWeight: Weight = Weight::from_parts(1_000_000_000, 1_000_000); + pub const MessageQueueHeapSize: u32 = 65_536; + pub const MessageQueueMaxStale: u32 = 16; +} + +pub struct MessageProcessor; +impl ProcessMessage for MessageProcessor { + type Origin = AggregateMessageOrigin; + + fn process_message( + message: &[u8], + origin: Self::Origin, + meter: &mut WeightMeter, + id: &mut [u8; 32], + ) -> Result { + let para = match origin { + AggregateMessageOrigin::Ump(UmpQueueId::Para(para)) => para, + }; + ProcessXcmMessage::, RuntimeCall>::process_message( + message, + Junction::Parachain(para.into()), + meter, + id, + ) + } +} + +impl pallet_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Size = u32; + type HeapSize = MessageQueueHeapSize; + type MaxStale = MessageQueueMaxStale; + type ServiceWeight = MessageQueueServiceWeight; + type MessageProcessor = MessageProcessor; + type QueueChangeHandler = (); + type WeightInfo = (); + type QueuePausedQuery = (); +} + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + MessageQueue: pallet_message_queue, + XcmPallet: pallet_xcm, + Utility: pallet_utility, + Hrmp: hrmp, + Dmp: dmp, + Paras: paras, + Configuration: configuration, + } +); + +pub(crate) fn relay_events() -> Vec { + System::events() + .into_iter() + .map(|r| r.event) + .filter_map(|e| Some(e)) + .collect::>() +} + +use frame_support::traits::{OnFinalize, OnInitialize}; +pub(crate) fn relay_roll_to(n: BlockNumber) { + while System::block_number() < n { + XcmPallet::on_finalize(System::block_number()); + Balances::on_finalize(System::block_number()); + System::on_finalize(System::block_number()); + System::set_block_number(System::block_number() + 1); + System::on_initialize(System::block_number()); + Balances::on_initialize(System::block_number()); + XcmPallet::on_initialize(System::block_number()); + } +} + +/// A weight info that is only suitable for testing. +pub struct TestHrmpWeightInfo; + +impl hrmp::WeightInfo for TestHrmpWeightInfo { + fn hrmp_accept_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn force_clean_hrmp(_: u32, _: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_close(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_process_hrmp_open(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_cancel_open_request(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_close_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn hrmp_init_open_channel() -> Weight { + Weight::from_parts(1, 0) + } + fn clean_open_channel_requests(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn force_open_hrmp_channel(_: u32) -> Weight { + Weight::from_parts(1, 0) + } + fn establish_system_channel() -> Weight { + Weight::from_parts(1, 0) + } + + fn poke_channel_deposits() -> Weight { + Weight::from_parts(1, 0) + } +} diff --git a/tracing/2902/runtime/moonriver/tests/xcm_mock/statemine_like.rs b/tracing/2902/runtime/moonriver/tests/xcm_mock/statemine_like.rs new file mode 100644 index 00000000..b3d5e778 --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/xcm_mock/statemine_like.rs @@ -0,0 +1,575 @@ +// Copyright 2021 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Relay chain runtime mock. + +use frame_support::{ + construct_runtime, parameter_types, + traits::{AsEnsureOriginWithArg, Contains, Everything, Nothing}, + weights::Weight, +}; +use frame_system::{EnsureRoot, EnsureSigned}; + +use sp_core::H256; +use sp_runtime::{ + traits::{ConstU32, Hash, IdentityLookup}, + AccountId32, +}; + +use polkadot_core_primitives::BlockNumber as RelayBlockNumber; + +use polkadot_parachain::primitives::Id as ParaId; +use polkadot_parachain::primitives::Sibling; +use sp_std::convert::TryFrom; +use xcm::latest::prelude::*; +use xcm::VersionedXcm; +use xcm_builder::{ + AccountId32Aliases, AllowKnownQueryResponses, AllowSubscriptionsFrom, + AllowTopLevelPaidExecutionFrom, AllowUnpaidExecutionFrom, AsPrefixedGeneralIndex, + ConvertedConcreteId, EnsureXcmOrigin, FixedRateOfFungible, FixedWeightBounds, FungibleAdapter, + FungiblesAdapter, IsConcrete, NoChecking, ParentAsSuperuser, ParentIsPreset, + RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, +}; +use xcm_executor::{traits::JustTry, Config, XcmExecutor}; +use xcm_simulator::{ + DmpMessageHandlerT as DmpMessageHandler, XcmpMessageFormat, + XcmpMessageHandlerT as XcmpMessageHandler, +}; +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type AssetId = u128; + +parameter_types! { + pub const BlockHashCount: u32 = 250; +} + +impl frame_system::Config for Runtime { + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type RuntimeTask = RuntimeTask; + type Nonce = u64; + type Block = Block; + type Hash = H256; + type Hashing = ::sp_runtime::traits::BlakeTwo256; + type AccountId = AccountId; + type Lookup = IdentityLookup; + type RuntimeEvent = RuntimeEvent; + type BlockHashCount = BlockHashCount; + type BlockWeights = (); + type BlockLength = (); + type Version = (); + type PalletInfo = PalletInfo; + type AccountData = pallet_balances::AccountData; + type OnNewAccount = (); + type OnKilledAccount = (); + type DbWeight = (); + type BaseCallFilter = Everything; + type SystemWeightInfo = (); + type SS58Prefix = (); + type OnSetCode = (); + type MaxConsumers = frame_support::traits::ConstU32<16>; +} + +parameter_types! { + pub ExistentialDeposit: Balance = 1; + pub const MaxLocks: u32 = 50; + pub const MaxReserves: u32 = 50; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = MaxLocks; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ExistentialDeposit; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = MaxReserves; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = (); + type FreezeIdentifier = (); + type MaxFreezes = (); + type RuntimeFreezeReason = (); +} + +// Required for runtime benchmarks +pallet_assets::runtime_benchmarks_enabled! { + pub struct BenchmarkHelper; + impl pallet_assets::BenchmarkHelper for BenchmarkHelper + where + AssetIdParameter: From, + { + fn create_asset_id_parameter(id: u32) -> AssetIdParameter { + (id as u128).into() + } + } +} + +parameter_types! { + pub const AssetDeposit: Balance = 0; // 1 UNIT deposit to create asset + pub const ApprovalDeposit: Balance = 0; + pub const AssetsStringLimit: u32 = 50; + /// Key = 32 bytes, Value = 36 bytes (32+1+1+1+1) + // https://github.com/paritytech/substrate/blob/069917b/frame/assets/src/lib.rs#L257L271 + pub const MetadataDepositBase: Balance = 0; + pub const MetadataDepositPerByte: Balance = 0; + pub const ExecutiveBody: BodyId = BodyId::Executive; + pub const AssetAccountDeposit: Balance = 0; +} + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type Currency = Balances; + type ForceOrigin = EnsureRoot; + type AssetDeposit = AssetDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type Freezer = (); + type Extra = (); + type AssetAccountDeposit = AssetAccountDeposit; + type WeightInfo = (); + type RemoveItemsLimit = ConstU32<656>; + type AssetIdParameter = AssetId; + type CreateOrigin = AsEnsureOriginWithArg>; + type CallbackHandle = (); + pallet_assets::runtime_benchmarks_enabled! { + type BenchmarkHelper = BenchmarkHelper; + } +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); + pub UniversalLocation: InteriorLocation = + [GlobalConsensus(RelayNetwork::get()), Parachain(MsgQueue::parachain_id().into())].into(); + pub Local: Location = Here.into(); + pub CheckingAccount: AccountId = PolkadotXcm::check_account(); + pub KsmPerSecond: (xcm::latest::prelude::AssetId, u128, u128) = + (AssetId(KsmLocation::get()), 1, 1); +} + +/// Type for specifying how a `Location` can be converted into an `AccountId`. This is used +/// when determining ownership of accounts for asset transacting and when attempting to use XCM +/// `Transact` in order to determine the dispatch Origin. +pub type LocationToAccountId = ( + // The parent (Relay-chain) origin converts to the default `AccountId`. + ParentIsPreset, + // Sibling parachain origins convert to AccountId via the `ParaId::into`. + SiblingParachainConvertsVia, + // Straight up local `AccountId32` origins just alias directly to `AccountId`. + AccountId32Aliases, +); + +/// Means for transacting the native currency on this chain. +pub type CurrencyTransactor = FungibleAdapter< + // Use this currency: + Balances, + // Use this currency when it is a fungible asset matching the given location or name: + IsConcrete, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We don't track any teleports of `Balances`. + (), +>; + +/// Means for transacting assets besides the native currency on this chain. +pub type FungiblesTransactor = FungiblesAdapter< + // Use this fungibles implementation: + Assets, + // Use this currency when it is a fungible asset matching the given location or name: + ConvertedConcreteId< + AssetId, + Balance, + AsPrefixedGeneralIndex, + JustTry, + >, + // Convert an XCM Location into a local account id: + LocationToAccountId, + // Our chain's account ID type (we can't get away without mentioning it explicitly): + AccountId, + // We only want to allow teleports of known assets. We use non-zero issuance as an indication + // that this asset is known. + NoChecking, + // The account to use for tracking teleports. + CheckingAccount, +>; +/// Means for transacting assets on this chain. +pub type AssetTransactors = (CurrencyTransactor, FungiblesTransactor); + +/// This is the type we use to convert an (incoming) XCM origin into a local `Origin` instance, +/// ready for dispatching a transaction with Xcm's `Transact`. There is an `OriginKind` which can +/// biases the kind of local `Origin` it will become. +pub type XcmOriginToTransactDispatchOrigin = ( + // Sovereign account converter; this attempts to derive an `AccountId` from the origin location + // using `LocationToAccountId` and then turn that into the usual `Signed` origin. Useful for + // foreign chains who want to have a local sovereign account on this chain which they control. + SovereignSignedViaLocation, + // Native converter for Relay-chain (Parent) location; will convert to a `Relay` origin when + // recognised. + RelayChainAsNative, + // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when + // recognised. + SiblingParachainAsNative, + // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a + // transaction from the Root origin. + ParentAsSuperuser, + // Native signed account converter; this just converts an `AccountId32` origin into a normal + // `RuntimeOrigin::signed` origin of the same 32-byte value. + SignedAccountId32AsNative, + // Xcm origins can be represented natively under the Xcm pallet's Xcm origin. + pallet_xcm::XcmPassthrough, +); + +parameter_types! { + // One XCM operation is 1_000_000_000 weight - almost certainly a conservative estimate. + pub UnitWeightCost: Weight = Weight::from_parts(100u64, 100u64); + pub const MaxInstructions: u32 = 100; +} + +pub struct ParentOrParentsExecutivePlurality; +impl Contains for ParentOrParentsExecutivePlurality { + fn contains(location: &Location) -> bool { + matches!( + location.unpack(), + (1, []) + | ( + 1, + [Plurality { + id: BodyId::Executive, + .. + }] + ) + ) + } +} + +pub struct ParentOrSiblings; +impl Contains for ParentOrSiblings { + fn contains(location: &Location) -> bool { + matches!(location.unpack(), (1, []) | (1, [_])) + } +} + +pub type Barrier = ( + TakeWeightCredit, + AllowTopLevelPaidExecutionFrom, + // Parent and its exec plurality get free execution + AllowUnpaidExecutionFrom, + // Expected responses are OK. + AllowKnownQueryResponses, + // Subscriptions for version tracking are OK. + AllowSubscriptionsFrom, +); + +parameter_types! { + pub MatcherLocation: Location = Location::here(); + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = AssetTransactors; + type OriginConverter = XcmOriginToTransactDispatchOrigin; + type IsReserve = + orml_xcm_support::MultiNativeAsset; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = PolkadotXcm; + type AssetTrap = PolkadotXcm; + type AssetClaims = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type CallDispatcher = RuntimeCall; + type AssetLocker = (); + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + + type TransactionalProcessor = (); +} + +/// No local origins on this chain are allowed to dispatch XCM sends/executions. +pub type LocalOriginToLocation = SignedToAccountId32; + +pub type XcmRouter = super::ParachainXcmRouter; + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type SendXcmOrigin = EnsureXcmOrigin; + type XcmRouter = XcmRouter; + type ExecuteXcmOrigin = EnsureXcmOrigin; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmTeleportFilter = Everything; + type XcmReserveTransferFilter = Everything; + type Weigher = FixedWeightBounds; + type UniversalLocation = UniversalLocation; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = pallet_xcm::CurrentXcmVersion; + type Currency = Balances; + type CurrencyMatcher = IsConcrete; + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type AdminOrigin = frame_system::EnsureRoot; +} + +impl cumulus_pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +#[frame_support::pallet] +pub mod mock_msg_queue { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + impl Get for Pallet { + fn get() -> ParaId { + Self::parachain_id() + } + } + + pub type MessageId = [u8; 32]; + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // XCMP + /// Some XCM was executed OK. + Success(Option), + /// Some XCM failed. + Fail(Option, XcmError), + /// Bad XCM version used. + BadVersion(Option), + /// Bad XCM format used. + BadFormat(Option), + + // DMP + /// Downward message is invalid XCM. + InvalidFormat(MessageId), + /// Downward message is unsupported version of XCM. + UnsupportedVersion(MessageId), + /// Downward message executed with the given outcome. + ExecutedDownward(MessageId, Outcome), + } + + impl Pallet { + pub fn set_para_id(para_id: ParaId) { + ParachainId::::put(para_id); + } + + fn handle_xcmp_message( + sender: ParaId, + _sent_at: RelayBlockNumber, + xcm: VersionedXcm, + max_weight: Weight, + ) -> Result { + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = Location::new(1, [Parachain(sender.into())]); + let mut id = [0u8; 32]; + id.copy_from_slice(hash.as_ref()); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut id, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => { + (Err(error.clone()), Event::Fail(Some(hash), error)) + } + Outcome::Complete { used } => (Ok(used), Event::Success(Some(hash))), + // As far as the caller is concerned, this was dispatched without error, so + // we just report the weight used. + Outcome::Incomplete { used, error } => { + (Ok(used), Event::Fail(Some(hash), error)) + } + } + } + Err(()) => ( + Err(XcmError::UnhandledXcmVersion), + Event::BadVersion(Some(hash)), + ), + }; + Self::deposit_event(event); + result + } + } + + impl XcmpMessageHandler for Pallet { + fn handle_xcmp_messages<'a, I: Iterator>( + iter: I, + max_weight: Weight, + ) -> Weight { + for (sender, sent_at, data) in iter { + let mut data_ref = data; + let _ = XcmpMessageFormat::decode(&mut data_ref) + .expect("Simulator encodes with versioned xcm format; qed"); + + let mut remaining_fragments = &data_ref[..]; + while !remaining_fragments.is_empty() { + if let Ok(xcm) = + VersionedXcm::::decode(&mut remaining_fragments) + { + let _ = Self::handle_xcmp_message(sender, sent_at, xcm, max_weight); + } else { + debug_assert!(false, "Invalid incoming XCMP message data"); + } + } + } + max_weight + } + } + + impl DmpMessageHandler for Pallet { + fn handle_dmp_messages( + iter: impl Iterator)>, + limit: Weight, + ) -> Weight { + for (_i, (_sent_at, data)) in iter.enumerate() { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_msg = VersionedXcm::::decode(&mut &data[..]) + .map(Xcm::::try_from); + match maybe_msg { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + } + Ok(Err(())) => { + Self::deposit_event(Event::UnsupportedVersion(id)); + } + Ok(Ok(x)) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x, + &mut id, + limit, + Weight::zero(), + ); + + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + } + } + } + limit + } + } +} +impl mock_msg_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +// Pallet to cover test cases for change https://github.com/paritytech/cumulus/pull/831 +#[frame_support::pallet] +pub mod mock_statemine_prefix { + use super::*; + use frame_support::pallet_prelude::*; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn current_prefix)] + pub(super) type CurrentPrefix = StorageValue<_, Location, ValueQuery>; + + impl Get for Pallet { + fn get() -> Location { + Self::current_prefix() + } + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + // Changed Prefix + PrefixChanged(Location), + } + + impl Pallet { + pub fn set_prefix(prefix: Location) { + CurrentPrefix::::put(&prefix); + Self::deposit_event(Event::PrefixChanged(prefix)); + } + } +} + +impl mock_statemine_prefix::Config for Runtime { + type RuntimeEvent = RuntimeEvent; +} + +type Block = frame_system::mocking::MockBlockU32; +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + PolkadotXcm: pallet_xcm, + CumulusXcm: cumulus_pallet_xcm, + MsgQueue: mock_msg_queue, + Assets: pallet_assets, + PrefixChanger: mock_statemine_prefix, + + } +); diff --git a/tracing/2902/runtime/moonriver/tests/xcm_tests.rs b/tracing/2902/runtime/moonriver/tests/xcm_tests.rs new file mode 100644 index 00000000..0eab574b --- /dev/null +++ b/tracing/2902/runtime/moonriver/tests/xcm_tests.rs @@ -0,0 +1,3998 @@ +// 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 . + +//! Moonriver Runtime Xcm Tests + +mod xcm_mock; +use frame_support::{ + assert_ok, + traits::{PalletInfo, PalletInfoAccess}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, + BoundedVec, +}; +use sp_core::ConstU32; +use sp_runtime::traits::MaybeEquivalence; +use xcm::latest::prelude::{ + AccountId32, AccountKey20, All, BuyExecution, ClearOrigin, DepositAsset, GeneralIndex, + Junction, Junctions, Limited, Location, OriginKind, PalletInstance, Parachain, QueryResponse, + Reanchorable, Response, WeightLimit, WithdrawAsset, Xcm, +}; +use xcm::{VersionedLocation, WrapVersion}; +use xcm_executor::traits::ConvertLocation; +use xcm_mock::parachain; +use xcm_mock::relay_chain; +use xcm_mock::*; +use xcm_simulator::TestExt; +mod common; +use cumulus_primitives_core::relay_chain::HrmpChannelId; +use pallet_xcm_transactor::{ + Currency, CurrencyPayment, HrmpInitParams, HrmpOperation, TransactWeights, +}; +use xcm_primitives::{UtilityEncodeCall, DEFAULT_PROOF_SIZE}; + +// Send a relay asset (like DOT) to a parachain A +#[test] +fn receive_relay_asset_from_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // Register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // Verify that parachain received the asset + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +// Send relay asset (like DOT) back from Parachain A to relaychain +#[test] +fn send_relay_asset_to_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register relay asset in paraA + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // free execution + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // First send relay chain asset to Parachain like in previous test + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Lets gather the balance before sending back money + let mut balance_before_sending = 0; + Relay::execute_with(|| { + balance_before_sending = RelayBalances::free_balance(&RELAYALICE); + }); + + // We now send back some money to the relay + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: RELAYALICE.into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 123, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The balances in paraAlice should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); + + // Balances in the relay should have been received + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(&RELAYALICE) > balance_before_sending); + }); +} + +#[test] +fn send_relay_asset_to_para_b() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Register asset in paraA. Free execution + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // First send relay chain asset to Parachain A like in previous test + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); + + // Now send relay asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances should have been substracted + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 23); + }); + + // Para B balances should have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_to_para_b() { + MockNet::reset(); + + // This represents the asset in paraA + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register asset in paraB. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset from para A to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Native token is substracted in paraA + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Asset is minted in paraB + ParaB::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); +} + +#[test] +fn send_para_a_asset_from_para_b_to_para_c() { + MockNet::reset(); + + // Represents para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in parachain B. Free execution + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location.clone(), + 0u128, + 0 + )); + }); + + // Register para A asset in parachain C. Free execution + ParaC::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send para A asset from para B to para C + let dest = Location { + parents: 1, + interior: [ + Parachain(3), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // The message passed through parachainA so we needed to pay since its the native token + ParaC::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 96); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_and_back_to_para_a() { + MockNet::reset(); + + // Para A asset + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + // Register para A asset in para B + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send para A asset to para B + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Balances have been substracted + ParaA::execute_with(|| { + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // Para B balances have been credited + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // Send back para A asset to para A + let dest = Location { + parents: 1, + interior: [ + Parachain(1), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaB::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + // Para A asset has been credited + ParaA::execute_with(|| { + // Weight used is 4 + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 4 + ); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_and_back_to_para_a_with_new_reanchoring() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // Free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + ParaB::execute_with(|| { + // Free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // This time we will force the new reanchoring by manually sending the + // Message through polkadotXCM pallet + + let dest = Location { + parents: 1, + interior: [Parachain(1)].into(), + }; + + let reanchored_para_a_balances = Location::new(0, [PalletInstance(1u8)]); + + let message = xcm::VersionedXcm::<()>::V4(Xcm(vec![ + WithdrawAsset((reanchored_para_a_balances.clone(), 100).into()), + ClearOrigin, + BuyExecution { + fees: (reanchored_para_a_balances, 100).into(), + weight_limit: Limited(80.into()), + }, + DepositAsset { + assets: All.into(), + beneficiary: Location::new( + 0, + [AccountKey20 { + network: None, + key: PARAALICE, + }], + ), + }, + ])); + ParaB::execute_with(|| { + // Send a message to the sovereign account in ParaA to withdraw + // and deposit asset + assert_ok!(ParachainPalletXcm::send( + parachain::RuntimeOrigin::root(), + Box::new(dest.into()), + Box::new(message), + )); + }); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // This time we will force the new reanchoring by manually sending the + // Message through polkadotXCM pallet + + let dest = Location { + parents: 1, + interior: [Parachain(1)].into(), + }; + + let reanchored_para_a_balances = Location::new(0, [PalletInstance(1u8)]); + + let message = xcm::VersionedXcm::<()>::V4(Xcm(vec![ + WithdrawAsset((reanchored_para_a_balances.clone(), 100).into()), + ClearOrigin, + BuyExecution { + fees: (reanchored_para_a_balances, 100).into(), + weight_limit: Limited(80.into()), + }, + DepositAsset { + assets: All.into(), + beneficiary: Location::new( + 0, + [AccountKey20 { + network: None, + key: PARAALICE, + }], + ), + }, + ])); + ParaB::execute_with(|| { + // Send a message to the sovereign account in ParaA to withdraw + // and deposit asset + assert_ok!(ParachainPalletXcm::send( + parachain::RuntimeOrigin::root(), + Box::new(dest.into()), + Box::new(message), + )); + }); + + ParaA::execute_with(|| { + // Weight used is 4 + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 4 + ); + }); +} + +#[test] +fn receive_relay_asset_with_trader() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // We are sending 100 tokens from relay. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Therefore with no refund, we should receive 10 tokens less + // Native trader fails for this, and we use the asset trader + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 100).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // non-free execution, not full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // In destination chain, we only need 4 weight + // We put 10 weight, 6 of which should be refunded and 4 of which should go to treasury + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(10u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + // We are sending 100 tokens from para A. + // Amount spent in fees is Units per second * weight / 1_000_000_000_000 (weight per second) + // weight is 4 since we are executing 4 instructions with a unitweightcost of 1. + // Units per second should be 2_500_000_000_000_000 + // Since we set 10 weight in destination chain, 25 will be charged upfront + // 15 of those will be refunded, while 10 will go to treasury as the true weight used + // will be 4 + ParaB::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 90); + // Fee should have been received by treasury + assert_eq!(Assets::balance(source_id, &Treasury::account_id()), 10); + }); +} + +#[test] +fn send_para_a_asset_to_para_b_with_trader_and_fee() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + + ParaB::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + // With these units per second, 80K weight convrets to 1 asset unit + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 12500000u128, + 0 + )); + }); + + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + + // we use transfer_with_fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_with_fee( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + 1, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(800000u64, DEFAULT_PROOF_SIZE)) + )); + }); + ParaA::execute_with(|| { + // 100 tokens transferred plus 1 taken from fees + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 - 1 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received because trully the xcm instruction does not cost + // what it is specified + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 101); + }); +} + +#[test] +fn error_when_not_paying_enough() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + let dest: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + // This time we are gonna put a rather high number of units per second + // we know later we will divide by 1e12 + // Lets put 1e6 as units per second + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 2500000000000u128, + 0 + )); + }); + + // We are sending 100 tokens from relay. + // If we set the dest weight to be 1e7, we know the buy_execution will spend 1e7*1e6/1e12 = 10 + // Therefore with no refund, we should receive 10 tokens less + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 5).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // amount not received as it is not paying enough + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 0); + }); +} + +#[test] +fn transact_through_derivative_multilocation() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + encoded, + // 4000000000 + 3000 we should have taken out 4000003000 tokens from the caller + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 3000 correspond to 4000003000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000003000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + // 4000000000 + 3000 we should have taken out 4000003000 tokens from the caller + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + false + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_derivative_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + // Let's construct the call to know how much weight it is going to require + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + // 4000000000 transact + 9000 correspond to 4000009000 tokens. 100 more for the transfer call + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_derivative( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::MockTransactors::Relay, + 0, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee weight mapping + fee_amount: Some(overall_weight as u128) + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + let event_found: Option = parachain::para_events() + .iter() + .find_map(|event| match event.clone() { + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::AssetsTrapped { + .. + }) => Some(event.clone()), + _ => None, + }); + // Assert that the events do not contain the assets being trapped + assert!(event_found.is_none()); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn transact_through_sovereign() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_fee_payer_none() { + MockNet::reset(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + None + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + }); + + let derivative_address = derivative_account_id(para_a_account(), 0); + + Relay::execute_with(|| { + // Transfer 100 tokens to derivative_address on the relay + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derivative_address.clone(), + 100u128 + )); + + // Transfer the XCM execution fee amount to ParaA's sovereign account + assert_ok!(RelayBalances::transfer_keep_alive( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 4000003000u128 + )); + }); + + // Check balances before the transact call + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000003000); + assert_eq!(RelayBalances::free_balance(&derivative_address), 100); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 0); + }); + + // Encode the call. Balances transfer of 100 relay tokens to RELAYBOB + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: RELAYBOB, + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + // The final call will be an AsDerivative using index 0 + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + // No fee_payer here. The sovereign account will pay the fees on destination. + None, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + // Check balances after the transact call are correct + Relay::execute_with(|| { + assert_eq!(RelayBalances::free_balance(¶_a_account()), 0); + assert_eq!(RelayBalances::free_balance(&derivative_address), 0); + assert_eq!(RelayBalances::free_balance(&RELAYBOB), 100); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000003100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000003000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000003000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000003000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(®istered_address) == 0); + }); +} + +#[test] +fn transact_through_sovereign_with_custom_fee_weight_refund() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 1u128, + 0 + )); + }); + + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 4000009100u128).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009100); + }); + + // Register address + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::register( + parachain::RuntimeOrigin::root(), + PARAALICE.into(), + 0, + )); + }); + + // Send to registered address + let registered_address = derivative_account_id(para_a_account(), 0); + let dest = Location { + parents: 1, + interior: [AccountId32 { + network: None, + id: registered_address.clone().into(), + }] + .into(), + }; + + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::ForeignAsset(source_id), + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(40000u64, DEFAULT_PROOF_SIZE)) + )); + }); + + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 4000009000); + }); + + // What we will do now is transfer this relay tokens from the derived account to the sovereign + // again + Relay::execute_with(|| { + // free execution,x full amount received + assert!(RelayBalances::free_balance(¶_a_account()) == 4000009000); + 0 + }); + + // We send the xcm transact operation to parent + let dest = Location { + parents: 1, + interior: /* Here */ [].into(), + }; + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let utility_bytes = parachain::MockTransactors::Relay.encode_call( + xcm_primitives::UtilityAvailableCalls::AsDerivative(0, encoded), + ); + + let total_weight = 4000009000u64; + // Root can directly pass the execution byes to the sovereign + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_sovereign( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(dest)), + Some(PARAALICE.into()), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + // 1-1 fee-weight mapping + fee_amount: Some(total_weight as u128) + }, + utility_bytes, + OriginKind::SovereignAccount, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // free execution,x full amount received + // 4000005186 refunded + 100 transferred = 4000005286 + assert_eq!(RelayBalances::free_balance(¶_a_account()), 4000005286); + + assert_eq!(RelayBalances::free_balance(®istered_address), 0); + }); +} + +#[test] +fn test_automatic_versioning_on_runtime_upgrade_with_relay() { + MockNet::reset(); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A and set XCM version to 1 + ParaA::execute_with(|| { + parachain::XcmVersioner::set_version(1); + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + let response = Response::Version(2); + let querier: Location = ([]/* Here */).into(); + + // This is irrelevant, nothing will be done with this message, + // but we need to pass a message as an argument to trigger the storage change + let mock_message: Xcm<()> = Xcm(vec![QueryResponse { + query_id: 0, + response, + max_weight: Weight::zero(), + querier: Some(querier), + }]); + // The router is mocked, and we cannot use WrapVersion in ChildParachainRouter. So we will force + // it directly here + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + Relay::execute_with(|| { + // This sets the default version, for not known destinations + assert_ok!(RelayChainPalletXcm::force_default_xcm_version( + relay_chain::RuntimeOrigin::root(), + Some(2) + )); + + // Wrap version, which sets VersionedStorage + // This is necessary because the mock router does not use wrap_version, but + // this is not necessary in prod + assert_ok!(::wrap_version( + &Parachain(1).into(), + mock_message + )); + + // Transfer assets. Since it is an unknown destination, it will query for version + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + + // Let's advance the relay. This should trigger the subscription message + relay_chain::relay_roll_to(2); + + // queries should have been updated + assert!(RelayChainPalletXcm::query(0).is_some()); + }); + + let expected_supported_version: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 1, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the version change + assert!(relay_chain::relay_events().contains(&expected_supported_version)); + }); + + // ParaA changes version to 2, and calls on_runtime_upgrade. This should notify the targets + // of the new version change + ParaA::execute_with(|| { + // Set version + parachain::XcmVersioner::set_version(2); + // Do runtime upgrade + parachain::on_runtime_upgrade(); + // Initialize block, to call on_initialize and notify targets + parachain::para_roll_to(2); + // Expect the event in the parachain + assert!(parachain::para_events().iter().any(|e| matches!( + e, + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::VersionChangeNotified { + result: 2, + .. + }) + ))); + }); + + // This event should have been seen in the relay + let expected_supported_version_2: relay_chain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 0, + interior: [Parachain(1)].into(), + }, + version: 2, + } + .into(); + + Relay::execute_with(|| { + // Assert that the events vector contains the new version change + assert!(relay_chain::relay_events().contains(&expected_supported_version_2)); + }); +} + +#[test] +fn test_automatic_versioning_on_runtime_upgrade_with_para_b() { + MockNet::reset(); + + let para_a_balances = Location::new(1, [Parachain(1), PalletInstance(1u8)]); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(¶_a_balances).expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"ParaAToken".to_vec(), + symbol: b"ParaA".to_vec(), + decimals: 18, + }; + let response = Response::Version(2); + let querier: Location = [] /* Here */ + .into(); + + // This is irrelevant, nothing will be done with this message, + // but we need to pass a message as an argument to trigger the storage change + let mock_message: Xcm<()> = Xcm(vec![QueryResponse { + query_id: 0, + response, + max_weight: Weight::zero(), + querier: Some(querier), + }]); + + ParaA::execute_with(|| { + // advertised version + parachain::XcmVersioner::set_version(2); + }); + + ParaB::execute_with(|| { + // Let's try with v0 + parachain::XcmVersioner::set_version(0); + + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + ParaA::execute_with(|| { + // This sets the default version, for not known destinations + assert_ok!(ParachainPalletXcm::force_default_xcm_version( + parachain::RuntimeOrigin::root(), + Some(2) + )); + // Wrap version, which sets VersionedStorage + assert_ok!(::wrap_version( + &Location::new(1, [Parachain(2)]).into(), + mock_message + )); + + parachain::para_roll_to(2); + + // queries should have been updated + assert!(ParachainPalletXcm::query(0).is_some()); + }); + + let expected_supported_version: parachain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 1, + interior: [Parachain(2)].into(), + }, + version: 0, + } + .into(); + + ParaA::execute_with(|| { + // Assert that the events vector contains the version change + assert!(parachain::para_events().contains(&expected_supported_version)); + }); + + // Let's ensure talking in v0 works + let dest = Location { + parents: 1, + interior: [ + Parachain(2), + AccountKey20 { + network: None, + key: PARAALICE.into(), + }, + ] + .into(), + }; + ParaA::execute_with(|| { + // free execution, full amount received + assert_ok!(XTokens::transfer( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + parachain::CurrencyId::SelfReserve, + 100, + Box::new(VersionedLocation::V4(dest)), + WeightLimit::Limited(Weight::from_parts(80u64, DEFAULT_PROOF_SIZE)) + )); + // free execution, full amount received + assert_eq!( + ParaBalances::free_balance(&PARAALICE.into()), + INITIAL_BALANCE - 100 + ); + }); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 100); + }); + + // ParaB changes version to 2, and calls on_runtime_upgrade. This should notify the targets + // of the new version change + ParaB::execute_with(|| { + // Set version + parachain::XcmVersioner::set_version(2); + // Do runtime upgrade + parachain::on_runtime_upgrade(); + // Initialize block, to call on_initialize and notify targets + parachain::para_roll_to(2); + // Expect the event in the parachain + assert!(parachain::para_events().iter().any(|e| matches!( + e, + parachain::RuntimeEvent::PolkadotXcm(pallet_xcm::Event::VersionChangeNotified { + result: 2, + .. + }) + ))); + }); + + // This event should have been seen in para A + let expected_supported_version_2: parachain::RuntimeEvent = + pallet_xcm::Event::SupportedVersionChanged { + location: Location { + parents: 1, + interior: [Parachain(2)].into(), + }, + version: 2, + } + .into(); + + // Para A should have received the version change + ParaA::execute_with(|| { + // Assert that the events vector contains the new version change + assert!(parachain::para_events().contains(&expected_supported_version_2)); + }); +} + +#[test] +fn receive_asset_with_no_sufficients_not_possible_if_non_existent_account() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should not have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 0); + }); + + // Send native token to fresh_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + fresh_account.into(), + 100 + )); + }); + + // Re-send tokens + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn receive_assets_with_sufficients_true_allows_non_funded_account_to_receive_assets() { + MockNet::reset(); + + let fresh_account = [2u8; 20]; + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: fresh_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // parachain should have received assets + ParaA::execute_with(|| { + // free execution, full amount received + assert_eq!(Assets::balance(source_id, &fresh_account.into()), 123); + }); +} + +#[test] +fn evm_account_receiving_assets_should_handle_sufficients_ref_count() { + MockNet::reset(); + + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + // Evm account is self sufficient + ParaA::execute_with(|| { + assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + // Evm account sufficient ref count increased by 1. + ParaA::execute_with(|| { + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 2); + }); + + ParaA::execute_with(|| { + // Remove the account from the evm context. + parachain::EVM::remove_account(&evm_account()); + // Evm account sufficient ref count decreased by 1. + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // assert_eq!(parachain::System::account(evm_account_id).sufficients, 1); + }); +} + +#[test] +fn empty_account_should_not_be_reset() { + MockNet::reset(); + + // Test account has nonce 1 on genesis. + let mut sufficient_account = [0u8; 20]; + sufficient_account[0..20].copy_from_slice(&evm_account()[..]); + + let evm_account_id = parachain::AccountId::from(sufficient_account); + + let source_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_id: parachain::AssetId = source_location.clone().into(); + let asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + // register relay asset in parachain A + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata, + 1u128, + false + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + // Send native token to evm_account + ParaA::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + evm_account_id, + 100 + )); + }); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: sufficient_account, + } + .into(); + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new(VersionedLocation::V4(dest.clone()).clone().into()), + Box::new(([] /* Here */, 123).into()), + 0, + )); + }); + + ParaA::execute_with(|| { + // Empty the assets from the account. + // As this makes the account go below the `min_balance`, the account is considered dead + // at eyes of pallet-assets, and the consumer reference is decreased by 1 and is now Zero. + assert_ok!(parachain::Assets::transfer( + parachain::RuntimeOrigin::signed(evm_account_id), + source_id, + PARAALICE.into(), + 123 + )); + // Verify account asset balance is Zero. + assert_eq!( + parachain::Assets::balance(source_id, &evm_account_id.into()), + 0 + ); + // Because we no longer have consumer references, we can set the balance to Zero. + // This would reset the account if our ED were to be > than Zero. + assert_ok!(ParaBalances::force_set_balance( + parachain::RuntimeOrigin::root(), + evm_account_id, + 0, + )); + // Verify account native balance is Zero. + assert_eq!(ParaBalances::free_balance(&evm_account_id), 0); + // Remove the account from the evm context. + // This decreases the sufficients reference by 1 and now is Zero. + parachain::EVM::remove_account(&evm_account()); + // Verify reference count. + let account = parachain::System::account(evm_account_id); + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // revert account.sufficients to 0 + assert_eq!(account.sufficients, 1); + assert_eq!(account.consumers, 0); + assert_eq!(account.providers, 1); + // We expect the account to be alive in a Zero ED context. + // TODO: since the suicided logic was introduced an smart contract account + // is not deleted completely until it's data is deleted. Data deletion + // will be implemented in a future release + // the following needs to be 1 + assert_eq!(parachain::System::account_nonce(evm_account_id), 2); + }); +} + +#[test] +fn test_statemine_like() { + MockNet::reset(); + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemine_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + let statemine_asset_a_balances = Location::new( + 1, + [ + Parachain(4), + PalletInstance(5), + xcm::latest::prelude::GeneralIndex(0u128), + ], + ); + let source_location = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemine_asset_a_balances) + .expect("convert to v3"), + ); + let source_id: parachain::AssetId = source_location.clone().into(); + + let asset_metadata = parachain::AssetMetadata { + name: b"StatemineToken".to_vec(), + symbol: b"StatemineToken".to_vec(), + decimals: 12, + }; + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + source_location.clone(), + asset_metadata.clone(), + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + source_location, + 0u128, + 0 + )); + }); + + Statemine::execute_with(|| { + // Set new prefix + statemine_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + assert_ok!(StatemineAssets::create( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 1 + )); + + assert_ok!(StatemineAssets::mint( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + 0, + RELAYALICE, + 300000000000000 + )); + + // This is needed, since the asset is created as non-sufficient + assert_ok!(StatemineBalances::transfer_allow_death( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Actually send relay asset to parachain + let dest: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send with new prefix + assert_ok!(StatemineChainPalletXcm::reserve_transfer_assets( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new(VersionedLocation::V4(dest).clone().into()), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + xcm::latest::prelude::GeneralIndex(0), + ], + 123 + ) + .into() + ), + 0, + )); + }); + + ParaA::execute_with(|| { + assert_eq!(Assets::balance(source_id, &PARAALICE.into()), 123); + }); +} + +#[test] +fn send_statemint_asset_from_para_a_to_statemine_with_relay_fee() { + MockNet::reset(); + + // Relay asset + let relay_location = parachain::AssetType::Xcm(xcm::v3::Location::parent()); + let source_relay_id: parachain::AssetId = relay_location.clone().into(); + + let relay_asset_metadata = parachain::AssetMetadata { + name: b"RelayToken".to_vec(), + symbol: b"Relay".to_vec(), + decimals: 12, + }; + + // Statemine asset + let statemine_asset = Location::new( + 1, + [Parachain(4u32), PalletInstance(5u8), GeneralIndex(10u128)], + ); + let statemine_location_asset = parachain::AssetType::Xcm( + xcm_builder::V4V3LocationConverter::convert(&statemine_asset).expect("convert to v3"), + ); + let source_statemine_asset_id: parachain::AssetId = statemine_location_asset.clone().into(); + + let asset_metadata_statemine_asset = parachain::AssetMetadata { + name: b"USDC".to_vec(), + symbol: b"USDC".to_vec(), + decimals: 12, + }; + + let dest_para = Location::new(1, [Parachain(1)]); + + let sov = xcm_builder::SiblingParachainConvertsVia::< + polkadot_parachain::primitives::Sibling, + statemine_like::AccountId, + >::convert_location(&dest_para) + .unwrap(); + + ParaA::execute_with(|| { + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + relay_location.clone(), + relay_asset_metadata, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + relay_location, + 0u128, + 0 + )); + + assert_ok!(AssetManager::register_foreign_asset( + parachain::RuntimeOrigin::root(), + statemine_location_asset.clone(), + asset_metadata_statemine_asset, + 1u128, + true + )); + assert_ok!(AssetManager::set_asset_units_per_second( + parachain::RuntimeOrigin::root(), + statemine_location_asset, + 0u128, + 1 + )); + }); + + let parachain_beneficiary_from_relay: Location = Junction::AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send relay chain asset to Alice in Parachain A + Relay::execute_with(|| { + assert_ok!(RelayChainPalletXcm::reserve_transfer_assets( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + Box::new(Parachain(1).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_relay) + .clone() + .into() + ), + Box::new(([] /* Here */, 200).into()), + 0, + )); + }); + + Statemine::execute_with(|| { + // Set new prefix + statemine_like::PrefixChanger::set_prefix( + PalletInstance(::index() as u8).into(), + ); + + assert_ok!(StatemineAssets::create( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 1 + )); + + assert_ok!(StatemineAssets::mint( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + 10, + RELAYALICE, + 300000000000000 + )); + + // Send some native statemine tokens to sovereign for fees. + // We can't pay fees with USDC as the asset is minted as non-sufficient. + assert_ok!(StatemineBalances::transfer_allow_death( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + sov, + 100000000000000 + )); + + // Send statemine USDC asset to Alice in Parachain A + let parachain_beneficiary_from_statemint: Location = AccountKey20 { + network: None, + key: PARAALICE, + } + .into(); + + // Send with new prefix + assert_ok!(StatemineChainPalletXcm::reserve_transfer_assets( + statemine_like::RuntimeOrigin::signed(RELAYALICE), + Box::new(Location::new(1, [Parachain(1)]).into()), + Box::new( + VersionedLocation::V4(parachain_beneficiary_from_statemint) + .clone() + .into() + ), + Box::new( + ( + [ + xcm::latest::prelude::PalletInstance( + ::index() as u8 + ), + GeneralIndex(10), + ], + 125 + ) + .into() + ), + 0, + )); + }); + + let statemine_beneficiary = Location { + parents: 1, + interior: [ + Parachain(4), + AccountId32 { + network: None, + id: RELAYBOB.into(), + }, + ] + .into(), + }; + + ParaA::execute_with(|| { + // Alice has received 125 USDC + assert_eq!( + Assets::balance(source_statemine_asset_id, &PARAALICE.into()), + 125 + ); + + // Alice has received 200 Relay assets + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 200); + }); + + Statemine::execute_with(|| { + // Check that BOB's balance is empty before the transfer + assert_eq!(StatemineAssets::account_balances(RELAYBOB), vec![]); + }); + + // Transfer USDC from Parachain A to Statemine using Relay asset as fee + ParaA::execute_with(|| { + assert_ok!(XTokens::transfer_multicurrencies( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + vec![ + ( + parachain::CurrencyId::ForeignAsset(source_statemine_asset_id), + 100 + ), + (parachain::CurrencyId::ForeignAsset(source_relay_id), 100) + ], + 1, + Box::new(VersionedLocation::V4(statemine_beneficiary)), + WeightLimit::Limited(Weight::from_parts(80_000_000u64, 100_000u64)) + )); + }); + + ParaA::execute_with(|| { + // Alice has 100 USDC less + assert_eq!( + Assets::balance(source_statemine_asset_id, &PARAALICE.into()), + 25 + ); + + // Alice has 100 relay asset less + assert_eq!(Assets::balance(source_relay_id, &PARAALICE.into()), 100); + }); + + Statemine::execute_with(|| { + // Check that BOB received 100 USDC on statemine + assert_eq!(StatemineAssets::account_balances(RELAYBOB), vec![(10, 100)]); + }); +} + +#[test] +fn transact_through_signed_multilocation() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + // Relay charges 1000 for every instruction, and we have 3, so 3000 + 3000.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4000.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + WEIGHT_REF_TIME_PER_SECOND as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000004100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000004100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000004000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + false + )); + }); + + Relay::execute_with(|| { + assert!(RelayBalances::free_balance(¶_a_account()) == 100); + + assert!(RelayBalances::free_balance(&derived) == 0); + }); +} + +#[test] +fn transact_through_signed_multilocation_custom_fee_and_weight_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + ParaA::execute_with(|| { + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_multilocation = parachain::SelfLocation::get(); + descend_origin_multilocation + .append_with(signed_origin) + .unwrap(); + + // To convert it to what the relay will see instead of us + descend_origin_multilocation + .reanchor(&Location::parent(), &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::Account32Hash::< + relay_chain::KusamaNetwork, + relay_chain::AccountId, + >::convert_location(&descend_origin_multilocation) + .unwrap(); + + Relay::execute_with(|| { + // free execution, full amount received + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(RelayBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(RelayBalances::free_balance(¶_a_account()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = ::PalletInfo::index::< + relay_chain::Balances, + >() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let total_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(Location::parent())), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(total_weight.into())) + }, + true + )); + }); + + Relay::execute_with(|| { + // 100 transferred + assert_eq!(RelayBalances::free_balance(¶_a_account()), 100); + + // 4000005186 refunded + assert_eq!(RelayBalances::free_balance(&derived), 4000005186); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + assert!(ParaBalances::free_balance(&derived) == 0); + + assert!(ParaBalances::free_balance(¶_a_account_20()) == 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_refund() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + ParaB::execute_with(|| { + // free execution, full amount received + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000009100u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000009100); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + // Then call bytes + let mut call_bytes = pallet_balances::Call::::transfer_allow_death { + // 100 to sovereign + dest: para_a_account_20(), + value: 100u32.into(), + } + .encode(); + encoded.append(&mut call_bytes); + + let overall_weight = 4000009000u64; + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: Some(overall_weight as u128) + }, + encoded, + // 4000000000 for transfer + 9000 for XCM + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: Some(Limited(overall_weight.into())) + }, + true + )); + }); + + ParaB::execute_with(|| { + // Check the derived account was refunded + assert_eq!(ParaBalances::free_balance(&derived), 8993); + + // Check the transfer was executed + assert_eq!(ParaBalances::free_balance(¶_a_account_20()), 100); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact { + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + // 4000000000 for transfer + 4000 for XCM + // 1-1 to fee + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer went through + assert!( + ParaBalances::free_balance(&PARAALICE.into()) + == parachain_b_alice_balances_before + 100 + ); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_no_proxy_fails() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let mut parachain_b_alice_balances_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + parachain_b_alice_balances_before = ParaBalances::free_balance(&PARAALICE.into()) + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V1(xcm_primitives::EthereumXcmTransactionV1 { + gas_limit: U256::from(21000), + fee_payment: xcm_primitives::EthereumXcmFee::Auto, + action: pallet_ethereum::TransactionAction::Call(PARAALICE.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer wasn't executed + assert!(ParaBalances::free_balance(&PARAALICE.into()) == parachain_b_alice_balances_before); + }); +} + +#[test] +fn transact_through_signed_multilocation_para_to_para_ethereum_proxy_succeeds() { + MockNet::reset(); + let mut ancestry = Location::parent(); + + let para_b_location = Location::new(1, [Parachain(2)]); + + let para_b_balances = Location::new(1, [Parachain(2), PalletInstance(1u8)]); + + ParaA::execute_with(|| { + // Root can set transact info + assert_ok!(XcmTransactor::set_transact_info( + parachain::RuntimeOrigin::root(), + // ParaB + Box::new(xcm::VersionedLocation::V4(para_b_location.clone())), + // Para charges 1000 for every instruction, and we have 3, so 3 + 3.into(), + 20000000000.into(), + // 4 instructions in transact through signed + Some(4.into()) + )); + // Root can set transact info + assert_ok!(XcmTransactor::set_fee_per_second( + parachain::RuntimeOrigin::root(), + Box::new(xcm::VersionedLocation::V4(para_b_balances.clone())), + parachain::ParaTokensPerSecond::get().1 as u128, + )); + ancestry = parachain::UniversalLocation::get().into(); + }); + + // Let's construct the Junction that we will append with DescendOrigin + let signed_origin: Junctions = [AccountKey20 { + network: None, + key: PARAALICE, + }] + .into(); + + let mut descend_origin_location = parachain::SelfLocation::get(); + descend_origin_location.append_with(signed_origin).unwrap(); + + // To convert it to what the paraB will see instead of us + descend_origin_location + .reanchor(¶_b_location, &ancestry.interior) + .unwrap(); + + let derived = xcm_builder::HashedDescription::< + parachain::AccountId, + xcm_builder::DescribeFamily, + >::convert_location(&descend_origin_location) + .unwrap(); + + let transfer_recipient = evm_account(); + let mut transfer_recipient_balance_before = 0; + ParaB::execute_with(|| { + assert_ok!(ParaBalances::transfer_allow_death( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + derived.clone(), + 4000000104u128, + )); + // derived account has all funds + assert!(ParaBalances::free_balance(&derived) == 4000000104); + // sovereign account has 0 funds + assert!(ParaBalances::free_balance(¶_a_account_20()) == 0); + + transfer_recipient_balance_before = ParaBalances::free_balance(&transfer_recipient.into()); + + // Add proxy ALICE -> derived + let _ = parachain::Proxy::add_proxy_delegate( + &PARAALICE.into(), + derived, + parachain::ProxyType::Any, + 0, + ); + }); + + // Encode the call. Balances transact to para_a_account + // First index + let mut encoded: Vec = Vec::new(); + let index = + ::PalletInfo::index::() + .unwrap() as u8; + + encoded.push(index); + + use sp_core::U256; + // Let's do a EVM transfer + let eth_tx = + xcm_primitives::EthereumXcmTransaction::V2(xcm_primitives::EthereumXcmTransactionV2 { + gas_limit: U256::from(21000), + action: pallet_ethereum::TransactionAction::Call(transfer_recipient.into()), + value: U256::from(100), + input: BoundedVec::< + u8, + ConstU32<{ xcm_primitives::MAX_ETHEREUM_XCM_INPUT_SIZE }> + >::try_from(vec![]).unwrap(), + access_list: None, + }); + + // Then call bytes + let mut call_bytes = pallet_ethereum_xcm::Call::::transact_through_proxy { + transact_as: PARAALICE.into(), + xcm_transaction: eth_tx, + } + .encode(); + encoded.append(&mut call_bytes); + + ParaA::execute_with(|| { + assert_ok!(XcmTransactor::transact_through_signed( + parachain::RuntimeOrigin::signed(PARAALICE.into()), + Box::new(xcm::VersionedLocation::V4(para_b_location)), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + para_b_balances + ))), + fee_amount: None + }, + encoded, + TransactWeights { + transact_required_weight_at_most: 4000000000.into(), + overall_weight: None + }, + false + )); + }); + + ParaB::execute_with(|| { + // Make sure the EVM transfer was executed + assert!( + ParaBalances::free_balance(&transfer_recipient.into()) + == transfer_recipient_balance_before + 100 + ); + }); +} + +#[test] +fn hrmp_init_accept_through_root() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_b_account(), + 1000u128 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp init channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::InitOpen(HrmpInitParams { + para_id: 2u32.into(), + proposed_max_capacity: 1, + proposed_max_message_size: 1 + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelRequested { + sender: 1u32.into(), + recipient: 2u32.into(), + proposed_max_capacity: 1u32, + proposed_max_message_size: 1u32, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); + ParaB::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp accept channel + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Accept { + para_id: 1u32.into() + }, + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::OpenChannelAccepted { + sender: 1u32.into(), + recipient: 2u32.into(), + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +#[test] +fn hrmp_close_works() { + MockNet::reset(); + + Relay::execute_with(|| { + assert_ok!(RelayBalances::transfer_allow_death( + relay_chain::RuntimeOrigin::signed(RELAYALICE), + para_a_account(), + 1000u128 + )); + assert_ok!(Hrmp::force_open_hrmp_channel( + relay_chain::RuntimeOrigin::root(), + 1u32.into(), + 2u32.into(), + 1u32, + 1u32 + )); + assert_ok!(Hrmp::force_process_hrmp_open( + relay_chain::RuntimeOrigin::root(), + 1u32 + )); + }); + + ParaA::execute_with(|| { + let total_fee = 1_000u128; + let total_weight: u64 = 1_000_000_000; + let tx_weight: u64 = 500_000_000; + // Root can send hrmp close + assert_ok!(XcmTransactor::hrmp_manage( + parachain::RuntimeOrigin::root(), + HrmpOperation::Close(HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into() + }), + CurrencyPayment { + currency: Currency::AsMultiLocation(Box::new(xcm::VersionedLocation::V4( + Location::parent() + ))), + fee_amount: Some(total_fee) + }, + TransactWeights { + transact_required_weight_at_most: tx_weight.into(), + overall_weight: Some(Limited(total_weight.into())) + } + )); + }); + Relay::execute_with(|| { + let expected_event: relay_chain::RuntimeEvent = + polkadot_runtime_parachains::hrmp::Event::ChannelClosed { + by_parachain: 1u32.into(), + channel_id: HrmpChannelId { + sender: 1u32.into(), + recipient: 2u32.into(), + }, + } + .into(); + assert!(relay_chain::relay_events().contains(&expected_event)); + }); +} + +use parity_scale_codec::{Decode, Encode}; +use sp_io::hashing::blake2_256; + +// Helper to derive accountIds +pub fn derivative_account_id(who: sp_runtime::AccountId32, index: u16) -> sp_runtime::AccountId32 { + let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); + sp_runtime::AccountId32::decode(&mut &entropy[..]).expect("valid account id") +} diff --git a/tracing/2902/rust-toolchain b/tracing/2902/rust-toolchain new file mode 100644 index 00000000..e7f84ae3 --- /dev/null +++ b/tracing/2902/rust-toolchain @@ -0,0 +1,5 @@ +[toolchain] +channel = "1.74.0" +components = [ "rustfmt", "clippy", "rust-src" ] +targets = [ "wasm32-unknown-unknown" ] +profile = "minimal" diff --git a/tracing/2902/shared/primitives/ext/Cargo.toml b/tracing/2902/shared/primitives/ext/Cargo.toml new file mode 100644 index 00000000..fc6bbf5e --- /dev/null +++ b/tracing/2902/shared/primitives/ext/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "moonbeam-primitives-ext" +version = '0.1.0' +authors = ['PureStake'] +edition = '2018' +homepage = 'https://moonbeam.network' +license = 'GPL-3.0-only' +repository = 'https://github.com/PureStake/moonbeam/' + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ethereum-types = { workspace = true } + +# Moonbeam +evm-tracing-events = { workspace = true } + +# Substrate +parity-scale-codec = { workspace = true } +sp-runtime-interface = { workspace = true } +sp-externalities = { workspace = true } +sp-std = { workspace = true } + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "ethereum-types/std", + "evm-tracing-events/std", + "sp-runtime-interface/std", + "sp-externalities/std", + "sp-std/std", +] \ No newline at end of file diff --git a/tracing/2902/shared/primitives/ext/src/lib.rs b/tracing/2902/shared/primitives/ext/src/lib.rs new file mode 100644 index 00000000..2e0fe897 --- /dev/null +++ b/tracing/2902/shared/primitives/ext/src/lib.rs @@ -0,0 +1,82 @@ +// 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 . + +//! Environmental-aware externalities for EVM tracing in Wasm runtime. This enables +//! capturing the - potentially large - trace output data in the host and keep +//! a low memory footprint in `--execution=wasm`. +//! +//! - The original trace Runtime Api call is wrapped `using` environmental (thread local). +//! - Arguments are scale-encoded known types in the host. +//! - Host functions will decode the input and emit an event `with` environmental. + +#![cfg_attr(not(feature = "std"), no_std)] +use sp_runtime_interface::runtime_interface; + +use parity_scale_codec::Decode; +use sp_std::vec::Vec; + +use evm_tracing_events::{Event, EvmEvent, GasometerEvent, RuntimeEvent, StepEventFilter}; + +#[runtime_interface] +pub trait MoonbeamExt { + fn raw_step(&mut self, _data: Vec) {} + + fn raw_gas(&mut self, _data: Vec) {} + + fn raw_return_value(&mut self, _data: Vec) {} + + fn call_list_entry(&mut self, _index: u32, _value: Vec) {} + + fn call_list_new(&mut self) {} + + // New design, proxy events. + /// An `Evm` event proxied by the Moonbeam runtime to this host function. + /// evm -> moonbeam_runtime -> host. + fn evm_event(&mut self, event: Vec) { + if let Ok(event) = EvmEvent::decode(&mut &event[..]) { + Event::Evm(event).emit(); + } + } + + /// A `Gasometer` event proxied by the Moonbeam runtime to this host function. + /// evm_gasometer -> moonbeam_runtime -> host. + fn gasometer_event(&mut self, event: Vec) { + if let Ok(event) = GasometerEvent::decode(&mut &event[..]) { + Event::Gasometer(event).emit(); + } + } + + /// A `Runtime` event proxied by the Moonbeam runtime to this host function. + /// evm_runtime -> moonbeam_runtime -> host. + fn runtime_event(&mut self, event: Vec) { + if let Ok(event) = RuntimeEvent::decode(&mut &event[..]) { + Event::Runtime(event).emit(); + } + } + + /// Allow the tracing module in the runtime to know how to filter Step event + /// content, as cloning the entire data is expensive and most of the time + /// not necessary. + fn step_event_filter(&self) -> StepEventFilter { + evm_tracing_events::step_event_filter().unwrap_or_default() + } + + /// An event to create a new CallList (currently a new transaction when tracing a block). + #[version(2)] + fn call_list_new(&mut self) { + Event::CallListNew().emit(); + } +} diff --git a/tracing/2902/shared/primitives/rpc/debug/Cargo.toml b/tracing/2902/shared/primitives/rpc/debug/Cargo.toml new file mode 100644 index 00000000..a81a24e7 --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/debug/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "moonbeam-rpc-primitives-debug" +authors = [ "PureStake" ] +edition = "2018" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +repository = "https://github.com/PureStake/moonbeam/" +version = "0.1.0" + +[dependencies] +environmental = { workspace = true } +ethereum = { workspace = true, features = [ "with-codec" ] } +ethereum-types = { workspace = true } +hex = { workspace = true, optional = true, features = [ "serde" ] } +serde = { workspace = true, optional = true, features = [ "derive" ] } + +# Substrate +parity-scale-codec = { workspace = true } +sp-api = { workspace = true } +sp-core = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +[features] +default = [ "std" ] + +before_700 = [] +_700_to_1200 = [] +runtime-2900 = [] + +std = [ + "parity-scale-codec/std", + "environmental/std", + "ethereum-types/std", + "ethereum/std", + "hex", + "serde", + "sp-api/std", + "sp-core/std", + "sp-io/std", + "sp-runtime/std", + "sp-std/std", +] diff --git a/tracing/2902/shared/primitives/rpc/debug/src/lib.rs b/tracing/2902/shared/primitives/rpc/debug/src/lib.rs new file mode 100644 index 00000000..5be13130 --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/debug/src/lib.rs @@ -0,0 +1,97 @@ +// 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 . + +#![cfg_attr(not(feature = "std"), no_std)] + +use parity_scale_codec::{Decode, Encode}; + +#[cfg(feature = "before_700")] +use ethereum::Transaction; +#[cfg(feature = "_700_to_1200")] +use ethereum::TransactionV0 as Transaction; +#[cfg(all(not(feature = "before_700"), not(feature = "_700_to_1200")))] +use ethereum::TransactionV2 as Transaction; + +use ethereum_types::{H160, H256, U256}; +use sp_std::vec::Vec; + +#[cfg(feature = "runtime-2900")] +sp_api::decl_runtime_apis! { + #[api_version(5)] + pub trait DebugRuntimeApi { + fn trace_transaction( + extrinsics: Vec, + transaction: &Transaction, + header: &Block::Header, + ) -> Result<(), sp_runtime::DispatchError>; + + fn trace_block( + extrinsics: Vec, + known_transactions: Vec, + header: &Block::Header, + ) -> Result<(), sp_runtime::DispatchError>; + } +} + +#[cfg(all( + not(feature = "before_700"), + not(feature = "_700_to_1200"), + not(feature = "runtime-2900") +))] +sp_api::decl_runtime_apis! { + #[api_version(4)] + pub trait DebugRuntimeApi { + fn trace_transaction( + extrinsics: Vec, + transaction: &Transaction, + ) -> Result<(), sp_runtime::DispatchError>; + + fn trace_block( + extrinsics: Vec, + known_transactions: Vec, + ) -> Result<(), sp_runtime::DispatchError>; + } +} + +#[cfg(any(feature = "before_700", feature = "_700_to_1200"))] +sp_api::decl_runtime_apis! { + pub trait DebugRuntimeApi { + fn trace_transaction( + extrinsics: Vec, + transaction: &Transaction, + ) -> Result<(), sp_runtime::DispatchError>; + + fn trace_block( + extrinsics: Vec, + known_transactions: Vec, + ) -> Result<(), sp_runtime::DispatchError>; + } +} + +#[derive(Clone, Copy, Eq, PartialEq, Debug, Encode, Decode)] +pub enum TracerInput { + None, + Blockscout, + CallTracer, +} + +/// DebugRuntimeApi V2 result. Trace response is stored in client and runtime api call response is +/// empty. +#[derive(Debug)] +pub enum Response { + Single, + Block, +} diff --git a/tracing/2902/shared/primitives/rpc/evm-tracing-events/Cargo.toml b/tracing/2902/shared/primitives/rpc/evm-tracing-events/Cargo.toml new file mode 100644 index 00000000..d94d74a4 --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/evm-tracing-events/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "evm-tracing-events" +version = '0.1.0' +authors = ['PureStake'] +edition = '2018' +homepage = 'https://moonbeam.network' +license = 'GPL-3.0-only' +repository = 'https://github.com/PureStake/moonbeam/' + +[dependencies] +parity-scale-codec = { workspace = true } +sp-runtime-interface = { workspace = true } + +ethereum = { workspace = true, features = ["with-codec"] } +ethereum-types = { workspace = true } + +environmental = { workspace = true } + +evm = { workspace = true, features = ["with-codec"] } +evm-runtime = { workspace = true } +evm-gasometer = { workspace = true } + +[features] +default = ["std"] + +evm-tracing = ["evm/tracing", "evm-runtime/tracing", "evm-gasometer/tracing"] +std = [ + "parity-scale-codec/std", + "ethereum/std", + "ethereum-types/std", + "environmental/std", + "evm/std", + "evm-runtime/std", + "evm-gasometer/std", +] + +runtime-1600 = [] \ No newline at end of file diff --git a/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/evm.rs b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/evm.rs new file mode 100644 index 00000000..a5ac04ee --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/evm.rs @@ -0,0 +1,258 @@ +// 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 . + +extern crate alloc; + +use alloc::vec::Vec; +use ethereum_types::{H160, H256, U256}; +use evm::ExitReason; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] +pub struct Transfer { + /// Source address. + pub source: H160, + /// Target address. + pub target: H160, + /// Transfer value. + pub value: U256, +} + +impl From for Transfer { + fn from(i: evm_runtime::Transfer) -> Self { + Self { + source: i.source, + target: i.target, + value: i.value, + } + } +} + +#[derive(Clone, Copy, Eq, PartialEq, Debug, Encode, Decode)] +pub enum CreateScheme { + /// Legacy create scheme of `CREATE`. + Legacy { + /// Caller of the create. + caller: H160, + }, + /// Create scheme of `CREATE2`. + Create2 { + /// Caller of the create. + caller: H160, + /// Code hash. + code_hash: H256, + /// Salt. + salt: H256, + }, + /// Create at a fixed location. + Fixed(H160), +} + +impl From for CreateScheme { + fn from(i: evm_runtime::CreateScheme) -> Self { + match i { + evm_runtime::CreateScheme::Legacy { caller } => Self::Legacy { caller }, + evm_runtime::CreateScheme::Create2 { + caller, + code_hash, + salt, + } => Self::Create2 { + caller, + code_hash, + salt, + }, + evm_runtime::CreateScheme::Fixed(address) => Self::Fixed(address), + } + } +} + +#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] +pub enum EvmEvent { + Call { + code_address: H160, + transfer: Option, + input: Vec, + target_gas: Option, + is_static: bool, + context: super::Context, + }, + Create { + caller: H160, + address: H160, + scheme: CreateScheme, + value: U256, + init_code: Vec, + target_gas: Option, + }, + Suicide { + address: H160, + target: H160, + balance: U256, + }, + Exit { + reason: ExitReason, + return_value: Vec, + }, + TransactCall { + caller: H160, + address: H160, + value: U256, + data: Vec, + gas_limit: u64, + }, + TransactCreate { + caller: H160, + value: U256, + init_code: Vec, + gas_limit: u64, + address: H160, + }, + TransactCreate2 { + caller: H160, + value: U256, + init_code: Vec, + salt: H256, + gas_limit: u64, + address: H160, + }, + PrecompileSubcall { + code_address: H160, + transfer: Option, + input: Vec, + target_gas: Option, + is_static: bool, + context: super::Context, + }, +} + +#[cfg(feature = "evm-tracing")] +impl<'a> From> for EvmEvent { + fn from(i: evm::tracing::Event<'a>) -> Self { + match i { + evm::tracing::Event::Call { + code_address, + transfer, + input, + target_gas, + is_static, + context, + } => Self::Call { + code_address, + transfer: if let Some(transfer) = transfer { + Some(transfer.clone().into()) + } else { + None + }, + input: input.to_vec(), + target_gas, + is_static, + context: context.clone().into(), + }, + evm::tracing::Event::Create { + caller, + address, + scheme, + value, + init_code, + target_gas, + } => Self::Create { + caller, + address, + scheme: scheme.into(), + value, + init_code: init_code.to_vec(), + target_gas, + }, + evm::tracing::Event::Suicide { + address, + target, + balance, + } => Self::Suicide { + address, + target, + balance, + }, + evm::tracing::Event::Exit { + reason, + return_value, + } => Self::Exit { + reason: reason.clone(), + return_value: return_value.to_vec(), + }, + evm::tracing::Event::TransactCall { + caller, + address, + value, + data, + gas_limit, + } => Self::TransactCall { + caller, + address, + value, + data: data.to_vec(), + gas_limit, + }, + evm::tracing::Event::TransactCreate { + caller, + value, + init_code, + gas_limit, + address, + } => Self::TransactCreate { + caller, + value, + init_code: init_code.to_vec(), + gas_limit, + address, + }, + evm::tracing::Event::TransactCreate2 { + caller, + value, + init_code, + salt, + gas_limit, + address, + } => Self::TransactCreate2 { + caller, + value, + init_code: init_code.to_vec(), + salt, + gas_limit, + address, + }, + #[cfg(feature = "runtime-1600")] + evm::tracing::Event::PrecompileSubcall { + code_address, + transfer, + input, + target_gas, + is_static, + context, + } => Self::PrecompileSubcall { + code_address, + transfer: if let Some(transfer) = transfer { + Some(transfer.clone().into()) + } else { + None + }, + input: input.to_vec(), + target_gas, + is_static, + context: context.clone().into(), + }, + } + } +} diff --git a/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/gasometer.rs b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/gasometer.rs new file mode 100644 index 00000000..33a6f724 --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/gasometer.rs @@ -0,0 +1,119 @@ +// 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 parity_scale_codec::{Decode, Encode}; + +#[derive(Debug, Default, Copy, Clone, Encode, Decode, PartialEq, Eq)] +pub struct Snapshot { + pub gas_limit: u64, + pub memory_gas: u64, + pub used_gas: u64, + pub refunded_gas: i64, +} + +impl Snapshot { + pub fn gas(&self) -> u64 { + self.gas_limit - self.used_gas - self.memory_gas + } +} + +impl From for Snapshot { + fn from(snapshot: evm_gasometer::Snapshot) -> Self { + Self { + gas_limit: snapshot.gas_limit, + memory_gas: snapshot.memory_gas, + used_gas: snapshot.used_gas, + refunded_gas: snapshot.refunded_gas, + } + } +} + +impl From> for Snapshot { + fn from(snapshot_opt: Option) -> Self { + if let Some(snapshot) = snapshot_opt { + snapshot.into() + } else { + Snapshot::default() + } + } +} + +#[derive(Debug, Copy, Clone, Encode, Decode, PartialEq, Eq)] +pub enum GasometerEvent { + RecordCost { + cost: u64, + snapshot: Snapshot, + }, + RecordRefund { + refund: i64, + snapshot: Snapshot, + }, + RecordStipend { + stipend: u64, + snapshot: Snapshot, + }, + RecordDynamicCost { + gas_cost: u64, + memory_gas: u64, + gas_refund: i64, + snapshot: Snapshot, + }, + RecordTransaction { + cost: u64, + snapshot: Snapshot, + }, +} + +#[cfg(feature = "evm-tracing")] +impl From for GasometerEvent { + fn from(i: evm_gasometer::tracing::Event) -> Self { + match i { + evm_gasometer::tracing::Event::RecordCost { cost, snapshot } => Self::RecordCost { + cost, + snapshot: snapshot.into(), + }, + evm_gasometer::tracing::Event::RecordRefund { refund, snapshot } => { + Self::RecordRefund { + refund, + snapshot: snapshot.into(), + } + } + evm_gasometer::tracing::Event::RecordStipend { stipend, snapshot } => { + Self::RecordStipend { + stipend, + snapshot: snapshot.into(), + } + } + evm_gasometer::tracing::Event::RecordDynamicCost { + gas_cost, + memory_gas, + gas_refund, + snapshot, + } => Self::RecordDynamicCost { + gas_cost, + memory_gas, + gas_refund, + snapshot: snapshot.into(), + }, + evm_gasometer::tracing::Event::RecordTransaction { cost, snapshot } => { + Self::RecordTransaction { + cost, + snapshot: snapshot.into(), + } + } + } + } +} diff --git a/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/lib.rs b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/lib.rs new file mode 100644 index 00000000..fcc8f3d8 --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/lib.rs @@ -0,0 +1,284 @@ +// 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 . + +//! A Proxy in this context is an environmental trait implementor meant to be used for capturing +//! EVM trace events sent to a Host function from the Runtime. Works like: +//! - Runtime Api call `using` environmental. +//! - Runtime calls a Host function with some scale-encoded Evm event. +//! - Host function emits an additional event to this Listener. +//! - Proxy listens for the event and format the actual trace response. +//! +//! There are two proxy types: `Raw` and `CallList`. +//! - `Raw` - used for opcode-level traces. +//! - `CallList` - used for block tracing (stack of call stacks) and custom tracing outputs. +//! +//! The EVM event types may contain references and not implement Encode/Decode. +//! This module provide mirror types and conversion into them from the original events. + +#![cfg_attr(not(feature = "std"), no_std)] +extern crate alloc; + +pub mod evm; +pub mod gasometer; +pub mod runtime; + +pub use self::evm::EvmEvent; +pub use gasometer::GasometerEvent; +pub use runtime::RuntimeEvent; + +use ::evm::Opcode; +use alloc::vec::Vec; +use ethereum_types::{H160, U256}; +use parity_scale_codec::{Decode, Encode}; +use sp_runtime_interface::pass_by::PassByCodec; + +environmental::environmental!(listener: dyn Listener + 'static); + +pub fn using R>(l: &mut (dyn Listener + 'static), f: F) -> R { + listener::using(l, f) +} + +/// Allow to configure which data of the Step event +/// we want to keep or discard. Not discarding the data requires cloning the data +/// in the runtime which have a significant cost for each step. +#[derive(Clone, Copy, Eq, PartialEq, Debug, Encode, Decode, Default, PassByCodec)] +pub struct StepEventFilter { + pub enable_stack: bool, + pub enable_memory: bool, +} + +#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode)] +pub enum Event { + Evm(evm::EvmEvent), + Gasometer(gasometer::GasometerEvent), + Runtime(runtime::RuntimeEvent), + CallListNew(), +} + +impl Event { + /// Access the global reference and call it's `event` method, passing the `Event` itself as + /// argument. + /// + /// This only works if we are `using` a global reference to a `Listener` implementor. + pub fn emit(self) { + listener::with(|listener| listener.event(self)); + } +} + +/// Main trait to proxy emitted messages. +/// Used 2 times : +/// - Inside the runtime to proxy the events throught the host functions +/// - Inside the client to forward those events to the client listener. +pub trait Listener { + fn event(&mut self, event: Event); + + /// Allow the runtime to know which data should be discarded and not cloned. + /// WARNING: It is only called once when the runtime tracing is instanciated to avoid + /// performing many ext calls. + fn step_event_filter(&self) -> StepEventFilter; +} + +pub fn step_event_filter() -> Option { + let mut filter = None; + listener::with(|listener| filter = Some(listener.step_event_filter())); + filter +} + +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] +pub struct Context { + /// Execution address. + pub address: H160, + /// Caller of the EVM. + pub caller: H160, + /// Apparent value of the EVM. + pub apparent_value: U256, +} + +impl From for Context { + fn from(i: evm_runtime::Context) -> Self { + Self { + address: i.address, + caller: i.caller, + apparent_value: i.apparent_value, + } + } +} + +/// Converts an Opcode into its name, stored in a `Vec`. +pub fn opcodes_string(opcode: Opcode) -> Vec { + let tmp; + let out = match opcode { + Opcode(0) => "Stop", + Opcode(1) => "Add", + Opcode(2) => "Mul", + Opcode(3) => "Sub", + Opcode(4) => "Div", + Opcode(5) => "SDiv", + Opcode(6) => "Mod", + Opcode(7) => "SMod", + Opcode(8) => "AddMod", + Opcode(9) => "MulMod", + Opcode(10) => "Exp", + Opcode(11) => "SignExtend", + Opcode(16) => "Lt", + Opcode(17) => "Gt", + Opcode(18) => "Slt", + Opcode(19) => "Sgt", + Opcode(20) => "Eq", + Opcode(21) => "IsZero", + Opcode(22) => "And", + Opcode(23) => "Or", + Opcode(24) => "Xor", + Opcode(25) => "Not", + Opcode(26) => "Byte", + Opcode(27) => "Shl", + Opcode(28) => "Shr", + Opcode(29) => "Sar", + Opcode(32) => "Keccak256", + Opcode(48) => "Address", + Opcode(49) => "Balance", + Opcode(50) => "Origin", + Opcode(51) => "Caller", + Opcode(52) => "CallValue", + Opcode(53) => "CallDataLoad", + Opcode(54) => "CallDataSize", + Opcode(55) => "CallDataCopy", + Opcode(56) => "CodeSize", + Opcode(57) => "CodeCopy", + Opcode(58) => "GasPrice", + Opcode(59) => "ExtCodeSize", + Opcode(60) => "ExtCodeCopy", + Opcode(61) => "ReturnDataSize", + Opcode(62) => "ReturnDataCopy", + Opcode(63) => "ExtCodeHash", + Opcode(64) => "BlockHash", + Opcode(65) => "Coinbase", + Opcode(66) => "Timestamp", + Opcode(67) => "Number", + Opcode(68) => "Difficulty", + Opcode(69) => "GasLimit", + Opcode(70) => "ChainId", + Opcode(80) => "Pop", + Opcode(81) => "MLoad", + Opcode(82) => "MStore", + Opcode(83) => "MStore8", + Opcode(84) => "SLoad", + Opcode(85) => "SStore", + Opcode(86) => "Jump", + Opcode(87) => "JumpI", + Opcode(88) => "GetPc", + Opcode(89) => "MSize", + Opcode(90) => "Gas", + Opcode(91) => "JumpDest", + Opcode(96) => "Push1", + Opcode(97) => "Push2", + Opcode(98) => "Push3", + Opcode(99) => "Push4", + Opcode(100) => "Push5", + Opcode(101) => "Push6", + Opcode(102) => "Push7", + Opcode(103) => "Push8", + Opcode(104) => "Push9", + Opcode(105) => "Push10", + Opcode(106) => "Push11", + Opcode(107) => "Push12", + Opcode(108) => "Push13", + Opcode(109) => "Push14", + Opcode(110) => "Push15", + Opcode(111) => "Push16", + Opcode(112) => "Push17", + Opcode(113) => "Push18", + Opcode(114) => "Push19", + Opcode(115) => "Push20", + Opcode(116) => "Push21", + Opcode(117) => "Push22", + Opcode(118) => "Push23", + Opcode(119) => "Push24", + Opcode(120) => "Push25", + Opcode(121) => "Push26", + Opcode(122) => "Push27", + Opcode(123) => "Push28", + Opcode(124) => "Push29", + Opcode(125) => "Push30", + Opcode(126) => "Push31", + Opcode(127) => "Push32", + Opcode(128) => "Dup1", + Opcode(129) => "Dup2", + Opcode(130) => "Dup3", + Opcode(131) => "Dup4", + Opcode(132) => "Dup5", + Opcode(133) => "Dup6", + Opcode(134) => "Dup7", + Opcode(135) => "Dup8", + Opcode(136) => "Dup9", + Opcode(137) => "Dup10", + Opcode(138) => "Dup11", + Opcode(139) => "Dup12", + Opcode(140) => "Dup13", + Opcode(141) => "Dup14", + Opcode(142) => "Dup15", + Opcode(143) => "Dup16", + Opcode(144) => "Swap1", + Opcode(145) => "Swap2", + Opcode(146) => "Swap3", + Opcode(147) => "Swap4", + Opcode(148) => "Swap5", + Opcode(149) => "Swap6", + Opcode(150) => "Swap7", + Opcode(151) => "Swap8", + Opcode(152) => "Swap9", + Opcode(153) => "Swap10", + Opcode(154) => "Swap11", + Opcode(155) => "Swap12", + Opcode(156) => "Swap13", + Opcode(157) => "Swap14", + Opcode(158) => "Swap15", + Opcode(159) => "Swap16", + Opcode(160) => "Log0", + Opcode(161) => "Log1", + Opcode(162) => "Log2", + Opcode(163) => "Log3", + Opcode(164) => "Log4", + Opcode(176) => "JumpTo", + Opcode(177) => "JumpIf", + Opcode(178) => "JumpSub", + Opcode(180) => "JumpSubv", + Opcode(181) => "BeginSub", + Opcode(182) => "BeginData", + Opcode(184) => "ReturnSub", + Opcode(185) => "PutLocal", + Opcode(186) => "GetLocal", + Opcode(225) => "SLoadBytes", + Opcode(226) => "SStoreBytes", + Opcode(227) => "SSize", + Opcode(240) => "Create", + Opcode(241) => "Call", + Opcode(242) => "CallCode", + Opcode(243) => "Return", + Opcode(244) => "DelegateCall", + Opcode(245) => "Create2", + Opcode(250) => "StaticCall", + Opcode(252) => "TxExecGas", + Opcode(253) => "Revert", + Opcode(254) => "Invalid", + Opcode(255) => "SelfDestruct", + Opcode(n) => { + tmp = alloc::format!("Unknown({})", n); + &tmp + } + }; + out.as_bytes().to_vec() +} diff --git a/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/runtime.rs b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/runtime.rs new file mode 100644 index 00000000..d9ba718d --- /dev/null +++ b/tracing/2902/shared/primitives/rpc/evm-tracing-events/src/runtime.rs @@ -0,0 +1,156 @@ +// 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 . + +extern crate alloc; + +use super::{opcodes_string, Context, StepEventFilter}; +use alloc::vec::Vec; +use ethereum_types::{H160, H256, U256}; +pub use evm::{ExitError, ExitReason, ExitSucceed, Opcode}; +use parity_scale_codec::{Decode, Encode}; + +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] +pub struct Stack { + pub data: Vec, + pub limit: u64, +} + +impl From<&evm::Stack> for Stack { + fn from(i: &evm::Stack) -> Self { + Self { + data: i.data().clone(), + limit: i.limit() as u64, + } + } +} + +#[derive(Clone, Debug, Encode, Decode, PartialEq, Eq)] +pub struct Memory { + pub data: Vec, + pub effective_len: U256, + pub limit: u64, +} + +impl From<&evm::Memory> for Memory { + fn from(i: &evm::Memory) -> Self { + Self { + data: i.data().clone(), + effective_len: i.effective_len(), + limit: i.limit() as u64, + } + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Encode, Decode)] +pub enum Capture { + /// The machine has exited. It cannot be executed again. + Exit(E), + /// The machine has trapped. It is waiting for external information, and can + /// be executed again. + Trap(T), +} + +pub type Trap = Vec; // Should hold the marshalled Opcode. + +#[derive(Debug, Clone, Encode, Decode, PartialEq, Eq)] +pub enum RuntimeEvent { + Step { + context: Context, + // This needs to be marshalled in the runtime no matter what. + opcode: Vec, + // We can use ExitReason with `with-codec` feature, + position: Result, + stack: Option, + memory: Option, + }, + StepResult { + result: Result<(), Capture>, + return_value: Vec, + }, + SLoad { + address: H160, + index: H256, + value: H256, + }, + SStore { + address: H160, + index: H256, + value: H256, + }, +} + +#[cfg(feature = "evm-tracing")] +impl RuntimeEvent { + pub fn from_evm_event<'a>(i: evm_runtime::tracing::Event<'a>, filter: StepEventFilter) -> Self { + match i { + evm_runtime::tracing::Event::Step { + context, + opcode, + position, + stack, + memory, + } => Self::Step { + context: context.clone().into(), + opcode: opcodes_string(opcode), + position: match position { + Ok(position) => Ok(*position as u64), + Err(e) => Err(e.clone()), + }, + stack: if filter.enable_stack { + Some(stack.into()) + } else { + None + }, + memory: if filter.enable_memory { + Some(memory.into()) + } else { + None + }, + }, + evm_runtime::tracing::Event::StepResult { + result, + return_value, + } => Self::StepResult { + result: match result { + Ok(_) => Ok(()), + Err(capture) => match capture { + evm::Capture::Exit(e) => Err(Capture::Exit(e.clone())), + evm::Capture::Trap(t) => Err(Capture::Trap(opcodes_string(*t))), + }, + }, + return_value: return_value.to_vec(), + }, + evm_runtime::tracing::Event::SLoad { + address, + index, + value, + } => Self::SLoad { + address, + index, + value, + }, + evm_runtime::tracing::Event::SStore { + address, + index, + value, + } => Self::SStore { + address, + index, + value, + }, + } + } +} diff --git a/tracing/2902/shared/runtime/evm_tracer/Cargo.toml b/tracing/2902/shared/runtime/evm_tracer/Cargo.toml new file mode 100644 index 00000000..1b724f04 --- /dev/null +++ b/tracing/2902/shared/runtime/evm_tracer/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "moonbeam-evm-tracer" +authors = [ "PureStake" ] +edition = "2018" +homepage = "https://moonbeam.network" +license = "GPL-3.0-only" +repository = "https://github.com/PureStake/moonbeam/" +version = "0.1.0" + +[dependencies] +# In those shared code the branch is irrelevant as long as revers to a rust2018 workspace. +# Each version of the runtime will patch the Subtrate and Frontier dependencies to the correct +# git repo and branch. Since cargo don't want to patch with the same repo url, we use a dummy fork +# not used in the runtimes. + +# Moonbeam +evm-tracing-events = { workspace = true, features = [ "evm-tracing" ] } +moonbeam-primitives-ext = { workspace = true } + +# Substrate +parity-scale-codec = { workspace = true } +sp-core = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } + +# Frontier +ethereum-types = { workspace = true } +evm = { workspace = true, features = [ "with-codec" ] } +evm-gasometer = { workspace = true } +evm-runtime = { workspace = true } +fp-evm = { workspace = true } +pallet-evm = { workspace = true } + +[features] +default = [ "std" ] +std = [ + "parity-scale-codec/std", + "ethereum-types/std", + "evm-gasometer/std", + "evm-runtime/std", + "evm-tracing-events/std", + "evm/std", + "evm/with-serde", + "fp-evm/std", + "moonbeam-primitives-ext/std", + "pallet-evm/std", + "sp-core/std", + "sp-runtime/std", + "sp-std/std", +] diff --git a/tracing/2902/shared/runtime/evm_tracer/src/lib.rs b/tracing/2902/shared/runtime/evm_tracer/src/lib.rs new file mode 100644 index 00000000..5d998775 --- /dev/null +++ b/tracing/2902/shared/runtime/evm_tracer/src/lib.rs @@ -0,0 +1,117 @@ +// 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 . + +//! Substrate EVM tracing. +//! +//! The purpose of this crate is enable tracing the EVM opcode execution and will be used by +//! both Dapp developers - to get a granular view on their transactions - and indexers to access +//! the EVM callstack (internal transactions). +//! +//! Proxies EVM messages to the host functions. + +#![cfg_attr(not(feature = "std"), no_std)] + +pub mod tracer { + use evm_tracing_events::{EvmEvent, GasometerEvent, RuntimeEvent, StepEventFilter}; + use parity_scale_codec::Encode; + + use evm::tracing::{using as evm_using, EventListener as EvmListener}; + use evm_gasometer::tracing::{using as gasometer_using, EventListener as GasometerListener}; + use evm_runtime::tracing::{using as runtime_using, EventListener as RuntimeListener}; + use sp_std::{cell::RefCell, rc::Rc}; + + struct ListenerProxy(pub Rc>); + impl GasometerListener for ListenerProxy { + fn event(&mut self, event: evm_gasometer::tracing::Event) { + self.0.borrow_mut().event(event); + } + } + + impl RuntimeListener for ListenerProxy { + fn event(&mut self, event: evm_runtime::tracing::Event) { + self.0.borrow_mut().event(event); + } + } + + impl EvmListener for ListenerProxy { + fn event(&mut self, event: evm::tracing::Event) { + self.0.borrow_mut().event(event); + } + } + + pub struct EvmTracer { + step_event_filter: StepEventFilter, + } + + impl EvmTracer { + pub fn new() -> Self { + Self { + step_event_filter: moonbeam_primitives_ext::moonbeam_ext::step_event_filter(), + } + } + + /// Setup event listeners and execute provided closure. + /// + /// Consume the tracer and return it alongside the return value of + /// the closure. + pub fn trace R>(self, f: F) { + let wrapped = Rc::new(RefCell::new(self)); + + let mut gasometer = ListenerProxy(Rc::clone(&wrapped)); + let mut runtime = ListenerProxy(Rc::clone(&wrapped)); + let mut evm = ListenerProxy(Rc::clone(&wrapped)); + + // Each line wraps the previous `f` into a `using` call. + // Listening to new events results in adding one new line. + // Order is irrelevant when registering listeners. + let f = || runtime_using(&mut runtime, f); + let f = || gasometer_using(&mut gasometer, f); + let f = || evm_using(&mut evm, f); + f(); + } + + pub fn emit_new() { + moonbeam_primitives_ext::moonbeam_ext::call_list_new(); + } + } + + impl EvmListener for EvmTracer { + /// Proxies `evm::tracing::Event` to the host. + fn event(&mut self, event: evm::tracing::Event) { + let event: EvmEvent = event.into(); + let message = event.encode(); + moonbeam_primitives_ext::moonbeam_ext::evm_event(message); + } + } + + impl GasometerListener for EvmTracer { + /// Proxies `evm_gasometer::tracing::Event` to the host. + fn event(&mut self, event: evm_gasometer::tracing::Event) { + let event: GasometerEvent = event.into(); + let message = event.encode(); + moonbeam_primitives_ext::moonbeam_ext::gasometer_event(message); + } + } + + impl RuntimeListener for EvmTracer { + /// Proxies `evm_runtime::tracing::Event` to the host. + fn event(&mut self, event: evm_runtime::tracing::Event) { + let event = RuntimeEvent::from_evm_event(event, self.step_event_filter); + let message = event.encode(); + moonbeam_primitives_ext::moonbeam_ext::runtime_event(message); + } + } +} diff --git a/wasm/moonbase-runtime-2902-substitute-tracing.wasm b/wasm/moonbase-runtime-2902-substitute-tracing.wasm new file mode 100644 index 00000000..5e073fb3 Binary files /dev/null and b/wasm/moonbase-runtime-2902-substitute-tracing.wasm differ diff --git a/wasm/moonbeam-runtime-2902-substitute-tracing.wasm b/wasm/moonbeam-runtime-2902-substitute-tracing.wasm new file mode 100644 index 00000000..6f182a4e Binary files /dev/null and b/wasm/moonbeam-runtime-2902-substitute-tracing.wasm differ diff --git a/wasm/moonriver-runtime-2902-substitute-tracing.wasm b/wasm/moonriver-runtime-2902-substitute-tracing.wasm new file mode 100644 index 00000000..905f275f Binary files /dev/null and b/wasm/moonriver-runtime-2902-substitute-tracing.wasm differ