UNPKG

flashbots-cli

Version:
43 lines (42 loc) 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = require("axios"); const core_1 = require("@oclif/core"); const ethers_1 = require("ethers"); // lib const constants_1 = require("../lib/constants"); const error_1 = require("../lib/error"); class BundleCache extends core_1.Command { async catch(e) { (0, error_1.handleGenericError)(e, this); } async run() { const { args } = await this.parse(BundleCache); if (args.raw_tx) { // add tx to bundle const provider = new ethers_1.providers.JsonRpcProvider(`${constants_1.FLASHBOTS_PROTECT_URL}?bundle=${args.bundle_id}`); const res = await provider.sendTransaction(args.raw_tx); this.log(JSON.stringify(res)); this.log(`Cached tx in bundle ${args.bundle_id}`); } else { // get bundle const res = await axios_1.default.get(`${constants_1.FLASHBOTS_PROTECT_URL}/bundle?id=${args.bundle_id}`); this.log(JSON.stringify(res.data)); } } } exports.default = BundleCache; BundleCache.description = `Add txs to a bundle one at a time. Specify [BUNDLE_ID] AND [RAW_TX] to add a new transaction to a bundle. To get the current cached bundle, only set [BUNDLE_ID].`; BundleCache.examples = [ `# Add a transaction to a bundle <%= config.bin %> <%= command.id %> 5b479f88-01ca 0x02f8d30182024...`, `# Get transactions in a bundle <%= config.bin %> <%= command.id %> 5b479f88-01ca`, ]; BundleCache.args = [ { name: 'bundle_id', description: 'Unique ID to identify your bundle (UUIDv4 recommended)', required: true }, { name: 'raw_tx', description: 'Raw signed transaction (0x-prefixed hex data)' } ];