Verified contractPartialMIT
Titanum
Address0x4b836d6a3ba2f0d5962c82818df42dda50e54e9b
- Balance
0 ETH
- Transactions
173
- Compiler
solc 0.8.26
- Same code
1 more contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 1,000,000 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,725,944
- Creation transaction
- 0xae0d71dd1e…d5bdc24df6
src/Titanum.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.26;
// ┌─────────────────────────────────────────────────────────────┐
// │ Titanum ($Ti) — hold-to-earn rebasing memecoin (Uniswap V4) │
// │ Website: https://titanum.fun │
// │ Twitter/X: https://x.com/TitanumFun │
// └─────────────────────────────────────────────────────────────┘
/// @title Titanum ($Ti) — elastic rebasing ERC-20 with a rebase-exclusion set.
/// @notice Non-excluded ("elastic") holders are tracked in gons and scale on every
/// rebase. Excluded holders (the Uniswap V4 PoolManager, the dead address,
/// the treasury) are tracked in fixed fragments and NEVER move on a rebase —
/// this is what keeps the AMM reserves (and burned supply) stable.
///
/// @dev Accounting model (the crux):
/// - `_totalGons` = sum of gons currently held by ELASTIC accounts (mutable).
/// - `elasticSupply = _totalSupply - _totalExcluded`.
/// - `_gonsPerFragment = _totalGons / elasticSupply` (resynced only on rebase + setExcluded).
/// - elastic balanceOf = gonBalance / _gonsPerFragment
/// - excluded balanceOf = stored fragments (rebase-immune)
/// Transfers across the elastic/excluded boundary move both `_totalGons` (by the
/// gon amount) and `_totalExcluded` (by the fragment amount), which keeps the
/// invariant `_totalGons == _gonsPerFragment * elasticSupply` exact between rebases,
/// so a transfer never needs a resync and never disturbs other holders' balances.
contract Titanum {
string public name;
string public symbol;
uint8 public constant decimals = 18;
uint256 private _totalSupply; // total fragments (elastic + excluded)
uint256 private _totalExcluded; // sum of excluded fragment balances
uint256 private _totalGons; // sum of elastic gons (mutable)
uint256 private constant MAX_UINT = type(uint256).max;
uint256 private immutable INITIAL_GONS;
uint256 private _gonsPerFragment;
mapping(address => uint256) private _gonBalances; // elastic holders
mapping(address => uint256) private _excludedBalances; // excluded holders (fragments)
mapping(address => bool) public isExcluded;
mapping(address => mapping(address => uint256)) public allowance;
address public owner; // hook after deploy; may setExcluded + rebase + setOwner
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
event Rebase(uint256 indexed epoch, uint256 totalSupply);
event ExclusionSet(address indexed account, bool excluded);
event OwnerSet(address indexed owner);
error NotOwner();
error ZeroAddress();
error Balance();
error Allowance();
error NoElastic();
modifier onlyOwner() { if (msg.sender != owner) revert NotOwner(); _; }
constructor(string memory _name, string memory _sym, uint256 _supply, address _owner) {
if (_supply == 0) revert NoElastic();
name = _name;
symbol = _sym;
owner = _owner;
_totalSupply = _supply;
INITIAL_GONS = MAX_UINT - (MAX_UINT % _supply); // divisible by supply
_totalGons = INITIAL_GONS;
_gonsPerFragment = INITIAL_GONS / _supply; // exact
_gonBalances[msg.sender] = INITIAL_GONS; // deployer holds all supply, elastic
emit OwnerSet(_owner);
emit Transfer(address(0), msg.sender, _supply);
}
// ───────────────────────── views ─────────────────────────
function totalSupply() external view returns (uint256) { return _totalSupply; }
function elasticSupply() public view returns (uint256) { return _totalSupply - _totalExcluded; }
function balanceOf(address a) public view returns (uint256) {
if (isExcluded[a]) return _excludedBalances[a];
return _gonBalances[a] / _gonsPerFragment;
}
/// @notice gons held by an elastic account (0 for excluded). Exposed for tests/inspection.
function gonsOf(address a) external view returns (uint256) { return _gonBalances[a]; }
// ───────────────────────── ERC-20 ─────────────────────────
function approve(address spender, uint256 value) external returns (bool) {
allowance[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value) external returns (bool) {
_transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
uint256 a = allowance[from][msg.sender];
if (a != MAX_UINT) {
if (a < value) revert Allowance();
allowance[from][msg.sender] = a - value;
}
_transfer(from, to, value);
return true;
}
/// @dev Converts across the elastic/excluded boundary while preserving the
/// `_totalGons == _gonsPerFragment * elasticSupply` invariant (no resync needed).
function _transfer(address from, address to, uint256 value) internal {
if (to == address(0)) revert ZeroAddress();
uint256 gonValue = value * _gonsPerFragment;
// debit `from`
if (isExcluded[from]) {
if (_excludedBalances[from] < value) revert Balance();
unchecked { _excludedBalances[from] -= value; _totalExcluded -= value; }
} else {
if (_gonBalances[from] < gonValue) revert Balance();
unchecked { _gonBalances[from] -= gonValue; _totalGons -= gonValue; }
}
// credit `to`
if (isExcluded[to]) {
_excludedBalances[to] += value;
_totalExcluded += value;
} else {
_gonBalances[to] += gonValue;
_totalGons += gonValue;
}
emit Transfer(from, to, value);
}
/// @notice Burn `value` from the caller's balance, reducing total supply.
/// Works for both elastic and excluded callers; no resync needed
/// (the `_totalGons == gpf * elasticSupply` invariant is preserved).
function burn(uint256 value) external {
address from = msg.sender;
if (isExcluded[from]) {
if (_excludedBalances[from] < value) revert Balance();
unchecked { _excludedBalances[from] -= value; _totalExcluded -= value; }
} else {
uint256 g = value * _gonsPerFragment;
if (_gonBalances[from] < g) revert Balance();
unchecked { _gonBalances[from] -= g; _totalGons -= g; }
}
_totalSupply -= value;
emit Transfer(from, address(0), value);
}
// ─────────────────────── owner ops ───────────────────────
function setOwner(address o) external onlyOwner {
owner = o;
emit OwnerSet(o);
}
/// @notice Toggle an account's rebase-exclusion, converting its balance representation
/// and moving its weight between the elastic and excluded pools.
function setExcluded(address account, bool excluded) external onlyOwner {
if (isExcluded[account] == excluded) return;
uint256 bal = balanceOf(account);
if (excluded) {
// elastic -> excluded: pull its gons out of the elastic pool, store fixed fragments
uint256 g = _gonBalances[account];
_gonBalances[account] = 0;
_totalGons -= g;
_excludedBalances[account] = bal;
_totalExcluded += bal;
} else {
// excluded -> elastic: mint gons at the current rate, drop fixed fragments
_totalExcluded -= bal;
_excludedBalances[account] = 0;
uint256 g = bal * _gonsPerFragment;
_gonBalances[account] = g;
_totalGons += g;
}
isExcluded[account] = excluded;
emit ExclusionSet(account, excluded);
_resync();
}
/// @notice Positive (or negative) rebase: inflates only the ELASTIC portion of supply.
/// Excluded balances (pool, dead, treasury) are untouched.
function rebase(uint256 epoch, int256 supplyDelta) external onlyOwner returns (uint256) {
if (supplyDelta == 0) {
emit Rebase(epoch, _totalSupply);
return _totalSupply;
}
if (supplyDelta < 0) {
_totalSupply -= uint256(-supplyDelta);
} else {
_totalSupply += uint256(supplyDelta);
}
_resync();
emit Rebase(epoch, _totalSupply);
return _totalSupply;
}
/// @dev Recompute gons-per-fragment from current elastic gons / elastic supply.
function _resync() internal {
uint256 elastic = elasticSupply();
if (elastic == 0) revert NoElastic();
_gonsPerFragment = _totalGons / elastic;
// TI-01 defense-in-depth: gpf must never collapse to 0, or elastic balanceOf
// (gonBalance / _gonsPerFragment) would divide by zero and brick every read.
// Unreachable in normal flow (a positive rebase while _totalGons==0 can't occur —
// the hook derives the rebase delta from current elastic supply, which is 0 then),
// but this makes that theoretical brick impossible.
if (_gonsPerFragment == 0) revert NoElastic();
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "none",
"useLiteralContent": false
},
"optimizer": {
"runs": 1000000,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"forge-std/=lib/forge-std/src/",
"solady/=lib/solady/src/",
"solmate/=lib/v4-core/lib/solmate/",
"openzeppelin-contracts/=lib/v4-core/lib/openzeppelin-contracts/",
"v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"@uniswap/v4-core/=lib/v4-core/",
"@uniswap/v4-periphery/=lib/v4-periphery/",
"permit2/=lib/v4-periphery/lib/permit2/",
"ds-test/=lib/v4-core/lib/solmate/lib/ds-test/src/",
"erc4626-tests/=lib/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.