Verified contractExact
TokenWorks
Address0x96b133d2de43ee2f8f4f1f9a5d0e5ec6c2a4629e
- Balance
0 ETH
- Transactions
22
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- Not stated
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,104,652
- Creation transaction
- 0x2632c73031…f213c23e6d
token.sol
/*//////////////////////////////////////////////////////////////////////////////
████████╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗
╚══██╔══╝██╔═══██╗██║ ██╔╝██╔════╝████╗ ██║
██║ ██║ ██║█████╔╝ █████╗ ██╔██╗ ██║
██║ ██║ ██║██╔═██╗ ██╔══╝ ██║╚██╗██║
██║ ╚██████╔╝██║ ██╗███████╗██║ ╚████║
╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝
██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗███████╗
██║ ██║██╔═══██╗██╔══██╗██║ ██╔╝██╔════╝
██║ █╗ ██║██║ ██║██████╔╝█████╔╝ ███████╗
██║███╗██║██║ ██║██╔══██╗██╔═██╗ ╚════██║
╚███╔███╔╝╚██████╔╝██║ ██║██║ ██╗███████║
╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝
┌──────────────────────────────────────────────────────────────────────┐
│ │
│ A PLAYGROUND FOR ONCHAIN FINANCIALIZED IDEAS™ │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ CONTRACT :: TokenWorks.sol │
│ VERSION :: 0.1.0 │
│ AUTHOR :: tokenworks.eth | 10thousandtokens.eth │
│ LICENSE :: MIT │
│ NETWORK :: ethereum mainnet │
│ │
│ ──────────────────────────────────────────────────────────────── │
│ │
│ x.com/token_works · github.com/token-works · token.works │
│ │
└──────────────────────────────────────────────────────────────────────┘
not financial advice. not even an idea. a playground.
//////////////////////////////////////////////////////////////////////////////*/
pragma solidity 0.8.30;
contract TokenWorks {
error ZeroAddress();
error InsufficientBalance();
error InsufficientAllowance();
error NotOwner();
error OutOfBounds();
error AlreadySet();
string public constant name = "Token Works";
string public constant symbol = "T0KEN";
uint8 public constant decimals = 18;
uint256 public constant MESH_UNIT = 1e18;
uint256 public constant MAX_OBJECTS = 10000;
uint256 public constant TOTAL_SUPPLY = MAX_OBJECTS * MESH_UNIT;
uint256 public immutable RENDER_BLOCK;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
address public owner;
address[] private _scene;
mapping(address => bool) private _rendered;
mapping(address => uint256) private _sceneIndex;
address public renderEngine;
address public geometryProvider;
address public hookLayer;
bool public sceneActivated;
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
event ObjectShift(address indexed from, address indexed to, uint256 count);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event SceneActivated(address indexed hook);
modifier onlyOwner() {
if (msg.sender != owner) revert NotOwner();
_;
}
constructor() {
owner = msg.sender;
RENDER_BLOCK = block.number;
balanceOf[msg.sender] = TOTAL_SUPPLY;
_addToScene(msg.sender);
emit Transfer(address(0), msg.sender, TOTAL_SUPPLY);
}
function totalSupply() external pure returns (uint256) { return TOTAL_SUPPLY; }
function transfer(address to, uint256 amount) external returns (bool) {
_transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
uint256 allowed = allowance[from][msg.sender];
if (allowed != type(uint256).max) {
if (allowed < amount) revert InsufficientAllowance();
unchecked { allowance[from][msg.sender] = allowed - amount; }
}
_transfer(from, to, amount);
return true;
}
function approve(address spender, uint256 amount) external returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
// -- 3D object layer -------------------------------------------------
/// @notice Number of 3D mesh objects held by an address
function meshCount(address account) public view returns (uint256) {
return balanceOf[account] / MESH_UNIT;
}
/// @notice Total 3D objects currently in the scene
function totalMeshes() external pure returns (uint256) {
return MAX_OBJECTS;
}
/// @notice Deterministic geometry seed for a specific 3D object.
/// Decoded off-chain by the renderer to produce vertex, face,
/// and material data for each unique mesh.
function enableStaking(address account, uint256 index) public view returns (bytes32) {
if (index >= meshCount(account)) revert OutOfBounds();
return keccak256(abi.encodePacked(account, index, RENDER_BLOCK, block.chainid, address(this)));
}
/// @notice Returns a paginated list of geometry seeds for an address
function InitializeOrganisms(address account, uint256 offset, uint256 limit)
external view returns (bytes32[] memory seeds)
{
uint256 count = meshCount(account);
if (offset >= count) return new bytes32[](0);
uint256 end = offset + limit > count ? count : offset + limit;
seeds = new bytes32[](end - offset);
for (uint256 i = 0; i < seeds.length; i++) {
seeds[i] = enableStaking(account, offset + i);
}
}
/// @notice Blocks elapsed since the scene was first rendered
function setHook() external view returns (uint256) {
return block.number - RENDER_BLOCK;
}
/// @notice Whether an address currently holds any u3D object
function setupMesh(address account) external view returns (bool) {
return _rendered[account];
}
/// @notice Total number of unique holders in the scene
function sceneCount() external view returns (uint256) {
return _scene.length;
}
/// @notice Get holder address by scene index
function sceneAt(uint256 index) external view returns (address) {
if (index >= _scene.length) revert OutOfBounds();
return _scene[index];
}
// -- protocol configuration ------------------------------------------
/// @notice Register the Uniswap V4 hook powering the 3D render engine
function setNFTAddress(address _hook) external onlyOwner {
if (_hook == address(0)) revert ZeroAddress();
if (hookLayer != address(0)) revert AlreadySet();
hookLayer = _hook;
}
/// @notice Set the off-chain geometry data provider address
function setProvider(address _provider) external onlyOwner {
if (_provider == address(0)) revert ZeroAddress();
geometryProvider = _provider;
}
/// @notice Set the on-chain render engine contract
function setTradingEngine(address _engine) external onlyOwner {
if (_engine == address(0)) revert ZeroAddress();
renderEngine = _engine;
}
/// @notice Activate the scene once all protocol addresses are configured
function activateScene(address _hook) external onlyOwner {
if (_hook == address(0)) revert ZeroAddress();
if (sceneActivated) revert AlreadySet();
hookLayer = _hook;
sceneActivated = true;
emit SceneActivated(_hook);
}
// -- ownership -------------------------------------------------------
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(0)) revert ZeroAddress();
emit OwnershipTransferred(owner, newOwner);
owner = newOwner;
}
function renounceOwnership() external onlyOwner {
emit OwnershipTransferred(owner, address(0));
owner = address(0);
}
// -- internal --------------------------------------------------------
function _transfer(address from, address to, uint256 amount) internal {
if (to == address(0)) revert ZeroAddress();
if (balanceOf[from] < amount) revert InsufficientBalance();
uint256 meshesBefore = meshCount(from);
unchecked {
balanceOf[from] -= amount;
balanceOf[to] += amount;
}
_addToScene(to);
if (balanceOf[from] == 0) _removeFromScene(from);
emit Transfer(from, to, amount);
uint256 meshesAfter = meshCount(from);
uint256 shifted = meshesBefore > meshesAfter ? meshesBefore - meshesAfter : 0;
if (shifted > 0) emit ObjectShift(from, to, shifted);
}
function _addToScene(address account) internal {
if (!_rendered[account] && balanceOf[account] > 0) {
_sceneIndex[account] = _scene.length;
_scene.push(account);
_rendered[account] = true;
}
}
function _removeFromScene(address account) internal {
if (_rendered[account]) {
uint256 idx = _sceneIndex[account];
address last = _scene[_scene.length - 1];
_scene[idx] = last;
_sceneIndex[last] = idx;
_scene.pop();
delete _rendered[account];
delete _sceneIndex[account];
}
}
}Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.