@firefly-exchange/library-sui
Version:
Sui library housing helper methods, classes to interact with Bluefin protocol(s) deployed on Sui
326 lines (325 loc) • 20.2 kB
TypeScript
import { DeploymentParser } from "../utils";
import { ITxBuilderOptionalParams, IDeployment, IBatchTrade, IPosition } from "../interfaces";
import { MarketName, SupportedAssets } from "../types";
import { Address, BigNumberable, ID, NumStr, Serialized, SuiAddress, TransactionBlock } from "../../types";
import { TransactionArgument } from "@mysten/sui/transactions";
import { OPERATORS, PERPETUAl_CONFIG_FIELDS } from "../enums";
export declare class TxBuilder {
parser: DeploymentParser;
constructor(_deployment: IDeployment);
/**
* Creates support asset transaction
* @param supportedCoin supported coin address. should be of format 0xax....bs::coin::COIN
* @param supportedCoinSymbol Name of the supported coin
* @param coinDecimals The number of decimals in supported coin
* @param weight The discounted price percentage to be used for asset
* @param collateral True if the asset can be used to collateralize a position
* @param options Optional tx building params
* @returns TransactionBlock
*/
supportAsset(supportedCoin: string, supportedCoinSymbol: string, coinDecimals: NumStr, weight: NumStr, price: NumStr, collateral: boolean, minDeposit: NumStr, maxDeposit: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create data store creation transaction
* @param sequencer address of the sequencer that will own the data store
* @param options Optional tx building params
* @returns TransactionBlock
*/
createInternalDataStore(sequencer: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create internal data store transfer call
* @param sequencer address of the new sequencer that will own ids
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
transferInternalDataStore(sequencer: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Builds USDC mint coin transaction
* @param amount the amount to be minted
* @param to the receiver of the amount
* @param options Optional tx building params
* @returns TransactionBlock
*/
mintUSDC(amount: NumStr, to: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Builds transaction to deposit usdc to external bank
* @param assetSymbol name of the asset to be deposited
* @param destination the receiver of the deposited coins on the bank
* @param amount the amount to be deposited - should be in the decimals of the coin being deposited
* @param coinID the id of the usdc coin to be deposited
* @param options Optional tx building params
* @returns TransactionBlock
*/
depositToAssetBank(assetSymbol: SupportedAssets, destination: string, amount: BigNumberable, coinID: TransactionArgument, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Builds transaction to deposit usdc to internal bank
* @param assetSymbol The symbol of the asset being deposited to internal bank
* @param nonce the nonce emitted during asset deposit in shared bank
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx building params
* @returns TransactionBlock
*/
depositToInternalBank(assetSymbol: SupportedAssets, nonce: NumStr, sequenceHash: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Builds transaction to remove tainted asset from EDS
* @param assetSymbol The symbol of the asset being deposited to internal bank
* @param nonce the nonce emitted during asset deposit in shared bank
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx building params
* @returns TransactionBlock
*/
removeTaintedAsset(assetSymbol: SupportedAssets, nonce: NumStr, sequenceHash: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates perpetual creation transaction
* @param PerpetualCreationParams take a look at IPerpetualConfig
* @param options Optional tx building params
* @returns TransactionBlock
*/
createPerpetual(symbol: string, imr: NumStr, mmr: NumStr, stepSize: NumStr, tickSize: NumStr, minTradeQuantity: NumStr, maxTradeQuantity: NumStr, minTradePrice: NumStr, maxTradePrice: NumStr, maxNotionalAtOpen: NumStr[], mtbLong: NumStr, mtbShort: NumStr, makerFee: NumStr, takerFee: NumStr, maxFundingRate: NumStr, insurancePoolRatio: NumStr, tradingStartTime: NumStr, insurancePool: string, feePool: string, isolatedOnly: boolean, baseAssetSymbol: string, baseAssetName: string, baseAssetDecimals: NumStr, maxLimitOrderQuantity: NumStr, maxMarketOrderQuantity: NumStr, defaultLeverage: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to update perpetual
* @param perpetual the symbol of the perpetual/market to be updated
* @param field the name of the field/config being updated
* @param serialized_value A BCS serialized value to be set on perpetual config
* @param options Optional tx building params
* @returns OnChainCallResponse
*/
updatePerpetual(perpetual: MarketName, field: PERPETUAl_CONFIG_FIELDS, serialized_value: Uint8Array, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction to synchronize the attributes of provided perpetual between ids and eds
* @param perpetual the symbol of the perpetual/market to be synced
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx building params
* @returns Transaction Block
*/
syncPerpetual(perpetual: MarketName, sequenceHash: string, options?: ITxBuilderOptionalParams & {
ids?: ID | Address;
eds?: ID | Address;
}): TransactionBlock;
/**
* Creates transaction to synchronize the supported asset among data stores
* @param symbol the symbol of the asset
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx building params
* @returns Transaction Block
*/
syncSupportedAsset(symbol: string, sequenceHash: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for withdraw call on-chain to move funds for a user
* from the bank to user address
* @param data serialized hex string of the withdrawal payload
* @param signature base64 signature payload generated by the user by signing the withdrawal request
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx execution params
* @returns TransactionBlock
*/
withdrawFromBank(data: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for user authorization call on-chain to authorize/un-authorized given user
* @param data serialized hex string of the authorization payload
* @param signature base64 signature generate by singing the request payload data
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which off-chain margining engine processed this request
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
authorizeUser(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates trade transaction block
* @param makerOrder The signed maker order
* @param takerOrder The signed taker order
* @param quantity The quantity to be trade
* @param perpetuals The list of perpetual address for which oracle prices are to be updated
* @param oraclePrice The list of oracle prices
* @param sequenceHash Sequence hash
* @param timestamp The timestamp at which trade was executed off-chain ( on margining engine )
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
performTrade(makerOrder: Uint8Array, takerOrder: Uint8Array, makerSignature: string, takerSignature: string, quantity: NumStr, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates batch trade transaction block
* @param trades The batch of trade to be executed
* @param perpetuals The list of perpetual address for which oracle prices are to be updated
* @param oraclePrice The list of oracle prices
* @param sequenceHash Sequence hash
* @param timestamp The timestamp at which trade was executed off-chain ( on margining engine )
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
performBatchTrade(batchTrade: IBatchTrade, perpetuals: Array<string>, oraclePrices: Array<string>, batchHash: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams & {
gasFee?: NumStr;
}): TransactionBlock;
/**
* Creates liquidation transaction block
* @param payload The liquidation payload that was signed by the liquidator
* @param signature The liquidator's signature (base64 format)
* @param perpetuals The list of perpetual address for which oracle prices are to be updated
* @param oraclePrice The list of oracle prices
* @param sequenceHash Sequence hash
* @param timestamp The timestamp at which liquidation was executed off-chain ( on margining engine )
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
performLiquidation(payload: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates adjust margin transaction block
* @param data serialized hex string of the adjust margin payload
* @param signature base64 signature payload generated by the user by signing the adjust margin request
* @param perpetuals The list of perpetual address for which oracle prices are to be updated
* @param oraclePrice The list of oracle prices
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The time at which margin got adjusted off-chain
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
adjustMargin(data: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates adjust leverage transaction block
* @param data serialized hex string of the adjust leverage payload
* @param signature base64 signature payload generated by the user by signing the adjust leverage request
* @param perpetuals The list of perpetual address for which oracle prices are to be updated
* @param oraclePrice The list of oracle prices
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The time at which leverage got adjusted off-chain
* @param options Optional tx execution params
* @returns TransactionBlock
*/
adjustLeverage(data: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates set operator on eds transaction block
* @param type The type of the operator be updated
* @param newOperator The address of the new operator to be set
* @param options Optional tx execution params
* @returns TransactionBlock
*/
setOperatorEDS(type: OPERATORS, newOperator: SuiAddress, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction to synchronize the provided operator among data stores
* @param type The operator key/type to be synced
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param options Optional tx building params
* @returns Transaction Block
*/
syncOperator(type: OPERATORS, sequenceHash: string, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for setting funding rate for markets/perpetuals on-chain
* @param data serialized hex string of the set funding rate payload
* @param signature base64 signature payload generated by the user by signing the funding rate request
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp the timestamp at which funding rate was set off-chain
* @param options Optional tx execution params
* @returns TransactionBlock
*/
setFundingRate(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for applying funding rate to provided accounts on-chain
* @param data serialized hex string of the apply funding rate payload
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The time at which funding rate was applied off-chain
* @param options Optional tx execution params
* @returns TransactionBlock
*/
applyFundingRate(data: Serialized, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to prune table
* @param data serialized hex string of purging table
* @param signature base64 signature payload generated by the user by signing the prune table request
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which table got pruned off-chain
* @param options?: ITxBuilderOptionalParams
* @returns TransactionBlock
*/
pruneTable(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to authorize a liquidator
* @param data serialized hex string of purging table
* @param signature base64 signature payload generated by the user by signing the request
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options?: ITxBuilderOptionalParams
* @returns TransactionBlock
*/
authorizeLiquidator(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to set fee tier of an account
* @param data bcs serialized data
* @param signature base64 signature encoded signature of the data
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
setFeeTier(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to set an account's type
* @param data bcs serialized data
* @param signature base64 signature encoded signature of the data
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
setAccountType(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to set an gas fee
* @param data bcs serialized data
* @param signature base64 signature encoded signature of the data
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
setGasFee(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Create transaction to set gas pool address
* @param data bcs serialized data
* @param signature base64 signature encoded signature of the data
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params
* @returns OnChainCallResponse
*/
setGasPool(data: Serialized, signature: string, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates ADL transaction and returns it
* @param data The serialized adl payload
* @param signature The adl operator's signature on the data payload
* @param oraclePrice The list of perpetuals and their new oracle prices
* @param sequenceHash Sequence hash
* @param timestamp The time at which adl was executed off-chain
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
performADL(payload: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates close position transaction and returns it
* @param data The serialized close position payload
* @param signature The account signature
* @param oraclePrice The list of perpetuals and their new oracle prices
* @param sequenceHash Sequence hash
* @param timestamp The time at which adl was executed off-chain
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
closePosition(payload: Serialized, signature: string, perpetuals: Array<string>, oraclePrices: Array<string>, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for overwriting an account's position on-chain
* @param account The address of the account being updated
* @param positon The position to be updated
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
overwriteUserPosition(account: Address, positon: IPosition, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
/**
* Creates transaction for overwriting an account's position on-chain
* @param account The address of the account being updated
* @param amount The amount of USDC to be updated
* @param sequenceHash the expected sequence hash on-chain after the tx execution
* @param timestamp The timestamp at which the request was processed off-chain
* @param options Optional tx execution params & execution time
* @returns TransactionBlock
*/
overwriteUserAssets(account: Address, amount: NumStr, sequenceHash: string, timestamp: NumStr, options?: ITxBuilderOptionalParams): TransactionBlock;
}