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

legacy distribution sc #965

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
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
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
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
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>();
}
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
Loading