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
11 changes: 7 additions & 4 deletions crates/bin/escrow_manager/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u128> {
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<()> {
Expand Down
13 changes: 11 additions & 2 deletions crates/bin/escrow_manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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));
}
}

Expand Down Expand Up @@ -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).
Expand Down
Loading