On-chain (Solidity)

The Somnia Reactivity Precompile serves as the backbone for on-chain reactivity

Somnia Reactivity Precompile

The Somnia Reactivity Precompile is located at address 0x0100. It provides an interface for managing event subscriptions.

Interface

The interface for the precompile is defined in ISomniaReactivityPrecompile.sol:

interface ISomniaReactivityPrecompile {
    struct SubscriptionData {
        bytes32[4] eventTopics;      // Topic filter (0x0 for wildcard)
        address origin;              // Origin (tx.origin) filter (address(0) for wildcard)
        address caller;              // Caller (msg.sender) filter (address(0) for wildcard)
        address emitter;             // Contract emitting the event (address(0) for wildcard)
        address handlerContractAddress; // Address of the contract to handle the event
        bytes4 handlerFunctionSelector; // Function selector in the handler contract
        uint64 priorityFeePerGas;    // Extra fee to prioritize handling
        uint64 maxFeePerGas;         // Max fee willing to pay
        uint64 gasLimit;             // Maximum gas that will be provisioned per subscription callback
        bool isGuaranteed;           // If true, moves to next block if current is full
        bool isCoalesced;            // If true, multiple events can be coalesced
    }

    event SubscriptionCreated(uint64 indexed subscriptionId, address indexed owner, SubscriptionData subscriptionData);
    event SubscriptionRemoved(uint64 indexed subscriptionId, address indexed owner);

    function subscribe(SubscriptionData calldata subscriptionData) external returns (uint64 subscriptionId);
    function unsubscribe(uint64 subscriptionId) external;
    function getSubscriptions(address owner) external view returns (uint64[] memory);
    function getSubscriptionInfo(uint64 subscriptionId) external view returns (SubscriptionData memory subscriptionData, address owner);
}

Last updated