MatrixBridge_L1_PEPUTest

Description:

Smart contract deployed on Ethereum.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

/**
 * ============================================================================
 * MATRIX BRIDGE L1 - PEPU TESTING VERSION
 * ============================================================================
 * 
 * FOR TESTING WITH SMALL AMOUNTS!
 * Just bridge PEPU directly - no ETH swap needed
 * 
 * Perfect for testing with 100 PEPU (~$0.008)
 * 
 * ✅ CONFIRMED ADDRESSES:
 * - SequencerInbox: 0x93CA3db0dF3e78e798004bbE14e1ADE222B14dFa
 * - Bridge: 0xd3643255ea784c75a5325CC5a4A549C7CD62E499
 * - PEPU L1: 0x93aA0ccD1e5628d3A841C4DbdF602D9eb04085d6
 * - PEPU L2: 0xF9Cf4A16d26979b929Be7176bAc4e7084975FCB8
 */

interface IERC20 {
    function transfer(address to, uint256 amount) external returns (bool);
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
    function approve(address spender, uint256 amount) external returns (bool);
    function balanceOf(address account) external view returns (uint256);
}

interface IInbox {
    function createRetryableTicket(
        address to,
        uint256 l2CallValue,
        uint256 maxSubmissionCost,
        address excessFeeRefundAddress,
        address callValueRefundAddress,
        uint256 gasLimit,
        uint256 maxFeePerGas,
        bytes calldata data
    ) external payable returns (uint256);
}

