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

privileged accounts (liquidation) #164

Merged
merged 8 commits into from
Oct 12, 2021
Merged

Conversation

hussein-aitlahcen
Copy link
Contributor

@hussein-aitlahcen hussein-aitlahcen commented Oct 7, 2021

In this PR we draft the privilege capability of an account.
I am not familiar enough with low level substrate to tell whether this clash with the Origin (if it can cover this use case then perfect !).

The idea is to allow a group of privileged users to have access to special features of some pallets.
Let's take the current case: being a privileged liquidator for a lending market.

  • lending markets are dynamically generated and isolated from each other
  • liquidation is currently done via a dutch auction + order book
  • we want to introduce a set of privileged liquidator that would be able to take prority when an auction is starting (basically being able to pay at a previous block price). @KaiserKarel explained everything in confluence
  • the set of privileged liquidator will be altered by governance (bad actor wiped, new actor etc...), directly impacting new/already existing markets (a revoked liquidator will be removed from all the markets where it has been defined as a possible privileged liquidator)

I implemented a trait that would allow us to handle a set of privileged users, for any combination of privilege.
Instead of handling the state inside every pallet where we will need a set of privileged accounts, we handle it through a single pallet which provide an interface where we can register privileged groups. Whenever an account privilege is revoked, the user is revoked from all groups that expect their member to own the privilege.

Using this pallet, in the liquidation case we would be able to:

  • pass a list of privileged liquidator at market creation
  • check that every account are privileged while creating the market
  • create a privileged liquidators group consisting of all the provided accounts for the given market.
  • retrieve the list of privileged accounts when a liquidation is occuring (via the group id), allowing any user to be revoked from the group between liquidation (independently of the liquidation pallet, via governance for instance).

NOTE: this might be implemented using the membership pallet? or the election pallet?

@hussein-aitlahcen hussein-aitlahcen force-pushed the lending-liquidator branch 2 times, most recently from bf1ccc1 to d5d5bcf Compare October 7, 2021 10:17
dzmitry-lahoda
dzmitry-lahoda previously approved these changes Oct 7, 2021
Copy link
Contributor

@dzmitry-lahoda dzmitry-lahoda left a comment

Choose a reason for hiding this comment

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

thanks for fixing doc comments, so i thin need to lint them and generate docs, so i be sure i write correct markup:)

@hussein-aitlahcen hussein-aitlahcen force-pushed the lending-liquidator branch 4 times, most recently from ffced31 to 9909fec Compare October 11, 2021 14:40
@hussein-aitlahcen hussein-aitlahcen marked this pull request as ready for review October 11, 2021 14:41
@hussein-aitlahcen hussein-aitlahcen force-pushed the lending-liquidator branch 2 times, most recently from e777576 to dccab94 Compare October 11, 2021 14:54
@dzmitry-lahoda
Copy link
Contributor

membership is single map of runtime -> members. not map of any id -> members, so it does not work as i see

dzmitry-lahoda
dzmitry-lahoda previously approved these changes Oct 11, 2021
frame/privilege/src/lib.rs Show resolved Hide resolved
frame/privilege/src/lib.rs Show resolved Hide resolved
frame/privilege/src/lib.rs Show resolved Hide resolved
frame/privilege/src/lib.rs Show resolved Hide resolved
dzmitry-lahoda
dzmitry-lahoda previously approved these changes Oct 11, 2021
dzmitry-lahoda
dzmitry-lahoda previously approved these changes Oct 12, 2021
dzmitry-lahoda
dzmitry-lahoda previously approved these changes Oct 12, 2021
andor0 and others added 8 commits October 12, 2021 13:46
* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>
@hussein-aitlahcen
Copy link
Contributor Author

Fixed conflicts

@hussein-aitlahcen hussein-aitlahcen changed the base branch from main to develop October 12, 2021 15:11
.github/RELEASE_TEMPLATE.md Show resolved Hide resolved
@hussein-aitlahcen hussein-aitlahcen merged commit 44c705f into develop Oct 12, 2021
@hussein-aitlahcen hussein-aitlahcen deleted the lending-liquidator branch October 12, 2021 15:30
dzmitry-lahoda added a commit that referenced this pull request Oct 20, 2021
* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* better naming, comments & documentation

