UNPKG

aftermath-ts-sdk

Version:
253 lines (252 loc) 11.8 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.Aftermath = void 0; const pools_1 = require("../../packages/pools/pools"); const wallet_1 = require("../wallet/wallet"); const suiFrens_1 = require("../../packages/suiFrens/suiFrens"); const coin_1 = require("../../packages/coin/coin"); const faucet_1 = require("../../packages/faucet/faucet"); const staking_1 = require("../../packages/staking/staking"); const helpers_1 = require("../utils/helpers"); const casting_1 = require("../utils/casting"); const caller_1 = require("../utils/caller"); const prices_1 = require("../prices/prices"); const packages_1 = require("../../packages"); const perpetuals_1 = require("../../packages/perpetuals"); const oracle_1 = require("../../packages/oracle/oracle"); const farms_1 = require("../../packages/farms/farms"); const dynamicGas_1 = require("../dynamicGas/dynamicGas"); const aftermathApi_1 = require("./aftermathApi"); const client_1 = require("@mysten/sui/client"); const dca_1 = require("../../packages/dca/dca"); const multisig_1 = require("../../packages/multisig/multisig"); const limitOrders_1 = require("../../packages/limitOrders/limitOrders"); const userData_1 = require("../../packages/userData/userData"); /** * The `Aftermath` class serves as the primary entry point for interacting with * the Aftermath Finance protocols and utilities on the Sui blockchain. * It provides various sub-providers (e.g. `Router`, `Staking`, `Farms`) * initialized under the specified network environment (MAINNET, TESTNET, etc). * * @example * ```typescript * // Create provider * const aftermath = new Aftermath("MAINNET"); * // Create package provider * const router = aftermath.Router(); * // Call sdk from package provider * const supportedCoins = await router.getSupportedCoins(); * * // Or do it all in one go * const supportedCoins = await (new Aftermath("MAINNET")).Router().getSupportedCoins(); * ``` */ class Aftermath extends caller_1.Caller { // ========================================================================= // Constructor // ========================================================================= /** * Creates an `Aftermath` provider instance to call the Aftermath Finance APIs * and interact with Sui-based protocols. * * @param network - The target Sui network ("MAINNET", "TESTNET", "DEVNET", or "LOCAL"). * @param Provider - Optionally pass a custom `AftermathApi` instance if you already have one. */ constructor(network, Provider) { super({ network, accessToken: undefined, }); this.network = network; this.Provider = Provider; // ========================================================================= // Class Object Creation // ========================================================================= // ========================================================================= // Packages // ========================================================================= /** * Returns an instance of the `Pools` class, which handles DEX pool operations * within the Aftermath platform (if supported). */ this.Pools = () => new pools_1.Pools(this.config, this.Provider); /** * Returns an instance of the `Staking` class for Aftermath's staking and unstaking features. */ this.Staking = () => new staking_1.Staking(this.config, this.Provider); /** * Returns an instance of `LeveragedStaking` for advanced leveraged staking workflows (if supported). */ this.LeveragedStaking = () => new packages_1.LeveragedStaking(this.config); /** * Returns an instance of `SuiFrens`, a specialized package for social or utility services. */ this.SuiFrens = () => new suiFrens_1.SuiFrens(this.config, this.Provider); /** * Returns an instance of `Faucet`, allowing test/dev networks to dispense tokens. */ this.Faucet = () => new faucet_1.Faucet(this.config, this.Provider); /** * Returns an instance of the `Router` class, which handles smart order routing * across multiple DEX protocols. */ this.Router = () => new packages_1.Router(this.config); /** * Returns an instance of `NftAmm`, which supports NFT AMM (automated market maker) features. */ this.NftAmm = () => new packages_1.NftAmm(this.config, this.Provider); /** * Returns an instance of `ReferralVault` for referral-based interactions in the protocol. */ this.ReferralVault = () => new packages_1.ReferralVault(this.config, this.Provider); /** * Returns an instance of `Perpetuals` for futures or perpetual contract interactions. */ this.Perpetuals = () => new perpetuals_1.Perpetuals(this.config); /** * Returns an instance of `Oracle`, which provides price oracles or other data feed services. */ this.Oracle = () => new oracle_1.Oracle(this.config, this.Provider); /** * Returns an instance of `Farms` for yield farming or liquidity mining functionalities. */ this.Farms = () => new farms_1.Farms(this.config, this.Provider); /** * Returns an instance of the `Dca` class, supporting dollar-cost averaging logic. */ this.Dca = () => new dca_1.Dca(this.config); /** * Returns an instance of `Multisig`, enabling multi-signature address creation and management. */ this.Multisig = () => new multisig_1.Multisig(this.config, this.Provider); /** * Returns an instance of `LimitOrders`, supporting limit order placement on certain DEX protocols. */ this.LimitOrders = () => new limitOrders_1.LimitOrders(this.config); /** * Returns an instance of `UserData` for creating and managing user-specific data or key storage. */ this.UserData = () => new userData_1.UserData(this.config); // ========================================================================= // General // ========================================================================= /** * Returns an instance of `Sui` for low-level Sui chain information and utilities. */ this.Sui = () => new packages_1.Sui(this.config, this.Provider); /** * Returns an instance of `Prices`, which provides coin price data from external or internal feeds. */ this.Prices = () => new prices_1.Prices(this.config); /** * Creates a new `Wallet` instance for a specific user address, enabling you to fetch balances, * transaction history, etc. * * @param address - The Sui address of the wallet (e.g., "0x<32_byte_hex>"). */ this.Wallet = (address) => new wallet_1.Wallet(address, this.config, this.Provider); /** * Returns an instance of the `Coin` class, which handles coin metadata, decimal conversions, * and other coin-related utilities for a specified `CoinType`. * * @param coinType - Optionally specify a coin type for immediate usage in coin methods. */ this.Coin = (coinType) => new coin_1.Coin(coinType, this.config, this.Provider); /** * Returns an instance of `DynamicGas`, enabling dynamic assignment of gas * objects or sponsored transactions for user operations. */ this.DynamicGas = () => new dynamicGas_1.DynamicGas(this.config); /** * Returns an instance of `Auth`, handling user authentication or token-based flows (if applicable). */ this.Auth = () => new packages_1.Auth(this.config); } // ========================================================================= // Public Methods // ========================================================================= /** * Initializes the Aftermath provider by fetching addresses from the backend * and configuring the Sui fullnode client. This method must be called before * performing many API operations. * * @param inputs - Optional object allowing you to override the default `fullnodeUrl`. * @example * ```typescript * const afSdk = new Aftermath("MAINNET"); * await afSdk.init(); // sets up internal providers * ``` */ init(inputs) { return __awaiter(this, void 0, void 0, function* () { var _a; const addresses = yield this.getAddresses(); // Determine the fullnode URL based on the chosen network or user override const fullnodeUrl = (_a = inputs === null || inputs === void 0 ? void 0 : inputs.fullnodeUrl) !== null && _a !== void 0 ? _a : (this.network === "LOCAL" ? "http://127.0.0.1:9000" : this.network === "DEVNET" ? "https://fullnode.devnet.sui.io:443" : this.network === "TESTNET" ? "https://fullnode.testnet.sui.io:443" : "https://fullnode.mainnet.sui.io:443"); // Create a new AftermathApi provider this.Provider = new aftermathApi_1.AftermathApi(new client_1.SuiClient({ transport: new client_1.SuiHTTPTransport({ url: fullnodeUrl, }), }), addresses); }); } /** * Retrieves the Aftermath-specific on-chain addresses (object IDs, packages, etc.). * * @returns A `ConfigAddresses` object containing relevant addresses for the protocol. * * @example * ```typescript * const addresses = await aftermath.getAddresses(); * console.log(addresses); // { routerPackageId: "...", someOtherPackageId: "..." } * ``` */ getAddresses() { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi("addresses"); }); } /** * Returns the base URL used for Aftermath API calls. * * @returns The base URL for this instance's API. * * @example * ```typescript * const apiBaseUrl = aftermath.getApiBaseUrl(); * console.log(apiBaseUrl); // "https://api.after..." * ``` */ getApiBaseUrl() { return this.apiBaseUrl; } } exports.Aftermath = Aftermath; // ========================================================================= // Utils // ========================================================================= /** * Exposes a set of helper functions for general-purpose usage across * the Aftermath ecosystem. Includes utilities for math, logging, etc. */ Aftermath.helpers = helpers_1.Helpers; /** * Exposes a set of casting utilities for data type conversions (e.g., BigInt <-> fixed). */ Aftermath.casting = casting_1.Casting;