UNPKG

client-aftermath-ts-sdk

Version:
172 lines (171 loc) 8.17 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 historicalData_1 = require("../historicalData/historicalData"); const perpetuals_1 = require("../../packages/perpetuals"); const oracle_1 = require("../../packages/oracle/oracle"); // import { PriceFeeds } from "../priceFeeds/priceFeeds"; 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"); /** * @class Aftermath Provider * * @example * ``` * // 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 `Aftermath` provider to call api. * * @param network - The Sui network to interact with * @returns New `Aftermath` instance */ constructor(network, Provider) { super({ network, accessToken: undefined, }); this.network = network; this.Provider = Provider; // ========================================================================= // Class Object Creation // ========================================================================= // ========================================================================= // Packages // ========================================================================= /** * Returns an instance of the Pools class. * @returns {Pools} An instance of the Pools class. */ this.Pools = () => new pools_1.Pools(this.config, this.Provider); /** * Creates a new instance of the Staking class. * @returns A new instance of the Staking class. */ this.Staking = () => new staking_1.Staking(this.config, this.Provider); this.LeveragedStaking = () => new packages_1.LeveragedStaking(this.config); this.SuiFrens = () => new suiFrens_1.SuiFrens(this.config, this.Provider); this.Faucet = () => new faucet_1.Faucet(this.config, this.Provider); /** * Creates a new instance of the Router class with the current network. * @returns A new instance of the Router class. */ this.Router = () => new packages_1.Router(this.config); this.NftAmm = () => new packages_1.NftAmm(this.config, this.Provider); this.ReferralVault = () => new packages_1.ReferralVault(this.config, this.Provider); this.Perpetuals = () => new perpetuals_1.Perpetuals(this.config); this.Oracle = () => new oracle_1.Oracle(this.config, this.Provider); /** * Creates a new instance of the Farms class. * @returns A new instance of the Farms class. */ this.Farms = () => new farms_1.Farms(this.config, this.Provider); /** * Creates a new instance of the DCA class. * @returns A new instance of the DCA class. */ this.Dca = () => new dca_1.Dca(this.config); this.Multisig = () => new multisig_1.Multisig(this.config, this.Provider); this.LimitOrders = () => new limitOrders_1.LimitOrders(this.config); this.UserData = () => new userData_1.UserData(this.config); // ========================================================================= // General // ========================================================================= this.Sui = () => new packages_1.Sui(this.config, this.Provider); this.Prices = () => new prices_1.Prices(this.config); /** * Creates a new instance of the Wallet class. * @param address - The address of the wallet. * @returns A new instance of the Wallet class. */ this.Wallet = (address) => new wallet_1.Wallet(address, this.config, this.Provider); /** * Creates a new instance of the Coin class. * @param coinType The type of coin to create. * @returns A new instance of the Coin class. */ this.Coin = (coinType) => new coin_1.Coin(coinType, this.config, this.Provider); this.HistoricalData = () => new historicalData_1.HistoricalData(this.config); // public PriceFeeds = () => new PriceFeeds(this.config, this.Provider); this.DynamicGas = () => new dynamicGas_1.DynamicGas(this.config); } // ========================================================================= // Public Methods // ========================================================================= init(inputs) { var _a; return __awaiter(this, void 0, void 0, function* () { const addresses = yield this.getAddresses(); 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"); this.Provider = new aftermathApi_1.AftermathApi(new client_1.SuiClient({ transport: new client_1.SuiHTTPTransport({ url: fullnodeUrl, }), }), addresses); }); } /** * Retrieves the addresses from the Aftermath API. * @returns A promise that resolves to a ConfigAddresses object. */ getAddresses() { return __awaiter(this, void 0, void 0, function* () { return this.fetchApi("addresses"); }); } getApiBaseUrl() { return this.apiBaseUrl; } } exports.Aftermath = Aftermath; // public Auth = () => new Auth(this.config); // ========================================================================= // Utils // ========================================================================= Aftermath.helpers = helpers_1.Helpers; Aftermath.casting = casting_1.Casting;