hm-aftermath-ts-sdk
Version:
Aftermath TypeScript SDK
144 lines (143 loc) • 7.51 kB
JavaScript
"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");
/**
* This class represents the Aftermath API and provides helper methods for various functionalities.
* @class
*/
class AftermathApi {
// =========================================================================
// Constructor
// =========================================================================
/**
* Creates an instance of AftermathApi.
* @param provider - The SuiClient instance to use for interacting with the blockchain.
* @param addresses - The configuration addresses for the Aftermath protocol.
* @param providerV0 - The SuiClient instance to use for interacting with the blockchain.
*/
constructor(provider, addresses, providerV0) {
this.provider = provider;
this.addresses = addresses;
this.providerV0 = providerV0;
// =========================================================================
// Class Object Creation
// =========================================================================
// =========================================================================
// General
// =========================================================================
this.DynamicFields = () => new dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers(this);
this.Events = () => new eventsApiHelpers_1.EventsApiHelpers(this);
this.Inspections = () => new inspectionsApiHelpers_1.InspectionsApiHelpers(this);
this.Objects = () => new objectsApiHelpers_1.ObjectsApiHelpers(this);
this.Transactions = () => new transactionsApiHelpers_1.TransactionsApiHelpers(this);
// =========================================================================
// Utils
// =========================================================================
this.Wallet = () => new walletApi_1.WalletApi(this);
this.Nfts = () => new nftsApi_1.NftsApi(this);
// =========================================================================
// General Packages
// =========================================================================
this.Coin = () => new coinApi_1.CoinApi(this);
this.Sui = () => new suiApi_1.SuiApi(this);
// =========================================================================
// Aftermath Packages
// =========================================================================
this.Pools = () => new poolsApi_1.PoolsApi(this);
this.Faucet = () => new faucetApi_1.FaucetApi(this);
this.SuiFrens = () => new suiFrensApi_1.SuiFrensApi(this);
this.Staking = () => new stakingApi_1.StakingApi(this);
this.NftAmm = () => new nftAmmApi_1.NftAmmApi(this);
this.ReferralVault = () => new referralVaultApi_1.ReferralVaultApi(this);
this.Perpetuals = () => new perpetualsApi_1.PerpetualsApi(this);
this.Oracle = () => new oracleApi_1.OracleApi(this);
this.Farms = () => new farmsApi_1.FarmsApi(this);
this.Dca = () => new dcaApi_1.DcaApi(this);
// public Multisig = () => new MultisigApi(this);
/**
* Creates a new instance of the RouterApi class.
* @returns A new instance of the RouterApi class.
*/
this.Router = () => new routerApi_1.RouterApi(this);
this.LeveragedStaking = (ScallopProviders // ScallopProviders
) => new leveragedStakingApi_1.LeveragedStakingApi(this, ScallopProviders);
// =========================================================================
// Helpers
// =========================================================================
this.translateMoveErrorMessage = (inputs) => {
const { errorMessage } = inputs;
// TODO: make this work more cleanly
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) { }
}
return undefined;
};
}
}
exports.AftermathApi = AftermathApi;
// =========================================================================
// Helpers
// =========================================================================
AftermathApi.helpers = {
// =========================================================================
// General
// =========================================================================
dynamicFields: dynamicFieldsApiHelpers_1.DynamicFieldsApiHelpers,
events: eventsApiHelpers_1.EventsApiHelpers,
inspections: inspectionsApiHelpers_1.InspectionsApiHelpers,
objects: objectsApiHelpers_1.ObjectsApiHelpers,
transactions: transactionsApiHelpers_1.TransactionsApiHelpers,
// =========================================================================
// Utils
// =========================================================================
wallet: walletApi_1.WalletApi,
// =========================================================================
// General Packages
// =========================================================================
coin: coinApi_1.CoinApi,
sui: suiApi_1.SuiApi,
};