@nemoprotocol/vaults-sdk
Version:
A TypeScript SDK for interacting with Nemo Vaults on the Sui blockchain
665 lines (659 loc) • 23.8 kB
TypeScript
import { SuiClient } from '@mysten/sui/client';
import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions';
import Decimal from 'decimal.js';
import { MmtSDK } from '@mmt-finance/clmm-sdk';
import BN from 'bn.js';
import { ExtendedPoolWithApr } from '@mmt-finance/clmm-sdk/dist/types';
interface SdkConfig {
suiClient: SuiClient;
mmtClmmSDK: MmtSDK;
}
interface CalculateAmountParams {
vault_id: string;
is_amount_a: boolean;
input_amount: string;
slippage: number;
side: InputType;
}
interface CalculateAmountResult {
request_id?: string;
side: InputType;
original_input_amount: string;
amount_a: string;
amount_b: string;
amount_limit_a: string;
amount_limit_b: string;
ft_amount: string;
is_amount_a: boolean;
swap_result?: SwapAmountResult;
partner?: string;
}
type SwapAmountResult = {
swap_in_amount: string;
swap_out_amount: string;
a2b: boolean;
is_exceed: boolean;
sui_stake_protocol: SuiStakeProtocol;
after_sqrt_price?: string;
route_obj?: any;
};
declare enum SuiStakeProtocol {
Mmt = "Mmt",
Haedal = "Haedal",
Volo = "Volo",
Aftermath = "aftermath"
}
declare enum InputType {
Both = "both",
OneSide = "oneSide"
}
interface Vault {
id: string;
clmm_pool_id: string;
free_balance_a: string;
free_balance_b: string;
fee_a: string;
fee_b: string;
seed_balance: string;
upper_price_scalling: string;
lower_price_scalling: string;
upper_price_scalling_dec: Decimal;
lower_price_scalling_dec: Decimal;
lower_trigger_price: string;
upper_trigger_price: string;
upper_trigger_price_scalling_dec: Decimal;
lower_trigger_price_scalling_dec: Decimal;
last_rebalance_sqrt_price: string;
last_rebalance_sqrt_price_dec: Decimal;
last_rebalance_time: string;
deposit_limit: string;
free_threshold_a: string;
free_threshold_b: string;
lock_threshold_a: string;
lock_threshold_b: string;
slippage_up: string;
slippage_down: string;
slippage_up_dec: Decimal;
slippage_down_dec: Decimal;
fee_val: string;
withdraw_fee_val: string;
decimals_a: string;
decimals_b: string;
coin_type_a: string;
coin_type_b: string;
lp_token_type: string;
config_type: string;
is_lock: boolean;
is_deposit_enabled: boolean;
pool_sqrt_price: string;
liquidity: string;
total_supply: string;
position: Position;
pool: ExtendedPoolWithApr;
}
interface VaultWithInfo extends Vault {
vault_info: UserVaultInfo;
}
interface VaultBalance {
vault_id: string;
clmm_pool_id: string;
owner: string;
lp_token_type: string;
lp_token_balance: string;
lp_token_decimals: number;
liquidity: string;
tick_lower_index: number;
tick_upper_index: number;
amount_a: string;
amount_b: string;
coin_type_a: string;
coin_type_b: string;
decimal_a: string;
decimal_b: string;
}
interface UserVaultInfo {
vaultName: string;
aliasName: string;
vaultAddress: string;
vaultId: string;
poolId: string;
sourceProtocol: string;
sourceProtocolUrl: string;
sourceProtocolLogoUrl: string;
apy: string;
apyRateChange: string;
vaultType: string;
vaultLogo: string;
vaultPrice: string;
vaultPriceRateChange: string;
earningRateChange: string;
decimal: string;
leftCoinType: string;
leftCoinName: string;
leftCoinLogo: string;
leftTokenAmount: string;
leftCoinPrice: string;
leftCoinDecimal: string;
leftSwapUrl: string;
rightCoinType: string;
rightCoinName: string;
rightCoinLogo: string;
rightTokenAmount: string;
rightCoinPrice: string;
rightCoinDecimal: string;
rightSwapUrl: string;
vaultOverview: string;
deploymentUnix: string;
maturity: string;
fee: string;
cardShowTagList: string[];
cumulativeEarning: string;
lastHarvestUnix: string;
tradeStatus: string;
vaultContract: string;
vaultContractVersionList: string[];
vaultGroup: string;
vaultBalanceCap: string;
vaultSupply: string;
points: string;
boost: string;
tvl: string;
earnings: string;
}
interface UserVaultInfoResponse {
count: number;
data: UserVaultInfo[];
msg: string;
page: {
pageIndex: number;
pageSize: number;
};
}
interface VaultHolder {
address: string;
usdValue: number;
}
interface VaultHoldersResponse {
data: {
[vaultId: string]: VaultHolder[];
};
msg: string;
}
interface YtHoldDetail {
marketStateId: string;
usdValue: number;
ytAmount: number;
}
interface YtHoldResponse {
data: {
[vaultId: string]: YtHoldDetail;
};
msg: string;
}
interface Position {
id: string;
pool_id: string;
name: string;
liquidity: string;
clmm_position_id: string;
clmm_pool_id: string;
tick_lower_index: number;
tick_upper_index: number;
type_x: string;
type_y: string;
price_lower_tick_dec: Decimal;
price_upper_tick_dec: Decimal;
}
interface LiquidityInput {
/**
* The amount of coin A.
*/
coin_amount_a: string;
/**
* The amount of coin B.
*/
coin_amount_b: string;
/**
* The maximum amount of token A.
*/
coin_amount_limit_a: string;
/**
* The maximum amount of token B.
*/
coin_amount_limit_b: string;
/**
* The liquidity amount.
*/
liquidity_amount: string;
/**
* Whether to fix the amount of token A.
*/
is_amount_a: boolean;
}
type CoinAmounts = {
coin_amount_a: string;
coin_amount_b: string;
};
type DepositParams = {
vault_id: string;
coin_object_a?: TransactionObjectArgument;
coin_object_b?: TransactionObjectArgument;
slippage: number;
deposit_result: CalculateAmountResult;
return_coin?: boolean;
};
type WithdrawParams = {
vault_id: string;
ft_amount: string;
slippage: number;
return_coin?: boolean;
};
type CalculateRemoveAmountParams = {
vault_id: string;
is_amount_a: boolean;
is_ft_input: boolean;
input_amount: string;
max_ft_amount: string;
slippage: number;
side: InputType;
request_id?: string;
};
type CalculateRemoveAmountResult = {
request_id?: string;
side: InputType;
amount_a: string;
amount_b: string;
amount_limit_a: string;
amount_limit_b: string;
burn_ft_amount: string;
swap_result?: SwapAmountResult;
};
/**
* Represents a paginated data page with optional cursor and limit.
*/
type DataPage<T> = {
data: T[];
next_cursor?: any;
has_next_page: boolean;
};
/**
* Represents query parameters for pagination.
*/
type PageQuery = {
cursor?: any;
limit?: number | null;
};
/**
* Represents arguments for pagination, with options for fetching all data or using PageQuery.
*/
type PaginationArgs = 'all' | PageQuery;
/**
* Represents a SUI struct tag.
*/
type SuiStructTag = {
/**
* The full address of the struct.
*/
full_address: string;
/**
* The source address of the struct.
*/
source_address: string;
/**
* The address of the struct.
*/
address: string;
/**
* The module to which the struct belongs.
*/
module: string;
/**
* The name of the struct.
*/
name: string;
/**
* An array of type arguments (SUI addresses) for the struct.
*/
type_arguments: string[];
};
/**
* Represents a coin asset with address, object ID, and balance information.
*/
type CoinAsset = {
/**
* The address type of the coin asset.
*/
coin_type: string;
/**
* The object identifier of the coin asset.
*/
coin_object_id: string;
/**
* The balance amount of the coin asset.
*/
balance: bigint;
};
type BuildCoinResult = {
target_coin: TransactionObjectArgument;
selected_coins: string[];
remain_coins: CoinAsset[];
is_mint_zero_coin: boolean;
target_coin_amount: string;
original_spited_coin?: TransactionObjectArgument;
};
interface PreSwapLpChangeParams {
poolID: string;
ticklower: number;
tickUpper: number;
deltaLiquidity: number;
}
interface FindRouterParams {
from: string;
target: string;
amount: BN;
byAmountIn: boolean;
depth?: number;
splitAlgorithm?: string;
splitFactor?: number;
splitCount?: number;
providers?: string[];
liquidityChanges?: PreSwapLpChangeParams[];
}
type WithdrawBothParams = {
vault_id: string;
ft_amount: string;
slippage: number;
return_coin?: boolean;
};
type WithdrawOneSideParams = {
vault_id: string;
is_amount_a: boolean;
is_ft_input: boolean;
input_amount: string;
max_ft_amount: string;
slippage: number;
partner?: string;
return_coin?: boolean;
primary_coin_inputs?: TransactionObjectArgument;
};
interface CoinMetadata {
decimals: number;
}
interface CoinBalance {
totalBalance: string;
}
declare class CacheUtil {
/**
* The underlying SuiClient instance used for making RPC calls to the Sui network.
* This client is used to interact with the Sui blockchain and execute various operations.
*/
private readonly _cache;
private static instance;
private constructor();
static getInstance(): CacheUtil;
/**
* Updates the cache for the given key.
*
* @param key The key of the cache entry to update.
* @param data The data to store in the cache.
* @param time The time in minutes after which the cache entry should expire.
*/
updateCache(key: string, data: any, time?: number): void;
/**
* Gets the cache entry for the given key.
*
* @param key The key of the cache entry to get.
* @param force_refresh Whether to force a refresh of the cache entry.
* @returns The cache entry for the given key, or undefined if the cache entry does not exist or is expired.
*/
getCache<T>(key: string, force_refresh?: boolean): T | undefined;
}
declare class Vaults {
protected _config: SdkConfig;
protected _cache: CacheUtil;
protected _default_sender_address: string;
constructor(config: SdkConfig);
getConfig(): SdkConfig;
static createSDK(options: {
client?: any;
fullNodeUrl?: string;
headers?: HeadersInit;
}): Vaults;
getOwnerVaultBalance(wallet_address: any, vault_id: string): Promise<VaultBalance | null>;
/**
* Get position tokenA and tokenB amounts for a specific vault with price data
* @param vault_id - The vault ID to get position amounts for
* @returns Object containing tokenA and tokenB amounts with their decimals and price data
*/
getPositionAssets(vault_id: string): Promise<{
amount_a: string;
amount_b: string;
decimal_a: number;
decimal_b: number;
coin_type_a: string;
coin_type_b: string;
price_a?: number;
price_b?: number;
value_usd_a?: number;
value_usd_b?: number;
total_value_usd?: number;
lp_usd_price?: number;
} | null>;
private getTokenSchemas;
/**
* Get remaining deposit capacity for a specific vault
* @param vault_id - The vault ID to get remaining capacity for
* @returns Object containing deposit limit, current position value, and remaining capacity in USD
*/
getRemainingCap(vault_id: string): Promise<{
deposit_limit_usd: number;
current_position_value_usd: number;
remaining_cap_usd: number;
} | null>;
getOwnerVaultsBalance(wallet_address: any): Promise<VaultBalance[]>;
getOwnerVaultsBalanceObj(wallet_address: any): Promise<Record<string, VaultBalance>>;
/**
* Get list of vault holders for a specific vault with their USD values
* @param vault_id - The vault ID to get holders for
* @returns Vault holders response with addresses and USD values
*/
getVaultHolders(vault_id: string): Promise<VaultHoldersResponse>;
/**
* Get detailed vault information including APY, earnings, and token details
* @param vault_id - The vault ID to get information for
* @returns Vault information with earnings, APY, and token details
*/
getVaultInfo(vault_id: string): Promise<UserVaultInfo>;
/**
* Get YT (Yield Token) hold details for a specific address
* @param address - The wallet address to get YT hold details for
* @returns YT hold information including market state, volume, and YT amount
*/
getYtHoldDetail(address: string): Promise<YtHoldResponse>;
getOwnerVaultsBalanceByVaultId(wallet_address: any, vault_id: string): Promise<VaultBalance | undefined>;
getAllVaultObj(pagination_args?: PaginationArgs): Promise<Record<string, Vault>>;
getVaultList(pagination_args?: PaginationArgs): Promise<Vault[]>;
private getVaultByIds;
getVault(id: string, force_refresh?: boolean): Promise<VaultWithInfo | undefined>;
private getVaultAndPool;
/**
* Check if a vault is currently rebalancing
* @param vault - The vault to check
* @returns true if the vault is rebalancing, false otherwise
*/
private isVaultRebalancing;
calculateDepositAmount(params: CalculateAmountParams, should_request_stake?: boolean, adjust_best_amount?: boolean): Promise<CalculateAmountResult>;
private calculateAmountFromBoth;
private calculateDepositAmountFromOneSide;
/**
* @param params
*/
calculateStakeDepositFixSui(params: {
input_sui_amount: Decimal;
swap_sui_amount: Decimal;
left_sui_amount: Decimal;
right_sui_amount: Decimal;
lower_tick: number;
upper_tick: number;
cur_sqrt_price: string;
remain_rate: number;
fix_coin_a: boolean;
rebalance_count: number;
should_request_stake: boolean;
stake_protocol: SuiStakeProtocol;
slippage: number;
exchange_rate?: string;
}): Promise<any | null>;
deposit(params: DepositParams, sender_address: string, tx: Transaction): Promise<TransactionObjectArgument | undefined>;
private depositInternal;
private handleDepositSwap;
withdraw(params: WithdrawBothParams | WithdrawOneSideParams, sender_address: string, tx: Transaction): Promise<{
return_coin_a?: TransactionObjectArgument;
return_coin_b?: TransactionObjectArgument;
}>;
calculateWithdrawAmount(params: CalculateRemoveAmountParams): Promise<CalculateRemoveAmountResult>;
private calculateWithdrawAmountFromOneSide;
private withdrawInternal;
getVaultMarketHolders(vaultId?: string): Promise<{
address: string;
usdValue: string;
}[]>;
getVaultStatus(): Promise<{
vaultId: string;
isRebalancing: boolean;
vaultName: string;
disable: boolean;
}[]>;
}
declare class Admin {
static readonly FEE_FACTOR = 1000000;
protected _config: SdkConfig;
protected _senderAddress: string;
constructor(config: SdkConfig, senderAddress: string);
setSenderAddress(value: string): void;
getSenderAddress(): string;
getConfig(): SdkConfig;
static createSDK(options: {
fullNodeUrl?: string;
senderAddress: string;
}): Admin;
newUncorrelatedVault(param: UncorrelatedVaultParam, tx?: Transaction): Promise<Transaction>;
newStableVault(param: StableVaultParam, tx?: Transaction): Promise<Transaction>;
newDriftVault(param: DriftVaultParam, tx?: Transaction): Promise<Transaction>;
seed(param: SeedParam, tx?: Transaction): Promise<Transaction>;
private getVault;
private buildVaultWithoutLiquidityAndPosition;
setSource(coinType: string, isPrimary: boolean, tx: Transaction): Promise<Transaction>;
setCoinDecimals(coinType: string, decimals: number, tx: Transaction): Promise<Transaction>;
setDepositLimit(vaultId: string, vaultCap: string, depositLimit: bigint, tx: Transaction): Promise<Transaction>;
setPricePairId(coinType: string, tx: Transaction): Promise<Transaction>;
setSlippage(riskAdminCapId: string, vaultId: string, slippageUp: string, slippageDown: string, tx: Transaction): Promise<Transaction>;
setFreeThresholdA(riskAdminCapId: string, vaultId: string, vaultCap: string, freeThresholdA: string, tx: Transaction): Promise<Transaction>;
setFreeThresholdB(riskAdminCapId: string, vaultId: string, vaultCap: string, freeThresholdB: string, tx: Transaction): Promise<Transaction>;
setLockThresholdA(riskAdminCapId: string, vaultId: string, vaultCap: string, lockThresholdB: string, tx: Transaction): Promise<Transaction>;
setLockThresholdB(riskAdminCapId: string, vaultId: string, vaultCap: string, lockThresholdB: string, tx: Transaction): Promise<Transaction>;
pauseVault(pauseAdminCapId: string, vaultId: string, tx: Transaction): Promise<Transaction>;
setPositionPriceScalingForVault(vaultConfigAdminCapId: string, vaultId: string, lowerPriceFactor: string, upperPriceFactor: string, tx: Transaction): Promise<Transaction>;
setTriggerScalling(vaultConfigAdminCapId: string, vaultId: string, lowerTriggerPriceScalling: string, upperTriggerPriceScalling: string, tx: Transaction): Promise<Transaction>;
setUpgeerTriggerPriceFactorDrift(vaultConfigAdminCapId: string, vaultId: string, upperTriggerPriceScalling: string, tx: Transaction): Promise<Transaction>;
addForceRebalanceDf(riskAdminCapId: string, vaultId: string, tx: Transaction): Promise<Transaction>;
setDepositEnable(riskAdminCapId: string, vaultId: string, enable: boolean, tx: Transaction): Promise<Transaction>;
unpauseVault(unpauseAdminCapId: string, vaultId: string, tx: Transaction): Promise<Transaction>;
setFee(feeAdminCapId: string, vaultId: string, feeVal: string, tx: Transaction): Promise<Transaction>;
setWithdrawFee(feeAdminCapId: string, vaultId: string, withdrawFeeVal: string, tx: Transaction): Promise<Transaction>;
setRebalancePriceSource(rebalanceAdminCap: string, vaultId: string, price_source: number, tx: Transaction): Promise<Transaction>;
setUcTargetAdapter(rebalanceAdminCapId: string, vaultId: string, vaultCap: string, targetAdapter: string, tx: Transaction): Promise<Transaction>;
setTargetAdapter(rebalanceAdminCapId: string, vaultId: string, targetAdapter: string, tx: Transaction): Promise<Transaction>;
setUcIsTargetReverse(rebalanceAdminCapId: string, vaultId: string, isTargetReverse: boolean, tx: Transaction): Promise<Transaction>;
issueVaultCap(treasuryAdminCapId: string, vaultId: string, tx: Transaction): Promise<Transaction>;
setActiveVaultCap(treasuryAdminCapId: string, vaultId: string, vaultCapId: string, tx: Transaction): Promise<Transaction>;
setVaultParameters(vaultConfigAdminCapId: string, riskAdminCapId: string, vaultId: string, lowerPriceFactor: string, upperPriceFactor: string, slippageUp: string, slippageDown: string, freeThresholdA: string, freeThresholdB: string, lockThresholdA: string, lockThresholdB: string, depositLimit: string, tx: Transaction): Promise<Transaction>;
issueVaultConfigCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issueRiskAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issueFeeAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issueRebalanceAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issueTreasuryAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issuePauseAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
issueUnpauseAdminCap(userAddress: string, tx: Transaction): Promise<Transaction>;
revokeVaultConfigCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokeRiskAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokeFeeAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokeRebalanceAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokeTreasuryAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokePauseAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
revokeUnpauseAdminCap(capId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
issueAllCapabilities(userAddress: string, tx: Transaction): Promise<Transaction>;
issueRebalanceCap(vaultCapId: string, userAddress: string, tx: Transaction): Promise<Transaction>;
issueSpecificCapabilities(userAddress: string, issueVaultConfig: boolean, issueRisk: boolean, issueFee: boolean, issueRebalance: boolean, issueTreasury: boolean, issuePause: boolean, issueUnpause: boolean, tx: Transaction): Promise<Transaction>;
addSwapRoute(vaultId: string, vaultCap: string, poolId: string, returnsX: boolean, xToY: boolean, typeArg: string, tx: Transaction, poolId1?: string, xToY1?: boolean): Promise<Transaction>;
removeSwapRoute(vaultId: string, vaultCap: string, typeArg: string, tx: Transaction): Promise<Transaction>;
updateStalenessThreshold(stalenessThreshold: number, tx: Transaction): Promise<Transaction>;
}
interface UncorrelatedVaultParam {
pool_id: string;
treasury_cap_id: string;
upper_price_scalling: string;
lower_price_scalling: string;
slippage_up: string;
slippage_down: string;
free_threshold_a: string;
free_threshold_b: string;
lock_threshold_a: string;
lock_threshold_b: string;
fee_val: string;
withdraw_fee_val: string;
decimals_a: number;
decimals_b: number;
deposit_limit: string;
target_adapter: string;
is_target_reverse: boolean;
coin_type_a: string;
coin_type_b: string;
coin_type_token: string;
}
interface StableVaultParam {
pool_id: string;
treasury_cap_id: string;
upper_price_scalling: string;
lower_price_scalling: string;
slippage_up: string;
slippage_down: string;
free_threshold_a: string;
free_threshold_b: string;
fee_val: string;
withdraw_fee_val: string;
decimals_a: number;
decimals_b: number;
deposit_limit: string;
coin_type_a: string;
coin_type_b: string;
coin_type_token: string;
}
interface DriftVaultParam {
pool_id: string;
treasury_cap_id: string;
upper_price_scalling: string;
lower_price_scalling: string;
slippage_up: string;
slippage_down: string;
free_threshold_a: string;
free_threshold_b: string;
lock_threshold_a: string;
lock_threshold_b: string;
fee_val: string;
withdraw_fee_val: string;
decimals_a: number;
decimals_b: number;
deposit_limit: string;
target_adapter: string;
coin_type_a: string;
coin_type_b: string;
coin_type_token: string;
}
interface SeedParam {
vault_id: string;
vault_cap: string;
asset_a: string;
asset_b: string;
}
export { Admin, type BuildCoinResult, type CalculateAmountParams, type CalculateAmountResult, type CalculateRemoveAmountParams, type CalculateRemoveAmountResult, type CoinAmounts, type CoinAsset, type CoinBalance, type CoinMetadata, type DataPage, type DepositParams, type FindRouterParams, InputType, type LiquidityInput, type PageQuery, type PaginationArgs, type Position, type PreSwapLpChangeParams, type SdkConfig, SuiStakeProtocol, type SuiStructTag, type SwapAmountResult, type UserVaultInfo, type UserVaultInfoResponse, type Vault, type VaultBalance, type VaultHolder, type VaultHoldersResponse, type VaultWithInfo, Vaults, type WithdrawBothParams, type WithdrawOneSideParams, type WithdrawParams, type YtHoldDetail, type YtHoldResponse };