How cosmo-local-credit/protocol works
Purpose and entry points
CLC Protocol is a Solidity smart-contract system for community asset vouchers, commitment pooling, protocol fees, and multi-hop swaps. On-chain contracts live under src/; their public interfaces are in src/interfaces/. The operational entry point is the Go deployment library at pkg/publish/publish.go, with deployment and upgrade procedures in docs/DEPLOY.md and docs/PUBLISH.md.
Contract domains
The protocol is composed of deployable contract implementations, including identity/indexing and asset primitives: pkg/publish/contracts/accountsindex/accountsindex.go, pkg/publish/contracts/cat/cat.go, and pkg/publish/contracts/giftabletoken/giftabletoken.go. Registry and discovery infrastructure is represented by pkg/publish/contracts/contractregistry/contractregistry.go and pkg/publish/contracts/tokenuniquesymbolindex/tokenuniquesymbolindex.go.
Swap and pricing path
Swap execution is centered on SwapRouter, which supports multi-hop routing through SwapPool instances: pkg/publish/contracts/swaprouter/swaprouter.go and pkg/publish/contracts/swappool/swappool.go. Quote sources/adapters are independently deployable: pkg/publish/contracts/oraclequoter/oraclequoter.go, pkg/publish/contracts/relativequoter/relativequoter.go, and pkg/publish/contracts/decimalquoter/decimalquoter.go. This separates route execution and liquidity/pool state from price-normalization or oracle-derived quote logic.
Fee, distribution, and controls
Protocol economics and transfer controls are separate contracts: pkg/publish/contracts/feepolicy/feepolicy.go, pkg/publish/contracts/protocolfeecontroller/protocolfeecontroller.go, and pkg/publish/contracts/splitter/splitter.go. Time/period and rate-limiting behavior is isolated in pkg/publish/contracts/periodsimple/periodsimple.go and pkg/publish/contracts/limiter/limiter.go. Rescue and faucet functions are separately bounded operational contracts: pkg/publish/contracts/rescuevault/rescuevault.go and pkg/publish/contracts/ethfaucet/ethfaucet.go.
Deployment and upgrade boundary
The Go package embeds compiled bytecode plus Go bindings per contract, e.g. pkg/publish/contracts/swaprouter/SwapRouter.bin and pkg/publish/contracts/swaprouter/swaprouter.go. pkg/publish/publish.go deploys implementations, creates ERC-1967 proxies where applicable, waits for receipts, and checks deployed code. pkg/publish/contracts/erc1967factory/erc1967factory.go is the factory binding used for proxy-oriented and deterministic CREATE2 deployment workflows.
Runtimes and external dependencies
Contracts target Solidity 0.8.34 / Osaka EVM settings through Foundry configuration in foundry.toml; Solidity dependencies are vendored under lib/forge-std and lib/solady. Deployment tooling runs in Go (go.mod) against an EVM RPC endpoint and uses the Arachnid CREATE2 factory for deterministic deployments. The README records production implementation deployments on Celo Mainnet (chain ID 42220).
Control-flow summary
An operator invokes the Go publisher with a signer and chain RPC; it selects embedded bytecode/bindings, deploys or deterministically creates implementations, optionally initializes ERC-1967 proxies, then confirms transaction receipts and runtime code. At runtime, user asset operations flow through token/voucher and index contracts; swaps flow router → pools across hops, using configured quoters; fee policy/controller and splitter contracts calculate, collect, or distribute protocol economics. Registry/index contracts provide the discovery boundary between independently deployed protocol modules.
Main entry points: swaprouter.go Swap router · publish.go Go publisher · protocolfeecontroller.go Protocol fee controller · contractregistry.go Contract registry
Components 21
Deployment boundary
Go tooling deploys and verifies contract implementations and proxies.
- Operator · Supplies signer and EVM RPC endpoint.
- Go publisher · Deploys implementations, proxies, and verifies receipts and code.
pkg/publish/publish.go - Embedded bindings and bytecode · Generated bindings package compiled contract bytecode.
pkg/publish/contracts/swaprouter/swaprouter.go - ERC-1967 factory · Supports proxy-oriented deterministic CREATE2 deployments.
pkg/publish/contracts/erc1967factory/erc1967factory.go - EVM RPC / Celo · Deployment target; production implementations run on Celo Mainnet.
Assets and discovery
Voucher assets, identities, and module discovery.
- Asset primitives · Community asset voucher and token primitives.
pkg/publish/contracts/cat/cat.go - Accounts index
pkg/publish/contracts/accountsindex/accountsindex.go - Token symbol index
pkg/publish/contracts/tokenuniquesymbolindex/tokenuniquesymbolindex.go - Contract registry · Discovery boundary for independently deployed modules.
pkg/publish/contracts/contractregistry/contractregistry.go
Swap and pricing
Multi-hop execution is separate from pool state and quote sources.
- Swap router · Executes multi-hop swap routes.
pkg/publish/contracts/swaprouter/swaprouter.go - Swap pools · Hold pool state for route hops.
pkg/publish/contracts/swappool/swappool.go - Oracle quoter
pkg/publish/contracts/oraclequoter/oraclequoter.go - Relative quoter
pkg/publish/contracts/relativequoter/relativequoter.go - Decimal quoter · Normalizes decimal-based prices.
pkg/publish/contracts/decimalquoter/decimalquoter.go
Economics and controls
Fees, distribution, periods, and bounded operations.
- Fee policy
pkg/publish/contracts/feepolicy/feepolicy.go - Protocol fee controller
pkg/publish/contracts/protocolfeecontroller/protocolfeecontroller.go - Splitter · Distributes protocol economics.
pkg/publish/contracts/splitter/splitter.go - Simple period
pkg/publish/contracts/periodsimple/periodsimple.go - Limiter
pkg/publish/contracts/limiter/limiter.go - Rescue vault · Bounded rescue operations.
pkg/publish/contracts/rescuevault/rescuevault.go - ETH faucet · Bounded faucet operations.
pkg/publish/contracts/ethfaucet/ethfaucet.go
Connections 21
- Operator → Go publisher: invokes
- Go publisher → Embedded bindings and bytecode: selects artifacts
- Go publisher → ERC-1967 factory: uses for proxies / CREATE2
- Go publisher → EVM RPC / Celo: submits and verifies
- ERC-1967 factory → EVM RPC / Celo: creates implementations and proxies
- Go publisher → Contract registry: deploys modules
- Asset primitives → Accounts index: asset identity operations
- Asset primitives → Token symbol index: indexes symbols
- Contract registry → Asset primitives: discovers
- Contract registry → Swap router: discovers
- Contract registry → Protocol fee controller: discovers
- Swap router → Swap pools: routes across hops
- Swap router → Oracle quoter: uses configured quotes
- Swap router → Relative quoter: uses configured quotes
- Swap router → Decimal quoter: uses configured quotes
- Fee policy → Protocol fee controller: defines fees
- Protocol fee controller → Splitter: collects for distribution
- Simple period → Limiter: sets time windows
- Limiter → ETH faucet: bounds access
- Asset primitives → Protocol fee controller: applies protocol economics
- Swap router → Protocol fee controller: applies protocol economics