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

Update to oz v5.0 #49

Merged
merged 125 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
85605b8
Merge pull request #26 from CanzaApps/rinkeby-oracle
David405 Sep 26, 2022
64a6389
switched to hardhat, wrote deploy scripts
David405 Nov 21, 2022
eee3521
fixed bug with remove from blacklist function
David405 Nov 28, 2022
a36aeaa
changed value used to compare in test impact to USD value of collater…
David405 Dec 1, 2022
4e6c76f
added slither
David405 Dec 8, 2022
230fb06
added package-lock and specified directory to run slither test
David405 Dec 8, 2022
6a8935d
fixed syntax error on yaml file
David405 Dec 8, 2022
a8b40ab
fixed syntax error on yaml file
David405 Dec 8, 2022
aa47e1a
fix dependency tree
David405 Dec 8, 2022
2b5991c
changed node version for github action
David405 Dec 8, 2022
b7c5fca
fixed dependency tree
David405 Dec 8, 2022
8309009
added sarif to slither
David405 Dec 8, 2022
a90d95d
added codeql
David405 Dec 8, 2022
426003e
Delete codeql.yml
David405 Dec 8, 2022
6c525f2
Update slither.yml
David405 Dec 8, 2022
92a28e2
Update slither.yml
David405 Dec 8, 2022
2e6d745
Update slither.yml
David405 Dec 8, 2022
177e64a
Update Oracle.sol
David405 Dec 8, 2022
ee68e44
Update Oracle.sol
David405 Dec 8, 2022
40e55b2
merged hardhat-port
David405 Dec 12, 2022
ba4ca50
gas estimation fixes attempt
David405 Dec 31, 2022
d68cf65
fixed re-eentrancy on liquidation
David405 Dec 31, 2022
84f38ef
fixed re-entrancy in claim fees
David405 Dec 31, 2022
3ec8fc4
Added USDC code
Sir-Deon Jan 3, 2023
faad6e5
Added USDC code
Sir-Deon Jan 3, 2023
5767ce8
updated deploy script
David405 Jan 5, 2023
6565d6c
added public getters for liquidation
David405 Jan 11, 2023
c5ef473
added getters for tracking total collateral, swap volume
David405 Jan 12, 2023
b8f17b5
an attempt to fix stack too deep error in swap function
David405 Jan 13, 2023
75ec261
2nd attempt to fix stack too deep error in swap
David405 Jan 13, 2023
edf4187
fixed iteration bug in blacklist remove function
David405 Jan 16, 2023
1ec88e3
added a manager function for users in liquidation zone
David405 Jan 17, 2023
b597f74
added script to upgrade contract
David405 Jan 16, 2023
0ad986d
fixed minimum bytes bug, upgrade script
David405 Jan 19, 2023
1a7b540
added a public getter for globalDebt
David405 Jan 19, 2023
e93439f
fixed vulnerable in liquidation by using USDValue of collateral
David405 Jan 24, 2023
82cdd07
fixed liquidation vulnerability
David405 Jan 24, 2023
b934f35
removed minters wallet
David405 Jan 24, 2023
e3d0e14
fixed error in liquidate function
David405 Jan 26, 2023
7e2c932
fixed overflow error in repay and withdrawal
David405 Jan 26, 2023
a6d7a09
fixed calculation bug in swap
David405 Jan 26, 2023
650f450
made some quality of life improvements
David405 Jan 27, 2023
2e109d0
Merge pull request #38 from CanzaApps/unit-tests
David405 Jan 27, 2023
e11323c
adjusted get Decimal to 1e16, added a limit of 1000 to setZCollateralUSD
David405 Feb 7, 2023
3933d74
Merge pull request #39 from CanzaApps/unit-tests
David405 Feb 7, 2023
2a201e5
Bump crytic/slither-action from 0.2.0 to 0.3.0
dependabot[bot] Feb 24, 2023
a6c278f
added a function to get user debt
David405 Mar 6, 2023
adf8a96
fixed swap fees
David405 Mar 6, 2023
2192ed3
Merge pull request #41 from CanzaApps/unit-tests
David405 Mar 6, 2023
64cf256
removed decimals
David405 May 30, 2023
06b329e
added support for arbitrary ztokens
David405 Jun 7, 2023
bd26d42
added function to remove ztoken address, added events
David405 Jun 19, 2023
cc1d8ca
switched ztoken parameter in swap, repay and other functions from add…
David405 Jun 27, 2023
cd6d140
fixed bug with adding first time user to mint list
David405 Jun 28, 2023
0dec51d
changed mint logic
David405 Jun 30, 2023
b7e0cc5
made minor cleanups
David405 Aug 2, 2023
5e23cfe
Merge pull request #40 from CanzaApps/dependabot/github_actions/cryti…
David405 Aug 2, 2023
f6e94cb
Merge pull request #42 from CanzaApps/support-arbitrary-ztokens
David405 Aug 2, 2023
6bfe95c
changed pause function name, removed unused event and added optimizer
David405 Aug 20, 2023
35cc6f7
added storage gap
David405 Aug 20, 2023
16cc129
added SafeERC20
David405 Aug 20, 2023
b48c66c
removed admin control from _removeUserFromLiquidation
David405 Aug 20, 2023
c2cc86e
fixed inconsistency with comment and code in Math library
David405 Aug 20, 2023
aacc834
added initializer for reentrancy guard
David405 Aug 20, 2023
b30fa3b
added initializer modifier to vault_init
David405 Aug 20, 2023
2e6b14c
optimised calculation for adding user to minters list, swap rewards, …
David405 Aug 20, 2023
7cbdb6f
added validation to fee settings
David405 Aug 20, 2023
e856867
fixed vulnerability with remove token function
David405 Aug 20, 2023
988dbc2
added check to set zToken value in oracle contract
David405 Aug 20, 2023
419c0e2
added swap volume tracking to repay function
David405 Aug 20, 2023
d7531cc
made correction to the MULTIPLIER used while total swap volume
David405 Aug 20, 2023
3cc6645
fixed vulnerabilities with adding and removing zTokens
David405 Aug 20, 2023
abbff19
initialised zusd
David405 Aug 20, 2023
c6fcd03
added access control to admin functions
David405 Aug 20, 2023
af3cc4c
fixed bug with swapVolume, getSwapRewards()
David405 Aug 23, 2023
a36b07a
fixed bug with swapVolume
David405 Aug 23, 2023
77d998f
upgraded solidity compiler version, removed unused function from toke…
David405 Aug 23, 2023
75b21df
updated solidity version in hardhat config
David405 Aug 23, 2023
081750f
moved solidity version to v0.8.18
David405 Aug 23, 2023
13c0fdb
fixed vulnerability in claimFees
David405 Aug 23, 2023
cfd5218
combined fee settings into single function
David405 Aug 23, 2023
b6b2ae9
fixed bug with pausing and unpausing transactions
David405 Aug 23, 2023
a19ceb0
added check to swap rewards
David405 Aug 24, 2023
c27c738
added mainnet config
David405 Aug 31, 2023
66c6390
Stopped tracking .env File
David405 Sep 4, 2023
9423cde
Stopped tracking .DS_Store
David405 Sep 4, 2023
9a1a222
added robust access control
David405 Sep 4, 2023
ff3c8c5
fixed syntax error
David405 Sep 4, 2023
3048e72
pass slither action
David405 Sep 4, 2023
f88cdfe
dummy private key for slither action
David405 Sep 4, 2023
aacb538
added default role to vault_init
David405 Sep 4, 2023
7ce0d9f
gas optimization
David405 Sep 18, 2023
c2cb308
gas optimizations
David405 Sep 18, 2023
004d303
gas optimization
David405 Sep 18, 2023
83a8e5f
added initializer for access control
David405 Sep 18, 2023
a3e0105
removed comment
David405 Sep 18, 2023
0d4e6d1
reverted reward logic
David405 Sep 20, 2023
4f66355
fixed mint flow
David405 Sep 27, 2023
88d7c12
added new reward implementation
David405 Oct 3, 2023
60488c9
upgrade v2 for testnet vault
David405 Oct 12, 2023
fd55af7
fixed netmint change edge case
David405 Oct 16, 2023
e79ab45
made updates
Sir-Deon Oct 16, 2023
246f398
made updates
Sir-Deon Oct 16, 2023
ef665b6
avalanche hardhat verify setup, mainnet USDC support upgrade
David405 Oct 31, 2023
79022a6
made updates
Sir-Deon Nov 21, 2023
399054b
added events and getter functions for analytics
David405 Dec 14, 2023
a060136
changed amount param on swap event to swapAmount
David405 Jan 10, 2024
ab4a24e
updated manage liquidation function to view function
David405 Feb 27, 2024
b31933e
init
Sir-Deon Apr 3, 2024
2f863ac
init
Sir-Deon Apr 3, 2024
ce685e6
Finished Treasury
Sir-Deon Apr 3, 2024
780ff09
Finished Treasury
Sir-Deon Apr 3, 2024
deaf733
Finished Treasury
Sir-Deon Apr 3, 2024
7be9dd5
Finished Treasury
Sir-Deon Apr 3, 2024
c53b667
Finished Treasury
Sir-Deon Apr 4, 2024
59613bd
made updates to the treasury contract
David405 Apr 7, 2024
d9242af
upgraded contracts and scripts to latest openzeppelin and hardhat ver…
David405 Apr 14, 2024
e78fca6
Merge branch 'develop' into update-to-oz-v5.0
David405 Apr 15, 2024
a3c6157
updated node version for slither
David405 Apr 15, 2024
89a7a91
fixed merge conflict
David405 Apr 15, 2024
14918f6
updated mainnet deploy scripts
David405 Apr 15, 2024
502ff95
fixed slither complaints
David405 Apr 15, 2024
32810e3
added programatic contract addition to defender, add vault function
David405 Apr 15, 2024
f5e85cb
added reset functions
David405 Apr 21, 2024
3f876c2
added ownership
David405 Apr 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
Empty file removed .env
Empty file.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
26 changes: 26 additions & 0 deletions .github/workflows/slither.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Slither Analysis

