{
  "name": "Perpetual Binary Market ABIs",
  "version": "1.0.0",
  "chainId": 8453,
  "description": "Contract ABIs for CyMetica Perpetual Binary Trading on Base L2",
  "docs": "https://cymetica.com/perpetual/api",

  "contracts": {
    "market": {
      "description": "PerpetualBinaryMarket - Main trading contract for each asset",
      "example": "0x54F033598D130f374C62DB5313816f7a83b7Bb2b",
      "abi": [
        {
          "name": "buyYes",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "amount", "type": "uint256"}],
          "outputs": []
        },
        {
          "name": "buyNo",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "amount", "type": "uint256"}],
          "outputs": []
        },
        {
          "name": "sellYes",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "amount", "type": "uint256"}],
          "outputs": []
        },
        {
          "name": "sellNo",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "amount", "type": "uint256"}],
          "outputs": []
        },
        {
          "name": "claimWinnings",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "epoch", "type": "uint256"}],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "claimRefund",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [{"name": "epoch", "type": "uint256"}],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "getCurrentStatus",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [
            {"name": "epoch", "type": "uint256"},
            {"name": "startPrice", "type": "uint256"},
            {"name": "timeRemaining", "type": "uint256"},
            {"name": "tradingActive", "type": "bool"},
            {"name": "yesPrice", "type": "uint256"},
            {"name": "noPrice", "type": "uint256"},
            {"name": "yesSupply", "type": "uint256"},
            {"name": "noSupply", "type": "uint256"}
          ]
        },
        {
          "name": "currentEpoch",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "collateralToken",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "address"}]
        },
        {
          "name": "yesToken",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "address"}]
        },
        {
          "name": "noToken",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "address"}]
        },
        {
          "name": "epochDuration",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "tradingWindow",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "getEpochInfo",
          "type": "function",
          "stateMutability": "view",
          "inputs": [{"name": "epoch", "type": "uint256"}],
          "outputs": [
            {"name": "startPrice", "type": "uint256"},
            {"name": "endPrice", "type": "uint256"},
            {"name": "yesSupply", "type": "uint256"},
            {"name": "noSupply", "type": "uint256"},
            {"name": "totalCollateral", "type": "uint256"},
            {"name": "resolved", "type": "bool"},
            {"name": "yesWins", "type": "bool"}
          ]
        },
        {
          "name": "getUserPosition",
          "type": "function",
          "stateMutability": "view",
          "inputs": [
            {"name": "user", "type": "address"},
            {"name": "epoch", "type": "uint256"}
          ],
          "outputs": [
            {"name": "yesAmount", "type": "uint256"},
            {"name": "noAmount", "type": "uint256"},
            {"name": "claimed", "type": "bool"}
          ]
        },
        {
          "name": "TokensPurchased",
          "type": "event",
          "inputs": [
            {"name": "user", "type": "address", "indexed": true},
            {"name": "epoch", "type": "uint256", "indexed": true},
            {"name": "isYes", "type": "bool", "indexed": false},
            {"name": "amount", "type": "uint256", "indexed": false},
            {"name": "cost", "type": "uint256", "indexed": false}
          ]
        },
        {
          "name": "TokensSold",
          "type": "event",
          "inputs": [
            {"name": "user", "type": "address", "indexed": true},
            {"name": "epoch", "type": "uint256", "indexed": true},
            {"name": "isYes", "type": "bool", "indexed": false},
            {"name": "amount", "type": "uint256", "indexed": false},
            {"name": "payout", "type": "uint256", "indexed": false}
          ]
        },
        {
          "name": "EpochStarted",
          "type": "event",
          "inputs": [
            {"name": "epoch", "type": "uint256", "indexed": true},
            {"name": "startPrice", "type": "uint256", "indexed": false},
            {"name": "startTime", "type": "uint256", "indexed": false}
          ]
        },
        {
          "name": "EpochResolved",
          "type": "event",
          "inputs": [
            {"name": "epoch", "type": "uint256", "indexed": true},
            {"name": "startPrice", "type": "uint256", "indexed": false},
            {"name": "endPrice", "type": "uint256", "indexed": false},
            {"name": "yesWins", "type": "bool", "indexed": false},
            {"name": "yesSupply", "type": "uint256", "indexed": false},
            {"name": "noSupply", "type": "uint256", "indexed": false}
          ]
        },
        {
          "name": "WinningsClaimed",
          "type": "event",
          "inputs": [
            {"name": "user", "type": "address", "indexed": true},
            {"name": "epoch", "type": "uint256", "indexed": true},
            {"name": "amount", "type": "uint256", "indexed": false}
          ]
        }
      ]
    },

    "erc20": {
      "description": "Standard ERC20 interface for collateral and position tokens",
      "abi": [
        {
          "name": "approve",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [
            {"name": "spender", "type": "address"},
            {"name": "amount", "type": "uint256"}
          ],
          "outputs": [{"name": "", "type": "bool"}]
        },
        {
          "name": "transfer",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [
            {"name": "to", "type": "address"},
            {"name": "amount", "type": "uint256"}
          ],
          "outputs": [{"name": "", "type": "bool"}]
        },
        {
          "name": "transferFrom",
          "type": "function",
          "stateMutability": "nonpayable",
          "inputs": [
            {"name": "from", "type": "address"},
            {"name": "to", "type": "address"},
            {"name": "amount", "type": "uint256"}
          ],
          "outputs": [{"name": "", "type": "bool"}]
        },
        {
          "name": "balanceOf",
          "type": "function",
          "stateMutability": "view",
          "inputs": [{"name": "account", "type": "address"}],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "allowance",
          "type": "function",
          "stateMutability": "view",
          "inputs": [
            {"name": "owner", "type": "address"},
            {"name": "spender", "type": "address"}
          ],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "symbol",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "string"}]
        },
        {
          "name": "decimals",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "uint8"}]
        },
        {
          "name": "totalSupply",
          "type": "function",
          "stateMutability": "view",
          "inputs": [],
          "outputs": [{"name": "", "type": "uint256"}]
        },
        {
          "name": "Transfer",
          "type": "event",
          "inputs": [
            {"name": "from", "type": "address", "indexed": true},
            {"name": "to", "type": "address", "indexed": true},
            {"name": "value", "type": "uint256", "indexed": false}
          ]
        },
        {
          "name": "Approval",
          "type": "event",
          "inputs": [
            {"name": "owner", "type": "address", "indexed": true},
            {"name": "spender", "type": "address", "indexed": true},
            {"name": "value", "type": "uint256", "indexed": false}
          ]
        }
      ]
    }
  },

  "addresses": {
    "markets": {
      "ETH": "0x54F033598D130f374C62DB5313816f7a83b7Bb2b",
      "SOL": "0x3278fDFaF7E70688FCEE785c4342D20f9c6A112c",
      "DOGE": "0xA375b157bbD4d997Ea48787744caAe9e551c3bBa",
      "AAPL_V2": "0x2e6F229F9d7E69dAC080cB8C086c14b394A20a49",
      "NVDA_V2": "0x26b48d99a27f11E830E1063a27f099Bf0724497d",
      "TSLA_V2": "0x0b4474f79557e9651789504A345Ef5E26C890ff3",
      "LINK_V2": "0xF0e0cd02dceaFe180c76679B1275f9EA85Fd7f36"
    },
    "collateral": {
      "CYM1": "0x133969FEb4A827e0b4F38f5926A552DCc10131Da"
    }
  },

  "usage": {
    "javascript": "const { ethers } = require('ethers');\nconst abis = require('./perpetual-abis.json');\n\nconst provider = new ethers.JsonRpcProvider('https://base.publicnode.com');\nconst market = new ethers.Contract(\n  abis.addresses.markets.ETH,\n  abis.contracts.market.abi,\n  provider\n);\n\nconst status = await market.getCurrentStatus();\nconsole.log('Epoch:', status.epoch.toString());",

    "python": "from web3 import Web3\nimport json\n\nwith open('perpetual-abis.json') as f:\n    abis = json.load(f)\n\nw3 = Web3(Web3.HTTPProvider('https://base.publicnode.com'))\nmarket = w3.eth.contract(\n    address=abis['addresses']['markets']['ETH'],\n    abi=abis['contracts']['market']['abi']\n)\n\nstatus = market.functions.getCurrentStatus().call()\nprint(f'Epoch: {status[0]}')"
  }
}
