Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions crates/dips/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ use store::AgreementStore;
use thiserror::Error;
use uuid::Uuid;

/// The Arbitrum One (mainnet) chain ID (eip155).
const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161

/// DIPs EIP-712 domain salt
const EIP712_DOMAIN_SALT: B256 =
b256!("b4632c657c26dce5d4d7da1d65bda185b14ff8f905ddbb03ea0382ed06c5ef28");
Expand All @@ -38,29 +35,29 @@ const EIP712_DOMAIN_SALT: B256 =
pub const PROTOCOL_VERSION: u64 = 1; // MVP

/// Create an EIP-712 domain given a chain ID and dispute manager address.
pub fn dips_agreement_eip712_domain() -> Eip712Domain {
pub fn dips_agreement_eip712_domain(chain_id: ChainId) -> Eip712Domain {
eip712_domain! {
name: "Graph Protocol Indexing Agreement",
version: "0",
chain_id: CHAIN_ID_ARBITRUM_ONE,
chain_id: chain_id,
salt: EIP712_DOMAIN_SALT,
}
}

pub fn dips_cancellation_eip712_domain() -> Eip712Domain {
pub fn dips_cancellation_eip712_domain(chain_id: ChainId) -> Eip712Domain {
eip712_domain! {
name: "Graph Protocol Indexing Agreement Cancellation",
version: "0",
chain_id: CHAIN_ID_ARBITRUM_ONE,
chain_id: chain_id,
salt: EIP712_DOMAIN_SALT,
}
}

pub fn dips_collection_eip712_domain() -> Eip712Domain {
pub fn dips_collection_eip712_domain(chain_id: ChainId) -> Eip712Domain {
eip712_domain! {
name: "Graph Protocol Indexing Agreement Collection",
version: "0",
chain_id: CHAIN_ID_ARBITRUM_ONE,
chain_id: chain_id,
salt: EIP712_DOMAIN_SALT,
}
}
Expand Down Expand Up @@ -393,7 +390,7 @@ mod test {
use indexer_monitor::EscrowAccounts;
use rand::{distr::Alphanumeric, Rng};
use thegraph_core::alloy::{
primitives::{Address, FixedBytes, U256},
primitives::{Address, ChainId, FixedBytes, U256},
signers::local::PrivateKeySigner,
sol_types::{Eip712Domain, SolValue},
};
Expand All @@ -406,6 +403,9 @@ mod test {
SubgraphIndexingVoucherMetadata,
};

/// The Arbitrum One (mainnet) chain ID (eip155).
const CHAIN_ID_ARBITRUM_ONE: ChainId = 0xa4b1; // 42161

#[tokio::test]
async fn test_validate_and_create_agreement() -> anyhow::Result<()> {
let deployment_id = "Qmbg1qF4YgHjiVfsVt6a13ddrVcRtWyJQfD4LA3CwHM29f".to_string();
Expand Down Expand Up @@ -435,7 +435,7 @@ mod test {
deadline: 10000000,
metadata: metadata.abi_encode().into(),
};
let domain = dips_agreement_eip712_domain();
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);

let voucher = voucher.sign(&domain, payer)?;
let abi_voucher = voucher.abi_encode();
Expand Down Expand Up @@ -491,7 +491,7 @@ mod test {
metadata: metadata.abi_encode().into(),
};

let domain = dips_agreement_eip712_domain();
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
let signed = voucher.sign(&domain, payer).unwrap();
assert_eq!(
signed
Expand Down Expand Up @@ -545,7 +545,7 @@ mod test {
deadline: 10000000,
metadata: metadata.abi_encode().into(),
};
let domain = dips_agreement_eip712_domain();
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);

let mut signed = voucher.sign(&domain, payer).unwrap();
signed.voucher.service = Address::repeat_byte(9);
Expand Down Expand Up @@ -597,7 +597,7 @@ mod test {
let voucher = CancellationRequest {
agreement_id: Uuid::now_v7().as_bytes().into(),
};
let domain = dips_cancellation_eip712_domain();
let domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE);

let signed = voucher.sign(&domain, signer).unwrap();

Expand Down Expand Up @@ -627,7 +627,7 @@ mod test {
}
}
pub fn domain(&self) -> Eip712Domain {
dips_agreement_eip712_domain()
dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE)
}

pub fn test_voucher_with_signer(
Expand All @@ -637,7 +637,7 @@ mod test {
) -> SignedIndexingAgreementVoucher {
let agreement_id = Uuid::now_v7();

let domain = dips_agreement_eip712_domain();
let domain = dips_agreement_eip712_domain(CHAIN_ID_ARBITRUM_ONE);

let voucher = IndexingAgreementVoucher {
agreement_id: agreement_id.as_bytes().into(),
Expand Down Expand Up @@ -693,7 +693,7 @@ mod test {
.await?;

// Create and sign cancellation request
let cancel_domain = dips_cancellation_eip712_domain();
let cancel_domain = dips_cancellation_eip712_domain(CHAIN_ID_ARBITRUM_ONE);
let cancel_request = CancellationRequest {
agreement_id: agreement_id.as_bytes().into(),
};
Expand Down
17 changes: 11 additions & 6 deletions crates/dips/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use std::sync::Arc;
use async_trait::async_trait;
#[cfg(test)]
use indexer_monitor::EscrowAccounts;
use thegraph_core::alloy::{primitives::Address, sol_types::Eip712Domain};
use thegraph_core::alloy::primitives::{Address, ChainId};
use tonic::{Request, Response, Status};

use crate::{
dips_agreement_eip712_domain, dips_cancellation_eip712_domain,
ipfs::IpfsFetcher,
price::PriceCalculator,
proto::indexer::graphprotocol::indexer::dips::{
Expand Down Expand Up @@ -63,7 +64,7 @@ pub struct DipsServer {
pub ctx: Arc<DipsServerContext>,
pub expected_payee: Address,
pub allowed_payers: Vec<Address>,
pub domain: Eip712Domain,
pub chain_id: ChainId,
}

#[async_trait]
Expand All @@ -88,7 +89,7 @@ impl IndexerDipsService for DipsServer {
// - The subgraph deployment is available on IPFS
validate_and_create_agreement(
self.ctx.clone(),
&self.domain,
&dips_agreement_eip712_domain(self.chain_id),
&self.expected_payee,
&self.allowed_payers,
signed_voucher,
Expand All @@ -114,9 +115,13 @@ impl IndexerDipsService for DipsServer {
return Err(Status::invalid_argument("invalid version"));
}

validate_and_cancel_agreement(self.ctx.store.clone(), &self.domain, signed_cancellation)
.await
.map_err(Into::<tonic::Status>::into)?;
validate_and_cancel_agreement(
self.ctx.store.clone(),
&dips_cancellation_eip712_domain(self.chain_id),
signed_cancellation,
)
.await
.map_err(Into::<tonic::Status>::into)?;

Ok(tonic::Response::new(CancelAgreementResponse {}))
}
Expand Down
3 changes: 2 additions & 1 deletion crates/service/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub async fn run() -> anyhow::Result<()> {
config.blockchain.chain_id as u64,
config.blockchain.receipts_verifier_address,
);
let chain_id = config.blockchain.chain_id as u64;

let host_and_port = config.service.host_and_port;
let indexer_address = config.indexer.indexer_address;
Expand Down Expand Up @@ -159,7 +160,7 @@ pub async fn run() -> anyhow::Result<()> {
ctx: Arc::new(ctx),
expected_payee: indexer_address,
allowed_payers: allowed_payers.clone(),
domain: domain_separator,
chain_id,
};

info!("starting dips grpc server on {}", addr);
Expand Down
Loading