UNPKG

@firefly-exchange/library-sui

Version:

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

75 lines (74 loc) 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChainCallsUtils = void 0; const SuiBlocks_1 = require("./SuiBlocks"); class ChainCallsUtils { constructor(_suiClient, _config, options) { this.suiClient = _suiClient; this.config = _config; this.signerConfig = { signer: options?.signer, address: options?.address || options?.signer?.toSuiAddress(), isUIWallet: options?.isUIWallet == true, isZkLogin: options?.isZkLogin == true, zkPayload: options?.zkPayload }; } /** * Signs and executes the given transaction block * @param txb Sui transaction block * @returns Sui Transaction Block Response */ async signAndExecuteTxb(txb) { const signedBlock = await SuiBlocks_1.SuiBlocks.buildAndSignTxBlock(txb, this.suiClient, this.signerConfig.signer, this.signerConfig.isUIWallet); return SuiBlocks_1.SuiBlocks.executeSignedTxBlock(signedBlock, this.suiClient); } /** * Signs the given transaction * @param txb Sui transaction block * @returns Sui Transaction Block Response */ async signTransaction(txb) { return SuiBlocks_1.SuiBlocks.signTxBlock(txb, this.signerConfig.signer, this.signerConfig.isUIWallet); } /** * Signs and executes the given transaction block * @param txb Sui transaction block * @returns Sui Transaction Block Response */ async dryRunTxb(txb) { const builtBlock = (await SuiBlocks_1.SuiBlocks.buildTxBlock(txb, this.suiClient, this.signerConfig.address, false)); return this.suiClient.dryRunTransactionBlock({ transactionBlock: builtBlock }); } /** * Handles call execution * @param txb The transaction block * @param options IOnChainCallOptionalParams * @returns OnChainCallResponse */ async handleReturn(txb, options) { if (options?.returnTx) return txb; if (this.signerConfig.isZkLogin) { return options?.dryRun == true ? await this.dryRunTxb(txb) : await SuiBlocks_1.SuiBlocks.signAndExecuteTransactionUsingZkWallet({ caller: this.signerConfig.signer, txBlock: txb, suiClient: this.suiClient, zkAddress: this.signerConfig.address, zkPayload: this.signerConfig.zkPayload }); } else { return options?.dryRun == true ? await this.dryRunTxb(txb) : options?.sign ? this.signTransaction(txb) : await this.signAndExecuteTxb(txb); } } } exports.ChainCallsUtils = ChainCallsUtils;