diff --git a/deployments/PowerToken.abi b/deployments/PowerToken.abi index 64e0943..81e800e 100644 --- a/deployments/PowerToken.abi +++ b/deployments/PowerToken.abi @@ -829,6 +829,25 @@ ], "anonymous": false }, + { + "type": "event", + "name": "TaxCollected", + "inputs": [ + { + "name": "collector", + "type": "address", + "indexed": true, + "internalType": "address" + }, + { + "name": "amount", + "type": "uint256", + "indexed": true, + "internalType": "uint256" + } + ], + "anonymous": false + }, { "type": "event", "name": "Tip", diff --git a/src/PowerToken.sol b/src/PowerToken.sol index a883929..3570853 100644 --- a/src/PowerToken.sol +++ b/src/PowerToken.sol @@ -117,9 +117,14 @@ contract PowerToken is uint256 tax = _getTaxAmount(taxBasisPoints, amount); - _transfer(address(this), ADMIN, tax); + uint256 airdropAmount = amount - tax; - _transfer(address(this), to, amount - tax); + if (tax > 0) { + _transfer(address(this), ADMIN, tax); + emit TaxCollected(ADMIN, tax); + } + + _transfer(address(this), to, airdropAmount); emit AirdropTokens(to, amount); } @@ -147,7 +152,10 @@ contract PowerToken is _feedBalances[feedId] += tipAmount; } - _transfer(msg.sender, ADMIN, tax); + if (tax > 0) { + _transfer(msg.sender, ADMIN, tax); + emit TaxCollected(ADMIN, tax); + } _transfer(msg.sender, receiver, tipAmount); @@ -228,9 +236,13 @@ contract PowerToken is */ function _issuePoints(address to, uint256 amount, uint256 taxBasisPoints) internal { uint256 tax = _getTaxAmount(taxBasisPoints, amount); - _transfer(address(this), ADMIN, tax); - uint256 points = amount - tax; + + if (tax > 0) { + _transfer(address(this), ADMIN, tax); + emit TaxCollected(ADMIN, tax); + } + _pointsBalancesV2[to] += points; _transfer(address(this), to, points); diff --git a/src/interfaces/IEvents.sol b/src/interfaces/IEvents.sol index 45fcd96..bbee3e9 100644 --- a/src/interfaces/IEvents.sol +++ b/src/interfaces/IEvents.sol @@ -10,11 +10,16 @@ interface IEvents { * @dev Emitted when points are tipped from one address to another. */ event Tip(address indexed from, address indexed to, bytes32 indexed feedId, uint256 amount); - /** * @dev Emitted when points are airdropped to an address. */ event AirdropTokens(address indexed to, uint256 indexed amount); + /** + * @dev Emitted when tax is collected. + * @param collector The address that collected the tax. + * @param amount The amount of tax collected. + */ + event TaxCollected(address indexed collector, uint256 indexed amount); /** * @dev Emitted when points are withdrawn by feed id. */ diff --git a/test/PowerToken.t.sol b/test/PowerToken.t.sol index 6d84aca..7c1a203 100644 --- a/test/PowerToken.t.sol +++ b/test/PowerToken.t.sol @@ -95,6 +95,7 @@ contract PowerTokenTest is Utils, IErrors, IEvents, ERC20Upgradeable { _token.mintToTreasury(address(_token), amount); expectEmit(); + emit TaxCollected(appAdmin, expectedTax); emit DistributePoints(alice, amount - expectedTax); vm.prank(appAdmin); _token.mint(alice, amount, taxBasisPoints); @@ -212,6 +213,8 @@ contract PowerTokenTest is Utils, IErrors, IEvents, ERC20Upgradeable { expectEmit(); emit Transfer(address(_token), appAdmin, tax); + emit TaxCollected(appAdmin, tax); + emit Transfer(address(_token), alice, amount - tax); emit DistributePoints(alice, amount - tax); vm.prank(alice); @@ -330,6 +333,7 @@ contract PowerTokenTest is Utils, IErrors, IEvents, ERC20Upgradeable { expectEmit(); emit Transfer(address(_token), appAdmin, tax); + emit TaxCollected(appAdmin, tax); emit Transfer(address(_token), alice, amount - tax); emit AirdropTokens(alice, amount - tax); vm.prank(appAdmin);