Fujicracy / fuji-v2

Cross-chain money market aggregator
https://fuji-v2-frontend.vercel.app
15 stars 10 forks source link

Fix balanceOfDebt #251

Closed brozorec closed 1 year ago

brozorec commented 1 year ago

vault.balanceOf returns shares while vault.balanceOfDebt returns amounts. This is inconsistent and should be fixed.

brozorec commented 1 year ago

I'm implementing some new methods in the sdk, and this issue starts becoming a huge pain in the ass. How should we handle it?

  1. We make balanceOfDebt() return shares similar to balanceOf() -> This implies a good chunk of refactoring (both in the vault and in tests).
  2. We introduce a new function like balanceOfAssets() that returns amount of assets. Do we still have some margin regarding the contract size?

@DaigaroCota wdyt?

0xdcota commented 1 year ago

I'm implementing some new methods in the sdk, and this issue starts becoming a huge pain in the ass. How should we handle it?

  1. We make balanceOfDebt() return shares similar to balanceOf() -> This implies a good chunk of refactoring (both in the vault and in tests).
  2. We introduce a new function like balanceOfAssets() that returns amount of assets. Do we still have some margin regarding the contract size?

@DaigaroCota wdyt?

To minimize the size of this impact, I suggest to align in the following way: Keep balanceOfDebt() as currently implemented in smart contracts. It should returns thedebt amount. This is how is currently implemented in v0.0.1 We introduce a new method that returns the _debtShares and we can call it balanceOfDebtShares(address). We will need to add this to the {IVault}, return zero in {YieldVault} and return _debtShares in the {BorrowingVault}.

brozorec commented 1 year ago

I suggest the following:

balanceOf() -> asset shares balanceOfDebtShares() -> debt shares balanceOfDebt() -> debt amount balanceOfAsset() -> asset amount (if we have a method for the debt amount then we need one for the asset amount as well)

0xdcota commented 1 year ago

I suggest the following:

balanceOf() -> asset shares balanceOfDebtShares() -> debt shares balanceOfDebt() -> debt amount balanceOfAsset() -> asset amount (if we have a method for the debt amount then we need one for the asset amount as well)

Lets proceed this way.