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

Lock utilised capacity #39

Merged
merged 15 commits into from
Dec 6, 2022
Merged

Conversation

amarinkovic
Copy link
Member

@amarinkovic amarinkovic commented Nov 30, 2022

When creating a policy, funds should be locked in the entity's balance. One of the reasons for this is, so that the collateral cannot be used for trading or withdrawing while there are active policies that could potentially require these funds as a collateral for the claims.

Few other things are included in this pull-requests:

  • Funds locked and utilised capacity are factored with the collateral ratio, not necessarily the entire amount gets locked/utilised
  • Only entity administrator can pay out the dividends
  • Refactor tests, pull in initPolicy into D03ProtocolDefaults and few other small improvements

ClickUp: CU-320z296

@amarinkovic amarinkovic marked this pull request as ready for review December 5, 2022 10:25
Copy link
Contributor

@kevin-fruitful kevin-fruitful left a comment

Choose a reason for hiding this comment

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

lgtm :)

@amarinkovic amarinkovic merged commit 3e05127 into main Dec 6, 2022
@amarinkovic amarinkovic deleted the CU-320z296_lock_utilized_capacity_funds branch December 6, 2022 11:48
amarinkovic added a commit that referenced this pull request Dec 9, 2022
* refactor: give more general name to locked up funds mapping

* refactor: use more generic require messages for locked tokens

* feat: update locked funds with utilised capacity

* refactor: general locked balance getter; test defaults improvements

* test: not able to trade with locked funds

* feat: only entity admin can pay dividend

* feat: locked funds and utilised capacity are factored by collateral ratio

* 📝 docs: update natspec generated markdowns

* test: harden collateral ratio test case

* feat: add collateral ratio updated event

* test: fix cell update test

* feat: ensure enough balance available when increasing collateral ratio
# Conflicts:
#	src/diamonds/nayms/facets/TokenizedVaultFacet.sol
#	src/diamonds/nayms/libs/LibEntity.sol
#	test/T02User.t.sol
#	test/T03TokenizedVault.t.sol
#	test/T04Entity.t.sol
#	test/T04Market.t.sol
#	test/T05TokenWrapper.t.sol
@amarinkovic amarinkovic mentioned this pull request Dec 9, 2022
amarinkovic added a commit that referenced this pull request Dec 12, 2022
* refactor: give more general name to locked up funds mapping

* refactor: use more generic require messages for locked tokens

* feat: update locked funds with utilised capacity

* refactor: general locked balance getter; test defaults improvements

* test: not able to trade with locked funds

* feat: only entity admin can pay dividend

* feat: locked funds and utilised capacity are factored by collateral ratio

* 📝 docs: update natspec generated markdowns

* test: harden collateral ratio test case

* feat: add collateral ratio updated event

* test: fix cell update test

* feat: ensure enough balance available when increasing collateral ratio
# Conflicts:
#	src/diamonds/nayms/facets/TokenizedVaultFacet.sol
#	src/diamonds/nayms/libs/LibEntity.sol
#	test/T02User.t.sol
#	test/T03TokenizedVault.t.sol
#	test/T04Entity.t.sol
#	test/T04Market.t.sol
#	test/T05TokenWrapper.t.sol
amarinkovic added a commit that referenced this pull request Dec 12, 2022
* refactor: give more general name to locked up funds mapping

* refactor: use more generic require messages for locked tokens

* feat: update locked funds with utilised capacity

* refactor: general locked balance getter; test defaults improvements

* test: not able to trade with locked funds

* feat: only entity admin can pay dividend

* feat: locked funds and utilised capacity are factored by collateral ratio

* 📝 docs: update natspec generated markdowns

* test: harden collateral ratio test case

* feat: add collateral ratio updated event

* test: fix cell update test

* feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 14, 2022
* refactor: give more general name to locked up funds mapping

* refactor: use more generic require messages for locked tokens

* feat: update locked funds with utilised capacity

* refactor: general locked balance getter; test defaults improvements

* test: not able to trade with locked funds

* feat: only entity admin can pay dividend

* feat: locked funds and utilised capacity are factored by collateral ratio

* 📝 docs: update natspec generated markdowns

* test: harden collateral ratio test case

* feat: add collateral ratio updated event

* test: fix cell update test

* feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 14, 2022
* refactor: give more general name to locked up funds mapping

* refactor: use more generic require messages for locked tokens

* feat: update locked funds with utilised capacity

* refactor: general locked balance getter; test defaults improvements

* test: not able to trade with locked funds

* feat: only entity admin can pay dividend

* feat: locked funds and utilised capacity are factored by collateral ratio

* 📝 docs: update natspec generated markdowns

* test: harden collateral ratio test case

* feat: add collateral ratio updated event

* test: fix cell update test

* feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 14, 2022
…city (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping
   
    * refactor: use more generic require messages for locked tokens
   
    * feat: update locked funds with utilised capacity
   
    * refactor: general locked balance getter; test defaults improvements
   
    * test: not able to trade with locked funds
   
    * feat: only entity admin can pay dividend
   
    * feat: locked funds and utilised capacity are factored by collateral ratio
   
    * 📝 docs: update natspec generated markdowns
   
    * test: harden collateral ratio test case
   
    * feat: add collateral ratio updated event
   
    * test: fix cell update test
   
    * feat: ensure enough balance available when increasing collateral ratio
kevin-fruitful pushed a commit that referenced this pull request Dec 16, 2022
…city (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping
   
    * refactor: use more generic require messages for locked tokens
   
    * feat: update locked funds with utilised capacity
   
    * refactor: general locked balance getter; test defaults improvements
   
    * test: not able to trade with locked funds
   
    * feat: only entity admin can pay dividend
   
    * feat: locked funds and utilised capacity are factored by collateral ratio
   
    * 📝 docs: update natspec generated markdowns
   
    * test: harden collateral ratio test case
   
    * feat: add collateral ratio updated event
   
    * test: fix cell update test
   
    * feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 16, 2022
…city (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping
   
    * refactor: use more generic require messages for locked tokens
   
    * feat: update locked funds with utilised capacity
   
    * refactor: general locked balance getter; test defaults improvements
   
    * test: not able to trade with locked funds
   
    * feat: only entity admin can pay dividend
   
    * feat: locked funds and utilised capacity are factored by collateral ratio
   
    * 📝 docs: update natspec generated markdowns
   
    * test: harden collateral ratio test case
   
    * feat: add collateral ratio updated event
   
    * test: fix cell update test
   
    * feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 16, 2022
…city (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping

    * refactor: use more generic require messages for locked tokens

    * feat: update locked funds with utilised capacity

    * refactor: general locked balance getter; test defaults improvements

    * test: not able to trade with locked funds

    * feat: only entity admin can pay dividend

    * feat: locked funds and utilised capacity are factored by collateral ratio

    * 📝 docs: update natspec generated markdowns

    * test: harden collateral ratio test case

    * feat: add collateral ratio updated event

    * test: fix cell update test

    * feat: ensure enough balance available when increasing collateral ratio
kevin-fruitful pushed a commit that referenced this pull request Dec 16, 2022
…city (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping

    * refactor: use more generic require messages for locked tokens

    * feat: update locked funds with utilised capacity

    * refactor: general locked balance getter; test defaults improvements

    * test: not able to trade with locked funds

    * feat: only entity admin can pay dividend

    * feat: locked funds and utilised capacity are factored by collateral ratio

    * 📝 docs: update natspec generated markdowns

    * test: harden collateral ratio test case

    * feat: add collateral ratio updated event

    * test: fix cell update test

    * feat: ensure enough balance available when increasing collateral ratio
amarinkovic added a commit that referenced this pull request Dec 22, 2022
* fix(QSP-5): risk of initialize() twice

* fix(QSP-2): avoid offer execution overflow

fix(QSP-2): avoid offer execution overflow

* fix(QSP-3): assert entity and policy asset match; prevent changing it

* fix(QSP-6): missing validations

* fix(QSP-4): prevent admin privilege loss

* fix(QSP-7): unify dust checks and simplify redundant insert check

* fix(QSP-8): remove dividendDeduction, reduce unnecessary complexity

* fix(QSP-9): assigning duplicated stakeholders

* fix(QSP-17): prevent reentrancy

* fix(QSP-19): fix commission value thrown in event

* fix(QSP-20): purge unused vars from appstorage, move doc into lib

* fix(QSP-21): add EIP-165 support

* fix(QSP-24): add explicit relation to interfaces in facets

* fix(QSP-10): signature replay attack

* fix(QSP-11): reentrancy guard colliding with storage slot

* fix(QSP-12): risk of insolvent balance with non-standard erc20 token integration

* fix(QSP-30): remove staking related requirement

* fix(QSP-13): invalid policy configurations

* fix(QSP-14): incorrect checks in _assertValidOffer()

* fix(QSP-26): clear up comments and docs

* fix(QSP-28): prevent dividend distribution guid reuse

* fix(QSP-16): production rediness concern

* fix(QSP-15): out-of-gas errors when adding external tokens to a protocol

* fix(QSP-1): only entity admin can pay dividend and lock utilised capacity (#42)

* fix: only entity admin can pay dividend

* Lock utilised capacity (#39)

    * refactor: give more general name to locked up funds mapping

    * refactor: use more generic require messages for locked tokens

    * feat: update locked funds with utilised capacity

    * refactor: general locked balance getter; test defaults improvements

    * test: not able to trade with locked funds

    * feat: only entity admin can pay dividend

    * feat: locked funds and utilised capacity are factored by collateral ratio

    * 📝 docs: update natspec generated markdowns

    * test: harden collateral ratio test case

    * feat: add collateral ratio updated event

    * test: fix cell update test

    * feat: ensure enough balance available when increasing collateral ratio

* fix(QSP): apply recommended best practices

docs: address QS code docs comments

* fix(QSP-22): lock to a specific Solidity version - v0.8.17

* ci: bump solc to v0.8.17

* fix: few slither reported warnings

* ci: exclude low-level-calls rule from slither

* refactor: revert interface pragma to `>= 0.8.13` due to lack of web3j support

* fix(qsp-12-hotfix-deposit): use address(this) when checking balances in externalDeposit() (#45)

* fix(qsp-12-hotfix): add low level call assertion checks (#43)

Co-authored-by: Kevin Park <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants