Skip to content

fix: fee-on-transfer token deposit accounting#146

Open
Tranquil-Flow wants to merge 1 commit into
devfrom
fix/fee-on-transfer-deposits
Open

fix: fee-on-transfer token deposit accounting#146
Tranquil-Flow wants to merge 1 commit into
devfrom
fix/fee-on-transfer-deposits

Conversation

@Tranquil-Flow
Copy link
Copy Markdown

Summary

Closes #122

ERC20 fee-on-transfer tokens break deposit accounting because _deposit() assumed a 1:1 transfer ratio. Tokens that deduct a fee on every transfer (deflationary tokens) deliver less than the sent amount.

This fix uses a balance-before / balance-after pattern to credit only the net amount actually received by the contract.

Changes

  • _deposit(): measure balanceOf before and after safeTransferFrom, credit the delta
  • MockFeeOnTransferERC20: test mock with configurable fee in basis points
  • test_DepositFeeOnTransferTokenCreditsNetAmount: regression test for fee tokens
  • Replaced vm.mockCall with real token transfers in existing deposit/withdraw tests

Test plan

  • forge test passes (141 tests)
  • Fee-on-transfer test verifies balance reflects net received amount (99% of nominal with 1% fee)
  • Existing deposit and withdraw tests still pass with real transfers

Use balance-before/balance-after accounting so only the net amount
actually received is credited to the depositor. Previous implementation
assumed a 1:1 transfer, breaking with fee-on-transfer tokens.

- Add _deposit() net-crediting logic
- Add MockFeeOnTransferERC20 test mock
- Add test_DepositFeeOnTransferTokenCreditsNetAmount test
- Closes: #122
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.

Fee-on-transfer / rebasing ERC20s break deposit accounting and can cause cross-circle fund loss / insolvency

1 participant