-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsendComposableBundle.ts
70 lines (64 loc) · 2.37 KB
/
sendComposableBundle.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { JsonRpcProvider, TransactionRequest, Wallet, hexlify, toBigInt, toUtf8Bytes } from 'ethers'
// lib
import MevShareClient, { BundleParams } from '..'
import { getProvider, initExample } from './lib/helpers'
import env from './lib/env'
const NUM_TARGET_BLOCKS = 3
/** Send a bundle that shares as much data as possible by setting the `privacy` param. */
const sendTestBundle = async (provider: JsonRpcProvider, mevshare: MevShareClient, wallet: Wallet, targetBlock: number) => {
const feeData = await provider.getFeeData()
const tip = BigInt(1e9) * BigInt(2e7) // 0.02 eth
const tx: TransactionRequest = {
type: 2,
chainId: provider._network.chainId,
to: wallet.address,
nonce: await wallet.getNonce(),
value: 0,
gasLimit: 22000,
data: hexlify(toUtf8Bytes("im shariiiiiing")),
maxFeePerGas: toBigInt(feeData.maxFeePerGas || 42) + tip,
maxPriorityFeePerGas: toBigInt(feeData.maxPriorityFeePerGas || 2) + tip,
}
/*
NOTE: only bundles comprised solely of signed transactions are supported at the moment.
Bundles containing `hash` cannot set `privacy` settings.
*/
const bundle = [
{tx: await wallet.signTransaction(tx), canRevert: false},
]
console.log(`sending backrun bundles targeting next ${NUM_TARGET_BLOCKS} blocks...`)
const bundleParams: BundleParams = {
inclusion: {
block: targetBlock,
maxBlock: targetBlock + NUM_TARGET_BLOCKS,
},
body: bundle,
privacy: {
hints: {
txHash: true,
calldata: true,
logs: true,
functionSelector: true,
contractAddress: true,
},
builders: ["flashbots"]
}
}
const backrunResult = await mevshare.sendBundle(bundleParams)
return {
bundleParams,
backrunResult,
}
}
const main = async () => {
const provider = getProvider()
const {mevshare} = await initExample(provider)
const targetBlock = (await provider.getBlockNumber()) + 1
const wallet = new Wallet(env.senderKey, provider)
const {bundleParams, backrunResult} = await sendTestBundle(provider, mevshare, wallet, targetBlock)
console.log("bundleParams", bundleParams)
console.log("backrunResult", backrunResult)
}
main().then(() => {
process.exit(0)
})