Skip to content

Commit

Permalink
changes epochs usage to rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiuolteanu committed Jan 18, 2024
1 parent 1d59a55 commit 814d73a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
24 changes: 12 additions & 12 deletions launchpad-guaranteed-tickets/src/token_release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const MAX_PERCENTAGE: u64 = 10_000;

#[derive(TopEncode, TopDecode, TypeAbi)]
pub struct UnlockSchedule {
claim_start_epoch: u64,
claim_start_round: u64,
initial_release_percentage: u64,
vesting_release_times: u64,
vesting_release_percentage: u64,
Expand All @@ -16,14 +16,14 @@ pub struct UnlockSchedule {

impl UnlockSchedule {
pub fn new(
claim_start_epoch: u64,
claim_start_round: u64,
initial_release_percentage: u64,
vesting_release_times: u64,
vesting_release_percentage: u64,
vesting_release_period: u64,
) -> Self {
UnlockSchedule {
claim_start_epoch,
claim_start_round,
initial_release_percentage,
vesting_release_times,
vesting_release_percentage,
Expand All @@ -38,7 +38,7 @@ pub trait TokenReleaseModule: config::ConfigModule {
#[endpoint(setUnlockSchedule)]
fn set_unlock_schedule(
&self,
claim_start_epoch: u64,
claim_start_round: u64,
initial_release_percentage: u64,
vesting_release_times: u64,
vesting_release_percentage: u64,
Expand All @@ -52,14 +52,14 @@ pub trait TokenReleaseModule: config::ConfigModule {
let confirmation_period_start_block = configuration.get().confirmation_period_start_block;

let current_block = self.blockchain().get_block_nonce();
let current_epoch = self.blockchain().get_block_epoch();
let current_round = self.blockchain().get_block_round();
require!(
current_block < confirmation_period_start_block || self.unlock_schedule().is_empty(),
"Can't change the unlock schedule"
);
require!(
claim_start_epoch >= current_epoch,
"Wrong claim start epoch"
claim_start_round >= current_round,
"Wrong claim start round"
);
require!(
vesting_release_period > 0,
Expand All @@ -75,7 +75,7 @@ pub trait TokenReleaseModule: config::ConfigModule {
);

let unlock_schedule = UnlockSchedule::new(
claim_start_epoch,
claim_start_round,
initial_release_percentage,
vesting_release_times,
vesting_release_percentage,
Expand All @@ -97,13 +97,13 @@ pub trait TokenReleaseModule: config::ConfigModule {
return BigUint::zero();
}
let unlock_schedule = unlock_schedule_mapper.get();
let current_epoch = self.blockchain().get_block_epoch();
if unlock_schedule.claim_start_epoch > current_epoch {
let current_round = self.blockchain().get_block_round();
if unlock_schedule.claim_start_round > current_round {
return BigUint::zero();
}

let epochs_passed = current_epoch - unlock_schedule.claim_start_epoch;
let mut claimable_periods = epochs_passed / unlock_schedule.vesting_release_period;
let rounds_passed = current_round - unlock_schedule.claim_start_round;
let mut claimable_periods = rounds_passed / unlock_schedule.vesting_release_period;
if claimable_periods > unlock_schedule.vesting_release_times {
claimable_periods = unlock_schedule.vesting_release_times;
}
Expand Down
7 changes: 5 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: 35
// Endpoints: 38
// Async Callback (empty): 1
// Total number of exported functions: 37
// Total number of exported functions: 40

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

Expand Down

0 comments on commit 814d73a

Please sign in to comment.