Fix flp cli (#631)
* Wrapping adjusting * add rpc support for one command - wip * rpc support for other method
This commit is contained in:
parent
0f7e0fe80d
commit
a6c1c21615
|
@ -1190,10 +1190,18 @@ program
|
|||
'--keypair not provided',
|
||||
)
|
||||
.option('-f, --fair-launch <string>', 'fair launch id')
|
||||
.option(
|
||||
'-r, --rpc-url <string>',
|
||||
'custom rpc url since this is a heavy command',
|
||||
)
|
||||
.action(async (_, cmd) => {
|
||||
const { env, keypair, fairLaunch } = cmd.opts();
|
||||
const { env, keypair, fairLaunch, rpcUrl } = cmd.opts();
|
||||
const walletKeyPair = loadWalletKey(keypair);
|
||||
const anchorProgram = await loadFairLaunchProgram(walletKeyPair, env);
|
||||
const anchorProgram = await loadFairLaunchProgram(
|
||||
walletKeyPair,
|
||||
env,
|
||||
rpcUrl,
|
||||
);
|
||||
|
||||
const fairLaunchKey = new anchor.web3.PublicKey(fairLaunch);
|
||||
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
||||
|
@ -1379,17 +1387,36 @@ program
|
|||
allIndexesInSlice[i],
|
||||
ticket.model.buyer.toBase58(),
|
||||
);
|
||||
await adjustTicket({
|
||||
amountNumber: 0,
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: true,
|
||||
});
|
||||
let tries = 0;
|
||||
let done = false;
|
||||
while (tries < 3 && !done) {
|
||||
try {
|
||||
await adjustTicket({
|
||||
amountNumber: 0,
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: true,
|
||||
});
|
||||
done = true;
|
||||
} catch (e) {
|
||||
if (tries > 3) {
|
||||
throw e;
|
||||
} else {
|
||||
tries++;
|
||||
}
|
||||
console.log(e);
|
||||
console.log(
|
||||
'Adjusting ticket failed',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const myByte =
|
||||
fairLaunchLotteryBitmapObj.data[
|
||||
|
@ -1418,24 +1445,40 @@ program
|
|||
allIndexesInSlice[i],
|
||||
'before punching',
|
||||
);
|
||||
try {
|
||||
await adjustTicket({
|
||||
//@ts-ignore
|
||||
amountNumber: fairLaunchObj.currentMedian.toNumber(),
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: false,
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(
|
||||
'Adjusting ticket failed',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
let tries = 0;
|
||||
let done = false;
|
||||
while (tries < 3 && !done) {
|
||||
try {
|
||||
await adjustTicket({
|
||||
//@ts-ignore
|
||||
amountNumber: fairLaunchObj.currentMedian.toNumber(),
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: false,
|
||||
});
|
||||
done = true;
|
||||
console.log(
|
||||
'Adjusting ticket succeeded',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
} catch (e) {
|
||||
if (tries > 3) {
|
||||
throw e;
|
||||
} else {
|
||||
tries++;
|
||||
}
|
||||
console.log(e);
|
||||
console.log(
|
||||
'Adjusting ticket failed',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
let tries = 0;
|
||||
|
@ -1476,18 +1519,41 @@ program
|
|||
ticket.model.buyer.toBase58(),
|
||||
'was eligible but lost lottery, refunding',
|
||||
);
|
||||
await adjustTicket({
|
||||
//@ts-ignore
|
||||
amountNumber: 0,
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: true,
|
||||
});
|
||||
let tries = 0;
|
||||
let done = false;
|
||||
while (tries < 3 && !done) {
|
||||
try {
|
||||
await adjustTicket({
|
||||
//@ts-ignore
|
||||
amountNumber: 0,
|
||||
fairLaunchObj,
|
||||
adjuster: ticket.model.buyer,
|
||||
fairLaunch,
|
||||
fairLaunchTicket: ticket.key,
|
||||
fairLaunchLotteryBitmap,
|
||||
anchorProgram,
|
||||
payer: walletKeyPair,
|
||||
adjustMantissa: true,
|
||||
});
|
||||
done = true;
|
||||
console.log(
|
||||
'Refunding ticket succeeded',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
} catch (e) {
|
||||
if (tries > 3) {
|
||||
throw e;
|
||||
} else {
|
||||
tries++;
|
||||
}
|
||||
console.log(e);
|
||||
console.log(
|
||||
'Adjusting ticket failed',
|
||||
ticket.key.toBase58(),
|
||||
);
|
||||
await sleep(1000);
|
||||
}
|
||||
}
|
||||
console.log('Refunded.');
|
||||
}
|
||||
}
|
||||
|
@ -2153,10 +2219,18 @@ program
|
|||
'--keypair not provided',
|
||||
)
|
||||
.option('-f, --fair-launch <string>', 'fair launch id')
|
||||
.option(
|
||||
'-r, --rpc-url <string>',
|
||||
'custom rpc url since this is a heavy command',
|
||||
)
|
||||
.action(async (_, cmd) => {
|
||||
const { env, keypair, fairLaunch } = cmd.opts();
|
||||
const { env, keypair, fairLaunch, rpcUrl } = cmd.opts();
|
||||
const walletKeyPair = loadWalletKey(keypair);
|
||||
const anchorProgram = await loadFairLaunchProgram(walletKeyPair, env);
|
||||
const anchorProgram = await loadFairLaunchProgram(
|
||||
walletKeyPair,
|
||||
env,
|
||||
rpcUrl,
|
||||
);
|
||||
|
||||
const fairLaunchKey = new anchor.web3.PublicKey(fairLaunch);
|
||||
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
||||
|
|
|
@ -283,9 +283,15 @@ export async function loadCandyProgram(walletKeyPair: Keypair, env: string) {
|
|||
export async function loadFairLaunchProgram(
|
||||
walletKeyPair: Keypair,
|
||||
env: string,
|
||||
customRpcUrl?: string,
|
||||
) {
|
||||
if (customRpcUrl) console.log('USING CUSTOM URL', customRpcUrl);
|
||||
|
||||
// @ts-ignore
|
||||
const solConnection = new anchor.web3.Connection(web3.clusterApiUrl(env));
|
||||
const solConnection = new anchor.web3.Connection(
|
||||
//@ts-ignore
|
||||
customRpcUrl || web3.clusterApiUrl(env),
|
||||
);
|
||||
const walletWrapper = new anchor.Wallet(walletKeyPair);
|
||||
const provider = new anchor.Provider(solConnection, walletWrapper, {
|
||||
preflightCommitment: 'recent',
|
||||
|
|
Loading…
Reference in New Issue