UNPKG

@mirage-protocol/sdk

Version:

Typescript library for interacting with Mirage Protocol move contracts

1,019 lines (978 loc) 85.4 kB
import { AccountAddress, Aptos, MoveVector, U8, TypeTagStruct, MoveObjectType, MoveResource, TransactionPayloadEntryFunction, U64 } from '@aptos-labs/ts-sdk'; import { AptosPriceServiceConnection, Price } from '@pythnetwork/pyth-aptos-js'; import { Client } from 'urql'; import BigNumber from 'bignumber.js'; import * as graphql from 'graphql'; declare enum Deployment { APTOS_TESTNET = "testnet", APTOS_MAINNET = "mainnet", MOVEMENT_MAINNET = "movement" } declare const getDeploymentByChainId: (chainId: number) => Deployment; declare const getChainIdByDeployment: (deployment: Deployment) => number; type MirageClientOptions = { fullnodeUrl?: string; indexerUrl?: string; mirageIndexerUrl?: string; pythUrl?: string; aptosApiKey?: string; deployment?: Deployment; customConfig?: MirageJsonConfig; }; type NetworkConfig = { fullnodeUrl: string; indexerUrl: string; mirageIndexerUrl: string; pythUrl: string; }; type MarketConfig = { address: string; name: string; perpSymbol: string; marginSymbol: string; marginOracle: string; perpOracle: string; }; type MarketsConfig = { [market: string]: MarketConfig; }; type OracleConfig = { name: string; address: string; priceFeedId: string; priceMultiplier: number; }; type OraclesConfig = { [oracle: string]: OracleConfig; }; type VaultConfig = { address: string; name: string; collateralSymbol: string; borrowSymbol: string; collateralOracle: string; borrowOracle: string; }; type VaultsConfig = { [vault: string]: VaultConfig; }; type FungibleAssetConfig = { symbol: string; address: string; name: string; coinType?: string; decimals: number; }; type FungibleAssetConfigs = { [token: string]: FungibleAssetConfig; }; type MirageJsonConfig = { chainId: number; deployerAddress: string; markets: MarketConfig[]; vaults: VaultConfig[]; fungibleAssets: FungibleAssetConfig[]; oracles: OracleConfig[]; }; declare class MirageConfig { chainId: number; deployerAddress: AccountAddress; markets: MarketsConfig; vaults: VaultsConfig; fungibleAssets: FungibleAssetConfigs; oracles: OraclesConfig; fullnodeUrl: string; indexerUrl: string; mirageIndexerUrl: string; pythUrl: string; aptosApiKey?: string; deployment: Deployment; constructor(options: MirageClientOptions); } declare const defaultMirageNetworks: { [deployment in Deployment]: NetworkConfig; }; declare const getDefaultFullnodeUrl: (deployment: Deployment | string) => string; declare const getDefaultIndexerUrl: (deployment: Deployment) => string; declare const getDefaultMirageIndexerUrl: (deployment: Deployment) => string; declare const getDefaultPythUrl: (deployment: Deployment) => string; declare class MirageClientBase { protected config: MirageConfig; protected aptosClient: Aptos; protected aptosGqlClient: Client; protected mirageGqlClient: Client; protected pythClient: AptosPriceServiceConnection; constructor(config: MirageConfig); getDeployerAddress: () => AccountAddress; } declare const buildMirageConfig: (fullnodeUrl: string, deployerAddress: AccountAddress) => Promise<MirageJsonConfig>; declare const ZERO: BigNumber; declare const PRECISION_8 = "100000000"; declare const EXCHANGE_RATE_PRECISION = "100000000"; declare const PERCENT_PRECISION = "10000"; declare const INTEREST_PRECISION = "1000000000000"; declare const SECONDS_PER_YEAR = 31622400; declare const FEE_PRECISION = 1000000; declare const RATE_PRECISION = 100000000; declare const U64_MAX = "18446744073709551615"; declare const MIN_TRIGGER_PAYMENT = 0.01; /** * Move modules that Mirage Protocol utilizes */ declare enum MoveModules { MIRAGE = "mirage", MIRAGE_SCRIPTS = "mirage_scripts", KEEPER_SCRIPTS = "keeper_scripts", MIRAGE_CORE = "mirage_core", MIRAGE_ORACLE = "mirage_oracle", MARKET = "market" } /** * Get the address of a module * @param module the module to get the address of, can pass type or string * @returns the module address if it was found */ declare const getModuleAddress: (module: MoveModules | string, deployerAddress: AccountAddress) => AccountAddress; declare const createGraphqlClientWithUri: (gqlURI: string, API_KEY?: string) => Client; declare const createGraphqlClient: (uriStr: string) => Client; declare const createPythClient: (uriString: string) => AptosPriceServiceConnection; /** * Gets a priceFeed update data promise from Pyth * @param priceFeedId the price feed id string * @param network the network, default mainnet * @returns the update data promise */ declare const getPriceFeedUpdateData: (priceFeedId: string, pythClient: AptosPriceServiceConnection) => Promise<MoveVector<U8>>; declare const getPrice: (priceFeedId: string, pythClient: AptosPriceServiceConnection) => Promise<number>; /** * Gets a ui price from a pyth price * @param price the pyth price * @returns the ui price */ declare const getUiPythPrice: ({ price, expo }: Price) => number; declare const getCollectionType: () => TypeTagStruct; declare const getPropertyMapU64: (key: string, data: any) => BigNumber; declare const integerToDecimal: (value: BigNumber, decimal: number) => BigNumber; declare const getPropertyMapSigned64: (key: string, data: any) => BigNumber; declare const normalizeAddress: (address: string) => string; declare class FungibleAssetBase extends MirageClientBase { getAllFASymbols: () => string[]; getFA: (faSymbol: string) => FungibleAssetConfig; getAllFAs: () => FungibleAssetConfig[]; getFADecimals(tokenSymbol: string): number; getFACoinType(tokenSymbol: string): `${string}::${string}::${string}` | undefined; getFAName(tokenSymbol: string): string; getFAMetadataAddress(tokenSymbol: string): string; getFASymbolFromAddress(tokenMetadataAddress: string): string; /** * Get the balance of a coin in a Ui friendly format * @param balance the balance to convert * @param coin the coin * @returns a human-readable balance value */ balanceToDecimal(balance: BigNumber, tokenSymbol: string): BigNumber; } declare class FungibleAssetViewsClient { private readonly base; private readonly aptosClient; constructor(base: FungibleAssetBase, aptosClient: Aptos); getUserAssetBalance: (tokenSymbol: string, userAddress: string) => Promise<BigNumber>; getFATotalSupply: (tokenSymbol: string) => Promise<BigNumber>; } declare class FungibleAssetClient extends FungibleAssetBase { readonly views: FungibleAssetViewsClient; } declare class OracleClientBase extends MirageClientBase { getAllOracleNames: () => string[]; getOracleNameFromAddress: (oracleObjectAddress: string) => string; getPriceFeedId: (oracleName: string) => string; getPriceFeedUpdateData: (oracleName: string) => Promise<MoveVector<U8>>; getPrice: (oracleName: string) => Promise<number>; } declare class OracleViewsClient { private readonly base; private readonly aptosClient; constructor(base: MirageClientBase, aptosClient: Aptos); getAllOracles: () => Promise<MoveObjectType[]>; getPriceFeedId: (oracleObjectAddress: MoveObjectType) => Promise<string>; getOracleName: (oracleObjAddress: MoveObjectType) => Promise<string>; getOraclePriceMultiplier: (oracleObjAddress: MoveObjectType) => Promise<number>; } declare class OracleClient extends OracleClientBase { readonly views: OracleViewsClient; } declare class MarketClientBase extends MirageClientBase { private readonly oracles; constructor(oracleClient: OracleClient, config: MirageConfig); static createMarketName: (perpSymbol: string, collateralSymbol: string) => string; marketExists: (perpSymbol: string, collateralSymbol: string) => boolean; getMarket: (perpSymbol: string, marginSymbol: string) => MarketConfig; getAllMarkets: () => MarketConfig[]; getAllMarketAddresses: () => string[]; getMarketIdFromAddress: (marketAddress: string) => { perpSymbol: string; marginSymbol: string; }; getMarketAddress: (perpSymbol: string, marginSymbol: string) => string; getPerpPriceFeedId: (perpSymbol: string, marginSymbol: string) => string; getMarginPriceFeedId: (perpSymbol: string, marginSymbol: string) => string; getPerpPriceFeedUpdate: (perpSymbol: string, marginSymbol: string) => Promise<MoveVector<U8>>; getMarginPriceFeedUpdate: (perpSymbol: string, marginSymbol: string) => Promise<MoveVector<U8>>; getPerpPrice: (perpSymbol: string, marginSymbol: string) => Promise<number>; getMarginPrice: (perpSymbol: string, marginSymbol: string) => Promise<number>; } /** * Represents a mirage-protocol perpetuals market. */ declare class Market { /** * The markets perp symbol */ readonly perpSymbol: string; /** * The markets perp symbol */ readonly marginTokenAddress: string; /** * The total long margin of a market */ readonly totalLongMargin: BigNumber; /** * The total short margin of a market */ readonly totalShortMargin: BigNumber; /** * Long open interest in musd */ readonly longOpenInterest: BigNumber; /** * Short open interest in musd */ readonly shortOpenInterest: BigNumber; /** * Long open interest in musd */ readonly longFundingAccumulated: BigNumber; /** * Short open interest in musd */ readonly shortFundingAccumulated: BigNumber; /** * The funding that will be taken next funding round */ readonly nextFundingRate: BigNumber; /** * The time of the last funding round */ readonly lastFundingRound: Date; /** * Whether long positions are close only */ readonly longCloseOnly: boolean; /** * Whether short positions are close only */ readonly shortCloseOnly: boolean; /** * Minimum taker fee at equal oi */ readonly minTakerFee: number; /** * Maximum taker fee at the max_oi_imbalance */ readonly maxTakerFee: number; /** * Min maker fee at large oi imbalance */ readonly minMakerFee: number; /** * Max maker fee at equal oi */ readonly maxMakerFee: number; /** * The minimum funding rate */ readonly minFundingRate: number; /** * The maximum funding rate */ readonly maxFundingRate: number; /** * The maximum funding rate */ readonly baseFundingRate: number; /** * The interval between funding payments */ readonly fundingInterval: BigNumber; /** * The max total oi allowed for the long & short sides */ readonly maxOpenInterest: BigNumber; /** * The max allowed imbalance between long and short oi */ readonly maxOpenInterestImbalance: BigNumber; /** * The base percent maintenance margin */ readonly maintenanceMargin: number; /** * The max leverage for this market */ readonly maxLeverage: number; /** * The min order size in mUSD for a trade */ readonly minOrderSize: BigNumber; /** * The max order size in mUSD for a trade */ readonly maxOrderSize: BigNumber; /** * The market collection address */ readonly objectAddress: string; /** * Construct an instance of Market * @param marketObjectResources resources from the market token collection account * @param marginCoin the margin asset of the market * @param perpetualAsset the asset being traded */ constructor(marketObjectResources: MoveResource[], objectAddress: string, deployerAddress: AccountAddress); getOpenCloseFee(side: PositionSide, isClose: boolean, positionSize: BigNumber, perpPrice: BigNumber, marginPrice: BigNumber): BigNumber; getCloseFee(currSkew: BigNumber, side: PositionSide, positionSizeMUSD: BigNumber): BigNumber; getOpenFee(currSkew: BigNumber, side: PositionSide, positionSizeMUSD: BigNumber): BigNumber; getSkew(perpPrice: BigNumber, isClose: boolean): BigNumber; calculateFee(skew: BigNumber, is_taker: boolean): BigNumber; } /** * LimitOrder struct data */ type TpSlData = { take_profit_price: string; stop_loss_price: string; is_long: boolean; }; /** * Represents a TpSl struct */ declare class TpSl { /** * The side of the order */ readonly side: PositionSide; readonly takeProfitPrice: BigNumber; readonly stopLossPrice: BigNumber; readonly marketObjectAddress: string; readonly positionObjectAddress: string; readonly objectAddress: string; /** * Construct a TpSl instance * @param tpslResources the data to parse */ constructor(tpslResources: MoveResource[], objectAddress: string, deployerAddress: AccountAddress); static getTpslType(deployerAddress: AccountAddress): TypeTagStruct; } /** * Direction of a position */ declare enum PositionSide { UNKNOWN = 0, LONG = 1, SHORT = 2 } declare enum OrderType { UNKNOWN = 0, MARKET = 1, LIMIT = 2, STOP = 3, FLIP = 4 } declare const stringToPositionSide: (str: string) => PositionSide; declare const stringToOrderType: (str: string) => OrderType; /** * Represents a position on a specific Mirage Market */ declare class Position { /** * The token id */ readonly tokenId: bigint; /** * The market of the position */ readonly market: Market; /** * The positions side */ readonly side: PositionSide; /** * The position data if open */ readonly openingPrice: BigNumber; readonly margin: BigNumber; readonly positionSize: BigNumber; readonly fundingAccrued: BigNumber; readonly maintenanceMargin: BigNumber; readonly strategyAddresses: string[]; /** * The fees paid by this position in margin token */ readonly feesPaid: BigNumber; /** * The funding paid by this position in margin token */ readonly fundingPaid: BigNumber; /** * The trade pnl (realized_pnl - feesPaid - funding) in margin token */ readonly tradePnl: BigNumber; /** * The realized pnl of this position in margin token */ readonly realizedPnl: BigNumber; tpsl: TpSl | undefined; limitOrders: LimitOrder[]; /** * The positions initial leverage */ readonly leverage: BigNumber; readonly objectAddress: string; /** * Construct an instance of a trader * @param positionObjectResources Resources from position object account * @param objectAddress the address of the vault collection object * @param config the mirage config */ constructor(positionObjectResources: MoveResource[], strategyObjectsResources: MoveResource[][], market: Market, objectAddress: string, deployerAddress: AccountAddress); static getStrategyAddresses(positionObjectResources: MoveResource[], deployerAddress: AccountAddress): string[]; /** * Returns bool on if the position is open * @returns If the position is open */ isOpen(): boolean; /** * Calculates the leverage of a position given the prices * @param position The position * @param perpetualPrice The perpetual price * @param marginPrice The margin price * @returns The leverage, where 1 == 1x leverage */ static getLeverage(position: Position, perpetualPrice: number, marginPrice: number): number; /** * Estimates a positions pnl in terms of the margin type * @param position The position * @param perpetualPrice The perpetual price * @param marginPrice The margin price * @returns The amount of pnl in terms of the margin of the market */ static estimatePnl(position: Position, perpetualPrice: number, marginPrice: number): number; /** * Estimates a positions percent pnl in terms of the margin * @param position The position * @param perpetualPrice The perpetual price * @param marginPrice The margin price * @returns The percent pnl in terms of the margin of the market */ static estimatePercentPnl(position: Position, perpetualPrice: number, marginPrice: number): number; getPositionMaintenanceMarginMUSD(perpPrice: BigNumber, marginPrice: BigNumber): BigNumber; getLiquidationPrice(perpPrice: BigNumber, marginPrice: BigNumber): BigNumber; static getPositionType(deployerAddress: AccountAddress): TypeTagStruct; } /** * LimitOrder struct data */ type LimitOrderData = { is_decrease_only: boolean; position_size: string; is_long: boolean; trigger_price: BigNumber; triggers_above: boolean; max_price_slippage: string; expiration: string; }; /** * Represents a LimitOrder struct */ declare class LimitOrder { /** * The side of the order */ readonly side: PositionSide; /** * Is this a limit order only to decrease a position */ readonly isDecreaseOnly: boolean; /** * Position size in units of the asset */ readonly positionSize: BigNumber; /** * This trades margin amount */ readonly margin: BigNumber; /** * The price this order gets triggered */ readonly triggerPrice: BigNumber; /** * Will this order trigger above or below the triggerPrice */ readonly triggersAbove: boolean; /** * The max price slippage on trigger for the order */ readonly maxPriceSlippage: BigNumber; /** * The expiration time of the order */ readonly expiration: bigint; readonly marketObjectAddress: string; readonly positionObjectAddress: string; readonly objectAddress: string; /** * Construct a LimitOrder instance * @param limitOrderData the data to parse */ constructor(limitOrderResources: MoveResource[], objectAddress: string, deployerAddress: AccountAddress); static gtcExpiration(): bigint; isGtc(): boolean; /** * Turn a percentage slippage into a price slippage * @param triggerPrice The trigger price of the trade * @param percentSlippage The allowed slippage in basis points * @returns The amount of price slippage allowed */ static percentSlippageToPriceSlippage(triggerPrice: BigNumber, percentSlippage: number): BigNumber; static getLimitOrderType(deployerAddress: AccountAddress): TypeTagStruct; } /** * Represents an elastic rebase number * See: https://github.com/mirage-protocol/rebase */ declare class Rebase { /** * The elastic part of the rebase */ readonly elastic: BigNumber; /** * The base part of the rebase */ readonly base: BigNumber; /** * Construct an instance of rebase * @param elastic the elastic part * @param base the base part */ constructor(elastic: BigNumber, base: BigNumber); /** * Get a elastic value represented in terms of the current rebase. * @param base the base value to convert * @param roundUp should we roundup the division * @returns the converted elastic part */ toElastic(base: BigNumber, roundUp: boolean): BigNumber; /** * Get a base value represented in terms of the current rebase. * @param elastic the elastic value to convert * @param roundUp should we roundup the division * @returns the converted base part */ toBase(elastic: BigNumber, roundUp: boolean): BigNumber; } declare class MirageAsset { readonly symbol: string; readonly name: string; readonly decimals: number; readonly debtRebase: Rebase; readonly objectAddress: AccountAddress; constructor(tokenObjectResources: MoveResource[], deployerAddress: AccountAddress); static getMirageAssetAddress(symbol: string, deployerAddress: AccountAddress): AccountAddress; } declare const getMusdAddress: (deployerAddress: AccountAddress) => AccountAddress; /** * Represents a mirage-protocol VaultCollection. * Deposit collateral and borrow "mirage-assets". */ declare class VaultCollection { /** * The collateral asset of the vault */ readonly collateralAddress: string; /** * The borrow asset of the vault (a mirage asset e.g. mUSD) */ readonly borrowAddress: string; /** * The borrow asset of the vault (a mirage asset e.g. mUSD) */ readonly borrowSymbol: string; /** * The collateral asset of the vault (a mirage asset e.g. mUSD) */ readonly collateralSymbol: string; /** * The rebase representing the total borrow in the vault */ readonly borrowRebase: Rebase; /** * The total collateral deposited in this vault */ readonly totalCollateral: BigNumber; /** * The total borrowed from this vault */ readonly totalBorrow: BigNumber; /** * The interest rate of this vault (precision: 1e12) */ readonly interestPerSecond: BigNumber; /** * The minimum a position must be collateralized in the vault to update vault position (remove collateral, borrow more) (percent) */ readonly initialCollateralizationPercent: number; /** * The minimum a position must be collateralized in the vault to avoid liquidation (percent) */ readonly maintenanceCollateralizationPercent: number; /** * The flat borrow fee for the vault (percent) */ readonly borrowFeePercent: number; /** * The last cached exchange rate of the vault (precision: 1e8) * This price is collateral / borrow */ readonly exchangeRate: BigNumber; /** * If this collection is in an emergency and is frozen */ readonly isEmergency: boolean; /** * The percent taken as a protocol/liquidator cut during a liquidation */ readonly liquidationPercent: number; /** * The global debt */ readonly mirage: MirageAsset; /** * The collateral pyth price feed id */ readonly collateralOracleAddress: string; /** * The borrow pyth price feed id */ readonly borrowOracleAddress: string; readonly collateralDecimals: number; readonly minCollateralAmount: BigNumber; readonly maxCollectionDebtAmount: BigNumber; /** * The vault collection object address */ readonly objectAddress: AccountAddress; readonly name: string; /** * Construct an instance of VaultCollection * @param collectionObjectResources resources from the VaultCollection account * @param borrowTokenObjectResources resources from the borrow token and its debt store * @param objectAddress the address of the vault collection object * @param config mirage configuration */ constructor(collectionObjectResources: MoveResource[], borrowTokenObjectResources: MoveResource[], collateralDecimals: number, deployerAddress: AccountAddress); static getVaultCollectionType(deployerAddress: AccountAddress): TypeTagStruct; /** * Get the vault collection annual interest rate * @returns the interest rate in a percent */ getInterestRatePercent(): number; /** * Gets debt part for borrow token amount * @param borrowAmount amount of tokens * @returns debt part in global rebase */ borrowTokensToDebtPart(borrowAmount: number): number; static getVaultCollectionName(collateralSymbol: string, borrowSymbol: string): string; static getVaultCollectionAddress(name: string, deployerAddress: AccountAddress): AccountAddress; } /** * Represents a Vault struct. * Stores info about a vault's deposits and borrows */ declare class Vault { /** * The amount of collateral deposited */ readonly collateralAmount: BigNumber; /** * The amount borrowed */ readonly borrowAmount: BigNumber; /** * The vaults pnl in the borrow token */ readonly pnl: BigNumber; /** * The vaults fees in the borrow token */ readonly feesPaid: BigNumber; /** * An instance of the VaultCollection for this Vault */ readonly vaultCollection: VaultCollection; readonly objectAddress: AccountAddress; /** * Construct an instance of Vault * @param vaultObjectResources resources from vault token account * @param vaultCollection a vault collection entity * @param objectAddress the vault object address */ constructor(vaultObjectResources: MoveResource[], vaultCollection: VaultCollection, deployerAddress: AccountAddress); getHealth(collateralPrice: BigNumber, borrowPrice: BigNumber): number; static getVaultType(deployerAddress: AccountAddress): TypeTagStruct; } declare function calculateVaultHealth(collateralAmount: BigNumber, borrowAmount: BigNumber, maintenanceCollateralizationPercent: number, collateralPrice: BigNumber, borrowPrice: BigNumber): number; /** * Represents a Vault struct. * Stores info about a vault's deposits and borrows */ declare class UserProfileCollection { readonly referralPeriodLengthSec: number; readonly referralPeriodInitTime: Date; readonly baseReferralRate: number; readonly maxReferralRate: number; readonly maxVipReferralRate: number; readonly feesRequiredForMaxRate: BigNumber; readonly objectAddress: AccountAddress; /** * Construct an instance of Vault * @param profileObjectResources resources from vault token account * @param objectAddress the vault object address * @param deployerAddress the deployer address */ constructor(profileObjectResources: MoveResource[], deployerAddress: AccountAddress); static getUserProfileCollectionType(deployerAddress: AccountAddress): TypeTagStruct; timestampPeriodsAgo(): number; static getUserProfileCollectionAddress(deployerAddress: AccountAddress): AccountAddress; } declare class UserProfile { readonly customReferralCode: string | undefined; readonly lastPeriodVolumeMusd: BigNumber; readonly currentPeriodVolumeMusd: BigNumber; readonly nextPeriodFeeRate: number; readonly lastFeesEarned: Date; readonly vipFeeRate: BigNumber | undefined; readonly feeDepositAddress: AccountAddress | undefined; readonly objectAddress: AccountAddress; constructor(profileObjectResources: MoveResource[], profileCollection: UserProfileCollection, deployerAddress: AccountAddress); static getUserProfileType(deployerAddress: AccountAddress): TypeTagStruct; static getUserProfileAddress(userAddress: AccountAddress, deployerAddress: AccountAddress): AccountAddress; } declare class UserReferral { readonly referrerAddress: AccountAddress; readonly lastPeriodVolumeMusd: BigNumber; readonly currentPeriodVolumeMusd: BigNumber; readonly lastReferralTimestamp: Date; constructor(accountResources: MoveResource[], deployerAddress: AccountAddress); static getUserReferralType(deployerAddress: AccountAddress): TypeTagStruct; } declare class MarketEntitiesClient { private readonly config; constructor(config: MirageConfig); createMarket(marketObjectResources: MoveResource[], objectAddress: string): Market; createPosition(positionObjectResources: MoveResource[], market: Market, objectAddress: string): Position; createPositionWithStrategies(positionObjectResources: MoveResource[], strategyObjectsResources: MoveResource[][], market: Market, objectAddress: string): Position; createLimitOrder(limitOrderResources: MoveResource[], objectAddress: string): LimitOrder; createTpsl(tpslResources: MoveResource[], objectAddress: string): TpSl; } declare class MarketQueriesClient { private readonly base; private readonly aptosGqlClient; constructor(base: MarketClientBase, aptosGqlClient: Client); getOwnedPositionAddresses: (owner: string) => Promise<string[]>; getOwnedPositionAddressesByMarket: (perpSymbol: string, marginSymbol: string, owner: string) => Promise<string[]>; } type CreatePositionOptionals = { takeProfit?: number; stopLoss?: number; expiration?: bigint; }; declare class MarketTransactionClient { private readonly base; constructor(base: MarketClientBase); getPlaceOrderPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, orderType: OrderType, marginAmount: number, positionSize: number, side: PositionSide, desiredPrice: number, maxPriceSlippage: number, isDecreaseOnly: boolean, options?: CreatePositionOptionals) => Promise<TransactionPayloadEntryFunction>; getPlaceOrderPayloadVaas: (positionObjectAddress: MoveObjectType, orderType: OrderType, marginAmount: number, positionSize: number, side: PositionSide, desiredPrice: number, maxPriceSlippage: number, isDecreaseOnly: boolean, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined, options?: CreatePositionOptionals) => TransactionPayloadEntryFunction; getCreatePositionAndPlaceOrderPayload: (perpSymbol: string, marginSymbol: string, orderType: OrderType, marginAmount: number, positionSize: number, side: PositionSide, desiredPrice: number, maxPriceSlippage: number, createPositionOptionals?: CreatePositionOptionals) => Promise<TransactionPayloadEntryFunction>; getCreatePositionAndPlaceOrderPayloadVaas: (perpSymbol: string, marginSymbol: string, orderType: OrderType, marginAmount: number, positionSize: number, side: PositionSide, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined, createPositionOptionals?: CreatePositionOptionals) => TransactionPayloadEntryFunction; getIncreaseMarginPayload: (positionObjectAddress: MoveObjectType, increaseMarginAmount: number) => Promise<TransactionPayloadEntryFunction>; getDecreaseMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, decreaseMarginAmount: number) => Promise<TransactionPayloadEntryFunction>; getDecreaseMarginPayloadVaas: (positionObjectAddress: MoveObjectType, decreaseMarginAmount: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getIncreasePositionSizePayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, positionSizeIncrease: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getIncreasePositionSizePayloadVaas: (positionObjectAddress: MoveObjectType, positionSizeIncrease: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getDecreasePositionSizePayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, decreasePositionSize: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getDecreasePositionSizePayloadVaas: (positionObjectAddress: MoveObjectType, decreasePositionSize: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getClosePositionPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, desired_price: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getClosePositionPayloadVaas: (positionObjectAddress: MoveObjectType, desired_price: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getPlaceTpslPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, takeProfitPrice: number, stopLossPrice: number) => Promise<TransactionPayloadEntryFunction>; getPlaceTpslPayloadVaas: (positionObjectAddress: MoveObjectType, takeProfitPrice: number, stopLossPrice: number, perpVaa: MoveVector<U8>) => TransactionPayloadEntryFunction; getUpdateTpslPayload: (perpSymbol: string, marginSymbol: string, tpslObjectAddress: MoveObjectType, takeProfitPrice: number, stopLossPrice: number) => Promise<TransactionPayloadEntryFunction>; getUpdateTpslPayloadVaas: (tpslObjectAddress: MoveObjectType, takeProfitPrice: number, stopLossPrice: number, perpVaa: MoveVector<U8>) => TransactionPayloadEntryFunction; getUpdateMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, oldMarginAmount: number, newMarginAmount: number) => Promise<TransactionPayloadEntryFunction>; getUpdateMarginPayloadVaas: (positionObjectAddress: MoveObjectType, oldMarginAmount: number, newMarginAmount: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getUpdateLimitOrderPayload: (perpSymbol: string, marginSymbol: string, limitOrderObjectAddress: MoveObjectType, newPositionSize: number, newSide: PositionSide, newTriggerPrice: number, newMaxPriceSlippage: number, newIsDecreaseOnly: boolean, newTriggersAbove: boolean, newExpiration: bigint) => Promise<TransactionPayloadEntryFunction>; getUpdateLimitOrderPayloadVaas: (limitOrderObjectAddress: MoveObjectType, newPositionSize: number, newSide: PositionSide, newTriggerPrice: number, newMaxPriceSlippage: number, newIsDecreaseOnly: boolean, newTriggersAbove: boolean, newExpiration: bigint, perpVaa: MoveVector<U8>) => TransactionPayloadEntryFunction; getTriggerLimitOrderPayload: (perpSymbol: string, marginSymbol: string, limitOrderObjectAddress: MoveObjectType, triggererAddress: string) => Promise<TransactionPayloadEntryFunction>; getTriggerLimitOrderPayloadVaas: (limitOrderObjectAddress: MoveObjectType, triggererAddress: string, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getTriggerTpslPayload: (perpSymbol: string, marginSymbol: string, tpslObjectAddress: MoveObjectType, triggererAddress: string) => Promise<TransactionPayloadEntryFunction>; getTriggerTpslPayloadVaas: (tpslObjectAddress: MoveObjectType, triggererAddress: string, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getLiquidatePositionPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, triggererAddress: string) => Promise<TransactionPayloadEntryFunction>; getLiquidatePositionPayloadVaas: (positionObjectAddress: MoveObjectType, triggererAddress: string, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getIncreaseSizeAndIncreaseMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, positionSizeIncrease: number, marginAmountIncrease: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getIncreaseSizeAndIncreaseMarginPayloadVaas: (positionObjectAddress: MoveObjectType, positionSizeIncrease: number, marginAmountIncrease: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getIncreaseSizeAndDecreaseMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, positionSizeIncrease: number, marginAmountDecrease: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getIncreaseSizeAndDecreaseMarginPayloadVaas: (positionObjectAddress: MoveObjectType, positionSizeIncrease: number, marginAmountDecrease: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getDecreaseSizeAndDecreaseMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, positionSizeDecrease: number, marginAmountDecrease: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getDecreaseSizeAndDecreaseMarginPayloadVaas: (positionObjectAddress: MoveObjectType, positionSizeDecrease: number, marginAmountDecrease: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getDecreaseSizeAndIncreaseMarginPayload: (perpSymbol: string, marginSymbol: string, positionObjectAddress: MoveObjectType, positionSizeDecrease: number, marginAmountIncrease: number, desiredPrice: number, maxPriceSlippage: number) => Promise<TransactionPayloadEntryFunction>; getDecreaseSizeAndIncreaseMarginPayloadVaas: (positionObjectAddress: MoveObjectType, positionSizeDecrease: number, marginAmountIncrease: number, desiredPrice: number, maxPriceSlippage: number, perpVaa: MoveVector<U8>, marginVaa: MoveVector<U8> | undefined) => TransactionPayloadEntryFunction; getCancelLimitOrderPayload: (limitOrderObjectAddress: MoveObjectType) => TransactionPayloadEntryFunction; getCleanupLimitOrderPayload: (limitOrderObjectAddress: MoveObjectType) => TransactionPayloadEntryFunction; getCleanupTpslPayload: (tpslObjectAddress: MoveObjectType) => TransactionPayloadEntryFunction; getCancelTpslPayload: (tpslObjectAddress: MoveObjectType) => TransactionPayloadEntryFunction; getIncreaseLimitOrderMarginPayload: (limitOrderObjectAddress: MoveObjectType, marginIncrease: number) => TransactionPayloadEntryFunction; getDecreaseLimitOrderMarginPayload: (limitOrderObjectAddress: MoveObjectType, marginDecrease: number) => TransactionPayloadEntryFunction; getCloseAllPositionsPayload: (allPositionObjectAddress: MoveObjectType[], allPerpVaas: (MoveVector<U8> | undefined)[], allMarginVaas: (MoveVector<U8> | undefined)[]) => TransactionPayloadEntryFunction; } declare const userAssetBalanceView: (userAddress: string, tokenMetadataAddress: string, coinType: `${string}::${string}::${string}` | undefined, tokenDecimals: number, aptosClient: Aptos) => Promise<BigNumber>; declare const allMirageAssetsView: (aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType[]>; declare const fATotalSupplyView: (faMetadataAddress: MoveObjectType, faDecimals: number, aptosClient: Aptos) => Promise<BigNumber>; type AllPositionInfo = { marketObjectAddress: string; openingPrice: number; isLong: boolean; marginAmount: number; positionSize: number; outstandingFunding: number; liquidationPrice: number; maintenanceMarginUsd: number; }; declare const allMarketAddressesView: (aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType[]>; declare const marketPerpSymbolView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const marketNameView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos) => Promise<MoveObjectType>; declare const marketMarginOracleView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const marketPerpOracleView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const marketMarginTokenAddressView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const marketMarginSymbolView: (marketObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const isLimitOrderTriggerableView: (limitOrderObject: MoveObjectType, perpPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<boolean>; declare const isLimitOrderTriggerableBulkView: (limitOrderObjectAddresses: MoveObjectType[], perpPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<boolean[]>; declare const liquidationPriceView: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const availableMarginView: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const positionFundingView: (positionObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const liquidationPriceBulkView: (positionObjectAddresses: MoveObjectType[], perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number[]>; /** * Get an estimate of the current fee in terms of USD * @param positionSizeAsset the position size * @param isLong if the trade is long * @param isClose if the trade is an open or close * @returns the fee in USD */ declare const estimateFeeView: (marketObjectAddress: string, positionSize: number, isLong: boolean, perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const positionMaintenanceMarginMusdView: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const allPositionInfoView: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<AllPositionInfo>; declare const allPositionByOwnerQuery: (owner: string, marketObjectAddresses: MoveObjectType[], aptosGqlClient: Client) => Promise<string[]>; declare const positionIdsByMarketAndOwnerQuery: (owner: string, marketObjectAddress: string, aptosGqlClient: Client) => Promise<string[]>; declare const allOraclesView: (aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType[]>; declare const priceFeedIdView: (oracleObjAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const oracleNameView: (oracleObjAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const oraclePriceMultiplierView: (oracleObjAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const numberOfClaimsAvailableView: (userAddress: string, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const timeUntilNextClaimView: (userAddress: string, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const referralDepositAddressView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const userProfileExistsView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<boolean>; declare const userReferrerAddressView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const currentPeriodFeeRateView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const userProfileFeeVolumeView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number[]>; declare const nextReferralRateView: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<number>; declare const getUserProfileCode: (userAddress: AccountAddress, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<string>; declare const allVaultCollectionsView: (aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType[]>; declare const collateralTokenView: (collectionObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType>; declare const borrowTokenView: (collectionObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType>; declare const collateralOracleView: (collectionObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType>; declare const borrowOracleView: (collectionObjectAddress: MoveObjectType, aptosClient: Aptos, deployerAddress: AccountAddress) => Promise<MoveObjectType>; declare const vaultCollectionNameView: (collectionObjectAddress: MoveObjectType, aptosClient: Aptos) => Promise<MoveObjectType>; declare const liquidatableAmountsBulkView: (vaultObjectAddresses: MoveObjectType[], client: Aptos, deployerAddress: AccountAddress, exchangeRate: number) => Promise<number[]>; declare const allOwnedVaultAddressesQuery: (owner: string, allVaultCollectionAddresses: MoveObjectType[], aptosGqlClient: Client) => Promise<string[]>; declare const ownedVaultAddressesByCollectionQuery: (collectionObjectAddress: MoveObjectType, owner: string, aptosGqlClient: Client) => Promise<string[]>; declare const vaultCollectionAPRQuery: (beginDate: Date, collectionObjectAddresses: MoveObjectType, mirageGqlClient: Client) => Promise<number>; declare class MarketViewsClient { private readonly base; private readonly aptosClient; constructor(base: MarketClientBase, aptosClient: Aptos); getAllMarketAddresses: () => Promise<MoveObjectType[]>; getMarketPerpSymbol: (marketObjectAddress: MoveObjectType) => Promise<string>; getMarketMarginTokenAddress: (marketObjectAddress: MoveObjectType) => Promise<string>; getMarketMarginSymbol: (marketObjectAddress: MoveObjectType) => Promise<string>; getMarketMarginOracle: (marketObjectAddress: MoveObjectType) => Promise<string>; getMarketPerpOracle: (marketObjectAddress: MoveObjectType) => Promise<string>; getIsLimitOrderTriggerable: (limitOrderObject: MoveObjectType, perpPrice: number) => Promise<boolean>; getIsLimitOrderTriggerableBulk: (limitOrderObjectAddresses: MoveObjectType[], perpPrice: number) => Promise<boolean[]>; getLiquidationPrice: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number) => Promise<number>; getAvailableMargin: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number) => Promise<number>; getPositionFunding: (positionObjectAddress: MoveObjectType) => Promise<number>; getLiquidationPriceBulk: (positionObjectAddresses: MoveObjectType[], perpPrice: number, marginPrice: number) => Promise<number[]>; getEstimateFee: (perpSymbol: string, marginSymbol: string, positionSize: number, isLong: boolean, perpPrice: number, marginPrice: number) => Promise<number>; getPositionMaintenanceMarginMusd: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number) => Promise<number>; getAllPositionInfo: (positionObjectAddress: MoveObjectType, perpPrice: number, marginPrice: number) => Promise<AllPositionInfo>; } declare class MarketClient extends MarketClientBase { readonly transactions: MarketTransactionClient; readonly views: MarketViewsClient; readonly entities: MarketEntitiesClient; readonly queries: MarketQueriesClient; } declare class VaultClientBase extends MirageClientBase { private readonly fungibleAssets; private readonly oracles; constructor(fungibleAssetClient: FungibleAssetClient, oracleClient: OracleClient, mirageConfig: MirageConfig); static createVaultCollectionName: (collateralSymbol: string, borrowSymbol: string) => string; vaultCollectionExists: (collateralSymbol: string, borrowSymbol: string) => boolean; getVaultCollection: (collateralSymbol: string, borrowSymbol: string) => VaultConfig; getAllVaultCollections: () => VaultConfig[]; getAllVaultCollectionAddresses: () => string[]; getVaultCollectionAddress: (collateralSymbol: string, borrowSymbol: string) => string; getVaultTokensFromAddress: (vaultAddress: string) => { collateralSymbol: string; borrowSymbol: string; }; getCollateralPriceFeedId: (collateralSymbol: string, borrowSymbol: string) => string; getBorrowPriceFeedId: (collateralSymbol: string, borrowSymbol: string) => string; getCollateralPriceFeedUpdate: (collateralSymbol: string, borrowSymbol: string) => Promise<MoveVector<U8>>; getBorrowPriceFeedUpdate: (collateralSymbol: string, borrowSymbol: string) => Promise<MoveVector<U8>>; getCollateralCoinType: (collateralSymbol: string) => string | undefined; getCollateralCoinDecimals: (collateralSymbol: string) => number; } declare class VaultEntitiesClient { private readonly base; private readonly config; constructor(base: VaultClientBase, config: MirageConfig); createRebase(elastic: BigNumber, base: BigNumber): Rebase; createMirageAsset(tokenObjectResources: MoveResource[]): MirageAsset; createVaultCollection(collectionObjectResources: MoveResource[], borrowTokenObjectResources: MoveResource[]): VaultCollection; createVault(vaultObjectResources: MoveResource[], vaultCollection: VaultCollection): Vault; } declare class VaultQueriesClient { private readonly base; private readonly aptosGqlClient; private readonly mirageGqlClient; constructor(base: VaultClientBase, aptosGqlClient: Client, mirageGqlClient: Client); getAllOwnedVaultAddresses: (ownerAddress: string) => Promise<string[]>; getOwnedVaultAddressesByCollection: (collateralSymbol: string, borrowSymbol: string, ownerAddress: string) => Promise<string[]>; getVaultCollectionAPR: (collateralSymbol: string, borrowSymbol: string, beginDate: Date) => Promise<number>; } declare class VaultTransactionClient { private readonly base; constructor(base: VaultClientBase); getCreateVaultPayload: (collateralSymbol: string, borrowSymbol: string, collateralAmount: number) => TransactionPayloadEntryFunction; getCreateVaultAndBorrowPayload: (collateralSymbol: string, borrowSymbol: string, collateralAmount: number, borrowAmount: number) => Promise<TransactionPayloadEntryFunction>; getCreateVaultAndBorrowPayloadVaas: (collateralSymbol: string