UNPKG

@firefly-exchange/library-sui

Version:

Sui library housing helper methods, classes to interact with Bluefin protocol(s) deployed on Sui

57 lines (56 loc) 2.12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnChainCalls = void 0; const deployment_parser_1 = require("../utils/deployment-parser"); const tx_builder_1 = require("./tx-builder"); const classes_1 = require("../../classes"); const blv_1 = require("../../blv"); class OnChainCalls { constructor(_network, _suiClient, _deployment, _signer, _walletAddress) { this.network = _network; this.suiClient = _suiClient; this.parser = new deployment_parser_1.DeploymentParser(_deployment); // could be undefined, if initializing the bluefinV3 for only get calls this.signer = _signer; this.walletAddress = _walletAddress || _signer?.toSuiAddress(); this.txBuilder = new tx_builder_1.TxBuilder(_deployment); } /** * Signs and executes the given transaction block * @param txBlock Sui transaction block * @returns Sui Transaction Block Response */ async signAndExecuteTxBlock(txBlock) { return classes_1.SuiBlocks.signAndExecuteTxBlock(txBlock, this.suiClient, this.signer); } /** * Signs and executes the given transaction block * @param txBlock Sui transaction block * @returns Sui Transaction Block Response */ async dryRunTxBlock(txBlock) { return classes_1.SuiBlocks.dryRunTxBlock(txBlock, this.suiClient, this.signer); } /** * Dry runs or executes the call on chain depending on the params * @param dryRun True if dry run is to be performed * @param txBlock The transaction block * @returns */ async execCall(txBlock, options) { if (options?.dryRun) { return this.dryRunTxBlock(txBlock); } else if (options?.returnTxb) { return txBlock; } else { // TODO remove these sleeps for production await (0, blv_1.sleep)(1000); const response = await this.signAndExecuteTxBlock(txBlock); await (0, blv_1.sleep)(1000); return response; } } } exports.OnChainCalls = OnChainCalls;