UNPKG

aftermath-ts-sdk

Version:
266 lines (265 loc) 12.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AftermathApi = void 0; const poolsApi_1 = require("../../packages/pools/api/poolsApi"); const faucetApi_1 = require("../../packages/faucet/api/faucetApi"); const coinApi_1 = require("../../packages/coin/api/coinApi"); const dynamicFieldsApiHelpers_1 = require("../apiHelpers/dynamicFieldsApiHelpers"); const eventsApiHelpers_1 = require("../apiHelpers/eventsApiHelpers"); const inspectionsApiHelpers_1 = require("../apiHelpers/inspectionsApiHelpers"); const objectsApiHelpers_1 = require("../apiHelpers/objectsApiHelpers"); const transactionsApiHelpers_1 = require("../apiHelpers/transactionsApiHelpers"); const suiApi_1 = require("../../packages/sui/api/suiApi"); const walletApi_1 = require("../wallet/walletApi"); const routerApi_1 = require("../../packages/router/api/routerApi"); const suiFrensApi_1 = require("../../packages/suiFrens/api/suiFrensApi"); const stakingApi_1 = require("../../packages/staking/api/stakingApi"); const nftAmmApi_1 = require("../../packages/nftAmm/api/nftAmmApi"); const referralVaultApi_1 = require("../../packages/referralVault/api/referralVaultApi"); const perpetualsApi_1 = require("../../packages/perpetuals/api/perpetualsApi"); const oracleApi_1 = require("../../packages/oracle/api/oracleApi"); const farmsApi_1 = require("../../packages/farms/api/farmsApi"); const dcaApi_1 = require("../../packages/dca/api/dcaApi"); const leveragedStakingApi_1 = require("../../packages/leveragedStaking/api/leveragedStakingApi"); const nftsApi_1 = require("../nfts/nftsApi"); const utils_1 = require("../utils"); const multisigApi_1 = require("../../packages/multisig/api/multisigApi"); const userDataApi_1 = require("../../packages/userData/api/userDataApi"); const limitOrdersApi_1 = require("../../packages/limitOrders/api/limitOrdersApi"); /** * The `AftermathApi` class is a low-level factory and reference point for * interacting directly with underlying API modules (e.g., PoolsApi, StakingApi). * It encapsulates a configured `SuiClient` and the known `addresses` for the * Aftermath protocol, allowing flexible or advanced usage scenarios. * * @example * ```typescript * import { AftermathApi } from "aftermath-ts-sdk"; * import { SuiClient, SuiHTTPTransport } from "@mysten/sui/client"; * * const addresses = { ... }; // from aftermath.getAddresses() * const suiClient = new SuiClient({ * transport: new SuiHTTPTransport({ * url: "https://fullnode.mainnet.sui.io", * }), * }); * * const afApi = new AftermathApi(suiClient, addresses); * // access protocol APIs * const poolsApi = afApi.Pools(); * ``` */ class AftermathApi { // ========================================================================= // Constructor // ========================================================================= /** * Constructs a new instance of the `AftermathApi`, binding the given Sui client * to the known `addresses`. * * @param provider - The `SuiClient` for on-chain queries and transactions. * @param addresses - The config addresses (object IDs, package IDs, etc.) for the Aftermath protocol. */ constructor(provider, addresses) { this.provider = provider; this.addresses = addresses; // ========================================================================= // Class Object Creation // ========================================================================= // ========================================================================= // General // ========================================================================= /** * Creates a new `DynamicFieldsApiHelpers` instance for complex object field queries. */ this.DynamicFields = () => new dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers(this); /** * Creates a new `EventsApiHelpers` instance for querying Sui events. */ this.Events = () => new eventsApiHelpers_1.EventsApiHelpers(this); /** * Creates a new `InspectionsApiHelpers` instance for reading Summaries or inspection data. */ this.Inspections = () => new inspectionsApiHelpers_1.InspectionsApiHelpers(this); /** * Creates a new `ObjectsApiHelpers` instance for object retrieval/manipulation. */ this.Objects = () => new objectsApiHelpers_1.ObjectsApiHelpers(this); /** * Creates a new `TransactionsApiHelpers` instance for querying or parsing transaction data. */ this.Transactions = () => new transactionsApiHelpers_1.TransactionsApiHelpers(this); // ========================================================================= // Utils // ========================================================================= /** * Creates a new `WalletApi` instance for direct wallet-based operations (fetching balances, etc.). */ this.Wallet = () => new walletApi_1.WalletApi(this); /** * Creates a new `NftsApi` instance for retrieving and interacting with NFT data. */ this.Nfts = () => new nftsApi_1.NftsApi(this); // ========================================================================= // General Packages // ========================================================================= /** * Creates a new `CoinApi` instance for detailed coin operations. */ this.Coin = () => new coinApi_1.CoinApi(this); /** * Creates a new `SuiApi` instance for lower-level Sui chain interactions. */ this.Sui = () => new suiApi_1.SuiApi(this); // ========================================================================= // Aftermath Packages // ========================================================================= /** * Creates a new `PoolsApi` instance for pool-related interactions (AMM pools, liquidity, etc.). */ this.Pools = () => new poolsApi_1.PoolsApi(this); /** * Creates a new `FaucetApi` instance for dispensing tokens on supported dev/test networks. */ this.Faucet = () => new faucetApi_1.FaucetApi(this); /** * Creates a new `SuiFrensApi` instance for special social or token gating utilities on Sui. */ this.SuiFrens = () => new suiFrensApi_1.SuiFrensApi(this); /** * Creates a new `StakingApi` instance for advanced or direct staking operations on Sui. */ this.Staking = () => new stakingApi_1.StakingApi(this); /** * Creates a new `NftAmmApi` instance for NFT AMM logic (buy, sell, liquidity). */ this.NftAmm = () => new nftAmmApi_1.NftAmmApi(this); /** * Creates a new `ReferralVaultApi` instance for referral-based logic in Aftermath. */ this.ReferralVault = () => new referralVaultApi_1.ReferralVaultApi(this); /** * Creates a new `PerpetualsApi` instance for futures or perpetual derivatives on Sui. */ this.Perpetuals = () => new perpetualsApi_1.PerpetualsApi(this); /** * Creates a new `OracleApi` instance for price or data feed oracles. */ this.Oracle = () => new oracleApi_1.OracleApi(this); /** * Creates a new `FarmsApi` instance for yield farming or liquidity mining interactions. */ this.Farms = () => new farmsApi_1.FarmsApi(this); /** * Creates a new `DcaApi` instance for dollar-cost averaging logic. */ this.Dca = () => new dcaApi_1.DcaApi(this); /** * Creates a new `MultisigApi` instance for multi-signature address creation and management. */ this.Multisig = () => new multisigApi_1.MultisigApi(this); /** * Creates a new `LimitOrdersApi` instance for placing limit orders on supported DEX protocols. */ this.LimitOrders = () => new limitOrdersApi_1.LimitOrdersApi(this); /** * Creates a new `UserDataApi` instance for managing user-specific data storage or sign-on logic. */ this.UserData = () => new userDataApi_1.UserDataApi(this); /** * Creates a new `RouterApi` instance for best-price trade routing across multiple DEX liquidity sources. */ this.Router = () => new routerApi_1.RouterApi(this); /** * Creates a new `LeveragedStakingApi` instance for leveraged staking operations, * optionally using `ScallopProviders` if needed. * * @param ScallopProviders - An optional object containing references to Scallop's Sui modules or providers. */ this.LeveragedStaking = (ScallopProviders) => new leveragedStakingApi_1.LeveragedStakingApi(this, ScallopProviders); // ========================================================================= // Helpers // ========================================================================= /** * Attempts to decode a Move error message into a structured error code, * package ID, module name, and descriptive error string. * * @param inputs - An object containing the raw `errorMessage`. * @returns An object with `errorCode`, `packageId`, `module`, and `error` if translation is successful, or `undefined`. * * @example * ```typescript * const errorDecoded = afApi.translateMoveErrorMessage({ errorMessage: "MoveAbort at ..." }); * if (errorDecoded) { * console.log(errorDecoded.errorCode, errorDecoded.error); * } * ``` */ this.translateMoveErrorMessage = (inputs) => { const { errorMessage } = inputs; // Candidate packageApis that define `moveErrors` we can search against const packageApis = [ // @ts-ignore this.Pools, // @ts-ignore this.Staking, // @ts-ignore this.Perpetuals, // @ts-ignore this.Farms, // @ts-ignore this.Router, ]; for (const packageApi of packageApis) { try { const moveErrors = packageApi().moveErrors; const translation = utils_1.Helpers.translateMoveErrorMessage({ errorMessage, moveErrors, }); if (!translation) continue; return translation; } catch (e) { // If any package lacks `moveErrors`, we skip it } } return undefined; }; } } exports.AftermathApi = AftermathApi; // ========================================================================= // Helpers // ========================================================================= /** * Static helper references for quick usage without instantiating the class. */ AftermathApi.helpers = { // ========================================================================= // General // ========================================================================= /** Helpers for accessing or iterating over dynamic fields in Sui objects. */ dynamicFields: dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers, /** Helpers for working with Sui events and pagination. */ events: eventsApiHelpers_1.EventsApiHelpers, /** Helpers for reading on-chain data in an "inspection" manner (designed for Summaries). */ inspections: inspectionsApiHelpers_1.InspectionsApiHelpers, /** Helpers for retrieving and parsing Sui objects by ID or type. */ objects: objectsApiHelpers_1.ObjectsApiHelpers, /** Helpers for reading transaction data (by digest, query, etc.). */ transactions: transactionsApiHelpers_1.TransactionsApiHelpers, // ========================================================================= // Utils // ========================================================================= /** Helper for wallet-based operations, separate from the main `Wallet` classes. */ wallet: walletApi_1.WalletApi, // ========================================================================= // General Packages // ========================================================================= /** Low-level direct coin operations, separate from the higher-level `Coin` class. */ coin: coinApi_1.CoinApi, /** Low-level Sui chain data ops, separate from the higher-level `Sui` class. */ sui: suiApi_1.SuiApi, };