UNPKG

aftermath-ts-sdk

Version:
1,723 lines (1,710 loc) 671 kB
import * as _mysten_sui_transactions from '@mysten/sui/transactions'; import { Transaction, TransactionObjectArgument, TransactionArgument, Argument } from '@mysten/sui/transactions'; import * as _mysten_sui_jsonRpc from '@mysten/sui/jsonRpc'; import { EventId, DynamicFieldInfo, SuiTransactionBlockResponse, CoinMetadata, SuiValidatorSummary, ValidatorsApy, SuiSystemStateSummary, SuiObjectResponse, CoinStruct, SuiEvent, SuiEventFilter, TransactionEffects, SuiObjectDataOptions, SuiObjectDataFilter, SuiTransactionBlockResponseQuery, SuiJsonRpcClient, DynamicFieldName, DisplayFieldsResponse } from '@mysten/sui/jsonRpc'; import { MultiSigPublicKey } from '@mysten/sui/multisig'; import { BcsType } from '@mysten/sui/bcs'; import { Keypair } from '@mysten/sui/cryptography'; /** * Represents the body payload sent to the dynamic gas service, * which includes the serialized transaction and any user-provided * gas configuration (e.g., coin type). */ interface ApiDynamicGasBody { /** * The serialized transaction block in base64 or similar format. */ serializedTx: SerializedTransaction; /** * The address of the user for whom the dynamic gas is being set. */ walletAddress: SuiAddress; /** * The coin type to be used for gas payment (e.g., "0x2::sui::SUI"). */ gasCoinType: CoinType; } /** * Represents the response from the dynamic gas service, typically returning * updated transaction bytes and possibly a sponsored signature if the * transaction gas is being partially or fully sponsored. */ interface ApiDynamicGasResponse { /** * The modified transaction bytes that incorporate a gas coin or sponsor information. */ txBytes: SerializedTransaction; /** * A signature used to sponsor or verify the updated transaction, if applicable. */ sponsoredSignature: string; } type SuiNetwork = "DEVNET" | "TESTNET" | "LOCAL" | "MAINNET"; /** * Represents a token or currency balance in the system, defined as a bigint. */ type Balance = bigint; /** * Represents a fixed-point integer using a bigint. May be used for calculations requiring * precision (e.g., decimal-like math). */ type IFixed = bigint; type SuiCheckpoint = bigint; /** * Represents a gas budget for transactions. Typically a raw `number`. */ type GasBudget = number; /** * Represents a timestamp in milliseconds or seconds. Typically a raw `number`. */ type Timestamp = number; /** * A single byte, typically expressed as a `number` from 0 to 255. */ type Byte = number; /** * Defines the allowable slippage in a trading scenario, expressed as an unscaled percentage (e.g., 0.01 = 1%). */ type Slippage = number; /** * Represents an unscaled percentage (e.g., 0.01 = 1%). */ type Percentage = number; /** * Annual percentage rate (APR), expressed as a `number` (e.g., 0.01 = 1%). */ type Apr = number; /** * Annual percentage yield (APY), expressed as a `number` (e.g., 0.01 = 1%). */ type Apy = number; /** * Represents the version of an on-chain object, expressed as a `number`. */ type ObjectVersion = number; /** * Represents an error code from a Move smart contract, typically a `number`. */ type MoveErrorCode = number; /** * Represents a serialized transaction in a base64 or similar format. */ type SerializedTransaction = string; /** * Represents raw transaction bytes in a base64 or similar format. */ type TxBytes = string; /** * Represents a BigInt in string form, typically used for JSON serialization. */ type BigIntAsString = string; /** * Represents a numeric value in string form, typically used for JSON serialization. */ type NumberAsString = string; /** * Represents an IFixed value in string form, typically used for JSON serialization. */ type IFixedAsString = string; /** * A key type used in certain contexts, typically a string (e.g., "ed25519", "secp256k1"). */ type KeyType = string; /** * Represents any string identifying an object type, such as "0x2::sui::SUI". */ type AnyObjectType = string; /** * Represents the name of a Move module, e.g. "Router" or "Coin". */ type ModuleName = string; /** * Represents the name of a Move function, e.g. "swap" or "mint". */ type FunctionName = string; /** * Represents the ID of a published Move package on the Sui network, e.g. "0x<package_id>". */ type PackageId = string; /** * Represents a color in a string format (e.g., "#FFFFFF" or "blue"). */ type Color = string; /** * Represents a URL in string format (e.g., "https://example.com"). */ type Url = string; /** * Represents a local resource URL (e.g., "file://path/to/resource"). */ type LocalUrl = string; /** * Represents a file path (e.g., "/usr/local/bin"). */ type FilePath = string; /** * Represents an on-chain object ID (e.g., "0x<32-byte_hex>"). */ type ObjectId = string; /** * Represents a Sui wallet address (e.g., "0x<address>"). */ type SuiAddress = string; /** * Represents a TransactionDigest from a Sui transaction, typically a hex-encoded string. */ type TransactionDigest = string; /** * Represents a single byte in string form, usually hex-encoded (e.g., "0xFF"). */ type StringByte = string; /** * Represents an object's digest, typically a hex-encoded string. */ type ObjectDigest = string; /** * Represents an IFixed type as an array of bytes. */ type IFixedAsBytes = Byte[]; /** * Represents an IFixed type in string form, each byte also in string form. */ type IFixedAsStringBytes = string[]; /** * Represents an ID as an array of bytes in string form. */ type IdAsStringBytes = string[]; /** * Holds information about third-party fees in transactions, including the recipient * and the fee percentage to be collected. */ interface ExternalFee { /** * Address of the recipient for collected fees. */ recipient: SuiAddress; /** * Percentage of the fee to be collected. * @remarks 0.54 = 54% */ feePercentage: Percentage; } /** * A function signature for signing arbitrary messages. Typically used in * cryptographic contexts. */ type SignMessageCallback = (args: { message: Uint8Array; }) => Promise<{ signature: string; }>; /** * Generic shape for events with optional paging cursor data. */ interface IndexerEventsWithCursor<EventType> { /** * An array of events of type `EventType`. */ events: EventType[]; /** * The next cursor position. If undefined, no more events are available. */ nextCursor: number | undefined; } /** * A generic shape for events with a Sui-based cursor structure. */ interface EventsWithCursor<EventType> { /** * An array of events of type `EventType`. */ events: EventType[]; /** * The next cursor position. If null, no more events are available. */ nextCursor: EventId | null; } /** * Represents a Sui event, typically including type, timestamp, and transaction digest. */ interface Event$1 { /** * A string identifying the Move event type. */ type: AnyObjectType; /** * Timestamp of the event, if available. */ timestamp: Timestamp | undefined; /** * The transaction digest associated with the event. */ txnDigest: TransactionDigest; } /** * Common inputs for event retrieval, including an optional cursor and limit. */ interface EventsInputs { /** * Cursor for pagination, often an EventId or numeric index. */ cursor?: EventId; /** * Limit for pagination, specifying the maximum number of events. */ limit?: number; } /** * Inputs for retrieving user events, extending from general event inputs * and including the user's wallet address. */ type UserEventsInputs = EventsInputs & { walletAddress: SuiAddress; }; /** * Represents a Sui object, including its ID and type. */ interface Object$1 { /** * The on-chain object ID. */ objectId: ObjectId; /** * The Move type of the object. */ objectType: AnyObjectType; } /** * Holds the dynamic fields and an optional next cursor for pagination. */ interface DynamicFieldsWithCursor { /** * An array of dynamic field information objects. */ dynamicFields: DynamicFieldInfo[]; /** * The next cursor for pagination. If null, no more fields are available. */ nextCursor: ObjectId | null; } /** * Holds the dynamic field objects and an optional next cursor for pagination. */ interface DynamicFieldObjectsWithCursor<ObjectType> { /** * An array of objects derived from dynamic fields. */ dynamicFieldObjects: ObjectType[]; /** * The next cursor for pagination. If null, no more fields are available. */ nextCursor: ObjectId | null; } /** * Inputs for fetching dynamic fields, including optional cursor and limit for pagination. */ interface DynamicFieldsInputs { cursor?: ObjectId; limit?: number; } /** * A collection of transactions with a cursor for pagination. */ interface TransactionsWithCursor { /** * An array of Sui transactions. */ transactions: SuiTransactionBlockResponse[]; /** * The next cursor for pagination. If null, no more transactions are available. */ nextCursor: TransactionDigest | null; } /** * Generic shape for API data requests that include pagination parameters. */ interface ApiDataWithCursorBody<CursorType> { /** * Cursor for pagination. */ cursor?: CursorType; /** * Limit for pagination. */ limit?: number; } /** * Specifies the shape for API calls involving events. */ type ApiEventsBody = ApiDataWithCursorBody<EventId>; /** * Specifies the shape for API calls involving dynamic fields. */ type ApiDynamicFieldsBody = ApiDataWithCursorBody<ObjectId>; /** * Specifies the shape for API calls involving transactions. */ type ApiTransactionsBody = ApiDataWithCursorBody<TransactionDigest>; /** * Body payload for indexer-based event queries, using a numeric cursor. */ type ApiIndexerEventsBody = ApiDataWithCursorBody<number>; /** * Body payload for indexer-based user events, extending from `ApiIndexerEventsBody`. */ type ApiIndexerUserEventsBody = ApiIndexerEventsBody & { /** * The wallet address of the user. */ walletAddress: SuiAddress; }; /** * Represents query parameters for retrieving data with skip/limit pagination in an indexer. */ interface IndexerDataWithCursorQueryParams { skip: number; limit: number; } /** * Configuration for constructing a `Caller`. Includes network specification * and optional access token for authentication. */ interface CallerConfig { /** * The target Sui network (e.g., "MAINNET", "TESTNET"). Determines the * default API host when `baseUrl` is not supplied. */ network?: SuiNetwork; /** * Explicit override for the API host (e.g. `"http://localhost:8080"`). * Takes precedence over the network-derived default. Use this to point * the SDK at a custom or local backend. */ baseUrl?: string; /** * Access token used for authenticated requests, if required. */ accessToken?: string; /** * URL path segment placed between the host and the package prefix when * building API call URLs (`{host}/{apiEndpoint}/{package}/...`). * Defaults to `"api"`. Override only when targeting a backend that * mounts the Aftermath API under a different path. */ apiEndpoint?: string; } interface ApiTransactionResponse { txKind: SerializedTransaction; sponsorSignature?: string; } interface SdkTransactionResponse { tx: Transaction; } interface KioskOwnerCapObject extends Object$1 { kioskObjectId: ObjectId; } interface KioskObject extends Object$1 { kioskOwnerCapId: ObjectId; nfts: Nft[]; isPersonal: boolean; } interface Nft { info: NftInfo; display: NftDisplay; } interface NftInfo { objectId: ObjectId; objectType: AnyObjectType; } interface NftDisplay { suggested: NftDisplaySuggested; other: NftDisplayOther; } interface NftDisplaySuggested { name?: string; link?: Url; imageUrl?: Url; description?: string; projectUrl?: Url; creator?: string; } type NftDisplayOther = Record<string, string>; type CoinGeckoChain = Lowercase<"Ethereum" | "Arbitrum" | "Bsc" | "Solana" | "Sui" | "Polygon" | "Avalanche" | "Optimism" | "Base">; type CoinGeckoCoinApiId = string; interface CoinGeckoCoinData { chain: CoinGeckoChain | ""; apiId: CoinGeckoCoinApiId; name: string; symbol: CoinSymbol; coinType: CoinType; } interface CoinGeckoCoinSymbolData { apiId: CoinGeckoCoinApiId; name: string; symbol: CoinSymbol; } type RpcEndpoint = string; interface ConfigAddresses { faucet?: FaucetAddresses; staking?: StakingAddresses; pools?: PoolsAddresses; daoFeePools?: DaoFeePoolsAddresses; suiFrens?: SuiFrensAddresses; nftAmm?: NftAmmAddresses; router?: RouterAddresses; referralVault?: ReferralVaultAddresses; perpetuals?: PerpetualsAddresses; perpetualsVaults?: PerpetualsVaultsAddresses; farms?: FarmsAddresses; dynamicGas?: DynamicGasAddresses; scallop?: ScallopAddresses; dca?: DcaAddresses; limitOrders?: LimitAddresses; sharedCustody?: SharedCustodyAddresses; nfts?: NftsAddresses; } interface FaucetAddresses { packages: { faucet: SuiAddress; suiFrensGenesisWrapper: SuiAddress; }; objects: { faucet: ObjectId; suiFrensMint: ObjectId; }; } interface StakingAddresses { packages: { lsd: SuiAddress; afsui: SuiAddress; events: SuiAddress; }; objects: { stakedSuiVault: ObjectId; stakedSuiVaultState: ObjectId; safe: ObjectId; treasury: ObjectId; referralVault: ObjectId; validatorConfigsTable: ObjectId; aftermathValidator: ObjectId; }; } interface PoolsAddresses { packages: { amm: SuiAddress; ammInterface: SuiAddress; events: SuiAddress; eventsV2: SuiAddress; }; objects: { poolRegistry: ObjectId; protocolFeeVault: ObjectId; treasury: ObjectId; insuranceFund: ObjectId; lpCoinsTable: ObjectId; }; other?: { createLpCoinPackageCompilations: Record<CoinDecimal, string>; }; } interface DaoFeePoolsAddresses { packages: { amm: SuiAddress; events: SuiAddress; }; objects: { version: ObjectId; }; } interface SuiFrensAddresses { packages: { suiFrens: SuiAddress; suiFrensBullshark: SuiAddress; accessories: SuiAddress; suiFrensVault: SuiAddress; suiFrensVaultCapyLabsExtension: SuiAddress; }; objects: { capyLabsApp: ObjectId; suiFrensVault: ObjectId; suiFrensVaultStateV1: ObjectId; suiFrensVaultStateV1MetadataTable: ObjectId; suiFrensVaultCapyLabsExtension: ObjectId; }; } interface NftAmmAddresses { packages: { nftAmm: SuiAddress; }; objects: { protocolFeeVault: ObjectId; treasury: ObjectId; insuranceFund: ObjectId; referralVault: ObjectId; }; } interface RouterAddresses { packages: { utils: SuiAddress; }; } interface ReferralVaultAddresses { packages: { referralVault: SuiAddress; }; objects: { referralVault: ObjectId; }; } interface PerpetualsAddresses { packages: { events: SuiAddress; }; objects: { registry: ObjectId; }; } interface PerpetualsVaultsAddresses { other: { createLpCoinPackageCompilation: string; }; } interface FarmsAddresses { packages: { vaults: SuiAddress; vaultsInitial: SuiAddress; vaultsV2: SuiAddress; eventsV2: SuiAddress; }; objects: { version: ObjectId; }; } interface DynamicGasAddresses { sponsorAddress: SuiAddress; } interface ScallopAddresses { objects: { version: ObjectId; afSuiMarket: ObjectId; coinDecimalsRegistry: ObjectId; xOracle: ObjectId; }; } interface DcaAddresses { packages: { dca: SuiAddress; events: SuiAddress; eventsV2: SuiAddress; }; objects: { readonly config: ObjectId; }; } interface LimitAddresses { packages: { limitOrders: SuiAddress; events: SuiAddress; }; } interface SharedCustodyAddresses { address: ObjectId; publicKey: ObjectId; } interface NftsAddresses { packages: { mystenTransferPolicy: SuiAddress; }; } interface MoveErrorsInterface { readonly moveErrors: MoveErrors; } type MoveErrors = Record<PackageId, Record<"ANY" | ModuleName, Record<MoveErrorCode, string>>>; /** Parsed location of a Move abort, the output of `Helpers.parseMoveErrorMessage`. */ interface ParsedMoveError { errorCode: MoveErrorCode; packageId: ObjectId; module: ModuleName; } /** Parsed Move abort plus the human-readable message resolved from the registry. */ interface TranslatedMoveError extends ParsedMoveError { error: string; } /** * Interface specifying allowable rate limits for an auth account. * The `p` field indicates the path or endpoint (e.g., "/pools"), * while `m` indicates the method-based limits (GET or POST, or both). */ interface RateLimit { /** * The path or endpoint to be rate-limited, e.g. "/pools" or "/router/trade". */ p: string; /** * The method-based limit specification. * For example: * ``` * { GET: { l: 100 } } * { POST: { l: 50 } } * { GET: { l: 100 }, POST: { l: 100 } } * ``` */ m: { GET: { l: number; }; } | { POST: { l: number; }; } | { GET: { l: number; }; POST: { l: number; }; }; } /** * The request body for creating a new auth account, typically * reserved for admin usage. The admin signs a JSON containing * an "AccountCreate" `method` plus desired sub-account data. */ interface ApiCreateAuthAccountBody { /** * The admin's Sui address, zero-padded if necessary. */ walletAddress: SuiAddress; /** * The signature of the serialized JSON data, from the admin's private key. */ signature: string; /** * The JSON string that was signed, containing the method and sub-account details. */ serializedJson: string; } /** * The request body for obtaining or refreshing an access token. The user signs * a "GetAccessToken" method message plus any relevant fields. */ interface ApiGetAccessTokenBody { /** * The user's Sui address, zero-padded if needed. */ walletAddress: SuiAddress; /** * The signature over the JSON-serialized request data (nonce, date, etc.). */ signature: string; /** * The actual JSON string that was signed, e.g.: * ``` * { * "date": 1234567890, * "nonce": 512, * "method": "GetAccessToken", * "value": {} * } * ``` */ serializedJson: string; } /** * The response returned when a user obtains or refreshes an access token, * containing the token string, the HTTP header name (usually "Authorization"), * and the token's expiration timestamp in milliseconds. */ interface ApiGetAccessTokenResponse { /** * The newly issued access token to be used in `Authorization` headers. */ accessToken: string; /** * The header key that should contain `accessToken` (e.g., "Authorization"). */ header: string; /** * The UNIX timestamp (milliseconds) after which the token is invalid. */ expirationTimestamp: Timestamp; } /** * Represents the decimal precision of a coin (e.g., 9 or 18). */ type CoinDecimal = number; /** * A string that uniquely identifies a coin type in the Sui network * (e.g., "0x2::sui::SUI"). */ type CoinType = string; /** * Represents a short symbol or ticker for a coin (e.g., "SUI", "BTC"). */ type CoinSymbol = string; /** * Represents a coin with an amount in integer or floating form, typically used * to specify a user’s holding or a transaction amount. */ interface CoinWithAmount { /** * The coin type, e.g. "0x2::sui::SUI". */ coin: CoinType; /** * The amount of the coin, typically expressed as an integer number of smallest units. */ amount: number; } /** * Represents a coin with an amount that can be `undefined`, typically for optional or * deferred usage scenarios. */ interface CoinWithAmountOrUndefined { /** * The coin type, e.g. "0x2::sui::SUI". */ coin: CoinType; /** * The amount of the coin, which can be `undefined`. */ amount: number | undefined; } /** * Represents an amount in both coin denomination and USD value for reference. */ interface AmountInCoinAndUsd { /** * The amount of the coin in smallest units. */ amount: number; /** * The USD equivalent of that coin amount. */ amountUsd: number; } /** * Maps a coin type to a numerical balance. Typically used to store multiple * coin balances under their respective coin types. */ type CoinsToBalance = Record<CoinType, Balance>; /** * Maps a coin type to a numerical balance, which may be `undefined`. */ type CoinsToBalanceOrUndefined = Record<CoinType, Balance | undefined>; /** * Maps a coin type to its price, typically as a number in USD or another fiat currency. */ type CoinsToPrice = Record<CoinType, number>; /** * Maps a coin type to its on-chain decimal precision. */ type CoinsToDecimals = Record<CoinType, CoinDecimal>; /** * Maps a coin type to price information, typically containing a price and a 24-hour change. */ type CoinsToPriceInfo = Record<CoinType, CoinPriceInfo>; /** * Maps a coin symbol (e.g., "SUI") to its price information, typically containing a price and a 24-hour change. */ type CoinSymbolsToPriceInfo = Record<CoinSymbol, CoinPriceInfo>; /** * Maps a coin symbol (e.g., "SUI") to an array of possible coin types (e.g., "0x2::sui::SUI"). */ type CoinSymbolToCoinTypes = Record<CoinSymbol, CoinType[]>; /** * Represents pricing information for a coin, including current price and 24-hour percentage change. */ interface CoinPriceInfo { /** * The current price in USD or another currency. */ price: number; /** * The 24-hour percentage change of the coin price. * @remarks 0.54 = 54% */ priceChange24HoursPercentage: Percentage; } /** * Extends the Sui `CoinMetadata` with optional properties relevant to external data * sources (e.g., CoinGecko). */ type CoinMetadaWithInfo = CoinMetadata & { /** * Indicates whether this coin's metadata was generated automatically. */ isGenerated?: boolean; /** * The associated CoinGecko API ID, if available. */ coingeckoId?: CoinGeckoCoinApiId; }; /** * Represents a coin reference in the Move environment, using either an on-chain ObjectId * or an input index or result index from a transaction. */ type ServiceCoinData = { Coin: ObjectId; } | { Input: number; } | { Result: number; } | { NestedResult: [number, number]; }; /** * **Legacy type** representing a coin reference in the Move environment, using * older transaction output indexing structures. */ type ServiceCoinDataV2 = "Gas" | { Input: number; } | { Result: number; } | { NestedResult: [number, number]; }; /** * A multiplier type (in fixed-point bigint) used to scale a staked amount based on lock duration. * Typically, 1.0 is represented as 1e9 (i.e., `FixedUtils.fixedOneB`). */ type FarmsMultiplier = bigint; /** * Enumerates the supported farm system versions. */ type FarmsVersion = 1 | 2; /** * A union type indicating whether an action is authorized by the `ownerCapId` * or by a `oneTimeAdminCapId`. */ type FarmOwnerOrOneTimeAdminCap = { ownerCapId: ObjectId; } | { oneTimeAdminCapId: ObjectId; }; /** * Indicates how strictly the lock duration is enforced in the vault. * - **Strict**: The position cannot be unlocked before the lock period ends. * - **Relaxed**: The position can be unlocked early, but may have penalized rewards. */ type FarmsLockEnforcement = "Strict" | "Relaxed"; /** * Describes a single reward coin's parameters and state within a staking pool. */ interface FarmsStakingPoolRewardCoin { /** * The coin type of this reward (e.g., "0x2::sui::SUI"). */ coinType: CoinType; /** * The total number of reward tokens allocated for this pool (in smallest units). */ rewards: Balance; /** * Represents how many rewards are allocated per share in the pool. The share * is typically the "stakedAmountWithMultiplier". */ rewardsAccumulatedPerShare: Balance; /** * The emission rate per emission schedule for this reward coin. For example, if * `emissionSchedulesMs` is 1 hour, then this emissionRate is distributed each hour. */ emissionRate: Balance; /** * The interval (in ms) at which the emissionRate is released. */ emissionSchedulesMs: Timestamp; /** * The timestamp (ms) when emission for this reward coin starts. */ emissionStartTimestamp: Timestamp; /** * The last timestamp (ms) at which rewards were emitted for this reward coin. */ lastRewardTimestamp: Timestamp; /** * The total number of rewards still available. If we have distributed * part of `rewards`, the remainder is `rewardsRemaining`. */ rewardsRemaining: Balance; /** * The actual number of reward tokens in the pool's on-chain object. This can differ * from `rewards` for internal or reserved logic. */ actualRewards: Balance; } /** * Represents the core object for a staking pool (a "vault"). It includes * information about staking amounts, locking constraints, reward coins, * and emission parameters. */ interface FarmsStakingPoolObject extends Object$1 { /** * The coin type that users stake into this pool. */ stakeCoinType: CoinType; /** * The total amount of staked tokens (principal) in this pool, in smallest units. */ stakedAmount: Balance; /** * The total staked amount multiplied by users' lock multipliers. Used for reward calculations. */ stakedAmountWithMultiplier: Balance; /** * The minimum time (ms) that a position can be locked for a valid multiplier. */ minLockDurationMs: Timestamp; /** * The maximum time (ms) that a position can be locked. The position's lock multiplier is derived from * minLockDurationMs to maxLockDurationMs. */ maxLockDurationMs: Timestamp; /** * The maximum lock multiplier in fixed-point representation (1.0 = 1e9). */ maxLockMultiplier: FarmsMultiplier; /** * An array of reward coins that this pool distributes. */ rewardCoins: FarmsStakingPoolRewardCoin[]; /** * The timestamp (ms) after which no further emissions occur. */ emissionEndTimestamp: Timestamp; /** * The minimum stake required to open a position in this pool. */ minStakeAmount: Balance; /** * Whether the pool is forcibly unlocked. If `true`, positions might be able to exit early. */ isUnlocked: boolean; /** * The lock enforcement policy for this pool. * - "Strict": positions must be unlocked before any principal can be withdrawn * - "Relaxed": positions can withdraw principal while locked, forfeiting pro-rata locked rewards */ lockEnforcement: FarmsLockEnforcement; /** * Indicates whether this is version 1 or version 2 of the farm system. */ version: FarmsVersion; } /** * Represents the owner's capability to manage a specific staking pool. Typically * allows updating emission rates, reward coins, or other parameters. */ interface StakingPoolOwnerCapObject extends Object$1 { /** * The staking pool (vault) ID associated with this owner cap. */ stakingPoolId: ObjectId; } /** * Represents a one-time admin capability object for a specific staking pool. Allows * the holder to initialize a new reward coin once. */ interface StakingPoolOneTimeAdminCapObject extends Object$1 { /** * The staking pool (vault) ID associated with this admin cap. */ stakingPoolId: ObjectId; } /** * Represents the rewards accumulated and owed to a staked position for a specific coin type. */ interface FarmsStakedPositionRewardCoin { /** * The coin type of the reward. */ coinType: CoinType; /** * The base (non-multiplied) rewards accrued since the position was opened or last updated. */ baseRewardsAccumulated: Balance; /** * The base rewards debt, representing the total base rewards from time t0 to the last update checkpoint. */ baseRewardsDebt: Balance; /** * The multiplier-based rewards accrued, factoring in the lock multiplier, since the position was opened or last updated. */ multiplierRewardsAccumulated: Balance; /** * The multiplier-based rewards debt, from time t0 to the last update checkpoint. */ multiplierRewardsDebt: Balance; } /** * Represents a user's staked position in a specific staking pool, including * the lock parameters, staked amounts, and accumulated rewards. */ interface FarmsStakedPositionObject extends Object$1 { /** * The on-chain object ID of the pool in which this position is staked. */ stakingPoolObjectId: ObjectId; /** * The coin type that was staked into this position (matching the pool's stakeCoinType). */ stakeCoinType: CoinType; /** * The amount of principal staked in smallest units. */ stakedAmount: Balance; /** * The principal multiplied by the lock multiplier. */ stakedAmountWithMultiplier: Balance; /** * The timestamp (ms) when this position’s lock started. */ lockStartTimestamp: Timestamp; /** * The duration (ms) for which this position is locked. */ lockDurationMs: Timestamp; /** * The current lock multiplier in fixed-point representation. */ lockMultiplier: FarmsMultiplier; /** * An array of reward coins that track base + multiplier rewards for this position. */ rewardCoins: FarmsStakedPositionRewardCoin[]; /** * The last time (ms) that rewards were updated or harvested for this position. */ lastHarvestRewardsTimestamp: Timestamp; /** * The farm system version of this staked position (1 or 2). */ version: FarmsVersion; } /** * A partial staked position structure sometimes used internally, excluding * certain fields like `coinType`. */ type PartialFarmsStakedPositionObject = Omit<FarmsStakedPositionObject, "rewardCoins"> & { rewardCoins: Omit<FarmsStakedPositionRewardCoin, "coinType">[]; }; /** * A union type representing any possible event from a farm (vault) system. */ type FarmEvent = FarmsAddedRewardEvent | FarmsCreatedVaultEvent | FarmsDepositedPrincipalEvent | FarmsDestroyedStakedPositionEvent | FarmsHarvestedRewardsEvent | FarmsIncreasedEmissionsEvent | FarmsInitializedRewardEvent | FarmsJoinedEvent | FarmsLockedEvent | FarmsSplitEvent | FarmsStakedEvent | FarmsStakedRelaxedEvent | FarmsUnlockedEvent | FarmsWithdrewPrincipalEvent; /** * A union type for events that specifically involve user interactions with a farm, * such as depositing principal, harvesting, or unlocking. */ type FarmUserEvent = FarmsDepositedPrincipalEvent | FarmsHarvestedRewardsEvent | FarmsLockedEvent | FarmsStakedEvent | FarmsUnlockedEvent | FarmsWithdrewPrincipalEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsDepositedPrincipalEvent`. */ declare const isFarmsDepositedPrincipalEvent: (event: FarmUserEvent) => event is FarmsDepositedPrincipalEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsHarvestedRewardsEvent`. */ declare const isFarmsHarvestedRewardsEvent: (event: FarmUserEvent) => event is FarmsHarvestedRewardsEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsLockedEvent`. */ declare const isFarmsLockedEvent: (event: FarmUserEvent) => event is FarmsLockedEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsStakedEvent`. */ declare const isFarmsStakedEvent: (event: FarmUserEvent) => event is FarmsStakedEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsUnlockedEvent`. */ declare const isFarmsUnlockedEvent: (event: FarmUserEvent) => event is FarmsUnlockedEvent; /** * Type guard to determine if a `FarmUserEvent` is a `FarmsWithdrewPrincipalEvent`. */ declare const isFarmsWithdrewPrincipalEvent: (event: FarmUserEvent) => event is FarmsWithdrewPrincipalEvent; /** * Fired when additional reward tokens are added to a vault after creation. */ interface FarmsAddedRewardEvent extends Event$1 { vaultId: ObjectId; rewardType: CoinType; rewardAmount: Balance; } /** * Fired when a new vault (staking pool) is created. */ interface FarmsCreatedVaultEvent extends Event$1 { vaultId: ObjectId; stakeType: CoinType; minLockDurationMs: Timestamp; maxLockDurationMs: Timestamp; maxLockMultiplier: FarmsMultiplier; minStakeAmount: Balance; } /** * Fired when principal is deposited into a staked position in the vault. */ interface FarmsDepositedPrincipalEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; amount: Balance; stakeType: CoinType; } /** * Fired when a staked position object is destroyed. */ interface FarmsDestroyedStakedPositionEvent extends Event$1 { stakedPositionId: ObjectId; } /** * Fired when a user harvests their rewards from one or more staked positions. */ interface FarmsHarvestedRewardsEvent extends Event$1 { vaultId: ObjectId; rewardTypes: CoinType[]; rewardAmounts: Balance[]; } /** * Fired when emissions (or the emission schedule) are increased for a specific reward coin. */ interface FarmsIncreasedEmissionsEvent extends Event$1 { vaultId: ObjectId; rewardType: CoinType; emissionScheduleMs: Timestamp; emissionRate: Balance; } /** * Fired when a new reward coin is initialized in the vault. */ interface FarmsInitializedRewardEvent extends Event$1 { vaultId: ObjectId; rewardType: CoinType; rewardAmount: Balance; emissionRate: Balance; emissionStartMs: Timestamp; } /** * Fired when two staked positions are combined (joined) into one. */ interface FarmsJoinedEvent extends Event$1 { stakedPositionId: ObjectId; otherStakedPositionId: ObjectId; } /** * Fired when a position is locked, specifying the lock duration and multiplier. */ interface FarmsLockedEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; stakedType: CoinType; stakedAmount: Balance; lockStartTimestampMs: Timestamp; lockDurationMs: Timestamp; lockMultiplier: FarmsMultiplier; } /** * Fired when a staked position is split into two separate positions. */ interface FarmsSplitEvent extends Event$1 { stakedPositionId: ObjectId; splitStakedPositionId: ObjectId; } /** * Fired when a user stakes a new position in the vault (version 1 only). */ interface FarmsStakedEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; stakedType: CoinType; stakedAmount: Balance; multipliedStakedAmount: Balance; lockStartTimestampMs: Timestamp; lockDurationMs: Timestamp; lockMultiplier: FarmsMultiplier; } /** * Fired when a user stakes a new position in the vault under "relaxed" locking (version 2). */ interface FarmsStakedRelaxedEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; stakedType: CoinType; stakedAmount: Balance; lockStartTimestampMs: Timestamp; lockEndTimestampMs: Timestamp; } /** * Fired when a position is unlocked. */ interface FarmsUnlockedEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; stakedType: CoinType; stakedAmount: Balance; } /** * Fired when principal is withdrawn from a staked position. */ interface FarmsWithdrewPrincipalEvent extends Event$1 { stakedPositionId: ObjectId; vaultId: ObjectId; amount: Balance; stakeType: CoinType; } /** * Request body for fetching all staked positions owned by a given user. */ interface ApiFarmsOwnedStakedPositionsBody { /** * The user's wallet address whose positions are being queried. */ walletAddress: SuiAddress; } /** * Request body for staking tokens in a pool (version 2). */ interface ApiFarmsStakeBody { stakingPoolId: ObjectId; lockDurationMs: Timestamp; stakeCoinType: CoinType; stakeAmount: Balance; walletAddress: SuiAddress; isSponsoredTx?: boolean; } /** * **Deprecated**: Use `ApiFarmsStakeBody` instead. */ interface ApiFarmsStakeBodyV1 { stakingPoolId: ObjectId; lockDurationMs: Timestamp; stakeCoinType: CoinType; stakeAmount: Balance; walletAddress: SuiAddress; isSponsoredTx?: boolean; } /** * Request body for depositing additional principal into an existing staked position. */ interface ApiFarmsDepositPrincipalBody { stakedPositionId: ObjectId; stakingPoolId: ObjectId; stakeCoinType: CoinType; depositAmount: Balance; walletAddress: SuiAddress; isSponsoredTx?: boolean; } /** * Request body for fully or partially unstaking a position. */ interface ApiFarmsUnstakeBody { stakedPositionId: ObjectId; stakingPoolId: ObjectId; stakeCoinType: CoinType; rewardCoinTypes: CoinType[]; withdrawAmount: Balance; walletAddress: SuiAddress; claimSuiAsAfSui?: boolean; } /** * Request body for locking a staked position to gain a multiplier (version 2). */ interface ApiFarmsLockBody { stakedPositionId: ObjectId; stakingPoolId: ObjectId; lockDurationMs: Timestamp; stakeCoinType: CoinType; walletAddress: SuiAddress; } /** * Request body for renewing an existing lock on a staked position. */ interface ApiFarmsRenewLockBody { stakedPositionId: ObjectId; stakingPoolId: ObjectId; stakeCoinType: CoinType; walletAddress: SuiAddress; } /** * Request body for unlocking a staked position prior to or at lock expiry. */ interface ApiFarmsUnlockBody { stakedPositionId: ObjectId; stakingPoolId: ObjectId; stakeCoinType: CoinType; walletAddress: SuiAddress; } /** * Request body for harvesting rewards from one or more staked positions. */ interface ApiHarvestFarmsRewardsBody { stakingPoolId: ObjectId; stakeCoinType: CoinType; stakedPositionIds: ObjectId[]; rewardCoinTypes: CoinType[]; walletAddress: SuiAddress; claimSuiAsAfSui?: boolean; } /** * Request body for creating a new staking pool (version 2). */ interface ApiFarmsCreateStakingPoolBody { minLockDurationMs: Timestamp; maxLockDurationMs: Timestamp; maxLockMultiplier: FarmsMultiplier; minStakeAmount: Balance; stakeCoinType: CoinType; walletAddress: SuiAddress; isSponsoredTx?: boolean; } /** * **Deprecated**: Use `ApiFarmsCreateStakingPoolBody` instead. */ interface ApiFarmsCreateStakingPoolBodyV1 { minLockDurationMs: Timestamp; maxLockDurationMs: Timestamp; maxLockMultiplier: FarmsMultiplier; minStakeAmount: Balance; stakeCoinType: CoinType; walletAddress: SuiAddress; isSponsoredTx?: boolean; } /** * Request body for initializing a new reward in a staking pool, requiring either `ownerCapId` or `oneTimeAdminCapId`. */ type ApiFarmsInitializeStakingPoolRewardBody = { stakingPoolId: ObjectId; rewardAmount: Balance; emissionScheduleMs: Timestamp; emissionRate: bigint; emissionDelayTimestampMs: Timestamp; stakeCoinType: CoinType; rewardCoinType: CoinType; walletAddress: SuiAddress; isSponsoredTx?: boolean; } & FarmOwnerOrOneTimeAdminCap; /** * Request body for topping up multiple reward coins in a staking pool, requiring either `ownerCapId` or `oneTimeAdminCapId`. */ type ApiFarmsTopUpStakingPoolRewardsBody = { stakingPoolId: ObjectId; stakeCoinType: CoinType; rewards: { rewardCoinType: CoinType; rewardAmount: Balance; }[]; walletAddress: SuiAddress; isSponsoredTx?: boolean; } & FarmOwnerOrOneTimeAdminCap; /** * Request body for increasing the emissions for specified reward coins in a pool (owner only). */ interface ApiFarmsIncreaseStakingPoolRewardsEmissionsBody { ownerCapId: ObjectId; stakingPoolId: ObjectId; stakeCoinType: CoinType; rewards: { rewardCoinType: CoinType; emissionScheduleMs: Timestamp; emissionRate: bigint; }[]; walletAddress: SuiAddress; } /** * Request body for fetching staking pool owner caps owned by a user. */ interface ApiFarmsOwnedStakingPoolOwnerCapsBody { walletAddress: SuiAddress; } /** * Request body for fetching staking pool one-time admin caps owned by a user. */ interface ApiFarmsOwnedStakingPoolOneTimeAdminCapsBody { walletAddress: SuiAddress; } /** * Request body for granting a one-time admin cap of a particular reward coin to another user. */ interface ApiFarmsGrantOneTimeAdminCapBody { ownerCapId: ObjectId; recipientAddress: SuiAddress; rewardCoinType: CoinType; walletAddress: SuiAddress; isSponsoredTx?: boolean; } interface FaucetMintCoinEvent extends Event$1 { minter: SuiAddress; coinType: CoinType; amount: Balance; } interface FaucetAddCoinEvent extends Event$1 { coinType: CoinType; } interface ApiFaucetRequestBody { coinType: CoinType; walletAddress: SuiAddress; } interface ApiFaucetMintSuiFrenBody { mintFee: Balance; suiFrenType: AnyObjectType; walletAddress: SuiAddress; } interface NftAmmMarketObject extends Object$1 { nftsTable: { objectId: ObjectId; size: bigint; }; pool: PoolObject; fractionalizedSupply: Balance; fractionalizedCoinAmount: Balance; fractionalizedCoinType: CoinType; assetCoinType: CoinType; lpCoinType: CoinType; nftType: AnyObjectType; } type NftAmmInterfaceGenericTypes = [ lpCoinType: CoinType, fractionalizedCoinType: CoinType, assetCoinType: CoinType, nftType: AnyObjectType ]; interface ApiNftAmmBuyBody { marketObjectId: ObjectId; walletAddress: SuiAddress; nftObjectIds: ObjectId[]; slippage: Slippage; referrer?: SuiAddress; } interface ApiNftAmmSellBody { marketObjectId: ObjectId; walletAddress: SuiAddress; nftObjectIds: ObjectId[]; slippage: Slippage; referrer?: SuiAddress; } interface ApiNftAmmDepositBody { walletAddress: SuiAddress; marketObjectId: ObjectId; assetCoinAmountIn: Balance; nftObjectIds: ObjectId[]; slippage: Slippage; referrer?: SuiAddress; } interface ApiNftAmmWithdrawBody { walletAddress: SuiAddress; marketObjectId: ObjectId; lpCoinAmount: Balance; nftObjectIds: ObjectId[]; slippage: Slippage; referrer?: SuiAddress; } /** * Semantic capability type for composed-flow transfers. * * Used by `getTransferCapTx` (Method 2) to specify which kind of capability * is being transferred without exposing Move type tags. */ type PerpetualsCapType = "accountAdmin" | "accountAgent" | "vaultAdmin" | "vaultAgent"; /** * Configuration for gas pool sponsorship on perpetuals transactions. * * When provided, the transaction will include a gas pool sponsor rebate step * that debits the specified wallet's gas pool. */ interface PerpetualsSponsorConfig { /** Wallet address to use for gas pool sponsorship. */ walletAddress: SuiAddress; } /** * Configuration for gas pool sponsorship on perpetuals transactions. * * When provided, the transaction will include a gas pool sponsor rebate step * that debits the specified wallet's gas pool. */ interface PerpetualsSponsorConfig { /** Wallet address to use for gas pool sponsorship. */ walletAddress: SuiAddress; } /** * PTB argument references returned by deferred `create_account` for use * in downstream composed endpoints (share-account, grant-agent-wallet, etc.). */ interface DeferredAccountArgs { /** Argument reference for the created Account object. */ accountArg: TransactionObjectArgument; /** Argument reference for the AccountSharePolicy. */ sharePolicyArg: TransactionObjectArgument; /** Argument reference for the AccountCap<ADMIN>. */ adminCapArg: TransactionObjectArgument; /** Collateral type for the account. */ collateralCoinType: CoinType; } /** * PTB argument reference + semantic capability type for composed-flow * party transfers. */ interface ComposedTransferArgs { /** PTB argument reference for the object to transfer. */ objectArg: TransactionObjectArgument; /** Semantic capability type being transferred. */ capType: PerpetualsCapType; } /** * Unique identifier for a perpetuals market, represented as a Sui object ID * (i.e. the `ClearingHouse` object on-chain). */ type PerpetualsMarketId = ObjectId; /** * Unique numeric identifier for a perpetuals account. * * This is a bigint, as it is derived directly from the on-chain representation. */ type PerpetualsAccountId = bigint; /** * Unique numeric identifier for a perpetuals order. * * This ID is stable across events and API responses. */ type PerpetualsOrderId = bigint; /** * String representation of a {@link PerpetualsOrderId}. * * Some APIs serialize order IDs as strings instead of `bigint`. */ type PerpetualsOrderIdAsString = string; /** * Price type for orders, represented as a fixed-point `bigint` in the * on-chain format (e.g., scaled by `1e9`). */ type PerpetualsOrderPrice = bigint; /** * Side of a perpetuals order. * * - `Bid` (0): Long-side orders / buyers. * - `Ask` (1): Short-side orders / sellers. */ declare enum PerpetualsOrderSide { Ask = 1,// true Bid = 0 } /** * Order execution and posting behavior. * * - `Standard`: No special constraints. * - `FillOrKill`: Either fully fills immediately or cancels. * - `PostOnly`: Only posts to the book; will not take liquidity. * - `ImmediateOrCancel`: Fills as much as possible immediately; remainder is canceled. */ declare enum PerpetualsOrderType { Standard = 0, FillOrKill = 1, PostOnly = 2, ImmediateOrCancel = 3 } /** * Stop order mode. * * - `SlTp`: Stop Loss / Take Profit order, intended to close a position * (fully or partially). * - `Standalone`: Independent stop order that can both reduce or increase * the position, potentially requiring additional allocated collateral. */ declare enum PerpetualsStopOrderType { /** * Stop Loss / Take Profit stop order. Can to be placed to close (fully or partially) * the position. */ SlTp = 0, /** * Stop order that can be both reduce or increase the position's size. May require * some collateral to be allocated to be able to be placed. */ Standalone = 1 } /** * Execution details for a stop order that has been executed. */ type PerpetualsExecutionInfo = { notSpecified: {}; } | { standaloneExecuted: { executionPrice: number; }; } | { stopLossExecuted: { executionPrice: number; }; } | { takeProfitExecuted: { executionPrice: number; }; }; /** * Current state of a stop order in its lifecycle. */ type PerpetualsOrderState = { unknown: {}; } | { invalid: { error: string; }; } | { pending: {}; } | { active: {}; } | { executed: PerpetualsExecutionInfo; } | { cancelled: {}; } | { inExecution: {}; } | { toCancel: {}; }; /** * Aggregate market configuration and state for a single perpetuals market. */ interface PerpetualsMarketData { /** Package ID of the deployed perpetuals contract. */ packageId: PackageId; /** Object ID for the market (clearing house) on-chain. */ objectId: ObjectId; /** Collateral coin type used for margin in this market. */ collateralCoinType: CoinType; /** Static configuration parameters for this market. */ marketParams: PerpetualsMarketParams; /** Dynamic runtime state (funding, open interest, etc.). */ marketState: PerpetualsMarketState; /** Current price of collateral in USD or the platform's base unit. */ collateralPrice: number; /** Oracle/index price of the base asset for this market. */ indexPrice: number; /** Estimated funding rate for the next funding interval. */ estimatedFundingRate: Percentage; /** Timestamp (ms) for the next funding event, as a bigint. */ nextFundingTimestampMs: bigint; } /** * On-chain capability object that grants control over a perpetuals account. * * This represents an "owned" account capability, used to sign and authorize * account-level actions. */ interface PerpetualsAccountCap { /** Object ID of the account capability on-chain. */ objectId: ObjectId; /** Wallet address that owns this account capability. */ walletAddress: SuiAddress; /** Logical ID of the associated perpetuals account. */ accountId: PerpetualsAccountId; /** Object ID of the associated `PerpetualsAccountObject`. */ accountObjectId: ObjectId; /** Collateral coin type backing this account. */ collateralCoinType: CoinType; /** Total collateral (native units) associated with this account. */ collateral: number; /** On-chain object version. */ objectVersion: ObjectVersion; /** On-chain object digest. */ objectDigest: ObjectDigest; /** True if this account cap was allocated to an agent wallet from the