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

Farm energy fix #920

Draft
wants to merge 69 commits into
base: feat/v3.1
Choose a base branch
from
Draft
Changes from 12 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
44cbbf1
Farm tests with original caller merge fix
psorinionut Apr 8, 2024
e4cfd13
clippy fixes
psorinionut Apr 8, 2024
80bcfba
Merge branch 'rc/v3.0' into farm-tests-with-original-caller-merge-fix
dorin-iancu Apr 9, 2024
dd4cb71
Github actions on rc branches
psorinionut Apr 9, 2024
c2a2d27
Merge pull request #881 from multiversx/github-actions-rc-branches
psorinionut Apr 9, 2024
4aaa01f
Merge branch 'rc/v3.0' into farm-tests-with-original-caller-merge-fix
psorinionut Apr 9, 2024
b21ea70
Router check pair refactor
psorinionut Apr 10, 2024
16f0d72
clippy fixes
psorinionut Apr 10, 2024
e09da89
framework update v0.48.0
psorinionut Apr 11, 2024
b01507b
add check on enable swap by user
psorinionut Apr 11, 2024
19e8ce3
Farm staking merge fix + unit tests
psorinionut Apr 11, 2024
74c16af
use FarmStakingWrapper for merge endpoint
psorinionut Apr 12, 2024
154b56a
Merge pull request #875 from multiversx/farm-tests-with-original-call…
psorinionut Apr 12, 2024
04ecfe4
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 12, 2024
0d174b9
Merge branch 'rc/v3.0' into framework-upgrade-v0.48.0
andrei-marinica Apr 12, 2024
7bdcf2f
Merge pull request #887 from multiversx/framework-upgrade-v0.48.0
andrei-marinica Apr 12, 2024
4463206
upgrade annotation
andrei-marinica Apr 12, 2024
0f92c4f
cargo fmt
andrei-marinica Apr 12, 2024
cb32307
Merge pull request #889 from multiversx/upgrade-annotation
andrei-marinica Apr 12, 2024
1f215e6
Merge branch 'rc/v3.0' into router-check-is-pair-refactor
psorinionut Apr 12, 2024
88ab1ca
router fix after framework upgrade
psorinionut Apr 12, 2024
baa4c13
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 12, 2024
c572908
energy factory tests
psorinionut Apr 12, 2024
ef12603
remove unneeded check
psorinionut Apr 15, 2024
6b5442e
total farm position through simple lock test
psorinionut Apr 15, 2024
f9b5a0d
farm updated tests
psorinionut Apr 15, 2024
ec4b550
add back the router reverse check pair logic
psorinionut Apr 16, 2024
954d65c
code cleanup
psorinionut Apr 16, 2024
a97b9c3
Merge pull request #886 from multiversx/router-check-is-pair-refactor
psorinionut Apr 16, 2024
6c2a608
farm staking proxy unit tests
psorinionut Apr 16, 2024
a470bc3
Merge branch 'rc/v3.0' into farm-staking-tests-with-merge-fix
psorinionut Apr 16, 2024
4544a92
merge logic update orig owner in a separate fn for safer future impl …
psorinionut Apr 16, 2024
27085fb
Merge pull request #888 from multiversx/farm-staking-tests-with-merge…
psorinionut Apr 17, 2024
08ef135
Merge branch 'rc/v3.0' into v3.0-various-unit-tests
psorinionut Apr 17, 2024
ee10fe1
clippy fixes
psorinionut Apr 18, 2024
fe7e92d
Proxy-dex: farm: original caller negative test
CostinCarabas Apr 23, 2024
e993235
original caller merge fix
psorinionut Apr 23, 2024
031b36a
proxy_dex: more unit tests
CostinCarabas Apr 23, 2024
6516b36
farm staking additional tests
psorinionut Apr 24, 2024
6eb7113
proxy_dex: more unit tests
CostinCarabas Apr 24, 2024
1a1f276
code coverage update
psorinionut Apr 24, 2024
01a0959
Merge pull request #897 from multiversx/original-caller-merge-fix
psorinionut Apr 29, 2024
aed790b
Merge branch 'rc/v3.0' into v3.0-various-unit-tests
psorinionut Apr 29, 2024
6101651
Merge pull request #890 from multiversx/v3.0-various-unit-tests
psorinionut Apr 29, 2024
5587d14
Merge branch 'rc/v3.0' into additional-farm-staking-tests
psorinionut Apr 29, 2024
9c04db5
clippy fixes
psorinionut Apr 29, 2024
19c6abf
Merge pull request #898 from multiversx/additional-farm-staking-tests
psorinionut Apr 29, 2024
a222bd3
Merge branch 'rc/v3.0' into github-actions-code-coverage-update
psorinionut Apr 29, 2024
0ef7b61
Merge branch 'rc/v3.0' into proxy-dex-unit-tests
psorinionut Apr 29, 2024
e3c3196
Merge pull request #899 from multiversx/proxy-dex-unit-tests
psorinionut Apr 29, 2024
7713e19
Merge branch 'rc/v3.0' into github-actions-code-coverage-update
psorinionut Apr 29, 2024
effd81c
force rebuild github actions
psorinionut Apr 29, 2024
297cf73
Merge pull request #900 from multiversx/github-actions-code-coverage-…
psorinionut Apr 29, 2024
1761d54
Total farm position test in proxy dex
psorinionut Apr 29, 2024
77218ba
Merge pull request #903 from multiversx/proxy-dex-total-farm-position…
psorinionut Apr 29, 2024
8e8d180
Metastaking claim total farm position fix
psorinionut May 1, 2024
db82bb5
Merge pull request #904 from multiversx/metastaking-total-farm-positi…
psorinionut May 3, 2024
067064b
Energy factory unit test audit update
psorinionut May 7, 2024
867a88d
clippy fix
psorinionut May 9, 2024
c8f3f21
farm energy fix
dorin-iancu May 13, 2024
d8a5d6f
more fixes + test
dorin-iancu May 13, 2024
4578311
fix for old users
dorin-iancu May 13, 2024
9803759
proxy dex unit tests audit update
psorinionut May 14, 2024
23f0e2d
Merge pull request #905 from multiversx/energy-factory-unit-test-audi…
psorinionut May 14, 2024
eebb627
Merge branch 'rc/v3.0' into proxy-dex-unit-tests-update
psorinionut May 14, 2024
55088f8
proxy dex unit test scenario improvement
psorinionut May 14, 2024
3f2314a
Merge branch 'rc/v3.0' into farm-energy-fix
dorin-iancu May 15, 2024
a0671e6
Merge pull request #912 from multiversx/proxy-dex-unit-tests-update
psorinionut May 15, 2024
fab29de
Merge branch 'rc/v3.0' into farm-energy-fix
psorinionut May 15, 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
33 changes: 25 additions & 8 deletions dex/router/src/config.rs
Original file line number Diff line number Diff line change
@@ -2,18 +2,38 @@ multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use crate::{enable_swap_by_user::EnableSwapByUserConfig, factory::PairTokens};
use pair::read_pair_storage;

