Verified contractPartialMIT
FeeDistributor
Address0x1fc39045035e37da1880d2102c380e8dd8e69a89
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.8.20
- Same code
1 more contract
Details
- Compiler
- solc 0.8.20+commit.a1b79de6
- Language
- solidity
- Optimization
- Yes, 50 runs
- EVM version
- paris
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,608,845
- Creation transaction
- 0x0a951f71f1…4aced2bb02
src/FeeDistributor.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IERC20FeeDistributor {
function transfer(address to, uint256 amount) external returns (bool);
}
contract FeeDistributor {
address public constant DEAD = 0xdEAD000000000000000042069420694206942069;
uint256 public constant BPS_DENOMINATOR = 10_000;
address public owner;
address public platformRecipient;
mapping(address => bool) public authorizedCollectors;
mapping(uint256 => uint16) public burnBpsByTokenId;
mapping(uint256 => bool) public burnBpsRegistered;
bool private locked;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event PlatformRecipientUpdated(address indexed previousRecipient, address indexed newRecipient);
event CollectorAuthorizationUpdated(address indexed collector, bool authorized);
event TokenIdBurnBpsRegistered(uint256 indexed tokenId, uint16 burnBps);
event FeeProcessed(
uint256 indexed tokenId,
address indexed token,
uint256 totalAmount,
uint256 burnedAmount,
uint256 platformAmount
);
modifier onlyOwner() {
require(msg.sender == owner, "ONLY_OWNER");
_;
}
modifier onlyAuthorizedCollector() {
require(authorizedCollectors[msg.sender], "ONLY_COLLECTOR");
_;
}
modifier nonReentrant() {
require(!locked, "LOCKED");
locked = true;
_;
locked = false;
}
constructor(address platformRecipient_) {
require(platformRecipient_ != address(0), "ZERO_PLATFORM");
owner = msg.sender;
platformRecipient = platformRecipient_;
emit OwnershipTransferred(address(0), msg.sender);
emit PlatformRecipientUpdated(address(0), platformRecipient_);
}
function transferOwnership(address newOwner) external onlyOwner {
require(newOwner != address(0), "ZERO_OWNER");
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function setPlatformRecipient(address newPlatformRecipient) external onlyOwner {
require(newPlatformRecipient != address(0), "ZERO_PLATFORM");
emit PlatformRecipientUpdated(platformRecipient, newPlatformRecipient);
platformRecipient = newPlatformRecipient;
}
function setAuthorizedCollector(address collector, bool authorized) external onlyOwner {
require(collector != address(0), "ZERO_COLLECTOR");
authorizedCollectors[collector] = authorized;
emit CollectorAuthorizationUpdated(collector, authorized);
}
function registerTokenIdBurnBps(uint256 tokenId, uint16 burnBps) external onlyAuthorizedCollector {
require(!burnBpsRegistered[tokenId], "ALREADY_REGISTERED");
require(burnBps <= BPS_DENOMINATOR, "BPS_TOO_HIGH");
burnBpsByTokenId[tokenId] = burnBps;
burnBpsRegistered[tokenId] = true;
emit TokenIdBurnBpsRegistered(tokenId, burnBps);
}
function processFee(uint256 tokenId, address token, uint256 amount)
external
onlyAuthorizedCollector
nonReentrant
returns (uint256 burnedAmount, uint256 platformAmount)
{
require(token != address(0), "ZERO_TOKEN");
require(burnBpsRegistered[tokenId], "TOKEN_ID_NOT_REGISTERED");
if (amount == 0) {
return (0, 0);
}
uint16 burnBps = burnBpsByTokenId[tokenId];
burnedAmount = (amount * burnBps) / BPS_DENOMINATOR;
platformAmount = amount - burnedAmount;
if (burnedAmount > 0) {
_safeTransfer(token, DEAD, burnedAmount);
}
if (platformAmount > 0) {
_safeTransfer(token, platformRecipient, platformAmount);
}
emit FeeProcessed(tokenId, token, amount, burnedAmount, platformAmount);
}
function _safeTransfer(address token, address to, uint256 value) internal {
(bool ok, bytes memory data) = token.call(
abi.encodeWithSelector(IERC20FeeDistributor.transfer.selector, to, value)
);
require(ok && (data.length == 0 || abi.decode(data, (bool))), "TOKEN_TRANSFER_FAILED");
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 50,
"enabled": true
},
"evmVersion": "paris",
"remappings": [
"forge-std/=lib/forge-std/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.