on: [push]

jobs:
analyze:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run Slither
uses: crytic/[email protected]
id: slither
with:
node-version: 20
sarif: outputs.sarif
fail-on: none

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
15 changes: 7 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
./node_modules
.env
.history/
node_modules/
package-lock.json
.history

./oracleServer/node_modules
./oracleServer/.env
node_modules
build
artifacts/
cache/
.openzeppelin/
.env
.DS_Store
13 changes: 13 additions & 0 deletions .hintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": [
"development"
],
"hints": {
"axe/forms": [
"default",
{
"label": "off"
}
]
}
}
47 changes: 47 additions & 0 deletions contracts/Faucet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

import "./interfaces/ZTokenInterface.sol";

contract Faucet is OwnableUpgradeable {
mapping(string => address) public assets;
address public avax;

event AvaxFinished(address _avax, address faucet, uint256 balance);

function init() external initializer {
__Ownable_init(msg.sender);
}


function setAsset(string memory asset, address _address) external onlyOwner {
require(_address != address(0), "address cannot be a zero address");
assets[asset] = _address;
}

function setAvax(address _address) external onlyOwner {
require(_address != address(0), "address cannot be a zero address");
avax = _address;
}

function getAsset(string memory asset, address receiver) external {
if(IERC20(avax).balanceOf(address(this)) > 0.02 ether){
if(IERC20(avax).balanceOf(msg.sender) < 0.02 ether){
IERC20(avax).approve(address(this), 0.02 ether);
bool _success = IERC20(avax).transferFrom(address(this), msg.sender, 0.02 ether);
if(!_success) revert();

}
} else {
emit AvaxFinished(avax, address(this), IERC20(avax).balanceOf(msg.sender));
}
bool success = ZTokenInterface(assets[asset]).mint(receiver, 1000000 ether);
if(!success) revert();
}


}
19 changes: 0 additions & 19 deletions contracts/Migrations.sol

