From b475d68b1eac0551edb23c25af8d17228db90b0b Mon Sep 17 00:00:00 2001 From: Crisgarner <@crisgarner> Date: Thu, 16 Feb 2023 09:59:03 -0600 Subject: [PATCH 1/3] renamed tests --- test/HardETHVaultHandler.t.sol | 6 +++--- test/VaultsPausing.t.sol | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/HardETHVaultHandler.t.sol b/test/HardETHVaultHandler.t.sol index 88b61b3..b0995a1 100644 --- a/test/HardETHVaultHandler.t.sol +++ b/test/HardETHVaultHandler.t.sol @@ -28,8 +28,8 @@ contract ETHVaultHandlerTest is Test { ChainlinkOracle ethOracle = new ChainlinkOracle(address(ethAggregator), address(this)); WETH weth = new WETH(); - address user = address(0x1); - address user2 = address(0x2); + address user = address(0x51); + address user2 = address(0x52); //// Params uint256 divisor = 10000000000; @@ -37,7 +37,7 @@ contract ETHVaultHandlerTest is Test { uint256 burnFee = 50; uint256 mintFee = 50; uint256 liquidationPenalty = 5; - address treasury = address(0x3); + address treasury = address(0x53); function setUp() public { ethVault = new ETHVaultHandler( diff --git a/test/VaultsPausing.t.sol b/test/VaultsPausing.t.sol index 34e2f8a..7a4cd44 100644 --- a/test/VaultsPausing.t.sol +++ b/test/VaultsPausing.t.sol @@ -30,8 +30,8 @@ contract VaultDisablingTest is Test { ChainlinkOracle ethOracle = new ChainlinkOracle(address(ethAggregator), address(this)); WETH weth = new WETH(); - address user = address(0x1); - address user2 = address(0x2); + address user = address(0x51); + address user2 = address(0x52); //// Params uint256 divisor = 10000000000; @@ -39,7 +39,7 @@ contract VaultDisablingTest is Test { uint256 burnFee = 50; uint256 mintFee = 50; uint256 liquidationPenalty = 5; - address treasury = address(0x3); + address treasury = address(0x53); function setUp() public { ethVault = new ETHVaultHandler( From c5517c8223cae68acd9beaa441382244ef9d37b9 Mon Sep 17 00:00:00 2001 From: Crisgarner <@crisgarner> Date: Thu, 16 Feb 2023 16:19:47 -0600 Subject: [PATCH 2/3] renamed tcap to index --- contracts/BaseOrchestrator.sol | 66 +++---- contracts/BaseTreasury.sol | 2 +- contracts/ERC20VaultHandler.sol | 22 +-- contracts/ETHVaultHandler.sol | 22 +-- contracts/IVaultHandler.sol | 168 ++++++++++-------- contracts/{TCAP.sol => IndexToken.sol} | 28 +-- contracts/MATICVaultHandler.sol | 18 +- contracts/Orchestrator.sol | 66 +++---- test/HardETHVaultHandler.t.sol | 58 +++--- test/LinkAave.t.sol | 2 +- test/VaultsPausing.t.sol | 6 +- .../GovernanceBridgeIntegration.t.sol | 8 +- test/arbitrum/JPEGZBridgeFork.t.sol | 4 +- test/arbitrum/JPEGzMainnetOracleFork.t.sol | 38 ++-- 14 files changed, 259 insertions(+), 249 deletions(-) rename contracts/{TCAP.sol => IndexToken.sol} (87%) diff --git a/contracts/BaseOrchestrator.sol b/contracts/BaseOrchestrator.sol index 420ac5b..d290c08 100644 --- a/contracts/BaseOrchestrator.sol +++ b/contracts/BaseOrchestrator.sol @@ -6,12 +6,12 @@ import "@openzeppelin/contracts/introspection/ERC165Checker.sol"; import "./IVaultHandler.sol"; import "./oracles/ChainlinkOracle.sol"; import "./Proprietor.sol"; -import "./TCAP.sol"; +import "./IndexToken.sol"; /** - * @title TCAP Orchestrator + * @title Cryptex Orchestrator * @author Cryptex.finance - * @notice Orchestrator contract in charge of managing the settings of the vaults, rewards and TCAP token. It acts as the owner of these contracts. + * @notice Orchestrator contract in charge of managing the settings of the vaults, rewards and Index token. It acts as the owner of these contracts. */ abstract contract BaseOrchestrator is Proprietor { /// @dev Enum which saves the available functions to emergency call. @@ -27,7 +27,7 @@ abstract contract BaseOrchestrator is Proprietor { /** @dev Interface constants*/ bytes4 private constant _INTERFACE_ID_IVAULT = 0x9e75ab0c; - bytes4 private constant _INTERFACE_ID_TCAP = 0xbd115939; + bytes4 private constant _INTERFACE_ID_INDEX = 0xbd115939; bytes4 private constant _INTERFACE_ID_CHAINLINK_ORACLE = 0x85be402b; /// @dev tracks which vault was emergency called @@ -79,13 +79,13 @@ abstract contract BaseOrchestrator is Proprietor { } /** - * @notice Throws if TCAP Token is not valid - * @param _tcap address + * @notice Throws if Index Token is not valid + * @param _indexToken address */ - modifier validTCAP(TCAP _tcap) { + modifier validIndex(IndexToken _indexToken) { require( - ERC165Checker.supportsInterface(address(_tcap), _INTERFACE_ID_TCAP), - "BaseOrchestrator::validTCAP: not a valid TCAP ERC20" + ERC165Checker.supportsInterface(address(_indexToken), _INTERFACE_ID_INDEX), + "BaseOrchestrator::validIndex: not a valid Index Token" ); _; } @@ -262,67 +262,67 @@ abstract contract BaseOrchestrator is Proprietor { } /** - * @notice Enables or disables the TCAP Cap - * @param _tcap address + * @notice Enables or disables the Index Token Cap + * @param _indexToken address * @param _enable bool * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid */ - function enableTCAPCap(TCAP _tcap, bool _enable) + function enableIndexCap(IndexToken _indexToken, bool _enable) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) { - _tcap.enableCap(_enable); + _indexToken.enableCap(_enable); } /** - * @notice Sets the TCAP maximum minting value - * @param _tcap address + * @notice Sets the Index Token maximum minting value + * @param _indexToken address * @param _cap uint value * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid */ - function setTCAPCap(TCAP _tcap, uint256 _cap) + function setIndexCap(IndexToken _indexToken, uint256 _cap) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) { - _tcap.setCap(_cap); + _indexToken.setCap(_cap); } /** - * @notice Adds Vault to TCAP ERC20 - * @param _tcap address + * @notice Adds Vault to Index Token + * @param _indexToken address * @param _vault address * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid * @dev Validates if _vault is valid */ - function addTCAPVault(TCAP _tcap, IVaultHandler _vault) + function addIndexVault(IndexToken _indexToken, IVaultHandler _vault) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) validVault(_vault) { - _tcap.addVaultHandler(address(_vault)); + _indexToken.addVaultHandler(address(_vault)); } /** - * @notice Removes Vault to TCAP ERC20 - * @param _tcap address + * @notice Removes Vault to Index Token + * @param _indexToken address * @param _vault address * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid * @dev Validates if _vault is valid */ - function removeTCAPVault(TCAP _tcap, IVaultHandler _vault) + function removeIndexVault(IndexToken _indexToken, IVaultHandler _vault) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) validVault(_vault) { - _tcap.removeVaultHandler(address(_vault)); + _indexToken.removeVaultHandler(address(_vault)); } /** diff --git a/contracts/BaseTreasury.sol b/contracts/BaseTreasury.sol index c36dcb3..8a912a1 100644 --- a/contracts/BaseTreasury.sol +++ b/contracts/BaseTreasury.sol @@ -4,7 +4,7 @@ pragma solidity 0.7.5; import "./Proprietor.sol"; /** - * @title TCAP Treasury + * @title "Cryptex Treasury * @author Cryptex.finance * @notice This contract will hold the assets generated on L2 networks. */ diff --git a/contracts/ERC20VaultHandler.sol b/contracts/ERC20VaultHandler.sol index cabe8c6..a544e70 100644 --- a/contracts/ERC20VaultHandler.sol +++ b/contracts/ERC20VaultHandler.sol @@ -5,9 +5,9 @@ import "./IVaultHandler.sol"; import "./Orchestrator.sol"; /** - * @title ERC-20 TCAP Vault + * @title ERC-20 Index Token Vault * @author Cryptex.finance - * @notice Contract in charge of handling the TCAP Vault and stake using a Collateral ERC20 + * @notice Contract in charge of handling the Index Token Vault and stake using a Collateral ERC20 */ contract ERC20VaultHandler is IVaultHandler { /** @@ -18,13 +18,13 @@ contract ERC20VaultHandler is IVaultHandler { * @param _burnFee uint256 * @param _mintFee uint256 * @param _liquidationPenalty uint256 - * @param _tcapOracle address - * @param _tcapAddress address + * @param _indexOracle address + * @param _indexAddress address * @param _collateralAddress address * @param _collateralOracle address * @param _ethOracle address * @param _treasury address - * @param _minimumTCAP uint256 + * @param _minimumMint uint256 */ constructor( Orchestrator _orchestrator, @@ -33,13 +33,13 @@ contract ERC20VaultHandler is IVaultHandler { uint256 _burnFee, uint256 _mintFee, uint256 _liquidationPenalty, - address _tcapOracle, - TCAP _tcapAddress, + address _indexOracle, + IndexToken _indexAddress, address _collateralAddress, address _collateralOracle, address _ethOracle, address _treasury, - uint256 _minimumTCAP + uint256 _minimumMint ) IVaultHandler( _orchestrator, @@ -48,13 +48,13 @@ contract ERC20VaultHandler is IVaultHandler { _burnFee, _mintFee, _liquidationPenalty, - _tcapOracle, - _tcapAddress, + _indexOracle, + _indexAddress, _collateralAddress, _collateralOracle, _ethOracle, _treasury, - _minimumTCAP + _minimumMint ) {} } diff --git a/contracts/ETHVaultHandler.sol b/contracts/ETHVaultHandler.sol index 0720f2a..a4159ae 100644 --- a/contracts/ETHVaultHandler.sol +++ b/contracts/ETHVaultHandler.sol @@ -7,9 +7,9 @@ import "./IWETH.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; /** - * @title ETH TCAP Vault + * @title ETH Index Token Vault * @author Cryptex.finance - * @notice Contract in charge of handling the TCAP Vault and stake using a ETH and WETH + * @notice Contract in charge of handling the Index Token Vault and stake using a ETH and WETH */ contract ETHVaultHandler is IVaultHandler { /// @notice Open Zeppelin libraries @@ -23,13 +23,13 @@ contract ETHVaultHandler is IVaultHandler { * @param _burnFee uint256 * @param _mintFee uint256 * @param _liquidationPenalty uint256 - * @param _tcapOracle address - * @param _tcapAddress address + * @param _indexOracle address + * @param _indexAddress address * @param _collateralAddress address * @param _collateralOracle address * @param _ethOracle address * @param _treasury address - * @param _minimumTCAP uint256 + * @param _minimumMint uint256 */ constructor( Orchestrator _orchestrator, @@ -38,13 +38,13 @@ contract ETHVaultHandler is IVaultHandler { uint256 _burnFee, uint256 _mintFee, uint256 _liquidationPenalty, - address _tcapOracle, - TCAP _tcapAddress, + address _indexOracle, + IndexToken _indexAddress, address _collateralAddress, address _collateralOracle, address _ethOracle, address _treasury, - uint256 _minimumTCAP + uint256 _minimumMint ) IVaultHandler( _orchestrator, @@ -53,13 +53,13 @@ contract ETHVaultHandler is IVaultHandler { _burnFee, _mintFee, _liquidationPenalty, - _tcapOracle, - _tcapAddress, + _indexOracle, + _indexAddress, _collateralAddress, _collateralOracle, _ethOracle, _treasury, - _minimumTCAP + _minimumMint ) {} diff --git a/contracts/IVaultHandler.sol b/contracts/IVaultHandler.sol index b38c640..aee9097 100644 --- a/contracts/IVaultHandler.sol +++ b/contracts/IVaultHandler.sol @@ -12,14 +12,14 @@ import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "@openzeppelin/contracts/utils/Counters.sol"; import "@openzeppelin/contracts/utils/Pausable.sol"; import "@openzeppelin/contracts/introspection/IERC165.sol"; -import "./TCAP.sol"; +import "./IndexToken.sol"; import "./Orchestrator.sol"; import "./oracles/ChainlinkOracle.sol"; /** - * @title TCAP Vault Handler Abstract Contract + * @title Vault Handler Abstract Contract * @author Cryptex.Finance - * @notice Contract in charge of handling the TCAP Token and stake + * @notice Contract in charge of handling the Index Token and stake */ abstract contract IVaultHandler is Ownable, @@ -44,10 +44,10 @@ abstract contract IVaultHandler is } /** - * @notice Vault object created to manage the mint and burns of TCAP tokens + * @notice Vault object created to manage the mint and burns of Index tokens * @param Id, unique identifier of the vault * @param Collateral, current collateral on vault - * @param Debt, current amount of TCAP tokens minted + * @param Debt, current amount of Index tokens minted * @param Owner, owner of the vault */ struct Vault { @@ -63,11 +63,11 @@ abstract contract IVaultHandler is /// @notice value used to divide collateral to adjust the decimal places uint256 public immutable collateralDecimalsAdjustmentFactor; - /// @notice TCAP Token Address - TCAP public immutable TCAPToken; + /// @notice Index Token Address + IndexToken public immutable indexToken; /// @notice Total Market Cap/USD Oracle Address - ChainlinkOracle public immutable tcapOracle; + ChainlinkOracle public immutable indexOracle; /// @notice Collateral Token Address IERC20 public immutable collateralContract; @@ -78,23 +78,23 @@ abstract contract IVaultHandler is /// @notice ETH/USD Oracle Address ChainlinkOracle public immutable ETHPriceOracle; - /// @notice Value used as divisor with the total market cap, just like the S&P 500 or any major financial index would to define the final tcap token price + /// @notice Value used as divisor with the value of the index token, just like the S&P 500 or any major financial index would to define the final token price uint256 public divisor; /// @notice Minimum ratio required to prevent liquidation of vault uint256 public ratio; - /// @notice Fee percentage of the total amount to burn charged on ETH when burning TCAP Tokens + /// @notice Fee percentage of the total amount to burn charged on ETH when burning Index Tokens uint256 public burnFee; - /// @notice Fee percentage of the total amount to mint charged on ETH when burning TCAP Tokens + /// @notice Fee percentage of the total amount to mint charged on ETH when burning Index Tokens uint256 public mintFee; /// @notice Penalty charged to vault owner when a vault is liquidated, this value goes to the liquidator uint256 public liquidationPenalty; - /// @notice Minimum amount of TCAP an user can mint - uint256 public minimumTCAP = 0; + /// @notice Minimum amount of Index Tokens an user can mint + uint256 public minimumMint = 0; /// @notice Address of the treasury contract (usually the timelock) where the funds generated by the protocol are sent address public treasury; @@ -148,8 +148,8 @@ abstract contract IVaultHandler is uint256 _liquidationPenalty ); - /// @notice An event emitted when the minimum required TCAP is updated - event NewMinimumTCAP(address indexed _owner, uint256 _minimumTCAP); + /// @notice An event emitted when the minimum required Token is updated + event NewMinimumMint(address indexed _owner, uint256 _minimumMint); /// @notice An event emitted when the treasury contract is updated event NewTreasury(address indexed _owner, address _tresury); @@ -211,13 +211,13 @@ abstract contract IVaultHandler is * @param _burnFee uint256 * @param _mintFee uint256 * @param _liquidationPenalty uint256 - * @param _tcapOracle address - * @param _tcapAddress address + * @param _indexOracle address + * @param _indexAddress address * @param _collateralAddress address * @param _collateralOracle address * @param _ethOracle address * @param _treasury address - * @param _minimumTCAP uint256 + * @param _minimumMint uint256 */ constructor( Orchestrator _orchestrator, @@ -226,13 +226,13 @@ abstract contract IVaultHandler is uint256 _burnFee, uint256 _mintFee, uint256 _liquidationPenalty, - address _tcapOracle, - TCAP _tcapAddress, + address _indexOracle, + IndexToken _indexAddress, address _collateralAddress, address _collateralOracle, address _ethOracle, address _treasury, - uint256 _minimumTCAP + uint256 _minimumMint ) { require( _liquidationPenalty.add(100) < _ratio, @@ -253,13 +253,13 @@ abstract contract IVaultHandler is burnFee = _burnFee; mintFee = _mintFee; liquidationPenalty = _liquidationPenalty; - tcapOracle = ChainlinkOracle(_tcapOracle); + indexOracle = ChainlinkOracle(_indexOracle); collateralContract = IERC20(_collateralAddress); collateralPriceOracle = ChainlinkOracle(_collateralOracle); ETHPriceOracle = ChainlinkOracle(_ethOracle); - TCAPToken = _tcapAddress; + indexToken = _indexAddress; treasury = _treasury; - minimumTCAP = _minimumTCAP; + minimumMint = _minimumMint; uint8 _collateralDecimals = ERC20(_collateralAddress).decimals(); require( _collateralDecimals <= MAX_DECIMAL_PLACES, @@ -317,7 +317,7 @@ abstract contract IVaultHandler is } /** - * @notice Sets the mint fee percentage an user pays when burning tcap tokens + * @notice Sets the mint fee percentage an user pays when burning Index tokens * @param _mintFee uint * @dev Only owner can call it */ @@ -331,7 +331,7 @@ abstract contract IVaultHandler is } /** - * @notice Sets the burn fee percentage an user pays when burning tcap tokens + * @notice Sets the burn fee percentage an user pays when burning Index tokens * @param _burnFee uint * @dev Only owner can call it */ @@ -365,14 +365,14 @@ abstract contract IVaultHandler is } /** - * @notice Sets the minimum TCAP a vault owner can mint - * @param _minimumTCAP uint + * @notice Sets the minimum token a vault owner has to mint + * @param _minimumMint uint * @dev Only owner can call it * @dev this is mostly used on hard mode vaults with low collateral ratio vaults */ - function setMinimumTCAP(uint256 _minimumTCAP) external virtual onlyOwner { - minimumTCAP = _minimumTCAP; - emit NewMinimumTCAP(msg.sender, _minimumTCAP); + function setMinimumMint(uint256 _minimumMint) external virtual onlyOwner { + minimumMint = _minimumMint; + emit NewMinimumMint(msg.sender, _minimumMint); } /** @@ -447,7 +447,7 @@ abstract contract IVaultHandler is } /** - * @notice Allows users to remove collateral currently not being used to generate TCAP tokens from their vaults + * @notice Allows users to remove collateral currently not being used to generate index tokens from their vaults * @param _amount of collateral to remove * @dev reverts if the resulting ratio is less than the minimum ratio * @dev _amount should be higher than 0 @@ -485,7 +485,7 @@ abstract contract IVaultHandler is } /** - * @notice Uses collateral to generate debt on TCAP Tokens which are minted and assigned to caller + * @notice Uses collateral to generate debt on index tokens which are minted and assigned to caller * @param _amount of tokens to mint * @dev _amount should be higher than 0 * @dev requires to have a vault ratio above the minimum ratio @@ -523,10 +523,10 @@ abstract contract IVaultHandler is ); require( - vault.Debt >= minimumTCAP, + vault.Debt >= minimumMint, "VaultHandler::mint: mint amount less than required" ); - TCAPToken.mint(msg.sender, _amount); + indexToken.mint(msg.sender, _amount); safeTransferETH(treasury, fee); emit TokensMinted(msg.sender, vault.Id, _amount); //send back ETH above fee @@ -534,7 +534,7 @@ abstract contract IVaultHandler is } /** - * @notice Pays the debt of TCAP tokens resulting them on burn, this releases collateral up to minimum vault ratio + * @notice Pays the debt of the Index token resulting them on burn, this releases collateral up to minimum vault ratio * @param _amount of tokens to burn * @dev _amount should be higher than 0 * @dev A fee of exactly burnFee must be sent as value on ETH @@ -568,14 +568,14 @@ abstract contract IVaultHandler is } /** - * @notice Allow users to burn TCAP tokens to liquidate vaults with vault collateral ratio under the minimum ratio, the liquidator receives the staked collateral of the liquidated vault at a premium + * @notice Allow users to burn Index tokens to liquidate vaults with vault collateral ratio under the minimum ratio, the liquidator receives the staked collateral of the liquidated vault at a premium * @param _vaultId to liquidate - * @param _maxTCAP max amount of TCAP the liquidator is willing to pay to liquidate vault + * @param _maxIndex max amount of Index the liquidator is willing to pay to liquidate vault * @dev Resulting ratio must be above or equal minimum ratio * @dev A fee of exactly burnFee must be sent as value on ETH * @dev The fee goes to the treasury contract */ - function liquidateVault(uint256 _vaultId, uint256 _maxTCAP) + function liquidateVault(uint256 _vaultId, uint256 _maxIndex) external payable nonReentrant @@ -591,20 +591,20 @@ abstract contract IVaultHandler is "VaultHandler::liquidateVault: vault is not liquidable" ); - uint256 requiredTCAP = requiredLiquidationTCAP(vault.Id); + uint256 requiredIndex = requiredLiquidationIndex(vault.Id); require( - _maxTCAP >= requiredTCAP, + _maxIndex >= requiredIndex, "VaultHandler::liquidateVault: liquidation amount different than required" ); - uint256 fee = getBurnFee(requiredTCAP); + uint256 fee = getBurnFee(requiredIndex); require( msg.value >= fee, "VaultHandler::liquidateVault: burn fee less than required" ); uint256 reward = liquidationReward(vault.Id); - _burn(vault.Id, requiredTCAP); + _burn(vault.Id, requiredIndex); //Removes the collateral that is rewarded to liquidator vault.Collateral = vault.Collateral.sub(reward); @@ -617,7 +617,7 @@ abstract contract IVaultHandler is //send back ETH above fee safeTransferETH(msg.sender, msg.value.sub(fee)); - emit VaultLiquidated(vault.Id, msg.sender, requiredTCAP, reward); + emit VaultLiquidated(vault.Id, msg.sender, requiredIndex, reward); } /** @@ -716,28 +716,28 @@ abstract contract IVaultHandler is } /** - * @notice Returns the price of the TCAP token - * @return price of the TCAP Token - * @dev TCAP token is 18 decimals + * @notice Returns the price of the Index token + * @return price of the Index Token + * @dev Index token is 18 decimals * @dev oracle totalMarketPrice must be in wei format * @dev P = T / d - * P = TCAP Token Price + * P = Index Token Price * T = Total Crypto Market Cap * d = Divisor */ - function TCAPPrice() public view virtual returns (uint256 price) { - uint256 totalMarketPrice = getOraclePrice(tcapOracle); + function indexPrice() public view virtual returns (uint256 price) { + uint256 totalMarketPrice = getOraclePrice(indexOracle); price = totalMarketPrice.div(divisor); } /** - * @notice Returns the minimal required collateral to mint TCAP token + * @notice Returns the minimal required collateral to mint Index token * @param _amount uint amount to mint - * @return collateral of the TCAP Token - * @dev TCAP token is 18 decimals + * @return collateral of the Index Token + * @dev Index token is 18 decimals * @dev C = ((P * A * r) / 100) / (cp * cdaf) * C = Required Collateral - * P = TCAP Token Price + * P = Index Token Price * A = Amount to Mint * cp = Collateral Price * r = Minimum Ratio for Liquidation @@ -749,44 +749,44 @@ abstract contract IVaultHandler is virtual returns (uint256 collateral) { - uint256 tcapPrice = TCAPPrice(); + uint256 iPrice = indexPrice(); uint256 collateralPrice = getOraclePrice(collateralPriceOracle); - collateral = ((tcapPrice.mul(_amount).mul(ratio)).div(100)) + collateral = ((iPrice.mul(_amount).mul(ratio)).div(100)) .div(collateralPrice) .div(collateralDecimalsAdjustmentFactor); } /** - * @notice Returns the minimal required TCAP to liquidate a Vault + * @notice Returns the minimal required Index to liquidate a Vault * @param _vaultId of the vault to liquidate - * @return amount required of the TCAP Token - * @dev LT = ((((D * r) / 100) - cTcap) * 100) / (r - (p + 100)) - * cTcap = ((C * cdaf * cp) / P) - * LT = Required TCAP + * @return amount required of the Index Token + * @dev LT = ((((D * r) / 100) - cIndex) * 100) / (r - (p + 100)) + * cIndex = ((C * cdaf * cp) / P) + * LT = Required Index * D = Vault Debt * C = Required Collateral - * P = TCAP Token Price + * P = Index Token Price * cdaf = Collateral Decimals adjustment Factor * cp = Collateral Price * r = Min Vault Ratio * p = Liquidation Penalty */ - function requiredLiquidationTCAP(uint256 _vaultId) + function requiredLiquidationIndex(uint256 _vaultId) public view virtual returns (uint256 amount) { Vault memory vault = vaults[_vaultId]; - uint256 tcapPrice = TCAPPrice(); + uint256 iPrice = indexPrice(); uint256 collateralPrice = getOraclePrice(collateralPriceOracle); - uint256 collateralTcap = ( + uint256 collateralIndex = ( vault.Collateral.mul(collateralDecimalsAdjustmentFactor).mul( collateralPrice ) - ).div(tcapPrice); + ).div(iPrice); uint256 reqDividend = ( - ((vault.Debt.mul(ratio)).div(100)).sub(collateralTcap) + ((vault.Debt.mul(ratio)).div(100)).sub(collateralIndex) ).mul(100); uint256 reqDivisor = ratio.sub(liquidationPenalty.add(100)); amount = Math.min(vault.Debt, reqDividend.div(reqDivisor)); @@ -801,7 +801,7 @@ abstract contract IVaultHandler is * @dev RC = R / (cp * cdaf) * R = Liquidation Reward * RC = Liquidation Reward Collateral - * LT = Required Liquidation TCAP + * LT = Required Liquidation Index * p = liquidation penalty * cp = Collateral Price * cdaf = Collateral Decimals adjustment factor @@ -813,11 +813,11 @@ abstract contract IVaultHandler is returns (uint256 rewardCollateral) { Vault memory vault = vaults[_vaultId]; - uint256 req = requiredLiquidationTCAP(_vaultId); - uint256 tcapPrice = TCAPPrice(); + uint256 req = requiredLiquidationIndex(_vaultId); + uint256 iPrice = indexPrice(); uint256 collateralPrice = getOraclePrice(collateralPriceOracle); uint256 reward = (req.mul(liquidationPenalty.add(100))); - uint256 _rewardCollateral = (reward.mul(tcapPrice)) + uint256 _rewardCollateral = (reward.mul(iPrice)) .div(collateralPrice.mul(100)) .div(collateralDecimalsAdjustmentFactor); rewardCollateral = Math.min(vault.Collateral, _rewardCollateral); @@ -833,7 +833,7 @@ abstract contract IVaultHandler is * cdaf = Collateral Decimals Adjustment Factor * cp = Collateral Price * D = Vault Debt - * P = TCAP Token Price + * P = Index Token Price */ function getVaultRatio(uint256 _vaultId) public @@ -851,7 +851,7 @@ abstract contract IVaultHandler is collateralPrice.mul( vault.Collateral.mul(100).mul(collateralDecimalsAdjustmentFactor) ) - ).div(vault.Debt.mul(TCAPPrice())) + ).div(vault.Debt.mul(indexPrice())) ); } } @@ -869,9 +869,14 @@ abstract contract IVaultHandler is * EP = ETH Price * 10000 = the value is 100 multiplied by 100 to support two decimals on the burn fee */ - function getMintFee(uint256 _amount) public view virtual returns (uint256 fee) { + function getMintFee(uint256 _amount) + public + view + virtual + returns (uint256 fee) + { uint256 ethPrice = getOraclePrice(ETHPriceOracle); - fee = (TCAPPrice().mul(_amount).mul(mintFee)).div(10000).div(ethPrice); + fee = (indexPrice().mul(_amount).mul(mintFee)).div(10000).div(ethPrice); } /** @@ -887,13 +892,18 @@ abstract contract IVaultHandler is * EP = ETH Price * 10000 = the value is 100 multiplied by 100 to support two decimals on the burn fee */ - function getBurnFee(uint256 _amount) public view virtual returns (uint256 fee) { + function getBurnFee(uint256 _amount) + public + view + virtual + returns (uint256 fee) + { uint256 ethPrice = getOraclePrice(ETHPriceOracle); - fee = (TCAPPrice().mul(_amount).mul(burnFee)).div(10000).div(ethPrice); + fee = (indexPrice().mul(_amount).mul(burnFee)).div(10000).div(ethPrice); } /** - * @notice Burns an amount of TCAP Tokens + * @notice Burns an amount of Index Tokens * @param _vaultId vault id * @param _amount to burn */ @@ -904,6 +914,6 @@ abstract contract IVaultHandler is "VaultHandler::burn: amount greater than debt" ); vault.Debt = vault.Debt.sub(_amount); - TCAPToken.burn(msg.sender, _amount); + indexToken.burn(msg.sender, _amount); } } diff --git a/contracts/TCAP.sol b/contracts/IndexToken.sol similarity index 87% rename from contracts/TCAP.sol rename to contracts/IndexToken.sol index 8d5269d..2d020dc 100644 --- a/contracts/TCAP.sol +++ b/contracts/IndexToken.sol @@ -8,23 +8,23 @@ import "@openzeppelin/contracts/math/SafeMath.sol"; import "./Orchestrator.sol"; /** - * @title Total Market Cap Token + * @title Syntethic Index Token * @author Cryptex.finance - * @notice ERC20 token on the Ethereum Blockchain that provides total exposure to the cryptocurrency sector. + * @notice ERC20 token on the Ethereum Blockchain that provides total exposure to a index assets pegged with an Oracle. */ -contract TCAP is ERC20, Ownable, IERC165 { +contract IndexToken is ERC20, Ownable, IERC165 { /// @notice Open Zeppelin libraries using SafeMath for uint256; - /// @notice if enabled TCAP can't be minted if the total supply is above or equal the cap value + /// @notice if enabled the token can't be minted if the total supply is above or equal the cap value bool public capEnabled = false; - /// @notice Maximum value the total supply of TCAP + /// @notice Maximum value the total supply of the token uint256 public cap; /** * @notice Address to Vault Handler - * @dev Only vault handlers can mint and burn TCAP + * @dev Only vault handlers can mint and burn the token */ mapping(address => bool) public vaultHandlers; @@ -40,7 +40,7 @@ contract TCAP is ERC20, Ownable, IERC165 { * removeVaultHandler.selector ^ * approve.selector => 0xbd115939 */ - bytes4 private constant _INTERFACE_ID_TCAP = 0xbd115939; + bytes4 private constant _INTERFACE_ID_INDEX = 0xbd115939; /// @dev bytes4(keccak256('supportsInterface(bytes4)')) == 0x01ffc9a7 bytes4 private constant _INTERFACE_ID_ERC165 = 0x01ffc9a7; @@ -86,7 +86,7 @@ contract TCAP is ERC20, Ownable, IERC165 { modifier onlyVault() { require( vaultHandlers[msg.sender], - "TCAP::onlyVault: caller is not a vault" + "IndexToken::onlyVault: caller is not a vault" ); _; } @@ -112,7 +112,7 @@ contract TCAP is ERC20, Ownable, IERC165 { } /** - * @notice Mints TCAP Tokens + * @notice Mints The token * @param _account address of the receiver of tokens * @param _amount uint of tokens to mint * @dev Only vault can call it @@ -122,7 +122,7 @@ contract TCAP is ERC20, Ownable, IERC165 { } /** - * @notice Burns TCAP Tokens + * @notice Burns the token * @param _account address of the account which is burning tokens. * @param _amount uint of tokens to burn * @dev Only vault can call it @@ -132,7 +132,7 @@ contract TCAP is ERC20, Ownable, IERC165 { } /** - * @notice Sets maximum value the total supply of TCAP can have + * @notice Sets maximum value the total supply of the token can have * @param _cap value * @dev When capEnabled is true, mint is not allowed to issue tokens that would increase the total supply above or equal the specified capacity. * @dev Only owner can call it @@ -164,7 +164,7 @@ contract TCAP is ERC20, Ownable, IERC165 { override returns (bool) { - return (_interfaceId == _INTERFACE_ID_TCAP || + return (_interfaceId == _INTERFACE_ID_INDEX || _interfaceId == _INTERFACE_ID_ERC165); } @@ -186,14 +186,14 @@ contract TCAP is ERC20, Ownable, IERC165 { require( _to != address(this), - "TCAP::transfer: can't transfer to TCAP contract" + "IndexToken::transfer: can't transfer to the Index Token contract" ); if (_from == address(0) && capEnabled) { // When minting tokens require( totalSupply().add(_amount) <= cap, - "TCAP::Transfer: TCAP cap exceeded" + "IndexToken::Transfer: cap exceeded" ); } } diff --git a/contracts/MATICVaultHandler.sol b/contracts/MATICVaultHandler.sol index bcf572c..1d434ab 100644 --- a/contracts/MATICVaultHandler.sol +++ b/contracts/MATICVaultHandler.sol @@ -23,12 +23,12 @@ contract MATICVaultHandler is IVaultHandler { * @param _burnFee uint256 * @param _mintFee uint256 * @param _liquidationPenalty uint256 - * @param _tcapOracle address - * @param _tcapAddress address + * @param _indexOracle address + * @param _indexAddress address * @param _collateralAddress address * @param _collateralOracle address * @param _treasury address - * @param _minimumTCAP uint256 + * @param _minimumMint uint256 */ constructor( Orchestrator _orchestrator, @@ -37,13 +37,13 @@ contract MATICVaultHandler is IVaultHandler { uint256 _burnFee, uint256 _mintFee, uint256 _liquidationPenalty, - address _tcapOracle, - TCAP _tcapAddress, + address _indexOracle, + IndexToken _indexAddress, address _collateralAddress, address _collateralOracle, address _maticOracle, address _treasury, - uint256 _minimumTCAP + uint256 _minimumMint ) IVaultHandler( _orchestrator, @@ -52,13 +52,13 @@ contract MATICVaultHandler is IVaultHandler { _burnFee, _mintFee, _liquidationPenalty, - _tcapOracle, - _tcapAddress, + _indexOracle, + _indexAddress, _collateralAddress, _collateralOracle, _maticOracle, _treasury, - _minimumTCAP + _minimumMint ) {} diff --git a/contracts/Orchestrator.sol b/contracts/Orchestrator.sol index ae285ca..72d63f4 100644 --- a/contracts/Orchestrator.sol +++ b/contracts/Orchestrator.sol @@ -4,14 +4,14 @@ pragma solidity 0.7.5; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/introspection/ERC165Checker.sol"; import "./IVaultHandler.sol"; -import "./TCAP.sol"; +import "./IndexToken.sol"; import "./oracles/ChainlinkOracle.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; /** - * @title TCAP Orchestrator + * @title Cryptex Orchestrator * @author Cryptex.finance - * @notice Orchestrator contract in charge of managing the settings of the vaults, rewards and TCAP token. It acts as the owner of these contracts. + * @notice Orchestrator contract in charge of managing the settings of the vaults, rewards and Index token. It acts as the owner of these contracts. */ contract Orchestrator is Ownable { /// @dev Enum which saves the available functions to emergency call. @@ -27,7 +27,7 @@ contract Orchestrator is Ownable { /** @dev Interface constants*/ bytes4 private constant _INTERFACE_ID_IVAULT = 0x9e75ab0c; - bytes4 private constant _INTERFACE_ID_TCAP = 0xbd115939; + bytes4 private constant _INTERFACE_ID_INDEX = 0xbd115939; bytes4 private constant _INTERFACE_ID_CHAINLINK_ORACLE = 0x85be402b; /// @dev tracks which vault was emergency called @@ -78,13 +78,13 @@ contract Orchestrator is Ownable { } /** - * @notice Throws if TCAP Token is not valid - * @param _tcap address + * @notice Throws if Index Token is not valid + * @param _indexToken address */ - modifier validTCAP(TCAP _tcap) { + modifier validIndex(IndexToken _indexToken) { require( - ERC165Checker.supportsInterface(address(_tcap), _INTERFACE_ID_TCAP), - "Orchestrator::validTCAP: not a valid TCAP ERC20" + ERC165Checker.supportsInterface(address(_indexToken), _INTERFACE_ID_INDEX), + "Orchestrator::validIndex: not a valid Index Token" ); _; } @@ -264,67 +264,67 @@ contract Orchestrator is Ownable { } /** - * @notice Enables or disables the TCAP Cap - * @param _tcap address + * @notice Enables or disables the Index Token Cap + * @param _indexToken address * @param _enable bool * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid */ - function enableTCAPCap(TCAP _tcap, bool _enable) + function enableIndexCap(IndexToken _indexToken, bool _enable) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) { - _tcap.enableCap(_enable); + _indexToken.enableCap(_enable); } /** - * @notice Sets the TCAP maximum minting value - * @param _tcap address + * @notice Sets the IndexToken maximum minting value + * @param _indexToken address * @param _cap uint value * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid */ - function setTCAPCap(TCAP _tcap, uint256 _cap) + function setIndexCap(IndexToken _indexToken, uint256 _cap) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) { - _tcap.setCap(_cap); + _indexToken.setCap(_cap); } /** - * @notice Adds Vault to TCAP ERC20 - * @param _tcap address + * @notice Adds Vault to Index Token + * @param _indexToken address * @param _vault address * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid * @dev Validates if _vault is valid */ - function addTCAPVault(TCAP _tcap, IVaultHandler _vault) + function addIndexVault(IndexToken _indexToken, IVaultHandler _vault) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) validVault(_vault) { - _tcap.addVaultHandler(address(_vault)); + _indexToken.addVaultHandler(address(_vault)); } /** - * @notice Removes Vault to TCAP ERC20 - * @param _tcap address + * @notice Removes Vault from Index Token + * @param _indexToken address * @param _vault address * @dev Only owner can call it - * @dev Validates if _tcap is valid + * @dev Validates if _indexToken is valid * @dev Validates if _vault is valid */ - function removeTCAPVault(TCAP _tcap, IVaultHandler _vault) + function removeIndexVault(IndexToken _indexToken, IVaultHandler _vault) external onlyOwner - validTCAP(_tcap) + validIndex(_indexToken) validVault(_vault) { - _tcap.removeVaultHandler(address(_vault)); + _indexToken.removeVaultHandler(address(_vault)); } /** diff --git a/test/HardETHVaultHandler.t.sol b/test/HardETHVaultHandler.t.sol index b0995a1..c2aa0bc 100644 --- a/test/HardETHVaultHandler.t.sol +++ b/test/HardETHVaultHandler.t.sol @@ -12,18 +12,18 @@ import "../contracts/mocks/WETH.sol"; contract ETHVaultHandlerTest is Test { // events - event NewMinimumTCAP(address indexed _owner, uint256 _minimumTCAP); + event NewMinimumMint(address indexed _owner, uint256 _minimumMint); event NewMintFee(address indexed _owner, uint256 _mintFee); event NewBurnFee(address indexed _owner, uint256 _burnFee); // Setup ETHVaultHandler ethVault; Orchestrator orchestrator = new Orchestrator(address(this)); - TCAP tcap = - new TCAP("Total Crypto Market Cap Token", "TCAP", 0, (orchestrator)); + IndexToken tcap = + new IndexToken("Total Crypto Market Cap Token", "TCAP", 0, (orchestrator)); AggregatorInterfaceTCAP tcapAggregator = new AggregatorInterfaceTCAP(); AggregatorInterface ethAggregator = new AggregatorInterface(); - ChainlinkOracle tcapOracle = + ChainlinkOracle indexOracle = new ChainlinkOracle(address(tcapAggregator), address(this)); ChainlinkOracle ethOracle = new ChainlinkOracle(address(ethAggregator), address(this)); @@ -47,7 +47,7 @@ contract ETHVaultHandlerTest is Test { burnFee, mintFee, liquidationPenalty, - address(tcapOracle), + address(indexOracle), tcap, address(weth), address(ethOracle), @@ -56,7 +56,7 @@ contract ETHVaultHandlerTest is Test { 1 ether ); - orchestrator.addTCAPVault(tcap, ethVault); + orchestrator.addIndexVault(tcap, ethVault); } function testConstructor_ShouldSetParams_WhenInitialized() public { @@ -66,13 +66,13 @@ contract ETHVaultHandlerTest is Test { assertEq(burnFee, ethVault.burnFee()); assertEq(burnFee, ethVault.mintFee()); assertEq(liquidationPenalty, ethVault.liquidationPenalty()); - assertEq(address(tcapOracle), address(ethVault.tcapOracle())); - assertEq(address(tcap), address(ethVault.TCAPToken())); + assertEq(address(indexOracle), address(ethVault.indexOracle())); + assertEq(address(tcap), address(ethVault.indexToken())); assertEq(address(weth), address(ethVault.collateralContract())); assertEq(address(ethOracle), address(ethVault.collateralPriceOracle())); assertEq(address(ethOracle), address(ethVault.ETHPriceOracle())); assertEq(treasury, ethVault.treasury()); - assertEq(1 ether, ethVault.minimumTCAP()); + assertEq(1 ether, ethVault.minimumMint()); } function testConstructor_ShouldRevert_WhenBurnFeeIsHigh(uint256 _burnFee) @@ -89,7 +89,7 @@ contract ETHVaultHandlerTest is Test { _burnFee, mintFee, liquidationPenalty, - address(tcapOracle), + address(indexOracle), tcap, address(weth), address(ethOracle), @@ -116,7 +116,7 @@ contract ETHVaultHandlerTest is Test { burnFee, _mintFee, liquidationPenalty, - address(tcapOracle), + address(indexOracle), tcap, address(weth), address(ethOracle), @@ -147,7 +147,7 @@ contract ETHVaultHandlerTest is Test { burnFee, mintFee, _liquidationPenalty, - address(tcapOracle), + address(indexOracle), tcap, address(weth), address(ethOracle), @@ -188,19 +188,19 @@ contract ETHVaultHandlerTest is Test { orchestrator.setRatio(ethVault, _ratio); } - function testSetMinimumTCAP_ShouldUpdateValue(uint256 _minimumTCAP) public { + function testSetMinimumMint_ShouldUpdateValue(uint256 _minimumMint) public { vm.expectRevert("Ownable: caller is not the owner"); - ethVault.setMinimumTCAP(_minimumTCAP); + ethVault.setMinimumMint(_minimumMint); vm.expectEmit(true, true, true, true); - emit NewMinimumTCAP(address(orchestrator), _minimumTCAP); + emit NewMinimumMint(address(orchestrator), _minimumMint); orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", - abi.encode(_minimumTCAP) + "setMinimumMint(uint256)", + abi.encode(_minimumMint) ); - assertEq(ethVault.minimumTCAP(), _minimumTCAP); + assertEq(ethVault.minimumMint(), _minimumMint); } function testMint_ShouldCreateTCAP_WhenFeeIsPaid() public { @@ -259,7 +259,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(20 ether) ); uint256 fee = ethVault.getMintFee(20 ether); @@ -284,7 +284,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(30 ether) ); @@ -310,7 +310,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); vm.startPrank(user); @@ -343,7 +343,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); uint256 mfee = ethVault.getMintFee(_tcapAmount); @@ -377,7 +377,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); uint256 mfee = ethVault.getMintFee(_tcapAmount); @@ -409,7 +409,7 @@ contract ETHVaultHandlerTest is Test { return; } - uint256 requiredLiquidation = ethVault.requiredLiquidationTCAP(1); + uint256 requiredLiquidation = ethVault.requiredLiquidationIndex(1); reward = ethVault.liquidationReward(1); uint256 fee = ethVault.getBurnFee(_tcapAmount); vm.deal(user2, fee); @@ -434,7 +434,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); uint256 mfee = ethVault.getMintFee(_tcapAmount); @@ -461,7 +461,7 @@ contract ETHVaultHandlerTest is Test { return; } - uint256 requiredLiquidation = ethVault.requiredLiquidationTCAP(1); + uint256 requiredLiquidation = ethVault.requiredLiquidationIndex(1); reward = ethVault.liquidationReward(1); uint256 fee = ethVault.getBurnFee(_tcapAmount); vm.deal(user2, fee); @@ -573,7 +573,7 @@ contract ETHVaultHandlerTest is Test { return; } orchestrator.setMintFee(ethVault, _mintFee); - uint256 calculatedFee = (ethVault.TCAPPrice() * (_amount) * (_mintFee)) / + uint256 calculatedFee = (ethVault.indexPrice() * (_amount) * (_mintFee)) / (10000) / (ethVault.getOraclePrice(ethOracle)); @@ -593,7 +593,7 @@ contract ETHVaultHandlerTest is Test { return; } orchestrator.setBurnFee(ethVault, _burnFee); - uint256 calculatedFee = (ethVault.TCAPPrice() * (_amount) * (_burnFee)) / + uint256 calculatedFee = (ethVault.indexPrice() * (_amount) * (_burnFee)) / (10000) / (ethVault.getOraclePrice(ethOracle)); @@ -617,7 +617,7 @@ contract ETHVaultHandlerTest is Test { orchestrator.setBurnFee(ethVault, _burnFeePercentage * 100); // By dividing by 100 in the formula below, we can ensure that fee calculated // is the same as the previous version - uint256 calculatedFee = (ethVault.TCAPPrice() * + uint256 calculatedFee = (ethVault.indexPrice() * (_amount) * (_burnFeePercentage)) / (100) / diff --git a/test/LinkAave.t.sol b/test/LinkAave.t.sol index af9d9ae..ce2bc52 100644 --- a/test/LinkAave.t.sol +++ b/test/LinkAave.t.sol @@ -4,7 +4,7 @@ pragma solidity 0.7.5; import "ds-test/test.sol"; import "../contracts/ERC20VaultHandler.sol"; import "../contracts/mocks/AAVE.sol"; -import "../contracts/TCAP.sol"; +import "../contracts/IndexToken.sol"; interface Vm { // Set block.timestamp (newTimestamp) diff --git a/test/VaultsPausing.t.sol b/test/VaultsPausing.t.sol index 7a4cd44..0469e60 100644 --- a/test/VaultsPausing.t.sol +++ b/test/VaultsPausing.t.sol @@ -21,8 +21,8 @@ contract VaultDisablingTest is Test { // Setup ETHVaultHandler ethVault; Orchestrator orchestrator = new Orchestrator(address(this)); - TCAP tcap = - new TCAP("Total Crypto Market Cap Token", "TCAP", 0, (orchestrator)); + IndexToken tcap = + new IndexToken("Total Crypto Market Cap Token", "TCAP", 0, (orchestrator)); AggregatorInterfaceTCAP tcapAggregator = new AggregatorInterfaceTCAP(); AggregatorInterface ethAggregator = new AggregatorInterface(); ChainlinkOracle tcapOracle = @@ -58,7 +58,7 @@ contract VaultDisablingTest is Test { 1 ether ); - orchestrator.addTCAPVault(tcap, ethVault); + orchestrator.addIndexVault(tcap, ethVault); } function testToggleFunction_ShouldRevert_WhenNotOwner() public { diff --git a/test/arbitrum/GovernanceBridgeIntegration.t.sol b/test/arbitrum/GovernanceBridgeIntegration.t.sol index db8143c..f75a474 100644 --- a/test/arbitrum/GovernanceBridgeIntegration.t.sol +++ b/test/arbitrum/GovernanceBridgeIntegration.t.sol @@ -20,7 +20,7 @@ import "../../contracts/oracles/ChainlinkOracle.sol"; import "../../contracts/mocks/AggregatorInterfaceTCAP.sol"; import "../../contracts/mocks/AggregatorInterface.sol"; import "../../contracts/mocks/WETH.sol"; -import "../../contracts/TCAP.sol"; +import "../../contracts/IndexToken.sol"; import "../../contracts/mocks/Greeter.sol"; import "./mocks/MockInbox.sol"; @@ -53,7 +53,7 @@ contract GovernanceBridgeIntegration is Test { ETHVaultHandler ethVault; Orchestrator orchestrator; - TCAP tcap; + IndexToken tcap; AggregatorInterfaceTCAP tcapAggregator; AggregatorInterface ethAggregator; ChainlinkOracle tcapOracle; @@ -88,7 +88,7 @@ contract GovernanceBridgeIntegration is Test { orchestrator = new Orchestrator(user); orchestrator.transferOwnership(address(proxy)); - tcap = new TCAP("Total Crypto Market Cap Token", "TCAP", 0, orchestrator); + tcap = new IndexToken("Total Crypto Market Cap Token", "TCAP", 0, orchestrator); tcapAggregator = new AggregatorInterfaceTCAP(); ethAggregator = new AggregatorInterface(); tcapOracle = new ChainlinkOracle( @@ -168,7 +168,7 @@ contract GovernanceBridgeIntegration is Test { function testAddVault() public { bytes memory _callData = abi.encodeWithSelector( - orchestrator.addTCAPVault.selector, + orchestrator.addIndexVault.selector, address(tcap), address(ethVault) ); diff --git a/test/arbitrum/JPEGZBridgeFork.t.sol b/test/arbitrum/JPEGZBridgeFork.t.sol index 6522fce..6907468 100644 --- a/test/arbitrum/JPEGZBridgeFork.t.sol +++ b/test/arbitrum/JPEGZBridgeFork.t.sol @@ -5,7 +5,7 @@ pragma abicoder v2; import "forge-std/Test.sol"; import "../../contracts/ETHVaultHandler.sol"; import "../../contracts/ERC20VaultHandler.sol"; -import "../../contracts/TCAP.sol"; +import "../../contracts/IndexToken.sol"; import "../../contracts/governance/GovernorBeta.sol"; import "../../contracts/governance/Timelock.sol"; import "../../contracts/governance/Ctx.sol"; @@ -42,7 +42,7 @@ contract JPEGZBridgeFork is Test { ArbitrumOrchestrator(0x60f5C89C26cd424DF5E8513FDe150D2CA8F0eB9f); ArbitrumTreasury treasury = ArbitrumTreasury(0x9474B771Fb46E538cfED114Ca816A3e25Bb346CF); - TCAP jpegz = TCAP(0xD5536c80191c624F6bFD5590A45b9E93B16DEA97); + IndexToken jpegz = IndexToken(0xD5536c80191c624F6bFD5590A45b9E93B16DEA97); GovernorBeta governorBeta = GovernorBeta(0x874C5D592AfC6803c3DD60d6442357879F196d5b); Timelock timeLock = Timelock(0xa54074b2cc0e96a43048d4a68472F7F046aC0DA8); diff --git a/test/arbitrum/JPEGzMainnetOracleFork.t.sol b/test/arbitrum/JPEGzMainnetOracleFork.t.sol index c8b5223..f1cd4bd 100644 --- a/test/arbitrum/JPEGzMainnetOracleFork.t.sol +++ b/test/arbitrum/JPEGzMainnetOracleFork.t.sol @@ -5,20 +5,20 @@ pragma abicoder v2; import "forge-std/Test.sol"; import "../../contracts/ETHVaultHandler.sol"; import "../../contracts/Orchestrator.sol"; -import "../../contracts/TCAP.sol"; +import "../../contracts/IndexToken.sol"; import "../../contracts/oracles/ChainlinkOracle.sol"; import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol"; contract JPEGzMainnetFork is Test { // events - event NewMinimumTCAP(address indexed _owner, uint256 _minimumTCAP); + event NewMinimumMint(address indexed _owner, uint256 _minimumMint); event NewMintFee(address indexed _owner, uint256 _mintFee); event NewBurnFee(address indexed _owner, uint256 _burnFee); // Setup ETHVaultHandler ethVault; Orchestrator orchestrator = new Orchestrator(address(this)); - TCAP jpegz = new TCAP("JPEGz Token", "JPEGz", 0, (orchestrator)); + IndexToken jpegz = new IndexToken("JPEGz Token", "JPEGz", 0, (orchestrator)); AggregatorV3Interface jpegzAggregator = AggregatorV3Interface(0x8D0e319eBAA8DF32e088e469062F85abF2eBe599); AggregatorV3Interface ethAggregator = @@ -56,7 +56,7 @@ contract JPEGzMainnetFork is Test { 0 ether ); - orchestrator.addTCAPVault(jpegz, ethVault); + orchestrator.addIndexVault(jpegz, ethVault); } function testConstructor_ShouldSetParams_WhenInitialized() public { @@ -66,13 +66,13 @@ contract JPEGzMainnetFork is Test { assertEq(burnFee, ethVault.burnFee()); assertEq(burnFee, ethVault.mintFee()); assertEq(liquidationPenalty, ethVault.liquidationPenalty()); - assertEq(address(jpegzOracle), address(ethVault.tcapOracle())); - assertEq(address(jpegz), address(ethVault.TCAPToken())); + assertEq(address(jpegzOracle), address(ethVault.indexOracle())); + assertEq(address(jpegz), address(ethVault.indexToken())); assertEq(address(weth), address(ethVault.collateralContract())); assertEq(address(ethOracle), address(ethVault.collateralPriceOracle())); assertEq(address(ethOracle), address(ethVault.ETHPriceOracle())); assertEq(treasury, ethVault.treasury()); - assertEq(0 ether, ethVault.minimumTCAP()); + assertEq(0 ether, ethVault.minimumMint()); } function testConstructor_ShouldRevert_WhenBurnFeeIsHigh(uint256 _burnFee) @@ -172,19 +172,19 @@ contract JPEGzMainnetFork is Test { orchestrator.setRatio(ethVault, _ratio); } - function testSetMinimumJGPEZ_ShouldUpdateValue(uint256 _minimumTCAP) public { + function testSetMinimumJGPEZ_ShouldUpdateValue(uint256 _minimumMint) public { vm.expectRevert("Ownable: caller is not the owner"); - ethVault.setMinimumTCAP(_minimumTCAP); + ethVault.setMinimumMint(_minimumMint); vm.expectEmit(true, true, true, true); - emit NewMinimumTCAP(address(orchestrator), _minimumTCAP); + emit NewMinimumMint(address(orchestrator), _minimumMint); orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", - abi.encode(_minimumTCAP) + "setMinimumMint(uint256)", + abi.encode(_minimumMint) ); - assertEq(ethVault.minimumTCAP(), _minimumTCAP); + assertEq(ethVault.minimumMint(), _minimumMint); } function testMint_ShouldCreateJPEGZ_WhenFeeIsPaid() public { @@ -248,7 +248,7 @@ contract JPEGzMainnetFork is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(20 ether) ); uint256 fee = ethVault.getMintFee(20 ether); @@ -273,7 +273,7 @@ contract JPEGzMainnetFork is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(30 ether) ); @@ -297,7 +297,7 @@ contract JPEGzMainnetFork is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); vm.startPrank(user); @@ -336,7 +336,7 @@ contract JPEGzMainnetFork is Test { orchestrator.executeTransaction( address(ethVault), 0, - "setMinimumTCAP(uint256)", + "setMinimumMint(uint256)", abi.encode(1 ether) ); uint256 mfee = ethVault.getMintFee(_tcapAmount); @@ -441,7 +441,7 @@ contract JPEGzMainnetFork is Test { //setUp vm.assume(_mintFee < 1000); orchestrator.setMintFee(ethVault, _mintFee); - uint256 calculatedFee = (ethVault.TCAPPrice() * (_amount) * (_mintFee)) / + uint256 calculatedFee = (ethVault.indexPrice() * (_amount) * (_mintFee)) / (10000) / (ethVault.getOraclePrice(ethOracle)); @@ -459,7 +459,7 @@ contract JPEGzMainnetFork is Test { //setUp vm.assume(_burnFee < 1000); orchestrator.setBurnFee(ethVault, _burnFee); - uint256 calculatedFee = (ethVault.TCAPPrice() * (_amount) * (_burnFee)) / + uint256 calculatedFee = (ethVault.indexPrice() * (_amount) * (_burnFee)) / (10000) / (ethVault.getOraclePrice(ethOracle)); From 95b64b59b307093b877096741a8537f4cf4f1314 Mon Sep 17 00:00:00 2001 From: Crisgarner <@crisgarner> Date: Thu, 16 Feb 2023 17:18:54 -0600 Subject: [PATCH 3/3] fixed tests --- test/ERCNon18DecimalsVaultHandler.test.ts | 18 +++++----- test/ERCVaultHandler.test.js | 34 +++++++++---------- test/ETHVaultHandler.test.js | 24 +++++++------- test/{TCAP.test.js => IndexToken.test.js} | 8 ++--- test/MATICVaultHandler.test.js | 24 +++++++------- test/Orchestrator.test.js | 40 +++++++++++------------ test/polygon/IntegrationTest.ts | 10 +++--- 7 files changed, 79 insertions(+), 79 deletions(-) rename test/{TCAP.test.js => IndexToken.test.js} (93%) diff --git a/test/ERCNon18DecimalsVaultHandler.test.ts b/test/ERCNon18DecimalsVaultHandler.test.ts index f63649c..e26d0e8 100644 --- a/test/ERCNon18DecimalsVaultHandler.test.ts +++ b/test/ERCNon18DecimalsVaultHandler.test.ts @@ -57,7 +57,7 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { wallet.address, ]); treasury = await deployContract("BaseTreasury", wallet, [wallet.address]); - tCAP = await deployContract("TCAP", wallet, [ + tCAP = await deployContract("IndexToken", wallet, [ "TCAP Token", "TCAP", 0, @@ -140,8 +140,8 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { 0, ]); // add Vaults - await orchestrator.addTCAPVault(tCAP.address, wBTCVaultHandler.address); - await orchestrator.addTCAPVault(tCAP.address, DAIVaultHandler.address); + await orchestrator.addIndexVault(tCAP.address, wBTCVaultHandler.address); + await orchestrator.addIndexVault(tCAP.address, DAIVaultHandler.address); // Mint tokens // 10000 * 10 ** 8 @@ -455,7 +455,7 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { ); }); - it("...should have same requiredLiquidationTCAP when vault ratio goes down", async () => { + it("...should have same requiredLiquidationIndex when vault ratio goes down", async () => { const USDAmountCollateralToDeposit = BigNumber.from(1000); // equivalent in decimals places supported by WBTC const btcCollateralAmountDeposit = USDAmountCollateralToDeposit.mul( @@ -521,9 +521,9 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { expect(newBTCVaultRatio.toNumber()).to.be.eq(newDAIVaultRatio.toNumber()); const BTCTcapLiquidationAmount = - await wBTCVaultHandler.requiredLiquidationTCAP(1); + await wBTCVaultHandler.requiredLiquidationIndex(1); const DAITcapLiquidationAmount = - await DAIVaultHandler.requiredLiquidationTCAP(1); + await DAIVaultHandler.requiredLiquidationIndex(1); expect(BTCTcapLiquidationAmount.toHexString() / 10 ** 18).to.be.closeTo( DAITcapLiquidationAmount.toHexString() / 10 ** 18, @@ -678,9 +678,9 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { expect(newBTCVaultRatio.toNumber()).to.be.eq(newDAIVaultRatio.toNumber()); const BTCTcapLiquidationAmount = - await wBTCVaultHandler.requiredLiquidationTCAP(1); + await wBTCVaultHandler.requiredLiquidationIndex(1); const DAITcapLiquidationAmount = - await DAIVaultHandler.requiredLiquidationTCAP(1); + await DAIVaultHandler.requiredLiquidationIndex(1); expect(BTCTcapLiquidationAmount.toHexString() / 10 ** 18).to.be.closeTo( DAITcapLiquidationAmount.toHexString() / 10 ** 18, @@ -739,7 +739,7 @@ describe("ERC20 Vaults With Non 18 Decimal", async function () { expect(newBTCVaultRatio).to.be.below(100); const BTCTcapLiquidationAmount = - await wBTCVaultHandler.requiredLiquidationTCAP(1); + await wBTCVaultHandler.requiredLiquidationIndex(1); const BTCBurnFee = await wBTCVaultHandler.getBurnFee( BTCTcapLiquidationAmount diff --git a/test/ERCVaultHandler.test.js b/test/ERCVaultHandler.test.js index 157d1db..4961715 100644 --- a/test/ERCVaultHandler.test.js +++ b/test/ERCVaultHandler.test.js @@ -44,7 +44,7 @@ describe("ERC20 Vault", async function () { const timelock = await ethers.getContractFactory("Timelock"); const timelockInstance = await timelock.deploy(orchestratorInstance.address, threeDays); - const TCAP = await ethers.getContractFactory("TCAP"); + const TCAP = await ethers.getContractFactory("IndexToken"); tcapInstance = await TCAP.deploy( "Total Market Cap Token", "TCAP", @@ -88,7 +88,7 @@ describe("ERC20 Vault", async function () { await ercTokenHandler.deployed(); expect(ercTokenHandler.address).properAddress; - await orchestratorInstance.addTCAPVault(tcapInstance.address, ercTokenHandler.address); + await orchestratorInstance.addIndexVault(tcapInstance.address, ercTokenHandler.address); }); it("...should allow the owner to set the treasury address", async () => { @@ -113,7 +113,7 @@ describe("ERC20 Vault", async function () { }); it("...should return the token price", async () => { - let tcapPrice = await ercTokenHandler.TCAPPrice(); + let tcapPrice = await ercTokenHandler.indexPrice(); let totalMarketCap = await tcapOracleInstance.getLatestAnswer(); let result = totalMarketCap.mul(10000000000).div(divisor); expect(tcapPrice).to.eq(result); @@ -238,7 +238,7 @@ describe("ERC20 Vault", async function () { let amount = ethersProvider.utils.parseEther("1"); const reqAmount = await ercTokenHandler.requiredCollateral(amount); const ethPrice = await priceOracleInstance.getLatestAnswer(); - const tcapPrice = await ercTokenHandler.TCAPPrice(); + const tcapPrice = await ercTokenHandler.indexPrice(); const ratio = await ercTokenHandler.ratio(); let result = tcapPrice.mul(amount).mul(ratio).div(100).div(ethPrice.mul(10000000000)); expect(reqAmount).to.eq(result); @@ -257,14 +257,14 @@ describe("ERC20 Vault", async function () { let enableHash = ethers.utils.solidityKeccak256(["bool"], [enableCap]); let tcapCap = 1; - await orchestratorInstance.enableTCAPCap(tcapInstance.address, enableCap); - await orchestratorInstance.setTCAPCap(tcapInstance.address, tcapCap); + await orchestratorInstance.enableIndexCap(tcapInstance.address, enableCap); + await orchestratorInstance.setIndexCap(tcapInstance.address, tcapCap); await expect(ercTokenHandler.connect(addr1).mint(reqAmount, { value: mintFee })).to.be.revertedWith( - "TCAP::Transfer: TCAP cap exceeded" + "IndexToken::Transfer: cap exceeded" ); // Remove Cap enableCap = false; - await orchestratorInstance.enableTCAPCap(tcapInstance.address, enableCap); + await orchestratorInstance.enableIndexCap(tcapInstance.address, enableCap); }); it("...should allow user to mint tokens", async () => { @@ -315,7 +315,7 @@ describe("ERC20 Vault", async function () { let tcapBalance = await tcapInstance.balanceOf(accounts[1]); await expect( tcapInstance.connect(addr1).transfer(tcapInstance.address, tcapBalance) - ).to.be.revertedWith("TCAP::transfer: can't transfer to TCAP contract"); + ).to.be.revertedWith("IndexToken::transfer: can't transfer to the Index Token contract"); }); it("...should allow users to get collateral ratio", async () => { @@ -335,7 +335,7 @@ describe("ERC20 Vault", async function () { it("...should calculate the burn fee", async () => { let amount = ethersProvider.utils.parseEther("10"); let divisor = 10000; - let tcapPrice = await ercTokenHandler.TCAPPrice(); + let tcapPrice = await ercTokenHandler.indexPrice(); let ethPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); let result = tcapPrice.mul(amount).div(divisor).div(ethPrice); let fee = await ercTokenHandler.getBurnFee(amount); @@ -429,11 +429,11 @@ describe("ERC20 Vault", async function () { }); it("...should get the required collateral for liquidation", async () => { - let reqLiquidation = await ercTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ercTokenHandler.requiredLiquidationIndex(2); let liquidationPenalty = await ercTokenHandler.liquidationPenalty(); let ratio = await ercTokenHandler.ratio(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await ercTokenHandler.TCAPPrice(); + let tcapPrice = await ercTokenHandler.indexPrice(); let vault = await ercTokenHandler.getVault(2); let collateralTcap = vault[1].mul(collateralPrice).div(tcapPrice); let reqDividend = vault[3].mul(ratio).div(100).sub(collateralTcap).mul(100); @@ -443,11 +443,11 @@ describe("ERC20 Vault", async function () { }); it("...should get the liquidation reward", async () => { - let reqLiquidation = await ercTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ercTokenHandler.requiredLiquidationIndex(2); let liquidationReward = await ercTokenHandler.liquidationReward(2); let liquidationPenalty = await ercTokenHandler.liquidationPenalty(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await ercTokenHandler.TCAPPrice(); + let tcapPrice = await ercTokenHandler.indexPrice(); let result = reqLiquidation.mul(liquidationPenalty.add(100)).div(100); result = result.mul(tcapPrice).div(collateralPrice); @@ -457,8 +457,8 @@ describe("ERC20 Vault", async function () { it("...should allow liquidators to return profits", async () => { const divisor = ethersProvider.utils.parseEther("1"); const liquidationReward = await ercTokenHandler.liquidationReward(2); - const reqLiquidation = await ercTokenHandler.requiredLiquidationTCAP(2); - const tcapPrice = await ercTokenHandler.TCAPPrice(); + const reqLiquidation = await ercTokenHandler.requiredLiquidationIndex(2); + const tcapPrice = await ercTokenHandler.indexPrice(); const collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); const rewardUSD = liquidationReward.mul(collateralPrice).div(divisor); const collateralUSD = reqLiquidation.mul(tcapPrice).div(divisor); @@ -485,7 +485,7 @@ describe("ERC20 Vault", async function () { await ercTokenHandler.connect(addr3).mint(liquidatorAmount, { value: mintFee }); let liquidationReward = await ercTokenHandler.liquidationReward(2); - let reqLiquidation = await ercTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ercTokenHandler.requiredLiquidationIndex(2); let aboveReqLiquidation = reqLiquidation.add(liquidatorAmount); let tcapBalance = await tcapInstance.balanceOf(accounts[3]); diff --git a/test/ETHVaultHandler.test.js b/test/ETHVaultHandler.test.js index d43239e..14967d3 100644 --- a/test/ETHVaultHandler.test.js +++ b/test/ETHVaultHandler.test.js @@ -45,7 +45,7 @@ describe("ETH Vault", async function () { const timelock = await ethers.getContractFactory("Timelock"); const timelockInstance = await timelock.deploy(orchestratorInstance.address, threeDays); - const TCAP = await ethers.getContractFactory("TCAP"); + const TCAP = await ethers.getContractFactory("IndexToken"); tcapInstance = await TCAP.deploy( "Total Market Cap Token", "TCAP", @@ -86,7 +86,7 @@ describe("ETH Vault", async function () { ); await ethTokenHandler.deployed(); expect(ethTokenHandler.address).properAddress; - await orchestratorInstance.addTCAPVault(tcapInstance.address, ethTokenHandler.address); + await orchestratorInstance.addIndexVault(tcapInstance.address, ethTokenHandler.address); }); it("...should allow the owner to set the treasury address", async () => { @@ -111,7 +111,7 @@ describe("ETH Vault", async function () { }); it("...should return the token price", async () => { - let tcapPrice = await ethTokenHandler.TCAPPrice(); + let tcapPrice = await ethTokenHandler.indexPrice(); let totalMarketCap = (await tcapOracleInstance.getLatestAnswer()).mul(10000000000); let result = totalMarketCap.div(divisor); expect(tcapPrice).to.eq(result); @@ -312,7 +312,7 @@ describe("ETH Vault", async function () { let amount = ethers.utils.parseEther("1"); const reqAmount = await ethTokenHandler.requiredCollateral(amount); const ethPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - const tcapPrice = await ethTokenHandler.TCAPPrice(); + const tcapPrice = await ethTokenHandler.indexPrice(); const ratio = await ethTokenHandler.ratio(); let result = tcapPrice.mul(amount).mul(ratio).div(100).div(ethPrice); expect(reqAmount).to.eq(result); @@ -369,7 +369,7 @@ describe("ETH Vault", async function () { it("...should calculate the burn fee", async () => { let amount = ethers.utils.parseEther("10"); let divisor = 10000; - let tcapPrice = await ethTokenHandler.TCAPPrice(); + let tcapPrice = await ethTokenHandler.indexPrice(); let ethPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); let result = tcapPrice.mul(amount).div(divisor).div(ethPrice); let fee = await ethTokenHandler.getBurnFee(amount); @@ -451,11 +451,11 @@ describe("ETH Vault", async function () { }); it("...should get the required collateral for liquidation", async () => { - let reqLiquidation = await ethTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ethTokenHandler.requiredLiquidationIndex(2); let liquidationPenalty = await ethTokenHandler.liquidationPenalty(); let ratio = await ethTokenHandler.ratio(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await ethTokenHandler.TCAPPrice(); + let tcapPrice = await ethTokenHandler.indexPrice(); let vault = await ethTokenHandler.getVault(2); let collateralTcap = vault[1].mul(collateralPrice).div(tcapPrice); let reqDividend = vault[3].mul(ratio).div(100).sub(collateralTcap).mul(100); @@ -465,11 +465,11 @@ describe("ETH Vault", async function () { }); it("...should get the liquidation reward", async () => { - let reqLiquidation = await ethTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ethTokenHandler.requiredLiquidationIndex(2); let liquidationReward = await ethTokenHandler.liquidationReward(2); let liquidationPenalty = await ethTokenHandler.liquidationPenalty(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await ethTokenHandler.TCAPPrice(); + let tcapPrice = await ethTokenHandler.indexPrice(); let result = reqLiquidation.mul(liquidationPenalty.add(100)).div(100); result = result.mul(tcapPrice).div(collateralPrice); @@ -479,8 +479,8 @@ describe("ETH Vault", async function () { it("...should allow liquidators to return profits", async () => { const divisor = ethers.utils.parseEther("1"); const liquidationReward = await ethTokenHandler.liquidationReward(2); - const reqLiquidation = await ethTokenHandler.requiredLiquidationTCAP(2); - const tcapPrice = await ethTokenHandler.TCAPPrice(); + const reqLiquidation = await ethTokenHandler.requiredLiquidationIndex(2); + const tcapPrice = await ethTokenHandler.indexPrice(); const collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); const rewardUSD = liquidationReward.mul(collateralPrice).div(divisor); const collateralUSD = reqLiquidation.mul(tcapPrice).div(divisor); @@ -507,7 +507,7 @@ describe("ETH Vault", async function () { await ethTokenHandler.connect(addr3).mint(liquidatorAmount, { value: mintFee }); let liquidationReward = await ethTokenHandler.liquidationReward(2); - let reqLiquidation = await ethTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await ethTokenHandler.requiredLiquidationIndex(2); let tcapBalance = await tcapInstance.balanceOf(accounts[3]); let collateralBalance = await wethTokenInstance.balanceOf(accounts[3]); let vault = await ethTokenHandler.getVault(2); diff --git a/test/TCAP.test.js b/test/IndexToken.test.js similarity index 93% rename from test/TCAP.test.js rename to test/IndexToken.test.js index 944c8c3..a3c2483 100644 --- a/test/TCAP.test.js +++ b/test/IndexToken.test.js @@ -1,7 +1,7 @@ var expect = require("chai").expect; var ethersProvider = require("ethers"); -describe("TCAP Token", async function () { +describe("Index Token", async function () { let tcapInstance; let orchestratorInstance; let [owner, addr1, handler, handler2, guardian] = []; @@ -30,7 +30,7 @@ describe("TCAP Token", async function () { expect(orchestratorInstance.address).properAddress; let cap = ethers.utils.parseEther("100"); - const TCAP = await ethers.getContractFactory("TCAP"); + const TCAP = await ethers.getContractFactory("IndexToken"); tcapInstance = await TCAP.deploy( "Total Market Cap Token", "TCAP", @@ -71,14 +71,14 @@ describe("TCAP Token", async function () { it("...shouldn't allow users to mint", async () => { const amount = ethersProvider.utils.parseEther("1000000"); await expect(tcapInstance.mint(accounts[0], amount)).to.be.revertedWith( - "TCAP::onlyVault: caller is not a vault" + "IndexToken::onlyVault: caller is not a vault" ); }); it("...shouldn't allow users to burn", async () => { const amount = ethersProvider.utils.parseEther("1000000"); await expect(tcapInstance.burn(accounts[1], amount)).to.be.revertedWith( - "TCAP::onlyVault: caller is not a vault" + "IndexToken::onlyVault: caller is not a vault" ); }); }); diff --git a/test/MATICVaultHandler.test.js b/test/MATICVaultHandler.test.js index c5d905e..1e8ac0c 100644 --- a/test/MATICVaultHandler.test.js +++ b/test/MATICVaultHandler.test.js @@ -39,7 +39,7 @@ describe("MATIC Vault", async function () { await orchestratorInstance.deployed(); expect(orchestratorInstance.address).properAddress; - const TCAP = await ethers.getContractFactory("TCAP"); + const TCAP = await ethers.getContractFactory("IndexToken"); tcapInstance = await TCAP.deploy( "Total Market Cap Token", "TCAP", @@ -79,7 +79,7 @@ describe("MATIC Vault", async function () { await maticTokenHandler.deployed(); expect(maticTokenHandler.address).properAddress; - await orchestratorInstance.addTCAPVault(tcapInstance.address, maticTokenHandler.address); + await orchestratorInstance.addIndexVault(tcapInstance.address, maticTokenHandler.address); }); it("...should allow the owner to set the treasury address", async () => { @@ -104,7 +104,7 @@ describe("MATIC Vault", async function () { }); it("...should return the token price", async () => { - let tcapPrice = await maticTokenHandler.TCAPPrice(); + let tcapPrice = await maticTokenHandler.indexPrice(); let totalMarketCap = (await tcapOracleInstance.getLatestAnswer()).mul(10000000000); let result = totalMarketCap.div(divisor); expect(tcapPrice).to.eq(result); @@ -307,7 +307,7 @@ describe("MATIC Vault", async function () { let amount = ethers.utils.parseEther("1"); const reqAmount = await maticTokenHandler.requiredCollateral(amount); const ethPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - const tcapPrice = await maticTokenHandler.TCAPPrice(); + const tcapPrice = await maticTokenHandler.indexPrice(); const ratio = await maticTokenHandler.ratio(); let result = tcapPrice.mul(amount).mul(ratio).div(100).div(ethPrice); expect(reqAmount).to.eq(result); @@ -364,7 +364,7 @@ describe("MATIC Vault", async function () { it("...should calculate the burn fee", async () => { let amount = ethers.utils.parseEther("10"); let divisor = 10000; - let tcapPrice = await maticTokenHandler.TCAPPrice(); + let tcapPrice = await maticTokenHandler.indexPrice(); let ethPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); let result = tcapPrice.mul(amount).div(divisor).div(ethPrice); let fee = await maticTokenHandler.getBurnFee(amount); @@ -447,11 +447,11 @@ describe("MATIC Vault", async function () { }); it("...should get the required collateral for liquidation", async () => { - let reqLiquidation = await maticTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await maticTokenHandler.requiredLiquidationIndex(2); let liquidationPenalty = await maticTokenHandler.liquidationPenalty(); let ratio = await maticTokenHandler.ratio(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await maticTokenHandler.TCAPPrice(); + let tcapPrice = await maticTokenHandler.indexPrice(); let vault = await maticTokenHandler.getVault(2); let collateralTcap = vault[1].mul(collateralPrice).div(tcapPrice); let reqDividend = vault[3].mul(ratio).div(100).sub(collateralTcap).mul(100); @@ -461,11 +461,11 @@ describe("MATIC Vault", async function () { }); it("...should get the liquidation reward", async () => { - let reqLiquidation = await maticTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await maticTokenHandler.requiredLiquidationIndex(2); let liquidationReward = await maticTokenHandler.liquidationReward(2); let liquidationPenalty = await maticTokenHandler.liquidationPenalty(); let collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); - let tcapPrice = await maticTokenHandler.TCAPPrice(); + let tcapPrice = await maticTokenHandler.indexPrice(); let result = reqLiquidation.mul(liquidationPenalty.add(100)).div(100); result = result.mul(tcapPrice).div(collateralPrice); @@ -475,8 +475,8 @@ describe("MATIC Vault", async function () { it("...should allow liquidators to return profits", async () => { const divisor = ethers.utils.parseEther("1"); const liquidationReward = await maticTokenHandler.liquidationReward(2); - const reqLiquidation = await maticTokenHandler.requiredLiquidationTCAP(2); - const tcapPrice = await maticTokenHandler.TCAPPrice(); + const reqLiquidation = await maticTokenHandler.requiredLiquidationIndex(2); + const tcapPrice = await maticTokenHandler.indexPrice(); const collateralPrice = (await priceOracleInstance.getLatestAnswer()).mul(10000000000); const rewardUSD = liquidationReward.mul(collateralPrice).div(divisor); const collateralUSD = reqLiquidation.mul(tcapPrice).div(divisor); @@ -505,7 +505,7 @@ describe("MATIC Vault", async function () { await maticTokenHandler.connect(addr3).mint(liquidatorAmount, { value: mintFee }); let liquidationReward = await maticTokenHandler.liquidationReward(2); - let reqLiquidation = await maticTokenHandler.requiredLiquidationTCAP(2); + let reqLiquidation = await maticTokenHandler.requiredLiquidationIndex(2); let tcapBalance = await tcapInstance.balanceOf(accounts[3]); let collateralBalance = await wmaticTokenInstance.balanceOf(accounts[3]); let vault = await maticTokenHandler.getVault(2); diff --git a/test/Orchestrator.test.js b/test/Orchestrator.test.js index db40923..fd231a5 100644 --- a/test/Orchestrator.test.js +++ b/test/Orchestrator.test.js @@ -41,7 +41,7 @@ describe("Orchestrator Contract", async function () { expect(orchestratorInstance.address).properAddress; //TCAP - const TCAP = await ethers.getContractFactory("TCAP"); + const TCAP = await ethers.getContractFactory("IndexToken"); tcapInstance = await TCAP.deploy( "Total Market Cap Token", "TCAP", @@ -292,14 +292,14 @@ describe("Orchestrator Contract", async function () { let enableCap = true; await expect( - orchestratorInstance.connect(addr1).enableTCAPCap(tcapInstance.address, false) + orchestratorInstance.connect(addr1).enableIndexCap(tcapInstance.address, false) ).to.be.revertedWith("Ownable: caller is not the owner"); await expect( - orchestratorInstance.enableTCAPCap(ethersProvider.constants.AddressZero, false) - ).to.be.revertedWith("Orchestrator::validTCAP: not a valid TCAP ERC20"); + orchestratorInstance.enableIndexCap(ethersProvider.constants.AddressZero, false) + ).to.be.revertedWith("Orchestrator::validIndex: not a valid Index Token"); - await expect(orchestratorInstance.enableTCAPCap(tcapInstance.address, enableCap)) + await expect(orchestratorInstance.enableIndexCap(tcapInstance.address, enableCap)) .to.emit(tcapInstance, "NewCapEnabled") .withArgs(orchestratorInstance.address, enableCap); @@ -310,14 +310,14 @@ describe("Orchestrator Contract", async function () { let tcapCap = 100; await expect( - orchestratorInstance.connect(addr1).setTCAPCap(tcapInstance.address, 0) + orchestratorInstance.connect(addr1).setIndexCap(tcapInstance.address, 0) ).to.be.revertedWith("Ownable: caller is not the owner"); await expect( - orchestratorInstance.setTCAPCap(ethersProvider.constants.AddressZero, 0) - ).to.be.revertedWith("Orchestrator::validTCAP: not a valid TCAP ERC20"); + orchestratorInstance.setIndexCap(ethersProvider.constants.AddressZero, 0) + ).to.be.revertedWith("Orchestrator::validIndex: not a valid Index Token"); - await expect(orchestratorInstance.setTCAPCap(tcapInstance.address, tcapCap)) + await expect(orchestratorInstance.setIndexCap(tcapInstance.address, tcapCap)) .to.emit(tcapInstance, "NewCap") .withArgs(orchestratorInstance.address, tcapCap); @@ -328,21 +328,21 @@ describe("Orchestrator Contract", async function () { await expect( orchestratorInstance .connect(addr1) - .addTCAPVault(tcapInstance.address, ethVaultInstance.address) + .addIndexVault(tcapInstance.address, ethVaultInstance.address) ).to.be.revertedWith("Ownable: caller is not the owner"); await expect( - orchestratorInstance.addTCAPVault( + orchestratorInstance.addIndexVault( ethersProvider.constants.AddressZero, ethVaultInstance.address ) - ).to.be.revertedWith("Orchestrator::validTCAP: not a valid TCAP ERC20"); + ).to.be.revertedWith("Orchestrator::validIndex: not a valid Index Token"); await expect( - orchestratorInstance.addTCAPVault(tcapInstance.address, ethersProvider.constants.AddressZero) + orchestratorInstance.addIndexVault(tcapInstance.address, ethersProvider.constants.AddressZero) ).to.be.revertedWith("Orchestrator::validVault: not a valid vault"); - await expect(orchestratorInstance.addTCAPVault(tcapInstance.address, ethVaultInstance.address)) + await expect(orchestratorInstance.addIndexVault(tcapInstance.address, ethVaultInstance.address)) .to.emit(tcapInstance, "VaultHandlerAdded") .withArgs(orchestratorInstance.address, ethVaultInstance.address); @@ -353,25 +353,25 @@ describe("Orchestrator Contract", async function () { await expect( orchestratorInstance .connect(addr1) - .removeTCAPVault(tcapInstance.address, ethVaultInstance.address) + .removeIndexVault(tcapInstance.address, ethVaultInstance.address) ).to.be.revertedWith("Ownable: caller is not the owner"); await expect( - orchestratorInstance.removeTCAPVault( + orchestratorInstance.removeIndexVault( ethersProvider.constants.AddressZero, ethVaultInstance.address ) - ).to.be.revertedWith("Orchestrator::validTCAP: not a valid TCAP ERC20"); + ).to.be.revertedWith("Orchestrator::validIndex: not a valid Index Token"); await expect( - orchestratorInstance.removeTCAPVault( + orchestratorInstance.removeIndexVault( tcapInstance.address, ethersProvider.constants.AddressZero ) ).to.be.revertedWith("Orchestrator::validVault: not a valid vault"); await expect( - orchestratorInstance.removeTCAPVault(tcapInstance.address, ethVaultInstance.address) + orchestratorInstance.removeIndexVault(tcapInstance.address, ethVaultInstance.address) ) .to.emit(tcapInstance, "VaultHandlerRemoved") .withArgs(orchestratorInstance.address, ethVaultInstance.address); @@ -380,7 +380,7 @@ describe("Orchestrator Contract", async function () { }); it("...should allow to execute a custom transaction", async () => { - await orchestratorInstance.addTCAPVault(tcapInstance.address, ethVaultInstance.address); + await orchestratorInstance.addIndexVault(tcapInstance.address, ethVaultInstance.address); let currentOwner = await tcapInstance.owner(); expect(currentOwner).to.eq(orchestratorInstance.address); diff --git a/test/polygon/IntegrationTest.ts b/test/polygon/IntegrationTest.ts index b27c0ea..7ec9558 100644 --- a/test/polygon/IntegrationTest.ts +++ b/test/polygon/IntegrationTest.ts @@ -223,7 +223,7 @@ describe("Polygon Integration Test", async function () { wallet, [] ); - tCAP = await deployContract("TCAP", wallet, [ + tCAP = await deployContract("IndexToken", wallet, [ "TCAP Token", "TCAP", 0, @@ -258,9 +258,9 @@ describe("Polygon Integration Test", async function () { it("...Add new vault without Governance", async () => { expect(await tCAP.vaultHandlers(wMATICVaultHandler.address)).to.be.false; - let ABI = ["function addTCAPVault(address,address)"]; + let ABI = ["function addIndexVault(address,address)"]; let iface = new hre.ethers.utils.Interface(ABI); - const _data = iface.encodeFunctionData("addTCAPVault", [ + const _data = iface.encodeFunctionData("addIndexVault", [ tCAP.address, wMATICVaultHandler.address, ]); @@ -327,9 +327,9 @@ describe("Polygon Integration Test", async function () { expect(await tCAP.vaultHandlers(wMATICVaultHandler.address)).to.be.false; - let ABI = ["function addTCAPVault(address,address)"]; + let ABI = ["function addIndexVault(address,address)"]; let iface = new hre.ethers.utils.Interface(ABI); - let _data = iface.encodeFunctionData("addTCAPVault", [ + let _data = iface.encodeFunctionData("addIndexVault", [ tCAP.address, wMATICVaultHandler.address, ]);