-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathagent.rs
92 lines (80 loc) · 3.27 KB
/
agent.rs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2023-, GraphOps and Semiotic Labs.
// SPDX-License-Identifier: Apache-2.0
use std::time::Duration;
use alloy_sol_types::eip712_domain;
use indexer_common::prelude::{
escrow_accounts, indexer_allocations, DeploymentDetails, SubgraphClient,
};
use crate::{
aggregator_endpoints, config, database,
tap::sender_allocation_relationships_manager::SenderAllocationRelationshipsManager,
};
pub async fn start_agent(config: &'static config::Cli) {
let pgpool = database::connect(&config.postgres).await;
let http_client = reqwest::Client::new();
let network_subgraph = Box::leak(Box::new(SubgraphClient::new(
http_client.clone(),
config
.network_subgraph
.network_subgraph_deployment
.map(|deployment| {
DeploymentDetails::for_graph_node(
&config.indexer_infrastructure.graph_node_status_endpoint,
&config.indexer_infrastructure.graph_node_query_endpoint,
deployment,
)
})
.transpose()
.expect("Failed to parse graph node query endpoint and network subgraph deployment"),
DeploymentDetails::for_query_url(&config.network_subgraph.network_subgraph_endpoint)
.expect("Failed to parse network subgraph endpoint"),
)));
let indexer_allocations = indexer_allocations(
network_subgraph,
config.ethereum.indexer_address,
1,
Duration::from_millis(config.network_subgraph.allocation_syncing_interval_ms),
);
let escrow_subgraph = Box::leak(Box::new(SubgraphClient::new(
http_client.clone(),
config
.escrow_subgraph
.escrow_subgraph_deployment
.map(|deployment| {
DeploymentDetails::for_graph_node(
&config.indexer_infrastructure.graph_node_status_endpoint,
&config.indexer_infrastructure.graph_node_query_endpoint,
deployment,
)
})
.transpose()
.expect("Failed to parse graph node query endpoint and escrow subgraph deployment"),
DeploymentDetails::for_query_url(&config.escrow_subgraph.escrow_subgraph_endpoint)
.expect("Failed to parse escrow subgraph endpoint"),
)));
let escrow_accounts = escrow_accounts(
escrow_subgraph,
config.ethereum.indexer_address,
Duration::from_millis(config.escrow_subgraph.escrow_syncing_interval_ms),
);
// TODO: replace with a proper implementation once the gateway registry contract is ready
let sender_aggregator_endpoints = aggregator_endpoints::load_aggregator_endpoints(
config.tap.sender_aggregator_endpoints_file.clone(),
);
let tap_eip712_domain_separator = eip712_domain! {
name: "Scalar TAP",
version: "1",
chain_id: config.receipts.receipts_verifier_chain_id,
verifying_contract: config.receipts.receipts_verifier_address,
};
let _sender_allocation_relationships_manager = SenderAllocationRelationshipsManager::new(
config,
pgpool,
indexer_allocations,
escrow_accounts,
escrow_subgraph,
tap_eip712_domain_separator,
sender_aggregator_endpoints,
)
.await;
}