Skip to content

Commit

Permalink
Allow non-incremental farming rewards (#1978)
Browse files Browse the repository at this point in the history
Co-authored-by: dio-will <[email protected]>
  • Loading branch information
0xrjman and dio-will authored Jul 31, 2024
1 parent 7663d7f commit d4ba9c5
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions pallets/loans/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,7 +1425,7 @@ impl<T: Config> Pallet<T> {
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::<T>::try_mutate_exists(asset_id, who, |deposits| -> DispatchResult {
Expand Down Expand Up @@ -1538,11 +1538,16 @@ impl<T: Config> Pallet<T> {
) -> DispatchResult {
let deposits = AccountDeposits::<T>::get(asset_id, who);
let account_earned = AccountEarned::<T>::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::<T>::insert(
asset_id,
Expand Down
2 changes: 1 addition & 1 deletion runtime/heiko/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/kerria/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/parallel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion runtime/vanilla/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion scripts/collator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4ba9c5

Please sign in to comment.