Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VEN-1909]: Add VTreasuryV8 #345

Merged
merged 15 commits into from
Nov 16, 2023
85 changes: 85 additions & 0 deletions contracts/Governance/VTreasuryV8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
pragma solidity 0.8.20;

import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

/**
* @title VTreasuryV8
* @author Venus
* @notice Protocol treasury that holds tokens owned by Venus
*/
contract VTreasuryV8 is Ownable {
using SafeERC20 for IERC20;

// WithdrawTreasuryToken Event
event WithdrawTreasuryToken(address indexed tokenAddress, uint256 withdrawAmount, address indexed withdrawAddress);

// WithdrawTreasuryNative Event
event WithdrawTreasuryNative(uint256 withdrawAmount, address indexed withdrawAddress);

/**
* @notice To receive Native when msg.data is not empty
*/
fallback() external payable {}

/**
* @notice To receive Native when msg.data is empty
*/
receive() external payable {}

/**
* @notice Withdraw Treasury Tokens, Only owner call it
* @param tokenAddress The address of treasury token
* @param withdrawAmount The withdraw amount to owner
* @param withdrawAddress The withdraw address
*/
function withdrawTreasuryToken(
address tokenAddress,
uint256 withdrawAmount,
address withdrawAddress
) external onlyOwner {
uint256 actualWithdrawAmount = withdrawAmount;
// Get Treasury Token Balance
uint256 treasuryBalance = IERC20(tokenAddress).balanceOf(address(this));

// Check Withdraw Amount
if (withdrawAmount > treasuryBalance) {
// Update actualWithdrawAmount
actualWithdrawAmount = treasuryBalance;
}

// Transfer Token to withdrawAddress
IERC20(tokenAddress).safeTransfer(withdrawAddress, actualWithdrawAmount);

emit WithdrawTreasuryToken(tokenAddress, actualWithdrawAmount, withdrawAddress);
}

/**
* @notice Withdraw Treasury Native, Only owner call it
* @param withdrawAmount The withdraw amount to owner
* @param withdrawAddress The withdraw address
*/
function withdrawTreasuryNative(
uint256 withdrawAmount,
address payable withdrawAddress
) external payable onlyOwner {
uint256 actualWithdrawAmount = withdrawAmount;
// Get Treasury Native Balance
uint256 nativeBalance = address(this).balance;

// Check Withdraw Amount
if (withdrawAmount > nativeBalance) {
// Update actualWithdrawAmount
actualWithdrawAmount = nativeBalance;
}
// Transfer the native token to withdrawAddress
withdrawAddress.transfer(actualWithdrawAmount);

emit WithdrawTreasuryNative(actualWithdrawAmount, withdrawAddress);
}

/**
* @notice Empty implementation to avoid any mishappening.
*/
function renounceOwnership() public override onlyOwner {}
}
36 changes: 36 additions & 0 deletions deploy/007-deploy-VTreasuryV8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ethers } from "hardhat";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

interface AdminAccounts {
[key: string]: string;
}
const acmAdminAccount: AdminAccounts = {
sepolia: "0x94fa6078b6b8a26f0b6edffbe6501b22a10470fb", // SEPOLIA MULTISIG
ethereum: "", // TODO: add Ethereum MULTISIG once it is deployed
};

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();
const deployerSigner = await hre.ethers.getSigner(deployer);

const treasuryInstance = await deploy("VTreasuryV8", {
from: deployer,
args: [],
log: true,
autoMine: true,
});

console.log("Transferring owner to venus admin account");
const adminAccount: string = acmAdminAccount[hre.network.name];
const VTreasuryV8 = await ethers.getContractAt("VTreasuryV8", treasuryInstance.address);
const tx = await VTreasuryV8.connect(deployerSigner).transferOwnership(adminAccount);
tx.wait();
console.log("Ownership Transffered to: ", await VTreasuryV8.owner());
};

func.tags = ["VTreasuryV8"];

export default func;
1 change: 1 addition & 0 deletions deployments/sepolia/.chainId
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11155111
249 changes: 249 additions & 0 deletions deployments/sepolia/VTreasuryV8.json

Large diffs are not rendered by default.

Loading
Loading