forked from OffchainLabs/arbitrum-orbit-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateRollupPrepareTransactionReceipt.ts
53 lines (42 loc) · 1.64 KB
/
createRollupPrepareTransactionReceipt.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { TransactionReceipt, getAbiItem, getEventSelector, Log, decodeEventLog } from 'viem';
import { rollupCreatorABI } from './contracts/RollupCreator';
import { CoreContracts } from './types/CoreContracts';
function findRollupCreatedEventLog(txReceipt: TransactionReceipt) {
const abiItem = getAbiItem({ abi: rollupCreatorABI, name: 'RollupCreated' });
const eventSelector = getEventSelector(abiItem);
const log = txReceipt.logs.find((log) => log.topics[0] === eventSelector);
if (typeof log === 'undefined') {
throw new Error(
`No "RollupCreated" logs found in logs for transaction: ${txReceipt.transactionHash}`,
);
}
return log;
}
function decodeRollupCreatedEventLog(log: Log<bigint, number>) {
const decodedEventLog = decodeEventLog({ ...log, abi: rollupCreatorABI });
if (decodedEventLog.eventName !== 'RollupCreated') {
throw new Error(`Expected "RollupCreated" event but found: ${decodedEventLog.eventName}`);
}
return decodedEventLog;
}
export type CreateRollupTransactionReceipt = TransactionReceipt & {
getCoreContracts(): CoreContracts;
};
export function createRollupPrepareTransactionReceipt(
txReceipt: TransactionReceipt,
): CreateRollupTransactionReceipt {
return {
...txReceipt,
getCoreContracts: function () {
const eventLog = findRollupCreatedEventLog(txReceipt);
const decodedEventLog = decodeRollupCreatedEventLog(eventLog);
const { rollupAddress, inboxAddress, ...rest } = decodedEventLog.args;
return {
rollup: rollupAddress,
inbox: inboxAddress,
...rest,
deployedAtBlockNumber: Number(txReceipt.blockNumber),
};
},
};
}