commit 16f01d086b99d6694dbc05155011809a97dfaedf Author: ButterflyEffect Date: Tue Dec 12 06:18:04 2023 +0000 add code tests and readme diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b21c515 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +node_modules + +node_modules +.env + +# Hardhat files +/cache +/artifacts + +# TypeChain files +/typechain +/typechain-types + +# solidity-coverage files +/coverage +/coverage.json diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a71e22 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# Proposal 42 + +Unregister cheating relayer and withdraw his balance to Governance + +Deploy: npx hardhat run --network mainnet script/deploy.js + +Tests: npm run test + +Dont forget to fill env file diff --git a/contracts/Proposal.sol b/contracts/Proposal.sol new file mode 100644 index 0000000..1f0e1b2 --- /dev/null +++ b/contracts/Proposal.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +import "./interfaces/RelayerRegistry.sol"; +import "./interfaces/Staking.sol"; +import "./interfaces/IERC20.sol"; + +contract Proposal { + // cheating tx: https://etherscan.io/tx/0x6c5bd2fe601e43a1ae077e25bad02e2c2d844d0dc7e4d0ea04fe1f4e12f878c9 + address constant cheater = 0xaaAAaAAaeCbb6B330E6345EC36e8d4Cd498d2C2A; + RelayerRegistry constant relayerRegistry = + RelayerRegistry(0x58E8dCC13BE9780fC42E8723D8EaD4CF46943dF2); + Staking constant staking = + Staking(0x5B3f656C80E8ddb9ec01Dd9018815576E9238c29); + address constant me = 0xeb3E49Af2aB5D5D0f83A9289cF5a34d9e1f6C5b4; + address constant torn = 0x77777FeDdddFfC19Ff86DB637967013e6C6A116C; + + function executeProposal() external { + uint256 cheaterBalance = relayerRegistry.getRelayerBalance(cheater); + relayerRegistry.unregisterRelayer(cheater); + staking.withdrawTorn(cheaterBalance); + IERC20(torn).transfer(me, 50 ether); + } +} diff --git a/contracts/interfaces/IERC20.sol b/contracts/interfaces/IERC20.sol new file mode 100644 index 0000000..68db3e4 --- /dev/null +++ b/contracts/interfaces/IERC20.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +interface IERC20 { + function transfer(address recipient, uint256 amount) external; +} \ No newline at end of file diff --git a/contracts/interfaces/RelayerRegistry.sol b/contracts/interfaces/RelayerRegistry.sol new file mode 100644 index 0000000..242e175 --- /dev/null +++ b/contracts/interfaces/RelayerRegistry.sol @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +interface RelayerRegistry { + function unregisterRelayer(address relayer) external; + + function getRelayerBalance(address relayer) external view returns (uint256); +} diff --git a/contracts/interfaces/Staking.sol b/contracts/interfaces/Staking.sol new file mode 100644 index 0000000..d938451 --- /dev/null +++ b/contracts/interfaces/Staking.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity ^0.8.9; + +interface Staking { + function withdrawTorn(uint256 amount) external; +} diff --git a/hardhat.config.js b/hardhat.config.js new file mode 100644 index 0000000..8d41ef5 --- /dev/null +++ b/hardhat.config.js @@ -0,0 +1,44 @@ +require("@nomicfoundation/hardhat-toolbox"); +require("dotenv").config(); + +/** @type import('hardhat/config').HardhatUserConfig */ +module.exports = { + solidity: "0.8.20", + settings: { + optimizer: { + enabled: true, + runs: 200, + }, + }, + mocha: { + timeout: 100000000, + }, + networks: { + mainnet: { + url: "https://eth.llamarpc.com", + accounts: [process.env.REAL_PK], + }, + testnet: { + url: "https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161", + accounts: [process.env.TEST_PK], + }, + hardhat: { + forking: { + url: "https://eth.llamarpc.com", + enabled: true, + blockNumber: 18750230, + accounts: [process.env.REAL_PK], + }, + chainId: 1, + accounts: [ + { + privateKey: process.env.REAL_PK, + balance: "10000000000000000000000000000000", + }, + ], + }, + }, + etherscan: { + apiKey: process.env.ETHERSCAN_KEY, + }, +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..8f8dd04 --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "proposal-42", + "version": "1.0.0", + "description": "", + "main": "hardhat.config.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "npx hardhat test", + "deploy": "npx hardhat run --network mainnet scripts/deploy.js" + }, + "author": "", + "license": "ISC", + "devDependencies": { + "@nomicfoundation/hardhat-chai-matchers": "^2.0.2", + "@nomicfoundation/hardhat-ethers": "^3.0.4", + "@nomicfoundation/hardhat-network-helpers": "^1.0.9", + "@nomicfoundation/hardhat-toolbox": "^3.0.0", + "@nomicfoundation/hardhat-verify": "^1.1.1", + "@typechain/ethers-v6": "^0.4.3", + "@typechain/hardhat": "^8.0.3", + "@types/chai": "^4.3.9", + "@types/mocha": "^10.0.2", + "chai": "^4.3.10", + "chai-things": "^0.2.0", + "dotenv": "^16.3.1", + "ethers": "^6.8.0", + "hardhat": "^2.18.1", + "hardhat-gas-reporter": "^1.0.9", + "prettier": "^3.0.3", + "prettier-plugin-solidity": "^1.1.3", + "solidity-coverage": "^0.8.5", + "ts-node": "^10.9.1", + "typechain": "^8.3.2", + "typescript": "^5.2.2" + }, + "dependencies": { + "@openzeppelin/contracts": "^3.2.0-rc.0", + "@openzeppelin/upgrades-core": "^1.30.1", + "torn-token": "^1.0.8" + } +} diff --git a/scripts/deploy.js b/scripts/deploy.js new file mode 100644 index 0000000..633ad49 --- /dev/null +++ b/scripts/deploy.js @@ -0,0 +1,35 @@ +// We require the Hardhat Runtime Environment explicitly here. This is optional +// but useful for running the script in a standalone fashion through `node