Support taxed tokens transfers in the ERC4626 contract
See original GitHub issueScope ERC4626
Motivation Make the standard more inclusive and usable across the hugely-diversified DeFi ecosystem by supporting taxed tokens transfers.
Description
Implement a token transfer library that takes into account tokens with transfer taxes or non-standard behaviours (example: a user calls deposit(...amount = 10)
but the actual deposit is 9 TKN because of a 10% transfer tax.
Example
function transferTokens(
IERC20 token,
address from,
address to,
uint256 amount
) internal returns (uint256 originalBalance, uint256 received) {
if (token.balanceOf(from) < amount) revert TransferHelper__Insufficient_Token_Balance(from, address(token));
if (token.allowance(from, address(this)) < amount)
revert TransferHelper__Insufficient_Token_Allowance(from, address(this), address(token));
// computes transferred balance for tokens with tax on transfers
originalBalance = token.balanceOf(to);
token.safeTransferFrom(from, to, amount);
received = token.balanceOf(to) - originalBalance;
}
Now instead of SafeERC20.transferFrom(...)
one could use the function above using the received
value instead of the user-inputted amount
.
Source: TransferHelper.sol
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Taxable Contract - Add an Optional Tx Tax to Your Token
Created a contract that can be imported into your ERC20 token contract that handles a tax. The tax amount can be updated within...
Read more >How to write an ERC-4626 token contract for yield-bearing ...
Before the function transfers or accepts the token into the vault, perform a check to ensure the user is depositing an actual token...
Read more >Token Issuers and Purchasers, Beware: The IRS May Tax ...
Generally, issuance of tokens should not result in the transfer of intangible property rights because token purchasers generally do not acquire ...
Read more >EIP-4626: Tokenized Vaults - Ethereum Improvement Proposals
Tokenized Vaults with a single underlying EIP-20 token. ... the shares are transferred to the Vault contract before the withdraw execution, ...
Read more >Expert Q&A on Cryptocurrency Compensation - Cooley LLP
of token-based awards, tax and securities laws considerations, and administrative ... RTUs represent a contractual obligation to transfer.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m okay with making
_deposit
and_withdraw
internal. Wouldn’t add special behavior for taxed tokens.ok perfect, if that is not going to largely impact the gas costs I think it could be useful to implement them for flexibility