Skip to content

Commit

Permalink
added legacy farm v1.3 contract
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Jul 1, 2024
1 parent 2231e50 commit 72f8304
Show file tree
Hide file tree
Showing 21 changed files with 3,760 additions and 851 deletions.
19 changes: 18 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ members = [
"legacy-contracts/simple-lock-legacy/meta",
"legacy-contracts/farm-staking-proxy-legacy",
"legacy-contracts/farm-staking-proxy-legacy/meta",
"legacy-contracts/farm-v-13",
"legacy-contracts/farm-v-13/meta",

"locked-asset/",
"locked-asset/distribution",
Expand Down
4 changes: 2 additions & 2 deletions legacy-contracts/farm-staking-proxy-legacy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ path = "../../farm-staking/farm-staking"
[dependencies.pair]
path = "../../dex/pair"

[dependencies.farm-with-locked-rewards]
path = "../../dex/farm-with-locked-rewards"
[dependencies.farm-v-13]
path = "../farm-v-13"

[dev-dependencies.energy-factory]
path = "../../locked-asset/energy-factory"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ multiversx_sc::imports!();
use common_structs::{RawResultWrapper, RawResultsType};
use farm_staking::unstake_farm::ProxyTrait as _;
use multiversx_sc::storage::StorageKey;
use pair::{pair_actions::remove_liq::ProxyTrait as _, safe_price_view::ProxyTrait as _};
use pair::pair_actions::remove_liq::ProxyTrait as _;

use crate::result_types::*;

Expand All @@ -17,15 +17,14 @@ pub trait ExternalContractsInteractionsModule:

fn lp_farm_exit(
&self,
orig_caller: ManagedAddress,
lp_farm_token_nonce: u64,
lp_farm_token_amount: BigUint,
) -> LpFarmExitResult<Self::Api> {
let lp_farm_token_id = self.lp_farm_token_id().get();
let lp_farm_address = self.lp_farm_address().get();
let raw_results: RawResultsType<Self::Api> = self
.lp_farm_proxy_obj(lp_farm_address)
.exit_farm_endpoint(OptionalValue::Some(orig_caller))
.exit_farm(OptionalValue::<ManagedBuffer>::None)
.with_esdt_transfer((lp_farm_token_id, lp_farm_token_nonce, lp_farm_token_amount))
.execute_on_dest_context();

Expand Down Expand Up @@ -136,39 +135,13 @@ pub trait ExternalContractsInteractionsModule:
}
}

fn get_lp_tokens_safe_price(&self, lp_tokens_amount: BigUint) -> BigUint {
let pair_address = self.pair_address().get();
let raw_results: RawResultsType<Self::Api> = self
.pair_proxy_obj(pair_address)
.update_and_get_tokens_for_given_position_with_safe_price(lp_tokens_amount)
.execute_on_dest_context();

let mut results_wrapper = RawResultWrapper::new(raw_results);
results_wrapper.trim_results_front(2);

let first_token_info: EsdtTokenPayment = results_wrapper.decode_next_result();
let second_token_info: EsdtTokenPayment = results_wrapper.decode_next_result();

let staking_token_id = self.staking_token_id().get();
if first_token_info.token_identifier == staking_token_id {
first_token_info.amount
} else if second_token_info.token_identifier == staking_token_id {
second_token_info.amount
} else {
sc_panic!("Invalid Pair contract called");
}
}

// proxies

#[proxy]
fn staking_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm_staking::Proxy<Self::Api>;

#[proxy]
fn lp_farm_proxy_obj(
&self,
sc_address: ManagedAddress,
) -> farm_with_locked_rewards::Proxy<Self::Api>;
fn lp_farm_proxy_obj(&self, sc_address: ManagedAddress) -> farm_v_13::Proxy<Self::Api>;

#[proxy]
fn pair_proxy_obj(&self, sc_address: ManagedAddress) -> pair::Proxy<Self::Api>;
Expand Down
10 changes: 5 additions & 5 deletions legacy-contracts/farm-staking-proxy-legacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ pub trait FarmStakingProxy:
#[init]
fn init(&self) {}

#[upgrade]
fn upgrade(&self) {}

