100 |
87 |
|
// create message payload for L2 |
101 |
88 |
|
bytes memory messageData = abi.encodeWithSignature("mintSecondaryFromDeposit(address,uint256)", msg.sender, amount); |
102 |
89 |
|
|
103 |
|
- |
// relay the message to this contract on L2 via Messenger1 |
104 |
|
- |
messenger().sendMessage(companion(), messageData, 3e6); |
|
90 |
+ |
// relay the message to this contract on L2 via L1 Messenger |
|
91 |
+ |
messenger().sendMessage(synthetixBridgeToBase(), messageData, CROSS_DOMAIN_MESSAGE_GAS_LIMIT); |
105 |
92 |
|
|
106 |
93 |
|
emit Deposit(msg.sender, amount); |
107 |
94 |
|
} |
108 |
95 |
|
|
109 |
|
- |
// invoked by user on L2 |
110 |
|
- |
function initiateWithdrawal( |
111 |
|
- |
uint /*amount*/ |
112 |
|
- |
) external { |
113 |
|
- |
revert("Not implemented"); |
114 |
|
- |
|
115 |
|
- |
// instruct L2 Synthetix to burn this supply |
116 |
|
- |
// synthetix().burnSecondary(msg.sender, amount); |
117 |
|
- |
|
118 |
|
- |
// // create message payload for L1 |
119 |
|
- |
// bytes memory messageData = abi.encodeWithSignature("completeWithdrawal(address,uint256)", msg.sender, amount); |
120 |
|
- |
|
121 |
|
- |
// // relay the message to SecondaryDepost on L1 via Messenger2 |
122 |
|
- |
// messenger().sendMessage(companion(), messageData, 3e6); |
123 |
|
- |
} |
124 |
|
- |
|
125 |
96 |
|
// ========= RESTRICTED FUNCTIONS ============== |
126 |
97 |
|
|
127 |
|
- |
// invoked by Messenger2 on L2 |
128 |
|
- |
function mintSecondaryFromDeposit(address account, uint amount) external { |
129 |
|
- |
// ensure function only callable from SecondaryDeposit1 via messenger (aka relayer) |
|
98 |
+ |
// invoked by Messenger on L1 after L2 waiting period elapses |
|
99 |
+ |
function completeWithdrawal(address account, uint amount) external { |
|
100 |
+ |
// ensure function only callable from L2 Bridge via messenger (aka relayer) |
130 |
101 |
|
require(msg.sender == address(messenger()), "Only the relayer can call this"); |
131 |
|
- |
require(messenger().xDomainMessageSender() == companion(), "Only deposit contract can invoke"); |
132 |
|
- |
|
133 |
|
- |
// now tell Synthetix to mint these tokens, deposited in L1, into the same account for L2 |
134 |
|
- |
synthetix().mintSecondary(account, amount); |
135 |
|
- |
|
136 |
|
- |
emit MintedSecondary(account, amount); |
137 |
|
- |
} |
138 |
|
- |
|
139 |
|
- |
// invoked by Messenger1 on L1 after L2 waiting period elapses |
140 |
|
- |
function completeWithdrawal( |
141 |
|
- |
address, /*account*/ |
142 |
|
- |
uint /*amount*/ |
143 |
|
- |
) external { |
144 |
|
- |
revert("Not implemented"); |
145 |
|
- |
// ensure function only callable from SecondaryDeposit2 via messenger (aka relayer) |
146 |
|
- |
// require(msg.sender == address(messenger()), "Only the relayer can call this"); |
147 |
|
- |
// require(messenger().xDomainMessageSender() == companion(), "Only deposit contract can invoke"); |
|
102 |
+ |
require(messenger().xDomainMessageSender() == synthetixBridgeToBase(), "Only the L2 bridge can invoke"); |
148 |
103 |
|
|
149 |
|
- |
// // transfer amount back to user |
150 |
|
- |
// synthetixERC20().transfer(account, amount); |
|
104 |
+ |
// transfer amount back to user |
|
105 |
+ |
synthetixERC20().transfer(account, amount); |
151 |
106 |
|
|
152 |
107 |
|
// no escrow actions - escrow remains on L2 |
|
108 |
+ |
emit WithdrawalCompleted(account, amount); |
153 |
109 |
|
} |
154 |
110 |
|
|
155 |
111 |
|
// invoked by the owner for migrating the contract to the new version that will allow for withdrawals |
156 |
|
- |
function migrateDeposit(address newDeposit) external onlyOwner { |
|
112 |
+ |
function migrateBridge(address newBridge) external onlyOwner { |
157 |
113 |
|
activated = false; |
158 |
114 |
|
|
159 |
115 |
|
IERC20 ERC20Synthetix = synthetixERC20(); |
160 |
|
- |
// get the current contract balance and transfer it to the new SecondaryDeposit contract |
|
116 |
+ |
// get the current contract balance and transfer it to the new SynthetixL1ToL2Bridge contract |
161 |
117 |
|
uint contractBalance = ERC20Synthetix.balanceOf(address(this)); |
162 |
|
- |
ERC20Synthetix.transfer(newDeposit, contractBalance); |
|
118 |
+ |
ERC20Synthetix.transfer(newBridge, contractBalance); |
163 |
119 |
|
|
164 |
|
- |
emit DepositMigrated(address(this), newDeposit, contractBalance); |
|
120 |
+ |
emit BridgeMigrated(address(this), newBridge, contractBalance); |
165 |
121 |
|
} |
166 |
122 |
|
|
167 |
123 |
|
// ========== EVENTS ========== |
168 |
124 |
|
|
169 |
125 |
|
event Deposit(address indexed account, uint amount); |
170 |
|
- |
event DepositMigrated(address oldDeposit, address newDeposit, uint amount); |
171 |
|
- |
event MintedSecondary(address indexed account, uint amount); |
|
126 |
+ |
event BridgeMigrated(address oldBridge, address newBridge, uint amount); |
|
127 |
+ |
event WithdrawalCompleted(address indexed account, uint amount); |
172 |
128 |
|
} |