From 5e4d9f9e4615a55f42692f008ac35cca7c815406 Mon Sep 17 00:00:00 2001 From: Jaiyeola Akinjide Date: Thu, 9 Jul 2026 19:13:42 +0100 Subject: [PATCH 1/3] chore: move pool contract into a Cargo workspace Relocates the existing crate to contracts/pool/ and adds a workspace root Cargo.toml, laying the groundwork for the additional contracts (LP token, factory, router) that will live alongside it. Behavior is unchanged: the workspace's shared target/ dir means the WASM artifact still lands at target/wasm32v1-none/release/nodus_protocol_amm.wasm, and every existing cargo build/test/clippy/fmt invocation still works unmodified from the repo root. [profile.release] moved to the workspace root, since Cargo only honors it there for workspace members. soroban-sdk's version is now declared once via [workspace.dependencies] so every future contract crate stays in lockstep. --- Cargo.toml | 21 ++++--------------- contracts/pool/Cargo.toml | 19 +++++++++++++++++ {src => contracts/pool/src}/errors.rs | 0 {src => contracts/pool/src}/events.rs | 0 {src => contracts/pool/src}/lib.rs | 0 {src => contracts/pool/src}/liquidity_pool.rs | 0 {src => contracts/pool/src}/lp_token.rs | 0 {src => contracts/pool/src}/math.rs | 0 {src => contracts/pool/src}/storage.rs | 0 {src => contracts/pool/src}/traits.rs | 0 {tests => contracts/pool/tests}/fuzz_tests.rs | 0 .../pool/tests}/integration_tests.rs | 0 {tests => contracts/pool/tests}/unit_tests.rs | 0 13 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 contracts/pool/Cargo.toml rename {src => contracts/pool/src}/errors.rs (100%) rename {src => contracts/pool/src}/events.rs (100%) rename {src => contracts/pool/src}/lib.rs (100%) rename {src => contracts/pool/src}/liquidity_pool.rs (100%) rename {src => contracts/pool/src}/lp_token.rs (100%) rename {src => contracts/pool/src}/math.rs (100%) rename {src => contracts/pool/src}/storage.rs (100%) rename {src => contracts/pool/src}/traits.rs (100%) rename {tests => contracts/pool/tests}/fuzz_tests.rs (100%) rename {tests => contracts/pool/tests}/integration_tests.rs (100%) rename {tests => contracts/pool/tests}/unit_tests.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 2393866..a171f73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,10 @@ -[package] -name = "nodus-protocol-amm" -version = "0.1.0" -authors = ["Nodus Protocol Team"] -edition = "2021" -license = "MIT" -description = "Constant-product AMM liquidity pool on Stellar Soroban" +[workspace] +resolver = "2" +members = ["contracts/pool"] -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -testutils = ["soroban-sdk/testutils"] - -[dependencies] +[workspace.dependencies] soroban-sdk = "26.1.0" -[dev-dependencies] -soroban-sdk = { version = "26.1.0", features = ["testutils"] } - [profile.release] overflow-checks = true panic = "abort" diff --git a/contracts/pool/Cargo.toml b/contracts/pool/Cargo.toml new file mode 100644 index 0000000..5d7f568 --- /dev/null +++ b/contracts/pool/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "nodus-protocol-amm" +version = "0.1.0" +authors = ["Nodus Protocol Team"] +edition = "2021" +license = "MIT" +description = "Constant-product AMM liquidity pool on Stellar Soroban" + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +testutils = ["soroban-sdk/testutils"] + +[dependencies] +soroban-sdk = { workspace = true } + +[dev-dependencies] +soroban-sdk = { workspace = true, features = ["testutils"] } diff --git a/src/errors.rs b/contracts/pool/src/errors.rs similarity index 100% rename from src/errors.rs rename to contracts/pool/src/errors.rs diff --git a/src/events.rs b/contracts/pool/src/events.rs similarity index 100% rename from src/events.rs rename to contracts/pool/src/events.rs diff --git a/src/lib.rs b/contracts/pool/src/lib.rs similarity index 100% rename from src/lib.rs rename to contracts/pool/src/lib.rs diff --git a/src/liquidity_pool.rs b/contracts/pool/src/liquidity_pool.rs similarity index 100% rename from src/liquidity_pool.rs rename to contracts/pool/src/liquidity_pool.rs diff --git a/src/lp_token.rs b/contracts/pool/src/lp_token.rs similarity index 100% rename from src/lp_token.rs rename to contracts/pool/src/lp_token.rs diff --git a/src/math.rs b/contracts/pool/src/math.rs similarity index 100% rename from src/math.rs rename to contracts/pool/src/math.rs diff --git a/src/storage.rs b/contracts/pool/src/storage.rs similarity index 100% rename from src/storage.rs rename to contracts/pool/src/storage.rs diff --git a/src/traits.rs b/contracts/pool/src/traits.rs similarity index 100% rename from src/traits.rs rename to contracts/pool/src/traits.rs diff --git a/tests/fuzz_tests.rs b/contracts/pool/tests/fuzz_tests.rs similarity index 100% rename from tests/fuzz_tests.rs rename to contracts/pool/tests/fuzz_tests.rs diff --git a/tests/integration_tests.rs b/contracts/pool/tests/integration_tests.rs similarity index 100% rename from tests/integration_tests.rs rename to contracts/pool/tests/integration_tests.rs diff --git a/tests/unit_tests.rs b/contracts/pool/tests/unit_tests.rs similarity index 100% rename from tests/unit_tests.rs rename to contracts/pool/tests/unit_tests.rs From f20325eb2b893f22cd3d7654c7288334038c37e3 Mon Sep 17 00:00:00 2001 From: Jaiyeola Akinjide Date: Thu, 9 Jul 2026 19:13:53 +0100 Subject: [PATCH 2/3] ci: use cargo fmt --all for workspace compatibility Bare 'cargo fmt' run from a virtual-manifest workspace root isn't guaranteed to cover every member as more contracts are added; --all makes that explicit. Matches the Makefile's lint target, which already used --all. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b969c86..56b21a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -47,4 +47,4 @@ jobs: - name: Clippy run: cargo clippy --all-targets --features testutils -- -D warnings - name: Format check - run: cargo fmt -- --check + run: cargo fmt --all -- --check From fdfc36be6c685b1e7aeb051c18da50f09a90bf5b Mon Sep 17 00:00:00 2001 From: Jaiyeola Akinjide Date: Thu, 9 Jul 2026 19:14:06 +0100 Subject: [PATCH 3/3] docs: update README for the contracts/pool/ layout Also fixes two stale references left over from before the crate was renamed nodus-protocol-amm: the wasm32-unknown-unknown target (CI and rust-toolchain.toml have used wasm32v1-none for a while) and the nodus_amm.wasm filename (actual artifact is nodus_protocol_amm.wasm). --- README.md | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fc79e9e..d7d71d5 100644 --- a/README.md +++ b/README.md @@ -39,21 +39,25 @@ LP tokens are tracked internally in the pool's persistent storage — no separat ## Repository Structure +This is a Cargo workspace; each Soroban contract is its own crate under +`contracts/`. + ``` -src/ - lib.rs Contract entry point — all public functions - liquidity_pool.rs Pool math: optimal amounts, K-invariant, LP mint/burn - lp_token.rs Internal LP ledger: mint, burn, transfer, approve, allowance - math.rs AMM formulas: get_amount_out, get_amount_in, sqrt - storage.rs DataKey enum for all instance + persistent storage keys - events.rs Soroban event wrappers: Mint, Burn, Swap, Sync - errors.rs Stable #[contracterror] enum - traits.rs IAmmPool interface definition - -tests/ - unit_tests.rs Pure math + liquidity-pool unit tests (no Soroban env) - integration_tests.rs Soroban testenv contract interaction tests - fuzz_tests.rs Property tests: k-invariant, sqrt floor, fee monotonicity +contracts/ + pool/ + src/ + lib.rs Contract entry point — all public functions + liquidity_pool.rs Pool math: optimal amounts, K-invariant, LP mint/burn + lp_token.rs Internal LP ledger: mint, burn, transfer, approve, allowance + math.rs AMM formulas: get_amount_out, get_amount_in, sqrt + storage.rs DataKey enum for all instance + persistent storage keys + events.rs Soroban event wrappers: Mint, Burn, Swap, Sync + errors.rs Stable #[contracterror] enum + traits.rs IAmmPool interface definition + tests/ + unit_tests.rs Pure math + liquidity-pool unit tests (no Soroban env) + integration_tests.rs Soroban testenv contract interaction tests + fuzz_tests.rs Property tests: k-invariant, sqrt floor, fee monotonicity ``` --- @@ -114,7 +118,7 @@ make build # or: stellar contract build # Build output used by the deploy scripts -target/wasm32-unknown-unknown/release/nodus_amm.wasm +target/wasm32v1-none/release/nodus_protocol_amm.wasm # Run tests make test @@ -137,11 +141,10 @@ STELLAR_SECRET_KEY=S... TOKEN_0=C... TOKEN_1=C... make deploy-mainnet The deploy script uploads the WASM, deploys a new contract instance, and calls `initialize`. -The crate name is `nodus-amm`, so the generated WASM artifact uses the -underscore form `nodus_amm.wasm`. This differs from the repository name -(`Nodus-Protocol-Smart-Contract`) by design. Keep deploy scripts and manual -commands pointed at `nodus_amm.wasm` unless the crate name is intentionally -changed. +The pool crate is named `nodus-protocol-amm`, so the generated WASM artifact +uses the underscore form `nodus_protocol_amm.wasm`. Keep deploy scripts and +manual commands pointed at that filename unless the crate name is +intentionally changed. ---