Last active
September 5, 2023 05:23
-
-
Save SKYBITDev3/eb8c5562c05b9011fc96e9fb68daaf1f to your computer and use it in GitHub Desktop.
Zoltu's factory vs Arachnid's factory vs Arachnid's factory deployed via Zoltu's factory
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
async function main() { | |
const { ethers, network } = require(`hardhat`) | |
const [wallet1, wallet2] = await ethers.getSigners() | |
const walletToUse = wallet1 // switch between wallet1 & wallet2 to see the difference in addresses | |
console.log(`Using network: ${network.name} (${network.config.chainId}), account: ${walletToUse.address} having ${await ethers.formatUnits(await ethers.provider.getBalance(walletToUse.address), `ether`)} of native currency, RPC url: ${network.config.url}`) | |
let txReceipt | |
// Deploy Zoltu's factory | |
const addressOfZoltusFactory = `0x7A0D94F55792C434d74a40883C6ed8545E406D12` // See https://github.com/Zoltu/deterministic-deployment-proxy | |
if (await ethers.provider.getCode(addressOfZoltusFactory) === `0x`) { | |
// Fund account of signer of transaction that deploys Zoltu's factory. | |
const addressOfSignerToDeployZoltusFactory = `0x4c8D290a1B368ac4728d83a9e8321fC3af2b39b1` | |
txReceipt = await walletToUse.sendTransaction({ to: addressOfSignerToDeployZoltusFactory, value: ethers.parseUnits(`0.1`, `ether`) }) | |
await txReceipt.wait() | |
txReceipt = await ethers.provider.broadcastTransaction(`0xf87e8085174876e800830186a08080ad601f80600e600039806000f350fe60003681823780368234f58015156014578182fd5b80825250506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222`) | |
await txReceipt.wait() | |
} | |
console.log(`Address of Zoltu's factory deployed keylessly: ${addressOfZoltusFactory}`) | |
// get Lock contract bytecode | |
const contractName = `Lock` | |
// const currentTimestampInSeconds = Math.round(Date.now() / 1000) | |
// const unlockTime = currentTimestampInSeconds + 60 | |
const unlockTime = 8888888888n // keep it constant otherwise address will be different on every deployment because of different bytecode every time | |
const constructorArgs = [unlockTime] | |
const cfToken = await ethers.getContractFactory(contractName) | |
const bytecodeOfLockWithArgs = (await cfToken.getDeployTransaction(...constructorArgs)).data | |
// Deploy Lock via Zoltu's factory | |
let txData = { | |
from: walletToUse.address, | |
to: addressOfZoltusFactory, | |
data: bytecodeOfLockWithArgs, | |
} | |
let expectedAddress = await walletToUse.call(txData) // same as: await ethers.provider.send(`eth_call`, [ txData, `latest` ]) | |
console.log(`Address of ${contractName} deployed via Zoltu's factory: ${expectedAddress}`) | |
txReceipt = await walletToUse.sendTransaction(txData) | |
await txReceipt.wait() | |
let lock = cfToken.attach(expectedAddress) | |
console.log(`Attached to ${contractName} at ${expectedAddress}`) | |
console.log(`lock.unlockTime(): ${await lock.unlockTime()}`) // Test deployed Lock contract at expected address | |
// Deploy Arachnid's factory | |
const addressOfArachnidsFactory = `0x4e59b44847b379578588920ca78fbf26c0b4956c` // See https://github.com/Arachnid/deterministic-deployment-proxy. Difference with Zoltu's factory is that salt must be prepended to bytecode of contract being deployed. | |
if (await ethers.provider.getCode(addressOfArachnidsFactory) === `0x`) { | |
// Fund account of signer of transaction that deploys Arachnid's factory. | |
const addressOfSignerToDeployArachnidsFactory = `0x3fab184622dc19b6109349b94811493bf2a45362` | |
txReceipt = await walletToUse.sendTransaction({ to: addressOfSignerToDeployArachnidsFactory, value: ethers.parseUnits(`0.1`, `ether`) }) | |
await txReceipt.wait() | |
txReceipt = await ethers.provider.broadcastTransaction(`0xf8a58085174876e800830186a08080b853604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf31ba02222222222222222222222222222222222222222222222222222222222222222a02222222222222222222222222222222222222222222222222222222222222222`) | |
await txReceipt.wait() | |
} | |
console.log(`Address of Arachnid's factory deployed keylessly: ${addressOfArachnidsFactory}`) | |
// Deploy Lock via Arachnid's factory | |
const salt = ethers.encodeBytes32String(``) // 0x0000000000000000000000000000000000000000000000000000000000000000 | |
txData = { | |
from: walletToUse.address, | |
to: addressOfArachnidsFactory, | |
data: bytecodeOfLockWithArgs.replace(`0x`, salt), | |
} | |
expectedAddress = await walletToUse.call(txData) | |
console.log(`Address of ${contractName} deployed via Arachnid's factory: ${expectedAddress}`) | |
txReceipt = await walletToUse.sendTransaction(txData) | |
await txReceipt.wait() | |
lock = cfToken.attach(expectedAddress) | |
console.log(`Attached to ${contractName} at ${expectedAddress}`) | |
console.log(`lock.unlockTime(): ${await lock.unlockTime()}`) // Test deployed Lock contract at expected address | |
// Deploy Arachnid's factory via Zoltu's factory | |
const bytecodeOfArachnidsFactory = `0x604580600e600039806000f350fe7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe03601600081602082378035828234f58015156039578182fd5b8082525050506014600cf3` | |
txData = { | |
to: addressOfZoltusFactory, | |
data: bytecodeOfArachnidsFactory, | |
} | |
const addressOfArachnidsFactoryDeployedViaZoltusFactory = await walletToUse.call(txData) | |
console.log(`Address of Arachnid's factory deployed via Zoltu's factory: ${JSON.stringify(addressOfArachnidsFactoryDeployedViaZoltusFactory, null, 2)}`) | |
txReceipt = await walletToUse.sendTransaction(txData) | |
await txReceipt.wait() | |
// Deploy Lock via Arachnid's factory that was deployed via Zoltu's factory | |
txData = { | |
to: addressOfArachnidsFactoryDeployedViaZoltusFactory, | |
data: bytecodeOfLockWithArgs.replace(`0x`, salt), | |
} | |
expectedAddress = await walletToUse.call(txData) | |
console.log(`Address of ${contractName} deployed via Arachnid's factory that was deployed via Zoltu's factory: ${expectedAddress}`) | |
txReceipt = await walletToUse.sendTransaction(txData) | |
await txReceipt.wait() | |
lock = cfToken.attach(expectedAddress) | |
console.log(`Attached to ${contractName} at ${expectedAddress}`) | |
console.log(`lock.unlockTime(): ${await lock.unlockTime()}`) // Test deployed Lock contract at expected address | |
} | |
main().catch(error => { | |
console.error(error) | |
process.exitCode = 1 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment