Skip to content

Commit 05cac7c

Browse files
committed
feat: rav trigger config in GRT instead of wei
Signed-off-by: Alexis Asseman <[email protected]>
1 parent 8e6460f commit 05cac7c

File tree

4 files changed

+76
-6
lines changed

4 files changed

+76
-6
lines changed

Cargo.lock

+18-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tap-agent/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ alloy-primitives = "0.4.2"
1313
alloy-sol-types = "0.4.2"
1414
anyhow = "1.0.72"
1515
async-trait = "0.1.72"
16+
bigdecimal = { version = "0.4.2", features = ["serde"] }
1617
clap = { version = "4.4.3", features = ["derive", "env"] }
1718
confy = "0.5.1"
1819
dotenvy = "0.15.7"

tap-agent/src/config.rs

+56-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright 2023-, GraphOps and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::path::PathBuf;
4+
use std::{path::PathBuf, str::FromStr};
55

66
use alloy_primitives::Address;
7+
use bigdecimal::{BigDecimal, ToPrimitive};
78
use clap::{command, Args, Parser, ValueEnum};
89
use dotenvy::dotenv;
910
use serde::{Deserialize, Serialize};
@@ -218,8 +219,9 @@ pub struct Tap {
218219
long,
219220
value_name = "rav-request-trigger-value",
220221
env = "RAV_REQUEST_TRIGGER_VALUE",
221-
help = "Value of unaggregated fees that triggers a RAV request (in GRT wei).",
222-
default_value_t = 10_000_000_000_000_000_000 // 10 GRT
222+
help = "Value of unaggregated fees that triggers a RAV request (in GRT).",
223+
default_value = "10",
224+
value_parser(parse_grt_value_to_nonzero_u64)
223225
)]
224226
pub rav_request_trigger_value: u64,
225227
#[clap(
@@ -266,6 +268,26 @@ fn init_tracing(format: String) -> Result<(), SetGlobalDefaultError> {
266268
}
267269
}
268270

271+
fn parse_grt_value_to_nonzero_u64(s: &str) -> Result<u64, std::io::Error> {
272+
let v = BigDecimal::from_str(s)
273+
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
274+
if v <= 0.into() {
275+
return Err(std::io::Error::new(
276+
std::io::ErrorKind::Other,
277+
"GRT value must be greater than 0".to_string(),
278+
));
279+
}
280+
// Convert to wei
281+
let v = v * BigDecimal::from(10u64.pow(18));
282+
// Convert to u64
283+
v.to_u64().ok_or_else(|| {
284+
std::io::Error::new(
285+
std::io::ErrorKind::Other,
286+
"GRT value cannot be represented as a u64 GRT wei value".to_string(),
287+
)
288+
})
289+
}
290+
269291
impl Cli {
270292
/// Parse config arguments If environmental variable for config is set to a valid
271293
/// config file path, then parse from config Otherwise parse from command line
@@ -319,3 +341,34 @@ pub enum LogLevel {
319341
Error,
320342
Fatal,
321343
}
344+
345+
#[cfg(test)]
346+
mod tests {
347+
use super::*;
348+
349+
#[test]
350+
fn test_parse_grt_value_to_u64() {
351+
assert_eq!(
352+
parse_grt_value_to_nonzero_u64("1").unwrap(),
353+
1_000_000_000_000_000_000
354+
);
355+
assert_eq!(
356+
parse_grt_value_to_nonzero_u64("1.1").unwrap(),
357+
1_100_000_000_000_000_000
358+
);
359+
assert_eq!(
360+
parse_grt_value_to_nonzero_u64("1.000000000000000001").unwrap(),
361+
1_000_000_000_000_000_001
362+
);
363+
assert_eq!(
364+
parse_grt_value_to_nonzero_u64("0.000000000000000001").unwrap(),
365+
1
366+
);
367+
assert!(parse_grt_value_to_nonzero_u64("0").is_err());
368+
assert!(parse_grt_value_to_nonzero_u64("-1").is_err());
369+
assert_eq!(
370+
parse_grt_value_to_nonzero_u64("1.0000000000000000001").unwrap(),
371+
1_000_000_000_000_000_000
372+
);
373+
}
374+
}

tap-agent/src/tap/sender_allocation_relationships_manager.rs

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ impl Drop for SenderAllocationRelationshipsManager {
302302

303303
#[cfg(test)]
304304
mod tests {
305+
305306
use indexer_common::{
306307
prelude::{AllocationStatus, SubgraphDeployment},
307308
subgraph_client::DeploymentDetails,

0 commit comments

Comments
 (0)