Skip to content

Commit

Permalink
Merge pull request #19 from multiversx/framework-upgrade-0.45.2
Browse files Browse the repository at this point in the history
framework upgrade 0.45.2
  • Loading branch information
psorinionut authored Dec 27, 2023
2 parents 7431bd8 + e9b1a78 commit b642dd1
Show file tree
Hide file tree
Showing 19 changed files with 691 additions and 2,179 deletions.
1,144 changes: 269 additions & 875 deletions Cargo.lock

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions common/common_structs/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "common_structs"
version = "0.0.0"
authors = ["MultiversX <[email protected]>"]
edition = "2021"

[lib]
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "=0.45.2"
features = ["esdt-token-payment-legacy-decode"]

[dependencies.mergeable]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "4be981b"
8 changes: 8 additions & 0 deletions common/common_structs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![no_std]

multiversx_sc::imports!();
multiversx_sc::derive_imports!();

pub mod unique_payments;

pub use unique_payments::*;
133 changes: 133 additions & 0 deletions common/common_structs/src/unique_payments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use mergeable::Mergeable;

pub type PaymentsVec<M> = ManagedVec<M, EsdtTokenPayment<M>>;

#[derive(TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, Clone, PartialEq, Debug)]
pub struct UniquePayments<M: ManagedTypeApi> {
payments: PaymentsVec<M>,
}

impl<M: ManagedTypeApi> Default for UniquePayments<M> {
#[inline]
fn default() -> Self {
Self {
payments: PaymentsVec::new(),
}
}
}

impl<M: ManagedTypeApi> UniquePayments<M> {
#[inline]
pub fn new() -> Self {
Self::default()
}

#[inline]
pub fn new_from_unique_payments(payments: PaymentsVec<M>) -> Self {
UniquePayments { payments }
}

pub fn new_from_payments(payments: PaymentsVec<M>) -> Self {
let mut merged_payments = Self::new();
for p in &payments {
merged_payments.add_payment(p);
}

merged_payments
}

pub fn add_payment(&mut self, new_payment: EsdtTokenPayment<M>) {
if new_payment.amount == 0 {
return;
}

let len = self.payments.len();
for i in 0..len {
let mut current_payment = self.payments.get(i);
if !current_payment.can_merge_with(&new_payment) {
continue;
}

current_payment.amount += new_payment.amount;
let _ = self.payments.set(i, &current_payment);

return;
}

self.payments.push(new_payment);
}
#[allow(clippy::result_unit_err)]
pub fn deduct_payment(&mut self, payment: &EsdtTokenPayment<M>) -> Result<(), ()> {
if payment.amount == 0 {
return Result::Ok(());
}

let len = self.payments.len();
for i in 0..len {
let mut current_payment = self.payments.get(i);
if !current_payment.can_merge_with(payment) {
continue;
}

if current_payment.amount < payment.amount {
return Result::Err(());
}

current_payment.amount -= &payment.amount;
let _ = self.payments.set(i, &current_payment);

return Result::Ok(());
}

Result::Err(())
}

#[inline]
pub fn into_payments(self) -> PaymentsVec<M> {
self.payments
}
}

impl<M: ManagedTypeApi> Mergeable<M> for UniquePayments<M> {
#[inline]
fn can_merge_with(&self, _other: &Self) -> bool {
true
}

fn merge_with(&mut self, mut other: Self) {
self.error_if_not_mergeable(&other);

if self.payments.is_empty() {
self.payments = other.payments;
return;
}
if other.payments.is_empty() {
return;
}

let first_len = self.payments.len();
let mut second_len = other.payments.len();
for i in 0..first_len {
let mut current_payment = self.payments.get(i);
for j in 0..second_len {
let other_payment = other.payments.get(j);
if !current_payment.can_merge_with(&other_payment) {
continue;
}

current_payment.amount += other_payment.amount;
let _ = self.payments.set(i, &current_payment);

other.payments.remove(j);
second_len -= 1;

break;
}
}

self.payments.append_vec(other.payments);
}
}
2 changes: 1 addition & 1 deletion common/common_subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ path = "src/common_subscriber.rs"
path = "../../subscription-fee"

[dependencies.multiversx-sc]
version = "=0.45.1"
version = "=0.45.2"
35 changes: 17 additions & 18 deletions farm-boosted-rewards-subscriber/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,39 @@ publish = false
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "=0.45.1"
version = "=0.45.2"

[dependencies.multiversx-sc-modules]
version = "=0.45.1"

[dependencies.auto-farm]
git = "https://github.com/multiversx/mx-exchange-tools-sc"
rev = "1416a8b"
version = "=0.45.2"

[dependencies.subscription-fee]
path = "../subscription-fee"

[dependencies.common_subscriber]
path = "../common/common_subscriber"

[dependencies.common_structs]
path = "../common/common_structs"

[dependencies.energy-query]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dependencies.energy-factory]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dependencies.pair]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dependencies.farm-with-locked-rewards]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dependencies.config]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies]
num-bigint = "0.4.2"
Expand All @@ -52,27 +51,27 @@ hex-literal = "0.3.4"

[dev-dependencies.farm-boosted-yields]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.pausable]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.farm_token]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.sc_whitelist_module]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.simple-lock]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.locking_module]
git = "https://github.com/multiversx/mx-exchange-sc"
rev = "56a8e77"
rev = "4be981b"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.45.1"
version = "=0.45.2"
2 changes: 1 addition & 1 deletion farm-boosted-rewards-subscriber/meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ authors = ["you"]
path = ".."

[dependencies.multiversx-sc-meta]
version = "=0.45.1"
version = "=0.45.2"
default-features = false
2 changes: 1 addition & 1 deletion farm-boosted-rewards-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use auto_farm::common::unique_payments::UniquePayments;
use common_structs::UniquePayments;
use subscriber_config::MexActionsPercentages;
use subscription_fee::subtract_payments::Epoch;

Expand Down
2 changes: 1 addition & 1 deletion farm-boosted-rewards-subscriber/src/subscriber_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use auto_farm::common::unique_payments::UniquePayments;
use common_structs::UniquePayments;
use config::ProxyTrait as _;
use subscription_fee::subtract_payments::Epoch;

Expand Down
Loading

0 comments on commit b642dd1

Please sign in to comment.