This guide captures the conventions used by the creator-keys contract so contributors can add a new entrypoint without fighting the existing layout or CI expectations.
Keep new public entrypoints in the main contract implementation in creator-keys/src/lib.rs and group them by responsibility:
- Trade entrypoints such as
buy_keyandsell_keybelong with the trading flow near the other market operations. - Config entrypoints such as fee or price updates belong with the configuration helpers in the same contract implementation.
- Read-only view methods belong near the other quote and profile read methods.
- Admin-only mutators should stay near the other admin-facing entrypoints so the access model is easy to audit.
Use the same auth pattern as the surrounding entrypoints:
admin.require_auth()for protocol-admin-only entrypoints.creator.require_auth()for creator-owned actions.buyer.require_auth()orseller.require_auth()for trade actions that are authorized by the user acting on the market.- Read-only methods should not call
require_auth().
When a function needs to validate the currently authorized address, prefer the same address that the existing entrypoint uses for the relevant role rather than introducing a new authorization model.
New state-changing entrypoints should publish events via env.events().publish(...) using the centralized names and helpers in creator-keys/src/events.rs.
For a new event:
- Add a new event struct to creator-keys/src/events.rs.
- Define a stable event name constant and any topic helpers there.
- Publish the event from the contract entrypoint after the state change is persisted.
- Keep field ordering stable so downstream indexers and tests remain deterministic.
Every new contract function should include tests for:
- a happy path,
- the main error case,
- any relevant state change or regression case.
The repo's minimum test structure lives in docs/minimum-viable-test-structure.md.
The repository CI workflow in .github/workflows/ci.yml expects:
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspaceRun the same checks locally before pushing so the maintainer sees a passing PR.