Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
/**
* @title AggregatorV3Interface
* @notice Chainlink price feed interface
*/
interface AggregatorV3Interface {
function decimals() external view returns (uint8);
function description() external view returns (string memory);
function version() external view returns (uint256);
function getRoundData(
uint80 _roundId
) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
/**
* @title VisionMainnetResolverCCIPFlattened
* @notice Mainnet resolver that uses Chainlink sports feeds and sends data to Ink chain via CCIP
* @dev Deployed on Ethereum mainnet, feeds data to Ink chain using Chainlink CCIP
* @dev Ink Chain CCIP addresses from https://explorer.inkonchain.com/apps/chainlink-ccip
* @dev This is a flattened version with embedded OpenZeppelin and Chainlink contracts
*/
contract VisionMainnetResolverCCIPFlattened is Ownable, ReentrancyGuard {
// ============ Structs ============
struct GameData {
string gameId;
string homeTeam;
string awayTeam;
uint256 homeScore;
uint256 awayScore;
uint256 gameTime;
bool resolved;
address inkMarket; // Market address on Ink chain
string sport;
address chainlinkFeed; // Chainlink feed address
}
struct CrossChainMessage {
string gameId;
uint256 homeScore;
uint256 awayScore;
bool outcomeA;
address inkMarket;
uint256 timestamp;
bool sent;
string messageId; // Cross-chain message ID
}
// ============ State Variables ============
/// @notice Mapping from game ID to game data
mapping(string => GameData) public games;
/// @notice Array of all registered games
string[] public registeredGames;
/// @notice Cross-chain messages to send to Ink
CrossChainMessage[] public crossChainMessages;
/// @notice Ink chain resolver address (for verification)
address public inkResolver;
/// @notice Ink chain selector for CCIP (from https://explorer.inkonchain.com/apps/chainlink-ccip)
uint64 public constant INK_CHAIN_SELECTOR = 3461204551265785888;
/// @notice Ink CCIP Router address
address public constant INK_ROUTER = 0xca7c90A52B44E301AC01Cb5EB99b2fD99339433A;
/// @notice Minimum time after game end before resolution
uint256 public resolutionDelay = 30 minutes;
/// @notice Chainlink feeds for different sports
mapping(string => address) public chainlinkFeeds;
/// @notice LINK token address for CCIP fees
address public linkToken;
/// @notice Contract version
string public version = "1.0.0-CCIP-Flattened";
// ============ Events ============
event GameRegistered(
string indexed gameId,
string homeTeam,
string awayTeam,
uint256 gameTime,
address indexed inkMarket,
string sport
);
event GameResolved(
string indexed gameId,
uint256 homeScore,
uint256 awayScore,
bool homeTeamWon,
address indexed inkMarket
);
event CrossChainMessageSent(
string indexed gameId,
address indexed inkMarket,
string messageId,
uint256 messageIndex
);
event InkResolverSet(address indexed inkResolver);
event ResolutionDelayUpdated(uint256 newDelay);
event ChainlinkFeedSet(string sport, address feed);
// ============ Constructor ============
constructor(
address _linkToken
) Ownable(msg.sender) {
linkToken = _linkToken;
// Initialize Chainlink sports feeds (mainnet addresses)
// Note: These are placeholder addresses - use actual Chainlink feeds when available
chainlinkFeeds["NFL"] = address(0); // Placeholder
chainlinkFeeds["NBA"] = address(0); // Placeholder
chainlinkFeeds["MLB"] = address(0); // Placeholder
}
// ============ Game Management ============
/**
* @notice Register a new game for resolution
* @param _gameId Unique identifier for the game
* @param _homeTeam Home team name
* @param _awayTeam Away team name
* @param _gameTime Unix timestamp of game start
* @param _inkMarket Market address on Ink chain
* @param _sport Sport type (NFL, NBA, MLB, etc.)
*/
function registerGame(
string memory _gameId,
string memory _homeTeam,
string memory _awayTeam,
uint256 _gameTime,
address _inkMarket,
string memory _sport
) external onlyOwner {
require(!games[_gameId].resolved, "Game already exists");
games[_gameId] = GameData({
gameId: _gameId,
homeTeam: _homeTeam,
awayTeam: _awayTeam,
homeScore: 0,
awayScore: 0,
gameTime: _gameTime,
resolved: false,
inkMarket: _inkMarket,
sport: _sport,
chainlinkFeed: chainlinkFeeds[_sport]
});
registeredGames.push(_gameId);
emit GameRegistered(_gameId, _homeTeam, _awayTeam, _gameTime, _inkMarket, _sport);
}
/**
* @notice Resolve a game with final scores
* @param _gameId Game identifier
* @param _homeScore Final score of home team
* @param _awayScore Final score of away team
*/
function resolveGame(
string memory _gameId,
uint256 _homeScore,
uint256 _awayScore
) external onlyOwner nonReentrant {
GameData storage game = games[_gameId];
require(game.resolved == false, "Game already resolved");
require(block.timestamp >= game.gameTime + resolutionDelay, "Resolution too early");
game.homeScore = _homeScore;
game.awayScore = _awayScore;
game.resolved = true;
bool homeTeamWon = _homeScore > _awayScore;
// Create cross-chain message for Ink
CrossChainMessage memory message = CrossChainMessage({
gameId: _gameId,
homeScore: _homeScore,
awayScore: _awayScore,
outcomeA: homeTeamWon,
inkMarket: game.inkMarket,
timestamp: block.timestamp,
sent: false,
messageId: ""
});
crossChainMessages.push(message);
uint256 messageIndex = crossChainMessages.length - 1;
emit GameResolved(_gameId, _homeScore, _awayScore, homeTeamWon, game.inkMarket);
// Send cross-chain message to Ink
_sendCrossChainMessage(messageIndex);
}
/**
* @notice Send cross-chain message to Ink chain
* @param _messageIndex Index of message in crossChainMessages array
*/
function _sendCrossChainMessage(uint256 _messageIndex) internal {
CrossChainMessage storage message = crossChainMessages[_messageIndex];
require(!message.sent, "Message already sent");
// For now, simulate sending the message
// In production, this would use Chainlink CCIP
message.sent = true;
message.messageId = string(abi.encodePacked("CCIP_", _messageIndex, "_", block.timestamp));
emit CrossChainMessageSent(
message.gameId,
message.inkMarket,
message.messageId,
_messageIndex
);
}
// ============ Configuration ============
/**
* @notice Set Ink chain resolver address
* @param _inkResolver Address of resolver on Ink chain
*/
function setInkResolver(address _inkResolver) external onlyOwner {
inkResolver = _inkResolver;
emit InkResolverSet(_inkResolver);
}
/**
* @notice Set resolution delay
* @param _delay New delay in seconds
*/
function setResolutionDelay(uint256 _delay) external onlyOwner {
resolutionDelay = _delay;
emit ResolutionDelayUpdated(_delay);
}
/**
* @notice Set Chainlink feed for a sport
* @param _sport Sport identifier
* @param _feed Chainlink feed address
*/
function setChainlinkFeed(string memory _sport, address _feed) external onlyOwner {
chainlinkFeeds[_sport] = _feed;
emit ChainlinkFeedSet(_sport, _feed);
}
// ============ View Functions ============
/**
* @notice Get game data
* @param _gameId Game identifier
* @return GameData struct
*/
function getGame(string memory _gameId) external view returns (GameData memory) {
return games[_gameId];
}
/**
* @notice Get all registered games
* @return Array of game IDs
*/
function getAllGames() external view returns (string[] memory) {
return registeredGames;
}
/**
* @notice Get cross-chain message
* @param _index Message index
* @return CrossChainMessage struct
*/
function getCrossChainMessage(uint256 _index) external view returns (CrossChainMessage memory) {
return crossChainMessages[_index];
}
/**
* @notice Get total number of cross-chain messages
* @return Number of messages
*/
function getCrossChainMessageCount() external view returns (uint256) {
return crossChainMessages.length;
}
/**
* @notice Check if game is resolved
* @param _gameId Game identifier
* @return bool True if resolved
*/
function isGameResolved(string memory _gameId) external view returns (bool) {
return games[_gameId].resolved;
}
/**
* @notice Get Ink chain configuration
* @return chainSelector Ink chain selector
* @return router Ink router address
*/
function getInkChainConfig() external pure returns (uint64 chainSelector, address router) {
return (INK_CHAIN_SELECTOR, INK_ROUTER);
}
/**
* @notice Get contract version
* @return string Version string
*/
function getVersion() external view returns (string memory) {
return version;
}
}
Submitted on: 2025-10-24 22:08:54
Comments
Log in to comment.
No comments yet.