* introduce account privilege traits, allowing inspection + mutation

* introduce pallet-privilege which implements all the privilege traits

* add privilege pallet event triggers

* add privilege pallet readme

* refactor promote/revoke behavior to be noop over privileged/nonprivileged user

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
# Conflicts:
#	Cargo.lock
#	frame/lending/src/lib.rs
dzmitry-lahoda added a commit that referenced this pull request Oct 21, 2021
* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* better naming, comments & documentation

* introduce account privilege traits, allowing inspection + mutation

* introduce pallet-privilege which implements all the privilege traits

* add privilege pallet event triggers

* add privilege pallet readme

* refactor promote/revoke behavior to be noop over privileged/nonprivileged user

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
Signed-off-by: dzmitry-lahoda <[email protected]>
dzmitry-lahoda added a commit that referenced this pull request Oct 21, 2021
* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* better naming, comments & documentation

* introduce account privilege traits, allowing inspection + mutation

* introduce pallet-privilege which implements all the privilege traits

* add privilege pallet event triggers

* add privilege pallet readme

* refactor promote/revoke behavior to be noop over privileged/nonprivileged user

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
Signed-off-by: dzmitry-lahoda <[email protected]>
dzmitry-lahoda added a commit that referenced this pull request Oct 21, 2021
* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* better naming, comments & documentation

* introduce account privilege traits, allowing inspection + mutation

* introduce pallet-privilege which implements all the privilege traits

* add privilege pallet event triggers

* add privilege pallet readme

* refactor promote/revoke behavior to be noop over privileged/nonprivileged user

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
# Conflicts:
#	Cargo.lock
#	frame/lending/src/lib.rs
Signed-off-by: dzmitry-lahoda <[email protected]>
dzmitry-lahoda added a commit that referenced this pull request Oct 21, 2021
* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* Refactoring of pallet-lending (#182)

* - Implement dynamic PID controller based interest rate model.
      See details at https://www.delphidigital.io/reports/dynamic-interest-rate-model-based-on-control-theory/
    - Add InterestRate trait which provides get_borrow_rate() method.

* start refactor and inline docs (#169)

* start refactor and inline docs

* added more inline docs

* more docs

* clean

* quick clean

* fmt

* fmt

* polkadot-v0.9.11 (#187)

* fix wasm build (#192)

* fix wasm build

* pin orml to rev

* Update off-chain worker of pallet-lending (#190)

* remove request id (#194)

* test fixes (#195)

* Fix release benchmark feature build.

* Add cumulus-ping in Runtime (#197)

* enable CI on develop branch (#199)

* Implement DoubleExponent interest rate model. (#185)

* Copy and paste code of cumulus-ping pallet (#198)

* Remove unused dependencies (#203)

* pallet-assets (#112)

* POC of pallet-assets

* use Assets in vault::Config

* implement ReservableCurrency

make event a placeholder

* define and implement MultiCurrency trait

clippy

* use Assets as Currency implementation

* add extrinsics to pallet-asset

* weights file

weights working

weights added

* implement common orml traits

* implement MultiReservableCurrency

* Use WeightInfo in extrinsics

* fix merge

* Update benchmarks of pallet-lending (#148)

* Add offchain worker to monitor loans which should be liquidate or warned. (#151)

* Add offchain worker to monitor loans which should be liquidate or warned.

* Update benchmarks of pallet-lending

Co-authored-by: Andrey Orlov <[email protected]>

* light refactoring (#152)

* simplify traits

Prefer the usage of by-value for value parameters such as Balance
and the usage of `DispatchResult` instead of custom error.

* use try_mutate for mutating the auction order

* move `WrappingNext` to composable traits

* update gitignore, some tools are not supporting **/ patterns

* lending borrow/repay fixes & isolation test & more vault test (#156)

* add a note about how we are handling vault<->market

* use the more explicit type aliases

* `into_sub_account` require >8bytes AccountId

* fix borrow_for_collateral, express itself as borrow asset unit instead of $

* introduce vault stock_dilution_rate tests

* documentation & more inline pragmas

* better error name

When we hit a MustLiquidate while borrowing, this probably
mean that the market is being closed and waiting for repays
to happen.

* refactor

* avoid setting minimum deposit to let proptest pass with low values

* fix borrow/repay tests and introduce market isolation test

* auction and lending test fixes (#153)

Signed-off-by: dzmitry-lahoda <[email protected]>

* Pass InterestRateModel as input to create_new_market() extrinsic.

Co-authored-by: Filip <[email protected]>
Co-authored-by: andor0 <[email protected]>
Co-authored-by: Vivek Pandya <[email protected]>
Co-authored-by: Hussein Ait-Lahcen <[email protected]>
Co-authored-by: Dzmitry Lahoda <[email protected]>
Signed-off-by: dzmitry-lahoda <[email protected]>

* privileged accounts (liquidation) (#164)

* Refactoring of pallet-lending (#178)

* Create SECURITY.md (#111) (#174)

* Create SECURITY.md

Set up for security  protocols.

* More guidelines

* rewards section

Co-authored-by: Filip <[email protected]>

Update

setup-auto-release

Updating github workflow

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Implement auto update feature using two approaches

Co-authored-by: Douglas Kuhn <[email protected]>

* better naming, comments & documentation

* introduce account privilege traits, allowing inspection + mutation

* introduce pallet-privilege which implements all the privilege traits

* add privilege pallet event triggers

* add privilege pallet readme

* refactor promote/revoke behavior to be noop over privileged/nonprivileged user

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
# Conflicts:
#	Cargo.lock
#	frame/lending/src/lib.rs
Signed-off-by: dzmitry-lahoda <[email protected]>

* dex docs, groups for lending, api (#183)

Signed-off-by: dzmitry-lahoda <[email protected]>
# Conflicts:
#	Cargo.lock
#	frame/composable-traits/Cargo.toml
#	frame/composable-traits/src/lending.rs
#	frame/dutch-auction/src/lib.rs
#	frame/lending/src/lib.rs
#	frame/oracle/src/lib.rs

* smallest possible unit for currencies + refactor + lending fixes / tests more clear (#186)

* make sure we allow liquidation if the source account has zero funds after

* introduce PriceableAsset capability

* refactor lending pallet + oracle mock to use smallest unit of an asset

* fix merge conflicts, make tests more clear

* simpler priceable type & upgrade runtime currency to handle it

* simplify and better documentation

* cleanup unused constraints
# Conflicts:
#	frame/composable-traits/src/currency.rs
#	frame/composable-traits/src/lending.rs
#	frame/lending/src/lib.rs
#	frame/lending/src/tests.rs
#	frame/liquidations/src/lib.rs
#	frame/oracle/src/lib.rs
#	runtime/primitives/src/currency.rs

Signed-off-by: dzmitry-lahoda <[email protected]>

* Vault-index-configurable (#200)

* make VaultId an associated type

* Unmanle doc comment
# Conflicts:
#	frame/vault/src/lib.rs

Signed-off-by: dzmitry-lahoda <[email protected]>

* rent implementation (#189)

* implement rent and tombstoning

* clean up claim_surcharge

Also ensure that tombstoned vaults have funds returned by strategies.

* handle deletion_reward

* add delete_tombstoned functionality

* add add_surcharge

* fmt and fix doc comment

Signed-off-by: dzmitry-lahoda <[email protected]>

* Use NativeCurrency associated type instead of querying for native id (#202)

# Conflicts:
#	Cargo.lock
#	frame/vault/Cargo.toml

Signed-off-by: dzmitry-lahoda <[email protected]>

* fixed lending tests and run cargo fmt

Signed-off-by: dzmitry-lahoda <[email protected]>

* fixes from fmt and clippy

Signed-off-by: dzmitry-lahoda <[email protected]>

* fixes to benches

Signed-off-by: dzmitry-lahoda <[email protected]>

Co-authored-by: andor0 <[email protected]>
Co-authored-by: Adedayo Akinpelu <[email protected]>
Co-authored-by: Douglas Kuhn <[email protected]>
Co-authored-by: Vivek Pandya <[email protected]>
Co-authored-by: JesseAbram <[email protected]>
Co-authored-by: Seun Lanlege <[email protected]>
Co-authored-by: Karel L. Kubat <[email protected]>
Co-authored-by: Filip <[email protected]>
Co-authored-by: Hussein Ait-Lahcen <[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.

5 participants