Deployment Stages
Config-driven deployment flow, safety gates, and manifest verification for registered issuer stacks.
What this covers
Use the canonical deployment flow for registered-issuer collateral stacks:
DEPLOY_CONFIG=deployments/config/sepolia-m1-staging-active.json forge script script/production/DeployRegisteredIssuerStack.s.sol --rpc-url "$SEPOLIA_RPC_URL"Add --broadcast only after the dry-run plan, config, and verification expectations have been reviewed.
Deployment artifacts
deployments/config/sepolia-m1-staging-active.jsonis the active Sepolia M1 staging config. It uses the current staging AtomicBroker/USDM1 addresses andoracleMode = "fixed"withallowFixedOracle = true, so treat the oracle as staging plumbing rather than production-price readiness.deployments/config/mainnet.jsonis intentionally fail-closed until real addresses, signers, and feeds are filled in.deployments/manifests/receives generated deployment manifests after verified broadcasts.script/production/DeployRegisteredIssuerStack.s.solis the canonical registered-issuer deployment script.
Stages
1. Fill config
- Set
admin,guardian,collateral,stablecoin,atomicBroker,quoteSigner,issuerId, andpriceFeedId. - Set reviewed
mintCapBlockandredeemCapBlockvalues between the transaction and day caps, inclusive. Set nonzero collateral and stablecoinassetRiskCaps.maxAmountSpecifiedandmaxSettlementAbsDeltain each token's atomic units. The checked-in zero values are placeholders and fail validation. - For an existing stablecoin, set
rollingCapManagerto the manager used by a prior issuer source, and provide that source and the approved runtime code hashes. The script rejects first-use manager creation for an existing stablecoin. - For every additional source using the same USDM1 token, retain that manager address.
- Use
oracleMode = "chainlink"for production deployments. - Use
oracleMode = "fixed"only for local/testnet rehearsals withallowFixedOracle = true.
2. Validate config
quoteSignermust be explicit and non-zero.quoteSignercannot equaladminunlessallowAdminQuoteSigner = true.- Mainnet must use an existing stablecoin and live oracle mode.
- Registered-issuer deployments require
managerMintsStablecoin = false.
3. Plan hook address
- The script mines the
HybridCollateralSettlementHookaddress with the required Uniswap v4 permission bits. - The expected hook address and salt are included in the manifest.
- Do not replace this with an arbitrary deployment path.
4. Deploy and wire stack
- Deploy oracle, risk config, collateral manager, settlement controller, broker adapter, hook, and signed-quote router.
- Wire manager to hook/controller, controller to issuer config, adapter operator role, hook oracle/pool config, and router allowlist/codehash.
- Optionally initialize the pool and add liquidity when the config enables those steps.
5. Verify and persist manifest
- The script verifies all critical pointers and roles before writing the manifest.
- Manifest output includes the canonical
rollingCapManager, config hash, deployed addresses, expected hook address, hook salt, and verification status.
Canonical rolling-cap manager flow
Global registered-issuer mint and redemption capacity is shared by every source that settles the same USDM1 token. All such sources must use one canonical RollingCapManager contract. The stablecoin-scoped cap key alone is not sufficient because identical keys stored in different manager contracts still have independent usage accounting.
For a new sample stablecoin created by this script:
rollingCapManagermay be zero because the script resolves the address after deploying the token.- Deploy the registered-issuer stack. The script deploys the manager and initializes its global daily caps.
- Confirm the verified manifest contains the deployed
rollingCapManageraddress. - Use that address for subsequent sources of the same stablecoin. Do not recompute it from a later manager build.
For every subsequent registered-issuer source using the same USDM1 token:
- Verify the prior issuer source's stablecoin and manager pointer against chain state and the reviewed deployment record.
- Set that manager address as
rollingCapManager, setpriorIssuerSource, and pin the approved source and manager runtime code hashes in the additional source's deployment config. Do not leave the manager address as zero. - Run the deployment dry run and confirm the reuse preflight accepts the prior source, manager runtime code, admin role, and stored caps. Existing stored global caps are preserved. If all transaction, block, and day caps are zero for a direction, reuse requires its explicit
allowUncappedGlobalMintorallowUncappedGlobalRedeemapproval. - After deployment, confirm every active source reports the same manager address and has
OPERATOR_ROLEon that manager.
Every deployed registered-issuer source must use the stablecoin-scoped implementation. Do not deploy or activate the legacy source-scoped implementation. Reusing a manager address does not change key derivation embedded in contract bytecode, so the shared-manager invariant requires both the canonical manager address and the stablecoin-scoped source implementation.
Post-deploy checks
The script fails before manifest write if any critical check fails:
CollateralManager.settlementHook()matches the hook.CollateralManager.settlementController()matches the controller.- controller registered-issuer config matches the config file.
- broker adapter grants
OPERATOR_ROLEto the controller. - hook oracle adapter and pool risk config are set.
- registered-issuer hook points to the deployed
RiskConfig, and itspoolAllowedvalue matches the deployment config. - signed-quote router codehash is set and the router is allowlisted.
- registered-issuer
CollateralManagerdoes not have stablecoin minter authority. - issuer source points to the manifest
rollingCapManager. - issuer source has
OPERATOR_ROLEon the canonical manager. - on manager reuse, each global direction has at least one nonzero stored cap or the corresponding explicit uncapped approval; governance-configured limits are preserved rather than required to equal
RiskConfig. - hook address and permission flags match the mined values.
Sepolia rehearsal
Sepolia is for full plumbing validation: config loading, hook mining, deployment, wiring, optional pool initialization, optional liquidity, and post-deploy checks. The checked-in Sepolia config points at the M1 public API testnet flow (api.m1global.xyz with isTestnet=true, Sepolia testnet AtomicBroker, and Sepolia testnet USDM1) and fixed-oracle rehearsal data; switch it to oracleMode = "chainlink" with real feeds before treating a Sepolia run as oracle-readiness evidence.
A successful Sepolia deployment proves the stack is wired. It does not prove production readiness unless the production config also passes signer, oracle, stablecoin, broker, and manifest verification.
Testnet USDM1 funding
Use script/testing/request-usdm1-test-tokens.mjs for M1 testnet permit material. The script defaults to api.m1global.xyz with isTestnet=true; do not use api-staging.m1global.xyz unless you intentionally target M1's internal broker environment.
For a full Sepolia token flow, fund the caller with mock collateral, set M1_JWT, SEPOLIA_RPC_URL, and SEPOLIA_DEPLOYER_PRIVATE_KEY, then run:
node script/testing/request-usdm1-test-tokens.mjs --amount 916500000 --deposit --out /private/tmp/usdm1-test-token-request.json--deposit requests fresh permit material, verifies the attestation's verifying contract matches the configured AtomicBroker, approves the broker for the exact collateral amount, submits deposit(...), and reads the final balances.
Local Sepolia runtime
After a manifest-verified Sepolia deployment, use the root Makefile as the
local operator entrypoint:
cp .env.example .env
make install
make env-check
make runmake run validates runtime environment, including quote-signer private-key
ownership of the manifest quoteSigner, builds the SDK, starts the quote
server, starts the docs server, starts the management interface, and writes
logs/PIDs under .runtime/ only after the quote-server, docs, and interface
HTTP endpoints are reachable.
The interface uses the existing Wagmi 3 connector menu for this Sepolia-first
release. It shows injected wallets, MetaMask, and the local read-only
impersonator connector by default. To enable WalletConnect, set
WALLETCONNECT_PROJECT_ID in .env; make run forwards it to the interface as
VITE_WALLETCONNECT_PROJECT_ID.
Default local URLs:
| Component | URL |
|---|---|
| Quote server | http://127.0.0.1:8080 |
| Docs | http://127.0.0.1:3000 |
| Interface | http://127.0.0.1:5173 |
Useful targets:
| Target | Purpose |
|---|---|
make quote-health | Check GET /healthz on the quote server. |
make interface-check | Run the local interface release gate: Vitest, production build, Playwright smoke, docs type-check, secret scans, and diff hygiene. |
make interface-secret-check | Ensure secret-shaped VITE_* names are not exposed to the browser env surface. |
make working-tree-secret-check | Scan owned files for pasted JWT/private-key material outside ignored dependency/build artifacts. |
make live-qa-check | Validate pool ID, trader, runtime env, and manifest prerequisites before live Sepolia swap QA. |
make m1-request AMOUNT=... | Fetch M1 testnet price attestation and deposit permit material. |
make m1-deposit AMOUNT=... | Submit an AtomicBroker deposit from the configured deployer wallet. |
make registered-issuer-payload POOL_ID=... AMOUNT=... | Fetch adapter-bound M1 permit material and ask the quote server to sign registered-issuer hook data. |
make logs | Follow .runtime/quote-server.log, .runtime/docs.log, and .runtime/interface.log. |
make stop | Stop services started by make run. |
Run make interface-check before review or handoff; it includes
make interface-secret-check so browser VITE_* values stay secret-free and
make working-tree-secret-check to catch pasted JWT/private-key material. Run
make live-qa-check only when preparing the final Sepolia swap QA; it requires
a nonzero bytes32 REGISTERED_ISSUER_POOL_ID, a test trader address from
REGISTERED_ISSUER_TRADER or SEPOLIA_DEPLOYER_ADDRESS, runtime env, and
manifest values.
Keep signer roles separate:
M1_JWTauthenticates calls to the M1 API.- M1 signs the price attestation and deposit permit returned by its API.
REGISTERED_ISSUER_QUOTE_SIGNER_PRIVATE_KEYsigns the protocol quote verified byCollateralSettlementController.
For the current Sepolia manifest, the quote-server key must correspond to
0x6534b63957F4fC12B42B0BC74cE52b200bfE49fB. make env-check derives the
address from REGISTERED_ISSUER_QUOTE_SIGNER_PRIVATE_KEY and fails closed if it
does not match the manifest. Do not run the quote server with the M1 JWT or with
an M1 permit signer.
The browser-facing registered-issuer path calls the quote server endpoint
POST /quote/registered-issuer/m1-deposit. That endpoint keeps M1_JWT and the
quote signer private key on the server, fetches M1 testnet deposit material for
the deployed broker adapter, quotes only the AMM remainder through the official
v4 Quoter when available, and returns encoded hook data plus the total expected
output to the interface.
Required validation before PR or broadcast
forge test --match-path 'test/*Deploy*.t.sol'
forge test
./tools/check-contract-size.sh
forge build --skip test --skip script --sizes