diff --git a/src/Engine.sol b/src/Engine.sol index 4fcb6bd6..5af22f49 100644 --- a/src/Engine.sol +++ b/src/Engine.sol @@ -628,24 +628,6 @@ contract Engine is : SPOT_MARKET_PROXY.getSynth(_synthMarketId); } - /// @inheritdoc IEngine - function payDebt(uint128 _accountId, uint256 _amount) - external - payable - override - { - if (!isAccountOwner(_accountId, msg.sender)) revert Unauthorized(); - - SUSD.transferFrom(msg.sender, address(this), _amount); - SUSD.approve(address(zap), _amount); - - uint256 remaining = zap.burn(_amount, _accountId); - - if (remaining > 0) SUSD.transfer(msg.sender, remaining); - - emit Burned(_accountId, _amount - remaining); - } - /// @inheritdoc IEngine function payDebtWithUSDC( uint128 _accountId, diff --git a/src/interfaces/IEngine.sol b/src/interfaces/IEngine.sol index 1323272e..a1f311ec 100644 --- a/src/interfaces/IEngine.sol +++ b/src/interfaces/IEngine.sol @@ -343,11 +343,6 @@ interface IEngine { uint256 _tolerance ) external payable; - /// @notice Pays off debt for a specified account using USDx - /// @param _accountId The ID of the account to pay debt for - /// @param _amount The amount of USDx to use for paying the debt - function payDebt(uint128 _accountId, uint256 _amount) external payable; - /// @notice Pays off debt for a specified account using USDC /// @param _accountId The ID of the account to pay debt for /// @param _amount The amount of USDx to use for paying the debt diff --git a/test/PayDebt.t.sol b/test/PayDebt.t.sol index cbe3162d..905b0eba 100644 --- a/test/PayDebt.t.sol +++ b/test/PayDebt.t.sol @@ -18,20 +18,9 @@ contract PayDebtTest is Bootstrap { vm.rollFork(BASE_BLOCK_NUMBER_WITH_DEBT); initializeBase(); - synthMinter.mint_sUSD(DEBT_ACTOR, AMOUNT); deal(address(USDC), DEBT_ACTOR, AMOUNT); } - 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}); - } - function test_payDebtWithUSDC_Unauthorized() public { vm.startPrank(ACTOR); @@ -46,89 +35,6 @@ contract PayDebtTest is Bootstrap { }); } - function test_payDebt() public { - /// @dev on this block (BASE_BLOCK_NUMBER_WITH_DEBT) - /// 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); - - sUSD.approve(address(engine), INITIAL_DEBT); - - engine.payDebt({_accountId: ACCOUNT_ID, _amount: INITIAL_DEBT}); - vm.stopPrank(); - - uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID); - assertEq(finalAccountDebt, 0); - - uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR); - assertEq(finalSUSD, initialSUSD - INITIAL_DEBT); - } - - /// @notice asserts that if amount passed is greater than debt, - /// @notice excess sUSD is sent back to the user after paying off the debt - function test_payDebt_overpay() public { - /// @dev on this block (BASE_BLOCK_NUMBER_WITH_DEBT) - /// 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); - - sUSD.approve(address(engine), INITIAL_DEBT + SMALLEST_AMOUNT); - - engine.payDebt({ - _accountId: ACCOUNT_ID, - _amount: INITIAL_DEBT + SMALLEST_AMOUNT - }); - vm.stopPrank(); - - uint256 finalAccountDebt = perpsMarketProxy.debt(ACCOUNT_ID); - assertEq(finalAccountDebt, 0); - - uint256 finalSUSD = sUSD.balanceOf(DEBT_ACTOR); - assertEq(finalSUSD, initialSUSD - INITIAL_DEBT); - } - - function test_payDebt_Fuzz(uint256 amount) public { - vm.assume(amount < AMOUNT); - vm.assume(amount > SMALLEST_AMOUNT); - - /// @dev on this block (BASE_BLOCK_NUMBER_WITH_DEBT) - /// 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); - - sUSD.approve(address(engine), amount); - - engine.payDebt({_accountId: ACCOUNT_ID, _amount: amount}); - - vm.stopPrank(); - - 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); - } - } - function test_payDebtWithUSDC() public { /// @dev INITIAL_DEBT is in sUSD (18 decimals) /// so we need to convert it to USDC (6 decimals)