@ensdomains/unruggable-gateways
Version:
Trustless Ethereum Multichain CCIP-Read Gateway
112 lines (111 loc) • 4.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ZKSyncRollup = void 0;
const ZKSyncProver_js_1 = require("./ZKSyncProver.cjs");
const types_js_1 = require("./types.cjs");
const constants_1 = require("ethers/constants");
const contract_1 = require("ethers/contract");
const chains_js_1 = require("../chains.cjs");
const rollup_js_1 = require("../rollup.cjs");
const utils_js_1 = require("../utils.cjs");
class ZKSyncRollup extends rollup_js_1.AbstractRollup {
// https://docs.zksync.io/build/developer-reference/era-contracts/l1-contracts
static mainnetConfig = {
chain1: chains_js_1.CHAINS.MAINNET,
chain2: chains_js_1.CHAINS.ZKSYNC,
DiamondProxy: '0x32400084c286cf3e17e7b677ea9583e60a000324',
};
static sepoliaConfig = {
chain1: chains_js_1.CHAINS.SEPOLIA,
chain2: chains_js_1.CHAINS.ZKSYNC_SEPOLIA,
DiamondProxy: '0x9A6DE0f62Aa270A8bCB1e2610078650D539B1Ef9',
};
// https://docs.zero.network/main-features/system-contracts#zer%CE%B8-network
static zeroMainnetConfig = {
chain1: chains_js_1.CHAINS.MAINNET,
chain2: chains_js_1.CHAINS.ZERO,
DiamondProxy: '0xdbD849acC6bA61F461CB8A41BBaeE2D673CA02d9',
};
static zeroSepoliaConfig = {
chain1: chains_js_1.CHAINS.SEPOLIA,
chain2: chains_js_1.CHAINS.ZERO_SEPOLIA,
DiamondProxy: '0x9A62B01fFa3bD358d03508ef60bB522ABA5d1bEb',
};
// https://docs.abs.xyz/how-abstract-works/architecture/components/l1-rollup-contracts#list-of-l1-rollup-contracts
static abstractSepoliaConfig = {
chain1: chains_js_1.CHAINS.SEPOLIA,
chain2: chains_js_1.CHAINS.ABSTRACT_SEPOLIA,
DiamondProxy: '0x8aD52ff836A30f063dF51A00C99518880B8b36ac',
};
DiamondProxy;
constructor(providers, config) {
super(providers);
this.DiamondProxy = new contract_1.Contract(config.DiamondProxy, types_js_1.DIAMOND_ABI, this.provider1);
}
async fetchLatestCommitIndex() {
const count = await this.DiamondProxy.getTotalBatchesExecuted({
blockTag: this.latestBlockTag,
});
return count - 1n;
}
async _fetchCommit(index) {
const prover = new ZKSyncProver_js_1.ZKSyncProver(this.provider2, Number(index));
const details = await prover.fetchBatchDetails();
if (!details.commitTxHash)
throw new Error('no commitTxHash');
// 20240810: this check randomly fails even though the block is finalized
// if (details.status !== 'verified') {
// throw new Error(`not verified: ${details.status}`);
// }
const [tx, [log], l2LogsTreeRoot] = await Promise.all([
this.provider1.getTransaction(details.commitTxHash),
this.DiamondProxy.queryFilter(this.DiamondProxy.filters.BlockCommit(index, details.rootHash)),
this.DiamondProxy.l2LogsRootHash(index),
]);
if (!tx)
throw new Error(`missing commit tx: ${details.commitTxHash}`);
if (!(log instanceof contract_1.EventLog))
throw new Error(`no BlockCommit event`);
if (l2LogsTreeRoot === constants_1.ZeroHash)
throw new Error('not finalized');
const commits = types_js_1.DIAMOND_ABI.decodeFunctionData('commitBatchesSharedBridge', tx.data).newBatchesData;
const batchInfo = commits.find((x) => x.batchNumber == index);
if (!batchInfo)
throw new Error(`commit not in batch`);
const abiEncodedBatch = utils_js_1.ABI_CODER.encode([
'uint64', // batchNumber
'bytes32', // batchHash
'uint64', // indexRepeatedStorageChanges
'uint256', // numberOfLayer1Txs
'bytes32', // priorityOperationsHash
'bytes32', // l2LogsTreeRoot
'uint256', // timestamp
'bytes32', // commitment
], [
batchInfo.batchNumber, // == index
batchInfo.newStateRoot, // == details.rootHash
batchInfo.indexRepeatedStorageChanges,
batchInfo.numberOfLayer1Txs,
batchInfo.priorityOperationsHash,
l2LogsTreeRoot,
batchInfo.timestamp,
log.args.commitment,
]);
return {
index,
prover,
stateRoot: details.rootHash,
abiEncodedBatch,
};
}
encodeWitness(commit, proofSeq) {
return utils_js_1.ABI_CODER.encode(['(bytes, bytes[], bytes)'], [[commit.abiEncodedBatch, proofSeq.proofs, proofSeq.order]]);
}
windowFromSec(sec) {
// finalization time not on-chain
// approximately 1 batch every hour, sequential
// https://explorer.zksync.io/batches/
return Math.ceil(sec / 3600); // units of commit index
}
}
exports.ZKSyncRollup = ZKSyncRollup;