Skip to content

fix: preserve fractional token value - #234

Open
Kewe63 wants to merge 1 commit into
t1protocol:canaryfrom
Kewe63:fix/233-preserve-fractional-balances
Open

Kewe63 wants to merge 1 commit into
t1protocol:canaryfrom
Kewe63:fix/233-preserve-fractional-balances

Conversation

@Kewe63

@Kewe63 Kewe63 commented Sep 18, 2026

Copy link
Copy Markdown

Description

  • Preserve ERC-20 base units until after USD-price multiplication instead of truncating balances to whole tokens first.
  • Keep the existing whole-dollar bigint result and pause/unpause threshold semantics unchanged.
  • Add focused regression coverage for a 0.9 WETH balance and a whole-token control.
  • Use a separate test file so this change combines cleanly with the CoinGecko parsing work in fix: parse CoinGecko price response #232.

Motivation and Context

The previous calculation divided rawBal by the token scale before multiplying by price. Bigint division therefore discarded every fractional token balance. For example, 0.9 WETH at $4,200 was valued as $0 rather than $3,780, allowing the configured pause threshold to be missed.

Fixes #233.

How Has This Been Tested?

  • Pre-fix regression run: 1 passed, 1 failed; the 0.9 WETH case observed zero pause calls.
  • bun test test/TresholdMonitor.balance.test.ts — 2 passed, 0 failed.
  • bun test — 2 passed, 0 failed.
  • Combined tree with open PR fix: parse CoinGecko price response #232: 5 passed, 0 failed across both test files; git merge-tree reported no conflict.
  • git diff --cached --check — passed.
  • Independent review — approved with no blocking findings.
  • bun x tsc -p tsconfig.json --noEmit remains blocked on the unchanged base by the missing generated ../../contracts/artifacts/src/T1ERC7683.sol/T1ERC7683.json artifact.

Types of changes (remove all unchecked types)

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I assessed the documentation impact; no documentation update is required.
  • I assessed the deployment-script impact; no deployment-script update is required.
  • I added focused regression coverage for the corrected behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intent pauser discards fractional token balances before USD valuation

1 participant