Verified contractExactMIT
RiseSportsPoolEth
Address0xfb020e5595b28d414b7850957950e5d8a96c95fc
- Balance
0.00084 ETH
- Transactions
8
- Compiler
solc 0.8.34
- Same code
Only this contract
Details
- Compiler
- solc 0.8.34+commit.80d5c536
- Language
- solidity
- Optimization
- No
- License
- MIT
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 24,994,975
- Creation transaction
- 0x952b2e4a07…923964b2c4
RiseSportsPoolEth.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* RiseSportsPoolEth — P2P parimutuel 1X2 football-style pools in native ETH.
*
* - Anyone creates a pool with a `bytes32 fixtureRef` (off-chain: keccak256("rise:fb:v1:" | matchId)) and `lockAt` (unix).
* - Until `lockAt`, wallets stake on outcome 0=home, 1=draw, 2=away.
* - Each stake: 3% (300 bps) of gross `msg.value` goes to `feeRecipient` (same rounding pattern as Rise desk relay),
* remainder enters the pool pot for that outcome.
* - After kickoff (`lockAt` passed), `owner` settles the winning outcome. Entire combined pot is paid proportionally to
* winners; losers forfeit stakes (classic parimutuel).
*
* Deploy (MetaMask wallet / Remix / Foundry): `new RiseSportsPoolEth(feeRecipient)` where `feeRecipient` is your
* Rise ETH treasury (`PAYMENT_RECEIVER_ETH` / marketing wallet — same sink as desk fee).
*
* Configure the static site with:
* `<meta name="rise-sports-pool-eth" content="0x…deployed_address…">`
*/
contract RiseSportsPoolEth {
uint256 public constant FEE_BPS = 300;
uint8 public constant RESULT_UNSET = type(uint8).max;
address public feeRecipient;
address public owner;
uint256 public nextPoolId = 1;
struct Pool {
bytes32 fixtureRef;
uint64 lockAt;
uint8 result;
uint64 settledAt;
uint256 pot;
uint256 winTotal;
}
mapping(uint256 => Pool) public pools;
mapping(uint256 => uint256[3]) private stakeOf;
mapping(uint256 => mapping(address => uint256[3])) private userStakeOf;
/// Latest pool index for a fixture ref (many pools allowed historically; UX reads this).
mapping(bytes32 => uint256) public latestPoolByFixture;
error Auth();
error BadOutcome();
error TooLate();
error TooEarlySettle();
error NotSettled();
error NothingToClaim();
error FeeFailed();
error PayFailed();
error BadLock();
error ZeroValue();
error NoWinners();
error BadPool();
error PoolClosed();
error AlreadySettled();
modifier onlyOwner() {
if (msg.sender != owner) revert Auth();
_;
}
constructor(address _feeRecipient) {
require(_feeRecipient != address(0), "fee");
feeRecipient = _feeRecipient;
owner = msg.sender;
}
receive() external payable {}
event PoolCreated(uint256 indexed poolId, bytes32 indexed fixtureRef, uint64 lockAt, address creator);
event Staked(
uint256 indexed poolId,
address indexed user,
uint8 outcome,
uint256 grossWei,
uint256 netWei,
uint256 feeWei
);
event Settled(uint256 indexed poolId, uint8 winningOutcome, uint256 potWei, uint256 winSideWei);
event Claimed(uint256 indexed poolId, address indexed user, uint256 payWei);
function transferOwnership(address next) external onlyOwner {
require(next != address(0), "own");
owner = next;
}
function setFeeRecipient(address next) external onlyOwner {
require(next != address(0), "fee");
feeRecipient = next;
}
function stakes(uint256 poolId) external view returns (uint256 s0, uint256 s1, uint256 s2) {
uint256[3] storage s = stakeOf[poolId];
return (s[0], s[1], s[2]);
}
function userStake(
uint256 poolId,
address user,
uint8 outcome
) external view returns (uint256) {
if (outcome > 2) return 0;
return userStakeOf[poolId][user][outcome];
}
function createPool(bytes32 fixtureRef, uint64 lockAt) external returns (uint256 poolId) {
if (fixtureRef == bytes32(0)) revert BadLock();
if (lockAt <= block.timestamp) revert BadLock();
poolId = nextPoolId++;
pools[poolId] = Pool({
fixtureRef: fixtureRef,
lockAt: lockAt,
result: RESULT_UNSET,
settledAt: 0,
pot: 0,
winTotal: 0
});
latestPoolByFixture[fixtureRef] = poolId;
emit PoolCreated(poolId, fixtureRef, lockAt, msg.sender);
}
function stake(uint256 poolId, uint8 outcome) external payable {
if (poolId == 0 || poolId >= nextPoolId) revert BadPool();
if (outcome > 2) revert BadOutcome();
Pool storage p = pools[poolId];
if (p.result != RESULT_UNSET) revert PoolClosed();
if (block.timestamp > p.lockAt) revert TooLate();
uint256 gross = msg.value;
if (gross == 0) revert ZeroValue();
uint256 fee = (gross * FEE_BPS + 9999) / 10_000;
uint256 net = gross - fee;
if (net == 0) revert ZeroValue();
(bool okFee, ) = feeRecipient.call{value: fee}("");
if (!okFee) revert FeeFailed();
stakeOf[poolId][outcome] += net;
userStakeOf[poolId][msg.sender][outcome] += net;
emit Staked(poolId, msg.sender, outcome, gross, net, fee);
}
function settle(uint256 poolId, uint8 winningOutcome) external onlyOwner {
if (poolId == 0 || poolId >= nextPoolId) revert BadPool();
if (winningOutcome > 2) revert BadOutcome();
Pool storage p = pools[poolId];
if (p.result != RESULT_UNSET) revert AlreadySettled();
if (block.timestamp < p.lockAt) revert TooEarlySettle();
uint256 s0 = stakeOf[poolId][0];
uint256 s1 = stakeOf[poolId][1];
uint256 s2 = stakeOf[poolId][2];
uint256 winSide = winningOutcome == 0 ? s0 : (winningOutcome == 1 ? s1 : s2);
if (winSide == 0) revert NoWinners();
uint256 pot = s0 + s1 + s2;
p.pot = pot;
p.winTotal = winSide;
p.result = winningOutcome;
p.settledAt = uint64(block.timestamp);
emit Settled(poolId, winningOutcome, pot, winSide);
}
function claim(uint256 poolId) external {
if (poolId == 0 || poolId >= nextPoolId) revert BadPool();
Pool storage p = pools[poolId];
if (p.result == RESULT_UNSET || p.result > 2) revert NotSettled();
uint8 w = p.result;
uint256 userW = userStakeOf[poolId][msg.sender][w];
if (userW == 0) revert NothingToClaim();
userStakeOf[poolId][msg.sender][w] = 0;
uint256 pay = (p.pot * userW) / p.winTotal;
if (pay == 0) revert NothingToClaim();
(bool ok, ) = payable(msg.sender).call{value: pay}("");
if (!ok) revert PayFailed();
emit Claimed(poolId, msg.sender, pay);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.