diff --git a/Cargo.lock b/Cargo.lock index 2d7f7f83f..f8c3b0b04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "aquamarine" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074b80d14d0240b6ce94d68f059a2d26a5d77280ae142662365a21ef6e2594ef" +checksum = "21cc1548309245035eb18aa7f0967da6bc65587005170c56e6ef2788a4cf3f4e" dependencies = [ "include_dir", "itertools 0.10.5", @@ -701,6 +701,41 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "bifrost-buy-back" +version = "0.8.0" +dependencies = [ + "bifrost-asset-registry", + "bifrost-currencies", + "bifrost-primitives", + "bifrost-slp", + "bifrost-ve-minting", + "bifrost-vtoken-minting", + "cumulus-primitives-core", + "env_logger", + "frame-benchmarking", + "frame-support", + "frame-system", + "hex-literal 0.4.1", + "log", + "orml-tokens", + "orml-traits", + "orml-xtokens", + "pallet-balances", + "pallet-xcm", + "parity-scale-codec", + "scale-info", + "sp-arithmetic", + "sp-core", + "sp-io", + "sp-runtime", + "sp-std", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "zenlink-protocol", +] + [[package]] name = "bifrost-call-switchgear" version = "0.8.0" @@ -743,7 +778,7 @@ dependencies = [ [[package]] name = "bifrost-cli" -version = "0.10.0" +version = "0.11.0" dependencies = [ "bifrost-primitives", "bifrost-service", @@ -984,6 +1019,55 @@ dependencies = [ "sp-api", ] +[[package]] +name = "bifrost-integration-tests" +version = "0.8.0" +dependencies = [ + "bifrost-asset-registry", + "bifrost-currencies", + "bifrost-polkadot-runtime", + "bifrost-primitives", + "bifrost-runtime-common", + "bifrost-slp", + "bifrost-vtoken-voting", + "bifrost-xcm-interface", + "cumulus-primitives-core", + "env_logger", + "frame-support", + "frame-system", + "hex-literal 0.4.1", + "log", + "orml-tokens", + "orml-traits", + "orml-xtokens", + "pallet-assets", + "pallet-balances", + "pallet-conviction-voting", + "pallet-message-queue", + "pallet-referenda", + "pallet-staking", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-parachain-primitives", + "polkadot-runtime-common", + "polkadot-runtime-parachains", + "scale-info", + "serde", + "sp-core", + "sp-io", + "sp-runtime", + "sp-staking", + "sp-std", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "xcm-emulator", + "xcm-simulator", +] + [[package]] name = "bifrost-kusama-runtime" version = "0.8.0" @@ -1015,10 +1099,10 @@ dependencies = [ "bifrost-vsbond-auction", "bifrost-vstoken-conversion", "bifrost-vtoken-minting", + "bifrost-vtoken-minting-rpc-runtime-api", "bifrost-vtoken-voting", "bifrost-xcm-interface", "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", @@ -1141,6 +1225,7 @@ name = "bifrost-polkadot-runtime" version = "0.8.0" dependencies = [ "bifrost-asset-registry", + "bifrost-buy-back", "bifrost-call-switchgear", "bifrost-channel-commission", "bifrost-clouds-convert", @@ -1167,10 +1252,10 @@ dependencies = [ "bifrost-vesting", "bifrost-vstoken-conversion", "bifrost-vtoken-minting", + "bifrost-vtoken-minting-rpc-runtime-api", "bifrost-vtoken-voting", "bifrost-xcm-interface", "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", @@ -1296,6 +1381,8 @@ dependencies = [ "bifrost-stable-pool-rpc-runtime-api", "bifrost-ve-minting-rpc", "bifrost-ve-minting-rpc-runtime-api", + "bifrost-vtoken-minting-rpc", + "bifrost-vtoken-minting-rpc-runtime-api", "jsonrpsee", "lend-market-rpc", "lend-market-rpc-runtime-api", @@ -1323,7 +1410,6 @@ dependencies = [ "bifrost-asset-registry", "bifrost-primitives", "bifrost-xcm-interface", - "cumulus-pallet-dmp-queue", "cumulus-pallet-parachain-system", "cumulus-pallet-xcm", "cumulus-pallet-xcmp-queue", @@ -1579,6 +1665,7 @@ dependencies = [ "frame-system", "hex", "hex-literal 0.4.1", + "log", "orml-tokens", "orml-traits", "orml-xtokens", @@ -1925,6 +2012,33 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "bifrost-vtoken-minting-rpc" +version = "0.8.0" +dependencies = [ + "bifrost-primitives", + "bifrost-vtoken-minting-rpc-runtime-api", + "jsonrpsee", + "parity-scale-codec", + "serde", + "sp-api", + "sp-blockchain", + "sp-core", + "sp-rpc", + "sp-runtime", +] + +[[package]] +name = "bifrost-vtoken-minting-rpc-runtime-api" +version = "0.8.0" +dependencies = [ + "bifrost-primitives", + "parity-scale-codec", + "sp-api", + "sp-core", + "sp-std", +] + [[package]] name = "bifrost-vtoken-voting" version = "0.8.0" @@ -1978,9 +2092,9 @@ dependencies = [ [[package]] name = "binary-merkle-tree" -version = "13.0.0" +version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bf2706ac2641485d35ed06ebfe0b3b2c43e19a7ad8a90215580a91dd1766114" +checksum = "2bf857f8f411164ce1af14a778626af96251de7a77837711efbc440807e7053f" dependencies = [ "hash-db 0.16.0", "log", @@ -2160,9 +2274,9 @@ dependencies = [ [[package]] name = "bounded-collections" -version = "0.1.9" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca548b6163b872067dc5eb82fd130c56881435e30367d2073594a3d9744120dd" +checksum = "d32385ecb91a31bddaf908e8dcf4a15aef1bcd3913cc03ebfad02ff6d568abc1" dependencies = [ "log", "parity-scale-codec", @@ -2181,9 +2295,9 @@ dependencies = [ [[package]] name = "bp-xcm-bridge-hub-router" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f58cd5d7880f4bc8fc569e5bb0174302cd3f7e18a322e0fec2a4733cced35cb" +checksum = "86ff4abe93be7bc1663adc41817b1aa3476fbec953ce361537419924310d5dd4" dependencies = [ "parity-scale-codec", "scale-info", @@ -2217,16 +2331,6 @@ dependencies = [ "regex-automata 0.1.10", ] -[[package]] -name = "bstr" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706" -dependencies = [ - "memchr", - "serde", -] - [[package]] name = "bstringify" version = "0.1.2" @@ -2475,9 +2579,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.14" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33e92c5c1a78c62968ec57dbc2440366a2d6e5a23faf829970ff1585dc6b18e2" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", @@ -2485,9 +2589,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.14" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4323769dc8a61e2c39ad7dc26f6f2800524691a44d74fe3d1071a5c24db6370" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ "anstream", "anstyle", @@ -2498,11 +2602,11 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.4.7" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.60", @@ -2510,9 +2614,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "coarsetime" @@ -2894,9 +2998,9 @@ dependencies = [ [[package]] name = "cumulus-client-cli" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88972dcd58e7d411ebfd9d82d7399aad567afe737ba8ad0943abfaf1a8b3903b" +checksum = "70d2597fe3235d263457aaff65d0fb5bed506698b81530e2e6afecd6d6c9af32" dependencies = [ "clap", "parity-scale-codec", @@ -2912,9 +3016,9 @@ dependencies = [ [[package]] name = "cumulus-client-collator" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9d9114479da745e34b1a4529dca9e51a61860593b61681107249bc68024bd4" +checksum = "3c06ae72a125d056da3b722f00f87881a2afbb2af8fe9fa9a91587f139b9667e" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", @@ -2936,9 +3040,9 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-aura" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00378c991116820c354713b3d3be2c9789f84bfb86d0a3c97676cc9e8a39c174" +checksum = "18f4977f6a88af39c46832d571ac0d95e8322bf22eab42550fec34f72da9f034" dependencies = [ "async-trait", "cumulus-client-collator", @@ -2979,9 +3083,9 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "385c403c208f654e276f6d7ae30316d3d64f0975c9e19a18ed5943a963cc48c6" +checksum = "350db1fc8841a44f344474b791d2ebe61b79bf6061043a7d826b3d02d1935a56" dependencies = [ "async-trait", "cumulus-client-pov-recovery", @@ -3009,9 +3113,9 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-proposer" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "614b239940f64843c65ec19e157ee769c556f74f084077dc2f0425f0a671e9ba" +checksum = "38028f75597a34d447f059d6a7fd9c1c91bce0b8c48b08b1cbd19eb3def9c376" dependencies = [ "anyhow", "async-trait", @@ -3025,9 +3129,9 @@ dependencies = [ [[package]] name = "cumulus-client-network" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee9b8802b76850237bbf2c1afb869a9673b49ef9545b31698e1bffbffcaa4254" +checksum = "0ac095ef439c595ccb998be5a9d40778d8963c5a8ebbaed838fed6293232915b" dependencies = [ "async-trait", "cumulus-relay-chain-interface", @@ -3049,9 +3153,9 @@ dependencies = [ [[package]] name = "cumulus-client-parachain-inherent" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bcc095540bb3ad848b1d5cd8708d8b493729370d4671df5a0c38ea53382e46b" +checksum = "0b516290cd4a6efc117824135761f3642dc57685e13da00727c460053ce978fe" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3062,7 +3166,7 @@ dependencies = [ "sc-client-api", "scale-info", "sp-api", - "sp-core", + "sp-crypto-hashing", "sp-inherents", "sp-runtime", "sp-state-machine", @@ -3074,9 +3178,9 @@ dependencies = [ [[package]] name = "cumulus-client-pov-recovery" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddd12cbdd57209ffc68d167b0c22c90d5680185b57d03e4c2436aef7dfd918a2" +checksum = "b4d55e96004ca9aa9d9b96a28ab2d97b1ca8d303c9d2405ea34cdf1462d4c4f0" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3099,9 +3203,9 @@ dependencies = [ [[package]] name = "cumulus-client-service" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5be0615943319f8750eb54793f8ec8721b2081852c23ed450da54cfcf6aca97" +checksum = "657f57c56159bb6cb74d9221de8f11c9e09962666381357896562662d3019799" dependencies = [ "cumulus-client-cli", "cumulus-client-collator", @@ -3136,9 +3240,9 @@ dependencies = [ [[package]] name = "cumulus-pallet-aura-ext" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8100a3283be2c46905345141e9a063f092949c6630a1fb70993b04c97f309e55" +checksum = "9e8e78b18548ae3454bc8a46e2bc2e3f521ea547844cbaecc9344d4741f4b1ef" dependencies = [ "cumulus-pallet-parachain-system", "frame-support", @@ -3153,30 +3257,11 @@ dependencies = [ "sp-std", ] -[[package]] -name = "cumulus-pallet-dmp-queue" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f461956a4a85c053657fe64e73852940c8a52e7d8fc20ccb4f91688e73f0820b" -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" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a1a0e6800ea92447eab2c9170cc77d21987fd0e61ed79a6e1318f7b127b3e2c" +checksum = "1a215fe4d66d23e8f3956bd21b9d80d2b33239f3b150b36d56fa238cfc9421a5" dependencies = [ "bytes", "cumulus-pallet-parachain-system-proc-macro", @@ -3192,6 +3277,7 @@ dependencies = [ "pallet-message-queue", "parity-scale-codec", "polkadot-parachain-primitives", + "polkadot-runtime-common", "polkadot-runtime-parachains", "scale-info", "sp-core", @@ -3221,9 +3307,9 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcm" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9e5e8dd3f9c98620e32cbb1783725a3e75a3147cb351b43de37663824311cd9" +checksum = "8e802291060763f8d1176bf808da97aafe5afe7351f62bb093c317c1d35c5cee" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -3238,9 +3324,9 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcmp-queue" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439cdba45813623e7f45374f160f3356d27fb1aaca2536dd7f60ef2a7e9b30cd" +checksum = "0fa22d6e479a4d3a2790bab291269ba0917a1ac384255a54a2ebc3f7c37e505e" dependencies = [ "bounded-collections", "bp-xcm-bridge-hub-router", @@ -3264,9 +3350,9 @@ dependencies = [ [[package]] name = "cumulus-primitives-aura" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ad9d2b1454d6957a92b3f8755d7bfa2b5b70ab2fa7751215f6897de5ac4cf6" +checksum = "2f07d6177692154043d7ddcc0b87ca5365ae8e4d94b90d9931f6b2f76e162f09" dependencies = [ "parity-scale-codec", "polkadot-core-primitives", @@ -3279,9 +3365,9 @@ dependencies = [ [[package]] name = "cumulus-primitives-core" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "036b64697b5fd04c8039ccf15b9891104c496afb6c418c2cea1234d4898d0a28" +checksum = "9df07f6825fd50ea30aae335e43dc1a615a05de7465f5f329b9e414f2c886a12" dependencies = [ "parity-scale-codec", "polkadot-core-primitives", @@ -3297,9 +3383,9 @@ dependencies = [ [[package]] name = "cumulus-primitives-parachain-inherent" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cb6fe06744fed6e84682c48816181ad63652003570c2135c425481440fcd2f2" +checksum = "38ad140a065a6b8001fb26ec42b91391e90fde120f5b4e57986698249a9b98c8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3313,9 +3399,9 @@ dependencies = [ [[package]] name = "cumulus-primitives-proof-size-hostfunction" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a132e17ac2c79436bc5004b0d56cb35ca65b966434f14e5ff8a9bc1afcfca5a4" +checksum = "c1b74f9141190b9f4bf96a947ade46da64097b77f1ebfa8d611c81724250e119" dependencies = [ "sp-externalities", "sp-runtime-interface", @@ -3324,9 +3410,9 @@ dependencies = [ [[package]] name = "cumulus-primitives-timestamp" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d1d900bd9e76607a4a0734cbb2b004d86177d2d6938b5d25eb812c6c1b7500" +checksum = "34584abda4aeac69abe08ba3146d0ca059cd5636a8c4ccf680f2b9f99fc5f8ee" dependencies = [ "cumulus-primitives-core", "futures 0.3.30", @@ -3338,14 +3424,14 @@ dependencies = [ [[package]] name = "cumulus-primitives-utility" -version = "0.7.3" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2ece52eeb7e87faea0d374356571ebc13f279df3bf79a1dc8a0db6c49d6ba23" +checksum = "e65466e56d642f979b556d098a03755ae51972fff5fa0f9b1cdcfdb3df062ea3" dependencies = [ "cumulus-primitives-core", "frame-support", "log", - "pallet-xcm-benchmarks", + "pallet-asset-conversion", "parity-scale-codec", "polkadot-runtime-common", "polkadot-runtime-parachains", @@ -3359,9 +3445,9 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-inprocess-interface" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6801c53e543614ce1b9f87cfca8ed69aab5318ba51439c0db8a910c8c3d77a15" +checksum = "cff27dec2eab6cd1d854756d62bd7053721ccd115f36f9e8b0976b1e46b70ef7" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3384,9 +3470,9 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-interface" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf9bd710caacdee77f50f01a40f37f8c9af1040e895de3e0b421f2c4ad0a291" +checksum = "40c736f39b50eecf194707e15d0359677bb8fe8138b01f6493ab9b7e10d2d1ae" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3403,9 +3489,9 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-minimal-node" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b1e0847e45d6a5090ee32b4dc3497cb0671b9a6a9259f9a263a769560c5b60e" +checksum = "4c7718fe298d567adc44fae3dd7024418d6eff08264041e4b0544d1892861cd6" dependencies = [ "array-bytes 6.2.2", "async-trait", @@ -3445,9 +3531,9 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-rpc-interface" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cb8a4c98335aeac261bde9b21e7518c099bfacc96592a052750051cebda158c" +checksum = "d8e2269d4c1f37593257b3d7b90f8b56adab0793d9b9f5c1b5334c9ca7e3b10b" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3485,9 +3571,9 @@ dependencies = [ [[package]] name = "cumulus-test-relay-sproof-builder" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0ec12490a40b00427119fd1e12a6d1fe0652d2df3e992dea1bc4f331effed12" +checksum = "bfff604ad01c5c0c397f9a971c8cec6443aea3658813778875b4f64de07847d5" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", @@ -3967,7 +4053,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "syn 1.0.109", @@ -4370,9 +4456,9 @@ checksum = "6c2141d6d6c8512188a7891b4b01590a45f6dac67afb4f255c4124dbb86d4eaa" [[package]] name = "frame-benchmarking" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b16f7f853f64ec6fbc981b3e224cc3400752662da140ec62c160b5b859bab68" +checksum = "4090659c6aaa3c4d5b6c6ec909b4b0a25dec10ad92aad5f729efa8d5bd4d806a" dependencies = [ "frame-support", "frame-support-procedural", @@ -4396,9 +4482,9 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" -version = "32.0.0" +version = "33.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fec078a73892cb5a7146671cf76e3abf23201fefe431a013399ac2e5b03b54" +checksum = "efe02c96362e3c7308cdea7545859f767194a1f3f00928f0e1357f4b8a0b3b2c" dependencies = [ "Inflector", "array-bytes 6.2.2", @@ -4457,9 +4543,9 @@ dependencies = [ [[package]] name = "frame-election-provider-support" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c596d956c4eedaffbe2fd6f75562e63e3e60001222bc6f8cc45fa77f3ea51791" +checksum = "87da19ee99e6473cd057ead84337d20011fe5e299c6750e88e43b8b7963b8852" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -4475,9 +4561,9 @@ dependencies = [ [[package]] name = "frame-executive" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5247e367912fe95f813e96542921ab4edf671860fd557625b55f40155abf90" +checksum = "09bff9574ee2dcc349f646e1d2faadf76afd688c2ea1bbac5e4a0e19a0c19c59" dependencies = [ "frame-support", "frame-system", @@ -4506,9 +4592,9 @@ dependencies = [ [[package]] name = "frame-remote-externalities" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26ac8b505de5aa10e9c9548a3642fc708fc47fe3843b840992e6e6ab139f39d0" +checksum = "360bfdb6821372164a65933d9a6d5998f38c722360b59b69d2bf78a87ef58b2a" dependencies = [ "futures 0.3.30", "indicatif", @@ -4517,6 +4603,7 @@ dependencies = [ "parity-scale-codec", "serde", "sp-core", + "sp-crypto-hashing", "sp-io", "sp-runtime", "sp-state-machine", @@ -4528,9 +4615,9 @@ dependencies = [ [[package]] name = "frame-support" -version = "28.0.0" +version = "29.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48b00bb3e82c465a435b08827e7abe5144345bc1a998848bdd7ce72fa203bb5" +checksum = "b8e52c84b611d2049d9253f83a62ab0f093e4be5c42a7ef42ea5bb16d6611e32" dependencies = [ "aquamarine", "array-bytes 6.2.2", @@ -4552,7 +4639,7 @@ dependencies = [ "sp-api", "sp-arithmetic", "sp-core", - "sp-core-hashing-proc-macro", + "sp-crypto-hashing-proc-macro", "sp-debug-derive", "sp-genesis-builder", "sp-inherents", @@ -4570,9 +4657,9 @@ dependencies = [ [[package]] name = "frame-support-procedural" -version = "23.0.0" +version = "24.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0be717139a0da9b31b559356db73f6ce48876d331e833ebdc32de3a9ad581e15" +checksum = "3bf1d648c4007d421b9677b3c893256913498fff159dc2d85022cdd9cc432f3c" dependencies = [ "Inflector", "cfg-expr", @@ -4584,7 +4671,7 @@ dependencies = [ "proc-macro-warning", "proc-macro2", "quote", - "sp-core-hashing", + "sp-crypto-hashing", "syn 2.0.60", ] @@ -4614,9 +4701,9 @@ dependencies = [ [[package]] name = "frame-system" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "983b3215c8d97775b90dc1db88f858c46401682bd2fb8572bdd102ff8c2ca2a6" +checksum = "5bc20a793c3cec0b11165c1075fe11a255b2491f3eef8230bb3073cb296e7383" dependencies = [ "cfg-if", "docify", @@ -4635,9 +4722,9 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f78a2fe203b01b596156b2514e0b890b4a628dbdb50925316e755aa623b6fe53" +checksum = "ac47ee48fee3a0b49c9ab9ee68997dee3733776a355f780cf2858449cf495d69" dependencies = [ "frame-benchmarking", "frame-support", @@ -4651,9 +4738,9 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d183819ea7df1d89acd61fe423ae6bec24a29d87db5c18182339a751c0837a" +checksum = "4c1b20433c3c76b56ce905ed971631ec8c34fa64cf6c20e590afe46455fc0cc8" dependencies = [ "parity-scale-codec", "sp-api", @@ -4661,9 +4748,9 @@ dependencies = [ [[package]] name = "frame-try-runtime" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5b3dab79d14d2e8f6329d7e5cb49f2bdb81b9ef3019b1c405d94defa137a353" +checksum = "0eab87d07bc2f9a2160b818d1b7506c303b3b28b6a8a5f01dc5e2641390450b5" dependencies = [ "frame-support", "parity-scale-codec", @@ -4953,19 +5040,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "globset" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" -dependencies = [ - "aho-corasick", - "bstr 1.9.1", - "log", - "regex-automata 0.4.6", - "regex-syntax 0.8.3", -] - [[package]] name = "group" version = "0.13.0" @@ -5075,6 +5149,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.3.9" @@ -5252,7 +5332,6 @@ dependencies = [ "rustls-native-certs", "tokio", "tokio-rustls", - "webpki-roots 0.25.4", ] [[package]] @@ -5557,9 +5636,9 @@ dependencies = [ [[package]] name = "jsonrpsee" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "367a292944c07385839818bb71c8d76611138e2dedb0677d035b8da21d29c78b" +checksum = "affdc52f7596ccb2d7645231fc6163bb314630c989b64998f3699a28b4d5d4dc" dependencies = [ "jsonrpsee-core", "jsonrpsee-http-client", @@ -5567,19 +5646,19 @@ dependencies = [ "jsonrpsee-server", "jsonrpsee-types", "jsonrpsee-ws-client", + "tokio", "tracing", ] [[package]] name = "jsonrpsee-client-transport" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8b3815d9f5d5de348e5f162b316dc9cdf4548305ebb15b4eb9328e66cf27d7a" +checksum = "b5b005c793122d03217da09af68ba9383363caa950b90d3436106df8cabce935" dependencies = [ "futures-util", "http", "jsonrpsee-core", - "jsonrpsee-types", "pin-project", "rustls-native-certs", "soketto", @@ -5588,24 +5667,21 @@ dependencies = [ "tokio-rustls", "tokio-util", "tracing", - "webpki-roots 0.25.4", + "url", ] [[package]] name = "jsonrpsee-core" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5dde66c53d6dcdc8caea1874a45632ec0fcf5b437789f1e45766a1512ce803" +checksum = "da2327ba8df2fdbd5e897e2b5ed25ce7f299d345b9736b6828814c3dbd1fd47b" dependencies = [ "anyhow", - "arrayvec 0.7.4", "async-lock 2.8.0", "async-trait", "beef", - "futures-channel", "futures-timer", "futures-util", - "globset", "hyper", "jsonrpsee-types", "parking_lot 0.12.2", @@ -5621,30 +5697,31 @@ dependencies = [ [[package]] name = "jsonrpsee-http-client" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e5f9fabdd5d79344728521bb65e3106b49ec405a78b66fbff073b72b389fa43" +checksum = "5f80c17f62c7653ce767e3d7288b793dfec920f97067ceb189ebdd3570f2bc20" dependencies = [ "async-trait", "hyper", "hyper-rustls", "jsonrpsee-core", "jsonrpsee-types", - "rustc-hash", "serde", "serde_json", "thiserror", "tokio", + "tower", "tracing", + "url", ] [[package]] name = "jsonrpsee-proc-macros" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44e8ab85614a08792b9bff6c8feee23be78c98d0182d4c622c05256ab553892a" +checksum = "29110019693a4fa2dbda04876499d098fa16d70eba06b1e6e2b3f1b251419515" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-crate 1.3.1", "proc-macro2", "quote", @@ -5653,19 +5730,20 @@ dependencies = [ [[package]] name = "jsonrpsee-server" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4d945a6008c9b03db3354fb3c83ee02d2faa9f2e755ec1dfb69c3551b8f4ba" +checksum = "82c39a00449c9ef3f50b84fc00fc4acba20ef8f559f07902244abf4c15c5ab9c" dependencies = [ - "futures-channel", "futures-util", "http", "hyper", "jsonrpsee-core", "jsonrpsee-types", + "route-recognizer", "serde", "serde_json", "soketto", + "thiserror", "tokio", "tokio-stream", "tokio-util", @@ -5675,9 +5753,9 @@ dependencies = [ [[package]] name = "jsonrpsee-types" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245ba8e5aa633dd1c1e4fae72bce06e71f42d34c14a2767c6b4d173b57bee5e5" +checksum = "5be0be325642e850ed0bdff426674d2e66b2b7117c9be23a7caef68a2902b7d9" dependencies = [ "anyhow", "beef", @@ -5689,14 +5767,15 @@ dependencies = [ [[package]] name = "jsonrpsee-ws-client" -version = "0.16.3" +version = "0.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e1b3975ed5d73f456478681a417128597acd6a2487855fdb7b4a3d4d195bf5e" +checksum = "bca9cb3933ccae417eb6b08c3448eb1cb46e39834e5b503e395e5e5bd08546c0" dependencies = [ "http", "jsonrpsee-client-transport", "jsonrpsee-core", "jsonrpsee-types", + "url", ] [[package]] @@ -6206,7 +6285,7 @@ version = "0.32.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fba456131824ab6acd4c7bf61e9c0f0a3014b5fc9868ccb8e10d344594cdc4f" dependencies = [ - "heck", + "heck 0.4.1", "quote", "syn 1.0.109", ] @@ -6276,7 +6355,7 @@ dependencies = [ "rw-stream-sink", "soketto", "url", - "webpki-roots 0.22.6", + "webpki-roots", ] [[package]] @@ -6617,6 +6696,15 @@ dependencies = [ "libc", ] +[[package]] +name = "memmap2" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe751422e4a8caa417e13c3ea66452215d7d63e19e604f4980461212f3ae1322" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.8.0" @@ -6638,7 +6726,7 @@ dependencies = [ [[package]] name = "merkle-distributor" version = "0.1.0" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "frame-support", "frame-system", @@ -6730,9 +6818,9 @@ dependencies = [ [[package]] name = "mmr-gadget" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d0ba6676a84f182dabd7c3ec2c92f0e882fe4e4179ddf76f02ac132e6eb0ab" +checksum = "6f62cddc29c17965ab16a051a745520d41c28d8b4c2b6188aaf661db056d67c9" dependencies = [ "futures 0.3.30", "log", @@ -6750,11 +6838,10 @@ dependencies = [ [[package]] name = "mmr-rpc" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19066d17147f6819ec25f5f6fc3b9fca2008ae745ac7fa2d55ddb1d207119eae" +checksum = "2634b45039e064c343a0a77ed45e03ca027c84e1b250b2f3988af7cde9b7e79e" dependencies = [ - "anyhow", "jsonrpsee", "parity-scale-codec", "serde", @@ -7061,12 +7148,23 @@ dependencies = [ ] [[package]] -name = "no-std-net" -version = "0.6.0" +name = "nix" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" - -[[package]] +checksum = "2eb04e9c688eff1c89d72b407f168cf79bb9e867a9d3323ed6c01519eb9cc053" +dependencies = [ + "bitflags 2.5.0", + "cfg-if", + "libc", +] + +[[package]] +name = "no-std-net" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43794a0ace135be66a25d3ae77d41b91615fb68ae937f904090203e81f755b65" + +[[package]] name = "nodrop" version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -7249,7 +7347,7 @@ dependencies = [ "futures-timer", "orchestra-proc-macro", "pin-project", - "prioritized-metered-channel 0.6.1", + "prioritized-metered-channel", "thiserror", "tracing", ] @@ -7281,9 +7379,8 @@ dependencies = [ [[package]] name = "orml-oracle" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "094597ad71aba7e116d93af4d68ceaed95273c75c065dd89aeab43051083c485" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "frame-system", @@ -7300,9 +7397,8 @@ dependencies = [ [[package]] name = "orml-tokens" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02dce1f619f42d2a520423da923fd8f2eb8abb8dc3f5cdff3f853c7791abef3e" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "frame-system", @@ -7318,9 +7414,8 @@ dependencies = [ [[package]] name = "orml-traits" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f4617d5262e9a8f3b5e7ab5961e8d0a3d4e25ef0c9d34e6ff87766c406898b" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -7339,9 +7434,8 @@ dependencies = [ [[package]] name = "orml-unknown-tokens" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12c26e74a7407bd6bccc8d123a4f6d60e5b01188c135804dc1e48ca98c49dbf6" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "frame-system", @@ -7355,9 +7449,8 @@ dependencies = [ [[package]] name = "orml-utilities" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1756d8ca7c433fdb538ff14bbb60a343fc6cf7b0684af4a73889f89de364e18f" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "parity-scale-codec", @@ -7371,9 +7464,8 @@ dependencies = [ [[package]] name = "orml-xcm" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c3bdb23468f0532c78941c122a37c4f3d8629bb8fc69810ecf3b5f20fa7f81" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "frame-system", @@ -7386,9 +7478,8 @@ dependencies = [ [[package]] name = "orml-xcm-support" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dbb61790b9ce5698f7026bbf9ebd932df782a425b3551e9dd04300cb4eace179" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "orml-traits", @@ -7401,9 +7492,8 @@ dependencies = [ [[package]] name = "orml-xtokens" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18d1f2b938ce3c789a749e2214ec23a946e5110e0df16c605d1f75a1b852afa6" +version = "0.8.0" +source = "git+https://github.com/bifrost-finance/open-runtime-module-library?branch=release-polkadot-v1.7.0#fe62103da8f1dcce5c188f528571d7f629abf4d0" dependencies = [ "frame-support", "frame-system", @@ -7421,11 +7511,30 @@ dependencies = [ "staging-xcm-executor", ] +[[package]] +name = "pallet-asset-conversion" +version = "11.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4079f12db3cf98daa717337ab5b7e5ef15aa3bec3b497f501dc715d129b500da" +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-rate" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e6f4917bc6c9ed6864813bbb828e94c63e1878a21af89d25dd0ff7da742f53e" +checksum = "571ce57fd846911041749832b46a8c2b01f0b79ffebcd7585e3973865607036d" dependencies = [ "frame-benchmarking", "frame-support", @@ -7439,15 +7548,17 @@ dependencies = [ [[package]] name = "pallet-asset-tx-payment" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e967664d86219ca9f7d33504e8d914225cdb92e9e793d35edaab1fd2574f162f" +checksum = "9ed783679921ad8b96807d683d320c314e305753b230d5c04dc713bab7aca64c" dependencies = [ + "frame-benchmarking", "frame-support", "frame-system", "pallet-transaction-payment", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-io", "sp-runtime", @@ -7456,9 +7567,9 @@ dependencies = [ [[package]] name = "pallet-assets" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aca79db2bc70c269170893604d8a56d0f32d52c75a23a3d887b6b4df132366b7" +checksum = "46728a98a910af13f6a77033dd053456650773bb7adc71e0ba845bff7e31b33e" dependencies = [ "frame-benchmarking", "frame-support", @@ -7473,9 +7584,9 @@ dependencies = [ [[package]] name = "pallet-aura" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10c6ecf016520a6883df14b2f1d469d98166377eba4b299af7b76eee0130e3a6" +checksum = "a611bef3c8cf281e41a43f32a4153260bdc8b7b61b901e65c7a4442529224e11" dependencies = [ "frame-support", "frame-system", @@ -7491,9 +7602,9 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" -version = "28.0.0" +version = "29.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9224b0a0bb4fa721d51f56947c73d4189710691b4cb40e7f7a8abf59795759a" +checksum = "7cd9a381c613e6538638391fb51f353fd13b16f849d0d1ac66a388326bd456f1" dependencies = [ "frame-support", "frame-system", @@ -7508,9 +7619,9 @@ dependencies = [ [[package]] name = "pallet-authorship" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "817b0420f9c14bd9bfbaf9e2f769a7e8124ab4fe3da0d07c80485c0901947ab8" +checksum = "3d83773e731a1760f99684b09961ed7b92acafe335f36f08ebb8313d3b9c72e2" dependencies = [ "frame-support", "frame-system", @@ -7523,9 +7634,9 @@ dependencies = [ [[package]] name = "pallet-babe" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ba445228a941062d7c4d6295810a359df7757d6182c36ddb824f8c3bf350380" +checksum = "d3f2020c52667a650d64e84a4bbb63388e25bc1c9bc872a8243d03bfcb285049" dependencies = [ "frame-benchmarking", "frame-support", @@ -7548,9 +7659,9 @@ dependencies = [ [[package]] name = "pallet-bags-list" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0d7b6922a6bed960591efb49da6637312c034337faf4c85d8b35f2e2c611a" +checksum = "dd27bfa4bfa5751652842b81241c7eff3e68f2806d9dacc17b03d2cb20a39756" dependencies = [ "aquamarine", "docify", @@ -7571,10 +7682,11 @@ dependencies = [ [[package]] name = "pallet-balances" -version = "28.0.0" +version = "29.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8406b5616e468d80972b6365f3cd8211d0dbf4d107b379fac85fddcfdf0b5562" +checksum = "a9a54b5d0c7c4c3731883d6b1ac18aff44db20c3d0a3470c8861001a17afdc85" dependencies = [ + "docify", "frame-benchmarking", "frame-support", "frame-system", @@ -7587,9 +7699,9 @@ dependencies = [ [[package]] name = "pallet-beefy" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03f71d32d9681e9d78102dad00377629cac24b4bf43f6371c0dc7e5b25981eb4" +checksum = "4bedd80e9d8b196f31ea134efd271fdc1b8380ca3aa2d8af6ea8b5a0dc4fa460" dependencies = [ "frame-support", "frame-system", @@ -7608,9 +7720,9 @@ dependencies = [ [[package]] name = "pallet-beefy-mmr" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b8eaa5c053d9cbf20faa397f21b80b9b5bafbe428890b0171fd1bba16f52ce" +checksum = "7d334f24d3c0c016d16aa87d069485847d622e8ebebace18ec5cf56609ca3a67" dependencies = [ "array-bytes 6.2.2", "binary-merkle-tree", @@ -7634,9 +7746,9 @@ dependencies = [ [[package]] name = "pallet-bounties" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5d421e3228bc4e8170d817d657aa87761b77ee4675a9e16328e1ca070cb4c41" +checksum = "4765879e96676c13cdbed746d66fd59dcde1e9e65fda1f064fa2fffa3bc5d597" dependencies = [ "frame-benchmarking", "frame-support", @@ -7653,9 +7765,9 @@ dependencies = [ [[package]] name = "pallet-broker" -version = "0.6.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904983f117ff92ee24b251f2a883ff01b6f8e9063649877f3892ecbb516e3cbd" +checksum = "3626d7e8e49b153b84c74594e1fb4b6d64720b5a9588297d3ba3c049c3b3b9e3" dependencies = [ "bitvec", "frame-benchmarking", @@ -7671,9 +7783,9 @@ dependencies = [ [[package]] name = "pallet-child-bounties" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb62c44d3ab8dcbf106b22acc138eaea6e51563d16a8d4a246303f2e20eeb9e5" +checksum = "00fd06f2d719f5bb16ab3e836c6b053bbd92631ba694f8c2bf810013b2548167" dependencies = [ "frame-benchmarking", "frame-support", @@ -7691,9 +7803,9 @@ dependencies = [ [[package]] name = "pallet-collator-selection" -version = "9.0.2" +version = "10.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05cc67e8233b748a0c0b1ecc2cbecfc6deb08be633fedba9c3d6b1ade6c2a036" +checksum = "49d1157d9a4b7966040158a7b4f1fb29f0cefa8deb6eb9b3452df7ce4161a31c" dependencies = [ "frame-benchmarking", "frame-support", @@ -7712,9 +7824,9 @@ dependencies = [ [[package]] name = "pallet-collective" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed22cf9d91c120695063cfa95ae0ffabcadefdf2581657ddb5fd68555b3a2e0" +checksum = "4c362a0b8f30895c15ecc7d8c24b0d94bb586c4b9bbd37ac8053b4629d9cc80b" dependencies = [ "frame-benchmarking", "frame-support", @@ -7730,9 +7842,9 @@ dependencies = [ [[package]] name = "pallet-conviction-voting" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a189b5fb4a473edc7b2d52109fe10d0017b9b56f7c0324018b5970125db3ce3" +checksum = "6aee3a8b6fcde893f862993f9d45eb0fcd492dde0967fd56ef78d79fc7b53dc0" dependencies = [ "assert_matches", "frame-benchmarking", @@ -7748,9 +7860,9 @@ dependencies = [ [[package]] name = "pallet-democracy" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b687c8a22b37f9b8444a29959f9cd0cf0be2f8efb8cd9bf91860d5dbafdab8b3" +checksum = "aa781d632063087bcd3ff46eb1a668f15647ab116f1c8a7c573b7168f62d72c3" dependencies = [ "frame-benchmarking", "frame-support", @@ -7767,9 +7879,9 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc5e1f80bb4ce08b27f5a8a733d5c2d72d083a7d48afa4bdbb1ef3594a31e353" +checksum = "b54d1d3fe9ae61a144d581147e699b7c3009169de0019a0f87cca0bed82681e7" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -7791,9 +7903,9 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "193a8592c5fd534d56d07b2abe14e830d23947fb66f31867083e4f3ef80c8caa" +checksum = "46ec87816a1e32a1ab6deececa99e21e6684b111efe87b11b8298328dbbefd01" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -7806,9 +7918,9 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dd2f70c57cbb3dcde39f141721dd34a8c852e0caaf61ae6b0bbd23138b6e1d3" +checksum = "10cb0158cc7461fda5db04c5791d0df34635bec37181763aca449bade677d12d" dependencies = [ "frame-benchmarking", "frame-support", @@ -7826,9 +7938,9 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd6e0b51b82075b046792cdde2d4a2f6c9301f3deba44c26d30ab152060b9028" +checksum = "2222607a0dba10a9d57cab5360a6549b5fda925181c3c7af481246c0964998df" dependencies = [ "docify", "frame-benchmarking", @@ -7846,9 +7958,9 @@ dependencies = [ [[package]] name = "pallet-grandpa" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "935e91fa8936381aff2b88d8a7dad38ac30a1c8d2310340d73ce1c07b5ae72ce" +checksum = "a5b20be8592eed7ebca2ee661fc43450088552ebe0bd483d7b101cf5968ab12d" dependencies = [ "frame-benchmarking", "frame-support", @@ -7870,9 +7982,9 @@ dependencies = [ [[package]] name = "pallet-identity" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3259bb87d50529027fa40267c3662dc80c683f253f121f391c032b019c88fcb" +checksum = "e9e1cae19e30e7dc822c419988b30bb1318d79a8d5da92733822d0e84fe760ca" dependencies = [ "enumflags2", "frame-benchmarking", @@ -7888,9 +8000,9 @@ dependencies = [ [[package]] name = "pallet-im-online" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4be3f0165158828e4e77fae106a93bc1f48cc751755bdb012edb3ac0ef1d246" +checksum = "598ea5c87351edc953d1f455f32ff456cf2f1daf7bbada1f1e03be8e384852ab" dependencies = [ "frame-benchmarking", "frame-support", @@ -7909,9 +8021,9 @@ dependencies = [ [[package]] name = "pallet-indices" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ead239524e40e55d172f024ff6795998068a2ba1c0950e74c4db7f347cfa91e" +checksum = "2e880ebdb429ca76fb400b1b361ed7fce018a5ea2fc2da4764de5156fffdfa73" dependencies = [ "frame-benchmarking", "frame-support", @@ -7927,9 +8039,9 @@ dependencies = [ [[package]] name = "pallet-membership" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bc2dfdff5a7e5b21355b34245312ba2ea687444d9003960e7b876e1df518dab" +checksum = "ad901cdf3de23daf23ff8b092ab318b13faebfc1aa4d84263f2fdc84feaf3e9b" dependencies = [ "frame-benchmarking", "frame-support", @@ -7945,9 +8057,9 @@ dependencies = [ [[package]] name = "pallet-message-queue" -version = "31.0.0" +version = "32.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab6302efb264a65fd175f3082b72004df125f646a3c68b72fd08e657a468c0d6" +checksum = "9ccb23dee70b184a214d729db550117a0965a69107d466d35181d60a6feede38" dependencies = [ "environmental", "frame-benchmarking", @@ -7966,9 +8078,9 @@ dependencies = [ [[package]] name = "pallet-mmr" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba6565b91d1d585047648793feece7c2c70080b37e1f55ab3a4fb50b4c1bec86" +checksum = "a6f1f23a70764dad2b4094d8be12ebbb82df210f2e80dd36fa941a5ac191c6cd" dependencies = [ "frame-benchmarking", "frame-support", @@ -7985,9 +8097,9 @@ dependencies = [ [[package]] name = "pallet-multisig" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14dbcdea9d3d7963aab57078a5bd6f3596186bfcf181d666db6ea2bfdc0184ec" +checksum = "176f6a5c170185f892a047c0ae189bc52eb390f2c0b94d4261ed0ebc7f82a548" dependencies = [ "frame-benchmarking", "frame-support", @@ -8002,9 +8114,9 @@ dependencies = [ [[package]] name = "pallet-nis" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86c541b2785051ebe1ae378be4b086055fbb8b13ee18fd949dfcf68dbd1c3325" +checksum = "32a64a0e80dec2c60d5962dd249061a47dc4356db440f26cdec50b8acaded1d3" dependencies = [ "frame-benchmarking", "frame-support", @@ -8019,9 +8131,9 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" -version = "25.0.3" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5989ca1100694371c9951118d58e84e93b60c1919006e9d4ad0f7537952c388" +checksum = "0f14519c1c613d2f8c95c27015864c11a37969a23deeba9f6dbaff4276e1b81c" dependencies = [ "frame-support", "frame-system", @@ -8039,9 +8151,9 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d01847415cd33a92c65e8d13cb0041a32b2f2523c84d9d944287ae5c0d920c82" +checksum = "18a1eba3078e2492cad15e4695f90eb3fc570386d9f71f8b81f709c7123fc6b5" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -8060,9 +8172,9 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" -version = "23.0.0" +version = "24.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a64b17d862b833ca07a375646ecc80e164e5618c3aed4e5631816aa7288bf9b1" +checksum = "bc5b35e6c471a669437b987ff02e11e2283412c9ebaeec5334dec3f73bcea652" dependencies = [ "pallet-nomination-pools", "parity-scale-codec", @@ -8072,9 +8184,9 @@ dependencies = [ [[package]] name = "pallet-offences" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de7b17230f58ff6b1ec2a70b3c639c49f585841dacf63f30c78db6387a833e0b" +checksum = "60b5bcfdc4f6032d7570929094fd459de12d840c440c395fb4d365d679e13eda" dependencies = [ "frame-support", "frame-system", @@ -8090,9 +8202,9 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "060483993358293d041e5173635082c68c7783a800c0874e8df87c324232f0d1" +checksum = "bbc33e3086c19235cb903cbbbde1bc1c4f428519ad4c23446dc84c75d0061582" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -8115,9 +8227,9 @@ dependencies = [ [[package]] name = "pallet-preimage" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce688c68f117b1916a844579aa5a945d786059b119a1cc80ace370afd1e50da4" +checksum = "7344a30c304771beb90aec34604100185e47cdc0366e268ad18922de602a0c7e" dependencies = [ "frame-benchmarking", "frame-support", @@ -8160,9 +8272,9 @@ dependencies = [ [[package]] name = "pallet-proxy" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3162924576a70509136eb4d8513497fb640a8b3ea753883fe29bd454c511485" +checksum = "f7aa31a0b91e8060b808c3e3407e4578a5e94503b174b9e99769147b24fb2c56" dependencies = [ "frame-benchmarking", "frame-support", @@ -8176,13 +8288,14 @@ dependencies = [ [[package]] name = "pallet-ranked-collective" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86c6d11592a6ba9039bd3486dba15f0cb045889b2746f4619f5ec78188fdd151" +checksum = "3733dbfc44d8f5e1a08287a9064e5794e9d0e92b1bd68cdad2e22202b1964528" dependencies = [ "frame-benchmarking", "frame-support", "frame-system", + "impl-trait-for-tuples", "log", "parity-scale-codec", "scale-info", @@ -8195,9 +8308,9 @@ dependencies = [ [[package]] name = "pallet-recovery" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8649310b8f00e3b2983331cdb7173d1e66e5eeb3a3d21479e7a65386244f883" +checksum = "797b554ddc87082c18223440d61a81cf35ccab6573321ce473a099e7a709a760" dependencies = [ "frame-benchmarking", "frame-support", @@ -8211,9 +8324,9 @@ dependencies = [ [[package]] name = "pallet-referenda" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c6645c0c09ff8484c6c7ac1546d908202ed555b18169ea956955e4e2d77b210" +checksum = "da850889e7101b63cadb980b7f39df67feb6d63bc6092769b9b708e9eb596db1" dependencies = [ "assert_matches", "frame-benchmarking", @@ -8231,9 +8344,9 @@ dependencies = [ [[package]] name = "pallet-root-testing" -version = "4.0.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bd13ad045bda70f0d2023333d36620bd7b48172646274572332dc9f62fd3c8" +checksum = "59171cbf2b823c13685b1b80dd3e1e84425680ff4e006d8016f8c14d2ec44974" dependencies = [ "frame-support", "frame-system", @@ -8247,9 +8360,9 @@ dependencies = [ [[package]] name = "pallet-scheduler" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc26a27b77170c18261af7be04a6569e3d0d58788255b9f283ccd089aac37887" +checksum = "45e2a4ebe6a5f98b14a26deed8d7a1ea28bb2c2d3ad4d6dc129a725523a2042d" dependencies = [ "docify", "frame-benchmarking", @@ -8266,9 +8379,9 @@ dependencies = [ [[package]] name = "pallet-session" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e23ca2bfcffb5194de952050557bdd1fe9bce18b2bc81e8f8c01c8a3c3c3e5d8" +checksum = "7412ac59247b300feee53709f7009a23d1c6f8c70528599f48f44e102d896d03" dependencies = [ "frame-support", "frame-system", @@ -8289,9 +8402,9 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc660786028d46e03fb0a419d6a15df3fa556db7ce74efebf5a35037b32b4bc4" +checksum = "b9c2731415381020db1e78db8b40207f8423a16099e78f2fde599cbcb57ea8db" dependencies = [ "frame-benchmarking", "frame-support", @@ -8307,9 +8420,9 @@ dependencies = [ [[package]] name = "pallet-society" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c19c1f5a410c0b03dc1e3245ffc0269e6c9085e6f6a64ee023f7515b6f8d9b" +checksum = "dba64f96619c25ae7a0b41f4a5111c2d3102e8b8c6cbce80ece6955e825f9de2" dependencies = [ "frame-benchmarking", "frame-support", @@ -8326,9 +8439,9 @@ dependencies = [ [[package]] name = "pallet-staking" -version = "28.0.1" +version = "29.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a83fe4c845d10988b78022f1b0e197ceefc0b68c148efb6370d9e9b53a53baf4" +checksum = "668b7d28c499f0d9f295fad26cf6c342472e21842e3b13bcaaac8536358b2d6c" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -8362,9 +8475,9 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" -version = "19.0.0" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e23336e4da87101633f95f9932946564c926ca7f87499654b38923b1579c605e" +checksum = "505d45e08bad052f55fb51f00a6b6244d23ee46ffdc8091f6cddf4e3a880319d" dependencies = [ "log", "sp-arithmetic", @@ -8372,9 +8485,9 @@ dependencies = [ [[package]] name = "pallet-staking-runtime-api" -version = "14.0.0" +version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e27156b772eccb539cb1a1ea1b1b6e98d9c6589e18b913a30f67913fcf67fe7e" +checksum = "237d7b5a10cb6cba727c3e957fb241776302aa3cce589e6759ba53f50129c1a5" dependencies = [ "parity-scale-codec", "sp-api", @@ -8383,9 +8496,9 @@ dependencies = [ [[package]] name = "pallet-state-trie-migration" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a48713905a318b0307e523fd3d3ca4b197ce74b2520203ded0d02e8a6c6bbd7" +checksum = "d76e52dedc146b7a9c3b7c5a6ff4c4c442a8ab8cc58ec30e90e1e98cdc51ad34" dependencies = [ "frame-benchmarking", "frame-support", @@ -8401,9 +8514,9 @@ dependencies = [ [[package]] name = "pallet-sudo" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053dae9119d2d828af80e8ac98f497dc27155d6b5d42264dab8fae40f2314c41" +checksum = "b6d02f7855d411913e77e57126f4a8b8a32d90d9bf47d0b747e367a1301729c3" dependencies = [ "docify", "frame-benchmarking", @@ -8418,9 +8531,9 @@ dependencies = [ [[package]] name = "pallet-timestamp" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688b89bdd377609b592bd094b304ebca33f4767fe72935465e2fd7db0e797968" +checksum = "c1b8810ddfb254c7fb8cd7698229cce513d309a43ff117b38798dae6120f477b" dependencies = [ "docify", "frame-benchmarking", @@ -8439,9 +8552,9 @@ dependencies = [ [[package]] name = "pallet-tips" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "facf64cab7f7a4762c57e5827597b2ca073755de4c9716444cf0847db34836df" +checksum = "8ca4b9921c9e9b59e8eeb64677ba6ec49743ef5fe98e0b63f77411b2b9f6cc99" dependencies = [ "frame-benchmarking", "frame-support", @@ -8482,9 +8595,9 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18b4ca7a1af9b1f091900a354a96319c7614d7a32106ba86cb7f0b6f90239065" +checksum = "39f690f5c287ad34b28ca951ef7fae80b08cc9218d970723b7a70e4d29396872" dependencies = [ "frame-support", "frame-system", @@ -8499,9 +8612,9 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" -version = "30.0.0" +version = "31.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1486d58f38892df779a7812f28ff962d0b0632b955ea3c348f605caa01ba6d" +checksum = "08ef209d2d5d077e325bf49b024fd2eff109a5c2ca0d84ce0d50a65839e6b026" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -8516,9 +8629,9 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acdfd7c882439b8198c99ece57b5bf785965545a6fa6d0bb7b56b264df1e437a" +checksum = "c78bcba80c7c61712b98a6b5640975ebd25ceb688c18e975af78a0fac81785b0" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -8529,9 +8642,9 @@ dependencies = [ [[package]] name = "pallet-treasury" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75cb7498228e1a150fa09ce64acafe7105ff39b75dae1c266ba58b7e3eb225e" +checksum = "1605eb5083a2cd172544f33c6e59eca2e23ac49f02f13d1562b1b8a409df9c60" dependencies = [ "docify", "frame-benchmarking", @@ -8549,9 +8662,9 @@ dependencies = [ [[package]] name = "pallet-utility" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384c1d740c019410f6b40586cc387726c2e3c417c0e3e6f7e4774cd46bc6c1d0" +checksum = "954f15b98c3fdebb763bb5cea4ec6803fd180d540ec5b07a9fcb2c118251d52c" dependencies = [ "frame-benchmarking", "frame-support", @@ -8566,9 +8679,9 @@ dependencies = [ [[package]] name = "pallet-vesting" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55f3ac517a10c14beee86a737b9ea5d592af9ab21cc5354474bc5f7019210358" +checksum = "4525f3038cdf078fea39d913c563ca626f09a615e7724f0c9eac97743c75ff44" dependencies = [ "frame-benchmarking", "frame-support", @@ -8582,9 +8695,9 @@ dependencies = [ [[package]] name = "pallet-whitelist" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de259e3329422bf3eb10b7e966f4b1c5caadcb29cd2d45af3a000cb2d184e60d" +checksum = "da0ad4ce05688bdddcdb682cbed2f3edff0ee5349f0b745ebacc27d179582432" dependencies = [ "frame-benchmarking", "frame-support", @@ -8598,9 +8711,9 @@ dependencies = [ [[package]] name = "pallet-xcm" -version = "7.0.0" +version = "8.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cee3520e03ac679125e8dcaa00ce4afeeb106a9623e79b5acf970d72af7f5d02" +checksum = "c13f5c598737e84294880333170d1df3868a11ad7ee79d0b1d1af37365e1c277" dependencies = [ "bounded-collections", "frame-benchmarking", @@ -8622,9 +8735,9 @@ dependencies = [ [[package]] name = "pallet-xcm-benchmarks" -version = "7.0.4" +version = "8.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da15171c2dc870ad636fcdb16d9aa37eb84cfe6001c3f1c77cf2c97446ebfbe5" +checksum = "3c10e1c92086ce2069a3d2387d9431f48660b6ec92054c4d0a4e30a9f54e7ad3" dependencies = [ "frame-benchmarking", "frame-support", @@ -8642,16 +8755,15 @@ dependencies = [ [[package]] name = "parachains-common" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceadd4f51620023871ece5eeda64734acd17d84d49b45473d335e900a012fdde" +checksum = "d34aa00981a24a2b772afaa49e258f9bcd6bb372db060a05614becc1c74d4456" dependencies = [ "cumulus-primitives-core", "cumulus-primitives-utility", "frame-support", "frame-system", "log", - "num-traits", "pallet-asset-tx-payment", "pallet-assets", "pallet-authorship", @@ -8660,11 +8772,8 @@ dependencies = [ "pallet-message-queue", "pallet-xcm", "parity-scale-codec", - "polkadot-core-primitives", "polkadot-primitives", - "rococo-runtime-constants", "scale-info", - "smallvec", "sp-consensus-aura", "sp-core", "sp-io", @@ -8672,10 +8781,8 @@ dependencies = [ "sp-std", "staging-parachain-info", "staging-xcm", - "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "westend-runtime-constants", ] [[package]] @@ -8691,7 +8798,7 @@ dependencies = [ "libc", "log", "lz4", - "memmap2", + "memmap2 0.5.10", "parking_lot 0.12.2", "rand", "siphasher", @@ -8971,9 +9078,9 @@ checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] name = "polkadot-approval-distribution" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98fd276eccca3ada04cb274f4b8c51f669087d8b334c775f1231a9194d5260d0" +checksum = "8cdfa52beecc446ccf733dede1a0089e6396d3df13401004d27c0ce2530816bc" dependencies = [ "bitvec", "futures 0.3.30", @@ -8992,9 +9099,9 @@ dependencies = [ [[package]] name = "polkadot-availability-bitfield-distribution" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51c43e54e0cc47dfb4f7c3917a774ccc796524087515b212d9fe109bde71846e" +checksum = "80ffc856dfbdb31178625760824ae320ddb7dd5694b217f489bd2832b8de15a5" dependencies = [ "always-assert", "futures 0.3.30", @@ -9009,9 +9116,9 @@ dependencies = [ [[package]] name = "polkadot-availability-distribution" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "121ded25722b8505335b05a77f1def84278802ed3f4774c7fe6ab7c961affe06" +checksum = "c9d05c26cc8d6fa0f5f432d9de880f20ad0d24ca51a618834ea6612d1bd96ab1" dependencies = [ "derive_more", "fatality", @@ -9033,9 +9140,9 @@ dependencies = [ [[package]] name = "polkadot-availability-recovery" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3902495dbba25e7526168c8f88b26cc0dbb96cfe10813238a650c67b34bf9f31" +checksum = "4d77e0b979f43861ab4c78c216c2729644bb12812f9bc859858bd3b8fc56b4d6" dependencies = [ "async-trait", "fatality", @@ -9057,9 +9164,9 @@ dependencies = [ [[package]] name = "polkadot-cli" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93cafe0d136732ad69bce9cd82a34a7b1ff0cd2268d84309aeb673622d40a013" +checksum = "ef362c44280e3883a39ca452acc4a4fb61a18250d634d68578b22df7edd8290c" dependencies = [ "cfg-if", "clap", @@ -9086,9 +9193,9 @@ dependencies = [ [[package]] name = "polkadot-collator-protocol" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a70007b246c3679ee43f11123bda6d715f659f7b6d4134d0fcbe8980e049386b" +checksum = "507391f1be9f9b9a8fbf28ca13b0ab3f04947a54a1115d423d115aacf8889bf4" dependencies = [ "bitvec", "fatality", @@ -9109,9 +9216,9 @@ dependencies = [ [[package]] name = "polkadot-core-primitives" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bda2b0f0c580c38f12445a4af10e0a23acf48381b2a95653e0be48ba787e10e5" +checksum = "b6a08e4e014c853b252ecbbe3ccd67b2d33d78e46988d309b8cccf4ac06e25ef" dependencies = [ "parity-scale-codec", "scale-info", @@ -9122,15 +9229,15 @@ dependencies = [ [[package]] name = "polkadot-dispute-distribution" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a9b173e02d1f600a422269b3b5a1db203d39f436f7db7d7e41ef6dda6f42e0" +checksum = "ae32e83ef6bc0ec2874c76c19dff8f3795832ccc27f0abc587a7137994c42d26" dependencies = [ "derive_more", "fatality", "futures 0.3.30", "futures-timer", - "indexmap 1.9.3", + "indexmap 2.2.6", "parity-scale-codec", "polkadot-erasure-coding", "polkadot-node-network-protocol", @@ -9148,9 +9255,9 @@ dependencies = [ [[package]] name = "polkadot-erasure-coding" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff8347b3528fe94e47ec1b818b06bf821010a5f180d0ac5c89138da0d382debc" +checksum = "1b10514ace3272d38b602e1795a5a340b265285c4af875473d682a5c9d6c831c" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", @@ -9163,9 +9270,9 @@ dependencies = [ [[package]] name = "polkadot-gossip-support" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4de739371a4b5f036848de5c7185dfee88587016d2bb32af07f38fb909b80d8" +checksum = "01f05f7f60022d4beb30414f1f7c7e4ae728fea02086a4a0f8ff0a73e73ea4aa" dependencies = [ "futures 0.3.30", "futures-timer", @@ -9179,15 +9286,16 @@ dependencies = [ "sc-network-common", "sp-application-crypto", "sp-core", + "sp-crypto-hashing", "sp-keystore", "tracing-gum", ] [[package]] name = "polkadot-network-bridge" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4598c9d00dbc017c0f01e82a7c0740805cc500c3b8946ad0b7945ab4d68dd7ee" +checksum = "049ec1298ac6e96bcf4d980cd5864aceeee73b3298ab5d6dd7a3193d47578abc" dependencies = [ "always-assert", "async-trait", @@ -9209,9 +9317,9 @@ dependencies = [ [[package]] name = "polkadot-node-collation-generation" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba987629ab789f529426d6187dbafaa8209f5ee479c645184e4c1e33a59e2135" +checksum = "6f1211ab8b154c2e2b4b89c64f57f96056c881e4fcfa2ce29b6e5cbc978e74f1" dependencies = [ "futures 0.3.30", "parity-scale-codec", @@ -9228,9 +9336,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-approval-voting" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5910fa99def47accbb4505bef91f74614f62347bc0c53c11296d5ce70d8e255" +checksum = "c61a17b7e4edd3b73afbe0c6e8b5369bf3b721361a232baf11fb1698077067a4" dependencies = [ "bitvec", "derive_more", @@ -9262,9 +9370,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-av-store" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1583533dc82a719607323432c013e01c2a8c971eb7e7703ff5eadd762f4e3" +checksum = "84b334f06423ff701e4b807d6832741ec24e0e97ebc13b560fc99bc0652926c0" dependencies = [ "bitvec", "futures 0.3.30", @@ -9285,9 +9393,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-backing" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7b5468fa618ccbeb4611b073d2c28b9440b51f4012e69c117e43192f9de8b17" +checksum = "f07f8840f3f2f0bee6264c18ce471c99c925f9afb65952e1d584b6d773cf4115" dependencies = [ "bitvec", "fatality", @@ -9298,6 +9406,7 @@ dependencies = [ "polkadot-node-subsystem-util", "polkadot-primitives", "polkadot-statement-table", + "schnellru", "sp-keystore", "thiserror", "tracing-gum", @@ -9305,9 +9414,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-bitfield-signing" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4975e2ecc81d34605748781e9449a7b7ff956c385b46496005257a1a7dd56f0d" +checksum = "0687006f843d6da8687eb24da735a04cbdcf4c3a98d82055b9b3a9047537e17e" dependencies = [ "futures 0.3.30", "polkadot-node-subsystem", @@ -9321,9 +9430,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-candidate-validation" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcfd720b86c1ddf6616cf083a2cb273147687521c1d13a7f3c991b1d5ae03444" +checksum = "c3035acf9069801e980b91b5178591f8a7052b4409de13824db7a6c798b36b98" dependencies = [ "async-trait", "futures 0.3.30", @@ -9343,9 +9452,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-api" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a9f00bd39f433a2e8281524529853a3be54970e799a451e2c14fc5b75cf226f" +checksum = "c990b9ffdde6725fe79f55e3b7c4c32ce2134a06103708476fa595a4ac652e95" dependencies = [ "futures 0.3.30", "polkadot-node-metrics", @@ -9358,9 +9467,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-selection" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea28475a96dfb6419432314d8021780e5c5b0f50a5525fd332e8b2a947a2deb5" +checksum = "451965f3ace786d392c407872d61324765061b87027890b02ffd625554531f97" dependencies = [ "futures 0.3.30", "futures-timer", @@ -9376,9 +9485,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-dispute-coordinator" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad9cfb3e775dc4c611a79e294549fe4b244052ddaacf14133380e793c25a99f" +checksum = "c13ea9d5b4aa43b5b1f718c3ec951adff0b0d74909cb1fe28206f5d88492247d" dependencies = [ "fatality", "futures 0.3.30", @@ -9396,9 +9505,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-parachains-inherent" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb2535ef374a218b1e9d05b98a903edbdddf4eea47f9e137fcc09c8e1bc199dd" +checksum = "6574c0bda4e10d722f761d4b8ab5d1708f0f963e5840370aa9cee8f559c90a23" dependencies = [ "async-trait", "futures 0.3.30", @@ -9414,9 +9523,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-prospective-parachains" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a8876cc0aa627190f1d41c01061a7acee9621703501d9a60118d35e81579f9" +checksum = "160f80a11b9d2b8e36e510ea54ce5b06e77179c0c502f7e19e5a5809bc1523ee" dependencies = [ "bitvec", "fatality", @@ -9432,9 +9541,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-provisioner" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25c88b17b93bf410a72bfb4543b1ae01bb0d33fd6cba9af1f0e74c4ef2b906ad" +checksum = "b0d0a64371700537c3dc15b3956536e4541f093b7c38ac21737ea9fea3562a83" dependencies = [ "bitvec", "fatality", @@ -9450,9 +9559,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c80f2810b2eb843f3282b11e7ce1624866b6dd1ee6a95541b5882b5df3f36f25" +checksum = "f3bbb1b5f4b966f21a0336e94c0a0222958d2f3cba451da1157af271d07f9748" dependencies = [ "always-assert", "array-bytes 6.2.2", @@ -9484,9 +9593,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-checker" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14d8ddb21cb3ad1868967b116fbf289610880cb95313b2798762cdd8653d36b7" +checksum = "94ab4a91e62a9f7e67cf400931578f2505417cc43a32ac29458163604f2b277b" dependencies = [ "futures 0.3.30", "polkadot-node-primitives", @@ -9501,15 +9610,16 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-common" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80bbf311b112a8552e89e5be55b0305d86328ba04528e47d3203cd27751405bc" +checksum = "003981d3b63e4f527ef7f03cbe280e41ec649d9be365668887f0b107610640f4" dependencies = [ "cfg-if", "cpu-time", "futures 0.3.30", "landlock", "libc", + "nix 0.27.1", "parity-scale-codec", "polkadot-parachain-primitives", "polkadot-primitives", @@ -9518,6 +9628,7 @@ dependencies = [ "sc-executor-wasmtime", "seccompiler", "sp-core", + "sp-crypto-hashing", "sp-externalities", "sp-io", "sp-tracing", @@ -9527,9 +9638,9 @@ dependencies = [ [[package]] name = "polkadot-node-core-runtime-api" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17345f76b7ebcf2f1e1be5411a6420971ef60d69070f115e459b2f017f91bcb5" +checksum = "6ba6ea6a03f297b7387fc59c41c3c32285803971cb27e81d7e9ca696824d6773" dependencies = [ "futures 0.3.30", "polkadot-node-metrics", @@ -9543,9 +9654,9 @@ dependencies = [ [[package]] name = "polkadot-node-jaeger" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b099624af4597bac5d1617a3cab057785ee47e657de7ad078957bfa397d82c4" +checksum = "f7d113b48e7b6126964c3a790b101d99e17fd3cb75a92e94d54587ce1340df21" dependencies = [ "lazy_static", "log", @@ -9562,9 +9673,9 @@ dependencies = [ [[package]] name = "polkadot-node-metrics" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b5b00a9646875f22ab45e61ede04f623a3fbbc03bae52263b3d558c964bc32" +checksum = "aef2e2a934f0d0d606fcfc53fc26f4cacd8b9f18fb2118829203fa813af2cdae" dependencies = [ "bs58 0.5.1", "futures 0.3.30", @@ -9572,7 +9683,7 @@ dependencies = [ "log", "parity-scale-codec", "polkadot-primitives", - "prioritized-metered-channel 0.5.1", + "prioritized-metered-channel", "sc-cli", "sc-service", "sc-tracing", @@ -9582,9 +9693,9 @@ dependencies = [ [[package]] name = "polkadot-node-network-protocol" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e420ba9220abaa468a393ff2834b7c2b4d7d87b6d903d9046dfd682c97d35d4c" +checksum = "07f9e67b0f25d695947a15b6fe8ee6f8e83f3dfcbca124a13281c0edd0dc4703" dependencies = [ "async-channel 1.9.0", "async-trait", @@ -9607,9 +9718,9 @@ dependencies = [ [[package]] name = "polkadot-node-primitives" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "366d18f1498426975c610246063149ad84788eb1e924cab6ee44a4d8958ecf61" +checksum = "375744eee7a53576387e14856e1c65be8ecef8b449567bb2cff85706266c8912" dependencies = [ "bitvec", "bounded-vec", @@ -9631,9 +9742,9 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "831cf07bf6588d7d8ab872f8f214b4b24b2c4243faf8028534f8a11a3f03c466" +checksum = "24d6c226cdbcd48ab1e506d8512f0fb01839f9a72eec2fc0cf7771f6d3352171" dependencies = [ "polkadot-node-jaeger", "polkadot-node-subsystem-types", @@ -9642,9 +9753,9 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-types" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd132afdfcdf2e30f7924c9561bbc1208b0838ab9c2275bf0ef32525f63b8bd0" +checksum = "1404525da0ab9d44bac1041449bf0c5576240f9031b305dc41654567e98b6021" dependencies = [ "async-trait", "bitvec", @@ -9671,9 +9782,9 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-util" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d32c2f2027689777bd61681d769ed5ec726144905c4e3cb16c5f8a4edb55250a" +checksum = "65a7d101f28bf718d15f01a060ed8cf7a7e2d8d5705c494b49ece696cada0adf" dependencies = [ "async-trait", "derive_more", @@ -9694,7 +9805,7 @@ dependencies = [ "polkadot-node-subsystem-types", "polkadot-overseer", "polkadot-primitives", - "prioritized-metered-channel 0.5.1", + "prioritized-metered-channel", "rand", "sc-client-api", "schnellru", @@ -9707,9 +9818,9 @@ dependencies = [ [[package]] name = "polkadot-overseer" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aa0b71f50f0be1959bcb10a46105ca66b9c6868d549385a247750e5b7a45c77" +checksum = "bd5ed988deffeddf440473586f62efc5dd498f6016e6650881db09dd60b3b24f" dependencies = [ "async-trait", "futures 0.3.30", @@ -9730,9 +9841,9 @@ dependencies = [ [[package]] name = "polkadot-parachain-primitives" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b37c55955147479e7b2f3c2e5385db4846ac3e3b997cd4a4ad52344524b5447" +checksum = "248ab090959a92e61493277e33b7e85104280a4beb4cb0815137d3c8c50a07f4" dependencies = [ "bounded-collections", "derive_more", @@ -9748,12 +9859,13 @@ dependencies = [ [[package]] name = "polkadot-primitives" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aefd230a654f5b2aee18ebbd9c081835def0e1898ee6c018501dd77c18f5929" +checksum = "e0d5f9930210cab0233d81204415c9ef4a8889cdf3e60de1435250481a2773ca" dependencies = [ "bitvec", "hex-literal 0.4.1", + "log", "parity-scale-codec", "polkadot-core-primitives", "polkadot-parachain-primitives", @@ -9775,9 +9887,9 @@ dependencies = [ [[package]] name = "polkadot-rpc" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "382eada9005c73375778e1dca58116e0660431cf90989fe0dde54ebe1f621a1e" +checksum = "bb4747cb8faa532e8446b38b74266fd626d6b660fe6b00776dd6c4543cc0457f" dependencies = [ "jsonrpsee", "mmr-rpc", @@ -9809,9 +9921,9 @@ dependencies = [ [[package]] name = "polkadot-runtime-common" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4641a850b7415a42e56bd262aba243ed77a9280cb2b825a427c425bdc8961d70" +checksum = "06afbb3bd10245ad1907242a98ddffc3c0c1e209738b8382bc5bcfc1f28c0429" dependencies = [ "bitvec", "frame-benchmarking", @@ -9836,7 +9948,6 @@ dependencies = [ "pallet-transaction-payment", "pallet-treasury", "pallet-vesting", - "pallet-xcm-benchmarks", "parity-scale-codec", "polkadot-primitives", "polkadot-runtime-parachains", @@ -9862,9 +9973,9 @@ dependencies = [ [[package]] name = "polkadot-runtime-metrics" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac3c6ee03f38556274b26049c51c5c7095abfd4ebfd11cd492918a4344f2851" +checksum = "e3566c6fd0c21b5dd555309427c984cf506f875ee90f710acea295b478fecbe0" dependencies = [ "bs58 0.5.1", "frame-benchmarking", @@ -9876,9 +9987,9 @@ dependencies = [ [[package]] name = "polkadot-runtime-parachains" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d253ef2952097398d98ed12729e47f9328bcd1baa92c3acc1524a4baca7d1ac" +checksum = "9bcfd672be236fd1c38c702e7e99fe3f3e54df0ddb8127e542423221d1f50669" dependencies = [ "bitflags 1.3.2", "bitvec", @@ -9926,9 +10037,9 @@ dependencies = [ [[package]] name = "polkadot-service" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d75bf984471c2608905176b62726b3552bbfdc3e04ebdc7fe75e5179ff215588" +checksum = "b2fd665185877bec296588c7cf1ec0ef75e0545050b5e1d42d94240a284149da" dependencies = [ "async-trait", "frame-benchmarking", @@ -10044,16 +10155,16 @@ dependencies = [ [[package]] name = "polkadot-statement-distribution" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82b48ff9204ea663ccccde78aefa8a524958aadff5c84a4f1fd773c291057d" +checksum = "8ff6d16cbd994987f48a9f107f12e4c7fff26cdd71df6288e9521adc7cff3427" dependencies = [ "arrayvec 0.7.4", "bitvec", "fatality", "futures 0.3.30", "futures-timer", - "indexmap 1.9.3", + "indexmap 2.2.6", "parity-scale-codec", "polkadot-node-network-protocol", "polkadot-node-primitives", @@ -10068,13 +10179,14 @@ dependencies = [ [[package]] name = "polkadot-statement-table" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478dea03265eb2465010dae149616e4f28fe858e103671b1a96dc19e9e388c8f" +checksum = "de5e010da3c6a65d8f263d0f825a04d995ffc8a37f886f674fcbbc73bf158d01" dependencies = [ "parity-scale-codec", "polkadot-primitives", "sp-core", + "tracing-gum", ] [[package]] @@ -10223,22 +10335,6 @@ dependencies = [ "uint", ] -[[package]] -name = "prioritized-metered-channel" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e99f0c89bd88f393aab44a4ab949351f7bc7e7e1179d11ecbfe50cbe4c47e342" -dependencies = [ - "coarsetime", - "crossbeam-queue", - "derive_more", - "futures 0.3.30", - "futures-timer", - "nanorand", - "thiserror", - "tracing", -] - [[package]] name = "prioritized-metered-channel" version = "0.6.1" @@ -10371,7 +10467,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" dependencies = [ "bytes", - "prost-derive", + "prost-derive 0.11.9", +] + +[[package]] +name = "prost" +version = "0.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" +dependencies = [ + "bytes", + "prost-derive 0.12.5", ] [[package]] @@ -10381,14 +10487,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools 0.10.5", "lazy_static", "log", "multimap", "petgraph", "prettyplease 0.1.11", - "prost", + "prost 0.11.9", "prost-types", "regex", "syn 1.0.109", @@ -10409,13 +10515,26 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "prost-derive" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9554e3ab233f0a932403704f1a1d08c30d5ccd931adfdfa1e8b5a19b52c1d55a" +dependencies = [ + "anyhow", + "itertools 0.11.0", + "proc-macro2", + "quote", + "syn 2.0.60", +] + [[package]] name = "prost-types" version = "0.11.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" dependencies = [ - "prost", + "prost 0.11.9", ] [[package]] @@ -10645,13 +10764,12 @@ dependencies = [ [[package]] name = "reed-solomon-novelpoly" -version = "1.0.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58130877ca403ab42c864fbac74bb319a0746c07a634a92a5cfc7f54af272582" +checksum = "87413ebb313323d431e85d0afc5a68222aaed972843537cbfe5f061cf1b4bcab" dependencies = [ "derive_more", "fs-err", - "itertools 0.11.0", "static_init", "thiserror", ] @@ -10825,9 +10943,9 @@ dependencies = [ [[package]] name = "rococo-runtime" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e5ae118c3f3189a376703a4ca8569eb51ce1b121bc6b571c051b68c31e10a16" +checksum = "d089e93be2b8b76dd0d4b794a6a995ca3a1d6cb0ea3dd1cd42462f048bcfc926" dependencies = [ "binary-merkle-tree", "frame-benchmarking", @@ -10922,9 +11040,9 @@ dependencies = [ [[package]] name = "rococo-runtime-constants" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b5b507493a19b5061eb2860c394847261216c7ea7f8f62ba2cb02e55c27d611" +checksum = "0b45c21ccb0f8777512a65510c106aeee4b59682944b9a5cb31cd7b8ed4ccb47" dependencies = [ "frame-support", "polkadot-primitives", @@ -10937,6 +11055,12 @@ dependencies = [ "staging-xcm-builder", ] +[[package]] +name = "route-recognizer" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afab94fb28594581f62d981211a9a4d53cc8130bbcbbb89a0440d9b8e81a7746" + [[package]] name = "rpassword" version = "7.3.1" @@ -10958,7 +11082,7 @@ dependencies = [ "log", "netlink-packet-route", "netlink-proto", - "nix", + "nix 0.24.3", "thiserror", "tokio", ] @@ -11159,9 +11283,9 @@ dependencies = [ [[package]] name = "sc-allocator" -version = "23.0.0" +version = "24.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b05714bc70605d5f8983612d1643d875cd4782ef53a8720907a0eb75070cba" +checksum = "357127c91373ed6d1ae582f6e3300ab5b13bcde43bbf270a891f44194ef48b70" dependencies = [ "log", "sp-core", @@ -11171,9 +11295,9 @@ dependencies = [ [[package]] name = "sc-authority-discovery" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1c23040352415cdcc22203d3b18e56f3516e51865f106f8bbf7efa95b411a59" +checksum = "7fb3c14cb8022844835a6f7209196b8c6544d389fe5d2972d8df2ae4ca75afbe" dependencies = [ "async-trait", "futures 0.3.30", @@ -11184,7 +11308,7 @@ dependencies = [ "multihash 0.18.1", "multihash-codetable", "parity-scale-codec", - "prost", + "prost 0.12.4", "prost-build", "rand", "sc-client-api", @@ -11201,9 +11325,9 @@ dependencies = [ [[package]] name = "sc-basic-authorship" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c016e38155386e23649a4a995ea67c55a1fe25a54c7cc7509954d454ee75eb3b" +checksum = "724c3a6eee5f0829a1b79a15e12d63ed81b33281b14004a6331a8883b2fd8fd1" dependencies = [ "futures 0.3.30", "futures-timer", @@ -11224,9 +11348,9 @@ dependencies = [ [[package]] name = "sc-block-builder" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "656b85de8aad8dd758f2e5f250f300e4711f294f238c9299064fbd624cb263f7" +checksum = "8e8b0640994965c6ff3afa13242d95a61611b83da21fd86ac2b1ebd03e241a02" dependencies = [ "parity-scale-codec", "sp-api", @@ -11240,14 +11364,14 @@ dependencies = [ [[package]] name = "sc-chain-spec" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7f6a6926973e084fe9b23ffee9784cd41d84ea0627c605891542661bd9ff958" +checksum = "0f73880050f8b04fed7f6301279ef3899df13a3891bd06156d56f9a1c50fefba" dependencies = [ "array-bytes 6.2.2", "docify", "log", - "memmap2", + "memmap2 0.9.4", "parity-scale-codec", "sc-chain-spec-derive", "sc-client-api", @@ -11258,6 +11382,7 @@ dependencies = [ "serde_json", "sp-blockchain", "sp-core", + "sp-crypto-hashing", "sp-genesis-builder", "sp-io", "sp-runtime", @@ -11278,9 +11403,9 @@ dependencies = [ [[package]] name = "sc-cli" -version = "0.36.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9819b656041094ca4e97402be145c2bcf3f47d00d854708b25ecd3211eafcd62" +checksum = "e8a284c10ea92b1fe789b9f0e5815d393f3a1e3bf6a4adaa884f24e36143b83b" dependencies = [ "array-bytes 6.2.2", "bip39", @@ -11320,9 +11445,9 @@ dependencies = [ [[package]] name = "sc-client-api" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af05565a0f6467ebe0b430f3a44524fecee9e4aff621647ea5eab8833f775b6f" +checksum = "3e914dfadaaf384d8869ae47f3ec783bf6a1ac24e7827f5fec2e0e649a450a91" dependencies = [ "fnv", "futures 0.3.30", @@ -11348,9 +11473,9 @@ dependencies = [ [[package]] name = "sc-client-db" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9fbd18eb275120fdf2e9558a5006a69022405abb9c260c91d218ddb05db39" +checksum = "1f08c4f29e6d2b8915bab6435b8817fa39ef7708c04a7cf6226f803e133b017c" dependencies = [ "hash-db 0.16.0", "kvdb", @@ -11375,9 +11500,9 @@ dependencies = [ [[package]] name = "sc-consensus" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b0409758bb01f2e975b01c7cb2203aa27746e9796a483b18c57123e6e78fae5" +checksum = "c8e1ac2c698b828073982b6f5b1a466fcc345a452983356af74254ade8e9987d" dependencies = [ "async-trait", "futures 0.3.30", @@ -11401,9 +11526,9 @@ dependencies = [ [[package]] name = "sc-consensus-aura" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cc4ebc06768af3e5457a5780aa6dbebeefe27131e70d11b62cfc8136e41747a" +checksum = "a16fd09794291795ad43ea1df7190083f9a47fc0a73e9b8ec0ae98fbe53a2b34" dependencies = [ "async-trait", "futures 0.3.30", @@ -11431,9 +11556,9 @@ dependencies = [ [[package]] name = "sc-consensus-babe" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a7d698d9d2bde7e0b80e7ada57ede9255a6382da79d2ad9a4e9e70805c40e74" +checksum = "82ec3dc31f8fd024684d1306488836680558b680a8ec38219e19f20854811f02" dependencies = [ "async-trait", "fork-tree", @@ -11458,6 +11583,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-slots", "sp-core", + "sp-crypto-hashing", "sp-inherents", "sp-keystore", "sp-runtime", @@ -11467,9 +11593,9 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f55379d0ce6f87026f896f03bce33862b57f77a46fbb4fb7e974182d20d458" +checksum = "bf2b3004672f9eea0d9af6c9b944fa3ef0bc72fd88cea9075cdf6dc96d1439ac" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -11490,9 +11616,9 @@ dependencies = [ [[package]] name = "sc-consensus-beefy" -version = "13.0.0" +version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3664a3cddc718187e058f67d9075ef9078c8f8347c0408304ead8565d4ba8164" +checksum = "e9ce3ee15eff7fa642791966d427f185184df3c7f4e58893705f3e7781da8ef5" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -11515,6 +11641,7 @@ dependencies = [ "sp-consensus", "sp-consensus-beefy", "sp-core", + "sp-crypto-hashing", "sp-keystore", "sp-mmr-primitives", "sp-runtime", @@ -11526,9 +11653,9 @@ dependencies = [ [[package]] name = "sc-consensus-beefy-rpc" -version = "13.0.0" +version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b4e3602efe1e206032164772c24365642e3dab807c5f8db0af166f6ef63af3e" +checksum = "2a1ed5e8ac2cb53c6a248c8f469353f55bd23c72f23fe371ac19c1d46618de1a" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -11546,9 +11673,9 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0befddf2ca16d5f222968fceeab8625532f2d49303fafd17ae2e5d0e939da6" +checksum = "19f68ddb91626f901578515eed93c7919f739660161f4e9f7b9407e2d0ede981" dependencies = [ "fork-tree", "parity-scale-codec", @@ -11560,9 +11687,9 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a824457a3384e7bc19d7ee587dffa5b646deb81a2351be0dd075c2110a3d677a" +checksum = "7ae91e5b5a120be4d13a59eaf94fd85d7c7af528482b8e21d861fa1167df3083" dependencies = [ "ahash 0.8.11", "array-bytes 6.2.2", @@ -11595,6 +11722,7 @@ dependencies = [ "sp-consensus", "sp-consensus-grandpa", "sp-core", + "sp-crypto-hashing", "sp-keystore", "sp-runtime", "substrate-prometheus-endpoint", @@ -11603,9 +11731,9 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa-rpc" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "694328880bf11fce67f5e066d7884dbdf1f2a41c42a7dfce9b0a6bc6b90448a1" +checksum = "697cbd528516561dbc818a8990d5477169e86d9335a0b29207cf6f6a90269e7c" dependencies = [ "finality-grandpa", "futures 0.3.30", @@ -11624,9 +11752,9 @@ dependencies = [ [[package]] name = "sc-consensus-manual-seal" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b87636dd0b8aa3d294200100196b0fb51c389ed73e6722ff648feb0fd4adafdb" +checksum = "4c26241f1846c897626b141e2568dbf9088036a1b18b241de23fcebc7a8f5e2e" dependencies = [ "assert_matches", "async-trait", @@ -11660,9 +11788,9 @@ dependencies = [ [[package]] name = "sc-consensus-slots" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6649665fcf91d89c16bfb08e9326baf6547e5fe719d6438197434e5b642d716b" +checksum = "567bddd65d52951fb9bc7a7e05d1dfdfc47ff2c594ec5ca9756d27e7226635bb" dependencies = [ "async-trait", "futures 0.3.30", @@ -11684,9 +11812,9 @@ dependencies = [ [[package]] name = "sc-executor" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3129f8af1f8aa5b05829ffec942feff61163054a536704ba48fdcc2276f6042a" +checksum = "aa2ac6c356538d67987bbb867e11a12a84ba87250c70fd50005b6d74f570a4f7" dependencies = [ "parity-scale-codec", "parking_lot 0.12.2", @@ -11707,9 +11835,9 @@ dependencies = [ [[package]] name = "sc-executor-common" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0285a4a14c0d2c1d04380ff83cddd79181ded510c605d36804cb9c6eb3bbf2ae" +checksum = "07498138dee3ddf2c71299ca372d8449880bb3a8a8a299a483094e9c26b0823e" dependencies = [ "sc-allocator", "sp-maybe-compressed-blob", @@ -11720,9 +11848,9 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" -version = "0.29.0" +version = "0.30.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c2ba6ea0e68400caf4847fbcfca6123952b05a817e06f024e9cbafa665ac9d8" +checksum = "30a387779ab54ec1ffce0bf3a6631faada079459d42796c1895683767918a642" dependencies = [ "anyhow", "cfg-if", @@ -11739,9 +11867,9 @@ dependencies = [ [[package]] name = "sc-informant" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e07d2dde727c30974767aed4cddd241447c0a800b702662b529dd2e32a10db1" +checksum = "eb603a0a703f1bc10a4e6462bec1036d8fb8b3e3eff5513a9c07f98ccb8d662d" dependencies = [ "ansi_term", "futures 0.3.30", @@ -11757,9 +11885,9 @@ dependencies = [ [[package]] name = "sc-keystore" -version = "25.0.0" +version = "26.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93acb7f7c6e5e4be067e78b782a35d1a6d34dafcd955975a1aec05cab9dbf8fe" +checksum = "4cc4f6a558dd23e3bae2e9f195da822465258b9aaf211c34360d7f6efb944e54" dependencies = [ "array-bytes 6.2.2", "parking_lot 0.12.2", @@ -11772,9 +11900,9 @@ dependencies = [ [[package]] name = "sc-mixnet" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cac7d7145c712c4a8b184b3979fe1a154c200ebb1b9f11f1e4e39db97a389f8" +checksum = "45fb213c15679fe5b87c383815d7fb758c70d3e7c573948bd7fe26ff344d2272" dependencies = [ "array-bytes 4.2.0", "arrayvec 0.7.4", @@ -11802,9 +11930,9 @@ dependencies = [ [[package]] name = "sc-network" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2f49eccabc1de61ff976a184f5380a230f07baa5cb075a31c8ec9459fcd076" +checksum = "f231c7d5e749ec428b4cfa669d759ae76cd3da4f50d7352a2d711acdc7532891" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -11846,16 +11974,16 @@ dependencies = [ [[package]] name = "sc-network-bitswap" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2779d97eff742c1ebcce812bfd154a7273c2c2eb02e11fad76cf7eb583365834" +checksum = "e2f89b0134738cb3d982b6e625ca93ae8dbe83ce2a06e4b6a396e4df09ed3499" dependencies = [ "async-channel 1.9.0", "cid", "futures 0.3.30", "libp2p-identity", "log", - "prost", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-network", @@ -11867,9 +11995,9 @@ dependencies = [ [[package]] name = "sc-network-common" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b798acc12d5b3120b2d5e8a078fcec39d6732089261136ac31c993235ade917" +checksum = "3504bbff5ab016948dbab0f21a8be26324810b76eff3627ce744adb5bfc1b3ce" dependencies = [ "async-trait", "bitflags 1.3.2", @@ -11885,9 +12013,9 @@ dependencies = [ [[package]] name = "sc-network-gossip" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd92792f3a04fcb1f21018c9f8a5d6d438d705a2548ffcdc7730280c667b8386" +checksum = "dad02cf809c34b53614fa61377e3289064edf6c78eb11df071d11fbf7546d7e9" dependencies = [ "ahash 0.8.11", "futures 0.3.30", @@ -11905,9 +12033,9 @@ dependencies = [ [[package]] name = "sc-network-light" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34e7a126492850dbbd5cf0b77ec3ad350422c2822d165941ddbe618a76af0153" +checksum = "38d84ef0b212c775f58e0304ec09166089f6b09afddf559b7c2b5702933b3be4" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -11915,7 +12043,7 @@ dependencies = [ "libp2p-identity", "log", "parity-scale-codec", - "prost", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-network", @@ -11927,9 +12055,9 @@ dependencies = [ [[package]] name = "sc-network-sync" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4c92fd35c49f748abf0bf420e1e99aa76b0f48ab43c183ea5dacef951116d7e" +checksum = "9aa9377059deece4e7d419d9ec456f657268c0c603e1cf98df4a920f6da83461" dependencies = [ "array-bytes 6.2.2", "async-channel 1.9.0", @@ -11941,7 +12069,7 @@ dependencies = [ "log", "mockall", "parity-scale-codec", - "prost", + "prost 0.12.4", "prost-build", "sc-client-api", "sc-consensus", @@ -11964,9 +12092,9 @@ dependencies = [ [[package]] name = "sc-network-transactions" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99a1af3b9e158fa91df0cd92916b3ee5d8b8a14a2b61eb5dd9e36e045808f644" +checksum = "16c9cad4baf348725bd82eadcd1747fc112ec49c76b863755ce79c588fa73fe4" dependencies = [ "array-bytes 6.2.2", "futures 0.3.30", @@ -11984,9 +12112,9 @@ dependencies = [ [[package]] name = "sc-offchain" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd5408dbdc3fe345813e983bd2b7ecf8f20e996141fa39a36336f511ab1859bb" +checksum = "1aee89f2abd406356bfd688bd7a51155dc963259e4b752bb85d1f8a061a194fd" dependencies = [ "array-bytes 6.2.2", "bytes", @@ -12029,9 +12157,9 @@ dependencies = [ [[package]] name = "sc-rpc" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac0d83b9117c9c004e58331a593a28044eaf6414e5b3c605d1571b4a6981966" +checksum = "4a5acf6d89f062d1334a0c5b67e9dea97666cd47a49acb2696eab55ff1a1bf74" dependencies = [ "futures 0.3.30", "jsonrpsee", @@ -12062,9 +12190,9 @@ dependencies = [ [[package]] name = "sc-rpc-api" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630e81a436f32487452ae1a57ad0ba31f320ddf864bb7faefd7490fe16b3e139" +checksum = "e9db6aaabfa7e0c27ec15d0f0a11b994cd4bcf86e362f0d9732b4a414d793f0f" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -12083,9 +12211,9 @@ dependencies = [ [[package]] name = "sc-rpc-server" -version = "11.0.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b623908525a2f22aafa079080aa7fbce8b58ca8de53b9f31e3cc8547e0ad8b2" +checksum = "691440bbaddd3bc2675309c965cc75f8bf694f51e0a28039bfc9658299fbc394" dependencies = [ "http", "jsonrpsee", @@ -12099,9 +12227,9 @@ dependencies = [ [[package]] name = "sc-rpc-spec-v2" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a54150c808fa10364b73faedd97aff0977a911a521d1caa8bad2bdc7943ad579" +checksum = "a7f10275c62296a785f6e2ac716521e3b6e0fae470416fdf86491cbbfcc2e23d" dependencies = [ "array-bytes 6.2.2", "futures 0.3.30", @@ -12113,6 +12241,7 @@ dependencies = [ "parking_lot 0.12.2", "sc-chain-spec", "sc-client-api", + "sc-rpc", "sc-transaction-pool-api", "sc-utils", "serde", @@ -12129,9 +12258,9 @@ dependencies = [ [[package]] name = "sc-service" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "703bd8b1fc0a137185bfa0b654e04283a58a1d8a2751380e7a0eca919961f150" +checksum = "e14ea779b8c5bdb0d0199c8beebcf1fdc5641e468c480e1c4684be660c8c90af" dependencies = [ "async-trait", "directories", @@ -12193,9 +12322,9 @@ dependencies = [ [[package]] name = "sc-state-db" -version = "0.30.0" +version = "0.31.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fac20128b09ac6305aaf482a72c918b35400f3955d7032971df499b0661a5e76" +checksum = "aa842052c41ad379eaecdfddc0d5c953d57e311ae688233f68f461b91d38da0a" dependencies = [ "log", "parity-scale-codec", @@ -12205,9 +12334,9 @@ dependencies = [ [[package]] name = "sc-storage-monitor" -version = "0.16.0" +version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "838d31b4316424d1c2c3a2f06f4e76cd56b53f38d366fc9882444d4ce8faabec" +checksum = "26cb401aad6732700c8d866cbbef1175b9aeb8230908aff27059ef14bd058ef3" dependencies = [ "clap", "fs4", @@ -12219,9 +12348,9 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb310dce9d2474a74152605dc0ca0f81a46f61ba4e7a39752f1203121f47c0c6" +checksum = "9bc382c7d997f4531eee5e5d57f970eaf2761d722298d7747385a4ad69fa6b12" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -12239,9 +12368,9 @@ dependencies = [ [[package]] name = "sc-sysinfo" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfc9a5da78281735c6ff3b8d0287e95dcf32fc001415ac20cb2844c0ab4e6d05" +checksum = "25d2ab8f15021916a07cfbe7a08be484c5dc7d57f07bc0e2aa03260b55a5632f" dependencies = [ "derive_more", "futures 0.3.30", @@ -12254,15 +12383,16 @@ dependencies = [ "serde", "serde_json", "sp-core", + "sp-crypto-hashing", "sp-io", "sp-std", ] [[package]] name = "sc-telemetry" -version = "15.0.0" +version = "16.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96841bdc22e1ad5931e6cb7557b06ef33aeda7f5eef3864653359840f9fd025a" +checksum = "0673a93aa0684b606abfc5fce6c882ada7bb5fad8a2ddc66a09a42bcc9664d91" dependencies = [ "chrono", "futures 0.3.30", @@ -12280,9 +12410,9 @@ dependencies = [ [[package]] name = "sc-tracing" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90864e5e042d1238bcb082b0fa73ce58b7eb4897127783dae1dd66eee59cdaef" +checksum = "e77b4fdb4f359f19c395ba862430f3ca0efb50b0310b09753caaa06997edd606" dependencies = [ "ansi_term", "chrono", @@ -12323,9 +12453,9 @@ dependencies = [ [[package]] name = "sc-transaction-pool" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7985fab634814ee28fe3ecd2131fa2cb4c8eee88a7e60f1cd59dc0afa826fe2" +checksum = "326dc8ea417c53b6787bd1bb27431d44768504451f5ce4efdde0c15877c7c121" dependencies = [ "async-trait", "futures 0.3.30", @@ -12341,6 +12471,7 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-core", + "sp-crypto-hashing", "sp-runtime", "sp-tracing", "sp-transaction-pool", @@ -12350,9 +12481,9 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3402336f81a52fd6b1fd5a16fa3f4279032de1e113fe4a973865bf0b0e28679c" +checksum = "93ae888ce3491acb1b489c3dba930d0c46c7ef9f9893ba0ab8af9125362f3d14" dependencies = [ "async-trait", "futures 0.3.30", @@ -12367,9 +12498,9 @@ dependencies = [ [[package]] name = "sc-utils" -version = "14.0.0" +version = "15.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4d5d1f106d670dd0c56fe540e8b0916aaeff6960bb39440ed8f3c80b52f8d4" +checksum = "28b1a238f5baa56405db4e440e2d2f697583736fa2e2f1aac345c438a42975f1" dependencies = [ "async-channel 1.9.0", "futures 0.3.30", @@ -12741,7 +12872,7 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa42c91313f1d05da9b26f267f931cf178d4aba455b4c4622dd7355eb80c6640" dependencies = [ - "bstr 0.2.17", + "bstr", "unicode-segmentation", ] @@ -12784,9 +12915,9 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "slot-range-helper" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d9bb569dc58f1e139c20f532a2ad13d54795060c0000c2c49dc812b17684197" +checksum = "d40fa5e14772407fd2ccffdd5971bf055bbf46a40727c0ea96d2bb6563d17e1c" dependencies = [ "enumn", "parity-scale-codec", @@ -12979,9 +13110,9 @@ dependencies = [ [[package]] name = "sp-api" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dea138c6dbf282ab57756492f0232ea0a08575ca9cbe2b7b1ead49000f238a7" +checksum = "6ef42aa652381ade883c14ffbbb5c0fec36d382d2217b5bace01b8a0e8634778" dependencies = [ "hash-db 0.16.0", "log", @@ -13016,9 +13147,9 @@ dependencies = [ [[package]] name = "sp-application-crypto" -version = "30.0.0" +version = "31.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e4fe7a9b7fa9da76272b201e2fb3c7900d97d32a46b66af9a04dad457f73c71" +checksum = "547cad7a6eabb52c639ec117b3db9c6b43cf1b29a9393b18feb19e101a91833f" dependencies = [ "parity-scale-codec", "scale-info", @@ -13030,9 +13161,9 @@ dependencies = [ [[package]] name = "sp-arithmetic" -version = "23.0.0" +version = "24.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f42721f072b421f292a072e8f52a3b3c0fbc27428f0c9fe24067bc47046bad63" +checksum = "afa823ca5adc490d47dccb41d69ad482bc57a317bd341de275868378f48f131c" dependencies = [ "integer-sqrt", "num-traits", @@ -13045,9 +13176,9 @@ dependencies = [ [[package]] name = "sp-authority-discovery" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22a740c05e9096eb17e93b5ab6aa5fe8ce0c9b4243777826d92133b3dd682e14" +checksum = "c92b177c72b5d2973c36d60f6ef942d791d9fd91eae8b08c71882e4118d4fbfc" dependencies = [ "parity-scale-codec", "scale-info", @@ -13059,9 +13190,9 @@ dependencies = [ [[package]] name = "sp-block-builder" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6d2aa0943101367b955f5806c3ecea2e23df7c90059708107470dbfb9d3d7ab" +checksum = "1b36ce171caa7eb2bbe682c089f755fdefa71d3702e4fb1ba30d10146aef99d5" dependencies = [ "sp-api", "sp-inherents", @@ -13071,9 +13202,9 @@ dependencies = [ [[package]] name = "sp-blockchain" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9adee5ddcf0682d0302ed640a285b9f922d933a205b63c7819a74d6092b6f78" +checksum = "a31303e766d2e53812641bbc1f1cec03a85793fc9e627e55f0a6854b28708758" dependencies = [ "futures 0.3.30", "log", @@ -13090,9 +13221,9 @@ dependencies = [ [[package]] name = "sp-consensus" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfcac16e85f78db9c99c9424659bb25790be079a0b758a3674ee8e1e7ef635b0" +checksum = "cb6e512b862c4ff7a26cdcd364898cc42e181ff5cb35fbb226ff27d88c81569a" dependencies = [ "async-trait", "futures 0.3.30", @@ -13106,9 +13237,9 @@ dependencies = [ [[package]] name = "sp-consensus-aura" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8e878a116b0885eaefd068235657737cb72fdce60a8c080dfd092f7d645cc" +checksum = "4bf13c293685319751f72fa5216c7fb5f25f3e8e8fe29b4503296ed5f5466b3d" dependencies = [ "async-trait", "parity-scale-codec", @@ -13124,9 +13255,9 @@ dependencies = [ [[package]] name = "sp-consensus-babe" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebfedfdea5b22fb3625cd664e72503dcbd1087373181d5be0d092b3e7b4c61f5" +checksum = "b9be2f86a2f0ce2a78b455feb547aa27604fd76a7f7a691995cbad44e0b1b9dd" dependencies = [ "async-trait", "parity-scale-codec", @@ -13144,9 +13275,9 @@ dependencies = [ [[package]] name = "sp-consensus-beefy" -version = "13.0.0" +version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09a424196a673f0e6b5fe79e4ab97da416491cfecab7bc835fa595134ac1b5c" +checksum = "90ff890a84ef57628b010df0e1d75b3a78fb7f575e4ceeba7215c276902c403e" dependencies = [ "lazy_static", "parity-scale-codec", @@ -13155,6 +13286,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-core", + "sp-crypto-hashing", "sp-io", "sp-mmr-primitives", "sp-runtime", @@ -13164,9 +13296,9 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" -version = "13.0.0" +version = "14.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a906b20409a5a69b1d9580848f502af20cf2c51a1ae028ba208375eb11f332b" +checksum = "64b606164600db36e596db7abf32b4533dc9a74526d9444c4c45035427b2199b" dependencies = [ "finality-grandpa", "log", @@ -13183,9 +13315,9 @@ dependencies = [ [[package]] name = "sp-consensus-slots" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc5c1620d81196391daa15e78ea20cc11c59f08c509381c276d5d6a3d4d36af" +checksum = "73a5bd1fcd84bbdc7255528c7cdb92f9357fd555f06ee553af7e340cbdab517c" dependencies = [ "parity-scale-codec", "scale-info", @@ -13196,9 +13328,9 @@ dependencies = [ [[package]] name = "sp-core" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f230cb12575455070da0fc174815958423a0b9a641d5e304a9457113c7cb4007" +checksum = "7c33c7a1568175250628567d50c4e1c54a6ac5bc1190413b9be29a9e810cbe73" dependencies = [ "array-bytes 6.2.2", "bip39", @@ -13226,7 +13358,7 @@ dependencies = [ "secp256k1", "secrecy", "serde", - "sp-core-hashing", + "sp-crypto-hashing", "sp-debug-derive", "sp-externalities", "sp-runtime-interface", @@ -13241,10 +13373,10 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing" -version = "15.0.0" +name = "sp-crypto-hashing" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0f4990add7b2cefdeca883c0efa99bb4d912cb2196120e1500c0cc099553b0" +checksum = "bc9927a7f81334ed5b8a98a4a978c81324d12bd9713ec76b5c68fd410174c5eb" dependencies = [ "blake2b_simd", "byteorder", @@ -13255,13 +13387,13 @@ dependencies = [ ] [[package]] -name = "sp-core-hashing-proc-macro" -version = "15.0.0" +name = "sp-crypto-hashing-proc-macro" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7527f8dda7667c41009b2cd0efaddcb81709b9741bd5ee6d17b11bad835cc698" +checksum = "b85d0f1f1e44bd8617eb2a48203ee854981229e3e79e6f468c7175d5fd37489b" dependencies = [ "quote", - "sp-core-hashing", + "sp-crypto-hashing", "syn 2.0.60", ] @@ -13288,9 +13420,9 @@ dependencies = [ [[package]] name = "sp-externalities" -version = "0.25.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63867ec85950ced90d4ab1bba902a47db1b1efdf2829f653945669b2bb470a9c" +checksum = "e7096ed024cec397804864898b093b51e14c7299f1d00c67dd5800330e02bb82" dependencies = [ "environmental", "parity-scale-codec", @@ -13300,9 +13432,9 @@ dependencies = [ [[package]] name = "sp-genesis-builder" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfdc79df83221ec5a279cbbd08fd6f8be164b9b081c8e84593ce2c2ebd5d66c0" +checksum = "fd865540ec19479c7349b584ccd78cc34c3f3a628a2a69dbb6365ceec36295ee" dependencies = [ "serde_json", "sp-api", @@ -13312,9 +13444,9 @@ dependencies = [ [[package]] name = "sp-inherents" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a3caf2d1288549d7e6c32b453f2d4855d498bb88600101011e35653e022a6f2" +checksum = "607c9e35e96966645ff180a9e9f976433b96e905d0a91d8d5315e605a21f4bc0" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -13327,9 +13459,9 @@ dependencies = [ [[package]] name = "sp-io" -version = "30.0.0" +version = "31.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c55f26d89feedaf0faf81688b6e1e1e81329cd8b4c6a4fd6c5b97ed9dd068b8a" +checksum = "ec43aa073eab35fcb920d7592474d5427ea3be2bf938706a3ad955d7ba54fd8d" dependencies = [ "bytes", "ed25519-dalek", @@ -13339,6 +13471,7 @@ dependencies = [ "rustversion", "secp256k1", "sp-core", + "sp-crypto-hashing", "sp-externalities", "sp-keystore", "sp-runtime-interface", @@ -13352,9 +13485,9 @@ dependencies = [ [[package]] name = "sp-keyring" -version = "31.0.0" +version = "32.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98165ce7c625a8cdb88d39c6bbd56fe8b32ada64ed0894032beba99795f557da" +checksum = "69cf0a2f881958466fc92bc9b39bbc2c0d815ded4a21f8f953372b0ac2e11b02" dependencies = [ "sp-core", "sp-runtime", @@ -13363,9 +13496,9 @@ dependencies = [ [[package]] name = "sp-keystore" -version = "0.34.0" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96806a28a62ed9ddecd0b28857b1344d029390f7c5c42a2ff9199cbf5638635c" +checksum = "444f2d53968b1ce5e908882710ff1f3873fcf3e95f59d57432daf685bbacb959" dependencies = [ "parity-scale-codec", "parking_lot 0.12.2", @@ -13398,9 +13531,9 @@ dependencies = [ [[package]] name = "sp-mixnet" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85ed83d2f899484bde61c72cbae6edfb25708d43e6b19934e206f3c706df67df" +checksum = "7bebd44b915c65aeb7e7eeaea466aba3b27cdd915c83ea83d4643c54f21ffbbf" dependencies = [ "parity-scale-codec", "scale-info", @@ -13411,9 +13544,9 @@ dependencies = [ [[package]] name = "sp-mmr-primitives" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7526a73d518c03fa2447588b1544019a194a4f113cf34d2610d3b5925c80c86" +checksum = "891b7263b7c44a569173ee1078f68fb1a01991a44914607c0100aa5ae41f6562" dependencies = [ "ckb-merkle-mountain-range", "log", @@ -13430,9 +13563,9 @@ dependencies = [ [[package]] name = "sp-npos-elections" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa8efff28b504b4b928288976e5f72c00c7ece9d2348a7ca2496c77849dd4c8f" +checksum = "195d7e1154c91cce5c3abc8c778689c3e5799da6411328dd32ac7a974c68e526" dependencies = [ "parity-scale-codec", "scale-info", @@ -13445,9 +13578,9 @@ dependencies = [ [[package]] name = "sp-offchain" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb45b3e397dc9c7b81cb2d8d641d0bcb1f525b60e83835783413ba73b3f61ac9" +checksum = "4d83b955dce0b6d143bec3f60571311168f362b1c16cf044da7037a407b66c19" dependencies = [ "sp-api", "sp-core", @@ -13467,9 +13600,9 @@ dependencies = [ [[package]] name = "sp-rpc" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a55f2c7660b579627d22932ecfe2e5f001a7671d2fa77667387517c7f80e6fb" +checksum = "9af4b73fe7ddd88b1641cca90048c4e525e721763199e6fd29c4f590884f4d16" dependencies = [ "rustc-hash", "serde", @@ -13478,9 +13611,9 @@ dependencies = [ [[package]] name = "sp-runtime" -version = "31.0.1" +version = "32.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3bb49a4475d390198dfd3d41bef4564ab569fbaf1b5e38ae69b35fc01199d91" +checksum = "0a95e71603a6281e91b0f1fd3d68057644be16d75a4602013187b8137db8abee" dependencies = [ "docify", "either", @@ -13503,9 +13636,9 @@ dependencies = [ [[package]] name = "sp-runtime-interface" -version = "24.0.0" +version = "25.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f66b66d8cec3d785fa6289336c1d9cbd4305d5d84f7134378c4d79ed7983e6fb" +checksum = "4e2321ab29d4bcc31f1ba1b4f076a81fb2a666465231e5c981c72320d74dbe63" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -13536,9 +13669,9 @@ dependencies = [ [[package]] name = "sp-session" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8048981db53d4f5171e6003f5e11fbfc27a8c196b0827619907a4214746a623b" +checksum = "3b86531090cc04d2ab3535df07146258e2fb3ab6257b0a77ef14aa08282c3d4a" dependencies = [ "parity-scale-codec", "scale-info", @@ -13552,9 +13685,9 @@ dependencies = [ [[package]] name = "sp-staking" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0e68be3fff84dd8ee552f9d13dd2e9eab3663e0bddfc6c6c88de02aaca1e311" +checksum = "1e14d003ecf0b610bf1305a92bdab875289b39d514c073f30e75e78c2763a788" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -13567,9 +13700,9 @@ dependencies = [ [[package]] name = "sp-state-machine" -version = "0.35.0" +version = "0.36.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "718c779ad1d6fcc0be64c7ce030b33fa44b5c8914b3a1319ef63bb5f27fb98df" +checksum = "a67297e702aa32027d7766803f362a420d6d3ec9e2f84961f3c64e2e52b5aaf9" dependencies = [ "hash-db 0.16.0", "log", @@ -13589,9 +13722,9 @@ dependencies = [ [[package]] name = "sp-statement-store" -version = "10.0.0" +version = "11.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fee6d4ceb2513f180e6e017fd6d6f3c9a1a122dcedee5fc8e4254d8a7ecf793d" +checksum = "309a9ae4e8134bbed8ffc510cf4d461a4a651f9250b556de782cedd876abe1ff" dependencies = [ "aes-gcm", "curve25519-dalek 4.1.2", @@ -13604,6 +13737,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-core", + "sp-crypto-hashing", "sp-externalities", "sp-runtime", "sp-runtime-interface", @@ -13620,9 +13754,9 @@ checksum = "12f8ee986414b0a9ad741776762f4083cd3a5128449b982a3919c4df36874834" [[package]] name = "sp-storage" -version = "19.0.0" +version = "20.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb92d7b24033a8a856d6e20dd980b653cbd7af7ec471cc988b1b7c1d2e3a32b" +checksum = "8dba5791cb3978e95daf99dad919ecb3ec35565604e88cd38d805d9d4981e8bd" dependencies = [ "impl-serde", "parity-scale-codec", @@ -13634,9 +13768,9 @@ dependencies = [ [[package]] name = "sp-timestamp" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "347eaddd5b07856ccec69ac3300e72e392a5efc3aea5fb4b7230888a0b447b9e" +checksum = "249cd06624f2edb53b25af528ab216a508dc9d0870e158b43caac3a97e86699f" dependencies = [ "async-trait", "parity-scale-codec", @@ -13661,9 +13795,9 @@ dependencies = [ [[package]] name = "sp-transaction-pool" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97c4052e69eacdb7a411e050c56a838f460b8a879071125451e9bb2d4814df34" +checksum = "9742861c5330bdcb42856a6eed3d3745b58ee1c92ca4c9260032ff4e6c387165" dependencies = [ "sp-api", "sp-runtime", @@ -13671,9 +13805,9 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" -version = "26.0.0" +version = "27.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2a2c693bc7ca363c9d2cd412276582aef10c794399aaffbd1fe2351099a1a5" +checksum = "ece8e22a5419c7a336a2544654e1389fec8cac19b93081a30912842b44e8167f" dependencies = [ "async-trait", "parity-scale-codec", @@ -13687,9 +13821,9 @@ dependencies = [ [[package]] name = "sp-trie" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e4d24d84a0beb44a71dcac1b41980e1edf7fb722c7f3046710136a283cd479b" +checksum = "eed48dfd05081e8b36741b10ce4eb686c135a2952227a11fe71caec89890ddbb" dependencies = [ "ahash 0.8.11", "hash-db 0.16.0", @@ -13712,16 +13846,16 @@ dependencies = [ [[package]] name = "sp-version" -version = "29.0.0" +version = "30.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afd1b053394347e22f541696bca4a9ac3ec848b50d1b86f5018d2b771f39f11a" +checksum = "ff4a660c68995663d6778df324f4e2b4efc48d55a8e9c92c22a5fb7dae7899cd" dependencies = [ "impl-serde", "parity-scale-codec", "parity-wasm", "scale-info", "serde", - "sp-core-hashing-proc-macro", + "sp-crypto-hashing-proc-macro", "sp-runtime", "sp-std", "sp-version-proc-macro", @@ -13756,9 +13890,9 @@ dependencies = [ [[package]] name = "sp-weights" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e874bdf9dd3fd3242f5b7867a4eaedd545b02f29041a46d222a9d9d5caaaa5c" +checksum = "a3be30aec904994451dcacf841a9168cfbbaf817de6b24b6a1c1418cbf1af2fe" dependencies = [ "bounded-collections", "parity-scale-codec", @@ -13826,9 +13960,9 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "staging-node-inspect" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98c55152a6c1d08faa7aef9b838c7d6d5d240e3cd638e1504d06a798b4652dd0" +checksum = "394fb14c6e056213bfc3a97a246492604a6c6a0813b786f87cc2d585270c0a0b" dependencies = [ "clap", "parity-scale-codec", @@ -13845,9 +13979,9 @@ dependencies = [ [[package]] name = "staging-parachain-info" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad554ffd27fbcafd82e234d7e7188e458e51bfe2b3b5000dd236dce762e3e95f" +checksum = "da7dc139d104f676a18c13380a09c3f72d59450a7471116387cbf8cb5f845a0e" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -13860,9 +13994,9 @@ dependencies = [ [[package]] name = "staging-xcm" -version = "7.0.0" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df18af00766d22926916bb443f14742c65cc6b2f0fe997b8f26da0d0f9ee9ca" +checksum = "48fa328b87de3466bc38cc9a07244c42c647b7755b81115e1dfeb47cc13fc6e6" dependencies = [ "array-bytes 6.2.2", "bounded-collections", @@ -13879,9 +14013,9 @@ dependencies = [ [[package]] name = "staging-xcm-builder" -version = "7.0.3" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ba4f214fe99d79ffcc266f431abbb32d3596788327b925d469c7bb6a3c84d3c" +checksum = "a8f6cfc27c1d45f9a67e20ed3f7e60296299688825350291606add10bf3bbff2" dependencies = [ "frame-support", "frame-system", @@ -13902,9 +14036,9 @@ dependencies = [ [[package]] name = "staging-xcm-executor" -version = "7.0.3" +version = "8.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f1dea1e33eefee513c197c24255670951a2c515a6ce2c7049fe86385400074f" +checksum = "a638f4c8735cc04b5c93920a1f59e679f48b131315a07d146798e0decebf7720" dependencies = [ "environmental", "frame-benchmarking", @@ -13971,9 +14105,9 @@ dependencies = [ [[package]] name = "strsim" -version = "0.10.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" @@ -14005,7 +14139,7 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -14018,7 +14152,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -14031,7 +14165,7 @@ version = "0.26.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c6cf59daf282c0a494ba14fd21610a0325f9f90ec9d1231dea26bcb1d696c946" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -14070,9 +14204,9 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" -version = "28.0.0" +version = "29.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcee7812a1e1cec85e3095c5d1c1627ceb084c0c81e66c2f9df7cb7b3a5938f3" +checksum = "332f903d2f34703204f0003136c9abbc569d691028279996a1daf8f248a7369f" dependencies = [ "frame-system-rpc-runtime-api", "futures 0.3.30", @@ -14103,9 +14237,9 @@ dependencies = [ [[package]] name = "substrate-rpc-client" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9076480cc6f480429b081bf93607d32183bdac4d6f0d2969d5e08de08bea1701" +checksum = "40e5235d8460ec81e9a382345aa80d75e2943f224a332559847344bb62fa13b3" dependencies = [ "async-trait", "jsonrpsee", @@ -14117,9 +14251,9 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" -version = "27.0.0" +version = "28.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92c25dcb3e4aee5559c2bd9b4d105786220cad116719d7ebb39e4f359865d44" +checksum = "5768a5d3c76eebfdf94c23a3fde6c832243a043d60561e5ac1a2b475b9ad09f3" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -14145,13 +14279,13 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" -version = "17.0.0" +version = "18.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac08d23ff4da66fe6cb0300f249be010d78e5abeafef0390cae39736a374e6cd" +checksum = "511bbc2df035f5fe2556d855369a1bbb45df620360391a1f6e3fa1a1d64af79a" dependencies = [ - "ansi_term", "build-helper", "cargo_metadata", + "console", "filetime", "parity-wasm", "sp-maybe-compressed-blob", @@ -14598,6 +14732,10 @@ version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite 0.2.14", "tower-layer", "tower-service", "tracing", @@ -14678,9 +14816,9 @@ dependencies = [ [[package]] name = "tracing-gum" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f134d9dda0e872989ddf57b90ca73bcad27f1fba2cc19cfada7b76549c590b0" +checksum = "9690af7fe11d125786fa1b5ca802192f631b61a4411277865c8e0581c887e286" dependencies = [ "coarsetime", "polkadot-primitives", @@ -14831,9 +14969,9 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "try-runtime-cli" -version = "0.38.0" +version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb82b8de45dabaaba00c8c7394f18c6f97dd0e27954d4de08b352a24886d8407" +checksum = "9454e1af0a0be675f837d63080ef8f43510c05df8c059570622386a0cf40b548" dependencies = [ "async-trait", "clap", @@ -15160,9 +15298,9 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-instrument" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa1dafb3e60065305741e83db35c6c2584bb3725b692b5b66148a38d72ace6cd" +checksum = "2a47ecb37b9734d1085eaa5ae1a81e60801fd8c28d4cabdd8aedb982021918bc" dependencies = [ "parity-wasm", ] @@ -15496,17 +15634,11 @@ dependencies = [ "webpki", ] -[[package]] -name = "webpki-roots" -version = "0.25.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" - [[package]] name = "westend-runtime" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "390ccc949904980061c181f0a1507ceb793f3b57f8f930ef60222839e08cb2ca" +checksum = "db2a5cebb4c678a0d1291bb21f9d44ddebceae044b0fb5200fa3bed108a31595" dependencies = [ "binary-merkle-tree", "bitvec", @@ -15611,9 +15743,9 @@ dependencies = [ [[package]] name = "westend-runtime-constants" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c410b8a17b87e5228f9c27ba4a8020e7ece4a8afb0f452b989834623afe84a2" +checksum = "3b080c193714605ce1033311d85035247adca170181cd68a3ad7e3ca87755a14" dependencies = [ "frame-support", "polkadot-primitives", @@ -15996,11 +16128,46 @@ dependencies = [ "time", ] +[[package]] +name = "xcm-emulator" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b49681988880dd6d08a4d5f6b7cb612a0f12172270349655c1e2f870b3526fd" +dependencies = [ + "cumulus-pallet-parachain-system", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-parachain-inherent", + "cumulus-test-relay-sproof-builder", + "frame-support", + "frame-system", + "impl-trait-for-tuples", + "lazy_static", + "log", + "pallet-balances", + "pallet-message-queue", + "parachains-common", + "parity-scale-codec", + "paste", + "polkadot-parachain-primitives", + "polkadot-primitives", + "polkadot-runtime-parachains", + "sp-arithmetic", + "sp-core", + "sp-crypto-hashing", + "sp-io", + "sp-runtime", + "sp-std", + "sp-tracing", + "staging-xcm", + "staging-xcm-executor", +] + [[package]] name = "xcm-procedural" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7998facd751c42ec9b11a4cf71fcdb41fb147c5c8db8bcd1281fe84f8760d515" +checksum = "f4717a97970a9cda70d7db53cf50d2615c2f6f6b7c857445325b4a39ea7aa2cd" dependencies = [ "Inflector", "proc-macro2", @@ -16010,9 +16177,9 @@ dependencies = [ [[package]] name = "xcm-simulator" -version = "7.0.0" +version = "8.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "958836c9a2dc17a9b3a8b23fab47903a7dbc934f8d447386813c813139dbba8a" +checksum = "c65d85900081973f0c2cf0aad76e61f2d2560ea57ee2c7c886a68a0e4cf81c8a" dependencies = [ "frame-support", "parity-scale-codec", @@ -16053,7 +16220,7 @@ dependencies = [ [[package]] name = "zenlink-protocol" version = "0.4.4" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "cumulus-primitives-core", "frame-benchmarking", @@ -16075,7 +16242,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-rpc" version = "0.4.4" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -16091,7 +16258,7 @@ dependencies = [ [[package]] name = "zenlink-protocol-runtime-api" version = "0.4.4" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "parity-scale-codec", "sp-api", @@ -16102,7 +16269,7 @@ dependencies = [ [[package]] name = "zenlink-stable-amm" version = "0.1.0" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "frame-support", "frame-system", @@ -16119,7 +16286,7 @@ dependencies = [ [[package]] name = "zenlink-stable-amm-rpc" version = "0.1.0" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -16133,7 +16300,7 @@ dependencies = [ [[package]] name = "zenlink-stable-amm-runtime-api" version = "0.1.0" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "parity-scale-codec", "sp-api", @@ -16144,7 +16311,7 @@ dependencies = [ [[package]] name = "zenlink-swap-router" version = "0.1.0" -source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.6.0#ab51f2d277ac58364db1cd3ec7b1dfc4218d48bc" +source = "git+https://github.com/bifrost-finance/Zenlink-DEX-Module?branch=release-polkadot-v1.7.0#c9528ec121fe1c19dd6a790d7ad24abad7fd95fa" dependencies = [ "frame-support", "frame-system", diff --git a/Cargo.toml b/Cargo.toml index 8884bcc67..ba572d23c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "node/service", "primitives", "pallets/asset-registry", + "pallets/buy-back", "pallets/currencies", "pallets/flexible-fee", "pallets/farming", @@ -35,6 +36,8 @@ members = [ "runtime/bifrost-kusama", "runtime/bifrost-polkadot", + + "integration-tests" ] resolver = "2" @@ -49,6 +52,7 @@ bifrost-salp-rpc = { path = "pallets/salp/rpc" } bifrost-stable-pool-rpc = { path = "pallets/stable-pool/rpc" } bifrost-ve-minting-rpc = { path = "pallets/ve-minting/rpc" } lend-market-rpc = { path = "pallets/lend-market/rpc" } +bifrost-vtoken-minting-rpc = { path = "pallets/vtoken-minting/rpc" } # Bifrost Runtime bifrost-kusama-runtime = { path = "runtime/bifrost-kusama" } @@ -56,6 +60,7 @@ bifrost-polkadot-runtime = { path = "runtime/bifrost-polkadot" } # Bifrost Wasm bifrost-asset-registry = { path = "pallets/asset-registry", default-features = false } +bifrost-buy-back = { path = "pallets/buy-back", default-features = false } bifrost-call-switchgear = { path = "pallets/call-switchgear", default-features = false } bifrost-cross-in-out = { path = "pallets/cross-in-out", default-features = false } bifrost-currencies = { path = "pallets/currencies", default-features = false } @@ -93,183 +98,183 @@ pallet-traits = { path = "pallets/traits", default-featur leverage-staking = { path = "pallets/leverage-staking", default-features = false } bifrost-channel-commission = { path = "pallets/channel-commission", default-features = false } bifrost-clouds-convert = { path = "pallets/clouds-convert", default-features = false } +bifrost-vtoken-minting-rpc-runtime-api = { path = "pallets/vtoken-minting/rpc/runtime-api", default-features = false } # Zenlink -merkle-distributor = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } -zenlink-protocol = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } -zenlink-protocol-rpc = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0" } -zenlink-protocol-runtime-api = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } -zenlink-stable-amm = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } -zenlink-stable-amm-rpc = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0" } -zenlink-stable-amm-runtime-api = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } -zenlink-swap-router = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.6.0", default-features = false } +merkle-distributor = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } +zenlink-protocol = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } +zenlink-protocol-rpc = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0" } +zenlink-protocol-runtime-api = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } +zenlink-stable-amm = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } +zenlink-stable-amm-rpc = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0" } +zenlink-stable-amm-runtime-api = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } +zenlink-swap-router = { git = "https://github.com/bifrost-finance/Zenlink-DEX-Module", branch = "release-polkadot-v1.7.0", default-features = false } # Orml -orml-tokens = { version = "0.7.0", default-features = false } -orml-traits = { version = "0.7.0", default-features = false } -orml-unknown-tokens = { version = "0.7.0", default-features = false } -orml-utilities = { version = "0.7.0", default-features = false } -orml-xcm = { version = "0.7.0", default-features = false } -orml-xcm-support = { version = "0.7.0", default-features = false } -orml-xtokens = { version = "0.7.0", default-features = false } -orml-oracle = { version = "0.7.0", default-features = false } +orml-tokens = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-traits = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-unknown-tokens = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-utilities = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-xcm = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-xcm-support = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-xtokens = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } +orml-oracle = { git = "https://github.com/bifrost-finance/open-runtime-module-library", branch = "release-polkadot-v1.7.0", default-features = false } # polkadot-sdk (wasm) -cumulus-client-collator = { version = "0.7.0", default-features = false } -cumulus-client-consensus-proposer = { version = "0.7.0", default-features = false } -cumulus-pallet-aura-ext = { version = "0.7.0", default-features = false } -cumulus-pallet-dmp-queue = { version = "0.7.0", default-features = false } -cumulus-pallet-parachain-system = { version = "0.7.0", default-features = false, features = ["parameterized-consensus-hook"] } -cumulus-pallet-xcm = { version = "0.7.0", default-features = false } -cumulus-pallet-xcmp-queue = { version = "0.7.0", default-features = false } -cumulus-primitives-core = { version = "0.7.0", default-features = false } -cumulus-primitives-parachain-inherent = { version = "0.7.0", default-features = false } -cumulus-primitives-timestamp = { version = "0.7.0", default-features = false } -cumulus-primitives-utility = { version = "0.7.3", default-features = false } -cumulus-test-relay-sproof-builder = { version = "0.7.0", default-features = false } -frame-benchmarking = { version = "28.0.0", default-features = false } -frame-executive = { version = "28.0.0", default-features = false } -frame-support = { version = "28.0.0", default-features = false } -frame-system = { version = "28.0.0", default-features = false } -frame-system-benchmarking = { version = "28.0.0", default-features = false } -frame-system-rpc-runtime-api = { version = "26.0.0", default-features = false } -frame-try-runtime = { version = "0.34.0", default-features = false } -pallet-assets = { version = "29.0.0", default-features = false } -pallet-asset-rate = { version = "7.0.0", default-features = false } -pallet-aura = { version = "27.0.0", default-features = false } -pallet-authority-discovery = { version = "28.0.0", default-features = false } -pallet-authorship = { version = "28.0.0", default-features = false } -pallet-balances = { version = "28.0.0", default-features = false } -pallet-bounties = { version = "27.0.0", default-features = false } -pallet-collator-selection = { version = "9.0.0", default-features = false } -pallet-collective = { version = "28.0.0", default-features = false } -pallet-conviction-voting = { version = "28.0.0", default-features = false } -pallet-democracy = { version = "28.0.0", default-features = false } -pallet-elections-phragmen = { version = "29.0.0", default-features = false } -pallet-identity = { version = "28.0.0", default-features = false } -pallet-im-online = { version = "27.0.0", default-features = false } -pallet-indices = { version = "28.0.0", default-features = false } -pallet-membership = { version = "28.0.0", default-features = false } -pallet-message-queue = { version = "31.0.0", default-features = false } -pallet-multisig = { version = "28.0.0", default-features = false } -pallet-preimage = { version = "28.0.0", default-features = false } -pallet-proxy = { version = "28.0.0", default-features = false } -pallet-ranked-collective = { version = "28.0.0", default-features = false } -pallet-recovery = { version = "28.0.0", default-features = false } -pallet-referenda = { version = "28.0.0", default-features = false } -pallet-scheduler = { version = "29.0.0", default-features = false } -pallet-session = { version = "28.0.0", default-features = false } -pallet-staking = { version = "28.0.0", default-features = false } -pallet-sudo = { version = "28.0.0", default-features = false } -pallet-timestamp = { version = "27.0.0", default-features = false } -pallet-tips = { version = "27.0.0", default-features = false } -pallet-transaction-payment = { version = "28.0.0", default-features = false } -pallet-transaction-payment-rpc-runtime-api = { version = "28.0.0", default-features = false } -pallet-treasury = { version = "27.0.0", default-features = false } -pallet-utility = { version = "28.0.0", default-features = false } -pallet-whitelist = { version = "27.0.0", default-features = false } -pallet-xcm = { version = "7.0.0", default-features = false } -parachains-common = { version = "7.0.0", default-features = false } -parachain-info = { version = "0.7.0", package = "staging-parachain-info", default-features = false } -polkadot-core-primitives = { version = "7.0.0", default-features = false } -polkadot-parachain-primitives = { version = "6.0.0", default-features = false } -polkadot-primitives = { version = "7.0.0", default-features = false } -polkadot-runtime-common = { version = "7.0.0", default-features = false } -polkadot-runtime-parachains = { version = "7.0.0", default-features = false } -sp-api = { version = "26.0.0", default-features = false } -sp-application-crypto = { version = "30.0.0", default-features = false } -sp-arithmetic = { version = "23.0.0", default-features = false } -sp-authority-discovery = { version = "26.0.0", default-features = false } -sp-block-builder = { version = "26.0.0", default-features = false } -sp-blockchain = { version = "28.0.0", default-features = false } -sp-consensus = { version = "0.32.0", default-features = false } -sp-consensus-aura = { version = "0.32.0", default-features = false } -sp-consensus-slots = { version = "0.32.0", default-features = false } -sp-core = { version = "28.0.0", default-features = false } +cumulus-client-collator = { version = "0.8.0", default-features = false } +cumulus-client-consensus-proposer = { version = "0.8.0", default-features = false } +cumulus-pallet-aura-ext = { version = "0.8.0", default-features = false } +cumulus-pallet-parachain-system = { version = "0.8.0", default-features = false, features = ["parameterized-consensus-hook"] } +cumulus-pallet-xcm = { version = "0.8.0", default-features = false } +cumulus-pallet-xcmp-queue = { version = "0.8.0", default-features = false } +cumulus-primitives-core = { version = "0.8.0", default-features = false } +cumulus-primitives-parachain-inherent = { version = "0.8.0", default-features = false } +cumulus-primitives-timestamp = { version = "0.8.0", default-features = false } +cumulus-primitives-utility = { version = "0.8.0", default-features = false } +cumulus-test-relay-sproof-builder = { version = "0.8.0", default-features = false } +frame-benchmarking = { version = "29.0.0", default-features = false } +frame-executive = { version = "29.0.0", default-features = false } +frame-support = { version = "29.0.0", default-features = false } +frame-system = { version = "29.0.0", default-features = false } +frame-system-benchmarking = { version = "29.0.0", default-features = false } +frame-system-rpc-runtime-api = { version = "27.0.0", default-features = false } +frame-try-runtime = { version = "0.35.0", default-features = false } +pallet-assets = { version = "30.0.0", default-features = false } +pallet-asset-rate = { version = "8.0.0", default-features = false } +pallet-aura = { version = "28.0.0", default-features = false } +pallet-authority-discovery = { version = "29.0.0", default-features = false } +pallet-authorship = { version = "29.0.0", default-features = false } +pallet-balances = { version = "29.0.0", default-features = false } +pallet-bounties = { version = "28.0.0", default-features = false } +pallet-collator-selection = { version = "10.0.0", default-features = false } +pallet-collective = { version = "29.0.0", default-features = false } +pallet-conviction-voting = { version = "29.0.0", default-features = false } +pallet-democracy = { version = "29.0.0", default-features = false } +pallet-elections-phragmen = { version = "30.0.0", default-features = false } +pallet-identity = { version = "29.0.0", default-features = false } +pallet-im-online = { version = "28.0.0", default-features = false } +pallet-indices = { version = "29.0.0", default-features = false } +pallet-membership = { version = "29.0.0", default-features = false } +pallet-message-queue = { version = "32.0.0", default-features = false } +pallet-multisig = { version = "29.0.0", default-features = false } +pallet-preimage = { version = "29.0.0", default-features = false } +pallet-proxy = { version = "29.0.0", default-features = false } +pallet-ranked-collective = { version = "29.0.0", default-features = false } +pallet-recovery = { version = "29.0.0", default-features = false } +pallet-referenda = { version = "29.0.0", default-features = false } +pallet-scheduler = { version = "30.0.0", default-features = false } +pallet-session = { version = "29.0.0", default-features = false } +pallet-staking = { version = "29.0.0", default-features = false } +pallet-sudo = { version = "29.0.0", default-features = false } +pallet-timestamp = { version = "28.0.0", default-features = false } +pallet-tips = { version = "28.0.0", default-features = false } +pallet-transaction-payment = { version = "29.0.0", default-features = false } +pallet-transaction-payment-rpc-runtime-api = { version = "29.0.0", default-features = false } +pallet-treasury = { version = "28.0.0", default-features = false } +pallet-utility = { version = "29.0.0", default-features = false } +pallet-whitelist = { version = "28.0.0", default-features = false } +pallet-xcm = { version = "8.0.0", default-features = false } +parachains-common = { version = "8.0.0", default-features = false } +parachain-info = { version = "0.8.0", package = "staging-parachain-info", default-features = false } +polkadot-core-primitives = { version = "8.0.0", default-features = false } +polkadot-parachain-primitives = { version = "7.0.0", default-features = false } +polkadot-primitives = { version = "8.0.0", default-features = false } +polkadot-runtime-common = { version = "8.0.0", default-features = false } +polkadot-runtime-parachains = { version = "8.0.0", default-features = false } +sp-api = { version = "27.0.0", default-features = false } +sp-application-crypto = { version = "31.0.0", default-features = false } +sp-arithmetic = { version = "24.0.0", default-features = false } +sp-authority-discovery = { version = "27.0.0", default-features = false } +sp-block-builder = { version = "27.0.0", default-features = false } +sp-blockchain = { version = "29.0.0", default-features = false } +sp-consensus = { version = "0.33.0", default-features = false } +sp-consensus-aura = { version = "0.33.0", default-features = false } +sp-consensus-slots = { version = "0.33.0", default-features = false } +sp-core = { version = "29.0.0", default-features = false } sp-debug-derive = { version = "14.0.0", default-features = false } -sp-externalities = { version = "0.25.0", default-features = false } -sp-genesis-builder = { version = "0.7.0", default-features = false } -sp-inherents = { version = "26.0.0", default-features = false } -sp-io = { version = "30.0.0", default-features = false } -sp-keyring = { version = "31.0.0", default-features = false } -sp-keystore = { version = "0.34.0", default-features = false } +sp-externalities = { version = "0.26.0", default-features = false } +sp-genesis-builder = { version = "0.8.0", default-features = false } +sp-inherents = { version = "27.0.0", default-features = false } +sp-io = { version = "31.0.0", default-features = false } +sp-keyring = { version = "32.0.0", default-features = false } +sp-keystore = { version = "0.35.0", default-features = false } sp-maybe-compressed-blob = { version = "11.0.0", default-features = false } -sp-npos-elections = { version = "26.0.0", default-features = false } -sp-offchain = { version = "26.0.0", default-features = false } -sp-runtime = { version = "31.0.0", default-features = false } -sp-runtime-interface = { version = "24.0.0", default-features = false } -sp-session = { version = "27.0.0", default-features = false } -sp-staking = { version = "26.0.0", default-features = false } -sp-state-machine = { version = "0.35.0", default-features = false } +sp-npos-elections = { version = "27.0.0", default-features = false } +sp-offchain = { version = "27.0.0", default-features = false } +sp-runtime = { version = "32.0.0", default-features = false } +sp-runtime-interface = { version = "25.0.0", default-features = false } +sp-session = { version = "28.0.0", default-features = false } +sp-staking = { version = "27.0.0", default-features = false } +sp-state-machine = { version = "0.36.0", default-features = false } sp-std = { version = "14.0.0", default-features = false } -sp-storage = { version = "19.0.0", default-features = false } -sp-timestamp = { version = "26.0.0", default-features = false } +sp-storage = { version = "20.0.0", default-features = false } +sp-timestamp = { version = "27.0.0", default-features = false } sp-tracing = { version = "16.0.0", default-features = false } -sp-transaction-pool = { version = "26.0.0", default-features = false } -sp-trie = { version = "29.0.0", default-features = false } -sp-version = { version = "29.0.0", default-features = false } +sp-transaction-pool = { version = "27.0.0", default-features = false } +sp-trie = { version = "30.0.0", default-features = false } +sp-version = { version = "30.0.0", default-features = false } sp-wasm-interface = { version = "20.0.0", default-features = false } -sp-weights = { version = "27.0.0", default-features = false } +sp-weights = { version = "28.0.0", default-features = false } substrate-fixed = { git = "https://github.com/encointer/substrate-fixed", default-features = false } -xcm = { version = "7.0.0", package = "staging-xcm", default-features = false } -xcm-builder = { version = "7.0.3", package = "staging-xcm-builder", default-features = false } -xcm-executor = { version = "7.0.3", package = "staging-xcm-executor", default-features = false } +xcm = { version = "8.0.0", package = "staging-xcm", default-features = false } +xcm-builder = { version = "8.0.0", package = "staging-xcm-builder", default-features = false } +xcm-executor = { version = "8.0.1", package = "staging-xcm-executor", default-features = false } # polkadot-sdk (client) -cumulus-client-cli = { version = "0.7.0" } -cumulus-client-consensus-aura = { version = "0.7.0" } -cumulus-client-consensus-common = { version = "0.7.0" } -cumulus-client-consensus-relay-chain = { version = "0.7.0" } -cumulus-client-network = { version = "0.7.0" } -cumulus-client-pov-recovery = { version = "0.7.0" } -cumulus-client-service = { version = "0.7.0" } -cumulus-relay-chain-inprocess-interface = { version = "0.7.0" } -cumulus-relay-chain-interface = { version = "0.7.0" } -cumulus-relay-chain-minimal-node = { version = "0.7.0" } -cumulus-relay-chain-rpc-interface = { version = "0.7.0" } -frame-benchmarking-cli = { version = "32.0.0" } -node-inspect = { version = "0.12.0", package = "staging-node-inspect" } -pallet-transaction-payment-rpc = { version = "30.0.0" } -polkadot-cli = { version = "7.0.0" } -polkadot-service = { version = "7.0.0" } -sc-basic-authorship = { version = "0.34.0" } -sc-chain-spec = { version = "27.0.0" } -sc-cli = { version = "0.36.0" } -sc-client-api = { version = "28.0.0" } -sc-consensus = { version = "0.33.0" } -sc-consensus-aura = { version = "0.34.0" } -sc-consensus-grandpa = { version = "0.19.0" } -sc-consensus-manual-seal = { version = "0.35.0" } -sc-consensus-slots = { version = "0.33.0" } -sc-executor = { version = "0.32.0" } -sc-keystore = { version = "25.0.0" } -sc-network = { version = "0.34.0" } -sc-network-common = { version = "0.33.0" } -sc-network-sync = { version = "0.33.0" } -sc-offchain = { version = "29.0.0" } -sc-rpc = { version = "29.0.0" } -sc-rpc-api = { version = "0.33.0" } -sc-rpc-server = { version = "11.0.0" } -sc-service = { version = "0.35.0" } -sc-sysinfo = { version = "27.0.0" } -sc-telemetry = { version = "15.0.0" } -sc-tracing = { version = "28.0.0" } -sc-transaction-pool = { version = "28.0.0" } -sc-transaction-pool-api = { version = "28.0.0" } -sp-consensus-babe = { version = "0.32.0" } -sp-rpc = { version = "26.0.0" } +cumulus-client-cli = { version = "0.8.0" } +cumulus-client-consensus-aura = { version = "0.8.0" } +cumulus-client-consensus-common = { version = "0.8.0" } +cumulus-client-consensus-relay-chain = { version = "0.8.0" } +cumulus-client-network = { version = "0.8.0" } +cumulus-client-pov-recovery = { version = "0.8.0" } +cumulus-client-service = { version = "0.8.0" } +cumulus-relay-chain-inprocess-interface = { version = "0.8.0" } +cumulus-relay-chain-interface = { version = "0.8.0" } +cumulus-relay-chain-minimal-node = { version = "0.8.0" } +cumulus-relay-chain-rpc-interface = { version = "0.8.0" } +frame-benchmarking-cli = { version = "33.0.0" } +node-inspect = { version = "0.13.0", package = "staging-node-inspect" } +pallet-transaction-payment-rpc = { version = "31.0.0" } +polkadot-cli = { version = "8.0.0" } +polkadot-service = { version = "8.0.0" } +sc-basic-authorship = { version = "0.35.0" } +sc-chain-spec = { version = "28.0.0" } +sc-cli = { version = "0.37.0" } +sc-client-api = { version = "29.0.0" } +sc-consensus = { version = "0.34.0" } +sc-consensus-aura = { version = "0.35.0" } +sc-consensus-grandpa = { version = "0.20.0" } +sc-consensus-manual-seal = { version = "0.36.0" } +sc-consensus-slots = { version = "0.34.0" } +sc-executor = { version = "0.33.0" } +sc-keystore = { version = "26.0.0" } +sc-network = { version = "0.35.0" } +sc-network-common = { version = "0.34.0" } +sc-network-sync = { version = "0.34.0" } +sc-offchain = { version = "30.0.0" } +sc-rpc = { version = "30.0.0" } +sc-rpc-api = { version = "0.34.0" } +sc-rpc-server = { version = "12.0.0" } +sc-service = { version = "0.36.0" } +sc-sysinfo = { version = "28.0.0" } +sc-telemetry = { version = "16.0.0" } +sc-tracing = { version = "29.0.0" } +sc-transaction-pool = { version = "29.0.0" } +sc-transaction-pool-api = { version = "29.0.0" } +sp-consensus-babe = { version = "0.33.0" } +sp-rpc = { version = "27.0.0" } substrate-build-script-utils = { version = "11.0.0" } -substrate-frame-rpc-system = { version = "28.0.0" } +substrate-frame-rpc-system = { version = "29.0.0" } substrate-prometheus-endpoint = { version = "0.17.0" } -substrate-wasm-builder = { version = "17.0.0" } -try-runtime-cli = { version = "0.38.0" } -xcm-emulator = { version = "0.5.0" } -xcm-simulator = { version = "7.0.0" } +substrate-wasm-builder = { version = "18.0.0" } +try-runtime-cli = { version = "0.39.0" } +xcm-emulator = { version = "0.6.0" } +xcm-simulator = { version = "8.0.0" } # Other async-trait = { version = "0.1.76" } bstringify = { version = "0.1.2" } -clap = { version = "=4.4.14" } +clap = { version = "4.4.14" } env_logger = { version = "0.10.2" } ethabi = { version = "18.0.0", default-features = false } ethereum = { version = "0.14.0", default-features = false, features = ["with-codec"] } @@ -277,7 +282,7 @@ futures = { version = "0.3.30" } hex = { version = "0.4.3", default-features = false } hex-literal = { version = "0.4.1" } impl-trait-for-tuples = { version = "0.2.2" } -jsonrpsee = { version = "0.16.3" } +jsonrpsee = { version = "0.20.3" } log = { version = "0.4.21", default-features = false } num-bigint = { version = "0.4.3", default-features = false } num-traits = { version = "0.2.18", default-features = false } diff --git a/Makefile b/Makefile index e6bac077a..f85585344 100644 --- a/Makefile +++ b/Makefile @@ -51,10 +51,14 @@ copy-genesis-config-release: .PHONY: format # cargo fmt format: + cargo +nightly fmt --all + +.PHONY: format-check # cargo fmt check +format-check: cargo +nightly fmt --all -- --check .PHONY: clippy # cargo clippy -clippy: +clippy: format-check SKIP_WASM_BUILD= cargo clippy --all --all-targets --features=with-all-runtime -- -D warnings .PHONY: benchmarking-staking # benchmarking staking pallet diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml new file mode 100644 index 000000000..4f1942630 --- /dev/null +++ b/integration-tests/Cargo.toml @@ -0,0 +1,50 @@ +[package] +name = "bifrost-integration-tests" +version = "0.8.0" +authors = ["hqwangningbo <2536935847@qq.com>"] +edition = "2021" + +[dev-dependencies] +bifrost-asset-registry = { workspace = true } +bifrost-currencies = { workspace = true } +bifrost-polkadot-runtime = { workspace = true } +bifrost-primitives = { workspace = true } +bifrost-runtime-common = { workspace = true } +bifrost-slp = { workspace = true } +bifrost-vtoken-voting = { workspace = true } +bifrost-xcm-interface = { workspace = true } +cumulus-primitives-core = { workspace = true } +env_logger = { workspace = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +hex-literal = { workspace = true } +log = { workspace = true } +orml-tokens = { workspace = true } +orml-traits = { workspace = true } +orml-xtokens = { workspace = true } +pallet-assets = { workspace = true } +pallet-balances = { workspace = true } +pallet-conviction-voting = { workspace = true } +pallet-message-queue = { workspace = true } +pallet-referenda = { workspace = true } +pallet-staking = { workspace = true } +pallet-xcm = { workspace = true } +parachain-info = { workspace = true } +parachains-common = { workspace = true } +parity-scale-codec = { workspace = true } +polkadot-core-primitives = { workspace = true } +polkadot-parachain-primitives = { workspace = true, features = ["std"] } +polkadot-runtime-common = { workspace = true, features = ["std"] } +polkadot-runtime-parachains = { workspace = true, features = ["std"] } +scale-info = { workspace = true } +serde = { workspace = true } +sp-core = { workspace = true } +sp-io = { workspace = true } +sp-runtime = { workspace = true } +sp-staking = { workspace = true } +sp-std = { workspace = true } +xcm = { workspace = true } +xcm-builder = { workspace = true } +xcm-emulator = { workspace = true } +xcm-executor = { workspace = true } +xcm-simulator = { workspace = true } diff --git a/integration-tests/bifrost-kusama/Cargo.toml b/integration-tests/bifrost-kusama/Cargo.toml deleted file mode 100644 index 0957a8cb8..000000000 --- a/integration-tests/bifrost-kusama/Cargo.toml +++ /dev/null @@ -1,45 +0,0 @@ -[package] -name = "bifrost-kusama-integration-tests" -version = "0.8.0" -authors = ["Ron Yang "] -edition = "2021" - -[dependencies] -env_logger = { workspace = true } -log = { workspace = true } -hex-literal = { workspace = true } -parity-scale-codec = { workspace = true } - -# Substrate -sp-runtime = { workspace = true } -sp-io = { workspace = true } -sp-staking = { workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -pallet-balances = { workspace = true } -pallet-assets = { workspace = true } -pallet-conviction-voting = { workspace = true } -pallet-referenda = { workspace = true } -pallet-staking = { workspace = true } - -# Polkadot -polkadot-parachain-primitives = { workspace = true } -kusama-runtime = { workspace = true } -xcm = { workspace = true } -pallet-xcm = { workspace = true } -pallet-message-queue = { workspace = true } - -# Cumulus -parachains-common = { workspace = true } -xcm-emulator = { workspace = true } - -# Local -integration-tests-common = { path = "../common", default-features = false } -bifrost-slp = { workspace = true } -bifrost-vtoken-voting = { workspace = true } -bifrost-primitives = { workspace = true } -bifrost-asset-registry = { workspace = true } -bifrost-kusama-runtime = { workspace = true } -bifrost-runtime-common = { workspace = true } -orml-traits = { workspace = true } -orml-tokens = { workspace = true } diff --git a/integration-tests/bifrost-kusama/src/account_id.rs b/integration-tests/bifrost-kusama/src/account_id.rs deleted file mode 100644 index 71785f649..000000000 --- a/integration-tests/bifrost-kusama/src/account_id.rs +++ /dev/null @@ -1,185 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use frame_support::PalletId; -use integration_tests_common::{ - impls::{AccountId, ParaId}, - BifrostKusama, -}; -use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::{app_crypto::Ss58Codec, traits::AccountIdConversion}; -use xcm_emulator::TestExt; - -pub const TREASURY_PALLET_ID: PalletId = PalletId(*b"bf/trsry"); -pub const BIFROST_CROWDLOAN_ID: PalletId = PalletId(*b"bf/salp#"); -pub const BIFROST_SALP_LITE_CROWDLOAN_ID: PalletId = PalletId(*b"bf/salpl"); -pub const LIQUIDITY_MINING_PALLET_ID: PalletId = PalletId(*b"bf/lm###"); -pub const LIQUIDITY_MINING_DOTPALLET_ID: PalletId = PalletId(*b"bf/lmdot"); -pub const LIGHTENING_REDEEM_PALLET_ID: PalletId = PalletId(*b"bf/ltnrd"); -pub const MERKLE_DIRTRIBUTOR_PALLET_ID: PalletId = PalletId(*b"bf/mklds"); -pub const VSBOND_AUCTION_PALLET_ID: PalletId = PalletId(*b"bf/vsbnd"); -pub const PARACHAIN_STAKING_PALLET_ID: PalletId = PalletId(*b"bf/stake"); -pub const BIFROST_VSBOND_PALLET_ID: PalletId = PalletId(*b"bf/salpb"); -pub const SLP_ENTRANCE_PALLET_ID: PalletId = PalletId(*b"bf/vtkin"); -pub const SLP_EXIT_PALLET_ID: PalletId = PalletId(*b"bf/vtout"); -pub const STABLE_AMM_PALLET_ID: PalletId = PalletId(*b"bf/stamm"); -pub const FARMING_KEEPER_PALLET_ID: PalletId = PalletId(*b"bf/fmkpr"); -pub const FARMING_REWARD_ISSUER_PALLET_ID: PalletId = PalletId(*b"bf/fmrir"); -pub const SYSTEM_STAKING_PALLET_ID: PalletId = PalletId(*b"bf/sysst"); -pub const BUYBACK_PALLET_ID: PalletId = PalletId(*b"bf/salpc"); -pub const SYSTEM_MAKER_PALLET_ID: PalletId = PalletId(*b"bf/sysmk"); - -#[test] -fn parachain_account_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!( - >::into_account_truncating(&ParaId::from( - 2001 - )), - AccountId::from_ss58check("F7fq1jMmNj5j2jAHcBxgM26JzUn2N4duXu1U4UZNdkfZEPV").unwrap() - ); - assert_eq!( - >::into_account_truncating(&ParaId::from( - 2030 - )), - AccountId::from_ss58check("eGJryu57ZpFQjFRiya9nGcqiGG2RZeGWuXMENq4Na7jFNjs").unwrap() - ); - assert_eq!( - >::into_account_truncating(&Sibling::from( - 2034 - )), - AccountId::from_ss58check("eLHN5PtznDscogoZVS9feWwMGaziRRryQ451m1ocUHB1cMe").unwrap() - ); - }) -} - -#[test] -fn pallet_id_account_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!( - >::into_account_truncating( - &TREASURY_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNYdM3UjBNxcBNBqGxtz3SEEfydKragtL4pJ4F").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &BIFROST_CROWDLOAN_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQGSkjt2tjezJRdzUJNGgdgAihwxKQsa4LdPN").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &BIFROST_SALP_LITE_CROWDLOAN_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQGSkmPV2DLuQyBiG1dA5eMWAvRFGkQjZ7YDU").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &LIQUIDITY_MINING_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGMTkdAd9Z5P96SQ4UheKhx4pWNg5Pu734mRHbm").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &LIQUIDITY_MINING_DOTPALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGMTm5SYswh7EECLDTdu9gFbjt2HALzH1gazWUG").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &LIGHTENING_REDEEM_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGMTyaXsM7F3G8oR4bAgy6qU27xfobQkzN5CH3h").unwrap() - ); - // - assert_eq!( - >::into_account_truncating( - &MERKLE_DIRTRIBUTOR_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGMbYEwSupkwsPfjzzSGSf9MWxCHf1mEUyUyc4Y").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &VSBOND_AUCTION_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNpLKqNkBEJLLkTkSzHt41QDhqiECF5shU8Qsp").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &PARACHAIN_STAKING_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQr7VZ48fkCX5vkt1H16F8Np9g2hYssRXHZJF").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &BIFROST_VSBOND_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQGSkmBWD7AfnKVcXzjriDdZs2ezEjKfsR4h5").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &SLP_ENTRANCE_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNpNATVMhrmGeJj8drJWWGXrHtVo4Vym2cUnSz").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &SLP_EXIT_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNpNC5wLwUw92XQSHZ9tyrU5SYVDmRyodCrdAR").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &STABLE_AMM_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQr7Vjo4uHNjwii1g4zfTHyWC5iBMrQj7R4P2").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &FARMING_KEEPER_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGLejANY2XNJzg7B8cB4mBx8Rbw4tXHpY6GK5YE").unwrap() - ); - // - assert_eq!( - >::into_account_truncating( - &FARMING_REWARD_ISSUER_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGLejDBGEgnWnj8mNePufttUVCjF3snTttG6SDZ").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &SYSTEM_STAKING_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNR17nzbZNJxo7G9mYziLiJcujnWXCNB2CUakX").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &BUYBACK_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNQGSkmChh1z6Lz4d7CRneZWAJ22p98daSPJsF").unwrap() - ); - assert_eq!( - >::into_account_truncating( - &SYSTEM_MAKER_PALLET_ID - ), - AccountId::from_ss58check("eCSrvbA5gGNR17nSgitMhUyrqX8e4a8wuk5Q7UKUBhxdi5S").unwrap() - ); - }) -} diff --git a/integration-tests/bifrost-kusama/src/dollor_tests.rs b/integration-tests/bifrost-kusama/src/dollor_tests.rs deleted file mode 100644 index 9ba5c8ed9..000000000 --- a/integration-tests/bifrost-kusama/src/dollor_tests.rs +++ /dev/null @@ -1,129 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use bifrost_kusama_runtime::Runtime; -use bifrost_primitives::{CurrencyId, TokenSymbol::*}; -use bifrost_runtime_common::{cent, dollar, micro, microcent, milli, millicent}; -use integration_tests_common::BifrostKusama; -use xcm_emulator::TestExt; - -const DECIMAL_18: u128 = 1_000_000_000_000_000_000; -const DECIMAL_12: u128 = 1_000_000_000_000; -const DOT_DECIMALS: u128 = 10_000_000_000; - -#[test] -fn dollar_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(dollar::(CurrencyId::Token(ASG)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(BNC)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(KUSD)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(DOT)), DOT_DECIMALS); - assert_eq!(dollar::(CurrencyId::Token(KSM)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(ETH)), DECIMAL_18); - assert_eq!(dollar::(CurrencyId::Token(KAR)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(ZLK)), DECIMAL_18); - assert_eq!(dollar::(CurrencyId::Token(PHA)), DECIMAL_12); - assert_eq!(dollar::(CurrencyId::Token(RMRK)), DOT_DECIMALS); - assert_eq!(dollar::(CurrencyId::Token(MOVR)), DECIMAL_18); - }); -} - -#[test] -fn milli_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(milli::(CurrencyId::Token(ASG)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(BNC)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(KUSD)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(DOT)), DOT_DECIMALS / 1000); - assert_eq!(milli::(CurrencyId::Token(KSM)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(ETH)), DECIMAL_18 / 1000); - assert_eq!(milli::(CurrencyId::Token(KAR)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(ZLK)), DECIMAL_18 / 1000); - assert_eq!(milli::(CurrencyId::Token(PHA)), DECIMAL_12 / 1000); - assert_eq!(milli::(CurrencyId::Token(RMRK)), DOT_DECIMALS / 1000); - assert_eq!(milli::(CurrencyId::Token(MOVR)), DECIMAL_18 / 1000); - }); -} - -#[test] -fn micro_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(micro::(CurrencyId::Token(ASG)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(BNC)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(KUSD)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(DOT)), DOT_DECIMALS / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(KSM)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(ETH)), DECIMAL_18 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(KAR)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(ZLK)), DECIMAL_18 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(PHA)), DECIMAL_12 / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(RMRK)), DOT_DECIMALS / 1_000_000); - assert_eq!(micro::(CurrencyId::Token(MOVR)), DECIMAL_18 / 1_000_000); - }); -} - -#[test] -fn cent_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(cent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(DOT)), DOT_DECIMALS / 100); - assert_eq!(cent::(CurrencyId::Token(KSM)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(ETH)), DECIMAL_18 / 100); - assert_eq!(cent::(CurrencyId::Token(KAR)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(ZLK)), DECIMAL_18 / 100); - assert_eq!(cent::(CurrencyId::Token(PHA)), DECIMAL_12 / 100); - assert_eq!(cent::(CurrencyId::Token(RMRK)), DOT_DECIMALS / 100); - assert_eq!(cent::(CurrencyId::Token(MOVR)), DECIMAL_18 / 100); - }); -} - -#[test] -fn millicent_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(millicent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(DOT)), DOT_DECIMALS / 100_000); - assert_eq!(millicent::(CurrencyId::Token(KSM)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(ETH)), DECIMAL_18 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(KAR)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(ZLK)), DECIMAL_18 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(PHA)), DECIMAL_12 / 100_000); - assert_eq!(millicent::(CurrencyId::Token(RMRK)), DOT_DECIMALS / 100_000); - assert_eq!(millicent::(CurrencyId::Token(MOVR)), DECIMAL_18 / 100_000); - }); -} - -#[test] -fn microcent_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(microcent::(CurrencyId::Token(ASG)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(BNC)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(KUSD)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(DOT)), DOT_DECIMALS / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(KSM)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(ETH)), DECIMAL_18 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(KAR)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(ZLK)), DECIMAL_18 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(PHA)), DECIMAL_12 / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(RMRK)), DOT_DECIMALS / 100_000_000); - assert_eq!(microcent::(CurrencyId::Token(MOVR)), DECIMAL_18 / 100_000_000); - }); -} diff --git a/integration-tests/bifrost-kusama/src/salp.rs b/integration-tests/bifrost-kusama/src/salp.rs deleted file mode 100644 index 6124e97b8..000000000 --- a/integration-tests/bifrost-kusama/src/salp.rs +++ /dev/null @@ -1,843 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use crate::{kusama_integration_tests::*, kusama_test_net::*}; -use bifrost_asset_registry::AssetIdMaps; -use bifrost_kusama_runtime::{LeasePeriod, MinContribution, Runtime}; -use bifrost_salp::{Error, FundInfo, FundStatus}; -use frame_support::{assert_noop, assert_ok}; -use frame_system::RawOrigin; -use xcm_emulator::TestExt; - -const KSM: u128 = 1_000_000_000_000; - -#[test] -fn set_confirm_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::set_multisig_confirm_account( - RawOrigin::Root.into(), - AccountId::new(BOB) - )); - assert_eq!(Salp::multisig_confirm_account(), Some(AccountId::new(BOB)),); - }); - }) -} - -#[test] -fn create_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_eq!(AssetIdMaps::::check_token_registered(TokenSymbol::KSM), true); - assert_eq!( - AssetIdMaps::::check_vsbond_registered(TokenSymbol::KSM, 3000, 1, 8), - false - ); - // first_slot + 7 >= last_slot - assert_ok!(Salp::create( - RawOrigin::Root.into(), - //paraid - 3_000, - //cap - 100 * KSM, - //first_slot - 1, - //last_slot - SlotLength::get() - )); - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: Zero::zero(), - cap: 100 * KSM, - first_slot: 1, - last_slot: SlotLength::get(), - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - assert_eq!( - AssetIdMaps::::check_vsbond_registered(TokenSymbol::KSM, 3000, 1, 8), - true - ); - }); - }) -} - -#[test] -fn edit_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create( - RawOrigin::Root.into(), - 3_000, - 100 * KSM, - 1, - SlotLength::get() - )); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: Zero::zero(), - cap: 100 * KSM, - first_slot: 1, - last_slot: SlotLength::get(), - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - - assert_ok!(Salp::edit( - RawOrigin::Root.into(), - //paraid - 3_000, - //cap - 1000 * KSM, - //raised - 150, - //first_slot - 2, - //last_slot - SlotLength::get() + 1, - Some(FundStatus::Ongoing) - )); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 150, - cap: 1000 * KSM, - first_slot: 2, - last_slot: 9, - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - }); - }) -} - -#[test] -fn contribute_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create( - RawOrigin::Root.into(), - 3_000, - 100 * KSM, - 1, - SlotLength::get() - )); - //MinContribution 0.1 KSM - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - //7200 1 day - let (contributed, status) = Salp::contribution(0, &AccountId::from(BOB)); - assert_eq!(contributed, 0); - assert_eq!(status.is_contributing(), true); - assert_eq!(status.contributing(), 1 * KSM); - //check free balance 9 ksm, should reserve 1 ksm - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 9 * KSM - ); - - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - sp_runtime::AccountId32::from(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - - //check free balance 9 ksm - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 9 * KSM - ); - - //check free balance 9 ksm - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 9 * KSM - ); - - //check free balance 1 vsksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSToken(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 1 * KSM - ); - //check free balance 1 vsbondksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSBond(TokenSymbol::KSM, 3000, 1, 8), - &AccountId::from(BOB) - ), - 1 * KSM - ); - - let (contributed, status) = Salp::contribution(0, &sp_runtime::AccountId32::from(BOB)); - assert_eq!(contributed, 1 * KSM); - assert_eq!(status.is_contributing(), false); - assert_eq!(status.contributing(), 0); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 100 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - }); - }) -} - -#[test] -fn double_contribute_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 5 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - - assert_noop!( - Salp::contribute(RuntimeOrigin::signed(AccountId::new(BOB)), 3_000, 5 * KSM), - Error::::CapExceeded - ); - - assert_noop!( - Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - MinContribution::get() - 1 - ), - Error::::ContributionTooSmall - ); - - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 2 * KSM - )); - - let (contributed, status) = Salp::contribution(0, &sp_runtime::AccountId32::from(BOB)); - assert_eq!(contributed, 1 * KSM); - assert_eq!(status.is_contributing(), true); - assert_eq!(status.contributing(), 2 * KSM); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 5 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - }); - }) -} - -#[test] -fn fund_fail_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 5 * KSM, 1, SlotLength::get())); - // crownload is failed, so enable the withdrawal function of vsToken/vsBond - assert_ok!(Salp::fund_fail(RawOrigin::Root.into(), 3_000,)); - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 0, - cap: 5 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::Failed, - } - ); - }); - }) -} - -#[test] -fn fund_retire_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - //Failed/Retired - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::fund_retire(RawOrigin::Root.into(), 3_000)); - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 0, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::Retired, - } - ); - }); - }) -} - -#[test] -fn fund_retire_withdraw_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //Failed/Retired - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::fund_retire(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RedeemWithdrew, - } - ); - assert_eq!(Salp::redeem_pool(), 1 * KSM); - }); - }) -} - -#[test] -fn fund_fail_withdraw_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //Failed/Retired - assert_ok!(Salp::fund_fail(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RefundWithdrew, - } - ); - assert_eq!(Salp::redeem_pool(), 1 * KSM); - }); - }) -} - -#[test] -fn continue_fund_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //Failed/Retired - assert_ok!(Salp::fund_fail(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RefundWithdrew, - } - ); - assert_eq!(Salp::redeem_pool(), 1 * KSM); - - assert_ok!(Salp::continue_fund(RawOrigin::Root.into(), 3_000, 2, 9)); - assert_eq!( - Salp::failed_funds_to_refund((3_000, 1, 8)).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::FailedToContinue, - } - ); - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 2, - last_slot: 9, - trie_index: 0, - status: FundStatus::Ongoing, - } - ); - }); - }) -} - -#[test] -fn refund_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //check free balance 1 vsksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSToken(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 1 * KSM - ); - //check free balance 1 vsbondksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSBond(TokenSymbol::KSM, 3000, 1, 8), - &AccountId::from(BOB) - ), - 1 * KSM - ); - assert_ok!(Salp::fund_fail(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - //fund_fail-> withdraw -> RefundWithdrew - assert_ok!(Salp::refund( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1, - SlotLength::get(), - KSM / 2 - )); - - //check free balance 0.5 vsksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSToken(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - KSM / 2 - ); - //check free balance 0.5 vsbondksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSBond(TokenSymbol::KSM, 3000, 1, 8), - &AccountId::from(BOB) - ), - KSM / 2 - ); - //check free balance 0.5 ksm - assert_eq!(Salp::redeem_pool(), KSM / 2); - - //check funds - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM - KSM / 2, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RefundWithdrew, - } - ); - - //check free balance 9.5 ksm - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 9 * KSM + KSM / 2 - ); - }); - }) -} - -#[test] -fn redeem_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //Failed/Retired - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::fund_retire(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - - //check free balance 1 vsksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSToken(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 1 * KSM - ); - //check free balance 1 vsbondksm - assert_eq!( - Currencies::free_balance( - CurrencyId::VSBond(TokenSymbol::KSM, 3000, 1, 8), - &AccountId::from(BOB) - ), - 1 * KSM - ); - - assert_ok!(Salp::redeem(RuntimeOrigin::signed(AccountId::new(BOB)), 3_000, KSM / 2)); - - //check free balance 0.5 ksm - assert_eq!(Salp::redeem_pool(), KSM / 2); - - //check funds - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM - KSM / 2, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RedeemWithdrew, - } - ); - //check free balance 9.5 ksm - assert_eq!( - Currencies::free_balance( - CurrencyId::Token(TokenSymbol::KSM), - &AccountId::from(BOB) - ), - 9 * KSM + KSM / 2 - ); - }); - }) -} - -#[test] -fn redeem_with_speical_vsbond_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 2001, 1000_000_000_000, 13, 20)); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 2001, - 100_000_000_000 - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 2001, - true, - CONTRIBUTON_INDEX - )); - - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 2001)); - assert_ok!(Salp::unlock( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 2001 - )); - - // Mock the BlockNumber - let block_begin_redeem = (SlotLength::get() + 1) * LeasePeriod::get(); - System::set_block_number(block_begin_redeem); - - assert_ok!(Salp::fund_retire(RawOrigin::Root.into(), 2001)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 2001)); - - let vs_token = - ::CurrencyIdConversion::convert_to_vstoken( - RelayCurrencyId::get(), - ) - .unwrap(); - let vs_bond = - ::CurrencyIdConversion::convert_to_vsbond( - RelayCurrencyId::get(), - 2001, - 13, - 20, - ) - .unwrap(); - - assert_ok!(>::transfer( - vs_token, - &AccountId::new(BOB), - &AccountId::new(CATHI), - 500_000_000 - )); - assert_ok!(>::transfer( - vs_bond, - &AccountId::new(BOB), - &AccountId::new(CATHI), - 500_000_000 - )); - assert_ok!(Salp::redeem(RuntimeOrigin::signed(AccountId::new(BOB)), 2001, 500_000_000)); - assert_ok!(Salp::redeem( - RuntimeOrigin::signed(AccountId::new(CATHI)), - 2001, - 500_000_000 - )); - }); - }) -} - -#[test] -fn dissolve_refunded_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create(RawOrigin::Root.into(), 3_000, 10 * KSM, 1, SlotLength::get())); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 1 * KSM - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - //Failed/Retired - assert_ok!(Salp::fund_fail(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - - assert_eq!( - Salp::funds(3_000).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::RefundWithdrew, - } - ); - assert_eq!(Salp::redeem_pool(), 1 * KSM); - - assert_ok!(Salp::continue_fund(RawOrigin::Root.into(), 3_000, 2, 9)); - assert_eq!( - Salp::failed_funds_to_refund((3_000, 1, 8)).unwrap(), - FundInfo { - raised: 1 * KSM, - cap: 10 * KSM, - first_slot: 1, - last_slot: 8, - trie_index: 0, - status: FundStatus::FailedToContinue, - } - ); - - assert_ok!(Salp::dissolve_refunded(RawOrigin::Root.into(), 3_000, 1, 8)); - - assert_eq!(Salp::failed_funds_to_refund((3_000, 1, 8)), None); - }); - }) -} - -#[test] -fn dissolve_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create( - RawOrigin::Root.into(), - 3_000, - 1000_000_000_000, - 1, - SlotLength::get() - )); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 100_000_000_000 - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::fund_retire(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::withdraw(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::fund_end(RawOrigin::Root.into(), 3_000)); - - assert_ok!(Salp::dissolve(RawOrigin::Root.into(), 3_000)); - - assert!(Salp::funds(3_000).is_none()); - }); - }) -} - -#[test] -fn batch_unlock_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create( - RawOrigin::Root.into(), - 3_000, - 1000_000_000_000, - 1, - SlotLength::get() - )); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 100_000_000_000 - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - - assert_ok!(Salp::fund_success(RawOrigin::Root.into(), 3_000)); - assert_ok!(Salp::batch_unlock(RuntimeOrigin::signed(AccountId::new(ALICE)), 3_000)); - }) - }) -} - -#[test] -fn unlock_when_fund_ongoing_should_work() { - sp_io::TestExternalities::default().execute_with(|| { - Bifrost::execute_with(|| { - assert_ok!(Salp::create( - RawOrigin::Root.into(), - 3_000, - 1000_000_000_000, - 1, - SlotLength::get() - )); - assert_ok!(Salp::contribute( - RuntimeOrigin::signed(AccountId::new(BOB)), - 3_000, - 100_000_000_000 - )); - assert_ok!(Salp::confirm_contribute( - RuntimeOrigin::signed(AccountId::new(ALICE)), - AccountId::new(BOB), - 3_000, - true, - CONTRIBUTON_INDEX - )); - assert_ok!(Salp::unlock( - RuntimeOrigin::signed(AccountId::new(BOB)), - AccountId::new(BOB), - 3_000 - )); - }); - }) -} diff --git a/integration-tests/bifrost-kusama/src/slp.rs b/integration-tests/bifrost-kusama/src/slp.rs deleted file mode 100644 index 5e1b10a3b..000000000 --- a/integration-tests/bifrost-kusama/src/slp.rs +++ /dev/null @@ -1,1079 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -//! Cross-chain transfer tests within Kusama network. - -use bifrost_kusama_runtime::{ - Balances, Currencies, NativeCurrencyId, RelayCurrencyId, Runtime, RuntimeOrigin, Slp, Tokens, - VtokenMinting, XcmDestWeightAndFeeHandler, -}; -use bifrost_primitives::{TimeUnit, XcmOperationType as XcmOperation, KSM, VKSM}; -use bifrost_slp::{primitives::UnlockChunk, Delays, Ledger, MinimumsMaximums, SubstrateLedger}; -use frame_support::{assert_ok, BoundedVec}; -use integration_tests_common::{impls::AccountId, BifrostKusama, Kusama}; -use orml_traits::MultiCurrency; -use sp_runtime::Permill; -use xcm::{prelude::*, v3::Weight, VersionedMultiAssets, VersionedMultiLocation}; -use xcm_emulator::{assert_expected_events, Chain, ParaId, TestExt}; - -pub const ALICE: [u8; 32] = - hex_literal::hex!["d43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d"]; -pub const BOB: [u8; 32] = - hex_literal::hex!["8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48"]; -pub const KUSAMA_ALICE_STASH_ACCOUNT: [u8; 32] = - hex_literal::hex!["be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f"]; -pub const KUSAMA_BOB_STASH_ACCOUNT: [u8; 32] = - hex_literal::hex!["fe65717dad0447d715f660a0a58411de509b42e6efb8375f562f58a554d5860e"]; -const ENTRANCE_ACCOUNT: [u8; 32] = - hex_literal::hex!["6d6f646c62662f76746b696e0000000000000000000000000000000000000000"]; -const BIFROST_TREASURY_ACCOUNT: [u8; 32] = - hex_literal::hex!["6d6f646c62662f74727372790000000000000000000000000000000000000000"]; -const KSM_DELEGATOR_0_ACCOUNT: [u8; 32] = - hex_literal::hex!["5a53736d8e96f1c007cf0d630acf5209b20611617af23ce924c8e25328eb5d28"]; - -const EXIT_ACCOUNT: [u8; 32] = - hex_literal::hex!["6d6f646c62662f76746f75740000000000000000000000000000000000000000"]; - -const BIFROST_TREASURY_MULTILOCATION: MultiLocation = MultiLocation { - parents: 0, - interior: X1(AccountId32 { network: None, id: BIFROST_TREASURY_ACCOUNT }), -}; -const KSM_DELEGATOR_0_MULTILOCATION: MultiLocation = MultiLocation { - parents: 1, - interior: X1(AccountId32 { network: None, id: KSM_DELEGATOR_0_ACCOUNT }), -}; - -const ENTRANCE_ACCOUNT_MULTILOCATION: MultiLocation = - MultiLocation { parents: 0, interior: X1(AccountId32 { network: None, id: ENTRANCE_ACCOUNT }) }; - -const EXIT_ACCOUNT_MULTILOCATION: MultiLocation = - MultiLocation { parents: 0, interior: X1(AccountId32 { network: None, id: EXIT_ACCOUNT }) }; - -const KUSAMA_ALICE_MULTILOCATION: MultiLocation = - MultiLocation { parents: 1, interior: X1(AccountId32 { network: None, id: ALICE }) }; -const KUSAMA_ALICE_STASH_MULTILOCATION: MultiLocation = MultiLocation { - parents: 1, - interior: X1(AccountId32 { network: None, id: KUSAMA_ALICE_STASH_ACCOUNT }), -}; -const KUSAMA_BOB_STASH_MULTILOCATION: MultiLocation = MultiLocation { - parents: 1, - interior: X1(AccountId32 { network: None, id: KUSAMA_BOB_STASH_ACCOUNT }), -}; - -const KSM_DECIMALS: u128 = 1_000_000_000_000; -const BNC_DECIMALS: u128 = 1_000_000_000_000; - -/// **************************************************** -/// ********* Preparation section ******************** -/// **************************************************** - -// Preparation: register sub-account index 0. -fn slp_setup() { - cross_ksm_to_bifrost(BIFROST_TREASURY_ACCOUNT, 10000 * KSM_DECIMALS); - // cross_ksm_to_bifrost(ENTRANCE_ACCOUNT, 10000 * KSM_DECIMALS); - cross_ksm_to_bifrost(ALICE, 10000 * KSM_DECIMALS); - cross_ksm_to_bifrost(BOB, 10000 * KSM_DECIMALS); - - Kusama::execute_with(|| { - assert_ok!(kusama_runtime::Balances::force_set_balance( - kusama_runtime::RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - )); - kusama_runtime::System::reset_events(); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(AccountId::from(BIFROST_TREASURY_ACCOUNT)), - 10000 * BNC_DECIMALS - )); - assert_ok!(Tokens::set_balance( - RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(AccountId::from(ALICE)), - KSM, - 10000 * KSM_DECIMALS, - 0 - )); - }); - - BifrostKusama::execute_with(|| { - // set operate origin to be ALICE for vksm - assert_ok!(Slp::set_operate_origin( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some(AccountId::from(ALICE)) - )); - // Set OngoingTimeUnitUpdateInterval as 1/3 Era(1800 blocks per Era, 12 seconds per - // block) - assert_ok!(Slp::set_ongoing_time_unit_update_interval( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some(1) - )); - // Initialize ongoing timeunit as 0. - assert_ok!(Slp::update_ongoing_time_unit( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - TimeUnit::Era(0) - )); - assert_ok!(Slp::set_ongoing_time_unit_update_interval( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some(600) - )); - - // set fee_source for ksm to be treasury - assert_ok!(Slp::set_fee_source( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some((BIFROST_TREASURY_MULTILOCATION, 1 * KSM_DECIMALS)) - )); - // set fee_source for ksm to be treasury - assert_ok!(Slp::set_fee_source( - RuntimeOrigin::root(), - NativeCurrencyId::get(), - Some((BIFROST_TREASURY_MULTILOCATION, 1 * BNC_DECIMALS)) - )); - - let mins_and_maxs = MinimumsMaximums { - delegator_bonded_minimum: KSM_DECIMALS / 10, - bond_extra_minimum: KSM_DECIMALS / 1000, - unbond_minimum: KSM_DECIMALS / 1000, - rebond_minimum: KSM_DECIMALS / 1000, - unbond_record_maximum: 32, - validators_back_maximum: 24, - delegator_active_staking_maximum: 80000 * KSM_DECIMALS, - validators_reward_maximum: 256, - delegation_amount_minimum: KSM_DECIMALS / 1000, - delegators_maximum: 100, - validators_maximum: 300, - }; - - // Set minimums and maximums - assert_ok!(Slp::set_minimums_and_maximums( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some(mins_and_maxs) - )); - - // Initialize currency delays. - let delay = - Delays { unlock_delay: TimeUnit::Era(0), leave_delegators_delay: TimeUnit::Era(0) }; - assert_ok!(Slp::set_currency_delays( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some(delay) - )); - - assert_ok!(Slp::set_hosting_fees( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some((Permill::from_parts(1000), BIFROST_TREASURY_MULTILOCATION)) - )); - - assert_ok!(Slp::set_currency_tune_exchange_rate_limit( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Some((10, Permill::from_parts(1000))) - )); - - // add Alice and Bob to validators - assert_ok!(Slp::add_validator( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Box::new(KUSAMA_ALICE_STASH_MULTILOCATION), - )); - assert_ok!(Slp::add_validator( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Box::new(KUSAMA_BOB_STASH_MULTILOCATION), - )); - - // Register Operation weight and fee - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::TransferTo, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Bond, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::BondExtra, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Unbond, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Rebond, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Delegate, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Payout, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Liquidize, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::Chill, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - assert_ok!( - ::XcmWeightAndFeeHandler::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::TransferBack, - Some((Weight::from_parts(10000000000, 1000000), 10_000_000_000)), - ) - ); - - // initialize two delegators - assert_ok!(Slp::initialize_delegator(RuntimeOrigin::root(), RelayCurrencyId::get(), None)); - - bifrost_kusama_runtime::System::reset_events(); - }); -} - -fn cross_ksm_to_bifrost(to: [u8; 32], amount: u128) { - Kusama::execute_with(|| { - assert_ok!(kusama_runtime::Balances::force_set_balance( - kusama_runtime::RuntimeOrigin::root(), - sp_runtime::MultiAddress::Id(AccountId::from(to)), - amount - )); - assert_ok!(kusama_runtime::XcmPallet::reserve_transfer_assets( - kusama_runtime::RuntimeOrigin::signed(to.into()), - Box::new(VersionedMultiLocation::V3(X1(Parachain(2001)).into())), - Box::new(VersionedMultiLocation::V3( - X1(Junction::AccountId32 { id: to, network: None }).into() - )), - Box::new(VersionedMultiAssets::V3((Here, amount / 10).into())), - 0, - )); - }); -} - -#[test] -fn vtoken_minting() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - BifrostKusama::execute_with(|| { - assert_eq!(Currencies::free_balance(VKSM, &AccountId::from(ALICE)), 0); - assert_eq!( - Currencies::free_balance(KSM, &AccountId::from(ALICE)), - 10000 * KSM_DECIMALS - ); - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(AccountId::from(ALICE)), - KSM, - 100 * KSM_DECIMALS, - BoundedVec::default(), - None - )); - // alice account should have 99.9 vKSM - assert_eq!(Currencies::free_balance(VKSM, &AccountId::from(ALICE)), 100 * KSM_DECIMALS); - assert_eq!( - Currencies::free_balance(KSM, &AccountId::from(ENTRANCE_ACCOUNT)), - 100 * KSM_DECIMALS - ); - assert_eq!(Currencies::free_balance(KSM, &AccountId::from(ALICE)), 9900 * KSM_DECIMALS); - }) - }); -} - -#[test] -fn transfer_to() { - slp_setup(); - - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); - - BifrostKusama::execute_with(|| { - // Bond 50 ksm for sub-account index 0 - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(AccountId::from(ALICE)), - KSM, - 100 * KSM_DECIMALS, - BoundedVec::default(), - None - )); - - assert_ok!(Slp::transfer_to( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(ENTRANCE_ACCOUNT_MULTILOCATION), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - )); - - assert_eq!( - Currencies::free_balance(KSM, &AccountId::from(ENTRANCE_ACCOUNT)), - 50 * KSM_DECIMALS - ); - }); - - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10050009921672574 - ); - }); -} - -#[test] -fn transfer_back() { - slp_setup(); - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); - - BifrostKusama::execute_with(|| { - // Bond 50 ksm for sub-account index 0 - assert_eq!(Currencies::free_balance(KSM, &AccountId::from(EXIT_ACCOUNT)), 0); - - assert_ok!(Slp::transfer_back( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Box::new(EXIT_ACCOUNT_MULTILOCATION), - 50 * KSM_DECIMALS, - None - )); - }); - - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 9949998630000371 - ); - }); - - BifrostKusama::execute_with(|| { - assert_eq!(Currencies::free_balance(KSM, &AccountId::from(EXIT_ACCOUNT)), 49999919630000); - }); -} - -#[test] -fn bond_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - - BifrostKusama::execute_with(|| { - // Bond 50 ksm for sub-account index 0 - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::Staking(pallet_staking::Event::Bonded { stash, amount}) => { - stash: *stash == AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - amount: *amount == 50 * KSM_DECIMALS, - }, - ] - ); - }); - - BifrostKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - // Bond 50 ksm and auto confirm - assert_expected_events!( - BifrostKusama, - vec![ - // Amount to reserve transfer is transferred to System Parachain's Sovereign account - RuntimeEvent::Slp(bifrost_slp::Event::DelegatorLedgerQueryResponseConfirmed {..}) => { }, - ] - ); - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 50 * KSM_DECIMALS, - unlocking: vec![], - })) - ); - }); - }) -} - -#[test] -fn bond_extra_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - BifrostKusama::execute_with(|| { - // Bond_extra 20 ksm for sub-account index 0 - assert_ok!(Slp::bond_extra( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 20 * KSM_DECIMALS, - None - )); - }); - - Kusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::Staking(pallet_staking::Event::Bonded { stash, amount}) => { - stash: *stash == AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - amount: *amount == 20 * KSM_DECIMALS, - }, - ] - ); - }); - - BifrostKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - // Bond 20 ksm and auto confirm - assert_expected_events!( - BifrostKusama, - vec![ - RuntimeEvent::Slp(bifrost_slp::Event::DelegatorLedgerQueryResponseConfirmed {..}) => { }, - ] - ); - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 70 * KSM_DECIMALS, - active: 70 * KSM_DECIMALS, - unlocking: vec![], - })) - ); - }); - }) -} - -#[test] -fn unbond_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| {}); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 20 * KSM_DECIMALS, - None - )); - }); - - Kusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::Staking(pallet_staking::Event::Unbonded { stash, amount}) => { - stash: *stash == AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - amount: *amount == 20 * KSM_DECIMALS, - }, - ] - ); - }); - - BifrostKusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - BifrostKusama, - vec![ - // Amount to reserve transfer is transferred to System Parachain's Sovereign account - RuntimeEvent::Slp(bifrost_slp::Event::DelegatorLedgerQueryResponseConfirmed {..}) => { }, - ] - ); - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 20 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); -} - -#[test] -fn unbond_all_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - // Unbond 0.5 ksm, 0.5 ksm left. - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| {}); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::unbond_all( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None - )); - }); - - Kusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::Staking(pallet_staking::Event::Unbonded { stash, amount}) => { - stash: *stash == AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - amount: *amount == 20 * KSM_DECIMALS, - }, - ] - ); - }); - - BifrostKusama::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 0, - unlocking: vec![UnlockChunk { - value: 50 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); -} - -#[test] -fn rebond_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 30 * KSM_DECIMALS, - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - // rebond 0.5 ksm. - assert_ok!(Slp::rebond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - Some(20 * KSM_DECIMALS), - None - )); - }); - - // So the bonded amount should be 1 ksm - Kusama::execute_with(|| { - type RuntimeEvent = ::RuntimeEvent; - assert_expected_events!( - Kusama, - vec![ - RuntimeEvent::Staking(pallet_staking::Event::Bonded { stash, amount}) => { - stash: *stash == AccountId::from(KSM_DELEGATOR_0_ACCOUNT), - amount: *amount == 20 * KSM_DECIMALS, - }, - ] - ); - }); - - BifrostKusama::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 40 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 10 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); -} - -#[test] -fn delegate_works() { - sp_io::TestExternalities::default().execute_with(|| { - // bond 1 ksm for sub-account index 0 - slp_setup(); - - Kusama::execute_with(|| { - use kusama_runtime::System; - System::reset_events(); - }); - - BifrostKusama::execute_with(|| { - // Unbond 0.5 ksm, 0.5 ksm left. - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(AccountId::from(ALICE)), - KSM, - 100 * KSM_DECIMALS, - BoundedVec::default(), - None - )); - - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| {}); - - BifrostKusama::execute_with(|| { - // delegate - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - Kusama::assert_ump_queue_processed(true, Some(ParaId::new(2001)), None); - }); - }) -} - -#[test] -fn undelegate_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - // Undelegate validator 0. Only validator 1 left. - assert_ok!(Slp::undelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - Kusama::assert_ump_queue_processed(true, Some(ParaId::new(2001)), None); - }); -} - -#[test] -fn redelegate_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - // Undelegate validator 0. Only validator 1 left. - assert_ok!(Slp::undelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::redelegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Some(vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION]), - None - )); - }); - - Kusama::execute_with(|| { - Kusama::assert_ump_queue_processed(true, Some(ParaId::new(2001)), None); - }); -} - -#[test] -fn payout_works() { - slp_setup(); - BifrostKusama::execute_with(|| { - // Bond 1 ksm for sub-account index 0 - assert_ok!(Slp::payout( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Box::new(KUSAMA_ALICE_STASH_MULTILOCATION), - Some(TimeUnit::Era(27)), - None - )); - }); -} - -#[test] -fn liquidize_works() { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None, - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::unbond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None, - 20 * KSM_DECIMALS, - None - )); - }); - - Kusama::execute_with(|| { - // TODO: Assert events; - }); - - BifrostKusama::execute_with(|| { - // Bond 70 ksm and auto confirm - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 50 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![UnlockChunk { - value: 20 * KSM_DECIMALS, - unlock_time: TimeUnit::Era(0) - }], - })) - ); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::liquidize( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - Some(TimeUnit::SlashingSpan(5)), - None, - None, - None - )); - }); - - Kusama::execute_with(|| { - Kusama::assert_ump_queue_processed(true, Some(ParaId::new(2001)), None); - }); - - BifrostKusama::execute_with(|| { - assert_eq!( - Slp::get_delegator_ledger(RelayCurrencyId::get(), KSM_DELEGATOR_0_MULTILOCATION), - Some(Ledger::Substrate(SubstrateLedger { - account: KSM_DELEGATOR_0_MULTILOCATION, - total: 30 * KSM_DECIMALS, - active: 30 * KSM_DECIMALS, - unlocking: vec![], - })) - ); - }); -} - -#[test] -fn chill_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::bond( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - 50 * KSM_DECIMALS, - None, - None - )); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::delegate( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - vec![KUSAMA_ALICE_STASH_MULTILOCATION, KUSAMA_BOB_STASH_MULTILOCATION], - None - )); - }); - - // check if sub-account index 0 belongs to the group of nominators - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Staking::ledger(AccountId::from(KSM_DELEGATOR_0_ACCOUNT).into()) - .is_ok(), - true - ); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::chill( - RuntimeOrigin::signed(AccountId::from(ALICE)), - RelayCurrencyId::get(), - Box::new(KSM_DELEGATOR_0_MULTILOCATION), - None - )); - }); - - // check if sub-account index 0 belongs to the group of nominators - Kusama::execute_with(|| {}); - }) -} - -#[test] -fn supplement_fee_reserve_works() { - sp_io::TestExternalities::default().execute_with(|| { - slp_setup(); - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); - - BifrostKusama::execute_with(|| { - assert_ok!(Slp::supplement_fee_reserve( - RuntimeOrigin::root(), - RelayCurrencyId::get(), - Box::new(KUSAMA_ALICE_MULTILOCATION), - )); - }); - - Kusama::execute_with(|| { - assert_eq!( - kusama_runtime::Balances::free_balance(&AccountId::from(KSM_DELEGATOR_0_ACCOUNT)), - 10000 * KSM_DECIMALS - ); - }); - }) -} diff --git a/integration-tests/bifrost-kusama/src/total_issuance.rs b/integration-tests/bifrost-kusama/src/total_issuance.rs deleted file mode 100644 index 3dec79e52..000000000 --- a/integration-tests/bifrost-kusama/src/total_issuance.rs +++ /dev/null @@ -1,51 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use bifrost_kusama_runtime::{ - constants::currency::{BNCS, MILLIBNC}, - Balances, RuntimeOrigin, -}; -use frame_support::{assert_ok, traits::Currency}; -use integration_tests_common::{ - BifrostKusama, BifrostKusamaAlice, BifrostKusamaBob, BifrostKusamaTreasury, -}; -use xcm_emulator::TestExt; - -#[test] -fn remove_dust_account_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(Balances::minimum_balance(), 10 * MILLIBNC); - - assert_eq!(Balances::total_issuance(), 8_000_0000 * BNCS); - - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(BifrostKusamaAlice::get()), - BifrostKusamaBob::get().into(), - Balances::free_balance(&BifrostKusamaAlice::get()) - MILLIBNC - )); - - // As expected dust balance is removed. - assert_eq!(Balances::free_balance(&BifrostKusamaAlice::get()), 0); - assert_eq!( - Balances::free_balance(&BifrostKusamaTreasury::get()), - 1_000_0000 * BNCS + MILLIBNC - ); - - assert_eq!(Balances::total_issuance(), 8_000_0000 * BNCS); - }); -} diff --git a/integration-tests/bifrost-kusama/src/transact.rs b/integration-tests/bifrost-kusama/src/transact.rs deleted file mode 100644 index b5506c994..000000000 --- a/integration-tests/bifrost-kusama/src/transact.rs +++ /dev/null @@ -1,141 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use crate::vtoken_voting::set_balance_proposal_bounded; -use bifrost_kusama_runtime::{Runtime, RuntimeCall, RuntimeEvent, System}; -use bifrost_primitives::Balance; -use frame_support::{ - assert_ok, - dispatch::{GetDispatchInfo, RawOrigin}, -}; -use integration_tests_common::{BifrostKusama, Kusama, KusamaAlice}; -use pallet_conviction_voting::{AccountVote, Vote}; -use parity_scale_codec::Encode; -use xcm::v3::{prelude::*, Weight}; -use xcm_emulator::{bx, Parachain, RelayChain, TestExt}; - -#[test] -fn relaychain_transact_works() { - let vote_call = - kusama_runtime::RuntimeCall::ConvictionVoting(pallet_conviction_voting::Call::< - kusama_runtime::Runtime, - >::vote { - poll_index: 0, - vote: aye(1_000_000_000_000u128, 1), - }); - - let notify_vote_call = - RuntimeCall::VtokenVoting(bifrost_vtoken_voting::Call::::notify_vote { - query_id: 0, - response: Default::default(), - }); - - Kusama::execute_with(|| { - use frame_support::traits::schedule::DispatchTime; - use kusama_runtime::{Balances, Referenda, RuntimeEvent, RuntimeOrigin, System}; - - println!("KusamaNet vote_call weight: {:?}", vote_call.get_dispatch_info().weight); - - assert_ok!(Referenda::submit( - RuntimeOrigin::signed(KusamaAlice::get()), - bx!(RawOrigin::Root.into()), - set_balance_proposal_bounded(1), - DispatchTime::At(1), - )); - - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), - 100_000_000_000_000u128 - )); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { - index: 0, - track: _, - proposal: _, - }) - ))); - }); - - BifrostKusama::execute_with(|| { - let notify_vote_call_weight = notify_vote_call.get_dispatch_info().weight; - let query_id = pallet_xcm::Pallet::::new_notify_query( - MultiLocation::parent(), - notify_vote_call, - 100u32.into(), - Here, - ); - - let asset: MultiAsset = - MultiAsset { id: Concrete(MultiLocation::here()), fun: Fungible(1000000000000) }; - let msg = Xcm(vec![ - WithdrawAsset(asset.clone().into()), - BuyExecution { fees: asset, weight_limit: Unlimited }, - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: Weight::from_parts(1019439000, 83866), - call: vote_call.encode().into(), - }, - ReportTransactStatus(QueryResponseInfo { - destination: MultiLocation::from(X1(Parachain(2001))), - query_id, - max_weight: notify_vote_call_weight, - }), - RefundSurplus, - DepositAsset { - assets: All.into(), - beneficiary: MultiLocation { parents: 0, interior: X1(Parachain(2001)) }, - }, - ]); - assert_ok!(pallet_xcm::Pallet::::send_xcm(Here, MultiLocation::parent(), msg)); - }); - - Kusama::execute_with(|| { - use kusama_runtime::{RuntimeEvent, System}; - - System::events().iter().for_each(|r| println!("KusamaNet >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - &r.event, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { - id: _, - origin: _, - weight_used: _, - success: true - }) - ))); - }); - - BifrostKusama::execute_with(|| { - System::events().iter().for_each(|r| println!("Bifrost >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::ResponseReceived { - responder: MultiLocation { parents: 1, interior: Here }, - query_id: 0, - response: Response::DispatchResult(MaybeErrorCode::Success) - }) - ))); - }); -} - -pub fn aye(amount: Balance, conviction: u8) -> AccountVote { - let vote = Vote { aye: true, conviction: conviction.try_into().unwrap() }; - AccountVote::Standard { vote, balance: amount } -} diff --git a/integration-tests/bifrost-kusama/src/vtoken_minting.rs b/integration-tests/bifrost-kusama/src/vtoken_minting.rs deleted file mode 100644 index 9f4684d84..000000000 --- a/integration-tests/bifrost-kusama/src/vtoken_minting.rs +++ /dev/null @@ -1,186 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use bifrost_asset_registry::AssetIdMaps; -use bifrost_kusama_runtime::{ - Currencies, MultiCurrency, Runtime, SlpEntrancePalletId, VtokenMinting, VtokenMintingOperator, -}; -use bifrost_primitives::{CurrencyIdRegister, TimeUnit, TokenSymbol, KSM, VKSM}; -use frame_support::{assert_ok, dispatch::RawOrigin}; -use integration_tests_common::{BifrostKusama, BifrostKusamaAlice}; -use sp_runtime::{traits::AccountIdConversion, BoundedVec, Permill}; -use xcm_emulator::TestExt; - -#[test] -fn set_unlock_duration_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_unlock_duration( - RawOrigin::Root.into(), - KSM, - TimeUnit::Era(28), - )); - assert_eq!(VtokenMinting::unlock_duration(KSM), Some(TimeUnit::Era(28))); - }); -} - -#[test] -fn set_minimum_mint_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_minimum_mint(RawOrigin::Root.into(), KSM, 50_000_000_000,)); - assert_eq!(VtokenMinting::minimum_mint(KSM), 50_000_000_000); - assert_eq!(AssetIdMaps::::check_vtoken_registered(TokenSymbol::KSM), true); - assert_eq!(AssetIdMaps::::check_token_registered(TokenSymbol::KSM), true); - }); -} - -#[test] -fn set_minimum_redeem_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_minimum_redeem(RawOrigin::Root.into(), KSM, 10_000,)); - assert_eq!(VtokenMinting::minimum_redeem(KSM), 10_000); - }); -} - -#[test] -fn add_support_rebond_token_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(VtokenMinting::token_to_rebond(KSM), None); - assert_ok!(VtokenMinting::add_support_rebond_token(RawOrigin::Root.into(), KSM,)); - assert_eq!(VtokenMinting::token_to_rebond(KSM), Some(0)); - }); -} - -#[test] -fn remove_support_rebond_token_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(VtokenMinting::token_to_rebond(KSM), None); - assert_ok!(VtokenMinting::add_support_rebond_token(RawOrigin::Root.into(), KSM,)); - assert_eq!(VtokenMinting::token_to_rebond(KSM), Some(0)); - assert_ok!(VtokenMinting::remove_support_rebond_token(RawOrigin::Root.into(), KSM,)); - assert_eq!(VtokenMinting::token_to_rebond(KSM), None); - }); -} - -#[test] -fn set_fees_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_fees( - RawOrigin::Root.into(), - Permill::from_perthousand(0), - Permill::from_perthousand(1), - )); - assert_eq!( - VtokenMinting::fees(), - (Permill::from_perthousand(0), Permill::from_perthousand(1)) - ); - println!("{:#?}", Permill::from_perthousand(1)); - }); -} - -#[test] -fn set_hook_iteration_limit_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_hook_iteration_limit(RawOrigin::Root.into(), 10)); - assert_eq!(VtokenMinting::hook_iteration_limit(), 10); - }); -} - -#[test] -fn set_unlocking_total_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!( - VtokenMinting::set_unlocking_total(RawOrigin::Root.into(), KSM, 10_000_000_000,) - ); - assert_eq!(VtokenMinting::unlocking_total(KSM), 10_000_000_000); - }); -} - -#[test] -fn set_min_time_unit_should_work() { - BifrostKusama::execute_with(|| { - assert_ok!(VtokenMinting::set_min_time_unit( - RawOrigin::Root.into(), - KSM, - TimeUnit::Era(4362), - )); - assert_eq!(VtokenMinting::min_time_unit(KSM), TimeUnit::Era(4362)); - }); -} - -#[test] -fn mint_should_work() { - BifrostKusama::execute_with(|| { - assert_eq!(VtokenMinting::token_pool(KSM), 0); - assert_eq!(Currencies::total_issuance(VKSM), 0); - assert_eq!( - VtokenMinting::fees(), - (Permill::from_perthousand(0), Permill::from_perthousand(0)) - ); - - assert_ok!(VtokenMinting::mint( - RawOrigin::Signed(BifrostKusamaAlice::get()).into(), - KSM, - 5_000_000_000_000, - BoundedVec::default(), - None - )); - - //check balance - let entrance_account = SlpEntrancePalletId::get().into_account_truncating(); - assert_eq!(Currencies::free_balance(VKSM, &BifrostKusamaAlice::get()), 5_000_000_000_000); - assert_eq!(Currencies::free_balance(KSM, &entrance_account), 5_000_000_000_000); - assert_eq!(VtokenMinting::token_pool(KSM), 5_000_000_000_000); - }); -} - -#[test] -fn redeem_should_work() { - BifrostKusama::execute_with(|| { - pub const FEE: Permill = Permill::from_percent(2); - assert_ok!(VtokenMinting::set_fees(RawOrigin::Root.into(), FEE, FEE)); - assert_ok!(VtokenMinting::set_unlock_duration( - RawOrigin::Root.into(), - KSM, - TimeUnit::Era(1) - )); - assert_ok!(VtokenMinting::update_ongoing_time_unit(KSM, TimeUnit::Era(1))); - assert_ok!(VtokenMinting::set_minimum_redeem( - RawOrigin::Root.into(), - KSM, - 2 * 1_000_000_000_000 - )); - assert_ok!(VtokenMinting::mint( - RawOrigin::Signed(BifrostKusamaAlice::get()).into(), - KSM, - 5 * 1_000_000_000_000, - BoundedVec::default(), - None - )); - assert_eq!(VtokenMinting::token_pool(KSM), 5 * 1_000_000_000_000 - 5 * 20_000_000_000); // 1000 + 980 - 98 - 196 - - assert_ok!(VtokenMinting::redeem( - RawOrigin::Signed(BifrostKusamaAlice::get()).into(), - VKSM, - 1 * 1_000_000_000_000 - )); - assert_eq!( - VtokenMinting::token_pool(KSM), - 5 * 1_000_000_000_000 - 5 * 20_000_000_000 - 1_000_000_000_000 + 20_000_000_000 - ); - }); -} diff --git a/integration-tests/bifrost-kusama/src/vtoken_voting.rs b/integration-tests/bifrost-kusama/src/vtoken_voting.rs deleted file mode 100644 index 68a4653c7..000000000 --- a/integration-tests/bifrost-kusama/src/vtoken_voting.rs +++ /dev/null @@ -1,275 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use bifrost_kusama_runtime::{ - Runtime, RuntimeOrigin, Slp, XcmDestWeightAndFeeHandler, XcmInterface, -}; -use bifrost_primitives::{ - currency::VKSM, Balance, CurrencyId, VTokenSupplyProvider, XcmOperationType as XcmOperation, - KSM, -}; -use bifrost_slp::{Ledger, MinimumsMaximums, SubstrateLedger}; -use bifrost_vtoken_voting::{AccountVote, TallyOf}; -use frame_support::{ - assert_ok, - dispatch::RawOrigin, - traits::{schedule::DispatchTime, StorePreimage}, - weights::Weight, -}; -use integration_tests_common::{BifrostKusama, BifrostKusamaAlice, Kusama, KusamaAlice}; -use pallet_conviction_voting::Vote; -use sp_runtime::Perbill; -use xcm::v3::Parent; -use xcm_emulator::{Parachain, RelayChain, TestExt}; - -#[test] -fn vote_works() { - let vtoken = VKSM; - let poll_index = 0; - - Kusama::execute_with(|| { - use kusama_runtime::{Balances, Referenda, RuntimeEvent, RuntimeOrigin, System, Utility}; - - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), - 1_000_000_000_000_000u128 - )); - assert_ok!(Balances::force_set_balance( - RuntimeOrigin::root(), - Utility::derivative_account_id( - Kusama::sovereign_account_id_of_child_para(BifrostKusama::para_id()).into(), - 5 - ) - .into(), - 1_000_000_000_000_000u128 - )); - assert_ok!(Referenda::submit( - RuntimeOrigin::signed(BifrostKusamaAlice::get()), - Box::new(RawOrigin::Root.into()), - set_balance_proposal_bounded(1), - DispatchTime::At(10), - )); - System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Referenda(pallet_referenda::Event::Submitted { - index: 0, - track: 0, - proposal: _, - }) - ))); - System::reset_events(); - }); - - BifrostKusama::execute_with(|| { - use bifrost_kusama_runtime::{ - RuntimeEvent, RuntimeOrigin, System, VtokenMinting, VtokenVoting, - }; - - assert_ok!(VtokenMinting::mint( - RuntimeOrigin::signed(BifrostKusamaAlice::get()), - KSM, - 1_000_000_000_000, - Default::default(), - None - )); - assert_eq!( - ::VTokenSupplyProvider::get_token_supply(KSM), - Some(1_000_000_000_000) - ); - assert_eq!( - ::VTokenSupplyProvider::get_vtoken_supply( - VKSM - ), - Some(1_000_000_000_000) - ); - let token = CurrencyId::to_token(&vtoken).unwrap(); - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - token, - XcmOperation::Vote, - Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), - )); - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - token, - XcmOperation::RemoveVote, - Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), - )); - assert_ok!(Slp::set_minimums_and_maximums( - RuntimeOrigin::root(), - token, - Some(MinimumsMaximums { - delegator_bonded_minimum: 0u32.into(), - bond_extra_minimum: 0u32.into(), - unbond_minimum: 0u32.into(), - rebond_minimum: 0u32.into(), - unbond_record_maximum: 0u32, - validators_back_maximum: 0u32, - delegator_active_staking_maximum: 0u32.into(), - validators_reward_maximum: 0u32, - delegation_amount_minimum: 0u32.into(), - delegators_maximum: u16::MAX, - validators_maximum: 0u16, - }) - )); - assert_ok!(Slp::add_delegator(RuntimeOrigin::root(), token, 5, Box::new(Parent.into()))); - assert_ok!(Slp::set_delegator_ledger( - RuntimeOrigin::root(), - token, - Box::new(Parent.into()), - Box::new(Some(Ledger::Substrate(SubstrateLedger { - account: Parent.into(), - total: 1_000_000_000_000u128, - active: 1_000_000_000_000u128, - unlocking: vec![], - }))) - )); - - assert_ok!(VtokenVoting::set_vote_cap_ratio( - RuntimeOrigin::root(), - vtoken, - Perbill::from_percent(90) - )); - assert_ok!(VtokenVoting::add_delegator(RuntimeOrigin::root(), vtoken, 5)); - assert_ok!(VtokenVoting::set_vote_locking_period(RuntimeOrigin::root(), vtoken, 0)); - assert_ok!(VtokenVoting::set_undeciding_timeout(RuntimeOrigin::root(), vtoken, 100)); - - assert_ok!(VtokenVoting::vote( - RuntimeOrigin::signed(BifrostKusamaAlice::get()), - vtoken, - poll_index, - aye(1_000_000_000_000u128, 5) - )); - - assert_eq!( - tally(vtoken, poll_index), - TallyOf::::from_parts(5_000_000_000_000, 0, 1_000_000_000_000) - ); - - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::Voted { - who: _, - vtoken: VKSM, - poll_index: 0, - token_vote: _, - delegator_vote: _, - }) - ))); - System::reset_events(); - }); - - Kusama::execute_with(|| { - use kusama_runtime::System; - - System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - kusama_runtime::RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { - id: _, - origin: _, - weight_used: _, - success: true - }) - ))); - System::reset_events(); - }); - - BifrostKusama::execute_with(|| { - use bifrost_kusama_runtime::{RuntimeEvent, System, VtokenVoting}; - - System::events() - .iter() - .for_each(|r| log::debug!("BifrostKusama >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting(bifrost_vtoken_voting::Event::VoteNotified { - vtoken: VKSM, - poll_index: 0, - success: true, - }) - ))); - assert_ok!(VtokenVoting::set_referendum_status( - RuntimeOrigin::root(), - VKSM, - 0, - bifrost_vtoken_voting::ReferendumInfoOf::::Completed(1), - )); - assert_ok!(VtokenVoting::remove_delegator_vote( - RuntimeOrigin::signed(BifrostKusamaAlice::get()), - VKSM, - 0, - 5, - )); - System::reset_events(); - }); - - Kusama::execute_with(|| { - use kusama_runtime::{RuntimeEvent, System}; - - System::events().iter().for_each(|r| log::debug!("Kusama >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - &r.event, - RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { - id: _, - origin: _, - weight_used: _, - success: true - }) - ))); - }); - - BifrostKusama::execute_with(|| { - use bifrost_kusama_runtime::{RuntimeEvent, System}; - - System::events() - .iter() - .for_each(|r| log::debug!("BifrostKusama >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::VtokenVoting( - bifrost_vtoken_voting::Event::DelegatorVoteRemovedNotified { - vtoken: VKSM, - poll_index: 0, - success: true, - } - ) - ))); - }); -} - -pub fn set_balance_proposal_bounded( - value: Balance, -) -> pallet_referenda::BoundedCallOf { - let c = kusama_runtime::RuntimeCall::Balances(pallet_balances::Call::force_set_balance { - who: KusamaAlice::get().into(), - new_free: value, - }); - ::bound(c).unwrap() -} - -pub fn aye(amount: Balance, conviction: u8) -> AccountVote { - let vote = Vote { aye: true, conviction: conviction.try_into().unwrap() }; - AccountVote::Standard { vote, balance: amount } -} - -fn tally(vtoken: CurrencyId, poll_index: u32) -> TallyOf { - bifrost_kusama_runtime::VtokenVoting::ensure_referendum_ongoing(vtoken, poll_index) - .expect("No poll") - .tally -} diff --git a/integration-tests/bifrost-kusama/src/xcm_interface.rs b/integration-tests/bifrost-kusama/src/xcm_interface.rs deleted file mode 100644 index 0a88d6493..000000000 --- a/integration-tests/bifrost-kusama/src/xcm_interface.rs +++ /dev/null @@ -1,174 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use bifrost_asset_registry::AssetMetadata; -use bifrost_kusama_runtime::{ - AssetRegistry, RelayCurrencyId, RuntimeEvent, RuntimeOrigin, System, - XcmDestWeightAndFeeHandler, XcmInterface, -}; -use bifrost_primitives::{CurrencyId, XcmOperationType as XcmOperation}; -use frame_support::{assert_ok, traits::Currency}; -use integration_tests_common::{ - impls::Outcome::Complete, AssetHubKusama, AssetHubKusamaAlice, BifrostKusama, - BifrostKusamaAlice, -}; -use polkadot_parachain_primitives::primitives::Sibling; -use sp_runtime::{traits::AccountIdConversion, MultiAddress}; -use xcm::{ - v3::{prelude::*, Weight}, - VersionedMultiAssets, VersionedMultiLocation, -}; -use xcm_emulator::{bx, Parachain, TestExt}; - -const USDT: u128 = 1_000_000; - -#[test] -fn cross_usdt() { - BifrostKusama::execute_with(|| { - let metadata = AssetMetadata { - name: b"USDT".to_vec(), - symbol: b"USDT".to_vec(), - decimals: 6, - minimal_balance: 10, - }; - - assert_ok!(AssetRegistry::register_token_metadata( - RuntimeOrigin::root(), - bx!(metadata.clone()) - )); - - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: X3(Parachain(1000), PalletInstance(50), GeneralIndex(1984)), - }); - - assert_ok!(AssetRegistry::register_multilocation( - RuntimeOrigin::root(), - CurrencyId::Token2(0), - bx!(location.clone()), - Weight::zero() - )); - }); - - AssetHubKusama::execute_with(|| { - use asset_hub_kusama_runtime::{ - Assets, Balances, Runtime, RuntimeEvent, RuntimeOrigin, System, - }; - - let sibling_account = Sibling::from(2001).into_account_truncating(); - - // need to have some KSM to be able to receive user assets - Balances::make_free_balance_be(&sibling_account, 10 * 1_000_000_000_000u128); - - assert_ok!(Assets::create( - RuntimeOrigin::signed(AssetHubKusamaAlice::get()), - codec::Compact(1984), - MultiAddress::Id(AssetHubKusamaAlice::get()), - 10 - )); - - assert_ok!(Assets::set_metadata( - RuntimeOrigin::signed(AssetHubKusamaAlice::get()), - codec::Compact(1984), - b"USDT".to_vec(), - b"USDT".to_vec(), - 6 - )); - - assert_ok!(Assets::mint( - RuntimeOrigin::signed(AssetHubKusamaAlice::get()), - codec::Compact(1984), - MultiAddress::Id(AssetHubKusamaAlice::get()), - 100 * USDT - )); - assert_eq!(Assets::balance(1984, AssetHubKusamaAlice::get()), 100 * USDT); - - let assets = MultiAssets::from(vec![MultiAsset::from(( - Concrete(MultiLocation::new(0, X2(PalletInstance(50), GeneralIndex(1984)))), - Fungibility::from(10 * USDT), - ))]); - - assert_ok!(pallet_xcm::Pallet::::limited_reserve_transfer_assets( - RuntimeOrigin::signed(AssetHubKusamaAlice::get()), - bx!(AssetHubKusama::sibling_location_of(BifrostKusama::para_id()).into()), - bx!(AccountId32 { network: None, id: BifrostKusamaAlice::get().into() }.into()), - Box::new(VersionedMultiAssets::V3(assets)), - 0, - WeightLimit::Unlimited, - )); - assert!(System::events().iter().any(|r| matches!( - r.event, - RuntimeEvent::Assets(pallet_assets::Event::Transferred { - asset_id: 1984, - from: _, - to: _, - amount: 10_000_000 - }) - ))); - assert!(System::events().iter().any(|r| matches!( - &r.event, - RuntimeEvent::PolkadotXcm(pallet_xcm::Event::Attempted { outcome: Complete(_) }) - ))); - System::reset_events(); - }); - - BifrostKusama::execute_with(|| { - System::events().iter().for_each(|r| println!("Bifrost >>> {:?}", r.event)); - assert!(System::events().iter().any(|r| matches!( - &r.event, - RuntimeEvent::Tokens(orml_tokens::Event::Deposited { - currency_id: CurrencyId::Token2(0), - who: _, - amount: 10_000_000 - }) - ))); - - System::reset_events(); - - assert_ok!(XcmInterface::set_xcm_dest_weight_and_fee( - RelayCurrencyId::get(), - XcmOperation::StatemineTransfer, - Some((Weight::from_parts(400_000_000_000, 10_000), 4_000_000_000)), - )); - - // Alice transfers 5 statemine asset to Bob - // TODO: Failed to process XCMP-XCM message, caused by Barrier - // assert_ok!(XcmInterface::transfer_statemine_assets( - // RuntimeOrigin::signed(BifrostKusamaAlice::get()), - // 5 * USDT, - // 1984, - // Some(BifrostKusamaBob::get()) - // )); - }); - - // AsserHubKusama::execute_with(|| { - // use statemine_runtime::*; - // println!("{:?}", System::events()); - // - // // assert Bob has 5 statemine asset - // assert_eq!(Assets::balance(1984, AccountId::from(BOB)), 5 * USDT); - // - // assert!(System::events().iter().any(|r| matches!( - // r.event, - // RuntimeEvent::XcmpQueue(cumulus_pallet_xcmp_queue::Event::Success { - // message_hash: _, - // weight: _ - // }) - // ))); - // }); -} diff --git a/integration-tests/bifrost-polkadot/Cargo.toml b/integration-tests/bifrost-polkadot/Cargo.toml deleted file mode 100644 index e6d46f80c..000000000 --- a/integration-tests/bifrost-polkadot/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "bifrost-polkadot-integration-tests" -version = "0.8.0" -authors = ["Ron Yang "] -edition = "2021" - -[dependencies] -parity-scale-codec = { workspace = true } - -# Substrate -sp-runtime = { workspace = true } -sp-io = { workspace = true } -frame-support = { workspace = true } -frame-system = { workspace = true } -pallet-balances = { workspace = true } - -# Polkadot -polkadot-parachain-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-runtime = { workspace = true } -xcm = { workspace = true } -pallet-xcm = { workspace = true } - -# Cumulus -parachains-common = { workspace = true } -xcm-emulator = { workspace = true } - -# Local -integration-tests-common = { path = "../common", default-features = false} -bifrost-primitives = { workspace = true } -bifrost-asset-registry = { workspace = true } -bifrost-polkadot-runtime = { workspace = true } diff --git a/integration-tests/common/Cargo.toml b/integration-tests/common/Cargo.toml deleted file mode 100644 index 47e5d94f5..000000000 --- a/integration-tests/common/Cargo.toml +++ /dev/null @@ -1,56 +0,0 @@ -[package] -name = "integration-tests-common" -version = "0.8.0" -authors = ["hqwangningbo <2536935847@qq.com>"] -edition = "2021" - -[dependencies] -parity-scale-codec = { workspace = true } -paste = { workspace = true } - -# Substrate -sc-consensus-grandpa = { workspace = true } -sp-authority-discovery = { workspace = true } -sp-runtime = { workspace = true } -frame-support = { workspace = true } -sp-core = { workspace = true } -sp-consensus-babe = { workspace = true } -pallet-assets = { workspace = true } -pallet-staking = { workspace = true } -pallet-message-queue = { workspace = true } -pallet-im-online = { workspace = true } - -# Polkadot -polkadot-core-primitives = { workspace = true } -polkadot-parachain-primitives = { workspace = true } -polkadot-service = { workspace = true } -polkadot-primitives = { workspace = true } -polkadot-runtime-parachains = { workspace = true } -polkadot-runtime = { workspace = true } -polkadot-runtime-constants = { workspace = true } -kusama-runtime = { workspace = true } -kusama-runtime-constants = { workspace = true } -xcm = { workspace = true } -pallet-xcm = { workspace = true } - -# Cumulus -parachains-common = { workspace = true } -cumulus-primitives-core = { workspace = true } -xcm-emulator = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } -cumulus-pallet-xcmp-queue = { workspace = true } -cumulus-pallet-parachain-system = { workspace = true } - -bifrost-polkadot-runtime = { workspace = true } -bifrost-kusama-runtime = { workspace = true } -asset-hub-polkadot-runtime = { workspace = true } -asset-hub-kusama-runtime = { workspace = true } -bridge-hub-polkadot-runtime = { workspace = true } -bridge-hub-kusama-runtime = { workspace = true } -bifrost-parachain-staking = { workspace = true } -bifrost-primitives = { workspace = true } -beefy-primitives = { workspace = true } -grandpa-primitives = { workspace = true } -bp-messages = { workspace = true } -pallet-bridge-messages = { workspace = true } -bridge-runtime-common = { workspace = true } diff --git a/integration-tests/common/src/constants.rs b/integration-tests/common/src/constants.rs deleted file mode 100644 index 3e988504f..000000000 --- a/integration-tests/common/src/constants.rs +++ /dev/null @@ -1,794 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -// Substrate -use beefy_primitives::ecdsa_crypto::AuthorityId as BeefyId; -use grandpa_primitives::AuthorityId as GrandpaId; -use pallet_im_online::sr25519::AuthorityId as ImOnlineId; -use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId; -use sp_consensus_babe::AuthorityId as BabeId; -use sp_core::{sr25519, storage::Storage, Pair, Public}; -use sp_runtime::{ - traits::{IdentifyAccount, Verify}, - BuildStorage, MultiSignature, Perbill, -}; - -// Cumulus -use parachains_common::{AccountId, AssetHubPolkadotAuraId, AuraId, Balance, BlockNumber}; -use polkadot_parachain_primitives::primitives::{HeadData, ValidationCode}; -use polkadot_primitives::{AssignmentId, ValidatorId}; -use polkadot_runtime_parachains::{ - configuration::HostConfiguration, - paras::{ParaGenesisArgs, ParaKind}, -}; -use xcm; - -pub const XCM_V2: u32 = 3; -pub const XCM_V3: u32 = 2; -pub const REF_TIME_THRESHOLD: u64 = 33; -pub const PROOF_SIZE_THRESHOLD: u64 = 33; - -type AccountPublic = ::Signer; - -/// Helper function to generate a crypto pair from seed -fn get_from_seed(seed: &str) -> ::Public { - TPublic::Pair::from_string(&format!("//{}", seed), None) - .expect("static values are valid; qed") - .public() -} - -/// Helper function to generate an account ID from seed. -fn get_account_id_from_seed(seed: &str) -> AccountId -where - AccountPublic: From<::Public>, -{ - AccountPublic::from(get_from_seed::(seed)).into_account() -} - -pub mod accounts { - use super::*; - use sp_runtime::traits::AccountIdConversion; - pub const ALICE: &str = "Alice"; - pub const BOB: &str = "Bob"; - pub const CHARLIE: &str = "Charlie"; - pub const DAVE: &str = "Dave"; - pub const EVE: &str = "Eve"; - pub const FERDIE: &str = "Ferdei"; - pub const ALICE_STASH: &str = "Alice//stash"; - pub const BOB_STASH: &str = "Bob//stash"; - - pub fn init_balances() -> Vec { - vec![ - get_account_id_from_seed::(ALICE), - get_account_id_from_seed::(BOB), - get_account_id_from_seed::(CHARLIE), - get_account_id_from_seed::(DAVE), - get_account_id_from_seed::(EVE), - get_account_id_from_seed::(ALICE_STASH), - get_account_id_from_seed::(BOB_STASH), - bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(), - ] - } -} - -pub mod collators { - use super::*; - - pub fn invulnerables_asset_hub_polkadot() -> Vec<(AccountId, AssetHubPolkadotAuraId)> { - vec![ - ( - get_account_id_from_seed::("Alice"), - get_from_seed::("Alice"), - ), - ( - get_account_id_from_seed::("Bob"), - get_from_seed::("Bob"), - ), - ] - } - - pub fn invulnerables() -> Vec<(AccountId, AuraId)> { - vec![ - ( - get_account_id_from_seed::("Alice"), - get_from_seed::("Alice"), - ), - (get_account_id_from_seed::("Bob"), get_from_seed::("Bob")), - ] - } -} - -pub mod validators { - use super::*; - - pub fn initial_authorities() -> Vec<( - AccountId, - AccountId, - BabeId, - GrandpaId, - ImOnlineId, - ValidatorId, - AssignmentId, - AuthorityDiscoveryId, - BeefyId, - )> { - let seed = "Alice"; - vec![( - get_account_id_from_seed::(&format!("{}//stash", seed)), - get_account_id_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - get_from_seed::(seed), - )] - } -} - -/// The default XCM version to set in genesis config. -const SAFE_XCM_VERSION: u32 = xcm::prelude::XCM_VERSION; - -// Polkadot -pub mod polkadot { - use super::*; - pub const ED: Balance = polkadot_runtime_constants::currency::EXISTENTIAL_DEPOSIT; - const STASH: u128 = 100 * polkadot_runtime_constants::currency::UNITS; - - pub fn get_host_config() -> HostConfiguration { - HostConfiguration { - max_upward_queue_count: 10, - max_upward_queue_size: 51200, - max_upward_message_size: 51200, - max_upward_message_num_per_candidate: 10, - max_downward_message_size: 51200, - hrmp_sender_deposit: 100_000_000_000, - hrmp_recipient_deposit: 100_000_000_000, - hrmp_channel_max_capacity: 1000, - hrmp_channel_max_message_size: 102400, - hrmp_channel_max_total_size: 102400, - hrmp_max_parachain_outbound_channels: 30, - hrmp_max_parachain_inbound_channels: 30, - ..Default::default() - } - } - - fn session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, - ) -> polkadot_runtime::SessionKeys { - polkadot_runtime::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } - } - - pub fn genesis() -> Storage { - let genesis_config = polkadot_runtime::RuntimeGenesisConfig { - system: polkadot_runtime::SystemConfig { - code: polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - session: polkadot_runtime::SessionConfig { - keys: validators::initial_authorities() - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - polkadot::session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - staking: polkadot_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() - .iter() - .map(|x| { - (x.0.clone(), x.1.clone(), STASH, polkadot_runtime::StakerStatus::Validator) - }) - .collect(), - invulnerables: validators::initial_authorities() - .iter() - .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::ForceNone, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: polkadot_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(polkadot_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - configuration: polkadot_runtime::ConfigurationConfig { config: get_host_config() }, - paras: polkadot_runtime::ParasConfig { - paras: vec![ - ( - asset_hub_polkadot::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - asset_hub_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - bridge_hub_polkadot::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - bridge_hub_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - bifrost_polkadot::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - bifrost_polkadot_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ], - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Kusama -pub mod kusama { - use super::*; - pub const ED: Balance = kusama_runtime_constants::currency::EXISTENTIAL_DEPOSIT; - use kusama_runtime_constants::currency::UNITS as KSM; - const ENDOWMENT: u128 = 1_000_000 * KSM; - const STASH: u128 = 100 * KSM; - - pub fn get_host_config() -> HostConfiguration { - HostConfiguration { - max_upward_queue_count: 10, - max_upward_queue_size: 51200, - max_upward_message_size: 51200, - max_upward_message_num_per_candidate: 10, - max_downward_message_size: 51200, - hrmp_sender_deposit: 5_000_000_000_000, - hrmp_recipient_deposit: 5_000_000_000_000, - hrmp_channel_max_capacity: 1000, - hrmp_channel_max_message_size: 102400, - hrmp_channel_max_total_size: 102400, - hrmp_max_parachain_outbound_channels: 30, - hrmp_max_parachain_inbound_channels: 30, - ..Default::default() - } - } - - fn session_keys( - babe: BabeId, - grandpa: GrandpaId, - im_online: ImOnlineId, - para_validator: ValidatorId, - para_assignment: AssignmentId, - authority_discovery: AuthorityDiscoveryId, - beefy: BeefyId, - ) -> kusama_runtime::SessionKeys { - kusama_runtime::SessionKeys { - babe, - grandpa, - im_online, - para_validator, - para_assignment, - authority_discovery, - beefy, - } - } - - pub fn genesis() -> Storage { - let genesis_config = kusama_runtime::RuntimeGenesisConfig { - system: kusama_runtime::SystemConfig { - code: kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ..Default::default() - }, - balances: kusama_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .map(|k: &AccountId| (k.clone(), ENDOWMENT)) - .collect(), - }, - session: kusama_runtime::SessionConfig { - keys: validators::initial_authorities() - .iter() - .map(|x| { - ( - x.0.clone(), - x.0.clone(), - kusama::session_keys( - x.2.clone(), - x.3.clone(), - x.4.clone(), - x.5.clone(), - x.6.clone(), - x.7.clone(), - x.8.clone(), - ), - ) - }) - .collect::>(), - }, - staking: kusama_runtime::StakingConfig { - validator_count: validators::initial_authorities().len() as u32, - minimum_validator_count: 1, - stakers: validators::initial_authorities() - .iter() - .map(|x| { - (x.0.clone(), x.1.clone(), STASH, kusama_runtime::StakerStatus::Validator) - }) - .collect(), - invulnerables: validators::initial_authorities() - .iter() - .map(|x| x.0.clone()) - .collect(), - force_era: pallet_staking::Forcing::NotForcing, - slash_reward_fraction: Perbill::from_percent(10), - ..Default::default() - }, - babe: kusama_runtime::BabeConfig { - authorities: Default::default(), - epoch_config: Some(kusama_runtime::BABE_GENESIS_EPOCH_CONFIG), - ..Default::default() - }, - configuration: kusama_runtime::ConfigurationConfig { config: get_host_config() }, - paras: kusama_runtime::ParasConfig { - paras: vec![ - ( - asset_hub_kusama::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - asset_hub_kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - bridge_hub_kusama::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - bridge_hub_kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ( - bifrost_kusama::PARA_ID.into(), - ParaGenesisArgs { - genesis_head: HeadData::default(), - validation_code: ValidationCode( - bifrost_kusama_runtime::WASM_BINARY.unwrap().to_vec(), - ), - para_kind: ParaKind::Parachain, - }, - ), - ], - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Asset Hub Polkadot -pub mod asset_hub_polkadot { - use super::*; - pub const PARA_ID: u32 = 1000; - pub const ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = asset_hub_polkadot_runtime::RuntimeGenesisConfig { - system: asset_hub_polkadot_runtime::SystemConfig { - code: asset_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: asset_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: asset_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables_asset_hub_polkadot() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: asset_hub_polkadot_runtime::SessionConfig { - keys: collators::invulnerables_asset_hub_polkadot() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_polkadot_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: asset_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Asset Hub Kusama -pub mod asset_hub_kusama { - use super::*; - pub const PARA_ID: u32 = 1000; - pub const ED: Balance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = asset_hub_kusama_runtime::RuntimeGenesisConfig { - system: asset_hub_kusama_runtime::SystemConfig { - code: asset_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: asset_hub_kusama_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: asset_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: asset_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: asset_hub_kusama_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - asset_hub_kusama_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: asset_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Bridge Hub Polkadot -pub mod bridge_hub_polkadot { - use super::*; - pub const PARA_ID: u32 = 1002; - pub const ED: Balance = parachains_common::polkadot::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = bridge_hub_polkadot_runtime::RuntimeGenesisConfig { - system: bridge_hub_polkadot_runtime::SystemConfig { - code: bridge_hub_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: bridge_hub_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: bridge_hub_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: bridge_hub_polkadot_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_polkadot_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: bridge_hub_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Bridge Hub Kusama -pub mod bridge_hub_kusama { - use super::*; - pub const PARA_ID: u32 = 1002; - pub const ED: Balance = parachains_common::kusama::currency::EXISTENTIAL_DEPOSIT; - - pub fn genesis() -> Storage { - let genesis_config = bridge_hub_kusama_runtime::RuntimeGenesisConfig { - system: bridge_hub_kusama_runtime::SystemConfig { - code: bridge_hub_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bridge_hub_kusama_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: bridge_hub_kusama_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: bridge_hub_kusama_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: bridge_hub_kusama_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bridge_hub_kusama_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: bridge_hub_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Asset Hub Polkadot -pub mod bifrost_polkadot { - use super::*; - use crate::BOB; - use bifrost_primitives::DOT; - pub const PARA_ID: u32 = 2030; - pub const ED: Balance = 10_000_000_000; - - pub fn genesis() -> Storage { - let genesis_config = bifrost_polkadot_runtime::RuntimeGenesisConfig { - system: bifrost_polkadot_runtime::SystemConfig { - code: bifrost_polkadot_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bifrost_polkadot_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 4096)) - .collect(), - }, - parachain_info: bifrost_polkadot_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - collator_selection: bifrost_polkadot_runtime::CollatorSelectionConfig { - invulnerables: collators::invulnerables_asset_hub_polkadot() - .iter() - .cloned() - .map(|(acc, _)| acc) - .collect(), - candidacy_bond: ED * 16, - ..Default::default() - }, - session: bifrost_polkadot_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bifrost_polkadot_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - polkadot_xcm: bifrost_polkadot_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - tokens: bifrost_polkadot_runtime::TokensConfig { - balances: vec![( - get_account_id_from_seed::(BOB), - DOT, - 10 * 10_000_000_000u128, - )], - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} - -// Asset Hub Polkadot -pub mod bifrost_kusama { - use super::*; - use crate::ALICE; - use bifrost_primitives::KSM; - - pub const PARA_ID: u32 = 2001; - pub const ED: Balance = 1_000_000_000_000; - - pub fn genesis() -> Storage { - let genesis_config = bifrost_kusama_runtime::RuntimeGenesisConfig { - system: bifrost_kusama_runtime::SystemConfig { - code: bifrost_kusama_runtime::WASM_BINARY - .expect("WASM binary was not build, please build it!") - .to_vec(), - ..Default::default() - }, - balances: bifrost_kusama_runtime::BalancesConfig { - balances: accounts::init_balances() - .iter() - .cloned() - .map(|k| (k, ED * 10_000_000)) - .collect(), - }, - parachain_info: bifrost_kusama_runtime::ParachainInfoConfig { - parachain_id: PARA_ID.into(), - ..Default::default() - }, - session: bifrost_kusama_runtime::SessionConfig { - keys: collators::invulnerables() - .into_iter() - .map(|(acc, aura)| { - ( - acc.clone(), // account id - acc, // validator id - bifrost_kusama_runtime::SessionKeys { aura }, // session keys - ) - }) - .collect(), - }, - // bifrost_parachain_staking: bifrost_kusama_runtime::ParachainStakingConfig { - // candidates: collators::candidates(), - // delegations: collators::delegations(), - // inflation_config: collators::inflation_config(), - // }, - polkadot_xcm: bifrost_kusama_runtime::PolkadotXcmConfig { - safe_xcm_version: Some(SAFE_XCM_VERSION), - ..Default::default() - }, - tokens: bifrost_kusama_runtime::TokensConfig { - balances: vec![( - get_account_id_from_seed::(ALICE), - KSM, - 10 * 1_000_000_000_000u128, - )], - }, - asset_registry: bifrost_kusama_runtime::AssetRegistryConfig { - currency: vec![(KSM, 10_000_000, None)], - vcurrency: vec![], - vsbond: vec![], - phantom: Default::default(), - }, - ..Default::default() - }; - - genesis_config.build_storage().unwrap() - } -} diff --git a/integration-tests/common/src/impls.rs b/integration-tests/common/src/impls.rs deleted file mode 100644 index 2eafefd9e..000000000 --- a/integration-tests/common/src/impls.rs +++ /dev/null @@ -1,662 +0,0 @@ -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub use parity_scale_codec::{Decode, Encode}; -pub use paste; - -pub use crate::{ - constants::{PROOF_SIZE_THRESHOLD, REF_TIME_THRESHOLD}, - xcm_helpers::xcm_transact_unpaid_execution, -}; - -// Substrate -pub use frame_support::{assert_ok, traits::fungibles::Inspect}; -pub use pallet_assets; -pub use pallet_message_queue; -use sp_core::Get; - -// Cumulus -use bp_messages::{ - target_chain::{DispatchMessage, DispatchMessageData, MessageDispatch}, - LaneId, MessageKey, OutboundLaneData, -}; -use bridge_runtime_common::messages_xcm_extension::XcmBlobMessageDispatchResult; -pub use cumulus_pallet_dmp_queue; -pub use cumulus_pallet_parachain_system; -pub use cumulus_pallet_xcmp_queue; -pub use cumulus_primitives_core::{ - relay_chain::HrmpChannelId, DmpMessageHandler, ParaId, XcmpMessageHandler, -}; -use pallet_bridge_messages::{Config, Instance1, OutboundLanes, Pallet}; -pub use parachains_common::{AccountId, Balance}; -pub use xcm_emulator::{ - assert_expected_events, bx, helpers::weight_within_threshold, BridgeMessage, - BridgeMessageDispatchError, BridgeMessageHandler, Chain, Parachain, RelayChain, TestExt, -}; - -// Polkadot -pub use pallet_xcm; -pub use polkadot_runtime_parachains::{ - dmp, hrmp, - inclusion::{AggregateMessageOrigin, UmpQueueId}, -}; -pub use xcm::{ - prelude::{OriginKind, Outcome, VersionedXcm, Weight}, - v3::Error, - DoubleEncoded, -}; - -pub struct BridgeHubMessageHandler { - _marker: std::marker::PhantomData<(S, T, I)>, -} - -struct LaneIdWrapper(LaneId); - -impl From for u32 { - fn from(lane_id: LaneIdWrapper) -> u32 { - u32::from_be_bytes(lane_id.0 .0) - } -} - -impl From for LaneIdWrapper { - fn from(id: u32) -> LaneIdWrapper { - LaneIdWrapper(LaneId(id.to_be_bytes())) - } -} - -// TODO: uncomment when https://github.com/polkadot-fellows/runtimes/pull/108 is merged -// type BridgeHubPolkadotRuntime = ::Runtime; -// type BridgeHubKusamaRuntime = ::Runtime; - -// TODO: uncomment when https://github.com/polkadot-fellows/runtimes/pull/108 is merged -// pub type PolkadotKusamaMessageHandler -// = BridgeHubMessageHandler; -// pub type KusamaPolkadotMessageHandler -// = BridgeHubMessageHandler; - -impl BridgeMessageHandler for BridgeHubMessageHandler -where - S: Config, - T: Config, - I: 'static, - >::InboundPayload: From>, - >::MessageDispatch: - MessageDispatch, -{ - fn get_source_outbound_messages() -> Vec { - // get the source active outbound lanes - let active_lanes = S::ActiveOutboundLanes::get(); - - let mut messages: Vec = Default::default(); - - // collect messages from `OutboundMessages` for each active outbound lane in the source - for lane in active_lanes { - let latest_generated_nonce = - OutboundLanes::::get(lane).latest_generated_nonce; - let latest_received_nonce = - OutboundLanes::::get(lane).latest_received_nonce; - - (latest_received_nonce + 1..=latest_generated_nonce).for_each(|nonce| { - let encoded_payload: Vec = - Pallet::::outbound_message_data(*lane, nonce) - .expect("Bridge message does not exist") - .into(); - let payload = Vec::::decode(&mut &encoded_payload[..]) - .expect("Decodign XCM message failed"); - let id: u32 = LaneIdWrapper(*lane).into(); - let message = BridgeMessage { id, nonce, payload }; - - messages.push(message); - }); - } - messages - } - - fn dispatch_target_inbound_message( - message: BridgeMessage, - ) -> Result<(), BridgeMessageDispatchError> { - type TargetMessageDispatch = >::MessageDispatch; - type InboundPayload = >::InboundPayload; - - let lane_id = LaneIdWrapper::from(message.id).0; - let nonce = message.nonce; - let payload = Ok(From::from(message.payload)); - - // Directly dispatch outbound messages assuming everything is correct - // and bypassing the `Relayers` and `InboundLane` logic - let dispatch_result = TargetMessageDispatch::::dispatch(DispatchMessage { - key: MessageKey { lane_id, nonce }, - data: DispatchMessageData::> { payload }, - }); - - let result = match dispatch_result.dispatch_level_result { - XcmBlobMessageDispatchResult::Dispatched => Ok(()), - XcmBlobMessageDispatchResult::InvalidPayload => Err(BridgeMessageDispatchError( - Box::new(XcmBlobMessageDispatchResult::InvalidPayload), - )), - XcmBlobMessageDispatchResult::NotDispatched(e) => Err(BridgeMessageDispatchError( - Box::new(XcmBlobMessageDispatchResult::NotDispatched(e)), - )), - }; - result - } - - fn notify_source_message_delivery(lane_id: u32) { - let data = OutboundLanes::::get(LaneIdWrapper::from(lane_id).0); - let new_data = OutboundLaneData { - oldest_unpruned_nonce: data.oldest_unpruned_nonce + 1, - latest_received_nonce: data.latest_received_nonce + 1, - ..data - }; - - OutboundLanes::::insert(LaneIdWrapper::from(lane_id).0, new_data); - } -} - -#[macro_export] -macro_rules! impl_test_accounts_helpers_for_chain { - ( $( $chain:ident),+ ) => { - xcm_emulator::paste::paste! { - xcm_emulator::parameter_types! { - $( - pub [<$chain Alice>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::ALICE); - pub [<$chain Bob>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::BOB); - pub [<$chain Charlie>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::CHARLIE); - pub [<$chain Dave>]: parachains_common::AccountId = <$chain as xcm_emulator::Chain>::account_id_of(constants::accounts::DAVE); - pub [<$chain Treasury>]: parachains_common::AccountId = bifrost_kusama_runtime::TreasuryPalletId::get().into_account_truncating(); - )+ - } - } - }; -} - -#[macro_export] -macro_rules! impl_accounts_helpers_for_relay_chain { - ( $chain:ident ) => { - $crate::impls::paste::paste! { - impl $chain { - /// Fund a set of accounts with a balance - pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) { - ::execute_with(|| { - for account in accounts { - $crate::impls::assert_ok!(]>::Balances::force_set_balance( - ::RuntimeOrigin::root(), - account.0.into(), - account.1, - )); - } - }); - } - /// Fund a sovereign account based on its Parachain Id - pub fn fund_para_sovereign(amount: $crate::impls::Balance, para_id: $crate::impls::ParaId) -> sp_runtime::AccountId32 { - let sovereign_account = ::sovereign_account_id_of_child_para(para_id); - Self::fund_accounts(vec![(sovereign_account.clone(), amount)]); - sovereign_account - } - } - } - }; -} - -#[macro_export] -macro_rules! impl_assert_events_helpers_for_relay_chain { - ( $chain:ident ) => { - $crate::impls::paste::paste! { - type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent; - - impl $chain { - /// Asserts a dispatchable is completely executed and XCM sent - pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::XcmPallet( - $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) } - ) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - }, - ] - ); - } - - /// Asserts a dispatchable is incompletely executed and XCM sent - pub fn assert_xcm_pallet_attempted_incomplete( - expected_weight: Option<$crate::impls::Weight>, - expected_error: Option<$crate::impls::Error>, - ) { - $crate::impls::assert_expected_events!( - Self, - vec![ - // Dispatchable is properly executed and XCM message sent - [<$chain RuntimeEvent>]::XcmPallet( - $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) } - ) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - error: *error == expected_error.unwrap_or(*error), - }, - ] - ); - } - - /// Asserts a XCM message is sent - pub fn assert_xcm_pallet_sent() { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::XcmPallet($crate::impls::pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - } - - /// Asserts a XCM from System Parachain is succesfully received and proccessed - pub fn assert_ump_queue_processed( - expected_success: bool, - expected_id: Option<$crate::impls::ParaId>, - expected_weight: Option<$crate::impls::Weight>, - ) { - $crate::impls::assert_expected_events!( - Self, - vec![ - // XCM is succesfully received and proccessed - [<$chain RuntimeEvent>]::MessageQueue($crate::impls::pallet_message_queue::Event::Processed { - origin: $crate::impls::AggregateMessageOrigin::Ump($crate::impls::UmpQueueId::Para(id)), - weight_used, - success, - .. - }) => { - id: *id == expected_id.unwrap_or(*id), - weight_used: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight_used), - *weight_used - ), - success: *success == expected_success, - }, - ] - ); - } - } - } - }; -} - -#[macro_export] -macro_rules! impl_hrmp_channels_helpers_for_relay_chain { - ( $chain:ident ) => { - $crate::impls::paste::paste! { - impl $chain { - /// Init open channel request with another Parachain - pub fn init_open_channel_call( - recipient_para_id: $crate::impls::ParaId, - max_capacity: u32, - max_message_size: u32, - ) -> $crate::impls::DoubleEncoded<()> { - use $crate::impls::Encode; - - ::RuntimeCall::Hrmp($crate::impls::hrmp::Call::< - ::Runtime, - >::hrmp_init_open_channel { - recipient: recipient_para_id, - proposed_max_capacity: max_capacity, - proposed_max_message_size: max_message_size, - }) - .encode() - .into() - } - /// Recipient Parachain accept the open request from another Parachain - pub fn accept_open_channel_call(sender_para_id: $crate::impls::ParaId) -> $crate::impls::DoubleEncoded<()> { - use $crate::impls::Encode; - - ::RuntimeCall::Hrmp($crate::impls::hrmp::Call::< - ::Runtime, - >::hrmp_accept_open_channel { - sender: sender_para_id, - }) - .encode() - .into() - } - - /// A root origin force to open a channel between two Parachains - pub fn force_process_hrmp_open(sender: $crate::impls::ParaId, recipient: $crate::impls::ParaId) { - use $crate::impls::Chain; - - ::execute_with(|| { - let relay_root_origin = ::RuntimeOrigin::root(); - - // Force process HRMP open channel requests without waiting for the next session - $crate::impls::assert_ok!(]>::Hrmp::force_process_hrmp_open( - relay_root_origin, - u32::MAX, - )); - - let channel_id = $crate::impls::HrmpChannelId { sender, recipient }; - - let hrmp_channel_exist = $crate::impls::hrmp::HrmpChannels::< - ::Runtime, - >::contains_key(&channel_id); - - // Check the HRMP channel has been successfully registrered - assert!(hrmp_channel_exist) - }); - } - } - } - }; -} - -#[macro_export] -macro_rules! impl_accounts_helpers_for_parachain { - ( $chain:ident ) => { - $crate::impls::paste::paste! { - impl $chain { - /// Fund a set of accounts with a balance - pub fn fund_accounts(accounts: Vec<($crate::impls::AccountId, $crate::impls::Balance)>) { - ::execute_with(|| { - for account in accounts { - $crate::impls::assert_ok!(]>::Balances::force_set_balance( - ::RuntimeOrigin::root(), - account.0.into(), - account.1, - )); - } - }); - } - } - } - }; -} - -#[macro_export] -macro_rules! impl_assert_events_helpers_for_parachain { - ( $chain:ident ) => { - $crate::impls::paste::paste! { - type [<$chain RuntimeEvent>] = <$chain as $crate::impls::Chain>::RuntimeEvent; - - impl $chain { - /// Asserts a dispatchable is completely executed and XCM sent - pub fn assert_xcm_pallet_attempted_complete(expected_weight: Option<$crate::impls::Weight>) { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::PolkadotXcm( - $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Complete(weight) } - ) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - }, - ] - ); - } - - /// Asserts a dispatchable is incompletely executed and XCM sent - pub fn assert_xcm_pallet_attempted_incomplete( - expected_weight: Option<$crate::impls::Weight>, - expected_error: Option<$crate::impls::Error>, - ) { - $crate::impls::assert_expected_events!( - Self, - vec![ - // Dispatchable is properly executed and XCM message sent - [<$chain RuntimeEvent>]::PolkadotXcm( - $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Incomplete(weight, error) } - ) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - error: *error == expected_error.unwrap_or(*error), - }, - ] - ); - } - - /// Asserts a dispatchable throws and error when trying to be sent - pub fn assert_xcm_pallet_attempted_error(expected_error: Option<$crate::impls::Error>) { - $crate::impls::assert_expected_events!( - Self, - vec![ - // Execution fails in the origin with `Barrier` - [<$chain RuntimeEvent>]::PolkadotXcm( - $crate::impls::pallet_xcm::Event::Attempted { outcome: $crate::impls::Outcome::Error(error) } - ) => { - error: *error == expected_error.unwrap_or(*error), - }, - ] - ); - } - - /// Asserts a XCM message is sent - pub fn assert_xcm_pallet_sent() { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::PolkadotXcm($crate::impls::pallet_xcm::Event::Sent { .. }) => {}, - ] - ); - } - - /// Asserts a XCM message is sent to Relay Chain - pub fn assert_parachain_system_ump_sent() { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::ParachainSystem( - $crate::impls::cumulus_pallet_parachain_system::Event::UpwardMessageSent { .. } - ) => {}, - ] - ); - } - - /// Asserts a XCM from Relay Chain is completely executed - pub fn assert_dmp_queue_complete(expected_weight: Option<$crate::impls::Weight>) { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::DmpQueue($crate::impls::cumulus_pallet_dmp_queue::Event::ExecutedDownward { - outcome: $crate::impls::Outcome::Complete(weight), .. - }) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - }, - ] - ); - } - - /// Asserts a XCM from Relay Chain is incompletely executed - pub fn assert_dmp_queue_incomplete( - expected_weight: Option<$crate::impls::Weight>, - expected_error: Option<$crate::impls::Error>, - ) { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::DmpQueue($crate::impls::cumulus_pallet_dmp_queue::Event::ExecutedDownward { - outcome: $crate::impls::Outcome::Incomplete(weight, error), .. - }) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - error: *error == expected_error.unwrap_or(*error), - }, - ] - ); - } - - /// Asserts a XCM from another Parachain is completely executed - pub fn assert_xcmp_queue_success(expected_weight: Option<$crate::impls::Weight>) { - $crate::impls::assert_expected_events!( - Self, - vec![ - [<$chain RuntimeEvent>]::XcmpQueue( - $crate::impls::cumulus_pallet_xcmp_queue::Event::Success { weight, .. } - ) => { - weight: $crate::impls::weight_within_threshold( - ($crate::impls::REF_TIME_THRESHOLD, $crate::impls::PROOF_SIZE_THRESHOLD), - expected_weight.unwrap_or(*weight), - *weight - ), - }, - ] - ); - } - } - } - }; -} - -#[macro_export] -macro_rules! impl_assets_helpers_for_parachain { - ( $chain:ident, $relay_chain:ident ) => { - $crate::impls::paste::paste! { - impl $chain { - /// Returns the encoded call for `force_create` from the assets pallet - pub fn force_create_asset_call( - asset_id: u32, - owner: $crate::impls::AccountId, - is_sufficient: bool, - min_balance: $crate::impls::Balance, - ) -> $crate::impls::DoubleEncoded<()> { - use $crate::impls::{Chain, Encode}; - - ::RuntimeCall::Assets($crate::impls::pallet_assets::Call::< - ::Runtime, - $crate::impls::pallet_assets::Instance1, - >::force_create { - id: asset_id.into(), - owner: owner.into(), - is_sufficient, - min_balance, - }) - .encode() - .into() - } - - /// Returns a `VersionedXcm` for `force_create` from the assets pallet - pub fn force_create_asset_xcm( - origin_kind: $crate::impls::OriginKind, - asset_id: u32, - owner: $crate::impls::AccountId, - is_sufficient: bool, - min_balance: $crate::impls::Balance, - ) -> $crate::impls::VersionedXcm<()> { - let call = Self::force_create_asset_call(asset_id, owner, is_sufficient, min_balance); - $crate::impls::xcm_transact_unpaid_execution(call, origin_kind) - } - - /// Mint assets making use of the assets pallet - pub fn mint_asset( - signed_origin: ::RuntimeOrigin, - id: u32, - beneficiary: $crate::impls::AccountId, - amount_to_mint: u128, - ) { - ::execute_with(|| { - $crate::impls::assert_ok!(]>::Assets::mint( - signed_origin, - id.into(), - beneficiary.clone().into(), - amount_to_mint - )); - - type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; - - $crate::impls::assert_expected_events!( - Self, - vec![ - RuntimeEvent::Assets($crate::impls::pallet_assets::Event::Issued { asset_id, owner, amount }) => { - asset_id: *asset_id == id, - owner: *owner == beneficiary.clone().into(), - amount: *amount == amount_to_mint, - }, - ] - ); - }); - } - - /// Force create and mint assets making use of the assets pallet - pub fn force_create_and_mint_asset( - id: u32, - min_balance: u128, - is_sufficient: bool, - asset_owner: $crate::impls::AccountId, - amount_to_mint: u128, - ) { - use $crate::impls::{bx, Chain, RelayChain, Parachain, Inspect, TestExt}; - // Init values for Relay Chain - let root_origin = <$relay_chain as Chain>::RuntimeOrigin::root(); - let destination = <$relay_chain>::child_location_of(<$chain>::para_id()); - let xcm = Self::force_create_asset_xcm( - $crate::impls::OriginKind::Superuser, - id, - asset_owner.clone(), - is_sufficient, - min_balance, - ); - - <$relay_chain>::execute_with(|| { - $crate::impls::assert_ok!(<$relay_chain as [<$relay_chain Pallet>]>::XcmPallet::send( - root_origin, - bx!(destination.into()), - bx!(xcm), - )); - - <$relay_chain>::assert_xcm_pallet_sent(); - }); - - Self::execute_with(|| { - Self::assert_dmp_queue_complete(Some($crate::impls::Weight::from_parts(1_020_000_000, 200_000))); - - type RuntimeEvent = <$chain as $crate::impls::Chain>::RuntimeEvent; - - $crate::impls::assert_expected_events!( - Self, - vec![ - // Asset has been created - RuntimeEvent::Assets($crate::impls::pallet_assets::Event::ForceCreated { asset_id, owner }) => { - asset_id: *asset_id == id, - owner: *owner == asset_owner.clone(), - }, - ] - ); - - assert!(]>::Assets::asset_exists(id.into())); - }); - - let signed_origin = ::RuntimeOrigin::signed(asset_owner.clone()); - - // Mint asset for System Parachain's sender - Self::mint_asset(signed_origin, id, asset_owner, amount_to_mint); - } - } - } - }; -} diff --git a/integration-tests/common/src/lib.rs b/integration-tests/common/src/lib.rs deleted file mode 100644 index d2e1c5faf..000000000 --- a/integration-tests/common/src/lib.rs +++ /dev/null @@ -1,248 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -pub mod constants; -pub mod impls; -pub mod xcm_helpers; - -pub use constants::{ - accounts::{ALICE, BOB}, - bifrost_kusama, bifrost_polkadot, kusama, polkadot, -}; - -// Substrate -use frame_support::traits::OnInitialize; - -// Cumulus -use crate::constants::{ - asset_hub_kusama, asset_hub_polkadot, bridge_hub_kusama, bridge_hub_polkadot, -}; -use polkadot_primitives::runtime_api::runtime_decl_for_parachain_host::ParachainHostV7; -use sp_runtime::traits::AccountIdConversion; -use xcm_emulator::{ - decl_test_networks, decl_test_parachains, decl_test_relay_chains, DefaultMessageProcessor, -}; - -decl_test_relay_chains! { - #[api_version(5)] - pub struct Polkadot { - genesis = polkadot::genesis(), - on_init = (), - runtime = polkadot_runtime, - core = { - MessageProcessor: DefaultMessageProcessor, - SovereignAccountOf: polkadot_runtime::xcm_config::SovereignAccountOf, - }, - pallets = { - System: polkadot_runtime::System, - XcmPallet: polkadot_runtime::XcmPallet, - Balances: polkadot_runtime::Balances, - Hrmp: polkadot_runtime::Hrmp, - } - }, - #[api_version(5)] - pub struct Kusama { - genesis = kusama::genesis(), - on_init = (), - runtime = kusama_runtime, - core = { - MessageProcessor: DefaultMessageProcessor, - SovereignAccountOf: kusama_runtime::xcm_config::SovereignAccountOf, - }, - pallets = { - System: kusama_runtime::System, - XcmPallet: kusama_runtime::XcmPallet, - Balances: kusama_runtime::Balances, - Hrmp: kusama_runtime::Hrmp, - Referenda: kusama_runtime::Referenda, - } - } -} - -decl_test_parachains! { - // Polkadot Parachains - pub struct BifrostPolkadot { - genesis = bifrost_polkadot::genesis(), - on_init = { - bifrost_polkadot_runtime::AuraExt::on_initialize(1); - }, - runtime = bifrost_polkadot_runtime, - core = { - XcmpMessageHandler: bifrost_polkadot_runtime::XcmpQueue, - DmpMessageHandler: bifrost_polkadot_runtime::DmpQueue, - LocationToAccountId: bifrost_polkadot_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bifrost_polkadot_runtime::ParachainInfo, - }, - pallets = { - System: bifrost_polkadot_runtime::System, - PolkadotXcm: bifrost_polkadot_runtime::PolkadotXcm, - Tokens: bifrost_polkadot_runtime::Tokens, - XTokens: bifrost_polkadot_runtime::XTokens, - Balances: bifrost_polkadot_runtime::Balances, - } - }, - pub struct AssetHubPolkadot { - genesis = asset_hub_polkadot::genesis(), - on_init = { - asset_hub_polkadot_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_polkadot_runtime, - core = { - XcmpMessageHandler: asset_hub_polkadot_runtime::XcmpQueue, - DmpMessageHandler: asset_hub_polkadot_runtime::DmpQueue, - LocationToAccountId: asset_hub_polkadot_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_polkadot_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_polkadot_runtime::PolkadotXcm, - Assets: asset_hub_polkadot_runtime::Assets, - Balances: asset_hub_polkadot_runtime::Balances, - } - }, - pub struct BridgeHubPolkadot { - genesis = bridge_hub_polkadot::genesis(), - on_init = { - bridge_hub_polkadot_runtime::AuraExt::on_initialize(1); - }, - runtime = bridge_hub_polkadot_runtime, - core = { - XcmpMessageHandler: bridge_hub_polkadot_runtime::XcmpQueue, - DmpMessageHandler: bridge_hub_polkadot_runtime::DmpQueue, - LocationToAccountId: bridge_hub_polkadot_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bridge_hub_polkadot_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: bridge_hub_polkadot_runtime::PolkadotXcm, - } - }, - // Kusama Parachains - pub struct BifrostKusama { - genesis = bifrost_kusama::genesis(), - on_init = { - bifrost_kusama_runtime::AuraExt::on_initialize(1); - }, - runtime = bifrost_kusama_runtime, - core = { - XcmpMessageHandler: bifrost_kusama_runtime::XcmpQueue, - DmpMessageHandler: bifrost_kusama_runtime::DmpQueue, - LocationToAccountId: bifrost_kusama_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bifrost_kusama_runtime::ParachainInfo, - }, - pallets = { - System: bifrost_kusama_runtime::System, - PolkadotXcm: bifrost_kusama_runtime::PolkadotXcm, - Tokens: bifrost_kusama_runtime::Tokens, - XTokens: bifrost_kusama_runtime::XTokens, - Balances: bifrost_kusama_runtime::Balances, - } - }, - pub struct AssetHubKusama { - genesis = asset_hub_kusama::genesis(), - on_init = { - asset_hub_kusama_runtime::AuraExt::on_initialize(1); - }, - runtime = asset_hub_kusama_runtime, - core = { - XcmpMessageHandler: asset_hub_kusama_runtime::XcmpQueue, - DmpMessageHandler: asset_hub_kusama_runtime::DmpQueue, - LocationToAccountId: asset_hub_kusama_runtime::xcm_config::LocationToAccountId, - ParachainInfo: asset_hub_kusama_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: asset_hub_kusama_runtime::PolkadotXcm, - Assets: asset_hub_kusama_runtime::Assets, - ForeignAssets: asset_hub_kusama_runtime::ForeignAssets, - PoolAssets: asset_hub_kusama_runtime::PoolAssets, - AssetConversion: asset_hub_kusama_runtime::AssetConversion, - Balances: asset_hub_kusama_runtime::Balances, - } - }, - pub struct BridgeHubKusama { - genesis = bridge_hub_kusama::genesis(), - on_init = { - bridge_hub_kusama_runtime::AuraExt::on_initialize(1); - }, - runtime = bridge_hub_kusama_runtime, - core = { - XcmpMessageHandler: bridge_hub_kusama_runtime::XcmpQueue, - DmpMessageHandler: bridge_hub_kusama_runtime::DmpQueue, - LocationToAccountId: bridge_hub_kusama_runtime::xcm_config::LocationToAccountId, - ParachainInfo: bridge_hub_kusama_runtime::ParachainInfo, - }, - pallets = { - PolkadotXcm: bridge_hub_kusama_runtime::PolkadotXcm, - } - }, -} - -decl_test_networks! { - pub struct PolkadotMockNet { - relay_chain = Polkadot, - parachains = vec![ - BifrostPolkadot, - AssetHubPolkadot, - BridgeHubPolkadot, - ], - // TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged - // bridge = PolkadotKusamaMockBridge - bridge = () - }, - pub struct KusamaMockNet { - relay_chain = Kusama, - parachains = vec![ - BifrostKusama, - AssetHubKusama, - BridgeHubKusama, - ], - // TODO: uncomment when https://github.com/paritytech/cumulus/pull/2528 is merged - // bridge = KusamaPolkadotMockBridge - bridge = () - }, -} - -// Polkadot implementation -impl_accounts_helpers_for_relay_chain!(Polkadot); -impl_assert_events_helpers_for_relay_chain!(Polkadot); -impl_hrmp_channels_helpers_for_relay_chain!(Polkadot); - -// Kusama implementation -impl_accounts_helpers_for_relay_chain!(Kusama); -impl_assert_events_helpers_for_relay_chain!(Kusama); -impl_hrmp_channels_helpers_for_relay_chain!(Kusama); - -// BifrostPolkadot implementation -impl_accounts_helpers_for_parachain!(BifrostPolkadot); -impl_assert_events_helpers_for_parachain!(BifrostPolkadot); - -// BifrostKusama implementation -impl_accounts_helpers_for_parachain!(BifrostKusama); -impl_assert_events_helpers_for_parachain!(BifrostKusama); - -// AssetHubPolkadot implementation -impl_accounts_helpers_for_parachain!(AssetHubPolkadot); -impl_assets_helpers_for_parachain!(AssetHubPolkadot, Polkadot); -impl_assert_events_helpers_for_parachain!(AssetHubPolkadot); - -// AssetHubKusama implementation -impl_accounts_helpers_for_parachain!(AssetHubKusama); -impl_assets_helpers_for_parachain!(AssetHubKusama, Kusama); -impl_assert_events_helpers_for_parachain!(AssetHubKusama); - -impl_test_accounts_helpers_for_chain! { - Polkadot, Kusama, BifrostPolkadot, BifrostKusama -} diff --git a/integration-tests/common/src/xcm_helpers.rs b/integration-tests/common/src/xcm_helpers.rs deleted file mode 100644 index cd5fe1a98..000000000 --- a/integration-tests/common/src/xcm_helpers.rs +++ /dev/null @@ -1,68 +0,0 @@ -// This file is part of Bifrost. - -// Copyright (C) Liebi Technologies PTE. LTD. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program 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. - -// This program 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 this program. If not, see . - -use parachains_common::AccountId; -use xcm::{ - prelude::{ - AccountId32, All, BuyExecution, DepositAsset, MultiAsset, MultiAssets, MultiLocation, - OriginKind, RefundSurplus, Transact, UnpaidExecution, VersionedXcm, Weight, WeightLimit, - WithdrawAsset, Xcm, X1, - }, - DoubleEncoded, -}; - -/// Helper method to build a XCM with a `Transact` instruction and paying for its execution -pub fn xcm_transact_paid_execution( - call: DoubleEncoded<()>, - origin_kind: OriginKind, - native_asset: MultiAsset, - beneficiary: AccountId, -) -> VersionedXcm<()> { - let weight_limit = WeightLimit::Unlimited; - let require_weight_at_most = Weight::from_parts(1000000000, 200000); - let native_assets: MultiAssets = native_asset.clone().into(); - - VersionedXcm::from(Xcm(vec![ - WithdrawAsset(native_assets), - BuyExecution { fees: native_asset, weight_limit }, - Transact { require_weight_at_most, origin_kind, call }, - RefundSurplus, - DepositAsset { - assets: All.into(), - beneficiary: MultiLocation { - parents: 0, - interior: X1(AccountId32 { network: None, id: beneficiary.into() }), - }, - }, - ])) -} - -/// Helper method to build a XCM with a `Transact` instruction without paying for its execution -pub fn xcm_transact_unpaid_execution( - call: DoubleEncoded<()>, - origin_kind: OriginKind, -) -> VersionedXcm<()> { - let weight_limit = WeightLimit::Unlimited; - let require_weight_at_most = Weight::from_parts(1000000000, 200000); - let check_origin = None; - - VersionedXcm::from(Xcm(vec![ - UnpaidExecution { weight_limit, check_origin }, - Transact { require_weight_at_most, origin_kind, call }, - ])) -} diff --git a/integration-tests/bifrost-polkadot/src/lib.rs b/integration-tests/src/lib.rs similarity index 97% rename from integration-tests/bifrost-polkadot/src/lib.rs rename to integration-tests/src/lib.rs index 122d5b2fd..99ac59f58 100644 --- a/integration-tests/bifrost-polkadot/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -17,3 +17,6 @@ // along with this program. If not, see . #![cfg(test)] + +mod mock; +mod tests; diff --git a/integration-tests/src/mock/bifrost.rs b/integration-tests/src/mock/bifrost.rs new file mode 100644 index 000000000..b76157e29 --- /dev/null +++ b/integration-tests/src/mock/bifrost.rs @@ -0,0 +1,334 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ConstU32, Everything, Nothing}, + weights::{constants::WEIGHT_REF_TIME_PER_SECOND, Weight}, +}; +use frame_system::EnsureRoot; +use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key}; +use sp_runtime::{traits::IdentityLookup, AccountId32}; +use sp_std::prelude::*; + +use crate::mock::{mock_message_queue, Amount}; +use bifrost_asset_registry::AssetIdMaps; +use bifrost_polkadot_runtime::{ + xcm_config::{ + BaseXcmWeight, BifrostAccountIdToLocation, BifrostAssetTransactor, MaxAssetsForTransfer, + ParachainMinFee, SelfRelativeLocation, UniversalLocation, + }, + BifrostCurrencyIdConvert, BifrostTreasuryAccount, MaxLengthLimit, MaxRefundPerBlock, + MaxTypeEntryPerBlock, NativeCurrencyId, SelfParaChainId, SubAccountIndexMultiLocationConvertor, + VtokenMinting, XcmInterface, +}; +use bifrost_primitives::CurrencyId; +use bifrost_slp::QueryResponseManager; +use pallet_xcm::{QueryStatus, XcmPassthrough}; +use polkadot_parachain_primitives::primitives::Sibling; +use xcm::latest::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowUnpaidExecutionFrom, EnsureXcmOrigin, FixedRateOfFungible, + FixedWeightBounds, FrameTransactionalProcessor, NativeAsset, ParentIsPreset, + SiblingParachainConvertsVia, SignedAccountId32AsNative, SignedToAccountId32, + SovereignSignedViaLocation, +}; +use xcm_executor::{traits::QueryHandler, Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; +pub type BlockNumber = u64; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type AccountData = pallet_balances::AccountData; +} + +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 = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +impl parachain_info::Config for Runtime {} + +parameter_type_with_key! { + pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { + Default::default() + }; +} + +impl orml_tokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type Amount = Amount; + type CurrencyId = CurrencyId; + type WeightInfo = (); + type ExistentialDeposits = ExistentialDeposits; + type CurrencyHooks = (); + type MaxLocks = ConstU32<50>; + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; + type DustRemovalWhitelist = Everything; +} + +parameter_types! { + pub const XtokensRateLimiterId: u8 = 0; +} + +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = BifrostCurrencyIdConvert; + type AccountIdToLocation = BifrostAccountIdToLocation; + type SelfLocation = SelfRelativeLocation; + type LocationsFilter = Everything; + type MinXcmFee = ParachainMinFee; + type XcmExecutor = XcmExecutor; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type UniversalLocation = UniversalLocation; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); +} + +parameter_types! { + pub const ReservedXcmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); + pub const ReservedDmpWeight: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_div(4), 0); +} + +parameter_types! { + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = NetworkId::Kusama; +} + +pub type LocationToAccountId = ( + ParentIsPreset, + SiblingParachainConvertsVia, + AccountId32Aliases, +); + +pub type XcmOriginToCallOrigin = ( + SovereignSignedViaLocation, + SignedAccountId32AsNative, + XcmPassthrough, +); + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(1, 1); + pub KsmPerSecondPerByte: (AssetId, u128, u128) = (AssetId(Parent.into()), 1, 1); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +pub type XcmRouter = super::ParachainXcmRouter; +pub type Barrier = AllowUnpaidExecutionFrom; + +pub struct XcmConfig; +impl Config for XcmConfig { + type RuntimeCall = RuntimeCall; + type XcmSender = XcmRouter; + type AssetTransactor = BifrostAssetTransactor; + type OriginConverter = XcmOriginToCallOrigin; + type IsReserve = NativeAsset; + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type Barrier = Barrier; + type Weigher = FixedWeightBounds; + type Trader = FixedRateOfFungible; + type ResponseHandler = (); + type AssetTrap = (); + type AssetLocker = (); + type AssetExchanger = (); + type AssetClaims = (); + type SubscriptionService = (); + type PalletInstancesInfo = (); + type FeeManager = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; +} + +impl mock_message_queue::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type XcmExecutor = XcmExecutor; +} + +pub type LocalOriginToLocation = SignedToAccountId32; + +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 = 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 = LocationToAccountId; + type MaxLockers = ConstU32<8>; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; +} + +impl bifrost_currencies::Config for Runtime { + type GetNativeCurrencyId = NativeCurrencyId; + type MultiCurrency = Tokens; + type NativeCurrency = + bifrost_currencies::BasicCurrencyAdapter; + type WeightInfo = (); +} + +// impl bifrost_xcm_interface::Config for Runtime { +// type RuntimeEvent = RuntimeEvent; +// type UpdateOrigin = EnsureRoot; +// type MultiCurrency = Currencies; +// type RelayNetwork = bifrost_polkadot_runtime::xcm_config::RelayNetwork; +// type RelaychainCurrencyId = RelayCurrencyId; +// type ParachainSovereignAccount = ParachainAccount; +// type XcmExecutor = XcmExecutor; +// type AccountIdToLocation = BifrostAccountIdToLocation; +// type SalpHelper = Salp; +// type ParachainId = SelfParaChainId; +// type CallBackTimeOut = ConstU32<10>; +// type CurrencyIdConvert = AssetIdMaps; +// } + +pub struct SubstrateResponseManager; +impl QueryResponseManager + for SubstrateResponseManager +{ + fn get_query_response_record(query_id: QueryId) -> bool { + if let Some(QueryStatus::Ready { .. }) = PolkadotXcm::query(query_id) { + true + } else { + false + } + } + + fn create_query_record( + responder: Location, + call_back: Option, + timeout: BlockNumber, + ) -> u64 { + if let Some(call_back) = call_back { + PolkadotXcm::new_notify_query(responder.clone(), call_back, timeout, Here) + } else { + PolkadotXcm::new_query(responder, timeout, Here) + } + } + + fn remove_query_record(query_id: bifrost_slp::QueryId) -> bool { + // Temporarily banned. Querries from pallet_xcm cannot be removed unless it is in ready + // status. And we are not allowed to mannually change query status. + // So in the manual mode, it is not possible to remove the query at all. + // PolkadotXcm::take_response(query_id).is_some() + + PolkadotXcm::take_response(query_id); + true + } +} + +impl bifrost_slp::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type MultiCurrency = Currencies; + type ControlOrigin = EnsureRoot; + type WeightInfo = (); + type VtokenMinting = VtokenMinting; + type AccountConverter = SubAccountIndexMultiLocationConvertor; + type ParachainId = SelfParaChainId; + type SubstrateResponseManager = SubstrateResponseManager; + type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; + type MaxRefundPerBlock = MaxRefundPerBlock; + type ParachainStaking = (); + type XcmTransfer = XTokens; + type MaxLengthLimit = MaxLengthLimit; + type XcmWeightAndFeeHandler = XcmInterface; + type ChannelCommission = (); + type StablePoolHandler = (); + type AssetIdMaps = AssetIdMaps; + type TreasuryAccount = BifrostTreasuryAccount; +} + +impl bifrost_asset_registry::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type RegisterOrigin = EnsureRoot; + type WeightInfo = (); +} + +type Block = frame_system::mocking::MockBlock; + +construct_runtime!( + pub enum Runtime + { + System: frame_system, + ParachainInfo: parachain_info, + Balances: pallet_balances, + MessageQueue: mock_message_queue, + PolkadotXcm: pallet_xcm, + Tokens: orml_tokens, + XTokens: orml_xtokens, + Currencies: bifrost_currencies, + Slp: bifrost_slp, + AssetRegistry: bifrost_asset_registry + } +); diff --git a/integration-tests/src/mock/mock_message_queue/mod.rs b/integration-tests/src/mock/mock_message_queue/mod.rs new file mode 100644 index 000000000..d209c1074 --- /dev/null +++ b/integration-tests/src/mock/mock_message_queue/mod.rs @@ -0,0 +1,184 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use cumulus_primitives_core::{ParaId, XcmpMessageFormat, XcmpMessageHandler}; +use frame_support::pallet_prelude::*; +use parity_scale_codec::{Decode, Encode}; +use polkadot_parachain_primitives::primitives::DmpMessageHandler; +use sp_std::prelude::*; +use xcm::{ + v4::{prelude::*, Weight}, + VersionedXcm, +}; + +pub use module::*; + +#[frame_support::pallet] +pub mod module { + use super::*; + + type RelayBlockNumber = u32; + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type XcmExecutor: ExecuteXcm; + } + + #[pallet::call] + impl Pallet {} + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::storage] + #[pallet::getter(fn parachain_id)] + pub(super) type ParachainId = StorageValue<_, ParaId, ValueQuery>; + + #[pallet::storage] + #[pallet::getter(fn received_dmp)] + /// A queue of received DMP messages + pub(super) type ReceivedDmp = StorageValue<_, Vec>, 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 { + use sp_runtime::traits::Hash; + let hash = Encode::using_encoded(&xcm, T::Hashing::hash); + let mut message_hash = Encode::using_encoded(&xcm, sp_io::hashing::blake2_256); + let (result, event) = match Xcm::::try_from(xcm) { + Ok(xcm) => { + let location = (Parent, Parachain(sender.into())); + match T::XcmExecutor::prepare_and_execute( + location, + xcm, + &mut message_hash, + max_weight, + Weight::zero(), + ) { + Outcome::Error { error } => (Err(error), 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 (_sent_at, data) in iter { + let mut id = sp_io::hashing::blake2_256(&data[..]); + let maybe_versioned = VersionedXcm::::decode(&mut &data[..]); + match maybe_versioned { + Err(_) => { + Self::deposit_event(Event::InvalidFormat(id)); + }, + Ok(versioned) => match Xcm::try_from(versioned) { + Err(()) => Self::deposit_event(Event::UnsupportedVersion(id)), + Ok(x) => { + let outcome = T::XcmExecutor::prepare_and_execute( + Parent, + x.clone(), + &mut id, + limit, + Weight::zero(), + ); + >::append(x); + Self::deposit_event(Event::ExecutedDownward(id, outcome)); + }, + }, + } + } + limit + } + } +} diff --git a/integration-tests/src/mock/mod.rs b/integration-tests/src/mock/mod.rs new file mode 100644 index 000000000..d7423adf0 --- /dev/null +++ b/integration-tests/src/mock/mod.rs @@ -0,0 +1,101 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +pub mod bifrost; +mod mock_message_queue; +pub mod relaychain; + +use bifrost_primitives::CurrencyId; +use sp_io::TestExternalities; +use sp_runtime::{AccountId32, BuildStorage}; +use xcm_simulator::{decl_test_network, decl_test_parachain, decl_test_relay_chain, TestExt}; + +pub const ALICE: AccountId32 = AccountId32::new([0u8; 32]); +pub const BOB: AccountId32 = AccountId32::new([1u8; 32]); +pub type Amount = i128; + +decl_test_parachain! { + pub struct Bifrost { + Runtime = bifrost::Runtime, + XcmpMessageHandler = bifrost::MessageQueue, + DmpMessageHandler = bifrost::MessageQueue, + new_ext = para_ext(2030), + } +} + +decl_test_relay_chain! { + pub struct Relay { + Runtime = relaychain::Runtime, + RuntimeCall = relaychain::RuntimeCall, + RuntimeEvent = relaychain::RuntimeEvent, + XcmConfig = relaychain::XcmConfig, + MessageQueue = relaychain::MessageQueue, + System = relaychain::System, + new_ext = relay_ext(), + } +} + +decl_test_network! { + pub struct TestNet { + relay_chain = Relay, + parachains = vec![ + (2030, Bifrost), + ], + } +} + +pub type BifrostTokens = orml_tokens::Pallet; +pub type BifrostXTokens = orml_xtokens::Pallet; +pub type BifrostSlp = bifrost_slp::Pallet; + +pub type RelayBalances = pallet_balances::Pallet; +pub type RelaySystem = frame_system::Pallet; +pub type RelayXcmPallet = pallet_xcm::Pallet; + +pub fn para_ext(para_id: u32) -> TestExternalities { + use bifrost::{MessageQueue, Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + orml_tokens::GenesisConfig:: { + balances: vec![(ALICE, CurrencyId::Token2(0), 100_000_000_000)], + } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = TestExternalities::new(t); + ext.execute_with(|| { + System::set_block_number(1); + MessageQueue::set_para_id(para_id.into()); + }); + ext +} + +pub fn relay_ext() -> TestExternalities { + use relaychain::{Runtime, System}; + + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + + pallet_balances::GenesisConfig:: { balances: vec![(ALICE, 100_000_000_000)] } + .assimilate_storage(&mut t) + .unwrap(); + + let mut ext = TestExternalities::new(t); + ext.execute_with(|| System::set_block_number(1)); + ext +} diff --git a/integration-tests/src/mock/relaychain.rs b/integration-tests/src/mock/relaychain.rs new file mode 100644 index 000000000..6772a2580 --- /dev/null +++ b/integration-tests/src/mock/relaychain.rs @@ -0,0 +1,222 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use cumulus_primitives_core::ParaId; +use frame_support::{ + construct_runtime, derive_impl, parameter_types, + traits::{ConstU128, ConstU32, Everything, Nothing, ProcessMessage, ProcessMessageError}, + weights::{IdentityFee, WeightMeter}, +}; +use frame_system::EnsureRoot; +use polkadot_runtime_parachains::{ + configuration, + inclusion::{AggregateMessageOrigin, UmpQueueId}, + origin, shared, +}; +use sp_runtime::{traits::IdentityLookup, AccountId32}; +use xcm::v4::prelude::*; +use xcm_builder::{ + AccountId32Aliases, AllowTopLevelPaidExecutionFrom, ChildParachainAsNative, + ChildParachainConvertsVia, FixedWeightBounds, FungibleAdapter, IsConcrete, + SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation, TakeWeightCredit, + UsingComponents, +}; +use xcm_executor::{Config, XcmExecutor}; + +pub type AccountId = AccountId32; +pub type Balance = u128; + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountId = AccountId; + type Lookup = IdentityLookup; + type Block = Block; + type AccountData = pallet_balances::AccountData; +} + +impl pallet_balances::Config for Runtime { + type MaxLocks = ConstU32<50>; + type Balance = Balance; + type RuntimeEvent = RuntimeEvent; + type DustRemoval = (); + type ExistentialDeposit = ConstU128<1>; + type AccountStore = System; + type WeightInfo = (); + type MaxReserves = ConstU32<50>; + type ReserveIdentifier = [u8; 8]; + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = [u8; 8]; + type MaxFreezes = (); +} + +impl shared::Config for Runtime { + type DisabledValidators = (); +} + +impl configuration::Config for Runtime { + type WeightInfo = configuration::TestWeightInfo; +} + +parameter_types! { + pub DotLocation: Location = Here.into(); + pub const PolkadotNetwork: NetworkId = NetworkId::Polkadot; + pub UniversalLocation: InteriorLocation = [GlobalConsensus(PolkadotNetwork::get())].into(); +} + +pub type SovereignAccountOf = + (ChildParachainConvertsVia, AccountId32Aliases); + +pub type LocalAssetTransactor = + FungibleAdapter, SovereignAccountOf, AccountId, ()>; + +type LocalOriginConverter = ( + SovereignSignedViaLocation, + ChildParachainAsNative, + SignedAccountId32AsNative, +); + +pub type XcmRouter = super::RelayChainXcmRouter; +pub type Barrier = (TakeWeightCredit, AllowTopLevelPaidExecutionFrom); + +parameter_types! { + pub Polkadot: AssetFilter = Wild(AllOf { fun: WildFungible, id: AssetId(DotLocation::get()) }); + pub Statemine: Location = Parachain(3).into(); + pub PolkadotForStatemine: (AssetFilter, Location) = (Polkadot::get(), Statemine::get()); +} + +pub type TrustedTeleporters = xcm_builder::Case; + +parameter_types! { + pub const UnitWeightCost: Weight = Weight::from_parts(10, 10); + pub const BaseXcmWeight: Weight = Weight::from_parts(100_000_000, 100_000_000); + pub const MaxInstructions: u32 = 100; + pub const MaxAssetsIntoHolding: u32 = 64; +} + +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 = Barrier; + type Weigher = FixedWeightBounds; + type Trader = UsingComponents, DotLocation, AccountId, Balances, ()>; + type ResponseHandler = (); + type AssetTrap = (); + type AssetClaims = (); + type SubscriptionService = XcmPallet; + type AssetLocker = XcmPallet; + type AssetExchanger = (); + type PalletInstancesInfo = (); + type MaxAssetsIntoHolding = MaxAssetsIntoHolding; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type Aliasers = (); + 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 = Everything; + 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 AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); +} + +impl origin::Config for Runtime {} + +type Block = frame_system::mocking::MockBlock; + +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, + }; + xcm_builder::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 QueuePausedQuery = (); + type WeightInfo = (); +} + +construct_runtime!( + pub enum Runtime { + System: frame_system, + Balances: pallet_balances, + ParasOrigin: origin, + MessageQueue: pallet_message_queue, + XcmPallet: pallet_xcm, + } +); diff --git a/integration-tests/bifrost-kusama/src/lib.rs b/integration-tests/src/tests/mod.rs similarity index 84% rename from integration-tests/bifrost-kusama/src/lib.rs rename to integration-tests/src/tests/mod.rs index a96e16acb..2639991d6 100644 --- a/integration-tests/bifrost-kusama/src/lib.rs +++ b/integration-tests/src/tests/mod.rs @@ -16,13 +16,5 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -#![cfg(test)] -mod account_id; -mod dollor_tests; -mod general_key; -mod transact; -// mod salp; +mod send_relay_chain_asset; mod slp; -mod total_issuance; -mod vtoken_minting; -mod vtoken_voting; diff --git a/integration-tests/src/tests/send_relay_chain_asset.rs b/integration-tests/src/tests/send_relay_chain_asset.rs new file mode 100644 index 000000000..86e14aaf3 --- /dev/null +++ b/integration-tests/src/tests/send_relay_chain_asset.rs @@ -0,0 +1,63 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use crate::mock::{ + Bifrost, BifrostTokens, BifrostXTokens, Relay, RelayBalances, RelaySystem, TestNet, ALICE, BOB, +}; +use bifrost_primitives::CurrencyId; +use cumulus_primitives_core::ParaId; +use frame_support::{assert_ok, traits::Currency}; +use orml_traits::MultiCurrency; +use sp_runtime::traits::AccountIdConversion; +use xcm::v4::{Junction, Location, WeightLimit}; +use xcm_simulator::TestExt; + +#[test] +fn send_relay_chain_asset_to_relay_chain() { + TestNet::reset(); + + Relay::execute_with(|| { + let _ = RelayBalances::deposit_creating( + &ParaId::from(2030).into_account_truncating(), + 100_000_000_000, + ); + }); + + Bifrost::execute_with(|| { + assert_ok!(BifrostXTokens::transfer( + Some(ALICE).into(), + CurrencyId::Token2(0), + 50_000_000_000, + Box::new( + Location::new(1, [Junction::AccountId32 { network: None, id: BOB.into() }]).into() + ), + WeightLimit::Unlimited + )); + assert_eq!(BifrostTokens::free_balance(CurrencyId::Token2(0), &ALICE), 50_000_000_000); + }); + + Relay::execute_with(|| { + println!("{:?}", RelaySystem::events()); + + assert_eq!( + RelayBalances::free_balance(&ParaId::from(2030).into_account_truncating()), + 50_000_000_000 + ); + assert_eq!(RelayBalances::free_balance(&BOB), 49999999960); + }); +} diff --git a/integration-tests/src/tests/slp.rs b/integration-tests/src/tests/slp.rs new file mode 100644 index 000000000..433a18dea --- /dev/null +++ b/integration-tests/src/tests/slp.rs @@ -0,0 +1,137 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use crate::mock::{bifrost, Bifrost, BifrostSlp, Relay, RelayBalances, RelayXcmPallet}; +use bifrost_polkadot_runtime::xcm_config::ParaId; +use bifrost_primitives::CurrencyId; +use bifrost_slp::MinimumsMaximums; +use frame_support::{assert_ok, traits::Currency}; +use sp_runtime::{ + traits::{AccountIdConversion, Convert}, + AccountId32, +}; +use std::convert::Into; +use xcm::{v3::MultiLocation, v4::prelude::*, VersionedAssets, VersionedLocation}; +use xcm_simulator::TestExt; + +const ENTRANCE_ACCOUNT: [u8; 32] = + hex_literal::hex!["6d6f646c62662f76746b696e0000000000000000000000000000000000000000"]; +const BIFROST_TREASURY_ACCOUNT: [u8; 32] = + hex_literal::hex!["6d6f646c62662f74727372790000000000000000000000000000000000000000"]; +const BIFROST_TREASURY_MULTILOCATION: MultiLocation = MultiLocation { + parents: 0, + interior: xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { + network: None, + id: BIFROST_TREASURY_ACCOUNT, + }), +}; +pub const KUSAMA_ALICE_STASH_ACCOUNT: [u8; 32] = + hex_literal::hex!["be5ddb1579b72e84524fc29e78609e3caf42e85aa118ebfe0b0ad404b5bdd25f"]; +const KUSAMA_ALICE_STASH_MULTILOCATION: MultiLocation = MultiLocation { + parents: 1, + interior: xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { + network: None, + id: KUSAMA_ALICE_STASH_ACCOUNT, + }), +}; + +const DOT_DECIMALS: u128 = 10_000_000_000; + +fn cross_dot_to_bifrost(to: AccountId32, amount: u128) { + Relay::execute_with(|| { + let _ = RelayBalances::deposit_creating( + &ParaId::from(2030).into_account_truncating(), + 100_000_000_000, + ); + let _ = RelayBalances::deposit_creating(&to, amount); + assert_ok!(RelayXcmPallet::reserve_transfer_assets( + Some(to.clone()).into(), + Box::new(VersionedLocation::V4(Parachain(2030).into())), + Box::new(VersionedLocation::V4( + Junction::AccountId32 { id: to.into(), network: None }.into() + )), + Box::new(VersionedAssets::V4((Here, amount / 10).into())), + 0, + )); + }); +} + +fn slp_setup() { + cross_dot_to_bifrost(BIFROST_TREASURY_ACCOUNT.into(), 10000 * DOT_DECIMALS); + cross_dot_to_bifrost(ENTRANCE_ACCOUNT.into(), 10000 * DOT_DECIMALS); + + let mins_and_maxs = MinimumsMaximums { + delegator_bonded_minimum: DOT_DECIMALS / 10, + bond_extra_minimum: DOT_DECIMALS / 1000, + unbond_minimum: DOT_DECIMALS / 1000, + rebond_minimum: DOT_DECIMALS / 1000, + unbond_record_maximum: 32, + validators_back_maximum: 24, + delegator_active_staking_maximum: 80000 * DOT_DECIMALS, + validators_reward_maximum: 256, + delegation_amount_minimum: DOT_DECIMALS / 1000, + delegators_maximum: 100, + validators_maximum: 300, + }; + + Bifrost::execute_with(|| { + assert_ok!(BifrostSlp::set_minimums_and_maximums( + bifrost::RuntimeOrigin::root(), + CurrencyId::Token2(0), + Some(mins_and_maxs) + )); + + // set fee_source for ksm to be treasury + assert_ok!(BifrostSlp::set_fee_source( + bifrost::RuntimeOrigin::root(), + CurrencyId::Token2(0), + Some((BIFROST_TREASURY_MULTILOCATION, 1 * DOT_DECIMALS)) + )); + + assert_ok!(BifrostSlp::initialize_delegator( + bifrost::RuntimeOrigin::root(), + CurrencyId::Token2(0), + None + )); + + assert_ok!(BifrostSlp::add_validator( + bifrost::RuntimeOrigin::root(), + CurrencyId::Token2(0), + Box::new(KUSAMA_ALICE_STASH_MULTILOCATION), + )); + }) +} + +#[test] +fn relaychain_staking_bond() { + slp_setup(); + Bifrost::execute_with(|| { + let delegator = bifrost_polkadot_runtime::SubAccountIndexMultiLocationConvertor::convert(( + 0, + CurrencyId::Token2(0), + )); + assert_ok!(BifrostSlp::bond( + bifrost::RuntimeOrigin::root(), + CurrencyId::Token2(0), + Box::new(delegator), + 50 * DOT_DECIMALS, + None, + Some((Weight::from_parts(10000000000u64, 65535u64), 100000000u128)) + )); + }); +} diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 4b4aaada0..73f754bfa 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bifrost-cli" -version = "0.10.0" +version = "0.11.0" authors = ["Liebi Technologies "] description = "Bifrost Parachain Node" build = "build.rs" diff --git a/node/rpc/Cargo.toml b/node/rpc/Cargo.toml index e4ed12119..bf69260c2 100644 --- a/node/rpc/Cargo.toml +++ b/node/rpc/Cargo.toml @@ -37,4 +37,6 @@ zenlink-protocol-rpc = { workspace = true } zenlink-protocol-runtime-api = { workspace = true } zenlink-stable-amm-rpc = { workspace = true } zenlink-stable-amm-runtime-api = { workspace = true } +bifrost-vtoken-minting-rpc = { workspace = true } +bifrost-vtoken-minting-rpc-runtime-api = { workspace = true } diff --git a/node/rpc/src/lib.rs b/node/rpc/src/lib.rs index 22fb09afa..0fef634c8 100644 --- a/node/rpc/src/lib.rs +++ b/node/rpc/src/lib.rs @@ -44,6 +44,8 @@ use bifrost_stable_pool_rpc::{StablePoolRpc, StablePoolRpcApiServer}; use bifrost_stable_pool_rpc_runtime_api::StablePoolRuntimeApi; use bifrost_ve_minting_rpc::{VeMintingRpc, VeMintingRpcApiServer}; use bifrost_ve_minting_rpc_runtime_api::VeMintingRuntimeApi; +use bifrost_vtoken_minting_rpc::{VtokenMintingRpc, VtokenMintingRpcApiServer}; +use bifrost_vtoken_minting_rpc_runtime_api::VtokenMintingRuntimeApi; use lend_market_rpc::{LendMarket, LendMarketApiServer}; use lend_market_rpc_runtime_api::LendMarketApi; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; @@ -89,6 +91,7 @@ where C::Api: SalpRuntimeApi, C::Api: StablePoolRuntimeApi, C::Api: LendMarketApi, + C::Api: VtokenMintingRuntimeApi, C::Api: ZenlinkProtocolRuntimeApi, C::Api: zenlink_stable_amm_runtime_api::StableAmmApi, @@ -107,7 +110,8 @@ where module.merge(ZenlinkProtocol::new(client.clone()).into_rpc())?; module.merge(StableAmm::new(client.clone()).into_rpc())?; module.merge(StablePoolRpc::new(client.clone()).into_rpc())?; - module.merge(LendMarket::new(client).into_rpc())?; + module.merge(LendMarket::new(client.clone()).into_rpc())?; + module.merge(VtokenMintingRpc::new(client).into_rpc())?; Ok(module) } @@ -131,6 +135,7 @@ where C::Api: SalpRuntimeApi, C::Api: VeMintingRuntimeApi, C::Api: LendMarketApi, + C::Api: VtokenMintingRuntimeApi, C::Api: ZenlinkProtocolRuntimeApi, C::Api: StablePoolRuntimeApi, C::Api: BlockBuilder, @@ -148,7 +153,8 @@ where module.merge(VeMintingRpc::new(client.clone()).into_rpc())?; module.merge(ZenlinkProtocol::new(client.clone()).into_rpc())?; module.merge(StablePoolRpc::new(client.clone()).into_rpc())?; - module.merge(LendMarket::new(client).into_rpc())?; + module.merge(LendMarket::new(client.clone()).into_rpc())?; + module.merge(VtokenMintingRpc::new(client).into_rpc())?; Ok(module) } diff --git a/pallets/asset-registry/src/benchmarking.rs b/pallets/asset-registry/src/benchmarking.rs index 2bc375dd5..309065886 100644 --- a/pallets/asset-registry/src/benchmarking.rs +++ b/pallets/asset-registry/src/benchmarking.rs @@ -24,16 +24,15 @@ use bifrost_primitives::{CurrencyId, TokenSymbol}; use frame_benchmarking::{benchmarks, v1::BenchmarkError}; use frame_support::{assert_ok, traits::UnfilteredDispatchable}; use sp_runtime::traits::UniqueSaturatedFrom; -use xcm::v3::prelude::*; benchmarks! { register_native_asset { let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - let v3_location = VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000)))); + let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)])); let call = Call::::register_native_asset { - currency_id: CurrencyId::Token(TokenSymbol::DOT), - location: Box::new(v3_location.clone()), + currency_id: Token(TokenSymbol::DOT), + location: Box::new(versioned_location.clone()), metadata: Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -44,7 +43,7 @@ benchmarks! { }: {call.dispatch_bypass_filter(origin)?} verify { assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token( + AssetMetadatas::::get(AssetIds::NativeAssetId(Token( TokenSymbol::DOT ))), Some(AssetMetadata { @@ -58,12 +57,12 @@ benchmarks! { update_native_asset { let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; - let v3_location = VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000)))); + let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)])); assert_ok!(AssetRegistry::::register_native_asset( origin.clone(), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location.clone()), + Token(TokenSymbol::DOT), + Box::new(versioned_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -73,8 +72,8 @@ benchmarks! { )); let call = Call::::update_native_asset { - currency_id: CurrencyId::Token(TokenSymbol::DOT), - location: Box::new(v3_location.clone()), + currency_id: Token(TokenSymbol::DOT), + location: Box::new(versioned_location.clone()), metadata: Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -85,7 +84,7 @@ benchmarks! { }: {call.dispatch_bypass_filter(origin)?} verify { assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token( + AssetMetadatas::::get(AssetIds::NativeAssetId(Token( TokenSymbol::DOT ))), Some(AssetMetadata { @@ -111,7 +110,7 @@ benchmarks! { }; }: {call.dispatch_bypass_filter(origin)?} verify { - assert_eq!(CurrencyMetadatas::::get(CurrencyId::Token2(0)), Some(metadata.clone())) + assert_eq!(CurrencyMetadatas::::get(Token2(0)), Some(metadata.clone())) } register_vtoken_metadata { @@ -208,7 +207,7 @@ benchmarks! { ) } - register_multilocation { + register_location { let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let metadata = AssetMetadata { name: b"Bifrost Native Coin".to_vec(), @@ -216,38 +215,34 @@ benchmarks! { decimals: 12, minimal_balance: BalanceOf::::unique_saturated_from(0u128), }; - // v3 - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: Junctions::X1(Parachain(2001)), - }); + let versioned_location = VersionedLocation::V4(Location::new(1, [Parachain(2001)])); - let multi_location: MultiLocation = location.clone().try_into().unwrap(); + let location: xcm::v3::Location = versioned_location.clone().try_into().unwrap(); assert_ok!(AssetRegistry::::register_token_metadata( origin.clone(), Box::new(metadata.clone()) )); - let call = Call::::register_multilocation { - currency_id: CurrencyId::Token2(0), - location:Box::new(location.clone()), + let call = Call::::register_location { + currency_id: Token2(0), + location:Box::new(versioned_location.clone()), weight:Weight::from_parts(2000_000_000, u64::MAX), }; }: {call.dispatch_bypass_filter(origin)?} verify { assert_eq!( - LocationToCurrencyIds::::get(multi_location.clone()), - Some(CurrencyId::Token2(0)) + LocationToCurrencyIds::::get(location.clone()), + Some(Token2(0)) ); assert_eq!( - CurrencyIdToLocations::::get(CurrencyId::Token2(0)), - Some(multi_location.clone()) + CurrencyIdToLocations::::get(Token2(0)), + Some(location.clone()) ); - assert_eq!(CurrencyIdToWeights::::get(CurrencyId::Token2(0)), Some(Weight::from_parts(2000_000_000, u64::MAX))); + assert_eq!(CurrencyIdToWeights::::get(Token2(0)), Some(Weight::from_parts(2000_000_000, u64::MAX))); } - force_set_multilocation { + force_set_location { let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; let metadata = AssetMetadata { name: b"Bifrost Native Coin".to_vec(), @@ -255,26 +250,56 @@ benchmarks! { decimals: 12, minimal_balance: BalanceOf::::unique_saturated_from(0u128), }; - // v3 - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: Junctions::X1(Parachain(2001)), - }); + let versioned_location = VersionedLocation::V4(Location::new(1, [Parachain(2001)])); - let multi_location: MultiLocation = location.clone().try_into().unwrap(); + let location: xcm::v3::Location = versioned_location.clone().try_into().unwrap(); assert_ok!(AssetRegistry::::register_token_metadata( origin.clone(), Box::new(metadata.clone()) )); - let call = Call::::force_set_multilocation { - currency_id: CurrencyId::Token2(0), - location:Box::new(location.clone()), + let call = Call::::force_set_location { + currency_id: Token2(0), + location:Box::new(versioned_location.clone()), weight:Weight::from_parts(2000_000_000, u64::MAX), }; }: {call.dispatch_bypass_filter(origin)?} + update_currency_metadata { + let origin = T::RegisterOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + + assert_ok!(AssetRegistry::::register_token_metadata( + origin.clone(), + Box::new(AssetMetadata { + name: b"Old Token Name".to_vec(), + symbol: b"OTN".to_vec(), + decimals: 10, + minimal_balance: BalanceOf::::unique_saturated_from(1u128), + }) + )); + + let call = Call::::update_currency_metadata { + currency_id: CurrencyId::Token2(0), + asset_name: Some(b"Token Name".to_vec()), + asset_symbol: Some(b"TN".to_vec()), + asset_decimals : Some(12), + asset_minimal_balance : Some(BalanceOf::::unique_saturated_from(1000u128)), + }; + + }: {call.dispatch_bypass_filter(origin)?} + verify { + assert_eq!( + CurrencyMetadatas::::get(CurrencyId::Token2(0)), + Some(AssetMetadata { + name: b"Token Name".to_vec(), + symbol: b"TN".to_vec(), + decimals: 12, + minimal_balance: BalanceOf::::unique_saturated_from(1000u128), + }) + ); + } + impl_benchmark_test_suite!( AssetRegistry, crate::mock::ExtBuilder::default().build(), diff --git a/pallets/asset-registry/src/lib.rs b/pallets/asset-registry/src/lib.rs index 8ab32138f..b7bab37f0 100644 --- a/pallets/asset-registry/src/lib.rs +++ b/pallets/asset-registry/src/lib.rs @@ -22,7 +22,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -use bifrost_primitives::{ +pub use bifrost_primitives::{ AssetIds, CurrencyId, CurrencyId::{Native, Token, Token2}, CurrencyIdConversion, CurrencyIdMapping, CurrencyIdRegister, ForeignAssetId, LeasePeriod, @@ -43,15 +43,13 @@ use sp_runtime::{ }; use sp_std::{boxed::Box, vec::Vec}; use xcm::{ - opaque::{ - lts::XcmContext, - v3::{prelude::XcmError, AssetId, Fungibility::Fungible, MultiAsset}, - }, + opaque::lts::XcmContext, v3::MultiLocation, - VersionedMultiLocation, + v4::{prelude::*, Asset, Location}, + VersionedLocation, }; use xcm_builder::TakeRevenue; -use xcm_executor::{traits::WeightTrader, Assets}; +use xcm_executor::{traits::WeightTrader, AssetsInHolding}; pub mod migration; mod mock; @@ -100,8 +98,8 @@ pub mod pallet { /// The given location could not be used (e.g. because it cannot be expressed in the /// desired version of XCM). BadLocation, - /// MultiLocation existed - MultiLocationExisted, + /// Location existed + LocationExisted, /// AssetId not exists AssetIdNotExists, /// AssetId exists @@ -121,8 +119,10 @@ pub mod pallet { AssetUpdated { asset_id: AssetIds, metadata: AssetMetadata> }, /// The CurrencyId registered. CurrencyIdRegistered { currency_id: CurrencyId, metadata: AssetMetadata> }, - /// MultiLocation Force set. - MultiLocationSet { currency_id: CurrencyId, location: MultiLocation, weight: Weight }, + /// Location Force set. + LocationSet { currency_id: CurrencyId, location: Location, weight: Weight }, + /// The CurrencyId updated. + CurrencyIdUpdated { currency_id: CurrencyId, metadata: AssetMetadata> }, } /// Next available Foreign AssetId ID. @@ -139,21 +139,21 @@ pub mod pallet { #[pallet::getter(fn next_token_id)] pub type NextTokenId = StorageValue<_, TokenId, ValueQuery>; - /// The storages for MultiLocations. + /// The storages for Locations. /// - /// CurrencyIdToLocations: map CurrencyId => Option + /// CurrencyIdToLocations: map CurrencyId => Option #[pallet::storage] #[pallet::getter(fn currency_id_to_locations)] pub type CurrencyIdToLocations = - StorageMap<_, Twox64Concat, CurrencyId, MultiLocation, OptionQuery>; + StorageMap<_, Twox64Concat, CurrencyId, xcm::v3::Location, OptionQuery>; /// The storages for CurrencyIds. /// - /// LocationToCurrencyIds: map MultiLocation => Option + /// LocationToCurrencyIds: map Location => Option #[pallet::storage] #[pallet::getter(fn location_to_currency_ids)] pub type LocationToCurrencyIds = - StorageMap<_, Twox64Concat, MultiLocation, CurrencyId, OptionQuery>; + StorageMap<_, Twox64Concat, xcm::v3::Location, CurrencyId, OptionQuery>; #[pallet::storage] #[pallet::getter(fn currency_id_to_weight)] @@ -279,12 +279,12 @@ pub mod pallet { pub fn register_native_asset( origin: OriginFor, currency_id: CurrencyId, - location: Box, + location: Box, metadata: Box>>, ) -> DispatchResult { T::RegisterOrigin::ensure_origin(origin)?; - let location: MultiLocation = + let location: Location = (*location).try_into().map_err(|()| Error::::BadLocation)?; Self::do_register_native_asset(currency_id, &location, &metadata)?; @@ -300,12 +300,12 @@ pub mod pallet { pub fn update_native_asset( origin: OriginFor, currency_id: CurrencyId, - location: Box, + location: Box, metadata: Box>>, ) -> DispatchResult { T::RegisterOrigin::ensure_origin(origin)?; - let location: MultiLocation = + let location: Location = (*location).try_into().map_err(|()| Error::::BadLocation)?; Self::do_update_native_asset(currency_id, &location, &metadata)?; @@ -325,7 +325,7 @@ pub mod pallet { T::RegisterOrigin::ensure_origin(origin)?; let token_id = Self::get_next_token_id()?; - let currency_id = CurrencyId::Token2(token_id); + let currency_id = Token2(token_id); Self::do_register_metadata(currency_id, &metadata)?; Ok(()) @@ -336,8 +336,7 @@ pub mod pallet { pub fn register_vtoken_metadata(origin: OriginFor, token_id: TokenId) -> DispatchResult { T::RegisterOrigin::ensure_origin(origin)?; - if let Some(token_metadata) = CurrencyMetadatas::::get(CurrencyId::Token2(token_id)) - { + if let Some(token_metadata) = CurrencyMetadatas::::get(Token2(token_id)) { let vtoken_metadata = Self::convert_to_vtoken_metadata(token_metadata); Self::do_register_metadata(CurrencyId::VToken2(token_id), &vtoken_metadata)?; @@ -397,50 +396,86 @@ pub mod pallet { } #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::register_multilocation())] - pub fn register_multilocation( + #[pallet::weight(T::WeightInfo::register_location())] + pub fn register_location( origin: OriginFor, currency_id: CurrencyId, - location: Box, + location: Box, weight: Weight, ) -> DispatchResult { T::RegisterOrigin::ensure_origin(origin)?; - let location: MultiLocation = + let location: Location = (*location).try_into().map_err(|()| Error::::BadLocation)?; - Self::do_register_multilocation(currency_id, &location)?; + Self::do_register_location(currency_id, &location)?; Self::do_register_weight(currency_id, weight)?; Ok(()) } #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::force_set_multilocation())] - pub fn force_set_multilocation( + #[pallet::weight(T::WeightInfo::force_set_location())] + pub fn force_set_location( origin: OriginFor, currency_id: CurrencyId, - location: Box, + location: Box, weight: Weight, ) -> DispatchResult { T::RegisterOrigin::ensure_origin(origin)?; - let location: MultiLocation = + let location: Location = (*location).try_into().map_err(|()| Error::::BadLocation)?; + let v3_location = xcm::v3::Location::try_from(location.clone()) + .map_err(|()| Error::::BadLocation)?; + ensure!( CurrencyMetadatas::::get(currency_id).is_some(), Error::::CurrencyIdNotExists ); - LocationToCurrencyIds::::insert(location, currency_id); - CurrencyIdToLocations::::insert(currency_id, location); + LocationToCurrencyIds::::insert(v3_location, currency_id); + CurrencyIdToLocations::::insert(currency_id, v3_location); CurrencyIdToWeights::::insert(currency_id, weight); - Pallet::::deposit_event(Event::::MultiLocationSet { - currency_id, - location, - weight, - }); + Pallet::::deposit_event(Event::::LocationSet { currency_id, location, weight }); + + Ok(()) + } + + #[pallet::call_index(8)] + #[pallet::weight(T::WeightInfo::update_currency_metadata())] + pub fn update_currency_metadata( + origin: OriginFor, + currency_id: CurrencyId, + asset_name: Option>, + asset_symbol: Option>, + asset_decimals: Option, + asset_minimal_balance: Option>, + ) -> DispatchResult { + T::RegisterOrigin::ensure_origin(origin)?; + + // Check if the currency metadata exists + let mut metadata = + CurrencyMetadatas::::get(currency_id).ok_or(Error::::CurrencyIdNotExists)?; + + // Update the metadata fields based on the provided options + if let Some(name) = asset_name { + metadata.name = name; + } + if let Some(symbol) = asset_symbol { + metadata.symbol = symbol; + } + if let Some(decimals) = asset_decimals { + metadata.decimals = decimals; + } + if let Some(minimal_balance) = asset_minimal_balance { + metadata.minimal_balance = minimal_balance; + } + + // Store the updated metadata + CurrencyMetadatas::::insert(currency_id, metadata.clone()); + Self::deposit_event(Event::::CurrencyIdUpdated { currency_id, metadata }); Ok(()) } @@ -458,21 +493,24 @@ impl Pallet { pub fn do_register_native_asset( currency_id: CurrencyId, - location: &MultiLocation, + location: &Location, metadata: &AssetMetadata>, ) -> DispatchResult { - ensure!(LocationToCurrencyIds::::get(location).is_none(), Error::::AssetIdExisted); + let v3_location = + xcm::v3::Location::try_from(location.clone()).map_err(|()| Error::::BadLocation)?; + + ensure!(LocationToCurrencyIds::::get(v3_location).is_none(), Error::::AssetIdExisted); ensure!( CurrencyIdToLocations::::get(currency_id).is_none(), - Error::::MultiLocationExisted + Error::::LocationExisted ); ensure!( AssetMetadatas::::get(AssetIds::NativeAssetId(currency_id)).is_none(), Error::::AssetIdExisted ); - LocationToCurrencyIds::::insert(location, currency_id); - CurrencyIdToLocations::::insert(currency_id, location); + LocationToCurrencyIds::::insert(v3_location, currency_id); + CurrencyIdToLocations::::insert(currency_id, v3_location); AssetMetadatas::::insert(AssetIds::NativeAssetId(currency_id), metadata); Ok(()) @@ -532,30 +570,29 @@ impl Pallet { Ok(()) } - pub fn do_register_multilocation( - currency_id: CurrencyId, - location: &MultiLocation, - ) -> DispatchResult { + pub fn do_register_location(currency_id: CurrencyId, location: &Location) -> DispatchResult { + let v3_location = + xcm::v3::Location::try_from(location.clone()).map_err(|()| Error::::BadLocation)?; + ensure!( CurrencyMetadatas::::get(currency_id).is_some(), Error::::CurrencyIdNotExists ); - ensure!(LocationToCurrencyIds::::get(location).is_none(), Error::::CurrencyIdExisted); + ensure!( + LocationToCurrencyIds::::get(v3_location).is_none(), + Error::::CurrencyIdExisted + ); ensure!( CurrencyIdToLocations::::get(currency_id).is_none(), - Error::::MultiLocationExisted + Error::::LocationExisted ); - LocationToCurrencyIds::::insert(location, currency_id); - CurrencyIdToLocations::::insert(currency_id, location); + LocationToCurrencyIds::::insert(v3_location, currency_id); + CurrencyIdToLocations::::insert(currency_id, v3_location); Ok(()) } - pub fn do_remove_multilocation(location: &MultiLocation) { - LocationToCurrencyIds::::remove(location); - } - pub fn do_register_weight(currency_id: CurrencyId, weight: Weight) -> DispatchResult { ensure!( CurrencyMetadatas::::get(currency_id).is_some(), @@ -569,21 +606,27 @@ impl Pallet { fn do_update_native_asset( currency_id: CurrencyId, - location: &MultiLocation, + location: &Location, metadata: &AssetMetadata>, ) -> DispatchResult { - ensure!(LocationToCurrencyIds::::get(location).is_some(), Error::::AssetIdNotExists); + let v3_location = + xcm::v3::Location::try_from(location.clone()).map_err(|()| Error::::BadLocation)?; + + ensure!( + LocationToCurrencyIds::::get(v3_location).is_some(), + Error::::AssetIdNotExists + ); ensure!( CurrencyIdToLocations::::get(currency_id).is_some(), - Error::::MultiLocationExisted + Error::::LocationExisted ); ensure!( AssetMetadatas::::get(AssetIds::NativeAssetId(currency_id)).is_some(), Error::::AssetIdNotExists ); - LocationToCurrencyIds::::insert(location, currency_id); - CurrencyIdToLocations::::insert(currency_id, location); + LocationToCurrencyIds::::insert(v3_location, currency_id); + CurrencyIdToLocations::::insert(currency_id, v3_location); AssetMetadatas::::insert(AssetIds::NativeAssetId(currency_id), metadata); Ok(()) @@ -603,12 +646,18 @@ impl CurrencyIdMapping::currency_metadatas(currency_id) } - fn get_multi_location(currency_id: CurrencyId) -> Option { + fn get_all_currency() -> Vec { + CurrencyMetadatas::::iter_keys().collect() + } + + fn get_location(currency_id: CurrencyId) -> Option { Pallet::::currency_id_to_locations(currency_id) + .map(|location| location.try_into().ok())? } - fn get_currency_id(multi_location: MultiLocation) -> Option { - Pallet::::location_to_currency_ids(multi_location) + fn get_currency_id(multi_location: Location) -> Option { + let v3_location = xcm::v3::Location::try_from(multi_location).ok()?; + Pallet::::location_to_currency_ids(v3_location) } } @@ -853,7 +902,7 @@ pub struct FixedRateOfAsset, R: TakeRevenue> { weight: u64, amount: u128, ed_ratio: FixedU128, - multi_location: Option, + location: Option, _marker: PhantomData<(T, FixedRate, R)>, } @@ -867,7 +916,7 @@ where weight: 0, amount: 0, ed_ratio: Default::default(), - multi_location: None, + location: None, _marker: PhantomData, } } @@ -875,9 +924,9 @@ where fn buy_weight( &mut self, weight: Weight, - payment: Assets, + payment: AssetsInHolding, _context: &XcmContext, - ) -> Result { + ) -> Result { log::trace!(target: "asset-registry::weight", "buy_weight weight: {:?}, payment: {:?}", weight, payment); // only support first fungible assets now. @@ -887,51 +936,51 @@ where .next() .map_or(Err(XcmError::TooExpensive), |v| Ok(v.0))?; - if let AssetId::Concrete(ref multi_location) = asset_id { - log::debug!(target: "asset-registry::weight", "buy_weight multi_location: {:?}", multi_location); - - if let Some(currency_id) = Pallet::::location_to_currency_ids(multi_location) { - if let Some(currency_metadatas) = Pallet::::currency_metadatas(currency_id) { - // The integration tests can ensure the ed is non-zero. - let ed_ratio = FixedU128::saturating_from_rational( - currency_metadatas.minimal_balance.into(), - T::Currency::minimum_balance().into(), - ); - // The WEIGHT_REF_TIME_PER_SECOND is non-zero. - let weight_ratio = FixedU128::saturating_from_rational( - weight.ref_time(), - WEIGHT_REF_TIME_PER_SECOND, - ); - let amount = ed_ratio - .saturating_mul_int(weight_ratio.saturating_mul_int(FixedRate::get())); - - let required = MultiAsset { id: *asset_id, fun: Fungible(amount) }; - - log::trace!( - target: "asset-registry::weight", "buy_weight payment: {:?}, required: {:?}, fixed_rate: {:?}, ed_ratio: {:?}, weight_ratio: {:?}", - payment, required, FixedRate::get(), ed_ratio, weight_ratio - ); - let unused = payment - .clone() - .checked_sub(required) - .map_err(|_| XcmError::TooExpensive)?; - self.weight = self.weight.saturating_add(weight.ref_time()); - self.amount = self.amount.saturating_add(amount); - self.ed_ratio = ed_ratio; - self.multi_location = Some(*multi_location); - return Ok(unused); - } + let AssetId(ref location) = asset_id.clone(); + log::debug!(target: "asset-registry::weight", "buy_weight location: {:?}", location); + + let v3_location = + xcm::v3::Location::try_from(location.clone()).map_err(|_| XcmError::InvalidLocation)?; + + if let Some(currency_id) = Pallet::::location_to_currency_ids(v3_location) { + if let Some(currency_metadatas) = Pallet::::currency_metadatas(currency_id) { + // The integration tests can ensure the ed is non-zero. + let ed_ratio = FixedU128::saturating_from_rational( + currency_metadatas.minimal_balance.into(), + T::Currency::minimum_balance().into(), + ); + // The WEIGHT_REF_TIME_PER_SECOND is non-zero. + let weight_ratio = FixedU128::saturating_from_rational( + weight.ref_time(), + WEIGHT_REF_TIME_PER_SECOND, + ); + let amount = + ed_ratio.saturating_mul_int(weight_ratio.saturating_mul_int(FixedRate::get())); + + let required = Asset { id: asset_id.clone(), fun: Fungible(amount) }; + + log::trace!( + target: "asset-registry::weight", "buy_weight payment: {:?}, required: {:?}, fixed_rate: {:?}, ed_ratio: {:?}, weight_ratio: {:?}", + payment, required, FixedRate::get(), ed_ratio, weight_ratio + ); + let unused = + payment.clone().checked_sub(required).map_err(|_| XcmError::TooExpensive)?; + self.weight = self.weight.saturating_add(weight.ref_time()); + self.amount = self.amount.saturating_add(amount); + self.ed_ratio = ed_ratio; + self.location = Some(location.clone()); + return Ok(unused); } - } + }; log::trace!(target: "asset-registry::weight", "no concrete fungible asset"); Err(XcmError::TooExpensive) } - fn refund_weight(&mut self, weight: Weight, _context: &XcmContext) -> Option { + fn refund_weight(&mut self, weight: Weight, _context: &XcmContext) -> Option { log::trace!( - target: "asset-registry::weight", "refund_weight weight: {:?}, weight: {:?}, amount: {:?}, ed_ratio: {:?}, multi_location: {:?}", - weight, self.weight, self.amount, self.ed_ratio, self.multi_location + target: "asset-registry::weight", "refund_weight weight: {:?}, weight: {:?}, amount: {:?}, ed_ratio: {:?}, location: {:?}", + weight, self.weight, self.amount, self.ed_ratio, self.location ); let weight = weight.min(Weight::from_parts(self.weight, 0)); let weight_ratio = @@ -944,8 +993,13 @@ where self.amount = self.amount.saturating_sub(amount); log::trace!(target: "asset-registry::weight", "refund_weight amount: {:?}", amount); - if amount > 0 && self.multi_location.is_some() { - Some((*self.multi_location.as_ref().expect("checked is non-empty; qed"), amount).into()) + if amount > 0 && self.location.is_some() { + Some(Asset { + fun: Fungible(amount), + id: AssetId( + self.location.clone().expect("checked is non-empty; qed").try_into().unwrap(), + ), + }) } else { None } @@ -954,12 +1008,14 @@ where impl, R: TakeRevenue> Drop for FixedRateOfAsset { fn drop(&mut self) { - log::trace!(target: "asset-registry::weight", "take revenue, weight: {:?}, amount: {:?}, multi_location: {:?}", self.weight, self.amount, self.multi_location); - if self.amount > 0 && self.multi_location.is_some() { - R::take_revenue( - (*self.multi_location.as_ref().expect("checked is non-empty; qed"), self.amount) - .into(), - ); + log::trace!(target: "asset-registry::weight", "take revenue, weight: {:?}, amount: {:?}, location: {:?}", self.weight, self.amount, self.location); + if self.amount > 0 && self.location.is_some() { + R::take_revenue(Asset { + fun: Fungible(self.amount), + id: AssetId( + self.location.clone().expect("checked is non-empty; qed").try_into().unwrap(), + ), + }); } } } diff --git a/pallets/asset-registry/src/migration.rs b/pallets/asset-registry/src/migration.rs index 21937d0b7..9e9a21b9d 100644 --- a/pallets/asset-registry/src/migration.rs +++ b/pallets/asset-registry/src/migration.rs @@ -21,7 +21,7 @@ use bifrost_primitives::{CurrencyId, BNC}; use frame_support::traits::{Get, OnRuntimeUpgrade}; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; -use xcm::prelude::{GeneralKey, X1}; +use xcm::v3::prelude::{GeneralKey, X1}; const LOG_TARGET: &str = "asset-registry::migration"; @@ -42,7 +42,7 @@ pub fn update_blp_metadata(pool_count: u32) -> Weight { T::DbWeight::get().reads(pool_count.into()) + T::DbWeight::get().writes(pool_count.into()) } -const BNC_LOCATION: MultiLocation = MultiLocation { +const BNC_LOCATION: xcm::v3::Location = xcm::v3::Location { parents: 0, interior: X1(GeneralKey { length: 2, diff --git a/pallets/asset-registry/src/mock.rs b/pallets/asset-registry/src/mock.rs index 349037759..a948e290c 100644 --- a/pallets/asset-registry/src/mock.rs +++ b/pallets/asset-registry/src/mock.rs @@ -59,7 +59,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/asset-registry/src/tests.rs b/pallets/asset-registry/src/tests.rs index cfae30dd6..470a22438 100644 --- a/pallets/asset-registry/src/tests.rs +++ b/pallets/asset-registry/src/tests.rs @@ -26,49 +26,25 @@ use frame_support::{assert_noop, assert_ok}; use mock::{ AssetRegistry, CouncilAccount, ExtBuilder, Runtime, RuntimeEvent, RuntimeOrigin, System, }; -use xcm::prelude::*; #[test] fn versioned_multi_location_convert_work() { ExtBuilder::default().build().execute_with(|| { - // V3 - let v3_location = - VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000)))); - let location: MultiLocation = v3_location.try_into().unwrap(); - assert_eq!( - location, - MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(1000)) } - ); - - // V3 - let v3_location = VersionedMultiLocation::V3(MultiLocation { - parents: 0, - interior: Junctions::X1(Junction::Parachain(1000)), - }); - let location: MultiLocation = v3_location.clone().try_into().unwrap(); - assert_eq!( - location, - MultiLocation { parents: 0, interior: Junctions::X1(Junction::Parachain(1000)) } - ); - - // handle all of VersionedMultiLocation - assert!(match v3_location { - VersionedMultiLocation::V3 { .. } => true, - _ => false, - }); + let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)])); + let location: Location = versioned_location.try_into().unwrap(); + assert_eq!(location, Location::new(0, [Parachain(1000)])); }); } #[test] fn register_native_asset_works() { ExtBuilder::default().build().execute_with(|| { - let v3_location = - VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000)))); + let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)])); assert_ok!(AssetRegistry::register_native_asset( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location.clone()), + Token(TokenSymbol::DOT), + Box::new(versioned_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -76,8 +52,8 @@ fn register_native_asset_works() { minimal_balance: 1, }) )); - System::assert_last_event(RuntimeEvent::AssetRegistry(crate::Event::AssetRegistered { - asset_id: AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT)), + System::assert_last_event(RuntimeEvent::AssetRegistry(Event::AssetRegistered { + asset_id: AssetIds::NativeAssetId(Token(TokenSymbol::DOT)), metadata: AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -87,9 +63,7 @@ fn register_native_asset_works() { })); assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token( - TokenSymbol::DOT - ))), + AssetMetadatas::::get(AssetIds::NativeAssetId(Token(TokenSymbol::DOT))), Some(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -101,8 +75,8 @@ fn register_native_asset_works() { assert_noop!( AssetRegistry::register_native_asset( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location), + Token(TokenSymbol::DOT), + Box::new(versioned_location), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -117,15 +91,14 @@ fn register_native_asset_works() { #[test] fn update_native_asset_works() { - let v3_location = - VersionedMultiLocation::V3(MultiLocation::from(X1(Junction::Parachain(1000)))); + let versioned_location = VersionedLocation::V4(Location::from([Parachain(1000)])); ExtBuilder::default().build().execute_with(|| { assert_noop!( AssetRegistry::update_native_asset( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location.clone()), + Token(TokenSymbol::DOT), + Box::new(versioned_location.clone()), Box::new(AssetMetadata { name: b"New Token Name".to_vec(), symbol: b"NTN".to_vec(), @@ -138,8 +111,8 @@ fn update_native_asset_works() { assert_ok!(AssetRegistry::register_native_asset( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location.clone()), + Token(TokenSymbol::DOT), + Box::new(versioned_location.clone()), Box::new(AssetMetadata { name: b"Token Name".to_vec(), symbol: b"TN".to_vec(), @@ -150,8 +123,8 @@ fn update_native_asset_works() { assert_ok!(AssetRegistry::update_native_asset( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token(TokenSymbol::DOT), - Box::new(v3_location.clone()), + Token(TokenSymbol::DOT), + Box::new(versioned_location.clone()), Box::new(AssetMetadata { name: b"New Token Name".to_vec(), symbol: b"NTN".to_vec(), @@ -160,8 +133,8 @@ fn update_native_asset_works() { }) )); - System::assert_last_event(RuntimeEvent::AssetRegistry(crate::Event::AssetUpdated { - asset_id: AssetIds::NativeAssetId(CurrencyId::Token(TokenSymbol::DOT)), + System::assert_last_event(RuntimeEvent::AssetRegistry(Event::AssetUpdated { + asset_id: AssetIds::NativeAssetId(Token(TokenSymbol::DOT)), metadata: AssetMetadata { name: b"New Token Name".to_vec(), symbol: b"NTN".to_vec(), @@ -171,9 +144,7 @@ fn update_native_asset_works() { })); assert_eq!( - AssetMetadatas::::get(AssetIds::NativeAssetId(CurrencyId::Token( - TokenSymbol::DOT - ))), + AssetMetadatas::::get(AssetIds::NativeAssetId(Token(TokenSymbol::DOT))), Some(AssetMetadata { name: b"New Token Name".to_vec(), symbol: b"NTN".to_vec(), @@ -199,7 +170,7 @@ fn register_token_metadata_should_work() { Box::new(metadata.clone()) )); - assert_eq!(CurrencyMetadatas::::get(CurrencyId::Token2(0)), Some(metadata.clone())) + assert_eq!(CurrencyMetadatas::::get(Token2(0)), Some(metadata.clone())) }) } @@ -332,18 +303,15 @@ fn register_multilocation_should_work() { decimals: 12, minimal_balance: 0, }; - // V3 - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: Junctions::X1(Junction::Parachain(2001)), - }); - let multi_location: MultiLocation = location.clone().try_into().unwrap(); + + let versioned_location = VersionedLocation::V4(Location::new(1, [Parachain(2001)])); + let location: xcm::v3::Location = versioned_location.clone().try_into().unwrap(); assert_noop!( - AssetRegistry::register_multilocation( + AssetRegistry::register_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) ), Error::::CurrencyIdNotExists @@ -354,33 +322,27 @@ fn register_multilocation_should_work() { Box::new(metadata.clone()) )); - assert_ok!(AssetRegistry::register_multilocation( + assert_ok!(AssetRegistry::register_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) )); assert_noop!( - AssetRegistry::register_multilocation( + AssetRegistry::register_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) ), Error::::CurrencyIdExisted ); + assert_eq!(LocationToCurrencyIds::::get(location), Some(Token2(0))); + assert_eq!(CurrencyIdToLocations::::get(Token2(0)), Some(location)); assert_eq!( - LocationToCurrencyIds::::get(multi_location), - Some(CurrencyId::Token2(0)) - ); - assert_eq!( - CurrencyIdToLocations::::get(CurrencyId::Token2(0)), - Some(multi_location) - ); - assert_eq!( - CurrencyIdToWeights::::get(CurrencyId::Token2(0)), + CurrencyIdToWeights::::get(Token2(0)), Some(Weight::from_parts(2000_000_000, 0)) ); }) @@ -395,18 +357,14 @@ fn force_set_multilocation_should_work() { decimals: 12, minimal_balance: 0, }; - // V3 - let location = VersionedMultiLocation::V3(MultiLocation { - parents: 1, - interior: Junctions::X1(Junction::Parachain(2001)), - }); - let multi_location: MultiLocation = location.clone().try_into().unwrap(); + let versioned_location = VersionedLocation::V4(Location::new(1, [Parachain(2001)])); + let location: xcm::v3::Location = versioned_location.clone().try_into().unwrap(); assert_noop!( - AssetRegistry::force_set_multilocation( + AssetRegistry::force_set_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) ), Error::::CurrencyIdNotExists @@ -417,31 +375,145 @@ fn force_set_multilocation_should_work() { Box::new(metadata.clone()) )); - assert_ok!(AssetRegistry::force_set_multilocation( + assert_ok!(AssetRegistry::force_set_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) )); - assert_ok!(AssetRegistry::force_set_multilocation( + assert_ok!(AssetRegistry::force_set_location( RuntimeOrigin::signed(CouncilAccount::get()), - CurrencyId::Token2(0), - Box::new(location.clone()), + Token2(0), + Box::new(versioned_location.clone()), Weight::from_parts(2000_000_000, 0) )); + assert_eq!(LocationToCurrencyIds::::get(location), Some(Token2(0))); + assert_eq!(CurrencyIdToLocations::::get(Token2(0)), Some(location)); assert_eq!( - LocationToCurrencyIds::::get(multi_location), - Some(CurrencyId::Token2(0)) - ); - assert_eq!( - CurrencyIdToLocations::::get(CurrencyId::Token2(0)), - Some(multi_location) - ); - assert_eq!( - CurrencyIdToWeights::::get(CurrencyId::Token2(0)), + CurrencyIdToWeights::::get(Token2(0)), Some(Weight::from_parts(2000_000_000, 0)) ); }) } + +#[test] +fn update_currency_metadata_should_work() { + ExtBuilder::default().build().execute_with(|| { + let caller = CouncilAccount::get(); + let currency_id = CurrencyId::Token2(0); + let name = b"Updated Name".to_vec(); + let symbol = b"UN".to_vec(); + let decimals: u8 = 10; + let minimal_balance = 1000u32.into(); + + // Pre-insert a currency_metadata to update + CurrencyMetadatas::::insert( + currency_id, + AssetMetadata { + name: b"Old Name".to_vec(), + symbol: b"ON".to_vec(), + decimals: 8, + minimal_balance: 1u32.into(), + }, + ); + + // Ensure the origin has the required permissions + let origin = RuntimeOrigin::signed(caller); + assert_ok!(AssetRegistry::update_currency_metadata( + origin, + currency_id, + Some(name.clone()), + Some(symbol.clone()), + Some(decimals), + Some(minimal_balance) + )); + + System::assert_last_event(RuntimeEvent::AssetRegistry(crate::Event::CurrencyIdUpdated { + currency_id, + metadata: AssetMetadata { + name: name.clone(), + symbol: symbol.clone(), + decimals, + minimal_balance, + }, + })); + + // Verify the updated metadata + let updated_metadata = CurrencyMetadatas::::get(currency_id).unwrap(); + assert_eq!(updated_metadata.name, name); + assert_eq!(updated_metadata.symbol, symbol); + assert_eq!(updated_metadata.decimals, decimals); + assert_eq!(updated_metadata.minimal_balance, minimal_balance); + }) +} + +#[test] +fn update_currency_metadata_should_work_no_change() { + ExtBuilder::default().build().execute_with(|| { + let caller = CouncilAccount::get(); + let currency_id = CurrencyId::Token2(0); + let name = None; + let symbol = None; + let decimals = None; + let minimal_balance = None; + + let old_metadata = AssetMetadata { + name: b"Old Name".to_vec(), + symbol: b"ON".to_vec(), + decimals: 8, + minimal_balance: 1u32.into(), + }; + + // Pre-insert a currency_metadata to update + CurrencyMetadatas::::insert(currency_id, old_metadata.clone()); + + // Ensure the origin has the required permissions + let origin = RuntimeOrigin::signed(caller); + assert_ok!(AssetRegistry::update_currency_metadata( + origin, + currency_id, + name, + symbol, + decimals, + minimal_balance + )); + + // Verify the event + System::assert_last_event(RuntimeEvent::AssetRegistry(crate::Event::CurrencyIdUpdated { + currency_id, + metadata: old_metadata.clone(), + })); + + // Verify the updated metadata + let updated_metadata = CurrencyMetadatas::::get(currency_id).unwrap(); + assert_eq!(updated_metadata, old_metadata); + }); +} + +#[test] +fn update_currency_metadata_nonexistent_currency_id() { + ExtBuilder::default().build().execute_with(|| { + let caller = CouncilAccount::get(); + let currency_id = CurrencyId::Token2(1); // Non-existent currency ID + let name = Some(b"Updated Name".to_vec()); + let symbol = Some(b"UN".to_vec()); + let decimals = Some(10); + let minimal_balance = Some(1000u32.into()); + + // Ensure the origin has the required permissions + let origin = RuntimeOrigin::signed(caller); + assert_noop!( + AssetRegistry::update_currency_metadata( + origin, + currency_id, + name, + symbol, + decimals, + minimal_balance + ), + Error::::CurrencyIdNotExists + ); + }); +} diff --git a/pallets/asset-registry/src/weights.rs b/pallets/asset-registry/src/weights.rs index de8544355..162c6fad6 100644 --- a/pallets/asset-registry/src/weights.rs +++ b/pallets/asset-registry/src/weights.rs @@ -59,8 +59,9 @@ pub trait WeightInfo { fn register_vtoken_metadata() -> Weight; fn register_vstoken_metadata() -> Weight; fn register_vsbond_metadata() -> Weight; - fn register_multilocation() -> Weight; - fn force_set_multilocation() -> Weight; + fn register_location() -> Weight; + fn force_set_location() -> Weight; + fn update_currency_metadata() -> Weight; } // For backwards compatibility and tests @@ -149,7 +150,7 @@ impl WeightInfo for () { /// Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) /// Storage: AssetRegistry CurrencyIdToWeights (r:0 w:1) /// Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) - fn register_multilocation() -> Weight { + fn register_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -166,7 +167,7 @@ impl WeightInfo for () { /// Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) /// Storage: AssetRegistry CurrencyIdToLocations (r:0 w:1) /// Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) - fn force_set_multilocation() -> Weight { + fn force_set_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -175,4 +176,15 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(1_u64)) .saturating_add(RocksDbWeight::get().writes(3_u64)) } + /// Storage: `AssetRegistry::CurrencyMetadatas` (r:1 w:1) + /// Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn update_currency_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `409` + // Estimated: `3874` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(13_000_000, 3874) + .saturating_add(RocksDbWeight::get().reads(1_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } diff --git a/pallets/buy-back/Cargo.toml b/pallets/buy-back/Cargo.toml new file mode 100644 index 000000000..38a9f9ba5 --- /dev/null +++ b/pallets/buy-back/Cargo.toml @@ -0,0 +1,69 @@ +[package] +authors = ["Kadokura "] +edition = "2021" +name = "bifrost-buy-back" +version = "0.8.0" + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[dependencies] +bifrost-primitives = { workspace = true } +bifrost-slp = { workspace = true } +bifrost-vtoken-minting = { workspace = true } +cumulus-primitives-core = { workspace = true } +frame-benchmarking = { workspace = true, optional = true } +frame-support = { workspace = true } +frame-system = { workspace = true } +hex-literal = { workspace = true } +log = { workspace = true } +orml-traits = { workspace = true } +pallet-balances = { workspace = true } +parity-scale-codec = { workspace = true, features = ["derive"] } +scale-info = { workspace = true, features = ["derive"] } +sp-arithmetic = { workspace = true } +sp-core = { workspace = true } +sp-runtime = { workspace = true } +sp-std = { workspace = true } +xcm = { workspace = true } +zenlink-protocol = { workspace = true } +bifrost-ve-minting = { workspace = true } + +[dev-dependencies] +bifrost-asset-registry = { workspace = true } +bifrost-currencies = { workspace = true } +orml-tokens = { workspace = true } +orml-traits = { workspace = true } +orml-xtokens = { workspace = true } +pallet-xcm = { workspace = true } +sp-core = { workspace = true } +sp-io = { workspace = true } +xcm-builder = { workspace = true } +xcm-executor = { workspace = true } +env_logger = { workspace = true } + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "scale-info/std", + "sp-runtime/std", + "frame-support/std", + "frame-system/std", + "frame-benchmarking/std", + "bifrost-primitives/std", + "orml-traits/std", + "bifrost-vtoken-minting/std", + "zenlink-protocol/std", + "bifrost-slp/std", + "bifrost-asset-registry/std", + "orml-xtokens/std", +] + +runtime-benchmarks = [ + "frame-benchmarking/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", +] +try-runtime = ["frame-support/try-runtime"] diff --git a/pallets/buy-back/src/benchmarking.rs b/pallets/buy-back/src/benchmarking.rs new file mode 100644 index 000000000..1b2ee3f10 --- /dev/null +++ b/pallets/buy-back/src/benchmarking.rs @@ -0,0 +1,75 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +// Ensure we're `no_std` when compiling for Wasm. + +#![cfg(feature = "runtime-benchmarks")] + +use crate::{BalanceOf, Call, Config, Pallet, Pallet as BuyBack, *}; +use bifrost_primitives::{CurrencyId, TokenSymbol, DOT}; +use frame_benchmarking::v1::{account, benchmarks, BenchmarkError}; +use frame_support::{ + assert_ok, + traits::{EnsureOrigin, Hooks}, +}; +use frame_system::RawOrigin; +use orml_traits::MultiCurrency; +use sp_runtime::traits::UniqueSaturatedFrom; + +benchmarks! { + set_vtoken { + let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + }: _(origin,CurrencyId::VToken(TokenSymbol::KSM),1_000_000u32.into(),Permill::from_percent(2),1000u32.into(),1000u32.into(),true) + + charge { + let test_account: T::AccountId = account("seed",1,1); + + T::MultiCurrency::deposit(DOT, &test_account, BalanceOf::::unique_saturated_from(1_000_000_000_000_000u128))?; + }: _(RawOrigin::Signed(test_account),DOT,BalanceOf::::unique_saturated_from(9_000_000_000_000u128)) + + remove_vtoken { + let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + assert_ok!(BuyBack::::set_vtoken( + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, + CurrencyId::VToken(TokenSymbol::KSM), + 1_000_000u32.into(), + Permill::from_percent(2), + 1000u32.into(), + 1000u32.into(), + true + )); + }: _(origin,CurrencyId::Token(TokenSymbol::KSM)) + + + on_idle { + let origin = T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?; + assert_ok!(BuyBack::::set_vtoken( + T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?, + CurrencyId::VToken(TokenSymbol::KSM), + 1_000_000u32.into(), + Permill::from_percent(2), + 1000u32.into(), + 1000u32.into(), + true + )); + }: { + BuyBack::::on_idle(BlockNumberFor::::from(0u32),Weight::from_parts(0, u64::MAX)); + } + + impl_benchmark_test_suite!(BuyBack,crate::mock::ExtBuilder::default().build(),crate::mock::Runtime); +} diff --git a/pallets/buy-back/src/lib.rs b/pallets/buy-back/src/lib.rs new file mode 100644 index 000000000..7504adf3e --- /dev/null +++ b/pallets/buy-back/src/lib.rs @@ -0,0 +1,340 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +// Ensure we're `no_std` when compiling for Wasm. +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(test)] +mod mock; + +#[cfg(test)] +mod tests; + +#[cfg(feature = "runtime-benchmarks")] +mod benchmarking; + +pub mod weights; + +use bifrost_primitives::{ + currency::BNC, CurrencyId, CurrencyIdConversion, CurrencyIdRegister, TryConvertFrom, +}; +use bifrost_ve_minting::VeMintingInterface; +use cumulus_primitives_core::ParaId; +use frame_support::{ + pallet_prelude::*, + sp_runtime::{ + traits::{AccountIdConversion, Zero}, + Permill, SaturatedConversion, + }, + transactional, PalletId, +}; +use frame_system::pallet_prelude::*; +use orml_traits::MultiCurrency; +pub use pallet::*; +use sp_std::vec; +pub use weights::WeightInfo; +use zenlink_protocol::{AssetId, ExportZenlink}; + +pub type AccountIdOf = ::AccountId; + +pub type CurrencyIdOf = <::MultiCurrency as MultiCurrency< + ::AccountId, +>>::CurrencyId; + +type BalanceOf = <::MultiCurrency as MultiCurrency>>::Balance; + +#[frame_support::pallet] +pub mod pallet { + use super::*; + + #[pallet::pallet] + #[pallet::without_storage_info] + pub struct Pallet(_); + + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + + type MultiCurrency: MultiCurrency, CurrencyId = CurrencyId>; + + type ControlOrigin: EnsureOrigin; + + type WeightInfo: WeightInfo; + + type DexOperator: ExportZenlink; + + type CurrencyIdConversion: CurrencyIdConversion; + + #[pallet::constant] + type TreasuryAccount: Get; + + #[pallet::constant] + type RelayChainToken: Get; + + #[pallet::constant] + type BuyBackAccount: Get; + + #[pallet::constant] + type LiquidityAccount: Get; + + type ParachainId: Get; + + type CurrencyIdRegister: CurrencyIdRegister; + + type VeMinting: VeMintingInterface< + AccountIdOf, + CurrencyIdOf, + BalanceOf, + BlockNumberFor, + >; + } + + #[pallet::event] + #[pallet::generate_deposit(pub(super) fn deposit_event)] + pub enum Event { + Charged { who: AccountIdOf, asset_id: CurrencyIdOf, value: BalanceOf }, + ConfigSet { asset_id: CurrencyIdOf, info: Info, BlockNumberFor> }, + Removed { asset_id: CurrencyIdOf }, + BuyBackFailed { asset_id: CurrencyIdOf, block_number: BlockNumberFor }, + BuyBackSuccess { asset_id: CurrencyIdOf, block_number: BlockNumberFor }, + AddLiquidityFailed { asset_id: CurrencyIdOf, block_number: BlockNumberFor }, + AddLiquiditySuccess { asset_id: CurrencyIdOf, block_number: BlockNumberFor }, + } + + #[pallet::error] + pub enum Error { + ArgumentsError, + NotEnoughBalance, + } + + #[pallet::storage] + #[pallet::getter(fn configs)] + pub type Infos = + StorageMap<_, Twox64Concat, CurrencyIdOf, Info, BlockNumberFor>>; + + #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo)] + pub struct Info { + value: BalanceOf, + if_auto: bool, + proportion: Permill, + buyback_duration: BlockNumberFor, + last_buyback: BlockNumberFor, + add_liquidity_duration: BlockNumberFor, + last_add_liquidity: BlockNumberFor, + } + + #[pallet::hooks] + impl Hooks> for Pallet { + fn on_idle(n: BlockNumberFor, _remaining_weight: Weight) -> Weight { + let buyback_address = T::BuyBackAccount::get().into_account_truncating(); + let liquidity_address = T::LiquidityAccount::get().into_account_truncating(); + for (asset_id, mut info) in Infos::::iter() { + if !info.if_auto { + continue; + } + + if info.last_add_liquidity == BlockNumberFor::::from(0u32) || + info.last_add_liquidity + info.add_liquidity_duration == n + { + if let Some(e) = Self::add_liquidity(&liquidity_address, asset_id, &info).err() + { + log::error!( + target: "runtime::add_liquidity", + "Received invalid justification for {:?}", + e, + ); + Self::deposit_event(Event::AddLiquidityFailed { + asset_id, + block_number: n, + }); + } else { + Self::deposit_event(Event::AddLiquiditySuccess { + asset_id, + block_number: n, + }); + } + info.last_add_liquidity = n; + Infos::::insert(asset_id, info.clone()); + } + if info.last_buyback == BlockNumberFor::::from(0u32) || + info.last_buyback + info.buyback_duration == n + { + if let Some(e) = Self::buy_back(&buyback_address, asset_id, &info).err() { + log::error!( + target: "runtime::buy_back", + "Received invalid justification for {:?}", + e, + ); + Self::deposit_event(Event::BuyBackFailed { asset_id, block_number: n }); + } else { + Self::deposit_event(Event::BuyBackSuccess { asset_id, block_number: n }); + } + info.last_buyback = n; + Infos::::insert(asset_id, info); + } + } + T::WeightInfo::on_idle() + } + } + + #[pallet::call] + impl Pallet { + #[pallet::call_index(0)] + #[pallet::weight(T::WeightInfo::set_vtoken())] + pub fn set_vtoken( + origin: OriginFor, + asset_id: CurrencyIdOf, + value: BalanceOf, + proportion: Permill, + buyback_duration: BlockNumberFor, + add_liquidity_duration: BlockNumberFor, + if_auto: bool, + ) -> DispatchResult { + T::ControlOrigin::ensure_origin(origin)?; + + match asset_id { + CurrencyId::Token(token_symbol) => + if !T::CurrencyIdRegister::check_vtoken_registered(token_symbol) { + return Err(Error::::ArgumentsError.into()); + }, + CurrencyId::Token2(token_id) => { + if !T::CurrencyIdRegister::check_vtoken2_registered(token_id) { + return Err(Error::::ArgumentsError.into()); + } + }, + _ => (), + }; + + let info = Info { + value, + if_auto, + proportion, + buyback_duration, + last_buyback: BlockNumberFor::::from(0u32), + add_liquidity_duration, + last_add_liquidity: BlockNumberFor::::from(0u32), + }; + Infos::::insert(asset_id, info.clone()); + + Self::deposit_event(Event::ConfigSet { asset_id, info }); + + Ok(()) + } + + #[pallet::call_index(1)] + #[pallet::weight(T::WeightInfo::charge())] + pub fn charge( + origin: OriginFor, + asset_id: CurrencyIdOf, + value: BalanceOf, + ) -> DispatchResult { + let exchanger = ensure_signed(origin)?; + + T::MultiCurrency::transfer( + asset_id, + &exchanger, + &T::BuyBackAccount::get().into_account_truncating(), + value, + )?; + + Self::deposit_event(Event::Charged { who: exchanger, asset_id, value }); + + Ok(()) + } + + #[pallet::call_index(2)] + #[pallet::weight(T::WeightInfo::remove_vtoken())] + pub fn remove_vtoken(origin: OriginFor, asset_id: CurrencyIdOf) -> DispatchResult { + T::ControlOrigin::ensure_origin(origin)?; + + Infos::::remove(asset_id); + + Self::deposit_event(Event::Removed { asset_id }); + + Ok(()) + } + } + + impl Pallet { + #[transactional] + pub fn buy_back( + buyback_address: &AccountIdOf, + currency_id: CurrencyId, + info: &Info, BlockNumberFor>, + ) -> DispatchResult { + let asset_id: AssetId = + AssetId::try_convert_from(currency_id, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let bnc_asset_id: AssetId = + AssetId::try_convert_from(BNC, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let path = vec![asset_id, bnc_asset_id]; + let balance = T::MultiCurrency::free_balance(currency_id, &buyback_address); + ensure!(balance > Zero::zero(), Error::::NotEnoughBalance); + + T::DexOperator::inner_swap_exact_assets_for_assets( + buyback_address, + balance.min(info.value).saturated_into(), + 0, + &path, + &buyback_address, + )?; + + let bnc_balance = T::MultiCurrency::free_balance(BNC, &buyback_address); + T::VeMinting::notify_reward(0, &Some(buyback_address.clone()), vec![(BNC, bnc_balance)]) + } + + #[transactional] + fn add_liquidity( + buyback_address: &AccountIdOf, + currency_id: CurrencyId, + info: &Info, BlockNumberFor>, + ) -> DispatchResult { + let asset_id: AssetId = + AssetId::try_convert_from(currency_id, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let bnc_asset_id: AssetId = + AssetId::try_convert_from(BNC, T::ParachainId::get().into()) + .map_err(|_| DispatchError::Other("Conversion Error."))?; + let path = vec![asset_id, bnc_asset_id]; + let balance = T::MultiCurrency::free_balance(currency_id, &buyback_address); + let token_balance = info.proportion * balance; + ensure!(token_balance > Zero::zero(), Error::::NotEnoughBalance); + + T::DexOperator::inner_swap_exact_assets_for_assets( + buyback_address, + token_balance.saturated_into(), + 0, + &path, + &buyback_address, + )?; + let remaining_balance = T::MultiCurrency::free_balance(currency_id, &buyback_address); + let bnc_balance = T::MultiCurrency::free_balance(BNC, &buyback_address); + + T::DexOperator::inner_add_liquidity( + buyback_address, + asset_id, + bnc_asset_id, + remaining_balance.saturated_into(), + bnc_balance.saturated_into(), + 0, + 0, + ) + } + } +} diff --git a/pallets/buy-back/src/mock.rs b/pallets/buy-back/src/mock.rs new file mode 100644 index 000000000..61a75824e --- /dev/null +++ b/pallets/buy-back/src/mock.rs @@ -0,0 +1,555 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +// Ensure we're `no_std` when compiling for Wasm. + +#![cfg(test)] +#![allow(non_upper_case_globals)] + +use bifrost_asset_registry::AssetIdMaps; +pub use bifrost_primitives::{currency::*, CurrencyId, SlpxOperator, TokenSymbol}; +use bifrost_slp::{QueryId, QueryResponseManager}; +pub use cumulus_primitives_core::ParaId; +use frame_support::{ + derive_impl, ord_parameter_types, + pallet_prelude::Get, + parameter_types, + sp_runtime::{traits::ConvertInto, DispatchError, DispatchResult}, + traits::{Everything, Nothing}, + PalletId, +}; +use frame_system::{EnsureRoot, EnsureSignedBy}; +use hex_literal::hex; +use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key, MultiCurrency}; +use sp_core::ConstU32; +use sp_runtime::{ + traits::{AccountIdConversion, IdentityLookup, UniqueSaturatedInto}, + AccountId32, BuildStorage, SaturatedConversion, +}; +use sp_std::marker::PhantomData; +use xcm::{v3::Weight, v4::prelude::*}; +use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; +use xcm_executor::XcmExecutor; +use zenlink_protocol::{ + AssetBalance, AssetId as ZenlinkAssetId, LocalAssetHandler, PairLpGenerate, ZenlinkMultiAssets, +}; + +use crate as bifrost_buy_back; + +pub type BlockNumber = u64; +pub type Amount = i128; +pub type Balance = u128; + +pub type AccountId = AccountId32; +pub const ALICE: AccountId = AccountId32::new([0u8; 32]); +pub const BOB: AccountId = AccountId32::new([1u8; 32]); +pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]); +pub const TREASURY_ACCOUNT: AccountId = AccountId32::new([9u8; 32]); + +frame_support::construct_runtime!( + pub enum Runtime { + System: frame_system, + Tokens: orml_tokens, + XTokens: orml_xtokens, + Balances: pallet_balances, + Currencies: bifrost_currencies, + BuyBack: bifrost_buy_back, + Slp: bifrost_slp, + VtokenMinting: bifrost_vtoken_minting, + ZenlinkProtocol: zenlink_protocol, + AssetRegistry: bifrost_asset_registry, + PolkadotXcm: pallet_xcm, + VeMinting: bifrost_ve_minting, + } +); + +ord_parameter_types! { + pub const CouncilAccount: AccountId = AccountId::from([1u8; 32]); +} +impl bifrost_asset_registry::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type RegisterOrigin = EnsureSignedBy; + type WeightInfo = (); +} + +type Block = frame_system::mocking::MockBlock; + +parameter_types! { + pub const BlockHashCount: u64 = 250; +} + +#[derive_impl(frame_system::config_preludes::TestDefaultConfig as frame_system::DefaultConfig)] +impl frame_system::Config for Runtime { + type AccountData = pallet_balances::AccountData; + type AccountId = AccountId; + type Block = Block; + type Lookup = IdentityLookup; +} + +parameter_types! { + pub const GetNativeCurrencyId: CurrencyId = CurrencyId::Native(TokenSymbol::BNC); +} + +pub type AdaptedBasicCurrency = + bifrost_currencies::BasicCurrencyAdapter; + +impl bifrost_currencies::Config for Runtime { + type GetNativeCurrencyId = GetNativeCurrencyId; + type MultiCurrency = Tokens; + type NativeCurrency = AdaptedBasicCurrency; + type WeightInfo = (); +} + +parameter_types! { + pub const ExistentialDeposit: Balance = 1; +} + +impl pallet_balances::Config for Runtime { + type AccountStore = frame_system::Pallet; + type Balance = Balance; + type DustRemoval = (); + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposit = ExistentialDeposit; + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type WeightInfo = (); + type RuntimeHoldReason = RuntimeHoldReason; + type RuntimeFreezeReason = RuntimeFreezeReason; + type FreezeIdentifier = (); + type MaxFreezes = ConstU32<0>; +} + +orml_traits::parameter_type_with_key! { + pub ExistentialDeposits: |_currency_id: CurrencyId| -> Balance { + 0 + }; +} +impl orml_tokens::Config for Runtime { + type Amount = i128; + type Balance = Balance; + type CurrencyId = CurrencyId; + type DustRemovalWhitelist = Nothing; + type RuntimeEvent = RuntimeEvent; + type ExistentialDeposits = ExistentialDeposits; + type MaxLocks = (); + type MaxReserves = (); + type ReserveIdentifier = [u8; 8]; + type WeightInfo = (); + type CurrencyHooks = (); +} + +parameter_types! { + pub const TreasuryAccount: AccountId32 = TREASURY_ACCOUNT; + pub BifrostVsbondAccount: PalletId = PalletId(*b"bf/salpb"); + pub const BuyBackAccount: PalletId = PalletId(*b"bf/bybck"); + pub const LiquidityAccount: PalletId = PalletId(*b"bf/liqdt"); +} + +ord_parameter_types! { + pub const One: AccountId = ALICE; + // pub const RelayChainTokenSymbolKSM: TokenSymbol = TokenSymbol::KSM; + pub const RelayCurrencyId: CurrencyId = CurrencyId::Token(TokenSymbol::KSM); +} + +impl bifrost_buy_back::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiCurrency = Currencies; + type ControlOrigin = EnsureSignedBy; + type WeightInfo = (); + type DexOperator = ZenlinkProtocol; + type CurrencyIdConversion = AssetIdMaps; + type TreasuryAccount = TreasuryAccount; + type RelayChainToken = RelayCurrencyId; + type BuyBackAccount = BuyBackAccount; + type LiquidityAccount = LiquidityAccount; + type ParachainId = ParaInfo; + type CurrencyIdRegister = AssetIdMaps; + type VeMinting = VeMinting; +} + +pub struct ParaInfo; +impl Get for ParaInfo { + fn get() -> ParaId { + ParaId::from(2001) + } +} + +pub struct ParachainId; +impl Get for ParachainId { + fn get() -> ParaId { + 2001.into() + } +} + +parameter_types! { + pub const MaxTypeEntryPerBlock: u32 = 10; + pub const MaxRefundPerBlock: u32 = 10; + pub const MaxLengthLimit: u32 = 100; +} + +pub struct SubstrateResponseManager; +impl QueryResponseManager for SubstrateResponseManager { + fn get_query_response_record(_query_id: QueryId) -> bool { + Default::default() + } + fn create_query_record( + _responder: Location, + _call_back: Option, + _timeout: u64, + ) -> u64 { + Default::default() + } + fn remove_query_record(_query_id: QueryId) -> bool { + Default::default() + } +} + +pub struct SlpxInterface; +impl SlpxOperator for SlpxInterface { + fn get_moonbeam_transfer_to_fee() -> Balance { + Default::default() + } +} + +impl bifrost_slp::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + type MultiCurrency = Currencies; + type ControlOrigin = EnsureSignedBy; + type WeightInfo = (); + type VtokenMinting = VtokenMinting; + type AccountConverter = (); + type ParachainId = ParachainId; + type SubstrateResponseManager = SubstrateResponseManager; + type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; + type MaxRefundPerBlock = MaxRefundPerBlock; + type ParachainStaking = (); + type XcmTransfer = XTokens; + type MaxLengthLimit = MaxLengthLimit; + type XcmWeightAndFeeHandler = (); + type ChannelCommission = (); + type StablePoolHandler = (); + type AssetIdMaps = AssetIdMaps; + type TreasuryAccount = TreasuryAccount; +} + +parameter_type_with_key! { + pub ParachainMinFee: |_location: Location| -> Option { + Some(u128::MAX) + }; +} + +parameter_types! { + pub SelfRelativeLocation: Location = Location::here(); + pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); + pub const MaxAssetsForTransfer: usize = 2; +} + +impl orml_xtokens::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type CurrencyId = CurrencyId; + type CurrencyIdConvert = (); + type AccountIdToLocation = (); + type UniversalLocation = UniversalLocation; + type SelfLocation = SelfRelativeLocation; + type XcmExecutor = XcmExecutor; + type Weigher = FixedWeightBounds; + type BaseXcmWeight = BaseXcmWeight; + type MaxAssetsForTransfer = MaxAssetsForTransfer; + type MinXcmFee = ParachainMinFee; + type LocationsFilter = Everything; + type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); +} + +parameter_types! { + pub const MaximumUnlockIdOfUser: u32 = 10; + pub const MaximumUnlockIdOfTimeUnit: u32 = 50; + pub BifrostEntranceAccount: PalletId = PalletId(*b"bf/vtkin"); + pub BifrostExitAccount: PalletId = PalletId(*b"bf/vtout"); + pub BifrostFeeAccount: AccountId = hex!["e4da05f08e89bf6c43260d96f26fffcfc7deae5b465da08669a9d008e64c2c63"].into(); + pub IncentivePoolAccount: PalletId = PalletId(*b"bf/inpoo"); +} + +impl bifrost_vtoken_minting::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiCurrency = Currencies; + type ControlOrigin = EnsureSignedBy; + type MaximumUnlockIdOfUser = MaximumUnlockIdOfUser; + type MaximumUnlockIdOfTimeUnit = MaximumUnlockIdOfTimeUnit; + type EntranceAccount = BifrostEntranceAccount; + type ExitAccount = BifrostExitAccount; + type FeeAccount = BifrostFeeAccount; + type RedeemFeeAccount = BifrostFeeAccount; + type BifrostSlp = Slp; + type BifrostSlpx = SlpxInterface; + type RelayChainToken = RelayCurrencyId; + type CurrencyIdConversion = AssetIdMaps; + type CurrencyIdRegister = AssetIdMaps; + type WeightInfo = (); + type OnRedeemSuccess = (); + type XcmTransfer = XTokens; + type AstarParachainId = ConstU32<2007>; + type MoonbeamParachainId = ConstU32<2023>; + type HydradxParachainId = ConstU32<2034>; + type MantaParachainId = ConstU32<2104>; + type InterlayParachainId = ConstU32<2032>; + type ChannelCommission = (); + type MaxLockRecords = ConstU32<100>; + type IncentivePoolAccount = IncentivePoolAccount; + type VeMinting = (); + type AssetIdMaps = AssetIdMaps; +} + +parameter_types! { + pub const ZenlinkPalletId: PalletId = PalletId(*b"/zenlink"); + pub const GetExchangeFee: (u32, u32) = (3, 1000); // 0.3% + pub const SelfParaId: u32 = 2001; +} + +impl zenlink_protocol::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiAssetsHandler = MultiAssets; + type PalletId = ZenlinkPalletId; + type SelfParaId = SelfParaId; + type TargetChains = (); + type WeightInfo = (); + type AssetId = ZenlinkAssetId; + type LpGenerate = PairLpGenerate; +} + +type MultiAssets = ZenlinkMultiAssets>; + +// Below is the implementation of tokens manipulation functions other than native token. +pub struct LocalAssetAdaptor(PhantomData); + +impl LocalAssetHandler for LocalAssetAdaptor +where + Local: MultiCurrency, +{ + fn local_balance_of(asset_id: ZenlinkAssetId, who: &AccountId) -> AssetBalance { + let currency_id: CurrencyId = asset_id.try_into().unwrap(); + Local::free_balance(currency_id, &who).saturated_into() + } + + fn local_total_supply(asset_id: ZenlinkAssetId) -> AssetBalance { + let currency_id: CurrencyId = asset_id.try_into().unwrap(); + Local::total_issuance(currency_id).saturated_into() + } + + fn local_is_exists(asset_id: ZenlinkAssetId) -> bool { + let rs: Result = asset_id.try_into(); + match rs { + Ok(_) => true, + Err(_) => false, + } + } + + fn local_transfer( + asset_id: ZenlinkAssetId, + origin: &AccountId, + target: &AccountId, + amount: AssetBalance, + ) -> DispatchResult { + let currency_id: CurrencyId = asset_id.try_into().unwrap(); + Local::transfer(currency_id, &origin, &target, amount.unique_saturated_into())?; + + Ok(()) + } + + fn local_deposit( + asset_id: ZenlinkAssetId, + origin: &AccountId, + amount: AssetBalance, + ) -> Result { + let currency_id: CurrencyId = asset_id.try_into().unwrap(); + Local::deposit(currency_id, &origin, amount.unique_saturated_into())?; + return Ok(amount); + } + + fn local_withdraw( + asset_id: ZenlinkAssetId, + origin: &AccountId, + amount: AssetBalance, + ) -> Result { + let currency_id: CurrencyId = asset_id.try_into().unwrap(); + Local::withdraw(currency_id, &origin, amount.unique_saturated_into())?; + + Ok(amount) + } +} + +parameter_types! { + // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 + pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); + pub const MaxInstructions: u32 = 100; + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); +} + +pub struct XcmConfig; +impl xcm_executor::Config for XcmConfig { + type AssetClaims = PolkadotXcm; + type AssetTransactor = (); + type AssetTrap = PolkadotXcm; + type Barrier = (); + type RuntimeCall = RuntimeCall; + type IsReserve = (); + type IsTeleporter = (); + type UniversalLocation = UniversalLocation; + type OriginConverter = (); + type ResponseHandler = PolkadotXcm; + type SubscriptionService = PolkadotXcm; + type Trader = (); + type Weigher = FixedWeightBounds; + type XcmSender = (); + type PalletInstancesInfo = AllPalletsWithSystem; + type MaxAssetsIntoHolding = ConstU32<64>; + type FeeManager = (); + type MessageExporter = (); + type UniversalAliases = Nothing; + type CallDispatcher = RuntimeCall; + type SafeCallFilter = Everything; + type AssetLocker = (); + type AssetExchanger = (); + type Aliasers = Nothing; + type TransactionalProcessor = FrameTransactionalProcessor; +} + +#[cfg(feature = "runtime-benchmarks")] +parameter_types! { + pub ReachableDest: Option = Some(Parent.into()); +} + +impl pallet_xcm::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; + type UniversalLocation = UniversalLocation; + type SendXcmOrigin = xcm_builder::EnsureXcmOrigin; + type Weigher = FixedWeightBounds; + type XcmExecuteFilter = Nothing; + type XcmExecutor = XcmExecutor; + type XcmReserveTransferFilter = Everything; + type XcmRouter = (); + type XcmTeleportFilter = Nothing; + type RuntimeOrigin = RuntimeOrigin; + type RuntimeCall = RuntimeCall; + const VERSION_DISCOVERY_QUEUE_SIZE: u32 = 100; + type AdvertisedXcmVersion = ConstU32<2>; + type Currency = Balances; + type CurrencyMatcher = (); + type TrustedLockers = (); + type SovereignAccountOf = (); + type MaxLockers = ConstU32<8>; + type WeightInfo = pallet_xcm::TestWeightInfo; + type AdminOrigin = EnsureRoot; + type MaxRemoteLockConsumers = ConstU32<0>; + type RemoteLockConsumerIdentifier = (); +} + +parameter_types! { + pub const VeMintingTokenType: CurrencyId = CurrencyId::VToken(TokenSymbol::BNC); + pub VeMintingPalletId: PalletId = PalletId(*b"bf/vemnt"); + pub IncentivePalletId: PalletId = PalletId(*b"bf/veict"); + pub const Week: BlockNumber = 50400; // a week + pub const MaxBlock: BlockNumber = 10512000; // four years + pub const Multiplier: Balance = 10_u128.pow(12); + pub const VoteWeightMultiplier: Balance = 1; + pub const MaxPositions: u32 = 10; + pub const MarkupRefreshLimit: u32 = 100; +} + +impl bifrost_ve_minting::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiCurrency = Currencies; + type ControlOrigin = EnsureSignedBy; + type TokenType = VeMintingTokenType; + type VeMintingPalletId = VeMintingPalletId; + type IncentivePalletId = IncentivePalletId; + type WeightInfo = (); + type BlockNumberToBalance = ConvertInto; + type Week = Week; + type MaxBlock = MaxBlock; + type Multiplier = Multiplier; + type VoteWeightMultiplier = VoteWeightMultiplier; + type MaxPositions = MaxPositions; + type MarkupRefreshLimit = MarkupRefreshLimit; +} + +pub struct ExtBuilder { + endowed_accounts: Vec<(AccountId, CurrencyId, Balance)>, +} + +impl Default for ExtBuilder { + fn default() -> Self { + Self { endowed_accounts: vec![] } + } +} + +impl ExtBuilder { + pub fn balances(mut self, endowed_accounts: Vec<(AccountId, CurrencyId, Balance)>) -> Self { + self.endowed_accounts = endowed_accounts; + self + } + + pub fn one_hundred_for_alice_n_bob(self) -> Self { + self.balances(vec![ + (ALICE, BNC, 10000), + (BOB, BNC, 100), + (CHARLIE, BNC, 100), + // (ALICE, RelayCurrencyId::get(), 10000), + (ALICE, VKSM, 10000), + (BOB, KSM, 100), + (BuyBackAccount::get().into_account_truncating(), VKSM, 9000), + (BuyBackAccount::get().into_account_truncating(), KSM, 10000), + ]) + } + + pub fn build(self) -> sp_io::TestExternalities { + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + env_logger::try_init().unwrap_or(()); + + pallet_balances::GenesisConfig:: { + balances: self + .endowed_accounts + .clone() + .into_iter() + .filter(|(_, currency_id, _)| *currency_id == BNC) + .map(|(account_id, _, initial_balance)| (account_id, initial_balance)) + .collect::>(), + } + .assimilate_storage(&mut t) + .unwrap(); + + orml_tokens::GenesisConfig:: { + balances: self + .endowed_accounts + .into_iter() + .filter(|(_, currency_id, _)| *currency_id != BNC) + .collect::>(), + } + .assimilate_storage(&mut t) + .unwrap(); + + t.into() + } +} diff --git a/pallets/buy-back/src/tests.rs b/pallets/buy-back/src/tests.rs new file mode 100644 index 000000000..8a0e9a99e --- /dev/null +++ b/pallets/buy-back/src/tests.rs @@ -0,0 +1,122 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +// Ensure we're `no_std` when compiling for Wasm. + +#![cfg(test)] + +use crate::{mock::*, *}; +use frame_support::assert_ok; +use sp_arithmetic::per_things::Permill; + +#[test] +fn buy_back_should_work() { + ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| { + let para_id = 2001u32; + let zenlink_pair_account_id = init_zenlink(para_id); + + assert_ok!(BuyBack::set_vtoken( + RuntimeOrigin::signed(ALICE), + VKSM, + 1000u128, + Permill::from_percent(2), + 1000, + 1000, + true + )); + let buyback_account = ::BuyBackAccount::get().into_account_truncating(); + let incentive_account = IncentivePalletId::get().into_account_truncating(); + assert_eq!(Currencies::free_balance(VKSM, &buyback_account), 9000); + assert_eq!(Currencies::free_balance(VKSM, &zenlink_pair_account_id), 2200); + assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); + assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); + assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); + VeMinting::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); + let infos = Infos::::get(VKSM).unwrap(); + assert_ok!(BuyBack::buy_back(&buyback_account, VKSM, &infos)); + System::set_block_number(System::block_number() + 1); + assert_eq!(Currencies::free_balance(VKSM, &buyback_account), 9000); + assert_eq!(Currencies::free_balance(VKSM, &zenlink_pair_account_id), 3200); + assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 1377); + assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); + assert_eq!(Currencies::free_balance(BNC, &incentive_account), 623); + }); +} + +#[test] +fn on_idle_should_work() { + ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| { + let para_id = 2001u32; + let zenlink_pair_account_id = init_zenlink(para_id); + + assert_ok!(BuyBack::set_vtoken( + RuntimeOrigin::signed(ALICE), + VKSM, + 1_000_000u128, + Permill::from_percent(2), + 1000, + 1000, + true + )); + let buyback_account = ::BuyBackAccount::get().into_account_truncating(); + let incentive_account = IncentivePalletId::get().into_account_truncating(); + assert_eq!(Currencies::free_balance(VKSM, &buyback_account), 9000); + assert_eq!(Currencies::free_balance(VKSM, &zenlink_pair_account_id), 2200); + assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 2000); + assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); + assert_eq!(Currencies::free_balance(BNC, &incentive_account), 0); + VeMinting::set_incentive(0, Some(7 * 86400 / 12), Some(buyback_account.clone())); + assert_ok!(BuyBack::charge(RuntimeOrigin::signed(ALICE), VKSM, 1000)); + BuyBack::on_idle( + >::block_number(), + Weight::from_parts(100000000, 0), + ); + System::set_block_number(System::block_number() + 1); + assert_eq!(Currencies::free_balance(VKSM, &buyback_account), 0); + assert_eq!(Currencies::free_balance(VKSM, &zenlink_pair_account_id), 12200); + assert_eq!(Currencies::free_balance(BNC, &zenlink_pair_account_id), 362); + assert_eq!(Currencies::free_balance(BNC, &buyback_account), 0); + assert_eq!(Currencies::free_balance(BNC, &incentive_account), 1638); + }); +} + +fn init_zenlink(para_id: u32) -> AccountIdOf { + let asset_0_currency_id: AssetId = AssetId::try_convert_from(BNC, para_id).unwrap(); + let asset_1_currency_id: AssetId = AssetId::try_convert_from(VKSM, para_id).unwrap(); + // let path = vec![asset_0_currency_id, asset_1_currency_id]; + assert_ok!(ZenlinkProtocol::create_pair( + RuntimeOrigin::root(), + asset_0_currency_id, + asset_1_currency_id, + ALICE + )); + let deadline: BlockNumberFor = + >::block_number() + BlockNumberFor::::from(100u32); + assert_ok!(ZenlinkProtocol::add_liquidity( + RuntimeOrigin::signed(ALICE), + asset_0_currency_id, + asset_1_currency_id, + 2000, + 2200, + 1, + 1, + deadline + )); + ZenlinkProtocol::pair_account_id(asset_0_currency_id, asset_1_currency_id) +} diff --git a/pallets/buy-back/src/weights.rs b/pallets/buy-back/src/weights.rs new file mode 100644 index 000000000..2776509fd --- /dev/null +++ b/pallets/buy-back/src/weights.rs @@ -0,0 +1,138 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +//! Autogenerated weights for `bifrost_buy_back` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-06-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `yml`, CPU: `AMD Ryzen 9 3950X 16-Core Processor` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bifrost-polkadot-local")`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/bifrost +// benchmark +// pallet +// --chain=bifrost-polkadot-local +// --pallet=bifrost-buy-back +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./bifrost-buy-back.rs + +#![cfg_attr(rustfmt, rustfmt_skip)] +#![allow(unused_parens)] +#![allow(unused_imports)] +#![allow(missing_docs)] + +use frame_support::{traits::Get, weights::{constants::RocksDbWeight, Weight}}; +use core::marker::PhantomData; + +/// Weight functions for `bifrost_buy_back`. +impl WeightInfo for () { + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `BuyBack::Infos` (r:0 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn set_vtoken() -> Weight { + // Proof Size summary in bytes: + // Measured: `25` + // Estimated: `1510` + // Minimum execution time: 11_582_000 picoseconds. + Weight::from_parts(11_753_000, 0) + .saturating_add(Weight::from_parts(0, 1510)) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(3)) + } + /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn charge() -> Weight { + // Proof Size summary in bytes: + // Measured: `508` + // Estimated: `6196` + // Minimum execution time: 43_842_000 picoseconds. + Weight::from_parts(44_144_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(RocksDbWeight::get().reads(8)) + .saturating_add(RocksDbWeight::get().writes(5)) + } + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `BuyBack::Infos` (r:0 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_vtoken() -> Weight { + // Proof Size summary in bytes: + // Measured: `25` + // Estimated: `1510` + // Minimum execution time: 10_931_000 picoseconds. + Weight::from_parts(11_161_000, 0) + .saturating_add(Weight::from_parts(0, 1510)) + .saturating_add(RocksDbWeight::get().reads(4)) + .saturating_add(RocksDbWeight::get().writes(3)) + } + /// Storage: `BuyBack::Infos` (r:2 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:2 w:0) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + fn on_idle() -> Weight { + // Proof Size summary in bytes: + // Measured: `502` + // Estimated: `6442` + // Minimum execution time: 32_792_000 picoseconds. + Weight::from_parts(33_293_000, 0) + .saturating_add(Weight::from_parts(0, 6442)) + .saturating_add(RocksDbWeight::get().reads(5)) + .saturating_add(RocksDbWeight::get().writes(1)) + } +} + + +/// Weight functions needed for bifrost_buy_back. +pub trait WeightInfo { + fn set_vtoken() -> Weight; + fn charge() -> Weight; + fn remove_vtoken() -> Weight; + fn on_idle() -> Weight; +} diff --git a/pallets/call-switchgear/src/mock.rs b/pallets/call-switchgear/src/mock.rs index d93dde0f4..f75e1e5d8 100644 --- a/pallets/call-switchgear/src/mock.rs +++ b/pallets/call-switchgear/src/mock.rs @@ -61,7 +61,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/channel-commission/src/mock.rs b/pallets/channel-commission/src/mock.rs index 29e7b2ec5..69ef466b2 100644 --- a/pallets/channel-commission/src/mock.rs +++ b/pallets/channel-commission/src/mock.rs @@ -96,7 +96,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/clouds-convert/src/mock.rs b/pallets/clouds-convert/src/mock.rs index b1062a5fa..cf44d4be6 100644 --- a/pallets/clouds-convert/src/mock.rs +++ b/pallets/clouds-convert/src/mock.rs @@ -120,7 +120,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/cross-in-out/src/mock.rs b/pallets/cross-in-out/src/mock.rs index 4b5623f3c..527975bec 100644 --- a/pallets/cross-in-out/src/mock.rs +++ b/pallets/cross-in-out/src/mock.rs @@ -95,7 +95,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/currencies/src/mock.rs b/pallets/currencies/src/mock.rs index a4520ea5b..66005251b 100644 --- a/pallets/currencies/src/mock.rs +++ b/pallets/currencies/src/mock.rs @@ -42,7 +42,6 @@ impl pallet_balances::Config for Runtime { type ReserveIdentifier = ReserveIdentifier; type WeightInfo = (); type FreezeIdentifier = [u8; 8]; - type MaxHolds = (); type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; diff --git a/pallets/farming/rpc/src/lib.rs b/pallets/farming/rpc/src/lib.rs index 5a02dbbb4..9a926babd 100644 --- a/pallets/farming/rpc/src/lib.rs +++ b/pallets/farming/rpc/src/lib.rs @@ -23,7 +23,7 @@ use bifrost_primitives::Balance; use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, + types::error::{ErrorCode, ErrorObject}, }; use parity_scale_codec::Codec; use sp_api::ProvideRuntimeApi; @@ -92,13 +92,12 @@ where .into_iter() .map(|(token, amount)| (token, NumberOrHex::Hex(amount.into()))) .collect()), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get farming rewards.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } fn get_gauge_rewards( @@ -117,12 +116,11 @@ where .into_iter() .map(|(token, amount)| (token, NumberOrHex::Hex(amount.into()))) .collect()), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get gauge rewards.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } } diff --git a/pallets/farming/src/mock.rs b/pallets/farming/src/mock.rs index 969ff2ec3..899a71430 100644 --- a/pallets/farming/src/mock.rs +++ b/pallets/farming/src/mock.rs @@ -100,7 +100,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/fee-share/src/mock.rs b/pallets/fee-share/src/mock.rs index ac61b7fdf..f60adbbde 100644 --- a/pallets/fee-share/src/mock.rs +++ b/pallets/fee-share/src/mock.rs @@ -36,12 +36,9 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use hex_literal::hex; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key, MultiCurrency}; -use parity_scale_codec::{Decode, Encode}; -use sp_core::{hashing::blake2_256, ConstU32}; +use sp_core::ConstU32; use sp_runtime::{ - traits::{ - AccountIdConversion, Convert, IdentityLookup, TrailingZeroInput, UniqueSaturatedInto, - }, + traits::{AccountIdConversion, IdentityLookup, UniqueSaturatedInto}, AccountId32, BuildStorage, SaturatedConversion, }; use sp_std::marker::PhantomData; @@ -135,7 +132,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -184,48 +180,6 @@ impl Get for ParaInfo { } } -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - Junction::AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex_literal::hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -240,12 +194,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -271,13 +225,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -289,13 +241,13 @@ impl bifrost_slp::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -305,7 +257,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -313,8 +265,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -353,6 +307,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -437,7 +392,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -471,7 +426,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/flexible-fee/rpc/src/lib.rs b/pallets/flexible-fee/rpc/src/lib.rs index 00997feb0..c99fb3cdd 100644 --- a/pallets/flexible-fee/rpc/src/lib.rs +++ b/pallets/flexible-fee/rpc/src/lib.rs @@ -23,7 +23,7 @@ use bifrost_primitives::{Balance, CurrencyId}; use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorObject}, + types::error::ErrorObject, }; pub use pallet_transaction_payment_rpc_runtime_api::TransactionPaymentApi as TransactionPaymentRuntimeApi; use parity_scale_codec::{Codec, Decode}; @@ -100,19 +100,19 @@ where let encoded_len = encoded_xt.len() as u32; let uxt: Block::Extrinsic = Decode::decode(&mut &*encoded_xt).map_err(|e| { - CallError::Custom(ErrorObject::owned( + ErrorObject::owned( Error::DecodeError.into(), "Unable to query fee details.", Some(format!("{:?}", e)), - )) + ) })?; let fee_details = api.query_fee_details(at, uxt.clone(), encoded_len).map_err(|e| { - CallError::Custom(ErrorObject::owned( + ErrorObject::owned( Error::RuntimeError.into(), "Unable to query fee details.", Some(format!("{:?}", e)), - )) + ) })?; let total_inclusion_fee: Balance = { @@ -131,22 +131,21 @@ where let try_into_rpc_balance = |value: Balance| { value.try_into().map_err(|e| { - CallError::Custom(ErrorObject::owned( + ErrorObject::owned( Error::RuntimeError.into(), format!("{} doesn't fit in NumberOrHex representation", value), Some(format!("{:?}", e)), - )) + ) }) }; match rs { Ok((id, val)) => try_into_rpc_balance(val).map(|value| (id, value)), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( Error::RuntimeError.into(), "Unable to query fee token and amount.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } } diff --git a/pallets/flexible-fee/src/mock.rs b/pallets/flexible-fee/src/mock.rs index 7c26edd90..5d7948e7d 100644 --- a/pallets/flexible-fee/src/mock.rs +++ b/pallets/flexible-fee/src/mock.rs @@ -48,7 +48,7 @@ use sp_runtime::{ }; use sp_std::marker::PhantomData; use std::convert::TryInto; -use xcm::prelude::*; +use xcm::{prelude::*, v3::MultiLocation}; use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; use xcm_executor::XcmExecutor; use zenlink_protocol::{ @@ -144,7 +144,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -414,7 +413,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -448,7 +447,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Test { @@ -527,7 +526,7 @@ impl DerivativeAccountHandler for DerivativeAccount { _token: CurrencyId, _derivative_index: DerivativeIndex, ) -> Option { - Some(Parent.into()) + Some(xcm::v3::Parent.into()) } fn get_stake_info( diff --git a/pallets/flexible-fee/src/tests.rs b/pallets/flexible-fee/src/tests.rs index 1d57badb8..8ad017fbc 100644 --- a/pallets/flexible-fee/src/tests.rs +++ b/pallets/flexible-fee/src/tests.rs @@ -89,25 +89,29 @@ fn basic_setup() { assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_1_currency_id + asset_1_currency_id, + ALICE )); assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_2_currency_id + asset_2_currency_id, + ALICE )); assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_3_currency_id + asset_3_currency_id, + ALICE )); assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_4_currency_id + asset_4_currency_id, + ALICE )); let mut deadline: BlockNumberFor = diff --git a/pallets/lend-market/rpc/src/lib.rs b/pallets/lend-market/rpc/src/lib.rs index 6ea27754b..f99569287 100644 --- a/pallets/lend-market/rpc/src/lib.rs +++ b/pallets/lend-market/rpc/src/lib.rs @@ -18,9 +18,9 @@ pub use lend_market_rpc_runtime_api::LendMarketApi as LendMarketRuntimeApi; use bifrost_primitives::{CurrencyId, Liquidity, Rate, Ratio, Shortfall}; use jsonrpsee::{ - core::{async_trait, Error as JsonRpseeError, RpcResult}, + core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, + types::error::{ErrorCode, ErrorObject}, }; use parity_scale_codec::Codec; use sp_api::ProvideRuntimeApi; @@ -158,40 +158,36 @@ where } /// Converts a runtime trap into an RPC error. -fn runtime_error_into_rpc_error(err: impl std::fmt::Debug) -> JsonRpseeError { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( - Error::RuntimeError.into(), - "Runtime trapped", - Some(format!("{:?}", err)), - ))) +fn runtime_error_into_rpc_error(err: impl std::fmt::Debug) -> ErrorObject<'static> { + ErrorObject::owned(Error::RuntimeError.into(), "Runtime trapped", Some(format!("{:?}", err))) } /// Converts an account liquidity error into an RPC error. -fn account_liquidity_error_into_rpc_error(err: impl std::fmt::Debug) -> JsonRpseeError { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( +fn account_liquidity_error_into_rpc_error(err: impl std::fmt::Debug) -> ErrorObject<'static> { + ErrorObject::owned( Error::AccountLiquidityError.into(), "Not able to get account liquidity", Some(format!("{:?}", err)), - ))) + ) } /// Converts an market status error into an RPC error. -fn market_status_error_into_rpc_error(err: impl std::fmt::Debug) -> JsonRpseeError { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( +fn market_status_error_into_rpc_error(err: impl std::fmt::Debug) -> ErrorObject<'static> { + ErrorObject::owned( Error::MarketStatusError.into(), "Not able to get market status", Some(format!("{:?}", err)), - ))) + ) } fn try_into_rpc_balance>( value: T, ) -> RpcResult { value.try_into().map_err(|_| { - JsonRpseeError::Call(CallError::Custom(ErrorObject::owned( + ErrorObject::owned( ErrorCode::InvalidParams.code(), format!("{} doesn't fit in NumberOrHex representation", value), None::<()>, - ))) + ) }) } diff --git a/pallets/lend-market/src/mock.rs b/pallets/lend-market/src/mock.rs index c9c303c2b..79b560c3a 100644 --- a/pallets/lend-market/src/mock.rs +++ b/pallets/lend-market/src/mock.rs @@ -106,7 +106,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/leverage-staking/src/mock.rs b/pallets/leverage-staking/src/mock.rs index 262ca6617..c909670c6 100644 --- a/pallets/leverage-staking/src/mock.rs +++ b/pallets/leverage-staking/src/mock.rs @@ -40,10 +40,7 @@ use std::{ collections::HashMap, hash::{Hash, Hasher}, }; -use xcm::{ - prelude::*, - v3::{MultiLocation, Weight}, -}; +use xcm::{prelude::*, v3::Weight}; use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; use xcm_executor::XcmExecutor; @@ -133,7 +130,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -166,16 +163,16 @@ impl xcm_executor::Config for XcmConfig { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: xcm::v4::Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: xcm::v4::Location = xcm::v4::Location::here(); // pub const BaseXcmWeight: Weight = Weight::from_ref_time(1000_000_000u64); pub const MaxAssetsForTransfer: usize = 2; - // pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + // pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } impl orml_xtokens::Config for Test { @@ -183,7 +180,7 @@ impl orml_xtokens::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -191,8 +188,10 @@ impl orml_xtokens::Config for Test { type BaseXcmWeight = (); type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -210,7 +209,6 @@ impl pallet_balances::Config for Test { type ReserveIdentifier = [u8; 8]; type WeightInfo = (); type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; @@ -319,6 +317,7 @@ impl bifrost_vtoken_minting::Config for Test { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } pub struct Slp; @@ -450,11 +449,6 @@ impl pallet_prices::Config for Test { type WeightInfo = (); } -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Test { type RuntimeEvent = RuntimeEvent; type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; diff --git a/pallets/parachain-staking/src/mock.rs b/pallets/parachain-staking/src/mock.rs index 01d101b83..29303a027 100644 --- a/pallets/parachain-staking/src/mock.rs +++ b/pallets/parachain-staking/src/mock.rs @@ -74,7 +74,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } parameter_types! { diff --git a/pallets/prices/src/lib.rs b/pallets/prices/src/lib.rs index 89281e53f..28339aa0b 100644 --- a/pallets/prices/src/lib.rs +++ b/pallets/prices/src/lib.rs @@ -75,7 +75,7 @@ pub mod pallet { #[pallet::constant] type RelayCurrency: Get; - /// Convert MultiLocation to `T::CurrencyId`. + /// Convert Location to `T::CurrencyId`. type CurrencyIdConvert: CurrencyIdMapping< CurrencyId, MultiLocation, diff --git a/pallets/prices/src/mock.rs b/pallets/prices/src/mock.rs index 991eef464..c01150e0e 100644 --- a/pallets/prices/src/mock.rs +++ b/pallets/prices/src/mock.rs @@ -123,7 +123,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/salp/rpc/src/lib.rs b/pallets/salp/rpc/src/lib.rs index f2d97354d..ebd2a8222 100644 --- a/pallets/salp/rpc/src/lib.rs +++ b/pallets/salp/rpc/src/lib.rs @@ -23,7 +23,7 @@ pub use bifrost_salp_rpc_runtime_api::{self as runtime_api, SalpRuntimeApi}; use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, + types::error::{ErrorCode, ErrorObject}, }; use parity_scale_codec::Codec; use sp_api::ProvideRuntimeApi; @@ -44,16 +44,13 @@ impl SalpRpc { } fn convert_rpc_params(value: Balance) -> RpcResult { - value - .try_into() - .map_err(|e| { - CallError::Custom(ErrorObject::owned( - ErrorCode::InvalidParams.code(), - format!("{} doesn't fit in NumberOrHex representation", value), - Some(format!("{:?}", e)), - )) - }) - .map_err(|e| jsonrpsee::core::Error::Call(e)) + value.try_into().map_err(|e| { + ErrorObject::owned( + ErrorCode::InvalidParams.code(), + format!("{} doesn't fit in NumberOrHex representation", value), + Some(format!("{:?}", e)), + ) + }) } #[rpc(client, server)] @@ -94,12 +91,11 @@ where Ok(value) => Ok((value, status)), Err(e) => Err(e), }, - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get salp contribution.", Some(format!("{:?}", e)), - ))) - .map_err(|e| jsonrpsee::core::Error::Call(e)), + )), } } } diff --git a/pallets/salp/src/benchmarking.rs b/pallets/salp/src/benchmarking.rs index 858c0da71..ee8d173a9 100644 --- a/pallets/salp/src/benchmarking.rs +++ b/pallets/salp/src/benchmarking.rs @@ -26,7 +26,7 @@ use frame_benchmarking::v2::*; use frame_support::assert_ok; use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin}; use sp_runtime::{ - traits::{AccountIdConversion, Bounded, UniqueSaturatedFrom}, + traits::{AccountIdConversion, Bounded, StaticLookup, UniqueSaturatedFrom}, SaturatedConversion, }; use sp_std::prelude::*; @@ -369,10 +369,13 @@ mod benchmarks { let relay_vstoken_id = ::CurrencyIdConversion::convert_to_vstoken(relay_currency_id).unwrap(); + let caller_lookup: ::Source = + T::Lookup::unlookup(caller.clone()); assert_ok!(zenlink_protocol::Pallet::::create_pair( RawOrigin::Root.into(), zenlink_protocol::AssetId { chain_id: 2001, asset_type: 2, asset_index: 516 }, zenlink_protocol::AssetId { chain_id: 2001, asset_type: 2, asset_index: 1028 }, + caller_lookup )); let buybck_caller = T::BuybackPalletId::get().into_account_truncating(); diff --git a/pallets/salp/src/lib.rs b/pallets/salp/src/lib.rs index eb338ada9..82a9749e2 100644 --- a/pallets/salp/src/lib.rs +++ b/pallets/salp/src/lib.rs @@ -113,7 +113,7 @@ pub mod pallet { }; use sp_arithmetic::Percent; use sp_std::{convert::TryInto, prelude::*}; - use xcm::v3::{MaybeErrorCode, MultiLocation}; + use xcm::v3::MaybeErrorCode; use super::*; @@ -1212,7 +1212,7 @@ pub mod pallet { response: Response, ) -> DispatchResult { let responder = ensure_response(::RuntimeOrigin::from(origin))?; - ensure!(responder == MultiLocation::parent(), Error::::ResponderNotRelayChain); + ensure!(responder == xcm::v4::Location::parent(), Error::::ResponderNotRelayChain); let (index, contributer, _amount) = QueryIdContributionInfo::::get(query_id) .ok_or(Error::::NotFindContributionValue)?; diff --git a/pallets/salp/src/mock.rs b/pallets/salp/src/mock.rs index ef22afb67..628dd72e9 100644 --- a/pallets/salp/src/mock.rs +++ b/pallets/salp/src/mock.rs @@ -121,7 +121,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -378,13 +377,13 @@ impl SlpxOperator for SlpxInterface { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const MaxAssetsForTransfer: usize = 2; } @@ -393,7 +392,7 @@ impl orml_xtokens::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -401,8 +400,10 @@ impl orml_xtokens::Config for Test { type BaseXcmWeight = (); type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } pub struct Slp; @@ -440,6 +441,7 @@ impl bifrost_vtoken_minting::Config for Test { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -480,7 +482,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); pub const RelayNetwork: NetworkId = NetworkId::Kusama; } @@ -515,7 +517,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Test { @@ -545,9 +547,9 @@ impl pallet_xcm::Config for Test { } pub struct BifrostAccountIdToMultiLocation; -impl Convert for BifrostAccountIdToMultiLocation { - fn convert(account: AccountId) -> MultiLocation { - X1(AccountId32 { network: None, id: account.into() }).into() +impl Convert for BifrostAccountIdToMultiLocation { + fn convert(account: AccountId) -> Location { + (AccountId32 { network: None, id: account.into() }).into() } } @@ -559,7 +561,7 @@ impl bifrost_xcm_interface::Config for Test { type RelaychainCurrencyId = RelayCurrencyId; type ParachainSovereignAccount = TreasuryAccount; type XcmExecutor = DoNothingExecuteXcm; - type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type AccountIdToLocation = BifrostAccountIdToMultiLocation; type SalpHelper = Salp; type ParachainId = ParaInfo; type CallBackTimeOut = ConstU64<10>; diff --git a/pallets/salp/src/tests.rs b/pallets/salp/src/tests.rs index d9161ca39..fc15ce71f 100644 --- a/pallets/salp/src/tests.rs +++ b/pallets/salp/src/tests.rs @@ -1346,7 +1346,8 @@ fn refund_meanwhile_issue_should_work() { assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_1_currency_id + asset_1_currency_id, + ALICE )); let deadline: BlockNumberFor = >::block_number() + BlockNumberFor::::from(100u32); diff --git a/pallets/slp/src/agents/astar_agent/agent.rs b/pallets/slp/src/agents/astar_agent/agent.rs index d9df3383b..ea0a27692 100644 --- a/pallets/slp/src/agents/astar_agent/agent.rs +++ b/pallets/slp/src/agents/astar_agent/agent.rs @@ -41,7 +41,7 @@ use sp_std::prelude::*; use xcm::{ opaque::v3::{Junction::Parachain, Junctions::X1, MultiLocation}, v3::prelude::*, - VersionedMultiAssets, VersionedMultiLocation, + VersionedAssets, VersionedLocation, }; /// StakingAgent implementation for Astar @@ -152,8 +152,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -251,8 +252,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -394,8 +396,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -416,7 +419,7 @@ impl fn transfer_back( &self, from: &MultiLocation, - to: &MultiLocation, + _to: &MultiLocation, amount: BalanceOf, currency_id: CurrencyId, weight_and_fee: Option<(Weight, BalanceOf)>, @@ -428,32 +431,26 @@ impl DelegatorsMultilocation2Index::::get(currency_id, from) .ok_or(Error::::DelegatorNotExist)?; - // Make sure the receiving account is the Exit_account from vtoken-minting module. - let to_account_id = Pallet::::multilocation_to_account(to)?; - let (_, exit_account) = T::VtokenMinting::get_entrance_and_exit_accounts(); - ensure!(to_account_id == exit_account, Error::::InvalidAccount); + // Make sure the receiving account is the entrance_account from vtoken-minting module. + let (entrance_account, _) = T::VtokenMinting::get_entrance_and_exit_accounts(); // Prepare parameter dest and beneficiary. - let to_32: [u8; 32] = Pallet::::multilocation_to_account_32(to)?; - - let dest = Box::new(VersionedMultiLocation::from(MultiLocation::new( + let dest = Box::new(VersionedLocation::V3(MultiLocation::new( 1, X1(Parachain(T::ParachainId::get().into())), ))); - let beneficiary = - Box::new(VersionedMultiLocation::from(MultiLocation::from(X1(AccountId32 { - network: None, - id: to_32, - })))); + let beneficiary = Box::new(VersionedLocation::V3(MultiLocation::from(X1(AccountId32 { + network: None, + id: entrance_account.encode().try_into().map_err(|_| Error::::FailToConvert)?, + })))); // Prepare parameter assets. let asset = MultiAsset { fun: Fungible(amount.unique_saturated_into()), id: Concrete(MultiLocation { parents: 0, interior: Here }), }; - let assets: Box = - Box::new(VersionedMultiAssets::from(MultiAssets::from(asset))); + let assets: Box = Box::new(VersionedAssets::V3(MultiAssets::from(asset))); // Prepare parameter fee_asset_item. let fee_asset_item: u32 = 0; diff --git a/pallets/slp/src/agents/astar_agent/types.rs b/pallets/slp/src/agents/astar_agent/types.rs index 14ea9ed42..c9d270afb 100644 --- a/pallets/slp/src/agents/astar_agent/types.rs +++ b/pallets/slp/src/agents/astar_agent/types.rs @@ -22,7 +22,7 @@ use scale_info::TypeInfo; use sp_core::H160; use sp_runtime::RuntimeDebug; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{opaque::v3::WeightLimit, VersionedMultiAssets, VersionedMultiLocation}; +use xcm::{opaque::v3::WeightLimit, VersionedAssets, VersionedLocation}; #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum AstarCall { @@ -66,9 +66,9 @@ pub enum AstarDappsStakingCall { pub enum XcmCall { #[codec(index = 8)] LimitedReserveTransferAssets( - Box, - Box, - Box, + Box, + Box, + Box, u32, WeightLimit, ), diff --git a/pallets/slp/src/agents/common.rs b/pallets/slp/src/agents/common.rs index 085213f8a..021bb5b80 100644 --- a/pallets/slp/src/agents/common.rs +++ b/pallets/slp/src/agents/common.rs @@ -21,14 +21,12 @@ use crate::{ ParachainStakingLedgerUpdateEntry, ParachainStakingLedgerUpdateOperation, TIMEOUT_BLOCKS, }, traits::QueryResponseManager, - vec, AccountIdOf, BalanceOf, BlockNumberFor, BoundedVec, Box, Config, CurrencyDelays, + vec, AccountIdOf, BalanceOf, BlockNumberFor, BoundedVec, Config, CurrencyDelays, DelegationsOccupied, DelegatorLatestTuneRecord, DelegatorLedgerXcmUpdateQueue, DelegatorLedgers, DelegatorNextIndex, DelegatorsIndex2Multilocation, - DelegatorsMultilocation2Index, Encode, Event, FeeSources, - Junction::{AccountId32, Parachain}, - Junctions::X1, - Ledger, LedgerUpdateEntry, MinimumsAndMaximums, MultiLocation, Pallet, TimeUnit, Validators, - Vec, Weight, Xcm, XcmOperationType, Zero, ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR, PHA, + DelegatorsMultilocation2Index, Encode, Event, FeeSources, Ledger, LedgerUpdateEntry, + MinimumsAndMaximums, Pallet, TimeUnit, Validators, Vec, Weight, XcmOperationType, Zero, ASTR, + BNC, DOT, GLMR, KSM, MANTA, MOVR, PHA, }; use bifrost_primitives::{CurrencyId, VtokenMintingOperator, XcmDestWeightAndFeeHandler}; use frame_support::{dispatch::GetDispatchInfo, ensure, traits::Len}; @@ -39,7 +37,7 @@ use sp_runtime::{ traits::{AccountIdConversion, CheckedAdd, UniqueSaturatedFrom, UniqueSaturatedInto}, DispatchResult, Saturating, }; -use xcm::{opaque::v3::Instruction, v3::prelude::*, VersionedMultiLocation}; +use xcm::v3::{prelude::*, MultiLocation}; // Some common business functions for all agents impl Pallet { @@ -206,36 +204,6 @@ impl Pallet { Ok(()) } - pub(crate) fn get_transfer_back_dest_and_beneficiary( - from: &MultiLocation, - to: &MultiLocation, - currency_id: CurrencyId, - ) -> Result<(Box, Box), Error> { - // Check if from is one of our delegators. If not, return error. - DelegatorsMultilocation2Index::::get(currency_id, from) - .ok_or(Error::::DelegatorNotExist)?; - - // Make sure the receiving account is the Exit_account from vtoken-minting module. - let to_account_id = Self::multilocation_to_account(to)?; - let (_, exit_account) = T::VtokenMinting::get_entrance_and_exit_accounts(); - ensure!(to_account_id == exit_account, Error::::InvalidAccount); - - // Prepare parameter dest and beneficiary. - let to_32: [u8; 32] = Self::multilocation_to_account_32(to)?; - - let dest = Box::new(VersionedMultiLocation::from(MultiLocation::from(X1(Parachain( - T::ParachainId::get().into(), - ))))); - - let beneficiary = - Box::new(VersionedMultiLocation::from(MultiLocation::from(X1(AccountId32 { - network: None, - id: to_32, - })))); - - Ok((dest, beneficiary)) - } - pub(crate) fn tune_vtoken_exchange_rate_without_update_ledger( who: &MultiLocation, token_amount: BalanceOf, @@ -301,36 +269,42 @@ impl Pallet { pub(crate) fn inner_construct_xcm_message( currency_id: CurrencyId, extra_fee: BalanceOf, - ) -> Result, Error> { - let multi = Self::get_currency_local_multilocation(currency_id); + ) -> Result>, Error> { + let remote_fee_location = Self::convert_currency_to_remote_fee_location(currency_id); - let asset = - MultiAsset { id: Concrete(multi), fun: Fungible(extra_fee.unique_saturated_into()) }; + let asset = xcm::v4::Asset { + id: xcm::v4::AssetId(remote_fee_location), + fun: xcm::v4::prelude::Fungible(extra_fee.unique_saturated_into()), + }; - let interior = Self::get_interior_by_currency_id(currency_id); + let refund_receiver = Self::convert_currency_to_refund_receiver(currency_id); Ok(vec![ - WithdrawAsset(asset.clone().into()), - BuyExecution { fees: asset, weight_limit: Unlimited }, - RefundSurplus, - DepositAsset { - assets: AllCounted(8).into(), - beneficiary: MultiLocation { parents: 0, interior }, + xcm::v4::prelude::WithdrawAsset(asset.clone().into()), + xcm::v4::prelude::BuyExecution { fees: asset, weight_limit: Unlimited }, + xcm::v4::prelude::RefundSurplus, + xcm::v4::prelude::DepositAsset { + assets: xcm::v4::prelude::AllCounted(8).into(), + beneficiary: xcm::v4::prelude::Location { parents: 0, interior: refund_receiver }, }, ]) } - pub(crate) fn get_interior_by_currency_id(currency_id: CurrencyId) -> Junctions { + pub(crate) fn convert_currency_to_refund_receiver( + currency_id: CurrencyId, + ) -> xcm::v4::Junctions { let interior = match currency_id { - KSM | DOT => X1(Parachain(T::ParachainId::get().into())), - MOVR | GLMR => X1(AccountKey20 { + KSM | DOT => xcm::v4::Junctions::from([xcm::v4::prelude::Parachain( + T::ParachainId::get().into(), + )]), + MOVR | GLMR => xcm::v4::Junctions::from([xcm::v4::prelude::AccountKey20 { network: None, key: Sibling::from(T::ParachainId::get()).into_account_truncating(), - }), - _ => X1(AccountId32 { + }]), + _ => xcm::v4::Junctions::from([xcm::v4::prelude::AccountId32 { network: None, id: Sibling::from(T::ParachainId::get()).into_account_truncating(), - }), + }]), }; return interior; @@ -372,7 +346,7 @@ impl Pallet { who: &MultiLocation, currency_id: CurrencyId, weight_and_fee: Option<(Weight, BalanceOf)>, - ) -> Result<(QueryId, BlockNumberFor, BalanceOf, Xcm<()>), Error> { + ) -> Result<(QueryId, BlockNumberFor, BalanceOf, xcm::v4::Xcm<()>), Error> { // prepare the query_id for reporting back transact status let now = frame_system::Pallet::::block_number(); let timeout = BlockNumberFor::::from(TIMEOUT_BLOCKS).saturating_add(now); @@ -405,7 +379,7 @@ impl Pallet { ) -> Result<(QueryId, Weight), Error> { let now = frame_system::Pallet::::block_number(); let timeout = BlockNumberFor::::from(TIMEOUT_BLOCKS).saturating_add(now); - let responder = Self::get_para_multilocation_by_currency_id(currency_id)?; + let responder = Self::convert_currency_to_dest_location(currency_id)?; let (notify_call_weight, callback_option) = match (currency_id, operation) { (DOT, &XcmOperationType::Delegate) | @@ -422,7 +396,7 @@ impl Pallet { }; let query_id = - T::SubstrateResponseManager::create_query_record(&responder, callback_option, timeout); + T::SubstrateResponseManager::create_query_record(responder, callback_option, timeout); return Ok((query_id, notify_call_weight)); } @@ -451,8 +425,9 @@ impl Pallet { None, )?; - let dest = Self::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Self::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(withdraw_fee) } @@ -461,13 +436,23 @@ impl Pallet { query_id: QueryId, max_weight: Weight, currency_id: CurrencyId, - ) -> Instruction { + ) -> xcm::v4::Instruction<()> { let dest_location = match currency_id { - DOT | KSM => MultiLocation::from(X1(Parachain(u32::from(T::ParachainId::get())))), - _ => MultiLocation::new(1, X1(Parachain(u32::from(T::ParachainId::get())))), + DOT | KSM => xcm::v4::Location::new( + 0, + [xcm::v4::prelude::Parachain(u32::from(T::ParachainId::get()))], + ), + _ => xcm::v4::Location::new( + 1, + [xcm::v4::prelude::Parachain(u32::from(T::ParachainId::get()))], + ), }; - ReportTransactStatus(QueryResponseInfo { destination: dest_location, query_id, max_weight }) + xcm::v4::prelude::ReportTransactStatus(xcm::v4::prelude::QueryResponseInfo { + destination: dest_location, + query_id, + max_weight, + }) } pub(crate) fn insert_delegator_ledger_update_entry( @@ -520,7 +505,8 @@ impl Pallet { ensure!(from.parents.is_zero(), Error::::InvalidTransferSource); let from_account = Pallet::::multilocation_to_account(from)?; - T::XcmTransfer::transfer(from_account, currency_id, amount, *to, Unlimited) + let v4_location = (*to).try_into().map_err(|()| Error::::FailToConvert)?; + T::XcmTransfer::transfer(from_account, currency_id, amount, v4_location, Unlimited) .map_err(|_| Error::::TransferToError)?; Ok(()) @@ -558,9 +544,9 @@ impl Pallet { currency_id: CurrencyId, query_id: Option, notify_call_weight: Option, - ) -> Result, Error> { + ) -> Result, Error> { let mut xcm_message = Self::inner_construct_xcm_message(currency_id, extra_fee)?; - let transact = Transact { + let transact = xcm::v4::prelude::Transact { origin_kind: OriginKind::SovereignAccount, require_weight_at_most: transact_weight, call: call.into(), @@ -577,7 +563,7 @@ impl Pallet { }, _ => {}, }; - Ok(Xcm(xcm_message)) + Ok(xcm::v4::Xcm(xcm_message)) } pub(crate) fn get_unlocking_time_unit_from_current( diff --git a/pallets/slp/src/agents/filecoin_agent/agent.rs b/pallets/slp/src/agents/filecoin_agent/agent.rs index e03f132ec..f1a69b595 100644 --- a/pallets/slp/src/agents/filecoin_agent/agent.rs +++ b/pallets/slp/src/agents/filecoin_agent/agent.rs @@ -20,8 +20,8 @@ use crate::{ primitives::{FilecoinLedger, Ledger}, traits::StakingAgent, AccountIdOf, BalanceOf, BoundedVec, Config, DelegatorLatestTuneRecord, DelegatorLedgers, - LedgerUpdateEntry, MinimumsAndMaximums, MultiLocation, Pallet, TimeUnit, Validators, - ValidatorsByDelegator, ValidatorsByDelegatorUpdateEntry, + LedgerUpdateEntry, MinimumsAndMaximums, Pallet, TimeUnit, Validators, ValidatorsByDelegator, + ValidatorsByDelegatorUpdateEntry, }; use bifrost_primitives::{CurrencyId, VtokenMintingOperator}; use core::marker::PhantomData; diff --git a/pallets/slp/src/agents/parachain_staking_agent/agent.rs b/pallets/slp/src/agents/parachain_staking_agent/agent.rs index bd551f091..54c265c3e 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/agent.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/agent.rs @@ -40,7 +40,7 @@ use bifrost_primitives::{ use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; use orml_traits::MultiCurrency; -use parity_scale_codec::alloc::collections::BTreeMap; +use parity_scale_codec::{alloc::collections::BTreeMap, Encode}; use sp_arithmetic::Percent; use sp_runtime::{ traits::{CheckedAdd, CheckedSub, Convert, UniqueSaturatedInto, Zero}, @@ -50,10 +50,10 @@ use sp_std::prelude::*; use xcm::{ opaque::v3::{ Junction::{AccountId32, Parachain}, - MultiLocation, WeightLimit, + MultiLocation, }, v3::prelude::*, - VersionedMultiLocation, + VersionedLocation, }; /// StakingAgent implementation for Moonriver/Moonbeam @@ -307,8 +307,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -455,8 +456,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -619,8 +621,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -835,8 +838,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -983,8 +987,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -1328,8 +1333,9 @@ impl } // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; query_index = query_id; } @@ -1350,7 +1356,7 @@ impl fn transfer_back( &self, from: &MultiLocation, - to: &MultiLocation, + _to: &MultiLocation, amount: BalanceOf, currency_id: CurrencyId, weight_and_fee: Option<(Weight, BalanceOf)>, @@ -1363,23 +1369,25 @@ impl .ok_or(Error::::DelegatorNotExist)?; // Make sure the receiving account is the Exit_account from vtoken-minting module. - let to_account_id = Pallet::::multilocation_to_account(&to)?; - - let (_, exit_account) = T::VtokenMinting::get_entrance_and_exit_accounts(); - ensure!(to_account_id == exit_account, Error::::InvalidAccount); + let (entrance_account, _) = T::VtokenMinting::get_entrance_and_exit_accounts(); if currency_id == BNC { let from_account = Pallet::::multilocation_to_account(from)?; - T::MultiCurrency::transfer(currency_id, &from_account, &to_account_id, amount) + T::MultiCurrency::transfer(currency_id, &from_account, &entrance_account, amount) .map_err(|_| Error::::Unexpected)?; } else { // Prepare parameter dest and beneficiary. - let to_32: [u8; 32] = Pallet::::multilocation_to_account_32(&to)?; - let dest = Box::new(VersionedMultiLocation::from(MultiLocation { + let dest = Box::new(VersionedLocation::V3(MultiLocation { parents: 1, interior: X2( Parachain(T::ParachainId::get().into()), - AccountId32 { network: None, id: to_32 }, + AccountId32 { + network: None, + id: entrance_account + .encode() + .try_into() + .map_err(|_| Error::::FailToConvert)?, + }, ), })); @@ -1389,7 +1397,7 @@ impl MoonbeamCurrencyId::SelfReserve, amount.unique_saturated_into(), dest, - WeightLimit::Unlimited, + Unlimited, )) .encode() .into(), @@ -1397,7 +1405,7 @@ impl MantaCurrencyId::MantaCurrency(1), amount.unique_saturated_into(), dest, - WeightLimit::Unlimited, + Unlimited, )) .encode() .into(), diff --git a/pallets/slp/src/agents/parachain_staking_agent/types/manta_types.rs b/pallets/slp/src/agents/parachain_staking_agent/types/manta_types.rs index f716e8c64..0ee7e0504 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/types/manta_types.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/types/manta_types.rs @@ -19,7 +19,7 @@ use crate::{BalanceOf, Config, Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::{traits::StaticLookup, RuntimeDebug}; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{opaque::v3::WeightLimit, VersionedMultiLocation}; +use xcm::{opaque::v3::WeightLimit, VersionedLocation}; #[derive(Encode, Decode, RuntimeDebug)] pub enum MantaCall { @@ -86,7 +86,7 @@ pub enum MantaParachainStakingCall { #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum MantaXtokensCall { #[codec(index = 0)] - Transfer(MantaCurrencyId, BalanceOf, Box, WeightLimit), + Transfer(MantaCurrencyId, BalanceOf, Box, WeightLimit), } #[derive(Clone, Eq, Debug, PartialEq, Ord, PartialOrd, Encode, Decode, TypeInfo)] diff --git a/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs b/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs index a94b207ea..abb20ae39 100644 --- a/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs +++ b/pallets/slp/src/agents/parachain_staking_agent/types/moonbeam_types.rs @@ -26,7 +26,7 @@ use sp_runtime::{ RuntimeDebug, }; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{opaque::v3::WeightLimit, VersionedMultiLocation}; +use xcm::{opaque::v3::WeightLimit, VersionedLocation}; #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum MoonbeamCall { @@ -91,7 +91,7 @@ pub enum MoonbeamParachainStakingCall { #[derive(Encode, Decode, RuntimeDebug, Clone)] pub enum MoonbeamXtokensCall { #[codec(index = 0)] - Transfer(MoonbeamCurrencyId, BalanceOf, Box, WeightLimit), + Transfer(MoonbeamCurrencyId, BalanceOf, Box, WeightLimit), } #[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] diff --git a/pallets/slp/src/agents/phala_agent/agent.rs b/pallets/slp/src/agents/phala_agent/agent.rs index 15407628c..f6494fa41 100644 --- a/pallets/slp/src/agents/phala_agent/agent.rs +++ b/pallets/slp/src/agents/phala_agent/agent.rs @@ -170,8 +170,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -280,8 +281,9 @@ impl )?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -508,8 +510,9 @@ impl Pallet::::burn_fee_from_source_account(fee, currency_id)?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -588,10 +591,14 @@ impl T::ParachainId::get().into(), )?; - let locat = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + let dest_location = + xcm::v3::Location::try_from(dest_location).map_err(|_| Error::::FailToConvert)?; // Prepare parameter assets. - let asset = - MultiAsset { fun: Fungible(amount.unique_saturated_into()), id: Concrete(locat) }; + let asset = MultiAsset { + fun: Fungible(amount.unique_saturated_into()), + id: Concrete(dest_location), + }; // Construct xcm message. let call: PhalaCall = @@ -690,8 +697,9 @@ impl Pallet::::burn_fee_from_source_account(fee, currency_id)?; // Send out the xcm message. - let dest = Pallet::::get_para_multilocation_by_currency_id(currency_id)?; - send_xcm::(dest, xcm_message).map_err(|_e| Error::::XcmFailure)?; + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) } @@ -918,10 +926,7 @@ impl PhalaAgent { DelegatorLedgerXcmUpdateQueue::::remove(query_id); // Delete the query in pallet_xcm. - ensure!( - T::SubstrateResponseManager::remove_query_record(query_id), - Error::::QueryResponseRemoveError - ); + T::SubstrateResponseManager::remove_query_record(query_id); Ok(()) } diff --git a/pallets/slp/src/agents/phala_agent/types.rs b/pallets/slp/src/agents/phala_agent/types.rs index ed9a3d4b6..cfdba6ee2 100644 --- a/pallets/slp/src/agents/phala_agent/types.rs +++ b/pallets/slp/src/agents/phala_agent/types.rs @@ -16,11 +16,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{agents::BalancesCall, BalanceOf, Config, MultiLocation}; +use crate::{agents::BalancesCall, BalanceOf, Config}; use parity_scale_codec::{Decode, Encode}; use sp_runtime::RuntimeDebug; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{opaque::v3::MultiAsset, v3::Weight as XCMWeight}; +use xcm::{ + opaque::v3::MultiAsset, + v3::{MultiLocation, Weight as XCMWeight}, +}; #[derive(Encode, Decode, RuntimeDebug)] pub enum PhalaCall { diff --git a/pallets/slp/src/agents/polkadot_agent/agent.rs b/pallets/slp/src/agents/polkadot_agent/agent.rs index 57dffc09f..3b6eff0e1 100644 --- a/pallets/slp/src/agents/polkadot_agent/agent.rs +++ b/pallets/slp/src/agents/polkadot_agent/agent.rs @@ -36,12 +36,13 @@ use bifrost_primitives::{ use core::marker::PhantomData; use frame_support::{ensure, traits::Get}; use frame_system::pallet_prelude::BlockNumberFor; +use parity_scale_codec::Encode; use sp_runtime::{ traits::{CheckedAdd, CheckedSub, Convert, StaticLookup, UniqueSaturatedInto, Zero}, DispatchResult, }; use sp_std::prelude::*; -use xcm::{opaque::v3::MultiLocation, v3::prelude::*, VersionedMultiAssets}; +use xcm::{opaque::v3::MultiLocation, v3::prelude::*, VersionedAssets, VersionedLocation}; /// StakingAgent implementation for Kusama/Polkadot pub struct PolkadotAgent(PhantomData); @@ -154,7 +155,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -223,7 +225,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -300,7 +303,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -353,7 +357,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -428,7 +433,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -499,7 +505,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -577,7 +584,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -705,7 +713,8 @@ impl )?; // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -769,7 +778,8 @@ impl } // Send out the xcm message. - send_xcm::(Parent.into(), xcm_message) + let dest_location = Pallet::::convert_currency_to_dest_location(currency_id)?; + xcm::v4::send_xcm::(dest_location, xcm_message) .map_err(|_e| Error::::XcmFailure)?; Ok(query_id) @@ -779,7 +789,7 @@ impl fn transfer_back( &self, from: &MultiLocation, - to: &MultiLocation, + _to: &MultiLocation, amount: BalanceOf, currency_id: CurrencyId, weight_and_fee: Option<(Weight, BalanceOf)>, @@ -787,16 +797,29 @@ impl // Ensure amount is greater than zero. ensure!(!amount.is_zero(), Error::::AmountZero); - let (dest, beneficiary) = - Pallet::::get_transfer_back_dest_and_beneficiary(from, to, currency_id)?; + // Check if from is one of our delegators. If not, return error. + DelegatorsMultilocation2Index::::get(currency_id, from) + .ok_or(Error::::DelegatorNotExist)?; + + // Make sure the receiving account is the Exit_account from vtoken-minting module. + let (entrance_account, _) = T::VtokenMinting::get_entrance_and_exit_accounts(); + + // Prepare parameter dest and beneficiary. + let dest = Box::new(VersionedLocation::V3(Location::from([Parachain( + T::ParachainId::get().into(), + )]))); + + let beneficiary = Box::new(VersionedLocation::V3(Location::from([AccountId32 { + network: None, + id: entrance_account.encode().try_into().map_err(|_| Error::::FailToConvert)?, + }]))); // Prepare parameter assets. let asset = MultiAsset { fun: Fungible(amount.unique_saturated_into()), id: Concrete(MultiLocation { parents: 0, interior: Here }), }; - let assets: Box = - Box::new(VersionedMultiAssets::from(MultiAssets::from(asset))); + let assets: Box = Box::new(VersionedAssets::V3(MultiAssets::from(asset))); // Prepare parameter fee_asset_item. let fee_asset_item: u32 = 0; diff --git a/pallets/slp/src/agents/polkadot_agent/types.rs b/pallets/slp/src/agents/polkadot_agent/types.rs index 089a212a0..c2689c93f 100644 --- a/pallets/slp/src/agents/polkadot_agent/types.rs +++ b/pallets/slp/src/agents/polkadot_agent/types.rs @@ -21,7 +21,7 @@ use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::{traits::StaticLookup, RuntimeDebug}; use sp_std::{boxed::Box, vec::Vec}; -use xcm::{v3::prelude::*, VersionedMultiAssets, VersionedMultiLocation}; +use xcm::{v3::prelude::*, VersionedAssets, VersionedLocation}; #[derive(Encode, Decode, RuntimeDebug)] pub enum KusamaCall { @@ -116,9 +116,9 @@ pub enum StakingCall { pub enum XcmCall { #[codec(index = 8)] LimitedReserveTransferAssets( - Box, - Box, - Box, + Box, + Box, + Box, u32, WeightLimit, ), diff --git a/pallets/slp/src/agents/utils.rs b/pallets/slp/src/agents/utils.rs index 41b2c26a7..228d362f4 100644 --- a/pallets/slp/src/agents/utils.rs +++ b/pallets/slp/src/agents/utils.rs @@ -26,14 +26,7 @@ use frame_support::ensure; use parity_scale_codec::Encode; use sp_core::Get; use sp_std::prelude::*; -use xcm::{ - opaque::v3::{ - Junction::{AccountId32, Parachain}, - Junctions::X1, - MultiLocation, - }, - v3::prelude::*, -}; +use xcm::v3::{prelude::*, MultiLocation}; // Some untilities. impl Pallet { @@ -322,20 +315,25 @@ impl Pallet { H160::from_slice(sub_id.as_slice()) } - pub fn get_para_multilocation_by_currency_id( + pub fn convert_currency_to_dest_location( currency_id: CurrencyId, - ) -> Result> { + ) -> Result> { match currency_id { - KSM | DOT => Ok(MultiLocation::parent()), - MOVR => - Ok(MultiLocation { parents: 1, interior: X1(Parachain(parachains::moonriver::ID)) }), - GLMR => - Ok(MultiLocation { parents: 1, interior: X1(Parachain(parachains::moonbeam::ID)) }), + KSM | DOT => Ok(xcm::v4::Location::parent()), + MOVR => Ok(xcm::v4::Location::new( + 1, + [xcm::v4::prelude::Parachain(parachains::moonriver::ID)], + )), + GLMR => Ok(xcm::v4::Location::new( + 1, + [xcm::v4::prelude::Parachain(parachains::moonbeam::ID)], + )), ASTR => - Ok(MultiLocation { parents: 1, interior: X1(Parachain(parachains::astar::ID)) }), + Ok(xcm::v4::Location::new(1, [xcm::v4::prelude::Parachain(parachains::astar::ID)])), MANTA => - Ok(MultiLocation { parents: 1, interior: X1(Parachain(parachains::manta::ID)) }), - PHA => Ok(MultiLocation { parents: 1, interior: X1(Parachain(parachains::phala::ID)) }), + Ok(xcm::v4::Location::new(1, [xcm::v4::prelude::Parachain(parachains::manta::ID)])), + PHA => + Ok(xcm::v4::Location::new(1, [xcm::v4::prelude::Parachain(parachains::phala::ID)])), _ => Err(Error::::NotSupportedCurrencyId), } } @@ -364,18 +362,17 @@ impl Pallet { } } - pub fn get_currency_local_multilocation(currency_id: CurrencyId) -> MultiLocation { + pub fn convert_currency_to_remote_fee_location(currency_id: CurrencyId) -> xcm::v4::Location { match currency_id { - KSM | DOT | PHA | MANTA | ASTR => MultiLocation::here(), - MOVR => MultiLocation { - parents: 0, - interior: X1(PalletInstance(parachains::moonriver::PALLET_ID)), - }, - GLMR => MultiLocation { - parents: 0, - interior: X1(PalletInstance(parachains::moonbeam::PALLET_ID)), - }, - _ => MultiLocation::here(), + MOVR => xcm::v4::Location::new( + 0, + [xcm::v4::prelude::PalletInstance(parachains::moonriver::PALLET_ID)], + ), + GLMR => xcm::v4::Location::new( + 0, + [xcm::v4::prelude::PalletInstance(parachains::moonbeam::PALLET_ID)], + ), + _ => xcm::v4::Location::here(), } } } diff --git a/pallets/slp/src/benchmarking.rs b/pallets/slp/src/benchmarking.rs index d64d5c958..f5dce590c 100644 --- a/pallets/slp/src/benchmarking.rs +++ b/pallets/slp/src/benchmarking.rs @@ -710,26 +710,6 @@ mod benchmarks { Ok(()) } - #[benchmark] - fn refund_currency_due_unbond() -> Result<(), BenchmarkError> { - let origin = ::ControlOrigin::try_successful_origin() - .map_err(|_| BenchmarkError::Weightless)?; - init_ongoing_time::(origin.clone()); - - let (_, exit_account) = ::VtokenMinting::get_entrance_and_exit_accounts(); - orml_tokens::Pallet::::deposit( - KSM, - &exit_account, - ::Balance::saturated_from(1_000_000_000_000u128), - ) - .unwrap(); - - #[extrinsic_call] - _(origin as ::RuntimeOrigin, KSM); - - Ok(()) - } - #[benchmark] fn supplement_fee_reserve() -> Result<(), BenchmarkError> { let origin = ::ControlOrigin::try_successful_origin() diff --git a/pallets/slp/src/lib.rs b/pallets/slp/src/lib.rs index f422ea973..2e9f3fa92 100644 --- a/pallets/slp/src/lib.rs +++ b/pallets/slp/src/lib.rs @@ -56,10 +56,7 @@ use sp_io::hashing::blake2_256; use sp_runtime::traits::{CheckedAdd, CheckedSub, Convert, TrailingZeroInput, UniqueSaturatedFrom}; use sp_std::{boxed::Box, vec, vec::Vec}; pub use weights::WeightInfo; -use xcm::{ - prelude::*, - v3::{Junction, Junctions, MultiLocation, Xcm}, -}; +use xcm::v3::{Junction, Junctions, MultiLocation}; mod agents; pub mod migrations; @@ -97,7 +94,6 @@ const ITERATE_LENGTH: usize = 100; pub mod pallet { use super::*; use crate::agents::{AstarAgent, FilecoinAgent, ParachainStakingAgent, PhalaAgent}; - use bifrost_primitives::{RedeemType, SlpxOperator}; use frame_support::dispatch::GetDispatchInfo; use orml_traits::XcmTransfer; use pallet_xcm::ensure_response; @@ -127,8 +123,6 @@ pub mod pallet { TimeUnit, >; - type BifrostSlpx: SlpxOperator>; - /// xtokens xcm transfer interface type XcmTransfer: XcmTransfer, BalanceOf, CurrencyIdOf>; @@ -142,15 +136,11 @@ pub mod pallet { /// Substrate response manager. type SubstrateResponseManager: QueryResponseManager< QueryId, - MultiLocation, + xcm::v4::Location, BlockNumberFor, ::RuntimeCall, >; - /// Handler to notify the runtime when refund. - /// If you don't need it, you can specify the type `()`. - type OnRefund: OnRefund, CurrencyId, BalanceOf>; - type XcmWeightAndFeeHandler: XcmDestWeightAndFeeHandler>; #[pallet::constant] @@ -1246,220 +1236,11 @@ pub mod pallet { #[pallet::call_index(18)] #[pallet::weight(::WeightInfo::refund_currency_due_unbond())] pub fn refund_currency_due_unbond( - origin: OriginFor, - currency_id: CurrencyId, + _origin: OriginFor, + _currency_id: CurrencyId, ) -> DispatchResultWithPostInfo { - // Ensure origin - Self::ensure_authorized(origin, currency_id)?; - - // Get entrance_account and exit_account, as well as their currency balances. - let (entrance_account, exit_account) = - T::VtokenMinting::get_entrance_and_exit_accounts(); - let mut exit_account_balance = - T::MultiCurrency::free_balance(currency_id, &exit_account); - - if exit_account_balance.is_zero() { - return Ok(().into()); - } - - // Get the currency due unlocking records - let time_unit = T::VtokenMinting::get_ongoing_time_unit(currency_id) - .ok_or(Error::::TimeUnitNotExist)?; - let rs = T::VtokenMinting::get_unlock_records(currency_id, time_unit.clone()); - - let mut extra_weight = 0 as u64; - - // Refund due unlocking records one by one. - if let Some((_locked_amount, idx_vec)) = rs { - let mut counter = 0; - - for idx in idx_vec.iter() { - if counter >= T::MaxRefundPerBlock::get() { - break; - } - // get idx record amount - let idx_record_amount_op = - T::VtokenMinting::get_token_unlock_ledger(currency_id, *idx); - - if let Some((user_account, idx_record_amount, _unlock_era, redeem_type)) = - idx_record_amount_op - { - let mut deduct_amount = idx_record_amount; - if exit_account_balance < idx_record_amount { - match redeem_type { - RedeemType::Native => {}, - RedeemType::Astar(_) | - RedeemType::Moonbeam(_) | - RedeemType::Hydradx(_) | - RedeemType::Manta(_) | - RedeemType::Interlay(_) => break, - }; - deduct_amount = exit_account_balance; - }; - match redeem_type { - RedeemType::Native => { - // Transfer some amount from the exit_account to the user's account - T::MultiCurrency::transfer( - currency_id, - &exit_account, - &user_account, - deduct_amount, - )?; - }, - RedeemType::Astar(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( - Parachain(T::VtokenMinting::get_astar_parachain_id()), - AccountId32 { - network: None, - id: receiver.encode().try_into().unwrap(), - }, - ), - }; - T::XcmTransfer::transfer( - user_account.clone(), - currency_id, - deduct_amount, - dest, - Unlimited, - )?; - }, - RedeemType::Hydradx(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( - Parachain(T::VtokenMinting::get_hydradx_parachain_id()), - AccountId32 { - network: None, - id: receiver.encode().try_into().unwrap(), - }, - ), - }; - T::XcmTransfer::transfer( - user_account.clone(), - currency_id, - deduct_amount, - dest, - Unlimited, - )?; - }, - RedeemType::Interlay(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( - Parachain(T::VtokenMinting::get_interlay_parachain_id()), - AccountId32 { - network: None, - id: receiver.encode().try_into().unwrap(), - }, - ), - }; - T::XcmTransfer::transfer( - user_account.clone(), - currency_id, - deduct_amount, - dest, - Unlimited, - )?; - }, - RedeemType::Manta(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( - Parachain(T::VtokenMinting::get_manta_parachain_id()), - AccountId32 { - network: None, - id: receiver.encode().try_into().unwrap(), - }, - ), - }; - T::XcmTransfer::transfer( - user_account.clone(), - currency_id, - deduct_amount, - dest, - Unlimited, - )?; - }, - RedeemType::Moonbeam(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( - Parachain(T::VtokenMinting::get_moonbeam_parachain_id()), - AccountKey20 { - network: None, - key: receiver.to_fixed_bytes(), - }, - ), - }; - if currency_id == FIL { - let assets = vec![ - (currency_id, deduct_amount), - (BNC, T::BifrostSlpx::get_moonbeam_transfer_to_fee()), - ]; - - T::XcmTransfer::transfer_multicurrencies( - user_account.clone(), - assets, - 1, - dest, - Unlimited, - )?; - } else { - T::XcmTransfer::transfer( - user_account.clone(), - currency_id, - deduct_amount, - dest, - Unlimited, - )?; - } - }, - }; - // Delete the corresponding unlocking record storage. - T::VtokenMinting::deduct_unlock_amount(currency_id, *idx, deduct_amount)?; - - extra_weight = - T::OnRefund::on_refund(currency_id, user_account, deduct_amount); - - // Deposit event. - Pallet::::deposit_event(Event::Refund { - currency_id, - time_unit: time_unit.clone(), - index: *idx, - amount: deduct_amount, - }); - - counter = counter.saturating_add(1); - - exit_account_balance = exit_account_balance - .checked_sub(&deduct_amount) - .ok_or(Error::::UnderFlow)?; - if exit_account_balance == Zero::zero() { - break; - } - } - } - } else { - // Automatically move the rest amount in exit account to entrance account. - T::MultiCurrency::transfer( - currency_id, - &exit_account, - &entrance_account, - exit_account_balance, - )?; - } - - if extra_weight != 0 { - Ok(Some( - ::WeightInfo::refund_currency_due_unbond() + - Weight::from_parts(extra_weight, 0), - ) - .into()) - } else { - Ok(().into()) - } + ensure!(false, Error::::Unsupported); + Ok(().into()) } #[pallet::call_index(19)] @@ -2618,7 +2399,7 @@ impl>> currency_id, &who, Ledger::Substrate(SubstrateLedger { - account: Parent.into(), + account: xcm::v3::Parent.into(), total: u32::MAX.into(), active: u32::MAX.into(), unlocking: vec![], diff --git a/pallets/slp/src/migrations/mod.rs b/pallets/slp/src/migrations/mod.rs index f5231cb7b..cab834f9d 100644 --- a/pallets/slp/src/migrations/mod.rs +++ b/pallets/slp/src/migrations/mod.rs @@ -16,6 +16,6 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -/// Version 2. -pub mod v2; -pub mod v3; +// Version 2. +// pub mod v2; +// pub mod v3; diff --git a/pallets/slp/src/migrations/v2.rs b/pallets/slp/src/migrations/v2.rs index d5463f5cf..542916d86 100644 --- a/pallets/slp/src/migrations/v2.rs +++ b/pallets/slp/src/migrations/v2.rs @@ -32,15 +32,15 @@ impl OnRuntimeUpgrade for SlpMigration { // Transform storage values // We transform the storage values from the old into the new format. log::info!(target: LOG_TARGET, "Start to migrate Validators storage..."); - Validators::::translate(|k: CurrencyId, value: Vec| { + Validators::::translate(|k: CurrencyId, value: Vec| { log::info!(target: LOG_TARGET, "Migrated to boundedvec for {:?}...", k); - let target_bounded_vec: BoundedVec; + let target_bounded_vec: BoundedVec; if value.len() != 0 { target_bounded_vec = BoundedVec::try_from(value).unwrap(); } else { - target_bounded_vec = BoundedVec::::default(); + target_bounded_vec = BoundedVec::::default(); } Some(target_bounded_vec) @@ -48,7 +48,7 @@ impl OnRuntimeUpgrade for SlpMigration { log::info!(target: LOG_TARGET, "Start to migrate ValidatorsByDelegator storage..."); //migrate the value type of ValidatorsByDelegator - ValidatorsByDelegator::::translate(|key1, key2, value: Vec| { + ValidatorsByDelegator::::translate(|key1, key2, value: Vec| { log::info!( target: LOG_TARGET, "Migrated to boundedvec for {:?} - {:?}...", @@ -56,12 +56,12 @@ impl OnRuntimeUpgrade for SlpMigration { key2 ); - let target_bounded_vec: BoundedVec; + let target_bounded_vec: BoundedVec; if value.len() != 0 { target_bounded_vec = BoundedVec::try_from(value).unwrap(); } else { - target_bounded_vec = BoundedVec::::default(); + target_bounded_vec = BoundedVec::::default(); } Some(target_bounded_vec) @@ -70,11 +70,11 @@ impl OnRuntimeUpgrade for SlpMigration { log::info!(target: LOG_TARGET, "Start to migrate ValidatorBoostList storage..."); //migrate the value type of ValidatorBoostList ValidatorBoostList::::translate( - |k: CurrencyId, value: Vec<(MultiLocation, BlockNumberFor)>| { + |k: CurrencyId, value: Vec<(Location, BlockNumberFor)>| { log::info!(target: LOG_TARGET, "Migrated to boundedvec for {:?}...", k); let target_bounded_vec: BoundedVec< - (MultiLocation, BlockNumberFor), + (Location, BlockNumberFor), T::MaxLengthLimit, >; @@ -82,7 +82,7 @@ impl OnRuntimeUpgrade for SlpMigration { target_bounded_vec = BoundedVec::try_from(value).unwrap(); } else { target_bounded_vec = BoundedVec::< - (MultiLocation, BlockNumberFor), + (Location, BlockNumberFor), T::MaxLengthLimit, >::default(); } diff --git a/pallets/slp/src/mocks/mock.rs b/pallets/slp/src/mocks/mock.rs index 991369d3c..7229247f2 100644 --- a/pallets/slp/src/mocks/mock.rs +++ b/pallets/slp/src/mocks/mock.rs @@ -46,7 +46,7 @@ use sp_runtime::{ AccountId32, BuildStorage, Percent, }; use sp_std::{boxed::Box, vec::Vec}; -use xcm::v3::{prelude::*, Weight}; +use xcm::v3::{prelude::*, MultiLocation, Weight}; use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; use xcm_executor::XcmExecutor; @@ -119,7 +119,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -153,13 +152,13 @@ impl bifrost_currencies::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: xcm::v4::Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: xcm::v4::Location = xcm::v4::Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -169,7 +168,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -177,8 +176,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -217,6 +218,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -393,12 +395,12 @@ parameter_types! { pub BifrostTreasuryAccount: AccountId = PalletId(*b"bf/trsry").into_account_truncating(); } -impl QueryResponseManager for () { +impl QueryResponseManager for () { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -410,19 +412,19 @@ impl QueryResponseManager for () { } pub struct BifrostCurrencyIdConvert; -impl Convert> for BifrostCurrencyIdConvert { - fn convert(id: CurrencyId) -> Option { +impl Convert> for BifrostCurrencyIdConvert { + fn convert(id: CurrencyId) -> Option { use CurrencyId::*; use TokenSymbol::*; match id { - Token(MOVR) => Some(MultiLocation::new(1, X2(Parachain(2023), PalletInstance(10)))), - Token(KSM) => Some(MultiLocation::parent()), - Native(BNC) => Some(MultiLocation::new( + Token(MOVR) => Some(Location::new(1, [Parachain(2023), PalletInstance(10)])), + Token(KSM) => Some(Location::parent()), + Native(BNC) => Some(Location::new( 0, - X1(Junction::from(BoundedVec::try_from("0x0001".encode()).unwrap())), + Junction::from(BoundedVec::try_from("0x0001".encode()).unwrap()), )), - Token(PHA) => Some(MultiLocation::new(1, X1(Parachain(2004)))), + Token(PHA) => Some(Location::new(1, [Parachain(2004)])), _ => None, } } @@ -435,6 +437,25 @@ impl SlpxOperator for SlpxInterface { } } +pub struct SubstrateResponseManager; +impl QueryResponseManager + for SubstrateResponseManager +{ + fn get_query_response_record(_query_id: QueryId) -> bool { + Default::default() + } + fn create_query_record( + _responder: xcm::v4::Location, + _call_back: Option, + _timeout: u64, + ) -> u64 { + Default::default() + } + fn remove_query_record(_query_id: QueryId) -> bool { + Default::default() + } +} + impl Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -443,13 +464,11 @@ impl Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; type AccountConverter = SubAccountIndexMultiLocationConvertor; type ParachainId = ParachainId; - type SubstrateResponseManager = (); + type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = ParachainStaking; type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -483,7 +502,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: xcm::v4::InteriorLocation = xcm::v4::Junction::Parachain(2001).into(); } pub struct XcmConfig; @@ -517,7 +536,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/slp/src/mocks/mock_kusama.rs b/pallets/slp/src/mocks/mock_kusama.rs index 2264d78d2..794c3b67b 100644 --- a/pallets/slp/src/mocks/mock_kusama.rs +++ b/pallets/slp/src/mocks/mock_kusama.rs @@ -56,9 +56,6 @@ pub type Block = frame_system::mocking::MockBlock; pub const ALICE: AccountId = AccountId32::new([1u8; 32]); pub const BOB: AccountId = AccountId32::new([2u8; 32]); -pub const CHARLIE: AccountId = AccountId32::new([3u8; 32]); -pub const DAVE: AccountId = AccountId32::new([4u8; 32]); -pub const EDDIE: AccountId = AccountId32::new([5u8; 32]); construct_runtime!( pub enum Runtime { @@ -173,7 +170,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -207,13 +203,13 @@ impl bifrost_currencies::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: xcm::v4::Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: xcm::v4::Location = xcm::v4::Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -223,7 +219,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = BifrostCurrencyIdConvert; - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = DoNothingExecuteXcm; @@ -231,8 +227,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -278,6 +276,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -401,7 +400,8 @@ impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationC MANTA => { // get parachain id if let Some(location) = BifrostCurrencyIdConvert::convert(currency_id) { - if let Some(Parachain(para_id)) = location.interior().first() { + let v3_location = xcm::v3::Location::try_from(location).unwrap(); + if let Some(Parachain(para_id)) = v3_location.interior().first() { MultiLocation::new( 1, X2( @@ -430,7 +430,8 @@ impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationC _ => { // get parachain id if let Some(location) = BifrostCurrencyIdConvert::convert(currency_id) { - if let Some(Parachain(para_id)) = location.interior().first() { + let v3_location = xcm::v3::Location::try_from(location).unwrap(); + if let Some(Parachain(para_id)) = v3_location.interior().first() { MultiLocation::new( 1, X2( @@ -482,32 +483,37 @@ parameter_types! { } pub struct BifrostCurrencyIdConvert; -impl Convert> for BifrostCurrencyIdConvert { - fn convert(id: CurrencyId) -> Option { +impl Convert> for BifrostCurrencyIdConvert { + fn convert(id: CurrencyId) -> Option { use CurrencyId::*; use TokenSymbol::*; match id { - Token(MOVR) => Some(MultiLocation::new(1, X2(Parachain(2023), PalletInstance(10)))), - Token(KSM) => Some(MultiLocation::parent()), - Native(BNC) => Some(MultiLocation::new( + Token(MOVR) => Some(xcm::v4::Location::new( + 1, + [xcm::v4::Junction::Parachain(2023), xcm::v4::Junction::PalletInstance(10)], + )), + Token(KSM) => Some(xcm::v4::Location::parent()), + Native(BNC) => Some(xcm::v4::Location::new( 0, - X1(Junction::from(BoundedVec::try_from("0x0001".encode()).unwrap())), + [xcm::v4::Junction::from(BoundedVec::try_from("0x0001".encode()).unwrap())], )), - Token(PHA) => Some(MultiLocation::new(1, X1(Parachain(2004)))), - MANTA => Some(MultiLocation::new(1, X1(Parachain(2104)))), + Token(PHA) => Some(xcm::v4::Location::new(1, [xcm::v4::Junction::Parachain(2004)])), + MANTA => Some(xcm::v4::Location::new(1, [xcm::v4::Junction::Parachain(2104)])), _ => None, } } } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager + for SubstrateResponseManager +{ fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: xcm::v4::Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -530,13 +536,11 @@ impl Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; type AccountConverter = SubAccountIndexMultiLocationConvertor; type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = ParachainStaking; type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -570,14 +574,14 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: xcm::v4::InteriorLocation = xcm::v4::Junction::Parachain(2001).into(); } pub struct Barrier; impl ShouldExecute for Barrier { fn should_execute( - _origin: &MultiLocation, - _message: &mut [Instruction], + _origin: &xcm::v4::Location, + _message: &mut [xcm::v4::Instruction], _max_weight: Weight, _weight_credit: &mut Properties, ) -> Result<(), ProcessMessageError> { @@ -616,7 +620,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/slp/src/primitives/filecoin_primitives.rs b/pallets/slp/src/primitives/filecoin_primitives.rs index ab99bab93..ab7880001 100644 --- a/pallets/slp/src/primitives/filecoin_primitives.rs +++ b/pallets/slp/src/primitives/filecoin_primitives.rs @@ -16,10 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{CurrencyId, MultiLocation}; +use crate::CurrencyId; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; +use xcm::v3::MultiLocation; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct FilecoinLedger { diff --git a/pallets/slp/src/primitives/parachain_staking_primitives.rs b/pallets/slp/src/primitives/parachain_staking_primitives.rs index 49ad86659..99bfa14be 100644 --- a/pallets/slp/src/primitives/parachain_staking_primitives.rs +++ b/pallets/slp/src/primitives/parachain_staking_primitives.rs @@ -16,12 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::MultiLocation; use bifrost_primitives::{CurrencyId, TimeUnit}; use parity_scale_codec::{alloc::collections::BTreeMap, Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; use sp_std::vec::Vec; +use xcm::v3::MultiLocation; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct OneToManyLedger { diff --git a/pallets/slp/src/primitives/phala_primitives.rs b/pallets/slp/src/primitives/phala_primitives.rs index 8926c1dfa..9eda26110 100644 --- a/pallets/slp/src/primitives/phala_primitives.rs +++ b/pallets/slp/src/primitives/phala_primitives.rs @@ -16,10 +16,11 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::{MultiLocation, TimeUnit}; +use crate::TimeUnit; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; +use xcm::v3::MultiLocation; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct PhalaLedger { diff --git a/pallets/slp/src/primitives/polkadot_primitives.rs b/pallets/slp/src/primitives/polkadot_primitives.rs index f764dc892..5e5050703 100644 --- a/pallets/slp/src/primitives/polkadot_primitives.rs +++ b/pallets/slp/src/primitives/polkadot_primitives.rs @@ -16,12 +16,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::MultiLocation; use bifrost_primitives::{CurrencyId, TimeUnit}; use parity_scale_codec::{Decode, Encode}; use scale_info::TypeInfo; use sp_runtime::RuntimeDebug; use sp_std::vec::Vec; +use xcm::v3::MultiLocation; #[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug, TypeInfo)] pub struct SubstrateLedger { diff --git a/pallets/slp/src/tests/kusama_tests.rs b/pallets/slp/src/tests/kusama_tests.rs index 217695b50..a7e8766c7 100644 --- a/pallets/slp/src/tests/kusama_tests.rs +++ b/pallets/slp/src/tests/kusama_tests.rs @@ -19,13 +19,11 @@ #![cfg(test)] use crate::{mocks::mock_kusama::*, *}; -use bifrost_primitives::{ - currency::{BNC, KSM, VKSM}, - RedeemType, -}; +use bifrost_primitives::currency::{BNC, KSM, VKSM}; use frame_support::{assert_noop, assert_ok, PalletId}; use orml_traits::MultiCurrency; -use sp_runtime::{traits::AccountIdConversion, MultiAddress}; +use sp_runtime::traits::AccountIdConversion; +use xcm::v3::prelude::*; const SUBACCOUNT_0_32: [u8; 32] = hex_literal::hex!["5a53736d8e96f1c007cf0d630acf5209b20611617af23ce924c8e25328eb5d28"]; @@ -213,211 +211,6 @@ fn update_ongoing_time_unit_works() { }); } -#[test] -fn refund_currency_due_unbond_works() { - ExtBuilder::default().build().execute_with(|| { - // Preparations - // get entrance and exit accounts - let (entrance_acc, exit_acc) = VtokenMinting::get_entrance_and_exit_accounts(); - // Set exit account balance to be 50. - assert_ok!(Tokens::set_balance( - RuntimeOrigin::root(), - MultiAddress::Id(exit_acc.clone()), - KSM, - 50, - 0 - )); - - // set current era to be 100. - bifrost_vtoken_minting::OngoingTimeUnit::::insert(KSM, TimeUnit::Era(100)); - - // Set TokenUnlockLedger records. - let record_bob = (BOB, 10, TimeUnit::Era(90), RedeemType::Native); - bifrost_vtoken_minting::TokenUnlockLedger::::insert(KSM, 0, record_bob); - - let record_charlie = (CHARLIE, 28, TimeUnit::Era(100), RedeemType::Native); - bifrost_vtoken_minting::TokenUnlockLedger::::insert(KSM, 1, record_charlie); - - let record_dave = (DAVE, 30, TimeUnit::Era(100), RedeemType::Native); - bifrost_vtoken_minting::TokenUnlockLedger::::insert(KSM, 2, record_dave); - - let record_eddie_1 = (EDDIE, 7, TimeUnit::Era(110), RedeemType::Native); - bifrost_vtoken_minting::TokenUnlockLedger::::insert(KSM, 3, record_eddie_1); - - let record_eddie_2 = (EDDIE, 6, TimeUnit::Era(110), RedeemType::Native); - bifrost_vtoken_minting::TokenUnlockLedger::::insert(KSM, 4, record_eddie_2); - - // insert TimeUnitUnlockLedger records - let bounded_vec_90 = BoundedVec::try_from(vec![0]).unwrap(); - let time_record_90 = (10, bounded_vec_90, KSM); - bifrost_vtoken_minting::TimeUnitUnlockLedger::::insert( - TimeUnit::Era(90), - KSM, - time_record_90.clone(), - ); - - let bounded_vec_100 = BoundedVec::try_from(vec![1, 2]).unwrap(); - let time_record_100 = (58, bounded_vec_100, KSM); - bifrost_vtoken_minting::TimeUnitUnlockLedger::::insert( - TimeUnit::Era(100), - KSM, - time_record_100, - ); - - let bounded_vec_110 = BoundedVec::try_from(vec![3, 4]).unwrap(); - let time_record_110 = (13, bounded_vec_110, KSM); - bifrost_vtoken_minting::TimeUnitUnlockLedger::::insert( - TimeUnit::Era(110), - KSM, - time_record_110.clone(), - ); - - // insert UserUnlockLedger records. - let bounded_vec_bob = BoundedVec::try_from(vec![0]).unwrap(); - bifrost_vtoken_minting::UserUnlockLedger::::insert( - BOB, - KSM, - (10, bounded_vec_bob.clone()), - ); - - let bounded_vec_charlie = BoundedVec::try_from(vec![1]).unwrap(); - bifrost_vtoken_minting::UserUnlockLedger::::insert( - CHARLIE, - KSM, - (28, bounded_vec_charlie), - ); - - let bounded_vec_dave = BoundedVec::try_from(vec![2]).unwrap(); - bifrost_vtoken_minting::UserUnlockLedger::::insert( - DAVE, - KSM, - (30, bounded_vec_dave.clone()), - ); - - let bounded_vec_eddie = BoundedVec::try_from(vec![3, 4]).unwrap(); - bifrost_vtoken_minting::UserUnlockLedger::::insert( - EDDIE, - KSM, - (13, bounded_vec_eddie.clone()), - ); - - bifrost_vtoken_minting::UnlockingTotal::::insert(KSM, 1000); - - // check account balances before refund - assert_eq!(Tokens::free_balance(KSM, &exit_acc), 50); - assert_eq!(Tokens::free_balance(KSM, &BOB), 0); - assert_eq!(Tokens::free_balance(KSM, &CHARLIE), 0); - assert_eq!(Tokens::free_balance(KSM, &DAVE), 0); - assert_eq!(Tokens::free_balance(KSM, &EDDIE), 0); - - // Before: check pool_token amount - assert_eq!(bifrost_vtoken_minting::TokenPool::::get(KSM), 0); - // Before: check vksm amount - assert_eq!(Currencies::total_issuance(VKSM), 0); - - // Refund user - assert_ok!(Slp::refund_currency_due_unbond(RuntimeOrigin::signed(ALICE), KSM)); - - // After: check pool_token amount - assert_eq!(bifrost_vtoken_minting::TokenPool::::get(KSM), 0); - // After: check vksm amount - assert_eq!(Currencies::total_issuance(VKSM), 0); - - // Check account balances after refund - assert_eq!(Tokens::free_balance(KSM, &exit_acc), 0); - assert_eq!(Tokens::free_balance(KSM, &BOB), 0); - assert_eq!(Tokens::free_balance(KSM, &CHARLIE), 28); - assert_eq!(Tokens::free_balance(KSM, &DAVE), 22); - assert_eq!(Tokens::free_balance(KSM, &EDDIE), 0); - - // Check storage - // Unlocking records for era 90 - assert_eq!( - bifrost_vtoken_minting::TimeUnitUnlockLedger::::get(TimeUnit::Era(90), KSM,), - Some(time_record_90) - ); - assert_eq!( - bifrost_vtoken_minting::UserUnlockLedger::::get(BOB, KSM,), - Some((10, bounded_vec_bob)) - ); - - // Unlocking records for era 100 - let bounded_vec_100_new = BoundedVec::try_from(vec![2]).unwrap(); - let time_record_100_new = (8, bounded_vec_100_new, KSM); - let record_dave_new = (DAVE, 8, TimeUnit::Era(100), RedeemType::Native); - assert_eq!( - bifrost_vtoken_minting::TokenUnlockLedger::::get(KSM, 2), - Some(record_dave_new.clone()) - ); - - assert_eq!( - bifrost_vtoken_minting::TokenUnlockLedger::::get(KSM, 2), - Some(record_dave_new) - ); - - assert_eq!( - bifrost_vtoken_minting::TimeUnitUnlockLedger::::get(TimeUnit::Era(100), KSM,), - Some(time_record_100_new) - ); - - assert_eq!(bifrost_vtoken_minting::UserUnlockLedger::::get(CHARLIE, KSM,), None); - assert_eq!( - bifrost_vtoken_minting::UserUnlockLedger::::get(DAVE, KSM,), - Some((8, bounded_vec_dave)) - ); - - // Unlocking records for era 110 - assert_eq!( - bifrost_vtoken_minting::TimeUnitUnlockLedger::::get(TimeUnit::Era(110), KSM,), - Some(time_record_110) - ); - - assert_eq!( - bifrost_vtoken_minting::UserUnlockLedger::::get(EDDIE, KSM,), - Some((13, bounded_vec_eddie)) - ); - - // Set some more balance to exit account. - assert_ok!(Tokens::set_balance( - RuntimeOrigin::root(), - MultiAddress::Id(exit_acc.clone()), - KSM, - 30, - 0 - )); - - // set era to 110 - bifrost_vtoken_minting::OngoingTimeUnit::::insert(KSM, TimeUnit::Era(110)); - - // Refund user - assert_ok!(Slp::refund_currency_due_unbond(RuntimeOrigin::signed(ALICE), KSM)); - - // Check storages - assert_eq!( - bifrost_vtoken_minting::TimeUnitUnlockLedger::::get(TimeUnit::Era(110), KSM,), - None - ); - - assert_eq!(bifrost_vtoken_minting::TokenUnlockLedger::::get(KSM, 3), None); - assert_eq!(bifrost_vtoken_minting::TokenUnlockLedger::::get(KSM, 4), None); - - assert_eq!(bifrost_vtoken_minting::UserUnlockLedger::::get(EDDIE, KSM,), None); - - // check account balances - assert_eq!(Tokens::free_balance(KSM, &exit_acc), 17); - assert_eq!(Tokens::free_balance(KSM, &entrance_acc), 0); - assert_eq!(Tokens::free_balance(KSM, &BOB), 0); - assert_eq!(Tokens::free_balance(KSM, &CHARLIE), 28); - assert_eq!(Tokens::free_balance(KSM, &DAVE), 22); - assert_eq!(Tokens::free_balance(KSM, &EDDIE), 13); - assert_ok!(Slp::refund_currency_due_unbond(RuntimeOrigin::signed(ALICE), KSM)); - - // check account balances - assert_eq!(Tokens::free_balance(KSM, &exit_acc), 0); - assert_eq!(Tokens::free_balance(KSM, &entrance_acc), 17); - }); -} - #[test] fn charge_host_fee_and_tune_vtoken_exchange_rate_works() { let para_chain_account: AccountId = ParaId::from(2001).into_account_truncating(); @@ -681,8 +474,8 @@ fn test_construct_xcm() { register_subaccount_index_0(); // construct_xcm_as_subaccount_with_query_id - let weight = Weight::from_parts(20000000000, 20000000000); - let (_, _, _, messsage) = + let _weight = Weight::from_parts(20000000000, 20000000000); + let (_, _, _, _messsage) = crate::Pallet::::construct_xcm_as_subaccount_with_query_id( XcmOperationType::Bond, sp_std::vec![], @@ -692,27 +485,8 @@ fn test_construct_xcm() { ) .unwrap(); - assert_eq!( - messsage.0[1], - BuyExecution { - fees: MultiAsset { - id: Concrete(MultiLocation { parents: 0, interior: Here }), - fun: Fungible(10000000000) - }, - weight_limit: Unlimited - } - ); - assert_eq!( - messsage.0[2], - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: weight, - call: [26, 1, 0, 0].to_vec().into() - } - ); - let weight = Weight::from_parts(100, 100); - let (_, _, _, messsage) = + let (_, _, _, _messsage) = crate::Pallet::::construct_xcm_as_subaccount_with_query_id( XcmOperationType::Bond, sp_std::vec![], @@ -721,24 +495,6 @@ fn test_construct_xcm() { Some((weight, 100u32.into())), ) .unwrap(); - assert_eq!( - messsage.0[1], - BuyExecution { - fees: MultiAsset { - id: Concrete(MultiLocation { parents: 0, interior: Here }), - fun: Fungible(100) - }, - weight_limit: Unlimited - } - ); - assert_eq!( - messsage.0[2], - Transact { - origin_kind: OriginKind::SovereignAccount, - require_weight_at_most: weight, - call: [26, 1, 0, 0].to_vec().into() - } - ); // construct_xcm_and_send_as_subaccount_without_query_id let fee = crate::Pallet::::construct_xcm_and_send_as_subaccount_without_query_id( diff --git a/pallets/slp/src/traits.rs b/pallets/slp/src/traits.rs index d83775ba8..8b1c0f426 100644 --- a/pallets/slp/src/traits.rs +++ b/pallets/slp/src/traits.rs @@ -235,7 +235,7 @@ pub trait QueryResponseManager { // False is returned. fn get_query_response_record(query_id: QueryId) -> bool; fn create_query_record( - responder: &AccountId, + responder: AccountId, call_back: Option, timeout: BlockNumber, ) -> u64; diff --git a/pallets/slpx/Cargo.toml b/pallets/slpx/Cargo.toml index ff1e4830b..ba5ed8a6b 100644 --- a/pallets/slpx/Cargo.toml +++ b/pallets/slpx/Cargo.toml @@ -36,6 +36,7 @@ bifrost-asset-registry = { workspace = true } bifrost-stable-pool = { workspace = true } bifrost-stable-asset = { workspace = true } orml-tokens = { workspace = true } +log = { workspace = true } [dev-dependencies] hex = { workspace = true } @@ -77,6 +78,7 @@ std = [ "bifrost-asset-registry/std", "bifrost-stable-pool/std", "bifrost-stable-asset/std", + "log/std", ] runtime-benchmarks = [ "frame-benchmarking/runtime-benchmarks", diff --git a/pallets/slpx/src/benchmarking.rs b/pallets/slpx/src/benchmarking.rs index 3e58fb064..d0c07e15d 100644 --- a/pallets/slpx/src/benchmarking.rs +++ b/pallets/slpx/src/benchmarking.rs @@ -46,8 +46,8 @@ fn init_whitelist() -> (T::AccountId BalanceOf::::unique_saturated_from(100_000_000_000_000u128), )); - CurrencyIdToLocations::::insert(KSM, MultiLocation::default()); - CurrencyIdToLocations::::insert(VKSM, MultiLocation::default()); + CurrencyIdToLocations::::insert(KSM, xcm::v3::Location::default()); + CurrencyIdToLocations::::insert(VKSM, xcm::v3::Location::default()); (caller, receiver) } @@ -110,6 +110,21 @@ mod benchmarks { ); } + #[benchmark] + fn mint_with_channel_id() { + let (caller, receiver) = init_whitelist::(); + + #[extrinsic_call] + _( + RawOrigin::Signed(caller), + receiver, + KSM, + TargetChain::Astar(receiver), + BoundedVec::default(), + 0u32, + ); + } + #[benchmark] fn redeem() { let (caller, receiver) = init_whitelist::(); diff --git a/pallets/slpx/src/lib.rs b/pallets/slpx/src/lib.rs index a3915139a..90b970239 100644 --- a/pallets/slpx/src/lib.rs +++ b/pallets/slpx/src/lib.rs @@ -51,7 +51,7 @@ use sp_runtime::{ BoundedVec, DispatchError, }; use sp_std::{vec, vec::Vec}; -use xcm::{latest::prelude::*, v3::MultiLocation}; +use xcm::v4::{prelude::*, Location}; use zenlink_protocol::AssetBalance; pub mod migration; @@ -84,7 +84,10 @@ pub mod pallet { use frame_system::ensure_root; use zenlink_protocol::{AssetId, ExportZenlink}; + const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); + #[pallet::pallet] + #[pallet::storage_version(STORAGE_VERSION)] pub struct Pallet(_); #[pallet::config] @@ -115,10 +118,10 @@ pub mod pallet { /// type XcmSender: SendXcm; - /// Convert MultiLocation to `T::CurrencyId`. + /// Convert Location to `T::CurrencyId`. type CurrencyIdConvert: CurrencyIdMapping< CurrencyId, - MultiLocation, + xcm::v3::MultiLocation, AssetMetadata>, >; @@ -456,6 +459,8 @@ pub mod pallet { currency_id, remark, target_chain, + // default to 0 + channel_id: 0u32, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -515,6 +520,8 @@ pub mod pallet { bifrost_chain_caller, derivative_account, target_chain, + // default to 0 + channel_id: 0u32, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -738,6 +745,41 @@ pub mod pallet { currency_id, remark, target_chain, + // default to 0 + channel_id: 0u32, + }; + + OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { + order_queue.try_push(order.clone()).map_err(|_| Error::::ArgumentsError)?; + Self::deposit_event(Event::::CreateOrder { order }); + Ok(().into()) + }) + } + + #[pallet::call_index(13)] + #[pallet::weight(::WeightInfo::mint_with_channel_id())] + pub fn mint_with_channel_id( + origin: OriginFor, + evm_caller: H160, + currency_id: CurrencyIdOf, + target_chain: TargetChain>, + remark: BoundedVec>, + channel_id: u32, + ) -> DispatchResultWithPostInfo { + let (source_chain_caller, derivative_account, bifrost_chain_caller) = + Self::ensure_singer_on_whitelist(origin.clone(), evm_caller, &target_chain)?; + + let order = Order { + create_block_number: >::block_number(), + order_type: OrderType::Mint, + currency_amount: Default::default(), + source_chain_caller, + bifrost_chain_caller, + derivative_account, + currency_id, + remark, + target_chain, + channel_id, }; OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { @@ -755,14 +797,12 @@ impl Pallet { xcm_weight: Weight, xcm_fee: u128, ) -> DispatchResult { - let dest = MultiLocation { - parents: 1, - interior: X1(Parachain(T::VtokenMintingInterface::get_moonbeam_parachain_id())), - }; + let dest = + Location::new(1, [Parachain(T::VtokenMintingInterface::get_moonbeam_parachain_id())]); // Moonbeam Native Token - let asset = MultiAsset { - id: Concrete(MultiLocation { parents: 0, interior: X1(PalletInstance(10)) }), + let asset = Asset { + id: AssetId::from(Location::new(0, [PalletInstance(10)])), fun: Fungible(xcm_fee), }; @@ -777,13 +817,13 @@ impl Pallet { RefundSurplus, DepositAsset { assets: AllCounted(8).into(), - beneficiary: MultiLocation { - parents: 0, - interior: X1(AccountKey20 { + beneficiary: Location::new( + 0, + [AccountKey20 { network: None, key: Sibling::from(T::ParachainId::get()).into_account_truncating(), - }), - }, + }], + ), }, ]); @@ -899,57 +939,57 @@ impl Pallet { match target_chain { TargetChain::Astar(receiver) => { let receiver = Self::h160_to_account_id(*receiver); - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::VtokenMintingInterface::get_astar_parachain_id()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap() }, - ), - }; + ], + ); T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?; }, TargetChain::Hydradx(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::VtokenMintingInterface::get_hydradx_parachain_id()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap() }, - ), - }; + ], + ); T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?; }, TargetChain::Interlay(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::VtokenMintingInterface::get_interlay_parachain_id()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap() }, - ), - }; + ], + ); T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?; }, TargetChain::Manta(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::VtokenMintingInterface::get_manta_parachain_id()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap() }, - ), - }; + ], + ); T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?; }, TargetChain::Moonbeam(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::VtokenMintingInterface::get_moonbeam_parachain_id()), AccountKey20 { network: None, key: receiver.to_fixed_bytes() }, - ), - }; + ], + ); if SupportXcmFeeList::::get().contains(¤cy_id) { T::XcmTransfer::transfer(caller, currency_id, amount, dest, Unlimited)?; } else { @@ -1000,7 +1040,7 @@ impl Pallet { order.currency_id, currency_amount, order.remark.clone(), - None, + Some(order.channel_id), ) .map_err(|_| Error::::ArgumentsError)?; let vtoken_id = T::VtokenMintingInterface::vtoken_id(order.currency_id) diff --git a/pallets/slpx/src/migration.rs b/pallets/slpx/src/migration.rs index 91d3e9b8e..a0c5945b2 100644 --- a/pallets/slpx/src/migration.rs +++ b/pallets/slpx/src/migration.rs @@ -16,12 +16,14 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use crate::*; -use bifrost_primitives::currency::{ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR}; -use frame_support::traits::OnRuntimeUpgrade; +use frame_support::{storage_alias, traits::OnRuntimeUpgrade}; #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; +use bifrost_primitives::currency::{ASTR, BNC, DOT, GLMR, KSM, MANTA, MOVR}; + +use crate::*; + pub struct BifrostKusamaAddCurrencyToSupportXcmFee(sp_std::marker::PhantomData); impl OnRuntimeUpgrade for BifrostKusamaAddCurrencyToSupportXcmFee { fn on_runtime_upgrade() -> Weight { @@ -73,3 +75,100 @@ impl OnRuntimeUpgrade for BifrostPolkadotAddCurrencyToSupportXcmFee = StorageValue< + Pallet, + BoundedVec< + OldOrder, CurrencyIdOf, BalanceOf, BlockNumberFor>, + ConstU32<1000>, + >, + ValueQuery, + >; + + #[derive(Encode, Decode)] + pub struct OldOrder { + pub source_chain_caller: OrderCaller, + pub bifrost_chain_caller: AccountId, + pub derivative_account: AccountId, + pub create_block_number: BlockNumber, + pub currency_id: CurrencyId, + pub currency_amount: Balance, + pub order_type: OrderType, + pub remark: BoundedVec>, + pub target_chain: TargetChain, + } +} + +pub mod v1 { + use frame_support::pallet_prelude::StorageVersion; + + use super::*; + + pub struct MigrateToV1(sp_std::marker::PhantomData); + impl OnRuntimeUpgrade for MigrateToV1 { + fn on_runtime_upgrade() -> Weight { + if StorageVersion::get::>() == 0 { + let weight_consumed = migrate_to_v1::(); + log::info!("Migrating slpx storage to v1"); + StorageVersion::new(1).put::>(); + weight_consumed.saturating_add(T::DbWeight::get().writes(1)) + } else { + log::warn!("slpx migration should be removed."); + T::DbWeight::get().reads(1) + } + } + + #[cfg(feature = "try-runtime")] + fn pre_upgrade() -> Result, sp_runtime::DispatchError> { + log::info!("slpx before migration: version: {:?}", StorageVersion::get::>()); + log::info!("slpx before migration: v0 count: {}", v0::OrderQueue::::get().len()); + + Ok(Vec::new()) + } + + #[cfg(feature = "try-runtime")] + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::DispatchError> { + log::info!("slpx after migration: version: {:?}", StorageVersion::get::>()); + log::info!("slpx after migration: v1 count: {}", OrderQueue::::get().len()); + + Ok(()) + } + } +} + +pub fn migrate_to_v1() -> Weight { + let mut weight: Weight = Weight::zero(); + + let old_orders = v0::OrderQueue::::get(); + for old_order in old_orders.into_iter() { + let order = Order { + source_chain_caller: old_order.source_chain_caller, + bifrost_chain_caller: old_order.bifrost_chain_caller, + derivative_account: old_order.derivative_account, + create_block_number: old_order.create_block_number, + currency_id: old_order.currency_id, + currency_amount: old_order.currency_amount, + order_type: old_order.order_type, + remark: old_order.remark, + target_chain: old_order.target_chain, + // default to 0 + channel_id: 0u32, + }; + + OrderQueue::::mutate(|order_queue| -> DispatchResultWithPostInfo { + order_queue.try_push(order.clone()).map_err(|_| Error::::ArgumentsError)?; + Ok(().into()) + }) + .expect("BoundedVec should not overflow"); + + weight = weight.saturating_add(T::DbWeight::get().writes(1)); + } + + weight +} diff --git a/pallets/slpx/src/mock.rs b/pallets/slpx/src/mock.rs index 8d2bd5876..d0ef639e6 100644 --- a/pallets/slpx/src/mock.rs +++ b/pallets/slpx/src/mock.rs @@ -37,21 +37,16 @@ use orml_traits::{ location::RelativeReserveProvider, parameter_type_with_key, xcm_transfer::Transferred, MultiCurrency, XcmTransfer, }; -use sp_core::{blake2_256, ConstU128}; +use sp_core::ConstU128; use sp_runtime::{ - traits::{ - AccountIdConversion, Convert, IdentityLookup, TrailingZeroInput, UniqueSaturatedInto, - }, + traits::{Convert, IdentityLookup, UniqueSaturatedInto}, AccountId32, SaturatedConversion, }; use sp_std::vec; pub use xcm::latest::prelude::*; use xcm::{ - latest::{Junction, MultiLocation}, - opaque::latest::{ - Junction::Parachain, - Junctions::{X1, X2}, - }, + latest::{Junction, Location}, + opaque::latest::Junction::Parachain, }; use xcm_builder::FrameTransactionalProcessor; pub use xcm_builder::{EnsureXcmOrigin, FixedWeightBounds}; @@ -119,7 +114,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -211,6 +205,7 @@ impl bifrost_vtoken_minting::Config for Test { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } // Below is the implementation of tokens manipulation functions other than native token. pub struct LocalAssetAdaptor(PhantomData); @@ -291,10 +286,10 @@ impl zenlink_protocol::Config for Test { type LpGenerate = PairLpGenerate; } -pub struct AccountIdToMultiLocation; -impl Convert for AccountIdToMultiLocation { - fn convert(account_id: AccountId) -> MultiLocation { - MultiLocation::from(Junction::AccountId32 { network: None, id: account_id.into() }) +pub struct AccountIdToLocation; +impl Convert for AccountIdToLocation { + fn convert(account_id: AccountId) -> Location { + Location::from(Junction::AccountId32 { network: None, id: account_id.into() }) } } @@ -302,7 +297,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -335,26 +330,26 @@ impl xcm_executor::Config for XcmConfig { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { None }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } pub struct BifrostCurrencyIdConvert(sp_std::marker::PhantomData); -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(id: CurrencyId) -> Option { - AssetIdMaps::::get_multi_location(id) +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(id: CurrencyId) -> Option { + AssetIdMaps::::get_location(id) } } -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(location: MultiLocation) -> Option { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(location: Location) -> Option { AssetIdMaps::::get_currency_id(location) } } @@ -366,7 +361,7 @@ impl orml_xtokens::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = BifrostCurrencyIdConvert; - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = DoNothingExecuteXcm; @@ -374,8 +369,10 @@ impl orml_xtokens::Config for Test { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } ord_parameter_types! { @@ -388,48 +385,6 @@ impl bifrost_asset_registry::Config for Test { type WeightInfo = (); } -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - Junction::AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -444,12 +399,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -468,13 +423,11 @@ impl bifrost_slp::Config for Test { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = Slpx; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -487,7 +440,7 @@ impl bifrost_slp::Config for Test { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Test { @@ -565,7 +518,7 @@ impl XcmTransfer for XTokensMock { who: AccountId, currency_id: CurrencyId, amount: Balance, - dest: MultiLocation, + dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { Currencies::withdraw(currency_id, &who, amount).ok(); @@ -573,15 +526,15 @@ impl XcmTransfer for XTokensMock { Ok(Transferred { sender: who, assets: Default::default(), - fee: MultiAsset { id: [0u8; 32].into(), fun: Fungible(0u128) }, + fee: Asset { id: AssetId(Location::new(1, Here)), fun: Fungible(0u128) }, dest, }) } fn transfer_multiasset( _who: AccountId, - _asset: MultiAsset, - _dest: MultiLocation, + _asset: Asset, + _dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { todo!() @@ -592,7 +545,7 @@ impl XcmTransfer for XTokensMock { _currency_id: CurrencyId, _amount: Balance, _fee: Balance, - _dest: MultiLocation, + _dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { todo!() @@ -600,9 +553,9 @@ impl XcmTransfer for XTokensMock { fn transfer_multiasset_with_fee( _who: AccountId, - _asset: MultiAsset, - _fee: MultiAsset, - _dest: MultiLocation, + _asset: Asset, + _fee: Asset, + _dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { todo!() @@ -612,7 +565,7 @@ impl XcmTransfer for XTokensMock { _who: AccountId, _currencies: Vec<(CurrencyId, Balance)>, _fee_item: u32, - _dest: MultiLocation, + _dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { todo!() @@ -620,9 +573,9 @@ impl XcmTransfer for XTokensMock { fn transfer_multiassets( _who: AccountId, - _assets: cumulus_primitives_core::MultiAssets, - _fee: MultiAsset, - _dest: MultiLocation, + _assets: Assets, + _fee: Asset, + _dest: Location, _dest_weight_limit: WeightLimit, ) -> Result, DispatchError> { todo!() diff --git a/pallets/slpx/src/tests.rs b/pallets/slpx/src/tests.rs index 8eaebd2e0..2ab622765 100644 --- a/pallets/slpx/src/tests.rs +++ b/pallets/slpx/src/tests.rs @@ -145,7 +145,12 @@ fn test_zenlink() { let ksm_token: AssetId = AssetId::try_convert_from(CurrencyId::Token(TokenSymbol::KSM), 2001).unwrap(); - assert_ok!(ZenlinkProtocol::create_pair(RawOrigin::Root.into(), bnc_token, ksm_token)); + assert_ok!(ZenlinkProtocol::create_pair( + RawOrigin::Root.into(), + bnc_token, + ksm_token, + ALICE + )); assert_ok!(ZenlinkProtocol::add_liquidity( RawOrigin::Signed(ALICE).into(), bnc_token, @@ -374,6 +379,30 @@ fn test_add_order() { }) } +#[test] +fn test_mint_with_channel_id() { + sp_io::TestExternalities::default().execute_with(|| { + assert_ok!(Slpx::add_whitelist(RuntimeOrigin::root(), SupportChain::Astar, ALICE)); + let source_chain_caller = H160::default(); + assert_ok!(Slpx::mint_with_channel_id( + RuntimeOrigin::signed(ALICE), + source_chain_caller, + DOT, + TargetChain::Astar(source_chain_caller), + BoundedVec::default(), + 0u32 + )); + assert_eq!(OrderQueue::::get().len(), 1usize); + assert_ok!(Slpx::redeem( + RuntimeOrigin::signed(ALICE), + source_chain_caller, + VDOT, + TargetChain::Astar(source_chain_caller) + )); + assert_eq!(OrderQueue::::get().len(), 2usize); + }) +} + #[test] fn test_hook() { sp_io::TestExternalities::default().execute_with(|| { diff --git a/pallets/slpx/src/types.rs b/pallets/slpx/src/types.rs index bcf02e857..5290126d5 100644 --- a/pallets/slpx/src/types.rs +++ b/pallets/slpx/src/types.rs @@ -130,4 +130,5 @@ pub struct Order { pub order_type: OrderType, pub remark: BoundedVec>, pub target_chain: TargetChain, + pub channel_id: u32, } diff --git a/pallets/slpx/src/weights.rs b/pallets/slpx/src/weights.rs index 0dd1a9be0..446fdaf15 100644 --- a/pallets/slpx/src/weights.rs +++ b/pallets/slpx/src/weights.rs @@ -58,6 +58,7 @@ pub trait WeightInfo { fn set_execution_fee() -> Weight; fn set_transfer_to_fee() -> Weight; fn mint() -> Weight; + fn mint_with_channel_id() -> Weight; fn redeem() -> Weight; fn zenlink_swap() -> Weight; fn stable_pool_swap() -> Weight; @@ -138,6 +139,19 @@ impl WeightInfo for () { .saturating_add(RocksDbWeight::get().reads(16_u64)) .saturating_add(RocksDbWeight::get().writes(8_u64)) } + /// Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + /// Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + /// Storage: `Slpx::OrderQueue` (r:1 w:1) + /// Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000_000 picoseconds. + Weight::from_parts(12_000_000, 204487) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } /// Storage: Slpx WhitelistAccountId (r:1 w:0) /// Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) /// Storage: Tokens Accounts (r:2 w:2) diff --git a/pallets/stable-asset/src/mock.rs b/pallets/stable-asset/src/mock.rs index 4c6769d34..ef1811eff 100644 --- a/pallets/stable-asset/src/mock.rs +++ b/pallets/stable-asset/src/mock.rs @@ -63,7 +63,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = (); type MaxFreezes = (); } diff --git a/pallets/stable-pool/rpc/src/lib.rs b/pallets/stable-pool/rpc/src/lib.rs index 6e35b4d15..05e4906a4 100644 --- a/pallets/stable-pool/rpc/src/lib.rs +++ b/pallets/stable-pool/rpc/src/lib.rs @@ -23,7 +23,7 @@ pub use bifrost_stable_pool_rpc_runtime_api::{self as runtime_api, StablePoolRun use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, + types::error::{ErrorCode, ErrorObject}, }; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; @@ -87,13 +87,12 @@ where match rs { Ok(amount) => Ok(NumberOrHex::Hex(amount.into())), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get stable_pool swap output amount.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } fn add_liquidity_amount( @@ -109,12 +108,11 @@ where match rs { Ok(amount) => Ok(NumberOrHex::Hex(amount.into())), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get stable_pool add liquidity amount.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } } diff --git a/pallets/stable-pool/src/mock.rs b/pallets/stable-pool/src/mock.rs index ac1793936..b5f3e9c6e 100644 --- a/pallets/stable-pool/src/mock.rs +++ b/pallets/stable-pool/src/mock.rs @@ -31,10 +31,7 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key}; use sp_runtime::{traits::IdentityLookup, BuildStorage}; -use xcm::{ - prelude::*, - v3::{MultiLocation, Weight}, -}; +use xcm::{prelude::*, v3::Weight}; use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; use xcm_executor::XcmExecutor; @@ -119,7 +116,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -152,16 +149,16 @@ impl xcm_executor::Config for XcmConfig { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: xcm::v4::Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: xcm::v4::Location = xcm::v4::Location::here(); // pub const BaseXcmWeight: Weight = Weight::from_ref_time(1000_000_000u64); pub const MaxAssetsForTransfer: usize = 2; - // pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + // pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } impl orml_xtokens::Config for Test { @@ -169,7 +166,7 @@ impl orml_xtokens::Config for Test { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -177,8 +174,10 @@ impl orml_xtokens::Config for Test { type BaseXcmWeight = (); type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -203,7 +202,6 @@ impl pallet_balances::Config for Test { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -300,6 +298,7 @@ impl bifrost_vtoken_minting::Config for Test { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } pub struct Slp; @@ -310,11 +309,6 @@ impl SlpOperator for Slp { } } -#[cfg(feature = "runtime-benchmarks")] -parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); -} - impl pallet_xcm::Config for Test { type RuntimeEvent = RuntimeEvent; type ExecuteXcmOrigin = xcm_builder::EnsureXcmOrigin; diff --git a/pallets/system-maker/Cargo.toml b/pallets/system-maker/Cargo.toml index d835ec026..2173b235b 100644 --- a/pallets/system-maker/Cargo.toml +++ b/pallets/system-maker/Cargo.toml @@ -55,6 +55,7 @@ std = [ "zenlink-protocol/std", "bifrost-slp/std", "bifrost-asset-registry/std", + "orml-xtokens/std", ] runtime-benchmarks = [ diff --git a/pallets/system-maker/src/mock.rs b/pallets/system-maker/src/mock.rs index 0bd902043..bcd18d750 100644 --- a/pallets/system-maker/src/mock.rs +++ b/pallets/system-maker/src/mock.rs @@ -36,12 +36,9 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use hex_literal::hex; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key, MultiCurrency}; -use parity_scale_codec::{Decode, Encode}; -use sp_core::{hashing::blake2_256, ConstU32}; +use sp_core::ConstU32; use sp_runtime::{ - traits::{ - AccountIdConversion, Convert, IdentityLookup, TrailingZeroInput, UniqueSaturatedInto, - }, + traits::{AccountIdConversion, IdentityLookup, UniqueSaturatedInto}, AccountId32, BuildStorage, SaturatedConversion, }; use sp_std::marker::PhantomData; @@ -135,7 +132,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -191,48 +187,6 @@ impl Get for ParaInfo { } } -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -247,12 +201,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -278,13 +232,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -296,13 +248,13 @@ impl bifrost_slp::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -312,7 +264,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -320,8 +272,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -360,6 +314,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -444,7 +399,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -478,7 +433,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/system-maker/src/tests.rs b/pallets/system-maker/src/tests.rs index 2dd524648..00c57ec38 100644 --- a/pallets/system-maker/src/tests.rs +++ b/pallets/system-maker/src/tests.rs @@ -78,7 +78,8 @@ fn init_zenlink(para_id: u32) -> AccountIdOf { assert_ok!(ZenlinkProtocol::create_pair( RuntimeOrigin::root(), asset_0_currency_id, - asset_1_currency_id + asset_1_currency_id, + ALICE )); let deadline: BlockNumberFor = >::block_number() + BlockNumberFor::::from(100u32); diff --git a/pallets/system-staking/src/mock.rs b/pallets/system-staking/src/mock.rs index 6dbbc5b08..f55394832 100644 --- a/pallets/system-staking/src/mock.rs +++ b/pallets/system-staking/src/mock.rs @@ -33,10 +33,9 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use hex_literal::hex; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key}; -use parity_scale_codec::{Decode, Encode}; -use sp_core::{blake2_256, ConstU32}; +use sp_core::ConstU32; use sp_runtime::{ - traits::{AccountIdConversion, Convert, ConvertInto, IdentityLookup, TrailingZeroInput}, + traits::{ConvertInto, IdentityLookup}, AccountId32, BuildStorage, }; use sp_std::vec; @@ -117,7 +116,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -141,13 +139,13 @@ impl orml_tokens::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -157,7 +155,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -165,8 +163,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -206,6 +206,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } ord_parameter_types! { @@ -218,48 +219,6 @@ impl bifrost_asset_registry::Config for Runtime { type WeightInfo = (); } -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -274,12 +233,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -305,13 +264,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -376,7 +333,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -410,7 +367,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/token-issuer/src/mock.rs b/pallets/token-issuer/src/mock.rs index 89bc83c28..b110b7b22 100644 --- a/pallets/token-issuer/src/mock.rs +++ b/pallets/token-issuer/src/mock.rs @@ -100,7 +100,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/ve-minting/rpc/src/lib.rs b/pallets/ve-minting/rpc/src/lib.rs index 4d0f99c1a..d55fe6b5d 100644 --- a/pallets/ve-minting/rpc/src/lib.rs +++ b/pallets/ve-minting/rpc/src/lib.rs @@ -23,7 +23,7 @@ pub use bifrost_ve_minting_rpc_runtime_api::{self as runtime_api, VeMintingRunti use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, - types::error::{CallError, ErrorCode, ErrorObject}, + types::error::{ErrorCode, ErrorObject}, }; use parity_scale_codec::Codec; use sp_api::ProvideRuntimeApi; @@ -90,24 +90,23 @@ where None => None, }) .map_err(|e| { - jsonrpsee::core::Error::Call(CallError::Custom(ErrorObject::owned( + ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get balance_of.", Some(format!("{:?}", e)), - ))) + ) })?; let rs: Result = lm_rpc_api.balance_of(at, who, block_number); match rs { Ok(balane) => Ok(NumberOrHex::Hex(balane.into())), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get balance_of.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } fn total_supply(&self, at: Option<::Hash>) -> RpcResult { @@ -121,24 +120,23 @@ where None => None, }) .map_err(|e| { - jsonrpsee::core::Error::Call(CallError::Custom(ErrorObject::owned( + ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get total_supply.", Some(format!("{:?}", e)), - ))) + ) })?; let rs: Result = lm_rpc_api.total_supply(at, block_number.expect("no block found")); match rs { Ok(supply) => Ok(NumberOrHex::Hex(supply.into())), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get total_supply.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } fn find_block_epoch( @@ -156,23 +154,22 @@ where None => None, }) .map_err(|e| { - jsonrpsee::core::Error::Call(CallError::Custom(ErrorObject::owned( + ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get find_block_epoch.", Some(format!("{:?}", e)), - ))) + ) })?; let rs: Result = lm_rpc_api.find_block_epoch(at, block_number.expect("no block found"), max_epoch); match rs { Ok(epoch) => Ok(NumberOrHex::Hex(epoch.into())), - Err(e) => Err(CallError::Custom(ErrorObject::owned( + Err(e) => Err(ErrorObject::owned( ErrorCode::InternalError.code(), "Failed to get find_block_epoch.", Some(format!("{:?}", e)), - ))), + )), } - .map_err(|e| jsonrpsee::core::Error::Call(e)) } } diff --git a/pallets/ve-minting/src/mock.rs b/pallets/ve-minting/src/mock.rs index cc599d73e..9c59dd190 100644 --- a/pallets/ve-minting/src/mock.rs +++ b/pallets/ve-minting/src/mock.rs @@ -39,10 +39,9 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use hex_literal::hex; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key}; -use parity_scale_codec::{Decode, Encode}; -use sp_core::{blake2_256, ConstU32}; +use sp_core::ConstU32; use sp_runtime::{ - traits::{AccountIdConversion, Convert, ConvertInto, IdentityLookup, TrailingZeroInput}, + traits::{ConvertInto, IdentityLookup}, AccountId32, BuildStorage, }; use xcm::{prelude::*, v3::Weight}; @@ -125,7 +124,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -160,13 +158,13 @@ impl orml_tokens::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -176,7 +174,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -184,8 +182,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -229,6 +229,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } ord_parameter_types! { @@ -270,48 +271,6 @@ impl bifrost_ve_minting::Config for Runtime { type MarkupRefreshLimit = MarkupRefreshLimit; } -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex_literal::hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -326,12 +285,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -362,13 +321,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -383,7 +340,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -417,7 +374,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { diff --git a/pallets/ve-minting/src/traits.rs b/pallets/ve-minting/src/traits.rs index 9bdf2b94b..32e7deb27 100644 --- a/pallets/ve-minting/src/traits.rs +++ b/pallets/ve-minting/src/traits.rs @@ -68,6 +68,11 @@ pub trait VeMintingInterface { rewards: &Vec<(CurrencyId, Balance)>, remaining: Balance, ) -> DispatchResult; + fn notify_reward( + pool_id: PoolId, + addr: &Option, + rewards: Vec<(CurrencyId, Balance)>, + ) -> DispatchResult; } impl VeMintingInterface, CurrencyIdOf, BalanceOf, BlockNumberFor> @@ -318,6 +323,7 @@ impl VeMintingInterface, CurrencyIdOf, BalanceOf IncentiveConfigs::::set(pool_id, incentive_config.clone()); Self::deposit_event(Event::IncentiveSet { incentive_config }); } + fn add_reward( addr: &AccountIdOf, conf: &mut IncentiveConfig< @@ -367,6 +373,14 @@ impl VeMintingInterface, CurrencyIdOf, BalanceOf ) }) } + + fn notify_reward( + pool_id: PoolId, + addr: &Option>, + rewards: Vec<(CurrencyIdOf, BalanceOf)>, + ) -> DispatchResult { + Self::notify_reward_amount(pool_id, addr, rewards) + } } impl @@ -459,6 +473,13 @@ where ) -> DispatchResult { Ok(()) } + fn notify_reward( + _pool_id: PoolId, + _addr: &Option, + _rewards: Vec<(CurrencyId, Balance)>, + ) -> DispatchResult { + Ok(()) + } } #[derive(Clone, Encode, Decode, PartialEq, Eq, RuntimeDebug, TypeInfo, Default)] diff --git a/pallets/vesting/src/mock.rs b/pallets/vesting/src/mock.rs index b717801af..8ed458342 100644 --- a/pallets/vesting/src/mock.rs +++ b/pallets/vesting/src/mock.rs @@ -64,7 +64,6 @@ impl pallet_balances::Config for Test { type MaxFreezes = (); type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; - type MaxHolds = (); } parameter_types! { pub const MinVestedTransfer: u64 = 256 * 2; diff --git a/pallets/vstoken-conversion/src/mock.rs b/pallets/vstoken-conversion/src/mock.rs index ad49b14eb..0e9fa07d8 100644 --- a/pallets/vstoken-conversion/src/mock.rs +++ b/pallets/vstoken-conversion/src/mock.rs @@ -96,7 +96,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } diff --git a/pallets/vtoken-minting/Cargo.toml b/pallets/vtoken-minting/Cargo.toml index 5db3a3f78..ade306b6e 100644 --- a/pallets/vtoken-minting/Cargo.toml +++ b/pallets/vtoken-minting/Cargo.toml @@ -24,6 +24,7 @@ cumulus-primitives-core = { workspace = true } sp-core = { workspace = true } sp-runtime = { workspace = true } bifrost-ve-minting = { workspace = true } +bifrost-asset-registry = { workspace = true } [dev-dependencies] orml-tokens = { workspace = true } diff --git a/pallets/vtoken-minting/rpc/Cargo.toml b/pallets/vtoken-minting/rpc/Cargo.toml new file mode 100644 index 000000000..080396f47 --- /dev/null +++ b/pallets/vtoken-minting/rpc/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "bifrost-vtoken-minting-rpc" +version = "0.8.0" +authors = ["Tiebing "] +edition = "2021" + +[dependencies] +serde = { workspace = true, features = ["derive"] } +parity-scale-codec = { workspace = true, features = ["derive"] } +jsonrpsee = { workspace = true, features = ["server", "macros"] } +sp-api = { workspace = true } +sp-runtime = { workspace = true } +sp-blockchain = { workspace = true } +sp-core = { workspace = true } +sp-rpc = { workspace = true } +bifrost-primitives = { workspace = true } +bifrost-vtoken-minting-rpc-runtime-api = { workspace = true } diff --git a/pallets/vtoken-minting/rpc/runtime-api/Cargo.toml b/pallets/vtoken-minting/rpc/runtime-api/Cargo.toml new file mode 100644 index 000000000..a18515f8d --- /dev/null +++ b/pallets/vtoken-minting/rpc/runtime-api/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "bifrost-vtoken-minting-rpc-runtime-api" +version = "0.8.0" +authors = ["Tiebing "] +edition = "2021" + +[dependencies] +parity-scale-codec = { workspace = true, features = ["derive"] } +sp-std = { workspace = true } +sp-api = { workspace = true } +sp-core = { workspace = true } +bifrost-primitives = { workspace = true } + +[features] +default = ["std"] +std = [ + "parity-scale-codec/std", + "sp-api/std", + "bifrost-primitives/std", +] diff --git a/integration-tests/bifrost-kusama/src/general_key.rs b/pallets/vtoken-minting/rpc/runtime-api/src/lib.rs similarity index 58% rename from integration-tests/bifrost-kusama/src/general_key.rs rename to pallets/vtoken-minting/rpc/runtime-api/src/lib.rs index a811dbd3f..6af2840b8 100644 --- a/integration-tests/bifrost-kusama/src/general_key.rs +++ b/pallets/vtoken-minting/rpc/runtime-api/src/lib.rs @@ -16,26 +16,16 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use bifrost_primitives::{CurrencyId, TokenSymbol}; -use integration_tests_common::BifrostKusama; -use parity_scale_codec::Encode; -use sp_runtime::BoundedVec; -use xcm::prelude::*; -use xcm_emulator::TestExt; +#![cfg_attr(not(feature = "std"), no_std)] -#[test] -fn dollar_should_work() { - BifrostKusama::execute_with(|| { - let id = CurrencyId::Token(TokenSymbol::KSM); - assert_eq!( - Junction::from(BoundedVec::try_from(id.encode()).unwrap()), - GeneralKey { - length: 2, - data: [ - 2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0 - ] - } - ); - }); +use parity_scale_codec::Codec; +use sp_api::decl_runtime_apis; +use sp_core::U256; +use sp_std::vec::Vec; + +decl_runtime_apis! { + pub trait VtokenMintingRuntimeApi where CurrencyId: Codec + { + fn get_exchange_rate(token_id: Option) -> Vec<(CurrencyId, U256)>; + } } diff --git a/pallets/vtoken-minting/rpc/src/lib.rs b/pallets/vtoken-minting/rpc/src/lib.rs new file mode 100644 index 000000000..301d82f26 --- /dev/null +++ b/pallets/vtoken-minting/rpc/src/lib.rs @@ -0,0 +1,88 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +use std::{marker::PhantomData, sync::Arc}; + +pub use bifrost_vtoken_minting_rpc_runtime_api::VtokenMintingRuntimeApi; +use jsonrpsee::{ + core::{async_trait, RpcResult}, + proc_macros::rpc, + types::error::{ErrorCode, ErrorObject}, +}; +use parity_scale_codec::Codec; +use sp_api::ProvideRuntimeApi; +use sp_blockchain::HeaderBackend; +use sp_core::U256; +use sp_rpc::number::NumberOrHex; +use sp_runtime::traits::Block as BlockT; + +#[rpc(client, server)] +pub trait VtokenMintingRpcApi { + /// rpc method for getting vtoken exchange rate + #[method(name = "vtoken_minting_getExchangeRate")] + fn get_exchange_rate( + &self, + asset_id: Option, + at: Option, + ) -> RpcResult>; +} + +#[derive(Clone, Debug)] +pub struct VtokenMintingRpc { + client: Arc, + _marker: PhantomData, +} + +impl VtokenMintingRpc { + pub fn new(client: Arc) -> Self { + Self { client, _marker: PhantomData } + } +} + +#[async_trait] +impl VtokenMintingRpcApiServer::Hash> + for VtokenMintingRpc +where + Block: BlockT, + C: Send + Sync + 'static + ProvideRuntimeApi + HeaderBackend, + C::Api: VtokenMintingRuntimeApi, + CurrencyId: Codec, +{ + fn get_exchange_rate( + &self, + token_id: Option, + at: Option<::Hash>, + ) -> RpcResult> { + let api = self.client.runtime_api(); + let at = at.unwrap_or_else(|| self.client.info().best_hash); + + let rs: Result, _> = api.get_exchange_rate(at, token_id); + + match rs { + Ok(data) => Ok(data + .into_iter() + .map(|(token, rate)| (token, NumberOrHex::Hex(rate.into()))) + .collect()), + Err(e) => Err(ErrorObject::owned( + ErrorCode::InternalError.code(), + "Failed to get find_block_epoch.", + Some(format!("{:?}", e)), + )), + } + } +} diff --git a/pallets/vtoken-minting/src/lib.rs b/pallets/vtoken-minting/src/lib.rs index 4bebd2b38..24836a404 100644 --- a/pallets/vtoken-minting/src/lib.rs +++ b/pallets/vtoken-minting/src/lib.rs @@ -33,10 +33,11 @@ pub mod traits; pub mod weights; pub use weights::WeightInfo; +use bifrost_asset_registry::AssetMetadata; use bifrost_primitives::{ - CurrencyId, CurrencyIdConversion, CurrencyIdExt, CurrencyIdRegister, RedeemType, SlpOperator, - SlpxOperator, TimeUnit, VTokenMintRedeemProvider, VTokenSupplyProvider, VtokenMintingInterface, - VtokenMintingOperator, + CurrencyId, CurrencyIdConversion, CurrencyIdExt, CurrencyIdMapping, CurrencyIdRegister, + RedeemType, SlpOperator, SlpxOperator, TimeUnit, VTokenMintRedeemProvider, + VTokenSupplyProvider, VtokenMintingInterface, VtokenMintingOperator, }; use bifrost_ve_minting::traits::VeMintingInterface; use frame_support::{ @@ -57,6 +58,7 @@ pub use pallet::*; use sp_core::U256; use sp_std::{vec, vec::Vec}; pub use traits::*; +use xcm::v3::MultiLocation; pub type AccountIdOf = ::AccountId; @@ -77,7 +79,7 @@ pub mod pallet { use bifrost_primitives::{currency::BNC, FIL}; use frame_support::pallet_prelude::DispatchResultWithPostInfo; use orml_traits::XcmTransfer; - use xcm::{prelude::*, v3::MultiLocation}; + use xcm::{prelude::*, v4::Location}; #[pallet::pallet] pub struct Pallet(_); @@ -165,6 +167,12 @@ pub mod pallet { type ChannelCommission: VTokenMintRedeemProvider>; + type AssetIdMaps: CurrencyIdMapping< + CurrencyId, + MultiLocation, + AssetMetadata>, + >; + /// Set default weight. type WeightInfo: WeightInfo; } @@ -1261,16 +1269,16 @@ pub mod pallet { match redeem_type { RedeemType::Native => {}, RedeemType::Astar(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::AstarParachainId::get()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap(), }, - ), - }; + ], + ); T::XcmTransfer::transfer( account.clone(), token_id, @@ -1281,16 +1289,16 @@ pub mod pallet { redeem_to = RedeemTo::Astar(receiver); }, RedeemType::Hydradx(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::HydradxParachainId::get()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap(), }, - ), - }; + ], + ); T::XcmTransfer::transfer( account.clone(), token_id, @@ -1301,16 +1309,16 @@ pub mod pallet { redeem_to = RedeemTo::Hydradx(receiver); }, RedeemType::Interlay(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::InterlayParachainId::get()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap(), }, - ), - }; + ], + ); T::XcmTransfer::transfer( account.clone(), token_id, @@ -1321,16 +1329,16 @@ pub mod pallet { redeem_to = RedeemTo::Interlay(receiver); }, RedeemType::Manta(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::MantaParachainId::get()), AccountId32 { network: None, id: receiver.encode().try_into().unwrap(), }, - ), - }; + ], + ); T::XcmTransfer::transfer( account.clone(), token_id, @@ -1341,13 +1349,13 @@ pub mod pallet { redeem_to = RedeemTo::Manta(receiver); }, RedeemType::Moonbeam(receiver) => { - let dest = MultiLocation { - parents: 1, - interior: X2( + let dest = Location::new( + 1, + [ Parachain(T::MoonbeamParachainId::get()), AccountKey20 { network: None, key: receiver.to_fixed_bytes() }, - ), - }; + ], + ); if token_id == FIL { let assets = vec![ (token_id, unlock_amount), @@ -1918,6 +1926,52 @@ pub mod pallet { Ok(incentive_amount) } + + pub fn get_exchange_rate( + token_id: Option, + ) -> Result, U256)>, DispatchError> { + let mut result: Vec<(CurrencyIdOf, U256)> = Vec::new(); + + match token_id { + Some(token_id) => { + let vtoken_amount = Self::get_vtoken_amount(token_id, 1000u128)?; + result.push((token_id, vtoken_amount)); + }, + None => + for token_id in T::AssetIdMaps::get_all_currency() { + if token_id.is_vtoken() { + let vtoken_id = token_id; + let token_id = T::CurrencyIdConversion::convert_to_token(vtoken_id) + .map_err(|_| Error::::NotSupportTokenType)?; + + let vtoken_amount = Self::get_vtoken_amount(token_id, 1000u128)?; + result.push((token_id, vtoken_amount)); + } + }, + } + Ok(result) + } + + fn get_vtoken_amount(token: CurrencyIdOf, amount: u128) -> Result { + let vtoken_id = T::CurrencyIdConversion::convert_to_vtoken(token) + .map_err(|_| Error::::NotSupportTokenType)?; + + let token_pool_amount = Self::token_pool(token); + let vtoken_total_issuance = T::MultiCurrency::total_issuance(vtoken_id); + + let mut vtoken_amount = U256::from(amount); + if token_pool_amount != BalanceOf::::zero() { + let vtoken_total_issuance_u256 = + U256::from(vtoken_total_issuance.saturated_into::()); + let token_pool_amount_u256 = U256::from(token_pool_amount.saturated_into::()); + + vtoken_amount = vtoken_amount + .saturating_mul(vtoken_total_issuance_u256) + .checked_div(token_pool_amount_u256) + .ok_or(Error::::CalculationOverflow)?; + } + Ok(vtoken_amount) + } } } diff --git a/pallets/vtoken-minting/src/mock.rs b/pallets/vtoken-minting/src/mock.rs index 9fcdf2d50..e33677c9d 100644 --- a/pallets/vtoken-minting/src/mock.rs +++ b/pallets/vtoken-minting/src/mock.rs @@ -40,10 +40,8 @@ use frame_support::{ use frame_system::{EnsureRoot, EnsureSignedBy}; use hex_literal::hex; use orml_traits::{location::RelativeReserveProvider, parameter_type_with_key}; -use parity_scale_codec::{Decode, Encode}; -use sp_core::blake2_256; use sp_runtime::{ - traits::{AccountIdConversion, ConstU32, Convert, IdentityLookup, TrailingZeroInput}, + traits::{ConstU32, IdentityLookup}, AccountId32, BuildStorage, DispatchError, DispatchResult, }; use xcm::{prelude::*, v3::Weight}; @@ -126,7 +124,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -166,13 +163,13 @@ impl orml_tokens::Config for Runtime { } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } parameter_types! { - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } @@ -182,7 +179,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = (); - type AccountIdToMultiLocation = (); + type AccountIdToLocation = (); type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -190,8 +187,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } parameter_types! { @@ -236,6 +235,7 @@ impl vtoken_minting::Config for Runtime { type MantaParachainId = ConstU32<2104>; type InterlayParachainId = ConstU32<2032>; type ChannelCommission = (); + type AssetIdMaps = AssetIdMaps; } ord_parameter_types! { @@ -247,49 +247,6 @@ impl bifrost_asset_registry::Config for Runtime { type RegisterOrigin = EnsureSignedBy; type WeightInfo = (); } - -pub struct SubAccountIndexMultiLocationConvertor; -impl Convert<(u16, CurrencyId), MultiLocation> for SubAccountIndexMultiLocationConvertor { - fn convert((sub_account_index, currency_id): (u16, CurrencyId)) -> MultiLocation { - match currency_id { - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( - 1, - X2( - Parachain(2023), - AccountKey20 { - network: None, - key: Slp::derivative_account_id_20( - hex!["7369626cd1070000000000000000000000000000"].into(), - sub_account_index, - ) - .into(), - }, - ), - ), - _ => MultiLocation::new( - 1, - X1(Junction::AccountId32 { - network: None, - id: Self::derivative_account_id( - ParaId::from(2001u32).into_account_truncating(), - sub_account_index, - ) - .into(), - }), - ), - } - } -} - -// Mock Utility::derivative_account_id function. -impl SubAccountIndexMultiLocationConvertor { - pub fn derivative_account_id(who: AccountId, index: u16) -> AccountId { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - Decode::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .expect("infinite length input; no invalid inputs for type; qed") - } -} - pub struct ParachainId; impl Get for ParachainId { fn get() -> ParaId { @@ -304,12 +261,12 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager for SubstrateResponseManager { +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(_query_id: QueryId) -> bool { Default::default() } fn create_query_record( - _responder: &MultiLocation, + _responder: Location, _call_back: Option, _timeout: u64, ) -> u64 { @@ -340,13 +297,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EnsureSignedBy; type WeightInfo = (); type VtokenMinting = VtokenMinting; - type BifrostSlpx = SlpxInterface; - type AccountConverter = SubAccountIndexMultiLocationConvertor; + type AccountConverter = (); type ParachainId = ParachainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = (); type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -361,7 +316,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -395,7 +350,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { @@ -595,4 +550,11 @@ impl VeMintingInterface for VeMinti ) -> DispatchResult { Ok(()) } + fn notify_reward( + _pool_id: u32, + _addr: &Option, + _rewards: Vec<(CurrencyId, Balance)>, + ) -> DispatchResult { + Ok(()) + } } diff --git a/pallets/vtoken-voting/src/benchmarking.rs b/pallets/vtoken-voting/src/benchmarking.rs index 54e0392b8..72159e0e5 100644 --- a/pallets/vtoken-voting/src/benchmarking.rs +++ b/pallets/vtoken-voting/src/benchmarking.rs @@ -52,8 +52,8 @@ fn init_vote(vtoken: CurrencyIdOf) -> Result<(), BenchmarkError> { Some((Weight::from_parts(4000000000, 100000), 4000000000u32.into())), )?; T::DerivativeAccount::init_minimums_and_maximums(token); - T::DerivativeAccount::add_delegator(token, derivative_index, Parent.into()); - T::DerivativeAccount::new_delegator_ledger(token, Parent.into()); + T::DerivativeAccount::add_delegator(token, derivative_index, xcm::v3::Parent.into()); + T::DerivativeAccount::new_delegator_ledger(token, xcm::v3::Parent.into()); Pallet::::set_undeciding_timeout(RawOrigin::Root.into(), vtoken, Zero::zero())?; Pallet::::add_delegator(RawOrigin::Root.into(), vtoken, derivative_index)?; Pallet::::set_vote_cap_ratio(RawOrigin::Root.into(), vtoken, Perbill::from_percent(10))?; @@ -250,7 +250,7 @@ mod benchmarks { T::DerivativeAccount::add_delegator( CurrencyId::to_token(&vtoken).unwrap(), derivative_index, - Parent.into(), + xcm::v3::Parent.into(), ); #[extrinsic_call] diff --git a/pallets/vtoken-voting/src/lib.rs b/pallets/vtoken-voting/src/lib.rs index 711295d41..3cd4ea416 100644 --- a/pallets/vtoken-voting/src/lib.rs +++ b/pallets/vtoken-voting/src/lib.rs @@ -30,7 +30,7 @@ mod tests; mod call; mod vote; -pub mod migration; +// pub mod migration; pub mod weights; use crate::vote::{Casting, Tally, Voting}; @@ -61,7 +61,7 @@ use sp_runtime::{ }; use sp_std::prelude::*; pub use weights::WeightInfo; -use xcm::v3::{prelude::*, Weight as XcmWeight}; +use xcm::v4::{prelude::*, Weight as XcmWeight}; const CONVICTION_VOTING_ID: LockIdentifier = *b"vtvoting"; @@ -109,7 +109,7 @@ pub mod pallet { type ResponseOrigin: EnsureOrigin< ::RuntimeOrigin, - Success = MultiLocation, + Success = xcm::v4::Location, >; type XcmDestWeightAndFee: XcmDestWeightAndFeeHandler, BalanceOf>; @@ -194,7 +194,7 @@ pub mod pallet { success: bool, }, ResponseReceived { - responder: MultiLocation, + responder: xcm::v4::Location, query_id: QueryId, response: Response, }, @@ -1010,7 +1010,7 @@ pub mod pallet { extra_fee: BalanceOf, f: impl FnOnce(QueryId) -> (), ) -> DispatchResult { - let responder = MultiLocation::parent(); + let responder = xcm::v4::Location::parent(); let now = frame_system::Pallet::::block_number(); let timeout = now.saturating_add(T::QueryTimeout::get()); let notify_runtime_call = ::RuntimeCall::from(notify_call); @@ -1019,7 +1019,7 @@ pub mod pallet { responder, notify_runtime_call, timeout, - Here, + xcm::v4::Junctions::Here, ); f(query_id); @@ -1032,8 +1032,8 @@ pub mod pallet { query_id, )?; - send_xcm::(Parent.into(), xcm_message) - .map_err(|_| Error::::XcmFailure)?; + xcm::v4::send_xcm::(Parent.into(), xcm_message) + .map_err(|_e| Error::::XcmFailure)?; Ok(()) } @@ -1046,11 +1046,11 @@ pub mod pallet { query_id: QueryId, ) -> Result, Error> { let para_id = T::ParachainId::get().into(); - let asset = MultiAsset { - id: Concrete(MultiLocation::here()), + let asset = Asset { + id: AssetId(Location::here()), fun: Fungible(UniqueSaturatedInto::::unique_saturated_into(extra_fee)), }; - let xcm_message = vec![ + let xcm_message = sp_std::vec![ WithdrawAsset(asset.clone().into()), BuyExecution { fees: asset, weight_limit: Unlimited }, Transact { @@ -1059,14 +1059,14 @@ pub mod pallet { call: call.into(), }, ReportTransactStatus(QueryResponseInfo { - destination: MultiLocation::from(X1(Parachain(para_id))), + destination: Location::from(Parachain(para_id)), query_id, max_weight: notify_call_weight, }), RefundSurplus, DepositAsset { assets: All.into(), - beneficiary: MultiLocation { parents: 0, interior: X1(Parachain(para_id)) }, + beneficiary: Location::new(0, [Parachain(para_id)]), }, ]; @@ -1154,9 +1154,10 @@ pub mod pallet { fn ensure_xcm_response_or_governance( origin: OriginFor, - ) -> Result { - let responder = T::ResponseOrigin::ensure_origin(origin.clone()) - .or_else(|_| T::ControlOrigin::ensure_origin(origin).map(|_| Here.into()))?; + ) -> Result { + let responder = T::ResponseOrigin::ensure_origin(origin.clone()).or_else(|_| { + T::ControlOrigin::ensure_origin(origin).map(|_| xcm::v4::Junctions::Here.into()) + })?; Ok(responder) } diff --git a/pallets/vtoken-voting/src/mock.rs b/pallets/vtoken-voting/src/mock.rs index a936341df..686900e18 100644 --- a/pallets/vtoken-voting/src/mock.rs +++ b/pallets/vtoken-voting/src/mock.rs @@ -39,7 +39,7 @@ use sp_runtime::{ traits::{BlockNumberProvider, ConstU32, IdentityLookup}, BuildStorage, Perbill, }; -use xcm::prelude::*; +use xcm::{prelude::*, v3::MultiLocation}; use xcm_builder::{FixedWeightBounds, FrameTransactionalProcessor}; use xcm_executor::XcmExecutor; @@ -110,7 +110,6 @@ impl pallet_balances::Config for Runtime { type RuntimeHoldReason = RuntimeHoldReason; type RuntimeFreezeReason = RuntimeFreezeReason; type FreezeIdentifier = (); - type MaxHolds = ConstU32<0>; type MaxFreezes = ConstU32<0>; } @@ -142,7 +141,7 @@ parameter_types! { // One XCM operation is 200_000_000 XcmWeight, cross-chain transfer ~= 2x of transfer = 3_000_000_000 pub UnitWeightCost: Weight = Weight::from_parts(200_000_000, 0); pub const MaxInstructions: u32 = 100; - pub UniversalLocation: InteriorMultiLocation = X1(Parachain(2001)); + pub UniversalLocation: InteriorLocation = Parachain(2001).into(); } pub struct XcmConfig; @@ -176,7 +175,7 @@ impl xcm_executor::Config for XcmConfig { #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { @@ -248,7 +247,7 @@ impl DerivativeAccountHandler for DerivativeAccount { _token: CurrencyId, _derivative_index: DerivativeIndex, ) -> Option { - Some(Parent.into()) + Some(xcm::v3::Parent.into()) } fn get_stake_info( @@ -291,7 +290,8 @@ impl BlockNumberProvider for RelaychainDataProvider { } parameter_types! { - pub static VTokenSupply: Balance = u64::MAX.into(); + // modify TokenSupply to be twice that of VTokenSupply, making the exchange rate for vtokenming 1:2 + pub static VTokenSupply: Balance = u64::MAX.checked_div(2u64).unwrap().into(); pub static TokenSupply: Balance = u64::MAX.into(); } diff --git a/pallets/vtoken-voting/src/tests.rs b/pallets/vtoken-voting/src/tests.rs index 8f0fac3cb..48f204fa2 100644 --- a/pallets/vtoken-voting/src/tests.rs +++ b/pallets/vtoken-voting/src/tests.rs @@ -71,13 +71,13 @@ fn basic_voting_works() { let vtoken = VKSM; assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, poll_index, aye(2, 5))); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(10, 0, 2)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(20, 0, 4)); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::Voted { who: ALICE, vtoken, poll_index, - token_vote: aye(2, 5), - delegator_vote: aye(100, 0), + token_vote: aye(4, 5), + delegator_vote: aye(200, 0), })); assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response_success())); @@ -101,7 +101,7 @@ fn voting_balance_gets_locked() { poll_index, nay(10, 0) )); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 1, 0)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(0, 2, 0)); assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response_success())); assert_eq!(usable_balance(vtoken, &ALICE), 0); @@ -177,6 +177,105 @@ fn unsuccessful_conviction_vote_balance_can_be_unlocked() { }); } +#[test] +fn ensure_balance_after_unlock() { + new_test_ext().execute_with(|| { + let poll_index = 3; + let poll_index_2 = 4; + let vtoken = VKSM; + let locking_period = 10; + assert_ok!(VtokenVoting::set_vote_locking_period( + RuntimeOrigin::root(), + vtoken, + locking_period, + )); + + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index, + aye(10, 1) + )); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response_success())); + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index_2, + aye(10, 5) + )); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response_success())); + + assert_ok!(VtokenVoting::set_referendum_status( + RuntimeOrigin::root(), + vtoken, + poll_index, + ReferendumInfoOf::::Completed(3), + )); + RelaychainDataProvider::set_block_number(13); + assert_ok!(VtokenVoting::unlock(RuntimeOrigin::signed(ALICE), vtoken, poll_index)); + assert_eq!(usable_balance(vtoken, &ALICE), 0); + assert_eq!(Tokens::accounts(&ALICE, vtoken).frozen, 10); + assert_eq!(VotingFor::::get(&ALICE).locked_balance(), 10); + }); +} + +#[test] +fn ensure_comprehensive_balance_after_unlock() { + new_test_ext().execute_with(|| { + let poll_index = 3; + let poll_index_2 = 4; + let poll_index_3 = 5; + let vtoken = VKSM; + let locking_period = 10; + assert_ok!(VtokenVoting::set_vote_locking_period( + RuntimeOrigin::root(), + vtoken, + locking_period, + )); + + assert_ok!(VtokenVoting::vote(RuntimeOrigin::signed(ALICE), vtoken, poll_index, aye(2, 1))); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 0, response_success())); + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index_2, + aye(1, 5) + )); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 1, response_success())); + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index_3, + aye(2, 5) + )); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 2, response_success())); + + assert_ok!(VtokenVoting::set_referendum_status( + RuntimeOrigin::root(), + vtoken, + poll_index, + ReferendumInfoOf::::Completed(3), + )); + RelaychainDataProvider::set_block_number(13); + assert_ok!(VtokenVoting::unlock(RuntimeOrigin::signed(ALICE), vtoken, poll_index)); + assert_eq!(usable_balance(vtoken, &ALICE), 8); + assert_eq!(Tokens::accounts(&ALICE, vtoken).frozen, 2); + assert_eq!(VotingFor::::get(&ALICE).locked_balance(), 2); + + assert_ok!(VtokenVoting::vote( + RuntimeOrigin::signed(ALICE), + vtoken, + poll_index_2, + aye(10, 5) + )); + assert_ok!(VtokenVoting::notify_vote(origin_response(), 3, response_success())); + + assert_eq!(usable_balance(vtoken, &ALICE), 0); + assert_eq!(Tokens::accounts(&ALICE, vtoken).frozen, 10); + assert_eq!(VotingFor::::get(&ALICE).locked_balance(), 10); + }); +} + #[test] fn successful_conviction_vote_balance_stays_locked_for_correct_time() { new_test_ext().execute_with(|| { @@ -614,25 +713,25 @@ fn notify_vote_success_works() { ReferendumInfoFor::::get(vtoken, poll_index), Some(ReferendumInfo::Ongoing(ReferendumStatus { submitted: None, - tally: TallyOf::::from_parts(10, 0, 2), + tally: TallyOf::::from_parts(20, 0, 4), })) ); assert_eq!( PendingDelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); assert_eq!(DelegatorVotes::::get(vtoken, poll_index).len(), 0); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(10, 0, 2)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(20, 0, 4)); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::Voted { who: ALICE, vtoken, poll_index, - token_vote: aye(2, 5), - delegator_vote: aye(100, 0), + token_vote: aye(4, 5), + delegator_vote: aye(200, 0), })); assert_ok!(VtokenVoting::notify_vote(origin_response(), query_id, response.clone())); @@ -640,7 +739,7 @@ fn notify_vote_success_works() { ReferendumInfoFor::::get(vtoken, poll_index), Some(ReferendumInfo::Ongoing(ReferendumStatus { submitted: Some(1), - tally: TallyOf::::from_parts(10, 0, 2), + tally: TallyOf::::from_parts(20, 0, 4), })) ); assert_eq!(PendingDelegatorVotes::::get(vtoken, poll_index).len(), 0); @@ -648,7 +747,7 @@ fn notify_vote_success_works() { DelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); @@ -662,7 +761,7 @@ fn notify_vote_success_works() { poll_index, info: ReferendumInfo::Ongoing(ReferendumStatus { submitted: Some(1), - tally: TallyOf::::from_parts(10, 0, 2), + tally: TallyOf::::from_parts(20, 0, 4), }), })); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::ResponseReceived { @@ -742,7 +841,7 @@ fn notify_vote_fail_works() { ReferendumInfoFor::::get(vtoken, poll_index), Some(ReferendumInfo::Ongoing(ReferendumStatus { submitted: None, - tally: TallyOf::::from_parts(10, 0, 2), + tally: TallyOf::::from_parts(20, 0, 4), })) ); assert_eq!(DelegatorVotes::::get(vtoken, poll_index).len(), 0); @@ -750,17 +849,17 @@ fn notify_vote_fail_works() { PendingDelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(10, 0, 2)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(20, 0, 4)); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::Voted { who: ALICE, vtoken, poll_index, - token_vote: aye(2, 5), - delegator_vote: aye(100, 0), + token_vote: aye(4, 5), + delegator_vote: aye(200, 0), })); assert_ok!(VtokenVoting::notify_vote(origin_response(), query_id, response.clone())); @@ -805,24 +904,24 @@ fn notify_remove_delegator_vote_success_works() { PendingDelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(10, 0, 2)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(20, 0, 4)); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::Voted { who: ALICE, vtoken, poll_index, - token_vote: aye(2, 5), - delegator_vote: aye(100, 0), + token_vote: aye(4, 5), + delegator_vote: aye(200, 0), })); assert_ok!(VtokenVoting::notify_vote(origin_response(), query_id, response.clone())); assert_eq!( DelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); @@ -880,24 +979,24 @@ fn notify_remove_delegator_vote_fail_works() { PendingDelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); - assert_eq!(tally(vtoken, poll_index), Tally::from_parts(10, 0, 2)); + assert_eq!(tally(vtoken, poll_index), Tally::from_parts(20, 0, 4)); System::assert_last_event(RuntimeEvent::VtokenVoting(Event::Voted { who: ALICE, vtoken, poll_index, - token_vote: aye(2, 5), - delegator_vote: aye(100, 0), + token_vote: aye(4, 5), + delegator_vote: aye(200, 0), })); assert_ok!(VtokenVoting::notify_vote(origin_response(), query_id, response_success())); assert_eq!( DelegatorVotes::::get(vtoken, poll_index), BoundedVec::<(DerivativeIndex, AccountVote), ConstU32<100>>::try_from(vec![( derivative_index, - aye(100, 0) + aye(200, 0) )]) .unwrap() ); diff --git a/pallets/vtoken-voting/src/vote.rs b/pallets/vtoken-voting/src/vote.rs index 2797fe136..a9a9b1b86 100644 --- a/pallets/vtoken-voting/src/vote.rs +++ b/pallets/vtoken-voting/src/vote.rs @@ -415,7 +415,7 @@ where pub fn locked_balance(&self) -> Balance { match self { Voting::Casting(Casting { votes, prior, .. }) => - votes.iter().map(|i| i.1.balance()).fold(prior.locked(), |a, i| a.max(i)), + votes.iter().map(|i| i.3).fold(prior.locked(), |a, i| a.max(i)), Voting::Delegating(Delegating { balance, prior, .. }) => *balance.max(&prior.locked()), } } diff --git a/pallets/xcm-interface/src/calls.rs b/pallets/xcm-interface/src/calls.rs index ffb540298..99e816841 100644 --- a/pallets/xcm-interface/src/calls.rs +++ b/pallets/xcm-interface/src/calls.rs @@ -19,7 +19,8 @@ use frame_support::sp_runtime::MultiSignature; use parity_scale_codec::{Decode, Encode}; use sp_runtime::RuntimeDebug; -use sp_std::vec::Vec; +use sp_std::{boxed::Box, vec::Vec}; +use xcm::{VersionedAssets, VersionedLocation}; use crate::ChainId; @@ -37,6 +38,23 @@ pub enum StakingCall { WithdrawUnbonded(u32), } +#[derive(Encode, Decode, RuntimeDebug, Clone)] +pub enum PolkadotXcm { + #[codec(index = 2)] + ReserveTransferAssets( + Box, + Box, + Box, + u32, + ), +} + +#[derive(Encode, Decode, RuntimeDebug, Clone)] +pub enum SystemCall { + #[codec(index = 7)] + RemarkWithEvent(Vec), +} + pub mod rococo { pub use crate::calls::*; diff --git a/pallets/xcm-interface/src/lib.rs b/pallets/xcm-interface/src/lib.rs index 2965f267e..e7ea013fc 100644 --- a/pallets/xcm-interface/src/lib.rs +++ b/pallets/xcm-interface/src/lib.rs @@ -63,7 +63,7 @@ pub mod pallet { use sp_runtime::{traits::Convert, DispatchError}; use sp_std::{convert::From, prelude::*, vec, vec::Vec}; use xcm::{ - v3::{prelude::*, ExecuteXcm, Parent}, + v4::{prelude::*, Asset, ExecuteXcm, Location}, DoubleEncoded, VersionedXcm, }; @@ -92,8 +92,8 @@ pub mod pallet { /// XCM executor. type XcmExecutor: ExecuteXcm<::RuntimeCall>; - /// Convert `T::AccountId` to `MultiLocation`. - type AccountIdToMultiLocation: Convert, MultiLocation>; + /// Convert `T::AccountId` to `Location`. + type AccountIdToLocation: Convert, Location>; /// Salp call encode type SalpHelper: SalpHelper< @@ -102,10 +102,10 @@ pub mod pallet { BalanceOf, >; - /// Convert MultiLocation to `T::CurrencyId`. + /// Convert Location to `T::CurrencyId`. type CurrencyIdConvert: CurrencyIdMapping< CurrencyIdOf, - MultiLocation, + xcm::v3::MultiLocation, AssetMetadata>, >; @@ -126,6 +126,8 @@ pub mod pallet { XcmSendFailed, OperationWeightAndFeeNotExist, FailToConvert, + UnweighableMessage, + LocalExecutionIncomplete, } #[pallet::event] @@ -219,13 +221,13 @@ pub mod pallet { TryInto::::try_into(amount).map_err(|_| Error::::FeeConvertFailed)?; // get currency_id from asset_id - let asset_location = MultiLocation::new( + let asset_location = Location::new( 1, - X3( + [ Parachain(parachains::Statemine::ID), PalletInstance(parachains::Statemine::PALLET_ID), GeneralIndex(asset_id.into()), - ), + ], ); let currency_id = T::CurrencyIdConvert::get_currency_id(asset_location) .ok_or(Error::::FailToConvert)?; @@ -233,7 +235,7 @@ pub mod pallet { // first, we need to withdraw the statemine asset from the user's account T::MultiCurrency::withdraw(currency_id, &who, amount)?; - let dst_location = T::AccountIdToMultiLocation::convert(dest.clone()); + let dst_location = T::AccountIdToLocation::convert(dest.clone()); let (dest_weight, xcm_fee) = Self::xcm_dest_weight_and_fee( T::RelaychainCurrencyId::get(), @@ -244,35 +246,30 @@ pub mod pallet { let xcm_fee_u128 = TryInto::::try_into(xcm_fee).map_err(|_| Error::::FeeConvertFailed)?; - let mut assets = MultiAssets::new(); - let statemine_asset = MultiAsset { - id: Concrete(MultiLocation::new( + let mut assets = Assets::new(); + let statemine_asset = Asset { + id: AssetId(Location::new( 0, - X2( + [ PalletInstance(parachains::Statemine::PALLET_ID), GeneralIndex(asset_id.into()), - ), + ], )), fun: Fungible(amount_u128), }; - let fee_asset = MultiAsset { - id: Concrete(MultiLocation::new(1, Junctions::Here)), - fun: Fungible(xcm_fee_u128), - }; + let fee_asset = + Asset { id: AssetId(Location::new(1, Here)), fun: Fungible(xcm_fee_u128) }; assets.push(statemine_asset.clone()); assets.push(fee_asset.clone()); let msg = Xcm(vec![ WithdrawAsset(assets), - BuyExecution { - fees: fee_asset, - weight_limit: cumulus_primitives_core::Limited(dest_weight), - }, + BuyExecution { fees: fee_asset, weight_limit: Limited(dest_weight) }, DepositAsset { assets: AllCounted(2).into(), beneficiary: dst_location }, ]); pallet_xcm::Pallet::::send_xcm( Here, - MultiLocation::new(1, X1(Parachain(parachains::Statemine::ID))), + Location::new(1, Parachain(parachains::Statemine::ID)), msg, ) .map_err(|_| Error::::XcmExecutionFailed)?; @@ -301,10 +298,10 @@ pub mod pallet { let confirm_contribute_call = T::SalpHelper::confirm_contribute_call(); // Generate query_id let query_id = pallet_xcm::Pallet::::new_notify_query( - MultiLocation::parent(), + Location::parent(), confirm_contribute_call, T::CallBackTimeOut::get(), - Here, + xcm::v4::Junctions::Here, ); // Bind query_id and contribution @@ -313,7 +310,11 @@ pub mod pallet { let (msg_id, msg) = Self::build_ump_transact(query_id, contribute_call, dest_weight, xcm_fee)?; - let result = pallet_xcm::Pallet::::send_xcm(Here, Parent, msg); + let result = pallet_xcm::Pallet::::send_xcm( + xcm::v4::Junctions::Here, + xcm::v4::Parent, + xcm::v4::Xcm::try_from(msg).unwrap(), + ); ensure!(result.is_ok(), Error::::XcmSendFailed); Ok(msg_id) } @@ -354,14 +355,11 @@ pub mod pallet { fee: BalanceOf, ) -> Result<(MessageId, Xcm<()>), Error> { let sovereign_account: AccountIdOf = T::ParachainSovereignAccount::get(); - let sovereign_location: MultiLocation = - T::AccountIdToMultiLocation::convert(sovereign_account); + let sovereign_location: Location = T::AccountIdToLocation::convert(sovereign_account); let fee_amount = TryInto::::try_into(fee).map_err(|_| Error::::FeeConvertFailed)?; - let asset: MultiAsset = MultiAsset { - id: Concrete(MultiLocation::here()), - fun: Fungibility::from(fee_amount), - }; + let asset: Asset = + Asset { id: AssetId(Location::here()), fun: Fungibility::from(fee_amount) }; let message = Xcm(vec![ WithdrawAsset(asset.clone().into()), BuyExecution { fees: asset, weight_limit: Unlimited }, @@ -371,9 +369,7 @@ pub mod pallet { call, }, ReportTransactStatus(QueryResponseInfo { - destination: MultiLocation::from(X1(Parachain(u32::from( - T::ParachainId::get(), - )))), + destination: Location::from([Parachain(u32::from(T::ParachainId::get()))]), query_id, max_weight: weight, }), diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index 7f65ca480..9e675a505 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -28,7 +28,7 @@ use sp_runtime::{ traits::{BlakeTwo256, IdentifyAccount, Verify}, FixedU128, MultiSignature, OpaqueExtrinsic, Permill, }; -use xcm::v3::prelude::*; +use xcm::v4::{prelude::*, Asset, Location}; use xcm_executor::traits::{AssetTransferError, TransferType, XcmAssetTransfers}; pub mod currency; @@ -254,8 +254,8 @@ impl Default for RedeemType { pub struct DoNothingRouter; impl SendXcm for DoNothingRouter { type Ticket = (); - fn validate(_dest: &mut Option, _msg: &mut Option>) -> SendResult<()> { - Ok(((), MultiAssets::new())) + fn validate(_dest: &mut Option, _msg: &mut Option>) -> SendResult<()> { + Ok(((), Assets::new())) } fn deliver(_: ()) -> Result { Ok([0; 32]) @@ -278,34 +278,15 @@ impl ExecuteXcm for DoNothingExecuteXcm { } fn execute( - _origin: impl Into, + _origin: impl Into, _pre: Self::Prepared, _hash: &mut XcmHash, _weight_credit: Weight, ) -> Outcome { - Outcome::Complete(Weight::default()) + Outcome::Complete { used: Weight::default() } } - fn execute_xcm( - _origin: impl Into, - _message: Xcm, - _hash: XcmHash, - _weight_limit: Weight, - ) -> Outcome { - Outcome::Complete(Weight::default()) - } - - fn execute_xcm_in_credit( - _origin: impl Into, - _message: Xcm, - _hash: XcmHash, - _weight_limit: Weight, - _weight_credit: Weight, - ) -> Outcome { - Outcome::Complete(Weight::default()) - } - - fn charge_fees(_location: impl Into, _fees: MultiAssets) -> XcmResult { + fn charge_fees(_location: impl Into, _fees: Assets) -> XcmResult { Ok(()) } } @@ -315,10 +296,7 @@ impl XcmAssetTransfers for DoNothingExecuteXcm { type IsTeleporter = (); type AssetTransactor = (); - fn determine_for( - _asset: &MultiAsset, - _dest: &MultiLocation, - ) -> Result { + fn determine_for(_asset: &Asset, _dest: &Location) -> Result { Ok(TransferType::DestinationReserve) } } diff --git a/primitives/src/traits.rs b/primitives/src/traits.rs index 222d35955..6279a91e9 100644 --- a/primitives/src/traits.rs +++ b/primitives/src/traits.rs @@ -168,10 +168,12 @@ pub trait CurrencyIdMapping { fn get_asset_metadata(asset_ids: AssetIds) -> Option; /// Returns the AssetMetadata associated with a given `CurrencyId`. fn get_currency_metadata(currency_id: CurrencyId) -> Option; - /// Returns the MultiLocation associated with a given CurrencyId. - fn get_multi_location(currency_id: CurrencyId) -> Option; - /// Returns the CurrencyId associated with a given MultiLocation. - fn get_currency_id(multi_location: MultiLocation) -> Option; + /// Returns the Location associated with a given CurrencyId. + fn get_location(currency_id: CurrencyId) -> Option; + /// Returns the CurrencyId associated with a given Location. + fn get_currency_id(multi_location: xcm::v4::Location) -> Option; + /// Returns all currencies in currencyMetadata. + fn get_all_currency() -> Vec; } pub trait CurrencyIdConversion { diff --git a/runtime/bifrost-kusama/Cargo.toml b/runtime/bifrost-kusama/Cargo.toml index e55515ed4..3df0cc57f 100644 --- a/runtime/bifrost-kusama/Cargo.toml +++ b/runtime/bifrost-kusama/Cargo.toml @@ -72,7 +72,6 @@ sp-genesis-builder = { workspace = true } # Cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } @@ -144,6 +143,7 @@ lend-market-rpc-runtime-api = { workspace = true } pallet-prices = { workspace = true } leverage-staking = { workspace = true } bifrost-channel-commission = { workspace = true } +bifrost-vtoken-minting-rpc-runtime-api = { workspace = true } [build-dependencies] substrate-wasm-builder = { workspace = true, optional = true } @@ -205,7 +205,6 @@ std = [ "sp-version/std", "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", @@ -263,6 +262,7 @@ std = [ "bifrost-vtoken-voting/std", "lend-market/std", "lend-market-rpc-runtime-api/std", + "bifrost-vtoken-minting-rpc-runtime-api/std", "pallet-prices/std", "leverage-staking/std", "bifrost-stable-asset/std", @@ -346,7 +346,6 @@ try-runtime = [ "cumulus-pallet-xcmp-queue/try-runtime", "pallet-xcm/try-runtime", "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", "pallet-utility/try-runtime", "pallet-scheduler/try-runtime", "pallet-proxy/try-runtime", diff --git a/runtime/bifrost-kusama/src/governance/fellowship.rs b/runtime/bifrost-kusama/src/governance/fellowship.rs index 4e44b954b..bd9844ff7 100644 --- a/runtime/bifrost-kusama/src/governance/fellowship.rs +++ b/runtime/bifrost-kusama/src/governance/fellowship.rs @@ -355,4 +355,8 @@ impl pallet_ranked_collective::Config for Runtime type Polls = FellowshipReferenda; type MinRankOfClass = sp_runtime::traits::Identity; type VoteWeight = pallet_ranked_collective::Geometric; + type ExchangeOrigin = EitherOfDiverse; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetup = (); + type MemberSwappedHandler = (); } diff --git a/runtime/bifrost-kusama/src/lib.rs b/runtime/bifrost-kusama/src/lib.rs index 4ae24ad20..a93e1549a 100644 --- a/runtime/bifrost-kusama/src/lib.rs +++ b/runtime/bifrost-kusama/src/lib.rs @@ -49,7 +49,7 @@ pub use pallet_balances::Call as BalancesCall; pub use pallet_timestamp::Call as TimestampCall; use sp_api::impl_runtime_apis; use sp_arithmetic::Percent; -use sp_core::{ConstBool, OpaqueMetadata}; +use sp_core::{ConstBool, OpaqueMetadata, U256}; use sp_runtime::{ create_runtime_str, generic, impl_opaque_keys, traits::{ @@ -98,9 +98,7 @@ use frame_support::{ OnUnbalanced, }, }; -use frame_system::{ - pallet_prelude::BlockNumberFor, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, -}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use hex_literal::hex; use orml_oracle::{DataFeeder, DataProvider, DataProviderExtended}; use pallet_identity::legacy::IdentityInfo; @@ -125,7 +123,7 @@ use governance::{ pub mod xcm_config; use pallet_xcm::{EnsureResponse, QueryStatus}; use sp_runtime::traits::{IdentityLookup, Verify}; -use xcm::v3::prelude::*; +use xcm::{v3::MultiLocation, v4::prelude::*}; pub use xcm_config::{ parachains, AccountId32Aliases, BifrostCurrencyIdConvert, BifrostTreasuryAccount, ExistentialDeposits, MultiCurrency, SelfParaChainId, Sibling, SiblingParachainConvertsVia, @@ -145,7 +143,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost"), impl_name: create_runtime_str!("bifrost"), authoring_version: 1, - spec_version: 10000, + spec_version: 11000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -662,7 +660,6 @@ impl pallet_balances::Config for Runtime { type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); - type MaxHolds = ConstU32<1>; type MaxFreezes = ConstU32<0>; type WeightInfo = pallet_balances::weights::SubstrateWeight; type RuntimeHoldReason = RuntimeHoldReason; @@ -1160,14 +1157,14 @@ parameter_types! { pub BifrostParachainAccountId20: [u8; 20] = cumulus_primitives_core::ParaId::from(ParachainInfo::get()).into_account_truncating(); } -pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLocation { +pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> xcm::v3::Location { match currency_id { // AccountKey20 format of Bifrost sibling para account - CurrencyId::Token(TokenSymbol::MOVR) => MultiLocation::new( + CurrencyId::Token(TokenSymbol::MOVR) => xcm::v3::Location::new( 1, - X2( - Parachain(parachains::moonriver::ID.into()), - AccountKey20 { + xcm::v3::Junctions::X2( + xcm::v3::Junction::Parachain(parachains::moonriver::ID.into()), + xcm::v3::Junction::AccountKey20 { network: None, key: Slp::derivative_account_id_20( polkadot_parachain_primitives::primitives::Sibling::from( @@ -1181,9 +1178,9 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca ), ), // Only relay chain use the Bifrost para account with "para" - CurrencyId::Token(TokenSymbol::KSM) => MultiLocation::new( + CurrencyId::Token(TokenSymbol::KSM) => xcm::v3::Location::new( 1, - X1(AccountId32 { + xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( ParachainInfo::get().into_account_truncating(), @@ -1193,9 +1190,9 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca }), ), // Bifrost Kusama Native token - CurrencyId::Native(TokenSymbol::BNC) => MultiLocation::new( + CurrencyId::Native(TokenSymbol::BNC) => xcm::v3::Location::new( 0, - X1(AccountId32 { + xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( polkadot_parachain_primitives::primitives::Sibling::from(ParachainInfo::get()) @@ -1212,11 +1209,11 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca BifrostCurrencyIdConvert::::convert(currency_id) { if let Some(Parachain(para_id)) = location.interior().first() { - MultiLocation::new( + xcm::v3::Location::new( 1, - X2( - Parachain(*para_id), - AccountId32 { + xcm::v3::Junctions::X2( + xcm::v3::Junction::Parachain(*para_id), + xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( polkadot_parachain_primitives::primitives::Sibling::from( @@ -1230,10 +1227,10 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca ), ) } else { - MultiLocation::default() + xcm::v3::Location::default() } } else { - MultiLocation::default() + xcm::v3::Location::default() } }, } @@ -1334,7 +1331,7 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(query_id: QueryId) -> bool { @@ -1346,16 +1343,16 @@ impl QueryResponseManager } fn create_query_record( - responder: &MultiLocation, + responder: Location, call_back: Option, timeout: BlockNumber, ) -> u64 { // for xcm v3 version see the following // PolkadotXcm::new_query(responder, timeout, Here) if let Some(call_back) = call_back { - PolkadotXcm::new_notify_query(*responder, call_back, timeout, Here) + PolkadotXcm::new_notify_query(responder.clone(), call_back, timeout, Here) } else { - PolkadotXcm::new_query(*responder, timeout, Here) + PolkadotXcm::new_query(responder, timeout, Here) } } @@ -1370,13 +1367,6 @@ impl QueryResponseManager } } -pub struct OnRefund; -impl bifrost_slp::OnRefund for OnRefund { - fn on_refund(token_id: CurrencyId, to: AccountId, token_amount: Balance) -> u64 { - SystemStaking::on_refund(token_id, to, token_amount).ref_time() - } -} - impl bifrost_slp::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -1385,13 +1375,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EitherOfDiverse; type WeightInfo = weights::bifrost_slp::BifrostWeight; type VtokenMinting = VtokenMinting; - type BifrostSlpx = Slpx; type AccountConverter = SubAccountIndexMultiLocationConvertor; type ParachainId = SelfParaChainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = OnRefund; type ParachainStaking = ParachainStaking; type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -1648,6 +1636,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = (); + type AssetIdMaps = AssetIdMaps; } impl bifrost_slpx::Config for Runtime { @@ -1945,7 +1934,6 @@ construct_runtime! { XcmpQueue: cumulus_pallet_xcmp_queue = 40, PolkadotXcm: pallet_xcm = 41, CumulusXcm: cumulus_pallet_xcm = 42, - DmpQueue: cumulus_pallet_dmp_queue = 43, MessageQueue: pallet_message_queue = 44, // utilities @@ -2041,17 +2029,16 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic; +parameter_types! { + pub const DmpQueuePalletName: &'static str = "DmpQueue"; +} + /// All migrations that will run on the next runtime upgrade. /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. pub type Migrations = migrations::Unreleased; -parameter_types! { - pub const TipsPalletName: &'static str = "Tips"; - pub const BountiesPalletName: &'static str = "Bounties"; -} - /// The runtime migrations per release. pub mod migrations { #![allow(unused_imports)] @@ -2059,36 +2046,15 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - // Unlock & unreserve funds - pallet_tips::migrations::unreserve_deposits::UnreserveDeposits, - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, - migration::slpx_migrates_whitelist::UpdateWhitelist, + bifrost_slpx::migration::v1::MigrateToV1, frame_support::migrations::RemovePallet< - TipsPalletName, + DmpQueuePalletName, ::DbWeight, >, - frame_support::migrations::RemovePallet< - BountiesPalletName, - ::DbWeight, - >, - pallet_identity::migration::versioned::V0ToV1, + pallet_xcm::migration::MigrateToLatestXcmVersion, ); } -// Special Config for tips pallets, allowing us to run migrations for them without -// implementing their configs on [`Runtime`]. -pub struct UnlockConfigForTips; -impl pallet_tips::migrations::unreserve_deposits::UnlockConfig<()> for UnlockConfigForTips { - type Currency = Balances; - type Hash = Hash; - type DataDepositPerByte = DataDepositPerByte; - type TipReportDepositBase = TipReportDepositBase; - type AccountId = AccountId; - type BlockNumber = BlockNumberFor; - type DbWeight = ::DbWeight; - type PalletName = TipsPalletName; -} - /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -2434,6 +2400,12 @@ impl_runtime_apis! { } } + impl bifrost_vtoken_minting_rpc_runtime_api::VtokenMintingRuntimeApi for Runtime { + fn get_exchange_rate(token_id: Option) -> Vec<(CurrencyId, U256)> { + VtokenMinting::get_exchange_rate(token_id).unwrap_or(Vec::new()) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/runtime/bifrost-kusama/src/weights/bifrost_asset_registry.rs b/runtime/bifrost-kusama/src/weights/bifrost_asset_registry.rs index 2ebcdcc3a..927135cec 100644 --- a/runtime/bifrost-kusama/src/weights/bifrost_asset_registry.rs +++ b/runtime/bifrost-kusama/src/weights/bifrost_asset_registry.rs @@ -138,7 +138,7 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig // Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) // Storage: AssetRegistry CurrencyIdToWeights (r:0 w:1) // Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) - fn register_multilocation() -> Weight { + fn register_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -155,7 +155,7 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig // Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) // Storage: AssetRegistry CurrencyIdToLocations (r:0 w:1) // Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) - fn force_set_multilocation() -> Weight { + fn force_set_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -164,4 +164,15 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } + // Storage: `AssetRegistry::CurrencyMetadatas` (r:1 w:1) + // Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn update_currency_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `409` + // Estimated: `3874` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 3874) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs b/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs index e9c0cddc2..5cc4a3e80 100644 --- a/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs +++ b/runtime/bifrost-kusama/src/weights/bifrost_slpx.rs @@ -127,6 +127,19 @@ impl bifrost_slpx::WeightInfo for BifrostWeight { .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(8)) } + // Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + // Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + // Storage: `Slpx::OrderQueue` (r:1 w:1) + // Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 204487) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Slpx WhitelistAccountId (r:1 w:0) // Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) diff --git a/runtime/bifrost-kusama/src/weights/pallet_xcm.rs b/runtime/bifrost-kusama/src/weights/pallet_xcm.rs index 3f413862f..5fe4c382a 100644 --- a/runtime/bifrost-kusama/src/weights/pallet_xcm.rs +++ b/runtime/bifrost-kusama/src/weights/pallet_xcm.rs @@ -64,35 +64,67 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn send() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3540` - // Minimum execution time: 24_079_000 picoseconds. - Weight::from_parts(24_695_000, 0) - .saturating_add(Weight::from_parts(0, 3540)) + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 21_170_000 picoseconds. + Weight::from_parts(21_757_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0) + /// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`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: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// 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 teleport_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `1489` - // Minimum execution time: 18_654_000 picoseconds. - Weight::from_parts(19_331_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `197` + // Estimated: `3662` + // Minimum execution time: 94_487_000 picoseconds. + Weight::from_parts(96_276_000, 0) + .saturating_add(Weight::from_parts(0, 3662)) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `XcmpQueue::DeliveryFeeFactor` (`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::RelevantMessagingState` (r:1 w:0) + /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) + /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: None, mode: `Measured`) fn reserve_transfer_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `1489` - // Minimum execution time: 13_972_000 picoseconds. - Weight::from_parts(14_410_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `419` + // Estimated: `6196` + // Minimum execution time: 119_502_000 picoseconds. + Weight::from_parts(121_486_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -116,10 +148,10 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn transfer_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `496` + // Measured: `600` // Estimated: `6208` - // Minimum execution time: 146_932_000 picoseconds. - Weight::from_parts(153_200_000, 0) + // Minimum execution time: 143_889_000 picoseconds. + Weight::from_parts(147_227_000, 0) .saturating_add(Weight::from_parts(0, 6208)) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(7)) @@ -140,8 +172,8 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_624_000 picoseconds. - Weight::from_parts(7_005_000, 0) + // Minimum execution time: 6_141_000 picoseconds. + Weight::from_parts(6_320_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -151,8 +183,8 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_213_000 picoseconds. - Weight::from_parts(2_374_000, 0) + // Minimum execution time: 2_013_000 picoseconds. + Weight::from_parts(2_144_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -176,11 +208,11 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn force_subscribe_version_notify() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3540` - // Minimum execution time: 28_117_000 picoseconds. - Weight::from_parts(29_002_000, 0) - .saturating_add(Weight::from_parts(0, 3540)) + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 26_192_000 picoseconds. + Weight::from_parts(26_891_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -202,11 +234,11 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn force_unsubscribe_version_notify() -> Weight { // Proof Size summary in bytes: - // Measured: `292` - // Estimated: `3757` - // Minimum execution time: 30_111_000 picoseconds. - Weight::from_parts(30_890_000, 0) - .saturating_add(Weight::from_parts(0, 3757)) + // Measured: `363` + // Estimated: `3828` + // Minimum execution time: 28_794_000 picoseconds. + Weight::from_parts(29_672_000, 0) + .saturating_add(Weight::from_parts(0, 3828)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -216,45 +248,45 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_126_000 picoseconds. - Weight::from_parts(2_293_000, 0) + // Minimum execution time: 1_890_000 picoseconds. + Weight::from_parts(2_068_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `PolkadotXcm::SupportedVersion` (r:4 w:2) + /// Storage: `PolkadotXcm::SupportedVersion` (r:5 w:2) /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) fn migrate_supported_version() -> Weight { // Proof Size summary in bytes: - // Measured: `129` - // Estimated: `11019` - // Minimum execution time: 17_037_000 picoseconds. - Weight::from_parts(17_778_000, 0) - .saturating_add(Weight::from_parts(0, 11019)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `159` + // Estimated: `13524` + // Minimum execution time: 18_690_000 picoseconds. + Weight::from_parts(19_397_000, 0) + .saturating_add(Weight::from_parts(0, 13524)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifiers` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifiers` (r:5 w:2) /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) fn migrate_version_notifiers() -> Weight { // Proof Size summary in bytes: - // Measured: `133` - // Estimated: `11023` - // Minimum execution time: 16_863_000 picoseconds. - Weight::from_parts(17_392_000, 0) - .saturating_add(Weight::from_parts(0, 11023)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `163` + // Estimated: `13528` + // Minimum execution time: 18_719_000 picoseconds. + Weight::from_parts(19_241_000, 0) + .saturating_add(Weight::from_parts(0, 13528)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:0) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:6 w:0) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) fn already_notified_target() -> Weight { // Proof Size summary in bytes: - // Measured: `140` - // Estimated: `13505` - // Minimum execution time: 18_745_000 picoseconds. - Weight::from_parts(19_010_000, 0) - .saturating_add(Weight::from_parts(0, 13505)) - .saturating_add(T::DbWeight::get().reads(5)) + // Measured: `173` + // Estimated: `16013` + // Minimum execution time: 20_555_000 picoseconds. + Weight::from_parts(21_068_000, 0) + .saturating_add(Weight::from_parts(0, 16013)) + .saturating_add(T::DbWeight::get().reads(6)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:2 w:1) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -272,38 +304,38 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn notify_current_targets() -> Weight { // Proof Size summary in bytes: - // Measured: `142` - // Estimated: `6082` - // Minimum execution time: 26_717_000 picoseconds. - Weight::from_parts(27_144_000, 0) - .saturating_add(Weight::from_parts(0, 6082)) + // Measured: `212` + // Estimated: `6152` + // Minimum execution time: 26_014_000 picoseconds. + Weight::from_parts(26_786_000, 0) + .saturating_add(Weight::from_parts(0, 6152)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(3)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:3 w:0) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 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: 9_128_000 picoseconds. - Weight::from_parts(9_445_000, 0) - .saturating_add(Weight::from_parts(0, 8587)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `206` + // Estimated: `11096` + // Minimum execution time: 11_678_000 picoseconds. + Weight::from_parts(12_132_000, 0) + .saturating_add(Weight::from_parts(0, 11096)) + .saturating_add(T::DbWeight::get().reads(4)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 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: `140` - // Estimated: `11030` - // Minimum execution time: 17_316_000 picoseconds. - Weight::from_parts(17_802_000, 0) - .saturating_add(Weight::from_parts(0, 11030)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `170` + // Estimated: `13535` + // Minimum execution time: 19_050_000 picoseconds. + Weight::from_parts(19_546_000, 0) + .saturating_add(Weight::from_parts(0, 13535)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:2) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0) /// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -319,37 +351,49 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// 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: `146` - // Estimated: `11036` - // Minimum execution time: 33_426_000 picoseconds. - Weight::from_parts(33_986_000, 0) - .saturating_add(Weight::from_parts(0, 11036)) - .saturating_add(T::DbWeight::get().reads(10)) + // Measured: `212` + // Estimated: `13577` + // Minimum execution time: 34_690_000 picoseconds. + Weight::from_parts(35_397_000, 0) + .saturating_add(Weight::from_parts(0, 13577)) + .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(4)) } - /// Storage: `XcmPallet::QueryCounter` (r:1 w:1) - /// Proof: `XcmPallet::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::Queries` (r:0 w:1) - /// Proof: `XcmPallet::Queries` (`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::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: `0` - // Estimated: `1485` - // Minimum execution time: 2_947_000 picoseconds. - Weight::from_parts(3_117_000, 0) - .saturating_add(Weight::from_parts(0, 1485)) + // Measured: `103` + // Estimated: `1588` + // Minimum execution time: 4_663_000 picoseconds. + Weight::from_parts(4_812_000, 0) + .saturating_add(Weight::from_parts(0, 1588)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `XcmPallet::Queries` (r:1 w:1) - /// Proof: `XcmPallet::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// 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: `7576` - // Estimated: `11041` - // Minimum execution time: 24_595_000 picoseconds. - Weight::from_parts(24_907_000, 0) - .saturating_add(Weight::from_parts(0, 11041)) + // Measured: `7740` + // Estimated: `11205` + // Minimum execution time: 25_044_000 picoseconds. + Weight::from_parts(25_416_000, 0) + .saturating_add(Weight::from_parts(0, 11205)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `PolkadotXcm::AssetTraps` (r:1 w:1) + /// Proof: `PolkadotXcm::AssetTraps` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn claim_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `160` + // Estimated: `3625` + // Minimum execution time: 37_380_000 picoseconds. + Weight::from_parts(37_761_000, 0) + .saturating_add(Weight::from_parts(0, 3625)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } diff --git a/runtime/bifrost-kusama/src/xcm_config.rs b/runtime/bifrost-kusama/src/xcm_config.rs index 357512339..edecccb34 100644 --- a/runtime/bifrost-kusama/src/xcm_config.rs +++ b/runtime/bifrost-kusama/src/xcm_config.rs @@ -55,7 +55,7 @@ use pallet_xcm::XcmPassthrough; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery; use sp_core::bounded::BoundedVec; -use xcm::v3::prelude::*; +use xcm::v4::{prelude::*, Location}; use xcm_builder::{FrameTransactionalProcessor, TrailingSetTopicAsId}; use xcm_executor::traits::Properties; @@ -67,12 +67,12 @@ pub struct BifrostAssetMatcher( impl MatchesFungible for BifrostAssetMatcher where - CurrencyIdConvert: Convert>, + CurrencyIdConvert: Convert>, Amount: TryFrom, { - fn matches_fungible(a: &MultiAsset) -> Option { - if let (Fungible(ref amount), Concrete(ref location)) = (&a.fun, &a.id) { - if CurrencyIdConvert::convert(*location).is_some() { + fn matches_fungible(a: &Asset) -> Option { + if let (Fungible(ref amount), AssetId(ref location)) = (&a.fun, &a.id) { + if CurrencyIdConvert::convert(location.clone()).is_some() { return CheckedConversion::checked_from(*amount); } } @@ -83,11 +83,11 @@ where /// A `FilterAssetLocation` implementation. Filters multi native assets whose /// reserve is same with `origin`. pub struct MultiNativeAsset(PhantomData); -impl ContainsPair for MultiNativeAsset +impl ContainsPair for MultiNativeAsset where ReserveProvider: Reserve, { - fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { + fn contains(asset: &Asset, origin: &Location) -> bool { if let Some(ref reserve) = ReserveProvider::reserve(asset) { if reserve == origin { return true; @@ -97,13 +97,13 @@ where } } -fn native_currency_location(id: CurrencyId) -> MultiLocation { - MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(id.encode()).unwrap()))) +fn native_currency_location(id: CurrencyId) -> Location { + Location::new(0, [Junction::from(BoundedVec::try_from(id.encode()).unwrap())]) } -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(asset: MultiAsset) -> Option { - if let MultiAsset { id: Concrete(id), fun: Fungible(_) } = asset { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(asset: Asset) -> Option { + if let Asset { id: AssetId(id), fun: xcm::v4::Fungibility::Fungible(_) } = asset { Self::convert(id) } else { None @@ -111,131 +111,125 @@ impl> Convert> for BifrostCurrency } } -pub struct BifrostAccountIdToMultiLocation; -impl Convert for BifrostAccountIdToMultiLocation { - fn convert(account: AccountId) -> MultiLocation { - X1(AccountId32 { network: None, id: account.into() }).into() +pub struct BifrostAccountIdToLocation; +impl Convert for BifrostAccountIdToLocation { + fn convert(account: AccountId) -> Location { + [AccountId32 { network: None, id: account.into() }].into() } } pub struct BifrostCurrencyIdConvert(sp_std::marker::PhantomData); -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(id: CurrencyId) -> Option { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(id: CurrencyId) -> Option { use CurrencyId::*; use TokenSymbol::*; - if let Some(id) = AssetIdMaps::::get_multi_location(id) { + if let Some(id) = AssetIdMaps::::get_location(id) { return Some(id); } match id { - Token(KSM) => Some(MultiLocation::parent()), + Token(KSM) => Some(Location::parent()), Native(ASG) | Native(BNC) | VSToken(KSM) | Token(ZLK) => Some(native_currency_location(id)), // Karura currencyId types - Token(KAR) => Some(MultiLocation::new( + Token(KAR) => Some(Location::new( 1, - X2( + [ Parachain(parachains::karura::ID), Junction::from( BoundedVec::try_from(parachains::karura::KAR_KEY.to_vec()).unwrap(), ), - ), + ], )), - Stable(KUSD) => Some(MultiLocation::new( + Stable(KUSD) => Some(Location::new( 1, - X2( + [ Parachain(parachains::karura::ID), Junction::from( BoundedVec::try_from(parachains::karura::KUSD_KEY.to_vec()).unwrap(), ), - ), + ], )), - Token(RMRK) => Some(MultiLocation::new( + Token(RMRK) => Some(Location::new( 1, - X3( + [ Parachain(parachains::Statemine::ID), PalletInstance(parachains::Statemine::PALLET_ID), GeneralIndex(parachains::Statemine::RMRK_ID as u128), - ), + ], )), // Phala Native token - Token(PHA) => Some(MultiLocation::new(1, X1(Parachain(parachains::phala::ID)))), + Token(PHA) => Some(Location::new(1, [Parachain(parachains::phala::ID)])), // Moonriver Native token - Token(MOVR) => Some(MultiLocation::new( + Token(MOVR) => Some(Location::new( 1, - X2( + [ Parachain(parachains::moonriver::ID), PalletInstance(parachains::moonriver::PALLET_ID.into()), - ), + ], )), _ => None, } } } -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(location: MultiLocation) -> Option { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(location: Location) -> Option { use CurrencyId::*; use TokenSymbol::*; - if location == MultiLocation::parent() { + if location == Location::parent() { return Some(Token(KSM)); } - if let Some(currency_id) = AssetIdMaps::::get_currency_id(location) { + if let Some(currency_id) = AssetIdMaps::::get_currency_id(location.clone()) { return Some(currency_id); } - match location { - MultiLocation { parents: 1, interior } => match interior { - X2(Parachain(id), GeneralKey { data, length }) if id == parachains::karura::ID => - if data[..length as usize] == parachains::karura::KAR_KEY.to_vec() { - Some(Token(KAR)) - } else if data[..length as usize] == parachains::karura::KUSD_KEY.to_vec() { - Some(Stable(KUSD)) - } else { - None - }, - X2(Parachain(id), GeneralIndex(key)) if id == parachains::Statemine::ID => { - if key == parachains::Statemine::RMRK_ID as u128 { - Some(Token(RMRK)) - } else { - None - } - }, - X3(Parachain(id), PalletInstance(index), GeneralIndex(key)) - if (id == parachains::Statemine::ID && - index == parachains::Statemine::PALLET_ID) => - { - if key == parachains::Statemine::RMRK_ID as u128 { - Some(Token(RMRK)) - } else { - None - } + match location.unpack() { + (1, [Parachain(id), GeneralKey { data, length }]) if *id == parachains::karura::ID => + if data[..*length as usize] == parachains::karura::KAR_KEY.to_vec() { + Some(Token(KAR)) + } else if data[..*length as usize] == parachains::karura::KUSD_KEY.to_vec() { + Some(Stable(KUSD)) + } else { + None }, - X1(Parachain(id)) if id == parachains::phala::ID => Some(Token(PHA)), - X2(Parachain(id), PalletInstance(index)) - if ((id == parachains::moonriver::ID) && - (index == parachains::moonriver::PALLET_ID)) => - Some(Token(MOVR)), - _ => None, + (1, [Parachain(id), GeneralIndex(key)]) if *id == parachains::Statemine::ID => { + if *key == parachains::Statemine::RMRK_ID as u128 { + Some(Token(RMRK)) + } else { + None + } }, - MultiLocation { parents: 0, interior } => match interior { - X1(GeneralKey { data, length }) => { - // decode the general key - let key = &data[..length as usize]; - if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { - match currency_id { - Native(ASG) | Native(BNC) | VToken(KSM) | VSToken(KSM) | Token(ZLK) => - Some(currency_id), - _ => None, - } - } else { - None + (1, [Parachain(id), PalletInstance(index), GeneralIndex(key)]) + if (*id == parachains::Statemine::ID && + *index == parachains::Statemine::PALLET_ID) => + { + if *key == parachains::Statemine::RMRK_ID as u128 { + Some(Token(RMRK)) + } else { + None + } + }, + (1, [Parachain(id)]) if *id == parachains::phala::ID => Some(Token(PHA)), + (1, [Parachain(id), PalletInstance(index)]) + if (*id == parachains::moonriver::ID) && + (*index == parachains::moonriver::PALLET_ID) => + Some(Token(MOVR)), + (0, [GeneralKey { data, length }]) => { + // decode the general key + let key = &data[..*length as usize]; + if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { + match currency_id { + Native(ASG) | Native(BNC) | VToken(KSM) | VSToken(KSM) | Token(ZLK) => + Some(currency_id), + _ => None, } - }, - _ => None, + } else { + None + } }, _ => None, } @@ -243,14 +237,14 @@ impl> Convert> for BifrostCurre } parameter_types! { - pub const KsmLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Kusama; + pub const KsmLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = Kusama; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub SelfParaChainId: CumulusParaId = ParachainInfo::parachain_id(); - pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); } -/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// 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 RuntimeOrigin. pub type LocationToAccountId = ( @@ -294,20 +288,13 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -match_types! { - pub type ParentOrParentsExecutivePlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } - }; -} - /// Barrier allowing a top level paid message with DescendOrigin instruction pub const DEFAULT_PROOF_SIZE: u64 = 64 * 1024; pub const DEFAULT_REF_TIMR: u64 = 10_000_000_000; pub struct AllowTopLevelPaidExecutionDescendOriginFirst(PhantomData); -impl> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst { +impl> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst { fn should_execute( - origin: &MultiLocation, + origin: &Location, message: &mut [Instruction], max_weight: Weight, _weight_credit: &mut Properties, @@ -383,45 +370,44 @@ pub type BifrostAssetTransactor = MultiCurrencyAdapter< >; parameter_types! { - pub KsmPerSecond: (AssetId, u128, u128) = (MultiLocation::parent().into(), ksm_per_second::(),0); + pub KsmPerSecond: (AssetId, u128, u128) = (Location::parent().into(), ksm_per_second::(),0); pub VksmPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(CurrencyId::VToken(TokenSymbol::KSM).encode()).unwrap())), + [Junction::from(BoundedVec::try_from(CurrencyId::VToken(TokenSymbol::KSM).encode()).unwrap())], ).into(), ksm_per_second::(), 0 ); pub VsksmPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(CurrencyId::VSToken(TokenSymbol::KSM).encode()).unwrap())) - + [Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(CurrencyId::VSToken(TokenSymbol::KSM).encode()).unwrap())] ).into(), ksm_per_second::(), 0 ); pub VsksmNewPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(CurrencyId::VSToken(TokenSymbol::KSM).encode()).unwrap())) + [Junction::from(BoundedVec::try_from(CurrencyId::VSToken(TokenSymbol::KSM).encode()).unwrap())] ).into(), ksm_per_second::(), 0 ); pub BncPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())) + [Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())] ).into(), // BNC:KSM = 80:1 ksm_per_second::() * 80, 0 ); pub BncNewPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())) + [Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())] ).into(), // BNC:KSM = 80:1 ksm_per_second::() * 80, @@ -429,9 +415,9 @@ parameter_types! { ); pub ZlkPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())) + [Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())] ).into(), // ZLK:KSM = 150:1 //ZLK has a decimal of 18, while KSM is 12. @@ -439,9 +425,9 @@ parameter_types! { 0 ); pub ZlkNewPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())) + [Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())] ).into(), // ZLK:KSM = 150:1 //ZLK has a decimal of 18, while KSM is 12. @@ -449,54 +435,54 @@ parameter_types! { 0 ); pub KarPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(parachains::karura::ID), Junction::from(BoundedVec::try_from(parachains::karura::KAR_KEY.to_vec()).unwrap())) + [Parachain(parachains::karura::ID), Junction::from(BoundedVec::try_from(parachains::karura::KAR_KEY.to_vec()).unwrap())] ).into(), // KAR:KSM = 100:1 ksm_per_second::() * 100, 0 ); pub KusdPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(parachains::karura::ID), Junction::from(BoundedVec::try_from(parachains::karura::KUSD_KEY.to_vec()).unwrap())) + [Parachain(parachains::karura::ID), Junction::from(BoundedVec::try_from(parachains::karura::KUSD_KEY.to_vec()).unwrap())] ).into(), // kUSD:KSM = 400:1 ksm_per_second::() * 400, 0 ); pub PhaPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X1(Parachain(parachains::phala::ID)), + [Parachain(parachains::phala::ID)], ).into(), // PHA:KSM = 400:1 ksm_per_second::() * 400, 0 ); pub RmrkPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(parachains::Statemine::ID), GeneralIndex(parachains::Statemine::RMRK_ID.into())) + [Parachain(parachains::Statemine::ID), GeneralIndex(parachains::Statemine::RMRK_ID.into())] ).into(), // rmrk:KSM = 10:1 ksm_per_second::() * 10 / 100, //rmrk currency decimal as 10 0 ); pub RmrkNewPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X3(Parachain(parachains::Statemine::ID), PalletInstance(parachains::Statemine::PALLET_ID),GeneralIndex(parachains::Statemine::RMRK_ID.into())) + [Parachain(parachains::Statemine::ID), PalletInstance(parachains::Statemine::PALLET_ID),GeneralIndex(parachains::Statemine::RMRK_ID.into())] ).into(), // rmrk:KSM = 10:1 ksm_per_second::() * 10 / 100, //rmrk currency decimal as 10 0 ); pub MovrPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(parachains::moonriver::ID), PalletInstance(parachains::moonriver::PALLET_ID.into())) + [Parachain(parachains::moonriver::ID), PalletInstance(parachains::moonriver::PALLET_ID.into())] ).into(), // MOVR:KSM = 2.67:1 ksm_per_second::() * 267 * 10_000, //movr currency decimal as 18 @@ -507,8 +493,10 @@ parameter_types! { pub struct ToTreasury; impl TakeRevenue for ToTreasury { - fn take_revenue(revenue: MultiAsset) { - if let MultiAsset { id: Concrete(location), fun: Fungible(amount) } = revenue { + fn take_revenue(revenue: Asset) { + if let Asset { id: AssetId(location), fun: xcm::v4::Fungibility::Fungible(amount) } = + revenue + { if let Some(currency_id) = BifrostCurrencyIdConvert::::convert(location) { @@ -641,28 +629,6 @@ impl Contains for SafeCallFilter { } } -/// Matches foreign assets from a given origin. -/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1. -pub struct IsForeignNativeAssetFrom(PhantomData); -impl ContainsPair for IsForeignNativeAssetFrom -where - Origin: Get, -{ - fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { - let loc = Origin::get(); - &loc == origin && - matches!( - asset, - MultiAsset { id: Concrete(MultiLocation { parents: 2, .. }), fun: Fungible(_) }, - ) - } -} - -parameter_types! { - /// Location of Asset Hub - pub AssetHubLocation: MultiLocation = (Parent, Parachain(1000)).into(); -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type AssetClaims = PolkadotXcm; @@ -670,8 +636,7 @@ impl xcm_executor::Config for XcmConfig { type AssetTrap = BifrostDropAssets; type Barrier = Barrier; type RuntimeCall = RuntimeCall; - type IsReserve = - (IsForeignNativeAssetFrom, MultiNativeAsset); + type IsReserve = MultiNativeAsset; type IsTeleporter = (); type UniversalLocation = UniversalLocation; type OriginConverter = XcmOriginToTransactDispatchOrigin; @@ -707,7 +672,7 @@ pub type XcmRouter = ( #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { @@ -763,12 +728,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type PriceForSiblingDelivery = NoPriceForMessageDelivery; } -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; - type DmpSink = frame_support::traits::EnqueueWithOrigin; -} - parameter_types! { pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; } @@ -908,14 +867,14 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfLocation: Location = Location::new(1, [Parachain(ParachainInfo::get().into())]); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } @@ -925,7 +884,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = BifrostCurrencyIdConvert; - type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type AccountIdToLocation = BifrostAccountIdToLocation; type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; #[cfg(feature = "runtime-benchmarks")] @@ -936,8 +895,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } impl orml_unknown_tokens::Config for Runtime { @@ -965,7 +926,7 @@ impl bifrost_xcm_interface::Config for Runtime { type XcmExecutor = bifrost_primitives::DoNothingExecuteXcm; #[cfg(not(feature = "runtime-benchmarks"))] type XcmExecutor = XcmExecutor; - type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type AccountIdToLocation = BifrostAccountIdToLocation; type SalpHelper = Salp; type ParachainId = SelfParaChainId; type CallBackTimeOut = ConstU32<10>; diff --git a/runtime/bifrost-polkadot/Cargo.toml b/runtime/bifrost-polkadot/Cargo.toml index 71bdb84f2..c152356c3 100644 --- a/runtime/bifrost-polkadot/Cargo.toml +++ b/runtime/bifrost-polkadot/Cargo.toml @@ -71,7 +71,6 @@ sp-genesis-builder = { workspace = true } # Cumulus dependencies cumulus-pallet-aura-ext = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-parachain-system = { workspace = true } cumulus-pallet-xcm = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } @@ -110,6 +109,7 @@ bifrost-stable-asset = { workspace = true } # Bifrost bifrost-asset-registry = { workspace = true } +bifrost-buy-back = { workspace = true } bifrost-call-switchgear = { workspace = true } bifrost-cross-in-out = { workspace = true } bifrost-currencies = { workspace = true } @@ -141,6 +141,7 @@ pallet-prices = { workspace = true } leverage-staking = { workspace = true } bifrost-channel-commission = { workspace = true } bifrost-clouds-convert = { workspace = true } +bifrost-vtoken-minting-rpc-runtime-api = { workspace = true } [build-dependencies] substrate-wasm-builder = { workspace = true, optional = true } @@ -198,7 +199,6 @@ std = [ "sp-genesis-builder/std", "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcm/std", "cumulus-pallet-xcmp-queue/std", @@ -225,6 +225,7 @@ std = [ "zenlink-protocol/std", "bifrost-asset-registry/std", + "bifrost-buy-back/std", "bifrost-cross-in-out/std", "bifrost-currencies/std", "bifrost-farming-rpc-runtime-api/std", @@ -254,6 +255,7 @@ std = [ "bifrost-xcm-interface/std", "bifrost-channel-commission/std", "bifrost-clouds-convert/std", + "bifrost-vtoken-minting-rpc-runtime-api/std", "substrate-wasm-builder" ] @@ -293,77 +295,78 @@ runtime-benchmarks = [ "lend-market/runtime-benchmarks", "bifrost-channel-commission/runtime-benchmarks", "bifrost-clouds-convert/runtime-benchmarks", + "bifrost-buy-back/runtime-benchmarks", ] try-runtime = [ - "frame-try-runtime", + "bifrost-asset-registry/try-runtime", + "bifrost-buy-back/try-runtime", + "bifrost-call-switchgear/try-runtime", + "bifrost-channel-commission/try-runtime", + "bifrost-clouds-convert/try-runtime", + "bifrost-cross-in-out/try-runtime", + "bifrost-currencies/try-runtime", + "bifrost-farming/try-runtime", + "bifrost-fee-share/try-runtime", + "bifrost-flexible-fee/try-runtime", + "bifrost-salp/try-runtime", + "bifrost-slp/try-runtime", + "bifrost-slpx/try-runtime", + "bifrost-stable-asset/try-runtime", + "bifrost-stable-pool/try-runtime", + "bifrost-system-maker/try-runtime", + "bifrost-system-staking/try-runtime", + "bifrost-ve-minting/try-runtime", + "bifrost-vesting/try-runtime", + "bifrost-vstoken-conversion/try-runtime", + "bifrost-vtoken-minting/try-runtime", + "bifrost-vtoken-voting/try-runtime", + "bifrost-xcm-interface/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "frame-executive/try-runtime", "frame-support/try-runtime", "frame-system/try-runtime", - "frame-executive/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-indices/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "parachain-info/try-runtime", - "pallet-balances/try-runtime", - "pallet-transaction-payment/try-runtime", + "frame-try-runtime", + "frame-try-runtime/try-runtime", + "lend-market/try-runtime", + "leverage-staking/try-runtime", + "merkle-distributor/try-runtime", + "orml-oracle/try-runtime", + "orml-tokens/try-runtime", + "orml-unknown-tokens/try-runtime", + "orml-xcm/try-runtime", + "orml-xtokens/try-runtime", + "pallet-aura/try-runtime", "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-bounties/try-runtime", "pallet-collator-selection/try-runtime", - "pallet-session/try-runtime", - "pallet-aura/try-runtime", - "cumulus-pallet-aura-ext/try-runtime", - "pallet-democracy/try-runtime", "pallet-collective/try-runtime", "pallet-conviction-voting/try-runtime", + "pallet-democracy/try-runtime", "pallet-elections-phragmen/try-runtime", + "pallet-identity/try-runtime", + "pallet-indices/try-runtime", "pallet-membership/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "pallet-xcm/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", - "pallet-utility/try-runtime", - "pallet-scheduler/try-runtime", - "pallet-proxy/try-runtime", "pallet-multisig/try-runtime", - "pallet-identity/try-runtime", + "pallet-preimage/try-runtime", + "pallet-prices/try-runtime", + "pallet-proxy/try-runtime", "pallet-ranked-collective/try-runtime", "pallet-referenda/try-runtime", - "bifrost-vesting/try-runtime", - "pallet-treasury/try-runtime", - "pallet-bounties/try-runtime", + "pallet-scheduler/try-runtime", + "pallet-session/try-runtime", + "pallet-timestamp/try-runtime", "pallet-tips/try-runtime", - "pallet-preimage/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-treasury/try-runtime", + "pallet-utility/try-runtime", "pallet-whitelist/try-runtime", - "orml-xtokens/try-runtime", - "orml-tokens/try-runtime", - "bifrost-currencies/try-runtime", - "orml-unknown-tokens/try-runtime", - "orml-xcm/try-runtime", - "orml-oracle/try-runtime", + "parachain-info/try-runtime", "zenlink-protocol/try-runtime", - "merkle-distributor/try-runtime", - "bifrost-flexible-fee/try-runtime", - "bifrost-salp/try-runtime", - "bifrost-call-switchgear/try-runtime", - "bifrost-asset-registry/try-runtime", - "bifrost-vtoken-minting/try-runtime", - "bifrost-slp/try-runtime", - "bifrost-xcm-interface/try-runtime", - "bifrost-vstoken-conversion/try-runtime", - "bifrost-farming/try-runtime", - "bifrost-system-staking/try-runtime", - "bifrost-system-maker/try-runtime", - "bifrost-fee-share/try-runtime", - "bifrost-ve-minting/try-runtime", - "bifrost-cross-in-out/try-runtime", - "bifrost-slpx/try-runtime", - "bifrost-stable-asset/try-runtime", - "bifrost-stable-pool/try-runtime", - "bifrost-vtoken-voting/try-runtime", - "lend-market/try-runtime", - "pallet-prices/try-runtime", - "leverage-staking/try-runtime", - "bifrost-channel-commission/try-runtime", - "bifrost-clouds-convert/try-runtime", ] # When enabled, the runtime API will not be build. diff --git a/runtime/bifrost-polkadot/src/governance/fellowship.rs b/runtime/bifrost-polkadot/src/governance/fellowship.rs index 4e44b954b..4d520a042 100644 --- a/runtime/bifrost-polkadot/src/governance/fellowship.rs +++ b/runtime/bifrost-polkadot/src/governance/fellowship.rs @@ -355,4 +355,8 @@ impl pallet_ranked_collective::Config for Runtime type Polls = FellowshipReferenda; type MinRankOfClass = sp_runtime::traits::Identity; type VoteWeight = pallet_ranked_collective::Geometric; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkSetup = (); + type MemberSwappedHandler = (); + type ExchangeOrigin = EitherOfDiverse; } diff --git a/runtime/bifrost-polkadot/src/lib.rs b/runtime/bifrost-polkadot/src/lib.rs index f82079b27..2dce7de4a 100644 --- a/runtime/bifrost-polkadot/src/lib.rs +++ b/runtime/bifrost-polkadot/src/lib.rs @@ -97,9 +97,7 @@ use frame_support::{ Currency, EitherOf, EitherOfDiverse, Get, LinearStoragePrice, }, }; -use frame_system::{ - pallet_prelude::BlockNumberFor, EnsureRoot, EnsureRootWithSuccess, EnsureSigned, -}; +use frame_system::{EnsureRoot, EnsureRootWithSuccess, EnsureSigned}; use hex_literal::hex; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; // zenlink imports @@ -115,8 +113,8 @@ use pallet_xcm::{EnsureResponse, QueryStatus}; use polkadot_runtime_common::prod_or_fast; use sp_runtime::traits::{IdentityLookup, Verify}; use static_assertions::const_assert; -use xcm::v3::prelude::*; -use xcm_config::{ +use xcm::{v3::MultiLocation, v4::prelude::*}; +pub use xcm_config::{ parachains, BifrostCurrencyIdConvert, BifrostTreasuryAccount, MultiCurrency, SelfParaChainId, }; use xcm_executor::{ @@ -143,7 +141,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("bifrost_polkadot"), impl_name: create_runtime_str!("bifrost_polkadot"), authoring_version: 0, - spec_version: 10000, + spec_version: 11000, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -329,6 +327,8 @@ parameter_types! { pub const CloudsPalletId: PalletId = PalletId(*b"bf/cloud"); pub IncentivePoolAccount: PalletId = PalletId(*b"bf/inpoo"); pub const FarmingGaugeRewardIssuerPalletId: PalletId = PalletId(*b"bf/fmgar"); + pub const BuyBackAccount: PalletId = PalletId(*b"bf/bybck"); + pub const LiquidityAccount: PalletId = PalletId(*b"bf/liqdt"); } impl frame_system::Config for Runtime { @@ -632,7 +632,6 @@ impl pallet_balances::Config for Runtime { type MaxReserves = ConstU32<50>; type ReserveIdentifier = [u8; 8]; type FreezeIdentifier = (); - type MaxHolds = ConstU32<1>; type MaxFreezes = ConstU32<0>; type WeightInfo = pallet_balances::weights::SubstrateWeight; type RuntimeHoldReason = RuntimeHoldReason; @@ -1016,9 +1015,9 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca match currency_id { CurrencyId::Token2(GLMR_TOKEN_ID) => MultiLocation::new( 1, - X2( - Parachain(parachains::moonbeam::ID.into()), - AccountKey20 { + xcm::v3::Junctions::X2( + xcm::v3::Junction::Parachain(parachains::moonbeam::ID.into()), + xcm::v3::Junction::AccountKey20 { network: None, key: Slp::derivative_account_id_20( polkadot_parachain_primitives::primitives::Sibling::from( @@ -1032,9 +1031,9 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca ), ), // Only relay chain use the Bifrost para account with "para" - CurrencyId::Token2(DOT_TOKEN_ID) => MultiLocation::new( + CurrencyId::Token2(DOT_TOKEN_ID) => xcm::v3::Location::new( 1, - X1(AccountId32 { + xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( ParachainInfo::get().into_account_truncating(), @@ -1044,9 +1043,9 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca }), ), // Bifrost Polkadot Native token - CurrencyId::Native(TokenSymbol::BNC) => MultiLocation::new( + CurrencyId::Native(TokenSymbol::BNC) => xcm::v3::Location::new( 0, - X1(AccountId32 { + xcm::v3::Junctions::X1(xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( polkadot_parachain_primitives::primitives::Sibling::from(ParachainInfo::get()) @@ -1063,11 +1062,11 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca BifrostCurrencyIdConvert::::convert(currency_id) { if let Some(Parachain(para_id)) = location.interior().first() { - MultiLocation::new( + xcm::v3::Location::new( 1, - X2( - Parachain(*para_id), - AccountId32 { + xcm::v3::Junctions::X2( + xcm::v3::Junction::Parachain(*para_id), + xcm::v3::Junction::AccountId32 { network: None, id: Utility::derivative_account_id( polkadot_parachain_primitives::primitives::Sibling::from( @@ -1081,10 +1080,10 @@ pub fn create_x2_multilocation(index: u16, currency_id: CurrencyId) -> MultiLoca ), ) } else { - MultiLocation::default() + xcm::v3::Location::default() } } else { - MultiLocation::default() + xcm::v3::Location::default() } }, } @@ -1160,7 +1159,7 @@ parameter_types! { } pub struct SubstrateResponseManager; -impl QueryResponseManager +impl QueryResponseManager for SubstrateResponseManager { fn get_query_response_record(query_id: QueryId) -> bool { @@ -1172,14 +1171,14 @@ impl QueryResponseManager } fn create_query_record( - responder: &MultiLocation, + responder: Location, call_back: Option, timeout: BlockNumber, ) -> u64 { if let Some(call_back) = call_back { - PolkadotXcm::new_notify_query(*responder, call_back, timeout, Here) + PolkadotXcm::new_notify_query(responder.clone(), call_back, timeout, Here) } else { - PolkadotXcm::new_query(*responder, timeout, Here) + PolkadotXcm::new_query(responder, timeout, Here) } } @@ -1194,13 +1193,6 @@ impl QueryResponseManager } } -pub struct OnRefund; -impl bifrost_slp::OnRefund for OnRefund { - fn on_refund(token_id: CurrencyId, to: AccountId, token_amount: Balance) -> u64 { - SystemStaking::on_refund(token_id, to, token_amount).ref_time() - } -} - impl bifrost_slp::Config for Runtime { type RuntimeEvent = RuntimeEvent; type RuntimeOrigin = RuntimeOrigin; @@ -1209,13 +1201,11 @@ impl bifrost_slp::Config for Runtime { type ControlOrigin = EitherOfDiverse; type WeightInfo = weights::bifrost_slp::BifrostWeight; type VtokenMinting = VtokenMinting; - type BifrostSlpx = Slpx; type AccountConverter = SubAccountIndexMultiLocationConvertor; type ParachainId = SelfParaChainId; type SubstrateResponseManager = SubstrateResponseManager; type MaxTypeEntryPerBlock = MaxTypeEntryPerBlock; type MaxRefundPerBlock = MaxRefundPerBlock; - type OnRefund = OnRefund; type ParachainStaking = (); type XcmTransfer = XTokens; type MaxLengthLimit = MaxLengthLimit; @@ -1479,6 +1469,7 @@ impl bifrost_vtoken_minting::Config for Runtime { type MaxLockRecords = ConstU32<100>; type IncentivePoolAccount = IncentivePoolAccount; type VeMinting = VeMinting; + type AssetIdMaps = AssetIdMaps; } parameter_types! { @@ -1632,6 +1623,22 @@ impl bifrost_clouds_convert::Config for Runtime { type LockedBlocks = MaxBlock; } +impl bifrost_buy_back::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type MultiCurrency = Currencies; + type ControlOrigin = EitherOfDiverse; + type WeightInfo = weights::bifrost_buy_back::BifrostWeight; + type DexOperator = ZenlinkProtocol; + type CurrencyIdConversion = AssetIdMaps; + type TreasuryAccount = BifrostTreasuryAccount; + type RelayChainToken = RelayCurrencyId; + type BuyBackAccount = BuyBackAccount; + type LiquidityAccount = LiquidityAccount; + type ParachainId = ParachainInfo; + type CurrencyIdRegister = AssetIdMaps; + type VeMinting = VeMinting; +} + // Below is the implementation of tokens manipulation functions other than native token. pub struct LocalAssetAdaptor(PhantomData); @@ -1762,7 +1769,6 @@ construct_runtime! { XcmpQueue: cumulus_pallet_xcmp_queue = 40, PolkadotXcm: pallet_xcm = 41, CumulusXcm: cumulus_pallet_xcm = 42, - DmpQueue: cumulus_pallet_dmp_queue = 43, MessageQueue: pallet_message_queue = 44, // utilities @@ -1816,6 +1822,7 @@ construct_runtime! { LeverageStaking: leverage_staking = 135, ChannelCommission: bifrost_channel_commission = 136, CloudsConvert: bifrost_clouds_convert = 137, + BuyBack: bifrost_buy_back = 138, } } @@ -1856,17 +1863,16 @@ pub type CheckedExtrinsic = generic::CheckedExtrinsic; +parameter_types! { + pub const DmpQueuePalletName: &'static str = "DmpQueue"; +} + /// All migrations that will run on the next runtime upgrade. /// /// This contains the combined migrations of the last 10 releases. It allows to skip runtime /// upgrades in case governance decides to do so. THE ORDER IS IMPORTANT. pub type Migrations = migrations::Unreleased; -parameter_types! { - pub const TipsPalletName: &'static str = "Tips"; - pub const BountiesPalletName: &'static str = "Bounties"; -} - /// The runtime migrations per release. pub mod migrations { #[allow(unused_imports)] @@ -1874,37 +1880,15 @@ pub mod migrations { /// Unreleased migrations. Add new ones here: pub type Unreleased = ( - // Unlock & unreserve funds - pallet_tips::migrations::unreserve_deposits::UnreserveDeposits, - cumulus_pallet_xcmp_queue::migration::v4::MigrationToV4, - migration::slpx_migrates_whitelist::UpdateWhitelist, - frame_support::migrations::RemovePallet< - TipsPalletName, - ::DbWeight, - >, + bifrost_slpx::migration::v1::MigrateToV1, frame_support::migrations::RemovePallet< - BountiesPalletName, + DmpQueuePalletName, ::DbWeight, >, - pallet_identity::migration::versioned::V0ToV1, - pallet_collator_selection::migration::v2::MigrationToV2, + pallet_xcm::migration::MigrateToLatestXcmVersion, ); } -// Special Config for tips pallets, allowing us to run migrations for them without -// implementing their configs on [`Runtime`]. -pub struct UnlockConfigForTips; -impl pallet_tips::migrations::unreserve_deposits::UnlockConfig<()> for UnlockConfigForTips { - type Currency = Balances; - type Hash = Hash; - type DataDepositPerByte = DataDepositPerByte; - type TipReportDepositBase = TipReportDepositBase; - type AccountId = AccountId; - type BlockNumber = BlockNumberFor; - type DbWeight = ::DbWeight; - type PalletName = TipsPalletName; -} - /// Executive: handles dispatch to the various modules. pub type Executive = frame_executive::Executive< Runtime, @@ -1921,7 +1905,10 @@ extern crate frame_benchmarking; #[cfg(feature = "runtime-benchmarks")] mod benches { - define_benchmarks!([bifrost_ve_minting, VeMinting]); + define_benchmarks!( + [bifrost_ve_minting, VeMinting] + [bifrost_buy_back, BuyBack] + ); } impl_runtime_apis! { @@ -2192,6 +2179,12 @@ impl_runtime_apis! { } } + impl bifrost_vtoken_minting_rpc_runtime_api::VtokenMintingRuntimeApi for Runtime { + fn get_exchange_rate(token_id: Option) -> Vec<(CurrencyId, U256)> { + VtokenMinting::get_exchange_rate(token_id).unwrap_or(Vec::new()) + } + } + #[cfg(feature = "runtime-benchmarks")] impl frame_benchmarking::Benchmark for Runtime { fn benchmark_metadata(extra: bool) -> ( diff --git a/runtime/bifrost-polkadot/src/migration.rs b/runtime/bifrost-polkadot/src/migration.rs index adb8af6de..fb6a68e23 100644 --- a/runtime/bifrost-polkadot/src/migration.rs +++ b/runtime/bifrost-polkadot/src/migration.rs @@ -239,6 +239,7 @@ pub mod slpx_migrates_whitelist { pub struct UpdateWhitelist; impl OnRuntimeUpgrade for UpdateWhitelist { fn on_runtime_upgrade() -> Weight { + pallet_xcm::migrations::migrate_to_v1::>(); let new_whitelist: BoundedVec> = vec![ AccountId::from_ss58check("gWEvf2EDMzxR7JHyrEHXf3nqxKLGvHaFbk7HUkJnNPUxDts") .unwrap(), diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_asset_registry.rs b/runtime/bifrost-polkadot/src/weights/bifrost_asset_registry.rs index 2ebcdcc3a..927135cec 100644 --- a/runtime/bifrost-polkadot/src/weights/bifrost_asset_registry.rs +++ b/runtime/bifrost-polkadot/src/weights/bifrost_asset_registry.rs @@ -138,7 +138,7 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig // Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) // Storage: AssetRegistry CurrencyIdToWeights (r:0 w:1) // Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) - fn register_multilocation() -> Weight { + fn register_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -155,7 +155,7 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig // Proof Skipped: AssetRegistry CurrencyIdToWeights (max_values: None, max_size: None, mode: Measured) // Storage: AssetRegistry CurrencyIdToLocations (r:0 w:1) // Proof Skipped: AssetRegistry CurrencyIdToLocations (max_values: None, max_size: None, mode: Measured) - fn force_set_multilocation() -> Weight { + fn force_set_location() -> Weight { // Proof Size summary in bytes: // Measured: `683` // Estimated: `4148` @@ -164,4 +164,15 @@ impl bifrost_asset_registry::WeightInfo for BifrostWeig .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(3)) } + // Storage: `AssetRegistry::CurrencyMetadatas` (r:1 w:1) + // Proof: `AssetRegistry::CurrencyMetadatas` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn update_currency_metadata() -> Weight { + // Proof Size summary in bytes: + // Measured: `409` + // Estimated: `3874` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 3874) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } } diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_buy_back.rs b/runtime/bifrost-polkadot/src/weights/bifrost_buy_back.rs new file mode 100644 index 000000000..2efdc3a79 --- /dev/null +++ b/runtime/bifrost-polkadot/src/weights/bifrost_buy_back.rs @@ -0,0 +1,130 @@ +// This file is part of Bifrost. + +// Copyright (C) Liebi Technologies PTE. LTD. +// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 + +// This program 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. + +// This program 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 this program. If not, see . + +//! Autogenerated weights for `bifrost_buy_back` +//! +//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 32.0.0 +//! DATE: 2024-06-05, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` +//! WORST CASE MAP SIZE: `1000000` +//! HOSTNAME: `yml`, CPU: `AMD Ryzen 9 3950X 16-Core Processor` +//! WASM-EXECUTION: `Compiled`, CHAIN: `Some("bifrost-polkadot-local")`, DB CACHE: 1024 + +// Executed Command: +// ./target/release/bifrost +// benchmark +// pallet +// --chain=bifrost-polkadot-local +// --pallet=bifrost-buy-back +// --extrinsic=* +// --steps=50 +// --repeat=20 +// --wasm-execution=compiled +// --heap-pages=4096 +// --header=./HEADER-GPL3 +// --output=./bifrost-buy-back.rs + +#![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 `bifrost_buy_back`. +pub struct BifrostWeight(PhantomData); +impl bifrost_buy_back::WeightInfo for BifrostWeight { + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `BuyBack::Infos` (r:0 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn set_vtoken() -> Weight { + // Proof Size summary in bytes: + // Measured: `25` + // Estimated: `1510` + // Minimum execution time: 11_582_000 picoseconds. + Weight::from_parts(11_753_000, 0) + .saturating_add(Weight::from_parts(0, 1510)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `Tokens::Accounts` (r:2 w:2) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + fn charge() -> Weight { + // Proof Size summary in bytes: + // Measured: `508` + // Estimated: `6196` + // Minimum execution time: 43_842_000 picoseconds. + Weight::from_parts(44_144_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(5)) + } + /// Storage: `System::Number` (r:1 w:0) + /// Proof: `System::Number` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::ExecutionPhase` (r:1 w:0) + /// Proof: `System::ExecutionPhase` (`max_values`: Some(1), `max_size`: Some(5), added: 500, mode: `MaxEncodedLen`) + /// Storage: `System::EventCount` (r:1 w:1) + /// Proof: `System::EventCount` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Events` (r:1 w:1) + /// Proof: `System::Events` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `BuyBack::Infos` (r:0 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn remove_vtoken() -> Weight { + // Proof Size summary in bytes: + // Measured: `25` + // Estimated: `1510` + // Minimum execution time: 10_931_000 picoseconds. + Weight::from_parts(11_161_000, 0) + .saturating_add(Weight::from_parts(0, 1510)) + .saturating_add(T::DbWeight::get().reads(4)) + .saturating_add(T::DbWeight::get().writes(3)) + } + /// Storage: `BuyBack::Infos` (r:2 w:1) + /// Proof: `BuyBack::Infos` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) + /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `Tokens::Accounts` (r:2 w:0) + /// Proof: `Tokens::Accounts` (`max_values`: None, `max_size`: Some(118), added: 2593, mode: `MaxEncodedLen`) + fn on_idle() -> Weight { + // Proof Size summary in bytes: + // Measured: `502` + // Estimated: `6442` + // Minimum execution time: 32_792_000 picoseconds. + Weight::from_parts(33_293_000, 0) + .saturating_add(Weight::from_parts(0, 6442)) + .saturating_add(T::DbWeight::get().reads(5)) + .saturating_add(T::DbWeight::get().writes(1)) + } +} diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs b/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs index e9c0cddc2..5cc4a3e80 100644 --- a/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs +++ b/runtime/bifrost-polkadot/src/weights/bifrost_slpx.rs @@ -127,6 +127,19 @@ impl bifrost_slpx::WeightInfo for BifrostWeight { .saturating_add(T::DbWeight::get().reads(16)) .saturating_add(T::DbWeight::get().writes(8)) } + // Storage: `Slpx::WhitelistAccountId` (r:1 w:0) + // Proof: `Slpx::WhitelistAccountId` (`max_values`: None, `max_size`: Some(338), added: 2813, mode: `MaxEncodedLen`) + // Storage: `Slpx::OrderQueue` (r:1 w:1) + // Proof: `Slpx::OrderQueue` (`max_values`: Some(1), `max_size`: Some(203002), added: 203497, mode: `MaxEncodedLen`) + fn mint_with_channel_id() -> Weight { + // Proof Size summary in bytes: + // Measured: `81` + // Estimated: `204487` + // Minimum execution time: 12_000 nanoseconds. + Weight::from_parts(13_000_000, 204487) + .saturating_add(T::DbWeight::get().reads(2)) + .saturating_add(T::DbWeight::get().writes(1)) + } // Storage: Slpx WhitelistAccountId (r:1 w:0) // Proof: Slpx WhitelistAccountId (max_values: None, max_size: Some(338), added: 2813, mode: MaxEncodedLen) // Storage: Tokens Accounts (r:2 w:2) diff --git a/runtime/bifrost-polkadot/src/weights/mod.rs b/runtime/bifrost-polkadot/src/weights/mod.rs index d6f4e9070..6ea6b29d5 100644 --- a/runtime/bifrost-polkadot/src/weights/mod.rs +++ b/runtime/bifrost-polkadot/src/weights/mod.rs @@ -21,6 +21,7 @@ //! A list of the different weight modules for our runtime. pub mod bifrost_asset_registry; +pub mod bifrost_buy_back; pub mod bifrost_call_switchgear; pub mod bifrost_channel_commission; pub mod bifrost_clouds_convert; diff --git a/runtime/bifrost-polkadot/src/weights/pallet_xcm.rs b/runtime/bifrost-polkadot/src/weights/pallet_xcm.rs index 3f413862f..5fe4c382a 100644 --- a/runtime/bifrost-polkadot/src/weights/pallet_xcm.rs +++ b/runtime/bifrost-polkadot/src/weights/pallet_xcm.rs @@ -64,35 +64,67 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn send() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3540` - // Minimum execution time: 24_079_000 picoseconds. - Weight::from_parts(24_695_000, 0) - .saturating_add(Weight::from_parts(0, 3540)) + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 21_170_000 picoseconds. + Weight::from_parts(21_757_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) .saturating_add(T::DbWeight::get().reads(6)) .saturating_add(T::DbWeight::get().writes(2)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0) + /// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`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: `System::Account` (r:1 w:1) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// 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 teleport_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `1489` - // Minimum execution time: 18_654_000 picoseconds. - Weight::from_parts(19_331_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `197` + // Estimated: `3662` + // Minimum execution time: 94_487_000 picoseconds. + Weight::from_parts(96_276_000, 0) + .saturating_add(Weight::from_parts(0, 3662)) + .saturating_add(T::DbWeight::get().reads(8)) + .saturating_add(T::DbWeight::get().writes(3)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) + /// Storage: `System::Account` (r:2 w:2) + /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(128), added: 2603, mode: `MaxEncodedLen`) + /// Storage: `XcmpQueue::DeliveryFeeFactor` (r:1 w:0) + /// Proof: `XcmpQueue::DeliveryFeeFactor` (`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::RelevantMessagingState` (r:1 w:0) + /// Proof: `ParachainSystem::RelevantMessagingState` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpStatus` (r:1 w:1) + /// Proof: `XcmpQueue::OutboundXcmpStatus` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) + /// Storage: `XcmpQueue::OutboundXcmpMessages` (r:0 w:1) + /// Proof: `XcmpQueue::OutboundXcmpMessages` (`max_values`: None, `max_size`: None, mode: `Measured`) fn reserve_transfer_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `1489` - // Minimum execution time: 13_972_000 picoseconds. - Weight::from_parts(14_410_000, 0) - .saturating_add(Weight::from_parts(0, 1489)) - .saturating_add(T::DbWeight::get().reads(1)) + // Measured: `419` + // Estimated: `6196` + // Minimum execution time: 119_502_000 picoseconds. + Weight::from_parts(121_486_000, 0) + .saturating_add(Weight::from_parts(0, 6196)) + .saturating_add(T::DbWeight::get().reads(9)) + .saturating_add(T::DbWeight::get().writes(5)) } /// Storage: `ParachainInfo::ParachainId` (r:1 w:0) /// Proof: `ParachainInfo::ParachainId` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) @@ -116,10 +148,10 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn transfer_assets() -> Weight { // Proof Size summary in bytes: - // Measured: `496` + // Measured: `600` // Estimated: `6208` - // Minimum execution time: 146_932_000 picoseconds. - Weight::from_parts(153_200_000, 0) + // Minimum execution time: 143_889_000 picoseconds. + Weight::from_parts(147_227_000, 0) .saturating_add(Weight::from_parts(0, 6208)) .saturating_add(T::DbWeight::get().reads(12)) .saturating_add(T::DbWeight::get().writes(7)) @@ -140,8 +172,8 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 6_624_000 picoseconds. - Weight::from_parts(7_005_000, 0) + // Minimum execution time: 6_141_000 picoseconds. + Weight::from_parts(6_320_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -151,8 +183,8 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_213_000 picoseconds. - Weight::from_parts(2_374_000, 0) + // Minimum execution time: 2_013_000 picoseconds. + Weight::from_parts(2_144_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } @@ -176,11 +208,11 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn force_subscribe_version_notify() -> Weight { // Proof Size summary in bytes: - // Measured: `75` - // Estimated: `3540` - // Minimum execution time: 28_117_000 picoseconds. - Weight::from_parts(29_002_000, 0) - .saturating_add(Weight::from_parts(0, 3540)) + // Measured: `145` + // Estimated: `3610` + // Minimum execution time: 26_192_000 picoseconds. + Weight::from_parts(26_891_000, 0) + .saturating_add(Weight::from_parts(0, 3610)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(5)) } @@ -202,11 +234,11 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `PolkadotXcm::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) fn force_unsubscribe_version_notify() -> Weight { // Proof Size summary in bytes: - // Measured: `292` - // Estimated: `3757` - // Minimum execution time: 30_111_000 picoseconds. - Weight::from_parts(30_890_000, 0) - .saturating_add(Weight::from_parts(0, 3757)) + // Measured: `363` + // Estimated: `3828` + // Minimum execution time: 28_794_000 picoseconds. + Weight::from_parts(29_672_000, 0) + .saturating_add(Weight::from_parts(0, 3828)) .saturating_add(T::DbWeight::get().reads(7)) .saturating_add(T::DbWeight::get().writes(4)) } @@ -216,45 +248,45 @@ impl pallet_xcm::WeightInfo for WeightInfo { // Proof Size summary in bytes: // Measured: `0` // Estimated: `0` - // Minimum execution time: 2_126_000 picoseconds. - Weight::from_parts(2_293_000, 0) + // Minimum execution time: 1_890_000 picoseconds. + Weight::from_parts(2_068_000, 0) .saturating_add(Weight::from_parts(0, 0)) .saturating_add(T::DbWeight::get().writes(1)) } - /// Storage: `PolkadotXcm::SupportedVersion` (r:4 w:2) + /// Storage: `PolkadotXcm::SupportedVersion` (r:5 w:2) /// Proof: `PolkadotXcm::SupportedVersion` (`max_values`: None, `max_size`: None, mode: `Measured`) fn migrate_supported_version() -> Weight { // Proof Size summary in bytes: - // Measured: `129` - // Estimated: `11019` - // Minimum execution time: 17_037_000 picoseconds. - Weight::from_parts(17_778_000, 0) - .saturating_add(Weight::from_parts(0, 11019)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `159` + // Estimated: `13524` + // Minimum execution time: 18_690_000 picoseconds. + Weight::from_parts(19_397_000, 0) + .saturating_add(Weight::from_parts(0, 13524)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifiers` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifiers` (r:5 w:2) /// Proof: `PolkadotXcm::VersionNotifiers` (`max_values`: None, `max_size`: None, mode: `Measured`) fn migrate_version_notifiers() -> Weight { // Proof Size summary in bytes: - // Measured: `133` - // Estimated: `11023` - // Minimum execution time: 16_863_000 picoseconds. - Weight::from_parts(17_392_000, 0) - .saturating_add(Weight::from_parts(0, 11023)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `163` + // Estimated: `13528` + // Minimum execution time: 18_719_000 picoseconds. + Weight::from_parts(19_241_000, 0) + .saturating_add(Weight::from_parts(0, 13528)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:0) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:6 w:0) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) fn already_notified_target() -> Weight { // Proof Size summary in bytes: - // Measured: `140` - // Estimated: `13505` - // Minimum execution time: 18_745_000 picoseconds. - Weight::from_parts(19_010_000, 0) - .saturating_add(Weight::from_parts(0, 13505)) - .saturating_add(T::DbWeight::get().reads(5)) + // Measured: `173` + // Estimated: `16013` + // Minimum execution time: 20_555_000 picoseconds. + Weight::from_parts(21_068_000, 0) + .saturating_add(Weight::from_parts(0, 16013)) + .saturating_add(T::DbWeight::get().reads(6)) } /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:2 w:1) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) @@ -272,38 +304,38 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// Proof: `ParachainSystem::PendingUpwardMessages` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) fn notify_current_targets() -> Weight { // Proof Size summary in bytes: - // Measured: `142` - // Estimated: `6082` - // Minimum execution time: 26_717_000 picoseconds. - Weight::from_parts(27_144_000, 0) - .saturating_add(Weight::from_parts(0, 6082)) + // Measured: `212` + // Estimated: `6152` + // Minimum execution time: 26_014_000 picoseconds. + Weight::from_parts(26_786_000, 0) + .saturating_add(Weight::from_parts(0, 6152)) .saturating_add(T::DbWeight::get().reads(8)) .saturating_add(T::DbWeight::get().writes(3)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:3 w:0) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 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: 9_128_000 picoseconds. - Weight::from_parts(9_445_000, 0) - .saturating_add(Weight::from_parts(0, 8587)) - .saturating_add(T::DbWeight::get().reads(3)) + // Measured: `206` + // Estimated: `11096` + // Minimum execution time: 11_678_000 picoseconds. + Weight::from_parts(12_132_000, 0) + .saturating_add(Weight::from_parts(0, 11096)) + .saturating_add(T::DbWeight::get().reads(4)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 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: `140` - // Estimated: `11030` - // Minimum execution time: 17_316_000 picoseconds. - Weight::from_parts(17_802_000, 0) - .saturating_add(Weight::from_parts(0, 11030)) - .saturating_add(T::DbWeight::get().reads(4)) + // Measured: `170` + // Estimated: `13535` + // Minimum execution time: 19_050_000 picoseconds. + Weight::from_parts(19_546_000, 0) + .saturating_add(Weight::from_parts(0, 13535)) + .saturating_add(T::DbWeight::get().reads(5)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:4 w:2) + /// Storage: `PolkadotXcm::VersionNotifyTargets` (r:5 w:2) /// Proof: `PolkadotXcm::VersionNotifyTargets` (`max_values`: None, `max_size`: None, mode: `Measured`) /// Storage: `ParachainSystem::UpwardDeliveryFeeFactor` (r:1 w:0) /// Proof: `ParachainSystem::UpwardDeliveryFeeFactor` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) @@ -319,37 +351,49 @@ impl pallet_xcm::WeightInfo for WeightInfo { /// 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: `146` - // Estimated: `11036` - // Minimum execution time: 33_426_000 picoseconds. - Weight::from_parts(33_986_000, 0) - .saturating_add(Weight::from_parts(0, 11036)) - .saturating_add(T::DbWeight::get().reads(10)) + // Measured: `212` + // Estimated: `13577` + // Minimum execution time: 34_690_000 picoseconds. + Weight::from_parts(35_397_000, 0) + .saturating_add(Weight::from_parts(0, 13577)) + .saturating_add(T::DbWeight::get().reads(11)) .saturating_add(T::DbWeight::get().writes(4)) } - /// Storage: `XcmPallet::QueryCounter` (r:1 w:1) - /// Proof: `XcmPallet::QueryCounter` (`max_values`: Some(1), `max_size`: None, mode: `Measured`) - /// Storage: `XcmPallet::Queries` (r:0 w:1) - /// Proof: `XcmPallet::Queries` (`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::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: `0` - // Estimated: `1485` - // Minimum execution time: 2_947_000 picoseconds. - Weight::from_parts(3_117_000, 0) - .saturating_add(Weight::from_parts(0, 1485)) + // Measured: `103` + // Estimated: `1588` + // Minimum execution time: 4_663_000 picoseconds. + Weight::from_parts(4_812_000, 0) + .saturating_add(Weight::from_parts(0, 1588)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(2)) } - /// Storage: `XcmPallet::Queries` (r:1 w:1) - /// Proof: `XcmPallet::Queries` (`max_values`: None, `max_size`: None, mode: `Measured`) + /// 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: `7576` - // Estimated: `11041` - // Minimum execution time: 24_595_000 picoseconds. - Weight::from_parts(24_907_000, 0) - .saturating_add(Weight::from_parts(0, 11041)) + // Measured: `7740` + // Estimated: `11205` + // Minimum execution time: 25_044_000 picoseconds. + Weight::from_parts(25_416_000, 0) + .saturating_add(Weight::from_parts(0, 11205)) + .saturating_add(T::DbWeight::get().reads(1)) + .saturating_add(T::DbWeight::get().writes(1)) + } + /// Storage: `PolkadotXcm::AssetTraps` (r:1 w:1) + /// Proof: `PolkadotXcm::AssetTraps` (`max_values`: None, `max_size`: None, mode: `Measured`) + fn claim_assets() -> Weight { + // Proof Size summary in bytes: + // Measured: `160` + // Estimated: `3625` + // Minimum execution time: 37_380_000 picoseconds. + Weight::from_parts(37_761_000, 0) + .saturating_add(Weight::from_parts(0, 3625)) .saturating_add(T::DbWeight::get().reads(1)) .saturating_add(T::DbWeight::get().writes(1)) } diff --git a/runtime/bifrost-polkadot/src/xcm_config.rs b/runtime/bifrost-polkadot/src/xcm_config.rs index 4e9500690..22d7e397e 100644 --- a/runtime/bifrost-polkadot/src/xcm_config.rs +++ b/runtime/bifrost-polkadot/src/xcm_config.rs @@ -56,6 +56,7 @@ use bifrost_runtime_common::currency_adapter::{ BifrostDropAssets, DepositToAlternative, MultiCurrencyAdapter, }; use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling}; +use xcm::v4::{prelude::*, Asset, AssetId, InteriorLocation, Location}; /// Bifrost Asset Matcher pub struct BifrostAssetMatcher( @@ -65,12 +66,12 @@ pub struct BifrostAssetMatcher( impl MatchesFungible for BifrostAssetMatcher where - CurrencyIdConvert: Convert>, + CurrencyIdConvert: Convert>, Amount: TryFrom, { - fn matches_fungible(a: &MultiAsset) -> Option { - if let (Fungible(ref amount), Concrete(ref location)) = (&a.fun, &a.id) { - if CurrencyIdConvert::convert(*location).is_some() { + fn matches_fungible(a: &Asset) -> Option { + if let (Fungible(ref amount), AssetId(ref location)) = (&a.fun, &a.id) { + if CurrencyIdConvert::convert(location.clone()).is_some() { return CheckedConversion::checked_from(*amount); } } @@ -81,11 +82,11 @@ where /// A `FilterAssetLocation` implementation. Filters multi native assets whose /// reserve is same with `origin`. pub struct MultiNativeAsset(PhantomData); -impl ContainsPair for MultiNativeAsset +impl ContainsPair for MultiNativeAsset where ReserveProvider: Reserve, { - fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { + fn contains(asset: &Asset, origin: &Location) -> bool { if let Some(ref reserve) = ReserveProvider::reserve(asset) { if reserve == origin { return true; @@ -95,13 +96,13 @@ where } } -fn native_currency_location(id: CurrencyId) -> MultiLocation { - MultiLocation::new(0, X1(Junction::from(BoundedVec::try_from(id.encode()).unwrap()))) +fn native_currency_location(id: CurrencyId) -> Location { + Location::new(0, [Junction::from(BoundedVec::try_from(id.encode()).unwrap())]) } -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(asset: MultiAsset) -> Option { - if let MultiAsset { id: Concrete(id), fun: Fungible(_) } = asset { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(asset: Asset) -> Option { + if let Asset { id: AssetId(id), fun: xcm::v4::Fungibility::Fungible(_) } = asset { Self::convert(id) } else { None @@ -109,87 +110,81 @@ impl> Convert> for BifrostCurrency } } -pub struct BifrostAccountIdToMultiLocation; -impl Convert for BifrostAccountIdToMultiLocation { - fn convert(account: AccountId) -> MultiLocation { - X1(AccountId32 { network: None, id: account.into() }).into() +pub struct BifrostAccountIdToLocation; +impl Convert for BifrostAccountIdToLocation { + fn convert(account: AccountId) -> Location { + [AccountId32 { network: None, id: account.into() }].into() } } -pub struct BifrostCurrencyIdConvert(sp_std::marker::PhantomData); -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(id: CurrencyId) -> Option { +pub struct BifrostCurrencyIdConvert(PhantomData); +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(id: CurrencyId) -> Option { use CurrencyId::*; use TokenSymbol::*; - if let Some(id) = AssetIdMaps::::get_multi_location(id) { + if let Some(id) = AssetIdMaps::::get_location(id) { return Some(id); } match id { - Token2(DOT_TOKEN_ID) => Some(MultiLocation::parent()), + Token2(DOT_TOKEN_ID) => Some(Location::parent()), Native(BNC) => Some(native_currency_location(id)), // Moonbeam Native token - Token2(GLMR_TOKEN_ID) => Some(MultiLocation::new( + Token2(GLMR_TOKEN_ID) => Some(Location::new( 1, - X2( + [ Parachain(parachains::moonbeam::ID), PalletInstance(parachains::moonbeam::PALLET_ID.into()), - ), + ], )), _ => None, } } } -impl> Convert> for BifrostCurrencyIdConvert { - fn convert(location: MultiLocation) -> Option { +impl> Convert> for BifrostCurrencyIdConvert { + fn convert(location: Location) -> Option { use CurrencyId::*; use TokenSymbol::*; - if location == MultiLocation::parent() { + if location == Location::parent() { return Some(Token2(DOT_TOKEN_ID)); } - if let Some(currency_id) = AssetIdMaps::::get_currency_id(location) { + if let Some(currency_id) = AssetIdMaps::::get_currency_id(location.clone()) { return Some(currency_id); } - match location { - MultiLocation { parents: 1, interior } => match interior { - X2(Parachain(id), PalletInstance(index)) - if ((id == parachains::moonbeam::ID) && - (index == parachains::moonbeam::PALLET_ID)) => - Some(Token2(GLMR_TOKEN_ID)), - X2(Parachain(id), GeneralKey { data, length }) - if (id == u32::from(ParachainInfo::parachain_id())) => - { - let key = &data[..length as usize]; - if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { - match currency_id { - Native(BNC) => Some(currency_id), - _ => None, - } - } else { - None + match &location.unpack() { + (0, [Parachain(id), PalletInstance(index)]) + if (*id == parachains::moonbeam::ID) && + (*index == parachains::moonbeam::PALLET_ID) => + Some(Token2(GLMR_TOKEN_ID)), + (0, [Parachain(id), GeneralKey { data, length }]) + if *id == u32::from(ParachainInfo::parachain_id()) => + { + let key = &data[..*length as usize]; + if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { + match currency_id { + Native(BNC) => Some(currency_id), + _ => None, } - }, - _ => None, + } else { + None + } }, - MultiLocation { parents: 0, interior } => match interior { - X1(GeneralKey { data, length }) => { - // decode the general key - let key = &data[..length as usize]; - if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { - match currency_id { - Native(BNC) => Some(currency_id), - _ => None, - } - } else { - None + (0, [GeneralKey { data, length }]) => { + // decode the general key + let key = &data[..*length as usize]; + if let Ok(currency_id) = CurrencyId::decode(&mut &key[..]) { + match currency_id { + Native(BNC) => Some(currency_id), + _ => None, } - }, - _ => None, + } else { + None + } }, _ => None, } @@ -197,14 +192,14 @@ impl> Convert> for BifrostCurre } parameter_types! { - pub const DotLocation: MultiLocation = MultiLocation::parent(); - pub const RelayNetwork: NetworkId = NetworkId::Polkadot; + pub const DotLocation: Location = Location::parent(); + pub const RelayNetwork: NetworkId = Polkadot; pub RelayChainOrigin: RuntimeOrigin = cumulus_pallet_xcm::Origin::Relay.into(); pub SelfParaChainId: CumulusParaId = ParachainInfo::parachain_id(); - pub UniversalLocation: InteriorMultiLocation = X2(GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())); + pub UniversalLocation: InteriorLocation = [GlobalConsensus(RelayNetwork::get()), Parachain(ParachainInfo::parachain_id().into())].into(); } -/// Type for specifying how a `MultiLocation` can be converted into an `AccountId`. This is used +/// 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 RuntimeOrigin. pub type LocationToAccountId = ( @@ -248,20 +243,13 @@ parameter_types! { pub const MaxInstructions: u32 = 100; } -match_types! { - pub type ParentOrParentsExecutivePlurality: impl Contains = { - MultiLocation { parents: 1, interior: Here } | - MultiLocation { parents: 1, interior: X1(Plurality { id: BodyId::Executive, .. }) } - }; -} - /// Barrier allowing a top level paid message with DescendOrigin instruction pub const DEFAULT_PROOF_SIZE: u64 = 64 * 1024; pub const DEFAULT_REF_TIMR: u64 = 10_000_000_000; pub struct AllowTopLevelPaidExecutionDescendOriginFirst(PhantomData); -impl> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst { +impl> ShouldExecute for AllowTopLevelPaidExecutionDescendOriginFirst { fn should_execute( - origin: &MultiLocation, + origin: &Location, message: &mut [Instruction], max_weight: Weight, _weight_credit: &mut Properties, @@ -337,38 +325,38 @@ pub type BifrostAssetTransactor = MultiCurrencyAdapter< >; parameter_types! { - pub DotPerSecond: (AssetId,u128, u128) = (MultiLocation::parent().into(), dot_per_second::(),0); + pub DotPerSecond: (AssetId,u128, u128) = (Location::parent().into(), dot_per_second::(),0); pub BncPerSecond: (AssetId,u128, u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())), + [xcm::v4::Junction::Parachain(SelfParaId::get()), xcm::v4::Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())], ).into(), // BNC:DOT = 80:1 dot_per_second::() * 80, 0 ); pub BncNewPerSecond: (AssetId,u128, u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())) + [xcm::v4::Junction::from(BoundedVec::try_from(NativeCurrencyId::get().encode()).unwrap())] ).into(), // BNC:DOT = 80:1 dot_per_second::() * 80, 0 ); pub ZlkPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 1, - X2(Parachain(SelfParaId::get()), Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())) + [xcm::v4::Junction::Parachain(SelfParaId::get()), xcm::v4::Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())] ).into(), // ZLK:KSM = 150:1 dot_per_second::() * 150 * 1_000_000, 0 ); pub ZlkNewPerSecond: (AssetId, u128,u128) = ( - MultiLocation::new( + Location::new( 0, - X1(Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())) + [xcm::v4::Junction::from(BoundedVec::try_from(CurrencyId::Token(TokenSymbol::ZLK).encode()).unwrap())] ).into(), // ZLK:KSM = 150:1 dot_per_second::() * 150 * 1_000_000, @@ -379,8 +367,10 @@ parameter_types! { pub struct ToTreasury; impl TakeRevenue for ToTreasury { - fn take_revenue(revenue: MultiAsset) { - if let MultiAsset { id: Concrete(location), fun: Fungible(amount) } = revenue { + fn take_revenue(revenue: Asset) { + if let Asset { id: AssetId(location), fun: xcm::v4::Fungibility::Fungible(amount) } = + revenue + { if let Some(currency_id) = BifrostCurrencyIdConvert::::convert(location) { @@ -493,28 +483,6 @@ impl Contains for SafeCallFilter { } } -/// Matches foreign assets from a given origin. -/// Foreign assets are assets bridged from other consensus systems. i.e parents > 1. -pub struct IsForeignNativeAssetFrom(PhantomData); -impl ContainsPair for IsForeignNativeAssetFrom -where - Origin: Get, -{ - fn contains(asset: &MultiAsset, origin: &MultiLocation) -> bool { - let loc = Origin::get(); - &loc == origin && - matches!( - asset, - MultiAsset { id: Concrete(MultiLocation { parents: 2, .. }), fun: Fungible(_) }, - ) - } -} - -parameter_types! { - /// Location of Asset Hub - pub AssetHubLocation: MultiLocation = (Parent, Parachain(1000)).into(); -} - pub struct XcmConfig; impl xcm_executor::Config for XcmConfig { type AssetClaims = PolkadotXcm; @@ -522,8 +490,7 @@ impl xcm_executor::Config for XcmConfig { type AssetTrap = BifrostDropAssets; type Barrier = Barrier; type RuntimeCall = RuntimeCall; - type IsReserve = - (IsForeignNativeAssetFrom, MultiNativeAsset); + type IsReserve = MultiNativeAsset; type IsTeleporter = (); type UniversalLocation = UniversalLocation; type OriginConverter = XcmOriginToTransactDispatchOrigin; @@ -559,7 +526,7 @@ pub type XcmRouter = ( #[cfg(feature = "runtime-benchmarks")] parameter_types! { - pub ReachableDest: Option = Some(Parent.into()); + pub ReachableDest: Option = Some(Parent.into()); } impl pallet_xcm::Config for Runtime { @@ -612,12 +579,6 @@ impl cumulus_pallet_xcmp_queue::Config for Runtime { type PriceForSiblingDelivery = NoPriceForMessageDelivery; } -impl cumulus_pallet_dmp_queue::Config for Runtime { - type RuntimeEvent = RuntimeEvent; - type WeightInfo = cumulus_pallet_dmp_queue::weights::SubstrateWeight; - type DmpSink = frame_support::traits::EnqueueWithOrigin; -} - parameter_types! { pub MessageQueueServiceWeight: Weight = Perbill::from_percent(35) * RuntimeBlockWeights::get().max_block; } @@ -688,6 +649,9 @@ impl Contains for DustRemovalWhitelist { .eq(a) || FeeSharePalletId::get().check_sub_account::(a) || a.eq(&ZenklinkFeeAccount::get()) || AccountIdConversion::::into_account_truncating(&CommissionPalletId::get()) + .eq(a) || AccountIdConversion::::into_account_truncating(&BuyBackAccount::get()) + .eq(a) || + AccountIdConversion::::into_account_truncating(&LiquidityAccount::get()) .eq(a) } } @@ -725,14 +689,14 @@ impl orml_tokens::Config for Runtime { } parameter_types! { - pub SelfLocation: MultiLocation = MultiLocation::new(1, X1(Parachain(ParachainInfo::get().into()))); - pub SelfRelativeLocation: MultiLocation = MultiLocation::here(); + pub SelfLocation: Location = Location::new(1, [Parachain(ParachainInfo::get().into())]); + pub SelfRelativeLocation: Location = Location::here(); pub const BaseXcmWeight: Weight = Weight::from_parts(1000_000_000u64, 0); pub const MaxAssetsForTransfer: usize = 2; } parameter_type_with_key! { - pub ParachainMinFee: |_location: MultiLocation| -> Option { + pub ParachainMinFee: |_location: Location| -> Option { Some(u128::MAX) }; } @@ -742,7 +706,7 @@ impl orml_xtokens::Config for Runtime { type Balance = Balance; type CurrencyId = CurrencyId; type CurrencyIdConvert = BifrostCurrencyIdConvert; - type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type AccountIdToLocation = BifrostAccountIdToLocation; type UniversalLocation = UniversalLocation; type SelfLocation = SelfRelativeLocation; type XcmExecutor = XcmExecutor; @@ -750,8 +714,10 @@ impl orml_xtokens::Config for Runtime { type BaseXcmWeight = BaseXcmWeight; type MaxAssetsForTransfer = MaxAssetsForTransfer; type MinXcmFee = ParachainMinFee; - type MultiLocationsFilter = Everything; + type LocationsFilter = Everything; type ReserveProvider = RelativeReserveProvider; + type RateLimiter = (); + type RateLimiterId = (); } impl orml_unknown_tokens::Config for Runtime { @@ -775,129 +741,9 @@ impl bifrost_xcm_interface::Config for Runtime { type RelaychainCurrencyId = RelayCurrencyId; type ParachainSovereignAccount = ParachainAccount; type XcmExecutor = XcmExecutor; - type AccountIdToMultiLocation = BifrostAccountIdToMultiLocation; + type AccountIdToLocation = BifrostAccountIdToLocation; type SalpHelper = Salp; type ParachainId = SelfParaChainId; type CallBackTimeOut = ConstU32<10>; type CurrencyIdConvert = AssetIdMaps; } - -#[cfg(test)] -mod tests { - use hex_literal::hex; - use sp_core::crypto::Ss58Codec; - use xcm::{ - prelude::{AccountId32, AccountKey20, Parachain, X2}, - v3::{MultiLocation, NetworkId}, - }; - use xcm_builder::{DescribeAllTerminal, DescribeFamily}; - use xcm_executor::traits::ConvertLocation; - - use crate::AccountId; - - #[test] - fn test_location_to_account() { - let moonbeam_slpx_origin_location = MultiLocation::new( - 1, - X2( - Parachain(2004), - AccountKey20 { - network: None, - key: hex!["F1d4797E51a4640a76769A50b57abE7479ADd3d8"].into(), - }, - ), - ); - let moonbeam_slpx_derived = xcm_builder::HashedDescription::< - AccountId, - DescribeFamily, - >::convert_location(&moonbeam_slpx_origin_location) - .unwrap(); - - let moonbeam_receiver_origin_location = MultiLocation::new( - 1, - X2( - Parachain(2004), - AccountKey20 { - network: None, - key: hex!["64DC1E8b5E9515dE37b58b4d8629Bf89BcD1F576"].into(), - }, - ), - ); - let moonbeam_receiver_derived = xcm_builder::HashedDescription::< - AccountId, - DescribeFamily, - >::convert_location(&moonbeam_receiver_origin_location) - .unwrap(); - - let moonriver_slpx_origin_location = MultiLocation::new( - 1, - X2( - Parachain(2023), - AccountKey20 { - network: None, - key: hex!["6b0A44c64190279f7034b77c13a566E914FE5Ec4"].into(), - }, - ), - ); - let moonriver_slpx_derived = xcm_builder::HashedDescription::< - AccountId, - DescribeFamily, - >::convert_location(&moonriver_slpx_origin_location) - .unwrap(); - - let astar_slpx_origin_location = MultiLocation::new( - 1, - X2( - Parachain(2006), - AccountId32 { - network: Some(NetworkId::Polkadot), - id: hex!["b3d19dad606c8f323460d7bb64a147af60923b85d3c853596954c71d2cfe20e3"] - .into(), - }, - ), - ); - let astar_slpx_derived = xcm_builder::HashedDescription::< - AccountId, - DescribeFamily, - >::convert_location(&astar_slpx_origin_location) - .unwrap(); - - let astar_receiver_origin_location = MultiLocation::new( - 1, - X2( - Parachain(2006), - AccountId32 { - network: Some(NetworkId::Polkadot), - id: hex!["576dee92eedbd7ffe0695569ac7a8db30edd204f2c42f53f14e0e863702c597e"] - .into(), - }, - ), - ); - let astar_receiver_derived = xcm_builder::HashedDescription::< - AccountId, - DescribeFamily, - >::convert_location(&astar_receiver_origin_location) - .unwrap(); - - assert_eq!( - moonbeam_slpx_derived, - AccountId::from_ss58check("gWEvf2EDMzxR7JHyrEHXf3nqxKLGvHaFbk7HUkJnNPUxDts").unwrap() - ); - assert_eq!( - moonbeam_receiver_derived, - AccountId::from_ss58check("bpRBE4rWcBJqqN2ESts5LefuvLonBeZ4r2YBpfuuxvMxoea").unwrap() - ); - assert_eq!( - moonriver_slpx_derived, - AccountId::from_ss58check("gtXJWw9ME9w7cXfmR6n9MFkKCSu2MrtA3dcFV2BhHpEZFjZ").unwrap() - ); - assert_eq!( - astar_slpx_derived, - AccountId::from_ss58check("g96o4GVpsAop1MJiArnmUYtXUjEisfkbfcpsuqmXrS28MEr").unwrap() - ); - assert_eq!( - astar_receiver_derived, - AccountId::from_ss58check("dZWAvaUWbPN1oKbWMkeDWHBceX8RqP4CMwmi1trq9uf5pBn").unwrap() - ); - } -} diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 3be219214..359d7a842 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -44,7 +44,6 @@ cumulus-pallet-parachain-system = { workspace = true } cumulus-primitives-core = { workspace = true } cumulus-primitives-timestamp = { workspace = true } cumulus-primitives-utility = { workspace = true } -cumulus-pallet-dmp-queue = { workspace = true } cumulus-pallet-xcmp-queue = { workspace = true } cumulus-pallet-xcm = { workspace = true } parachain-info = { workspace = true } @@ -98,7 +97,6 @@ std = [ "pallet-treasury/std", "pallet-scheduler/std", "pallet-transaction-payment/std", - "cumulus-pallet-dmp-queue/std", "cumulus-pallet-parachain-system/std", "cumulus-pallet-xcmp-queue/std", "cumulus-pallet-xcm/std", diff --git a/runtime/common/src/currency_adapter.rs b/runtime/common/src/currency_adapter.rs index 34275ee91..a928942cd 100644 --- a/runtime/common/src/currency_adapter.rs +++ b/runtime/common/src/currency_adapter.rs @@ -12,18 +12,21 @@ use sp_std::{ prelude::*, result, }; -use xcm::v3::{prelude::*, Error as XcmError, MultiAsset, MultiLocation, Result, Weight}; +use xcm::{ + v3::{Error as XcmError, Result, Weight}, + v4::Asset, +}; use xcm_builder::TakeRevenue; use xcm_executor::{ traits::{ConvertLocation, DropAssets, MatchesFungible, TransactAsset}, - Assets, + AssetsInHolding, }; /// Asset transaction errors. enum Error { /// Failed to match fungible. FailedToMatchFungible, - /// `MultiLocation` to `AccountId` Conversion failed. + /// `Location` to `AccountId` Conversion failed. AccountIdConversionFailed, /// `CurrencyId` conversion failed. CurrencyIdConversionFailed, @@ -56,13 +59,13 @@ pub trait OnDepositFail { /// Called on unknown asset deposit errors. fn on_deposit_unknown_asset_fail( err: DispatchError, - _asset: &MultiAsset, - _location: &MultiLocation, + _asset: &Asset, + _location: &xcm::v4::Location, ) -> Result { Err(XcmError::FailedToTransactAsset(err.into())) } - /// Called on `MultiLocation` to `AccountId` conversion errors. + /// Called on `Location` to `AccountId` conversion errors. fn on_account_id_convert_fail(currency_id: CurrencyId, amount: Balance) -> Result; } @@ -96,7 +99,7 @@ impl< } } -/// The `TransactAsset` implementation, to handle `MultiAsset` deposit/withdraw. +/// The `TransactAsset` implementation, to handle `Asset` deposit/withdraw. /// Note that teleport related functions are unimplemented. /// /// Methods of `DepositFailureHandler` would be called on multi-currency deposit @@ -134,7 +137,7 @@ impl< AccountId: sp_std::fmt::Debug + Clone, AccountIdConvert: ConvertLocation, CurrencyId: FullCodec + Eq + PartialEq + Copy + MaybeSerializeDeserialize + Debug, - CurrencyIdConvert: Convert>, + CurrencyIdConvert: Convert>, DepositFailureHandler: OnDepositFail, > TransactAsset for MultiCurrencyAdapter< @@ -149,9 +152,9 @@ impl< > { fn deposit_asset( - asset: &MultiAsset, - location: &MultiLocation, - _context: Option<&XcmContext>, + asset: &Asset, + location: &xcm::v4::Location, + _context: Option<&xcm::v4::XcmContext>, ) -> Result { match ( AccountIdConvert::convert_location(location), @@ -174,10 +177,10 @@ impl< } fn withdraw_asset( - asset: &MultiAsset, - location: &MultiLocation, - _maybe_context: Option<&XcmContext>, - ) -> result::Result { + asset: &Asset, + location: &xcm::v4::Location, + _maybe_context: Option<&xcm::v4::XcmContext>, + ) -> result::Result { UnknownAsset::withdraw(asset, location).or_else(|_| { let who = AccountIdConvert::convert_location(location) .ok_or(XcmError::from(Error::AccountIdConversionFailed))?; @@ -194,11 +197,11 @@ impl< } fn transfer_asset( - asset: &MultiAsset, - from: &MultiLocation, - to: &MultiLocation, - _context: &XcmContext, - ) -> result::Result { + asset: &Asset, + from: &xcm::v4::Location, + to: &xcm::v4::Location, + _context: &xcm::v4::XcmContext, + ) -> result::Result { let from_account = AccountIdConvert::convert_location(from) .ok_or(XcmError::from(Error::AccountIdConversionFailed))?; let to_account = AccountIdConvert::convert_location(to) @@ -220,8 +223,12 @@ impl DropAssets for BifrostDropAssets where T: TakeRevenue, { - fn drop_assets(_origin: &MultiLocation, assets: Assets, _context: &XcmContext) -> Weight { - let multi_assets: Vec = assets.into(); + fn drop_assets( + _origin: &xcm::v4::Location, + assets: AssetsInHolding, + _context: &xcm::v4::XcmContext, + ) -> Weight { + let multi_assets: Vec = assets.into(); for asset in multi_assets { T::take_revenue(asset); }