UNPKG

@ensdomains/unruggable-gateways

Version:

Trustless Ethereum Multichain CCIP-Read Gateway

76 lines (75 loc) 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TaikoRollup = void 0; const rollup_js_1 = require("../rollup.cjs"); const contract_1 = require("ethers/contract"); const chains_js_1 = require("../chains.cjs"); const EthProver_js_1 = require("../eth/EthProver.cjs"); const types_js_1 = require("./types.cjs"); const utils_js_1 = require("../utils.cjs"); class TaikoRollup extends rollup_js_1.AbstractRollup { TaikoL1; commitStep; // https://docs.taiko.xyz/network-reference/mainnet-addresses static mainnetConfig = { chain1: chains_js_1.CHAINS.MAINNET, chain2: chains_js_1.CHAINS.TAIKO, TaikoL1: '0x06a9Ab27c7e2255df1815E6CC0168d7755Feb19a', // based.taiko.eth commitBatchSpan: 1, }; static heklaConfig = { chain1: chains_js_1.CHAINS.HOLESKY, chain2: chains_js_1.CHAINS.TAIKO_HEKLA, TaikoL1: '0x79C9109b764609df928d16fC4a91e9081F7e87DB', commitBatchSpan: 1, }; static async create(providers, config) { const TaikoL1 = new contract_1.Contract(config.TaikoL1, types_js_1.TAIKO_ABI, providers.provider1); let commitStep; if (config.commitBatchSpan > 0) { const cfg = await TaikoL1.getConfig(); commitStep = cfg.stateRootSyncInternal * BigInt(config.commitBatchSpan); } else { commitStep = 1n; } return new this(providers, TaikoL1, commitStep); } constructor(providers, TaikoL1, commitStep) { super(providers); this.TaikoL1 = TaikoL1; this.commitStep = commitStep; } async fetchLatestCommitIndex() { // https://github.com/taikoxyz/taiko-mono/blob/main/packages/protocol/contracts/L1/libs/LibUtils.sol // by definition this is shouldSyncStateRoot() // eg. (block % 16) == 15 const res = await this.TaikoL1.getLastSyncedBlock({ blockTag: this.latestBlockTag, }); return res.blockId; } async _fetchParentCommitIndex(commit) { if (this.commitStep > 1) { // remove any unaligned remainder (see above) const rem = (commit.index + 1n) % this.commitStep; if (rem) return commit.index - rem; } return commit.index - this.commitStep; } async _fetchCommit(index) { const prover = new EthProver_js_1.EthProver(this.provider2, index); const blockInfo = await prover.fetchBlock(); return { index, prover, parentHash: blockInfo.parentHash }; } encodeWitness(commit, proofSeq) { return utils_js_1.ABI_CODER.encode(['(uint256, bytes32, bytes[], bytes)'], [[commit.index, commit.parentHash, proofSeq.proofs, proofSeq.order]]); } windowFromSec(sec) { // taiko is a based rollup const avgBlockSec = 16; // block every block 12-20 sec return Math.ceil(sec / avgBlockSec); // units of blocks } } exports.TaikoRollup = TaikoRollup;