Verified contractExactMIT
SpectrumPool
Address0xdf2c129c6382f50e9b2b9dc5068cd2b9f20ab692
- Balance
0 ETH
- Transactions
1
- Compiler
solc 0.8.26
- Same code
2 more contracts
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 800 runs
- EVM version
- cancun
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 25,648,618
- Creation transaction
- 0xdbbf4a9bb5…3eab44fa5d
- Main copy (most transactions)
- 0x079f762d…81f887c2
2 files
src/SpectrumPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @title SpectrumPool — Prism's reflexive "refraction" ledger + reward treasury.
/// @notice Holders REFRACT (opt-in, stake-in-place) their PRISM into one of 7 spectrum bands
/// (Red -> Violet) with escalating multipliers and lock terms. The contract snapshots the
/// caller's live PRISM balance — tokens never leave the wallet. Rewards stream from the
/// SpectrumPool, funded by the Uniswap v4 refraction hook (a slice of every swap) plus
/// emissions. The APR is REFLEXIVE: the base rate scales with total refracted supply.
/// A band that un-refracts before its term FORFEITS its accrued (unclaimed) reward, which
/// stays in the pool and is redistributed across the spectrum. Non-custodial: only rewards move.
contract SpectrumPool {
IERC20 public immutable prism;
address public owner;
// 7 bands: Red, Orange, Yellow, Green, Blue, Indigo, Violet
uint32[7] public BAND_MULT = [uint32(10000), 15000, 22000, 30000, 40000, 55000, 80000]; // 1.0x .. 8.0x (bps)
uint32[7] public BAND_DUR = [uint32(0), 7 days, 14 days, 30 days, 60 days, 90 days, 180 days];
uint256 public constant SUPPLY = 1_000_000_000 ether;
uint256 public aprBaseBps = 60_000; // 600% base APR (reflexive; owner-tunable, capped)
uint256 public constant APR_CAP_BPS = 700_000; // hard ceiling 7000%
struct Refraction { uint8 band; uint64 since; uint128 snapshot; uint128 settled; bool active; }
mapping(address => Refraction) public refr;
uint256 public totalRefracted; // sum of active snapshots
uint256 public totalPaid; // lifetime PRISM rewards paid
event Refracted(address indexed who, uint8 band, uint256 snapshot);
event UnRefracted(address indexed who, uint256 forfeited);
event Claimed(address indexed who, uint256 amount);
modifier onlyOwner() { require(msg.sender == owner, "only owner"); _; }
constructor(address _prism, address _owner) { prism = IERC20(_prism); owner = _owner; }
receive() external payable {} // accepts ETH refraction fees from the hook
/// @notice Effective APR (bps): base rate lifted by spectrum depth, up to 2x base, capped.
function effAprBps() public view returns (uint256 a) {
a = aprBaseBps + (aprBaseBps * totalRefracted) / SUPPLY;
if (a > APR_CAP_BPS) a = APR_CAP_BPS;
}
function _accrued(address u) internal view returns (uint256) {
Refraction storage r = refr[u];
if (!r.active) return 0;
uint256 elapsed = block.timestamp - r.since;
return uint256(r.snapshot) * effAprBps() / 10_000 * BAND_MULT[r.band] / 10_000 * elapsed / 365 days;
}
/// @notice Total claimable now (settled buffer + live accrual).
function pending(address u) public view returns (uint256) { return refr[u].settled + _accrued(u); }
/// @notice Refract the caller's wallet into `band` (0=Red/flex .. 6=Violet/180d). Snapshots balance.
function refract(uint8 band) external {
require(band < 7, "bad band");
Refraction storage r = refr[msg.sender];
if (r.active) { r.settled += uint128(_accrued(msg.sender)); totalRefracted -= r.snapshot; }
uint128 bal = uint128(prism.balanceOf(msg.sender));
require(bal > 0, "no PRISM");
r.band = band; r.since = uint64(block.timestamp); r.snapshot = bal; r.active = true;
totalRefracted += bal;
emit Refracted(msg.sender, band, bal);
}
/// @notice Stop refracting. Before the band term, accrued (unclaimed) reward is FORFEITED to the pool.
function unrefract() external {
Refraction storage r = refr[msg.sender];
require(r.active, "not refracted");
bool matured = block.timestamp >= r.since + BAND_DUR[r.band];
uint256 acc = _accrued(msg.sender);
uint256 forfeited = 0;
if (matured || r.band == 0) r.settled += uint128(acc); else forfeited = acc;
totalRefracted -= r.snapshot;
r.active = false; r.since = 0; r.snapshot = 0;
emit UnRefracted(msg.sender, forfeited);
}
/// @notice Claim PRISM rewards to the caller's wallet. Does NOT un-refract.
function claim() external {
uint256 amt = pending(msg.sender);
require(amt > 0, "nothing to claim");
Refraction storage r = refr[msg.sender];
r.settled = 0; if (r.active) r.since = uint64(block.timestamp);
uint256 pool = prism.balanceOf(address(this));
if (amt > pool) amt = pool;
require(amt > 0, "empty pool");
totalPaid += amt;
require(prism.transfer(msg.sender, amt), "transfer failed");
emit Claimed(msg.sender, amt);
}
// ---- funding / admin ----
function fund(uint256 amount) external { require(prism.transferFrom(msg.sender, address(this), amount), "fund failed"); }
function setAprBaseBps(uint256 bps) external onlyOwner { require(bps <= APR_CAP_BPS, "too high"); aprBaseBps = bps; }
function transferOwnership(address n) external onlyOwner { require(n != address(0), "zero"); owner = n; }
function withdrawEth(address to, uint256 amount) external onlyOwner { (bool ok,) = to.call{value: amount}(""); require(ok, "eth send failed"); }
// ---- views for the dApp ----
function refractionOf(address u) external view returns (uint8 band, uint64 since, uint256 snapshot, bool active, uint256 pendingPrism) {
Refraction storage r = refr[u];
return (r.band, r.since, r.snapshot, r.active, pending(u));
}
}
lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @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);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"optimizer": {
"runs": 800,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"solady/=lib/solady/",
"@openzeppelin/=lib/openzeppelin-contracts/",
"v4-core/=lib/v4-core/",
"v4-periphery/=lib/v4-periphery/",
"forge-std/=lib/forge-std/src/",
"@ensdomains/=lib/v4-core/node_modules/@ensdomains/",
"@uniswap/v4-core/=lib/v4-periphery/lib/v4-core/",
"ds-test/=lib/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"forge-gas-snapshot/=lib/v4-periphery/lib/permit2/lib/forge-gas-snapshot/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=lib/v4-core/node_modules/hardhat/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"permit2/=lib/v4-periphery/lib/permit2/",
"solmate/=lib/v4-core/lib/solmate/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.