Skip to content

Commit

Permalink
unlock schedule update endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
psorinionut committed Jul 9, 2024
1 parent d7e0ff1 commit c050cec
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
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
5 changes: 3 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: 40
// Async Callback (empty): 1
// Total number of exported functions: 41
// Total number of exported functions: 42

#![no_std]
#![feature(lang_items)]
Expand Down Expand Up @@ -53,6 +53,7 @@ multiversx_sc_wasm_adapter::endpoints! {
confirmTickets
hasUserClaimedTokens
setUnlockSchedule
updateUnlockSchedule
getClaimableTokens
getUserTotalClaimableBalance
getUserClaimedBalance
Expand Down

0 comments on commit c050cec

Please sign in to comment.