MockBridge.sol 3.74 KB
Newer Older
1 2 3 4 5
pragma solidity ^0.8.9;

import { MockMessenger } from "./MockMessenger.sol";

contract MockBridge {
6 7 8 9 10 11 12
    event ETHDepositInitiated(
        address indexed _from,
        address indexed _to,
        uint256 _amount,
        bytes _data
    );

13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    event ERC20DepositInitiated(
        address indexed _l1Token,
        address indexed _l2Token,
        address indexed _from,
        address _to,
        uint256 _amount,
        bytes _data
    );

    event ERC20WithdrawalFinalized(
        address indexed _l1Token,
        address indexed _l2Token,
        address indexed _from,
        address _to,
        uint256 _amount,
        bytes _data
    );

    event WithdrawalInitiated(
        address indexed _l1Token,
        address indexed _l2Token,
        address indexed _from,
        address _to,
        uint256 _amount,
        bytes _data
    );

    event DepositFinalized(
        address indexed _l1Token,
        address indexed _l2Token,
        address indexed _from,
        address _to,
        uint256 _amount,
        bytes _data
    );

    event DepositFailed(
        address indexed _l1Token,
        address indexed _l2Token,
        address indexed _from,
        address _to,
        uint256 _amount,
        bytes _data
    );

    struct TokenEventStruct {
        address l1Token;
        address l2Token;
        address from;
        address to;
        uint256 amount;
        bytes data;
    }

    MockMessenger public messenger;

    constructor(MockMessenger _messenger) {
        messenger = _messenger;
    }

    function emitERC20DepositInitiated(
        TokenEventStruct memory _params
    ) public {
        emit ERC20DepositInitiated(_params.l1Token, _params.l2Token, _params.from, _params.to, _params.amount, _params.data);
        messenger.triggerSentMessageEvent(
            MockMessenger.SentMessageEventParams(
                address(0),
                address(0),
                hex"1234",
                1234,
83 84
                12345678,
                0
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
            )
        );
    }

    function emitERC20WithdrawalFinalized(
        TokenEventStruct memory _params
    ) public {
        emit ERC20WithdrawalFinalized(_params.l1Token, _params.l2Token, _params.from, _params.to, _params.amount, _params.data);
    }

    function emitWithdrawalInitiated(
        TokenEventStruct memory _params
    ) public {
        emit WithdrawalInitiated(_params.l1Token, _params.l2Token, _params.from, _params.to, _params.amount, _params.data);
        messenger.triggerSentMessageEvent(
            MockMessenger.SentMessageEventParams(
                address(0),
                address(0),
                hex"1234",
                1234,
105 106
                12345678,
                0
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
            )
        );
    }

    function emitDepositFinalized(
        TokenEventStruct memory _params
    ) public {
        emit DepositFinalized(_params.l1Token, _params.l2Token, _params.from, _params.to, _params.amount, _params.data);
    }

    function emitDepositFailed(
        TokenEventStruct memory _params
    ) public {
        emit DepositFailed(_params.l1Token, _params.l2Token, _params.from, _params.to, _params.amount, _params.data);
    }
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

    function depositETH(
        uint32 _l2GasLimit,
        bytes memory _data
    )
        public
        payable
    {
        emit ETHDepositInitiated(
            msg.sender,
            msg.sender,
            msg.value,
            _data
        );
    }
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155

    function withdraw(
        address _l2Token,
        uint256 _amount,
        uint32 _l1Gas,
        bytes calldata _data
    )
        public
        payable
    {
        emit WithdrawalInitiated(
            address(0),
            _l2Token,
            msg.sender,
            msg.sender,
            _amount,
            _data
        );
    }
156
}