fix: fee-on-transfer token deposit accounting#146
Open
Tranquil-Flow wants to merge 1 commit into
Open
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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(): measurebalanceOfbefore and aftersafeTransferFrom, credit the deltaMockFeeOnTransferERC20: test mock with configurable fee in basis pointstest_DepositFeeOnTransferTokenCreditsNetAmount: regression test for fee tokensvm.mockCallwith real token transfers in existing deposit/withdraw testsTest plan
forge testpasses (141 tests)