From 385f212347605804c23f6d25a6090259c03d213a Mon Sep 17 00:00:00 2001 From: dio-will Date: Wed, 31 Jul 2024 14:57:17 +0800 Subject: [PATCH] Allow non-incremental farming rewards --- 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