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

Round based Launchpad #92

Merged
merged 3 commits into from
Jan 27, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ permissions:
jobs:
contracts:
name: Contracts
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v3.3.1
uses: multiversx/mx-sc-actions/.github/workflows/contracts.yml@v4.2.1
with:
rust-toolchain: stable
enable-contracts-size-report: false
Expand Down
14 changes: 0 additions & 14 deletions .github/workflows/on_pull_request_build_contracts.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ permissions:

jobs:
build:
uses: multiversx/mx-sc-actions/.github/workflows/reproducible-build.yml@v3.3.1
uses: multiversx/mx-sc-actions/.github/workflows/reproducible-build.yml@v4.2.1
with:
image_tag: v7.0.0
attach_to_existing_release: true
Expand Down
50 changes: 25 additions & 25 deletions launchpad-common/src/common_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ multiversx_sc::derive_imports!();
#[derive(TypeAbi, TopEncode)]
pub struct RefundTicketPaymentEvent<M: ManagedTypeApi> {
user: ManagedAddress<M>,
block: u64,
round: u64,
epoch: u64,
tickets_refunded: usize,
token_payment: EgldOrEsdtTokenPayment<M>,
Expand All @@ -13,15 +13,15 @@ pub struct RefundTicketPaymentEvent<M: ManagedTypeApi> {
#[derive(TypeAbi, TopEncode)]
pub struct SetTicketPriceEvent<M: ManagedTypeApi> {
user: ManagedAddress<M>,
block: u64,
round: u64,
epoch: u64,
ticket_price: EgldOrEsdtTokenPayment<M>,
}

#[derive(TypeAbi, TopEncode)]
pub struct ConfirmTicketsEvent<M: ManagedTypeApi> {
user: ManagedAddress<M>,
block: u64,
round: u64,
epoch: u64,
tickets_confirmed: usize,
total_confirmed: usize,
Expand All @@ -32,15 +32,15 @@ pub struct ConfirmTicketsEvent<M: ManagedTypeApi> {
#[derive(TypeAbi, TopEncode)]
pub struct FilterTicketsCompletedEvent<M: ManagedTypeApi> {
user: ManagedAddress<M>,
block: u64,
round: u64,
epoch: u64,
total_tickets_after_filtering: usize,
}

#[derive(TypeAbi, TopEncode)]
pub struct SelectWinnersCompletedEvent<M: ManagedTypeApi> {
user: ManagedAddress<M>,
block: u64,
round: u64,
epoch: u64,
total_winning_tickets: usize,
}
Expand All @@ -53,15 +53,15 @@ pub trait CommonEventsModule {
token_payment: EgldOrEsdtTokenPayment<Self::Api>,
) {
let user = self.blockchain().get_caller();
let block = self.blockchain().get_block_nonce();
let round = self.blockchain().get_block_round();
let epoch = self.blockchain().get_block_epoch();
self.refund_ticket_payment_event(
user.clone(),
block,
round,
epoch,
RefundTicketPaymentEvent {
user,
block,
round,
epoch,
tickets_refunded,
token_payment,
Expand All @@ -71,15 +71,15 @@ pub trait CommonEventsModule {

fn emit_set_ticket_price_event(&self, ticket_price: EgldOrEsdtTokenPayment<Self::Api>) {
let user = self.blockchain().get_caller();
let block = self.blockchain().get_block_nonce();
let round = self.blockchain().get_block_round();
let epoch = self.blockchain().get_block_epoch();
self.set_ticket_price_event(
user.clone(),
block,
round,
epoch,
SetTicketPriceEvent {
user,
block,
round,
epoch,
ticket_price,
},
Expand All @@ -94,15 +94,15 @@ pub trait CommonEventsModule {
token_payment: EgldOrEsdtTokenPayment<Self::Api>,
) {
let user = self.blockchain().get_caller();
let block = self.blockchain().get_block_nonce();
let round = self.blockchain().get_block_round();
let epoch = self.blockchain().get_block_epoch();
self.confirm_tickets_event(
user.clone(),
block,
round,
epoch,
ConfirmTicketsEvent {
user,
block,
round,
epoch,
tickets_confirmed,
total_confirmed,
Expand All @@ -114,15 +114,15 @@ pub trait CommonEventsModule {

fn emit_filter_tickets_completed_event(&self, total_tickets_after_filtering: usize) {
let user = self.blockchain().get_caller();
let block = self.blockchain().get_block_nonce();
let round = self.blockchain().get_block_round();
let epoch = self.blockchain().get_block_epoch();
self.filter_tickets_completed_event(
user.clone(),
block,
round,
epoch,
FilterTicketsCompletedEvent {
user,
block,
round,
epoch,
total_tickets_after_filtering,
},
Expand All @@ -131,15 +131,15 @@ pub trait CommonEventsModule {

fn emit_select_winners_completed_event(&self, total_winning_tickets: usize) {
let user = self.blockchain().get_caller();
let block = self.blockchain().get_block_nonce();
let round = self.blockchain().get_block_round();
let epoch = self.blockchain().get_block_epoch();
self.select_winners_completed_event(
user.clone(),
block,
round,
epoch,
SelectWinnersCompletedEvent {
user,
block,
round,
epoch,
total_winning_tickets,
},
Expand All @@ -150,7 +150,7 @@ pub trait CommonEventsModule {
fn refund_ticket_payment_event(
&self,
#[indexed] caller: ManagedAddress,
#[indexed] block: u64,
#[indexed] round: u64,
#[indexed] epoch: u64,
claim_egld_event: RefundTicketPaymentEvent<Self::Api>,
);
Expand All @@ -159,7 +159,7 @@ pub trait CommonEventsModule {
fn set_ticket_price_event(
&self,
#[indexed] caller: ManagedAddress,
#[indexed] block: u64,
#[indexed] round: u64,
#[indexed] epoch: u64,
set_ticket_price_event: SetTicketPriceEvent<Self::Api>,
);
Expand All @@ -168,7 +168,7 @@ pub trait CommonEventsModule {
fn confirm_tickets_event(
&self,
#[indexed] caller: ManagedAddress,
#[indexed] block: u64,
#[indexed] round: u64,
#[indexed] epoch: u64,
confirm_tickets_event: ConfirmTicketsEvent<Self::Api>,
);
Expand All @@ -177,7 +177,7 @@ pub trait CommonEventsModule {
fn filter_tickets_completed_event(
&self,
#[indexed] caller: ManagedAddress,
#[indexed] block: u64,
#[indexed] round: u64,
#[indexed] epoch: u64,
filter_tickets_completed_event: FilterTicketsCompletedEvent<Self::Api>,
);
Expand All @@ -186,7 +186,7 @@ pub trait CommonEventsModule {
fn select_winners_completed_event(
&self,
#[indexed] caller: ManagedAddress,
#[indexed] block: u64,
#[indexed] round: u64,
#[indexed] epoch: u64,
select_winners_completed_event: SelectWinnersCompletedEvent<Self::Api>,
);
Expand Down
6 changes: 3 additions & 3 deletions launchpad-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ pub struct TokenAmountPair<M: ManagedTypeApi> {

#[derive(TypeAbi, TopEncode, TopDecode)]
pub struct TimelineConfig {
pub confirmation_period_start_block: u64,
pub winner_selection_start_block: u64,
pub claim_start_block: u64,
pub confirmation_period_start_round: u64,
pub winner_selection_start_round: u64,
pub claim_start_round: u64,
}

#[multiversx_sc::module]
Expand Down
12 changes: 6 additions & 6 deletions launchpad-common/src/launch_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ pub struct Flags {
#[multiversx_sc::module]
pub trait LaunchStageModule: crate::config::ConfigModule {
fn get_launch_stage(&self) -> LaunchStage {
let current_block = self.blockchain().get_block_nonce();
let current_round = self.blockchain().get_block_round();
let config: TimelineConfig = self.configuration().get();
let flags: Flags = self.flags().get();

if current_block < config.confirmation_period_start_block {
if current_round < config.confirmation_period_start_round {
return LaunchStage::AddTickets;
}
if current_block < config.winner_selection_start_block {
if current_round < config.winner_selection_start_round {
return LaunchStage::Confirm;
}

let both_selection_steps_completed =
flags.were_winners_selected && flags.was_additional_step_completed;
if current_block >= config.winner_selection_start_block && !both_selection_steps_completed {
if current_round >= config.winner_selection_start_round && !both_selection_steps_completed {
return LaunchStage::WinnerSelection;
}
if current_block >= config.winner_selection_start_block
&& current_block < config.claim_start_block
if current_round >= config.winner_selection_start_round
&& current_round < config.claim_start_round
{
return LaunchStage::WinnerSelection;
}
Expand Down
14 changes: 7 additions & 7 deletions launchpad-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub trait LaunchpadMain:
ticket_payment_token: EgldOrEsdtTokenIdentifier,
ticket_price: BigUint,
nr_winning_tickets: usize,
confirmation_period_start_block: u64,
winner_selection_start_block: u64,
claim_start_block: u64,
confirmation_period_start_round: u64,
winner_selection_start_round: u64,
claim_start_round: u64,
flags: Flags,
) {
if ticket_payment_token.is_esdt() {
Expand All @@ -54,17 +54,17 @@ pub trait LaunchpadMain:
"Launchpad token must be different from ticket payment token"
);
}

self.launchpad_token_id().set(&launchpad_token_id);

self.try_set_launchpad_tokens_per_winning_ticket(&launchpad_tokens_per_winning_ticket);
self.try_set_ticket_price(ticket_payment_token, ticket_price);
self.try_set_nr_winning_tickets(nr_winning_tickets);

let config = TimelineConfig {
confirmation_period_start_block,
winner_selection_start_block,
claim_start_block,
confirmation_period_start_round,
winner_selection_start_round,
claim_start_round,
};
self.require_valid_time_periods(&config);
self.configuration().set(&config);
Expand Down
46 changes: 23 additions & 23 deletions launchpad-common/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,40 +48,40 @@ pub trait SetupModule:
}

#[only_owner]
#[endpoint(setConfirmationPeriodStartBlock)]
fn set_confirmation_period_start_block(&self, new_start_block: u64) {
#[endpoint(setConfirmationPeriodStartRound)]
fn set_confirmation_period_start_round(&self, new_start_round: u64) {
self.configuration().update(|config| {
self.require_valid_config_timeline_change(
config.confirmation_period_start_block,
new_start_block,
config.confirmation_period_start_round,
new_start_round,
);

config.confirmation_period_start_block = new_start_block;
config.confirmation_period_start_round = new_start_round;
self.require_valid_time_periods(config);
});
}

#[only_owner]
#[endpoint(setWinnerSelectionStartBlock)]
fn set_winner_selection_start_block(&self, new_start_block: u64) {
#[endpoint(setWinnerSelectionStartRound)]
fn set_winner_selection_start_round(&self, new_start_round: u64) {
self.configuration().update(|config| {
self.require_valid_config_timeline_change(
config.winner_selection_start_block,
new_start_block,
config.winner_selection_start_round,
new_start_round,
);

config.winner_selection_start_block = new_start_block;
config.winner_selection_start_round = new_start_round;
self.require_valid_time_periods(config);
});
}

#[only_owner]
#[endpoint(setClaimStartBlock)]
fn set_claim_start_block(&self, new_start_block: u64) {
#[endpoint(setClaimStartRound)]
fn set_claim_start_round(&self, new_start_round: u64) {
self.configuration().update(|config| {
self.require_valid_config_timeline_change(config.claim_start_block, new_start_block);
self.require_valid_config_timeline_change(config.claim_start_round, new_start_round);

config.claim_start_block = new_start_block;
config.claim_start_round = new_start_round;
self.require_valid_time_periods(config);
});
}
Expand Down Expand Up @@ -112,25 +112,25 @@ pub trait SetupModule:
self.nr_winning_tickets().set(nr_winning_tickets);
}

fn require_valid_config_timeline_change(&self, old_start_block: u64, new_start_block: u64) {
let current_block = self.blockchain().get_block_nonce();
fn require_valid_config_timeline_change(&self, old_start_round: u64, new_start_round: u64) {
let current_round = self.blockchain().get_block_round();
require!(
old_start_block > current_block,
"Cannot change start block, it's either in progress or passed already"
old_start_round > current_round,
"Cannot change start round, it's either in progress or passed already"
);
require!(
new_start_block > current_block,
"Start block cannot be in the past"
new_start_round > current_round,
"Start round cannot be in the past"
);
}

fn require_valid_time_periods(&self, config: &TimelineConfig) {
require!(
config.confirmation_period_start_block < config.winner_selection_start_block,
"Winner selection start block must be after confirm start block"
config.confirmation_period_start_round < config.winner_selection_start_round,
"Winner selection start round must be after confirm start round"
);
require!(
config.winner_selection_start_block <= config.claim_start_block,
config.winner_selection_start_round <= config.claim_start_round,
"Claim period must be after winner selection"
);
}
Expand Down
Loading
Loading