@bluefin-exchange/bluefin7k-aggregator-sdk
Version:
53 lines (52 loc) • 1.88 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeTx = void 0;
const config_1 = require("../../config");
const client_1 = require("../../libs/protocols/bluefinx/client");
const types_1 = require("../../libs/protocols/bluefinx/types");
/**
* Execute a transaction after it is signed
*
* Automatically handle BluefinX transaction execution if needed
* @example
* ```ts
* const { mutateAsync: signTransaction } = useSignTransaction();
* const quoteResponse = await getQuote(...quoteParams);
* const { tx } = await buildTx(...buildTxParams);
* const {signature, bytes} = await signTransaction({
* transaction: tx instanceof BluefinXTx ? tx.txBytes : tx,
* });
* const res = await executeTx(tx, signature, bytes);
* ```
* @param tx - AggregatorTx - received from `buildTx`
* @param signature - User signature after signing the transaction
* @param signedTxBytes - Signed transaction bytes after signing the transaction
* @param options - Options for the transaction
* @returns `SuiTransactionBlockResponse`
*/
const executeTx = async (tx, signature, signedTxBytes, options) => {
const isBluefinTx = tx instanceof types_1.BluefinXTx;
const client = config_1.Config.getSuiClient();
let res;
if (isBluefinTx) {
try {
const result = await (0, client_1.executeBluefinTx)(tx, signature);
res = await client.waitForTransaction({
digest: result.txDigest,
options,
});
}
catch (e) {
throw Error(`Could not retrieve BluefinX transaction with quoteId: ${tx.quoteId} ${e}`);
}
}
else {
res = await client.executeTransactionBlock({
transactionBlock: signedTxBytes,
signature,
options,
});
}
return res;
};
exports.executeTx = executeTx;
;