224 lines
5.7 KiB
Markdown
224 lines
5.7 KiB
Markdown
|
|
# Bridge Implementation Review & Next Steps
|
||
|
|
|
||
|
|
**Date**: 2025-01-12
|
||
|
|
**Status**: Implementation Checklist
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Review Summary
|
||
|
|
|
||
|
|
### Current State
|
||
|
|
|
||
|
|
1. **Bridge Contract**: `CCIPWETH9Bridge.sol` deployed on Chain 138
|
||
|
|
- Address: `0x89dd12025bfCD38A168455A44B400e913ED33BE2`
|
||
|
|
- Function: `sendCrossChain(uint64 destinationChainSelector, address recipient, uint256 amount)`
|
||
|
|
- Returns: `bytes32 messageId`
|
||
|
|
|
||
|
|
2. **Frontend State**:
|
||
|
|
- ✅ `ThirdwebBridgeWidget.tsx` exists but uses generic thirdweb Bridge component
|
||
|
|
- ✅ `BridgeForm.tsx` exists but has placeholder logic
|
||
|
|
- ❌ No custom Wrap/Approve/Bridge buttons implemented
|
||
|
|
- ✅ thirdweb SDK v5 installed (`@thirdweb-dev/react`)
|
||
|
|
|
||
|
|
3. **Verification Scripts**:
|
||
|
|
- ✅ `verify-bridge-prerequisites.sh` exists
|
||
|
|
- ✅ `verify-destination-chain-config.sh` exists
|
||
|
|
- ⚠️ Need comprehensive verification script for checklist
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Checklist Items
|
||
|
|
|
||
|
|
### ✅ 1. Bridge Function Signature Confirmed
|
||
|
|
|
||
|
|
**Function**: `sendCrossChain(uint64,address,uint256)`
|
||
|
|
|
||
|
|
```solidity
|
||
|
|
function sendCrossChain(
|
||
|
|
uint64 destinationChainSelector,
|
||
|
|
address recipient,
|
||
|
|
uint256 amount
|
||
|
|
) external returns (bytes32 messageId);
|
||
|
|
```
|
||
|
|
|
||
|
|
**ABI Signature**: `sendCrossChain(uint64,address,uint256)`
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### ⚠️ 2. LINK Token Deployment Verification
|
||
|
|
|
||
|
|
**Status**: Needs Verification
|
||
|
|
|
||
|
|
**LINK Token Address**: `0x514910771AF9Ca656af840dff83E8264EcF986CA`
|
||
|
|
|
||
|
|
**Actions Required**:
|
||
|
|
1. Verify LINK token contract exists on Chain 138
|
||
|
|
2. Verify CCIP Router recognizes LINK as fee token
|
||
|
|
3. Verify LINK token has proper ERC20 interface
|
||
|
|
|
||
|
|
**Verification Commands**:
|
||
|
|
```bash
|
||
|
|
# Check if LINK exists
|
||
|
|
cast code 0x514910771AF9Ca656af840dff83E8264EcF986CA --rpc-url <CHAIN138_RPC>
|
||
|
|
|
||
|
|
# Check router fee token
|
||
|
|
cast call <CCIP_ROUTER> "getFeeToken()" --rpc-url <CHAIN138_RPC>
|
||
|
|
|
||
|
|
# Check LINK balance
|
||
|
|
cast call 0x514910771AF9Ca656af840dff83E8264EcF986CA "balanceOf(address)" <ADDRESS> --rpc-url <CHAIN138_RPC>
|
||
|
|
```
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### ⚠️ 3. Destination Chain Configuration Verification
|
||
|
|
|
||
|
|
**Status**: Needs Verification
|
||
|
|
|
||
|
|
**Ethereum Mainnet Selector**: `5009297550715157269`
|
||
|
|
|
||
|
|
**Actions Required**:
|
||
|
|
1. Verify `destinations[5009297550715157269]` is set on bridge contract
|
||
|
|
2. Verify destination is enabled
|
||
|
|
3. Verify receiver bridge address is correct
|
||
|
|
|
||
|
|
**Verification Command**:
|
||
|
|
```bash
|
||
|
|
ETH_SELECTOR="5009297550715157269"
|
||
|
|
cast call <BRIDGE_ADDRESS> "destinations(uint64)" "$ETH_SELECTOR" --rpc-url <CHAIN138_RPC>
|
||
|
|
```
|
||
|
|
|
||
|
|
**Expected Output**: `(uint64 chainSelector, address receiverBridge, bool enabled)`
|
||
|
|
- `enabled` should be `true`
|
||
|
|
- `receiverBridge` should be the bridge address on Ethereum Mainnet
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### ❌ 4. Thirdweb UI Implementation
|
||
|
|
|
||
|
|
**Status**: Not Implemented
|
||
|
|
|
||
|
|
**Required**: 3 buttons in thirdweb:
|
||
|
|
1. **Wrap (Deposit)**: Wrap ETH → WETH9
|
||
|
|
2. **Approve**: Approve bridge to spend WETH9 and LINK
|
||
|
|
3. **Bridge (CCIP Send)**: Call `sendCrossChain()`
|
||
|
|
|
||
|
|
**Current State**:
|
||
|
|
- `ThirdwebBridgeWidget.tsx` uses generic thirdweb Bridge component
|
||
|
|
- `BridgeForm.tsx` has placeholder logic
|
||
|
|
- No custom button implementation
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Next Steps
|
||
|
|
|
||
|
|
### Step 1: Create Comprehensive Verification Script
|
||
|
|
|
||
|
|
**File**: `smom-dbis-138/scripts/verify-bridge-setup-checklist.sh`
|
||
|
|
|
||
|
|
**Purpose**: Verify all checklist items:
|
||
|
|
- LINK token deployment
|
||
|
|
- Router fee token recognition
|
||
|
|
- Destination chain configuration
|
||
|
|
- Contract addresses
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Step 2: Implement BridgeButtons Component
|
||
|
|
|
||
|
|
**File**: `smom-dbis-138/frontend-dapp/src/components/bridge/BridgeButtons.tsx`
|
||
|
|
|
||
|
|
**Features**:
|
||
|
|
- Wrap button (deposit ETH to WETH9)
|
||
|
|
- Approve button (approve WETH9 and LINK)
|
||
|
|
- Bridge button (sendCrossChain)
|
||
|
|
- Balance display (ETH, WETH9, LINK)
|
||
|
|
- Fee calculation display
|
||
|
|
- Error handling
|
||
|
|
- Loading states
|
||
|
|
|
||
|
|
**Dependencies**: Uses `@thirdweb-dev/react` hooks:
|
||
|
|
- `useContract`
|
||
|
|
- `useContractWrite`
|
||
|
|
- `useContractRead`
|
||
|
|
- `useAddress`
|
||
|
|
- `useBalance`
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Step 3: Update BridgeForm or Create New Component
|
||
|
|
|
||
|
|
**Options**:
|
||
|
|
- **Option A**: Replace `BridgeForm.tsx` with `BridgeButtons` component
|
||
|
|
- **Option B**: Create new `BridgePage.tsx` that uses `BridgeButtons`
|
||
|
|
- **Option C**: Integrate `BridgeButtons` into existing `BridgeForm`
|
||
|
|
|
||
|
|
**Recommendation**: Option B - Create dedicated bridge page
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Step 4: Configuration File
|
||
|
|
|
||
|
|
**File**: `smom-dbis-138/frontend-dapp/src/config/bridge.ts`
|
||
|
|
|
||
|
|
**Purpose**: Centralize contract addresses and chain selectors:
|
||
|
|
- Bridge contract address
|
||
|
|
- WETH9 address
|
||
|
|
- LINK token address
|
||
|
|
- Ethereum Mainnet selector
|
||
|
|
- Chain 138 RPC URL
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Step 5: Testing
|
||
|
|
|
||
|
|
**Test Cases**:
|
||
|
|
1. Wrap ETH → WETH9
|
||
|
|
2. Approve WETH9 allowance
|
||
|
|
3. Approve LINK allowance (if needed)
|
||
|
|
4. Calculate CCIP fee
|
||
|
|
5. Bridge WETH9 to Ethereum Mainnet
|
||
|
|
6. Error handling (insufficient balance, etc.)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Contract Addresses Reference
|
||
|
|
|
||
|
|
### Chain 138
|
||
|
|
- **WETH9**: `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2`
|
||
|
|
- **WETH9 Bridge**: `0x89dd12025bfCD38A168455A44B400e913ED33BE2`
|
||
|
|
- **LINK Token**: `0x514910771AF9Ca656af840dff83E8264EcF986CA`
|
||
|
|
- **CCIP Router**: `0x80226fc0Ee2b096224EeAc085Bb9a8cba1146f7D` (verify)
|
||
|
|
- **RPC URL**: `http://192.168.11.250:8545` or `https://rpc.d-bis.org`
|
||
|
|
|
||
|
|
### Ethereum Mainnet
|
||
|
|
- **Chain Selector**: `5009297550715157269`
|
||
|
|
- **WETH9 Bridge**: (verify from .env)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Implementation Priority
|
||
|
|
|
||
|
|
1. **High Priority**:
|
||
|
|
- Create verification script
|
||
|
|
- Implement BridgeButtons component
|
||
|
|
- Test basic functionality
|
||
|
|
|
||
|
|
2. **Medium Priority**:
|
||
|
|
- Update UI integration
|
||
|
|
- Add error handling
|
||
|
|
- Add loading states
|
||
|
|
|
||
|
|
3. **Low Priority**:
|
||
|
|
- UI polish
|
||
|
|
- Additional features (transaction history, etc.)
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
## Notes
|
||
|
|
|
||
|
|
- The bridge function is `sendCrossChain`, not `bridge`
|
||
|
|
- LINK token must be approved separately for fees
|
||
|
|
- User needs both WETH9 and LINK balances
|
||
|
|
- Fee calculation should be done before bridging
|
||
|
|
- Recipient address should default to connected wallet address
|