Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use prematched bundle #37

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"author": "",
"dependencies": {
"@flashbots/mev-share-client": "^0.7.10",
"@reinis_frp/mev-share-client": "^0.7.10",
"@types/axios": "^0.14.0",
"@types/body-parser": "^1.19.4",
"@types/express": "^4.17.20",
Expand Down
37 changes: 13 additions & 24 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import morgan from "morgan";

dotenv.config();

import { keccak256, Wallet, TransactionRequest, Interface, Transaction } from "ethers";
import { Wallet, TransactionRequest, Interface, Transaction } from "ethers";
import { FlashbotsBundleProvider } from "flashbots-ethers-v6-provider-bundle";
import { createJSONRPCErrorResponse, createJSONRPCSuccessResponse, isJSONRPCRequest, isJSONRPCID } from "json-rpc-2.0";
import { BundleParams } from "@flashbots/mev-share-client";
import MevShareClient from "@flashbots/mev-share-client";
import { BundleParams } from "@reinis_frp/mev-share-client";

import {
getProvider,
Expand Down Expand Up @@ -100,18 +99,16 @@ app.post("/", async (req, res, next) => {

Logger.debug(`Found valid unlock at ${unlock.ovalAddress}. Sending unlock tx bundle and backrun bundle...`);

// Send the call to Oval to unlock the latest value.
await sendUnlockLatestValue(
// Construct the inner bundle with call to Oval to unlock the latest value.
const unlockBundle = createUnlockLatestValueBundle(
unlock.signedUnlockTx,
ovalConfigs[unlock.ovalAddress].refundAddress,
adjustedRefundPercent,
mevshare,
targetBlock,
);

// Construct the bundle with the modified payload to backrun the UnlockLatestValue call.
// Construct the outer bundle with the modified payload to backrun the UnlockLatestValue call.
const bundle: BundleParams["body"] = [
{ hash: unlock.unlockBundleHash },
{ bundle: unlockBundle },
...backrunTxs.map((tx): { tx: string; canRevert: boolean } => {
return { tx, canRevert: false };
}),
Expand All @@ -126,6 +123,9 @@ app.post("/", async (req, res, next) => {
privacy: {
builders: env.builders,
},
validity: {
refund: [{ bodyIdx: 0, percent: adjustedRefundPercent }],
},
};

const backrunResult = await mevshare.sendBundle(bundleParams);
Expand Down Expand Up @@ -243,10 +243,7 @@ const findUnlock = async (

const simulationResponse = await flashbotsBundleProvider.simulate([signedUnlockTx, ...backrunTxs], targetBlock);

// MEV-Share is now referencing bundle hash as double hash of the transaction.
const unlockBundleHash = keccak256(unlockTxHash);

return { ovalAddress, unlockBundleHash, unlockTxHash, signedUnlockTx, simulationResponse };
return { ovalAddress, unlockTxHash, signedUnlockTx, simulationResponse };
}),
);

Expand All @@ -264,14 +261,8 @@ const findUnlock = async (
return undefined;
};

const sendUnlockLatestValue = async (
signedUnlockTx: string,
refundAddress: string,
refundPercent: number,
mevshare: MevShareClient,
targetBlock: number,
) => {
// Send this as a bundle. Define the max share hints and share kickback to configured refund address.
const createUnlockLatestValueBundle = (signedUnlockTx: string, refundAddress: string, targetBlock: number) => {
// Create this as a bundle. Define the max share hints and share kickback to configured refund address.
const bundleParams: ExtendedBundleParams = {
inclusion: { block: targetBlock, maxBlock: targetBlock },
body: [{ tx: signedUnlockTx, canRevert: false }],
Expand All @@ -292,12 +283,10 @@ const sendUnlockLatestValue = async (
txHash: true,
},
builders: env.builders,
wantRefund: refundPercent,
},
};

Logger.debug("Unlock Latest Call bundle", { bundleParams });
await mevshare.sendBundle(bundleParams);
return bundleParams;
};

// Adjusts refund percent to ensure that net builder captured value reaches the minimum configured amount.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JsonRpcProvider, Network, Wallet, Provider, isAddress, isHexString, Transaction, ethers } from "ethers";
import MevShareClient from "@flashbots/mev-share-client";
import MevShareClient from "@reinis_frp/mev-share-client";
import { FlashbotsBundleProvider } from "flashbots-ethers-v6-provider-bundle";
import { env } from "./env";
import { Logger } from "./logging";
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BundleParams, HintPreferences } from "@flashbots/mev-share-client";
import { BundleParams, HintPreferences } from "@reinis_frp/mev-share-client";

// Extend BundleParams to include undocumented wantRefund required for precise kickback to work.
export interface ExtendedBundleParams extends BundleParams {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -322,15 +322,6 @@
resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.1.0.tgz#0709e9f4cb252351c609c6e6d8d6779a8d25edff"
integrity sha512-+KpH+QxZU7O4675t3mnkQKcZZg56u+K/Ct2K+N2AZYNVK8kyeo/bI18tI8aPm3tvNNRyTWfj6s5tnGNlcbQRsA==

"@flashbots/mev-share-client@^0.7.10":
version "0.7.10"
resolved "https://registry.yarnpkg.com/@flashbots/mev-share-client/-/mev-share-client-0.7.10.tgz#f86383dd91bf3bb6d6451456ce418229814009eb"
integrity sha512-jK2ZejfPzNY4du4pKnu9PTxMikbgHOKhfpXgAe6g/QeDyzz1yzfGLIffxa6CaqM0ygyyUMIPs3h2pgL3MzA4tg==
dependencies:
async-mutex "^0.4.0"
axios "^1.3.4"
eventsource "^2.0.2"

"@gar/promisify@^1.0.1":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.3.tgz#555193ab2e3bb3b6adc3d551c9c030d9e860daf6"
Expand Down Expand Up @@ -752,6 +743,15 @@
resolved "https://registry.yarnpkg.com/@protobufjs/utf8/-/utf8-1.1.0.tgz#a777360b5b39a1a2e5106f8e858f2fd2d060c570"
integrity sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==

"@reinis_frp/mev-share-client@^0.7.10":
version "0.7.10"
resolved "https://registry.yarnpkg.com/@reinis_frp/mev-share-client/-/mev-share-client-0.7.10.tgz#e5627199b538e084e1eb720f53ceaa491fa47924"
integrity sha512-aOVfk8nJudMCwWVd+VZS1qpC86tmRk+PlBNXDvX30iD96AB0GylwnDYos51oN480YZOCQSF2H18rMtOFwtSJ9w==
dependencies:
async-mutex "^0.4.0"
axios "^1.3.4"
eventsource "^2.0.2"

"@sapphire/async-queue@^1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@sapphire/async-queue/-/async-queue-1.5.0.tgz#2f255a3f186635c4fb5a2381e375d3dfbc5312d8"
Expand Down