From 4bffd29245145eca61e62d5a73ddc95c998f3071 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 12 Apr 2023 11:55:20 +0200 Subject: [PATCH 01/24] feat: integrate dynamic fees into omnipool --- Cargo.lock | 570 +++++++++++-------- integration-tests/Cargo.toml | 18 +- pallets/circuit-breaker/Cargo.toml | 6 +- pallets/omnipool-liquidity-mining/Cargo.toml | 10 +- pallets/omnipool/Cargo.toml | 4 +- pallets/omnipool/src/lib.rs | 31 +- runtime/common/Cargo.toml | 19 +- runtime/common/src/adapters.rs | 41 +- runtime/common/src/lib.rs | 22 +- runtime/hydradx/Cargo.toml | 25 +- runtime/hydradx/src/lib.rs | 20 +- runtime/testing-hydradx/Cargo.toml | 25 +- runtime/testing-hydradx/src/lib.rs | 18 +- 13 files changed, 507 insertions(+), 302 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9730b45f6..78d1d12d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -42,7 +42,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b613b8e1e3cf911a086f53f03bf286f52fd7a7258e4fa606f0ef220d39d8877" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -77,7 +77,7 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.8", + "getrandom 0.2.9", "once_cell", "version_check", ] @@ -93,9 +93,9 @@ dependencies = [ [[package]] name = "always-assert" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf688625d06217d5b1bb0ea9d9c44a1635fd0ee3534466388d18203174f4d11" +checksum = "4436e0292ab1bb631b42973c61205e704475fe8126af845c8d923c0996328127" [[package]] name = "android_system_properties" @@ -132,9 +132,9 @@ dependencies = [ [[package]] name = "arrayref" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" [[package]] name = "arrayvec" @@ -159,9 +159,9 @@ checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" [[package]] name = "asn1_der" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22d1f4b888c298a027c99dc9048015fac177587de20fc30232a057dfbe24a21" +checksum = "155a5a185e42c6b77ac7b88a15143d930a9e9727a5b7b77eed417404ab15c247" [[package]] name = "assert_matches" @@ -192,9 +192,9 @@ dependencies = [ [[package]] name = "async-executor" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17adb73da160dfb475c183343c8cccd80721ea5a605d3eb57125f0a7b7a92d0b" +checksum = "6fa3dc5f2a8564f07759c008b9109dc0d39de92a88d5588b8a5036d286383afb" dependencies = [ "async-lock", "async-task", @@ -221,22 +221,22 @@ dependencies = [ [[package]] name = "async-io" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c374dda1ed3e7d8f0d9ba58715f924862c63eae6849c92d3a18e7fbde9e2794" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" dependencies = [ "async-lock", "autocfg", + "cfg-if 1.0.0", "concurrent-queue", "futures-lite", - "libc", "log", "parking", "polling", + "rustix 0.37.11", "slab", "socket2", "waker-fn", - "windows-sys 0.42.0", ] [[package]] @@ -250,9 +250,9 @@ dependencies = [ [[package]] name = "async-process" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6381ead98388605d0d9ff86371043b5aa922a3905824244de40dc263a14fcba4" +checksum = "7a9d28b1d97e08915212e2e45310d47854eafa69600756fc735fb788f75199c9" dependencies = [ "async-io", "async-lock", @@ -261,9 +261,9 @@ dependencies = [ "cfg-if 1.0.0", "event-listener", "futures-lite", - "libc", + "rustix 0.37.11", "signal-hook", - "windows-sys 0.42.0", + "windows-sys 0.48.0", ] [[package]] @@ -311,19 +311,19 @@ dependencies = [ [[package]] name = "async-task" -version = "4.3.0" +version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" +checksum = "ecc7ab41815b3c653ccd2978ec3255c81349336702dfdf62ee6f7069b12a3aae" [[package]] name = "async-trait" -version = "0.1.67" +version = "0.1.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86ea188f25f0255d8f92797797c97ebf5631fa88178beb1a46fdf5622c9a00e4" +checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] @@ -341,9 +341,9 @@ dependencies = [ [[package]] name = "atomic-waker" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "debc29dde2e69f9e47506b525f639ed42300fc014a3e007832592448fa8e4599" +checksum = "1181e1e0d1fce796a03db1ae795d67167da795f9cf4a39c37589e85ef57f26d3" [[package]] name = "atty" @@ -375,7 +375,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" dependencies = [ "futures-core", - "getrandom 0.2.8", + "getrandom 0.2.9", "instant", "pin-project-lite 0.2.9", "rand 0.8.5", @@ -655,7 +655,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -664,7 +664,7 @@ version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -678,9 +678,9 @@ dependencies = [ [[package]] name = "blocking" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c67b173a56acffd6d2326fb7ab938ba0b00a71480e14902b2591c87bc5741e8" +checksum = "77231a1c8f801696fc0123ec6150ce92cffb8e164a02afb9c8ddee0e9b65ad65" dependencies = [ "async-channel", "async-lock", @@ -688,6 +688,7 @@ dependencies = [ "atomic-waker", "fastrand", "futures-lite", + "log", ] [[package]] @@ -920,7 +921,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -944,9 +945,9 @@ dependencies = [ [[package]] name = "clang-sys" -version = "1.6.0" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ed9a53e5d4d9c573ae844bfac6872b159cb1d1585a83b29e7a64b7eef7332a" +checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" dependencies = [ "glob", "libc", @@ -994,9 +995,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.49" +version = "0.1.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" +checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" dependencies = [ "cc", ] @@ -1054,6 +1055,7 @@ dependencies = [ "pallet-collective", "pallet-currencies", "pallet-democracy", + "pallet-dynamic-fees", "pallet-ema-oracle", "pallet-identity", "pallet-liquidity-mining", @@ -1081,9 +1083,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278839b831783b70278b14df4d45e1beb1aad306c07bb796637de9a0e323e8e" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" dependencies = [ "crossbeam-utils", ] @@ -1124,9 +1126,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "core2" @@ -1148,9 +1150,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" dependencies = [ "libc", ] @@ -1262,9 +1264,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.7" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf2b3e8478797446514c91ef04bafcb59faba183e621ad488df88983cc14128c" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -1325,7 +1327,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "03c6a1d5fa1de37e071642dfa44ec552ca5b299adb128fab16138e24b548fd21" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "rand_core 0.6.4", "subtle", "zeroize", @@ -1337,7 +1339,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "typenum", ] @@ -1347,7 +1349,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1357,7 +1359,7 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -1901,9 +1903,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c00419335c41018365ddf7e4d5f1c12ee3659ddcf3e01974650ba1de73d038" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -1913,9 +1915,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb8307ad413a98fff033c8545ecf133e3257747b3bae935e7602aab8aa92d4ca" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -1923,24 +1925,24 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] name = "cxxbridge-flags" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edc52e2eb08915cb12596d29d55f0b5384f00d697a646dbd269b6ecb0fbd9d31" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.93" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "631569015d0d8d54e6c241733f944042623ab6df7bc3be7466874b05fcdb1c5f" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] @@ -2023,7 +2025,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -2192,7 +2194,7 @@ dependencies = [ "crypto-bigint", "der", "ff", - "generic-array 0.14.6", + "generic-array 0.14.7", "group", "rand_core 0.6.4", "sec1", @@ -2214,22 +2216,22 @@ dependencies = [ [[package]] name = "enumflags2" -version = "0.7.5" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e75d4cd21b95383444831539909fbb14b9dc3fdceb2a6f5d36577329a1f55ccb" +checksum = "0044ebdf7fbb2a772e0c0233a9d3173c5cd8af8ae7078d4c5188af44ffffaa4b" dependencies = [ "enumflags2_derive", ] [[package]] name = "enumflags2_derive" -version = "0.7.4" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f58dc3c5e468259f19f2d46304a6b28f1c3d034442e14b322d2b850e36f6d5ae" +checksum = "9d2c772ccdbdfd1967b4f5d79d17c98ebf92009fdcc838db7aa434462f600c26" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] @@ -2240,7 +2242,7 @@ checksum = "48016319042fb7c87b78d2993084a831793a897a5cd1a2a67cab9d1eeb4b7d76" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] @@ -2286,6 +2288,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "errno-dragonfly" version = "0.1.2" @@ -2403,9 +2416,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ace6ec7cc19c8ed33a32eaa9ea692d7faea05006b5356b9e2b668ec4bc3955" +checksum = "e825f6987101665dea6ec934c09ec6d721de7bc1bf92248e1d5810c8cd636b77" [[package]] name = "file-per-thread-logger" @@ -2419,14 +2432,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" +checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", - "windows-sys 0.45.0", + "redox_syscall 0.2.16", + "windows-sys 0.48.0", ] [[package]] @@ -2645,9 +2658,9 @@ dependencies = [ [[package]] name = "frame-metadata" -version = "15.0.0" +version = "15.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df6bb8542ef006ef0de09a5c4420787d79823c0ed7924225822362fd2bf2ff2d" +checksum = "878babb0b136e731cc77ec2fd883ff02745ff21e6fb662729953d44923df009c" dependencies = [ "cfg-if 1.0.0", "parity-scale-codec", @@ -2817,9 +2830,9 @@ checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" [[package]] name = "futures" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "531ac96c6ff5fd7c62263c5e3c67a603af4fcaee2e1a0ae5565ba3a11e69e549" +checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" dependencies = [ "futures-channel", "futures-core", @@ -2832,9 +2845,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "164713a5a0dcc3e7b4b1ed7d3b433cabc18025386f9339346e8daf15963cf7ac" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", "futures-sink", @@ -2842,15 +2855,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d7a0c1aa76363dac491de0ee99faf6941128376f1cf96f07db7603b7de69dd" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-executor" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1997dd9df74cdac935c76252744c1ed5794fac083242ea4fe77ef3ed60ba0f83" +checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" dependencies = [ "futures-core", "futures-task", @@ -2860,15 +2873,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89d422fa3cbe3b40dca574ab087abb5bc98258ea57eea3fd6f1fa7162c778b91" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-lite" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" dependencies = [ "fastrand", "futures-core", @@ -2881,13 +2894,13 @@ dependencies = [ [[package]] name = "futures-macro" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3eb14ed937631bd8b8b8977f2c198443447a8355b6e3ca599f38c975e5a963b6" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] @@ -2903,15 +2916,15 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec93083a4aecafb2a80a885c9de1f0ccae9dbd32c2bb54b0c3a65690e0b8d2f2" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd65540d33b37b16542a0438c12e6aeead10d4ac5d05bd3f805b8f35ab592879" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-timer" @@ -2921,9 +2934,9 @@ checksum = "e64b03909df88034c26dc1547e8970b91f98bdb65165d6a4e9110d94263dbb2c" [[package]] name = "futures-util" -version = "0.3.27" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef6b17e481503ec85211fed8f39d1970f128935ca1f814cd32ac4a6842e84ab" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-channel", "futures-core", @@ -2957,9 +2970,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -2990,9 +3003,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" dependencies = [ "cfg-if 1.0.0", "libc", @@ -3235,7 +3248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17ea0a1394df5b6574da6e0c1ade9e78868c9fb0a4e5ef4428e32da4676b85b1" dependencies = [ "digest 0.9.0", - "generic-array 0.14.6", + "generic-array 0.14.7", "hmac 0.8.1", ] @@ -3300,8 +3313,8 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "6.0.0" -source = "git+https://github.com/galacticcouncil/HydraDX-math?rev=bcb75f1c2b4f1d859ff133ca663539c59d1ed910#bcb75f1c2b4f1d859ff133ca663539c59d1ed910" +version = "6.1.0" +source = "git+https://github.com/galacticcouncil/HydraDX-math?rev=2fc83960a78bef9742551c78ae0264aa146d16b2#2fc83960a78bef9742551c78ae0264aa146d16b2" dependencies = [ "fixed", "num-traits", @@ -3396,7 +3409,7 @@ dependencies = [ [[package]] name = "hydradx-adapters" version = "0.2.2" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "hydradx-traits", @@ -3454,6 +3467,7 @@ dependencies = [ "pallet-currencies", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-genesis-history", @@ -3509,7 +3523,7 @@ dependencies = [ [[package]] name = "hydradx-traits" version = "2.2.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "impl-trait-for-tuples", @@ -3562,16 +3576,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows 0.48.0", ] [[package]] @@ -3630,7 +3644,7 @@ dependencies = [ "log", "rtnetlink", "system-configuration", - "windows", + "windows 0.34.0", ] [[package]] @@ -3664,9 +3678,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown 0.12.3", @@ -3679,7 +3693,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0c10553d664a4d0bcff9f4215d0aac67a639cc68ef660840afe309b807bc9f5" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", ] [[package]] @@ -3720,13 +3734,13 @@ checksum = "59ce5ef949d49ee85593fc4d3f3f95ad61657076395cbbce23e2121fc5542074" [[package]] name = "io-lifetimes" -version = "1.0.8" +version = "1.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd6da19f25979c7270e70fa95ab371ec3b701cd0eefc47667a09785b3c59155" +checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" dependencies = [ "hermit-abi 0.3.1", "libc", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -3749,20 +3763,20 @@ dependencies = [ [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" [[package]] name = "is-terminal" -version = "0.4.5" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ "hermit-abi 0.3.1", - "io-lifetimes 1.0.8", - "rustix 0.36.10", - "windows-sys 0.45.0", + "io-lifetimes 1.0.10", + "rustix 0.37.11", + "windows-sys 0.48.0", ] [[package]] @@ -4133,9 +4147,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libloading" @@ -4178,7 +4192,7 @@ dependencies = [ "bytes", "futures", "futures-timer", - "getrandom 0.2.8", + "getrandom 0.2.9", "instant", "lazy_static", "libp2p-autonat", @@ -4806,9 +4820,9 @@ checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d" [[package]] name = "linux-raw-sys" -version = "0.1.4" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" [[package]] name = "lock_api" @@ -5613,7 +5627,7 @@ dependencies = [ [[package]] name = "pallet-asset-registry" version = "2.1.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-benchmarking", "frame-support", @@ -5835,7 +5849,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-std", - "test-case 3.0.0", + "test-case 3.1.0", "test-utils", ] @@ -5867,7 +5881,7 @@ dependencies = [ [[package]] name = "pallet-collator-rewards" version = "1.0.3" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "frame-system", @@ -5923,7 +5937,7 @@ dependencies = [ [[package]] name = "pallet-currencies" version = "1.1.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "frame-system", @@ -5956,7 +5970,7 @@ dependencies = [ [[package]] name = "pallet-duster" version = "3.2.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-benchmarking", "frame-support", @@ -5970,6 +5984,23 @@ dependencies = [ "substrate-wasm-builder", ] +[[package]] +name = "pallet-dynamic-fees" +version = "1.0.0" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" +dependencies = [ + "frame-support", + "frame-system", + "hydra-dx-math", + "hydradx-traits", + "orml-traits", + "parity-scale-codec", + "scale-info", + "sp-core", + "sp-runtime", + "sp-std", +] + [[package]] name = "pallet-election-provider-multi-phase" version = "4.0.0-dev" @@ -6027,7 +6058,7 @@ dependencies = [ [[package]] name = "pallet-ema-oracle" version = "1.0.1" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-benchmarking", "frame-support", @@ -6154,7 +6185,7 @@ dependencies = [ [[package]] name = "pallet-liquidity-mining" version = "4.1.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "frame-system", @@ -6379,7 +6410,7 @@ dependencies = [ [[package]] name = "pallet-otc" version = "1.0.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-benchmarking", "frame-support", @@ -6442,7 +6473,7 @@ dependencies = [ [[package]] name = "pallet-relaychain-info" version = "0.3.2" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -6618,7 +6649,7 @@ dependencies = [ [[package]] name = "pallet-transaction-multi-payment" version = "8.0.4" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-support", "frame-system", @@ -6636,7 +6667,7 @@ dependencies = [ [[package]] name = "pallet-transaction-pause" version = "0.1.2" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-benchmarking", "frame-support", @@ -6896,9 +6927,9 @@ checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" [[package]] name = "parking" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" +checksum = "14f2252c834a40ed9bb5422029649578e63aa341ac401f74e719dd1afda8394e" [[package]] name = "parking_lot" @@ -6930,7 +6961,7 @@ dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "winapi", ] @@ -6943,7 +6974,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "windows-sys 0.45.0", ] @@ -6986,9 +7017,9 @@ checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cbd939b234e95d72bc393d51788aec68aeeb5d51e748ca08ff3aad58cb722f7" +checksum = "7b1403e8401ad5dedea73c626b99758535b342502f8d1e361f4a2dd952749122" dependencies = [ "thiserror", "ucd-trie", @@ -6996,9 +7027,9 @@ dependencies = [ [[package]] name = "pest_derive" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a81186863f3d0a27340815be8f2078dd8050b14cd71913db9fbda795e5f707d7" +checksum = "be99c4c1d2fc2769b1d00239431d711d08f6efedcecb8b6e30707160aee99c15" dependencies = [ "pest", "pest_generator", @@ -7006,22 +7037,22 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75a1ef20bf3193c15ac345acb32e26b3dc3223aff4d77ae4fc5359567683796b" +checksum = "e56094789873daa36164de2e822b3888c6ae4b4f9da555a1103587658c805b1e" dependencies = [ "pest", "pest_meta", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] name = "pest_meta" -version = "2.5.6" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e3b284b1f13a20dc5ebc90aff59a51b8d7137c221131b52a7260c08cbc1cc80" +checksum = "6733073c7cff3d8459fda0e42f13a047870242aed8b509fe98000928975f359e" dependencies = [ "once_cell", "pest", @@ -8236,9 +8267,9 @@ dependencies = [ [[package]] name = "polling" -version = "2.6.0" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e1f879b2998099c2d69ab9605d145d5b661195627eccc680002c4918a7fb6fa" +checksum = "4be1c66a6add46bff50935c313dae30a5030cf8385c5206e8a95e9e9def974aa" dependencies = [ "autocfg", "bitflags", @@ -8247,7 +8278,7 @@ dependencies = [ "libc", "log", "pin-project-lite 0.2.9", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -8377,9 +8408,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] @@ -8617,7 +8648,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.8", + "getrandom 0.2.9", ] [[package]] @@ -8703,14 +8734,23 @@ dependencies = [ "bitflags", ] +[[package]] +name = "redox_syscall" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_users" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "getrandom 0.2.8", - "redox_syscall", + "getrandom 0.2.9", + "redox_syscall 0.2.16", "thiserror", ] @@ -8744,7 +8784,7 @@ checksum = "8d2275aab483050ab2a7364c1a46604865ee7d6906684e08db0f090acf74f9e7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] @@ -8761,9 +8801,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" dependencies = [ "aho-corasick", "memchr", @@ -8781,9 +8821,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.6.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" [[package]] name = "region" @@ -9070,9 +9110,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" [[package]] name = "rustc-hash" @@ -9102,7 +9142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "938a344304321a9da4973b9ff4f9f8db9caf4597dfd9dda6a60b523340a0fff0" dependencies = [ "bitflags", - "errno", + "errno 0.2.8", "io-lifetimes 0.5.3", "libc", "linux-raw-sys 0.0.42", @@ -9116,7 +9156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "727a1a6d65f786ec22df8a81ca3121107f235970dc1705ed681d3e6e8b9cd5f9" dependencies = [ "bitflags", - "errno", + "errno 0.2.8", "io-lifetimes 0.7.5", "libc", "linux-raw-sys 0.0.46", @@ -9125,16 +9165,16 @@ dependencies = [ [[package]] name = "rustix" -version = "0.36.10" +version = "0.37.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fe885c3a125aa45213b68cc1472a49880cb5923dc23f522ad2791b882228778" +checksum = "85597d61f83914ddeba6a47b3b8ffe7365107221c2e557ed94426489fefb5f77" dependencies = [ "bitflags", - "errno", - "io-lifetimes 1.0.8", + "errno 0.3.1", + "io-lifetimes 1.0.10", "libc", - "linux-raw-sys 0.1.4", - "windows-sys 0.45.0", + "linux-raw-sys 0.3.1", + "windows-sys 0.48.0", ] [[package]] @@ -10238,9 +10278,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.3.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "001cf62ece89779fd16105b5f515ad0e5cedcd5440d3dd806bb067978e7c3608" +checksum = "0cfdffd972d76b22f3d7f81c8be34b2296afd3a25e0a547bd9abe340a4dbbe97" dependencies = [ "bitvec", "cfg-if 1.0.0", @@ -10252,9 +10292,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.3.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "303959cf613a6f6efd19ed4b4ad5bf79966a13352716299ad532cfb115f4205c" +checksum = "61fa974aea2d63dd18a4ec3a49d59af9f34178c73a4f56d2f18205628d00681e" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -10332,7 +10372,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08da66b8b0965a5555b6bd6639e68ccba85e1e2506f5fbb089e93f8a04e1a2d1" dependencies = [ "der", - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", "zeroize", ] @@ -10423,29 +10463,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.157" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707de5fcf5df2b5788fca98dd7eab490bc2fd9b7ef1404defc462833b83f25ca" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.157" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78997f4555c22a7971214540c4a661291970619afd56de19f77e0de86296e1e5" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] name = "serde_json" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c533a59c9d8a93a09c6ab31f0fd5e5f4dd1b8fc9434804029839884765d04ea" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -10512,9 +10552,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" +checksum = "54c2bb1a323307527314a36bfb73f24febb08ce2b8a554bf4ffd6f51ad15198c" dependencies = [ "digest 0.10.6", "keccak", @@ -11594,9 +11634,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.2" +version = "2.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59d3276aee1fa0c33612917969b5172b5be2db051232a6e4826f1a1a9191b045" +checksum = "fcf316d5356ed6847742d036f8a39c3b8435cac10bd528a4bd461928a6ab34d5" dependencies = [ "proc-macro2", "quote", @@ -11650,15 +11690,15 @@ checksum = "8ae9980cab1db3fceee2f6c6f643d5d8de2997c58ee8d25fb0cc8a9e9e7348e5" [[package]] name = "tempfile" -version = "3.4.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if 1.0.0", "fastrand", - "redox_syscall", - "rustix 0.36.10", - "windows-sys 0.42.0", + "redox_syscall 0.3.5", + "rustix 0.37.11", + "windows-sys 0.45.0", ] [[package]] @@ -11681,18 +11721,18 @@ dependencies = [ [[package]] name = "test-case" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "679b019fb241da62cc449b33b224d19ebe1c6767b495569765115dd7f7f9fba4" +checksum = "2a1d6e7bde536b0412f20765b76e921028059adfd1b90d8974d33fd3c91b25df" dependencies = [ - "test-case-macros 3.0.0", + "test-case-macros 3.1.0", ] [[package]] name = "test-case-core" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72dc21b5887f4032c4656502d085dc28f2afbb686f25f216472bb0526f4b1b88" +checksum = "d10394d5d1e27794f772b6fc854c7e91a2dc26e2cbf807ad523370c2a59c0cee" dependencies = [ "cfg-if 1.0.0", "proc-macro-error", @@ -11716,9 +11756,9 @@ dependencies = [ [[package]] name = "test-case-macros" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3786898e0be151a96f730fd529b0e8a10f5990fa2a7ea14e37ca27613c05190" +checksum = "eeb9a44b1c6a54c1ba58b152797739dba2a83ca74e18168a68c980eb142f9404" dependencies = [ "proc-macro-error", "proc-macro2", @@ -11730,7 +11770,7 @@ dependencies = [ [[package]] name = "test-utils" version = "1.1.0" -source = "git+https://github.com/galacticcouncil/warehouse?rev=a6085a6e0b435607403e0ff890fc61fab796fb46#a6085a6e0b435607403e0ff890fc61fab796fb46" +source = "git+https://github.com/galacticcouncil/warehouse?rev=070a34512258c7dad2e5edd7fd9830a06060c9b6#070a34512258c7dad2e5edd7fd9830a06060c9b6" dependencies = [ "frame-system", "pretty_assertions", @@ -11780,6 +11820,7 @@ dependencies = [ "pallet-currencies", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-genesis-history", @@ -11856,7 +11897,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.2", + "syn 2.0.14", ] [[package]] @@ -11955,14 +11996,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "parking_lot 0.12.1", @@ -11975,13 +12015,13 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.14", ] [[package]] @@ -12038,9 +12078,9 @@ checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" [[package]] name = "toml_edit" -version = "0.19.7" +version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc18466501acd8ac6a3f615dd29a3438f8ca6bb3b19537138b3106e575621274" +checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" dependencies = [ "indexmap", "toml_datetime", @@ -12319,9 +12359,9 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d502c968c6a838ead8e69b2ee18ec708802f99db92a0d156705ec9ef801993b" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" @@ -12356,7 +12396,7 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f214e8f697e925001e66ec2c6e37a4ef93f0f78c2eed7814394e10c62025b05" dependencies = [ - "generic-array 0.14.6", + "generic-array 0.14.7", "subtle", ] @@ -12970,18 +13010,27 @@ dependencies = [ "windows_x86_64_msvc 0.34.0", ] +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] @@ -12991,7 +13040,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -13000,21 +13058,42 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.2", "windows_aarch64_msvc 0.42.2", "windows_i686_gnu 0.42.2", "windows_i686_msvc 0.42.2", "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.2", "windows_x86_64_msvc 0.42.2", ] +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.34.0" @@ -13027,6 +13106,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.34.0" @@ -13039,6 +13124,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.34.0" @@ -13051,6 +13142,12 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.34.0" @@ -13063,12 +13160,24 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.34.0" @@ -13081,11 +13190,17 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winnow" -version = "0.3.6" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d020b441f92996c80d94ae9166e8501e59c7bb56121189dc9eab3bd8216966" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" dependencies = [ "memchr", ] @@ -13230,23 +13345,22 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zeroize" -version = "1.5.7" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.3.3" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bf07cb3e50ea2003396695d58bf46bc9887a1f362260446fad6bc4e79bd36c" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", - "synstructure", + "syn 2.0.14", ] [[package]] @@ -13270,9 +13384,9 @@ dependencies = [ [[package]] name = "zstd-sys" -version = "2.0.7+zstd.1.5.4" +version = "2.0.8+zstd.1.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" +checksum = "5556e6ee25d32df2586c098bbfa278803692a20d0ab9565e049480d52707ec8c" dependencies = [ "cc", "libc", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 89dab7300..73c289fa5 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -20,14 +20,14 @@ pallet-circuit-breaker = { path = "../pallets/circuit-breaker",default-features # HydraDX dependencies pallet-omnipool-liquidity-mining = { path = "../pallets/omnipool-liquidity-mining", default-features = true} -pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-duster = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} +pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-duster = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } @@ -112,7 +112,7 @@ remote-externalities = { git = "https://github.com/paritytech/substrate", branch [dev-dependencies] hex-literal = "0.3.1" pretty_assertions = "1.2.1" -pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46" } +pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6" } xcm-emulator = { git = "https://github.com/shaunxw/xcm-simulator", rev = "0460d04c798028e7bef82c907082e11753ed173b" } [features] diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index a56bbe0f3..92bd3ebd4 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -28,15 +28,15 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- pallet-omnipool = { path = "../omnipool", default-features = false } # Warehouse -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } [dev-dependencies] pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29" } orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29" } orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29" } -hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "bcb75f1c2b4f1d859ff133ca663539c59d1ed910" } +hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "2fc83960a78bef9742551c78ae0264aa146d16b2", default-features = false } -test-utils = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +test-utils = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } pretty_assertions = "1.2.1" test-case = "3.0.0" diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index 8e4e9bb37..f12a751cb 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -32,11 +32,11 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } # Warehouse -pallet-liquidity-mining = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +pallet-liquidity-mining = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } -hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "bcb75f1c2b4f1d859ff133ca663539c59d1ed910", default-features = false } +hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "2fc83960a78bef9742551c78ae0264aa146d16b2", default-features = false } # third party primitive-types = { version = "0.12.0", default-features = false } @@ -54,7 +54,7 @@ sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot- orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } proptest = "1.0.0" pretty_assertions = "1.2.1" -test-utils = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +test-utils = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } [features] default = ["std"] diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index d3d0b0511..2ed8ae9f2 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -29,9 +29,9 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk orml-traits = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } # Warehouse -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } -hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "bcb75f1c2b4f1d859ff133ca663539c59d1ed910", default-features = false } +hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "2fc83960a78bef9742551c78ae0264aa146d16b2", default-features = false } # third party primitive-types = { version = "0.12.0", default-features = false } diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index db8992ada..74a3dda91 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -80,7 +80,7 @@ use sp_std::prelude::*; use frame_support::traits::tokens::nonfungibles::{Create, Inspect, Mutate}; use hydra_dx_math::omnipool::types::{AssetStateChange, BalanceUpdate, HubTradeStateChange, TradeStateChange, I129}; use hydradx_traits::Registry; -use orml_traits::MultiCurrency; +use orml_traits::{GetByKey, MultiCurrency}; use scale_info::TypeInfo; use sp_runtime::{ArithmeticError, DispatchError, FixedPointNumber, FixedU128, Permill}; @@ -115,6 +115,7 @@ pub mod pallet { use frame_system::pallet_prelude::*; use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::omnipool::types::{BalanceUpdate, I129}; + use orml_traits::GetByKey; use sp_runtime::ArithmeticError; #[pallet::pallet] @@ -160,13 +161,8 @@ pub mod pallet { #[pallet::constant] type StableCoinAssetId: Get; - /// Protocol fee - #[pallet::constant] - type ProtocolFee: Get; - - /// Asset fee - #[pallet::constant] - type AssetFee: Get; + /// Asset and Protocol Fee for given asset + type Fee: GetByKey; /// Minimum trading limit #[pallet::constant] @@ -1032,12 +1028,14 @@ pub mod pallet { let current_imbalance = >::get(); + let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); + let state_changes = hydra_dx_math::omnipool::calculate_sell_state_changes( &(&asset_in_state).into(), &(&asset_out_state).into(), amount, - T::AssetFee::get(), - T::ProtocolFee::get(), + asset_fee, + protocol_fee, current_imbalance.value, ) .ok_or(ArithmeticError::Overflow)?; @@ -1207,12 +1205,13 @@ pub mod pallet { let current_imbalance = >::get(); + let (asset_fee, protocol_fee) = T::Fee::get(&asset_in); let state_changes = hydra_dx_math::omnipool::calculate_buy_state_changes( &(&asset_in_state).into(), &(&asset_out_state).into(), amount, - T::AssetFee::get(), - T::ProtocolFee::get(), + asset_fee, + protocol_fee, current_imbalance.value, ) .ok_or(ArithmeticError::Overflow)?; @@ -1611,10 +1610,12 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); + let (asset_fee, _) = T::Fee::get(&asset_out); + let state_changes = hydra_dx_math::omnipool::calculate_sell_hub_state_changes( &(&asset_state).into(), amount, - T::AssetFee::get(), + asset_fee, I129 { value: current_imbalance.value, negative: current_imbalance.negative, @@ -1707,10 +1708,12 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); + let (asset_fee, _) = T::Fee::get(&asset_out); + let state_changes = hydra_dx_math::omnipool::calculate_buy_for_hub_asset_state_changes( &(&asset_state).into(), amount, - T::AssetFee::get(), + asset_fee, I129 { value: current_imbalance.value, negative: current_imbalance.negative, diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 77d573153..65abc7ca9 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -17,8 +17,8 @@ codec = { package = "parity-scale-codec", version = "3.1.5", default-features = scale-info = { version = "2.1.1", default-features = false, features = ["derive"] } primitives = {path = '../../primitives', default-features = false} pallet-omnipool = {path = '../../pallets/omnipool', default-features = false} -pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } pallet-circuit-breaker = {path = '../../pallets/circuit-breaker', default-features = false} pallet-omnipool-liquidity-mining = {path = '../../pallets/omnipool-liquidity-mining', default-features = false} @@ -42,15 +42,16 @@ pallet-scheduler = { git = "https://github.com/paritytech/substrate", branch = " pallet-timestamp = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } pallet-balances = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "bcb75f1c2b4f1d859ff133ca663539c59d1ed910", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +hydra-dx-math = { git = "https://github.com/galacticcouncil/HydraDX-math", rev = "2fc83960a78bef9742551c78ae0264aa146d16b2", default-features = false } pallet-claims = { path = '../../pallets/claims', default-features = false } -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-dynamic-fees = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } orml-vesting = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } diff --git a/runtime/common/src/adapters.rs b/runtime/common/src/adapters.rs index 5db560eb4..ea558131a 100644 --- a/runtime/common/src/adapters.rs +++ b/runtime/common/src/adapters.rs @@ -2,8 +2,8 @@ use core::marker::PhantomData; use frame_support::{traits::Get, weights::Weight}; use hydra_dx_math::omnipool::types::BalanceUpdate; -use hydradx_traits::AggregatedPriceOracle; use hydradx_traits::{liquidity_mining::PriceAdjustment, OnLiquidityChangedHandler, OnTradeHandler, OraclePeriod}; +use hydradx_traits::{AggregatedOracle, AggregatedPriceOracle}; use pallet_circuit_breaker::WeightInfo; use pallet_ema_oracle::OnActivityHandler; use pallet_ema_oracle::Price; @@ -188,3 +188,42 @@ where FixedU128::checked_from_rational(price.n, price.d).ok_or(ArithmeticError::Overflow.into()) } } + +// Dynamic fees volume adapter +pub struct OracleVolume(Balance, Balance); + +impl pallet_dynamic_fees::traits::Volume for OracleVolume { + fn amount_in(&self) -> Balance { + self.0 + } + + fn amount_out(&self) -> Balance { + self.1 + } +} + +pub struct OracleAssetVolumeProvider(PhantomData<(Runtime, Lrna, Period)>); + +impl pallet_dynamic_fees::traits::VolumeProvider + for OracleAssetVolumeProvider +where + Runtime: pallet_ema_oracle::Config, + Lrna: Get, + Period: Get, +{ + type Volume = OracleVolume; + + fn asset_volume(asset_id: AssetId) -> Option { + let entry = + pallet_ema_oracle::Pallet::::get_entry(asset_id, Lrna::get(), Period::get(), OMNIPOOL_SOURCE) + .ok()?; + Some(OracleVolume(entry.volume.a_in, entry.volume.a_out)) + } + + fn asset_liquidity(asset_id: AssetId) -> Option { + let entry = + pallet_ema_oracle::Pallet::::get_entry(asset_id, Lrna::get(), Period::get(), OMNIPOOL_SOURCE) + .ok()?; + Some(entry.liquidity.a) + } +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index dd5182c19..67a5cab8d 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -26,14 +26,15 @@ use frame_support::traits::{Contains, EitherOfDiverse, LockIdentifier}; use frame_support::{parameter_types, weights::Pays, PalletId, RuntimeDebug}; use frame_system::EnsureRoot; use hydradx_traits::oracle::{OraclePeriod, Source}; +use pallet_dynamic_fees::types::FeeParams; pub use pallet_transaction_payment::Multiplier; pub use primitives::constants::{chain::*, currency::*, time::*}; pub use primitives::{Amount, AssetId, Balance, BlockNumber, CollectionId}; use scale_info::TypeInfo; use sp_runtime::{ generic, - traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, Verify}, - FixedPointNumber, MultiSignature, Perbill, Percent, Permill, Perquintill, + traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, One, Verify, Zero}, + FixedPointNumber, FixedU128, MultiSignature, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; @@ -358,3 +359,20 @@ parameter_types! { pub const OmnipoolLMOraclePeriod: OraclePeriod = OraclePeriod::TenMinutes; pub const OmnipoolLMOracleSource: Source = OMNIPOOL_SOURCE; } + +// Dynamic fees +parameter_types! { + pub AssetFeeParams: FeeParams = FeeParams{ + min_fee: Permill::from_rational(25u32,10000u32), + max_fee: Permill::from_percent(40), + decay: FixedU128::zero(), + amplification: FixedU128::one(), + }; + + pub ProtocolFeeParams: FeeParams = FeeParams{ + min_fee: Permill::from_rational(5u32,10000u32), + max_fee: Permill::from_percent(40), + decay: FixedU128::zero(), + amplification: FixedU128::one(), + }; +} diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ede3b3d14..8c39d9b53 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -50,18 +50,19 @@ pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", b pallet-uniques = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } # Warehouse dependencies -hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-collator-rewards = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-duster = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} +hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-collator-rewards = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-duster = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-dynamic-fees = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} # ORML dependencies orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 0b9269116..ff9c78257 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -53,7 +53,7 @@ use frame_support::{ }, BoundedVec, }; -use hydradx_traits::OraclePeriod; +use hydradx_traits::{OraclePeriod}; use pallet_transaction_multi_payment::{AddTxAssetOnAccount, DepositAll, RemoveTxAssetOnKilled, TransferFees}; use pallet_transaction_payment::TargetedFeeAdjustment; use primitives::{CollectionId, ItemId}; @@ -838,8 +838,7 @@ impl pallet_omnipool::Config for Runtime { type HdxAssetId = NativeAssetId; type HubAssetId = LRNA; type StableCoinAssetId = StableAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; + type Fee = pallet_dynamic_fees::UpdateAndRetrieveFees; type MinimumTradingLimit = MinTradingLimit; type MinimumPoolLiquidity = MinPoolLiquidity; type MaxInRatio = MaxInRatio; @@ -967,6 +966,20 @@ impl pallet_otc::Config for Runtime { type WeightInfo = weights::otc::HydraWeight; } +parameter_types! { + pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::LastBlock; +} + +impl pallet_dynamic_fees::Config for Runtime { + type Event = Event; + type BlockNumberProvider = System; + type Fee = Permill; + type AssetId = AssetId; + type Oracle = adapters::OracleAssetVolumeProvider; + type AssetFeeParameters = AssetFeeParams; + type ProtocolFeeParameters = ProtocolFeeParams; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -1004,6 +1017,7 @@ construct_runtime!( OmnipoolLiquidityMining: pallet_omnipool_liquidity_mining = 63, OTC: pallet_otc = 64, CircuitBreaker: pallet_circuit_breaker = 65, + DynamicFees: pallet_dynamic_fees = 66, // ORML related modules Tokens: orml_tokens = 77, diff --git a/runtime/testing-hydradx/Cargo.toml b/runtime/testing-hydradx/Cargo.toml index f7b255879..6e15967ad 100644 --- a/runtime/testing-hydradx/Cargo.toml +++ b/runtime/testing-hydradx/Cargo.toml @@ -51,18 +51,19 @@ pallet-elections-phragmen = { git = "https://github.com/paritytech/substrate", b pallet-uniques = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } # Warehouse dependencies -hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-collator-rewards = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} -pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-duster = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false } -pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "a6085a6e0b435607403e0ff890fc61fab796fb46", default-features = false} +hydradx-adapters = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +hydradx-traits = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-relaychain-info = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-transaction-multi-payment = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-asset-registry = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-collator-rewards = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-currencies = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-transaction-pause = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-duster = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } +pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-dynamic-fees = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} # ORML dependencies orml-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", branch = "polkadot-v0.9.29", default-features = false } diff --git a/runtime/testing-hydradx/src/lib.rs b/runtime/testing-hydradx/src/lib.rs index bfc08bcc0..655422d83 100644 --- a/runtime/testing-hydradx/src/lib.rs +++ b/runtime/testing-hydradx/src/lib.rs @@ -839,8 +839,7 @@ impl pallet_omnipool::Config for Runtime { type HdxAssetId = NativeAssetId; type HubAssetId = LRNA; type StableCoinAssetId = StableAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; + type Fee = pallet_dynamic_fees::UpdateAndRetrieveFees; type MinimumTradingLimit = MinTradingLimit; type MinimumPoolLiquidity = MinPoolLiquidity; type MaxInRatio = MaxInRatio; @@ -968,6 +967,20 @@ impl pallet_otc::Config for Runtime { type WeightInfo = weights::otc::HydraWeight; } +parameter_types! { + pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::LastBlock; +} + +impl pallet_dynamic_fees::Config for Runtime { + type Event = Event; + type BlockNumberProvider = System; + type Fee = Permill; + type AssetId = AssetId; + type Oracle = adapters::OracleAssetVolumeProvider; + type AssetFeeParameters = AssetFeeParams; + type ProtocolFeeParameters = ProtocolFeeParams; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -1005,6 +1018,7 @@ construct_runtime!( OmnipoolLiquidityMining: pallet_omnipool_liquidity_mining = 63, OTC: pallet_otc = 64, CircuitBreaker: pallet_circuit_breaker = 65, + DynamicFees: pallet_dynamic_fees = 66, // ORML related modules Tokens: orml_tokens = 77, From 605c608b5db196384b66aeab22b794e32eec3225 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 12 Apr 2023 13:02:40 +0200 Subject: [PATCH 02/24] update omnipool tests to reflect fee provider config --- Cargo.lock | 2 +- pallets/omnipool/Cargo.toml | 2 +- pallets/omnipool/src/tests/mock.rs | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 78d1d12d7..6aaf2ddd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6352,7 +6352,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "1.6.9" +version = "2.0.0" dependencies = [ "bitflags", "frame-benchmarking", diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index 2ed8ae9f2..d3cc9efe0 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "1.6.9" +version = "2.0.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/src/tests/mock.rs b/pallets/omnipool/src/tests/mock.rs index 21d35fd4e..f98babf78 100644 --- a/pallets/omnipool/src/tests/mock.rs +++ b/pallets/omnipool/src/tests/mock.rs @@ -169,6 +169,14 @@ parameter_types! { pub FourPercentDiff: Permill = Permill::from_percent(4); } +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} + impl Config for Test { type Event = Event; type AssetId = AssetId; @@ -176,8 +184,6 @@ impl Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -195,6 +201,7 @@ impl Config for Test { EnsurePriceWithin, EnsurePriceWithin, ); + type Fee = FeeProvider; } pub struct ExtBuilder { From cddd84e979a06c83be2f2e90d743d851ea190bb5 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 12 Apr 2023 13:04:37 +0200 Subject: [PATCH 03/24] reformat --- pallets/omnipool/src/tests/mock.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/omnipool/src/tests/mock.rs b/pallets/omnipool/src/tests/mock.rs index f98babf78..ebac587a8 100644 --- a/pallets/omnipool/src/tests/mock.rs +++ b/pallets/omnipool/src/tests/mock.rs @@ -171,7 +171,7 @@ parameter_types! { pub struct FeeProvider; -impl GetByKey for FeeProvider { +impl GetByKey for FeeProvider { fn get(_: &AssetId) -> (Permill, Permill) { (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) } From 063d0b1fd13b3a592c95bafdc4a52ba4ced64811 Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Thu, 13 Apr 2023 10:48:53 +0200 Subject: [PATCH 04/24] Fixed omnipool LM tests --- Cargo.lock | 2 +- pallets/omnipool-liquidity-mining/Cargo.toml | 2 +- pallets/omnipool-liquidity-mining/src/tests/mock.rs | 13 +++++++++---- runtime/hydradx/src/lib.rs | 4 ++-- runtime/testing-hydradx/src/lib.rs | 2 +- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6aaf2ddd8..40c03788c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6380,7 +6380,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.0.0" +version = "2.0.1" dependencies = [ "bitflags", "frame-benchmarking", diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index f12a751cb..0dfba355a 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.0.0" +version = "2.0.1" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index 5226ca1f8..432d4d0e5 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -261,8 +261,6 @@ parameter_types! { pub const DAIAssetId: AssetId = DAI; pub const PositionCollectionId: CollectionId = OMNIPOOL_COLLECTION_ID; - pub ProtocolFee: Permill = PROTOCOL_FEE.with(|v| *v.borrow()); - pub AssetFee: Permill = ASSET_FEE.with(|v| *v.borrow()); pub AssetWeightCap: Permill =ASSET_WEIGHT_CAP.with(|v| *v.borrow()); pub MinAddedLiquidity: Balance = MIN_ADDED_LIQUDIITY.with(|v| *v.borrow()); pub MinTradeAmount: Balance = MIN_TRADE_AMOUNT.with(|v| *v.borrow()); @@ -270,6 +268,14 @@ parameter_types! { pub MaxOutRatio: Balance = MAX_OUT_RATIO.with(|v| *v.borrow()); } +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} + impl pallet_omnipool::Config for Test { type Event = Event; type AssetId = AssetId; @@ -277,8 +283,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -293,6 +297,7 @@ impl pallet_omnipool::Config for Test { type CollectionId = u128; type OmnipoolHooks = (); type PriceBarrier = (); + type Fee = FeeProvider; } pub struct ExtBuilder { diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index ff9c78257..37cb8a16c 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -53,7 +53,7 @@ use frame_support::{ }, BoundedVec, }; -use hydradx_traits::{OraclePeriod}; +use hydradx_traits::OraclePeriod; use pallet_transaction_multi_payment::{AddTxAssetOnAccount, DepositAll, RemoveTxAssetOnKilled, TransferFees}; use pallet_transaction_payment::TargetedFeeAdjustment; use primitives::{CollectionId, ItemId}; @@ -975,7 +975,7 @@ impl pallet_dynamic_fees::Config for Runtime { type BlockNumberProvider = System; type Fee = Permill; type AssetId = AssetId; - type Oracle = adapters::OracleAssetVolumeProvider; + type Oracle = adapters::OracleAssetVolumeProvider; type AssetFeeParameters = AssetFeeParams; type ProtocolFeeParameters = ProtocolFeeParams; } diff --git a/runtime/testing-hydradx/src/lib.rs b/runtime/testing-hydradx/src/lib.rs index 655422d83..13d2de449 100644 --- a/runtime/testing-hydradx/src/lib.rs +++ b/runtime/testing-hydradx/src/lib.rs @@ -976,7 +976,7 @@ impl pallet_dynamic_fees::Config for Runtime { type BlockNumberProvider = System; type Fee = Permill; type AssetId = AssetId; - type Oracle = adapters::OracleAssetVolumeProvider; + type Oracle = adapters::OracleAssetVolumeProvider; type AssetFeeParameters = AssetFeeParams; type ProtocolFeeParameters = ProtocolFeeParams; } From fa978f2a62dce7317605e28ea2129d1be7ac4406 Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Thu, 13 Apr 2023 10:53:51 +0200 Subject: [PATCH 05/24] Fixed circuit-breaker tests --- Cargo.lock | 2 +- pallets/circuit-breaker/Cargo.toml | 2 +- pallets/circuit-breaker/src/tests/mock.rs | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40c03788c..74ab14689 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5830,7 +5830,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" -version = "1.1.2" +version = "1.1.3" dependencies = [ "frame-benchmarking", "frame-support", diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index 92bd3ebd4..718e6c13d 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-circuit-breaker" -version = "1.1.2" +version = "1.1.3" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/circuit-breaker/src/tests/mock.rs b/pallets/circuit-breaker/src/tests/mock.rs index ac3a4977e..bb4208cca 100644 --- a/pallets/circuit-breaker/src/tests/mock.rs +++ b/pallets/circuit-breaker/src/tests/mock.rs @@ -22,7 +22,7 @@ pub use frame_support::{assert_noop, assert_ok, parameter_types}; use frame_system::EnsureRoot; use hydra_dx_math::omnipool::types::BalanceUpdate; -use orml_traits::parameter_type_with_key; +use orml_traits::{parameter_type_with_key, GetByKey}; use sp_core::H256; use sp_runtime::traits::{ConstU128, ConstU32}; use sp_runtime::DispatchResult; @@ -194,8 +194,6 @@ parameter_types! { pub const DAIAssetId: AssetId = DAI; pub const PosiitionCollectionId: u32= 1000; - pub ProtocolFee: Permill = PROTOCOL_FEE.with(|v| *v.borrow()); - pub AssetFee: Permill = ASSET_FEE.with(|v| *v.borrow()); pub AssetWeightCap: Permill =ASSET_WEIGHT_CAP.with(|v| *v.borrow()); pub MinAddedLiquidity: Balance = MIN_ADDED_LIQUDIITY.with(|v| *v.borrow()); pub MinTradeAmount: Balance = MIN_TRADE_AMOUNT.with(|v| *v.borrow()); @@ -204,6 +202,14 @@ parameter_types! { pub const TVLCap: Balance = Balance::MAX; } +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} + impl pallet_omnipool::Config for Test { type Event = Event; type AssetId = AssetId; @@ -211,8 +217,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -227,6 +231,7 @@ impl pallet_omnipool::Config for Test { type CollectionId = u32; type OmnipoolHooks = CircuitBreakerHooks; type PriceBarrier = (); + type Fee = FeeProvider; } pub struct CircuitBreakerHooks(PhantomData); From aee3f1d8ccb7a9b4716926719d17e0fa53f40640 Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Thu, 13 Apr 2023 12:40:18 +0200 Subject: [PATCH 06/24] increased recursion limit for testing runtime and enabled dynamic fees try-runtime --- runtime/hydradx/Cargo.toml | 1 + runtime/testing-hydradx/src/lib.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 8c39d9b53..a66a082df 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -290,4 +290,5 @@ try-runtime= [ "pallet-circuit-breaker/try-runtime", "pallet-ema-oracle/try-runtime", "pallet-otc/try-runtime", + "pallet-dynamic-fees/try-runtime", ] diff --git a/runtime/testing-hydradx/src/lib.rs b/runtime/testing-hydradx/src/lib.rs index 13d2de449..7b7eb75ea 100644 --- a/runtime/testing-hydradx/src/lib.rs +++ b/runtime/testing-hydradx/src/lib.rs @@ -16,8 +16,8 @@ // limitations under the License. #![cfg_attr(not(feature = "std"), no_std)] -// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256. -#![recursion_limit = "256"] +// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 512. +#![recursion_limit = "512"] // Make the WASM binary available. #[cfg(feature = "std")] From a2926137508ed01aa84c0dd7fefedc35a6f148be Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Thu, 13 Apr 2023 15:29:44 +0200 Subject: [PATCH 07/24] WIP dynamic-fees integration tests --- Cargo.lock | 2 + integration-tests/Cargo.toml | 2 + integration-tests/src/dynamic_fees.rs | 393 ++++++++++++++++++++++++++ integration-tests/src/lib.rs | 1 + 4 files changed, 398 insertions(+) create mode 100644 integration-tests/src/dynamic_fees.rs diff --git a/Cargo.lock b/Cargo.lock index 74ab14689..f35a8979e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5996,6 +5996,7 @@ dependencies = [ "orml-traits", "parity-scale-codec", "scale-info", + "serde", "sp-core", "sp-runtime", "sp-std", @@ -9058,6 +9059,7 @@ dependencies = [ "pallet-currencies", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-liquidity-mining", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 73c289fa5..02d19d317 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -28,6 +28,7 @@ pallet-duster = { git = "https://github.com/galacticcouncil/warehouse",rev = "07 pallet-ema-oracle = { git = "https://github.com/galacticcouncil/warehouse",rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} warehouse-liquidity-mining = { package="pallet-liquidity-mining", git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false } pallet-otc = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} +pallet-dynamic-fees = { git = "https://github.com/galacticcouncil/warehouse", rev = "070a34512258c7dad2e5edd7fd9830a06060c9b6", default-features = false} pallet-treasury = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } pallet-democracy = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.29", default-features = false } @@ -173,4 +174,5 @@ std = [ "pallet-collator-selection/std", "pallet-authorship/std", "hydradx-traits/std", + "pallet-dynamic-fees/std", ] diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs new file mode 100644 index 000000000..10ae347f0 --- /dev/null +++ b/integration-tests/src/dynamic_fees.rs @@ -0,0 +1,393 @@ +#![cfg(test)] + +use crate::{oracle::hydradx_run_to_block, polkadot_test_net::*}; +use frame_support::assert_ok; +use pallet_dynamic_fees::types::FeeEntry; +use primitives::AssetId; +use sp_runtime::{FixedU128, Permill}; +use xcm_emulator::TestExt; + +const DOT_UNITS: u128 = 10_000_000_000; +const BTC_UNITS: u128 = 10_000_000; +const ETH_UNITS: u128 = 1_000_000_000_000_000_000; + +#[test] +fn fees_should_initialize_lazyly_when_sell_happen() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + assert!(hydradx_runtime::DynamicFees::current_fees(HDX).is_none()); + + //Act + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + //Assert + assert_eq!( + hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), + FeeEntry { + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.0005_f64), + timestamp: 10_u32 + } + ); + }); +} + +#[test] +fn fees_should_initialize_lazyly_when_buy_happen() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + assert!(hydradx_runtime::DynamicFees::current_fees(HDX).is_none()); + + set_balance(DAVE.into(), HDX, 1_000 * UNITS as i128); + //Act + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + //Assert + assert_eq!( + hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), + FeeEntry { + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.0005_f64), + timestamp: 10_u32 + } + ); + }); +} + +#[test] +fn fees_should_change_when_buys_happen_in_different_blocks() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + set_balance(DAVE.into(), HDX, 1_000 * UNITS as i128); + + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + let old_fees = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + + //Act + hydradx_run_to_block(11); + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + //Assert + let current_fee = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + assert_ne!(current_fee, old_fees); + assert_eq!( + current_fee, + FeeEntry { + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.000957_f64), + timestamp: 11_u32 + } + ); + }); +} + +#[test] +fn fees_should_change_when_sell_happen_in_different_blocks() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + let old_fees = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + + //Act + hydradx_run_to_block(11); + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + //Assert + let current_fee = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + assert_ne!(current_fee, old_fees); + assert_eq!( + current_fee, + FeeEntry { + asset_fee: Permill::from_float(0.002954_f64), + protocol_fee: Permill::from_float(0.0005_f64), + timestamp: 11_u32 + } + ); + }); +} + +#[test] +fn fees_should_change_when_trades_happen_in_different_blocks() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + let old_fees = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + + //Act + hydradx_run_to_block(11); + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + //Assert + let current_fee = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + assert_ne!(current_fee, old_fees); + assert_eq!( + current_fee, + FeeEntry { + asset_fee: Permill::from_float(0.002954_f64), + protocol_fee: Permill::from_float(0.0005_f64), + timestamp: 11_u32 + } + ); + }); +} + +#[test] +fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + init_oracle(); + hydradx_run_to_block(10); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + let old_fees = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + set_balance(DAVE.into(), HDX, 1_000 * UNITS as i128); + + //Act & assert + hydradx_run_to_block(11); + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + let current_fee = hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(); + assert_ne!(current_fee, old_fees); + assert_eq!( + current_fee, + FeeEntry { + asset_fee: Permill::from_float(0.002954_f64), + protocol_fee: Permill::from_float(0.0005_f64), + timestamp: 11_u32 + } + ); + + //NOTE: second trade in the same block should not change fees + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX, + )); + + assert_eq!(hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), current_fee); + + //NOTE: second trade in the same block should not change fees + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + assert_eq!(hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), current_fee); + }); +} + +fn set_balance(who: hydradx_runtime::AccountId, currency: AssetId, amount: i128) { + assert_ok!(hydradx_runtime::Currencies::update_balance( + hydradx_runtime::Origin::root(), + who, + currency, + amount, + )); +} + +fn init_omnipool() { + let native_price = FixedU128::from_inner(1201500000000000); + let stable_price = FixedU128::from_inner(45_000_000_000); + + assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( + hydradx_runtime::Origin::root(), + 522_222_000_000_000_000_000_000, + )); + + assert_ok!(hydradx_runtime::Omnipool::initialize_pool( + hydradx_runtime::Origin::root(), + stable_price, + native_price, + Permill::from_percent(100), + Permill::from_percent(10) + )); + + let dot_price = FixedU128::from_inner(25_650_000_000_000_000_000); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::Origin::root(), + DOT, + dot_price, + Permill::from_percent(100), + AccountId::from(BOB), + )); + + let eth_price = FixedU128::from_inner(71_145_071_145_071); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::Origin::root(), + ETH, + eth_price, + Permill::from_percent(100), + AccountId::from(BOB), + )); + + let btc_price = FixedU128::from_inner(9_647_109_647_109_650_000_000_000); + assert_ok!(hydradx_runtime::Omnipool::add_token( + hydradx_runtime::Origin::root(), + BTC, + btc_price, + Permill::from_percent(100), + AccountId::from(BOB), + )); +} + +/// This function executes one sell and buy with HDX for all assets in the omnipool. This is necessary to +/// oracle have a prices for the assets. +/// NOTE: It's necessary to change parachain block to oracle have prices. +fn init_oracle() { + let trader = DAVE; + + set_balance(trader.into(), HDX, 1_000 * UNITS as i128); + set_balance(trader.into(), DOT, 1_000 * DOT_UNITS as i128); + set_balance(trader.into(), ETH, 1_000 * ETH_UNITS as i128); + set_balance(trader.into(), BTC, 1_000 * BTC_UNITS as i128); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + u128::MAX + )); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + ETH, + HDX, + 2 * ETH_UNITS, + 0, + )); + + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + ETH, + HDX, + 2 * ETH_UNITS, + u128::MAX + )); + + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + BTC, + HDX, + 2 * BTC_UNITS, + 0, + )); + + assert_ok!(hydradx_runtime::Omnipool::buy( + hydradx_runtime::Origin::signed(DAVE.into()), + BTC, + HDX, + 2 * BTC_UNITS, + u128::MAX + )); +} diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index 80e7709cd..8d4208410 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -3,6 +3,7 @@ mod circuit_breaker; mod cross_chain_transfer; mod dust; mod dust_removal_whitelist; +mod dynamic_fees; mod non_native_fee; mod omnipool_init; mod omnipool_liquidity_mining; From 1704d8c44e8544638d6477a263bc05542af4751e Mon Sep 17 00:00:00 2001 From: martinfridrich Date: Thu, 11 May 2023 11:24:59 +0200 Subject: [PATCH 08/24] added asset_fee to omnipool::sel/buyExecuted events --- pallets/omnipool/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index 74a3dda91..19c5c959f 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -261,6 +261,7 @@ pub mod pallet { asset_out: T::AssetId, amount_in: Balance, amount_out: Balance, + asset_fee: Permill, }, /// Buy trade executed. BuyExecuted { @@ -269,6 +270,7 @@ pub mod pallet { asset_out: T::AssetId, amount_in: Balance, amount_out: Balance, + asset_fee: Permill, }, /// LP Position was created and NFT instance minted. PositionCreated { @@ -1133,6 +1135,7 @@ pub mod pallet { asset_out, amount_in: amount, amount_out: *state_changes.asset_out.delta_reserve, + asset_fee, }); Ok(()) @@ -1314,6 +1317,7 @@ pub mod pallet { asset_out, amount_in: *state_changes.asset_in.delta_reserve, amount_out: *state_changes.asset_out.delta_reserve, + asset_fee, }); Ok(()) @@ -1670,6 +1674,7 @@ impl Pallet { asset_out, amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, + asset_fee, }); T::OmnipoolHooks::on_hub_asset_trade(origin, info)?; @@ -1767,6 +1772,7 @@ impl Pallet { asset_out, amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, + asset_fee, }); T::OmnipoolHooks::on_hub_asset_trade(origin, info)?; From 790aca860cc7908d373dfe90a764eea031ee1fc5 Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Mon, 5 Jun 2023 15:36:32 +0200 Subject: [PATCH 09/24] Update integration-tests/src/dynamic_fees.rs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jakub Pánik --- integration-tests/src/dynamic_fees.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs index 10ae347f0..af841cb7f 100644 --- a/integration-tests/src/dynamic_fees.rs +++ b/integration-tests/src/dynamic_fees.rs @@ -45,7 +45,7 @@ fn fees_should_initialize_lazyly_when_sell_happen() { } #[test] -fn fees_should_initialize_lazyly_when_buy_happen() { +fn fees_should_initialize_lazily_when_buy_happen() { TestNet::reset(); Hydra::execute_with(|| { From 330676f4085f5dd24a8208b693255b7d00e592a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20P=C3=A1nik?= Date: Mon, 5 Jun 2023 23:21:56 +0200 Subject: [PATCH 10/24] review --- integration-tests/src/dynamic_fees.rs | 37 ++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs index af841cb7f..12863ee03 100644 --- a/integration-tests/src/dynamic_fees.rs +++ b/integration-tests/src/dynamic_fees.rs @@ -11,8 +11,39 @@ const DOT_UNITS: u128 = 10_000_000_000; const BTC_UNITS: u128 = 10_000_000; const ETH_UNITS: u128 = 1_000_000_000_000_000_000; + +#[test] +fn fees_should_work_when_oracle_not_initialized() { + TestNet::reset(); + + Hydra::execute_with(|| { + //Arrange + init_omnipool(); + + let trader = DAVE; + + set_balance(trader.into(), DOT, 1_000 * DOT_UNITS as i128); + + assert!(hydradx_runtime::DynamicFees::current_fees(HDX).is_none()); + + //Act + assert_ok!(hydradx_runtime::Omnipool::sell( + hydradx_runtime::Origin::signed(DAVE.into()), + DOT, + HDX, + 2 * DOT_UNITS, + 0, + )); + + // REVIEW: IS THIS CORRECT? + // If yes, are you testing this correctly in other tests? + // looks like you are not testing the change or maybe this is a special case when not initialized? + assert!(hydradx_runtime::DynamicFees::current_fees(HDX).is_none()); + }); +} + #[test] -fn fees_should_initialize_lazyly_when_sell_happen() { +fn fees_should_initialize_lazily_when_sell_happens() { TestNet::reset(); Hydra::execute_with(|| { @@ -45,7 +76,7 @@ fn fees_should_initialize_lazyly_when_sell_happen() { } #[test] -fn fees_should_initialize_lazily_when_buy_happen() { +fn fees_should_initialize_lazily_when_buy_happens() { TestNet::reset(); Hydra::execute_with(|| { @@ -125,7 +156,7 @@ fn fees_should_change_when_buys_happen_in_different_blocks() { } #[test] -fn fees_should_change_when_sell_happen_in_different_blocks() { +fn fees_should_change_when_sells_happen_in_different_blocks() { TestNet::reset(); Hydra::execute_with(|| { From 5822db1283558a83e9ca7ec5e35bc48c7711b154 Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Tue, 6 Jun 2023 12:40:38 +0200 Subject: [PATCH 11/24] integrate dyn fees - again --- Cargo.lock | 3 ++ pallets/omnipool/src/router_execution.rs | 22 +++++++++---- runtime/common/Cargo.toml | 1 + runtime/common/src/adapters.rs | 41 +++++++++++++++++++++++- runtime/common/src/lib.rs | 22 +++++++++++-- runtime/hydradx/Cargo.toml | 1 + runtime/hydradx/src/lib.rs | 18 +++++++++-- runtime/testing-hydradx/Cargo.toml | 1 + runtime/testing-hydradx/src/lib.rs | 18 +++++++++-- 9 files changed, 113 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index feb07c7d2..bd3839288 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1218,6 +1218,7 @@ dependencies = [ "pallet-currencies", "pallet-dca", "pallet-democracy", + "pallet-dynamic-fees", "pallet-ema-oracle", "pallet-identity", "pallet-liquidity-mining", @@ -3880,6 +3881,7 @@ dependencies = [ "pallet-dca", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-genesis-history", @@ -13087,6 +13089,7 @@ dependencies = [ "pallet-dca", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-genesis-history", diff --git a/pallets/omnipool/src/router_execution.rs b/pallets/omnipool/src/router_execution.rs index ac6ff6421..f275ddc89 100644 --- a/pallets/omnipool/src/router_execution.rs +++ b/pallets/omnipool/src/router_execution.rs @@ -4,7 +4,7 @@ use frame_system::pallet_prelude::OriginFor; use hydra_dx_math::omnipool::types::I129; use hydradx_traits::router::{ExecutorError, PoolType, TradeExecution}; -use orml_traits::MultiCurrency; +use orml_traits::{GetByKey, MultiCurrency}; use sp_runtime::traits::Get; use sp_runtime::{ArithmeticError, DispatchError}; @@ -32,10 +32,12 @@ impl TradeExecution, T::AccountId, T::AssetId, Balance> let current_hub_asset_liquidity = T::Currency::free_balance(T::HubAssetId::get(), &Self::protocol_account()); + let (asset_fee, _) = T::Fee::get(&asset_out); + let state_changes = hydra_dx_math::omnipool::calculate_sell_hub_state_changes( &(&asset_out_state).into(), amount_in, - T::AssetFee::get(), + asset_fee, I129 { value: current_imbalance.value, negative: current_imbalance.negative, @@ -47,13 +49,15 @@ impl TradeExecution, T::AccountId, T::AssetId, Balance> return Ok(*state_changes.asset.delta_reserve); } + let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); + let asset_in_state = Self::load_asset_state(asset_in).map_err(ExecutorError::Error)?; let state_changes = hydra_dx_math::omnipool::calculate_sell_state_changes( &(&asset_in_state).into(), &(&asset_out_state).into(), amount_in, - T::AssetFee::get(), - T::ProtocolFee::get(), + asset_fee, + protocol_fee, current_imbalance.value, ) .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))?; @@ -81,10 +85,12 @@ impl TradeExecution, T::AccountId, T::AssetId, Balance> let current_hub_asset_liquidity = T::Currency::free_balance(T::HubAssetId::get(), &Self::protocol_account()); + let (asset_fee, _) = T::Fee::get(&asset_out); + let state_changes = hydra_dx_math::omnipool::calculate_buy_for_hub_asset_state_changes( &(&asset_out_state).into(), amount_out, - T::AssetFee::get(), + asset_fee, I129 { value: current_imbalance.value, negative: current_imbalance.negative, @@ -98,12 +104,14 @@ impl TradeExecution, T::AccountId, T::AssetId, Balance> let asset_in_state = Self::load_asset_state(asset_in).map_err(ExecutorError::Error)?; + let (asset_fee, protocol_fee) = T::Fee::get(&asset_in); + let state_changes = hydra_dx_math::omnipool::calculate_buy_state_changes( &(&asset_in_state).into(), &(&asset_out_state).into(), amount_out, - T::AssetFee::get(), - T::ProtocolFee::get(), + asset_fee, + protocol_fee, current_imbalance.value, ) .ok_or_else(|| ExecutorError::Error(ArithmeticError::Overflow.into()))?; diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 94f6ae074..81a6cfc4e 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -23,6 +23,7 @@ pallet-circuit-breaker = { workspace = true } pallet-omnipool-liquidity-mining = { workspace = true } pallet-claims = { workspace = true } pallet-dca = { workspace = true } +pallet-dynamic-fees = { workspace = true } hydra-dx-math = { workspace = true } diff --git a/runtime/common/src/adapters.rs b/runtime/common/src/adapters.rs index e70ef160c..a80ef6961 100644 --- a/runtime/common/src/adapters.rs +++ b/runtime/common/src/adapters.rs @@ -9,9 +9,9 @@ use hydra_dx_math::ema::EmaPrice; use hydra_dx_math::omnipool::types::BalanceUpdate; use hydra_dx_math::support::rational::round_to_rational; use hydra_dx_math::support::rational::Rounding; -use hydradx_traits::AggregatedPriceOracle; use hydradx_traits::PriceOracle; use hydradx_traits::{liquidity_mining::PriceAdjustment, OnLiquidityChangedHandler, OnTradeHandler, OraclePeriod}; +use hydradx_traits::{AggregatedOracle, AggregatedPriceOracle}; use orml_xcm_support::OnDepositFail; use orml_xcm_support::UnknownAsset as UnknownAssetT; use pallet_circuit_breaker::WeightInfo; @@ -400,3 +400,42 @@ impl< Ok(asset.clone().into()) } } + +// Dynamic fees volume adapter +pub struct OracleVolume(Balance, Balance); + +impl pallet_dynamic_fees::traits::Volume for OracleVolume { + fn amount_in(&self) -> Balance { + self.0 + } + + fn amount_out(&self) -> Balance { + self.1 + } +} + +pub struct OracleAssetVolumeProvider(PhantomData<(Runtime, Lrna, Period)>); + +impl pallet_dynamic_fees::traits::VolumeProvider + for OracleAssetVolumeProvider +where + Runtime: pallet_ema_oracle::Config, + Lrna: Get, + Period: Get, +{ + type Volume = OracleVolume; + + fn asset_volume(asset_id: AssetId) -> Option { + let entry = + pallet_ema_oracle::Pallet::::get_entry(asset_id, Lrna::get(), Period::get(), OMNIPOOL_SOURCE) + .ok()?; + Some(OracleVolume(entry.volume.a_in, entry.volume.a_out)) + } + + fn asset_liquidity(asset_id: AssetId) -> Option { + let entry = + pallet_ema_oracle::Pallet::::get_entry(asset_id, Lrna::get(), Period::get(), OMNIPOOL_SOURCE) + .ok()?; + Some(entry.liquidity.a) + } +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 31eaf21ec..68be132ae 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -26,14 +26,15 @@ use frame_support::traits::{Contains, EitherOfDiverse, LockIdentifier}; use frame_support::{parameter_types, PalletId, RuntimeDebug}; use frame_system::EnsureRoot; use hydradx_traits::oracle::{OraclePeriod, Source}; +use pallet_dynamic_fees::types::FeeParams; pub use pallet_transaction_payment::Multiplier; pub use primitives::constants::{chain::*, currency::*, time::*}; pub use primitives::{Amount, AssetId, Balance, BlockNumber, CollectionId}; use scale_info::TypeInfo; use sp_runtime::{ generic, - traits::{AccountIdConversion, BlakeTwo256, Bounded, IdentifyAccount, Verify}, - FixedPointNumber, MultiSignature, Perbill, Percent, Permill, Perquintill, + traits::{AccountIdConversion, BlakeTwo256, Bounded, IdentifyAccount, One, Verify, Zero}, + FixedPointNumber, FixedU128, MultiSignature, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; @@ -357,6 +358,23 @@ parameter_types! { pub MaxNumberOfRetriesOnError: u8 = 3; } +// Dynamic fees +parameter_types! { + pub AssetFeeParams: FeeParams = FeeParams{ + min_fee: Permill::from_rational(25u32,10000u32), + max_fee: Permill::from_percent(40), + decay: FixedU128::zero(), + amplification: FixedU128::one(), + }; + + pub ProtocolFeeParams: FeeParams = FeeParams{ + min_fee: Permill::from_rational(5u32,10000u32), + max_fee: Permill::from_percent(40), + decay: FixedU128::zero(), + amplification: FixedU128::one(), + }; +} + #[cfg(test)] mod tests { use super::*; diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 4827944a2..6d86feae4 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -29,6 +29,7 @@ pallet-omnipool = { workspace = true } pallet-circuit-breaker = { workspace = true } pallet-omnipool-liquidity-mining = { workspace = true } pallet-dca = { workspace = true } +pallet-dynamic-fees = { workspace = true } # pallets pallet-balances = { workspace = true } diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index b709e159c..99d59484a 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -899,8 +899,6 @@ impl pallet_omnipool::Config for Runtime { type HdxAssetId = NativeAssetId; type HubAssetId = LRNA; type StableCoinAssetId = StableAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type MinWithdrawalFee = MinimumWithdrawalFee; type MinimumTradingLimit = MinTradingLimit; type MinimumPoolLiquidity = MinPoolLiquidity; @@ -929,6 +927,7 @@ impl pallet_omnipool::Config for Runtime { >, ); type ExternalPriceOracle = EmaOraclePriceAdapter; + type Fee = pallet_dynamic_fees::UpdateAndRetrieveFees; } impl pallet_transaction_pause::Config for Runtime { @@ -1064,6 +1063,20 @@ impl pallet_otc::Config for Runtime { type WeightInfo = weights::otc::HydraWeight; } +parameter_types! { + pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::LastBlock; +} + +impl pallet_dynamic_fees::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type BlockNumberProvider = System; + type Fee = Permill; + type AssetId = AssetId; + type Oracle = adapters::OracleAssetVolumeProvider; + type AssetFeeParameters = AssetFeeParams; + type ProtocolFeeParameters = ProtocolFeeParams; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -1102,6 +1115,7 @@ construct_runtime!( OTC: pallet_otc = 64, CircuitBreaker: pallet_circuit_breaker = 65, Router: pallet_route_executor = 67, + DynamicFees: pallet_dynamic_fees = 68, // ORML related modules Tokens: orml_tokens = 77, diff --git a/runtime/testing-hydradx/Cargo.toml b/runtime/testing-hydradx/Cargo.toml index ff6ee8cec..752351b67 100644 --- a/runtime/testing-hydradx/Cargo.toml +++ b/runtime/testing-hydradx/Cargo.toml @@ -29,6 +29,7 @@ pallet-omnipool = { workspace = true } pallet-circuit-breaker = { workspace = true } pallet-omnipool-liquidity-mining = { workspace = true } pallet-dca = { workspace = true } +pallet-dynamic-fees = { workspace = true } # pallets pallet-balances = { workspace = true } diff --git a/runtime/testing-hydradx/src/lib.rs b/runtime/testing-hydradx/src/lib.rs index 8b79c91ba..aee6d6c99 100644 --- a/runtime/testing-hydradx/src/lib.rs +++ b/runtime/testing-hydradx/src/lib.rs @@ -896,8 +896,6 @@ impl pallet_omnipool::Config for Runtime { type HdxAssetId = NativeAssetId; type HubAssetId = LRNA; type StableCoinAssetId = StableAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type MinWithdrawalFee = MinimumWithdrawalFee; type MinimumTradingLimit = MinTradingLimit; type MinimumPoolLiquidity = MinPoolLiquidity; @@ -926,6 +924,7 @@ impl pallet_omnipool::Config for Runtime { >, ); type ExternalPriceOracle = EmaOraclePriceAdapter; + type Fee = pallet_dynamic_fees::UpdateAndRetrieveFees; } impl pallet_transaction_pause::Config for Runtime { @@ -1061,6 +1060,20 @@ impl pallet_otc::Config for Runtime { type WeightInfo = weights::otc::HydraWeight; } +parameter_types! { + pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::LastBlock; +} + +impl pallet_dynamic_fees::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type BlockNumberProvider = System; + type Fee = Permill; + type AssetId = AssetId; + type Oracle = adapters::OracleAssetVolumeProvider; + type AssetFeeParameters = AssetFeeParams; + type ProtocolFeeParameters = ProtocolFeeParams; +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime where @@ -1099,6 +1112,7 @@ construct_runtime!( OTC: pallet_otc = 64, CircuitBreaker: pallet_circuit_breaker = 65, Router: pallet_route_executor = 67, + DynamicFees: pallet_dynamic_fees = 68, // ORML related modules Tokens: orml_tokens = 77, From 6fa2329e3ad3e0072128a83323304cb99bacdf70 Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Tue, 6 Jun 2023 14:39:53 +0200 Subject: [PATCH 12/24] fix circuit breaker tests, omnipool lm tests --- Cargo.lock | 1 + integration-tests/Cargo.toml | 1 + integration-tests/src/dynamic_fees.rs | 76 ++++++++++--------- pallets/circuit-breaker/src/tests/mock.rs | 13 +++- pallets/dca/src/tests/mock.rs | 13 +++- pallets/dynamic-fees/src/lib.rs | 2 +- pallets/dynamic-fees/src/tests/fees.rs | 6 +- .../src/tests/mock.rs | 11 ++- pallets/omnipool/src/tests/mock.rs | 11 ++- 9 files changed, 85 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a99999ece..0661976d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10172,6 +10172,7 @@ dependencies = [ "pallet-dca", "pallet-democracy", "pallet-duster", + "pallet-dynamic-fees", "pallet-elections-phragmen", "pallet-ema-oracle", "pallet-liquidity-mining", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 1621456e4..ecd247ea6 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -31,6 +31,7 @@ pallet-otc = { workspace = true } pallet-relaychain-info = { workspace = true } pallet-route-executor = { workspace = true} pallet-dca = { workspace = true} +pallet-dynamic-fees = { workspace = true } pallet-treasury = { workspace = true } pallet-democracy = { workspace = true } diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs index 12863ee03..9da2d22b0 100644 --- a/integration-tests/src/dynamic_fees.rs +++ b/integration-tests/src/dynamic_fees.rs @@ -11,7 +11,6 @@ const DOT_UNITS: u128 = 10_000_000_000; const BTC_UNITS: u128 = 10_000_000; const ETH_UNITS: u128 = 1_000_000_000_000_000_000; - #[test] fn fees_should_work_when_oracle_not_initialized() { TestNet::reset(); @@ -28,22 +27,21 @@ fn fees_should_work_when_oracle_not_initialized() { //Act assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, 0, )); - // REVIEW: IS THIS CORRECT? - // If yes, are you testing this correctly in other tests? - // looks like you are not testing the change or maybe this is a special case when not initialized? + // Fees are not recalculated because nothing has been provided by oracle ( it did not go through on init yet) assert!(hydradx_runtime::DynamicFees::current_fees(HDX).is_none()); + assert!(hydradx_runtime::DynamicFees::current_fees(DOT).is_none()); }); } #[test] -fn fees_should_initialize_lazily_when_sell_happens() { +fn fees_should_initialize_lazily_to_min_value_when_first_trade_happens() { TestNet::reset(); Hydra::execute_with(|| { @@ -56,19 +54,23 @@ fn fees_should_initialize_lazily_when_sell_happens() { //Act assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, 0, )); + let asset_fee_params = ::AssetFeeParameters::get(); + let protocol_fee_params = + ::ProtocolFeeParameters::get(); + //Assert assert_eq!( hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), FeeEntry { - asset_fee: Permill::from_float(0.0025_f64), - protocol_fee: Permill::from_float(0.0005_f64), + asset_fee: asset_fee_params.min_fee, + protocol_fee: protocol_fee_params.min_fee, timestamp: 10_u32 } ); @@ -76,7 +78,7 @@ fn fees_should_initialize_lazily_when_sell_happens() { } #[test] -fn fees_should_initialize_lazily_when_buy_happens() { +fn fees_should_initialize_lazily_to_min_value_when_first_buy_happens() { TestNet::reset(); Hydra::execute_with(|| { @@ -90,19 +92,23 @@ fn fees_should_initialize_lazily_when_buy_happens() { set_balance(DAVE.into(), HDX, 1_000 * UNITS as i128); //Act assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, u128::MAX, )); + let asset_fee_params = ::AssetFeeParameters::get(); + let protocol_fee_params = + ::ProtocolFeeParameters::get(); + //Assert assert_eq!( hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), FeeEntry { - asset_fee: Permill::from_float(0.0025_f64), - protocol_fee: Permill::from_float(0.0005_f64), + asset_fee: asset_fee_params.min_fee, + protocol_fee: protocol_fee_params.min_fee, timestamp: 10_u32 } ); @@ -122,7 +128,7 @@ fn fees_should_change_when_buys_happen_in_different_blocks() { set_balance(DAVE.into(), HDX, 1_000 * UNITS as i128); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -134,7 +140,7 @@ fn fees_should_change_when_buys_happen_in_different_blocks() { //Act hydradx_run_to_block(11); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -166,7 +172,7 @@ fn fees_should_change_when_sells_happen_in_different_blocks() { hydradx_run_to_block(10); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -178,7 +184,7 @@ fn fees_should_change_when_sells_happen_in_different_blocks() { //Act hydradx_run_to_block(11); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -210,7 +216,7 @@ fn fees_should_change_when_trades_happen_in_different_blocks() { hydradx_run_to_block(10); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -222,7 +228,7 @@ fn fees_should_change_when_trades_happen_in_different_blocks() { //Act hydradx_run_to_block(11); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -254,7 +260,7 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { hydradx_run_to_block(10); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -267,7 +273,7 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { //Act & assert hydradx_run_to_block(11); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -287,7 +293,7 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { //NOTE: second trade in the same block should not change fees assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -298,7 +304,7 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { //NOTE: second trade in the same block should not change fees assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -311,7 +317,7 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { fn set_balance(who: hydradx_runtime::AccountId, currency: AssetId, amount: i128) { assert_ok!(hydradx_runtime::Currencies::update_balance( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), who, currency, amount, @@ -323,12 +329,12 @@ fn init_omnipool() { let stable_price = FixedU128::from_inner(45_000_000_000); assert_ok!(hydradx_runtime::Omnipool::set_tvl_cap( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), 522_222_000_000_000_000_000_000, )); assert_ok!(hydradx_runtime::Omnipool::initialize_pool( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), stable_price, native_price, Permill::from_percent(100), @@ -337,7 +343,7 @@ fn init_omnipool() { let dot_price = FixedU128::from_inner(25_650_000_000_000_000_000); assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), DOT, dot_price, Permill::from_percent(100), @@ -346,7 +352,7 @@ fn init_omnipool() { let eth_price = FixedU128::from_inner(71_145_071_145_071); assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), ETH, eth_price, Permill::from_percent(100), @@ -355,7 +361,7 @@ fn init_omnipool() { let btc_price = FixedU128::from_inner(9_647_109_647_109_650_000_000_000); assert_ok!(hydradx_runtime::Omnipool::add_token( - hydradx_runtime::Origin::root(), + hydradx_runtime::RuntimeOrigin::root(), BTC, btc_price, Permill::from_percent(100), @@ -375,7 +381,7 @@ fn init_oracle() { set_balance(trader.into(), BTC, 1_000 * BTC_UNITS as i128); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -383,7 +389,7 @@ fn init_oracle() { )); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), DOT, HDX, 2 * DOT_UNITS, @@ -391,7 +397,7 @@ fn init_oracle() { )); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), ETH, HDX, 2 * ETH_UNITS, @@ -399,7 +405,7 @@ fn init_oracle() { )); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), ETH, HDX, 2 * ETH_UNITS, @@ -407,7 +413,7 @@ fn init_oracle() { )); assert_ok!(hydradx_runtime::Omnipool::sell( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), BTC, HDX, 2 * BTC_UNITS, @@ -415,7 +421,7 @@ fn init_oracle() { )); assert_ok!(hydradx_runtime::Omnipool::buy( - hydradx_runtime::Origin::signed(DAVE.into()), + hydradx_runtime::RuntimeOrigin::signed(DAVE.into()), BTC, HDX, 2 * BTC_UNITS, diff --git a/pallets/circuit-breaker/src/tests/mock.rs b/pallets/circuit-breaker/src/tests/mock.rs index d66f38270..4be5dbde2 100644 --- a/pallets/circuit-breaker/src/tests/mock.rs +++ b/pallets/circuit-breaker/src/tests/mock.rs @@ -22,7 +22,7 @@ pub use frame_support::{assert_noop, assert_ok, parameter_types}; use frame_system::EnsureRoot; use hydra_dx_math::omnipool::types::BalanceUpdate; -use orml_traits::parameter_type_with_key; +use orml_traits::{parameter_type_with_key, GetByKey}; use sp_core::H256; use sp_runtime::traits::{ConstU128, ConstU32}; use sp_runtime::DispatchResult; @@ -210,8 +210,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -228,6 +226,7 @@ impl pallet_omnipool::Config for Test { type PriceBarrier = (); type MinWithdrawalFee = MinWithdrawFee; type ExternalPriceOracle = WithdrawFeePriceOracle; + type Fee = FeeProvider; } pub struct CircuitBreakerHooks(PhantomData); @@ -627,3 +626,11 @@ impl ExternalPriceProvider for WithdrawFeePriceOracle { todo!() } } + +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} diff --git a/pallets/dca/src/tests/mock.rs b/pallets/dca/src/tests/mock.rs index 2faaea643..f71e89e22 100644 --- a/pallets/dca/src/tests/mock.rs +++ b/pallets/dca/src/tests/mock.rs @@ -29,7 +29,7 @@ use frame_support::{assert_ok, parameter_types}; use frame_system as system; use frame_system::{ensure_signed, EnsureRoot}; use hydradx_traits::{OraclePeriod, PriceOracle, Registry}; -use orml_traits::parameter_type_with_key; +use orml_traits::{parameter_type_with_key, GetByKey}; use pallet_currencies::BasicCurrencyAdapter; use primitive_types::U128; use sp_core::H256; @@ -246,8 +246,6 @@ impl pallet_omnipool::Config for Test { type PositionItemId = u32; type Currency = Currencies; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -265,6 +263,7 @@ impl pallet_omnipool::Config for Test { type PriceBarrier = (); type MinWithdrawalFee = (); type ExternalPriceOracle = WithdrawFeePriceOracle; + type Fee = FeeProvider; } pub struct WithdrawFeePriceOracle; @@ -963,3 +962,11 @@ pub(super) fn saturating_sub(l: EmaPrice, r: EmaPrice) -> EmaPrice { let d = l_d.full_mul(r_d); round_to_rational((n, d), Rounding::Nearest).into() } + +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} diff --git a/pallets/dynamic-fees/src/lib.rs b/pallets/dynamic-fees/src/lib.rs index d1cfdcfde..d9f9e20cd 100644 --- a/pallets/dynamic-fees/src/lib.rs +++ b/pallets/dynamic-fees/src/lib.rs @@ -164,7 +164,7 @@ where let current_fee_entry = Self::current_fees(asset_id).unwrap_or(FeeEntry { asset_fee: asset_fee_params.min_fee, protocol_fee: protocol_fee_params.min_fee, - timestamp: block_number, + timestamp: T::BlockNumber::default(), }); // Update only if it has not yet been updated this block diff --git a/pallets/dynamic-fees/src/tests/fees.rs b/pallets/dynamic-fees/src/tests/fees.rs index 8a0ab1cf9..cea2ea297 100644 --- a/pallets/dynamic-fees/src/tests/fees.rs +++ b/pallets/dynamic-fees/src/tests/fees.rs @@ -275,9 +275,9 @@ fn fees_should_not_change_when_already_update_within_same_block() { } #[test] -fn fees_should_be_minimum_when_nothing_in_storage() { +fn fees_should_be_recalculated_correctly_for_last_block_change_when_nothing_in_storage() { ExtBuilder::default() - .with_oracle(SingleValueOracle::new(ONE, 2 * ONE, 50 * ONE)) + .with_oracle(SingleValueOracle::new(ONE, 1_100_000_000_000, 50 * ONE)) .with_asset_fee_params( Fee::from_percent(1), Fee::from_percent(40), @@ -295,7 +295,7 @@ fn fees_should_be_minimum_when_nothing_in_storage() { System::set_block_number(1); let (asset_fee, protocol_fee) = retrieve_fee_entry(HDX); - assert_eq!(asset_fee, Fee::from_percent(1)); + assert_eq!(asset_fee, Fee::from_float(0.012)); assert_eq!(protocol_fee, Fee::from_percent(2)); }); } diff --git a/pallets/omnipool-liquidity-mining/src/tests/mock.rs b/pallets/omnipool-liquidity-mining/src/tests/mock.rs index 79f9676d5..9db82a8e5 100644 --- a/pallets/omnipool-liquidity-mining/src/tests/mock.rs +++ b/pallets/omnipool-liquidity-mining/src/tests/mock.rs @@ -276,8 +276,6 @@ impl pallet_omnipool::Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -294,6 +292,7 @@ impl pallet_omnipool::Config for Test { type PriceBarrier = (); type MinWithdrawalFee = MinWithdrawFee; type ExternalPriceOracle = WithdrawFeePriceOracle; + type Fee = FeeProvider; } pub struct ExtBuilder { @@ -776,3 +775,11 @@ impl ExternalPriceProvider for WithdrawFeePriceOracle { todo!() } } + +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} diff --git a/pallets/omnipool/src/tests/mock.rs b/pallets/omnipool/src/tests/mock.rs index 3c03fb6df..902be3e6f 100644 --- a/pallets/omnipool/src/tests/mock.rs +++ b/pallets/omnipool/src/tests/mock.rs @@ -177,8 +177,6 @@ impl Config for Test { type Currency = Tokens; type AuthorityOrigin = EnsureRoot; type HubAssetId = LRNAAssetId; - type ProtocolFee = ProtocolFee; - type AssetFee = AssetFee; type StableCoinAssetId = DAIAssetId; type WeightInfo = (); type HdxAssetId = HDXAssetId; @@ -198,6 +196,7 @@ impl Config for Test { ); type MinWithdrawalFee = MinWithdrawFee; type ExternalPriceOracle = WithdrawFeePriceOracle; + type Fee = FeeProvider; } pub struct ExtBuilder { @@ -639,3 +638,11 @@ pub(super) fn saturating_sub(l: EmaPrice, r: EmaPrice) -> EmaPrice { let d = l_d.full_mul(r_d); round_to_rational((n, d), Rounding::Nearest) } + +pub struct FeeProvider; + +impl GetByKey for FeeProvider { + fn get(_: &AssetId) -> (Permill, Permill) { + (ASSET_FEE.with(|v| *v.borrow()), PROTOCOL_FEE.with(|v| *v.borrow())) + } +} From 1700a0dee47e64edf01db039090df57b278ae678 Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Tue, 6 Jun 2023 15:08:51 +0200 Subject: [PATCH 13/24] add dynmic fees to runtime features --- runtime/hydradx/Cargo.toml | 2 ++ runtime/testing-hydradx/Cargo.toml | 1 + 2 files changed, 3 insertions(+) diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 6d86feae4..ad9156b06 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -243,6 +243,7 @@ std = [ "pallet-duster/std", "warehouse-liquidity-mining/std", "pallet-omnipool-liquidity-mining/std", + "pallet-dynamic-fees/std", ] try-runtime= [ "frame-try-runtime", @@ -298,4 +299,5 @@ try-runtime= [ "pallet-ema-oracle/try-runtime", "pallet-otc/try-runtime", "pallet-route-executor/try-runtime", + "pallet-dynamic-fees/try-runtime", ] diff --git a/runtime/testing-hydradx/Cargo.toml b/runtime/testing-hydradx/Cargo.toml index 752351b67..4ac38a314 100644 --- a/runtime/testing-hydradx/Cargo.toml +++ b/runtime/testing-hydradx/Cargo.toml @@ -230,4 +230,5 @@ std = [ "pallet-duster/std", "warehouse-liquidity-mining/std", "pallet-omnipool-liquidity-mining/std", + "pallet-dynamic-fees/std", ] From db8e06da2efea45d28283da24c528c5e786b973c Mon Sep 17 00:00:00 2001 From: Martin Hloska Date: Tue, 6 Jun 2023 15:11:21 +0200 Subject: [PATCH 14/24] bump versions --- Cargo.lock | 18 +++++++++--------- integration-tests/Cargo.toml | 2 +- pallets/circuit-breaker/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- pallets/dynamic-fees/Cargo.toml | 2 +- pallets/omnipool-liquidity-mining/Cargo.toml | 2 +- pallets/omnipool/Cargo.toml | 2 +- runtime/common/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- runtime/testing-hydradx/Cargo.toml | 2 +- runtime/testing-hydradx/src/lib.rs | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0661976d1..3204bcacb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1196,7 +1196,7 @@ dependencies = [ [[package]] name = "common-runtime" -version = "102.3.11" +version = "102.3.12" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-pallet-xcmp-queue", @@ -3838,7 +3838,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "157.0.0" +version = "158.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -6427,7 +6427,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" -version = "1.1.12" +version = "1.1.13" dependencies = [ "frame-benchmarking", "frame-support", @@ -6576,7 +6576,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.0.1" +version = "1.0.2" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -6659,7 +6659,7 @@ dependencies = [ [[package]] name = "pallet-dynamic-fees" -version = "1.0.0" +version = "1.0.1" dependencies = [ "frame-benchmarking", "frame-support", @@ -7087,7 +7087,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "2.1.1" +version = "3.0.0" dependencies = [ "bitflags", "frame-benchmarking", @@ -7114,7 +7114,7 @@ dependencies = [ [[package]] name = "pallet-omnipool-liquidity-mining" -version = "2.0.9" +version = "2.0.10" dependencies = [ "bitflags", "frame-benchmarking", @@ -10131,7 +10131,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.7.10" +version = "1.7.11" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -13047,7 +13047,7 @@ dependencies = [ [[package]] name = "testing-hydradx-runtime" -version = "157.0.0" +version = "158.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index ecd247ea6..f9b9240eb 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.7.10" +version = "1.7.11" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index 1a2d5fcb4..407e1dbb5 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-circuit-breaker" -version = "1.1.12" +version = "1.1.13" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 2a2ec4dcf..062168e52 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = '1.0.1' +version = '1.0.2' description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/dynamic-fees/Cargo.toml b/pallets/dynamic-fees/Cargo.toml index ae2f0c11e..3a13dd7ac 100644 --- a/pallets/dynamic-fees/Cargo.toml +++ b/pallets/dynamic-fees/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dynamic-fees' -version = '1.0.0' +version = '1.0.1' description = 'A pallet to provide support for dynamic fees' authors = ['GalacticCouncil'] edition = '2021' diff --git a/pallets/omnipool-liquidity-mining/Cargo.toml b/pallets/omnipool-liquidity-mining/Cargo.toml index 98a27ec91..dd8512d4e 100644 --- a/pallets/omnipool-liquidity-mining/Cargo.toml +++ b/pallets/omnipool-liquidity-mining/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool-liquidity-mining" -version = "2.0.9" +version = "2.0.10" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index 41373de99..a80bea29e 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "2.1.1" +version = "3.0.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index 81a6cfc4e..a8601670e 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "common-runtime" -version = "102.3.11" +version = "102.3.12" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ad9156b06..1bbbae93d 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "157.0.0" +version = "158.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 99d59484a..497539448 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -107,7 +107,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 157, + spec_version: 158, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/testing-hydradx/Cargo.toml b/runtime/testing-hydradx/Cargo.toml index 4ac38a314..3f9e3bd2d 100644 --- a/runtime/testing-hydradx/Cargo.toml +++ b/runtime/testing-hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "testing-hydradx-runtime" -version = "157.0.0" +version = "158.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/testing-hydradx/src/lib.rs b/runtime/testing-hydradx/src/lib.rs index aee6d6c99..57af137db 100644 --- a/runtime/testing-hydradx/src/lib.rs +++ b/runtime/testing-hydradx/src/lib.rs @@ -114,7 +114,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("testing-hydradx"), impl_name: create_runtime_str!("testing-hydradx"), authoring_version: 1, - spec_version: 157, + spec_version: 158, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 2b2dab3c8b928c3eebc1bf99757a46a157eb5543 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 7 Jun 2023 15:22:57 +0200 Subject: [PATCH 15/24] add fee amounts to omnipool's trade events --- Cargo.lock | 4 +- math/Cargo.toml | 2 +- math/src/omnipool/math.rs | 144 +++++++++++++++++++++++-- math/src/omnipool/tests.rs | 203 +++++++++++++++++++++++++++++++++++- math/src/omnipool/types.rs | 9 ++ pallets/omnipool/Cargo.toml | 2 +- pallets/omnipool/src/lib.rs | 22 +++- 7 files changed, 371 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba2e6ac61..fefbbd52f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3724,7 +3724,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "7.1.0" +version = "7.2.0" dependencies = [ "approx", "criterion", @@ -7088,7 +7088,7 @@ dependencies = [ [[package]] name = "pallet-omnipool" -version = "3.0.0" +version = "3.1.0" dependencies = [ "bitflags", "frame-benchmarking", diff --git a/math/Cargo.toml b/math/Cargo.toml index bd5f93434..c0c270065 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "7.1.0" +version = "7.2.0" [dependencies] primitive-types = {default-features = false, version = '0.12.0'} diff --git a/math/src/omnipool/math.rs b/math/src/omnipool/math.rs index aabd0405b..d1a7c21ee 100644 --- a/math/src/omnipool/math.rs +++ b/math/src/omnipool/math.rs @@ -1,6 +1,6 @@ use crate::omnipool::types::BalanceUpdate::{Decrease, Increase}; use crate::omnipool::types::{ - AssetReserveState, AssetStateChange, BalanceUpdate, HubTradeStateChange, LiquidityStateChange, Position, + AssetReserveState, AssetStateChange, BalanceUpdate, HubTradeStateChange, LiquidityStateChange, Position, TradeFee, TradeStateChange, I129, }; use crate::types::Balance; @@ -49,7 +49,10 @@ pub fn calculate_sell_state_changes( .checked_mul(delta_hub_reserve_out_hp) .and_then(|v| v.checked_div(out_hub_reserve_hp.checked_add(delta_hub_reserve_out_hp)?))?; - let delta_reserve_out = amount_without_fee(to_balance!(delta_reserve_out).ok()?, asset_fee)?; + let amount_out = to_balance!(delta_reserve_out).ok()?; + let delta_reserve_out = amount_without_fee(amount_out, asset_fee)?; + + let asset_fee = amount_out.saturating_sub(delta_reserve_out); let delta_imbalance = min(protocol_fee_amount, imbalance); @@ -68,6 +71,10 @@ pub fn calculate_sell_state_changes( }, delta_imbalance: BalanceUpdate::Increase(delta_imbalance), hdx_hub_amount: hdx_fee_amount, + fee: TradeFee { + asset_fee, + protocol_fee: protocol_fee_amount, + }, }) } @@ -101,8 +108,9 @@ pub fn calculate_sell_hub_state_changes( .checked_mul(amount_hp) .and_then(|v| v.checked_div(hub_reserve_hp.checked_add(amount_hp)?))?; - let delta_reserve_out = to_balance!(delta_reserve_out_hp).ok()?; - let delta_reserve_out = amount_without_fee(delta_reserve_out, asset_fee)?; + let amount_out = to_balance!(delta_reserve_out_hp).ok()?; + let delta_reserve_out = amount_without_fee(amount_out, asset_fee)?; + let asset_fee = amount_out.saturating_sub(delta_reserve_out); let delta_imbalance = calculate_imbalance_in_hub_swap(total_hub_reserve, hub_asset_amount, imbalance)?; @@ -113,6 +121,45 @@ pub fn calculate_sell_hub_state_changes( ..Default::default() }, delta_imbalance: Decrease(delta_imbalance), + fee: TradeFee { + asset_fee, + ..Default::default() + }, + }) +} + +// only temporary helper function to calculate in amount with no fees +// will be removed when fee calculation in buy is simplified +fn calculate_hub_asset_in_for_given_out_no_fees( + asset_out_state: &AssetReserveState, + asset_out_amount: Balance, + imbalance: I129, + total_hub_reserve: Balance, +) -> Option> { + let asset_fee = Permill::zero(); + let reserve_no_fee = amount_without_fee(asset_out_state.reserve, asset_fee)?; + let hub_denominator = reserve_no_fee.checked_sub(asset_out_amount)?; + + let (hub_reserve_hp, amount_hp, hub_denominator_hp) = + to_u256!(asset_out_state.hub_reserve, asset_out_amount, hub_denominator); + + let delta_hub_reserve_hp = hub_reserve_hp.checked_mul(amount_hp).and_then(|v| { + v.checked_div(hub_denominator_hp) + .and_then(|v| v.checked_add(U256::one())) + })?; + + let delta_hub_reserve = to_balance!(delta_hub_reserve_hp).ok()?; + + let delta_imbalance = calculate_imbalance_in_hub_swap(total_hub_reserve, delta_hub_reserve, imbalance)?; + + Some(HubTradeStateChange { + asset: AssetStateChange { + delta_reserve: Decrease(asset_out_amount), + delta_hub_reserve: Increase(delta_hub_reserve), + ..Default::default() + }, + delta_imbalance: Decrease(delta_imbalance), + fee: TradeFee::default(), }) } @@ -124,10 +171,8 @@ pub fn calculate_buy_for_hub_asset_state_changes( imbalance: I129, total_hub_reserve: Balance, ) -> Option> { - let hub_denominator = Permill::from_percent(100) - .checked_sub(&asset_fee)? - .mul_floor(asset_out_state.reserve) - .checked_sub(asset_out_amount)?; + let reserve_no_fee = amount_without_fee(asset_out_state.reserve, asset_fee)?; + let hub_denominator = reserve_no_fee.checked_sub(asset_out_amount)?; let (hub_reserve_hp, amount_hp, hub_denominator_hp) = to_u256!(asset_out_state.hub_reserve, asset_out_amount, hub_denominator); @@ -141,6 +186,12 @@ pub fn calculate_buy_for_hub_asset_state_changes( let delta_imbalance = calculate_imbalance_in_hub_swap(total_hub_reserve, delta_hub_reserve, imbalance)?; + // TODO: consider rework the math here + // currently we just recalculate the state changes with zero fees and work out the difference to get fee amount + let no_fee_changes = + calculate_hub_asset_in_for_given_out_no_fees(asset_out_state, asset_out_amount, imbalance, total_hub_reserve)?; + let asset_fee = delta_hub_reserve.saturating_sub(*no_fee_changes.asset.delta_hub_reserve); + Some(HubTradeStateChange { asset: AssetStateChange { delta_reserve: Decrease(asset_out_amount), @@ -148,6 +199,73 @@ pub fn calculate_buy_for_hub_asset_state_changes( ..Default::default() }, delta_imbalance: Decrease(delta_imbalance), + fee: TradeFee { + asset_fee, + ..Default::default() + }, + }) +} + +// only temporary helper function to calculate in amount with no fees +// will be removed when fee calculation in buy is simplified +fn calculate_amount_in_no_fee( + asset_in_state: &AssetReserveState, + asset_out_state: &AssetReserveState, + amount: Balance, + imbalance: Balance, +) -> Option> { + let asset_fee = Permill::zero(); + let protocol_fee = Permill::zero(); + let reserve_no_fee = amount_without_fee(asset_out_state.reserve, asset_fee)?; + let (out_hub_reserve, out_reserve_no_fee, out_amount) = + to_u256!(asset_out_state.hub_reserve, reserve_no_fee, amount); + + let delta_hub_reserve_out = out_hub_reserve + .checked_mul(out_amount) + .and_then(|v| v.checked_div(out_reserve_no_fee.checked_sub(out_amount)?))?; + + let delta_hub_reserve_out = to_balance!(delta_hub_reserve_out).ok()?; + let delta_hub_reserve_out = delta_hub_reserve_out.checked_add(Balance::one())?; + + // Negative + let delta_hub_reserve_in: Balance = FixedU128::from_inner(delta_hub_reserve_out) + .checked_div(&Permill::from_percent(100).sub(protocol_fee).into())? + .into_inner(); + + if delta_hub_reserve_in >= asset_in_state.hub_reserve { + return None; + } + + let (delta_hub_reserve_in_hp, in_hub_reserve_hp, in_reserve_hp) = + to_u256!(delta_hub_reserve_in, asset_in_state.hub_reserve, asset_in_state.reserve); + + let delta_reserve_in = in_reserve_hp + .checked_mul(delta_hub_reserve_in_hp) + .and_then(|v| v.checked_div(in_hub_reserve_hp.checked_sub(delta_hub_reserve_in_hp)?))?; + + let delta_reserve_in = to_balance!(delta_reserve_in).ok()?; + let delta_reserve_in = delta_reserve_in.checked_add(Balance::one())?; + + // Fee accounting and imbalance + let protocol_fee_amount = protocol_fee.mul_floor(delta_hub_reserve_in); + let delta_imbalance = min(protocol_fee_amount, imbalance); + + let hdx_fee_amount = protocol_fee_amount.checked_sub(delta_imbalance)?; + + Some(TradeStateChange { + asset_in: AssetStateChange { + delta_reserve: Increase(delta_reserve_in), + delta_hub_reserve: Decrease(delta_hub_reserve_in), + ..Default::default() + }, + asset_out: AssetStateChange { + delta_reserve: Decrease(amount), + delta_hub_reserve: Increase(delta_hub_reserve_out), + ..Default::default() + }, + delta_imbalance: BalanceUpdate::Increase(delta_imbalance), + hdx_hub_amount: hdx_fee_amount, + fee: TradeFee::default(), }) } @@ -190,6 +308,12 @@ pub fn calculate_buy_state_changes( let delta_reserve_in = to_balance!(delta_reserve_in).ok()?; let delta_reserve_in = delta_reserve_in.checked_add(Balance::one())?; + // TODO: consider rework the math here + // currently we just recalculate the state changes with zero fees and work out the difference to get fee amount + // but it is unnecessary work + let no_fee_changes = calculate_amount_in_no_fee(asset_in_state, asset_out_state, amount, imbalance)?; + let asset_fee = delta_reserve_in.saturating_sub(*no_fee_changes.asset_in.delta_reserve); + // Fee accounting and imbalance let protocol_fee_amount = protocol_fee.mul_floor(delta_hub_reserve_in); let delta_imbalance = min(protocol_fee_amount, imbalance); @@ -209,6 +333,10 @@ pub fn calculate_buy_state_changes( }, delta_imbalance: BalanceUpdate::Increase(delta_imbalance), hdx_hub_amount: hdx_fee_amount, + fee: TradeFee { + asset_fee, + protocol_fee: protocol_fee_amount, + }, }) } diff --git a/math/src/omnipool/tests.rs b/math/src/omnipool/tests.rs index 0e3d1e516..85f74ed35 100644 --- a/math/src/omnipool/tests.rs +++ b/math/src/omnipool/tests.rs @@ -1,4 +1,4 @@ -use crate::omnipool::types::{AssetReserveState, BalanceUpdate, Position, I129}; +use crate::omnipool::types::{AssetReserveState, BalanceUpdate, Position, TradeFee, I129}; use crate::omnipool::{ calculate_add_liquidity_state_changes, calculate_buy_for_hub_asset_state_changes, calculate_buy_state_changes, calculate_cap_difference, calculate_delta_imbalance, calculate_remove_liquidity_state_changes, @@ -64,6 +64,92 @@ fn calculate_sell_should_work_when_correct_input_provided() { ); assert_eq!(state_changes.delta_imbalance, BalanceUpdate::Increase(0u128)); assert_eq!(state_changes.hdx_hub_amount, 0u128); + assert_eq!(state_changes.fee, TradeFee::default()); +} + +#[test] +fn calculate_sell_should_return_correct_when_protocol_fee_is_zero() { + let asset_in_state = AssetReserveState { + reserve: 10 * UNIT, + hub_reserve: 20 * UNIT, + shares: 10 * UNIT, + protocol_shares: 0u128, + }; + let asset_out_state = AssetReserveState { + reserve: 5 * UNIT, + hub_reserve: 5 * UNIT, + shares: 20 * UNIT, + protocol_shares: 0u128, + }; + + let amount_to_sell = 4 * UNIT; + let asset_fee = Permill::from_percent(1); + let protocol_fee = Permill::from_percent(0); + let imbalance = 2 * UNIT; + + let state_changes = calculate_sell_state_changes( + &asset_in_state, + &asset_out_state, + amount_to_sell, + asset_fee, + protocol_fee, + imbalance, + ); + + assert!(state_changes.is_some()); + + let state_changes = state_changes.unwrap(); + assert_eq!( + state_changes.asset_out.delta_reserve, + BalanceUpdate::Decrease(2666666666666u128 - state_changes.fee.asset_fee) + ); + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 26666666667, + protocol_fee: 0, + } + ); +} + +#[test] +fn calculate_sell_should_return_correct_when_protocol_fee_is_not_zero() { + let asset_in_state = AssetReserveState { + reserve: 10 * UNIT, + hub_reserve: 20 * UNIT, + shares: 10 * UNIT, + protocol_shares: 0u128, + }; + let asset_out_state = AssetReserveState { + reserve: 5 * UNIT, + hub_reserve: 5 * UNIT, + shares: 20 * UNIT, + protocol_shares: 0u128, + }; + + let amount_to_sell = 4 * UNIT; + let asset_fee = Permill::from_percent(1); + let protocol_fee = Permill::from_percent(1); + let imbalance = 2 * UNIT; + + let state_changes = calculate_sell_state_changes( + &asset_in_state, + &asset_out_state, + amount_to_sell, + asset_fee, + protocol_fee, + imbalance, + ); + + assert!(state_changes.is_some()); + let state_changes = state_changes.unwrap(); + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 26541554960, + protocol_fee: 57142857142, + } + ); } #[test] @@ -159,6 +245,7 @@ fn calculate_sell_hub_asset_should_work_when_correct_input_provided() { ); assert_eq!(state_changes.delta_imbalance, BalanceUpdate::Decrease(7454545454546)); + assert_eq!(state_changes.fee, TradeFee::default()); } #[test] @@ -195,6 +282,13 @@ fn calculate_sell_hub_asset_with_fee_should_work_when_correct_input_provided() { ); assert_eq!(state_changes.delta_imbalance, BalanceUpdate::Decrease(7454545454546)); + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 16666666667, + protocol_fee: 0, + } + ); } #[test] @@ -251,6 +345,100 @@ fn calculate_buy_should_work_when_correct_input_provided() { assert_eq!(state_changes.hdx_hub_amount, 0u128); } +#[test] +fn calculate_buy_should_return_correct_fee_when_protocol_fee_is_zero() { + let asset_in_state = AssetReserveState { + reserve: 10 * UNIT, + hub_reserve: 20 * UNIT, + shares: 10 * UNIT, + protocol_shares: 0u128, + }; + let asset_out_state = AssetReserveState { + reserve: 5 * UNIT, + hub_reserve: 5 * UNIT, + shares: 20 * UNIT, + protocol_shares: 0u128, + }; + + let amount_to_buy = UNIT; + let asset_fee = Permill::from_percent(1); + let protocol_fee = Permill::from_percent(0); + let imbalance = 2 * UNIT; + + let state_changes = calculate_buy_state_changes( + &asset_in_state, + &asset_out_state, + amount_to_buy, + asset_fee, + protocol_fee, + imbalance, + ); + + assert!(state_changes.is_some()); + + let state_changes = state_changes.unwrap(); + + assert_eq!( + state_changes.asset_in.delta_reserve, + BalanceUpdate::Increase(666666666668u128 + state_changes.fee.asset_fee) + ); + + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 9009009009, + protocol_fee: 0, + } + ) +} + +#[test] +fn calculate_buy_should_return_correct_fee_when_protocol_fee_is_non_zero() { + let asset_in_state = AssetReserveState { + reserve: 10 * UNIT, + hub_reserve: 20 * UNIT, + shares: 10 * UNIT, + protocol_shares: 0u128, + }; + let asset_out_state = AssetReserveState { + reserve: 5 * UNIT, + hub_reserve: 5 * UNIT, + shares: 20 * UNIT, + protocol_shares: 0u128, + }; + + let amount_to_buy = UNIT; + let asset_fee = Permill::from_percent(1); + let protocol_fee = Permill::from_percent(1); + let imbalance = 2 * UNIT; + + let state_changes = calculate_buy_state_changes( + &asset_in_state, + &asset_out_state, + amount_to_buy, + asset_fee, + protocol_fee, + imbalance, + ); + + assert!(state_changes.is_some()); + + let state_changes = state_changes.unwrap(); + + assert_eq!( + state_changes.asset_in.delta_reserve, + BalanceUpdate::Increase(666666666668u128 + state_changes.fee.asset_fee) + ); + + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 16300141146, + protocol_fee: 12786088735, + } + ) +} + #[test] fn calculate_buy_with_fees_should_work_when_correct_input_provided() { let asset_in_state = AssetReserveState { @@ -344,6 +532,7 @@ fn calculate_buy_for_hub_asset_should_work_when_correct_input_provided() { ); assert_eq!(state_changes.delta_imbalance, BalanceUpdate::Decrease(9222222222224)); + assert_eq!(state_changes.fee, TradeFee::default()); } #[test] @@ -380,6 +569,18 @@ fn calculate_buy_for_hub_asset_with_fee_should_work_when_correct_input_provided( ); assert_eq!(state_changes.delta_imbalance, BalanceUpdate::Decrease(9332954060590)); + assert_eq!( + state_changes.asset.delta_hub_reserve, + BalanceUpdate::Increase(5000000000001u128 + state_changes.fee.asset_fee) + ); + + assert_eq!( + state_changes.fee, + TradeFee { + asset_fee: 63291139240, + protocol_fee: 0, + } + ); } #[test] diff --git a/math/src/omnipool/types.rs b/math/src/omnipool/types.rs index cb881a17e..f688393c7 100644 --- a/math/src/omnipool/types.rs +++ b/math/src/omnipool/types.rs @@ -155,6 +155,13 @@ where pub delta_protocol_shares: BalanceUpdate, } +/// Information about trade fee amounts +#[derive(Default, Debug, PartialEq, Eq)] +pub struct TradeFee { + pub asset_fee: Balance, + pub protocol_fee: Balance, +} + /// Delta changes after a trade is executed #[derive(Default, Debug, PartialEq, Eq)] pub struct TradeStateChange @@ -165,6 +172,7 @@ where pub asset_out: AssetStateChange, pub delta_imbalance: BalanceUpdate, pub hdx_hub_amount: Balance, + pub fee: TradeFee, } /// Delta changes after a trade with hub asset is executed. @@ -175,6 +183,7 @@ where { pub asset: AssetStateChange, pub delta_imbalance: BalanceUpdate, + pub fee: TradeFee, } /// Delta changes after add or remove liquidity. diff --git a/pallets/omnipool/Cargo.toml b/pallets/omnipool/Cargo.toml index a80bea29e..f31536277 100644 --- a/pallets/omnipool/Cargo.toml +++ b/pallets/omnipool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-omnipool" -version = "3.0.0" +version = "3.1.0" authors = ['GalacticCouncil'] edition = "2021" license = "Apache-2.0" diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index 9028bfdb5..151dbb974 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -269,6 +269,9 @@ pub mod pallet { amount_in: Balance, amount_out: Balance, asset_fee: Permill, + asset_fee_amount: Balance, + protocol_fee: Permill, + protocol_fee_amount: Balance, }, /// Buy trade executed. BuyExecuted { @@ -278,6 +281,9 @@ pub mod pallet { amount_in: Balance, amount_out: Balance, asset_fee: Permill, + asset_fee_amount: Balance, + protocol_fee: Permill, + protocol_fee_amount: Balance, }, /// LP Position was created and NFT instance minted. PositionCreated { @@ -1168,6 +1174,9 @@ pub mod pallet { amount_in: amount, amount_out: *state_changes.asset_out.delta_reserve, asset_fee, + asset_fee_amount: state_changes.fee.asset_fee, + protocol_fee, + protocol_fee_amount: state_changes.fee.protocol_fee, }); Ok(()) @@ -1351,6 +1360,9 @@ pub mod pallet { amount_in: *state_changes.asset_in.delta_reserve, amount_out: *state_changes.asset_out.delta_reserve, asset_fee, + asset_fee_amount: state_changes.fee.asset_fee, + protocol_fee, + protocol_fee_amount: state_changes.fee.protocol_fee, }); Ok(()) @@ -1651,7 +1663,7 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); - let (asset_fee, _) = T::Fee::get(&asset_out); + let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); let state_changes = hydra_dx_math::omnipool::calculate_sell_hub_state_changes( &(&asset_state).into(), @@ -1712,6 +1724,9 @@ impl Pallet { amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, asset_fee, + asset_fee_amount: state_changes.fee.asset_fee, + protocol_fee, + protocol_fee_amount: state_changes.fee.protocol_fee, }); T::OmnipoolHooks::on_hub_asset_trade(origin, info)?; @@ -1750,7 +1765,7 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); - let (asset_fee, _) = T::Fee::get(&asset_out); + let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); let state_changes = hydra_dx_math::omnipool::calculate_buy_for_hub_asset_state_changes( &(&asset_state).into(), @@ -1810,6 +1825,9 @@ impl Pallet { amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, asset_fee, + asset_fee_amount: state_changes.fee.asset_fee, + protocol_fee, + protocol_fee_amount: state_changes.fee.protocol_fee, }); T::OmnipoolHooks::on_hub_asset_trade(origin, info)?; From 5dba79999a6f64f93ab6c47c7135529a2bba3f22 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 7 Jun 2023 16:08:34 +0200 Subject: [PATCH 16/24] bump versions --- Cargo.lock | 8 ++++---- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- runtime/common/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fefbbd52f..3575abf30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1196,7 +1196,7 @@ dependencies = [ [[package]] name = "common-runtime" -version = "102.3.12" +version = "102.3.13" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-pallet-xcmp-queue", @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "158.0.0" +version = "159.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -6577,7 +6577,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.1.0" +version = "1.1.1" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10114,7 +10114,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.7.11" +version = "1.7.12" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index f9b9240eb..17f66f581 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.7.11" +version = "1.7.12" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 1f323cc8f..5fd606ba3 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = '1.1.0' +version = '1.1.1' description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml index f7ec45859..d36c63f2c 100644 --- a/runtime/common/Cargo.toml +++ b/runtime/common/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "common-runtime" -version = "102.3.12" +version = "102.3.13" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 1bbbae93d..baa4b322c 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "158.0.0" +version = "159.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index ab4f1f3bd..d4eaf62d2 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -110,7 +110,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 158, + spec_version: 159, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From ac57504c63a7d483edcc3006b6775daf688acefa Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Jun 2023 15:32:08 +0200 Subject: [PATCH 17/24] set dyn fees max fee to 0.4% --- runtime/common/src/lib.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 68be132ae..3bac4789b 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -362,14 +362,15 @@ parameter_types! { parameter_types! { pub AssetFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(25u32,10000u32), - max_fee: Permill::from_percent(40), + max_fee: Permill::from_rational(4u32,1000u32), decay: FixedU128::zero(), amplification: FixedU128::one(), }; + 004 pub ProtocolFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(5u32,10000u32), - max_fee: Permill::from_percent(40), + max_fee: Permill::from_rational(4u32,1000u32), decay: FixedU128::zero(), amplification: FixedU128::one(), }; From 7e4da28b598e5a7c996e6eab9d34892a79dcaf77 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Jun 2023 16:50:16 +0200 Subject: [PATCH 18/24] remove it --- runtime/common/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 3bac4789b..0b06375bc 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -367,7 +367,6 @@ parameter_types! { amplification: FixedU128::one(), }; - 004 pub ProtocolFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(5u32,10000u32), max_fee: Permill::from_rational(4u32,1000u32), From c8c28f80fc0c1b215fe0a20dcc05e32b1f9da830 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Jun 2023 17:04:28 +0200 Subject: [PATCH 19/24] fix versions --- Cargo.lock | 6 +++--- integration-tests/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 13 ++++++++++--- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 843535dfd..8024a3506 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "160.0.0" +version = "161.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -6577,7 +6577,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.1.4" +version = "1.1.5" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10094,7 +10094,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.7.15" +version = "1.7.16" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 9c0864770..587ab237f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.7.15" +version = "1.7.16" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 14120b73e..5c79de4bf 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = '1.1.4' +version = '1.1.5' description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index d31a79003..981019754 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "160.0.0" +version = "161.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 452ff0229..3dccb0e61 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -110,7 +110,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 160, + spec_version: 161, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -219,7 +219,14 @@ where Runtime: cumulus_pallet_parachain_system::Config, { fn parent_hash() -> Option { - None + // We use the same hash as for integration tests + // so the integration tests don't fail when they are run with 'runtime-benchmark' feature + let hash = [ + 14, 87, 81, 192, 38, 229, 67, 178, 232, 171, 46, 176, 96, 153, 218, 161, 209, 229, 223, 71, 119, 143, 119, + 135, 250, 171, 69, 205, 241, 47, 227, 168, + ] + .into(); + Some(hash) } } @@ -632,7 +639,7 @@ impl pallet_tips::Config for Runtime { type TipCountdown = TipCountdown; type TipFindersFee = TipFindersFee; type TipReportDepositBase = TipReportDepositBase; - type WeightInfo = (); + type WeightInfo = common_runtime::weights::tips::HydraWeight; } /// ORML Configurations From 7ba8eea983edd97c86e16f9e28924ffd08fa9166 Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 19 Jun 2023 18:04:38 +0200 Subject: [PATCH 20/24] revert changes --- runtime/common/src/lib.rs | 4 ++-- runtime/hydradx/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 0b06375bc..ab6d4d721 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -33,7 +33,7 @@ pub use primitives::{Amount, AssetId, Balance, BlockNumber, CollectionId}; use scale_info::TypeInfo; use sp_runtime::{ generic, - traits::{AccountIdConversion, BlakeTwo256, Bounded, IdentifyAccount, One, Verify, Zero}, + traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, One, Verify, Zero}, FixedPointNumber, FixedU128, MultiSignature, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; @@ -167,7 +167,7 @@ parameter_types! { /// that combined with `AdjustmentVariable`, we can recover from the minimum. pub MinimumMultiplier: Multiplier = Multiplier::saturating_from_rational(1, 1_000_000u128); /// The maximum amount of the multiplier. - pub MaximumMultiplier: Multiplier = Bounded::max_value(); + pub MaximumMultiplier: Multiplier = Multiplier::saturating_from_integer(4); } // pallet treasury diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 3dccb0e61..13c120ee6 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -639,7 +639,7 @@ impl pallet_tips::Config for Runtime { type TipCountdown = TipCountdown; type TipFindersFee = TipFindersFee; type TipReportDepositBase = TipReportDepositBase; - type WeightInfo = common_runtime::weights::tips::HydraWeight; + type WeightInfo = (); } /// ORML Configurations From 88bba4cad5b385853bc34cffad2cd1a52bc31e1d Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 22 Jun 2023 17:22:26 +0200 Subject: [PATCH 21/24] adjust fee params and decay params --- runtime/common/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index ab6d4d721..1f10a8246 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -363,14 +363,14 @@ parameter_types! { pub AssetFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(25u32,10000u32), max_fee: Permill::from_rational(4u32,1000u32), - decay: FixedU128::zero(), + decay: FixedU128::from_rational(5,1000000); amplification: FixedU128::one(), }; pub ProtocolFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(5u32,10000u32), - max_fee: Permill::from_rational(4u32,1000u32), - decay: FixedU128::zero(), + max_fee: Permill::from_rational(1u32,1000u32), + decay: FixedU128::from_rational(5,1000000); amplification: FixedU128::one(), }; } From db874fe2b82cdd56ff1c9d214a6c009584b0d516 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 23 Jun 2023 17:02:37 +0200 Subject: [PATCH 22/24] dynamic fees - set short oracle period --- integration-tests/src/dynamic_fees.rs | 22 +++++++++------------- pallets/omnipool/src/lib.rs | 16 ++-------------- runtime/common/src/lib.rs | 6 +++--- runtime/hydradx/src/lib.rs | 2 +- 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/integration-tests/src/dynamic_fees.rs b/integration-tests/src/dynamic_fees.rs index 9da2d22b0..98da46493 100644 --- a/integration-tests/src/dynamic_fees.rs +++ b/integration-tests/src/dynamic_fees.rs @@ -62,15 +62,13 @@ fn fees_should_initialize_lazily_to_min_value_when_first_trade_happens() { )); let asset_fee_params = ::AssetFeeParameters::get(); - let protocol_fee_params = - ::ProtocolFeeParameters::get(); //Assert assert_eq!( hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), FeeEntry { asset_fee: asset_fee_params.min_fee, - protocol_fee: protocol_fee_params.min_fee, + protocol_fee: Permill::from_float(0.000788_f64), timestamp: 10_u32 } ); @@ -100,15 +98,13 @@ fn fees_should_initialize_lazily_to_min_value_when_first_buy_happens() { )); let asset_fee_params = ::AssetFeeParameters::get(); - let protocol_fee_params = - ::ProtocolFeeParameters::get(); //Assert assert_eq!( hydradx_runtime::DynamicFees::current_fees(HDX).unwrap(), FeeEntry { asset_fee: asset_fee_params.min_fee, - protocol_fee: protocol_fee_params.min_fee, + protocol_fee: Permill::from_float(0.000788_f64), timestamp: 10_u32 } ); @@ -154,7 +150,7 @@ fn fees_should_change_when_buys_happen_in_different_blocks() { current_fee, FeeEntry { asset_fee: Permill::from_float(0.0025_f64), - protocol_fee: Permill::from_float(0.000957_f64), + protocol_fee: Permill::from_float(0.001_f64), timestamp: 11_u32 } ); @@ -197,8 +193,8 @@ fn fees_should_change_when_sells_happen_in_different_blocks() { assert_eq!( current_fee, FeeEntry { - asset_fee: Permill::from_float(0.002954_f64), - protocol_fee: Permill::from_float(0.0005_f64), + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.000926_f64), timestamp: 11_u32 } ); @@ -241,8 +237,8 @@ fn fees_should_change_when_trades_happen_in_different_blocks() { assert_eq!( current_fee, FeeEntry { - asset_fee: Permill::from_float(0.002954_f64), - protocol_fee: Permill::from_float(0.0005_f64), + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.000926_f64), timestamp: 11_u32 } ); @@ -285,8 +281,8 @@ fn fees_should_change_only_one_when_trades_happen_in_the_same_block() { assert_eq!( current_fee, FeeEntry { - asset_fee: Permill::from_float(0.002954_f64), - protocol_fee: Permill::from_float(0.0005_f64), + asset_fee: Permill::from_float(0.0025_f64), + protocol_fee: Permill::from_float(0.000926_f64), timestamp: 11_u32 } ); diff --git a/pallets/omnipool/src/lib.rs b/pallets/omnipool/src/lib.rs index 151dbb974..aeec139ba 100644 --- a/pallets/omnipool/src/lib.rs +++ b/pallets/omnipool/src/lib.rs @@ -268,9 +268,7 @@ pub mod pallet { asset_out: T::AssetId, amount_in: Balance, amount_out: Balance, - asset_fee: Permill, asset_fee_amount: Balance, - protocol_fee: Permill, protocol_fee_amount: Balance, }, /// Buy trade executed. @@ -280,9 +278,7 @@ pub mod pallet { asset_out: T::AssetId, amount_in: Balance, amount_out: Balance, - asset_fee: Permill, asset_fee_amount: Balance, - protocol_fee: Permill, protocol_fee_amount: Balance, }, /// LP Position was created and NFT instance minted. @@ -1173,9 +1169,7 @@ pub mod pallet { asset_out, amount_in: amount, amount_out: *state_changes.asset_out.delta_reserve, - asset_fee, asset_fee_amount: state_changes.fee.asset_fee, - protocol_fee, protocol_fee_amount: state_changes.fee.protocol_fee, }); @@ -1359,9 +1353,7 @@ pub mod pallet { asset_out, amount_in: *state_changes.asset_in.delta_reserve, amount_out: *state_changes.asset_out.delta_reserve, - asset_fee, asset_fee_amount: state_changes.fee.asset_fee, - protocol_fee, protocol_fee_amount: state_changes.fee.protocol_fee, }); @@ -1663,7 +1655,7 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); - let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); + let (asset_fee, _) = T::Fee::get(&asset_out); let state_changes = hydra_dx_math::omnipool::calculate_sell_hub_state_changes( &(&asset_state).into(), @@ -1723,9 +1715,7 @@ impl Pallet { asset_out, amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, - asset_fee, asset_fee_amount: state_changes.fee.asset_fee, - protocol_fee, protocol_fee_amount: state_changes.fee.protocol_fee, }); @@ -1765,7 +1755,7 @@ impl Pallet { let current_hub_asset_liquidity = Self::get_hub_asset_balance_of_protocol_account(); - let (asset_fee, protocol_fee) = T::Fee::get(&asset_out); + let (asset_fee, _) = T::Fee::get(&asset_out); let state_changes = hydra_dx_math::omnipool::calculate_buy_for_hub_asset_state_changes( &(&asset_state).into(), @@ -1824,9 +1814,7 @@ impl Pallet { asset_out, amount_in: *state_changes.asset.delta_hub_reserve, amount_out: *state_changes.asset.delta_reserve, - asset_fee, asset_fee_amount: state_changes.fee.asset_fee, - protocol_fee, protocol_fee_amount: state_changes.fee.protocol_fee, }); diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 1f10a8246..cf7836e8d 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -33,7 +33,7 @@ pub use primitives::{Amount, AssetId, Balance, BlockNumber, CollectionId}; use scale_info::TypeInfo; use sp_runtime::{ generic, - traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, One, Verify, Zero}, + traits::{AccountIdConversion, BlakeTwo256, IdentifyAccount, One, Verify}, FixedPointNumber, FixedU128, MultiSignature, Perbill, Percent, Permill, Perquintill, }; use sp_std::prelude::*; @@ -363,14 +363,14 @@ parameter_types! { pub AssetFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(25u32,10000u32), max_fee: Permill::from_rational(4u32,1000u32), - decay: FixedU128::from_rational(5,1000000); + decay: FixedU128::from_rational(5,1000000), amplification: FixedU128::one(), }; pub ProtocolFeeParams: FeeParams = FeeParams{ min_fee: Permill::from_rational(5u32,10000u32), max_fee: Permill::from_rational(1u32,1000u32), - decay: FixedU128::from_rational(5,1000000); + decay: FixedU128::from_rational(5,1000000), amplification: FixedU128::one(), }; } diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 17d3c7a87..42b4416b8 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -1067,7 +1067,7 @@ impl pallet_otc::Config for Runtime { } parameter_types! { - pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::LastBlock; + pub const DynamicFeesOraclePeriod: OraclePeriod = OraclePeriod::Short; } impl pallet_dynamic_fees::Config for Runtime { From 96a14c0364567fa5fb2d13ef0e7c7f33a73d2547 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 30 Jun 2023 16:33:00 +0200 Subject: [PATCH 23/24] bump versions --- Cargo.lock | 10 +++++----- integration-tests/Cargo.toml | 2 +- math/Cargo.toml | 2 +- pallets/circuit-breaker/Cargo.toml | 2 +- pallets/dca/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 50f934265..43f8cc762 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3724,7 +3724,7 @@ dependencies = [ [[package]] name = "hydra-dx-math" -version = "7.2.0" +version = "7.3.0" dependencies = [ "approx", "criterion", @@ -3839,7 +3839,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "162.0.0" +version = "163.0.0" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", @@ -6428,7 +6428,7 @@ dependencies = [ [[package]] name = "pallet-circuit-breaker" -version = "1.1.13" +version = "1.1.14" dependencies = [ "frame-benchmarking", "frame-support", @@ -6577,7 +6577,7 @@ dependencies = [ [[package]] name = "pallet-dca" -version = "1.1.5" +version = "1.1.6" dependencies = [ "cumulus-pallet-parachain-system", "cumulus-primitives-core", @@ -10094,7 +10094,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.7.16" +version = "1.7.17" dependencies = [ "common-runtime", "cumulus-pallet-aura-ext", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 587ab237f..8e4dcb81f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.7.16" +version = "1.7.17" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/math/Cargo.toml b/math/Cargo.toml index c0c270065..76c74d5ed 100644 --- a/math/Cargo.toml +++ b/math/Cargo.toml @@ -6,7 +6,7 @@ license = 'Apache-2.0' name = "hydra-dx-math" description = "A collection of utilities to make performing liquidity pool calculations more convenient." repository = 'https://github.com/galacticcouncil/hydradx-math' -version = "7.2.0" +version = "7.3.0" [dependencies] primitive-types = {default-features = false, version = '0.12.0'} diff --git a/pallets/circuit-breaker/Cargo.toml b/pallets/circuit-breaker/Cargo.toml index 407e1dbb5..2f29a29e4 100644 --- a/pallets/circuit-breaker/Cargo.toml +++ b/pallets/circuit-breaker/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pallet-circuit-breaker" -version = "1.1.13" +version = "1.1.14" authors = ["GalacticCouncil "] edition = "2021" license = "Apache-2.0" diff --git a/pallets/dca/Cargo.toml b/pallets/dca/Cargo.toml index 5c79de4bf..4db1fa6c3 100644 --- a/pallets/dca/Cargo.toml +++ b/pallets/dca/Cargo.toml @@ -1,6 +1,6 @@ [package] name = 'pallet-dca' -version = '1.1.5' +version = '1.1.6' description = 'A pallet to manage DCA scheduling' authors = ['GalacticCouncil'] edition = '2021' diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index 9cf554bfa..8bd4b782e 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "162.0.0" +version = "163.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index d0fdf3a47..ed93bd2cf 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -110,7 +110,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 162, + spec_version: 163, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1, From 92ee43039005f3f46bfb9deea59dc8311f3adb6a Mon Sep 17 00:00:00 2001 From: Martin Date: Mon, 3 Jul 2023 10:58:47 +0200 Subject: [PATCH 24/24] bump versions --- Cargo.lock | 4 ++-- integration-tests/Cargo.toml | 2 +- runtime/hydradx/Cargo.toml | 2 +- runtime/hydradx/src/lib.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6c30c49f9..c93306162 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3799,7 +3799,7 @@ dependencies = [ [[package]] name = "hydradx-runtime" -version = "163.0.0" +version = "164.0.0" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", @@ -10055,7 +10055,7 @@ dependencies = [ [[package]] name = "runtime-integration-tests" -version = "1.7.17" +version = "1.7.18" dependencies = [ "cumulus-pallet-aura-ext", "cumulus-pallet-dmp-queue", diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 93a86733a..9a4d94a94 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "runtime-integration-tests" -version = "1.7.17" +version = "1.7.18" description = "Integration tests" authors = ["GalacticCouncil"] edition = "2021" diff --git a/runtime/hydradx/Cargo.toml b/runtime/hydradx/Cargo.toml index ab0df59a6..33571e44e 100644 --- a/runtime/hydradx/Cargo.toml +++ b/runtime/hydradx/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hydradx-runtime" -version = "163.0.0" +version = "164.0.0" authors = ["GalacticCouncil"] edition = "2021" license = "Apache 2.0" diff --git a/runtime/hydradx/src/lib.rs b/runtime/hydradx/src/lib.rs index 2df4b34d9..a012dedf4 100644 --- a/runtime/hydradx/src/lib.rs +++ b/runtime/hydradx/src/lib.rs @@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("hydradx"), impl_name: create_runtime_str!("hydradx"), authoring_version: 1, - spec_version: 163, + spec_version: 164, impl_version: 0, apis: RUNTIME_API_VERSIONS, transaction_version: 1,