UNPKG

aftermath-ts-sdk

Version:
92 lines (91 loc) 4.16 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Sui = void 0; const caller_1 = require("../../general/utils/caller"); /** * The `Sui` class provides utilities to fetch core Sui chain information, * such as the system state. It also exposes a set of constant addresses * related to the Sui network package IDs. */ class Sui extends caller_1.Caller { // ========================================================================= // Constructor // ========================================================================= /** * Creates a new instance of the `Sui` class for fetching chain-level info. * * @param config - Optional configuration, including the Sui network and an access token. * @param Provider - An optional `AftermathApi` instance for advanced transaction building or data fetching. */ constructor(config, Provider) { super(config, "sui"); this.Provider = Provider; // ========================================================================= // Private Helpers // ========================================================================= /** * Internal helper to return the configured `Sui` provider. Throws an error if * no `AftermathApi` provider is defined. */ this.useProvider = () => { var _a; const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Sui(); if (!provider) throw new Error("missing AftermathApi Provider"); return provider; }; } // ========================================================================= // Chain Info // ========================================================================= /** * Fetches the Sui system state summary object, which contains details * about the current epoch, validator set, and other protocol-level data. * * @returns A promise that resolves to a `SuiSystemStateSummary` instance. * * @example * ```typescript * const afSdk = new Aftermath("MAINNET"); * await afSdk.init(); // initialize provider * * const sui = afSdk.Sui(); * * const systemState = await sui.getSystemState(); * console.log(systemState.epoch, systemState.validators); * ``` */ getSystemState() { return __awaiter(this, void 0, void 0, function* () { return this.useProvider().fetchSystemState(); }); } } exports.Sui = Sui; // ========================================================================= // Constants // ========================================================================= /** * Static constants containing important addresses on the Sui network: * - `zero`: The zero address (commonly used as a null placeholder). * - `suiPackageId`: The package ID for the Sui system package. * - `suiSystemStateId`: The object ID for the Sui system state. * - `suiClockId`: The object ID for the Sui on-chain clock. */ Sui.constants = { addresses: { zero: "0x0000000000000000000000000000000000000000000000000000000000000000", suiPackageId: "0x0000000000000000000000000000000000000000000000000000000000000002", suiSystemStateId: "0x0000000000000000000000000000000000000000000000000000000000000005", suiClockId: "0x0000000000000000000000000000000000000000000000000000000000000006", }, };