-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add SyncL2TxHashRelayer * optimise SyncL2TxHashRelayer * del useless dependencies
- Loading branch information
Showing
6 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import {IArbitrator} from "../interfaces/IArbitrator.sol"; | ||
import {IZkLink} from "../interfaces/IZkLink.sol"; | ||
|
||
contract SyncL2TxHashRelayer { | ||
/// @dev The address of the arbitrator contract | ||
IArbitrator public immutable ARBITRATOR; | ||
|
||
constructor(IArbitrator _arbitrator) { | ||
ARBITRATOR = _arbitrator; | ||
} | ||
|
||
function claimPrimaryChainSyncL2TxHashMessage( | ||
address _sourceChainCanonicalMessageService, | ||
bytes calldata _sourceChainClaimCallData, | ||
address _secondaryChainL1Gateway, | ||
bytes32 _secondaryChainL2TxHash, | ||
bytes32 _primaryChainL2TxHash, | ||
bytes calldata _forwardParams | ||
) external payable { | ||
// Send l2 tx hash to secondary chain by gateway | ||
bytes[] memory gatewayDataList = new bytes[](1); | ||
bytes memory callData = abi.encodeCall(IZkLink.syncL2TxHash, (_secondaryChainL2TxHash, _primaryChainL2TxHash)); | ||
gatewayDataList[0] = abi.encode(_secondaryChainL1Gateway, 0, callData); | ||
|
||
ARBITRATOR.claimMessage{value: msg.value}( | ||
_sourceChainCanonicalMessageService, | ||
_sourceChainClaimCallData, | ||
ARBITRATOR.primaryChainGateway(), | ||
0, | ||
abi.encode(gatewayDataList), | ||
_forwardParams | ||
); | ||
} | ||
} |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
const fs = require('fs'); | ||
const { | ||
verifyContractCode, | ||
createOrGetDeployLog, | ||
ChainContractDeployer, | ||
getDeployTx, | ||
readDeployLogField, | ||
} = require('./utils'); | ||
const logName = require('./deploy_log_name'); | ||
const { task, types } = require('hardhat/config'); | ||
|
||
function getRelayerContractName() { | ||
return 'SyncL2TxHashRelayer'; | ||
} | ||
|
||
task('deploySyncL2TxHashRelayer', 'Deploy SyncL2TxHashRelayer') | ||
.addParam( | ||
'arbitrator', | ||
'The arbitrator address (default get from arbitrator deploy log)', | ||
undefined, | ||
types.string, | ||
true, | ||
) | ||
.addParam('skipVerify', 'Skip verify', false, types.boolean, true) | ||
.setAction(async (taskArgs, hardhat) => { | ||
let arbitrator = taskArgs.arbitrator; | ||
if (arbitrator === undefined) { | ||
arbitrator = readDeployLogField(logName.DEPLOY_ARBITRATOR_LOG_PREFIX, logName.DEPLOY_LOG_ARBITRATOR); | ||
} | ||
let skipVerify = taskArgs.skipVerify; | ||
console.log('arbitrator', arbitrator); | ||
console.log('skip verify contracts?', skipVerify); | ||
|
||
const contractDeployer = new ChainContractDeployer(hardhat); | ||
await contractDeployer.init(); | ||
const deployerWallet = contractDeployer.deployerWallet; | ||
|
||
const { deployLogPath, deployLog } = createOrGetDeployLog(logName.DEPLOY_SYNCL2TXHASHRELAYER_LOG_PREFIX); | ||
deployLog[logName.DEPLOY_LOG_DEPLOYER] = deployerWallet.address; | ||
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); | ||
|
||
// deploy syncL2TxHashRelayer | ||
let syncL2TxHashRelayerAddr; | ||
if (!(logName.DEPLOY_LOG_SYNCL2TXHASHRELAYER in deployLog)) { | ||
console.log('deploy syncL2TxHashRelayer...'); | ||
const contractName = getRelayerContractName(); | ||
const contract = await contractDeployer.deployContract(contractName, [arbitrator]); | ||
const transaction = await getDeployTx(contract); | ||
syncL2TxHashRelayerAddr = await contract.getAddress(); | ||
deployLog[logName.DEPLOY_LOG_SYNCL2TXHASHRELAYER] = syncL2TxHashRelayerAddr; | ||
deployLog[logName.DEPLOY_LOG_DEPLOY_TX_HASH] = transaction.hash; | ||
deployLog[logName.DEPLOY_LOG_DEPLOY_BLOCK_NUMBER] = transaction.blockNumber; | ||
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); | ||
} else { | ||
syncL2TxHashRelayerAddr = deployLog[logName.DEPLOY_LOG_SYNCL2TXHASHRELAYER]; | ||
} | ||
console.log('syncL2TxHashRelayer', syncL2TxHashRelayerAddr); | ||
|
||
// verify target contract | ||
if (!(logName.DEPLOY_LOG_SYNCL2TXHASHRELAYER_VERIFIED in deployLog) && !skipVerify) { | ||
await verifyContractCode(hardhat, syncL2TxHashRelayerAddr, [arbitrator]); | ||
deployLog[logName.DEPLOY_LOG_SYNCL2TXHASHRELAYER_VERIFIED] = true; | ||
fs.writeFileSync(deployLogPath, JSON.stringify(deployLog, null, 2)); | ||
} | ||
}); |