Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
closes #100
I added a two fields in the Proposal struct
released_collateral which keeps track of how much of the collateral has been released.
amount_repaid which keeps track of how much amount has been repaid in dollars.
The logic in repay_proposal:
Added a new parameter called amount, which is the repaying amount in USD.
Then I calculate how much amount is being repaid in tokens.
If the amount being repaid in this transaction in USD + amount already paid in USD is >= proposal amount in USD. Then we cap it to be equal to the total amount. and adjust the tokens to be transferred accordingly.
Once we have the final amount in tokens, we start to calculate the interests, and protocol fees. We transfer the amount with interest to the lender.
Now to release collateral, We calculate how much percentage of the loan has been repaid. And release the collateral, so that the total collateral released is that same percentage.
Finally we store the updated proposal, and the interests earned.
And if the loan is repaid in full we emit the event.