From 67ec36a1db99e5d6abf566cdcc6757b0d30674d0 Mon Sep 17 00:00:00 2001 From: Kiryl Yermakou Date: Tue, 3 Oct 2023 12:48:56 -0400 Subject: [PATCH] fix(LockUnlockFee): always return adjusted amount (#110) * 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. * Added a getter for chain name to the remote address validator. * moved the tokenManager getter functionality to a separate contract which saves almost a kilobyte of codesize. * made lint happy * Removed tokenManagerGetter and put params into tokenManagers * Added separate tokenManager interfaces * addressed ackeeblockchains's 3.0 report * prettier * added interchain transfer methods to the service and unified receiving tokens a bit. * made lint happy * rename sendToken to interchainTransfer * changed sendToken everywhere * changed from uint256.max to a const * change setting to zero to delete for storage slots. * rearange storage variables to save a bit of gas. * Removed unecesairy casts * made as many event params inexed as possible * Removed unused imports * domain separator is calculated each time. * added some natspec * added an example for using pre-existing custom tokens. * added a comment * feat(TokenManager): MintBurnFrom and MintBurnFromAddress * fix(TokenManager): removed MintBurnFromAddress as deprecated * fix(LockUnlockFee): always return adjusted amount --------- Co-authored-by: Foivos Co-authored-by: Milap Sheth --- ...ransfer.sol => TokenManagerLockUnlockFee.sol} | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) rename contracts/token-manager/implementations/{TokenManagerLockUnlockFeeOnTransfer.sol => TokenManagerLockUnlockFee.sol} (89%) diff --git a/contracts/token-manager/implementations/TokenManagerLockUnlockFeeOnTransfer.sol b/contracts/token-manager/implementations/TokenManagerLockUnlockFee.sol similarity index 89% rename from contracts/token-manager/implementations/TokenManagerLockUnlockFeeOnTransfer.sol rename to contracts/token-manager/implementations/TokenManagerLockUnlockFee.sol index 733ec6aa..b3b95f01 100644 --- a/contracts/token-manager/implementations/TokenManagerLockUnlockFeeOnTransfer.sol +++ b/contracts/token-manager/implementations/TokenManagerLockUnlockFee.sol @@ -47,15 +47,11 @@ contract TokenManagerLockUnlockFee is TokenManager, NoReEntrancy { */ function _takeToken(address from, uint256 amount) internal override noReEntrancy returns (uint256) { IERC20 token = IERC20(tokenAddress()); - uint256 balance = token.balanceOf(address(this)); + uint256 balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(from, address(this), amount); - uint256 diff = token.balanceOf(address(this)) - balance; - if (diff < amount) { - amount = diff; - } - return amount; + return token.balanceOf(address(this)) - balanceBefore; } /** @@ -66,15 +62,11 @@ contract TokenManagerLockUnlockFee is TokenManager, NoReEntrancy { */ function _giveToken(address to, uint256 amount) internal override noReEntrancy returns (uint256) { IERC20 token = IERC20(tokenAddress()); - uint256 balance = token.balanceOf(to); + uint256 balanceBefore = token.balanceOf(to); token.safeTransfer(to, amount); - uint256 diff = token.balanceOf(to) - balance; - if (diff < amount) { - amount = diff; - } - return amount; + return token.balanceOf(to) - balanceBefore; } /**