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

Feat/v3.1 #845

Draft
wants to merge 91 commits into
base: rc/v3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 88 commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
c8632cb
allow setting first week epoch in farm
dorin-iancu Feb 12, 2024
d902eb3
fix
dorin-iancu Feb 12, 2024
abad7ad
fix mandos
dorin-iancu Feb 12, 2024
39d6bda
changes
dorin-iancu Feb 12, 2024
4a818dc
setup in farm staking
dorin-iancu Feb 12, 2024
2ed5386
Merge branch 'feat/v3.1' into farm-set-start-week
psorinionut Feb 22, 2024
834166d
Merge pull request #835 from multiversx/farm-set-start-week
psorinionut Feb 22, 2024
c98d1e6
Merge branch 'main' into feat/v3.1
dorin-iancu Mar 8, 2024
b4910e7
Merge pull request #851 from multiversx/merge-with-main-feat-v3.1
dorin-iancu Mar 8, 2024
c8fd624
accumulate boosted rewards
dorin-iancu Mar 8, 2024
06b77a8
fix mandos
dorin-iancu Mar 8, 2024
cda01d3
more mandos fix
dorin-iancu Mar 8, 2024
d128565
allow user to claim unlocked rewards
dorin-iancu Mar 8, 2024
bf91c5f
fix + test
dorin-iancu Mar 8, 2024
22d4c08
impl
dorin-iancu Mar 8, 2024
7b03403
call energy factory
dorin-iancu Mar 11, 2024
dfa420d
fix tests
dorin-iancu Mar 11, 2024
4bab210
unbond test
dorin-iancu Mar 11, 2024
d2fb8c8
fix token type
dorin-iancu Mar 11, 2024
fd67813
fix wrong call
dorin-iancu Mar 11, 2024
8521631
revert fix
dorin-iancu Mar 11, 2024
b24d8c7
simple lock improvements
dorin-iancu Mar 11, 2024
3187b46
test
dorin-iancu Mar 11, 2024
c284e4d
remove import
dorin-iancu Mar 11, 2024
08ade1b
alias
dorin-iancu Mar 11, 2024
0cbd734
claim developer rewards
dorin-iancu Mar 11, 2024
96176e4
small fixes pair
dorin-iancu Mar 12, 2024
637ae26
more pair fixes
dorin-iancu Mar 12, 2024
feab837
copy-paste proxy dex SC
dorin-iancu Mar 12, 2024
43bc868
group code into modules
dorin-iancu Mar 12, 2024
e0d9ad5
attempted fix
dorin-iancu Mar 12, 2024
b550a2d
temp commit
dorin-iancu Mar 12, 2024
7d7c32b
fixes
dorin-iancu Mar 12, 2024
ef30aaa
fix
dorin-iancu Mar 12, 2024
af8a8d1
create pair
dorin-iancu Mar 12, 2024
4b5bca0
opt
dorin-iancu Mar 13, 2024
337591e
revert change
dorin-iancu Mar 13, 2024
89cbd86
rename file
dorin-iancu Mar 13, 2024
91cbd26
create pair user + foundation
dorin-iancu Mar 13, 2024
2df2564
remove liq created pair
dorin-iancu Mar 13, 2024
952b118
fixes
dorin-iancu Mar 13, 2024
ea49cd3
fix existing tests
dorin-iancu Mar 13, 2024
318defd
use common code
dorin-iancu Mar 13, 2024
d04f83f
temp commit
dorin-iancu Mar 13, 2024
bfba5a3
update scs to latest framework version
mihaicalinluca Mar 13, 2024
16b28b4
Merge pull request #860 from multiversx/sc-update
dorin-iancu Mar 14, 2024
d05f9b7
cargo.lock
dorin-iancu Mar 14, 2024
e6f901e
Merge branch 'proxy-dex-xmex' of https://github.com/multiversx/mx-exc…
dorin-iancu Mar 14, 2024
df204af
fix read from storage
dorin-iancu Mar 15, 2024
a6c8d4d
Merge pull request #852 from multiversx/farm-accumulate-boosted-rewards
dorin-iancu Mar 15, 2024
1ecf790
fixes + test
dorin-iancu Mar 15, 2024
9830099
build
dorin-iancu Mar 15, 2024
c63da86
users creates pair from router directly
dorin-iancu Mar 15, 2024
aeb9186
resolve conflicts
dorin-iancu Mar 15, 2024
8c3ef99
opt arg to forced arg
dorin-iancu Mar 15, 2024
6ff3754
fix proxy tests
dorin-iancu Mar 15, 2024
d5c8394
use add initial liq endpoint
dorin-iancu Mar 15, 2024
f7940f4
common code
dorin-iancu Mar 15, 2024
0643cdf
Merge branch 'farm-locked-get-unlocked-rewards' into simple-lock-impr…
dorin-iancu Mar 18, 2024
7775e73
Merge branch 'simple-lock-improvements' into router-claim-developer-r…
dorin-iancu Mar 18, 2024
4b70df2
Merge branch 'router-claim-developer-rewards' into new-proxy-dex-sc
dorin-iancu Mar 18, 2024
d1c14ea
Merge branch 'new-proxy-dex-sc' into reorganize-code
dorin-iancu Mar 18, 2024
71d5305
merge
dorin-iancu Mar 18, 2024
c2fe406
fix decode attr
dorin-iancu Mar 19, 2024
6f2a4b1
remove annotation
dorin-iancu Mar 19, 2024
6f2985f
Merge pull request #853 from multiversx/farm-locked-get-unlocked-rewards
dorin-iancu Mar 20, 2024
5581432
Merge branch 'feat/v3.1' into simple-lock-improvements
dorin-iancu Mar 20, 2024
c3daf89
Merge pull request #855 from multiversx/simple-lock-improvements
dorin-iancu Mar 20, 2024
c602b4d
Merge branch 'feat/v3.1' into router-claim-developer-rewards
dorin-iancu Mar 20, 2024
1d6b276
fix test
dorin-iancu Mar 20, 2024
d4dbfac
Merge branch 'router-claim-developer-rewards' of https://github.com/m…
dorin-iancu Mar 20, 2024
eea8f43
Merge pull request #856 from multiversx/router-claim-developer-rewards
dorin-iancu Mar 21, 2024
e924ff4
Merge branch 'feat/v3.1' into new-proxy-dex-sc
dorin-iancu Mar 21, 2024
275d198
proxy-dex-xmex: Fix compiling issues
CostinCarabas Mar 21, 2024
a962cd4
proxy-dex-xmex: Fix tests
CostinCarabas Mar 21, 2024
28e2dbc
Merge pull request #857 from multiversx/new-proxy-dex-sc
dorin-iancu Mar 25, 2024
3b88b9a
Merge branch 'feat/v3.1' into reorganize-code
dorin-iancu Mar 26, 2024
ea72bf7
Merge pull request #858 from multiversx/reorganize-code
dorin-iancu Mar 27, 2024
5df3b56
conflicts
dorin-iancu Mar 27, 2024
1e3233f
annotation
dorin-iancu Mar 27, 2024
3021f80
more conflicts
dorin-iancu Mar 27, 2024
516d7f4
evil clippy
dorin-iancu Mar 27, 2024
68d9cf9
Merge pull request #859 from multiversx/proxy-dex-xmex
dorin-iancu Apr 1, 2024
5fd5dbc
Merge branch 'feat/v3.1' into farm-staking-decode-old-attr
dorin-iancu Apr 1, 2024
9270d91
Merge pull request #861 from multiversx/farm-staking-decode-old-attr
dorin-iancu Apr 9, 2024
ffe0e92
Merge branch 'rc/v3.0' into feat/v3.1
psorinionut Apr 9, 2024
d2dc1f2
upgrade contract scenario test fix
psorinionut Apr 10, 2024
44a4113
revert pair perfect swap change
psorinionut Apr 10, 2024
daba985
framework upgrade 0.48.1
psorinionut May 20, 2024
31e2a01
pair tests fixes
psorinionut May 20, 2024
bae1441
Merge pull request #919 from multiversx/feat-v3.1-branch-framework-up…
psorinionut May 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
716 changes: 404 additions & 312 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ members = [
"locked-asset/distribution/meta",
"locked-asset/proxy_dex",
"locked-asset/proxy_dex/meta",
"locked-asset/proxy-dex-xmex",
"locked-asset/proxy-dex-xmex/meta",
"locked-asset/lkmex-transfer",
"locked-asset/lkmex-transfer/meta",
"locked-asset/locked-token-wrapper",
Expand Down
2 changes: 1 addition & 1 deletion common/common_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
path = "src/lib.rs"

[dependencies.multiversx-sc]
version = "=0.46.1"
version = "=0.47.5"
features = ["esdt-token-payment-legacy-decode"]
2 changes: 1 addition & 1 deletion common/common_structs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
path = "src/lib.rs"

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

[dependencies.mergeable]
Expand Down
8 changes: 5 additions & 3 deletions common/common_structs/src/wrapper_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use core::ops::Deref;

use unwrappable::Unwrappable;

use crate::{Epoch, Nonce};

static NOT_ENOUGH_RESULTS_ERR_MSG: &[u8] = b"Not enough results";
const FIRST_VEC_INDEX: usize = 0;

Expand All @@ -22,13 +24,13 @@ impl<M: ManagedTypeApi> TokenPair<M> {

#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, TypeAbi)]
pub struct NonceAmountPair<M: ManagedTypeApi> {
pub nonce: u64,
pub nonce: Nonce,
pub amount: BigUint<M>,
}

impl<M: ManagedTypeApi> NonceAmountPair<M> {
#[inline]
pub fn new(nonce: u64, amount: BigUint<M>) -> Self {
pub fn new(nonce: Nonce, amount: BigUint<M>) -> Self {
NonceAmountPair { nonce, amount }
}
}
Expand All @@ -37,7 +39,7 @@ impl<M: ManagedTypeApi> NonceAmountPair<M> {
TypeAbi, TopEncode, TopDecode, NestedEncode, NestedDecode, ManagedVecItem, Clone, Debug,
)]
pub struct EpochAmountPair<M: ManagedTypeApi> {
pub epoch: u64,
pub epoch: Epoch,
pub amount: BigUint<M>,
}

Expand Down
2 changes: 1 addition & 1 deletion common/modules/farm/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ path = "../../pausable"
path = "../../permissions_module"

[dependencies.multiversx-sc]
version = "=0.46.1"
version = "=0.47.5"
features = ["esdt-token-payment-legacy-decode"]
4 changes: 2 additions & 2 deletions common/modules/farm/contexts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ path = "../../pausable"
path = "../../permissions_module"

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

[dependencies.multiversx-sc-modules]
version = "=0.46.1"
version = "=0.47.5"
2 changes: 1 addition & 1 deletion common/modules/farm/events/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ path = "../../../common_structs"
path = "../contexts"

[dependencies.multiversx-sc]
version = "=0.46.1"
version = "=0.47.5"
features = ["esdt-token-payment-legacy-decode"]
6 changes: 3 additions & 3 deletions common/modules/farm/farm_base_impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ path = "../../../traits/mergeable"
path = "../../../traits/fixed-supply-token"

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

[dependencies.multiversx-sc-modules]
version = "=0.46.1"
version = "=0.47.5"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.46.1"
version = "=0.47.5"
6 changes: 3 additions & 3 deletions common/modules/farm/farm_base_impl/src/base_farm_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ pub trait BaseFarmInitModule:

self.state().set(State::Inactive);
self.division_safety_constant()
.set_if_empty(&division_safety_constant);
.set(&division_safety_constant);

self.reward_token_id().set_if_empty(&reward_token_id);
self.farming_token_id().set_if_empty(&farming_token_id);
self.reward_token_id().set(&reward_token_id);
self.farming_token_id().set(&farming_token_id);

if !owner.is_zero() {
self.add_permissions(owner, Permissions::OWNER | Permissions::PAUSE);
Expand Down
74 changes: 49 additions & 25 deletions common/modules/farm/farm_base_impl/src/base_traits_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@ use mergeable::Mergeable;
use multiversx_sc_modules::transfer_role_proxy::PaymentsVec;
use rewards::RewardsModule;

pub struct RewardPair<M: ManagedTypeApi> {
pub base: BigUint<M>,
pub boosted: BigUint<M>,
}

impl<M: ManagedTypeApi> RewardPair<M> {
#[inline]
pub fn new(base: BigUint<M>, boosted: BigUint<M>) -> Self {
Self { base, boosted }
}

#[inline]
pub fn new_zero() -> Self {
Self::new(BigUint::zero(), BigUint::zero())
}

#[inline]
pub fn total_rewards(&self) -> BigUint<M> {
&self.base + &self.boosted
}
}

pub trait AllBaseFarmImplTraits =
rewards::RewardsModule
+ config::ConfigModule
Expand Down Expand Up @@ -63,34 +85,35 @@ pub trait FarmContract {
) -> BigUint<<Self::FarmSc as ContractBase>::Api> {
let current_block_nonce = sc.blockchain().get_block_nonce();
let last_reward_nonce = sc.last_reward_block_nonce().get();
if current_block_nonce > last_reward_nonce {
let to_mint =
Self::calculate_per_block_rewards(sc, current_block_nonce, last_reward_nonce);
if to_mint != 0 {
Self::mint_rewards(sc, token_id, &to_mint);
}

sc.last_reward_block_nonce().set(current_block_nonce);
if current_block_nonce <= last_reward_nonce {
return BigUint::zero();
}

to_mint
} else {
BigUint::zero()
let to_mint = Self::calculate_per_block_rewards(sc, current_block_nonce, last_reward_nonce);
if to_mint != 0 {
Self::mint_rewards(sc, token_id, &to_mint);
}

sc.last_reward_block_nonce().set(current_block_nonce);

to_mint
}

fn generate_aggregated_rewards(
sc: &Self::FarmSc,
storage_cache: &mut StorageCache<Self::FarmSc>,
) {
let total_reward = Self::mint_per_block_rewards(sc, &storage_cache.reward_token_id);
if total_reward > 0u64 {
storage_cache.reward_reserve += &total_reward;
if total_reward == 0u64 {
return;
}

if storage_cache.farm_token_supply != 0u64 {
let increase = (&total_reward * &storage_cache.division_safety_constant)
/ &storage_cache.farm_token_supply;
storage_cache.reward_per_share += &increase;
}
storage_cache.reward_reserve += &total_reward;

if storage_cache.farm_token_supply != 0u64 {
let increase = (&total_reward * &storage_cache.division_safety_constant)
/ &storage_cache.farm_token_supply;
storage_cache.reward_per_share += &increase;
}
}

Expand All @@ -100,14 +123,16 @@ pub trait FarmContract {
farm_token_amount: &BigUint<<Self::FarmSc as ContractBase>::Api>,
token_attributes: &Self::AttributesType,
storage_cache: &StorageCache<Self::FarmSc>,
) -> BigUint<<Self::FarmSc as ContractBase>::Api> {
) -> RewardPair<<Self::FarmSc as ContractBase>::Api> {
let token_rps = token_attributes.get_reward_per_share();
if storage_cache.reward_per_share > token_rps {
let rps_diff = &storage_cache.reward_per_share - &token_rps;
farm_token_amount * &rps_diff / &storage_cache.division_safety_constant
} else {
BigUint::zero()
if storage_cache.reward_per_share <= token_rps {
return RewardPair::new_zero();
}

let rps_diff = &storage_cache.reward_per_share - &token_rps;
let base_rewards = farm_token_amount * &rps_diff / &storage_cache.division_safety_constant;

RewardPair::new(base_rewards, BigUint::zero())
}

fn create_enter_farm_initial_attributes(
Expand Down Expand Up @@ -212,7 +237,6 @@ pub trait FarmContract {
}
}

#[inline]
fn increase_user_farm_position(
sc: &Self::FarmSc,
user: &ManagedAddress<<Self::FarmSc as ContractBase>::Api>,
Expand Down
10 changes: 5 additions & 5 deletions common/modules/farm/farm_base_impl/src/claim_rewards.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
multiversx_sc::imports!();

use crate::base_traits_impl::FarmContract;
use crate::base_traits_impl::{FarmContract, RewardPair};
use common_structs::{PaymentAttributesPair, PaymentsVec};
use contexts::{
claim_rewards_context::ClaimRewardsContext,
Expand All @@ -15,7 +15,7 @@ where
{
pub context: ClaimRewardsContext<C::Api, T>,
pub storage_cache: StorageCache<'a, C>,
pub rewards: EsdtTokenPayment<C::Api>,
pub rewards: RewardPair<C::Api>,
pub new_farm_token: PaymentAttributesPair<C::Api, T>,
pub created_with_merge: bool,
}
Expand Down Expand Up @@ -72,14 +72,14 @@ pub trait BaseClaimRewardsModule:
.clone()
.into_part(farm_token_amount);

let reward = FC::calculate_rewards(
let rewards = FC::calculate_rewards(
self,
&caller,
farm_token_amount,
&token_attributes,
&storage_cache,
);
storage_cache.reward_reserve -= &reward;
storage_cache.reward_reserve -= rewards.total_rewards();

FC::check_and_update_user_farm_position(self, &caller, &payments);

Expand Down Expand Up @@ -112,7 +112,7 @@ pub trait BaseClaimRewardsModule:
InternalClaimRewardsResult {
created_with_merge: !claim_rewards_context.additional_payments.is_empty(),
context: claim_rewards_context,
rewards: EsdtTokenPayment::new(storage_cache.reward_token_id.clone(), 0, reward),
rewards,
new_farm_token,
storage_cache,
}
Expand Down
13 changes: 7 additions & 6 deletions common/modules/farm/farm_base_impl/src/compound_rewards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ pub trait BaseCompoundRewardsModule:
.clone()
.into_part(farm_token_amount);

let reward = FC::calculate_rewards(
let rewards = FC::calculate_rewards(
self,
&caller,
farm_token_amount,
&token_attributes,
&storage_cache,
);
storage_cache.reward_reserve -= &reward;
storage_cache.farm_token_supply += &reward;
let total_rewards = rewards.total_rewards();
storage_cache.reward_reserve -= &total_rewards;
storage_cache.farm_token_supply += &total_rewards;

FC::check_and_update_user_farm_position(self, &caller, &payments);

Expand All @@ -78,15 +79,15 @@ pub trait BaseCompoundRewardsModule:
caller.clone(),
token_attributes,
storage_cache.reward_per_share.clone(),
&reward,
&total_rewards,
);
let new_farm_token = self.merge_and_create_token(
base_attributes,
&compound_rewards_context.additional_payments,
&farm_token_mapper,
);

FC::increase_user_farm_position(self, &caller, &reward);
FC::increase_user_farm_position(self, &caller, &total_rewards);

let first_farm_token = &compound_rewards_context.first_farm_token.payment;
farm_token_mapper.nft_burn(first_farm_token.token_nonce, &first_farm_token.amount);
Expand All @@ -97,7 +98,7 @@ pub trait BaseCompoundRewardsModule:
created_with_merge: !compound_rewards_context.additional_payments.is_empty(),
context: compound_rewards_context,
new_farm_token,
compounded_rewards: reward,
compounded_rewards: total_rewards,
storage_cache,
}
}
Expand Down
26 changes: 25 additions & 1 deletion common/modules/farm/farm_base_impl/src/enter_farm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use contexts::{
enter_farm_context::EnterFarmContext,
storage_cache::{FarmContracTraitBounds, StorageCache},
};
use fixed_supply_token::FixedSupplyToken;

pub struct InternalEnterFarmResult<'a, C, T>
where
Expand Down Expand Up @@ -34,6 +35,21 @@ pub trait BaseEnterFarmModule:
&self,
caller: ManagedAddress,
payments: PaymentsVec<Self::Api>,
) -> InternalEnterFarmResult<Self, FC::AttributesType> {
let mut result = self.enter_farm_base_no_token_create::<FC>(caller, payments);
let new_farm_token_payment = self.farm_token().nft_create(
result.new_farm_token.payment.amount,
&result.new_farm_token.attributes,
);
result.new_farm_token.payment = new_farm_token_payment;

result
}

fn enter_farm_base_no_token_create<FC: FarmContract<FarmSc = Self>>(
&self,
caller: ManagedAddress,
payments: PaymentsVec<Self::Api>,
) -> InternalEnterFarmResult<Self, FC::AttributesType> {
let mut storage_cache = StorageCache::new(self);
self.validate_contract_state(storage_cache.contract_state, &storage_cache.farm_token_id);
Expand Down Expand Up @@ -67,11 +83,19 @@ pub trait BaseEnterFarmModule:
enter_farm_context.farming_token_payment.amount.clone(),
storage_cache.reward_per_share.clone(),
);
let new_farm_token = self.merge_and_create_token(
let new_token_attributes = self.merge_attributes_from_payments(
base_attributes,
&enter_farm_context.additional_farm_tokens,
&farm_token_mapper,
);
let new_farm_token = PaymentAttributesPair {
payment: EsdtTokenPayment::new(
storage_cache.farm_token_id.clone(),
0,
new_token_attributes.get_total_supply(),
),
attributes: new_token_attributes,
};

self.send()
.esdt_local_burn_multi(&enter_farm_context.additional_farm_tokens);
Expand Down
Loading
Loading