@@ -6,7 +6,9 @@ use std::{str::FromStr, sync::Arc};
66use server:: DipsServerContext ;
77use thegraph_core:: alloy:: {
88 core:: primitives:: Address ,
9- primitives:: { b256, ChainId , PrimitiveSignature as Signature , Uint , B256 } ,
9+ primitives:: {
10+ b256, ruint:: aliases:: U256 , ChainId , PrimitiveSignature as Signature , Uint , B256 ,
11+ } ,
1012 signers:: SignerSync ,
1113 sol,
1214 sol_types:: { eip712_domain, Eip712Domain , SolStruct , SolValue } ,
@@ -18,6 +20,8 @@ pub mod ipfs;
1820pub mod price;
1921#[ cfg( feature = "rpc" ) ]
2022pub mod proto;
23+ #[ cfg( test) ]
24+ mod registry;
2125#[ cfg( feature = "rpc" ) ]
2226pub mod server;
2327pub mod signers;
@@ -145,8 +149,12 @@ pub enum DipsError {
145149 InvalidSubgraphManifest ( String ) ,
146150 #[ error( "chainId {0} is not supported" ) ]
147151 UnsupportedChainId ( String ) ,
148- #[ error( "price per block is below configured price for chain {0}, minimum: {1}, offered: {2}" ) ]
149- PricePerBlockTooLow ( String , u64 , String ) ,
152+ #[ error( "price per epoch is below configured price for chain {0}, minimum: {1}, offered: {2}" ) ]
153+ PricePerEpochTooLow ( String , U256 , String ) ,
154+ #[ error(
155+ "price per entity is below configured price for chain {0}, minimum: {1}, offered: {2}"
156+ ) ]
157+ PricePerEntityTooLow ( String , U256 , String ) ,
150158 // cancellation
151159 #[ error( "cancelled_by is expected to match the signer" ) ]
152160 UnexpectedSigner ,
@@ -304,6 +312,8 @@ pub async fn validate_and_create_agreement(
304312 ipfs_fetcher,
305313 price_calculator,
306314 signer_validator,
315+ registry,
316+ additional_networks,
307317 } = ctx. as_ref ( ) ;
308318 let decoded_voucher = SignedIndexingAgreementVoucher :: abi_decode ( voucher. as_ref ( ) , true )
309319 . map_err ( |e| DipsError :: AbiDecoding ( e. to_string ( ) ) ) ?;
@@ -316,12 +326,23 @@ pub async fn validate_and_create_agreement(
316326 decoded_voucher. validate ( signer_validator, domain, expected_payee, allowed_payers) ?;
317327
318328 let manifest = ipfs_fetcher. fetch ( & metadata. subgraphDeploymentId ) . await ?;
329+
330+ let network = match registry. get_network_by_id ( & metadata. chainId ) {
331+ Some ( network) => network. id . clone ( ) ,
332+ None => match additional_networks. get ( & metadata. chainId ) {
333+ Some ( network) => network. clone ( ) ,
334+ None => return Err ( DipsError :: UnsupportedChainId ( metadata. chainId ) ) ,
335+ } ,
336+ } ;
337+
319338 match manifest. network ( ) {
320- Some ( network_name) => {
321- tracing:: debug!( "Subgraph manifest network: {}" , network_name) ;
322- // TODO: Check if the network is supported
323- // This will require a mapping of network names to chain IDs
324- // by querying the supported networks from the EBO subgraph
339+ Some ( manifest_network_name) => {
340+ tracing:: debug!( "Subgraph manifest network: {}" , manifest_network_name) ;
341+ if manifest_network_name != network {
342+ return Err ( DipsError :: InvalidSubgraphManifest (
343+ metadata. subgraphDeploymentId ,
344+ ) ) ;
345+ }
325346 }
326347 None => {
327348 return Err ( DipsError :: InvalidSubgraphManifest (
@@ -330,19 +351,28 @@ pub async fn validate_and_create_agreement(
330351 }
331352 }
332353
333- let offered_price = metadata. pricePerEntity ;
354+ let offered_epoch_price = metadata. basePricePerEpoch ;
334355 match price_calculator. get_minimum_price ( & metadata. chainId ) {
335- Some ( price) if offered_price . lt ( & Uint :: from ( price) ) => {
336- return Err ( DipsError :: PricePerBlockTooLow (
337- metadata . chainId ,
356+ Some ( price) if offered_epoch_price . lt ( & Uint :: from ( price) ) => {
357+ return Err ( DipsError :: PricePerEpochTooLow (
358+ network ,
338359 price,
339- offered_price . to_string ( ) ,
360+ offered_epoch_price . to_string ( ) ,
340361 ) )
341362 }
342363 Some ( _) => { }
343364 None => return Err ( DipsError :: UnsupportedChainId ( metadata. chainId ) ) ,
344365 }
345366
367+ let offered_entity_price = metadata. pricePerEntity ;
368+ if offered_entity_price < price_calculator. entity_price ( ) {
369+ return Err ( DipsError :: PricePerEntityTooLow (
370+ network,
371+ price_calculator. entity_price ( ) ,
372+ offered_entity_price. to_string ( ) ,
373+ ) ) ;
374+ }
375+
346376 store
347377 . create_agreement ( decoded_voucher. clone ( ) , metadata)
348378 . await ?;
@@ -754,7 +784,17 @@ mod test {
754784 subgraphDeploymentId : voucher_ctx. deployment_id . clone ( ) ,
755785 } ;
756786
757- let low_price_voucher = voucher_ctx. test_voucher ( metadata) ;
787+ let low_entity_price_voucher = voucher_ctx. test_voucher ( metadata) ;
788+
789+ let metadata = SubgraphIndexingVoucherMetadata {
790+ basePricePerEpoch : U256 :: from ( 10_u64 ) ,
791+ pricePerEntity : U256 :: from ( 10000_u64 ) ,
792+ protocolNetwork : "eip155:42161" . to_string ( ) ,
793+ chainId : "mainnet" . to_string ( ) ,
794+ subgraphDeploymentId : voucher_ctx. deployment_id . clone ( ) ,
795+ } ;
796+
797+ let low_epoch_price_voucher = voucher_ctx. test_voucher ( metadata) ;
758798
759799 let metadata = SubgraphIndexingVoucherMetadata {
760800 basePricePerEpoch : U256 :: from ( 10000_u64 ) ,
@@ -775,9 +815,14 @@ mod test {
775815 Err ( DipsError :: InvalidSubgraphManifest (
776816 voucher_ctx. deployment_id. clone( ) ,
777817 ) ) ,
778- Err ( DipsError :: PricePerBlockTooLow (
818+ Err ( DipsError :: PricePerEntityTooLow (
819+ "mainnet" . to_string( ) ,
820+ U256 :: from( 100 ) ,
821+ "10" . to_string( ) ,
822+ ) ) ,
823+ Err ( DipsError :: PricePerEpochTooLow (
779824 "mainnet" . to_string( ) ,
780- 100 ,
825+ U256 :: from ( 200 ) ,
781826 "10" . to_string( ) ,
782827 ) ) ,
783828 Err ( DipsError :: SignerNotAuthorised ( signer. address( ) ) ) ,
@@ -790,7 +835,8 @@ mod test {
790835 ] ;
791836 let cases = vec ! [
792837 no_network_voucher,
793- low_price_voucher,
838+ low_entity_price_voucher,
839+ low_epoch_price_voucher,
794840 valid_voucher_invalid_signer,
795841 valid_voucher,
796842 ] ;
0 commit comments