Skip to content

Commit

Permalink
removed init to allow upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ovidiuolteanu committed Dec 22, 2022
1 parent 21bd9c2 commit 2c43374
Showing 1 changed file with 1 addition and 85 deletions.
86 changes: 1 addition & 85 deletions dex/price-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,91 +27,7 @@ pub trait PriceDiscovery:
{
/// For explanations regarding what each parameter means, please refer to docs/setup.md
#[init]
fn init(
&self,
launched_token_id: TokenIdentifier,
accepted_token_id: EgldOrEsdtTokenIdentifier,
launched_token_decimals: u32,
min_launched_token_price: BigUint,
start_block: u64,
no_limit_phase_duration_blocks: u64,
linear_penalty_phase_duration_blocks: u64,
fixed_penalty_phase_duration_blocks: u64,
unlock_epoch: u64,
penalty_min_percentage: BigUint,
penalty_max_percentage: BigUint,
fixed_penalty_percentage: BigUint,
locking_sc_address: ManagedAddress,
) {
require!(
launched_token_id.is_valid_esdt_identifier(),
"Invalid launched token ID"
);
require!(accepted_token_id.is_valid(), "Invalid payment token ID");
require!(
accepted_token_id != launched_token_id,
"Launched and accepted token must be different"
);

require!(
launched_token_decimals <= MAX_TOKEN_DECIMALS,
"Launched token has too many decimals"
);

let current_block = self.blockchain().get_block_nonce();
require!(
current_block < start_block,
"Start block cannot be in the past"
);

let end_block = start_block
+ no_limit_phase_duration_blocks
+ linear_penalty_phase_duration_blocks
+ fixed_penalty_phase_duration_blocks;

require!(
penalty_min_percentage <= penalty_max_percentage,
"Min percentage higher than max percentage"
);
require!(
penalty_max_percentage < MAX_PERCENTAGE,
"Max percentage higher than 100%"
);
require!(
fixed_penalty_percentage < MAX_PERCENTAGE,
"Fixed percentage higher than 100%"
);

let current_epoch = self.blockchain().get_block_epoch();
require!(
unlock_epoch > current_epoch,
"Unlock epoch cannot be in the past"
);

self.launched_token_id().set(&launched_token_id);
self.accepted_token_id().set(&accepted_token_id);
self.start_block().set(start_block);
self.end_block().set(end_block);
self.unlock_epoch().set(unlock_epoch);

let price_precision = 10u64.pow(launched_token_decimals);
self.price_precision().set(price_precision);
self.min_launched_token_price()
.set(&min_launched_token_price);

self.no_limit_phase_duration_blocks()
.set(no_limit_phase_duration_blocks);
self.linear_penalty_phase_duration_blocks()
.set(linear_penalty_phase_duration_blocks);
self.fixed_penalty_phase_duration_blocks()
.set(fixed_penalty_phase_duration_blocks);
self.penalty_min_percentage().set(&penalty_min_percentage);
self.penalty_max_percentage().set(&penalty_max_percentage);
self.fixed_penalty_percentage()
.set(&fixed_penalty_percentage);

self.set_locking_sc_address(locking_sc_address);
}
fn init(&self) {}

/// Users can deposit either launched_token or accepted_token.
/// They will receive an SFT that can be used to withdraw said tokens
Expand Down

0 comments on commit 2c43374

Please sign in to comment.