"""VKP contract ABIs and addresses.

Contains ONLY public contract interfaces — no secrets, no private keys.
"""

# ══════════════════════════════════════════════════════════
# SUPPORTED NETWORKS (same as Vaultfire Protocol)
# ══════════════════════════════════════════════════════════

SUPPORTED_NETWORKS: list[str] = [
    "base-mainnet",
    "arbitrum-mainnet",
    "polygon-mainnet",
    "avalanche-mainnet",
]

CHAIN_IDS: dict[str, int] = {
    "base-mainnet": 8453,
    "arbitrum-mainnet": 42161,
    "polygon-mainnet": 137,
    "avalanche-mainnet": 43114,
}

EXPLORER_URLS: dict[str, str] = {
    "base-mainnet": "https://basescan.org",
    "arbitrum-mainnet": "https://arbiscan.io",
    "polygon-mainnet": "https://polygonscan.com",
    "avalanche-mainnet": "https://snowtrace.io",
}

# ══════════════════════════════════════════════════════════
# VAULTFIRE IDENTITY REGISTRY — Used for registration checks
# ══════════════════════════════════════════════════════════

IDENTITY_REGISTRY_ADDRESSES: dict[str, str] = {
    "base-mainnet": "0xa7BD20bf5De63df949cA5Be2F20835978eCba81A",
    "arbitrum-mainnet": "0x83dd216449B3F0574E39043ECFE275946fa492e9",
    "polygon-mainnet": "0xD9bF6D92a1D9ee44a48c38481c046a819CBdf2ba",
    "avalanche-mainnet": "0x7448057C95Fb8a8B974a566cdcc9Cd042166A3f8",
}

ACCOUNTABILITY_BONDS_ADDRESSES: dict[str, str] = {
    "base-mainnet": "0x6750D28865434344e04e1D0a6044394b726C3dfE",
    "arbitrum-mainnet": "0xef3A944f4d7bb376699C83A29d7Cb42C90D9B6F0",
    "polygon-mainnet": "0xdB54B8925664816187646174bdBb6Ac658A55a5F",
    "avalanche-mainnet": "0x376831fB2457E34559891c32bEb61c442053C066",
}

REPUTATION_REGISTRY_ADDRESSES: dict[str, str] = {
    "base-mainnet": "0x98afd1440B2238D73c1394720277a6d031fCbbD0",
    "arbitrum-mainnet": "0x8B8Ba34F8AAB800F0Ba8391fb1388c6EFb911F92",
    "polygon-mainnet": "0x54e00081978eE2C8d9Ada8e9975B0Bb543D06A55",
    "avalanche-mainnet": "0x5DB1B4b412b80d03819395794fCcF5A73BF30656",
}

# ══════════════════════════════════════════════════════════
# VKP CONTRACT ABIs — Minimal function signatures
# ══════════════════════════════════════════════════════════

KEYVAULT_ABI: list[dict] = [
    {
        "name": "execute",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "to", "type": "address"},
            {"name": "value", "type": "uint256"},
            {"name": "data", "type": "bytes"},
        ],
        "outputs": [{"name": "result", "type": "bytes"}],
    },
    {
        "name": "deposit",
        "type": "function",
        "stateMutability": "payable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "updatePolicy",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "_maxPerTx", "type": "uint256"},
            {"name": "_maxHourly", "type": "uint256"},
            {"name": "_maxDaily", "type": "uint256"},
            {"name": "_emergencyThreshold", "type": "uint256"},
        ],
        "outputs": [],
    },
    {
        "name": "allowContract",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [{"name": "target", "type": "address"}],
        "outputs": [],
    },
    {
        "name": "removeContract",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [{"name": "target", "type": "address"}],
        "outputs": [],
    },
    {
        "name": "freeze",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "unfreeze",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "emergencyWithdraw",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "remainingHourly",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "uint256"}],
    },
    {
        "name": "remainingDaily",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "uint256"}],
    },
    {
        "name": "isFrozen",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "bool"}],
    },
    {
        "name": "balance",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "uint256"}],
    },
    {
        "name": "policy",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [
            {"name": "maxPerTx", "type": "uint256"},
            {"name": "maxDaily", "type": "uint256"},
            {"name": "maxHourly", "type": "uint256"},
            {"name": "emergencyThreshold", "type": "uint256"},
            {"name": "frozen", "type": "bool"},
        ],
    },
    {
        "name": "owner",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "address"}],
    },
]

