Skip to content

Commit

Permalink
Merge pull request #5 from RSSNext/feat/eventTaxCollected
Browse files Browse the repository at this point in the history
feat: add event tax collected
  • Loading branch information
iavl authored Oct 15, 2024
2 parents 235cbeb + 9370889 commit d287b71
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
19 changes: 19 additions & 0 deletions deployments/PowerToken.abi
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 17 additions & 5 deletions src/PowerToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
7 changes: 6 additions & 1 deletion src/interfaces/IEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 4 additions & 0 deletions test/PowerToken.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d287b71

Please sign in to comment.