diff --git a/crates/bin/escrow_manager/src/contracts.rs b/crates/bin/escrow_manager/src/contracts.rs index d05e363..f5f0aef 100644 --- a/crates/bin/escrow_manager/src/contracts.rs +++ b/crates/bin/escrow_manager/src/contracts.rs @@ -84,14 +84,17 @@ impl Contracts { *self.graph_tally_collector.address() } + /// Saturates at `u128::MAX`. An unlimited approval (`U256::MAX`) doesn't fit in `u128`, and the + /// only thing done with this value is comparing it against the configured allowance, which any + /// saturated value clears. Returning an error here instead bricked the whole process on startup. pub async fn allowance(&self) -> anyhow::Result { - self.token + let allowance = self + .token .allowance(self.payer(), *self.payments_escrow.address()) .call() .await - .context("get allowance")? - .try_into() - .context("result out of bounds") + .context("get allowance")?; + Ok(u128::try_from(allowance).unwrap_or(u128::MAX)) } pub async fn approve(&self, amount: u128) -> anyhow::Result<()> { diff --git a/crates/bin/escrow_manager/src/main.rs b/crates/bin/escrow_manager/src/main.rs index 8e2ca1a..1bcd1c8 100644 --- a/crates/bin/escrow_manager/src/main.rs +++ b/crates/bin/escrow_manager/src/main.rs @@ -134,7 +134,7 @@ async fn main() -> anyhow::Result<()> { let mut allowance = contracts.allowance().await?; let expected_allowance = config.grt_allowance as u128 * GRT; - tracing::info!(allowance = allowance as f64 * 1e-18); + tracing::info!(allowance = %format_allowance(allowance)); if allowance < expected_allowance { if config.dry_run { tracing::info!( @@ -147,7 +147,7 @@ async fn main() -> anyhow::Result<()> { .await .context("approve")?; allowance = contracts.allowance().await?; - tracing::info!(allowance = allowance as f64 * 1e-18); + tracing::info!(allowance = %format_allowance(allowance)); } } @@ -493,6 +493,15 @@ async fn main() -> anyhow::Result<()> { } } +/// `u128::MAX` is what `Contracts::allowance` saturates an unlimited on-chain approval to. Printed +/// as GRT it reads as 3.4e20, which looks like a real (absurd) number rather than "no limit set". +fn format_allowance(allowance: u128) -> String { + match allowance { + u128::MAX => "unlimited".to_string(), + allowance => format!("{}", allowance as f64 * 1e-18), + } +} + /// Target escrow balance for a receiver with the given debt. The balance steps up while debt /// reaches `fill_factor` of the current step, so the target settles at roughly `debt / fill_factor` /// once the steps are fine-grained (above `MAX_ADJUSTMENT`, where they stop doubling).