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

unlock schedule update endpoint #74

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
name: Contracts
uses: multiversx/mx-sc-actions/.github/workflows/[email protected]
with:
rust-toolchain: nightly-2023-05-27
rust-toolchain: nightly-2023-05-26
sc-meta-version: 0.41.1
vmtools-version: v1.4.60
secrets:
token: ${{ secrets.GITHUB_TOKEN }}
3 changes: 3 additions & 0 deletions launchpad-guaranteed-tickets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ pub trait LaunchpadGuaranteedTickets:
.set(min_confirmed_for_guaranteed_ticket);
}

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

#[only_owner]
#[endpoint(addTickets)]
fn add_tickets_endpoint(
Expand Down
50 changes: 50 additions & 0 deletions launchpad-guaranteed-tickets/src/token_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,56 @@ pub trait TokenReleaseModule: config::ConfigModule {
self.unlock_schedule().set(unlock_schedule);
}

#[only_owner]
#[endpoint(updateUnlockSchedule)]
fn update_unlock_schedule(
&self,
vesting_release_times: u64,
vesting_release_percentage: u64,
vesting_release_period: u64,
) {
let unlock_schedule_mapper = self.unlock_schedule();
require!(
!unlock_schedule_mapper.is_empty(),
"Unlock schedule is not set"
);

let unlocks_schedule = unlock_schedule_mapper.get();
let current_round = self.blockchain().get_block_round();
require!(
current_round > unlocks_schedule.claim_start_round,
"Unlock schedule update only possible after claim start round"
);
require!(
current_round < unlocks_schedule.claim_start_round + vesting_release_period,
"Unlock schedule update only possible between start claim and first vesting release"
);

require!(
vesting_release_period > 0
|| unlocks_schedule.initial_release_percentage == MAX_PERCENTAGE,
"Wrong vesting release recurrency"
);

let unlock_percentage = unlocks_schedule.initial_release_percentage
+ vesting_release_times * vesting_release_percentage;

require!(
unlock_percentage == MAX_PERCENTAGE,
"Unlock percentage is not 100%"
);

let unlock_schedule = UnlockSchedule::new(
unlocks_schedule.claim_start_round,
unlocks_schedule.initial_release_percentage,
vesting_release_times,
vesting_release_percentage,
vesting_release_period,
);

self.unlock_schedule().set(unlock_schedule);
}

#[view(getClaimableTokens)]
fn compute_claimable_tokens(&self, address: &ManagedAddress) -> BigUint {
let user_total_claimable_balance = self.user_total_claimable_balance(address).get();
Expand Down
6 changes: 4 additions & 2 deletions launchpad-guaranteed-tickets/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
////////////////////////////////////////////////////

// Init: 1
// Endpoints: 39
// Endpoints: 41
// Async Callback (empty): 1
// Total number of exported functions: 41
// Total number of exported functions: 43

#![no_std]
#![feature(lang_items)]
Expand All @@ -18,6 +18,7 @@ multiversx_sc_wasm_adapter::panic_handler!();
multiversx_sc_wasm_adapter::endpoints! {
launchpad_guaranteed_tickets
(
upgrade
addTickets
depositLaunchpadTokens
addUsersToBlacklist
Expand Down Expand Up @@ -53,6 +54,7 @@ multiversx_sc_wasm_adapter::endpoints! {
confirmTickets
hasUserClaimedTokens
setUnlockSchedule
updateUnlockSchedule
getClaimableTokens
getUserTotalClaimableBalance
getUserClaimedBalance
Expand Down
Loading