UNPKG

flashbots-cli

Version:
50 lines (49 loc) 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); // lib const error_1 = require("../lib/error"); const flashbots_1 = require("../lib/flashbots"); class SimulateBundle extends core_1.Command { async catch(e) { (0, error_1.handleGenericError)(e, this); } async run() { const { args, flags } = await this.parse(SimulateBundle); const flashbotsProvider = await (0, flashbots_1.getFlashbotsProvider)(); let targetBlock; if (flags['target-block']) { targetBlock = flags['target-block']; } else { const provider = (0, flashbots_1.getStandardProvider)(); targetBlock = await provider.getBlockNumber(); } this.log(`Targeting block ${targetBlock} for bundle simulation.`); const res = await flashbotsProvider.simulate(JSON.parse(args.bundle_txs), targetBlock, flags['state-block-tag'], flags['block-timestamp']); if (res.error) { this.error(JSON.stringify(res.error)); } else { this.log(JSON.stringify(res)); } } } exports.default = SimulateBundle; SimulateBundle.description = 'Simulate a bundle.'; SimulateBundle.examples = [ `# Simulate a bundle in the current block <%= config.bin %> <%= command.id %> '["0x02f8d37c496de...", "0x02f8d38a7bf47..."]'`, `# Simulate a bundle against a specific timestamp <%= config.bin %> <%= command.id %> '["0x02f8d37c496de...", "0x02f8d38a7bf47..."]' --block-timestamp 1652859017`, `# Simulate a bundle against a block tag <%= config.bin %> <%= command.id %> '["0x02f8d37c496de...", "0x02f8d38a7bf47..."]' --state-block-tag latest`, ]; SimulateBundle.flags = { 'target-block': core_1.Flags.integer({ char: 'b', description: 'Block to target for bundle submission' }), 'state-block-tag': core_1.Flags.string({ description: 'Block tag which specifies block state to execute simulation against' }), 'block-timestamp': core_1.Flags.integer({ description: 'Timestamp to execute simulation against' }), }; SimulateBundle.args = [ { name: 'bundle_txs', description: "JSON string-encoded array of raw signed transactions (0x-prefixed)", required: true }, ];