@firefly-exchange/library-sui
Version:
Sui library housing helper methods, classes to interact with Bluefin protocol(s) deployed on Sui
325 lines (324 loc) • 15.4 kB
TypeScript
import { BigNumberable, Signer } from "../types";
import { IApplyFundingRate, IDeployment, IMarketFundingRate, IRequestPayload } from "./interfaces";
import { IOrderCreation } from "./interfaces/IOrder";
import { MarketName, SupportedAssets } from "./types";
import { Address, ID, NumStr } from "../types";
import { DeploymentParser } from "./utils";
import { ASSUME_AS, POSITION_TYPES, PRUNE_TABLES_INDEX, ACCOUNT_TYPE } from "./enums";
export declare class RequestsBuilder {
parser: DeploymentParser;
signer: Signer;
walletAddress: string;
/**
* Class constructor
* @param _deployment the deployment config
* @param _signer the wallet/signer
* @param _walletAddress (optional) the wallet/signer address
*/
constructor(_deployment: IDeployment, _signer: Signer, _walletAddress?: Address);
/**
* Create a withdrawal request for user to submit to bluefin gateway
* @param assetSymbol name of the asset to be withdrawn
* @param amountE9 amount to be withdrawn. Should be in 9 decimal places
* @param options Optional params:
* - salt: A random number to make the withdrawal payload unique for the user
* - account: The address of the account performing the withdraw
* - assetBankID: The address of the asset bank. By default fetches the asset bank of the provided asset symbol
* - eds: The id of the External Data store
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
withdrawal(assetSymbol: SupportedAssets, amountE9: BigNumberable, options?: {
salt?: NumStr;
account?: Address;
signer?: Signer;
eds?: Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Creates an authorized user request for user to submit to bluefin gateway
* @param user The address of the account to be authorized or unauthorized
* @param status a boolean indicating if the users are to be authorized or not
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - account: The account for which to authorize users - defaults to `this.walletAddress`
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
authorizeUser(user: Address, status: boolean, options?: {
signer?: Signer;
account?: Address;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Creates a signed order
* @param orderParams Params for order creation
* @param options Optional params
* - signer: the signer of the order
* - ids: The id of internal data store
* @returns IRequestPayload
*/
createSignedOrder(orderParams: IOrderCreation, options?: {
signer?: Signer;
}): Promise<IRequestPayload>;
/**
* Create a liquidation request for user to submit to bluefin gateway
* @param liquidatee: The address of the account to be liquidated
* @param market: The symbol of the market/perpetual for which to liquidate user's position
* @param positionType: The type of position being liquidated
* @param assumeAs: The position to be assumed as isolated or cross
* @param quantityE9: The amount to be liquidated
* @param options Optional params:
* - signer: The signer to be used to sign the payload. Defaults to signer of the class (this.signer)
* - liquidator: The address of the liquidator. Defaults to the signer address
* - allOrNothing: True if the complete specified amount must be liquidated, false otherwise. Defaults to False
* - salt: A random number to make the payload unique
* - expiry: The timestamp till which the signed liquidation is valid
* - leverageE9: If assuming as an isolated position, specify the leverage. Defaults to 1 for isolated position, and passed as 0 for cross.
* - ids: The internal data store id/address
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
createSignedLiquidation(liquidatee: Address, market: MarketName, positionType: POSITION_TYPES, assumeAs: ASSUME_AS, quantityE9: BigNumberable, options?: {
signer?: Signer;
liquidator?: Address;
salt?: NumStr;
allOrNothing?: boolean;
expiry?: NumStr;
leverageE9?: BigNumberable;
ids?: ID | Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create an ADL request for user to submit to bluefin gateway
* @param maker: The address of the account to be deleveraged (bankrupt)
* @param taker: The address of the account to be deleveraged against +Pnl
* @param market: The symbol of the market/perpetual for which to liquidate user's position
* @param makerPositionType: The type of maker position being deleveraged
* @param takerPositionType: The type of taker position being deleveraged
* @param quantityE9: The amount to be deleveraged
* @param options Optional params:
* - signer: The signer to be used to sign the payload. Defaults to signer of the class (this.signer)
* - salt: A random number to make the payload unique
* - expiry: The timestamp till which the signed adl is valid
* - ids: The internal data store id/address
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
createSignedADL(maker: Address, taker: Address, makerPositionType: POSITION_TYPES, takerPositionType: POSITION_TYPES, market: MarketName, quantityE9: BigNumberable, options?: {
signer?: Signer;
salt?: NumStr;
expiry?: NumStr;
ids?: ID | Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a adjust margin request for user to submit to bluefin gateway
* @param marketAddress The address of the market/perpetual for which to adjust the margin
* @param amountE9 The amount to be added/withdrawn from isolated position
* @param options Optional params:
* - account: The account address for which margin to be adjusted. The account defaults to `this.walletAddress`
* - signer: The signer to be used to sign the payload. Defaults to signer of the class `this.signer`
* - salt: A random number to make the payload unique
* - ids: The internal data store id/address
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
adjustMargin(market: string, add: boolean, amountE9: BigNumberable, options?: {
account?: Address;
signer?: Signer;
salt?: NumStr;
ids?: ID | Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a adjust leverage request for user to submit to bluefin gateway
* @param market The symbol of the market/perpetual for which to adjust the leverage
* @param leverage The new leverage to be used
* @param options Optional params:
* - account: The account address for which margin to be adjusted. The account defaults to `this.walletAddress`
* - signer: The signer to be used to sign the payload. Defaults to signer of the class `this.signer`
* - salt: A random number to make the payload unique
* - ids: The internal data store id/address
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
adjustLeverage(market: Address, leverage: BigNumberable, options?: {
account?: Address;
signer?: Signer;
salt?: NumStr;
ids?: ID | Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a set funding rate request payload for the funding rate operator to submit to bluefin gateway
* @param marketsFundingRates The funding rate of each market/perpetual along with the market address
* @param options Optional params:
* - signer: The signer to be used to sign the payload. Defaults to signer of the class `this.signer`
* - salt: A random number to make the payload unique
* - timestamp: The timestamp in seconds for which the funding rate is being set.
* This should be hourly timestamp. If not provided the method takes current
* time and rounds it up/down to closest hour mark
* - ids: The internal data store id/address
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
setFundingRate(marketsFundingRates: Array<IMarketFundingRate>, options?: {
signer?: Signer;
salt?: NumStr;
timestamp?: NumStr;
ids?: ID | Address;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create bcs serialized payload for applying funding rate
* @param accounts The array of account addresses to which to apply funding rate
* @param options Optional params:
* - ids: The address/id of the internal data store - This makes sure that a payload
* signed for testnet can not be executed on mainnet
* - salt: A random number to make the payload unique
* - timestamp: The timestamp in seconds for which the funding rate is to be applied
* This should be hourly timestamp. If not provided the method takes current
* time and rounds it up/down to closest hour mark
* - market: If provided, the FR request is created to be applied to provided market
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
applyFundingRate(accounts: Array<Address>, options?: {
market?: string;
ids?: ID | Address;
salt?: NumStr;
timestamp?: NumStr;
signedAt?: NumStr;
}): Promise<{
rawData: IApplyFundingRate;
serializedData: string;
signature: any;
}>;
/**
* Creates a prune table payload and signs it
* @param hashes The list of hashes that are to be pruned
* @param table_index The table type (index) from which the hashes are to be pruned
* @param options Optional params:
* - signer: The signer to be used to sign the payload. Defaults to signer of the class `this.signer`
* - salt: A random number to make the payload unique
* - ids: The address/id of the internal data store - This makes sure that a payload
* signed for testnet can not be executed on mainnet
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
pruneTable(hashes: Array<Uint8Array>, table_index: PRUNE_TABLES_INDEX, options?: {
signer?: Signer;
salt?: NumStr;
signedAt?: NumStr;
ids?: ID | Address;
}): Promise<IRequestPayload>;
/**
* Create an authorize bankrupt liquidator payload to submit to api gateway
* @param status The address of the account to be authorized or unauthorized
* @param authorized a boolean indicating if the users are to be authorized or not
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
authorizeLiquidator(account: Address, authorized: boolean, options?: {
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Creates a signed payload for setting tier of an account
* @param status The address of the account to be authorized or unauthorized
* @param makerFee The maker side fee percentage
* @param takerFee The taker side fee percentage
* @param applied True if the fee tier is to be applied
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
setFeeTier(account: Address, makerFee: BigNumberable, takerFee: BigNumberable, applied: boolean, options?: {
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a set account type signed payload
* @param account The address for which to set type
* @param type The account type Institution or Retail
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
setAccountType(account: Address, type: ACCOUNT_TYPE, options?: {
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a set gas fee signed payload
* @param amount The new gas fee amount (in 1e9)
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
setGasFee(amount: BigNumberable, options?: {
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create a set gas pool signed payload
* @param pool The new gas pool address
* @param options Optional params:
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
setGasPool(pool: Address, options?: {
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
/**
* Create signed payload for closing position of a delisted market
* @param market Market name for which to close the position
* @param positionType The type of position being closed ISOLATED or CROSS
* @param options Optional params:
* - account: The address of the account for which the position is being closed
* - signer: The signer that will be signing the payload
* - ids: The internal data store id
* - salt: A random number to make the payload unique
* - signedAt: The timestamp in seconds at which the payload is signed
* @returns IRequestPayload
*/
closePosition(market: MarketName, positionType: POSITION_TYPES, options?: {
account?: Address;
signer?: Signer;
salt?: NumStr;
ids?: ID;
signedAt?: NumStr;
}): Promise<IRequestPayload>;
}