Skip to content

Commit a8b2971

Browse files
committed
fix: change price types
1 parent 8b3d142 commit a8b2971

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

crates/config/maximal-config-example.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,11 @@ host = "0.0.0.0"
160160
port = "7601"
161161
allowed_payers = ["0x3333333333333333333333333333333333333333"]
162162

163-
price_per_entity = 1000
163+
price_per_entity = "1000"
164164

165165
[dips.price_per_epoch]
166-
mainnet = 100
167-
hardhat = 100
166+
mainnet = "100"
167+
hardhat = "100"
168168

169169
[dips.additional_networks]
170170
"eip155:1337" = "hardhat"

crates/config/src/config.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ use regex::Regex;
2020
use serde::Deserialize;
2121
use serde_repr::Deserialize_repr;
2222
use serde_with::{serde_as, DurationSecondsWithFrac};
23-
use thegraph_core::{alloy::primitives::Address, DeploymentId};
23+
use thegraph_core::{
24+
alloy::primitives::{Address, U256},
25+
DeploymentId,
26+
};
2427
use url::Url;
2528

2629
use crate::NonZeroGRT;
@@ -397,8 +400,8 @@ pub struct DipsConfig {
397400
pub port: String,
398401
pub allowed_payers: Vec<Address>,
399402

400-
pub price_per_entity: u64,
401-
pub price_per_epoch: BTreeMap<String, u64>,
403+
pub price_per_entity: U256,
404+
pub price_per_epoch: BTreeMap<String, U256>,
402405
pub additional_networks: HashMap<String, String>,
403406
}
404407

@@ -408,7 +411,7 @@ impl Default for DipsConfig {
408411
host: "0.0.0.0".to_string(),
409412
port: "7601".to_string(),
410413
allowed_payers: vec![],
411-
price_per_entity: 100,
414+
price_per_entity: U256::from(100),
412415
price_per_epoch: BTreeMap::new(),
413416
additional_networks: HashMap::new(),
414417
}
@@ -453,7 +456,7 @@ mod tests {
453456

454457
use figment::value::Uncased;
455458
use sealed_test::prelude::*;
456-
use thegraph_core::alloy::primitives::{address, Address, FixedBytes};
459+
use thegraph_core::alloy::primitives::{address, Address, FixedBytes, U256};
457460
use tracing_test::traced_test;
458461

459462
use super::{DatabaseConfig, SHARED_PREFIX};
@@ -482,10 +485,10 @@ mod tests {
482485
allowed_payers: vec![Address(
483486
FixedBytes::<20>::from_str("0x3333333333333333333333333333333333333333").unwrap(),
484487
)],
485-
price_per_entity: 1000,
488+
price_per_entity: U256::from(1000),
486489
price_per_epoch: BTreeMap::from_iter(vec![
487-
("mainnet".to_string(), 100),
488-
("hardhat".to_string(), 100),
490+
("mainnet".to_string(), U256::from(100)),
491+
("hardhat".to_string(), U256::from(100)),
489492
]),
490493
additional_networks: HashMap::from([(
491494
"eip155:1337".to_string(),

crates/dips/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ pub enum DipsError {
149149
#[error("chainId {0} is not supported")]
150150
UnsupportedChainId(String),
151151
#[error("price per epoch is below configured price for chain {0}, minimum: {1}, offered: {2}")]
152-
PricePerEpochTooLow(String, u64, String),
152+
PricePerEpochTooLow(String, U256, String),
153153
#[error(
154154
"price per entity is below configured price for chain {0}, minimum: {1}, offered: {2}"
155155
)]
156-
PricePerEntityTooLow(String, u64, String),
156+
PricePerEntityTooLow(String, U256, String),
157157
// cancellation
158158
#[error("cancelled_by is expected to match the signer")]
159159
UnexpectedSigner,
@@ -816,12 +816,12 @@ mod test {
816816
)),
817817
Err(DipsError::PricePerEntityTooLow(
818818
"mainnet".to_string(),
819-
100,
819+
U256::from(100),
820820
"10".to_string(),
821821
)),
822822
Err(DipsError::PricePerEpochTooLow(
823823
"mainnet".to_string(),
824-
200,
824+
U256::from(200),
825825
"10".to_string(),
826826
)),
827827
Err(DipsError::SignerNotAuthorised(signer.address())),

crates/dips/src/price.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
use std::collections::BTreeMap;
55

6+
use thegraph_core::alloy::primitives::U256;
7+
68
#[derive(Debug, Default)]
79
pub struct PriceCalculator {
8-
base_price_per_epoch: BTreeMap<String, u64>,
9-
price_per_entity: u64,
10+
base_price_per_epoch: BTreeMap<String, U256>,
11+
price_per_entity: U256,
1012
}
1113

1214
impl PriceCalculator {
13-
pub fn new(base_price_per_epoch: BTreeMap<String, u64>, price_per_entity: u64) -> Self {
15+
pub fn new(base_price_per_epoch: BTreeMap<String, U256>, price_per_entity: U256) -> Self {
1416
Self {
1517
base_price_per_epoch,
1618
price_per_entity,
@@ -20,19 +22,22 @@ impl PriceCalculator {
2022
#[cfg(test)]
2123
pub fn for_testing() -> Self {
2224
Self {
23-
base_price_per_epoch: BTreeMap::from_iter(vec![("mainnet".to_string(), 200)]),
24-
price_per_entity: 100,
25+
base_price_per_epoch: BTreeMap::from_iter(vec![(
26+
"mainnet".to_string(),
27+
U256::from(200),
28+
)]),
29+
price_per_entity: U256::from(100),
2530
}
2631
}
2732

2833
pub fn is_supported(&self, chain_id: &str) -> bool {
2934
self.get_minimum_price(chain_id).is_some()
3035
}
31-
pub fn get_minimum_price(&self, chain_id: &str) -> Option<u64> {
36+
pub fn get_minimum_price(&self, chain_id: &str) -> Option<U256> {
3237
self.base_price_per_epoch.get(chain_id).copied()
3338
}
3439

35-
pub fn entity_price(&self) -> u64 {
40+
pub fn entity_price(&self) -> U256 {
3641
self.price_per_entity
3742
}
3843
}

0 commit comments

Comments
 (0)