@firefly-exchange/library-sui
Version:
Sui library housing helper methods, classes to interact with Bluefin protocol(s) deployed on Sui
416 lines (415 loc) • 21.2 kB
TypeScript
import { TransactionObjectArgument } from "@mysten/sui/transactions";
import { ZkPayload } from "../interfaces";
import { Address, BigNumber, BigNumberable, DryRunTransactionBlockResponse, ID, NumStr, OnChainCallResponse, SignatureWithBytes, Signer, SuiClient, SuiTransactionBlockResponse, TransactionBlock } from "../types";
import { CoinAmounts, LiquidityInput } from "./clmm";
import { IAddRewardParams, IBluefinSpotContracts, ICoinDetails, IFeeAndRewards, ILiquidityParams, IRewardAmounts, IRewardCoinsInPool, IShioFastModeCustomRange } from "./interfaces";
import { IOnChainCallOptionalParams, ISignerConfig, ISwapParams, ISwapRoute } from "./interfaces/IOnchainCalls";
import { Pool } from "./types";
import { QueryChain } from "./query-chain";
export declare class OnChainCalls {
queryChain: QueryChain;
suiClient: SuiClient;
config: IBluefinSpotContracts;
signerConfig: ISignerConfig;
fastModeEnabled: boolean;
constructor(_suiClient: SuiClient, _config: IBluefinSpotContracts, options?: {
signer?: Signer;
address?: Address;
isUIWallet?: boolean;
isZkLogin?: boolean;
zkPayload?: ZkPayload;
fastModeEnabled?: boolean;
});
/**
* Signs and executes the given transaction block
* @param txb Sui transaction block
* @param options IOnChainCallOptionalParams
* @returns Sui Transaction Block Response
*/
signAndExecuteTxb(txb: TransactionBlock, options?: IOnChainCallOptionalParams): Promise<SuiTransactionBlockResponse>;
/**
* Signs the given transaction
* @param txb Sui transaction block
* @returns Sui Transaction Block Response
*/
signTransaction(txb: TransactionBlock): Promise<SignatureWithBytes>;
/**
* Signs and executes the given transaction block
* @param txb Sui transaction block
* @returns Sui Transaction Block Response
*/
dryRunTxb(txb: TransactionBlock): Promise<DryRunTransactionBlockResponse>;
/**
* Handles call execution
* @param txb The transaction block
* @param options IOnChainCallOptionalParams
* @returns OnChainCallResponse
*/
handleReturn(txb: TransactionBlock, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
private executeZkTransaction;
/**
* Allows admin to set pool creation fee
* @param coinType The fee coin type
* @param amount The amount of fee to be paid
* @param options: OnChain params call
* Returns OnChainCallResponse
*/
setPoolCreationFee(coinType: string, amount: BigNumberable, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to create a pool for provided coins
* @param coinA the type of coin A
* @param coinB the type of coin B
* @param poolName the name of pool
* @param tickSpacing tick spacing
* @param feeBps The fee rate of the pool in bps
* @param price the starting price of the pool
* @param feeCoinType The coin type to be used for payment of pool creation
* @param options: OnChain params call
* Returns OnChainCallResponse
*/
createPool(coinA: ICoinDetails, coinB: ICoinDetails, poolName: string, tickSpacing: number, feeBps: NumStr, price: BigNumberable, feeCoinType: string, options?: IOnChainCallOptionalParams & {
iconURl?: string;
}): Promise<OnChainCallResponse>;
/**
* Allows caller to open a position for the provided pool for given ticks
* @param pool Name or the pool or the pool for which to open the position
* @param lowerTick signed lower tick number
* @param upperTick signed upper tick number
* @param options IOnChainCallOptionalParams & { owner: optional address of the position's owner }
*/
openPosition(pool: Pool, lowerTick: number, upperTick: number, options?: IOnChainCallOptionalParams & {
owner?: string;
}): Promise<OnChainCallResponse>;
/**
* Allows caller to provide liquidity to the pool
* @param pool Name or the pool itself to which liquidity is to be provided
* @param position The ID fo the position for which liquidity is being provided
* @param liquidity The amount of liquidity to provide
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
provideLiquidity(pool: Pool, position: ID, params: ILiquidityParams, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to provide liquidty to the pool by fixed amount of coins
* @param pool Name or the pool itself to which liquidity is to be provided
* @param position The ID fo the position for which liquidity is being provided
* @param amount The amount of coins to be provided
* @param isFixedA True if the amount being provided is coin A
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
provideLiquidityWithFixedAmount(pool: Pool, position: ID, liquidityInput: LiquidityInput, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to remove liquidity from the pool for provided position
* @param pool Name or the pool itself from which liquidity will be removed
* @param position The ID of the position for which liquidity is being removed from
* @param params: LiquidityInput
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
removeLiquidity(pool: Pool, position: ID, params: LiquidityInput, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to open a position and provide liquidity to the pool in a single Tx
* @param pool Name or the pool or the pool for which to open the position
* @param params Liquidity params
* @param options: IOnChainCallOptionalParams
*/
openPositionWithLiquidity(pool: Pool, params: ILiquidityParams, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to open a position and provide liquidity to the pool by fixed amount
* @param pool Name or the pool or the pool for which to open the position
* @param lowerTick The lower tick unsigned bits
* @param upperTick The upper tick unsigned bits
* @param liquidity The amount of liquidity to be provided
* @param options: IOnChainCallOptionalParams
*/
openPositionWithFixedAmount(pool: Pool, lowerTick: number, upperTick: number, params: LiquidityInput, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to fully close the provided position. Any residual liquidity is withdrawn
* @param pool The pool for which the position is providing liquidity
* @param position The ID fo the position to be closed
* @param options IOnChainCallOptionalParams & { transferCoinsTo: optional address to which removed liquidity will be sent to }
* Returns OnChainCallResponse
*/
closePosition(pool: Pool, position: ID, options?: IOnChainCallOptionalParams & {
transferCoinsTo?: Address;
}): Promise<OnChainCallResponse>;
/**
* Allows pool manager or rewards manager to initialize rewards in pool
* @param pool The pool in which rewards are to be initialized
* @param startTime start time in seconds for the rewards (must be in future).
* @param activeForSeconds seconds for which the rewards are to remain active.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param rewardAmount reward coin amount which is to be assigned (caller must have coins of specified reward type)
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
addRewardCoinInPool(params: IAddRewardParams, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows admin of the protocol to add rewards manager in pool
* @param address address of the reward manager
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
addRewardsManager(address: string, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows admin of the to pause/unpause a pool
* @param pool The pool for which to update pause status
* @param pause True/False the new status of the pool
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
updatePoolStatus(pool: Pool, pause: boolean, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows current pool manager to set a new pool manager
* @param pool the pool for which to set the manger
* @param address address of the new manager
* @param options IOnChainCallOptionalParams
*/
setPoolManager(pool: Pool, address: string, options?: IOnChainCallOptionalParams & {
owner?: string;
}): Promise<OnChainCallResponse>;
/**
* fetches pool manager of a given pool
* @param pool the pool for which to set the manger
* @param options IOnChainCallOptionalParams
*/
getPoolManager(pool: Pool, options?: IOnChainCallOptionalParams & {
owner?: string;
}): Promise<string>;
/**
* fetches information of rewards given in a pool
* @param pool the pool for which rewards are to be fetched
* @param options IOnChainCallOptionalParams
* Returns IRewardCoinsInPool[]
*/
getRewardCoinsInPool(pool: Pool): Promise<IRewardCoinsInPool[]>;
/**
* Allows pool manager or rewards manager to update reward emissions of initialized rewards in pool
* @param pool The pool in which rewards are initialized
* @param activeForSeconds seconds for which the rewards are to remain active.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param rewardAmount reward coin amount which is to be assigned (caller must have coins of specified reward type)
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
updateRewardCoinEmission(pool: Pool, activeForSeconds: number, rewardCoinType: string, rewardAmount: BigNumber, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows pool manager or rewards manager to add seconds to the reward emissions of initialized rewards in pool
* @param pool The pool in which rewards are intialized
* @param secondsToAdd seconds to increase in reward emission.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
addSecondsToRewardCoinEmission(pool: Pool, secondsToAdd: number, rewardCoinType: string, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows the current admin of the protocol to increase
* the supported protocol version
*/
updateSupportedVersion(options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Fetches the rewards accrued by the user
* by dev inspecting `collect_reward` method with provided params
* @param pool The pool for which the position is providing liquidity
* @param position id of the position against which rewards are accrued.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param options IOnChainCallOptionalParams & { rewardCoinsType?: string[] }
* Returns IRewardAmounts[]
*/
getAccruedRewards(pool: Pool, position: ID, options?: IOnChainCallOptionalParams & {
rewardCoinsType?: string[];
}): Promise<IRewardAmounts[]>;
/**
* Fetches the fee and rewards accrued by the user in a given position
* by dev inspecting `collect_reward` and `get_accrued_fee` method with provided params
* @param pool The pool for which the position is providing liquidity
* @param position id of the position against which rewards and fees are accrued.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param options IOnChainCallOptionalParams & { rewardCoinsType?: string[] }
* Returns IFeeAndRewards
*/
getAccruedFeeAndRewards(pool: Pool, position: ID, options?: IOnChainCallOptionalParams): Promise<IFeeAndRewards>;
/**
* Allows user to collect accrued rewards.
* @param pool The pool for which the position is providing liquidity
* @param position id of the position against which rewards are accrued.
* @param options IOnChainCallOptionalParams & { rewardCoinsType?: string[] }
* Returns OnChainCallResponse
*/
collectRewards(pool: Pool, position: ID, options?: IOnChainCallOptionalParams & {
rewardCoinsType?: string[];
}): Promise<OnChainCallResponse>;
/**
* Allows user to collect accrued fees and rewards from the provided position
* @param pool The pool for which the position is providing liquidity
* @param position id of the position against which fees and rewards are accrued.
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
collectFeeAndRewards(pool: Pool, position: ID, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows user to collect accrued rewards from all the provided positions
* @param userAddress The address of the user
* @param positionData positions data required for claiming rewards
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
collectRewardsForAllPositions(userAddress: string, positionsData?: {
pool: Pool;
positionId: ID;
}[], options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to perform a swap on the pool
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
swapAssets(params: ISwapParams, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Dev inspects `calculate_swap_results` method with provided params
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
computeSwapResults(params: ISwapParams, options?: IOnChainCallOptionalParams): Promise<any>;
/**
* Returns the estimated amount (input or output) the user will get for the swap
* by dev inspecting `calculate_swap_results` method with provided params
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
getEstimatedAmount(params: ISwapParams, options?: IOnChainCallOptionalParams): Promise<number>;
/**
* Allows the admin of the bluefin spot protocol to change the protocol fee share of a pool
* @param pool The pool for which protocol fee share is being updated
* @param protocolFeeShare the new protocol fee share, must be in 1e6 format. 100% is represented as 1e6
* @param options
*/
updateProtocolFeeShare(pool: Pool, protocolFeeShare: BigNumberable, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to execute the swap route to convert Asset A -> B -> C
*/
executeSwapRoute(route: ISwapRoute, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Allows caller to claim accrued fee from the provided position
* @param pool The name of the pool or the pool itself
* @param position The position id from which to collect fee
* @param options IOnChainCallOptionalParams
*/
collectFee(pool: Pool, position: ID, options?: IOnChainCallOptionalParams): Promise<OnChainCallResponse>;
/**
* Returns the fee accrued by provided position
* @param pool The complete state of the pool
* @param position The id of the position for which to get accrued fee
* @returns CoinAmounts: The fee accrued for coin A and B
*/
getAccruedFee(pool: Pool, position: ID): Promise<CoinAmounts>;
/**
* Returns the fee accrued by provided position
* @param pool The complete state of the pool
* @param position The id of the position for which to get accrued fee
* @returns CoinAmounts: The fee accrued for coin A and B
*/
getAccruedFeeForPositions(args: Array<{
pool: Pool;
position: ID;
}>): Promise<Array<CoinAmounts>>;
/**
* Returns true/false if the provided coin type is supported for pool creation along with the fee amount
*/
getPoolCreationFeeInfoForCoin(coinType: string): Promise<{
supported: boolean;
amount: number;
}>;
/**
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
private _swap;
/**
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns txBlock and coinOut
*/
swapAssetsAndReturnCoin(params: ISwapParams, options?: IOnChainCallOptionalParams): Promise<{
txb: TransactionBlock;
coinOut: TransactionObjectArgument;
}>;
swapAssetsAndReturnCoinV2(params: ISwapParams, balanceToSwap: TransactionObjectArgument, options?: IOnChainCallOptionalParams): Promise<{
txb: TransactionBlock;
coinOut: TransactionObjectArgument;
}>;
/**
* @param pool The pool to which liquidity is to be provided
* @param position ID or the position object for which liquidity is being provided
* @param params Liquidity params
* @param options IOnChainCallOptionalParams
* Returns Transaction Block
*/
private _provideLiquidityInternal;
/**
* @param pool The pool to which liquidity is to be provided
* @param position ID or the position object for which liquidity is being provided
* @param params Liquidity params
* @param options IOnChainCallOptionalParams
* Returns Transaction Block
*/
private _provideLiquidityInternalWithInputCoins;
/**
* @param pool The pool to which liquidity is to be provided
* @param position ID or the position object for which liquidity is being provided
* @param liquidityInput LiquidityInput
* @param options IOnChainCallOptionalParams
* Returns Transaction Block
*/
private _provideLiquidityFixedAmountInternal;
/**
* Allows caller to remove liquidity from the pool for provided position
* @param pool Name or the pool itself from which liquidity will be removed
* @param position The ID fo the position for which liquidity is being removed from
* @param position: liquidity Input params
* @param options IOnChainCallOptionalParams & { transferCoinsTo: optional address to which removed liquidity will be sent to }
* Returns Transaction Block
*/
private _removeLiquidityInternal;
/**
* Internal method that Allows user to collect accrued rewards from the provided position
* @param pool The pool for which the position is providing liquidity
* @param position id of the position against which rewards are accrued.
* @param rewardCoinType reward coin type (eg. 0x81650ac0868edf55349fa41d4323db5b8a4827bab3b672c16c14c7135abcc3df::usdc::USDC)
* @param options IOnChainCallOptionalParams & { rewardCoinsType?: string[] }
* Returns TransactionBlock
*/
private _collectRewardInternal;
/**
* Internal method that allows caller to claim accrued fee from the provided position
* @param pool The name of the pool or the pool itself
* @param position The position id from which to collect fee
* @param options IOnChainCallOptionalParams
* Returns TransactionBlock
*/
private _collectFeeInternal;
/**
* Allows caller to open a position for the provided pool for given ticks
* @param pool Name or the pool or the pool for which to open the position
* @param lowerTick The lower tick (signed)
* @param upperTick The upper tick (signed)
*/
private _openPositionInternal;
/**
* @param params The swap contract call parameters
* @param options IOnChainCallOptionalParams
* Returns OnChainCallResponse
*/
private _computeSwapResults;
isBluePointsReward(coinType: any): boolean;
/**
* Handles the shio fast mode and appends the tip for the transaction block.
* @param txb - The transaction block to be processed.
* @param shioFastModeCustomRange - fast mode tip
*/
appendTipToTransaction(txb: TransactionBlock, shioFastModeCustomRange?: IShioFastModeCustomRange): Promise<void>;
}