Autonomous multi-chain stablecoin infrastructure that combines:
- Overcollateralized minting + liquidation (
StableArbVault) - On-chain supply controls (
SUSD,PegDefender) - Cross-chain supply actions via CCIP (
CrossChainBuyback) - Off-chain peg monitoring + decentralized action dispatch via Chainlink CRE (
cre-workflow) - Operator and user dashboard (Next.js frontend)
- Architecture
- Repository Layout
- Core Components
- How Peg Defense Works
- Prerequisites
- Environment Configuration
- Quick Start
- Smart Contracts (Hardhat)
- CRE Workflow
- Frontend Dashboard
- Cross-Chain (CCIP) Flow
- Deployment Runbook
- Testing
- Verification & Observability
- Security Notes
- Deployed Addresses
- Chainlink Usage
flowchart TD
subgraph Offchain[Chainlink CRE / DON]
Cron["Cron Trigger (5m)"] --> Monitor["peg-monitor.ts"]
Monitor --> Decision["action-dispatcher.ts"]
Decision --> Report["DON consensus + signed report"]
end
subgraph OnchainSepolia[Sepolia]
Forwarder[Keystone Forwarder]
Defender[PegDefender.sol]
Vault[StableArbVault.sol]
SUSD[SUSD.sol]
BuybackSrc[CrossChainBuyback.sol]
end
subgraph OnchainArb[Arbitrum Sepolia]
BuybackDst[CrossChainBuyback.sol]
SUSDArb[SUSD.sol]
end
Report -->|evmClient.writeReport| Forwarder
Forwarder -->|onReport| Defender
Defender -->|MINT / BUYBACK| SUSD
Defender -->|optional trigger| BuybackSrc
BuybackSrc -->|ccipSend| BuybackDst
BuybackDst -->|mint / burn| SUSDArb
Vault --> SUSD
stablearb/
├─ contracts/ # Hardhat project (Solidity, tests, deploy/verify scripts)
├─ cre-workflow/ # Chainlink CRE TypeScript workflow for peg monitoring/actions
├─ frontend/ # Next.js dashboard + minting UI + API routes
├─ docs/ # Additional protocol/integration docs
├─ demo-video/ # Separate remotion/demo asset project
└─ README.md # This file
-
SUSD.sol- ERC-20 token (
StableArb USD) - Mint/burn restricted to an authorized vault/controller
- ERC-20 token (
-
StableArbVault.sol- Collateralized minting and debt accounting
- Key parameters:
- Minimum collateral ratio: 150%
- Liquidation threshold: 120%
- Liquidation bonus: 10%
- Supports ETH collateral (
address(0)) and optional ERC-20 collateral with Chainlink Data Feeds
-
PegDefender.sol- Receives signed CRE report through forwarder (
onReport) - Decodes
(price, actionType, amount)and executes:BUYBACK→ burn SUSDMINT→ mint SUSDNONE→ no-op event
- Includes cooldown and restricted forwarder access
- Receives signed CRE report through forwarder (
-
CrossChainBuyback.sol- CCIP sender+receiver contract for cross-chain action propagation
- Supports LINK or native gas fee payment for CCIP sends
- Enforces allowed source chain/sender on receive side
index.ts: Workflow entrypoint, cron trigger, orchestrationpeg-monitor.ts: Fetches Data Streams reports and aggregates with median consensusaction-dispatcher.ts: Decides action band + amount; performsevmClient.writeReportincident-reporter.ts: Incident logging helper
- Wallet connection via Wagmi + RainbowKit
- Mint/deposit flows against
StableArbVault - Dashboard pages for metrics and incidents
- Server routes:
GET /api/peg-price(Data Streams-backed)GET /api/incidents(readsPegDefenseTriggeredlogs)
- CRE cron triggers every 5 minutes (
cre-workflow/src/config.json). - Workflow fetches Data Streams report using secured credentials.
- DON reaches consensus on observed price.
- If outside peg band ($0.995–$1.005), workflow computes action + amount.
- Workflow submits signed report with
evmClient.writeReport. - On-chain forwarder calls
PegDefender.onReport. PegDefenderexecutesMINT,BUYBACK, orNONEand emitsPegDefenseTriggered.- Optional CCIP message can propagate action to Arbitrum Sepolia receiver.
- Node.js 20+
- npm 10+
- Hardhat (installed via
contracts/package.json) - CRE CLI (
cre) installed and authenticated - Access to:
- Sepolia RPC
- Arbitrum Sepolia RPC
- Etherscan/Arbiscan API keys
- Data Streams credentials
- WalletConnect project id (frontend)
Do not commit real secrets. Rotate any previously exposed keys.
DEPLOYER_ADDRESS=0x...
DEPLOYER_PRIVATE_KEY=0x...
SEPOLIA_RPC_URL=https://...
ARB_SEPOLIA_RPC_URL=https://...
ETHERSCAN_API_KEY=...
ARBISCAN_API_KEY=...
DATA_STREAMS_CLIENT_ID=...
DATA_STREAMS_CLIENT_SECRET=...Required secret IDs:
DATA_STREAMS_CLIENT_IDDATA_STREAMS_CLIENT_SECRETPEG_DEFENDER_ADDRESSCHAIN_IDDATA_STREAMS_FEED_ID
# Wallet
NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID=YOUR_PROJECT_ID
# Sepolia contracts
NEXT_PUBLIC_SUSD_ADDRESS=0x...
NEXT_PUBLIC_VAULT_ADDRESS=0x...
NEXT_PUBLIC_PEG_DEFENDER_ADDRESS=0x...
NEXT_PUBLIC_CROSS_CHAIN_BUYBACK_ADDRESS=0x...
# Arbitrum Sepolia contracts
NEXT_PUBLIC_SUSD_ARB_ADDRESS=0x...
NEXT_PUBLIC_CROSS_CHAIN_BUYBACK_ARB_ADDRESS=0x...
# Server-side
SEPOLIA_RPC_URL=https://...
DATA_STREAMS_ENDPOINT=https://api.testnet-dataengine.chain.link
DATA_STREAMS_CLIENT_ID=...
DATA_STREAMS_CLIENT_SECRET=...cd contracts && npm install
cd ../cre-workflow && npm install
cd ../frontend && npm installcd contracts
npm run compile
npm run testcd frontend
npm run devcd cre-workflow
cre login
cre workflow simulate . --target staging-settingsTo simulate and broadcast writes (if configured):
cre workflow simulate . --target production-settings --broadcastcd contracts
npm run compile
npm run test
npm run deploy:sepolia
npm run register-upkeepscripts/deploy.js— Sepolia deploymentscripts/deployArbitrum.js— Arbitrum Sepolia receiver-side deploymentscripts/deploy-arbitrum.js— alternative Arbitrum deployment pathscripts/deployArbitrumSameAddr.js— nonce-controlled deterministic sequencescripts/registerUpkeep.js/scripts/find-upkeep-id.jsscripts/verify-all.js/scripts/verify-arbitrum.js
Hardhat config defines:
sepoliaarbitrumSepolia
If a script uses --network arbitrum-sepolia, use arbitrumSepolia instead unless you add an alias in config.
Defined in cre-workflow/workflow.yaml:
staging-settingsproduction-settings
Both currently point to:
./src/index.ts./src/config.json./secrets.yaml
- Trigger schedule read from
src/config.json(*/5 * * * *) - Data Streams request to
https://api.testnet-dataengine.chain.link/api/v1/reports/latest - Decision thresholds:
< 0.995→BUYBACK> 1.005→MINT- otherwise
NONE
- Encodes payload as
(uint256 price, string actionType, uint256 amount) - Sends signed report to receiver contract from
PEG_DEFENDER_ADDRESS
- Wallet connect (Sepolia + Arbitrum Sepolia)
- Mint/deposit UX against Vault
- Live peg-price API response
- Incident feed from
PegDefenseTriggeredevents
cd frontend
npm run dev
npm run build
npm run start
npm run lintsequenceDiagram
participant Sep as Sepolia CrossChainBuyback
participant Router as CCIP Router
participant Arb as Arb Sepolia CrossChainBuyback
participant S as SUSD (Arb)
Sep->>Router: ccipSend(actionType, amount, recipient)
Router->>Arb: ccipReceive(message)
Arb->>Arb: verify source chain + sender
alt BUYBACK
Arb->>S: burn(amount)
else MINT
Arb->>S: mint(recipient, amount)
end
cd contracts
npm run deploy:sepoliaCapture deployed addresses for:
SUSDStableArbVaultPegDefenderCrossChainBuyback
Set env first:
export SEPOLIA_BUYBACK_ADDRESS=0x... # Sepolia CrossChainBuybackThen deploy:
cd contracts
hardhat run scripts/deployArbitrum.js --network arbitrumSepoliaUpdate frontend/.env.local with all new addresses.
Set PEG_DEFENDER_ADDRESS, CHAIN_ID, and Data Streams credentials in CRE secret store.
cd cre-workflow
cre workflow simulate . --target production-settings --broadcastContract tests live in contracts/test:
StableArbVault.test.jsPegDefender.test.jsCrossChainBuyback.test.js
Run all:
cd contracts
npm run test- Contract verification scripts
contracts/scripts/verify-all.jscontracts/scripts/verify-arbitrum.js
- Sepolia explorer: https://sepolia.etherscan.io
- Arbitrum Sepolia explorer: https://sepolia.arbiscan.io
- CCIP explorer: https://ccip.chain.link
- Frontend API checks:
/api/peg-price/api/incidents
- Treat all private keys and client secrets as compromised if ever committed.
- Use dedicated deployer accounts per environment.
- Restrict
PegDefender.forwarderto trusted Keystone forwarder only. - Validate CCIP source chain + sender (
setAllowedSource) before enabling receives. - Add pause/guardian controls before mainnet rollout.
- Perform third-party audit before production use.
Sepolia (Ethereum Testnet)
- SUSD Token:
0x461D7501ae9493b4678C60F97A903fc51069152A - StableArbVault:
0x71Fb66498976B7e09fB9FC176Fb1fb53959a4A54 - PegDefender:
0x216760e96222bCe5DC454a3353364FaD8C088999 - CrossChainBuyback:
0x0a468e2506ff15a74c8D094CC09e48561969Aa12
StableArb deeply integrates multiple Chainlink decentralized services to achieve its defining zero-latency peg defense mechanism:
-
Chainlink CRE:
- The off-chain guardian is powered by CRE. The workflow evaluates live data, measures thresholds, forms median consensus from DON operator nodes, and performs computationally heavy margin calculations off-chain, ensuring high scalability and negligible latency before committing the defense payload on-chain.
- Code:
cre-workflow/src(Seepeg-monitor.tsandaction-dispatcher.ts)
-
Chainlink Data Streams:
- Instead of relying on traditional lagging on-chain push oracles, StableArb pulls high-frequency, low-latency market data for the SUSD asset natively inside the CRE workflow. This allows real-time detection of micro-deviations in the peg.
-
Chainlink CCIP (Cross-Chain Interoperability Protocol):
- In order to solve the problem of maintaining exact circulating supply synchrony across a multi-chain environment during a flash market crash, CCIP is used to securely broadcast supply adjustment instructions. When the mainnet Ethereum Sepolia contract executes a buyback or mint, a CCIP payload is simultaneously transmitted to the Arbitrum Sepolia receiver contract to identically mirror the action.
- Code:
contracts/src/CrossChainBuyback.sol