diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 926caecea..957ed080c 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,6 +1,5 @@ { "crates/tap-agent": "1.7.3", - "crates/common": "1.4.0", "crates/config": "1.2.1", "crates/service": "1.3.2" } diff --git a/Cargo.lock b/Cargo.lock index e3342ff2b..63a473e12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3473,36 +3473,26 @@ dependencies = [ ] [[package]] -name = "indexer-common" -version = "1.4.0" +name = "indexer-allocation" +version = "0.1.0" dependencies = [ "alloy", "anyhow", - "async-trait", - "axum", - "bigdecimal", - "bip39", - "build-info", - "env_logger", - "eventuals", - "graphql_client", - "indexer-config", "indexer-query", - "indexer-types", - "lazy_static", - "prometheus", - "reqwest 0.12.9", "serde", - "serde_json", - "sqlx", - "tap_core", + "thegraph-core", +] + +[[package]] +name = "indexer-attestation" +version = "0.1.0" +dependencies = [ + "alloy", + "anyhow", + "indexer-allocation", + "test-assets", "test-log", - "test-tap-utils", "thegraph-core", - "thiserror", - "tokio", - "tracing", - "wiremock 0.5.22", ] [[package]] @@ -3540,6 +3530,32 @@ dependencies = [ "thiserror", ] +[[package]] +name = "indexer-monitor" +version = "1.4.0" +dependencies = [ + "alloy", + "anyhow", + "axum", + "bip39", + "env_logger", + "graphql_client", + "indexer-allocation", + "indexer-attestation", + "indexer-query", + "indexer-watcher", + "reqwest 0.12.9", + "serde", + "serde_json", + "test-assets", + "test-log", + "thegraph-core", + "thiserror", + "tokio", + "tracing", + "wiremock 0.5.22", +] + [[package]] name = "indexer-query" version = "0.1.0" @@ -3565,6 +3581,7 @@ dependencies = [ "axum-extra", "base64 0.22.1", "bigdecimal", + "bip39", "build-info", "build-info-build", "clap", @@ -3572,9 +3589,11 @@ dependencies = [ "graphql 0.3.0", "graphql_client", "hex-literal", - "indexer-common", + "indexer-allocation", + "indexer-attestation", "indexer-config", "indexer-dips", + "indexer-monitor", "indexer-query", "lazy_static", "prometheus", @@ -3583,7 +3602,7 @@ dependencies = [ "serde_json", "sqlx", "tap_core", - "test-tap-utils", + "test-assets", "thegraph-core", "thegraph-graphql-http", "thiserror", @@ -3610,9 +3629,11 @@ dependencies = [ "futures", "futures-util", "graphql_client", - "indexer-common", + "indexer-allocation", "indexer-config", + "indexer-monitor", "indexer-query", + "indexer-watcher", "jsonrpsee", "lazy_static", "prometheus", @@ -3634,14 +3655,12 @@ dependencies = [ ] [[package]] -name = "indexer-types" +name = "indexer-watcher" version = "0.1.0" dependencies = [ - "alloy", "anyhow", - "indexer-query", - "serde", - "thegraph-core", + "tokio", + "tracing", ] [[package]] @@ -6690,6 +6709,18 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "test-assets" +version = "0.1.0" +dependencies = [ + "alloy", + "bip39", + "indexer-allocation", + "lazy_static", + "tap_core", + "thegraph-core", +] + [[package]] name = "test-log" version = "0.2.16" @@ -6710,18 +6741,6 @@ dependencies = [ "syn 2.0.79", ] -[[package]] -name = "test-tap-utils" -version = "0.1.0" -dependencies = [ - "alloy", - "bip39", - "indexer-types", - "lazy_static", - "tap_core", - "thegraph-core", -] - [[package]] name = "thegraph-core" version = "0.7.0" diff --git a/Cargo.toml b/Cargo.toml index d7ad713d8..8eba38279 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,13 +1,15 @@ [workspace] members = [ - "crates/common", + "crates/allocation", + "crates/attestation", "crates/config", "crates/dips", + "crates/monitor", "crates/query", "crates/service", "crates/tap-agent", - "crates/types", - "crates/tests/tap-utils", + "crates/test-assets", + "crates/watcher", ] resolver = "2" @@ -68,3 +70,4 @@ thegraph-core = { git = "https://github.com/edgeandnode/toolshed", rev = "166353 ] } thegraph-graphql-http = "0.2.0" graphql_client = { version = "0.14.0", features = ["reqwest-rustls"] } +bip39 = "2.0.0" diff --git a/crates/types/Cargo.toml b/crates/allocation/Cargo.toml similarity index 89% rename from crates/types/Cargo.toml rename to crates/allocation/Cargo.toml index d38be691b..99453d253 100644 --- a/crates/types/Cargo.toml +++ b/crates/allocation/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "indexer-types" +name = "indexer-allocation" version = "0.1.0" edition = "2021" diff --git a/crates/types/src/lib.rs b/crates/allocation/src/lib.rs similarity index 100% rename from crates/types/src/lib.rs rename to crates/allocation/src/lib.rs diff --git a/crates/attestation/Cargo.toml b/crates/attestation/Cargo.toml new file mode 100644 index 000000000..621651c54 --- /dev/null +++ b/crates/attestation/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "indexer-attestation" +version = "0.1.0" +edition = "2021" + +[dependencies] +indexer-allocation = { path = "../allocation" } +alloy.workspace = true +thegraph-core.workspace = true +anyhow.workspace = true + + +[dev-dependencies] +test-log = { version = "0.2.12", default-features = false } +test-assets = { path = "../test-assets" } diff --git a/crates/common/src/attestation/signer.rs b/crates/attestation/src/lib.rs similarity index 97% rename from crates/common/src/attestation/signer.rs rename to crates/attestation/src/lib.rs index 2c5879517..9adad16f5 100644 --- a/crates/common/src/attestation/signer.rs +++ b/crates/attestation/src/lib.rs @@ -10,7 +10,7 @@ use alloy::{ }; use thegraph_core::{attestation, Address, Attestation, ChainId, DeploymentId}; -use indexer_types::Allocation; +use indexer_allocation::Allocation; pub fn derive_key_pair( indexer_mnemonic: &str, @@ -121,8 +121,8 @@ mod tests { use std::str::FromStr; use test_log::test; - use crate::test_vectors::DISPUTE_MANAGER_ADDRESS; - use indexer_types::{Allocation, AllocationStatus, SubgraphDeployment}; + use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment}; + use test_assets::DISPUTE_MANAGER_ADDRESS; use super::*; diff --git a/crates/common/CHANGELOG.md b/crates/common/CHANGELOG.md deleted file mode 100644 index 2f778649a..000000000 --- a/crates/common/CHANGELOG.md +++ /dev/null @@ -1,51 +0,0 @@ -# Changelog - -## [1.4.0](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.3.1...indexer-common-v1.4.0) (2024-11-08) - - -### Features - -* Add grace period ([#467](https://github.com/graphprotocol/indexer-rs/issues/467)) ([775f2f6](https://github.com/graphprotocol/indexer-rs/commit/775f2f62e6c7aad0489beef03a9346a943d7b406)) -* add subgraph health endpoint ([#449](https://github.com/graphprotocol/indexer-rs/issues/449)) ([bab22af](https://github.com/graphprotocol/indexer-rs/commit/bab22afabb10c58138f5d72f366cf3bf015b8251)) - -## [1.3.1](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.3.0...indexer-common-v1.3.1) (2024-11-06) - - -### Bug Fixes - -* use request from gateway instead of serde req ([#464](https://github.com/graphprotocol/indexer-rs/issues/464)) ([fdeda9f](https://github.com/graphprotocol/indexer-rs/commit/fdeda9fea996f96e1c0a7bef291a551f426f5591)) - -## [1.3.0](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.2.1...indexer-common-v1.3.0) (2024-11-01) - - -### Features - -* enable value check ([#430](https://github.com/graphprotocol/indexer-rs/issues/430)) ([466a5a9](https://github.com/graphprotocol/indexer-rs/commit/466a5a92c66f5cd31f5aa9c20fb51cd0df391d6c)) - -## [1.2.1](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.2.0...indexer-common-v1.2.1) (2024-10-30) - - -### Bug Fixes - -* add more information about failing subgraph query ([#436](https://github.com/graphprotocol/indexer-rs/issues/436)) ([1e52f82](https://github.com/graphprotocol/indexer-rs/commit/1e52f82ec240c63c940bcc3b20e58750c31b4d66)) -* proper build graph-node query url ([#438](https://github.com/graphprotocol/indexer-rs/issues/438)) ([df94692](https://github.com/graphprotocol/indexer-rs/commit/df94692e66f48a186deeac99bda8e0fcfddb2e52)) - -## [1.2.0](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.1.0...indexer-common-v1.2.0) (2024-10-30) - - -### Features - -* add value check ([#153](https://github.com/graphprotocol/indexer-rs/issues/153)) ([1e4a3cd](https://github.com/graphprotocol/indexer-rs/commit/1e4a3cdd8c18b5356e64285b8082d8abde20d6de)) - - -### Bug Fixes - -* disable value check ([#429](https://github.com/graphprotocol/indexer-rs/issues/429)) ([eb31981](https://github.com/graphprotocol/indexer-rs/commit/eb3198174dab1b08f365c5ac4e47da62c88b6fb4)) -* initialize allocations monitor ([#428](https://github.com/graphprotocol/indexer-rs/issues/428)) ([f0c7d03](https://github.com/graphprotocol/indexer-rs/commit/f0c7d0367abf8a833f1824264780df50ad6a3c52)) - -## [1.1.0](https://github.com/graphprotocol/indexer-rs/compare/indexer-common-v1.0.0...indexer-common-v1.1.0) (2024-10-09) - - -### Features - -* add metrics to service ([#319](https://github.com/graphprotocol/indexer-rs/issues/319)) ([57c89e2](https://github.com/graphprotocol/indexer-rs/commit/57c89e237a57b49214eaf902303e3d89c9d82396)) diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml deleted file mode 100644 index cb1a1be0e..000000000 --- a/crates/common/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "indexer-common" -version = "1.4.0" -edition = "2021" - -[dependencies] -indexer-config = { path = "../config" } -indexer-query = { path = "../query" } -indexer-types = { path = "../types" } -thiserror.workspace = true -async-trait.workspace = true -alloy.workspace = true -anyhow.workspace = true -eventuals.workspace = true -reqwest.workspace = true -sqlx.workspace = true -tap_core.workspace = true -tracing.workspace = true -bigdecimal.workspace = true -prometheus.workspace = true -thegraph-core.workspace = true -axum.workspace = true -lazy_static.workspace = true -build-info.workspace = true -graphql_client.workspace = true - -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -tokio = { workspace = true, features = ["fs", "tokio-macros"] } -bip39 = "2.0.0" - -[dev-dependencies] -env_logger = { version = "0.11.0", default-features = false } -test-log = { version = "0.2.12", default-features = false } -wiremock = "0.5.19" -test-tap-utils = { path = "../tests/tap-utils" } diff --git a/crates/common/src/attestation/mod.rs b/crates/common/src/attestation/mod.rs deleted file mode 100644 index 45065d0db..000000000 --- a/crates/common/src/attestation/mod.rs +++ /dev/null @@ -1,8 +0,0 @@ -// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. -// SPDX-License-Identifier: Apache-2.0 - -mod monitor; -pub mod signer; - -pub use monitor::attestation_signers; -pub use signer::{derive_key_pair, AttestationSigner}; diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs deleted file mode 100644 index 855b52094..000000000 --- a/crates/common/src/lib.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. -// SPDX-License-Identifier: Apache-2.0 - -mod allocations; -pub mod attestation; -pub mod client; -mod dispute_manager; -pub mod escrow_accounts; -pub mod wallet; -pub mod watcher; - -#[cfg(test)] -mod test_vectors; - -pub mod monitors { - pub use super::allocations::indexer_allocations; - pub use super::attestation::attestation_signers; - pub use super::dispute_manager::dispute_manager; - pub use super::escrow_accounts::escrow_accounts; -} - -pub use crate::client::{DeploymentDetails, SubgraphClient}; -pub use escrow_accounts::{EscrowAccounts, EscrowAccountsError}; -pub use indexer_types::{Allocation, AllocationStatus, SubgraphDeployment}; diff --git a/crates/monitor/Cargo.toml b/crates/monitor/Cargo.toml new file mode 100644 index 000000000..c29d15425 --- /dev/null +++ b/crates/monitor/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "indexer-monitor" +version = "0.1.0" +edition = "2021" + +[dependencies] +indexer-query = { path = "../query" } +indexer-allocation = { path = "../allocation" } +indexer-attestation = { path = "../attestation" } +indexer-watcher = { path = "../watcher" } +thiserror.workspace = true +alloy.workspace = true +anyhow.workspace = true +reqwest = { workspace = true, features = ["json"] } +tracing.workspace = true +thegraph-core.workspace = true +axum.workspace = true +graphql_client.workspace = true +serde = { workspace = true, features = ["derive"] } +serde_json.workspace = true +tokio.workspace = true +bip39.workspace = true + +[dev-dependencies] +env_logger = { version = "0.11.0", default-features = false } +test-log = { version = "0.2.12", default-features = false } +wiremock = "0.5.19" +test-assets = { path = "../test-assets" } diff --git a/crates/common/src/allocations.rs b/crates/monitor/src/allocations.rs similarity index 97% rename from crates/common/src/allocations.rs rename to crates/monitor/src/allocations.rs index a8618d8ad..d4f88666e 100644 --- a/crates/common/src/allocations.rs +++ b/crates/monitor/src/allocations.rs @@ -1,10 +1,11 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::{client::SubgraphClient, watcher::new_watcher}; +use crate::client::SubgraphClient; use alloy::{primitives::Address, primitives::TxHash}; +use indexer_allocation::Allocation; use indexer_query::allocations_query::{self, AllocationsQuery}; -use indexer_types::Allocation; +use indexer_watcher::new_watcher; use std::{ collections::HashMap, time::{Duration, SystemTime, UNIX_EPOCH}, diff --git a/crates/common/src/attestation/monitor.rs b/crates/monitor/src/attestation.rs similarity index 94% rename from crates/common/src/attestation/monitor.rs rename to crates/monitor/src/attestation.rs index 90146bdb7..b81c568fd 100644 --- a/crates/common/src/attestation/monitor.rs +++ b/crates/monitor/src/attestation.rs @@ -2,15 +2,15 @@ // SPDX-License-Identifier: Apache-2.0 use bip39::Mnemonic; +use indexer_allocation::Allocation; +use indexer_attestation::AttestationSigner; +use indexer_watcher::join_and_map_watcher; use std::sync::Arc; use std::{collections::HashMap, sync::Mutex}; use thegraph_core::{Address, ChainId}; use tokio::sync::watch::Receiver; use tracing::warn; -use crate::{attestation::signer::AttestationSigner, watcher::join_and_map_watcher}; -use indexer_types::Allocation; - /// An always up-to-date list of attestation signers, one for each of the indexer's allocations. pub fn attestation_signers( indexer_allocations_rx: Receiver>, @@ -75,7 +75,7 @@ fn modify_sigers( mod tests { use tokio::sync::watch; - use crate::test_vectors::{DISPUTE_MANAGER_ADDRESS, INDEXER_ALLOCATIONS, INDEXER_MNEMONIC}; + use test_assets::{DISPUTE_MANAGER_ADDRESS, INDEXER_ALLOCATIONS, INDEXER_MNEMONIC}; use super::*; diff --git a/crates/common/src/client/mod.rs b/crates/monitor/src/client/mod.rs similarity index 100% rename from crates/common/src/client/mod.rs rename to crates/monitor/src/client/mod.rs diff --git a/crates/common/src/client/monitor.rs b/crates/monitor/src/client/monitor.rs similarity index 99% rename from crates/common/src/client/monitor.rs rename to crates/monitor/src/client/monitor.rs index f2aed7765..53ba9de16 100644 --- a/crates/common/src/client/monitor.rs +++ b/crates/monitor/src/client/monitor.rs @@ -13,7 +13,7 @@ use serde::Deserialize; use thegraph_core::DeploymentId; use tokio::sync::watch::Receiver; -use crate::watcher::new_watcher; +use indexer_watcher::new_watcher; #[derive(Clone, Debug, Deserialize, Eq, PartialEq)] pub struct DeploymentStatus { diff --git a/crates/common/src/client/subgraph_client.rs b/crates/monitor/src/client/subgraph_client.rs similarity index 99% rename from crates/common/src/client/subgraph_client.rs rename to crates/monitor/src/client/subgraph_client.rs index 6a6e88163..aa68c6a63 100644 --- a/crates/common/src/client/subgraph_client.rs +++ b/crates/monitor/src/client/subgraph_client.rs @@ -254,8 +254,6 @@ mod test { use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; - use crate::test_vectors::{self}; - use super::*; const NETWORK_SUBGRAPH_URL: &str = @@ -266,7 +264,7 @@ mod test { let mock = Mock::given(method("POST")) .and(path(format!( "/subgraphs/id/{}", - *test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT + *test_assets::NETWORK_SUBGRAPH_DEPLOYMENT ))) .respond_with(ResponseTemplate::new(200).set_body_raw( r#" diff --git a/crates/common/src/dispute_manager.rs b/crates/monitor/src/dispute_manager.rs similarity index 88% rename from crates/common/src/dispute_manager.rs rename to crates/monitor/src/dispute_manager.rs index ea671bc97..481232f58 100644 --- a/crates/common/src/dispute_manager.rs +++ b/crates/monitor/src/dispute_manager.rs @@ -1,10 +1,11 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use crate::{client::SubgraphClient, watcher::new_watcher}; +use crate::client::SubgraphClient; use alloy::primitives::Address; use anyhow::Error; use indexer_query::dispute_manager::{self, DisputeManager}; +use indexer_watcher::new_watcher; use std::time::Duration; use tokio::sync::watch::Receiver; @@ -27,17 +28,14 @@ pub async fn dispute_manager( #[cfg(test)] mod test { use serde_json::json; + use test_assets::DISPUTE_MANAGER_ADDRESS; use tokio::time::sleep; use wiremock::{ matchers::{method, path}, Mock, MockServer, ResponseTemplate, }; - use crate::{ - client::DeploymentDetails, - client::SubgraphClient, - test_vectors::{self, DISPUTE_MANAGER_ADDRESS}, - }; + use crate::{client::DeploymentDetails, client::SubgraphClient}; use super::*; @@ -50,7 +48,7 @@ mod test { DeploymentDetails::for_query_url(&format!( "{}/subgraphs/id/{}", &mock_server.uri(), - *test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT + *test_assets::NETWORK_SUBGRAPH_DEPLOYMENT )) .unwrap(), ) @@ -62,7 +60,7 @@ mod test { Mock::given(method("POST")) .and(path(format!( "/subgraphs/id/{}", - *test_vectors::NETWORK_SUBGRAPH_DEPLOYMENT + *test_assets::NETWORK_SUBGRAPH_DEPLOYMENT ))) .respond_with(ResponseTemplate::new(200).set_body_json( json!({ "data": { "graphNetwork": { "disputeManager": *DISPUTE_MANAGER_ADDRESS }}}), diff --git a/crates/common/src/escrow_accounts.rs b/crates/monitor/src/escrow_accounts.rs similarity index 94% rename from crates/common/src/escrow_accounts.rs rename to crates/monitor/src/escrow_accounts.rs index f8d7a8c5e..95c0a82a8 100644 --- a/crates/common/src/escrow_accounts.rs +++ b/crates/monitor/src/escrow_accounts.rs @@ -14,7 +14,7 @@ use thiserror::Error; use tokio::sync::watch::Receiver; use tracing::{error, warn}; -use crate::{client::SubgraphClient, watcher}; +use crate::client::SubgraphClient; #[derive(Error, Debug)] pub enum EscrowAccountsError { @@ -93,7 +93,7 @@ pub async fn escrow_accounts( interval: Duration, reject_thawing_signers: bool, ) -> Result, anyhow::Error> { - watcher::new_watcher(interval, move || { + indexer_watcher::new_watcher(interval, move || { get_escrow_accounts(escrow_subgraph, indexer_address, reject_thawing_signers) }) .await @@ -164,16 +164,15 @@ async fn get_escrow_accounts( #[cfg(test)] mod tests { - use test_log::test; - use test_tap_utils::{ + use test_assets::{ ESCROW_ACCOUNTS_BALANCES, ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS, ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS, }; + use test_log::test; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; use crate::client::DeploymentDetails; - use crate::test_vectors; use super::*; @@ -201,7 +200,7 @@ mod tests { DeploymentDetails::for_query_url(&format!( "{}/subgraphs/id/{}", &mock_server.uri(), - *test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT + *test_assets::ESCROW_SUBGRAPH_DEPLOYMENT )) .unwrap(), ) @@ -211,17 +210,17 @@ mod tests { let mock = Mock::given(method("POST")) .and(path(format!( "/subgraphs/id/{}", - *test_vectors::ESCROW_SUBGRAPH_DEPLOYMENT + *test_assets::ESCROW_SUBGRAPH_DEPLOYMENT ))) .respond_with( ResponseTemplate::new(200) - .set_body_raw(test_vectors::ESCROW_QUERY_RESPONSE, "application/json"), + .set_body_raw(test_assets::ESCROW_QUERY_RESPONSE, "application/json"), ); mock_server.register(mock).await; let mut accounts = escrow_accounts( escrow_subgraph, - *test_vectors::INDEXER_ADDRESS, + *test_assets::INDEXER_ADDRESS, Duration::from_secs(60), true, ) diff --git a/crates/monitor/src/lib.rs b/crates/monitor/src/lib.rs new file mode 100644 index 000000000..765ee6299 --- /dev/null +++ b/crates/monitor/src/lib.rs @@ -0,0 +1,16 @@ +// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. +// SPDX-License-Identifier: Apache-2.0 + +mod allocations; +mod attestation; +mod client; +mod dispute_manager; +mod escrow_accounts; + +pub use crate::{ + allocations::indexer_allocations, + attestation::attestation_signers, + client::{DeploymentDetails, SubgraphClient}, + dispute_manager::dispute_manager, + escrow_accounts::{escrow_accounts, EscrowAccounts, EscrowAccountsError}, +}; diff --git a/crates/service/Cargo.toml b/crates/service/Cargo.toml index 65a1c0a57..4a9c6f2f3 100644 --- a/crates/service/Cargo.toml +++ b/crates/service/Cargo.toml @@ -7,7 +7,9 @@ license = "Apache-2.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -indexer-common = { path = "../common" } +indexer-monitor = { path = "../monitor" } +indexer-attestation = { path = "../attestation" } +indexer-allocation = { path = "../allocation" } indexer-config = { path = "../config" } indexer-dips = { path = "../dips" } indexer-query = { path = "../query" } @@ -50,10 +52,11 @@ axum-extra = { version = "0.9.3", features = [ ], default-features = false } tokio-util = "0.7.10" cost-model = { git = "https://github.com/graphprotocol/agora", rev = "3ed34ca" } +bip39.workspace = true [dev-dependencies] hex-literal = "0.4.1" -test-tap-utils = { path = "../tests/tap-utils" } +test-assets = { path = "../test-assets" } [build-dependencies] build-info-build = { version = "0.0.39", default-features = false } diff --git a/crates/service/src/lib.rs b/crates/service/src/lib.rs index 551e170aa..ac967df4e 100644 --- a/crates/service/src/lib.rs +++ b/crates/service/src/lib.rs @@ -7,3 +7,4 @@ mod error; mod routes; pub mod service; mod tap; +mod wallet; diff --git a/crates/service/src/routes/static_subgraph.rs b/crates/service/src/routes/static_subgraph.rs index b2447b0ac..eab55c996 100644 --- a/crates/service/src/routes/static_subgraph.rs +++ b/crates/service/src/routes/static_subgraph.rs @@ -6,7 +6,7 @@ use reqwest::StatusCode; use serde_json::json; use tracing::warn; -use indexer_common::SubgraphClient; +use indexer_monitor::SubgraphClient; #[autometrics::autometrics] pub async fn static_subgraph_request_handler( diff --git a/crates/service/src/service/indexer_service.rs b/crates/service/src/service/indexer_service.rs index 3325402e6..ec05ebeb7 100644 --- a/crates/service/src/service/indexer_service.rs +++ b/crates/service/src/service/indexer_service.rs @@ -13,12 +13,10 @@ use axum::{ }; use axum::{serve, ServiceExt}; use build_info::BuildInfo; -use indexer_common::{ - attestation::AttestationSigner, - client::{DeploymentDetails, SubgraphClient}, - escrow_accounts::{EscrowAccounts, EscrowAccountsError}, - monitors::{attestation_signers, dispute_manager, escrow_accounts, indexer_allocations}, - wallet::public_key, +use indexer_attestation::AttestationSigner; +use indexer_monitor::{ + attestation_signers, dispute_manager, escrow_accounts, indexer_allocations, DeploymentDetails, + EscrowAccounts, EscrowAccountsError, SubgraphClient, }; use prometheus::TextEncoder; use reqwest::StatusCode; @@ -45,6 +43,7 @@ use crate::routes::health; use crate::routes::request_handler; use crate::routes::static_subgraph_request_handler; use crate::tap::IndexerTapContext; +use crate::wallet::public_key; use indexer_config::Config; use super::SubgraphService; diff --git a/crates/service/src/service/tap_receipt_header.rs b/crates/service/src/service/tap_receipt_header.rs index 0f373e5ce..d5937cb45 100644 --- a/crates/service/src/service/tap_receipt_header.rs +++ b/crates/service/src/service/tap_receipt_header.rs @@ -71,7 +71,7 @@ mod test { use axum::http::HeaderValue; use axum_extra::headers::Header; - use test_tap_utils::create_signed_receipt; + use test_assets::create_signed_receipt; use super::TapReceipt; diff --git a/crates/service/src/tap.rs b/crates/service/src/tap.rs index b4b80c55f..ad5f1135f 100644 --- a/crates/service/src/tap.rs +++ b/crates/service/src/tap.rs @@ -9,7 +9,8 @@ use crate::tap::checks::timestamp_check::TimestampCheck; use crate::tap::checks::value_check::MinimumValue; use alloy::dyn_abi::Eip712Domain; use alloy::primitives::Address; -use indexer_common::{Allocation, EscrowAccounts}; +use indexer_allocation::Allocation; +use indexer_monitor::EscrowAccounts; use receipt_store::{DatabaseReceipt, InnerContext}; use sqlx::PgPool; use std::fmt::Debug; diff --git a/crates/service/src/tap/checks/allocation_eligible.rs b/crates/service/src/tap/checks/allocation_eligible.rs index 199890645..965a7b135 100644 --- a/crates/service/src/tap/checks/allocation_eligible.rs +++ b/crates/service/src/tap/checks/allocation_eligible.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use alloy::primitives::Address; use anyhow::anyhow; -use indexer_common::Allocation; +use indexer_allocation::Allocation; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, diff --git a/crates/service/src/tap/checks/deny_list_check.rs b/crates/service/src/tap/checks/deny_list_check.rs index 32745d3d6..44ca5af5e 100644 --- a/crates/service/src/tap/checks/deny_list_check.rs +++ b/crates/service/src/tap/checks/deny_list_check.rs @@ -3,7 +3,7 @@ use alloy::dyn_abi::Eip712Domain; use alloy::primitives::Address; -use indexer_common::escrow_accounts::EscrowAccounts; +use indexer_monitor::EscrowAccounts; use sqlx::postgres::PgListener; use sqlx::PgPool; use std::collections::HashSet; @@ -202,7 +202,7 @@ mod tests { use tap_core::receipt::{Context, ReceiptWithState}; use tokio::sync::watch; - use test_tap_utils::{ + use test_assets::{ self, create_signed_receipt, ESCROW_ACCOUNTS_BALANCES, ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS, TAP_EIP712_DOMAIN, TAP_SENDER, }; diff --git a/crates/service/src/tap/checks/sender_balance_check.rs b/crates/service/src/tap/checks/sender_balance_check.rs index 5e5bbc912..cc31c7425 100644 --- a/crates/service/src/tap/checks/sender_balance_check.rs +++ b/crates/service/src/tap/checks/sender_balance_check.rs @@ -4,7 +4,7 @@ use alloy::dyn_abi::Eip712Domain; use alloy::primitives::U256; use anyhow::anyhow; -use indexer_common::escrow_accounts::EscrowAccounts; +use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, diff --git a/crates/service/src/tap/checks/value_check.rs b/crates/service/src/tap/checks/value_check.rs index 0591b1f20..01acc1d5d 100644 --- a/crates/service/src/tap/checks/value_check.rs +++ b/crates/service/src/tap/checks/value_check.rs @@ -348,7 +348,7 @@ enum CostModelNotification { mod tests { use alloy::primitives::{address, Address}; use std::time::Duration; - use test_tap_utils::create_signed_receipt; + use test_assets::create_signed_receipt; use sqlx::PgPool; use tap_core::receipt::{checks::Check, Context, ReceiptWithState}; diff --git a/crates/common/src/wallet.rs b/crates/service/src/wallet.rs similarity index 100% rename from crates/common/src/wallet.rs rename to crates/service/src/wallet.rs diff --git a/crates/tap-agent/Cargo.toml b/crates/tap-agent/Cargo.toml index c4c28d447..2bc04f2e3 100644 --- a/crates/tap-agent/Cargo.toml +++ b/crates/tap-agent/Cargo.toml @@ -9,7 +9,9 @@ name = "indexer-tap-agent" path = "src/main.rs" [dependencies] -indexer-common = { path = "../common" } +indexer-monitor = { path = "../monitor" } +indexer-watcher = { path = "../watcher" } +indexer-allocation = { path = "../allocation" } indexer-config = { path = "../config" } indexer-query = { path = "../query" } alloy.workspace = true diff --git a/crates/tap-agent/src/agent.rs b/crates/tap-agent/src/agent.rs index 7d84b186f..cd069ab3d 100644 --- a/crates/tap-agent/src/agent.rs +++ b/crates/tap-agent/src/agent.rs @@ -1,14 +1,11 @@ // Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. // SPDX-License-Identifier: Apache-2.0 -use indexer_common::{ - monitors::{escrow_accounts, indexer_allocations}, - DeploymentDetails, SubgraphClient, -}; use indexer_config::{ Config, EscrowSubgraphConfig, GraphNodeConfig, IndexerConfig, NetworkSubgraphConfig, SubgraphConfig, SubgraphsConfig, TapConfig, }; +use indexer_monitor::{escrow_accounts, indexer_allocations, DeploymentDetails, SubgraphClient}; use ractor::concurrency::JoinHandle; use ractor::{Actor, ActorRef}; use sender_account::SenderAccountConfig; diff --git a/crates/tap-agent/src/agent/sender_account.rs b/crates/tap-agent/src/agent/sender_account.rs index 5cd9061c7..bc61d9be3 100644 --- a/crates/tap-agent/src/agent/sender_account.rs +++ b/crates/tap-agent/src/agent/sender_account.rs @@ -8,12 +8,12 @@ use bigdecimal::num_bigint::ToBigInt; use bigdecimal::ToPrimitive; use futures::{stream, StreamExt}; -use indexer_common::watcher::watch_pipe; use indexer_query::unfinalized_transactions; use indexer_query::{ closed_allocations::{self, ClosedAllocations}, UnfinalizedTransactions, }; +use indexer_watcher::watch_pipe; use jsonrpsee::http_client::HttpClientBuilder; use prometheus::{register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec}; use reqwest::Url; @@ -26,7 +26,7 @@ use tokio::task::JoinHandle; use alloy::dyn_abi::Eip712Domain; use alloy::primitives::Address; use anyhow::Result; -use indexer_common::{escrow_accounts::EscrowAccounts, SubgraphClient}; +use indexer_monitor::{EscrowAccounts, SubgraphClient}; use ractor::{Actor, ActorProcessingErr, ActorRef, MessagingErr, SupervisionEvent}; use sqlx::PgPool; use tap_core::rav::SignedRAV; @@ -1039,8 +1039,7 @@ pub mod tests { }; use alloy::hex::ToHexExt; use alloy::primitives::{Address, U256}; - use indexer_common::escrow_accounts::EscrowAccounts; - use indexer_common::{DeploymentDetails, SubgraphClient}; + use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; use ractor::concurrency::JoinHandle; use ractor::{call, Actor, ActorProcessingErr, ActorRef, ActorStatus}; use reqwest::Url; diff --git a/crates/tap-agent/src/agent/sender_accounts_manager.rs b/crates/tap-agent/src/agent/sender_accounts_manager.rs index aa10e1a41..283c65c08 100644 --- a/crates/tap-agent/src/agent/sender_accounts_manager.rs +++ b/crates/tap-agent/src/agent/sender_accounts_manager.rs @@ -15,9 +15,9 @@ use alloy::primitives::Address; use anyhow::Result; use anyhow::{anyhow, bail}; use futures::{stream, StreamExt}; -use indexer_common::escrow_accounts::EscrowAccounts; -use indexer_common::watcher::watch_pipe; -use indexer_common::{Allocation, SubgraphClient}; +use indexer_allocation::Allocation; +use indexer_monitor::{EscrowAccounts, SubgraphClient}; +use indexer_watcher::watch_pipe; use prometheus::{register_counter_vec, CounterVec}; use ractor::concurrency::JoinHandle; use ractor::{Actor, ActorCell, ActorProcessingErr, ActorRef, SupervisionEvent}; @@ -593,8 +593,7 @@ mod tests { ALLOCATION_ID_1, INDEXER, SENDER, SENDER_2, SENDER_3, SIGNER, TAP_EIP712_DOMAIN_SEPARATOR, }; use alloy::hex::ToHexExt; - use indexer_common::client::{DeploymentDetails, SubgraphClient}; - use indexer_common::escrow_accounts::EscrowAccounts; + use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; use ractor::concurrency::JoinHandle; use ractor::{Actor, ActorProcessingErr, ActorRef}; use reqwest::Url; diff --git a/crates/tap-agent/src/agent/sender_allocation.rs b/crates/tap-agent/src/agent/sender_allocation.rs index 5d7f64ef8..98ae0910b 100644 --- a/crates/tap-agent/src/agent/sender_allocation.rs +++ b/crates/tap-agent/src/agent/sender_allocation.rs @@ -10,7 +10,7 @@ use alloy::primitives::Address; use alloy::{dyn_abi::Eip712Domain, hex::ToHexExt}; use anyhow::{anyhow, ensure, Result}; use bigdecimal::{num_bigint::BigInt, ToPrimitive}; -use indexer_common::{escrow_accounts::EscrowAccounts, SubgraphClient}; +use indexer_monitor::{EscrowAccounts, SubgraphClient}; use jsonrpsee::{core::client::ClientT, rpc_params}; use prometheus::{register_counter_vec, register_histogram_vec, CounterVec, HistogramVec}; use ractor::{Actor, ActorProcessingErr, ActorRef}; @@ -872,7 +872,7 @@ pub mod tests { }, }; use futures::future::join_all; - use indexer_common::{escrow_accounts::EscrowAccounts, DeploymentDetails, SubgraphClient}; + use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient}; use jsonrpsee::http_client::HttpClientBuilder; use ractor::{ call, cast, concurrency::JoinHandle, Actor, ActorProcessingErr, ActorRef, ActorStatus, diff --git a/crates/tap-agent/src/tap/context.rs b/crates/tap-agent/src/tap/context.rs index b49a34d88..b543bb21f 100644 --- a/crates/tap-agent/src/tap/context.rs +++ b/crates/tap-agent/src/tap/context.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use alloy::primitives::Address; -use indexer_common::escrow_accounts::EscrowAccounts; +use indexer_monitor::EscrowAccounts; use sqlx::PgPool; use tokio::sync::watch::Receiver; diff --git a/crates/tap-agent/src/tap/context/checks/allocation_id.rs b/crates/tap-agent/src/tap/context/checks/allocation_id.rs index 8ae1be645..46990da91 100644 --- a/crates/tap-agent/src/tap/context/checks/allocation_id.rs +++ b/crates/tap-agent/src/tap/context/checks/allocation_id.rs @@ -5,8 +5,9 @@ use std::time::Duration; use alloy::primitives::Address; use anyhow::anyhow; -use indexer_common::{watcher::new_watcher, SubgraphClient}; +use indexer_monitor::SubgraphClient; use indexer_query::{tap_transactions, TapTransactions}; +use indexer_watcher::new_watcher; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, @@ -110,7 +111,7 @@ async fn query_escrow_check_transactions( #[cfg(test)] mod tests { - use indexer_common::{DeploymentDetails, SubgraphClient}; + use indexer_monitor::{DeploymentDetails, SubgraphClient}; #[tokio::test] async fn test_transaction_exists() { diff --git a/crates/tap-agent/src/tap/context/checks/signature.rs b/crates/tap-agent/src/tap/context/checks/signature.rs index afec26ea0..8010062fd 100644 --- a/crates/tap-agent/src/tap/context/checks/signature.rs +++ b/crates/tap-agent/src/tap/context/checks/signature.rs @@ -3,7 +3,7 @@ use alloy::{dyn_abi::Eip712Domain, primitives::U256}; use anyhow::anyhow; -use indexer_common::escrow_accounts::EscrowAccounts; +use indexer_monitor::EscrowAccounts; use tap_core::receipt::{ checks::{Check, CheckError, CheckResult}, state::Checking, diff --git a/crates/tap-agent/src/tap/context/error.rs b/crates/tap-agent/src/tap/context/error.rs index 91e43a991..aa5d443f7 100644 --- a/crates/tap-agent/src/tap/context/error.rs +++ b/crates/tap-agent/src/tap/context/error.rs @@ -9,7 +9,7 @@ pub enum AdapterError { EscrowEventualError { error: String }, #[error("Could not get available escrow for sender")] - AvailableEscrowError(#[from] indexer_common::escrow_accounts::EscrowAccountsError), + AvailableEscrowError(#[from] indexer_monitor::EscrowAccountsError), #[error("Sender {sender} escrow balance is too large to fit in u128, could not get available escrow.")] BalanceTooLarge { sender: Address }, diff --git a/crates/tap-agent/src/tap/context/rav.rs b/crates/tap-agent/src/tap/context/rav.rs index 5ec237ccc..c644bca4a 100644 --- a/crates/tap-agent/src/tap/context/rav.rs +++ b/crates/tap-agent/src/tap/context/rav.rs @@ -128,7 +128,7 @@ impl RAVStore for TapAgentContext { #[cfg(test)] mod test { - use indexer_common::escrow_accounts::EscrowAccounts; + use indexer_monitor::EscrowAccounts; use sqlx::PgPool; use tokio::sync::watch; diff --git a/crates/tap-agent/src/tap/context/receipt.rs b/crates/tap-agent/src/tap/context/receipt.rs index 5cbc3402b..83120e657 100644 --- a/crates/tap-agent/src/tap/context/receipt.rs +++ b/crates/tap-agent/src/tap/context/receipt.rs @@ -199,7 +199,7 @@ mod test { }; use alloy::{primitives::U256, signers::local::PrivateKeySigner}; use anyhow::Result; - use indexer_common::escrow_accounts::EscrowAccounts; + use indexer_monitor::EscrowAccounts; use lazy_static::lazy_static; use sqlx::PgPool; use std::collections::HashMap; diff --git a/crates/tap-agent/src/tap/mod.rs b/crates/tap-agent/src/tap/mod.rs index 535538ca6..839ee6036 100644 --- a/crates/tap-agent/src/tap/mod.rs +++ b/crates/tap-agent/src/tap/mod.rs @@ -3,7 +3,7 @@ use alloy::hex::ToHexExt; use alloy::primitives::Address; -use indexer_common::escrow_accounts::EscrowAccounts; +use indexer_monitor::EscrowAccounts; use tokio::sync::watch::Receiver; pub mod context; diff --git a/crates/tests/tap-utils/Cargo.toml b/crates/test-assets/Cargo.toml similarity index 72% rename from crates/tests/tap-utils/Cargo.toml rename to crates/test-assets/Cargo.toml index 440596d2c..20f242472 100644 --- a/crates/tests/tap-utils/Cargo.toml +++ b/crates/test-assets/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "test-tap-utils" +name = "test-assets" version = "0.1.0" edition = "2021" [dependencies] +indexer-allocation = { path = "../allocation" } alloy.workspace = true bip39 = "2.0.0" lazy_static.workspace = true tap_core.workspace = true thegraph-core.workspace = true -indexer-types = { path = "../../types" } diff --git a/crates/common/src/test_vectors.rs b/crates/test-assets/src/lib.rs similarity index 67% rename from crates/common/src/test_vectors.rs rename to crates/test-assets/src/lib.rs index 5f24f1f95..67d3f9e2e 100644 --- a/crates/common/src/test_vectors.rs +++ b/crates/test-assets/src/lib.rs @@ -3,12 +3,21 @@ use std::{collections::HashMap, str::FromStr}; -use alloy::primitives::U256; +use alloy::{ + dyn_abi::Eip712Domain, + primitives::U256, + signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, +}; use bip39::Mnemonic; use lazy_static::lazy_static; +use tap_core::{ + receipt::{Receipt, SignedReceipt}, + signed_message::EIP712SignedMessage, + tap_eip712_domain, +}; use thegraph_core::{Address, DeploymentId}; -use indexer_types::{Allocation, AllocationStatus, SubgraphDeployment}; +use indexer_allocation::{Allocation, AllocationStatus, SubgraphDeployment}; /// The allocation IDs below are generated using the mnemonic /// "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" @@ -179,4 +188,98 @@ lazy_static! { }, ), ]); + + pub static ref ESCROW_ACCOUNTS_BALANCES: HashMap = HashMap::from([ + (Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), U256::from(24)), // TAP_SENDER + (Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), U256::from(42)), + (Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), U256::from(2975)), + ]); + + + /// Maps signers back to their senders + pub static ref ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS: HashMap = HashMap::from([ + ( + Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER + Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + ), + ( + Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), + Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + ), + ( + Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap(), + Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), + ), + ]); + + + pub static ref ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS: HashMap> = HashMap::from([ + ( + Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER + vec![ + Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER + Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), + ], + ), + ( + Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), + vec![Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap()], + ), + ( + Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), + vec![], + ), + ]); + + + /// Fixture to generate a wallet and address. + /// Address: 0x9858EfFD232B4033E47d90003D41EC34EcaEda94 + pub static ref TAP_SENDER: (PrivateKeySigner, Address) = { + let wallet: PrivateKeySigner = MnemonicBuilder::::default() + .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") + .build() + .unwrap(); + let address = wallet.address(); + + (wallet, address) + }; + + /// Fixture to generate a wallet and address. + /// Address: 0x533661F0fb14d2E8B26223C86a610Dd7D2260892 + pub static ref TAP_SIGNER: (PrivateKeySigner, Address) = { + let wallet: PrivateKeySigner = MnemonicBuilder::::default() + .phrase("rude pipe parade travel organ vendor card festival magnet novel forget refuse keep draft tool") + .build() + .unwrap(); + let address = wallet.address(); + + (wallet, address) + }; + + pub static ref TAP_EIP712_DOMAIN: Eip712Domain = tap_eip712_domain( + 1, + Address::from([0x11u8; 20]) + ); +} + +/// Function to generate a signed receipt using the TAP_SIGNER wallet. +pub async fn create_signed_receipt( + allocation_id: Address, + nonce: u64, + timestamp_ns: u64, + value: u128, +) -> SignedReceipt { + let (wallet, _) = &*self::TAP_SIGNER; + + EIP712SignedMessage::new( + &self::TAP_EIP712_DOMAIN, + Receipt { + allocation_id, + nonce, + timestamp_ns, + value, + }, + wallet, + ) + .unwrap() } diff --git a/crates/tests/tap-utils/src/lib.rs b/crates/tests/tap-utils/src/lib.rs deleted file mode 100644 index 3169f6b24..000000000 --- a/crates/tests/tap-utils/src/lib.rs +++ /dev/null @@ -1,114 +0,0 @@ -// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs. -// SPDX-License-Identifier: Apache-2.0 - -use std::{collections::HashMap, str::FromStr}; - -use alloy::{ - dyn_abi::Eip712Domain, - primitives::U256, - signers::local::{coins_bip39::English, MnemonicBuilder, PrivateKeySigner}, -}; -use lazy_static::lazy_static; -use tap_core::{ - receipt::{Receipt, SignedReceipt}, - signed_message::EIP712SignedMessage, - tap_eip712_domain, -}; -use thegraph_core::Address; - -lazy_static! { - - pub static ref ESCROW_ACCOUNTS_BALANCES: HashMap = HashMap::from([ - (Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), U256::from(24)), // TAP_SENDER - (Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), U256::from(42)), - (Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), U256::from(2975)), - ]); - - - /// Maps signers back to their senders - pub static ref ESCROW_ACCOUNTS_SIGNERS_TO_SENDERS: HashMap = HashMap::from([ - ( - Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER - ), - ( - Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER - ), - ( - Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap(), - Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), - ), - ]); - - - pub static ref ESCROW_ACCOUNTS_SENDERS_TO_SIGNERS: HashMap> = HashMap::from([ - ( - Address::from_str("0x9858EfFD232B4033E47d90003D41EC34EcaEda94").unwrap(), // TAP_SENDER - vec![ - Address::from_str("0x533661F0fb14d2E8B26223C86a610Dd7D2260892").unwrap(), // TAP_SIGNER - Address::from_str("0x2740f6fA9188cF53ffB6729DDD21575721dE92ce").unwrap(), - ], - ), - ( - Address::from_str("0x22d491bde2303f2f43325b2108d26f1eaba1e32b").unwrap(), - vec![Address::from_str("0x245059163ff6ee14279aa7b35ea8f0fdb967df6e").unwrap()], - ), - ( - Address::from_str("0x192c3B6e0184Fa0Cc5B9D2bDDEb6B79Fb216a002").unwrap(), - vec![], - ), - ]); - - - /// Fixture to generate a wallet and address. - /// Address: 0x9858EfFD232B4033E47d90003D41EC34EcaEda94 - pub static ref TAP_SENDER: (PrivateKeySigner, Address) = { - let wallet: PrivateKeySigner = MnemonicBuilder::::default() - .phrase("abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about") - .build() - .unwrap(); - let address = wallet.address(); - - (wallet, address) - }; - - /// Fixture to generate a wallet and address. - /// Address: 0x533661F0fb14d2E8B26223C86a610Dd7D2260892 - pub static ref TAP_SIGNER: (PrivateKeySigner, Address) = { - let wallet: PrivateKeySigner = MnemonicBuilder::::default() - .phrase("rude pipe parade travel organ vendor card festival magnet novel forget refuse keep draft tool") - .build() - .unwrap(); - let address = wallet.address(); - - (wallet, address) - }; - - pub static ref TAP_EIP712_DOMAIN: Eip712Domain = tap_eip712_domain( - 1, - Address::from([0x11u8; 20]) - ); -} - -/// Function to generate a signed receipt using the TAP_SIGNER wallet. -pub async fn create_signed_receipt( - allocation_id: Address, - nonce: u64, - timestamp_ns: u64, - value: u128, -) -> SignedReceipt { - let (wallet, _) = &*self::TAP_SIGNER; - - EIP712SignedMessage::new( - &self::TAP_EIP712_DOMAIN, - Receipt { - allocation_id, - nonce, - timestamp_ns, - value, - }, - wallet, - ) - .unwrap() -} diff --git a/crates/watcher/Cargo.toml b/crates/watcher/Cargo.toml new file mode 100644 index 000000000..0a5daed61 --- /dev/null +++ b/crates/watcher/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "indexer-watcher" +version = "0.1.0" +edition = "2021" + +[dependencies] +tokio = { workspace = true, features = ["macros", "rt", "time", "sync"] } +tracing.workspace = true +anyhow.workspace = true diff --git a/crates/common/src/watcher.rs b/crates/watcher/src/lib.rs similarity index 100% rename from crates/common/src/watcher.rs rename to crates/watcher/src/lib.rs diff --git a/release-please-config.json b/release-please-config.json index 684352a64..b430b0c17 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -4,7 +4,6 @@ "release-type": "rust", "plugins": ["cargo-workspace"], "packages": { - "crates/common": {}, "crates/config": {}, "crates/service": {}, "crates/tap-agent": {}