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

Simple lock: Add endpoints that breaks farm #816

Merged
merged 25 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
68f6a9b
Simple lock: Add endpoints that breaks farm
CostinCarabas Jan 22, 2024
29f098a
Destroy farm in simple-lock
CostinCarabas Jan 26, 2024
8c7a270
Simple lock whitelist
CostinCarabas Jan 26, 2024
0fa9b7b
Destroy farm in proxy-dex
CostinCarabas Jan 26, 2024
5f76037
Merge branch 'main' into simple-lock-break-farm-into-initial-tokens
CostinCarabas Feb 6, 2024
016473d
Destroy farm: pair_addr provided as parameter
CostinCarabas Feb 6, 2024
5c8f183
Simple-lock fix: destroy farm returns locked token
CostinCarabas Feb 6, 2024
a250fb7
Burn farm tokens for claim and destry endpoints
CostinCarabas Feb 6, 2024
a60edcd
simple-lock: Fix ExitFarmResultType
CostinCarabas Feb 6, 2024
1d02cac
simple-lock/proxy-dex improvements
CostinCarabas Feb 6, 2024
61970b2
Merge branch 'main' into simple-lock-break-farm-into-initial-tokens
CostinCarabas Feb 8, 2024
6980ca8
simple-lock: Test destroy farm
CostinCarabas Feb 7, 2024
0d9e8f6
Simple lock: Destroy farm test
CostinCarabas Feb 20, 2024
1682a47
Cargo fmt
CostinCarabas Feb 20, 2024
c2eb950
Remove unnecessary test
CostinCarabas Feb 20, 2024
ea688d7
Fix clippy
CostinCarabas Feb 20, 2024
ac12c3c
Merge branch 'main' into simple-lock-break-farm-into-initial-tokens
CostinCarabas Feb 20, 2024
39cefd6
Fixes after review
CostinCarabas Feb 22, 2024
ce739aa
destroy_farm_proxy: Check pair_address is legitimate
CostinCarabas Feb 22, 2024
dad5423
simple-lock/destroy_farm_locked_tokens: Burn farm proxy token
CostinCarabas Feb 22, 2024
adf0267
Cargo format
CostinCarabas Feb 22, 2024
9d78167
Merge remote-tracking branch 'origin/simple-lock-break-farm-into-init…
CostinCarabas Feb 22, 2024
e760365
simple-lock: Remove burn of wrapped farm token from destroy and claim…
CostinCarabas Feb 22, 2024
f865799
Small fix
CostinCarabas Feb 22, 2024
31779fa
remove RemoveLiquidityProxyCommon struct
psorinionut Feb 27, 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
103 changes: 99 additions & 4 deletions dex/farm/tests/farm_setup/single_user_farm_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#![allow(deprecated)]

use common_structs::FarmTokenAttributes;
use multiversx_sc::codec::multi_types::OptionalValue;
use multiversx_sc::codec::multi_types::{MultiValue3, OptionalValue};
use multiversx_sc::storage::mappers::StorageTokenWrapper;
use multiversx_sc::types::{Address, EsdtLocalRole, ManagedAddress, MultiValueEncoded};
use multiversx_sc_scenario::whitebox_legacy::{TxContextStack, TxTokenTransfer};
Expand All @@ -17,9 +17,12 @@ use farm::exit_penalty::ExitPenaltyModule;
use farm::*;
use farm_boosted_yields::boosted_yields_factors::BoostedYieldsFactorsModule;
use farm_token::FarmTokenModule;
use pair::pair_actions::add_liq::AddLiquidityModule as _;
use pair::{config::ConfigModule as OtherConfigModule, Pair};
use pausable::{PausableModule, State};

pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm";
pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm";

pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef";
pub const MEX_TOKEN_ID: &[u8] = b"MEX-abcdef"; // reward token ID
Expand All @@ -36,25 +39,74 @@ pub const USER_REWARDS_ENERGY_CONST: u64 = 3;
pub const USER_REWARDS_FARM_CONST: u64 = 2;
pub const MIN_ENERGY_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1;
pub const MIN_FARM_AMOUNT_FOR_BOOSTED_YIELDS: u64 = 1;
pub const LOCKED_TOKEN_ID: &[u8] = b"XMEX-123456";
pub const LOCKED_LP_TOKEN_ID: &[u8] = b"LKLP-123456";
pub const FARM_PROXY_TOKEN_ID: &[u8] = b"PROXY-123456";