contract MatrixBridge_L1_PEPUTest {
    
    // Hardcoded addresses
    address public constant INBOX = 0x93CA3db0dF3e78e798004bbE14e1ADE222B14dFa;
    address public constant BRIDGE = 0xd3643255ea784c75a5325CC5a4A549C7CD62E499;
    address public constant PEPU_L1 = 0x93aA0ccD1e5628d3A841C4DbdF602D9eb04085d6;
    address public constant PEPU_L2 = 0xF9Cf4A16d26979b929Be7176bAc4e7084975FCB8;
    
    address public l2MatrixBridge;
    address public feeCollector;
    address public owner;
    
    // Ultra low gas for testing
    uint256 public feeBps = 30;              // 0.3%
    uint256 public l2Gas = 200000;
    uint256 public l2MaxFeePerGas = 1 gwei;
    uint256 public maxSubmissionCost = 0.001 ether;
    
    bool public paused;
    
    uint256 private constant BPS_DENOMINATOR = 10000;
    
    event BridgePEPU(
        address indexed user,
        uint256 amount,
        address outputToken,
        uint256 ticketId
    );
    
    constructor(address _l2MatrixBridge, address _feeCollector) {
        require(_l2MatrixBridge != address(0), "Zero L2");
        require(_feeCollector != address(0), "Zero collector");
        l2MatrixBridge = _l2MatrixBridge;
        feeCollector = _feeCollector;
        owner = msg.sender;
    }
    
    modifier onlyOwner() {
        require(msg.sender == owner, "Not owner");
        _;
    }
    
    modifier whenNotPaused() {
        require(!paused, "Paused");
        _;
    }
    
    /**
     * @notice Calculate L2 gas cost
     */
    function calculateL2GasCost() public view returns (uint256) {
        return maxSubmissionCost + (l2Gas * l2MaxFeePerGas);
    }
    
    /**
     * @notice Bridge PEPU directly - Perfect for testing!
     * @param amount Amount of PEPU to bridge (e.g., 100 for testing)
     * @param outputToken Token you want on L2
     * 
     * HOW TO USE:
     * 1. Approve this contract for your PEPU amount
     * 2. Send 0.0012 ETH with this transaction (for L2 gas)
     * 3. Bridge any amount of PEPU (even 100 tokens for testing!)
     * 
     * EXAMPLE:
     * - Amount: 100 PEPU (~$0.008)
     * - ETH needed: 0.0012 (just for L2 gas)
     * - Total cost: ~$3.60 (mostly L2 gas, tiny PEPU amount)
     */
    function bridgePEPU(
        uint256 amount,
        address outputToken
    ) external payable whenNotPaused {
        require(amount > 0, "Zero amount");
        require(outputToken != address(0), "Zero token");
        
        // Need ETH for L2 gas
        uint256 l2GasCost = calculateL2GasCost();
        require(msg.value >= l2GasCost, "Need 0.0012 ETH for L2 gas");
        
        // Transfer PEPU from user
        require(
            IERC20(PEPU_L1).transferFrom(msg.sender, address(this), amount),
            "PEPU transfer failed"
        );
        
        // Take 0.3% fee
        uint256 feeAmount = (amount * feeBps) / BPS_DENOMINATOR;
        uint256 amountAfterFee = amount - feeAmount;
        
        if (feeAmount > 0) {
            require(
                IERC20(PEPU_L1).transfer(feeCollector, feeAmount),
                "Fee transfer failed"
            );
        }
        
        // Encode L2 call
        bytes memory l2CallData = abi.encodeWithSignature(
            "receiveFromL1(address,uint256,address)",
            msg.sender,
            amountAfterFee,
            outputToken
        );
        
        // Approve PEPU for Bridge
        require(
            IERC20(PEPU_L1).approve(BRIDGE, amountAfterFee),
            "Approve failed"
        );
        
        // Create retryable ticket
        uint256 ticketId = IInbox(INBOX).createRetryableTicket{value: l2GasCost}(
            l2MatrixBridge,
            0,
            maxSubmissionCost,
            msg.sender,
            msg.sender,
            l2Gas,
            l2MaxFeePerGas,
            l2CallData
        );
        
        // Refund excess ETH
        if (msg.value > l2GasCost) {
            payable(msg.sender).transfer(msg.value - l2GasCost);
        }
        
        emit BridgePEPU(msg.sender, amountAfterFee, outputToken, ticketId);
    }
    
    /**
     * @notice Adjust gas if needed
     */
    function setGasParameters(uint256 _gas, uint256 _feePerGas, uint256 _submission) external onlyOwner {
        l2Gas = _gas;
        l2MaxFeePerGas = _feePerGas;
        maxSubmissionCost = _submission;
    }
    
    function setFee(uint256 newFee) external onlyOwner {
        feeBps = newFee;
    }
    
    function pause() external onlyOwner {
        paused = true;
    }
    
    function unpause() external onlyOwner {
        paused = false;
    }
    
    function rescueETH() external onlyOwner {
        payable(owner).transfer(address(this).balance);
    }
    
    function rescueTokens(address token, uint256 amount) external onlyOwner {
        IERC20(token).transfer(owner, amount);
    }
    
    receive() external payable {}
}

/**
 * ============================================================================
 * TESTING GUIDE
 * ============================================================================
 * 
 * TEST WITH JUST 100 PEPU:
 * 
 * 1. Get 100 PEPU on Ethereum (~$0.008 worth)
 * 2. Approve this contract: PEPU.approve(thisContract, 100e18)
 * 3. Bridge: bridgePEPU(100e18, outputToken, {value: 0.0012 ETH})
 * 4. Wait 10-15 min
 * 5. Check L2 for your tokens!
 * 
 * COST BREAKDOWN FOR 100 PEPU TEST:
 * - 100 PEPU: $0.008
 * - L2 Gas: 0.0012 ETH = ~$3.60
 * - L1 Gas: ~$5-10
 * - Total: ~$8-14 to test (mostly gas, tiny token amount)
 * 
 * This lets you test the entire bridge flow for under $15!
 * ============================================================================
 */

Tags:
addr:0x7a25432f2ad1d0f040f80cee32601bda5c6ce619|verified:true|block:23641734|tx:0x08ede8ec8da2588183e3a46b1144d4e0fc73e72409505ff1181a5f8429aa980d|first_check:1761312575

Submitted on: 2025-10-24 15:29:38

Comments

Log in to comment.

No comments yet.