#[multiversx_sc::module]
pub trait ConfigModule {
pub trait ConfigModule: read_pair_storage::ReadPairStorageModule {
fn is_active(&self) -> bool {
self.state().get()
}

fn check_is_pair_sc(&self, pair_address: &ManagedAddress) {
require!(
self.address_pair_map().contains_key(pair_address),
"Not a pair SC"
);
let first_token_id = self.get_first_token_id_mapper(pair_address.clone()).get();
let second_token_id = self.get_second_token_id_mapper(pair_address.clone()).get();

let pair_tokens = PairTokens {
first_token_id: first_token_id.clone(),
second_token_id: second_token_id.clone(),
};

let mut pair_map_address_opt = self.pair_map().get(&pair_tokens);
if pair_map_address_opt.is_none() {
let reverse_pair_tokens = PairTokens {
first_token_id: second_token_id.clone(),
second_token_id: first_token_id.clone(),
};
pair_map_address_opt = self.pair_map().get(&reverse_pair_tokens);
}

require!(pair_map_address_opt.is_some(), "Not a pair SC");

unsafe {
let pair_map_address = pair_map_address_opt.unwrap_unchecked();
require!(&pair_map_address == pair_address, "Not a pair SC");
}
}

#[view(getPairCreationEnabled)]
@@ -43,9 +63,6 @@ pub trait ConfigModule {
#[storage_mapper("pair_map")]
fn pair_map(&self) -> MapMapper<PairTokens<Self::Api>, ManagedAddress>;

#[storage_mapper("address_pair_map")]
fn address_pair_map(&self) -> MapMapper<ManagedAddress, PairTokens<Self::Api>>;

#[view(getPairTemplateAddress)]
#[storage_mapper("pair_template_address")]
fn pair_template_address(&self) -> SingleValueMapper<ManagedAddress>;
28 changes: 2 additions & 26 deletions dex/router/src/contract.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ pub mod multi_pair_swap;
use factory::PairTokens;
use pair::config::ProxyTrait as _;
use pair::fee::ProxyTrait as _;
use pair::ProxyTrait as _;
use pair::{read_pair_storage, ProxyTrait as _};
use pausable::ProxyTrait as _;

const LP_TOKEN_DECIMALS: usize = 18;
@@ -26,6 +26,7 @@ const USER_DEFINED_TOTAL_FEE_PERCENT: u64 = 1_000;
#[multiversx_sc::contract]
pub trait Router:
config::ConfigModule
+ read_pair_storage::ReadPairStorageModule
+ factory::FactoryModule
+ events::EventsModule
+ multi_pair_swap::MultiPairSwap
@@ -64,10 +65,6 @@ pub trait Router:
#[endpoint]
fn resume(&self, address: ManagedAddress) {
if address == self.blockchain().get_sc_address() {
require!(
self.pair_map().len() == self.address_pair_map().len(),
"The size of the 2 pair maps is not the same"
);
self.state().set(true);
} else {
self.check_is_pair_sc(&address);
@@ -317,8 +314,6 @@ pub trait Router:
.unwrap_or_else(ManagedAddress::zero);
}

self.address_pair_map().remove(&pair_address);

pair_address
}

@@ -385,23 +380,4 @@ pub trait Router:
fn set_pair_creation_enabled(&self, enabled: bool) {
self.pair_creation_enabled().set(enabled);
}

#[only_owner]
#[endpoint(migratePairMap)]
fn migrate_pair_map(&self) {
let pair_map = self.pair_map();
let mut address_pair_map = self.address_pair_map();
require!(
address_pair_map.is_empty(),
"The destination mapper must be empty"
);
for (pair_tokens, address) in pair_map.iter() {
address_pair_map.insert(address, pair_tokens);
}

require!(
pair_map.len() == address_pair_map.len(),
"The size of the 2 pair maps is not the same"
);
}
}
8 changes: 6 additions & 2 deletions dex/router/src/enable_swap_by_user.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _};
use pair::{config::ProxyTrait as _, pair_actions::views::ProxyTrait as _, read_pair_storage};
use pausable::{ProxyTrait as _, State};
use simple_lock::locked_token::LockedTokenAttributes;

@@ -27,7 +27,10 @@ pub struct SafePriceResult<M: ManagedTypeApi> {

#[multiversx_sc::module]
pub trait EnableSwapByUserModule:
config::ConfigModule + crate::factory::FactoryModule + crate::events::EventsModule
config::ConfigModule
+ read_pair_storage::ReadPairStorageModule
+ crate::factory::FactoryModule
+ crate::events::EventsModule
{
#[only_owner]
#[endpoint(configEnableByUserParameters)]
@@ -83,6 +86,7 @@ pub trait EnableSwapByUserModule:
#[payable("*")]
#[endpoint(setSwapEnabledByUser)]
fn set_swap_enabled_by_user(&self, pair_address: ManagedAddress) {
require!(self.is_active(), "Not active");
self.check_is_pair_sc(&pair_address);
self.require_state_active_no_swaps(&pair_address);

17 changes: 2 additions & 15 deletions dex/router/src/factory.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use crate::config;
use pair::read_pair_storage;

const TEMPORARY_OWNER_PERIOD_BLOCKS: u64 = 50;

@@ -19,7 +20,7 @@ pub struct PairContractMetadata<M: ManagedTypeApi> {
}

#[multiversx_sc::module]
pub trait FactoryModule: config::ConfigModule {
pub trait FactoryModule: config::ConfigModule + read_pair_storage::ReadPairStorageModule {
#[proxy]
fn pair_contract_deploy_proxy(&self) -> pair::Proxy<Self::Api>;

@@ -71,13 +72,6 @@ pub trait FactoryModule: config::ConfigModule {
},
new_address.clone(),
);
self.address_pair_map().insert(
new_address.clone(),
PairTokens {
first_token_id: first_token_id.clone(),
second_token_id: second_token_id.clone(),
},
);
self.pair_temporary_owner().insert(
new_address.clone(),
(
@@ -174,13 +168,6 @@ pub trait FactoryModule: config::ConfigModule {
address
}

#[view(getPairTokens)]
fn get_pair_tokens(&self, pair_address: ManagedAddress) -> PairTokens<Self::Api> {
let pair_tokens_opt = self.address_pair_map().get(&pair_address);
require!(pair_tokens_opt.is_some(), "Pair address not found");
pair_tokens_opt.unwrap()
}

fn get_pair_temporary_owner(&self, pair_address: &ManagedAddress) -> Option<ManagedAddress> {
let result = self.pair_temporary_owner().get(pair_address);

11 changes: 6 additions & 5 deletions dex/router/src/multi_pair_swap.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use pair::pair_actions::swap::ProxyTrait as _;

use crate::config;

use super::factory;
use crate::config;
use pair::{pair_actions::swap::ProxyTrait as _, read_pair_storage};

type SwapOperationType<M> =
MultiValue4<ManagedAddress<M>, ManagedBuffer<M>, TokenIdentifier<M>, BigUint<M>>;
@@ -15,7 +13,10 @@ pub const SWAP_TOKENS_FIXED_OUTPUT_FUNC_NAME: &[u8] = b"swapTokensFixedOutput";

#[multiversx_sc::module]
pub trait MultiPairSwap:
config::ConfigModule + factory::FactoryModule + token_send::TokenSendModule
config::ConfigModule
+ read_pair_storage::ReadPairStorageModule
+ factory::FactoryModule
+ token_send::TokenSendModule
{
#[payable("*")]
#[endpoint(multiPairSwap)]
13 changes: 0 additions & 13 deletions dex/router/tests/router_setup/mod.rs
Original file line number Diff line number Diff line change
@@ -284,17 +284,4 @@ where
)
.assert_ok();
}

pub fn migrate_pair_map(&mut self) {
self.blockchain_wrapper
.execute_tx(
&self.owner_address,
&self.router_wrapper,
&rust_biguint!(0u64),
|sc| {
sc.migrate_pair_map();
},
)
.assert_ok();
}
}
5 changes: 0 additions & 5 deletions dex/router/tests/router_test.rs
Original file line number Diff line number Diff line change
@@ -134,7 +134,6 @@ fn test_router_upgrade_pair() {
#[test]
fn test_multi_pair_swap() {
let mut router_setup = RouterSetup::new(router::contract_obj, pair::contract_obj);
router_setup.migrate_pair_map();

router_setup.add_liquidity();

@@ -255,8 +254,6 @@ fn user_enable_pair_swaps_through_router_test() {
managed_address!(pair_wrapper.address_ref()),
);

sc.migrate_pair_map();

sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![
managed_token_id!(USDC_TOKEN_ID),
])));
@@ -442,8 +439,6 @@ fn user_enable_pair_swaps_fail_test() {
managed_address!(pair_wrapper.address_ref()),
);

sc.migrate_pair_map();

sc.add_common_tokens_for_user_pairs(MultiValueEncoded::from(ManagedVec::from(vec![
managed_token_id!(USDC_TOKEN_ID),
])));
6 changes: 2 additions & 4 deletions dex/router/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 32
// Endpoints: 30
// Async Callback: 1
// Total number of exported functions: 34
// Total number of exported functions: 32

#![no_std]
#![allow(internal_features)]
@@ -31,7 +31,6 @@ multiversx_sc_wasm_adapter::endpoints! {
setFeeOn => set_fee_on
setFeeOff => set_fee_off
setPairCreationEnabled => set_pair_creation_enabled
migratePairMap => migrate_pair_map
getPairCreationEnabled => pair_creation_enabled
getState => state
getOwner => owner
@@ -44,7 +43,6 @@ multiversx_sc_wasm_adapter::endpoints! {
getAllPairTokens => get_all_token_pairs
getAllPairContractMetadata => get_all_pair_contract_metadata
getPair => get_pair
getPairTokens => get_pair_tokens
clearPairTemporaryOwnerStorage => clear_pair_temporary_owner_storage
multiPairSwap => multi_pair_swap
configEnableByUserParameters => config_enable_by_user_parameters