SESSION_KEY_MANAGER_ABI: list[dict] = [
    {
        "name": "createSession",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "sessionAddress", "type": "address"},
            {"name": "maxValue", "type": "uint256"},
            {"name": "totalLimit", "type": "uint256"},
            {"name": "durationSeconds", "type": "uint256"},
            {"name": "allowedContracts", "type": "address[]"},
        ],
        "outputs": [{"name": "sessionId", "type": "uint256"}],
    },
    {
        "name": "validateSession",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "sessionId", "type": "uint256"},
            {"name": "target", "type": "address"},
            {"name": "value", "type": "uint256"},
        ],
        "outputs": [{"name": "valid", "type": "bool"}],
    },
    {
        "name": "revokeSession",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [{"name": "sessionId", "type": "uint256"}],
        "outputs": [],
    },
    {
        "name": "revokeAllSessions",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "isSessionValid",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "sessionId", "type": "uint256"}],
        "outputs": [{"name": "", "type": "bool"}],
    },
    {
        "name": "sessionRemaining",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "sessionId", "type": "uint256"}],
        "outputs": [{"name": "", "type": "uint256"}],
    },
    {
        "name": "getSession",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "sessionId", "type": "uint256"}],
        "outputs": [
            {
                "name": "",
                "type": "tuple",
                "components": [
                    {"name": "owner", "type": "address"},
                    {"name": "sessionAddress", "type": "address"},
                    {"name": "maxValue", "type": "uint256"},
                    {"name": "totalLimit", "type": "uint256"},
                    {"name": "totalSpent", "type": "uint256"},
                    {"name": "expiresAt", "type": "uint256"},
                    {"name": "createdAt", "type": "uint256"},
                    {"name": "revoked", "type": "bool"},
                    {"name": "allowAnyContract", "type": "bool"},
                ],
            },
        ],
    },
    {
        "name": "getOwnerSessions",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "owner_", "type": "address"}],
        "outputs": [{"name": "", "type": "uint256[]"}],
    },
]

DELEGATION_REGISTRY_ABI: list[dict] = [
    {
        "name": "createDelegation",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "delegate", "type": "address"},
            {"name": "maxValue", "type": "uint256"},
            {"name": "totalLimit", "type": "uint256"},
            {"name": "durationSeconds", "type": "uint256"},
            {"name": "minBondRequired", "type": "uint256"},
            {"name": "minReputation", "type": "uint256"},
            {"name": "allowedContracts", "type": "address[]"},
            {"name": "allowedFunctions", "type": "bytes4[]"},
            {"name": "encryptedKeyHash", "type": "bytes32"},
        ],
        "outputs": [{"name": "delegationId", "type": "uint256"}],
    },
    {
        "name": "acceptDelegation",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "delegationId", "type": "uint256"},
            {"name": "bondId", "type": "uint256"},
        ],
        "outputs": [],
    },
    {
        "name": "validateDelegation",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "delegationId", "type": "uint256"},
            {"name": "target", "type": "address"},
            {"name": "value", "type": "uint256"},
            {"name": "selector", "type": "bytes4"},
        ],
        "outputs": [{"name": "valid", "type": "bool"}],
    },
    {
        "name": "revokeDelegation",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [{"name": "delegationId", "type": "uint256"}],
        "outputs": [],
    },
    {
        "name": "revokeAllDelegations",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [],
        "outputs": [],
    },
    {
        "name": "isDelegationValid",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "delegationId", "type": "uint256"}],
        "outputs": [{"name": "", "type": "bool"}],
    },
    {
        "name": "delegationRemaining",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "delegationId", "type": "uint256"}],
        "outputs": [{"name": "", "type": "uint256"}],
    },
    {
        "name": "getDelegation",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "delegationId", "type": "uint256"}],
        "outputs": [
            {
                "name": "",
                "type": "tuple",
                "components": [
                    {"name": "delegator", "type": "address"},
                    {"name": "delegate", "type": "address"},
                    {"name": "maxValue", "type": "uint256"},
                    {"name": "totalLimit", "type": "uint256"},
                    {"name": "totalSpent", "type": "uint256"},
                    {"name": "expiresAt", "type": "uint256"},
                    {"name": "createdAt", "type": "uint256"},
                    {"name": "minBondRequired", "type": "uint256"},
                    {"name": "minReputation", "type": "uint256"},
                    {"name": "revoked", "type": "bool"},
                    {"name": "accepted", "type": "bool"},
                    {"name": "encryptedKeyHash", "type": "bytes32"},
                ],
            },
        ],
    },
]

VKP_FACTORY_ABI: list[dict] = [
    {
        "name": "createVault",
        "type": "function",
        "stateMutability": "nonpayable",
        "inputs": [
            {"name": "maxPerTx", "type": "uint256"},
            {"name": "maxHourly", "type": "uint256"},
            {"name": "maxDaily", "type": "uint256"},
            {"name": "emergencyThreshold", "type": "uint256"},
        ],
        "outputs": [{"name": "vault", "type": "address"}],
    },
    {
        "name": "getAgentVaults",
        "type": "function",
        "stateMutability": "view",
        "inputs": [{"name": "agent", "type": "address"}],
        "outputs": [{"name": "", "type": "address[]"}],
    },
    {
        "name": "totalVaults",
        "type": "function",
        "stateMutability": "view",
        "inputs": [],
        "outputs": [{"name": "", "type": "uint256"}],
    },
]
