Skip to content

Commit

Permalink
✅ debt position todo
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Dec 14, 2024
1 parent 66d08aa commit 81bd9f4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 72 deletions.
125 changes: 63 additions & 62 deletions test/PayDebt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,97 +12,98 @@ contract PayDebtTest is Bootstrap {
uint256 public constant INITIAL_DEBT = 1_216_469_669_641_984_045;

function setUp() public {
vm.rollFork(266_832_048);
vm.rollFork(BASE_BLOCK_NUMBER);
initializeBase();

synthMinter.mint_sUSD(DEBT_ACTOR, AMOUNT);
}

function test_payDebt() public {
/// @dev on this block (266_832_048), ACCOUNT_ID has a debt value of INITIAL_DEBT
uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
assertEq(initialAccountDebt, INITIAL_DEBT);

uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);

vm.startPrank(DEBT_ACTOR);
function test_payDebt_Unauthorized() public {
vm.startPrank(ACTOR);

sUSD.approve(address(engine), INITIAL_DEBT);

vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));

engine.payDebt({_accountId: ACCOUNT_ID, _amount: INITIAL_DEBT});
vm.stopPrank();
}

uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
assertEq(finalAccountDebt, 0);
/// @custom:todo Get a debt position on Base to fork
// function test_payDebt() public {
// /// @dev on this block (266_832_048), ACCOUNT_ID has a debt value of INITIAL_DEBT
// uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(initialAccountDebt, INITIAL_DEBT);

uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);
assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
}
// uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);

/// @notice asserts that if amount passed is greater than debt, excess sUSD is sent back to the user after paying off the debt
function test_payDebt_overpay() public {
/// @dev on this block (ARBITRUM_BLOCK_NUMBER), ACCOUNT_ID has a debt value of INITIAL_DEBT
uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
assertEq(initialAccountDebt, INITIAL_DEBT);
// vm.startPrank(DEBT_ACTOR);

uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);
// sUSD.approve(address(engine), INITIAL_DEBT);

vm.startPrank(DEBT_ACTOR);
// engine.payDebt({_accountId: ACCOUNT_ID, _amount: INITIAL_DEBT});
// vm.stopPrank();

sUSD.approve(address(engine), INITIAL_DEBT + SMALLEST_AMOUNT);
// uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(finalAccountDebt, 0);

engine.payDebt({
_accountId: ACCOUNT_ID,
_amount: INITIAL_DEBT + SMALLEST_AMOUNT
});
vm.stopPrank();
// uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);
// assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
// }

uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
assertEq(finalAccountDebt, 0);
// /// @notice asserts that if amount passed is greater than debt, excess sUSD is sent back to the user after paying off the debt
// function test_payDebt_overpay() public {
// /// @dev on this block (ARBITRUM_BLOCK_NUMBER), ACCOUNT_ID has a debt value of INITIAL_DEBT
// uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(initialAccountDebt, INITIAL_DEBT);

uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);
assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
}
// uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);

function test_payDebt_Unauthorized() public {
vm.startPrank(ACTOR);
// vm.startPrank(DEBT_ACTOR);

sUSD.approve(address(engine), INITIAL_DEBT);
// sUSD.approve(address(engine), INITIAL_DEBT + SMALLEST_AMOUNT);

vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));
// engine.payDebt({
// _accountId: ACCOUNT_ID,
// _amount: INITIAL_DEBT + SMALLEST_AMOUNT
// });
// vm.stopPrank();

engine.payDebt({_accountId: ACCOUNT_ID, _amount: INITIAL_DEBT});
}
// uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(finalAccountDebt, 0);

function test_payDebt_Fuzz(uint256 amount) public {
vm.assume(amount < AMOUNT);
vm.assume(amount > SMALLEST_AMOUNT);
// uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);
// assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
// }

uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
assertEq(initialAccountDebt, INITIAL_DEBT);
// function test_payDebt_Fuzz(uint256 amount) public {
// vm.assume(amount < AMOUNT);
// vm.assume(amount > SMALLEST_AMOUNT);

uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);
// uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(initialAccountDebt, INITIAL_DEBT);

vm.startPrank(DEBT_ACTOR);
// uint256 initialSUSD = sUSD.balanceOf(DEBT_ACTOR);

sUSD.approve(address(engine), amount);
// vm.startPrank(DEBT_ACTOR);

engine.payDebt({_accountId: ACCOUNT_ID, _amount: amount});
// sUSD.approve(address(engine), amount);

vm.stopPrank();
// engine.payDebt({_accountId: ACCOUNT_ID, _amount: amount});

uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);
// vm.stopPrank();

if (amount > INITIAL_DEBT) {
// If amount is greater than the initial debt, the debt should be fully paid
// and excess sUSD should be sent back to the user
assertEq(finalAccountDebt, 0);
assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
} else {
// If amount is less or equal than the initial debt, only part of the debt is paid
assertEq(finalAccountDebt, INITIAL_DEBT - amount);
assertEq(finalSUSD, initialSUSD - amount);
}
}
// uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR);

// if (amount > INITIAL_DEBT) {
// // If amount is greater than the initial debt, the debt should be fully paid
// // and excess sUSD should be sent back to the user
// assertEq(finalAccountDebt, 0);
// assertEq(finalSUSD, initialSUSD - INITIAL_DEBT);
// } else {
// // If amount is less or equal than the initial debt, only part of the debt is paid
// assertEq(finalAccountDebt, INITIAL_DEBT - amount);
// assertEq(finalSUSD, initialSUSD - amount);
// }
// }
}
20 changes: 10 additions & 10 deletions test/Unwind.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ contract UnwindTest is Bootstrap {
address constant WETH_ADDR = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;

function setUp() public {
vm.rollFork(266_847_904);
vm.rollFork(BASE_BLOCK_NUMBER);
initializeBase();

synthMinter.mint_sUSD(DEBT_ACTOR, AMOUNT);

/// @dev this is needed because MWS hardcodes the live Engine contract address
/// therefore we cannot use our boostrap test state, we must fork
vm.startPrank(DEBT_ACTOR);
perpsMarketProxy.grantPermission({
accountId: ACCOUNT_ID,
permission: ADMIN_PERMISSION,
user: address(engine)
});
vm.stopPrank();
// vm.startPrank(DEBT_ACTOR);
// perpsMarketProxy.grantPermission({
// accountId: ACCOUNT_ID,
// permission: ADMIN_PERMISSION,
// user: address(engine)
// });
// vm.stopPrank();
}

function test_unwindCollateral_UNAUTHORIZED() public {
Expand All @@ -43,11 +43,11 @@ contract UnwindTest is Bootstrap {

function test_unwindCollateralETH_UNAUTHORIZED() public {
vm.expectRevert(abi.encodeWithSelector(IEngine.Unauthorized.selector));
engine.unwindCollateral(accountId, 1, 1, address(0), 1, 1, 1, "");
engine.unwindCollateralETH(accountId, 1, address(0), 1, 1, 1, "");
}

function test_unwindCollateral_s() public {
/// @custom:todo OracleDataRequired
/// @custom:todo Get a debt position on Base to fork
// uint256 initialAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID);
// assertEq(initialAccountDebt, INITIAL_DEBT);

Expand Down

0 comments on commit 81bd9f4

Please sign in to comment.