1
- import { getProofAtCount , getMessageDataToRelay , getSubgraph } from "./proof" ;
1
+ import { getProofAtCount , getMessageDataToRelay } from "./proof" ;
2
2
import { getVeaOutboxArbToEth } from "./ethers" ;
3
3
import request from "graphql-request" ;
4
- import { VeaInboxArbToEth , VeaOutboxArbToEth } from "@kleros/vea-contracts/typechain-types" ;
4
+ import { VeaOutboxArbToEth } from "@kleros/vea-contracts/typechain-types" ;
5
+ import { getBridgeConfig , getInboxSubgraph } from "../consts/bridgeRoutes" ;
5
6
const fs = require ( "fs" ) ;
6
7
7
8
require ( "dotenv" ) . config ( ) ;
@@ -10,22 +11,12 @@ const Web3 = require("web3");
10
11
const _batchedSend = require ( "web3-batched-send" ) ;
11
12
const _contract = require ( "@kleros/vea-contracts/deployments/sepolia/VeaOutboxArbToEthDevnet.json" ) ;
12
13
13
- const getParams = ( chainid : number ) : [ string , string , string ] => {
14
- if ( chainid !== 11155111 ) throw new Error ( "Invalid chainid" ) ;
15
-
16
- return [
17
- process . env . TRANSACTION_BATCHER_CONTRACT_ADDRESS_SEPOLIA ,
18
- process . env . VEAOUTBOX_ARBSEPOLIA_TO_SEPOLIA_ADDRESS ,
19
- process . env . RPC_SEPOLIA ,
20
- ] ;
21
- } ;
22
-
23
14
const getCount = async ( veaOutbox : VeaOutboxArbToEth , chainid : number ) : Promise < number > => {
24
- const subgraph = getSubgraph ( chainid ) ;
15
+ const subgraph = getInboxSubgraph ( chainid ) ;
25
16
const stateRoot = await veaOutbox . stateRoot ( ) ;
26
17
27
18
const result = await request (
28
- `https://api.studio.thegraph.com/query/85918/ ${ subgraph } /version/latest ` ,
19
+ `https://api.studio.thegraph.com/query/${ subgraph } ` ,
29
20
`{
30
21
snapshotSaveds(first: 1, where: { stateRoot: "${ stateRoot } " }) {
31
22
count
@@ -39,9 +30,9 @@ const getCount = async (veaOutbox: VeaOutboxArbToEth, chainid: number): Promise<
39
30
} ;
40
31
41
32
const relay = async ( chainid : number , nonce : number ) => {
42
- const [ TRANSACTION_BATCHER_CONTRACT_ADDRESS , VEAOUTBOX_ADDRESS , RPC_VEAOUTBOX ] = getParams ( chainid ) ;
33
+ const routeParams = getBridgeConfig ( chainid ) ;
43
34
44
- const veaOutbox = getVeaOutboxArbToEth ( VEAOUTBOX_ADDRESS , process . env . PRIVATE_KEY , RPC_VEAOUTBOX ) ;
35
+ const veaOutbox = getVeaOutboxArbToEth ( routeParams . veaOutbox , process . env . PRIVATE_KEY , routeParams . rpcOutbox ) ;
45
36
const count = await getCount ( veaOutbox , chainid ) ;
46
37
47
38
const proof = await getProofAtCount ( chainid , nonce , count ) ;
@@ -52,13 +43,13 @@ const relay = async (chainid: number, nonce: number) => {
52
43
} ;
53
44
54
45
const relayBatch = async ( chainid : number , nonce : number , iterations : number ) => {
55
- const [ TRANSACTION_BATCHER_CONTRACT_ADDRESS , VEAOUTBOX_ADDRESS , RPC_VEAOUTBOX ] = getParams ( chainid ) ;
46
+ const routeParams = getBridgeConfig ( chainid ) ;
56
47
57
- const web3 = new Web3 ( RPC_VEAOUTBOX ) ;
58
- const batchedSend = _batchedSend ( web3 , TRANSACTION_BATCHER_CONTRACT_ADDRESS , process . env . PRIVATE_KEY , 0 ) ;
48
+ const web3 = new Web3 ( routeParams . rpcOutbox ) ;
49
+ const batchedSend = _batchedSend ( web3 , routeParams . rpcOutbox , process . env . PRIVATE_KEY , 0 ) ;
59
50
60
- const contract = new web3 . eth . Contract ( _contract . abi , VEAOUTBOX_ADDRESS ) ;
61
- const veaOutbox = getVeaOutboxArbToEth ( VEAOUTBOX_ADDRESS , process . env . PRIVATE_KEY , RPC_VEAOUTBOX ) ;
51
+ const contract = new web3 . eth . Contract ( _contract . abi , routeParams . veaOutbox ) ;
52
+ const veaOutbox = getVeaOutboxArbToEth ( routeParams . veaOutbox , process . env . PRIVATE_KEY , routeParams . rpcOutbox ) ;
62
53
const count = await getCount ( veaOutbox , chainid ) ;
63
54
64
55
let txns = [ ] ;
@@ -73,24 +64,23 @@ const relayBatch = async (chainid: number, nonce: number, iterations: number) =>
73
64
} ) ;
74
65
}
75
66
76
- console . log ( txns ) ;
77
67
await batchedSend ( txns ) ;
78
68
} ;
79
69
80
70
const relayAllFrom = async ( chainid : number , nonce : number , msgSender : string ) : Promise < number > => {
81
- const [ TRANSACTION_BATCHER_CONTRACT_ADDRESS , VEAOUTBOX_ADDRESS , RPC_VEAOUTBOX ] = getParams ( chainid ) ;
71
+ const routeParams = getBridgeConfig ( chainid ) ;
82
72
83
- const web3 = new Web3 ( RPC_VEAOUTBOX ) ;
73
+ const web3 = new Web3 ( routeParams . rpcOutbox ) ;
84
74
const batchedSend = _batchedSend (
85
75
web3 , // Your web3 object.
86
76
// The address of the transaction batcher contract you wish to use. The addresses for the different networks are listed below. If the one you need is missing, feel free to deploy it yourself and make a PR to save the address here for others to use.
87
- TRANSACTION_BATCHER_CONTRACT_ADDRESS ,
77
+ routeParams . batcher ,
88
78
process . env . PRIVATE_KEY , // The private key of the account you want to send transactions from.
89
79
0 // The debounce timeout period in milliseconds in which transactions are batched.
90
80
) ;
91
81
92
- const contract = new web3 . eth . Contract ( _contract . abi , VEAOUTBOX_ADDRESS ) ;
93
- const veaOutbox = getVeaOutboxArbToEth ( VEAOUTBOX_ADDRESS , process . env . PRIVATE_KEY , RPC_VEAOUTBOX ) ;
82
+ const contract = new web3 . eth . Contract ( _contract . abi , routeParams . veaOutbox ) ;
83
+ const veaOutbox = getVeaOutboxArbToEth ( routeParams . veaOutbox , process . env . PRIVATE_KEY , routeParams . rpcOutbox ) ;
94
84
const count = await getCount ( veaOutbox , chainid ) ;
95
85
96
86
if ( ! count ) return null ;
@@ -116,10 +106,10 @@ const relayAllFrom = async (chainid: number, nonce: number, msgSender: string):
116
106
117
107
const getNonceFrom = async ( chainid : number , nonce : number , msgSender : string ) => {
118
108
try {
119
- const subgraph = getSubgraph ( chainid ) ;
109
+ const subgraph = getInboxSubgraph ( chainid ) ;
120
110
121
111
const result = await request (
122
- `https://api.studio.thegraph.com/query/85918/ ${ subgraph } /version/latest ` ,
112
+ `https://api.studio.thegraph.com/query/${ subgraph } ` ,
123
113
`{
124
114
messageSents(first: 1000, where: {nonce_gte: ${ nonce } , msgSender_: {id: "${ msgSender } "}}, orderBy: nonce, orderDirection: asc) {
125
115
nonce
0 commit comments