Skip to content

Commit

Permalink
Merge pull request #15 from zkLinkProtocol/zklink_testnet
Browse files Browse the repository at this point in the history
Zklink testnet
  • Loading branch information
zkbenny authored Jun 19, 2024
2 parents e689537 + 2fbed2d commit 9bd5508
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 25 deletions.
46 changes: 22 additions & 24 deletions l1-contracts/contracts/zksync/facets/Mailbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,30 +240,28 @@ contract MailboxFacet is Base, IMailbox {
uint256 gatewayLength = _secondaryChainGateways.length;
bytes[] memory gatewayDataList = new bytes[](gatewayLength);
uint256 totalForwardEthAmount = 0;
unchecked {
for (uint256 i = 0; i < gatewayLength; ++i) {
// Secondary chain should be registered
address _secondaryChainGateway = _secondaryChainGateways[i];
SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway];
require(secondaryChain.valid, "bsc");
uint256 _forwardEthAmount = s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw;
// Withdraw eth amount impossible overflow
totalForwardEthAmount += _forwardEthAmount;
s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0;
// Send range batch root to secondary chain
bytes memory gatewayCallData = abi.encodeCall(
IZkLink.syncRangeBatchRoot,
(_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount)
);
gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData);
emit SyncRangeBatchRoot(
_secondaryChainGateway,
_fromBatchNumber,
_toBatchNumber,
rangeBatchRootHash,
_forwardEthAmount
);
}
for (uint256 i = 0; i < gatewayLength; i = i.uncheckedInc()) {
// Secondary chain should be registered
address _secondaryChainGateway = _secondaryChainGateways[i];
SecondaryChain memory secondaryChain = s.secondaryChains[_secondaryChainGateway];
require(secondaryChain.valid, "bsc");
uint256 _forwardEthAmount = secondaryChain.totalPendingWithdraw;
// Withdraw eth amount impossible overflow
totalForwardEthAmount += _forwardEthAmount;
s.secondaryChains[_secondaryChainGateway].totalPendingWithdraw = 0;
// Send range batch root to secondary chain
bytes memory gatewayCallData = abi.encodeCall(
IZkLink.syncRangeBatchRoot,
(_fromBatchNumber, _toBatchNumber, rangeBatchRootHash, _forwardEthAmount)
);
gatewayDataList[i] = abi.encode(_secondaryChainGateway, _forwardEthAmount, gatewayCallData);
emit SyncRangeBatchRoot(
_secondaryChainGateway,
_fromBatchNumber,
_toBatchNumber,
rangeBatchRootHash,
_forwardEthAmount
);
}

// Forward fee to gateway
Expand Down
3 changes: 2 additions & 1 deletion l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"upgrade-system": "ts-node upgrade-system/index.ts",
"set-gateway": "ts-node scripts/set-gateway.ts",
"set-admin": "ts-node scripts/set-admin.ts",
"deploy-l1-erc20-bridge-imple": "ts-node scripts/deploy-l1-erc20-bridge-impl.ts"
"deploy-l1-erc20-bridge-imple": "ts-node scripts/deploy-l1-erc20-bridge-impl.ts",
"replace-tx": "ts-node scripts/replace-tx.ts"
},
"dependencies": {
"dotenv": "^16.0.3"
Expand Down
52 changes: 52 additions & 0 deletions l1-contracts/scripts/replace-tx.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Command } from "commander";
import { Wallet } from "ethers";
import { formatUnits } from "ethers/lib/utils";
import { web3Provider } from "./utils";

const provider = web3Provider();

async function main() {
const program = new Command();

program.version("0.1.0").name("replace-tx").description("replace a tx");

program
.requiredOption("--private-key <private-key>")
.requiredOption("--to <to>")
.requiredOption("--value <value>")
.requiredOption("--data <data>")
.requiredOption("--nonce <nonce>")
.requiredOption("--gas-price <gas-price>")
.requiredOption("--gas-limit <gas-limit>")
.action(async (cmd) => {
const deployWallet = new Wallet(cmd.privateKey, provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const nonce = cmd.nonce;
console.log(`Using nonce: ${nonce}`);

const gasPrice = cmd.gasPrice;
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const gasLimit = cmd.gasLimit;
console.log(`Using gas limit: ${gasLimit}`);

await deployWallet.sendTransaction({
to: cmd.to,
value: cmd.value,
data: cmd.data,
nonce,
gasPrice,
gasLimit,
});
});

await program.parseAsync(process.argv);
}

main()
.then(() => process.exit(0))
.catch((err) => {
console.error("Error:", err);
process.exit(1);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface IMergeTokenPortal {
/// @notice Source token info
/// @param isSupported Is the source token supported
/// @param isLocked Is the source token locked
/// @param mergeToken Deposit source token will receive the merge token
/// @param balance Source token balance
/// @param depositLimit Source token deposit limit
struct SourceTokenInfo {
Expand Down

0 comments on commit 9bd5508

Please sign in to comment.