diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..4c2a377 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,188 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + release: + types: [published] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +env: + RUST_VERSION: 1.75.0 + +jobs: + lint-toml-files: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + + - name: Install Cargo.toml linter + uses: baptiste0928/cargo-install@v2 + with: + crate: cargo-toml-lint + version: '0.1.1' + + - name: Run Cargo.toml linter + run: git ls-files | grep Cargo.toml$ | xargs --verbose -n 1 cargo-toml-lint + + orderbook-contract: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy, rustfmt + + - name: Init cache + uses: Swatinem/rust-cache@v2 + + - name: Install Fuel toolchain + uses: FuelLabs/action-fuel-toolchain@v0.6.0 + with: + toolchain: nightly + date: 2024-02-07 + + - name: Check Sway formatting + run: forc fmt --check --path contract + + - name: Build Sway + run: | + cd "contract" + forc build --locked + + tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy, rustfmt + + - name: Init cache + uses: Swatinem/rust-cache@v2 + + - name: Install Fuel toolchain + uses: FuelLabs/action-fuel-toolchain@v0.6.0 + with: + toolchain: nightly + date: 2024-02-07 + + - name: Build Sway + run: | + cd "contract" + forc build --locked + + - name: Check Rust formatting + run: cargo fmt --verbose --check --manifest-path tests/Cargo.toml + + - name: Check Clippy Linter + run: cargo clippy --manifest-path tests/Cargo.toml --all-features --all-targets -- -D warnings + + - name: Run Rust tests + run: cargo test --locked --manifest-path tests/Cargo.toml + + SDK: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy, rustfmt + + - name: Init cache + uses: Swatinem/rust-cache@v2 + + - name: Install Fuel toolchain + uses: FuelLabs/action-fuel-toolchain@v0.6.0 + with: + toolchain: nightly + date: 2024-02-07 + + - name: Build Sway + run: | + cd "contract" + forc build --locked + + - name: Build Rust files + run: cargo build --locked --manifest-path spark-market-sdk/Cargo.toml + + - name: Check Clippy Linter + run: cargo clippy --manifest-path spark-market-sdk/Cargo.toml --all-features --all-targets -- -D warnings + + utils: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy, rustfmt + + - name: Init cache + uses: Swatinem/rust-cache@v2 + + - name: Build Rust files + run: cargo build --locked --manifest-path utils/Cargo.toml + + - name: Check Clippy Linter + run: cargo clippy --manifest-path utils/Cargo.toml --all-features --all-targets -- -D warnings + + scripts: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_VERSION }} + components: clippy, rustfmt + + - name: Init cache + uses: Swatinem/rust-cache@v2 + + - name: Install Fuel toolchain + uses: FuelLabs/action-fuel-toolchain@v0.6.0 + with: + toolchain: nightly + date: 2024-02-07 + + - name: Build Sway + run: | + cd "contract" + forc build --locked + + - name: Build Rust files + run: cargo build --locked --manifest-path scripts/Cargo.toml + + - name: Check Clippy Linter + run: cargo clippy --manifest-path scripts/Cargo.toml --all-features --all-targets -- -D warnings diff --git a/Cargo.lock b/Cargo.lock index b613b35..1a2f282 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -232,18 +232,18 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] name = "async-trait" -version = "0.1.79" +version = "0.1.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507401cad91ec6a857ed5513a2073c82a9b9048762b885bb98655b306964681" +checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -423,9 +423,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.92" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b" [[package]] name = "cfg-if" @@ -435,16 +435,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -488,7 +488,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -749,7 +749,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -966,9 +966,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "elliptic-curve" @@ -1015,13 +1015,13 @@ dependencies = [ [[package]] name = "enum-iterator-derive" -version = "1.3.0" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03cdc46ec28bd728e67540c528013c6a10eb69a02eb31078a1bda695438cbfb8" +checksum = "c19cbb53d33b57ac4df1f0af6b92c38c107cded663c4aea9fae1189dcfc17cf5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1101,9 +1101,9 @@ dependencies = [ [[package]] name = "fiat-crypto" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f" +checksum = "38793c55593b33412e3ae40c2c9781ffaa6f438f6f8c10f24e71846fbd7ae01e" [[package]] name = "fixed-hash" @@ -1142,7 +1142,7 @@ dependencies = [ "regex", "serde", "serde_json", - "syn 2.0.58", + "syn 2.0.60", "thiserror", ] @@ -1442,7 +1442,7 @@ checksum = "ff58cf4d01a4fb9440c63a8764154dfd3b07c74e4b3639cce8eea77d67e63a7a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "synstructure", ] @@ -1587,7 +1587,7 @@ dependencies = [ "quote", "regex", "serde_json", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1628,7 +1628,7 @@ dependencies = [ "proc-macro2", "quote", "rand", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -1673,7 +1673,7 @@ dependencies = [ "rand", "serde", "serde_json", - "serde_with 3.7.0", + "serde_with 3.8.0", "tempfile", "tokio", "which", @@ -1741,7 +1741,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -2027,7 +2027,7 @@ dependencies = [ "http", "hyper", "log", - "rustls 0.21.10", + "rustls 0.21.11", "rustls-native-certs 0.6.3", "tokio", "tokio-rustls 0.24.1", @@ -2329,18 +2329,6 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" -[[package]] -name = "orderbook" -version = "0.1.0" -dependencies = [ - "dotenv", - "fuels", - "hex", - "rand", - "src20_sdk", - "tokio", -] - [[package]] name = "p256" version = "0.13.2" @@ -2435,7 +2423,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -2530,9 +2518,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] @@ -2569,7 +2557,7 @@ checksum = "440f724eba9f6996b75d63681b0a92b06947f1457076d503a4d2e2c8f56442b8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -2727,7 +2715,7 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", - "rustls 0.21.10", + "rustls 0.21.11", "rustls-pemfile", "serde", "serde_json", @@ -2811,9 +2799,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -2837,9 +2825,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.21.10" +version = "0.21.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +checksum = "7fecbfb7b1444f477b345853b1fce097a2c6fb637b2bfb87e6bc5db0f043fae4" dependencies = [ "log", "ring 0.17.8", @@ -2952,6 +2940,21 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "scripts" +version = "0.1.0" +dependencies = [ + "anyhow", + "dotenv", + "fuels", + "hex", + "rand", + "spark-market-sdk", + "src20_sdk", + "tokio", + "utils", +] + [[package]] name = "scrypt" version = "0.10.0" @@ -3057,29 +3060,29 @@ checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813" dependencies = [ "itoa", "ryu", @@ -3110,9 +3113,9 @@ dependencies = [ [[package]] name = "serde_with" -version = "3.7.0" +version = "3.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a" +checksum = "2c85f8e96d1d6857f13768fcbd895fcb06225510022a2774ed8b5150581847b0" dependencies = [ "serde", "serde_derive", @@ -3153,9 +3156,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -3195,6 +3198,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "spark-market-sdk" +version = "0.1.0" +dependencies = [ + "anyhow", + "fuels", + "rand", + "tokio", +] + [[package]] name = "spin" version = "0.5.2" @@ -3223,7 +3236,7 @@ dependencies = [ [[package]] name = "src20_sdk" version = "0.0.3" -source = "git+https://github.com/compolabs/src-20.git?branch=master#b424fdd6d8a11bcdbfe4be55dea8ac81edea67de" +source = "git+https://github.com/compolabs/src-20.git?branch=master#da1900d2881d44208064111ad4f3bccd8b37338b" dependencies = [ "dotenv", "fuels", @@ -3300,9 +3313,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -3323,7 +3336,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3374,24 +3387,36 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "tests" +version = "0.1.0" +dependencies = [ + "anyhow", + "fuels", + "spark-market-sdk", + "src20_sdk", + "tokio", + "utils", +] + [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3477,7 +3502,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3507,7 +3532,7 @@ version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ - "rustls 0.21.10", + "rustls 0.21.11", "tokio", ] @@ -3623,7 +3648,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -3736,6 +3761,10 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "utils" +version = "0.1.0" + [[package]] name = "uuid" version = "0.8.2" @@ -3803,7 +3832,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-shared", ] @@ -3837,7 +3866,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3915,7 +3944,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3933,7 +3962,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3953,17 +3982,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -3974,9 +4004,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -3986,9 +4016,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -3998,9 +4028,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -4010,9 +4046,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -4022,9 +4058,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -4034,9 +4070,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -4046,9 +4082,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" @@ -4095,7 +4131,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] [[package]] @@ -4115,5 +4151,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.60", ] diff --git a/Cargo.toml b/Cargo.toml index 39918ef..fd573ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,53 +1,22 @@ -[package] -name = "orderbook" -description = "A cargo-generate template for Rust + Sway integration testing." +[workspace] +resolver = "1" +members = [ + "spark-market-sdk", + "scripts", + "tests", + "utils", +] + +[workspace.package] +authors = ["alexey "] version = "0.1.0" edition = "2021" -authors = ["alexey "] license = "Apache-2.0" +rust-version = "1.75.0" -[dependencies] +[workspace.dependencies] +anyhow = "1.0.81" fuels = { version = "0.55.1", features = ["fuel-core-lib"] } rand = "0.8.5" -tokio = { version = "1.12", features = ["rt", "macros"] } src20_sdk = { git = "https://github.com/compolabs/src-20.git", branch = "master" } -dotenv = "0.15.0" -hex = "0.4" - -[[test]] -harness = true -name = "integration_tests" -path = "tests/harness.rs" - - -[[bin]] -name = "create_market" -path = "scripts/create_market.rs" - -[[bin]] -name = "create_order" -path = "scripts/create_order.rs" - -[[bin]] -name = "cancel_order" -path = "scripts/cancel_order.rs" - -[[bin]] -name = "deploy" -path = "scripts/deploy.rs" - -[[bin]] -name = "match_orders" -path = "scripts/match_orders.rs" - -[[bin]] -name = "create_accounts_with_tokens" -path = "scripts/create_accounts_with_tokens.rs" - -[[bin]] -name = "init_system" -path = "scripts/init_system.rs" - -[[bin]] -name = "fill_orderbook" -path = "scripts/fill_orderbook.rs" \ No newline at end of file +tokio = { version = "1.12", features = ["rt", "macros"] } diff --git a/Forc.lock b/Forc.lock deleted file mode 100644 index 74e0598..0000000 --- a/Forc.lock +++ /dev/null @@ -1,27 +0,0 @@ -[[package]] -name = "core" -source = "path+from-root-566CA1D5F8BEAFBF" - -[[package]] -name = "i64" -source = "git+https://github.com/compolabs/i64?default-branch#b983e37ec72b60a3544bde52babebec61b15c710" -dependencies = ["std"] - -[[package]] -name = "orderbook" -source = "member" -dependencies = [ - "i64", - "reentrancy", - "std", -] - -[[package]] -name = "reentrancy" -source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.18.0#8d196e9379463d4596ac582a20a84ed52ff58c69" -dependencies = ["std"] - -[[package]] -name = "std" -source = "git+https://github.com/fuellabs/sway?tag=v0.49.3#0dc6570377ee9c4a6359ade597fa27351e02a728" -dependencies = ["core"] diff --git a/Forc.toml b/Forc.toml deleted file mode 100644 index d7fbaaa..0000000 --- a/Forc.toml +++ /dev/null @@ -1,2 +0,0 @@ -[workspace] -members = ["contract"] diff --git a/contract/Forc.lock b/contract/Forc.lock index 5a413d6..74e0598 100644 --- a/contract/Forc.lock +++ b/contract/Forc.lock @@ -18,7 +18,7 @@ dependencies = [ [[package]] name = "reentrancy" -source = "git+https://github.com/FuelLabs/sway-libs?default-branch#7765aff5ed9cf76c789a95b1fde9ff19462623fd" +source = "git+https://github.com/FuelLabs/sway-libs?tag=v0.18.0#8d196e9379463d4596ac582a20a84ed52ff58c69" dependencies = ["std"] [[package]] diff --git a/contract/Forc.toml b/contract/Forc.toml index 7b6c53e..cdf1eac 100644 --- a/contract/Forc.toml +++ b/contract/Forc.toml @@ -5,5 +5,5 @@ license = "Apache-2.0" name = "orderbook" [dependencies] -reentrancy = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.18.0" } i64 = { git = "https://github.com/compolabs/i64" } +reentrancy = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.18.0" } diff --git a/contract/fuel-toolchain.toml b/contract/fuel-toolchain.toml new file mode 100644 index 0000000..ae7d2a7 --- /dev/null +++ b/contract/fuel-toolchain.toml @@ -0,0 +1,6 @@ +[toolchain] +channel = "beta-5" + +[components] +forc = "0.49.3" +fuel-core = "0.22.1" diff --git a/contract/src/events.sw b/contract/src/events.sw index b914ab6..12076c8 100644 --- a/contract/src/events.sw +++ b/contract/src/events.sw @@ -6,7 +6,7 @@ pub struct MarketCreateEvent { asset_id: AssetId, asset_decimals: u32, timestamp: u64, - tx_id: b256 + tx_id: b256, } pub struct TradeEvent { @@ -19,17 +19,15 @@ pub struct TradeEvent { sell_order_id: b256, buy_order_id: b256, timestamp: u64, - tx_id: b256 + tx_id: b256, } - -enum OrderChangeEventIdentifier{ +enum OrderChangeEventIdentifier { OrderOpenEvent: (), OrderCancelEvent: (), OrderMatchEvent: (), } - pub struct OrderChangeEvent { order_id: b256, sender: Identity, @@ -39,7 +37,7 @@ pub struct OrderChangeEvent { order: Option, } -impl OrderChangeEvent{ +impl OrderChangeEvent { pub fn open(id: b256, order: Option) -> self { Self { order_id: id, @@ -47,34 +45,29 @@ impl OrderChangeEvent{ sender: std::auth::msg_sender().unwrap(), identifier: OrderChangeEventIdentifier::OrderOpenEvent, timestamp: std::block::timestamp(), - tx_id: std::tx::tx_id() + tx_id: std::tx::tx_id(), } } - - pub fn cancel(order_id: b256, order: Option)-> self{ + pub fn cancel(order_id: b256, order: Option) -> self { Self { order_id, order, sender: std::auth::msg_sender().unwrap(), identifier: OrderChangeEventIdentifier::OrderCancelEvent, timestamp: std::block::timestamp(), - tx_id: std::tx::tx_id() + tx_id: std::tx::tx_id(), } } - - pub fn match_orders(id: b256, order: Option)-> self{ + pub fn match_orders(id: b256, order: Option) -> self { Self { order_id: id, order, sender: std::auth::msg_sender().unwrap(), identifier: OrderChangeEventIdentifier::OrderMatchEvent, timestamp: std::block::timestamp(), - tx_id: std::tx::tx_id() + tx_id: std::tx::tx_id(), } } - } - - diff --git a/contract/src/main.sw b/contract/src/main.sw index 7d91da5..054ace6 100644 --- a/contract/src/main.sw +++ b/contract/src/main.sw @@ -22,11 +22,10 @@ use std::hash::*; use std::storage::storage_vec::*; use std::tx::tx_id; - configurable { QUOTE_TOKEN: AssetId = BASE_ASSET_ID, QUOTE_TOKEN_DECIMALS: u32 = 9, - PRICE_DECIMALS: u32 = 9 + PRICE_DECIMALS: u32 = 9, } storage { @@ -34,7 +33,6 @@ storage { markets: StorageMap = StorageMap {}, orders_by_trader: StorageMap> = StorageMap {}, order_indexes_by_trader: StorageMap> = StorageMap {}, - order_change_events: StorageMap> = StorageMap {}, } @@ -59,7 +57,7 @@ abi OrderBook { #[storage(read)] fn market_exists(asset_id: AssetId) -> bool; - + #[storage(read)] fn get_market_by_id(asset_id: AssetId) -> Market; @@ -90,12 +88,12 @@ impl OrderBook for Contract { asset_id: asset_id, asset_decimals: asset_decimals, timestamp: timestamp(), - tx_id: tx_id() + tx_id: tx_id(), }); } #[storage(read)] - fn get_market_by_id(asset_id: AssetId) -> Market{ + fn get_market_by_id(asset_id: AssetId) -> Market { storage.markets.get(asset_id).read() } @@ -109,7 +107,7 @@ impl OrderBook for Contract { reentrancy_guard(); let market = storage.markets.get(base_token).try_read(); - require(base_size.value != 0,Error::BaseSizeIsZero); + require(base_size.value != 0, Error::BaseSizeIsZero); require(market.is_some(), Error::NoMarketFound); require(base_price != 0, Error::BadPrice); @@ -211,9 +209,17 @@ impl OrderBook for Contract { let mut tmp = order_sell; tmp.base_size = tmp.base_size.flip(); - let trade_size = min(order_sell.base_size.value, order_buy.base_size.value.mul_div(order_buy.base_price, order_sell.base_price)); + let trade_size = min( + order_sell + .base_size + .value, + order_buy + .base_size + .value + .mul_div(order_buy.base_price, order_sell.base_price), + ); tmp.base_size.value = trade_size; - + let seller: Address = order_sell.trader; let (sellerDealAssetId, sellerDealRefund) = order_return_asset_amount(tmp); remove_update_order_internal(order_sell, tmp.base_size); @@ -253,7 +259,7 @@ impl OrderBook for Contract { sell_order_id: order_sell.id, buy_order_id: order_buy.id, timestamp: timestamp(), - tx_id: tx_id() + tx_id: tx_id(), }); } @@ -269,10 +275,10 @@ impl OrderBook for Contract { #[storage(read)] fn get_order_change_events_by_order(order: b256) -> Vec { - storage.order_change_events.get(order).load_vec() + storage.order_change_events.get(order).load_vec() } - fn get_configurables() -> (AssetId, u32, u32){ + fn get_configurables() -> (AssetId, u32, u32) { (QUOTE_TOKEN, QUOTE_TOKEN_DECIMALS, PRICE_DECIMALS) } } @@ -311,7 +317,7 @@ fn update_order_internal(order: Order, base_size: I64) -> ((AssetId, u64), (Asse #[storage(read, write)] fn cancel_order_internal(order: Order) -> (AssetId, u64) { - require(order.base_size.value != 0,Error::BaseSizeIsZero); + require(order.base_size.value != 0, Error::BaseSizeIsZero); let refund = order_return_asset_amount(order); remove_update_order_internal(order, order.base_size.flip()); refund @@ -321,14 +327,36 @@ fn cancel_order_internal(order: Order) -> (AssetId, u64) { fn remove_update_order_internal(order: Order, base_size: I64) { if (order.base_size == base_size.flip()) { let pos_id = storage.order_indexes_by_trader.get(order.trader).get(order.id).read() - 1; // pos + 1 indexed - require(storage.order_indexes_by_trader.get(order.trader).remove(order.id), Error::CannotRemoveOrderIndex); + require( + storage + .order_indexes_by_trader + .get(order.trader) + .remove(order.id), + Error::CannotRemoveOrderIndex, + ); let last_pos = storage.orders_by_trader.get(order.trader).len() - 1; if last_pos != pos_id { let last_id = storage.orders_by_trader.get(order.trader).get(last_pos).unwrap().read(); - require(storage.orders_by_trader.get(order.trader).swap_remove(pos_id) == order.id, Error::CannotRemoveOrderByTrader); - storage.order_indexes_by_trader.get(order.trader).insert(last_id, pos_id + 1); + require( + storage + .orders_by_trader + .get(order.trader) + .swap_remove(pos_id) == order.id, + Error::CannotRemoveOrderByTrader, + ); + storage + .order_indexes_by_trader + .get(order.trader) + .insert(last_id, pos_id + 1); } else { - require(storage.orders_by_trader.get(order.trader).pop().unwrap() == order.id, Error::CannotRemoveOrderByTrader); + require( + storage + .orders_by_trader + .get(order.trader) + .pop() + .unwrap() == order.id, + Error::CannotRemoveOrderByTrader, + ); } require(storage.orders.remove(order.id), Error::CannotRemoveOrder); } else { diff --git a/contract/src/math.sw b/contract/src/math.sw index f806f84..7dfee2a 100644 --- a/contract/src/math.sw +++ b/contract/src/math.sw @@ -9,11 +9,15 @@ impl u64 { div_result.as_u64().unwrap() } - pub fn mul_div_rounding_up(self, mul_to: u64, div_to: u64) -> u64{ + pub fn mul_div_rounding_up(self, mul_to: u64, div_to: u64) -> u64 { let mul_result = U128::from((0, self)) * U128::from((0, mul_to)); let div_to = U128::from((0, div_to)); let div_result = mul_result / div_to; - let add = if div_result * div_to < mul_result {1} else {0}; + let add = if div_result * div_to < mul_result { + 1 + } else { + 0 + }; div_result.as_u64().unwrap() + add } diff --git a/scripts/Cargo.toml b/scripts/Cargo.toml new file mode 100644 index 0000000..4930559 --- /dev/null +++ b/scripts/Cargo.toml @@ -0,0 +1,58 @@ +[package] +name = "scripts" +authors = { workspace = true } +version = { workspace = true } +edition = { workspace = true } +license = { workspace = true } +rust-version = { workspace = true } + +[dependencies] +anyhow = { workspace = true } +dotenv = "0.15.0" +fuels = { workspace = true } +hex = "0.4" +rand = { workspace = true } +spark-market-sdk = { path = "../spark-market-sdk" } +src20_sdk = { workspace = true } +tokio = { workspace = true } +utils = { path = "../utils" } + +[[bin]] +name = "create_market" +path = "create_market.rs" +test = false + +[[bin]] +name = "create_order" +path = "create_order.rs" +test = false + +[[bin]] +name = "cancel_order" +path = "cancel_order.rs" +test = false + +[[bin]] +name = "deploy" +path = "deploy.rs" +test = false + +[[bin]] +name = "match_orders" +path = "match_orders.rs" +test = false + +[[bin]] +name = "create_accounts_with_tokens" +path = "create_accounts_with_tokens.rs" +test = false + +[[bin]] +name = "init_system" +path = "init_system.rs" +test = false + +[[bin]] +name = "fill_orderbook" +path = "fill_orderbook.rs" +test = false diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 0000000..538a966 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,14 @@ +## Running the scripts + +To run a script change into the `/scripts` directory and follow the example pattern to run your script. + +```bash +cargo run --bin