Skip to content

Commit

Permalink
👷 remove payDebt() not used on Base
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Dec 16, 2024
1 parent bf4556e commit 0f09f1b
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 117 deletions.
18 changes: 0 additions & 18 deletions src/Engine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 0 additions & 5 deletions src/interfaces/IEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
94 changes: 0 additions & 94 deletions test/PayDebt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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)
Expand Down

0 comments on commit 0f09f1b

Please sign in to comment.