From d4ba9c542f323fff60492bdb9b491f5f6ab70661 Mon Sep 17 00:00:00 2001 From: 0xrjman Date: Wed, 31 Jul 2024 15:01:57 +0800 Subject: [PATCH 1/4] Allow non-incremental farming rewards (#1978) Co-authored-by: dio-will --- pallets/loans/src/lib.rs | 17 +++++++++++------ runtime/heiko/src/lib.rs | 2 +- runtime/kerria/src/lib.rs | 2 +- runtime/parallel/src/lib.rs | 2 +- runtime/vanilla/src/lib.rs | 2 +- scripts/collator.sh | 2 +- 6 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pallets/loans/src/lib.rs b/pallets/loans/src/lib.rs index 43b888377..788ccc3d4 100644 --- a/pallets/loans/src/lib.rs +++ b/pallets/loans/src/lib.rs @@ -1425,7 +1425,7 @@ impl Pallet { Self::update_reward_supply_index(asset_id)?; Self::distribute_supplier_reward(asset_id, who)?; - let exchange_rate = Self::exchange_rate_stored(asset_id)?; + let exchange_rate: FixedU128 = Self::exchange_rate_stored(asset_id)?; let redeem_amount = Self::calc_underlying_amount(voucher_amount, exchange_rate)?; AccountDeposits::::try_mutate_exists(asset_id, who, |deposits| -> DispatchResult { @@ -1538,11 +1538,16 @@ impl Pallet { ) -> DispatchResult { let deposits = AccountDeposits::::get(asset_id, who); let account_earned = AccountEarned::::get(asset_id, who); - let total_earned_prior_new = exchange_rate - .checked_sub(&account_earned.exchange_rate_prior) - .and_then(|r| r.checked_mul_int(deposits.voucher_balance)) - .and_then(|r| r.checked_add(account_earned.total_earned_prior)) - .ok_or(ArithmeticError::Overflow)?; + + let total_earned_prior_new = if exchange_rate >= account_earned.exchange_rate_prior { + exchange_rate + .checked_sub(&account_earned.exchange_rate_prior) + .and_then(|delta| delta.checked_mul_int(deposits.voucher_balance)) + .and_then(|result| result.checked_add(account_earned.total_earned_prior)) + .ok_or(ArithmeticError::Overflow)? + } else { + account_earned.total_earned_prior + }; AccountEarned::::insert( asset_id, diff --git a/runtime/heiko/src/lib.rs b/runtime/heiko/src/lib.rs index 6f7ca8592..108238235 100644 --- a/runtime/heiko/src/lib.rs +++ b/runtime/heiko/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("heiko"), impl_name: create_runtime_str!("heiko"), authoring_version: 1, - spec_version: 207, + spec_version: 208, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/kerria/src/lib.rs b/runtime/kerria/src/lib.rs index 528f1ced6..e33503ff7 100644 --- a/runtime/kerria/src/lib.rs +++ b/runtime/kerria/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("kerria"), impl_name: create_runtime_str!("kerria"), authoring_version: 1, - spec_version: 207, + spec_version: 208, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index 42a82d956..0b9366ad1 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -185,7 +185,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("parallel"), impl_name: create_runtime_str!("parallel"), authoring_version: 1, - spec_version: 207, + spec_version: 208, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/vanilla/src/lib.rs b/runtime/vanilla/src/lib.rs index fd4836115..338ddc308 100644 --- a/runtime/vanilla/src/lib.rs +++ b/runtime/vanilla/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("vanilla"), impl_name: create_runtime_str!("vanilla"), authoring_version: 1, - spec_version: 207, + spec_version: 208, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/scripts/collator.sh b/scripts/collator.sh index 5390e2b2d..05fc078b2 100755 --- a/scripts/collator.sh +++ b/scripts/collator.sh @@ -20,7 +20,7 @@ VOLUME="chains" NODE_KEY="$1" KEYSTORE_PATH="$2" NODE_NAME="$3" -DOCKER_IMAGE="parallelfinance/parallel:v2.0.7" +DOCKER_IMAGE="parallelfinance/parallel:v2.0.8" BASE_PATH="/data" if [ $# -lt 3 ]; then From b1056269d694aef17034a3fef90f6bd805cd69b0 Mon Sep 17 00:00:00 2001 From: 0xrjman Date: Wed, 31 Jul 2024 16:22:56 +0800 Subject: [PATCH 2/4] Bump to version 209 (#1979) * Allow non-incremental farming rewards * bump to version 209 --------- Co-authored-by: dio-will --- runtime/heiko/src/lib.rs | 2 +- runtime/kerria/src/lib.rs | 2 +- runtime/parallel/src/lib.rs | 2 +- runtime/vanilla/src/lib.rs | 2 +- scripts/collator.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/heiko/src/lib.rs b/runtime/heiko/src/lib.rs index 108238235..c031b2f30 100644 --- a/runtime/heiko/src/lib.rs +++ b/runtime/heiko/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("heiko"), impl_name: create_runtime_str!("heiko"), authoring_version: 1, - spec_version: 208, + spec_version: 209, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/kerria/src/lib.rs b/runtime/kerria/src/lib.rs index e33503ff7..1fb5a5d45 100644 --- a/runtime/kerria/src/lib.rs +++ b/runtime/kerria/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("kerria"), impl_name: create_runtime_str!("kerria"), authoring_version: 1, - spec_version: 208, + spec_version: 209, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index 0b9366ad1..7defcd91d 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -185,7 +185,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("parallel"), impl_name: create_runtime_str!("parallel"), authoring_version: 1, - spec_version: 208, + spec_version: 209, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/vanilla/src/lib.rs b/runtime/vanilla/src/lib.rs index 338ddc308..b9fc400f9 100644 --- a/runtime/vanilla/src/lib.rs +++ b/runtime/vanilla/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("vanilla"), impl_name: create_runtime_str!("vanilla"), authoring_version: 1, - spec_version: 208, + spec_version: 209, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/scripts/collator.sh b/scripts/collator.sh index 05fc078b2..a6f6b796c 100755 --- a/scripts/collator.sh +++ b/scripts/collator.sh @@ -20,7 +20,7 @@ VOLUME="chains" NODE_KEY="$1" KEYSTORE_PATH="$2" NODE_NAME="$3" -DOCKER_IMAGE="parallelfinance/parallel:v2.0.8" +DOCKER_IMAGE="parallelfinance/parallel:v2.0.9" BASE_PATH="/data" if [ $# -lt 3 ]; then From 13dc9c84c60bf57ab52a0c2387dbd62b97883b4d Mon Sep 17 00:00:00 2001 From: dio-will Date: Thu, 8 Aug 2024 15:30:04 +0800 Subject: [PATCH 3/4] Update MIN_VALID_EXCHANGE_RATE for loans --- pallets/loans/src/interest.rs | 4 ++-- pallets/loans/src/lib.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pallets/loans/src/interest.rs b/pallets/loans/src/interest.rs index 7176c2033..93f2d9a4d 100644 --- a/pallets/loans/src/interest.rs +++ b/pallets/loans/src/interest.rs @@ -151,10 +151,10 @@ impl Pallet { Ok(Ratio::from_rational(borrows, total)) } - /// The exchange rate should be greater than 0.02 and less than 1 + /// The exchange rate should be greater than 0.015 and less than 1 pub(crate) fn ensure_valid_exchange_rate(exchange_rate: Rate) -> DispatchResult { ensure!( - exchange_rate >= Rate::from_inner(MIN_EXCHANGE_RATE) + exchange_rate >= Rate::from_inner(MIN_VALID_EXCHANGE_RATE) && exchange_rate < Rate::from_inner(MAX_EXCHANGE_RATE), Error::::InvalidExchangeRate ); diff --git a/pallets/loans/src/lib.rs b/pallets/loans/src/lib.rs index 788ccc3d4..4091ee513 100644 --- a/pallets/loans/src/lib.rs +++ b/pallets/loans/src/lib.rs @@ -80,6 +80,7 @@ pub const MIN_INTEREST_CALCULATING_INTERVAL: u64 = 100; // 100 seconds pub const MAX_EXCHANGE_RATE: u128 = 1_000_000_000_000_000_000; // 1 pub const MIN_EXCHANGE_RATE: u128 = 20_000_000_000_000_000; // 0.02 +pub const MIN_VALID_EXCHANGE_RATE: u128 = 15_000_000_000_000_000; // 0.015 type AccountIdOf = ::AccountId; type AssetIdOf = From 637d95003fbd9dc62685f1d93fbdc5b38e9d911e Mon Sep 17 00:00:00 2001 From: dio-will Date: Thu, 8 Aug 2024 15:38:47 +0800 Subject: [PATCH 4/4] Bump to spec 210 --- runtime/heiko/src/lib.rs | 2 +- runtime/kerria/src/lib.rs | 2 +- runtime/parallel/src/lib.rs | 2 +- runtime/vanilla/src/lib.rs | 2 +- scripts/collator.sh | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/heiko/src/lib.rs b/runtime/heiko/src/lib.rs index c031b2f30..857331596 100644 --- a/runtime/heiko/src/lib.rs +++ b/runtime/heiko/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("heiko"), impl_name: create_runtime_str!("heiko"), authoring_version: 1, - spec_version: 209, + spec_version: 210, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/kerria/src/lib.rs b/runtime/kerria/src/lib.rs index 1fb5a5d45..a1ae7a6e3 100644 --- a/runtime/kerria/src/lib.rs +++ b/runtime/kerria/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("kerria"), impl_name: create_runtime_str!("kerria"), authoring_version: 1, - spec_version: 209, + spec_version: 210, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/parallel/src/lib.rs b/runtime/parallel/src/lib.rs index 7defcd91d..4623e76ad 100644 --- a/runtime/parallel/src/lib.rs +++ b/runtime/parallel/src/lib.rs @@ -185,7 +185,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("parallel"), impl_name: create_runtime_str!("parallel"), authoring_version: 1, - spec_version: 209, + spec_version: 210, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/runtime/vanilla/src/lib.rs b/runtime/vanilla/src/lib.rs index b9fc400f9..e2dcfe135 100644 --- a/runtime/vanilla/src/lib.rs +++ b/runtime/vanilla/src/lib.rs @@ -180,7 +180,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("vanilla"), impl_name: create_runtime_str!("vanilla"), authoring_version: 1, - spec_version: 209, + spec_version: 210, impl_version: 33, apis: RUNTIME_API_VERSIONS, transaction_version: 17, diff --git a/scripts/collator.sh b/scripts/collator.sh index a6f6b796c..46818597d 100755 --- a/scripts/collator.sh +++ b/scripts/collator.sh @@ -20,7 +20,7 @@ VOLUME="chains" NODE_KEY="$1" KEYSTORE_PATH="$2" NODE_NAME="$3" -DOCKER_IMAGE="parallelfinance/parallel:v2.0.9" +DOCKER_IMAGE="parallelfinance/parallel:v2.1.0" BASE_PATH="/data" if [ $# -lt 3 ]; then