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

feat (Lending): deposit basics #47

Merged
merged 15 commits into from
Dec 12, 2022

Conversation

antoncoding
Copy link
Contributor

@antoncoding antoncoding commented Dec 9, 2022

Summary

  • Deposit USDC into the Lending contract and create balance

Details

  • Update to handleAdjustment: add manager check
  • the deposit function simply convert token amount => 18 decimals, and update that value in Account.
  • Add DecimalMath library that convert decimals for uint256
  • in DecimalMathTest test: it needs to setup a "helper contract" to let the forge coverage work properly with internal library. (reference)

Todo

  • decimal conversion for deposit
  • Unit tests for deposit
  • 100% coverage for deposit and convertDecimals

Checklist

Ensure you completed all of the steps below before submitting your pull request:

  • Add natspec for all functions / parameters
  • Ran forge snapshot
  • Ran forge fmt
  • Ran forge test
  • Triage Slither issues, and post uncertain ones in the PR
  • 100% test coverage on code changes

Slither Issues (Optional)

If you're unsure about a new issue reported by Slither, copy them here so others can verify as well.

@antoncoding antoncoding marked this pull request as draft December 9, 2022 03:59
@antoncoding antoncoding added the feature workstream feature label Dec 9, 2022
@antoncoding antoncoding changed the title feat: deposit with manager check on handleAdjustment feat (Lending): deposit Dec 9, 2022
@antoncoding antoncoding marked this pull request as ready for review December 9, 2022 04:47
@antoncoding antoncoding self-assigned this Dec 9, 2022
@antoncoding antoncoding requested review from LondonCalamari and removed request for LondonCalamari December 9, 2022 04:49
src/assets/Lending.sol Outdated Show resolved Hide resolved
@antoncoding
Copy link
Contributor Author

@LondonCalamari @joshpwrk 2 things I want your opinion on:

  1. I think having this PR first is gonna help with testing interest rate logic later, that's why i'm having this bare bone PR. do you think it's good to keep PR this size or have more stuff within 1 pr (like both deposit + withdraw if there're equivalently small )?

  2. I know by definition, it's not "unit tests" anymore if I setup Account contract and use it to test the actual callback of the hook, but I think it is more convenient to do it this way. Do you guys think this should belong to integration test or unit test?

  • I feel like it's clearer to live under integration test. but we might have another "more complex" integration test that includes real manager + real account + real asset in the future (after proto 1), so we will need to separate them somehow

@antoncoding antoncoding changed the title feat (Lending): deposit feat (Lending): deposit basic Dec 9, 2022
@antoncoding antoncoding changed the title feat (Lending): deposit basic feat (Lending): deposit basics Dec 9, 2022
@antoncoding antoncoding mentioned this pull request Dec 9, 2022
9 tasks
@joshpwrk
Copy link
Collaborator

joshpwrk commented Dec 9, 2022

@LondonCalamari @joshpwrk 2 things I want your opinion on:

  1. I think having this PR first is gonna help with testing interest rate logic later, that's why i'm having this bare bone PR. do you think it's good to keep PR this size or have more stuff within 1 pr (like both deposit + withdraw if there're equivalently small )?
  2. I know by definition, it's not "unit tests" anymore if I setup Account contract and use it to test the actual callback of the hook, but I think it is more convenient to do it this way. Do you guys think this should belong to integration test or unit test?
  • I feel like it's clearer to live under integration test. but we might have another "more complex" integration test that includes real manager + real account + real asset in the future (after proto 1), so we will need to separate them somehow
  1. I really like the current size - I feel like once things get really busy in the middle of a sprint, any PR longer than this I'd end up missing all the details

  2. I'm actually in favor of using Account but still keeping it in the unit-tests since the intent is to only test the behavior of the lending asset. I feel it will be quite hard to do useful unit-tests if we always limit them to only using mocks -> I think the intent matters more.

@LondonCalamari
Copy link
Contributor

@LondonCalamari @joshpwrk 2 things I want your opinion on:

  1. I think having this PR first is gonna help with testing interest rate logic later, that's why i'm having this bare bone PR. do you think it's good to keep PR this size or have more stuff within 1 pr (like both deposit + withdraw if there're equivalently small )?
  2. I know by definition, it's not "unit tests" anymore if I setup Account contract and use it to test the actual callback of the hook, but I think it is more convenient to do it this way. Do you guys think this should belong to integration test or unit test?
  • I feel like it's clearer to live under integration test. but we might have another "more complex" integration test that includes real manager + real account + real asset in the future (after proto 1), so we will need to separate them somehow
  1. Agree with Josh here. I think these PR sizes are very digestible, its alot easier to review ones this size.
  2. Unit test still makes sense here to me because the main intent of the tests is for Lending. Integration tests would be more for testing functionality across multiple contracts ?

@antoncoding
Copy link
Contributor Author

@LondonCalamari @joshpwrk I added the DecimalMath library in this PR and make the forge coverage work with it (finally). I think it's reasonable to assume that other workstreams won't need to use this lib for now, cause both manager and liquidation we only need numbers from Account which is always in 1e18.
(Feel like only asset contracts maybe OptionAsset too will need it, because we have to deal with exchanging with ERC20s)

Let me know if this is a good idea to have it here for now, and merge to other workstream later after sprint 1.

@LondonCalamari
Copy link
Contributor

@LondonCalamari @joshpwrk I added the DecimalMath library in this PR and make the forge coverage work with it (finally). I think it's reasonable to assume that other workstreams won't need to use this lib for now, cause both manager and liquidation we only need numbers from Account which is always in 1e18. (Feel like only asset contracts maybe OptionAsset too will need it, because we have to deal with exchanging with ERC20s)

Let me know if this is a good idea to have it here for now, and merge to other workstream later after sprint 1.

I think its okay to have it here for now and merge after sprint 1

Copy link
Contributor

@LondonCalamari LondonCalamari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

src/libraries/DecimalMath.sol Outdated Show resolved Hide resolved
@antoncoding antoncoding merged commit ac5c096 into proto1-sprint1/lending Dec 12, 2022
joshpwrk pushed a commit that referenced this pull request Dec 12, 2022
## Summary

* withdraw by USDC amount. Basically a mirrored function of `deposit`
* we might need a `withdrawByCashAmount` function to clear out balance
in Account. Otherwise there will always be dust amount left in an
account

## Todo

- [x] rebase after #47 is merged
- [x] Draft implementation for `withdraw`
- [x] Unit tests for `withdraw`

## Checklist

Ensure you completed **all of the steps** below before submitting your
pull request:

- [x] Add
[natspec](https://docs.soliditylang.org/en/latest/natspec-format.html)
for all functions / parameters
- [x] Ran `forge snapshot`
- [x] Ran `forge fmt`
- [x] Ran `forge test`
- [x] [Triage Slither issues](../README.md#triage-issues), and post
uncertain ones in the PR
- [x] 100% test coverage on code changes

### Slither Issues (Optional)

If you're unsure about a new issue reported by Slither, copy them here
so others can verify as well.
@antoncoding antoncoding deleted the feat/lending-deposit branch January 5, 2023 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature workstream feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants