UNPKG

@node-dlc/messaging

Version:
164 lines (163 loc) 5.79 kB
/// <reference types="node" /> import { MessageType } from '../MessageType'; import { IDlcMessage } from './DlcMessage'; import { OracleAnnouncement, OracleAnnouncementJSON } from './OracleAnnouncement'; /** * OracleParams describe allowed differences between oracles in * numerical outcome contracts, as per rust-dlc specification. */ export declare class OracleParams implements IDlcMessage { static type: MessageType; /** * Creates an OracleParams from JSON data * @param json JSON object representing oracle params */ static fromJSON(json: any): OracleParams; /** * Deserializes oracle_params_v0 message */ static deserialize(buf: Buffer): OracleParams; /** * Deserializes oracle params body without TLV wrapper (for optional deserialization) */ static deserializeBody(buf: Buffer): OracleParams; type: MessageType; length: bigint; /** The maximum allowed difference between oracle expressed as a power of 2. */ maxErrorExp: number; /** The minimum allowed difference that should be supported by the contract expressed as a power of 2. */ minFailExp: number; /** Whether to maximize coverage of the interval between maxErrorExp and minFailExp. */ maximizeCoverage: boolean; validate(): void; toJSON(): OracleParamsJSON; serialize(): Buffer; /** * Serializes the oracle params body without TLV wrapper (for optional serialization) */ serializeBody(): Buffer; } /** * SingleOracleInfo contains information about a single oracle. */ export declare class SingleOracleInfo implements IDlcMessage { static type: MessageType; /** * Creates a SingleOracleInfo from JSON data * @param json JSON object representing single oracle info */ static fromJSON(json: any): SingleOracleInfo; /** * Deserializes single oracle info */ static deserialize(buf: Buffer): SingleOracleInfo; type: MessageType; length: bigint; /** The oracle announcement from the oracle. */ announcement: OracleAnnouncement; /** * Returns the closest maturity date amongst all events */ getClosestMaturityDate(): number; validate(): void; toJSON(): SingleOracleInfoJSON; serialize(): Buffer; /** * Serializes the body without TLV wrapper (for embedding in ContractInfo) * This matches rust-dlc behavior where OracleInfo.write() doesn't add type_id */ serializeBody(): Buffer; /** * Deserializes the body without TLV wrapper (for embedding in ContractInfo) * This matches rust-dlc behavior where OracleInfo is read without type_id */ static deserializeBody(buf: Buffer): SingleOracleInfo; } /** * MultiOracleInfo contains information about multiple oracles used in multi-oracle based contracts. */ export declare class MultiOracleInfo implements IDlcMessage { static type: MessageType; /** * Creates a MultiOracleInfo from JSON data * @param json JSON object representing multi oracle info */ static fromJSON(json: any): MultiOracleInfo; /** * Deserializes multi oracle info */ static deserialize(buf: Buffer): MultiOracleInfo; type: MessageType; length: bigint; /** The threshold to be used for the contract (e.g. 2 of 3). */ threshold: number; /** The set of oracle announcements. */ announcements: OracleAnnouncement[]; /** The parameters to be used when allowing differences between oracle outcomes in numerical outcome contracts. */ oracleParams?: OracleParams; validate(): void; /** * Returns the closest maturity date amongst all events */ getClosestMaturityDate(): number; toJSON(): MultiOracleInfoJSON; serialize(): Buffer; /** * Serializes the body without TLV wrapper (for embedding in ContractInfo) * This matches rust-dlc behavior where OracleInfo.write() doesn't add type_id */ serializeBody(): Buffer; /** * Deserializes the body without TLV wrapper (for embedding in ContractInfo) * This matches rust-dlc behavior where OracleInfo is read without type_id */ static deserializeBody(buf: Buffer): MultiOracleInfo; } /** * OracleInfo contains information about the oracles to be used in * executing a DLC. Updated to support both single and multi-oracle * patterns as per rust-dlc specification. */ export declare abstract class OracleInfo implements IDlcMessage { static deserialize(buf: Buffer): SingleOracleInfo | MultiOracleInfo; /** * Creates an OracleInfo from JSON data (e.g., from test vectors) * @param json JSON object representing oracle info */ static fromJSON(json: any): OracleInfo; abstract type: number; abstract validate(): void; abstract toJSON(): SingleOracleInfoJSON | MultiOracleInfoJSON; abstract serialize(): Buffer; abstract serializeBody(): Buffer; /** * Returns the closest maturity date amongst all events */ getClosestMaturityDate(): number; } export declare class OracleInfoV0 extends SingleOracleInfo { /** * Creates an OracleInfoV0 from JSON data (alias for SingleOracleInfo.fromJSON) * @param json JSON object representing oracle info */ static fromJSON(json: any): OracleInfoV0; } export interface OracleParamsJSON { type?: number; maxErrorExp: number; minFailExp: number; maximizeCoverage: boolean; } export interface SingleOracleInfoJSON { single: { oracleAnnouncement: OracleAnnouncementJSON; }; } export interface MultiOracleInfoJSON { multi: { threshold: number; oracleAnnouncements: OracleAnnouncementJSON[]; oracleParams?: OracleParamsJSON; }; } export type OracleInfoV0JSON = SingleOracleInfoJSON;