Skip to content

Commit

Permalink
feat!: add VTresuryV8
Browse files Browse the repository at this point in the history
  • Loading branch information
GitGuru7 committed Sep 14, 2023
1 parent 2f089e3 commit 2b87b14
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 0 deletions.
87 changes: 87 additions & 0 deletions contracts/Governance/VTreasuryV8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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 tokenAddress, uint256 withdrawAmount, address withdrawAddress);

// WithdrawTreasuryNative Event
event WithdrawTreasuryNative(uint256 withdrawAmount, address 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 Native to withdrawAddress
bool res = withdrawAddress.send(actualWithdrawAmount);

require(res, "Transfer Failed");

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.

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ const config: HardhatUserConfig = {
},
},
},
{
version: "0.8.20",
settings: {
optimizer: {
enabled: true,
runs: 200,
},
outputSelection: {
"*": {
"*": ["storageLayout"],
},
},
},
},
],
},
networks: {
Expand All @@ -106,6 +120,15 @@ const config: HardhatUserConfig = {
live: true,
timeout: 1200000, // 20 minutes
},
sepolia: {
url: process.env.RPC_URL || "https://rpc.notadegen.com/eth/sepolia",
chainId: 11155111,
live: true,
gasPrice: 20000000000, // 20 gwei
accounts: {
mnemonic: process.env.MNEMONIC || "",
},
},
},
etherscan: {
apiKey: BSCSCAN_API_KEY,
Expand Down

0 comments on commit 2b87b14

Please sign in to comment.