// File: @openzeppelin/contracts/utils/Context.sol
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
// File: @openzeppelin/contracts/access/Ownable.sol
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
// File: contracts/Empire.sol
pragma solidity ^0.8.0;
contract Empire is Ownable, ReentrancyGuard {
IERC20 public immutable baseToken;
mapping(address => bool) public authorizedAddresses;
// Constants for Base network
address constant public WETH = 0x4200000000000000000000000000000000000006;
address constant public CLANKER = 0x1bc0c42215582d5A085795f4baDbaC3ff36d1Bcb;
address constant public DEGEN = 0x4ed4E862860beD51a9570b96d89aF5E1B0Efefed;
address constant public MOXIE = 0x8C9037D1Ef5c6D1f6816278C7AAF5491d24CD527;
address constant public GLANKER = 0x33aC788bc9Ccb27e9ec558fb2bde79950A6b9d5B;
// Tokens for distribution
address[] public allowedTokens;
mapping(address => bool) public isTokenAllowed;
enum SendPercentage {
TEN, // 10%
QUARTER, // 25%
HALF, // 50%
THREE_QUARTERS, // 75%
FULL // 100%
}
event BulkSendCompleted(address[] tokens, uint256[] amounts, uint256 recipientsCount);
event TokenAdded(address indexed token);
event TokenRemoved(address indexed token);
event TokensBurned(address[] tokens, uint256[] amounts);
event AuthorizedAddressAdded(address indexed account);
event AuthorizedAddressRemoved(address indexed account);
constructor(address _baseToken) Ownable(msg.sender) {
require(_baseToken != address(0), "Invalid base token");
baseToken = IERC20(_baseToken);
// Add default tokens
_addDefaultToken(WETH);
_addDefaultToken(CLANKER);
_addDefaultToken(DEGEN);
_addDefaultToken(MOXIE);
_addDefaultToken(GLANKER);
}
function _addDefaultToken(address token) private {
allowedTokens.push(token);
isTokenAllowed[token] = true;
emit TokenAdded(token);
}
modifier onlyAuthorized() {
require(owner() == msg.sender || authorizedAddresses[msg.sender], "Not authorized");
_;
}
receive() external payable {}
function addAuthorizedAddress(address _address) external onlyOwner {
require(_address != address(0), "Invalid address");
authorizedAddresses[_address] = true;
emit AuthorizedAddressAdded(_address);
}
function removeAuthorizedAddress(address _address) external onlyOwner {
authorizedAddresses[_address] = false;
emit AuthorizedAddressRemoved(_address);
}
function addToken(address _token) external onlyAuthorized {
require(_token != address(0), "Invalid token address");
require(!isTokenAllowed[_token], "Token already added");
allowedTokens.push(_token);
isTokenAllowed[_token] = true;
emit TokenAdded(_token);
}
function removeToken(address _token) external onlyAuthorized {
require(isTokenAllowed[_token], "Token not allowed");
isTokenAllowed[_token] = false;
for (uint i = 0; i < allowedTokens.length; i++) {
if (allowedTokens[i] == _token) {
allowedTokens[i] = allowedTokens[allowedTokens.length - 1];
allowedTokens.pop();
break;
}
}
emit TokenRemoved(_token);
}
function execute(
address target,
uint256 value,
bytes calldata data
) external onlyAuthorized returns (bytes memory) {
require(target != address(0), "Invalid target address");
(bool success, bytes memory result) = target.call{value: value}(data);
require(success, "External call failed");
return result;
}
struct RecipientShare {
address recipient;
uint256 percentage; // Percentage multiplied by 100 (e.g., 1000 = 10%)
}
function bulkSendAll(
RecipientShare[] calldata _recipientShares,
SendPercentage _percentage
) external onlyAuthorized nonReentrant {
require(_recipientShares.length > 0, "No recipients provided");
require(allowedTokens.length > 0, "No allowed tokens");
// Validate total percentage equals 100%
uint256 totalPercentage = 0;
for(uint256 i = 0; i < _recipientShares.length; i++) {
require(_recipientShares[i].recipient != address(0), "Invalid recipient");
require(_recipientShares[i].percentage > 0, "Invalid percentage");
totalPercentage += _recipientShares[i].percentage;
}
require(totalPercentage == 10000, "Total percentage must equal 100%"); // 10000 = 100.00%
uint256[] memory amounts = new uint256[](allowedTokens.length);
// Determine percentage multiplier for total amount to distribute
uint256 percentMultiplier;
if (_percentage == SendPercentage.TEN) {
percentMultiplier = 10;
} else if (_percentage == SendPercentage.QUARTER) {
percentMultiplier = 25;
} else if (_percentage == SendPercentage.HALF) {
percentMultiplier = 50;
} else if (_percentage == SendPercentage.THREE_QUARTERS) {
percentMultiplier = 75;
} else {
percentMultiplier = 100;
}
for(uint256 i = 0; i < allowedTokens.length; i++) {
IERC20 token = IERC20(allowedTokens[i]);
uint256 balance = token.balanceOf(address(this));
if(balance > 0) {
uint256 sendAmount = (balance * percentMultiplier) / 100;
amounts[i] = sendAmount;
for(uint256 j = 0; j < _recipientShares.length; j++) {
uint256 recipientAmount = (sendAmount * _recipientShares[j].percentage) / 10000;
if(recipientAmount > 0) {
require(token.transfer(_recipientShares[j].recipient, recipientAmount), "Transfer failed");
}
}
}
}
emit BulkSendCompleted(allowedTokens, amounts, _recipientShares.length);
}
function burn(
address[] calldata _tokens,
SendPercentage _percentage
) external onlyAuthorized nonReentrant {
address burnAddress = address(0xdead);
uint256[] memory amounts = new uint256[](_tokens.length);
// Determine percentage multiplier
uint256 percentMultiplier;
if (_percentage == SendPercentage.TEN) {
percentMultiplier = 10;
} else if (_percentage == SendPercentage.QUARTER) {
percentMultiplier = 25;
} else if (_percentage == SendPercentage.HALF) {
percentMultiplier = 50;
} else if (_percentage == SendPercentage.THREE_QUARTERS) {
percentMultiplier = 75;
} else {
percentMultiplier = 100;
}
for(uint256 i = 0; i < _tokens.length; i++) {
require(_tokens[i] != address(0), "Invalid token address");
IERC20 token = IERC20(_tokens[i]);
uint256 balance = token.balanceOf(address(this));
if(balance > 0) {
uint256 burnAmount = (balance * percentMultiplier) / 100;
require(token.transfer(burnAddress, burnAmount), "Burn failed");
amounts[i] = burnAmount;
}
}
emit TokensBurned(_tokens, amounts);
}
function getAllowedTokens() external view returns (address[] memory) {
return allowedTokens;
}
}
// File: contracts/EmpireFactory.sol
pragma solidity ^0.8.0;
contract EmpireFactory is Ownable {
error InvalidAddress();
error SenderExists();
error NotFound();
error NotAuthorized();
struct EmpireInfo {
address baseToken;
address sender;
string name;
address owner;
bool isActive;
}
event EmpireCreated(
address indexed baseToken,
address indexed empire,
string name,
address owner
);
mapping(address => address) public tokenToEmpire;
mapping(address => EmpireInfo) public empireDetails;
address[] public allEmpires;
mapping(address => address[]) private ownerToEmpires;
constructor() Ownable(msg.sender) {}
function createEmpire(
address _baseToken,
string calldata _name,
address _owner
) external onlyOwner returns (address) {
if(_baseToken == address(0) || _owner == address(0)) revert InvalidAddress();
// Check if existing empire is active
address existingEmpire = tokenToEmpire[_baseToken];
if(existingEmpire != address(0)) {
// Only allow new empire if existing one is inactive
if(empireDetails[existingEmpire].isActive) revert SenderExists();
// Clear the old mapping if inactive
delete tokenToEmpire[_baseToken];
}
Empire newEmpire = new Empire(_baseToken);
newEmpire.transferOwnership(_owner);
address empireAddress = address(newEmpire);
tokenToEmpire[_baseToken] = empireAddress;
allEmpires.push(empireAddress);
empireDetails[empireAddress] = EmpireInfo({
baseToken: _baseToken,
sender: empireAddress,
name: _name,
owner: _owner,
isActive: true
});
ownerToEmpires[_owner].push(empireAddress);
emit EmpireCreated(_baseToken, empireAddress, _name, _owner);
return empireAddress;
}
function getEmpires(address owner, bool activeOnly) external view returns (EmpireInfo[] memory) {
address[] storage empireAddresses = owner == address(0) ?
allEmpires : ownerToEmpires[owner];
// First count active empires if filtering is needed
uint256 activeCount = 0;
if (activeOnly) {
for(uint256 i = 0; i < empireAddresses.length; i++) {
if (empireDetails[empireAddresses[i]].isActive) {
activeCount++;
}
}
} else {
activeCount = empireAddresses.length;
}
EmpireInfo[] memory empires = new EmpireInfo[](activeCount);
uint256 currentIndex = 0;
for(uint256 i = 0; i < empireAddresses.length; i++) {
if (!activeOnly || empireDetails[empireAddresses[i]].isActive) {
empires[currentIndex] = empireDetails[empireAddresses[i]];
currentIndex++;
}
}
return empires;
}
function getTotalEmpires(bool activeOnly) external view returns (uint256) {
if (!activeOnly) {
return allEmpires.length;
}
uint256 activeCount = 0;
for(uint256 i = 0; i < allEmpires.length; i++) {
if (empireDetails[allEmpires[i]].isActive) {
activeCount++;
}
}
return activeCount;
}
function toggleActive(address empire) external onlyOwner {
if(empireDetails[empire].sender == address(0)) revert NotFound();
empireDetails[empire].isActive = !empireDetails[empire].isActive;
}
function updateName(address empire, string calldata newName) external {
if(empireDetails[empire].owner != msg.sender && owner() != msg.sender)
revert NotAuthorized();
empireDetails[empire].name = newName;
}
}
{
"compilationTarget": {
"EmpireFactory.sol": "EmpireFactory"
},
"evmVersion": "cancun",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotFound","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"SenderExists","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"baseToken","type":"address"},{"indexed":true,"internalType":"address","name":"empire","type":"address"},{"indexed":false,"internalType":"string","name":"name","type":"string"},{"indexed":false,"internalType":"address","name":"owner","type":"address"}],"name":"EmpireCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"allEmpires","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_baseToken","type":"address"},{"internalType":"string","name":"_name","type":"string"},{"internalType":"address","name":"_owner","type":"address"}],"name":"createEmpire","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"empireDetails","outputs":[{"internalType":"address","name":"baseToken","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"isActive","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"activeOnly","type":"bool"}],"name":"getEmpires","outputs":[{"components":[{"internalType":"address","name":"baseToken","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"bool","name":"isActive","type":"bool"}],"internalType":"struct EmpireFactory.EmpireInfo[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bool","name":"activeOnly","type":"bool"}],"name":"getTotalEmpires","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"empire","type":"address"}],"name":"toggleActive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokenToEmpire","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"empire","type":"address"},{"internalType":"string","name":"newName","type":"string"}],"name":"updateName","outputs":[],"stateMutability":"nonpayable","type":"function"}]