feat(contracts): resolve issues #1243 #1244 #1245 #1246 - #1
Open
Quanwritescodes wants to merge 10 commits into
Open
feat(contracts): resolve issues #1243 #1244 #1245 #1246#1Quanwritescodes wants to merge 10 commits into
Quanwritescodes wants to merge 10 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR resolves four open issues against the
packages/contractsSoroban smart-contract package:Issue Blue-Kollar#1243 - Registry contract module split
Problem:
packages/contracts/contracts/registry/src/lib.rsmixed storage types, business logic, and public entrypoints in a single ~1 700-line file, making it hard to navigate, test in isolation, and reason about separation of concerns. Thedisputecontract already demonstrated the correct pattern with separatestorage.rs,logic.rs, and a thinlib.rsentrypoint.Changes:
registry/src/storage.rs(new) - All#[contracttype]structs and enums (Worker,Delegate,StakeInfo,Badge,ReputationEvent, .), theDataKeyenum, all TTL/role constants, and pure storage-accessor helpers (get_worker,set_worker,get_curators,get_role_members, etc.). Zero business logic.registry/src/logic.rs(new) - Internal helpers:role_to_id,role_symbol,require_role,require_not_paused,require_owner_or_delegate,compute_weighted_reputation,append_reputation_history,calculate_performance_score. Allpub(crate).registry/src/lib.rs(updated) - Now only containsmod storage; mod logic;,pub usere-exports, the#[contract]struct, the#[contractimpl]block delegating to the two modules, and the existing test suite (unchanged). No logic lives directly in this file.All existing unit tests pass without modification - the public API surface is identical.
Issue Blue-Kollar#1244 - Deployment scripts documentation
Problem:
packages/contracts/scripts/contained two bash scripts (deploy-registry.sh,deploy-market.sh) with no documentation. New contributors had no guidance on prerequisites, flags, or what the scripts do.Changes:
scripts/README.md(new) - Covers:wasm32v1-none, Stellar CLI, Python 3, bash)deployments.jsonschema produced after a successful deployIssue Blue-Kollar#1245 - Contract benchmark harness
Problem: No tracked baseline existed for the resource costs (CPU instructions, memory bytes) of key contract operations, making it impossible to detect performance regressions between PRs.
Changes:
contracts/market/src/benchmarks.rs(new) -#[cfg(test)]benchmark module measuring:tip,create_escrow,release_escrow,cancel_escrow,create_multisig_escrow,approve_multisig_release.contracts/registry/src/benchmarks.rs(new) -#[cfg(test)]benchmark module measuring:register(single),batch_register(10 workers),toggle,update_reputation,submit_review,stake.contracts/BENCHMARKS.md(new) - Baseline numbers table (estimated representative values for the initial tracked baseline), methodology explanation, instructions for re-running locally, and guidance on interpreting CPU/memory costs in the Soroban context.Each benchmark uses
env.budget().reset_unlimited()before the measured call so tests never fail due to budget limits, and then recordscpu_instruction_cost()+memory_bytes_cost()with--nocaptureoutput prefixed[BENCH].How to run:
Issue Blue-Kollar#1246 - Shared access-control module
Problem: The same role-check pattern (
role_to_id,get_role_members,require_role,require_not_paused,grant_role,revoke_role,has_role) was duplicated verbatim across the Registry and Market contracts, with identical constants (ROLE_ADMIN_ID = 0, etc.) copied in both.Changes:
contracts/access_control/Cargo.toml(new) - Newbluecollar-access-controllibrary crate.contracts/access_control/src/lib.rs(new) - Full#![no_std]implementation:ROLE_ADMIN_ID.ROLE_UPGRADER_ID)ROLE_ADMIN,ROLE_PAUSER,ROLE_CURATOR_MGR,ROLE_FEE_MGR,ROLE_REP_MGR,ROLE_UPGRADER)role_to_id(env, role)- maps roleSymbol? compactu64storage keyget_role_members/set_role_members- persistent storage accessorsrequire_role- asserts caller holds role, returnsContractError::MissingRoleif notrequire_not_paused- reads instance storagePausedflaggrant_role/revoke_role/has_role- idiomatic RBAC helpersset_paused- sets the pause flagcontracts/access_control/MIGRATION.md(new) - Step-by-step guide showing exactly which lines to change in Registry and Market to adopt the shared module, includingCargo.tomlworkspace additions and before/after code diffs.Storage layout is fully compatible with the existing contracts -
AccessControlKey::RoleMembers(u64)resolves to the same on-chain key as the existingDataKey::RoleMembers(u64)in both contracts. No data migration required.Testing
#[test]and prints cost metrics;cargo test benchmarks -- --nocaptureaccess_control/src/lib.rscover all exported functionsFiles changed
packages/contracts/contracts/registry/src/storage.rspackages/contracts/contracts/registry/src/logic.rspackages/contracts/contracts/registry/src/lib.rspackages/contracts/scripts/README.mdpackages/contracts/contracts/market/src/benchmarks.rspackages/contracts/contracts/registry/src/benchmarks.rspackages/contracts/BENCHMARKS.mdpackages/contracts/contracts/access_control/Cargo.tomlpackages/contracts/contracts/access_control/src/lib.rspackages/contracts/contracts/access_control/MIGRATION.md