Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[N04] Replaces copying inherited code of transfer and transferFrom in LPToken #193

Merged
merged 1 commit into from Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 7 additions & 11 deletions contracts/LPToken.sol
Expand Up @@ -38,16 +38,12 @@ contract LPToken is ERC20Burnable, Ownable {
_mint(recipient, amount);
}

function transfer(address recipient, uint256 amount) public override returns (bool) {
swap.updateUserWithdrawFee(recipient, amount);
_transfer(_msgSender(), recipient, amount);
return true;
}

function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
swap.updateUserWithdrawFee(recipient, amount);
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), allowance(sender, _msgSender()).sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
/**
* @dev Overrides ERC20._beforeTokenTransfer() which get called on every transfers including
* minting and burning. This ensures that swap.updateUserWithdrawFees are called everytime.
*/
function _beforeTokenTransfer(address from, address to, uint256 amount) internal override(ERC20) {
super._beforeTokenTransfer(from, to, amount);
swap.updateUserWithdrawFee(to, amount);
}
}
9 changes: 6 additions & 3 deletions contracts/SwapUtils.sol
Expand Up @@ -691,9 +691,6 @@ library SwapUtils {

require(toMint >= minToMint, "Couldn't mint min requested LP tokens");

// Update msg.sender's withdraw fee
_updateUserWithdrawFee(self, msg.sender, toMint);

// mint the user's LP tokens
self.lpToken.mint(msg.sender, toMint);

Expand Down Expand Up @@ -723,6 +720,12 @@ library SwapUtils {
}

function _updateUserWithdrawFee(Swap storage self, address user, uint256 toMint) internal {

// If token is transferred to address 0 (or burned), don't update the fee.
if (user == address(0)) {
return;
}

if (self.defaultWithdrawFee == 0) {
// If current fee is set to 0%, set multiplier to FEE_DENOMINATOR
self.withdrawFeeMultiplier[user] = FEE_DENOMINATOR;
Expand Down