Production-oriented Soroban smart contracts for Lily Protocol on Stellar.
lily-contracts is the on-chain smart contract repository for Lily Protocol, an autonomous agent finance stack on Stellar. This workspace provides the protocol foundation for agent identity, wallet policy, payment settlement primitives, and global protocol configuration, with contributor-friendly structure for future protocol expansion.
Lily Protocol needs contract infrastructure that is secure, modular, and understandable by external contributors. This repository is designed to support:
- Agent registration and identity records
- Wallet and policy binding for AgentLily-controlled accounts
- Payment intent creation and asynchronous settlement flows
- Protocol-wide configuration and admin controls
- Shared storage, event, and error conventions across contracts
.
├── contracts
│ ├── identity
│ ├── payments
│ ├── protocol
│ └── wallet
├── crates
│ ├── lily-common
│ └── lily-test-support
├── .github
│ ├── ISSUE_TEMPLATE
│ └── workflows
├── scripts
├── Cargo.toml
└── Makefile
Global protocol configuration contract. Handles one-time initialization, admin transfer, fee basis points, and treasury configuration.
Agent identity registry. Supports protocol bootstrapping, agent registration, controller rotation, metadata updates, and admin deactivation.
Wallet policy registry. Maintains agent-to-wallet bindings, settlement asset symbols, spend limits, and enabled state toggles.
Binding lifecycle:
bind_walletcreates a brand-new binding and fails if the agent already has one.rebind_walletexplicitly replaces an existing binding (enabled or disabled) with a new wallet, asset, and spend limit, resetting revision to 0.update_spend_limitandset_enabledmutate the current binding without replacing it.
This split prevents the silent state overwrites that would occur if bind_wallet were reused after a binding had been disabled.
Payment intent and settlement primitive. Tracks payment intents, allows payer-side cancellation, and supports admin-driven settlement finalization.
See Payment intent indexes for payer pagination semantics and storage-cost considerations.
Shared contract utilities, typed protocol errors, payment status enum, basis point guards, and storage TTL helpers.
Reusable Soroban test helpers for local environments, synthetic addresses, and string conversion.
- Authorization model — function-by-function authorization matrix for every public contract function, with the reasoning behind each choice.
- Rust toolchain with
cargoandrustfmt clippycomponent available for lintingstellar-clifor contract artifact workflows and deploymentwasm32v1-nonetarget installed for Wasm builds
Official Stellar docs currently recommend:
- A Rust workspace with contracts under
contracts/* soroban-sdk = "22"for current Soroban contractsstellar-cliinstallation viabrew install stellar-cli,cargo install --locked stellar-cli, or the Stellar installer
git clone https://github.com/lily-protocol/lily-contracts.git
cd lily-contracts
make fmt
make testIf you need the CLI locally:
brew install stellar-cliIf you need the Wasm target:
rustup target add wasm32v1-noneYou can inspect the local toolchain status with:
./scripts/check-tooling.shBefore deploying or invoking contracts, check that a Soroban RPC endpoint is responding:
SOROBAN_RPC_URL=https://soroban-testnet.stellar.org ./scripts/rpc-health.shThe health probe calls both getHealth and getLatestLedger and exits non-zero on an HTTP, transport, or JSON-RPC failure.
make fmt
make fmt-check
make lint
make check
make test
make build
make build-wasm
make artifacts
make ci
The `make artifacts` target also generates `dist/manifest.json` with sha256 hashes, package versions, git commit, and build profile for each Wasm artifact.The lint target runs clippy with --all-features and the pedantic group enabled. A workspace allow-list suppresses stylistic lints that are not actionable for this codebase (must_use_candidate, needless_pass_by_value, similar_names, missing_panics_doc, should_panic_without_expect).
This repository intentionally ships a real, reviewable foundation without prematurely implementing every protocol feature. The current contracts establish:
- Typed storage keys and typed return structs
- Explicit initialization guards
- Auth-gated admin and actor actions
- Event emission on state transitions (see docs/EVENTS.md)
- Fee configuration in basis points with a documented treasury role (see docs/FEES.md)
- Conservative state transitions for settlement lifecycle
- Clear separation between protocol domains
- Documented storage layouts, TTL policy, and auth model (see docs/ARCHITECTURE.md)
- Event compatibility policy — additive and versioned change rules for topics and payloads consumed by indexers
See Contract Testing for guidance on mock authorization, real-auth negative tests, and the current authorization coverage debt.
For the signer requirements of every contract entry point and the reasoning behind each role boundary, see the authorization model.
- On-chain agent reputation and credential attestations
- Multi-role governance and timelocked admin changes
- Escrowed settlement and token transfer integration
- Cross-contract composition between identity, wallet, and payments
- Upgrade and migration playbooks
- Fuzzing, invariants, and deeper adversarial testing
- Mainnet deployment manifests and release signing
- CONTRIBUTING.md — setup, conventions, and PR expectations.
- docs/ERRORS.md — protocol error codes, raise sites, and triggering conditions.
Read CONTRIBUTING.md before opening a pull request and review the project's CHANGELOG.md for unreleased contract and tooling changes. Contributors should keep changes scoped to a clear protocol concern and include tests for any state transition, auth path, or storage behavior they modify.
This is smart contract infrastructure. Avoid introducing:
- Implicit authorization paths
- Unbounded storage growth without design review
- Silent state overwrites
- Incomplete initialization or upgrade assumptions
- Panic-driven business logic where typed errors are more appropriate
If you believe you’ve found a vulnerability, please follow the security guidance in CONTRIBUTING.md.