porter-finance / v1-core

⛰️ Smart contracts powering the Porter protocol.
https://porter.finance
GNU Affero General Public License v3.0
4 stars 3 forks source link

allow preview for payment amount #242

Closed RusseII closed 2 years ago

RusseII commented 2 years ago

Problem

There is currently not a good way for a user to know much collateral with be unlocked from a payment. An issuer may wonder "if i pay 10000, how much collateral will I be able to withdraw?"

This adds that functionality to the previewWithdraw method. If the user is paying back 10,000 the frontend could call

<> After paying you'll be able to withdraw ${previewWithdraw(10,000)} tokens! </>

or... How much collateral is unlocked specifically from the payment? previewWithdraw(10,000) - previewWithdraw(0)

Feedback plz

I'm looking for suggestions for maybe a better way to do this.

This is how I thought about doing it with the least number of code modifications.

RusseII commented 2 years ago

The only thing I could think of is naming it something different, but don't love any of my ideas. previewWithdrawWithPayment, previewWithdrawAfterPayment, previewPayment, previewPaymentAndWithdraw

Same... I didn't really like any of those ideas either. Maybe @Pet3ris will have a good idea when he does a full code review :)

Pet3ris commented 2 years ago

Could you use the ERC4626 style pure function convertPaymentToCollateral(uint256 paymentAmount) returns (uint256 collateralAmount) ?