Skip to content

Commit

Permalink
added programatic contract addition to defender, add vault function
Browse files Browse the repository at this point in the history
  • Loading branch information
David405 committed Apr 15, 2024
1 parent 502ff95 commit 32810e3
Show file tree
Hide file tree
Showing 13 changed files with 2,534 additions and 2,543 deletions.
4 changes: 1 addition & 3 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ZTokenInterface.sol";

contract Token is ERC20, ZTokenInterface, AccessControl, Ownable {
contract Token is ERC20, ZTokenInterface, Ownable {
// address private vault

/**
* Initializers
*/
constructor(string memory name_, string memory symbol_, address admin_) ERC20(name_, symbol_) Ownable(admin_) {
_grantRole(DEFAULT_ADMIN_ROLE, admin_);
}

event Mint(
Expand Down
3 changes: 1 addition & 2 deletions contracts/USDC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract USDC is ERC20, AccessControl, Ownable {
contract USDC is ERC20, Ownable {

constructor() ERC20("USDC", "USDC") Ownable(msg.sender) {
_mint(msg.sender, 1000000 * 10**18 * 10**18);
Expand Down
2 changes: 1 addition & 1 deletion contracts/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract Vault is
address _oracle,
IERC20 _collateral,
address _zusd
) external initializer {
) external reinitializer(2) {
TxPaused = false;
Oracle = _oracle;
collateral = _collateral;
Expand Down
20 changes: 6 additions & 14 deletions contracts/ZToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/ZTokenInterface.sol";

contract ZToken is ERC20, ZTokenInterface, AccessControl, Ownable {
contract ZToken is ERC20, ZTokenInterface, Ownable {
// address private vault;
bytes32 public constant VAULT = keccak256("VAULT");
address private vault;

/**
* Initializers
*/
constructor(string memory name_, string memory symbol_, address admin_) ERC20(name_, symbol_) Ownable(admin_) {
_grantRole(DEFAULT_ADMIN_ROLE, admin_);
}

event Mint(
Expand All @@ -34,10 +32,9 @@ contract ZToken is ERC20, ZTokenInterface, AccessControl, Ownable {
*/
function mint(address _userAddress, uint256 _amount)
external
onlyRole(VAULT)
returns (bool)
{

require(msg.sender == vault, "You do not have permission");
_mint(_userAddress, _amount);
emit Mint(_userAddress, _amount);

Expand All @@ -46,26 +43,21 @@ contract ZToken is ERC20, ZTokenInterface, AccessControl, Ownable {

function burn(address _userAddress, uint256 _amount)
external
onlyRole(VAULT)
returns (bool)
{

require(msg.sender == vault, "You do not have permission");
_burn(_userAddress, _amount);
emit Burn(_userAddress, _amount);

return true;
}

function addVaultAddress(address _address) external onlyRole(DEFAULT_ADMIN_ROLE) {
function addVault(address _address) external onlyOwner {
require(_address != address(0), "address cannot be a zero address");

_grantRole(VAULT, _address);
vault = _address;

emit AddVaultAddress(_address);
}

function vaultAddress() public pure returns (bytes32) {
return VAULT;
}

}
Loading

0 comments on commit 32810e3

Please sign in to comment.