This file was deleted.

125 changes: 108 additions & 17 deletions contracts/Oracle.sol
Original file line number Diff line number Diff line change
@@ -1,35 +1,126 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

pragma solidity 0.8.20;

import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/BakiOracleInterface.sol";

contract BakiOracle is Ownable, BakiOracleInterface {
uint256 _NGNUSD;
uint256 _XAFUSD;
uint256 _ZARUSD;
contract BakiOracle is AccessControl, BakiOracleInterface, Ownable {

bytes32 public constant DATA_FEED = keccak256("DATA_FEED");

mapping(string => address) private zTokenAddress;
mapping(address => uint256) private zTokenUSDValue;

string[] public zTokenList;
uint256 public collateralUSD;

constructor (address admin, address _datafeed, address _zusd, address _zngn, address _zzar, address _zxaf) Ownable(admin) {
string[4] memory default_currencies = ["zusd", "zngn", "zzar", "zxaf"];
_grantRole(DATA_FEED, _datafeed);
_grantRole(DEFAULT_ADMIN_ROLE, admin);

zTokenAddress["zusd"] = _zusd;
zTokenAddress["zngn"] = _zngn;
zTokenAddress["zzar"] = _zzar;
zTokenAddress["zxaf"] = _zxaf;

zTokenList = default_currencies;
}

event AddZToken(string indexed _name, address _address);
event RemoveZToken(string indexed _name);
event SetZTokenUSDValue(string indexed _name, uint256 _value);
event SetZCollateralUSD(uint256 _value);

function addZToken(string calldata _name, address _address) external onlyRole(DEFAULT_ADMIN_ROLE) {

require(_address != address(0), "Address is invalid");
require(!checkIfTokenExists(_name), "zToken already exists");

zTokenAddress[_name] = _address;
zTokenList.push(_name);

emit AddZToken(_name, _address);
}

function getZToken(string calldata _name) public view returns(address) {
require(zTokenAddress[_name] != address(0), "zToken does not exist");

return zTokenAddress[_name];
}

function setNGNUSD(uint256 _value) external onlyOwner {
_NGNUSD = _value;
function getZTokenList() external view returns(string[] memory){
return zTokenList;
}

function setXAFUSD(uint256 _value) external onlyOwner {
_XAFUSD = _value;
function removeZToken(string calldata _name) external onlyRole(DEFAULT_ADMIN_ROLE) {
require(zTokenAddress[_name] != address(0), "zToken does not exist");

delete zTokenAddress[_name];

uint256 index;
bytes32 nameHash = keccak256(bytes(_name));
uint len = zTokenList.length;

for (uint256 i; i < len; i++) {
if (keccak256(bytes(zTokenList[i])) == nameHash) {
index = i;
break;
}
}

if (index < len) {
zTokenList[index] = zTokenList[len - 1];
zTokenList.pop();
}

emit RemoveZToken(_name);
}

function setZARUSD(uint256 _value) external onlyOwner {
_ZARUSD = _value;
function checkIfTokenExists(string calldata _name) public view returns(bool){
bytes32 nameHash = keccak256(bytes(_name));
uint len = zTokenList.length;

for (uint256 i; i < len; i++) {
if (keccak256(bytes(zTokenList[i])) == nameHash) {
return true;
}
}
return false;
}

function NGNUSD() external view override returns (uint256) {
return _NGNUSD;

function setZTokenUSDValue(
string calldata _name,
uint256 _value
) external onlyRole(DATA_FEED) {
address zToken = getZToken(_name);

require(_value >= 1, "Invalid value");

zTokenUSDValue[zToken] = _value;

emit SetZTokenUSDValue(_name, _value);
}

function XAFUSD() external view override returns (uint256) {
return _XAFUSD;
function getZTokenUSDValue(
string calldata _name
) external view returns (uint256) {
address zToken = getZToken(_name);

return zTokenUSDValue[zToken];
}

function ZARUSD() external view override returns (uint256) {
return _ZARUSD;
function setZCollateralUSD(uint256 _value) external onlyRole(DATA_FEED){

if (_value > 1000) {
collateralUSD = 1000;
} else {
collateralUSD = _value;
}

emit SetZCollateralUSD(_value);
}
}
55 changes: 55 additions & 0 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

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

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

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

event Mint(
address indexed _userAddress,
uint256 _amount
);

event Burn(
address indexed _userAddress,
uint256 _amount
);


/**
* @dev these can only be called by the Vault contract
*/
function mint(address _userAddress, uint256 _amount)
external
override
returns (bool)
{
_mint(_userAddress, _amount);

emit Mint(_userAddress, _amount);

return true;
}

function burn(address _userAddress, uint256 _amount)
external
override
returns (bool)
{
_burn(_userAddress, _amount);

emit Burn(_userAddress, _amount);

return true;
}

}
Loading
Loading