Skip to content

Instantly share code, notes, and snippets.

@andrekorol
Last active July 19, 2023 05:35
Show Gist options
  • Save andrekorol/a371e3207363215f355bdb87a2dc700a to your computer and use it in GitHub Desktop.
Save andrekorol/a371e3207363215f355bdb87a2dc700a to your computer and use it in GitHub Desktop.
Flashbots ENS domain transfer
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