Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BasicActions _getGeneratedDeltaDebt precision issue #665

Closed
0xSero opened this issue Apr 30, 2024 · 1 comment · Fixed by #674
Closed

BasicActions _getGeneratedDeltaDebt precision issue #665

0xSero opened this issue Apr 30, 2024 · 1 comment · Fixed by #674
Assignees
Labels

Comments

@0xSero
Copy link

0xSero commented Apr 30, 2024

Intended behaviour:

Tax is added onto borrowed amount, not reduced from what is sent to the user as per @cupOJoseph

Example: 200 is borrowed, 200 OD is minted and sent to user, debt is incremented so they must pay back 200.01

Problem:

Example: When user's create a vault, and borrow 200 OD, only 199.98 is sent to their wallet, making it impossible for them to pay their debt without making a new vault, or obtaining OD.

We've investigate the Frontend, and SDK, the problem begins with the method:
Contract & line

  function openLockTokenCollateralAndGenerateDebt(
    address _manager,
    address _collateralJoin,
    address _coinJoin,
    bytes32 _cType,
    uint256 _collateralAmount,
    uint256 _deltaWad
  ) external delegateCall returns (uint256 _safe) {
    _safe = _openSAFE(_manager, _cType, address(this));

    _lockTokenCollateralAndGenerateDebt(_manager, _collateralJoin, _coinJoin, _safe, _collateralAmount, _deltaWad);
  }

_lockTokenCollateralAndGenerateDebt calls _getGeneratedDeltaDebt

Which calculates _deltaDebt, however _deltaDebt is slightly off wad, potentially due to solidity precision loss issues. As seen below:
image

// If there was already enough COIN in the safeEngine balance, just exits it without adding more debt
if (_coinAmount < _deltaWad * RAY) {
      // Calculates the needed deltaDebt so together with the existing coins in the safeEngine is enough to exit wad amount of COIN tokens
      _deltaDebt = ((_deltaWad * RAY - _coinAmount) / _rate).toInt();
      // This is neeeded due lack of precision. It might need to sum an extra deltaDebt wei (for the given COIN wad amount)
      _deltaDebt = uint256(_deltaDebt) * _rate < _deltaWad * RAY ? _deltaDebt + 1 : _deltaDebt;
 }

Notes:

Maybe use hardhat console.log to print out every value within _getGeneratedDeltaDebt to see where the issue lies.

Resources:

@MrDeadCe11
Copy link
Member

This is intended. You have to obtain OD on the open market to pay off all your debt. The protocol takes taxes any time the safe debt or collateral is modified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants