[FEATURE] USDC Swap Chain
Describe the feature you'd like
Implement a consensus-driven oracle on the USDC Chain to efficiently integrate off-chain data from the Ethereum blockchain, focusing on the synchronization of lock and close orders through a robust state machine.
Motivation
The integration of off-chain data via an oracle enables real-time functionality and reliability in handling transactions on the USDC Chain. This ensures that the system accurately reflects finalized Ethereum blocks and maintains integrity in order processing.
Additional context
The USDC Chain must operate with the understanding that Ethereum does not provide immediate block finality. The use of a committee for consensus, combined with an efficient WebSocket notifier, is critical for managing order flows and ensuring that both lock and close orders are appropriately processed in line with finalized Ethereum block updates.
Possible implementation
- Modify
sock.goto enable effective communication with the Ethereum blockchain for new block arrivals. - Implement a WebSocket notifier in the RPC or controller package that listens for incoming Ethereum block data.
- Develop
lib.EthereumChainInfoto facilitate data processing from the Ethereum chain. - Adapt
swap.go/ProcessRootChainOrderBookto ensure proper parsing and handling of incoming lock and close orders. - Establish the Consensus Rule (CR) based on the received orders and update the Root Chain Order Book accordingly.
- Create a reset mechanism that triggers when close orders are not detected within a predefined timeframe post-block parsing.
Required Tags
- Priority: High
- Module: Multi-Module
Overview
- USDC Chain: Functions as a decentralized consensus-driven oracle, retrieving off-chain data and integrating it on-chain.
Key Components
- Committee Members: Registered on the root chain, running software to read external chain data (specifically Ethereum).
- Ethereum Finality: Recognizes the delay due to GASPER finalization (6.4 minutes for epochs).
- Data Processing:
- Reads finalized Ethereum blocks via websockets.
- Looks for lock & close orders, represented in JSON.
Process Flow
-
Order Processing:
- Populate
CR.orderswith data from lock and close orders. - If a close order is missing, reference the order book on the root chain.
- Populate
-
Block Listening:
- Use
ResetBFTwhen a new block is received from peers. - Implement consensus triggered by finalized Ethereum blocks.
- Use
-
Controller Actions:
- Inside
sock.go, develop an Ethereum manager for reporting new blocks to the controller. - Trigger a reset upon new block detection (currently triggered by root or nested chain blocks).
- Create websocket notifier in RPC/controller package.
- Develop
lib.EthereumChainInfofor Ethereum metrics.
- Inside
-
Swap Process:
- Initiation: Seller defines USDC to CNPY swap ratio.
- Transaction:
- Eth participant locks intent with an ETH transaction (JSON).
- Committee witnesses the transaction, achieving a +⅔ quorum, and securely registers the lock on the root chain.
- Payment:
- Buyer sends USDC to seller's Ethereum address.
- Committee verifies the BTC transfer, achieves another +⅔ quorum, and releases CNPY to the buyer's RootChainAddress.
-
Certificate Result:
- Build
CertificateResultbased solely on Ethereum swap information. - Ensure transfer to an escrow pool.
- Build
Additional Notes
- Consider baking parser into the controller or refining existing processes for order parsing in
swap.ProcessRootChainOrderBook. - Emphasize the importance of successful multi-signature quorum in committee operations.
A few 'safe-guards' for the USDC chain that should be implemented:
- Refuse to accept new
lock ordersunder the following conditions:- On-disk
order-mempoolreaches 80% capacity - The
root-chainis halted
- On-disk
- Shouldn't send a
lockunless the order ID exists and isn't locked on the Root-Chain - There should be a
max_resubmitas a failsafe in orders