Working on recoding so that we can use spl tokens
This commit is contained in:
parent
1c6c46400e
commit
970ea6806f
|
@ -418,6 +418,16 @@ program
|
||||||
const remainingAccounts = [];
|
const remainingAccounts = [];
|
||||||
const instructions = [];
|
const instructions = [];
|
||||||
const signers = [];
|
const signers = [];
|
||||||
|
//@ts-ignore
|
||||||
|
const tokenAta = fairLaunchObj.treasuryMint
|
||||||
|
? (
|
||||||
|
await getAtaForMint(
|
||||||
|
//@ts-ignore
|
||||||
|
fairLaunchObj.treasuryMint,
|
||||||
|
walletKeyPair.publicKey,
|
||||||
|
)
|
||||||
|
)[0]
|
||||||
|
: undefined;
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (!fairLaunchObj.treasuryMint) {
|
if (!fairLaunchObj.treasuryMint) {
|
||||||
|
@ -434,13 +444,6 @@ program
|
||||||
);
|
);
|
||||||
const mintInfo = await token.getMintInfo();
|
const mintInfo = await token.getMintInfo();
|
||||||
amountNumber = Math.ceil(amountNumber * 10 ** mintInfo.decimals);
|
amountNumber = Math.ceil(amountNumber * 10 ** mintInfo.decimals);
|
||||||
const tokenAta = (
|
|
||||||
await getAtaForMint(
|
|
||||||
//@ts-ignore
|
|
||||||
fairLaunchObj.treasuryMint,
|
|
||||||
walletKeyPair.publicKey,
|
|
||||||
)
|
|
||||||
)[0];
|
|
||||||
|
|
||||||
instructions.push(
|
instructions.push(
|
||||||
Token.createApproveInstruction(
|
Token.createApproveInstruction(
|
||||||
|
@ -479,7 +482,11 @@ program
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await anchorProgram.rpc.purchaseTicket(bump, new anchor.BN(amountNumber), {
|
instructions.push(
|
||||||
|
await anchorProgram.instruction.purchaseTicket(
|
||||||
|
bump,
|
||||||
|
new anchor.BN(amountNumber),
|
||||||
|
{
|
||||||
accounts: {
|
accounts: {
|
||||||
fairLaunchTicket,
|
fairLaunchTicket,
|
||||||
fairLaunch,
|
fairLaunch,
|
||||||
|
@ -492,17 +499,43 @@ program
|
||||||
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
clock: anchor.web3.SYSVAR_CLOCK_PUBKEY,
|
||||||
},
|
},
|
||||||
remainingAccounts,
|
remainingAccounts,
|
||||||
signers,
|
},
|
||||||
instructions: instructions.length > 0 ? instructions : undefined,
|
),
|
||||||
});
|
);
|
||||||
|
|
||||||
|
if (tokenAta) {
|
||||||
|
instructions.push(
|
||||||
|
Token.createRevokeInstruction(
|
||||||
|
TOKEN_PROGRAM_ID,
|
||||||
|
tokenAta,
|
||||||
|
walletKeyPair.publicKey,
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendTransactionWithRetryWithKeypair(
|
||||||
|
anchorProgram.provider.connection,
|
||||||
|
walletKeyPair,
|
||||||
|
instructions,
|
||||||
|
signers,
|
||||||
|
'max',
|
||||||
|
);
|
||||||
console.log(
|
console.log(
|
||||||
`create fair launch ticket Done: ${fairLaunchTicket.toBase58()}. Trying to create seq now...we may or may not get a validator with data on chain. Either way, your ticket is secure.`,
|
`create fair launch ticket Done: ${fairLaunchTicket.toBase58()}. Trying to create seq now...we may or may not get a validator with data on chain. Either way, your ticket is secure.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let fairLaunchTicketObj;
|
||||||
|
for (let i = 0; i < 10; i++) {
|
||||||
await sleep(5000);
|
await sleep(5000);
|
||||||
const fairLaunchTicketObj =
|
try {
|
||||||
|
fairLaunchTicketObj =
|
||||||
await anchorProgram.account.fairLaunchTicket.fetch(fairLaunchTicket);
|
await anchorProgram.account.fairLaunchTicket.fetch(fairLaunchTicket);
|
||||||
|
break;
|
||||||
|
} catch (e) {
|
||||||
|
console.log('Not found. Trying again...');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const [fairLaunchTicketSeqLookup, seqBump] =
|
const [fairLaunchTicketSeqLookup, seqBump] =
|
||||||
await getFairLaunchTicketSeqLookup(
|
await getFairLaunchTicketSeqLookup(
|
||||||
|
@ -683,7 +716,16 @@ async function adjustTicket({
|
||||||
const remainingAccounts = [];
|
const remainingAccounts = [];
|
||||||
const instructions = [];
|
const instructions = [];
|
||||||
const signers = [];
|
const signers = [];
|
||||||
|
//@ts-ignore
|
||||||
|
const tokenAta = fairLaunchObj.treasuryMint
|
||||||
|
? (
|
||||||
|
await getAtaForMint(
|
||||||
|
//@ts-ignore
|
||||||
|
fairLaunchObj.treasuryMint,
|
||||||
|
adjuster,
|
||||||
|
)
|
||||||
|
)[0]
|
||||||
|
: undefined;
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (!fairLaunchObj.treasuryMint) {
|
if (!fairLaunchObj.treasuryMint) {
|
||||||
amountNumber = Math.ceil(amountNumber * LAMPORTS_PER_SOL);
|
amountNumber = Math.ceil(amountNumber * LAMPORTS_PER_SOL);
|
||||||
|
@ -698,18 +740,17 @@ async function adjustTicket({
|
||||||
);
|
);
|
||||||
|
|
||||||
const mintInfo = await token.getMintInfo();
|
const mintInfo = await token.getMintInfo();
|
||||||
|
amountNumber = Math.ceil(amountNumber * 10 ** mintInfo.decimals);
|
||||||
if (amountNumber > 0) {
|
if (amountNumber > 0) {
|
||||||
instructions.push(
|
instructions.push(
|
||||||
Token.createApproveInstruction(
|
Token.createApproveInstruction(
|
||||||
TOKEN_PROGRAM_ID,
|
TOKEN_PROGRAM_ID,
|
||||||
//@ts-ignore
|
tokenAta,
|
||||||
fairLaunchObj.treasuryMint,
|
|
||||||
transferAuthority.publicKey,
|
transferAuthority.publicKey,
|
||||||
adjuster,
|
adjuster,
|
||||||
[],
|
[],
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
amountNumber * 10 ** mintInfo.decimals +
|
amountNumber,
|
||||||
fairLaunchObj.data.fees.toNumber(),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -721,13 +762,7 @@ async function adjustTicket({
|
||||||
isSigner: false,
|
isSigner: false,
|
||||||
});
|
});
|
||||||
remainingAccounts.push({
|
remainingAccounts.push({
|
||||||
pubkey: (
|
pubkey: tokenAta,
|
||||||
await getAtaForMint(
|
|
||||||
//@ts-ignore
|
|
||||||
fairLaunchObj.treasuryMint,
|
|
||||||
adjuster,
|
|
||||||
)
|
|
||||||
)[0],
|
|
||||||
isWritable: true,
|
isWritable: true,
|
||||||
isSigner: false,
|
isSigner: false,
|
||||||
});
|
});
|
||||||
|
@ -743,7 +778,8 @@ async function adjustTicket({
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await anchorProgram.rpc.adjustTicket(new anchor.BN(amountNumber), {
|
instructions.push(
|
||||||
|
await anchorProgram.instruction.adjustTicket(new anchor.BN(amountNumber), {
|
||||||
accounts: {
|
accounts: {
|
||||||
fairLaunchTicket,
|
fairLaunchTicket,
|
||||||
fairLaunch,
|
fairLaunch,
|
||||||
|
@ -762,9 +798,27 @@ async function adjustTicket({
|
||||||
},
|
},
|
||||||
...remainingAccounts,
|
...remainingAccounts,
|
||||||
],
|
],
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
if (fairLaunchObj.treasuryMint && amountNumber > 0) {
|
||||||
|
instructions.push(
|
||||||
|
Token.createRevokeInstruction(
|
||||||
|
FAIR_LAUNCH_PROGRAM_ID,
|
||||||
|
tokenAta,
|
||||||
|
payer.publicKey,
|
||||||
|
[],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendTransactionWithRetryWithKeypair(
|
||||||
|
anchorProgram.provider.connection,
|
||||||
|
payer,
|
||||||
|
instructions,
|
||||||
signers,
|
signers,
|
||||||
instructions: instructions.length > 0 ? instructions : undefined,
|
);
|
||||||
});
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`update fair launch ticket Done: ${fairLaunchTicket.toBase58()}.`,
|
`update fair launch ticket Done: ${fairLaunchTicket.toBase58()}.`,
|
||||||
|
@ -1412,7 +1466,7 @@ program
|
||||||
Token.createApproveInstruction(
|
Token.createApproveInstruction(
|
||||||
TOKEN_PROGRAM_ID,
|
TOKEN_PROGRAM_ID,
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
fairLaunchObj.tokenMint,
|
buyerTokenAccount,
|
||||||
transferAuthority.publicKey,
|
transferAuthority.publicKey,
|
||||||
walletKeyPair.publicKey,
|
walletKeyPair.publicKey,
|
||||||
[],
|
[],
|
||||||
|
|
|
@ -11,6 +11,7 @@ use {
|
||||||
prelude::*,
|
prelude::*,
|
||||||
solana_program::{
|
solana_program::{
|
||||||
program::{invoke, invoke_signed},
|
program::{invoke, invoke_signed},
|
||||||
|
program_option::COption,
|
||||||
program_pack::Pack,
|
program_pack::Pack,
|
||||||
system_instruction, system_program,
|
system_instruction, system_program,
|
||||||
},
|
},
|
||||||
|
@ -317,10 +318,11 @@ pub mod fair_launch {
|
||||||
return Err(ErrorCode::TreasuryMintMismatch.into());
|
return Err(ErrorCode::TreasuryMintMismatch.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
if buyer_token_account.delegate.is_some() {
|
if let COption::Some(val) = buyer_token_account.delegate {
|
||||||
msg!("Delegate {}", buyer_token_account.delegate.unwrap());
|
if val != *transfer_authority_info.key {
|
||||||
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
assert_owned_by(treasury_mint_info, &token_program.key)?;
|
assert_owned_by(treasury_mint_info, &token_program.key)?;
|
||||||
assert_owned_by(buyer_token_account_info, &token_program.key)?;
|
assert_owned_by(buyer_token_account_info, &token_program.key)?;
|
||||||
|
@ -517,9 +519,11 @@ pub mod fair_launch {
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if buyer_token_account.delegate.is_some() {
|
if let COption::Some(val) = buyer_token_account.delegate {
|
||||||
|
if val != *transfer_authority_info.key {
|
||||||
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
return Err(ErrorCode::AccountShouldHaveNoDelegates.into());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let signer_seeds = [
|
let signer_seeds = [
|
||||||
PREFIX.as_bytes(),
|
PREFIX.as_bytes(),
|
||||||
|
|
Loading…
Reference in New Issue