-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
461 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11155111 |
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
deployments/sepolia/solcInputs/8f044f8922734cfdbad0a866002b3c24.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters