question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support taxed tokens transfers in the ERC4626 contract

See original GitHub issue

Scope 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:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
frangiocommented, Jun 23, 2022

I’m okay with making _deposit and _withdraw internal. Wouldn’t add special behavior for taxed tokens.

0reactions
OxMarcocommented, Jun 24, 2022

ok perfect, if that is not going to largely impact the gas costs I think it could be useful to implement them for flexibility

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found