-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
44 lines (40 loc) · 1.55 KB
/
index.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
import { ethers } from 'ethers';
import { FlashbotsBundleProvider } from '@flashbots/ethers-provider-bundle';
import dotenv from 'dotenv';
dotenv.config();
class CustomError extends Error {
constructor(...args: any) {
super(...args)
Object.setPrototypeOf(this, new.target.prototype)
}
}
const provider = new ethers.providers.JsonRpcProvider(process.env.PROVIDER_URL);
const createBundle = async (fundingWalletTransaction, claimTransaction, withdrawTransaction, flushTransaction) => {
return [
fundingWalletTransaction,
claimTransaction,
withdrawTransaction,
flushTransaction
]
}
const yeetCover = async (
provider: ethers.providers.JsonRpcProvider,
transactions: any
) => {
try {
const flashbotsProvider = await FlashbotsBundleProvider.create(provider, ethers.Wallet.createRandom())
provider.on('block', async (blockNumber: number) => {
const bundle = await createBundle(transactions.fund, transactions.claim, transactions.withdraw, transactions.flush)
const flashbotsTransactionResponse = await flashbotsProvider.sendBundle(bundle, blockNumber + 1);
// in event of error produce error msg
if ('error' in flashbotsTransactionResponse) {
console.warn(flashbotsTransactionResponse.error.message)
return
}
// simulate transaction
console.log(await flashbotsTransactionResponse.simulate())
})
} catch (error) {
throw new CustomError(error.message)
}
}