diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml index 0c8d5e0c..6984c8a8 100644 --- a/.github/workflows/e2e-tests.yaml +++ b/.github/workflows/e2e-tests.yaml @@ -16,6 +16,8 @@ jobs: steps: - name: Checkout the source code uses: actions/checkout@v3 + with: + submodules: true - name: Cache Crates uses: actions/cache@v3 diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index f6b52df4..e78d61f6 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -13,6 +13,8 @@ jobs: steps: - name: Checkout the source code uses: actions/checkout@v3 + with: + submodules: true - name: Cache Crates uses: actions/cache@v3 diff --git a/.gitignore b/.gitignore index f0636a41..aeb04814 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,9 @@ addresses.json # Ignore Rust contract wrappers. amm/e2e-tests/src/*_contract.rs -amm/e2e-tests/src/psp22_token.rs +amm/e2e-tests/src/psp22.rs +amm/e2e-tests/src/wrapped_azero.rs +amm/e2e-tests/src/amm_farm.rs # Ignore backup files creates by cargo fmt. **/*.rs.bk diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..ea08f7b3 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "test-contracts/psp22"] + path = test-contracts/psp22 + url = https://github.com/Cardinal-Cryptography/PSP22.git +[submodule "test-contracts/wrapped-azero"] + path = test-contracts/wrapped-azero + url = https://github.com/Cardinal-Cryptography/wAZERO.git diff --git a/Cargo.lock b/Cargo.lock index 9af539d9..79725900 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "1.0.2" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" dependencies = [ "memchr", ] @@ -30,7 +30,7 @@ dependencies = [ "ink", "parity-scale-codec", "primitive-types", - "psp22-traits", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scale-info", "sp-arithmetic", ] @@ -61,9 +61,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "2.3.3" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" [[package]] name = "bitvec" @@ -103,15 +103,18 @@ checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.0.79" +version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] [[package]] name = "cfg-if" @@ -121,9 +124,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "cpufeatures" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" dependencies = [ "libc", ] @@ -203,9 +206,9 @@ dependencies = [ [[package]] name = "either" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[package]] name = "env_logger" @@ -222,31 +225,20 @@ dependencies = [ [[package]] name = "equivalent" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.1" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +checksum = "7c18ee0ed65a5f1f81cac6b1d213b69c35fa47d4252ad41f1486dbd8226fe36e" dependencies = [ - "errno-dragonfly", "libc", "windows-sys", ] -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "factory_contract" version = "0.1.0" @@ -295,9 +287,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" dependencies = [ "cfg-if", "libc", @@ -306,9 +298,9 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "f93e7192158dbcda357bdec5fb5788eebf8bbac027f3f33e719d29135ae84156" [[package]] name = "heck" @@ -318,9 +310,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" [[package]] name = "hex" @@ -349,17 +341,6 @@ dependencies = [ "parity-scale-codec", ] -[[package]] -name = "impl-num-traits" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "951641f13f873bff03d4bf19ae8bec531935ac0ac2cc775f84d7edfdcfed3f17" -dependencies = [ - "integer-sqrt", - "num-traits", - "uint", -] - [[package]] name = "impl-serde" version = "0.4.0" @@ -382,9 +363,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f" dependencies = [ "equivalent", "hashbrown", @@ -436,7 +417,7 @@ dependencies = [ "quote", "serde", "serde_json", - "syn 2.0.32", + "syn 2.0.39", ] [[package]] @@ -493,7 +474,7 @@ dependencies = [ "itertools", "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.39", ] [[package]] @@ -508,7 +489,7 @@ dependencies = [ "parity-scale-codec", "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.39", "synstructure", ] @@ -592,9 +573,9 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24fddda5af7e54bf7da53067d6e802dbcc381d0a8eef629df528e3ebf68755cb" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" dependencies = [ "hermit-abi", "rustix", @@ -612,9 +593,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0aa48fab2893d8a49caa94082ae8488f4e1050d73b367881dcd2198f4199fd8" +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "keccak" @@ -627,33 +608,33 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.147" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "linux-raw-sys" -version = "0.4.3" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" [[package]] name = "log" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" [[package]] name = "memchr" -version = "2.5.0" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" dependencies = [ "autocfg", ] @@ -672,7 +653,7 @@ dependencies = [ "ink", "parity-scale-codec", "primitive-types", - "psp22", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scale-info", "sp-arithmetic", "traits", @@ -680,9 +661,9 @@ dependencies = [ [[package]] name = "parity-scale-codec" -version = "3.6.2" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7467bc45fea3d77e829a4df331b9e969e2ec6a4dcd4e126e660f8509b40a475" +checksum = "0dec8a8073036902368c2cdc0387e85ff9a37054d7e7c98e592145e0c92cd4fb" dependencies = [ "arrayvec", "bitvec", @@ -694,9 +675,9 @@ dependencies = [ [[package]] name = "parity-scale-codec-derive" -version = "3.6.2" +version = "3.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9de611934c78014c455793552d0bf7d65a58211179c49996fde925aa667c38" +checksum = "312270ee71e1cd70289dacf597cab7b207aa107d2f28191c2ae45b2ece18a260" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -706,9 +687,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" [[package]] name = "ppv-lite86" @@ -718,13 +699,12 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "primitive-types" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f3486ccba82358b11a77516035647c34ba167dfa53312630de83b12bd4f3d66" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" dependencies = [ "fixed-hash", "impl-codec", - "impl-num-traits", "scale-info", "uint", ] @@ -741,9 +721,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" dependencies = [ "unicode-ident", ] @@ -751,7 +731,6 @@ dependencies = [ [[package]] name = "psp22" version = "0.2.0" -source = "git+https://github.com/Cardinal-Cryptography/PSP22.git#1c2e7cecd877a0bde98fb64b24afc7c571c697f4" dependencies = [ "ink", "parity-scale-codec", @@ -759,29 +738,21 @@ dependencies = [ ] [[package]] -name = "psp22-traits" -version = "1.0.0" -dependencies = [ - "ink", - "parity-scale-codec", - "scale-info", -] - -[[package]] -name = "psp22_token" -version = "0.1.0" +name = "psp22" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701aea3ff70bbecb49f4a664d25292076f13bbe5592406e2ca4bddf448c37fe0" dependencies = [ "ink", "parity-scale-codec", - "psp22", "scale-info", ] [[package]] name = "quote" -version = "1.0.29" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -824,9 +795,21 @@ dependencies = [ [[package]] name = "regex" -version = "1.8.4" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr", @@ -835,9 +818,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] name = "rlibc" @@ -852,10 +835,10 @@ dependencies = [ "amm-helpers", "ink", "parity-scale-codec", - "primitive-types", - "psp22", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scale-info", "traits", + "wrapped-azero 0.1.0 (git+https://github.com/Cardinal-Cryptography/wAZERO.git)", ] [[package]] @@ -866,9 +849,9 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" [[package]] name = "rustix" -version = "0.38.2" +version = "0.38.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabcb0461ebd01d6b79945797c27f8529082226cb630a9865a71870ff63532a4" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" dependencies = [ "bitflags", "errno", @@ -879,9 +862,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "scale-bits" @@ -948,9 +931,9 @@ dependencies = [ [[package]] name = "scale-info" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0a159d0c45c12b20c5a844feb1fe4bea86e28f17b92a5f0c42193634d3782" +checksum = "7f7d66a1128282b7ef025a8ead62a4a9fcf017382ec53b8ffbf4d7bf77bd3c60" dependencies = [ "bitvec", "cfg-if", @@ -962,9 +945,9 @@ dependencies = [ [[package]] name = "scale-info-derive" -version = "2.9.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "912e55f6d20e0e80d63733872b40e1227c0bce1e1ab81ba67d696339bfd7fd29" +checksum = "abf2c68b89cafb3b8d918dd07b42be0da66ff202cf1155c5739a4e0c1ea0dc19" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -992,29 +975,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "bca2a08484b285dcb282d0f67b26cadc0df8b19f8c12502c13d966bf9482f001" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.192" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "d6c7207fbec9faa48073f3e3074cbe553af6ea512d7c21ba46e434e70ea9fbc1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.39", ] [[package]] name = "serde_json" -version = "1.0.99" +version = "1.0.108" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46266871c240a00b8f503b877622fe33430b3c7d963bdc0f2adc511e54a1eae3" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" dependencies = [ "itoa", "ryu", @@ -1023,9 +1006,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.7" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -1044,9 +1027,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.11.0" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" [[package]] name = "sp-arithmetic" @@ -1100,9 +1083,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.32" +version = "2.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239814284fd6f1a4ffe4ca893952cdd93c224b6a1571c9a9eadd670295c0c9e2" +checksum = "23e78b90f2fcf45d3e842032ce32e3f2d1545ba6636271dcbf24fa306d87be7a" dependencies = [ "proc-macro2", "quote", @@ -1117,7 +1100,7 @@ checksum = "285ba80e733fac80aa4270fbcdf83772a79b80aa35c97075320abfee4a915b06" dependencies = [ "proc-macro2", "quote", - "syn 2.0.32", + "syn 2.0.39", "unicode-xid", ] @@ -1129,24 +1112,24 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "termcolor" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "6093bad37da69aab9d123a8091e4be0aa4a03e4d601ec641c327398315f62b64" dependencies = [ "winapi-util", ] [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" [[package]] name = "toml_edit" -version = "0.19.11" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ "indexmap", "toml_datetime", @@ -1162,16 +1145,16 @@ dependencies = [ "ink_metadata", "parity-scale-codec", "primitive-types", - "psp22", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scale-info", "sp-arithmetic", ] [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uint" @@ -1187,9 +1170,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-xid" @@ -1227,9 +1210,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" dependencies = [ "winapi", ] @@ -1251,9 +1234,9 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", @@ -1266,64 +1249,73 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winnow" -version = "0.4.7" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "829846f3e3db426d4cee4510841b71a8e58aa2a76b1132579487ae430ccd9c7b" dependencies = [ "memchr", ] [[package]] -name = "wnative_contract" +name = "wrapped-azero" version = "0.1.0" dependencies = [ "ink", "parity-scale-codec", - "psp22", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "scale-info", - "traits", +] + +[[package]] +name = "wrapped-azero" +version = "0.1.0" +source = "git+https://github.com/Cardinal-Cryptography/wAZERO.git#f60d2cce0eb6d291be0bcb93dbb50ad20906f886" +dependencies = [ + "ink", + "parity-scale-codec", + "psp22 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1337,6 +1329,6 @@ dependencies = [ [[package]] name = "xxhash-rust" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "735a71d46c4d68d71d4b24d03fdc2b98e38cea81730595801db779c04fe80d70" +checksum = "9828b178da53440fa9c766a3d2f73f7cf5d0ac1fe3980c1e5018d899fd19e07b" diff --git a/Cargo.toml b/Cargo.toml index 184bc909..d800e11d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,6 @@ resolver = "2" -members = ["amm/contracts/**", "farm/contracts"] +members = ["amm/contracts/*", "farm/contracts", "test-contracts/*"] exclude = ["amm/e2e-tests", "amm/traits", "helpers"] diff --git a/Makefile b/Makefile index e66b23d9..7f82b82b 100644 --- a/Makefile +++ b/Makefile @@ -37,20 +37,34 @@ build-node-x86_64: AMM_CONTRACTS = ./amm/contracts AMM_CONTRACTS_PATHS := $(shell find $(AMM_CONTRACTS) -mindepth 1 -maxdepth 1 -type d) -FARM_CONTRACTS = ./farm/contracts -FARM_PATHS := $(shell find ./farm -mindepth 1 -maxdepth 1 -type d) +FARM_CONTRACTS = ./farm +FARM_PATHS := $(shell find $(FARM_CONTRACTS) -mindepth 1 -maxdepth 1 -type d) + +TEST_CONTRACTS = ./test-contracts +TEST_PATHS := $(shell find $(TEST_CONTRACTS) -mindepth 1 -maxdepth 1 -type d) .PHONY: build-all -build-all: ## Builds all contracts. +build-all: ## Builds all production contracts. @for d in $(AMM_CONTRACTS_PATHS); do \ echo "Building $$d contract" ; \ cargo contract build --quiet --manifest-path $$d/Cargo.toml --release ; \ done - @for d in $(FARM_CONTRACTS); do \ + @for d in $(FARM_PATHS); do \ echo "Building $$d contract" ; \ cargo contract build --quiet --manifest-path $$d/Cargo.toml --release ; \ done +.PHONY: build-test-contracts +build-test-contracts: ## Builds contracts used in e2e-tests + @for d in $(TEST_PATHS); do \ + echo "Building $$d contract" ; \ + if [[ "$$d" = *psp22 ]]; then \ + cargo contract build --quiet --manifest-path $$d/Cargo.toml --release --features "contract"; \ + else \ + cargo contract build --quiet --manifest-path $$d/Cargo.toml --release; \ + fi \ + done + .PHONY: check-all check-all: ## Runs cargo checks and unit tests on all contracts. @cargo check --quiet --all-targets --all-features --all @@ -87,7 +101,7 @@ e2e-tests: ## Runs all the e2e tests in sequence. @cd amm/e2e-tests && cargo test -- --test-threads 1 && cd .. .PHONY: build-and-wrap-all -build-and-wrap-all: build-all wrap-all ## Builds all contracts and generates code for contract interaction. +build-and-wrap-all: build-all build-test-contracts wrap-all ## Builds all contracts and generates code for contract interaction. INK_DEV_IMAGE = public.ecr.aws/p6e8q1z1/ink-dev:1.7.0 diff --git a/amm/contracts/pair/Cargo.toml b/amm/contracts/pair/Cargo.toml index 0e3028f2..f3880a93 100644 --- a/amm/contracts/pair/Cargo.toml +++ b/amm/contracts/pair/Cargo.toml @@ -14,7 +14,7 @@ scale-info = { version = "2.9", default-features = false, features = [ "derive", ], optional = true } -psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false } +psp22 = { version = "0.2" , default-features = false } traits = { path = "../../traits", default-features = false } amm-helpers = { path = "../../../helpers", default-features = false } diff --git a/amm/contracts/psp22/Cargo.toml b/amm/contracts/psp22/Cargo.toml deleted file mode 100644 index 78697f1e..00000000 --- a/amm/contracts/psp22/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "psp22_token" -version = "0.1.0" -authors = ["Cardinal Cryptography"] -edition = "2021" - -[dependencies] -ink = { version = "=4.3.0", default-features = false } - -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ - "derive", -] } - -scale-info = { version = "2.9", default-features = false, features = [ - "derive", -], optional = true } - -psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false } - -[lib] -name = "psp22_token" -path = "lib.rs" - -[features] -default = ["std"] -std = [ - "ink/std", - "scale/std", - "scale-info/std", - "psp22/std", -] -ink-as-dependency = [] diff --git a/amm/contracts/psp22/lib.rs b/amm/contracts/psp22/lib.rs deleted file mode 100644 index b6b46bdf..00000000 --- a/amm/contracts/psp22/lib.rs +++ /dev/null @@ -1,184 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std, no_main)] - -#[ink::contract] -pub mod token { - use ink::prelude::{string::String, vec::Vec}; - use psp22::{PSP22Data, PSP22Error, PSP22Event, PSP22Metadata, PSP22}; - - #[ink(event)] - pub struct Approval { - #[ink(topic)] - owner: AccountId, - #[ink(topic)] - spender: AccountId, - amount: u128, - } - - #[ink(event)] - pub struct Transfer { - #[ink(topic)] - from: Option, - #[ink(topic)] - to: Option, - value: u128, - } - - #[ink(storage)] - pub struct MyPSP22 { - data: PSP22Data, - name: Option, - symbol: Option, - decimals: u8, - } - - impl MyPSP22 { - #[ink(constructor)] - pub fn new( - total_supply: u128, - name: Option, - symbol: Option, - decimals: u8, - ) -> Self { - Self { - data: PSP22Data::new(total_supply, Self::env().caller()), - name, - symbol, - decimals, - } - } - - fn emit_events(&self, events: Vec) { - for event in events { - match event { - PSP22Event::Transfer { from, to, value } => { - self.env().emit_event(Transfer { from, to, value }) - } - PSP22Event::Approval { - owner, - spender, - amount, - } => self.env().emit_event(Approval { - owner, - spender, - amount, - }), - } - } - } - } - - impl PSP22Metadata for MyPSP22 { - #[ink(message)] - fn token_name(&self) -> Option { - self.name.clone() - } - - #[ink(message)] - fn token_symbol(&self) -> Option { - self.symbol.clone() - } - - #[ink(message)] - fn token_decimals(&self) -> u8 { - self.decimals - } - } - - impl PSP22 for MyPSP22 { - #[ink(message)] - fn total_supply(&self) -> u128 { - self.data.total_supply() - } - - #[ink(message)] - fn balance_of(&self, owner: AccountId) -> u128 { - self.data.balance_of(owner) - } - - #[ink(message)] - fn allowance(&self, owner: AccountId, spender: AccountId) -> u128 { - self.data.allowance(owner, spender) - } - - #[ink(message)] - fn transfer( - &mut self, - to: AccountId, - value: u128, - _data: Vec, - ) -> Result<(), PSP22Error> { - let events = self.data.transfer(self.env().caller(), to, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn transfer_from( - &mut self, - from: AccountId, - to: AccountId, - value: u128, - _data: Vec, - ) -> Result<(), PSP22Error> { - let events = self - .data - .transfer_from(self.env().caller(), from, to, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn approve(&mut self, spender: AccountId, value: u128) -> Result<(), PSP22Error> { - let events = self.data.approve(self.env().caller(), spender, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn increase_allowance( - &mut self, - spender: AccountId, - delta_value: u128, - ) -> Result<(), PSP22Error> { - let events = self - .data - .increase_allowance(self.env().caller(), spender, delta_value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn decrease_allowance( - &mut self, - spender: AccountId, - delta_value: u128, - ) -> Result<(), PSP22Error> { - let events = self - .data - .decrease_allowance(self.env().caller(), spender, delta_value)?; - self.emit_events(events); - Ok(()) - } - } - - #[cfg(test)] - mod tests { - use super::*; - - #[ink::test] - fn initialize_works() { - let name = "TOKEN_A".to_string(); - let symbol = "TKNA".to_string(); - let decimals = 18; - let token = MyPSP22::new( - 1_000_000_000, - Some(name.clone()), - Some(symbol.clone()), - decimals, - ); - assert_eq!(token.name.unwrap(), name); - assert_eq!(token.symbol.unwrap(), symbol); - assert_eq!(token.decimals, decimals); - } - } -} diff --git a/amm/contracts/router/Cargo.toml b/amm/contracts/router/Cargo.toml index 004a5006..3ee5fcc2 100755 --- a/amm/contracts/router/Cargo.toml +++ b/amm/contracts/router/Cargo.toml @@ -5,9 +5,6 @@ authors = ["Cardinal Cryptography"] edition = "2021" [dependencies] -primitive-types = { version = "0.12.1", default-features = false, features = [ - "num-traits", -] } ink = { version = "=4.3.0", default-features = false } scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ @@ -17,7 +14,8 @@ scale-info = { version = "2.9", default-features = false, features = [ "derive", ], optional = true } -psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false } +psp22 = { version = "0.2" , default-features = false } +wrapped-azero = { git = "https://github.com/Cardinal-Cryptography/wAZERO.git", default-features = false, features = ["ink-as-dependency"] } traits = { path = "../../traits", default-features = false } amm-helpers = { path = "../../../helpers", default-features = false } @@ -30,6 +28,7 @@ path = "lib.rs" default = ["std"] std = [ "ink/std", + "psp22/std", "scale/std", "scale-info", "scale-info/std", diff --git a/amm/contracts/router/lib.rs b/amm/contracts/router/lib.rs index 91119594..c3f93e74 100755 --- a/amm/contracts/router/lib.rs +++ b/amm/contracts/router/lib.rs @@ -10,7 +10,8 @@ pub mod router { prelude::{string::String, vec, vec::Vec}, }; use psp22::{PSP22Error, PSP22}; - use traits::{Factory, MathError, Pair, Router, RouterError, Wnative}; + use traits::{Factory, MathError, Pair, Router, RouterError}; + use wrapped_azero::WrappedAZERO; #[ink(storage)] pub struct RouterContract { @@ -30,7 +31,7 @@ pub mod router { } #[inline] - fn wnative_ref(&self) -> contract_ref!(Wnative) { + fn wnative_ref(&self) -> contract_ref!(WrappedAZERO) { self.wnative.into() } @@ -71,7 +72,7 @@ pub mod router { .transferred_value(value) .try_invoke() .map_err(|_| { - RouterError::CrossContractCallFailed(String::from("Wnative:deposit")) + RouterError::CrossContractCallFailed(String::from("Wrapped AZERO: deposit")) })???; Ok(()) } diff --git a/amm/contracts/wnative/Cargo.toml b/amm/contracts/wnative/Cargo.toml deleted file mode 100644 index f802507b..00000000 --- a/amm/contracts/wnative/Cargo.toml +++ /dev/null @@ -1,35 +0,0 @@ -[package] -name = "wnative_contract" -version = "0.1.0" -authors = ["Cardinal Cryptography"] -edition = "2021" - -[dependencies] -ink = { version = "=4.3.0", default-features = false } - -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ - "derive", -] } -scale-info = { version = "2.9", default-features = false, features = [ - "derive", -], optional = true } - -traits = { path = "../../traits", default-features = false } - -psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false } - -[lib] -name = "wnative_contract" -path = "lib.rs" - -[features] -default = ["std"] -std = [ - "ink/std", - "scale/std", - "scale-info", - "scale-info/std", - "traits/std", - "psp22/std", -] -ink-as-dependency = [] diff --git a/amm/contracts/wnative/lib.rs b/amm/contracts/wnative/lib.rs deleted file mode 100644 index b981c349..00000000 --- a/amm/contracts/wnative/lib.rs +++ /dev/null @@ -1,285 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std, no_main)] - -#[ink::contract] -pub mod wnative { - use ink::prelude::{string::String, vec::Vec}; - use psp22::{PSP22Data, PSP22Error, PSP22Event, PSP22Metadata, PSP22}; - use traits::Wnative; - - #[ink(event)] - pub struct Approval { - #[ink(topic)] - owner: AccountId, - #[ink(topic)] - spender: AccountId, - amount: u128, - } - - #[ink(event)] - pub struct Transfer { - #[ink(topic)] - from: Option, - #[ink(topic)] - to: Option, - value: u128, - } - - #[ink(storage)] - #[derive(Default)] - pub struct WnativeContract { - data: PSP22Data, - } - - impl WnativeContract { - #[ink(constructor)] - pub fn new() -> Self { - Self::default() - } - - fn emit_events(&self, events: Vec) { - for event in events { - match event { - PSP22Event::Transfer { from, to, value } => { - self.env().emit_event(Transfer { from, to, value }) - } - PSP22Event::Approval { - owner, - spender, - amount, - } => self.env().emit_event(Approval { - owner, - spender, - amount, - }), - } - } - } - - /// For e2e testing purposes only. Do not use in production! - #[cfg(feature = "e2e-tests")] - #[ink(message)] - pub fn terminate(&mut self) -> Result<(), PSP22Error> { - let caller = self.env().caller(); - self.env().terminate_contract(caller) - } - } - - impl Wnative for WnativeContract { - #[ink(message)] - fn deposit(&mut self) -> Result<(), PSP22Error> { - let events = self - .data - .mint(self.env().caller(), self.env().transferred_value())?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn withdraw(&mut self, value: u128) -> Result<(), PSP22Error> { - let caller = self.env().caller(); - let events = self.data.burn(caller, value)?; - self.env() - .transfer(caller, value) - .map_err(|_| PSP22Error::Custom(String::from("Wrapper AZERO: withdraw failed")))?; - self.emit_events(events); - Ok(()) - } - } - - impl PSP22Metadata for WnativeContract { - #[ink(message)] - fn token_name(&self) -> Option { - Some(String::from("Wrapped AZERO")) - } - - #[ink(message)] - fn token_symbol(&self) -> Option { - Some(String::from("WAZERO")) - } - - #[ink(message)] - fn token_decimals(&self) -> u8 { - 12 - } - } - - impl PSP22 for WnativeContract { - #[ink(message)] - fn total_supply(&self) -> u128 { - self.data.total_supply() - } - - #[ink(message)] - fn balance_of(&self, owner: AccountId) -> u128 { - self.data.balance_of(owner) - } - - #[ink(message)] - fn allowance(&self, owner: AccountId, spender: AccountId) -> u128 { - self.data.allowance(owner, spender) - } - - #[ink(message)] - fn transfer( - &mut self, - to: AccountId, - value: u128, - _data: ink::prelude::vec::Vec, - ) -> Result<(), PSP22Error> { - let events = self.data.transfer(self.env().caller(), to, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn transfer_from( - &mut self, - from: AccountId, - to: AccountId, - value: u128, - _data: ink::prelude::vec::Vec, - ) -> Result<(), PSP22Error> { - let events = self - .data - .transfer_from(self.env().caller(), from, to, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn approve(&mut self, spender: AccountId, value: u128) -> Result<(), PSP22Error> { - let events = self.data.approve(self.env().caller(), spender, value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn increase_allowance( - &mut self, - spender: AccountId, - delta_value: u128, - ) -> Result<(), PSP22Error> { - let events = self - .data - .increase_allowance(self.env().caller(), spender, delta_value)?; - self.emit_events(events); - Ok(()) - } - - #[ink(message)] - fn decrease_allowance( - &mut self, - spender: AccountId, - delta_value: u128, - ) -> Result<(), PSP22Error> { - let events = self - .data - .decrease_allowance(self.env().caller(), spender, delta_value)?; - self.emit_events(events); - Ok(()) - } - } - - #[cfg(test)] - mod tests { - use super::*; - - #[ink::test] - fn register_works() { - let wnative_contract = WnativeContract::new(); - assert_eq!( - wnative_contract.token_name(), - Some(String::from("Wrapped AZERO")) - ); - assert_eq!( - wnative_contract.token_symbol(), - Some(String::from("WAZERO")) - ); - } - - #[ink::test] - fn test_deposit() { - let accounts = default_accounts(); - let mut wnative_contract = create_contract(0); - assert_eq!(deposit(&mut wnative_contract, 1000), Ok(())); - let balance = wnative_contract.balance_of(accounts.alice); - assert_eq!(balance, 1000, "balance not correct!"); - let native_balance: Balance = get_balance(contract_id()); - assert_eq!(native_balance, 1000, "native balance not correct!"); - } - - #[ink::test] - fn test_withdraw() { - let accounts = default_accounts(); - let mut wnative_contract = create_contract(1000); - assert_eq!(get_balance(contract_id()), 1000); - assert!( - wnative_contract.data.mint(accounts.alice, 1000).is_ok(), - "mint failed" - ); - let wnative_balance = wnative_contract.balance_of(accounts.alice); - assert_eq!(wnative_balance, 1000, "balance not correct!"); - - let before_balance = get_balance(accounts.alice); - assert_eq!(wnative_contract.withdraw(800), Ok(())); - assert_eq!( - get_balance(accounts.alice), - 800 + before_balance, - "withdraw should refund native token" - ); - let wnative_balance = wnative_contract.balance_of(accounts.alice); - assert_eq!(wnative_balance, 200, "balance not correct!"); - } - - fn default_accounts() -> ink::env::test::DefaultAccounts { - ink::env::test::default_accounts() - } - - fn set_next_caller(caller: AccountId) { - ink::env::test::set_caller::(caller); - } - - fn contract_id() -> AccountId { - ink::env::test::callee::() - } - - fn get_balance(account_id: AccountId) -> Balance { - ink::env::test::get_account_balance::(account_id) - .expect("Cannot get account balance") - } - - fn set_balance(account_id: AccountId, balance: Balance) { - ink::env::test::set_account_balance::(account_id, balance) - } - - /// Creates a new instance of `WnativeContract` with `initial_balance`. - /// - /// Returns the `contract_instance`. - fn create_contract(initial_balance: Balance) -> WnativeContract { - let accounts = default_accounts(); - set_next_caller(accounts.alice); - set_balance(contract_id(), initial_balance); - WnativeContract::new() - } - - fn deposit(contract: &mut WnativeContract, amount: Balance) -> Result<(), PSP22Error> { - let sender = ink::env::caller::(); - let contract_id = contract_id(); - let sender_balance = get_balance(sender); - let contract_balance = get_balance(contract_id); - // ↓ doesn't work, is upstream issue: https://github.com/paritytech/ink/issues/1117 - // set_balance(sender, sender_balance - amount); - set_balance( - sender, - if sender_balance > amount { - sender_balance - amount - } else { - 0 - }, - ); - set_balance(contract_id, contract_balance + amount); - ink::env::test::set_value_transferred::(amount); - contract.deposit() - } - } -} diff --git a/amm/e2e-tests/Cargo.lock b/amm/e2e-tests/Cargo.lock index 4b3937bd..3509a36e 100644 --- a/amm/e2e-tests/Cargo.lock +++ b/amm/e2e-tests/Cargo.lock @@ -2062,8 +2062,9 @@ dependencies = [ [[package]] name = "psp22" -version = "0.1.0" -source = "git+https://github.com/Cardinal-Cryptography/PSP22.git#c6744743e645f8120ceef84e2dbadf8f194fdb4f" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701aea3ff70bbecb49f4a664d25292076f13bbe5592406e2ca4bddf448c37fe0" dependencies = [ "ink", "parity-scale-codec", diff --git a/amm/e2e-tests/src/lib.rs b/amm/e2e-tests/src/lib.rs index 49f53a1b..c5e85acc 100644 --- a/amm/e2e-tests/src/lib.rs +++ b/amm/e2e-tests/src/lib.rs @@ -5,10 +5,10 @@ mod factory_contract; #[cfg(test)] mod pair_contract; #[cfg(test)] -mod psp22_token; +mod psp22; #[cfg(test)] mod router_contract; #[cfg(test)] mod test; #[cfg(test)] -mod wnative_contract; +mod wrapped_azero; diff --git a/amm/e2e-tests/src/test/pair.rs b/amm/e2e-tests/src/test/pair.rs index 20ce83e7..d9e86610 100644 --- a/amm/e2e-tests/src/test/pair.rs +++ b/amm/e2e-tests/src/test/pair.rs @@ -30,8 +30,8 @@ use crate::{ Pair, PSP22 as PairPSP22, }, - psp22_token, - psp22_token::PSP22 as TokenPSP22, + psp22 as psp22_token, + psp22::PSP22 as TokenPSP22, test::setup::{ get_env, random_salt, diff --git a/amm/e2e-tests/src/test/router.rs b/amm/e2e-tests/src/test/router.rs index ae560e05..5cfaef63 100644 --- a/amm/e2e-tests/src/test/router.rs +++ b/amm/e2e-tests/src/test/router.rs @@ -31,8 +31,8 @@ use crate::{ Pair, PSP22, }, - psp22_token, - psp22_token::PSP22 as TokenPSP22, + psp22 as psp22_token, + psp22::PSP22 as TokenPSP22, router_contract, router_contract::Router, test::setup::{ @@ -48,9 +48,9 @@ use crate::{ TOKEN_A_SYMBOL, WEALTHY_SEED, }, - wnative_contract, - wnative_contract::{ - Wnative, + wrapped_azero, + wrapped_azero::{ + WrappedAZERO, PSP22 as WnativePSP22, }, }; @@ -63,7 +63,7 @@ static ROUTER_TESTS_CODE_UPLOAD: OnceCell> = OnceCell::const_new(); struct RouterContractsSetup { factory_contract: factory_contract::Instance, token_a: psp22_token::Instance, - wnative_contract: wnative_contract::Instance, + wrapped_azero: wrapped_azero::Instance, router_contract: router_contract::Instance, } @@ -73,7 +73,7 @@ struct RouterTestSetup { regular_account: ink_primitives::AccountId, factory_contract: factory_contract::Instance, token_a: psp22_token::Instance, - wnative_contract: wnative_contract::Instance, + wrapped_azero: wrapped_azero::Instance, router_contract: router_contract::Instance, } @@ -88,9 +88,7 @@ async fn router_tests_code_upload() -> Result<()> { .upload(factory_contract::upload()) .await?; wealthy_connection.upload(psp22_token::upload()).await?; - wealthy_connection - .upload(wnative_contract::upload()) - .await?; + wealthy_connection.upload(wrapped_azero::upload()).await?; wealthy_connection.upload(router_contract::upload()).await?; Ok(()) @@ -119,12 +117,12 @@ async fn set_up_contracts( .with_salt(salt.clone()), ) .await?; - let wnative_contract = connection - .instantiate(wnative_contract::Instance::new().with_salt(salt.clone())) + let wrapped_azero = connection + .instantiate(wrapped_azero::Instance::new().with_salt(salt.clone())) .await?; let router_contract = connection .instantiate( - router_contract::Instance::new(factory_contract.into(), wnative_contract.into()) + router_contract::Instance::new(factory_contract.into(), wrapped_azero.into()) .with_salt(salt), ) .await?; @@ -132,7 +130,7 @@ async fn set_up_contracts( let router_contracts_setup = RouterContractsSetup { factory_contract, token_a, - wnative_contract, + wrapped_azero, router_contract, }; @@ -154,7 +152,7 @@ async fn set_up_router_test() -> Result { let RouterContractsSetup { factory_contract, token_a, - wnative_contract, + wrapped_azero, router_contract, } = set_up_contracts(&wealthy_connection, regular_account).await?; @@ -164,7 +162,7 @@ async fn set_up_router_test() -> Result { regular_account, factory_contract, token_a, - wnative_contract, + wrapped_azero, router_contract, }; @@ -181,7 +179,7 @@ pub async fn add_liquidity() -> Result<()> { factory_contract, token_a, router_contract, - wnative_contract, + wrapped_azero, .. } = set_up_router_test().await?; @@ -217,7 +215,7 @@ pub async fn add_liquidity() -> Result<()> { assert!(all_pairs_length_after == all_pairs_length_before + 1); let pair_contract: pair_contract::Instance = wealthy_connection - .read(factory_contract.get_pair(wnative_contract.into(), token_a.into())) + .read(factory_contract.get_pair(wrapped_azero.into(), token_a.into())) .await?? .ok_or(anyhow!("Specified token pair does not exist!"))? .into(); @@ -240,7 +238,7 @@ pub async fn swap_exact_native_for_tokens() -> Result<()> { wealthy_account, regular_account, token_a, - wnative_contract, + wrapped_azero, router_contract, .. } = set_up_router_test().await?; @@ -265,7 +263,7 @@ pub async fn swap_exact_native_for_tokens() -> Result<()> { ) .await?; - let path = vec![wnative_contract.into(), token_a.into()]; + let path = vec![wrapped_azero.into(), token_a.into()]; let amounts_in = wealthy_connection .read(router_contract.get_amounts_in(AMOUNT_OUT, path.clone())) .await?? @@ -299,7 +297,7 @@ pub async fn swap_native_for_exact_tokens() -> Result<()> { wealthy_account, regular_account, token_a, - wnative_contract, + wrapped_azero, router_contract, .. } = set_up_router_test().await?; @@ -324,7 +322,7 @@ pub async fn swap_native_for_exact_tokens() -> Result<()> { ) .await?; - let path = vec![wnative_contract.into(), token_a.into()]; + let path = vec![wrapped_azero.into(), token_a.into()]; let amounts_in = wealthy_connection .read(router_contract.get_amounts_in(AMOUNT_OUT, path.clone())) .await?? @@ -358,7 +356,7 @@ pub async fn swap_exact_tokens_for_tokens() -> Result<()> { wealthy_account, regular_account, token_a, - wnative_contract, + wrapped_azero, router_contract, .. } = set_up_router_test().await?; @@ -383,11 +381,11 @@ pub async fn swap_exact_tokens_for_tokens() -> Result<()> { ) .await?; wealthy_connection - .exec(wnative_contract.deposit().with_value(AMOUNT_TOKEN_DESIRED)) + .exec(wrapped_azero.deposit().with_value(AMOUNT_TOKEN_DESIRED)) .await?; wealthy_connection - .exec(wnative_contract.approve(router_contract.into(), AMOUNT_TOKEN_DESIRED)) + .exec(wrapped_azero.approve(router_contract.into(), AMOUNT_TOKEN_DESIRED)) .await?; let regular_account_balance_before = wealthy_connection @@ -397,7 +395,7 @@ pub async fn swap_exact_tokens_for_tokens() -> Result<()> { .exec(router_contract.swap_exact_tokens_for_tokens( AMOUNT_TOKEN_DESIRED, AMOUNT_OUT, - vec![wnative_contract.into(), token_a.into()], + vec![wrapped_azero.into(), token_a.into()], regular_account, deadline, )) @@ -421,7 +419,7 @@ pub async fn swap_tokens_for_exact_tokens() -> Result<()> { wealthy_account, regular_account, token_a, - wnative_contract, + wrapped_azero, router_contract, .. } = set_up_router_test().await?; @@ -449,11 +447,11 @@ pub async fn swap_tokens_for_exact_tokens() -> Result<()> { const AMOUNT_FOR_SWAP: Balance = 100_000; wealthy_connection - .exec(wnative_contract.deposit().with_value(AMOUNT_FOR_SWAP)) + .exec(wrapped_azero.deposit().with_value(AMOUNT_FOR_SWAP)) .await?; wealthy_connection - .exec(wnative_contract.approve(router_contract.into(), AMOUNT_FOR_SWAP)) + .exec(wrapped_azero.approve(router_contract.into(), AMOUNT_FOR_SWAP)) .await?; let regular_account_balance_before = wealthy_connection @@ -464,7 +462,7 @@ pub async fn swap_tokens_for_exact_tokens() -> Result<()> { .exec(router_contract.swap_tokens_for_exact_tokens( AMOUNT_OUT, AMOUNT_FOR_SWAP, - vec![wnative_contract.into(), token_a.into()], + vec![wrapped_azero.into(), token_a.into()], regular_account, deadline, )) @@ -565,7 +563,7 @@ pub async fn remove_liquidity() -> Result<()> { regular_account, factory_contract, token_a, - wnative_contract, + wrapped_azero, router_contract, } = set_up_router_test().await?; @@ -595,7 +593,7 @@ pub async fn remove_liquidity() -> Result<()> { .await?; let pair_contract: pair_contract::Instance = wealthy_connection - .read(factory_contract.get_pair(wnative_contract.into(), token_a.into())) + .read(factory_contract.get_pair(wrapped_azero.into(), token_a.into())) .await?? .ok_or(anyhow!("Specified token pair does not exist!"))? .into(); diff --git a/amm/traits/Cargo.lock b/amm/traits/Cargo.lock index 9271bf11..089a4c19 100644 --- a/amm/traits/Cargo.lock +++ b/amm/traits/Cargo.lock @@ -692,7 +692,8 @@ dependencies = [ [[package]] name = "psp22" version = "0.2.0" -source = "git+https://github.com/Cardinal-Cryptography/PSP22.git#1c2e7cecd877a0bde98fb64b24afc7c571c697f4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "701aea3ff70bbecb49f4a664d25292076f13bbe5592406e2ca4bddf448c37fe0" dependencies = [ "ink", "parity-scale-codec", diff --git a/amm/traits/Cargo.toml b/amm/traits/Cargo.toml index 9a4d2c5a..29ddb2ee 100644 --- a/amm/traits/Cargo.toml +++ b/amm/traits/Cargo.toml @@ -15,7 +15,7 @@ scale-info = { version = "2.9", default-features = false, features = [ "derive", ], optional = true } -psp22 = { git = "https://github.com/Cardinal-Cryptography/PSP22.git", default-features = false } +psp22 = { version = "0.2" , default-features = false } primitive-types = { version = "0.12.1", default-features = false, features = [ "codec", diff --git a/amm/traits/lib.rs b/amm/traits/lib.rs index f148ba5b..7b1fbd2a 100644 --- a/amm/traits/lib.rs +++ b/amm/traits/lib.rs @@ -3,14 +3,12 @@ mod factory; mod pair; mod router; -mod wnative; pub type Balance = ::Balance; pub use factory::{Factory, FactoryError}; pub use pair::{Pair, PairError}; pub use router::{Router, RouterError}; -pub use wnative::Wnative; #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] diff --git a/amm/traits/wnative.rs b/amm/traits/wnative.rs deleted file mode 100644 index c07682c5..00000000 --- a/amm/traits/wnative.rs +++ /dev/null @@ -1,12 +0,0 @@ -use psp22::PSP22Error; - -#[ink::trait_definition] -pub trait Wnative { - /// Deposit NATIVE to wrap it - #[ink(message, payable)] - fn deposit(&mut self) -> Result<(), PSP22Error>; - - /// Unwrap NATIVE - #[ink(message)] - fn withdraw(&mut self, value: u128) -> Result<(), PSP22Error>; -} diff --git a/farm/contracts/Cargo.toml b/farm/contracts/Cargo.toml index 788e32ea..02e6245a 100644 --- a/farm/contracts/Cargo.toml +++ b/farm/contracts/Cargo.toml @@ -18,7 +18,7 @@ primitive-types = { version = "0.12.1", default-features = false, features = [ "codec", ] } sp-arithmetic = { version = "18.0.0", default-features = false } -psp22-traits = { path = "../psp22-traits", default-features = false } +psp22 = { version = "0.2" , default-features = false } amm-helpers = { path = "../../helpers", default-features = false } [lib] path = "lib.rs" @@ -29,7 +29,7 @@ std = [ "ink/std", "scale/std", "scale-info/std", - "psp22-traits/std", + "psp22/std", "primitive-types/std", "primitive-types/scale-info", "sp-arithmetic/std", diff --git a/farm/contracts/error.rs b/farm/contracts/error.rs index 29fd2580..675fb2ea 100644 --- a/farm/contracts/error.rs +++ b/farm/contracts/error.rs @@ -1,5 +1,5 @@ use amm_helpers::math::MathError; -use psp22_traits::PSP22Error; +use psp22::PSP22Error; #[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] #[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] diff --git a/farm/contracts/lib.rs b/farm/contracts/lib.rs index e2fd03a5..e0f22cc5 100644 --- a/farm/contracts/lib.rs +++ b/farm/contracts/lib.rs @@ -13,23 +13,23 @@ mod tests; #[ink::contract] mod farm { - use crate::error::{FarmError, FarmStartError}; - - use crate::views::{FarmDetailsView, UserPositionView}; - - use crate::{reward_per_token, rewards_earned}; + use crate::{ + error::{FarmError, FarmStartError}, + reward_per_token, rewards_earned, + views::{FarmDetailsView, UserPositionView}, + }; - use primitive_types::U256; - use psp22_traits::PSP22; + use amm_helpers::types::WrappedU256; use ink::{ contract_ref, + prelude::{vec, vec::Vec}, storage::{traits::ManualKey, Lazy, Mapping}, }; - use ink::prelude::{vec, vec::Vec}; + use primitive_types::U256; - use amm_helpers::types::WrappedU256; + use psp22::PSP22; #[ink(event)] pub struct Deposited { @@ -575,7 +575,7 @@ mod farm { psp22: &mut contract_ref!(PSP22), recipient: AccountId, amount: u128, - ) -> Result<(), psp22_traits::PSP22Error> { + ) -> Result<(), psp22::PSP22Error> { match psp22 .call_mut() .transfer(recipient, amount, vec![]) diff --git a/farm/psp22-traits/Cargo.toml b/farm/psp22-traits/Cargo.toml deleted file mode 100644 index 36f10381..00000000 --- a/farm/psp22-traits/Cargo.toml +++ /dev/null @@ -1,23 +0,0 @@ -[package] -name = "psp22-traits" -version = "1.0.0" -authors = ["filip.bielejec@cardinals.cc"] -edition = "2021" - -[dependencies] -ink = { version = "=4.3.0", default-features = false } - -scale = { package = "parity-scale-codec", version = "3", default-features = false, features = [ - "derive", -] } -scale-info = { version = "2.5", default-features = false, features = [ - "derive", -], optional = true } - -[lib] -path = "lib.rs" - -[features] -default = ["std"] -std = ["ink/std", "scale/std", "scale-info/std"] -ink-as-dependency = [] diff --git a/farm/psp22-traits/lib.rs b/farm/psp22-traits/lib.rs deleted file mode 100644 index 8ce777aa..00000000 --- a/farm/psp22-traits/lib.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![cfg_attr(not(feature = "std"), no_std, no_main)] - -use ink::{ - env::{DefaultEnvironment, Environment}, - primitives::AccountId, -}; - -use ink::prelude::vec::Vec; - -pub type Balance = ::Balance; - -#[derive(Debug, PartialEq, Eq, scale::Encode, scale::Decode)] -#[cfg_attr(feature = "std", derive(scale_info::TypeInfo))] -pub enum PSP22Error { - InsufficientBalance, - InsufficientAllowance, -} - -#[ink::trait_definition] -pub trait PSP22 { - #[ink(message)] - fn total_supply(&self) -> Balance; - - #[ink(message)] - fn balance_of(&self, owner: AccountId) -> Balance; - - #[ink(message)] - fn allowance(&self, owner: AccountId, spender: AccountId) -> Balance; - - #[ink(message)] - fn approve(&mut self, spender: AccountId, amount: Balance) -> Result<(), PSP22Error>; - - #[ink(message)] - fn increase_allowance(&mut self, spender: AccountId, by: Balance) -> Result<(), PSP22Error>; - - #[ink(message)] - fn decrease_allowance(&mut self, spender: AccountId, by: Balance) -> Result<(), PSP22Error>; - - #[ink(message)] - fn transfer(&mut self, to: AccountId, value: Balance, data: Vec) -> Result<(), PSP22Error>; - - #[ink(message)] - fn transfer_from( - &mut self, - from: AccountId, - to: AccountId, - value: Balance, - data: Vec, - ) -> Result<(), PSP22Error>; -} diff --git a/test-contracts/psp22 b/test-contracts/psp22 new file mode 160000 index 00000000..f05e3180 --- /dev/null +++ b/test-contracts/psp22 @@ -0,0 +1 @@ +Subproject commit f05e31809aaae77782b21bd2d3265b398cf1e7a5 diff --git a/test-contracts/wrapped-azero b/test-contracts/wrapped-azero new file mode 160000 index 00000000..f60d2cce --- /dev/null +++ b/test-contracts/wrapped-azero @@ -0,0 +1 @@ +Subproject commit f60d2cce0eb6d291be0bcb93dbb50ad20906f886