UNPKG

@firefly-exchange/library-sui

Version:

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

55 lines (54 loc) 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ValidateTx = void 0; const utils_1 = require("@mysten/sui/utils"); const types_1 = require("../types"); const constants_1 = require("../constants"); // Add more methods in this array down the road const SPONSORED_TX_METHODS = [ "margin_bank::deposit_to_bank", "margin_bank::withdraw_from_bank", "exchange::add_margin", "exchange::remove_margin", "exchange::adjust_leverage", "exchange::close_position", "roles::set_sub_account", "margin_bank::withdraw_all_margin_from_bank_and_return_balance", "margin_bank::withdraw_all_margin_from_bank", "exchange::close_position", "pool::swap", "exchange::deposit_to_asset_bank" ]; const WHITELISTED_KINDS = ["MergeCoins"]; const SPONSORED_TX = []; for (const method of SPONSORED_TX_METHODS) { for (const env of Object.keys(constants_1.BLUEFIN_PACKAGES)) { for (const version of constants_1.BLUEFIN_PACKAGES[env]) { SPONSORED_TX.push(`${version}::${method}`); } } } class ValidateTx { /** * Given a base 64 encoded sponsored transaction bytes, returns true * if all the transactions in the block are whitelisted to be sponsored * by bluefin dec * @param txBytesB64 base 64 sponsored tx block bytes * @returns true/false */ static isWhitelistedForSponsor(txBytesB64) { const txBytes = (0, utils_1.fromB64)(txBytesB64); const txBlock = types_1.TransactionBlock.fromKind(txBytes); const transactions = txBlock.blockData.transactions; for (const tx of transactions) { // if the tx type is not in SPONSORED_TX return false // eslint-disable-next-line @typescript-eslint/no-explicit-any if (SPONSORED_TX.indexOf(tx.target) == -1 && WHITELISTED_KINDS.indexOf(tx.kind) == -1) return false; } // if we are here, implies all tx in the block are whitelisted to be sponsored return true return true; } } exports.ValidateTx = ValidateTx;