Smart contracts
Solidity catalog, authorization flow, and deploy scripts.
Foundry project: contracts/
Solidity 0.8.24, optimizer 200 runs, via_ir enabled.
Live addresses: Deployments (X Layer mainnet 196).
Contract catalog
| Contract | File | Role |
|---|---|---|
EmergencyControl |
EmergencyControl.sol |
Global / org pause |
OrganizationRegistry |
OrganizationRegistry.sol |
Register org; active checks |
VendorRegistry |
VendorRegistry.sol |
Vendor records + verification |
PaymentPolicyRegistry |
PaymentPolicyRegistry.sol |
Versioned policy → processor, circuitId, configHash |
PaymentAuthorization |
PaymentAuthorization.sol |
Relayer-only authorize; TapeOut re-eval; replay / expiry |
BusinessTreasury |
BusinessTreasury.sol |
Per-org USDC balances; execute after auth consume |
PaymentRouter |
PaymentRouter.sol |
Token allowlist + adapter allowlist |
AuditRegistry |
AuditRegistry.sol |
On-chain audit commitments |
ITapeOutProcessor |
interfaces/ITapeOutProcessor.sol |
eval(uint256,bytes) returns (bytes) |
MockUSDC / MockTapeOutProcessor |
mocks/ |
Local tests, Anvil, and testnet settlement re-eval |
X Layer mainnet deployment (196)
| Contract | Address |
|---|---|
| EmergencyControl | 0xcc5661D1471e9e61B37Df5Ad5D2E1B2C5578c884 |
| OrganizationRegistry | 0xD2445389196f2c502AB5ec6f49a90cc04BB71ff5 |
| VendorRegistry | 0x3dE7a4C348F7415087a9Cf58FBC57256bAF1eb4b |
| PaymentPolicyRegistry | 0x0Af7a5DDE4f2B30772eE60F80EfD516A94C56A52 |
| ControlsRegistry | 0xF10cDEB14604F6311195dA90B6076713f7f42f14 |
| PaymentAuthorization | 0x96778c369D85aaCCBF6DE0BcD0671B048E16E5CA |
| PaymentRouter | 0xE3F25b5e9Da3dFA72C0a12f05fd45cc0dD4243dD |
| BusinessTreasury | 0x951adC47425FB4441A3D057d3e10Fa5D4eC27Ed1 |
| AuditRegistry | 0xEc114e0B3d39CaFEBE9d9aC25932A75958A7fbDC |
- Native USDC:
0xB6CEceAB302E2E4948951eE7843FC24E92933061 - TapeOut: Cerebr
0xB04EB79D1A5EECaabAAfF7B77d7c27578EE693FFcircuit#1 - Organization ID:
0x603fd1000e3f9b350efdfbeaad5864a151b4bdac12228b5056569a9b2478f82a - Policy version:
1 - Full book + env mapping: deployments.md
- Verification:
./scripts/verify-xlayer.sh(Sourcify)
Authorization flow
relayer → PaymentAuthorization.authorize(AuthRequest)
├─ emergency / org active
├─ approvals >= required
├─ vendorEligible
├─ policy version exists
├─ if policy.processor != 0:
│ ITapeOutProcessor(processor).eval(circuitId, circuitInputs)
│ require LSB of output == 1
└─ store Authorization (unconsumed, 24h expiry)
relayer → BusinessTreasury.executeAuthorizedPayment(...)
├─ consume authorization (paymentId, amount, token, destination match)
└─ transfer native USDC to destination
AuthRequest includes circuitResult (packed flags) and circuitInputs (LSB-packed TapeOut inputs). Opaque non-zero circuitResult alone is not sufficient when a processor is bound.
BusinessTreasury
deposit(organizationId, amount)— pulls native USDC into vault accountingavailable(organizationId)— balance minus reservedexecuteAuthorizedPayment— relayer only; one execution perpaymentId- Token and
chainIdAllowfixed at construction
Testing
cd contracts
forge test
Coverage includes authorize + pay, replay, insufficient approvals, pause, double execute, and TapeOut-fail blocks auth.
Deploy
export DEPLOYER_PRIVATE_KEY=0x... # funded OKB; never commit
export XLAYER_CHAIN_ID=196
export XLAYER_RPC_URL=https://testrpc.xlayer.tech/terigon
export USDC_TOKEN_ADDRESS=0xB6CEceAB302E2E4948951eE7843FC24E92933061
./scripts/deploy-xlayer.sh
- Production-shaped:
script/Deploy.s.sol - Helper:
scripts/deploy-xlayer.sh - Local Anvil:
script/DeployLocal.s.sol
On testnet, deploy binds a settlement-compatible TapeOut processor for on-chain re-eval. API TapeOut eval continues to use mainnet Cerebr (TAPEOUT_EVAL_CHAIN_ID=196). See tapeout-xlayer.md.
Integration with the API
apps/api/src/payments/settlement.ts:
1. simulateContract(authorize) → capture authorizationId
2. writeContract(authorize)
3. writeContract(executeAuthorizedPayment) with that id
4. Assert native USDC via assertNativeUsdc
Security notes
See security.md. Before mainnet customer funds: audit, multisig ownership, KMS relayer, pinned processor bytecode, pause runbooks.