#[payable("*")]
#[endpoint(unstakeFarmTokens)]
fn unstake_farm_tokens(
Expand All @@ -34,11 +37,8 @@ pub trait FarmStakingProxy:
let attributes = self.get_dual_yield_token_attributes(payment_nonce);
let lp_farm_token_amount =
self.get_lp_farm_token_amount_equivalent(&attributes, &payment_amount);
let lp_farm_exit_result = self.lp_farm_exit(
caller.clone(),
attributes.lp_farm_token_nonce,
lp_farm_token_amount,
);
let lp_farm_exit_result =
self.lp_farm_exit(attributes.lp_farm_token_nonce, lp_farm_token_amount);

let remove_liq_result = self.pair_remove_liquidity(
lp_farm_exit_result.lp_tokens,
Expand Down
96 changes: 48 additions & 48 deletions legacy-contracts/farm-staking-proxy-legacy/tests/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
// Pair constants

pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm";
pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef";
pub const RIDE_TOKEN_ID: &[u8] = b"RIDE-abcdef";
pub const LP_TOKEN_ID: &[u8] = b"LPTOK-abcdef"; // also farming token ID for LP farm

pub const USER_TOTAL_WEGLD_TOKENS: u64 = 2_000_000_000;
pub const USER_TOTAL_RIDE_TOKENS: u64 = 2_000_000_000;
pub const USER_TOTAL_LP_TOKENS: u64 = 1_001_000_000;

pub const BLOCK_NONCE_FIRST_ADD_LIQ: u64 = 5;
pub const BLOCK_NONCE_SECOND_ADD_LIQ: u64 = 6;
pub const BLOCK_NONCE_AFTER_PAIR_SETUP: u64 = 100;

// LP farm constants

pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm";
pub const LP_FARM_TOKEN_ID: &[u8] = b"LPFARM-abcdef";
pub const DIVISION_SAFETY_CONSTANT: u64 = 1_000_000_000_000;
pub const MIN_FARMING_EPOCHS: u8 = 2;
pub const PENALTY_PERCENT: u64 = 10;
pub const LP_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 5_000;

// Energy factory constants

pub const EPOCHS_IN_YEAR: u64 = 360;
pub static MEX_TOKEN_ID: &[u8] = b"MEX-123456";
pub static LOCKED_TOKEN_ID: &[u8] = b"LOCKED-123456";
pub static LEGACY_LOCKED_TOKEN_ID: &[u8] = b"LEGACY-123456";
pub static LOCK_OPTIONS: &[u64] = &[EPOCHS_IN_YEAR, 5 * EPOCHS_IN_YEAR, 10 * EPOCHS_IN_YEAR]; // 1, 5 or 10 years
pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000];

// Staking farm constants

pub const STAKING_FARM_WASM_PATH: &str = "farm-staking/output/farm-staking.wasm";
pub const STAKING_REWARD_TOKEN_ID: &[u8] = RIDE_TOKEN_ID;
pub const STAKING_TOKEN_ID: &[u8] = RIDE_TOKEN_ID;
pub const STAKING_FARM_TOKEN_ID: &[u8] = b"STKFARM-abcdef";
pub const MAX_APR: u64 = 5_000; // 50%
pub const UNBOND_EPOCHS: u64 = 10;
pub const STAKING_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 1_000;
pub const REWARD_CAPACITY: u64 = 1_000_000_000_000;

// Proxy constants

pub const PROXY_WASM_PATH: &str = "farm-staking-proxy/output/farm-staking-proxy";
pub const DUAL_YIELD_TOKEN_ID: &[u8] = b"DYIELD-abcdef";
// // Pair constants

// pub const PAIR_WASM_PATH: &str = "pair/output/pair.wasm";
// pub const WEGLD_TOKEN_ID: &[u8] = b"WEGLD-abcdef";
// pub const RIDE_TOKEN_ID: &[u8] = b"RIDE-abcdef";
// pub const LP_TOKEN_ID: &[u8] = b"LPTOK-abcdef"; // also farming token ID for LP farm

// pub const USER_TOTAL_WEGLD_TOKENS: u64 = 2_000_000_000;
// pub const USER_TOTAL_RIDE_TOKENS: u64 = 2_000_000_000;
// pub const USER_TOTAL_LP_TOKENS: u64 = 1_001_000_000;

// pub const BLOCK_NONCE_FIRST_ADD_LIQ: u64 = 5;
// pub const BLOCK_NONCE_SECOND_ADD_LIQ: u64 = 6;
// pub const BLOCK_NONCE_AFTER_PAIR_SETUP: u64 = 100;

// // LP farm constants

// pub const FARM_WASM_PATH: &str = "farm/output/farm.wasm";
// pub const LP_FARM_TOKEN_ID: &[u8] = b"LPFARM-abcdef";
// pub const DIVISION_SAFETY_CONSTANT: u64 = 1_000_000_000_000;
// pub const MIN_FARMING_EPOCHS: u8 = 2;
// pub const PENALTY_PERCENT: u64 = 10;
// pub const LP_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 5_000;

// // Energy factory constants

// pub const EPOCHS_IN_YEAR: u64 = 360;
// pub static MEX_TOKEN_ID: &[u8] = b"MEX-123456";
// pub static LOCKED_TOKEN_ID: &[u8] = b"LOCKED-123456";
// pub static LEGACY_LOCKED_TOKEN_ID: &[u8] = b"LEGACY-123456";
// pub static LOCK_OPTIONS: &[u64] = &[EPOCHS_IN_YEAR, 5 * EPOCHS_IN_YEAR, 10 * EPOCHS_IN_YEAR]; // 1, 5 or 10 years
// pub static PENALTY_PERCENTAGES: &[u64] = &[4_000, 6_000, 8_000];

// // Staking farm constants

// pub const STAKING_FARM_WASM_PATH: &str = "farm-staking/output/farm-staking.wasm";
// pub const STAKING_REWARD_TOKEN_ID: &[u8] = RIDE_TOKEN_ID;
// pub const STAKING_TOKEN_ID: &[u8] = RIDE_TOKEN_ID;
// pub const STAKING_FARM_TOKEN_ID: &[u8] = b"STKFARM-abcdef";
// pub const MAX_APR: u64 = 5_000; // 50%
// pub const UNBOND_EPOCHS: u64 = 10;
// pub const STAKING_FARM_PER_BLOCK_REWARD_AMOUNT: u64 = 1_000;
// pub const REWARD_CAPACITY: u64 = 1_000_000_000_000;

// // Proxy constants

// pub const PROXY_WASM_PATH: &str = "farm-staking-proxy/output/farm-staking-proxy";
// pub const DUAL_YIELD_TOKEN_ID: &[u8] = b"DYIELD-abcdef";
Loading

0 comments on commit 72f8304

Please sign in to comment.