1- import { BigNumber , utils } from "ethers" ;
2- import { getVeaInboxArbToEthProvider , getVeaOutboxArbToEthDevnetProvider } from "../utils/ethers" ;
1+ import { ethers } from "ethers" ;
2+ import { getVeaInboxArbToEth , getVeaOutboxArbToEthDevnet } from "../utils/ethers" ;
33import { VeaInboxArbToEth , VeaOutboxArbToEthDevnet } from "@kleros/vea-contracts/typechain-types" ;
44import { JsonRpcProvider } from "@ethersproject/providers" ;
55
66async function initialize (
77 veaOutboxAddress : string ,
88 veaInboxAddress : string ,
99 outboxRPCUrl : string
10- ) : Promise < [ VeaInboxArbToEth , number , BigNumber , VeaOutboxArbToEthDevnet , BigNumber ] > {
10+ ) : Promise < [ VeaInboxArbToEth , number , BigInt , VeaOutboxArbToEthDevnet , BigInt ] > {
1111 const outboxProvider = new JsonRpcProvider ( outboxRPCUrl ) ;
12- const veaOutbox = getVeaOutboxArbToEthDevnetProvider ( veaOutboxAddress , process . env . PRIVATE_KEY , outboxProvider ) ;
12+ const veaOutbox = getVeaOutboxArbToEthDevnet ( veaOutboxAddress , process . env . PRIVATE_KEY , outboxRPCUrl ) ;
1313
1414 const arbSepoliaProvider = new JsonRpcProvider ( process . env . RPC_ARB_SEPOLIA ) ;
15- const veaInbox = getVeaInboxArbToEthProvider ( veaInboxAddress , process . env . PRIVATE_KEY , arbSepoliaProvider ) ;
15+ const veaInbox = getVeaInboxArbToEth ( veaInboxAddress , process . env . PRIVATE_KEY , process . env . RPC_ARB_SEPOLIA ) ;
1616
1717 const deposit = await veaOutbox . deposit ( ) ;
18- const epochPeriod = ( await veaOutbox . epochPeriod ( ) ) . toNumber ( ) ;
18+ const epochPeriod = Number ( await veaOutbox . epochPeriod ( ) ) ;
1919 let currentTS = Math . floor ( Date . now ( ) / 1000 ) ;
2020 let claimableEpoch = Math . floor ( currentTS / epochPeriod ) ;
2121
@@ -29,57 +29,53 @@ async function initialize(
2929 // not really correct since l2 blocks are different, but just an estimate
3030 const searchBlock = Math . max ( 0 , ( await arbSepoliaProvider . getBlockNumber ( ) ) - Math . floor ( 1209600 / 12 ) ) ;
3131
32- const logs = await arbSepoliaProvider . getLogs ( {
33- address : veaInboxAddress ,
34- topics : veaInbox . filters . SnapshotSaved ( null ) . topics ,
35- fromBlock : searchBlock ,
36- } ) ;
32+ const logs = await veaInbox . queryFilter ( veaInbox . filters . SnapshotSaved ( null ) , searchBlock ) ;
3733
3834 let lastSavedCount =
3935 logs . length > 0
40- ? utils . defaultAbiCoder . decode ( [ "bytes32" , "uint256" , "uint64" ] , logs [ logs . length - 1 ] . data ) [ 2 ]
41- : BigNumber . from ( 0 ) ;
36+ ? ethers . AbiCoder . defaultAbiCoder ( ) . decode ( [ "bytes32" , "uint256" , "uint64" ] , logs [ logs . length - 1 ] . data ) [ 2 ]
37+ : BigInt ( 0 ) ;
4238 return [ veaInbox , epochPeriod , lastSavedCount , veaOutbox , deposit ] ;
4339}
4440
4541async function happyPath (
4642 veaInbox : VeaInboxArbToEth ,
4743 epochPeriod : number ,
48- lastSavedCount : BigNumber ,
44+ lastSavedCount : BigInt ,
4945 veaOutbox : VeaOutboxArbToEthDevnet ,
50- deposit : BigNumber
51- ) : Promise < BigNumber > {
46+ deposit : BigInt
47+ ) : Promise < BigInt > {
5248 let currentTS = Math . floor ( Date . now ( ) / 1000 ) ;
5349 let claimableEpoch = Math . floor ( currentTS / epochPeriod ) ;
5450 let newCount = lastSavedCount ;
5551 const snapshot = await veaInbox . snapshots ( claimableEpoch ) ;
5652
5753 if ( snapshot == "0x0000000000000000000000000000000000000000000000000000000000000000" ) {
5854 // check if snapshot should be taken
59- const inboxCount = await veaInbox . count ( ) ;
60- if ( inboxCount . gt ( lastSavedCount ) ) {
55+ const inboxCount : BigInt = await veaInbox . count ( ) ;
56+ if ( inboxCount > lastSavedCount ) {
6157 // should take snapshot
6258 console . log ( "inbox updated: taking snapshot. . ." ) ;
6359 const txn = await veaInbox . saveSnapshot ( ) ;
6460 const receipt = await txn . wait ( ) ;
6561
66- newCount = BigNumber . from ( receipt . logs [ 0 ] . data ) ;
62+ newCount = BigInt ( receipt . logs [ 0 ] . data ) ;
6763
6864 const snapshot = await veaInbox . snapshots ( claimableEpoch ) ;
6965 console . log ( `Snapshot Txn: ${ txn . hash } ` ) ;
7066 console . log ( "snapshot count: " , receipt . logs [ 0 ] . data ) ;
7167 lastSavedCount = inboxCount ;
72- const txnOutbox = await veaOutbox . devnetAdvanceState ( claimableEpoch , snapshot , { value : deposit } ) ;
68+ const txnOutbox = await veaOutbox . devnetAdvanceState ( claimableEpoch , snapshot , { value : Number ( deposit ) } ) ;
7369 console . log ( `DevnetAdvanceState Txn: ${ txnOutbox . hash } ` ) ;
7470 } else {
7571 console . log ( "inbox not updated: not taking snapshot. . ." ) ;
7672 }
7773 } else {
7874 console . log ( "snapshot already taken. . ." ) ;
7975 const latestVerifiedEpoch = await veaOutbox . latestVerifiedEpoch ( ) ;
80- if ( latestVerifiedEpoch . toNumber ( ) < claimableEpoch ) {
76+ if ( latestVerifiedEpoch < claimableEpoch ) {
8177 console . log ( "advancing devnet state. . ." ) ;
82- const txnOutbox = await veaOutbox . devnetAdvanceState ( claimableEpoch , snapshot , { value : deposit } ) ;
78+ const txnOutbox = await veaOutbox . devnetAdvanceState ( claimableEpoch , snapshot , { value : Number ( deposit ) } ) ;
8379 console . log ( `DevnetAdvanceState Txn: ${ txnOutbox . hash } ` ) ;
8480 }
8581 }
0 commit comments