Skip to content

Commit

Permalink
fix: addec check to withdraw from treasury
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover committed Dec 19, 2024
1 parent 87bba72 commit 56bafc5
Show file tree
Hide file tree
Showing 2 changed files with 314 additions and 6 deletions.
289 changes: 289 additions & 0 deletions simulations/vip-502/abi/ERC20.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
31 changes: 25 additions & 6 deletions simulations/vip-502/basemainnet.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { impersonateAccount, setBalance } from "@nomicfoundation/hardhat-network-helpers";
import { expect } from "chai";
import { Contract } from "ethers";
import { ethers } from "hardhat";
Expand All @@ -14,7 +15,6 @@ import vip502, {
BOUND_VALIDATOR,
COMPTROLLERS,
VTOKENS,
XVS_BRIDGE,
XVS_BRIDGE_ADMIN,
XVS_STORE,
} from "../../vips/vip-502/bscmainnet";
Expand All @@ -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;
Expand All @@ -45,19 +44,25 @@ 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);
redstoneOracle = new ethers.Contract(basemainnet.REDSTONE_ORACLE, CHAINLINK_ORACLE_ABI, provider);
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());
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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"));
});
});
});

0 comments on commit 56bafc5

Please sign in to comment.