-
-
Save pjt3591oo/6517f0be9c5b8e0476f02a2409a246a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ethers } from "ethers"; | |
import { getMessenger, l1Provider, l2Provider } from "./common/messenger"; | |
import { TEST_EOAS } from "./common/eoa"; | |
// withdraw message for prove withdraw | |
// withdraw message for finalize withdraw | |
async function main(tx: string) { | |
const from = TEST_EOAS[0]; | |
const l1Wallet = new ethers.Wallet(from.privateKey, l1Provider); | |
const l2Wallet = new ethers.Wallet(from.privateKey, l2Provider); | |
const messenger = getMessenger(l1Wallet, l2Wallet); | |
/* | |
initiate(L2) | |
L2StandardBridge -> L2CrossDomainMessenger -> L2ToL1MessagePasser | |
{ | |
direction: 1, | |
target: '0xfe36E31dFE8Cb3A3Aa0CB9f35B191DdB5451b090', | |
sender: '0x4200000000000000000000000000000000000010', | |
message: '0x0166a07a0000000000000000000000002910e325cf29dd912e3476b61ef12f49cb931096000000000000000000000000915b110e8cd64b91e67278965627e3baee9b53fe00000000000000000000000030556546d4b398c3b0f67f0e1586feaf11ce9b3300000000000000000000000030556546d4b398c3b0f67f0e1586feaf11ce9b330000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000', | |
messageNonce: BigNumber { | |
_hex: '0x01000000000000000000000000000000000000000000000000000000000002', | |
_isBigNumber: true | |
}, | |
value: BigNumber { _hex: '0x00', _isBigNumber: true }, | |
minGasLimit: BigNumber { _hex: '0x00', _isBigNumber: true }, | |
logIndex: 5, | |
blockNumber: 8333, | |
transactionHash: '0x11268a9ccad7dfaf287ac5771bb2fa226d6cabab1247bbe8ca1bfbdbe0cb74de' | |
} | |
*/ | |
const resolved = await messenger.toCrossChainMessage(tx); | |
console.log(resolved); | |
/* | |
prove(L1) | |
OptimismPortal | |
{ | |
messageNonce: BigNumber { | |
_hex: '0x01000000000000000000000000000000000000000000000000000000000002', | |
_isBigNumber: true | |
}, | |
sender: '0x4200000000000000000000000000000000000007', | |
target: '0xd787A42Ee3ac477c46Dd6C912e7af795D44453d5', | |
value: BigNumber { _hex: '0x00', _isBigNumber: true }, | |
minGasLimit: BigNumber { _hex: '0x046988', _isBigNumber: true }, | |
message: '0xd764ad0b00010000000000000000000000000000000000000000000000000000000000020000000000000000000000004200000000000000000000000000000000000010000000000000000000000000fe36e31dfe8cb3a3aa0cb9f35b191ddb5451b0900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000001040166a07a0000000000000000000000002910e325cf29dd912e3476b61ef12f49cb931096000000000000000000000000915b110e8cd64b91e67278965627e3baee9b53fe00000000000000000000000030556546d4b398c3b0f67f0e1586feaf11ce9b3300000000000000000000000030556546d4b398c3b0f67f0e1586feaf11ce9b330000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' | |
} | |
*/ | |
const withdrawal = await messenger.toLowLevelMessage(resolved); | |
console.log(withdrawal) | |
/* | |
finalize(L1) - claim | |
finalize inner transaction | |
OptimismPortal -> L1CrossDomainMessenger -> L1StandardBridge | |
(toLowLevelMessage.target) (included toLowLevelMessage.message) | |
toLowLevelMessage.target: L1CrossDomainMessenger address | |
toLowLevelMessage.message: message | |
OptimismPortal.finalizeWithdrawalTransaction는 L1CrossDomainMessenger address를 호출. 이때 calldata로 toLowLevelMessage.message을 넣어줌 | |
toLowLevelMessage.message는 L1StandardBridge.FinalizeBridgeETH(FinalizeBridgeERC20)을 호출하는 calldata와 L1StandardBridge address를 포함한다. | |
*/ | |
// =========== inner transaction 1 =========== | |
console.log('OptimismPortal.finalizeWithdrawalTransaction 호출 시 첫 번째 인자로 전달되는 요소') | |
console.log(withdrawal) | |
// =========== inner transaction 2 =========== | |
const decodePassL1CrossDomainMessenger = messenger.contracts.l1.L1CrossDomainMessenger.interface.decodeFunctionData( | |
'relayMessage', | |
withdrawal.message | |
); | |
console.log('L1CrossDomainMessenger.relayMessage 호출 시 전달되는 요소'); | |
console.log(decodePassL1CrossDomainMessenger); | |
// =========== inner transaction 3 =========== | |
// 해당 inner transaction에서 실제 출금이 이루어짐 | |
try { | |
const decodePassL1StandardBridge = messenger.contracts.l1.L1StandardBridge.interface.decodeFunctionData( | |
'finalizeBridgeERC20', // finalizeBridgeERC20 or finalizeBridgeETH | |
decodePassL1CrossDomainMessenger._message | |
); | |
console.log('L1StandardBridge.finalizeBridgeERC20 호출 시 전달되는 요소'); | |
console.log(decodePassL1StandardBridge); | |
} catch { | |
const decodePassL1StandardBridge = messenger.contracts.l1.L1StandardBridge.interface.decodeFunctionData( | |
'finalizeBridgeETH', // finalizeBridgeERC20 or finalizeBridgeETH | |
decodePassL1CrossDomainMessenger._message | |
); | |
console.log('L1StandardBridge.finalizeBridgeETH 호출 시 전달되는 요소'); | |
console.log(decodePassL1StandardBridge); | |
} | |
} | |
main('0x11268a9ccad7dfaf287ac5771bb2fa226d6cabab1247bbe8ca1bfbdbe0cb74de'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment