-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fee on transfer as a separate token manager (#96)
* renamed folder and changed version * npmignore * npmignore * change version * using include pattern instead. * Fixed most of the things least auhority suggested. * made lint happy * Apply suggestions from code review * fixed some bugs * added events * rename set to transfer for distributor and operator * changed standardized token to always allow token managers to mint/burn it. * using immutable storage for remoteAddressValidator address to save gas * Added some recommended changes * added milap's suggested changes * Fixed some names and some minor gas optimizations * prettier and lint * stash * import .env in hardhat.config * trying to fix .env.example * Added some getters in IRemoteAddressValidator and removed useless check for distributor in the InterchainTokenService. * removed ternary operators * made lint happy * made lint happy * Added a new token manager to handle fee on transfer and added some tests for it as well * fixed the liquidity pool check. * fix a duplication bug * lint * added some more tests * Added more tests * Added proper re-entrancy protection for fee on transfer token managers. * change to tx.origin for refunds * Added support for more kinds of addresses. * some minor gas opts * some more gas optimizations. --------- Co-authored-by: Milap Sheth <[email protected]>
- Loading branch information
1 parent
c04aaa3
commit 8d66c0b
Showing
13 changed files
with
387 additions
and
58 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title Pausable | ||
* @notice This contract provides a mechanism to halt the execution of specific functions | ||
* if a pause condition is activated. | ||
*/ | ||
interface INoReEntrancy { | ||
error ReEntrancy(); | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import { InterchainToken } from '../interchain-token/InterchainToken.sol'; | ||
import { Distributable } from '../utils/Distributable.sol'; | ||
import { ITokenManager } from '../interfaces/ITokenManager.sol'; | ||
import { IERC20BurnableMintable } from '../interfaces/IERC20BurnableMintable.sol'; | ||
|
||
contract FeeOnTransferTokenTest is InterchainToken, Distributable, IERC20BurnableMintable { | ||
ITokenManager public tokenManager_; | ||
bool internal tokenManagerRequiresApproval_ = true; | ||
string public name; | ||
string public symbol; | ||
uint8 public decimals; | ||
|
||
constructor(string memory name_, string memory symbol_, uint8 decimals_, address tokenManagerAddress) { | ||
name = name_; | ||
symbol = symbol_; | ||
decimals = decimals_; | ||
_setDistributor(msg.sender); | ||
tokenManager_ = ITokenManager(tokenManagerAddress); | ||
} | ||
|
||
function tokenManager() public view override returns (ITokenManager) { | ||
return tokenManager_; | ||
} | ||
|
||
function _beforeInterchainTransfer( | ||
address sender, | ||
string calldata /*destinationChain*/, | ||
bytes calldata /*destinationAddress*/, | ||
uint256 amount, | ||
bytes calldata /*metadata*/ | ||
) internal override { | ||
if (!tokenManagerRequiresApproval_) return; | ||
address tokenManagerAddress = address(tokenManager_); | ||
uint256 allowance_ = allowance[sender][tokenManagerAddress]; | ||
if (allowance_ != type(uint256).max) { | ||
if (allowance_ > type(uint256).max - amount) { | ||
allowance_ = type(uint256).max - amount; | ||
} | ||
|
||
_approve(sender, tokenManagerAddress, allowance_ + amount); | ||
} | ||
} | ||
|
||
function setTokenManagerRequiresApproval(bool requiresApproval) public { | ||
tokenManagerRequiresApproval_ = requiresApproval; | ||
} | ||
|
||
function mint(address account, uint256 amount) external onlyDistributor { | ||
_mint(account, amount); | ||
} | ||
|
||
function burn(address account, uint256 amount) external onlyDistributor { | ||
_burn(account, amount); | ||
} | ||
|
||
function setTokenManager(ITokenManager tokenManagerAddress) external { | ||
tokenManager_ = tokenManagerAddress; | ||
} | ||
|
||
// Always transfer 10 less base tokens. | ||
function _transfer(address sender, address recipient, uint256 amount) internal override { | ||
if (sender == address(0) || recipient == address(0)) revert InvalidAccount(); | ||
|
||
balanceOf[sender] -= amount; | ||
balanceOf[recipient] += amount - 10; | ||
emit Transfer(sender, recipient, amount); | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.