-
-
Save Saw-mon-and-Natalie/2a0280c72cd1b93bd2ed25658899e169 to your computer and use it in GitHub Desktop.
Flashbots ENS domain transfer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hre = require('hardhat'); | |
const { map } = require('underscore'); | |
require('dotenv').config(); | |
const { | |
FlashbotsBundleProvider, | |
} = require('@flashbots/ethers-provider-bundle'); | |
const ENS = require('./ENSABI.json'); | |
const FlashBotsABI = require('./FlashBotsABI.json'); | |
const { provider } = hre.ethers; | |
const ENSAddr = '0x57f1887a8BF19b14fC0dF6Fd9B2acc9Af147eA85'; | |
const FlashbotsCheckAndSendAddr = '0xC4595E3966e0Ce6E3c46854647611940A09448d3'; | |
async function main() { | |
const flashbotsProvider = await FlashbotsBundleProvider.create( | |
provider, | |
process.env.FLASHBOTS_KEY_ID, | |
process.env.FLASHBOTS_SECRET | |
); | |
const ERC721 = new hre.ethers.Contract(ENSAddr, ENS, provider); | |
const FlashbotsCheckAndSend = new hre.ethers.Contract( | |
FlashbotsCheckAndSendAddr, | |
FlashBotsABI, | |
provider | |
); | |
const rogue = new hre.ethers.Wallet(process.env.ROGUE_PRIV_KEY, provider); | |
const user = new hre.ethers.Wallet(process.env.USER_PRIV_KEY, provider); | |
const transferENSDomain = await ERC721.populateTransaction.transferFrom( | |
rogue.address, | |
user.address, | |
process.env.ENS_DOMAIN_ID, | |
{ | |
from: rogue.address, | |
gasPrice: hre.ethers.BigNumber.from('0'), | |
gasLimit: hre.ethers.BigNumber.from('400000'), | |
} | |
); | |
const checkDomainOwner = await ERC721.populateTransaction.ownerOf( | |
process.env.ENS_DOMAIN_ID | |
); | |
const payload = checkDomainOwner.data; | |
// 32 bytes, encoded user address | |
const expectedResponse = | |
'0x000000000000000000000000d745c80485ef2792c5fdc02e879f0124756ea065'; | |
const checkAndSend = await FlashbotsCheckAndSend.populateTransaction.check32BytesAndSend( | |
ENSAddr, | |
payload, | |
expectedResponse, | |
{ | |
gasPrice: hre.ethers.BigNumber.from('0'), | |
gasLimit: hre.ethers.BigNumber.from('400000'), | |
value: hre.ethers.utils.parseEther('0.04'), | |
} | |
); | |
const blockNumber = await provider.getBlockNumber(); | |
const bundlePromises = map([...Array(20).keys()], (targetBlockNumber) => | |
flashbotsProvider.sendBundle( | |
[ | |
{ signer: rogue, transaction: transferENSDomain }, | |
{ signer: user, transaction: checkAndSend }, | |
], | |
targetBlockNumber + 1 + blockNumber | |
) | |
); | |
for (const bundle of bundlePromises) { | |
await (await bundle).wait(); | |
} | |
await main(); | |
} | |
main() | |
.then(() => main()) | |
.catch((error) => { | |
console.error(error); | |
main(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment