Adjust ticket
This commit is contained in:
parent
b2ebf9be87
commit
9dd06d4d19
|
@ -18,6 +18,7 @@ import {
|
||||||
getFairLaunchTicket,
|
getFairLaunchTicket,
|
||||||
getAtaForMint,
|
getAtaForMint,
|
||||||
getFairLaunchTicketSeqLookup,
|
getFairLaunchTicketSeqLookup,
|
||||||
|
getFairLaunchLotteryBitmap,
|
||||||
} from './helpers/accounts';
|
} from './helpers/accounts';
|
||||||
import { sleep } from './helpers/various';
|
import { sleep } from './helpers/various';
|
||||||
program.version('0.0.1');
|
program.version('0.0.1');
|
||||||
|
@ -285,6 +286,117 @@ program
|
||||||
|
|
||||||
console.log('Created seq');
|
console.log('Created seq');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
program
|
||||||
|
.command('adjust_ticket')
|
||||||
|
.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')
|
||||||
|
.option('-a, --amount <string>', 'amount')
|
||||||
|
.action(async (_, cmd) => {
|
||||||
|
const { env, keypair, fairLaunch, amount } = cmd.opts();
|
||||||
|
let amountNumber = parseFloat(amount);
|
||||||
|
|
||||||
|
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 fairLaunchTicket = (
|
||||||
|
await getFairLaunchTicket(
|
||||||
|
//@ts-ignore
|
||||||
|
fairLaunchObj.tokenMint,
|
||||||
|
walletKeyPair.publicKey,
|
||||||
|
)
|
||||||
|
)[0];
|
||||||
|
|
||||||
|
const fairLaunchLotteryBitmap = //@ts-ignore
|
||||||
|
(await getFairLaunchLotteryBitmap(fairLaunchObj.tokenMint))[0];
|
||||||
|
|
||||||
|
const remainingAccounts = [];
|
||||||
|
const instructions = [];
|
||||||
|
const signers = [];
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
if (!fairLaunchObj.treasuryMint) {
|
||||||
|
amountNumber = Math.ceil(amountNumber * LAMPORTS_PER_SOL);
|
||||||
|
} else {
|
||||||
|
const transferAuthority = anchor.web3.Keypair.generate();
|
||||||
|
signers.push(transferAuthority);
|
||||||
|
|
||||||
|
instructions.push(
|
||||||
|
Token.createApproveInstruction(
|
||||||
|
TOKEN_PROGRAM_ID,
|
||||||
|
//@ts-ignore
|
||||||
|
fairLaunchObj.treasuryMint,
|
||||||
|
transferAuthority.publicKey,
|
||||||
|
walletKeyPair.publicKey,
|
||||||
|
[],
|
||||||
|
//@ts-ignore
|
||||||
|
amountNumber + fairLaunchObj.data.fees.toNumber(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
remainingAccounts.push({
|
||||||
|
//@ts-ignore
|
||||||
|
pubkey: fairLaunchObj.treasuryMint,
|
||||||
|
isWritable: true,
|
||||||
|
isSigner: false,
|
||||||
|
});
|
||||||
|
remainingAccounts.push({
|
||||||
|
pubkey: (
|
||||||
|
await getAtaForMint(
|
||||||
|
//@ts-ignore
|
||||||
|
fairLaunchObj.treasuryMint,
|
||||||
|
walletKeyPair.publicKey,
|
||||||
|
)
|
||||||
|
)[0],
|
||||||
|
isWritable: true,
|
||||||
|
isSigner: false,
|
||||||
|
});
|
||||||
|
remainingAccounts.push({
|
||||||
|
pubkey: transferAuthority.publicKey,
|
||||||
|
isWritable: false,
|
||||||
|
isSigner: true,
|
||||||
|
});
|
||||||
|
remainingAccounts.push({
|
||||||
|
pubkey: TOKEN_PROGRAM_ID,
|
||||||
|
isWritable: false,
|
||||||
|
isSigner: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await anchorProgram.rpc.adjustTicket(new anchor.BN(amountNumber), {
|
||||||
|
accounts: {
|
||||||
|
fairLaunchTicket,
|
||||||
|
fairLaunch,
|
||||||
|
fairLaunchLotteryBitmap,
|
||||||
|
//@ts-ignore
|
||||||
|
treasury: fairLaunchObj.treasury,
|
||||||
|
buyer: walletKeyPair.publicKey,
|
||||||
|
systemProgram: anchor.web3.SystemProgram.programId,
|
||||||
|
},
|
||||||
|
//__private: { logAccounts: true },
|
||||||
|
remainingAccounts,
|
||||||
|
signers,
|
||||||
|
instructions: instructions.length > 0 ? instructions : undefined,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`update fair launch ticket Done: ${fairLaunchTicket.toBase58()}.`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
program
|
program
|
||||||
.command('create_missing_sequences')
|
.command('create_missing_sequences')
|
||||||
.option(
|
.option(
|
||||||
|
@ -380,6 +492,22 @@ program
|
||||||
fairLaunch,
|
fairLaunch,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let treasuryAmount = 0;
|
||||||
|
// @ts-ignore
|
||||||
|
if (fairLaunchObj.treasuryMint) {
|
||||||
|
const token =
|
||||||
|
await anchorProgram.provider.connection.getTokenAccountBalance(
|
||||||
|
// @ts-ignore
|
||||||
|
fairLaunchObj.treasury,
|
||||||
|
);
|
||||||
|
treasuryAmount = token.value.uiAmount;
|
||||||
|
} else {
|
||||||
|
treasuryAmount = await anchorProgram.provider.connection.getBalance(
|
||||||
|
// @ts-ignore
|
||||||
|
fairLaunchObj.treasury,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
console.log('Token Mint', fairLaunchObj.tokenMint.toBase58());
|
console.log('Token Mint', fairLaunchObj.tokenMint.toBase58());
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
@ -395,28 +523,30 @@ program
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
console.log('Token Mint Bump', fairLaunchObj.tokenMintBump);
|
console.log('Token Mint Bump', fairLaunchObj.tokenMintBump);
|
||||||
console.log(
|
console.log(
|
||||||
'Price Range Start',
|
'Price Range Start ',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
fairLaunchObj.data.priceRangeStart.toNumber(),
|
fairLaunchObj.data.priceRangeStart.toNumber(),
|
||||||
);
|
);
|
||||||
console.log(
|
console.log(
|
||||||
'Price Range Start',
|
'Price Range End ',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
fairLaunchObj.data.priceRangeEnd.toNumber(),
|
fairLaunchObj.data.priceRangeEnd.toNumber(),
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'Tick Size ',
|
'Tick Size ',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
fairLaunchObj.data.tickSize.toNumber(),
|
fairLaunchObj.data.tickSize.toNumber(),
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'Fees ',
|
'Fees ',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
fairLaunchObj.data.fee.toNumber(),
|
fairLaunchObj.data.fee.toNumber(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
console.log('Current Treasury Holdings', treasuryAmount);
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
'Phase One Start',
|
'Phase One Start',
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
|
|
|
@ -128,6 +128,15 @@ export const getFairLaunchTicket = async (
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getFairLaunchLotteryBitmap = async (
|
||||||
|
tokenMint: anchor.web3.PublicKey,
|
||||||
|
): Promise<[anchor.web3.PublicKey, number]> => {
|
||||||
|
return await anchor.web3.PublicKey.findProgramAddress(
|
||||||
|
[Buffer.from('fair_launch'), tokenMint.toBuffer(), Buffer.from('lottery')],
|
||||||
|
FAIR_LAUNCH_PROGRAM_ID,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export const getFairLaunchTicketSeqLookup = async (
|
export const getFairLaunchTicketSeqLookup = async (
|
||||||
tokenMint: anchor.web3.PublicKey,
|
tokenMint: anchor.web3.PublicKey,
|
||||||
seq: anchor.BN,
|
seq: anchor.BN,
|
||||||
|
|
|
@ -448,12 +448,6 @@ pub mod fair_launch {
|
||||||
|
|
||||||
adjust_counts(fair_launch, amount, Some(fair_launch_ticket.amount))?;
|
adjust_counts(fair_launch, amount, Some(fair_launch_ticket.amount))?;
|
||||||
|
|
||||||
let signer_seeds = [
|
|
||||||
PREFIX.as_bytes(),
|
|
||||||
fair_launch.token_mint.as_ref(),
|
|
||||||
&[fair_launch.bump],
|
|
||||||
];
|
|
||||||
|
|
||||||
if let Some(treasury_mint) = fair_launch.treasury_mint {
|
if let Some(treasury_mint) = fair_launch.treasury_mint {
|
||||||
let treasury_mint_info = &ctx.remaining_accounts[0];
|
let treasury_mint_info = &ctx.remaining_accounts[0];
|
||||||
let _treasury_mint: spl_token::state::Mint = assert_initialized(&treasury_mint_info)?;
|
let _treasury_mint: spl_token::state::Mint = assert_initialized(&treasury_mint_info)?;
|
||||||
|
@ -495,6 +489,12 @@ pub mod fair_launch {
|
||||||
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let signer_seeds = [
|
||||||
|
PREFIX.as_bytes(),
|
||||||
|
fair_launch.token_mint.as_ref(),
|
||||||
|
&[fair_launch.bump],
|
||||||
|
];
|
||||||
|
|
||||||
if amount > fair_launch_ticket.amount {
|
if amount > fair_launch_ticket.amount {
|
||||||
let difference = amount
|
let difference = amount
|
||||||
.checked_sub(fair_launch_ticket.amount)
|
.checked_sub(fair_launch_ticket.amount)
|
||||||
|
@ -551,6 +551,13 @@ pub mod fair_launch {
|
||||||
.checked_sub(amount)
|
.checked_sub(amount)
|
||||||
.ok_or(ErrorCode::NumericalOverflowError)?;
|
.ok_or(ErrorCode::NumericalOverflowError)?;
|
||||||
|
|
||||||
|
let treasury_signer_seeds = [
|
||||||
|
PREFIX.as_bytes(),
|
||||||
|
fair_launch.token_mint.as_ref(),
|
||||||
|
TREASURY.as_bytes(),
|
||||||
|
&[fair_launch.treasury_bump],
|
||||||
|
];
|
||||||
|
|
||||||
invoke_signed(
|
invoke_signed(
|
||||||
&system_instruction::transfer(ctx.accounts.treasury.key, buyer.key, difference),
|
&system_instruction::transfer(ctx.accounts.treasury.key, buyer.key, difference),
|
||||||
&[
|
&[
|
||||||
|
@ -558,7 +565,7 @@ pub mod fair_launch {
|
||||||
ctx.accounts.treasury.clone(),
|
ctx.accounts.treasury.clone(),
|
||||||
ctx.accounts.system_program.clone(),
|
ctx.accounts.system_program.clone(),
|
||||||
],
|
],
|
||||||
&[&signer_seeds],
|
&[&treasury_signer_seeds],
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue