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

V3.0 legacy contracts #942

Merged
merged 18 commits into from
Aug 14, 2024
Merged
Changes from all commits
Commits
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
14 changes: 0 additions & 14 deletions .github/workflows/on_pull_request_build_contracts.yml

This file was deleted.

143 changes: 136 additions & 7 deletions Cargo.lock

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

22 changes: 18 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -39,10 +39,24 @@ members = [

"legacy-contracts/simple-lock-legacy",
"legacy-contracts/simple-lock-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",
"legacy-contracts/farm-staking-proxy-v13",
"legacy-contracts/farm-staking-proxy-v13/meta",
"legacy-contracts/farm-v12",
"legacy-contracts/farm-v12/meta",
"legacy-contracts/farm-v13",
"legacy-contracts/farm-v13/meta",
"legacy-contracts/farm-v13-locked-rewards",
"legacy-contracts/farm-v13-locked-rewards/meta",
"legacy-contracts/farm-v13-custom-rewards",
"legacy-contracts/farm-v13-custom-rewards/meta",
"legacy-contracts/proxy-dex-legacy",
"legacy-contracts/proxy-dex-legacy/meta",
"legacy-contracts/factory-legacy",
"legacy-contracts/factory-legacy/meta",
"legacy-contracts/price-discovery-v1",
"legacy-contracts/price-discovery-v1/meta",
"legacy-contracts/price-discovery-v2",
"legacy-contracts/price-discovery-v2/meta",

"locked-asset/",
"locked-asset/distribution",
File renamed without changes.
30 changes: 30 additions & 0 deletions legacy-contracts/factory-legacy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "factory-legacy"
publish = false
version = "0.0.0"
edition = "2018"

[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"

[dev-dependencies.multiversx-sc-scenario]
version = "=0.50.5"

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

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

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

[dependencies.energy-factory]
path = "../../locked-asset/energy-factory"
26 changes: 26 additions & 0 deletions legacy-contracts/factory-legacy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Locked Asset Factory Smart Contract

This document presents how one can deploy and configure a Locked Asset Factory Contract.
The bigger picture about what a Locked Asset Factory Contract can do can be found in the Repository's Root Readme.

## Deployment

The Locked Asset Factory contract can be deployed using `erdpy` and using the interraction snippets.

The init parameters are:

- asset_token_id. The TokenId of the asset that a locked asset represents. In case of Maiar Exchange it will be MEX.

- default_unlock_period. A vector of unlock milestones. This represents a period since each epoch in the vector will be added with a starting epoch.

The Contract requires LocalMint and LocalBurn for asset token.

## Creating and Forwarding SFTs

Before creating LockedAssetLockens, the owner has to issue those tokens using `issueLockedAssetToken` and after this he also has to give the NftCreate, NftAddQuantity and NftBurn roles to the contract unsing `setLocalRolesLockedAssetToken`.

The Contract has an endpoint `createAndForward` that can be called in order to request an amount of Locked MEX. Only those addresses in the `whitelisted_contracts` set can call this endpoint. This whitelist can be configured by the admin using `whitelist` and `removeWhitelist` endpoints.

## Unlocking MEX

A user that has Locked MEX can unlock it and can receive the Locked MEX "remaining" and the unlocked MEX amount. The newly created Locked MEX will have its unlock milestones re-calculated such that the percents unlocking schedule will be updated to the new locked amount. For example: if default_unlock_period is `0x000000000000000232`, `0x000000000000000432` it would mean that after `0000000000000002` epochs, should unlock `32`.to_dec() (`50`) percent of the amount. After the first unlock at epoch 3 let's say, the next unlock milestone will be recalculated as `0x000000000000000464`. Notice the `50%` become `100%`.
14 changes: 14 additions & 0 deletions legacy-contracts/factory-legacy/meta/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "factory-legacy-meta"

version = "0.0.0"
authors = [ "you",]
edition = "2018"
publish = false

[dependencies.factory-legacy]
path = ".."

[dependencies.multiversx-sc-meta]
version = "0.50.5"
default-features = false
3 changes: 3 additions & 0 deletions legacy-contracts/factory-legacy/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::<factory_legacy::AbiProvider>();
}
4 changes: 4 additions & 0 deletions legacy-contracts/factory-legacy/multiversx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"language": "rust"
}

68 changes: 68 additions & 0 deletions legacy-contracts/factory-legacy/src/attr_ex_helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
multiversx_sc::imports!();
multiversx_sc::derive_imports!();

use common_structs::LockedAssetTokenAttributes;
use common_structs::LockedAssetTokenAttributesEx;
use common_structs::UnlockMilestoneEx;
use common_structs::UnlockScheduleEx;

// 1% = 1_000;
pub const _PRECISION_EXTENDED: u64 = 100_000u64;

// From 1 to 1_000;
pub const PRECISION_EX_INCREASE: u64 = 1_000u64;

#[multiversx_sc::module]
pub trait AttrExHelper {
fn get_attributes_ex(
&self,
token_id: &TokenIdentifier,
token_nonce: u64,
attr_ex_activation: u64,
) -> LockedAssetTokenAttributesEx<Self::Api> {
let token_info = self.blockchain().get_esdt_token_data(
&self.blockchain().get_sc_address(),
token_id,
token_nonce,
);

if token_nonce < attr_ex_activation {
let attr = self
.serializer()
.top_decode_from_managed_buffer::<LockedAssetTokenAttributes<Self::Api>>(
&token_info.attributes,
);
self.convert_attr_to_attr_ex(&attr)
} else {
self.serializer()
.top_decode_from_managed_buffer::<LockedAssetTokenAttributesEx<Self::Api>>(
&token_info.attributes,
)
}
}

fn convert_attr_to_attr_ex(
&self,
attr: &LockedAssetTokenAttributes<Self::Api>,
) -> LockedAssetTokenAttributesEx<Self::Api> {
let mut new_milestones: ManagedVec<UnlockMilestoneEx> = ManagedVec::new();

for milestones in attr.unlock_schedule.unlock_milestones.iter() {
new_milestones.push(UnlockMilestoneEx {
unlock_epoch: milestones.unlock_epoch,
unlock_percent: (milestones.unlock_percent as u64) * PRECISION_EX_INCREASE,
});
}

LockedAssetTokenAttributesEx {
unlock_schedule: UnlockScheduleEx {
unlock_milestones: new_milestones,
},
is_merged: attr.is_merged,
}
}

#[view(getExtendedAttributesActivationNonce)]
#[storage_mapper("extended_attributes_activation_nonce")]
fn extended_attributes_activation_nonce(&self) -> SingleValueMapper<u64>;
}
Loading
Loading