From 56bafc5f1cc9f92600f008baead1b4b2713b6bc2 Mon Sep 17 00:00:00 2001 From: web3rover Date: Thu, 19 Dec 2024 16:36:22 +0530 Subject: [PATCH] fix: addec check to withdraw from treasury --- simulations/vip-502/abi/ERC20.json | 289 +++++++++++++++++++++++++++++ simulations/vip-502/basemainnet.ts | 31 +++- 2 files changed, 314 insertions(+), 6 deletions(-) create mode 100644 simulations/vip-502/abi/ERC20.json diff --git a/simulations/vip-502/abi/ERC20.json b/simulations/vip-502/abi/ERC20.json new file mode 100644 index 000000000..28715d783 --- /dev/null +++ b/simulations/vip-502/abi/ERC20.json @@ -0,0 +1,289 @@ +[ + { + "inputs": [ + { + "internalType": "uint256", + "name": "_initialAmount", + "type": "uint256" + }, + { + "internalType": "string", + "name": "_tokenName", + "type": "string" + }, + { + "internalType": "uint8", + "name": "_decimalUnits", + "type": "uint8" + }, + { + "internalType": "string", + "name": "_tokenSymbol", + "type": "string" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "allocateTo", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "src", + "type": "address" + }, + { + "internalType": "address", + "name": "dst", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/simulations/vip-502/basemainnet.ts b/simulations/vip-502/basemainnet.ts index 6f41122bd..901df5928 100644 --- a/simulations/vip-502/basemainnet.ts +++ b/simulations/vip-502/basemainnet.ts @@ -1,3 +1,4 @@ +import { impersonateAccount, setBalance } from "@nomicfoundation/hardhat-network-helpers"; import { expect } from "chai"; import { Contract } from "ethers"; import { ethers } from "hardhat"; @@ -14,7 +15,6 @@ import vip502, { BOUND_VALIDATOR, COMPTROLLERS, VTOKENS, - XVS_BRIDGE, XVS_BRIDGE_ADMIN, XVS_STORE, } from "../../vips/vip-502/bscmainnet"; @@ -29,12 +29,11 @@ import BOUND_VALIDATOR_ABI from "../vip-502/abi/boundValidator.json"; import CHAINLINK_ORACLE_ABI from "../vip-502/abi/chainlinkOracle.json"; import RESILLIENT_ORACLE_ABI from "../vip-502/abi/resilientOracle.json"; import TREASURY_ABI from "../vip-502/abi/treasury.json"; -import XVS_BRIDGE_ABI from "../vip-502/abi/xvsBridge.json"; import XVS_BRIDGE_ADMIN_ABI from "../vip-502/abi/xvsBridgeAdmin.json"; const { basemainnet } = NETWORK_ADDRESSES; -forking(23864228, async () => { +forking(23908020, async () => { const provider = ethers.provider; let prime: Contract; let plp: Contract; @@ -45,10 +44,13 @@ forking(23864228, async () => { let resilientOracle: Contract; let boundValidator: Contract; let xvsBridgeAdmin: Contract; - let xvsBridge: Contract; let treasury: Contract; before(async () => { + await impersonateAccount(basemainnet.NORMAL_TIMELOCK); + await setBalance(basemainnet.NORMAL_TIMELOCK, ethers.utils.parseEther("1")); + await setBalance(basemainnet.VTREASURY, ethers.utils.parseEther("100")); + prime = new ethers.Contract(PRIME, PRIME_ABI, provider); plp = new ethers.Contract(PLP, PRIME_LIQUIDITY_PROVIDER_ABI, provider); chainLinkOracle = new ethers.Contract(basemainnet.CHAINLINK_ORACLE, CHAINLINK_ORACLE_ABI, provider); @@ -56,8 +58,11 @@ forking(23864228, async () => { resilientOracle = new ethers.Contract(basemainnet.RESILIENT_ORACLE, RESILLIENT_ORACLE_ABI, provider); boundValidator = new ethers.Contract(BOUND_VALIDATOR, BOUND_VALIDATOR_ABI, provider); xvsBridgeAdmin = await ethers.getContractAt(XVS_BRIDGE_ADMIN_ABI, XVS_BRIDGE_ADMIN); - xvsBridge = await ethers.getContractAt(XVS_BRIDGE_ABI, XVS_BRIDGE); - treasury = await ethers.getContractAt(TREASURY_ABI, basemainnet.VTREASURY); + treasury = await ethers.getContractAt( + TREASURY_ABI, + basemainnet.VTREASURY, + await ethers.getSigner(basemainnet.NORMAL_TIMELOCK), + ); await pretendExecutingVip(await vip003()); await pretendExecutingVip(await vip004()); @@ -66,6 +71,14 @@ forking(23864228, async () => { await pretendExecutingVip(await vip007()); }); + describe("Pre-VIP behavior", async () => { + it("cannot transfer tokens from the treasury", async () => { + await expect( + treasury.withdrawTreasuryNative(ethers.utils.parseEther("100"), basemainnet.NORMAL_TIMELOCK), + ).to.be.revertedWith("Ownable: caller is not the owner"); + }); + }); + testForkedNetworkVipCommands("vip502", await vip502()); describe("Post-VIP behavior", async () => { @@ -110,5 +123,11 @@ forking(23864228, async () => { it("Normal Timelock should be the owner of the Vtreasury", async () => { expect(await treasury.owner()).equals(basemainnet.NORMAL_TIMELOCK); }); + it("can transfer tokens from the treasury", async () => { + const prevBalance = await provider.getBalance(basemainnet.NORMAL_TIMELOCK); + await treasury.withdrawTreasuryNative(ethers.utils.parseEther("100"), basemainnet.NORMAL_TIMELOCK); + const newBalance = await provider.getBalance(basemainnet.NORMAL_TIMELOCK); + expect(newBalance.sub(prevBalance)).to.be.closeTo(ethers.utils.parseEther("100"), ethers.utils.parseEther("0.1")); + }); }); });