open-dollar / od-contracts

Open Dollar stablecoin contracts
https://OpenDollar.com
Other
55 stars 8 forks source link

Immediate debt increase #690

Open pi0neerpat opened 4 months ago

pi0neerpat commented 4 months ago

After opening a HAI vault with 1,000 HAI image

After opening a OD vault with 1,000 OD

image

For some reason our app is showing additional debt. However 1.75% APR should not have accumulated this quickly

pi0neerpat commented 4 months ago

Moving to contracts side since its likely not a frontend issue

Seroxdesign commented 3 months ago

Investigation Summary

The differences in the application of debt, interest, and tax between the Optimism and Arbitrum contracts have been identified and analyzed. Below are the key findings and conclusions:

On Optimism

  1. Debt and Interest Calculation:

    • When openLockTokenCollateralAndGenerateDebt is executed, it calls _lockTokenCollateralAndGenerateDebt.
    • _lockTokenCollateralAndGenerateDebt immediately calls ITaxCollector(_taxCollector).taxSingle(_safeInfo.collateralType);.
    • The debt and interest are applied to the account via modifySafeCollateralisation.
    • The tax fee event for HAI collaterals on Optimism is lower (around 0.003%) and occurs at the beginning of the function call.
  2. Function Call Stack:

    • The tax fee is calculated at the start of the function call sequence.

On Arbitrum

  1. Debt, Interest, and Tax Calculation:

    • When openLockTokenCollateralAndGenerateDebt is executed, it calls _lockTokenCollateralAndGenerateDebt.
    • _lockTokenCollateralAndGenerateDebt routes to _modifySAFECollateralization.
    • _modifySAFECollateralization calls ODSafeManager(_manager).modifySAFECollateralization(_safeId, _deltaCollateral, _deltaDebt, _nonSafeHandlerAddress);.
    • This sequence then calls taxSingle via TaxCollector.taxSingle, applying tax at the end of the function call.
    • The debt, interest, and tax are applied to the account with a higher tax rate (around 0.005%).
  2. Function Call Stack:

    • The tax fee is calculated at the end of the function call sequence.

Differences Based on Collateral Type and Deployment Timing

Example Transactions

Conclusion

The primary difference between the Optimism and Arbitrum contracts lies in the timing and rate of tax application. On Optimism, the tax is applied at the beginning of the function call with a slightly lower rate, whereas on Arbitrum, the tax is applied at the end of the function call with a higher rate. This distinction, influenced by the deployment timing and collateral types, results in a notable difference in user costs between the two networks.