-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4320a90
commit c2a140a
Showing
15 changed files
with
924 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Generated by Cargo | ||
# will have compiled files and executables | ||
/target/ | ||
*/target/ | ||
|
||
# The erdpy output | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "farm-staking-proxy-legacy" | ||
version = "0.0.0" | ||
authors = ["MultiversX <contact@multiversx.com>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
path = "src/lib.rs" | ||
|
||
[dependencies.multiversx-sc] | ||
version = "=0.50.4" | ||
features = ["esdt-token-payment-legacy-decode"] | ||
|
||
[dependencies.multiversx-sc-modules] | ||
version = "=0.50.4" | ||
|
||
[dependencies.token_merge_helper] | ||
path = "../../common/modules/token_merge_helper" | ||
|
||
[dependencies.common_structs] | ||
path = "../../common/common_structs" | ||
|
||
[dev-dependencies] | ||
num-bigint = "0.4.2" | ||
num-traits = "0.2" | ||
hex = "0.4" | ||
|
||
[dev-dependencies.multiversx-sc-scenario] | ||
version = "=0.50.4" |
13 changes: 13 additions & 0 deletions
13
legacy-contracts/farm-staking-proxy-legacy/meta/Cargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "farm-staking-proxy-legacy-meta" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
authors = ["MultiversX <contact@multiversx.com>"] | ||
|
||
[dependencies.farm-staking-proxy-legacy] | ||
path = ".." | ||
|
||
[dependencies.multiversx-sc-meta] | ||
version = "0.50.4" | ||
default-features = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
multiversx_sc_meta::cli_main::<farm_staking_proxy_legacy::AbiProvider>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"language": "rust" | ||
} |
108 changes: 108 additions & 0 deletions
108
legacy-contracts/farm-staking-proxy-legacy/src/dual_yield_token.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
multiversx_sc::imports!(); | ||
multiversx_sc::derive_imports!(); | ||
|
||
#[derive(TypeAbi, TopEncode, TopDecode, PartialEq, Debug)] | ||
pub struct DualYieldTokenAttributes<M: ManagedTypeApi> { | ||
pub lp_farm_token_nonce: u64, | ||
pub lp_farm_token_amount: BigUint<M>, | ||
pub staking_farm_token_nonce: u64, | ||
pub staking_farm_token_amount: BigUint<M>, | ||
} | ||
|
||
impl<M: ManagedTypeApi> DualYieldTokenAttributes<M> { | ||
/// dual yield tokens are always created with an amount equal to staking_farm_token_amount, | ||
/// so we just return this field instead of duplicating | ||
#[inline] | ||
pub fn get_total_dual_yield_tokens_for_position(&self) -> &BigUint<M> { | ||
&self.staking_farm_token_amount | ||
} | ||
} | ||
|
||
#[multiversx_sc::module] | ||
pub trait DualYieldTokenModule: token_merge_helper::TokenMergeHelperModule { | ||
#[only_owner] | ||
#[endpoint(setTransferRoleDualYieldToken)] | ||
fn set_transfer_role_dual_yield_token(&self, opt_address: OptionalValue<ManagedAddress>) { | ||
let address = self.resolve_address(opt_address); | ||
let token_id = self.dual_yield_token_id().get(); | ||
let roles = [EsdtLocalRole::Transfer]; | ||
|
||
self.send() | ||
.esdt_system_sc_proxy() | ||
.set_special_roles(&address, &token_id, roles.iter().cloned()) | ||
.async_call_and_exit() | ||
} | ||
|
||
fn resolve_address(&self, opt_address: OptionalValue<ManagedAddress>) -> ManagedAddress { | ||
match opt_address { | ||
OptionalValue::Some(addr) => addr, | ||
OptionalValue::None => self.blockchain().get_sc_address(), | ||
} | ||
} | ||
|
||
fn require_dual_yield_token(&self, token_id: &TokenIdentifier) { | ||
let dual_yield_token_id = self.dual_yield_token_id().get(); | ||
require!(token_id == &dual_yield_token_id, "Invalid payment token"); | ||
} | ||
|
||
fn require_all_payments_dual_yield_tokens( | ||
&self, | ||
payments: &ManagedVec<EsdtTokenPayment<Self::Api>>, | ||
) { | ||
if payments.is_empty() { | ||
return; | ||
} | ||
|
||
let dual_yield_token_id = self.dual_yield_token_id().get(); | ||
for p in payments { | ||
require!( | ||
p.token_identifier == dual_yield_token_id, | ||
"Invalid payment token" | ||
); | ||
} | ||
} | ||
|
||
fn burn_dual_yield_tokens(&self, sft_nonce: u64, amount: &BigUint) { | ||
let dual_yield_token_id = self.dual_yield_token_id().get(); | ||
self.send() | ||
.esdt_local_burn(&dual_yield_token_id, sft_nonce, amount); | ||
} | ||
|
||
fn get_dual_yield_token_attributes( | ||
&self, | ||
dual_yield_token_nonce: u64, | ||
) -> DualYieldTokenAttributes<Self::Api> { | ||
let own_sc_address = self.blockchain().get_sc_address(); | ||
let dual_yield_token_id = self.dual_yield_token_id().get(); | ||
let token_info = self.blockchain().get_esdt_token_data( | ||
&own_sc_address, | ||
&dual_yield_token_id, | ||
dual_yield_token_nonce, | ||
); | ||
|
||
token_info.decode_attributes() | ||
} | ||
|
||
fn get_lp_farm_token_amount_equivalent( | ||
&self, | ||
attributes: &DualYieldTokenAttributes<Self::Api>, | ||
amount: &BigUint, | ||
) -> BigUint { | ||
self.rule_of_three_non_zero_result( | ||
amount, | ||
attributes.get_total_dual_yield_tokens_for_position(), | ||
&attributes.lp_farm_token_amount, | ||
) | ||
} | ||
|
||
#[inline] | ||
fn get_staking_farm_token_amount_equivalent(&self, amount: &BigUint) -> BigUint { | ||
// since staking_farm_token_amount is equal to the total dual yield tokens, | ||
// we simply return the amount | ||
amount.clone() | ||
} | ||
|
||
#[view(getDualYieldTokenId)] | ||
#[storage_mapper("dualYieldTokenId")] | ||
fn dual_yield_token_id(&self) -> SingleValueMapper<TokenIdentifier>; | ||
} |
Oops, something went wrong.