Ninja'd that sh*t
This commit is contained in:
parent
e187212b7d
commit
fc35a71660
|
@ -49,9 +49,21 @@ program
|
|||
'--keypair not provided',
|
||||
)
|
||||
.option('-u, --uuid <string>', 'uuid')
|
||||
.option('-f, --fee <string>', 'price range end', '2')
|
||||
.option('-f, --fee <string>', 'fee', '2')
|
||||
.option('-s, --price-range-start <string>', 'price range start', '1')
|
||||
.option('-e, --price-range-end <string>', 'price range end', '2')
|
||||
.option(
|
||||
'-arbp, --anti-rug-reserve-bp <string>',
|
||||
'optional anti-rug treasury reserve basis points (1-10000)',
|
||||
)
|
||||
.option(
|
||||
'-atc, --anti-rug-token-requirement <string>',
|
||||
'optional anti-rug token requirement when reserve opens - 100 means 100 tokens remaining out of total supply',
|
||||
)
|
||||
.option(
|
||||
'-sd, --self-destruct-date <string>',
|
||||
'optional date when funds from anti-rug setting will be returned - eg "04 Dec 1995 00:12:00 GMT"',
|
||||
)
|
||||
.option(
|
||||
'-pos, --phase-one-start-date <string>',
|
||||
'timestamp - eg "04 Dec 1995 00:12:00 GMT"',
|
||||
|
@ -84,7 +96,31 @@ program
|
|||
fee,
|
||||
mint,
|
||||
uuid,
|
||||
selfDestructDate,
|
||||
antiRugTokenRequirement,
|
||||
antiRugReserveBp,
|
||||
} = cmd.opts();
|
||||
const antiRugTokenRequirementNumber = antiRugTokenRequirement
|
||||
? parseInt(antiRugTokenRequirement)
|
||||
: null;
|
||||
const antiRugReserveBpNumber = antiRugReserveBp
|
||||
? parseFloat(antiRugReserveBp)
|
||||
: null;
|
||||
const selfDestructDateActual = selfDestructDate
|
||||
? Date.parse(selfDestructDate) / 1000
|
||||
: null;
|
||||
|
||||
const antiRug =
|
||||
antiRugTokenRequirementNumber &&
|
||||
antiRugReserveBpNumber &&
|
||||
selfDestructDateActual
|
||||
? {
|
||||
reserveBp: antiRugReserveBpNumber,
|
||||
tokenRequirement: antiRugTokenRequirementNumber,
|
||||
selfDestructDate: selfDestructDateActual,
|
||||
}
|
||||
: null;
|
||||
|
||||
const parsedNumber = parseInt(numberOfTokens);
|
||||
let priceRangeStartNumber = parseFloat(priceRangeStart);
|
||||
let priceRangeEndNumber = parseFloat(priceRangeEnd);
|
||||
|
@ -132,7 +168,6 @@ program
|
|||
fairLaunchBump,
|
||||
treasuryBump,
|
||||
tokenBump,
|
||||
|
||||
{
|
||||
uuid: realUuid,
|
||||
priceRangeStart: new anchor.BN(priceRangeStartNumber),
|
||||
|
@ -143,6 +178,7 @@ program
|
|||
tickSize: new anchor.BN(tickSizeNumber),
|
||||
numberOfTokens: new anchor.BN(parsedNumber),
|
||||
fee: new anchor.BN(feeNumber),
|
||||
antiRugSetting: antiRug,
|
||||
},
|
||||
{
|
||||
accounts: {
|
||||
|
@ -179,6 +215,18 @@ program
|
|||
.option('-f, --fee <string>', 'price range end', '2')
|
||||
.option('-s, --price-range-start <string>', 'price range start', '1')
|
||||
.option('-e, --price-range-end <string>', 'price range end', '2')
|
||||
.option(
|
||||
'-arbp, --anti-rug-reserve-bp <string>',
|
||||
'optional anti-rug treasury reserve basis points (1-10000)',
|
||||
)
|
||||
.option(
|
||||
'-atc, --anti-rug-token-requirement <string>',
|
||||
'optional anti-rug token requirement when reserve opens - 100 means 100 tokens remaining out of total supply',
|
||||
)
|
||||
.option(
|
||||
'-sd, --self-destruct-date <string>',
|
||||
'optional date when funds from anti-rug setting will be returned - eg "04 Dec 1995 00:12:00 GMT"',
|
||||
)
|
||||
.option(
|
||||
'-pos, --phase-one-start-date <string>',
|
||||
'timestamp - eg "04 Dec 1995 00:12:00 GMT"',
|
||||
|
@ -211,7 +259,30 @@ program
|
|||
fee,
|
||||
mint,
|
||||
uuid,
|
||||
selfDestructDate,
|
||||
antiRugTokenRequirement,
|
||||
antiRugReserveBp,
|
||||
} = cmd.opts();
|
||||
const antiRugTokenRequirementNumber = antiRugTokenRequirement
|
||||
? parseInt(antiRugTokenRequirement)
|
||||
: null;
|
||||
const antiRugReserveBpNumber = antiRugReserveBp
|
||||
? parseFloat(antiRugReserveBp)
|
||||
: null;
|
||||
const selfDestructDateActual = selfDestructDate
|
||||
? Date.parse(selfDestructDate) / 1000
|
||||
: null;
|
||||
|
||||
const antiRug =
|
||||
antiRugTokenRequirementNumber &&
|
||||
antiRugReserveBpNumber &&
|
||||
selfDestructDateActual
|
||||
? {
|
||||
reserveBp: antiRugReserveBpNumber,
|
||||
tokenRequirement: antiRugTokenRequirementNumber,
|
||||
selfDestructDate: selfDestructDateActual,
|
||||
}
|
||||
: null;
|
||||
const parsedNumber = parseInt(numberOfTokens);
|
||||
let priceRangeStartNumber = parseFloat(priceRangeStart);
|
||||
let priceRangeEndNumber = parseFloat(priceRangeEnd);
|
||||
|
@ -255,6 +326,7 @@ program
|
|||
tickSize: new anchor.BN(tickSizeNumber),
|
||||
numberOfTokens: new anchor.BN(parsedNumber),
|
||||
fee: new anchor.BN(feeNumber),
|
||||
antiRugSetting: antiRug,
|
||||
},
|
||||
{
|
||||
accounts: {
|
||||
|
@ -434,8 +506,9 @@ program
|
|||
)
|
||||
)[0];
|
||||
|
||||
const fairLaunchLotteryBitmap = //@ts-ignore
|
||||
(await getFairLaunchLotteryBitmap(fairLaunchObj.tokenMint))[0];
|
||||
const fairLaunchLotteryBitmap = ( //@ts-ignore
|
||||
await getFairLaunchLotteryBitmap(fairLaunchObj.tokenMint)
|
||||
)[0];
|
||||
|
||||
const remainingAccounts = [];
|
||||
const instructions = [];
|
||||
|
@ -512,6 +585,44 @@ program
|
|||
);
|
||||
});
|
||||
|
||||
program
|
||||
.command('start_phase_three')
|
||||
.option(
|
||||
'-e, --env <string>',
|
||||
'Solana cluster env name',
|
||||
'devnet', //mainnet-beta, testnet, devnet
|
||||
)
|
||||
.option(
|
||||
'-k, --keypair <path>',
|
||||
`Solana wallet location`,
|
||||
'--keypair not provided',
|
||||
)
|
||||
.option('-f, --fair-launch <string>', 'fair launch id')
|
||||
.action(async (_, cmd) => {
|
||||
const { env, keypair, fairLaunch } = cmd.opts();
|
||||
|
||||
const walletKeyPair = loadWalletKey(keypair);
|
||||
const anchorProgram = await loadFairLaunchProgram(walletKeyPair, env);
|
||||
|
||||
const fairLaunchKey = new anchor.web3.PublicKey(fairLaunch);
|
||||
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
||||
fairLaunchKey,
|
||||
);
|
||||
const fairLaunchLotteryBitmap = ( //@ts-ignore
|
||||
await getFairLaunchLotteryBitmap(fairLaunchObj.tokenMint)
|
||||
)[0];
|
||||
|
||||
await anchorProgram.rpc.startPhaseThree({
|
||||
accounts: {
|
||||
fairLaunch,
|
||||
fairLaunchLotteryBitmap,
|
||||
authority: walletKeyPair.publicKey,
|
||||
},
|
||||
});
|
||||
|
||||
console.log(`Dang son, phase three.`);
|
||||
});
|
||||
|
||||
program
|
||||
.command('create_fair_launch_lottery')
|
||||
.option(
|
||||
|
@ -1056,6 +1167,10 @@ program
|
|||
const fairLaunchLotteryBitmapObj =
|
||||
await anchorProgram.provider.connection.getAccountInfo(fairLaunchLottery);
|
||||
|
||||
const fairLaunchLotteryBitmapAnchorObj =
|
||||
await anchorProgram.account.fairLaunchLotteryBitmap.fetch(
|
||||
fairLaunchLottery,
|
||||
);
|
||||
const seqKeys = [];
|
||||
//@ts-ignore
|
||||
for (let i = 0; i < fairLaunchObj.numberTicketsSold; i++) {
|
||||
|
@ -1129,5 +1244,11 @@ program
|
|||
isWinner > 0 ? 'won' : 'lost',
|
||||
);
|
||||
}
|
||||
|
||||
console.log(
|
||||
'Bit Map ones',
|
||||
//@ts-ignore
|
||||
fairLaunchLotteryBitmapAnchorObj.bitmapOnes.toNumber(),
|
||||
);
|
||||
});
|
||||
program.parse(process.argv);
|
||||
|
|
|
@ -154,7 +154,7 @@ pub mod fair_launch {
|
|||
let fair_launch = &mut ctx.accounts.fair_launch;
|
||||
let fair_launch_lottery_bitmap = &ctx.accounts.fair_launch_lottery_bitmap;
|
||||
|
||||
if fair_launch_lottery_bitmap.bitmap_ones != fair_launch.number_tickets_sold {
|
||||
if fair_launch_lottery_bitmap.bitmap_ones != fair_launch.data.number_of_tokens {
|
||||
return Err(ErrorCode::LotteryBitmapOnesMustEqualNumberOfTicketsSold.into());
|
||||
}
|
||||
|
||||
|
@ -182,8 +182,8 @@ pub mod fair_launch {
|
|||
let mut curr_pos = FAIR_LAUNCH_LOTTERY_SIZE + (index as usize);
|
||||
for byte in bytes {
|
||||
let curr_byte = lottery_data[curr_pos];
|
||||
msg!("Curr byte is {}", curr_byte);
|
||||
for bit_position in 0..7 {
|
||||
msg!("Curr byte is {}, new byte is {}", curr_byte, byte);
|
||||
for bit_position in 0..8 {
|
||||
msg!("Looking for position {}", bit_position);
|
||||
let mask = u8::pow(2, bit_position as u32);
|
||||
let curr_byte_masked = curr_byte & mask;
|
||||
|
@ -224,9 +224,8 @@ pub mod fair_launch {
|
|||
.checked_add(number_of_ones_changed as u64)
|
||||
.ok_or(ErrorCode::NumericalOverflowError)?;
|
||||
}
|
||||
|
||||
lottery_data[FAIR_LAUNCH_LOTTERY_SIZE - 4..FAIR_LAUNCH_LOTTERY_SIZE]
|
||||
.copy_from_slice(&(new_number_of_ones as u32).to_le_bytes());
|
||||
msg!("new number of ones is {}", new_number_of_ones);
|
||||
fair_launch_lottery_bitmap.bitmap_ones = new_number_of_ones;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -934,6 +933,10 @@ pub const FAIR_LAUNCH_SPACE_VEC_START: usize = 8 + // discriminator
|
|||
8 + // tick size
|
||||
8 + // number of tokens
|
||||
8 + // fee
|
||||
1 + // anti rug option
|
||||
2 + // anti rug bp
|
||||
8 + // anti rug token count
|
||||
8 + // self destruct date
|
||||
8 + // number of tickets unseq'ed
|
||||
8 + // number of tickets sold
|
||||
8 + // number of tickets dropped
|
||||
|
@ -956,6 +959,17 @@ pub const FAIR_LAUNCH_TICKET_SEQ_SIZE: usize = 8 + //discriminator
|
|||
8 + //seq
|
||||
1; // bump
|
||||
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
|
||||
pub struct AntiRugSetting {
|
||||
/// basis points kept in the treasury until conditions are met
|
||||
pub reserve_bp: u16,
|
||||
/// The supply of the fair launch mint must be below this amount
|
||||
/// to unlock the reserve
|
||||
pub token_requirement: u64,
|
||||
/// if you don't meet your promise by this date, pro-rated refunds are allowed
|
||||
pub self_destruct_date: i64,
|
||||
}
|
||||
|
||||
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Default)]
|
||||
pub struct FairLaunchData {
|
||||
pub uuid: String,
|
||||
|
@ -967,6 +981,7 @@ pub struct FairLaunchData {
|
|||
pub tick_size: u64,
|
||||
pub number_of_tokens: u64,
|
||||
pub fee: u64,
|
||||
pub anti_rug_setting: Option<AntiRugSetting>,
|
||||
}
|
||||
|
||||
#[account]
|
||||
|
|
|
@ -135,12 +135,13 @@ pub fn adjust_counts(
|
|||
let mut ticks: u64 = 0;
|
||||
let mut last_seen_tick_value_with_positive_counts: u64 = 0;
|
||||
for n in &fair_launch.counts_at_each_tick {
|
||||
let is_possible_perfect_split = counter == median_location;
|
||||
counter = counter
|
||||
.checked_add(*n)
|
||||
.ok_or(ErrorCode::NumericalOverflowError)?;
|
||||
if counter > median_location {
|
||||
if let Some(val) = median_location.checked_rem(2) {
|
||||
if val == 0 {
|
||||
if let Some(val) = total_counts.checked_rem(2) {
|
||||
if val == 0 && is_possible_perfect_split {
|
||||
let half_way = ticks
|
||||
.checked_sub(last_seen_tick_value_with_positive_counts)
|
||||
.ok_or(ErrorCode::NumericalOverflowError)?;
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue