-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #965 from multiversx/legacy-distribution-sc
Add legacy distribution SC
- Loading branch information
Showing
18 changed files
with
167 additions
and
495 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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
locked-asset/distribution/Cargo.toml → ...acts/locked-asset-distribution/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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
locked-asset/distribution/meta/Cargo.toml → ...locked-asset-distribution/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 |
---|---|---|
@@ -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] | ||
|
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_lib::cli_main::<locked_asset_distribution::AbiProvider>(); | ||
} |
File renamed without changes.
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,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>; | ||
} |
32 changes: 16 additions & 16 deletions
32
locked-asset/distribution/wasm/Cargo.lock → ...locked-asset-distribution/wasm/Cargo.lock
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
32 changes: 32 additions & 0 deletions
32
legacy-contracts/locked-asset-distribution/wasm/src/lib.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,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! {} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.