pub struct SingleUserFarmSetup<FarmObjBuilder>
pub struct SingleUserFarmSetup<FarmObjBuilder, PairObjBuilder>
where
FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj<DebugApi>,
PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj<DebugApi>,
{
pub blockchain_wrapper: BlockchainStateWrapper,
pub owner_address: Address,
pub user_address: Address,
pub farm_wrapper: ContractObjWrapper<farm::ContractObj<DebugApi>, FarmObjBuilder>,
pub pair_wrapper: ContractObjWrapper<pair::ContractObj<DebugApi>, PairObjBuilder>,
}

impl<FarmObjBuilder> SingleUserFarmSetup<FarmObjBuilder>
impl<FarmObjBuilder, PairObjBuilder> SingleUserFarmSetup<FarmObjBuilder, PairObjBuilder>
where
FarmObjBuilder: 'static + Copy + Fn() -> farm::ContractObj<DebugApi>,
PairObjBuilder: 'static + Copy + Fn() -> pair::ContractObj<DebugApi>,
{
pub fn new(farm_builder: FarmObjBuilder) -> Self {
pub fn new(farm_builder: FarmObjBuilder, pair_builder: PairObjBuilder) -> Self {
let rust_zero = rust_biguint!(0u64);
let mut blockchain_wrapper = BlockchainStateWrapper::new();
let owner_addr = blockchain_wrapper.create_user_account(&rust_zero);

let pair_wrapper = blockchain_wrapper.create_sc_account(
&rust_zero,
Some(&owner_addr),
pair_builder,
PAIR_WASM_PATH,
);

// init pair contract
blockchain_wrapper
.execute_tx(&owner_addr, &pair_wrapper, &rust_zero, |sc| {
let first_token_id = managed_token_id!(WEGLD_TOKEN_ID);
let second_token_id = managed_token_id!(MEX_TOKEN_ID);
let router_address = managed_address!(&owner_addr);
let router_owner_address = managed_address!(&owner_addr);
let total_fee_percent = 300u64;
let special_fee_percent = 50u64;

sc.init(
first_token_id,
second_token_id,
router_address,
router_owner_address,
total_fee_percent,
special_fee_percent,
ManagedAddress::<DebugApi>::zero(),
MultiValueEncoded::<DebugApi, ManagedAddress<DebugApi>>::new(),
);

let lp_token_id = managed_token_id!(LP_TOKEN_ID);
sc.lp_token_identifier().set(&lp_token_id);

sc.state().set(State::Active);
})
.assert_ok();

let lp_token_roles = [EsdtLocalRole::Mint, EsdtLocalRole::Burn];
blockchain_wrapper.set_esdt_local_roles(
pair_wrapper.address_ref(),
LP_TOKEN_ID,
&lp_token_roles[..],
);

let farm_wrapper = blockchain_wrapper.create_sc_account(
&rust_zero,
Some(&owner_addr),
Expand Down Expand Up @@ -142,9 +194,52 @@ where
owner_address: owner_addr,
user_address: user_addr,
farm_wrapper,
pair_wrapper,
}
}

#[allow(clippy::too_many_arguments)]
pub fn add_liquidity(
&mut self,
first_token_amount: u64,
first_token_min: u64,
second_token_amount: u64,
second_token_min: u64,
) {
let payments = vec![
TxTokenTransfer {
token_identifier: WEGLD_TOKEN_ID.to_vec(),
nonce: 0,
value: rust_biguint!(first_token_amount),
},
TxTokenTransfer {
token_identifier: LOCKED_TOKEN_ID.to_vec(),
nonce: 0,
value: rust_biguint!(second_token_amount),
},
];

self.blockchain_wrapper
.execute_esdt_multi_transfer(&self.user_address, &self.pair_wrapper, &payments, |sc| {
let MultiValue3 { 0: payments } = sc.add_liquidity(
managed_biguint!(first_token_min),
managed_biguint!(second_token_min),
);

assert_eq!(payments.0.token_identifier, managed_token_id!(LP_TOKEN_ID));

assert_eq!(
payments.1.token_identifier,
managed_token_id!(WEGLD_TOKEN_ID)
);
assert_eq!(
payments.2.token_identifier,
managed_token_id!(LOCKED_TOKEN_ID)
);
})
.assert_ok();
}

pub fn enter_farm(
&mut self,
farm_in_amount: u64,
Expand Down
Loading
Loading