Skip to content

Commit

Permalink
Interactors code updates
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Jun 4, 2024
1 parent ee2d464 commit 1cccc07
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 62 deletions.
2 changes: 1 addition & 1 deletion dex/interactor/src/energy_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(crate) async fn get_energy_entry_for_user(
.query()
.to(dex_interact.state.current_energy_factory_address())
.typed(energy_factory_proxy::SimpleLockEnergyProxy)
.get_updated_energy_entry_for_user(ManagedAddress::from(user))
.get_updated_energy_entry_for_user(user)
.returns(ReturnsResult)
.prepare_async()
.run()
Expand Down
44 changes: 21 additions & 23 deletions dex/interactor/src/farm_locked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use multiversx_sc_snippets::imports::*;

use crate::{
farm_with_locked_rewards_proxy,
structs::{extract_caller, to_rust_biguint, InteractorFarmTokenAttributes, InteractorToken},
structs::{extract_caller, to_rust_biguint, InteractorFarmTokenAttributes, InteractorPayment},
DexInteract,
};

pub(crate) async fn enter_farm(
dex_interact: &mut DexInteract,
lp_token: InteractorToken,
) -> (InteractorToken, InteractorToken) {
lp_token: InteractorPayment,
) -> (InteractorPayment, InteractorPayment) {
println!("Attempting to enter farm with locked rewards...");

let result_token = dex_interact
Expand All @@ -25,25 +25,23 @@ pub(crate) async fn enter_farm(
.current_farm_with_locked_rewards_address())
.gas(100_000_000u64)
.typed(farm_with_locked_rewards_proxy::FarmProxy)
.enter_farm_endpoint(OptionalValue::Some(ManagedAddress::from(
dex_interact.wallet_address.as_address(),
)))
.payment::<EsdtTokenPayment<StaticApi>>(lp_token.into())
.enter_farm_endpoint(OptionalValue::Some(dex_interact.wallet_address.clone()))
.esdt::<EsdtTokenPayment<StaticApi>>(lp_token.into())
.returns(ReturnsResult)
.prepare_async()
.run()
.await;
(
InteractorToken::from(result_token.0 .0),
InteractorToken::from(result_token.0 .1),
InteractorPayment::from(result_token.0 .0),
InteractorPayment::from(result_token.0 .1),
)
}

pub(crate) async fn claim_rewards(
dex_interact: &mut DexInteract,
payment: Vec<InteractorToken>,
payment: Vec<InteractorPayment>,
opt_original_caller: Option<Address>,
) -> (InteractorToken, InteractorToken) {
) -> (InteractorPayment, InteractorPayment) {
println!("Attempting to claim rewards from farm with locked rewards...");

let payments = payment
Expand All @@ -70,16 +68,16 @@ pub(crate) async fn claim_rewards(
.await;

(
InteractorToken::from(result_token.0 .0),
InteractorToken::from(result_token.0 .1),
InteractorPayment::from(result_token.0 .0),
InteractorPayment::from(result_token.0 .1),
)
}

pub(crate) async fn exit_farm(
dex_interact: &mut DexInteract,
payment: InteractorToken,
payment: InteractorPayment,
opt_original_caller: Option<Address>,
) -> (InteractorToken, InteractorToken) {
) -> (InteractorPayment, InteractorPayment) {
println!("Attempting to exit farm with locked rewards...");

let caller_arg = extract_caller(dex_interact, opt_original_caller);
Expand All @@ -101,16 +99,16 @@ pub(crate) async fn exit_farm(
.await;

(
InteractorToken::from(result_token.0 .0),
InteractorToken::from(result_token.0 .1),
InteractorPayment::from(result_token.0 .0),
InteractorPayment::from(result_token.0 .1),
)
}

pub(crate) async fn merge_farm_tokens(
dex_interact: &mut DexInteract,
payment: Vec<InteractorToken>,
payment: Vec<InteractorPayment>,
opt_original_caller: Option<Address>,
) -> (InteractorToken, InteractorToken) {
) -> (InteractorPayment, InteractorPayment) {
println!("Attempting to merge tokens in farm with locked rewards...");

let payments = payment
Expand All @@ -137,15 +135,15 @@ pub(crate) async fn merge_farm_tokens(
.await;

(
InteractorToken::from(result_token.0 .0),
InteractorToken::from(result_token.0 .1),
InteractorPayment::from(result_token.0 .0),
InteractorPayment::from(result_token.0 .1),
)
}

pub(crate) async fn claim_boosted_rewards(
dex_interact: &mut DexInteract,
opt_original_caller: Option<Address>,
) -> InteractorToken {
) -> InteractorPayment {
let caller_arg = extract_caller(dex_interact, opt_original_caller);

let result_token = dex_interact
Expand All @@ -163,7 +161,7 @@ pub(crate) async fn claim_boosted_rewards(
.run()
.await;

InteractorToken::from(result_token)
InteractorPayment::from(result_token)
}

pub(crate) async fn calculate_rewards_for_given_position(
Expand Down
8 changes: 4 additions & 4 deletions dex/interactor/src/farm_staking_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use proxies::farm_staking_proxy_sc_proxy;
use crate::{
structs::{
extract_caller, InteractorClaimDualYieldResult, InteractorStakeProxyResult,
InteractorToken, InteractorUnstakeResult,
InteractorPayment, InteractorUnstakeResult,
},
DexInteract,
};
Expand Down Expand Up @@ -167,7 +167,7 @@ pub(crate) async fn get_energy_factory_address(dex_interact: &mut DexInteract) -
// endpoints
pub(crate) async fn stake_farm_tokens(
dex_interact: &mut DexInteract,
payment: Vec<InteractorToken>,
payment: Vec<InteractorPayment>,
opt_original_caller: Option<Address>,
) -> InteractorStakeProxyResult {
let caller_arg = extract_caller(dex_interact, opt_original_caller);
Expand Down Expand Up @@ -196,7 +196,7 @@ pub(crate) async fn stake_farm_tokens(

pub(crate) async fn claim_dual_yield(
dex_interact: &mut DexInteract,
payment: InteractorToken,
payment: InteractorPayment,
opt_original_caller: Option<Address>,
) -> InteractorClaimDualYieldResult {
let caller_arg = extract_caller(dex_interact, opt_original_caller);
Expand All @@ -220,7 +220,7 @@ pub(crate) async fn claim_dual_yield(

pub(crate) async fn unstake_farm_tokens(
dex_interact: &mut DexInteract,
payment: InteractorToken,
payment: InteractorPayment,
pair_first_token_min_amount: RustBigUint,
pair_second_token_min_amount: RustBigUint,
opt_original_caller: Option<Address>,
Expand Down
6 changes: 3 additions & 3 deletions dex/interactor/src/pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use proxies::pair_proxy;

use crate::{
dex_interact_cli::{AddArgs, SwapArgs},
structs::{InteractorAddLiquidityResultType, InteractorToken},
structs::{InteractorAddLiquidityResultType, InteractorPayment},
DexInteract,
};

pub(crate) async fn swap_tokens_fixed_input(
dex_interact: &mut DexInteract,
args: &SwapArgs,
) -> InteractorToken {
) -> InteractorPayment {
let payment = args.as_payment(dex_interact);
let first_token_id = dex_interact.state.first_token_id();
let second_token_id = dex_interact.state.second_token_id();
Expand All @@ -38,7 +38,7 @@ pub(crate) async fn swap_tokens_fixed_input(
.run()
.await;

InteractorToken::from(result_token)
InteractorPayment::from(result_token)
}

pub(crate) async fn add_liquidity(
Expand Down
62 changes: 31 additions & 31 deletions dex/interactor/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<T0, T1, T2> InteractorMultiValue3<T0, T1, T2> {
}
}
pub type InteractorAddLiquidityResultType =
InteractorMultiValue3<InteractorToken, InteractorToken, InteractorToken>;
InteractorMultiValue3<InteractorPayment, InteractorPayment, InteractorPayment>;

impl<M: ManagedTypeApi>
From<MultiValue3<EsdtTokenPayment<M>, EsdtTokenPayment<M>, EsdtTokenPayment<M>>>
Expand All @@ -33,9 +33,9 @@ impl<M: ManagedTypeApi>
let extracted = value.0;

InteractorMultiValue3::new(
InteractorToken::from(extracted.0),
InteractorToken::from(extracted.1),
InteractorToken::from(extracted.2),
InteractorPayment::from(extracted.0),
InteractorPayment::from(extracted.1),
InteractorPayment::from(extracted.2),
)
}
}
Expand All @@ -44,53 +44,53 @@ pub type RustBigInt = num_bigint::BigInt;

#[allow(dead_code)]
pub struct InteractorUnstakeResult {
pub other_token_payment: InteractorToken,
pub lp_farm_rewards: InteractorToken,
pub staking_rewards: InteractorToken,
pub unbond_staking_farm_token: InteractorToken,
pub other_token_payment: InteractorPayment,
pub lp_farm_rewards: InteractorPayment,
pub staking_rewards: InteractorPayment,
pub unbond_staking_farm_token: InteractorPayment,
}

impl<M: ManagedTypeApi> From<UnstakeResult<M>> for InteractorUnstakeResult {
fn from(value: UnstakeResult<M>) -> Self {
InteractorUnstakeResult {
other_token_payment: InteractorToken::from(value.other_token_payment),
lp_farm_rewards: InteractorToken::from(value.lp_farm_rewards),
staking_rewards: InteractorToken::from(value.staking_rewards),
unbond_staking_farm_token: InteractorToken::from(value.unbond_staking_farm_token),
other_token_payment: InteractorPayment::from(value.other_token_payment),
lp_farm_rewards: InteractorPayment::from(value.lp_farm_rewards),
staking_rewards: InteractorPayment::from(value.staking_rewards),
unbond_staking_farm_token: InteractorPayment::from(value.unbond_staking_farm_token),
}
}
}

#[allow(dead_code)]
pub struct InteractorStakeProxyResult {
pub dual_yield_tokens: InteractorToken,
pub staking_boosted_rewards: InteractorToken,
pub lp_farm_boosted_rewards: InteractorToken,
pub dual_yield_tokens: InteractorPayment,
pub staking_boosted_rewards: InteractorPayment,
pub lp_farm_boosted_rewards: InteractorPayment,
}

impl<M: ManagedTypeApi> From<StakeProxyResult<M>> for InteractorStakeProxyResult {
fn from(value: StakeProxyResult<M>) -> Self {
InteractorStakeProxyResult {
dual_yield_tokens: InteractorToken::from(value.dual_yield_tokens),
staking_boosted_rewards: InteractorToken::from(value.staking_boosted_rewards),
lp_farm_boosted_rewards: InteractorToken::from(value.lp_farm_boosted_rewards),
dual_yield_tokens: InteractorPayment::from(value.dual_yield_tokens),
staking_boosted_rewards: InteractorPayment::from(value.staking_boosted_rewards),
lp_farm_boosted_rewards: InteractorPayment::from(value.lp_farm_boosted_rewards),
}
}
}

#[allow(dead_code)]
pub struct InteractorClaimDualYieldResult {
pub lp_farm_rewards: InteractorToken,
pub staking_farm_rewards: InteractorToken,
pub new_dual_yield_tokens: InteractorToken,
pub lp_farm_rewards: InteractorPayment,
pub staking_farm_rewards: InteractorPayment,
pub new_dual_yield_tokens: InteractorPayment,
}

impl<M: ManagedTypeApi> From<ClaimDualYieldResult<M>> for InteractorClaimDualYieldResult {
fn from(value: ClaimDualYieldResult<M>) -> Self {
InteractorClaimDualYieldResult {
lp_farm_rewards: InteractorToken::from(value.lp_farm_rewards),
staking_farm_rewards: InteractorToken::from(value.staking_farm_rewards),
new_dual_yield_tokens: InteractorToken::from(value.new_dual_yield_tokens),
lp_farm_rewards: InteractorPayment::from(value.lp_farm_rewards),
staking_farm_rewards: InteractorPayment::from(value.staking_farm_rewards),
new_dual_yield_tokens: InteractorPayment::from(value.new_dual_yield_tokens),
}
}
}
Expand All @@ -104,7 +104,7 @@ pub struct InteractorFarmTokenAttributes {
}

#[derive(Debug)]
pub struct InteractorToken {
pub struct InteractorPayment {
pub token_id: String,
pub nonce: u64,
pub amount: RustBigUint,
Expand All @@ -127,18 +127,18 @@ impl<M: ManagedTypeApi> From<Energy<M>> for InteractorEnergy {
}
}

impl<M: ManagedTypeApi> From<EsdtTokenPayment<M>> for InteractorToken {
impl<M: ManagedTypeApi> From<EsdtTokenPayment<M>> for InteractorPayment {
fn from(value: EsdtTokenPayment<M>) -> Self {
InteractorToken {
InteractorPayment {
token_id: value.token_identifier.to_string(),
nonce: value.token_nonce,
amount: to_rust_biguint(value.amount),
}
}
}

impl<M: ManagedTypeApi> From<InteractorToken> for EsdtTokenPayment<M> {
fn from(interactor_token: InteractorToken) -> Self {
impl<M: ManagedTypeApi> From<InteractorPayment> for EsdtTokenPayment<M> {
fn from(interactor_token: InteractorPayment) -> Self {
EsdtTokenPayment::new(
TokenIdentifier::from(interactor_token.token_id.as_bytes()),
interactor_token.nonce,
Expand All @@ -147,8 +147,8 @@ impl<M: ManagedTypeApi> From<InteractorToken> for EsdtTokenPayment<M> {
}
}

impl<M: ManagedTypeApi> From<&InteractorToken> for EsdtTokenPayment<M> {
fn from(interactor_token: &InteractorToken) -> Self {
impl<M: ManagedTypeApi> From<&InteractorPayment> for EsdtTokenPayment<M> {
fn from(interactor_token: &InteractorPayment) -> Self {
EsdtTokenPayment::new(
TokenIdentifier::from(interactor_token.token_id.as_bytes()),
interactor_token.nonce,
Expand Down

0 comments on commit 1cccc07

Please sign in to comment.