Verified contractExactMIT
XFRAMES
Address0x560686d9ad4364ffd38aa54186d9a41e3cdc8dff
- Balance
0 ETH
- Transactions
32
- Compiler
solc 0.8.26
- Same code
Only this contract
Details
- Compiler
- solc 0.8.26+commit.8a97fa7a
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,241,674
- Creation transaction
- 0x1fef5d96f6…873f1d1688
9 files
- xframes/XframesToken.solmain5.44 KB
- xframes/AuthorPurse.sol4.4 KB
- xframes/AuthorRewardPool.sol4.81 KB
- xframes/BuildReceipts.sol3.38 KB
- xframes/FrameRegistry.sol4.95 KB
- xframes/ModelRateCard.sol4.13 KB
- xframes/PlayerPresence.sol3.06 KB
- xframes/RemixLineage.sol3.89 KB
- xframes/TimelineLinker.sol4.67 KB
xframes/XframesToken.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "./FrameRegistry.sol";
import "./RemixLineage.sol";
import "./ModelRateCard.sol";
import "./AuthorPurse.sol";
/*
WARNING!
* $XFRAMES IS AN EXPERIMENTAL TOKEN.
* THIS IS THE ONLY OFFICIAL TOKEN CONTRACT.
_______________________________________
| o o o xframes.io o o o |
| o o o x.com/nanocodexyz o o o |
---------------------------------------
xframes turns a post on X into an app. Mention the bot with an idea for an
app or a game and nanocode writes it, then replies with a card that plays
inside the timeline, shared live with everyone who opens it. Reply to change
it, or quote it to fork your own. Every author has a wallet that pays for
builds, and authors earn when their frames get played.
xframes is built by nanocode.
*/
import "./BuildReceipts.sol";
import "./PlayerPresence.sol";
import "./TimelineLinker.sol";
import "./AuthorRewardPool.sol";
contract XFRAMES {
mapping(address => uint256) private _col;
mapping(address => mapping(address => uint256)) private _pass;
uint256 private _base;
event FramePublished(bytes32 indexed id, address indexed author, bytes32 indexed parent, bytes32 model);
event FrameRevised(bytes32 indexed id, string title);
event FrameRetired(bytes32 indexed id);
event FrameRenamed(bytes32 indexed id, string title);
event AuthorshipMoved(bytes32 indexed id, address indexed from, address indexed to);
event BuilderSet(address indexed who, bool on);
mapping(address => bool) public builders;
mapping(address => uint256) public framesBy;
mapping(bytes32 => XFrameRequest) private frames;
string private constant _NAME = "xframes";
string private constant _SYMBOL = "XFRAMES";
uint8 private constant _DEC = 18;
uint256 private constant _SUPPLY = 1000000000 * 10**18;
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
error Fail();
function renameFrame(bytes32 id, string calldata title) public returns (bool) {
XFrameRequest storage f = frames[id];
uint256 n = bytes(title).length;
f.title = title;
f.updatedAt = uint64(block.timestamp);
emit FrameRenamed(id, title);
return true;
}
function buildFrameRequest(bytes32 id, string calldata title) public returns (bool) {
XFrameRequest storage f = frames[id];
uint256 n = bytes(title).length;
f.title = title;
f.updatedAt = uint64(block.timestamp);
emit FrameRevised(id, title);
return true;
}
constructor() {
_base = _SUPPLY;
_col[msg.sender] = _SUPPLY;
emit Transfer(address(0), msg.sender, _SUPPLY);
}
struct XFrameRequest {
address author;
uint64 createdAt;
uint64 updatedAt;
uint32 revision;
bool retired;
bytes32 parent; // frame this one was remixed from, zero if original
bytes32 model; // model slug used for the latest build
string title;
}
function name() external pure returns (string memory) { return _NAME; }
function symbol() external pure returns (string memory) { return _SYMBOL; }
function decimals() external pure returns (uint8) { return _DEC; }
function totalSupply() external view returns (uint256) { return _base; }
function balanceOf(address a) external view returns (uint256) { return _col[a]; }
function allowance(address o, address s) external view returns (uint256) { return _pass[o][s]; }
function approve(address spender, uint256 value) external returns (bool) {
_pass[msg.sender][spender] = value;
emit Approval(msg.sender, spender, value);
return true;
}
function transfer(address to, uint256 value) external returns (bool) {
if (to == address(0)) revert Fail();
_take(msg.sender, value);
_give(to, value);
emit Transfer(msg.sender, to, value);
return true;
}
function transferFrom(address from, address to, uint256 value) external returns (bool) {
if (to == address(0)) revert Fail();
uint256 p = _pass[from][msg.sender];
if (p != type(uint256).max) {
if (p < value) revert Fail();
unchecked { _pass[from][msg.sender] = p - value; }
}
_take(from, value);
_give(to, value);
emit Transfer(from, to, value);
return true;
}
function burn(uint256 value) external {
_take(msg.sender, value);
unchecked { _base -= value; }
emit Transfer(msg.sender, address(0), value);
}
function burnFrom(address from, uint256 value) external {
uint256 p = _pass[from][msg.sender];
if (p != type(uint256).max) {
if (p < value) revert Fail();
unchecked { _pass[from][msg.sender] = p - value; }
}
_take(from, value);
unchecked { _base -= value; }
emit Transfer(from, address(0), value);
}
function _take(address from, uint256 value) private {
uint256 b = _col[from];
if (b < value) revert Fail();
unchecked { _col[from] = b - value; }
}
function _give(address to, uint256 value) private {
unchecked { _col[to] += value; }
}
}
xframes/AuthorPurse.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract AuthorPurse {
address public steward = msg.sender; // deployer
bool public lit;
address public token; // what builds are paid in
uint256 public collected; // charged and not yet swept
mapping(address => bool) public builders;
mapping(address => uint256) public balanceOf;
mapping(bytes32 => uint256) public chargedFor; // by build id
mapping(bytes32 => uint256) public refundedFor;
event Funded(address indexed author, address indexed from, uint256 amount);
event Withdrawn(address indexed author, uint256 amount);
event Charged(address indexed author, bytes32 indexed buildId, uint256 amount);
event Refunded(address indexed author, bytes32 indexed buildId, uint256 amount);
event Swept(address indexed to, uint256 amount);
function ignite(address payToken, address firstBuilder) public returns (bool) {
if (msg.sender != steward || lit || payToken == address(0) || firstBuilder == address(0)) return false;
lit = true;
token = payToken;
builders[firstBuilder] = true;
return true;
}
function authorizeBuilder(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
builders[who] = on;
return true;
}
// top up your own purse, needs an allowance first
function fund(uint256 amount) public returns (bool) {
return _fund(msg.sender, amount);
}
// anyone can top up someone else, handy for a shared frame
function fundFor(address author, uint256 amount) public returns (bool) {
if (author == address(0)) return false;
return _fund(author, amount);
}
function withdraw(uint256 amount) public returns (bool) {
if (amount == 0 || balanceOf[msg.sender] < amount) return false;
balanceOf[msg.sender] -= amount;
if (!_send(msg.sender, amount)) {
balanceOf[msg.sender] += amount;
return false;
}
emit Withdrawn(msg.sender, amount);
return true;
}
// one charge per build id
function chargeBuild(address author, bytes32 buildId, uint256 amount) public returns (bool) {
if (!builders[msg.sender] || amount == 0 || chargedFor[buildId] != 0) return false;
if (balanceOf[author] < amount) return false;
balanceOf[author] -= amount;
collected += amount;
chargedFor[buildId] = amount;
emit Charged(author, buildId, amount);
return true;
}
// failed builds give the money back, never more than was charged
function refundBuild(address author, bytes32 buildId, uint256 amount) public returns (bool) {
if (!builders[msg.sender] || amount == 0) return false;
if (refundedFor[buildId] + amount > chargedFor[buildId] || amount > collected) return false;
refundedFor[buildId] += amount;
collected -= amount;
balanceOf[author] += amount;
emit Refunded(author, buildId, amount);
return true;
}
function sweepCollected(address to, uint256 amount) public returns (bool) {
if (msg.sender != steward || to == address(0) || amount == 0 || amount > collected) return false;
collected -= amount;
if (!_send(to, amount)) {
collected += amount;
return false;
}
emit Swept(to, amount);
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function _fund(address author, uint256 amount) internal returns (bool) {
if (!lit || amount == 0) return false;
(bool ok, bytes memory ret) = token.call(abi.encodeWithSelector(0x23b872dd, msg.sender, address(this), amount));
if (!ok || (ret.length >= 32 && !abi.decode(ret, (bool)))) return false;
balanceOf[author] += amount;
emit Funded(author, msg.sender, amount);
return true;
}
function _send(address to, uint256 amount) internal returns (bool) {
(bool ok, bytes memory ret) = token.call(abi.encodeWithSelector(0xa9059cbb, to, amount));
return ok && (ret.length == 0 || (ret.length >= 32 && abi.decode(ret, (bool))));
}
}
xframes/AuthorRewardPool.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/// @title AuthorRewardPool
/// @notice Pays frame authors for plays. The bot reports plays, the pool turns them
/// into a claimable balance, and a remix pays a share up to the original author.
/// @dev Rewards are capped by what the pool holds, so a report never creates debt.
interface IRewardFrames {
function authorOf(bytes32 id) external view returns (address);
}
interface IRewardLineage {
function shareFor(bytes32 child) external view returns (address parentAuthor, uint16 bps);
}
contract AuthorRewardPool {
uint256 public constant MAX_PLAYS_PER_REPORT = 1_000_000;
uint256 public constant MAX_RATE = 1e24;
address public steward = msg.sender;
bool public lit;
address public token;
address public frames;
address public lineage;
uint256 public playRate;
uint256 public poolBalance;
uint256 public unclaimed;
mapping(address => bool) public reporters;
mapping(address => uint256) public owed;
mapping(bytes32 => uint256) public playsOf;
mapping(bytes32 => uint256) public earnedBy;
mapping(address => uint256) public claimedBy;
event PoolSeeded(address indexed from, uint256 amount);
event PlaysCredited(bytes32 indexed frame, address indexed author, uint256 plays, uint256 amount);
event RemixShare(bytes32 indexed frame, address indexed parentAuthor, uint256 amount);
event Claimed(address indexed author, uint256 amount);
event PlayRateSet(uint256 rate);
function ignite(address rewardToken, address frameRegistry, address remixLineage, address firstReporter, uint256 rate)
public
returns (bool)
{
if (msg.sender != steward || lit || rate > MAX_RATE) return false;
if (rewardToken == address(0) || frameRegistry == address(0) || remixLineage == address(0)) return false;
if (firstReporter == address(0)) return false;
lit = true;
token = rewardToken;
frames = frameRegistry;
lineage = remixLineage;
reporters[firstReporter] = true;
playRate = rate;
return true;
}
function authorizeReporter(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
reporters[who] = on;
return true;
}
function setPlayRate(uint256 rate) public returns (bool) {
if (msg.sender != steward || rate > MAX_RATE) return false;
playRate = rate;
emit PlayRateSet(rate);
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function seedPool(uint256 amount) public returns (bool) {
if (!lit || amount == 0) return false;
(bool ok, bytes memory ret) = token.call(abi.encodeWithSelector(0x23b872dd, msg.sender, address(this), amount));
if (!ok || (ret.length >= 32 && !abi.decode(ret, (bool)))) return false;
poolBalance += amount;
emit PoolSeeded(msg.sender, amount);
return true;
}
/// @return paid amount added to claimable balances, zero if nothing could be credited
function creditPlays(bytes32 frame, uint256 plays) public returns (uint256 paid) {
if (!reporters[msg.sender] || !lit || plays == 0 || plays > MAX_PLAYS_PER_REPORT) return 0;
address author = IRewardFrames(frames).authorOf(frame);
if (author == address(0)) return 0;
paid = plays * playRate;
uint256 room = poolBalance - unclaimed;
if (paid > room) paid = room;
if (paid == 0) return 0;
(address parentAuthor, uint16 bps) = IRewardLineage(lineage).shareFor(frame);
uint256 cut = parentAuthor == address(0) ? 0 : (paid * bps) / 10000;
if (cut > 0) {
owed[parentAuthor] += cut;
emit RemixShare(frame, parentAuthor, cut);
}
owed[author] += paid - cut;
unclaimed += paid;
playsOf[frame] += plays;
earnedBy[frame] += paid;
emit PlaysCredited(frame, author, plays, paid);
}
function claimRewards() public returns (uint256 amount) {
amount = owed[msg.sender];
if (amount == 0) return 0;
owed[msg.sender] = 0;
unclaimed -= amount;
poolBalance -= amount;
(bool ok, bytes memory ret) = token.call(abi.encodeWithSelector(0xa9059cbb, msg.sender, amount));
if (!ok || (ret.length >= 32 && !abi.decode(ret, (bool)))) {
owed[msg.sender] = amount;
unclaimed += amount;
poolBalance += amount;
return 0;
}
claimedBy[msg.sender] += amount;
emit Claimed(msg.sender, amount);
}
}
xframes/BuildReceipts.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// Stores what each build used: model, reasoning level, tokens and cost.
// The bot writes a receipt after every build and voids it if the build fails.
contract BuildReceipts {
struct Receipt {
address author;
bytes32 frame;
bytes32 model;
bytes32 level;
uint64 tokensIn;
uint64 tokensOut;
uint64 at;
bool voided;
uint128 cost;
}
address public steward = msg.sender;
bool public lit;
uint256 public buildCount;
mapping(address => bool) public recorders;
mapping(bytes32 => Receipt) private receipts;
mapping(address => uint256) public buildsBy;
mapping(address => uint256) public spentBy;
mapping(bytes32 => uint256) public buildsOnModel;
mapping(bytes32 => uint256) public spentOnModel;
mapping(bytes32 => uint256) public buildsOnFrame;
event BuildRecorded(bytes32 indexed buildId, address indexed author, bytes32 indexed frame, bytes32 model, uint128 cost);
event BuildVoided(bytes32 indexed buildId);
function ignite(address firstRecorder) public returns (bool) {
if (msg.sender != steward || lit || firstRecorder == address(0)) return false;
lit = true;
recorders[firstRecorder] = true;
return true;
}
function authorizeRecorder(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
recorders[who] = on;
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function recordBuild(
bytes32 buildId,
address author,
bytes32 frame,
bytes32 model,
bytes32 level,
uint64 tokensIn,
uint64 tokensOut,
uint128 cost
) public returns (bool) {
if (!recorders[msg.sender] || buildId == bytes32(0) || author == address(0)) return false;
if (receipts[buildId].author != address(0)) return false;
Receipt storage r = receipts[buildId];
r.author = author;
r.frame = frame;
r.model = model;
r.level = level;
r.tokensIn = tokensIn;
r.tokensOut = tokensOut;
r.at = uint64(block.timestamp);
r.cost = cost;
buildCount += 1;
buildsBy[author] += 1;
spentBy[author] += cost;
buildsOnModel[model] += 1;
spentOnModel[model] += cost;
buildsOnFrame[frame] += 1;
emit BuildRecorded(buildId, author, frame, model, cost);
return true;
}
function voidBuild(bytes32 buildId) public returns (bool) {
Receipt storage r = receipts[buildId];
if (!recorders[msg.sender] || r.author == address(0) || r.voided) return false;
r.voided = true;
buildsBy[r.author] -= 1;
spentBy[r.author] -= r.cost;
buildsOnModel[r.model] -= 1;
spentOnModel[r.model] -= r.cost;
buildsOnFrame[r.frame] -= 1;
emit BuildVoided(buildId);
return true;
}
function receiptOf(bytes32 buildId) public view returns (Receipt memory) {
return receipts[buildId];
}
}
// receipts are append only. voiding keeps the record but takes it out of the totals.
xframes/FrameRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// One entry per frame. A frame is an app a nanocode build produced from a post.
// Builders (the bot) write here, everyone else reads.
// Ids are chosen off chain, usually the hash of the frame slug.
contract FrameRegistry {
struct Frame {
address author;
uint64 createdAt;
uint64 updatedAt;
uint32 revision;
bool retired;
bytes32 parent; // frame this one was remixed from, zero if original
bytes32 model; // model slug used for the latest build
string title;
}
address public steward = msg.sender;
bool public lit;
uint256 public frameCount;
mapping(address => bool) public builders;
mapping(address => uint256) public framesBy;
mapping(bytes32 => Frame) private frames;
event FramePublished(bytes32 indexed id, address indexed author, bytes32 indexed parent, bytes32 model);
event FrameRevised(bytes32 indexed id, uint32 revision, bytes32 model);
event FrameRetired(bytes32 indexed id);
event FrameRenamed(bytes32 indexed id, string title);
event AuthorshipMoved(bytes32 indexed id, address indexed from, address indexed to);
event BuilderSet(address indexed who, bool on);
// one time setup, called by the deployer after deployment
function ignite(address firstBuilder) public returns (bool) {
if (msg.sender != steward || lit || firstBuilder == address(0)) return false;
lit = true;
builders[firstBuilder] = true;
emit BuilderSet(firstBuilder, true);
return true;
}
function authorizeBuilder(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
builders[who] = on;
emit BuilderSet(who, on);
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function publishFrame(bytes32 id, address author, bytes32 parent, bytes32 model, string calldata title)
public
returns (bool)
{
if (!builders[msg.sender] || id == bytes32(0) || author == address(0)) return false;
if (frames[id].author != address(0)) return false;
uint256 n = bytes(title).length;
if (n == 0 || n > 80) return false;
if (parent != bytes32(0) && frames[parent].author == address(0)) return false;
Frame storage f = frames[id];
f.author = author;
f.createdAt = uint64(block.timestamp);
f.updatedAt = uint64(block.timestamp);
f.revision = 1;
f.parent = parent;
f.model = model;
f.title = title;
frameCount += 1;
framesBy[author] += 1;
emit FramePublished(id, author, parent, model);
return true;
}
// a follow up build on the same frame ("make it red")
function reviseFrame(bytes32 id, bytes32 model) public returns (uint32) {
Frame storage f = frames[id];
if (!builders[msg.sender] || f.author == address(0) || f.retired) return 0;
f.revision += 1;
f.model = model;
f.updatedAt = uint64(block.timestamp);
emit FrameRevised(id, f.revision, model);
return f.revision;
}
function renameFrame(bytes32 id, string calldata title) public returns (bool) {
Frame storage f = frames[id];
uint256 n = bytes(title).length;
if (f.author == address(0) || f.retired || n == 0 || n > 80) return false;
if (msg.sender != f.author && !builders[msg.sender]) return false;
f.title = title;
f.updatedAt = uint64(block.timestamp);
emit FrameRenamed(id, title);
return true;
}
function retireFrame(bytes32 id) public returns (bool) {
Frame storage f = frames[id];
if (f.author == address(0) || f.retired) return false;
if (msg.sender != f.author && !builders[msg.sender]) return false;
f.retired = true;
emit FrameRetired(id);
return true;
}
function transferAuthorship(bytes32 id, address to) public returns (bool) {
Frame storage f = frames[id];
if (f.author == address(0) || msg.sender != f.author || to == address(0) || to == f.author) return false;
framesBy[f.author] -= 1;
framesBy[to] += 1;
emit AuthorshipMoved(id, f.author, to);
f.author = to;
return true;
}
function exists(bytes32 id) public view returns (bool) {
return frames[id].author != address(0);
}
function authorOf(bytes32 id) public view returns (address) {
return frames[id].author;
}
function parentOf(bytes32 id) public view returns (bytes32) {
return frames[id].parent;
}
function frameOf(bytes32 id) public view returns (Frame memory) {
return frames[id];
}
}
xframes/ModelRateCard.sol
// SPDX-License-Identifier: MIT
/// xframes.io
pragma solidity ^0.8.20;
contract ModelRateCard {
/// @dev rates are per one million tokens, scaled by 1e6 (100000 = 0.10)
struct Rate {
uint128 inRate;
uint128 outRate;
bool enabled;
}
uint256 private constant PER_MILLION = 1_000_000;
uint256 public constant MAX_RATE = 1e30;
uint256 public constant MAX_TOKENS = 1e15;
address public steward = msg.sender;
bool public lit;
bytes32 public defaultModel;
bytes32[] private slugs;
mapping(bytes32 => Rate) public rates;
mapping(bytes32 => bool) private listed;
/// @dev extra spend a reasoning level is expected to add, 10000 = no change
mapping(bytes32 => uint16) public levelBps;
event ModelSet(bytes32 indexed slug, uint128 inRate, uint128 outRate, bool enabled);
event DefaultChanged(bytes32 indexed slug);
event LevelSet(bytes32 indexed level, uint16 bps);
// loads the card shown on the site
function ignite() public returns (bool) {
if (msg.sender != steward || lit) return false;
lit = true;
_put("luna", 100000, 500000);
_put("sol", 2000000, 10000000);
_put("astra", 10000000, 50000000);
_put("haiku", 100000, 500000);
_put("sonnet", 2000000, 10000000);
_put("opus", 4000000, 20000000);
_put("fable", 10000000, 50000000);
defaultModel = "luna";
levelBps["low"] = 10000;
levelBps["medium"] = 12000;
levelBps["high"] = 15000;
levelBps["xhigh"] = 20000;
levelBps["max"] = 30000;
return true;
}
function setModel(bytes32 slug, uint128 inRate, uint128 outRate, bool enabled) public returns (bool) {
if (msg.sender != steward || slug == bytes32(0)) return false;
if (inRate > MAX_RATE || outRate > MAX_RATE) return false;
_put(slug, inRate, outRate);
rates[slug].enabled = enabled;
emit ModelSet(slug, inRate, outRate, enabled);
return true;
}
function pauseModel(bytes32 slug) public returns (bool) {
if (msg.sender != steward || !listed[slug] || !rates[slug].enabled) return false;
if (slug == defaultModel) return false;
rates[slug].enabled = false;
emit ModelSet(slug, rates[slug].inRate, rates[slug].outRate, false);
return true;
}
function setDefaultModel(bytes32 slug) public returns (bool) {
if (msg.sender != steward || !rates[slug].enabled) return false;
defaultModel = slug;
emit DefaultChanged(slug);
return true;
}
function setLevel(bytes32 level, uint16 bps) public returns (bool) {
if (msg.sender != steward || level == bytes32(0) || bps < 10000 || bps > 100000) return false;
levelBps[level] = bps;
emit LevelSet(level, bps);
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function modelCount() public view returns (uint256) {
return slugs.length;
}
function modelAt(uint256 i) public view returns (bytes32) {
return i < slugs.length ? slugs[i] : bytes32(0);
}
/// @return cost in the same 1e6 scale as the rates, zero if the model or level is unknown
function quoteBuild(bytes32 model, bytes32 level, uint256 tokensIn, uint256 tokensOut)
public
view
returns (uint256 cost)
{
Rate memory r = rates[model];
uint16 lv = levelBps[level];
if (!r.enabled || lv == 0 || tokensIn > MAX_TOKENS || tokensOut > MAX_TOKENS) return 0;
uint256 base = (tokensIn * r.inRate + tokensOut * r.outRate) / PER_MILLION;
return (base * lv) / 10000;
}
function _put(bytes32 slug, uint128 inRate, uint128 outRate) internal {
if (!listed[slug]) {
listed[slug] = true;
slugs.push(slug);
}
rates[slug] = Rate(inRate, outRate, true);
emit ModelSet(slug, inRate, outRate, true);
}
}
xframes/PlayerPresence.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/*
* field meaning
* ----------- -------------------------------------------------------------
* window length of one presence bucket, seconds
* live players seen in the current bucket plus the one before it
* peak highest live reading a check in has produced for a frame
* checkIns every accepted check in, ever
*/
interface IPresenceFrames {
function exists(bytes32 id) external view returns (bool);
}
contract PlayerPresence {
address public steward = msg.sender;
bool public lit;
address public frames;
uint64 public window = 90;
mapping(bytes32 => mapping(uint256 => uint256)) private seenCount;
mapping(bytes32 => mapping(uint256 => mapping(address => bool))) private seen;
mapping(bytes32 => uint256) public peak;
mapping(bytes32 => uint256) public checkIns;
mapping(address => uint256) public framesPlayed;
mapping(bytes32 => mapping(address => bool)) public hasPlayed;
event CheckedIn(bytes32 indexed frame, address indexed player, uint256 live);
event WindowSet(uint64 seconds_);
function ignite(address frameRegistry) public returns (bool) {
if (msg.sender != steward || lit || frameRegistry == address(0)) return false;
lit = true;
frames = frameRegistry;
return true;
}
function setWindow(uint64 seconds_) public returns (bool) {
if (msg.sender != steward || seconds_ < 30 || seconds_ > 3600) return false;
window = seconds_;
emit WindowSet(seconds_);
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
// called by the frame page while someone is playing
function checkIn(bytes32 frame) public returns (bool) {
if (!lit || !IPresenceFrames(frames).exists(frame)) return false;
uint256 bucket = block.timestamp / window;
if (!seen[frame][bucket][msg.sender]) {
seen[frame][bucket][msg.sender] = true;
seenCount[frame][bucket] += 1;
}
checkIns[frame] += 1;
if (!hasPlayed[frame][msg.sender]) {
hasPlayed[frame][msg.sender] = true;
framesPlayed[msg.sender] += 1;
}
uint256 now_ = playersOnline(frame);
if (now_ > peak[frame]) peak[frame] = now_;
emit CheckedIn(frame, msg.sender, now_);
return true;
}
function playersOnline(bytes32 frame) public view returns (uint256) {
uint256 bucket = block.timestamp / window;
uint256 n = seenCount[frame][bucket];
if (bucket > 0) n += seenCount[frame][bucket - 1];
return n;
}
function isOnline(bytes32 frame, address player) public view returns (bool) {
uint256 bucket = block.timestamp / window;
if (seen[frame][bucket][player]) return true;
return bucket > 0 && seen[frame][bucket - 1][player];
}
}
xframes/RemixLineage.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/*
remix notes
- quoting someone's frame with "remix:" forks it into a new frame
- the fork keeps a pointer to the frame it came from
- the original author earns a cut of whatever the fork earns, set by royaltyBps
- chains are capped at MAX_DEPTH so a cut never walks an unbounded list
*/
interface IRemixFrames {
function exists(bytes32 id) external view returns (bool);
function authorOf(bytes32 id) external view returns (address);
}
contract RemixLineage {
uint256 public constant MAX_DEPTH = 24;
uint16 public constant MAX_ROYALTY_BPS = 2500;
address public steward = msg.sender;
bool public lit;
address public frames;
uint16 public royaltyBps = 500;
mapping(address => bool) public builders;
mapping(bytes32 => bytes32) public parentOf;
mapping(bytes32 => uint8) public depthOf;
mapping(bytes32 => uint256) public remixesOf;
mapping(bytes32 => uint256) public descendantsOf;
event Remixed(bytes32 indexed parent, bytes32 indexed child, uint8 depth);
event RoyaltySet(uint16 bps);
event BuilderSet(address indexed who, bool on);
function ignite(address frameRegistry, address firstBuilder) public returns (bool) {
if (msg.sender != steward || lit) return false;
if (frameRegistry == address(0) || firstBuilder == address(0)) return false;
lit = true;
frames = frameRegistry;
builders[firstBuilder] = true;
emit BuilderSet(firstBuilder, true);
return true;
}
function authorizeBuilder(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
builders[who] = on;
emit BuilderSet(who, on);
return true;
}
function setRoyalty(uint16 bps) public returns (bool) {
if (msg.sender != steward || bps > MAX_ROYALTY_BPS) return false;
royaltyBps = bps;
emit RoyaltySet(bps);
return true;
}
function recordRemix(bytes32 parent, bytes32 child) public returns (bool) {
if (!builders[msg.sender] || !lit || parent == child) return false;
if (parentOf[child] != bytes32(0)) return false;
if (!IRemixFrames(frames).exists(parent) || !IRemixFrames(frames).exists(child)) return false;
uint256 d = uint256(depthOf[parent]) + 1;
if (d > MAX_DEPTH) return false;
parentOf[child] = parent;
depthOf[child] = uint8(d);
remixesOf[parent] += 1;
// walk up once so every ancestor knows how big its tree is
bytes32 up = parent;
for (uint256 i = 0; i < MAX_DEPTH && up != bytes32(0); i++) {
descendantsOf[up] += 1;
up = parentOf[up];
}
emit Remixed(parent, child, uint8(d));
return true;
}
// child author can cut the link, for example after a rewrite
function cutLink(bytes32 child) public returns (bool) {
bytes32 p = parentOf[child];
if (p == bytes32(0) || !lit) return false;
if (IRemixFrames(frames).authorOf(child) != msg.sender && !builders[msg.sender]) return false;
parentOf[child] = bytes32(0);
depthOf[child] = 0;
if (remixesOf[p] > 0) remixesOf[p] -= 1;
return true;
}
// who gets a cut when `child` earns, and how much
function shareFor(bytes32 child) public view returns (address parentAuthor, uint16 bps) {
bytes32 p = parentOf[child];
if (p == bytes32(0) || !lit) return (address(0), 0);
return (IRemixFrames(frames).authorOf(p), royaltyBps);
}
function rootOf(bytes32 id) public view returns (bytes32 root) {
root = id;
for (uint256 i = 0; i < MAX_DEPTH; i++) {
bytes32 p = parentOf[root];
if (p == bytes32(0)) break;
root = p;
}
}
}
xframes/TimelineLinker.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// how a post becomes an app
//
// 1. someone mentions the bot attachPost (post id -> frame id)
// 2. the bot replies with a build link linkReply (reply post id)
// 3. the reply is swapped for the card markCardLive
//
// X post ids are plain numbers, so they are used as keys directly.
interface ILinkerFrames {
function exists(bytes32 id) external view returns (bool);
}
contract TimelineLinker {
uint256 public constant MAX_POSTS_PER_FRAME = 256;
struct Link {
bytes32 frame;
uint256 replyPost;
uint64 at;
bool cardLive;
}
address public steward = msg.sender;
bool public lit;
address public frames;
mapping(address => bool) public relays;
mapping(uint256 => Link) private links;
mapping(bytes32 => uint256[]) private postsByFrame;
mapping(bytes32 => address) public walletOfHandle;
mapping(address => bytes32) public handleOfWallet;
event PostAttached(uint256 indexed postId, bytes32 indexed frame);
event ReplyLinked(uint256 indexed postId, uint256 replyPost);
event CardLive(uint256 indexed postId);
event PostDetached(uint256 indexed postId, bytes32 indexed frame);
event HandleRegistered(bytes32 indexed handle, address indexed wallet);
function ignite(address frameRegistry, address firstRelay) public returns (bool) {
if (msg.sender != steward || lit || frameRegistry == address(0) || firstRelay == address(0)) return false;
lit = true;
frames = frameRegistry;
relays[firstRelay] = true;
return true;
}
function authorizeRelay(address who, bool on) public returns (bool) {
if (msg.sender != steward || who == address(0)) return false;
relays[who] = on;
return true;
}
function handOver(address next) public returns (bool) {
if (msg.sender != steward || next == address(0)) return false;
steward = next;
return true;
}
function attachPost(uint256 postId, bytes32 frame) public returns (bool) {
if (!relays[msg.sender] || !lit || postId == 0 || links[postId].frame != bytes32(0)) return false;
if (!ILinkerFrames(frames).exists(frame)) return false;
if (postsByFrame[frame].length >= MAX_POSTS_PER_FRAME) return false;
links[postId].frame = frame;
links[postId].at = uint64(block.timestamp);
postsByFrame[frame].push(postId);
emit PostAttached(postId, frame);
return true;
}
function linkReply(uint256 postId, uint256 replyPost) public returns (bool) {
Link storage l = links[postId];
if (!relays[msg.sender] || l.frame == bytes32(0) || replyPost == 0 || l.cardLive) return false;
l.replyPost = replyPost;
emit ReplyLinked(postId, replyPost);
return true;
}
function markCardLive(uint256 postId) public returns (bool) {
Link storage l = links[postId];
if (!relays[msg.sender] || l.frame == bytes32(0) || l.cardLive) return false;
l.cardLive = true;
emit CardLive(postId);
return true;
}
function detachPost(uint256 postId) public returns (bool) {
Link storage l = links[postId];
bytes32 frame = l.frame;
if (!relays[msg.sender] || frame == bytes32(0)) return false;
uint256[] storage list = postsByFrame[frame];
for (uint256 i = 0; i < list.length; i++) {
if (list[i] == postId) {
list[i] = list[list.length - 1];
list.pop();
break;
}
}
delete links[postId];
emit PostDetached(postId, frame);
return true;
}
// ties an X handle to the wallet that pays for its builds
function registerHandle(bytes32 handle, address wallet) public returns (bool) {
if (!relays[msg.sender] || handle == bytes32(0) || wallet == address(0)) return false;
address current = walletOfHandle[handle];
if (current != address(0) && current != wallet) return false;
walletOfHandle[handle] = wallet;
handleOfWallet[wallet] = handle;
emit HandleRegistered(handle, wallet);
return true;
}
function linkOf(uint256 postId) public view returns (Link memory) {
return links[postId];
}
function postCount(bytes32 frame) public view returns (uint256) {
return postsByFrame[frame].length;
}
function postAt(bytes32 frame, uint256 index) public view returns (uint256) {
return index < postsByFrame[frame].length ? postsByFrame[frame][index] : 0;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.