Skip to content

Commit

Permalink
Merge branch 'rc/v3.0' into upgrade-0.50.5
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Jul 3, 2024
2 parents 8a7325b + 68f5ff1 commit e2de796
Show file tree
Hide file tree
Showing 31 changed files with 4,281 additions and 200 deletions.
37 changes: 32 additions & 5 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ members = [

"legacy-contracts/simple-lock-legacy",
"legacy-contracts/simple-lock-legacy/meta",
"legacy-contracts/farm-staking-proxy-legacy",
"legacy-contracts/farm-staking-proxy-legacy/meta",
"legacy-contracts/farm-staking-proxy-v-13",
"legacy-contracts/farm-staking-proxy-v-13/meta",
"legacy-contracts/farm-v-13",
"legacy-contracts/farm-v-13/meta",

"locked-asset/",
"locked-asset/distribution",
Expand Down
30 changes: 0 additions & 30 deletions legacy-contracts/farm-staking-proxy-legacy/Cargo.toml

This file was deleted.

3 changes: 0 additions & 3 deletions legacy-contracts/farm-staking-proxy-legacy/meta/src/main.rs

This file was deleted.

60 changes: 60 additions & 0 deletions legacy-contracts/farm-staking-proxy-v-13/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
[package]
name = "farm-staking-proxy-v-13"
version = "0.0.0"
authors = ["MultiversX <[email protected]>"]
edition = "2021"
publish = false

[lib]
path = "src/lib.rs"

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

[dependencies.multiversx-sc-modules]
version = "=0.50.5"

[dependencies.token_merge_helper]
path = "../../common/modules/token_merge_helper"

[dependencies.common_structs]
path = "../../common/common_structs"

[dependencies.farm-staking]
path = "../../farm-staking/farm-staking"

[dependencies.pair]
path = "../../dex/pair"

[dependencies.farm-v-13]
path = "../farm-v-13"

[dev-dependencies.energy-factory]
path = "../../locked-asset/energy-factory"

[dev-dependencies.energy-query]
path = "../../energy-integration/common-modules/energy-query"

[dev-dependencies.simple-lock]
path = "../../locked-asset/simple-lock"

[dev-dependencies.farm_token]
path = "../../common/modules/farm/farm_token"

[dev-dependencies.locking_module]
path = "../../common/modules/locking_module"

[dev-dependencies.pausable]
path = "../../common/modules/pausable"

[dev-dependencies.sc_whitelist_module]
path = "../../common/modules/sc_whitelist_module"

[dev-dependencies]
num-bigint = "0.4.2"
num-traits = "0.2"
hex = "0.4"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.50.5"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "farm-staking-proxy-legacy-meta"
name = "farm-staking-proxy-v-13-meta"
version = "0.0.0"
edition = "2021"
publish = false
authors = ["MultiversX <[email protected]>"]

[dependencies.farm-staking-proxy-legacy]
[dependencies.farm-staking-proxy-v-13]
path = ".."

[dependencies.multiversx-sc-meta]
Expand Down
3 changes: 3 additions & 0 deletions legacy-contracts/farm-staking-proxy-v-13/meta/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
multiversx_sc_meta::cli_main::<farm_staking_proxy_v_13::AbiProvider>();
}
Original file line number Diff line number Diff line change
@@ -1,57 +1,13 @@
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 _;

use crate::result_types::*;

mod farm_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait FarmProxy {
#[payable("*")]
#[endpoint(exitFarm)]
fn exit_farm(&self) -> MultiValue2<EsdtTokenPayment, EsdtTokenPayment>;

#[view(getFarmingTokenId)]
fn farming_token_id(&self) -> TokenIdentifier;
}
}

mod farm_staking_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait FarmStakingProxy {
#[payable("*")]
#[endpoint(unstakeFarmThroughProxy)]
fn unstake_farm_through_proxy(
&self,
original_caller: ManagedAddress,
) -> MultiValue2<EsdtTokenPayment, EsdtTokenPayment>;
}
}

mod pair_proxy {
multiversx_sc::imports!();

#[multiversx_sc::proxy]
pub trait PairProxy {
#[payable("*")]
#[endpoint(removeLiquidity)]
fn remove_liquidity(
&self,
first_token_amount_min: BigUint,
second_token_amount_min: BigUint,
) -> MultiValue2<EsdtTokenPayment, EsdtTokenPayment>;

#[endpoint(updateAndGetTokensForGivenPositionWithSafePrice)]
fn update_and_get_tokens_for_given_position_with_safe_price(
&self,
liquidity: BigUint,
) -> MultiValue2<EsdtTokenPayment, EsdtTokenPayment>;
}
}
pub static FARMING_TOKEN_STORAGE_KEY: &[u8] = b"farming_token_id";

#[multiversx_sc::module]
pub trait ExternalContractsInteractionsModule:
Expand All @@ -68,7 +24,7 @@ pub trait ExternalContractsInteractionsModule:
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()
.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 All @@ -93,9 +49,13 @@ pub trait ExternalContractsInteractionsModule:

fn get_lp_farming_token_identifier(&self) -> TokenIdentifier {
let lp_farm_address = self.lp_farm_address().get();
self.lp_farm_proxy_obj(lp_farm_address)
.farming_token_id()
.execute_on_dest_context()

let farming_token_mapper = SingleValueMapper::<_, _, ManagedAddress>::new_from_address(
lp_farm_address,
StorageKey::new(FARMING_TOKEN_STORAGE_KEY),
);

farming_token_mapper.get()
}

// staking farm
Expand Down Expand Up @@ -175,42 +135,16 @@ 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::Proxy<Self::Api>;
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_proxy::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::Proxy<Self::Api>;
fn pair_proxy_obj(&self, sc_address: ManagedAddress) -> pair::Proxy<Self::Api>;

// storage

Expand Down
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 Down
48 changes: 48 additions & 0 deletions legacy-contracts/farm-staking-proxy-v-13/tests/constants/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +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";
Loading

0 comments on commit e2de796

Please sign in to comment.