Skip to content

Commit

Permalink
Merge pull request #414 from VenusProtocol/vip/VEN-2891
Browse files Browse the repository at this point in the history
[VEN-2891] Transfer funds from vTreasury
  • Loading branch information
Debugger022 authored Dec 10, 2024
2 parents 17e348e + 498bd00 commit 55f57db
Show file tree
Hide file tree
Showing 4 changed files with 507 additions and 0 deletions.
231 changes: 231 additions & 0 deletions simulations/vip-404/abi/ERC20.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
[
{ "inputs": [], "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": "previousOwner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"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": 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": [
{ "internalType": "address", "name": "owner", "type": "address" },
{ "internalType": "address", "name": "spender", "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": "account", "type": "address" }],
"name": "balanceOf",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }],
"name": "burn",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "decimals",
"outputs": [{ "internalType": "uint8", "name": "", "type": "uint8" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "subtractedValue", "type": "uint256" }
],
"name": "decreaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "getOwner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "spender", "type": "address" },
{ "internalType": "uint256", "name": "addedValue", "type": "uint256" }
],
"name": "increaseAllowance",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }],
"name": "mint",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "name",
"outputs": [{ "internalType": "string", "name": "", "type": "string" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"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": "recipient", "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": "sender", "type": "address" },
{ "internalType": "address", "name": "recipient", "type": "address" },
{ "internalType": "uint256", "name": "amount", "type": "uint256" }
],
"name": "transferFrom",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
}
]
83 changes: 83 additions & 0 deletions simulations/vip-404/abi/VTreasury.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
[
{
"anonymous": false,
"inputs": [
{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" },
{ "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "address", "name": "tokenAddress", "type": "address" },
{ "indexed": false, "internalType": "uint256", "name": "withdrawAmount", "type": "uint256" },
{ "indexed": false, "internalType": "address", "name": "withdrawAddress", "type": "address" }
],
"name": "WithdrawTreasuryBEP20",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{ "indexed": false, "internalType": "uint256", "name": "withdrawAmount", "type": "uint256" },
{ "indexed": false, "internalType": "address", "name": "withdrawAddress", "type": "address" }
],
"name": "WithdrawTreasuryBNB",
"type": "event"
},
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
{
"constant": true,
"inputs": [],
"name": "owner",
"outputs": [{ "internalType": "address", "name": "", "type": "address" }],
"payable": false,
"stateMutability": "view",
"type": "function"
},
{
"constant": false,
"inputs": [],
"name": "renounceOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }],
"name": "transferOwnership",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "address", "name": "tokenAddress", "type": "address" },
{ "internalType": "uint256", "name": "withdrawAmount", "type": "uint256" },
{ "internalType": "address", "name": "withdrawAddress", "type": "address" }
],
"name": "withdrawTreasuryBEP20",
"outputs": [],
"payable": false,
"stateMutability": "nonpayable",
"type": "function"
},
{
"constant": false,
"inputs": [
{ "internalType": "uint256", "name": "withdrawAmount", "type": "uint256" },
{ "internalType": "address payable", "name": "withdrawAddress", "type": "address" }
],
"name": "withdrawTreasuryBNB",
"outputs": [],
"payable": true,
"stateMutability": "payable",
"type": "function"
}
]
75 changes: 75 additions & 0 deletions simulations/vip-404/bscmainnet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { expect } from "chai";
import { BigNumber, Contract } from "ethers";
import { ethers } from "hardhat";

import { expectEvents } from "../../src/utils";
import { forking, testVip } from "../../src/vip-framework";
import vip404, {
CERTIK,
CERTIK_AMOUNT_USDT,
CHAOS_LABS,
CHAOS_LABS_AMOUNT_USDC,
TOKEN_REDEEMER,
USDC,
USDT,
VANGUARD_VANTAGE_AMOUNT_USDT,
VANGUARD_VANTAGE_SOURCECONTROL_AMOUNT_USDT,
VANGUARD_VANTAGE_TREASURY,
VENUS_STARS_BEINCRYPTO_AMOUNT_USDT,
VENUS_STARS_TREASURY,
vUSDC,
} from "../../vips/vip-404/bscmainnet";
import ERC20_ABI from "./abi/ERC20.json";
import VTREASURY_ABI from "./abi/VTreasury.json";

forking(44729395, async () => {
let usdc: Contract;
let usdt: Contract;
let vusdc: Contract;

let prevUSDTBalanceOfVanguard: BigNumber;
let prevUSDTBalanceOfVenusStars: BigNumber;
let prevUSDCBalanceOfChaosLabs: BigNumber;
let prevUSDTBalanceOfCertik: BigNumber;

before(async () => {
usdt = new ethers.Contract(USDT, ERC20_ABI, ethers.provider);
usdc = new ethers.Contract(USDC, ERC20_ABI, ethers.provider);
vusdc = new ethers.Contract(vUSDC, ERC20_ABI, ethers.provider);

prevUSDTBalanceOfVanguard = await usdt.balanceOf(VANGUARD_VANTAGE_TREASURY);
prevUSDTBalanceOfVenusStars = await usdt.balanceOf(VENUS_STARS_TREASURY);
prevUSDCBalanceOfChaosLabs = await usdc.balanceOf(CHAOS_LABS);
prevUSDTBalanceOfCertik = await usdt.balanceOf(CERTIK);
});

testVip("VIP-404", await vip404(), {
callbackAfterExecution: async txResponse => {
await expectEvents(txResponse, [VTREASURY_ABI], ["WithdrawTreasuryBEP20"], [5]);
},
});

describe("Post-VIP behavior", async () => {
it("check balances", async () => {
const usdtBalanceOfCertik = await usdt.balanceOf(CERTIK);
const usdtBalanceOfVanguard = await usdt.balanceOf(VANGUARD_VANTAGE_TREASURY);
const usdcBalanceOfChaosLabs = await usdc.balanceOf(CHAOS_LABS);
const usdtBalanceOfVenusStars = await usdt.balanceOf(VENUS_STARS_TREASURY);

expect(usdtBalanceOfCertik.sub(prevUSDTBalanceOfCertik)).to.equal(CERTIK_AMOUNT_USDT);
expect(usdtBalanceOfVanguard.sub(prevUSDTBalanceOfVanguard)).to.equal(
BigNumber.from(VANGUARD_VANTAGE_AMOUNT_USDT).add(VANGUARD_VANTAGE_SOURCECONTROL_AMOUNT_USDT),
);
expect(usdcBalanceOfChaosLabs.sub(prevUSDCBalanceOfChaosLabs)).to.equal(CHAOS_LABS_AMOUNT_USDC);
expect(usdtBalanceOfVenusStars.sub(prevUSDTBalanceOfVenusStars)).to.equal(VENUS_STARS_BEINCRYPTO_AMOUNT_USDT);
});

it("Leaves no USDC in the redeemer helper contract", async () => {
expect(await usdc.balanceOf(TOKEN_REDEEMER)).to.equal(0);
});

it("Leaves no vUSDC in the redeemer helper contract", async () => {
expect(await vusdc.balanceOf(TOKEN_REDEEMER)).to.equal(0);
});
});
});
Loading

0 comments on commit 55f57db

Please sign in to comment.