suave-std icon indicating copy to clipboard operation
suave-std copied to clipboard

simulateBundle helpers + JSON RPC lib from #51

Open zeroXbrock opened this issue 1 year ago • 1 comments

  • adds Bundle.simulateBundle(bundleObj): syntactical sugar to call Suave.simulateBundle(encodeSimBundle(bundleObj))
  • adds encodeSimBundle: encodes bundleObj for Bundle.simulateBundle
bundleObj = Bundle.BundleObj({
    blockNumber: uint64(bundle.blockNumber + i),
    minTimestamp: 0,
    maxTimestamp: 0,
    txns: bundle.txs,
    revertingHashes: new bytes32[](0),
    refundPercent: 51
});

// simulate bundle and revert if it fails
uint64 simResult = Bundle.simulateBundle(bundleObj);
require(simResult > 0, "sim failed");

// send bundle w/ same bundleObj
bundleRes = Bundle.sendBundle(GOERLI_BUNDLE_RPC, bundleObj);

you can also use the using ... for syntax:

using Bundle for Bundle.BundleObj;

// ...

uint64 egp = bundleObj.simulateBundle();

~~merged with #51 to use its JSON library~~ removed bc gas too high

zeroXbrock avatar Feb 29 '24 08:02 zeroXbrock

While doing some integration testing, I noticed that the JSON encoder lib is using a LOT of gas. I have to set my gas limit to 30M for one CCR that JSON-encodes 10 (each) simBundle & sendBundle payloads. When the CCR lands, it only ends up using about 36k gas. But if I don't set the limit extremely high, I get an out of gas error.

Is this OK? I wonder if it would be better to do the JSON encoding offchain to avoid this, or maybe there's a way to tweak the gas estimate logic on the backend to avoid this confusion. cc @jinmel @lthibault @ferranbt

zeroXbrock avatar Mar 13 '24 19:03 zeroXbrock