Skip to content

Commit

Permalink
Merge pull request #965 from multiversx/legacy-distribution-sc
Browse files Browse the repository at this point in the history
Add legacy distribution SC
  • Loading branch information
psorinionut authored Oct 21, 2024
2 parents 5e828fd + ad6fd1c commit 79c6016
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 495 deletions.
35 changes: 17 additions & 18 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ members = [
"legacy-contracts/price-discovery-v1/meta",
"legacy-contracts/price-discovery-v2",
"legacy-contracts/price-discovery-v2/meta",
"legacy-contracts/locked-asset-distribution",
"legacy-contracts/locked-asset-distribution/meta",

"locked-asset/",
"locked-asset/distribution",
"locked-asset/distribution/meta",
"locked-asset/proxy_dex",
"locked-asset/proxy_dex/meta",
"locked-asset/lkmex-transfer",
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
edition = "2021"
name = "distribution"
name = "locked-asset-distribution"
publish = false
version = "0.0.0"

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "distribution-abi"
name = "locked-asset-distribution-abi"
version = "0.0.0"
authors = ["MultiversX <[email protected]>"]
edition = "2021"
publish = false

[dependencies.distribution]
[dependencies.locked-asset-distribution]
path = ".."

[dependencies.multiversx-sc-meta-lib]
Expand Down
3 changes: 3 additions & 0 deletions legacy-contracts/locked-asset-distribution/meta/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
multiversx_sc_meta_lib::cli_main::<locked_asset_distribution::AbiProvider>();
}
File renamed without changes.
92 changes: 92 additions & 0 deletions legacy-contracts/locked-asset-distribution/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#![no_std]
#![allow(clippy::type_complexity)]

use common_structs::UnlockPeriod;

multiversx_sc::imports!();
multiversx_sc::derive_imports!();

#[derive(ManagedVecItem)]
pub struct BigUintEpochPair<M: ManagedTypeApi> {
pub biguint: BigUint<M>,
pub epoch: u64,
}

#[derive(ManagedVecItem, TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi)]
pub struct UserLockedAssetKey<M: ManagedTypeApi> {
pub caller: ManagedAddress<M>,
pub spread_epoch: u64,
}

#[derive(TopEncode, TopDecode, NestedEncode, NestedDecode, PartialEq, TypeAbi, Clone)]
pub struct CommunityDistribution<M: ManagedTypeApi> {
pub total_amount: BigUint<M>,
pub spread_epoch: u64,
pub after_planning_amount: BigUint<M>,
}

#[multiversx_sc::contract]
pub trait Distribution {
#[init]
fn init(&self) {}

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

#[endpoint(clearSingleValueMappers)]
fn clear_single_value_mappers(&self) {
self.unlock_period().clear();
self.locked_asset_factory_address().clear();
self.asset_token_id().clear();
self.global_op_is_ongoing().clear();
}

// Returns the number of entries deleted and entries remaining in the storage.
#[endpoint(clearCommunityDistributionList)]
fn clear_community_distribution_list(&self, entries_to_delete: u64) -> (u64, usize) {
let mut counter = 0;
for node in self.community_distribution_list().iter() {
if counter >= entries_to_delete {
break;
}
self.community_distribution_list().remove_node(&node);
counter += 1;
}
(counter, self.community_distribution_list().len())
}

// Returns the number of entries deleted and entries remaining in the storage.
#[endpoint(clearUserLockedAssetMap)]
fn clear_user_locked_asset_map(&self, entries_to_delete: u64) -> (u64, usize) {
let mut counter = 0;
for key in self.user_locked_asset_map().keys() {
if counter >= entries_to_delete {
break;
}
self.user_locked_asset_map().remove(&key);
counter += 1;
}
(counter, self.user_locked_asset_map().len())
}

#[view(getUnlockPeriod)]
#[storage_mapper("unlock_period")]
fn unlock_period(&self) -> SingleValueMapper<UnlockPeriod<Self::Api>>;

#[view(getCommunityDistributionList)]
#[storage_mapper("community_distribution_list")]
fn community_distribution_list(&self) -> LinkedListMapper<CommunityDistribution<Self::Api>>;

#[storage_mapper("user_locked_asset_map")]
fn user_locked_asset_map(&self) -> MapMapper<UserLockedAssetKey<Self::Api>, BigUint>;

#[storage_mapper("locked_asset_factory_address")]
fn locked_asset_factory_address(&self) -> SingleValueMapper<ManagedAddress>;

#[view(getAssetTokenId)]
#[storage_mapper("asset_token_id")]
fn asset_token_id(&self) -> SingleValueMapper<TokenIdentifier>;

#[storage_mapper("global_operation_ongoing")]
fn global_op_is_ongoing(&self) -> SingleValueMapper<bool>;
}

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

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ##########################################

[package]
name = "distribution-wasm"
name = "locked-asset-distribution-wasm"
version = "0.0.0"
edition = "2021"
publish = false
Expand All @@ -24,7 +24,7 @@ overflow-checks = false
[profile.dev]
panic = "abort"

[dependencies.distribution]
[dependencies.locked-asset-distribution]
path = ".."

[dependencies.multiversx-sc-wasm-adapter]
Expand Down
32 changes: 32 additions & 0 deletions legacy-contracts/locked-asset-distribution/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Code generated by the multiversx-sc build system. DO NOT EDIT.

////////////////////////////////////////////////////
////////////////// AUTO-GENERATED //////////////////
////////////////////////////////////////////////////

// Init: 1
// Upgrade: 1
// Endpoints: 6
// Async Callback (empty): 1
// Total number of exported functions: 9

#![no_std]

multiversx_sc_wasm_adapter::allocator!();
multiversx_sc_wasm_adapter::panic_handler!();

multiversx_sc_wasm_adapter::endpoints! {
locked_asset_distribution
(
init => init
upgrade => upgrade
clearSingleValueMappers => clear_single_value_mappers
clearCommunityDistributionList => clear_community_distribution_list
clearUserLockedAssetMap => clear_user_locked_asset_map
getUnlockPeriod => unlock_period
getCommunityDistributionList => community_distribution_list
getAssetTokenId => asset_token_id
)
}

multiversx_sc_wasm_adapter::async_callback_empty! {}
3 changes: 0 additions & 3 deletions locked-asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ path = "../dex/pair"
[dependencies.router]
path = "../dex/router"

[dependencies.distribution]
path = "distribution"

[dependencies.simple-lock]
path = "simple-lock"

Expand Down
3 changes: 0 additions & 3 deletions locked-asset/distribution/elrond.json

This file was deleted.

3 changes: 0 additions & 3 deletions locked-asset/distribution/meta/src/main.rs

This file was deleted.

42 changes: 0 additions & 42 deletions locked-asset/distribution/src/global_op.rs

This file was deleted.

Loading

0 comments on commit 79c6016

Please sign in to comment.