PunkStrategy33ETHResolver

Description:

Smart contract deployed on Ethereum with Factory features.

Blockchain: Ethereum

Source Code: View Code On The Blockchain

Solidity Source Code:

{{
  "language": "Solidity",
  "sources": {
    "src/PunkStrategy33ETHResolver.sol": {
      "content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.30;

/// @notice Minimal interface to the provided PredictionMarket.
interface IPredictionMarketMinimal {
    function closeMarket(uint256 marketId) external;
    function resolve(uint256 marketId, bool outcome) external;
    function tradingOpen(uint256 marketId) external view returns (bool);
    function getMarket(uint256 marketId)
        external
        view
        returns (
            uint256 yesSupply,
            uint256 noSupply,
            address resolver,
            bool resolved,
            bool outcome,
            uint256 pot,
            uint256 payoutPerShare,
            string memory desc
        );
}

/**
 * @title PunkStrategy33ETHResolver
 * @notice Resolves: "Will PunkStrategy hold >= 33 ETH at or after timestamp 1759766666?"
 * Rules:
 *  - Pre-T: if balance >= 33 ETH and market open -> close now & resolve YES.
 *  - Otherwise, NO resolution before T (even if market is already closed).
 *  - At/after T: close if open, snapshot once, resolve YES if snapshot >= 33 ETH.
 */
contract PunkStrategy33ETHResolver {
    // ------------------ HARD-CODED CONFIG ------------------
    address public constant PM_ADDR = 0x0000000000337f99F242D11AF1908469B0424C8D;
    address public constant PUNK_STRATEGY = 0xc50673EDb3A7b94E8CAD8a7d4E0cD68864E33eDF;
    uint256 public constant THRESHOLD_WEI = 33_000000000000000000; // 33 ETH
    uint256 public constant TARGET_TS = 1759766666; // evaluation time

    // ------------------ STATE ------------------
    IPredictionMarketMinimal private constant PM = IPredictionMarketMinimal(PM_ADDR);
    uint256 public marketId; // set once via link()
    uint256 public observedBalanceWei; // first snapshot used for outcome
    bool public observed; // sticky once set

    // ------------------ EVENTS ------------------
    event Linked(uint256 indexed marketId);
    event Closed(uint256 indexed marketId, uint256 atTs);
    event Observed(uint256 balanceWei, uint256 atTs);
    event Resolved(uint256 indexed marketId, bool outcome, uint256 usedBalanceWei);

    // ------------------ ERRORS ------------------
    error AlreadyLinked();
    error NotLinked();
    error WrongResolver();
    error TooEarly();

    /// @notice One-time link; verifies this contract is the market's resolver.
    function link(uint256 _marketId) external {
        if (marketId != 0) revert AlreadyLinked();
        (,, address resolver,,,,,) = PM.getMarket(_marketId);
        if (resolver != address(this)) revert WrongResolver();
        marketId = _marketId;
        emit Linked(_marketId);
    }

    /// @notice Idempotent automation entrypoint.
    /// - Pre-T: if balance >= threshold and open -> close & resolve YES.
    /// - Before T otherwise: revert TooEarly (prevents last-minute gaming).
    /// - At/after T: close if open, snapshot if needed, resolve(snapshot >= threshold).
    function poke() external {
        uint256 id = marketId;
        if (id == 0) revert NotLinked();

        (,,, bool isResolved,,,,) = PM.getMarket(id);
        if (isResolved) return;

        bool isOpen = PM.tradingOpen(id);
        uint256 bal = address(PUNK_STRATEGY).balance;

        // EARLY YES: before TARGET_TS, threshold hit and market open.
        if (block.timestamp < TARGET_TS && isOpen && bal >= THRESHOLD_WEI) {
            _observeOnce(bal);
            PM.closeMarket(id); // requires market created with canClose = true
            emit Closed(id, block.timestamp);
            PM.resolve(id, true);
            emit Resolved(id, true, observedBalanceWei);
            return;
        }

        // BEFORE T but not early-YES: do not resolve (prevents last-minute gaming).
        if (block.timestamp < TARGET_TS) {
            revert TooEarly();
        }

        // AT/AFTER T: close first (if open), then resolve from snapshot.
        if (isOpen) {
            _observeOnce(bal);
            PM.closeMarket(id);
            emit Closed(id, block.timestamp);
        }
        if (!observed) _observeOnce(bal);
        bool outcome = (observedBalanceWei >= THRESHOLD_WEI);
        PM.resolve(id, outcome);
        emit Resolved(id, outcome, observedBalanceWei);
    }

    // ------------------ INTERNAL ------------------
    function _observeOnce(uint256 bal) internal {
        if (!observed) {
            observed = true;
            observedBalanceWei = bal;
            emit Observed(bal, block.timestamp);
        }
    }
}
"
    }
  },
  "settings": {
    "remappings": [
      "@solady/=lib/solady/",
      "@soledge/=lib/soledge/",
      "@forge/=lib/forge-std/src/",
      "forge-std/=lib/forge-std/src/",
      "solady/=lib/solady/src/"
    ],
    "optimizer": {
      "enabled": true,
      "runs": 9999999
    },
    "metadata": {
      "useLiteralContent": false,
      "bytecodeHash": "ipfs",
      "appendCBOR": true
    },
    "outputSelection": {
      "*": {
        "*": [
          "evm.bytecode",
          "evm.deployedBytecode",
          "devdoc",
          "userdoc",
          "metadata",
          "abi"
        ]
      }
    },
    "evmVersion": "prague",
    "viaIR": true
  }
}}

Tags:
Factory|addr:0x5c96e0ed8c939ca96fdb274553d0263949430e20|verified:true|block:23518231|tx:0x1f8f6f89e5407db5b59d5bd81226701e3f94f0c7157b6e36473320015cbe0ce1|first_check:1759749066

Submitted on: 2025-10-06 13:11:08

Comments

Log in to comment.

No comments yet.