8000 🍼 Feat: Owner can destroy funds of blacklisted users on Ethereum by qiwihui · Pull Request #10 · tutoken/smart-contracts · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🍼 Feat: Owner can destroy funds of blacklisted users on Ethereum #10

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/contracts-por/contracts/TokenControllerV3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,14 @@ contract TokenControllerV3 {
token.setBlacklisted(account, isBlacklisted);
}

/**
* @dev Destroy black funds for the blacklisted user
* @param _blackListedUser the blacklisted user
*/
function destroyBlackFunds(address _blackListedUser) external onlyOwner {
token.destroyBlackFunds(_blackListedUser);
}

/*
========================================
Proof of Reserve, administrative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ abstract contract BurnableTokenWithBounds is ReclaimerToken {
*/
event SetBurnBounds(uint256 newMin, uint256 newMax);

/**
* @dev Emitted when _blackListedUser's funds are destroyed
*/
event DestroyedBlackFunds(address indexed _blackListedUser, uint256 _balance);

/**
* @dev Destroys `amount` tokens from `msg.sender`, reducing the
* total supply.
Expand Down Expand Up @@ -75,4 +80,17 @@ abstract contract BurnableTokenWithBounds is ReclaimerToken {
super._burn(account, amount);
emit Burn(account, amount);
}

/**
* @dev destroy black funds from _blackListedUser
* @param _blackListedUser the address to destroy from
*/
function destroyBlackFunds(address _blackListedUser) external override onlyOwner {
require(isBlacklisted[_blackListedUser]);
uint256 dirtyFunds = balanceOf(_blackListedUser);

_balances[_blackListedUser] = 0;
_totalSupply = _totalSupply.sub(dirtyFunds);
emit DestroyedBlackFunds(_blackListedUser, dirtyFunds);
}
}
2 changes: 2 additions & 0 deletions packages/contracts-por/contracts/interface/ITrueCurrency.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ interface ITrueCurrency {
function reclaimToken(IERC20 token, address _to) external;

function setBlacklisted(address account, bool isBlacklisted) external;

function destroyBlackFunds(address _blackListedUser) external;
}
32 changes: 32 additions & 0 deletions packages/contracts-por/test/TokenController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,5 +598,37 @@ describe('TokenController', () => {
it('rejects when called by non owner', async () => {
await expect(controller.connect(otherWallet).setBlacklisted(otherWallet.address, true)).to.be.revertedWith('only Owner')
})

it('destroy black funds for blacklisted user', async () => {
await token.connect(thirdWallet).transfer(otherWallet.address, parseEther('10'))
const balance = await token.balanceOf(otherWallet.address)
expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('10'))

await expect(controller.setBlacklisted(otherWallet.address, true)).to.emit(token, 'Blacklisted')
.withArgs(otherWallet.address, true)
await expect(controller.destroyBlackFunds(otherWallet.address)).to.emit(token, 'DestroyedBlackFunds')
.withArgs(otherWallet.address, balance).and.to.not.emit(token, 'Transfer')

expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('0'))
})

it('rejects when destroying black funds for non blacklisted user', async () => {
await token.connect(thirdWallet).transfer(otherWallet.address, parseEther('10'))
expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('10'))
await expect(controller.destroyBlackFunds(otherWallet.address)).to.be.reverted

expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('10'))
})

it('rejects when destroying black funds for blacklisted user by non owner', async () => {
await token.connect(thirdWallet).transfer(otherWallet.address, parseEther('10'))
expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('10'))

await expect(controller.setBlacklisted(otherWallet.address, true)).to.emit(token, 'Blacklisted')
.withArgs(otherWallet.address, true)
await expect(controller.connect(otherWallet).destroyBlackFunds(otherWallet.address)).to.be.revertedWith('only Owner')

expect(await token.balanceOf(otherWallet.address)).to.equal(parseEther('10'))
})
})
})
0