Created
April 25, 2024 11:58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity =0.8.17; | |
import "forge-std/console.sol"; | |
import "forge-std/Test.sol"; | |
import {DNft} from "../../src/core/DNft.sol"; | |
import {DeployV2, Contracts} from "../../script/deploy/Deploy.V2.s.sol"; | |
import {Licenser} from "../../src/core/Licenser.sol"; | |
import {Parameters} from "../../src/params/Parameters.sol"; | |
import {ERC20} from "@solmate/src/tokens/ERC20.sol"; | |
contract V2Test is Test, Parameters { | |
Contracts contracts; | |
ERC20 weth; | |
function setUp() public { | |
vm.createSelectFork("https://rpc.ankr.com/eth"); | |
contracts = new DeployV2().run(); | |
} | |
function testLicenseVaultManager() public { | |
Licenser licenser = Licenser(MAINNET_VAULT_MANAGER_LICENSER); | |
vm.prank(MAINNET_OWNER); | |
licenser.add(address(contracts.vaultManager)); | |
} | |
function mintDNFT(address user) private returns (uint) { | |
vm.deal(user, 1 ether); | |
return DNft(MAINNET_DNFT).mintNft{value: 1 ether}(user); | |
} | |
function deposit( | |
ERC20 token, | |
uint id, | |
address vault, | |
uint amount, | |
address user | |
) public { | |
deal(address(token),user , amount); | |
token.approve(address(contracts.vaultManager), amount); | |
contracts.vaultManager.deposit(id, address(vault), amount); | |
} | |
function testAddKerosene() public{ | |
testLicenseVaultManager(); | |
uint id = mintDNFT(address(this)); | |
//user add same vault address to both addkerosene() and add() function | |
contracts.vaultManager.addKerosene(id, address(contracts.ethVault)); | |
contracts.vaultManager.add(id, address(contracts.ethVault)); | |
uint amountTodeposit = 1 ether; | |
//deposit to the vault | |
deposit(ERC20(MAINNET_WETH), id, address(contracts.ethVault),amountTodeposit , address(this)); | |
uint Total = contracts.vaultManager.getTotalUsdValue(id); | |
console.log("TotalValue:", Total); | |
uint getNon = contracts.vaultManager.getNonKeroseneValue(id); | |
console.log("nonker:", getNon); | |
uint getKer = contracts.vaultManager.getKeroseneValue(id); | |
console.log("nonker:", getKer); | |
//user is able to mint upto 100% of their collateral | |
contracts.vaultManager.mintDyad(id, getNon, address(this) ); | |
ERC20(MAINNET_DYAD).balanceOf(address(this)); | |
uint ratio = contracts.vaultManager.collatRatio(id); | |
console.log("collateral ratio:", ratio); | |
// 1e18 is 100% of the collateral ratio user minted | |
//assert ratio returned doubled of the ratio expected | |
assertEq(ratio, 1e18 * 2); | |
vm.startPrank(address(0x111)); // random users | |
uint idliq = mintDNFT(address(0x111)); | |
//unable to liquidate | |
vm.expectRevert(); | |
contracts.vaultManager.liquidate(id, idliq); | |
} | |
receive() external payable {} | |
function onERC721Received( | |
address, | |
address, | |
uint256, | |
bytes calldata | |
) external pure returns (bytes4) { | |
return 0x150b7a02; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment