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

Add incentive reserved ratio & Add liquidation threshold #1588

Merged
merged 21 commits into from
Apr 25, 2022

Conversation

yrong
Copy link
Contributor

@yrong yrong commented Apr 15, 2022

@zhoujia6139 @yz89

After checking the liquidate_borrow impl seems for ED-1392 we do not need to setup another reserve address. Just update liquidator's voucher_balance a little less should be enough and the left part will automatically reserved in our pallet account. Correct me if I'm wrong.

PS: The pr is not ready yet, just ignore the hard coded ratio will remove to runtime config later or as initialized parameter of market.

@yrong
Copy link
Contributor Author

yrong commented Apr 20, 2022

after some discussion, we add a separated pallet account for the reserved incentive and allow redeem back by governance when required

@yrong
Copy link
Contributor Author

yrong commented Apr 20, 2022

  • add liquidate incentive ratio to reserve some collateral asset
  • reserve to separated internal account
  • add extrinsic to redeem incentive reserved with governance origin
  • add another liquidate threshold param to avoid excessive liquidate_borrow
  • fix breaking tests & add more
  • market storage migration
  • update parallel-helper launch config with new market into

@yrong yrong marked this pull request as ready for review April 20, 2022 00:48
@yrong yrong requested review from a team, yz89 and zhoujia6139 April 20, 2022 00:48
@yrong yrong force-pushed the ron/reserve-liquidation-incentive branch from f71cabe to b26c276 Compare April 21, 2022 01:34
@codecov-commenter
Copy link

codecov-commenter commented Apr 21, 2022

Codecov Report

Merging #1588 (e2f58cd) into master (b8ba644) will increase coverage by 0.20%.
The diff coverage is 75.32%.

@@            Coverage Diff             @@
##           master    #1588      +/-   ##
==========================================
+ Coverage   66.46%   66.67%   +0.20%     
==========================================
  Files         105      105              
  Lines       10897    11024     +127     
==========================================
+ Hits         7243     7350     +107     
- Misses       3654     3674      +20     
Impacted Files Coverage Δ
pallets/loans/src/benchmarking.rs 0.00% <0.00%> (ø)
pallets/loans/src/migrations.rs 0.00% <0.00%> (ø)
pallets/loans/src/tests/interest_rate.rs 100.00% <ø> (ø)
runtime/heiko/src/lib.rs 0.00% <ø> (ø)
runtime/kerria/src/lib.rs 0.00% <ø> (ø)
runtime/parallel/src/lib.rs 0.00% <ø> (ø)
pallets/loans/src/lib.rs 85.18% <83.15%> (-0.41%) ⬇️
pallets/loans/src/mock.rs 71.87% <100.00%> (+0.59%) ⬆️
pallets/loans/src/tests.rs 100.00% <100.00%> (ø)
pallets/loans/src/tests/liquidate_borrow.rs 100.00% <100.00%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b8ba644...e2f58cd. Read the comment docs.

@yrong yrong changed the title Reserve 3% liquidation incentive Add incentive reserved ratio & Add loose threshold ratio Apr 21, 2022
@yrong yrong changed the title Add incentive reserved ratio & Add loose threshold ratio Add incentive reserved ratio & Add loose collateral ratio Apr 21, 2022
@yrong
Copy link
Contributor Author

yrong commented Apr 21, 2022

cargo run --bin parallel --features try-runtime -- try-runtime --chain heiko-dev --wasm-execution=compiled on-runtime-upgrade live --uri=wss://heiko-rpc.parallel.fi
    Finished dev [unoptimized + debuginfo] target(s) in 1.24s
     Running `target/debug/parallel try-runtime --chain heiko-dev --wasm-execution=compiled on-runtime-upgrade live '--uri=wss://heiko-rpc.parallel.fi'`
thread 'main' panicked at 'Argument "pallets"
  Arg::is_use_value_delimiter_set is required when Arg::is_require_value_delimiter_set is set.
', /home/ron/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/clap-3.1.3/src/build/debug_asserts.rs:659:5

during test of bd288c1 found the issue and seems related with paritytech/substrate#11017 and fixed in polkadot-v0.9.18 and later release

@GopherJ have you met this issue before? are we going to bump parity dependencies in next upgrade window? Meanwhile I guess can only test the storage migration with locally setup.

@0x8f701
Copy link
Contributor

0x8f701 commented Apr 21, 2022

@yrong yeah, polkadot-v0.9.19 is released and we are interested in it so I'm making #1632 , it'll be merged tomorrow I think

@yz89
Copy link
Contributor

yz89 commented Apr 21, 2022

cargo run --bin parallel --features try-runtime -- try-runtime --chain heiko-dev --wasm-execution=compiled on-runtime-upgrade live --uri=wss://heiko-rpc.parallel.fi
    Finished dev [unoptimized + debuginfo] target(s) in 1.24s
     Running `target/debug/parallel try-runtime --chain heiko-dev --wasm-execution=compiled on-runtime-upgrade live '--uri=wss://heiko-rpc.parallel.fi'`
thread 'main' panicked at 'Argument "pallets"
  Arg::is_use_value_delimiter_set is required when Arg::is_require_value_delimiter_set is set.
', /home/ron/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/clap-3.1.3/src/build/debug_asserts.rs:659:5

during test of bd288c1 found the issue and seems related with paritytech/substrate#11017 and fixed in polkadot-v0.9.18 and later release

@GopherJ have you met this issue before? are we going to bump parity dependencies in next upgrade window? Meanwhile I guess can only test the storage migration with locally setup.

Should use release bin rather than debug one.

pallets/loans/src/types.rs Outdated Show resolved Hide resolved
pallets/loans/src/lib.rs Outdated Show resolved Hide resolved
pallets/loans/src/lib.rs Outdated Show resolved Hide resolved
@yrong
Copy link
Contributor Author

yrong commented Apr 21, 2022

cargo run --bin parallel --release --features try-runtime -- try-runtime --chain heiko-dev --wasm-execution=compiled on-runtime-upgrade live --uri=wss://heiko-rpc.parallel.fi:443

...
2022-04-22 03:48:15 market 100, collateral_factor Permill(500000), loose_collateral_factor Permill(515000), liquidate_incentive_reserved_factor Permill(30000)
2022-04-22 03:48:15 market 0, collateral_factor Permill(50000), loose_collateral_factor Permill(51500), liquidate_incentive_reserved_factor Permill(30000)
2022-04-22 03:48:15 market 5002, collateral_factor Permill(0), loose_collateral_factor Permill(0), liquidate_incentive_reserved_factor Permill(30000)
2022-04-22 03:48:15 market 5004, collateral_factor Permill(0), loose_collateral_factor Permill(0), liquidate_incentive_reserved_factor Permill(30000)
2022-04-22 03:48:15 market 1000, collateral_factor Permill(500000), loose_collateral_factor Permill(515000), liquidate_incentive_reserved_factor Permill(30000)
2022-04-22 03:48:15 market 5003, collateral_factor Permill(0), loose_collateral_factor Permill(0), liquidate_incentive_reserved_factor Permill(30000)
...

migration works as expected

@yrong
Copy link
Contributor Author

yrong commented Apr 21, 2022

there is another issue found during try-runtime test when enable LiquidStakingMigrationV3

2022-04-21 14:53:18 MatchingLedger total_stake_amount: 9101340531076, total_unstake_amount: 0
2022-04-21 14:53:18 MarketCap.get()? 0
2022-04-21 14:53:18 panicked at 'MarketCap storage item not found!', /home/ron/parallel/pallets/liquid-staking/src/migrations.rs:48:9
Error: Input("failed to execute TryRuntime_on_runtime_upgrade: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed\nWASM backtrace:\n\n    0: 0x3fffe1 - <unknown>!rust_begin_unwind\n    1: 0x3aca - <unknown>!core::panicking::panic_fmt::h8f11323637b4db3b\n    2: 0x2aee36 - <unknown>!pallet_liquid_staking::migrations::v3::pre_migrate::hc4bfa8a02883da15\n    3: 0x15539b - <unknown>!frame_executive::Executive<System,Block,Context,UnsignedValidator,AllPalletsWithSystem,COnRuntimeUpgrade>::try_runtime_upgrade::h2aa0c3ccb9f5577f\n    4: 0x3a30f - <unknown>!<heiko_runtime::Runtime as frame_try_runtime::runtime_decl_for_TryRuntime::TryRuntime<sp_runtime::generic::block::Block<sp_runtime::generic::header::Header<u32,sp_runtime::traits::BlakeTwo256>,sp_runtime::generic::unchecked_extrinsic::UncheckedExtrinsic<sp_runtime::multiaddress::MultiAddress<<<sp_runtime::MultiSignature as sp_runtime::traits::Verify>::Signer as sp_runtime::traits::IdentifyAccount>::AccountId,()>,heiko_runtime::Call,sp_runtime::MultiSignature,(frame_system::extensions::check_non_zero_sender::CheckNonZeroSender<heiko_runtime::Runtime>,frame_system::extensions::check_spec_version::CheckSpecVersion<heiko_runtime::Runtime>,frame_system::extensions::check_tx_version::CheckTxVersion<heiko_runtime::Runtime>,frame_system::extensions::check_genesis::CheckGenesis<heiko_runtime::Runtime>,frame_system::extensions::check_mortality::CheckMortality<heiko_runtime::Runtime>,frame_system::extensions::check_nonce::CheckNonce<heiko_runtime::Runtime>,frame_system::extensions::check_weight::CheckWeight<heiko_runtime::Runtime>,pallet_transaction_payment::ChargeTransactionPayment<heiko_runtime::Runtime>)>>>>::on_runtime_upgrade::h9afd690cba0f7838\n    5: 0x265001 - <unknown>!TryRuntime_on_runtime_upgrade\n")

seems LiquidStakingMigrationV3 already removed in heiko runtime migration in master branch, so just ignore this error and will check again after resolve conflicts and merge

still can be reproduced in parallel runtime migration

@yrong yrong changed the title Add incentive reserved ratio & Add loose collateral ratio Add incentive reserved ratio & Add liquidation threshold Apr 22, 2022
pallets/loans/src/lib.rs Outdated Show resolved Hide resolved
pallets/loans/src/lib.rs Outdated Show resolved Hide resolved
pallets/loans/src/lib.rs Outdated Show resolved Hide resolved
@0x8f701
Copy link
Contributor

0x8f701 commented Apr 24, 2022

the CI issue may be caused by rust toolchain version, can you rebase/merge latest master and try again?

@0x8f701
Copy link
Contributor

0x8f701 commented Apr 24, 2022

weird dont know what happened:)

@yrong
Copy link
Contributor Author

yrong commented Apr 25, 2022

weird dont know what happened:)

@GopherJ
test the ci build flow in a forked repo, at least make test is success
https://github.com/yrong/parallel/runs/6147497103?check_suite_focus=true

seems not related to the version of rust, maybe we can remove the cache layer temporarily and try again? Or could we change to self host runner , speed of building in github host is a little slow

@0x8f701
Copy link
Contributor

0x8f701 commented Apr 25, 2022

yes we may think about changing to self hosted runner, I guess we can also remove cache layer it's not very useful actually

@0x8f701 0x8f701 self-requested a review April 25, 2022 04:47
@0x8f701 0x8f701 merged commit df626ab into master Apr 25, 2022
@0x8f701 0x8f701 deleted the ron/reserve-liquidation-incentive branch April 25, 2022 04:48
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