0.0.3 • Published 2 years ago

tx-express-test v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

tx-express

Scenario

Gas war on NFT minting / opensea listing

api:

  function sendTxsWithGasPriceDecay(txs: TransactionRequest[], signer: Signer, initialGasPrice: BigNumber, gasPriceDelta: BigNumber, roundNumbers, timeInterval, timeout) {
  }
  
  function sendRawTxs(rawTxs: RawTransaction[][], signer, timeInterval, timeout) {
    for (let i = 0; i < rawTxs.length; i += 1) {
      for (let id = 0; id < rawTxs[i].length; id +=1) {
        ethers.sendRawTx(rawTxs[i][id]);
      }
      sleep(timeInterval);
    }
  }

cli:

tx-express sendTxs --startTime --params

sniper:

sniper run

send non-urgent tx: cancel normal order

api:

  function sendTx(tx, signer, timeout, retryNumber, retryGasPriceMultiplier=1.1, maxGasPrice=1000 gwei, isUrgent) {
  }

send urgent tx: cancel wrong tx (in a wrong price, to-be-reverted)

api:

  function sendUrgentTx(tx, signer, timeout, retryNumber, retryGasPriceMultiplier=1.1, maxGasPrice=1000 gwei) {
     
  }

send flashbot bundles

api:

async function sendFlashBotBundle(rawTxSeq, fromNumber, toNumber) {
    console.log("Sending flashbot bundle txs");
    const fullBundle = rawTxSeq
        ? [rawTxSeq].concat(transactionBundle)
        : transactionBundle;

    console.log("Full bundle:");
    console.log(fullBundle);

    const simulation = await flashbotsProvider.simulate(
        fullBundle,
        toNumber - 1
    );
    if ("error" in simulation) {
        console.warn(`Simulation Error: ${simulation.error.message}`);
        return;
    } else {
        console.log(
            `Simulation Success: ${JSON.stringify(simulation, null, 2)}`
        );
    }
    const bundlePromises = _.map(
        _.range(fromNumber, toNumber),
        (targetBlockNumber) =>
            flashbotsProvider
                .sendRawBundle(fullBundle, targetBlockNumber)
                .then(async (bundleSubmission) => {
                    if ("error" in bundleSubmission) {
                        console.error(bundleSubmission.error.message);
                        return;
                    }
                    const waitResponse = await bundleSubmission.wait();
                    console.log(`Wait Response: ${waitResponse}`);
                    console.log({
                        bundleStats: await flashbotsProvider.getBundleStats(
                            simulation.bundleHash,
                            targetBlockNumber
                        ),
                        userStats: await flashbotsProvider.getUserStats(),
                    });
                })
    );

    await Promise.all(bundlePromises);
}

  function sendRawBundle(flashbotProvider, rpc, bundles[], currentBlockNumber, initialRequestNumbers, totalRequestNumbers) {
    sendFlashBotBundle(bundles, urrentBlockNumber + 1, currentBlockNumber + initialRequestNumbers +1);
    
    i = currentBlockNumber + initialRequestNumbers +1
    rpc.on("block") {
      i += 1;
      if (i - currentBlockNumber < totalRequestNumbers) {
        sendFlashBotBundle(bundles, i, i+1);
      }
    }
    
    setInterval(function() {}
    , 7000);
  }