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',
|
'--keypair not provided',
|
||||||
)
|
)
|
||||||
.option('-f, --fair-launch <string>', 'fair launch id')
|
.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) => {
|
.action(async (_, cmd) => {
|
||||||
const { env, keypair, fairLaunch } = cmd.opts();
|
const { env, keypair, fairLaunch, rpcUrl } = cmd.opts();
|
||||||
const walletKeyPair = loadWalletKey(keypair);
|
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 fairLaunchKey = new anchor.web3.PublicKey(fairLaunch);
|
||||||
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
||||||
|
@ -1379,17 +1387,36 @@ program
|
||||||
allIndexesInSlice[i],
|
allIndexesInSlice[i],
|
||||||
ticket.model.buyer.toBase58(),
|
ticket.model.buyer.toBase58(),
|
||||||
);
|
);
|
||||||
await adjustTicket({
|
let tries = 0;
|
||||||
amountNumber: 0,
|
let done = false;
|
||||||
fairLaunchObj,
|
while (tries < 3 && !done) {
|
||||||
adjuster: ticket.model.buyer,
|
try {
|
||||||
fairLaunch,
|
await adjustTicket({
|
||||||
fairLaunchTicket: ticket.key,
|
amountNumber: 0,
|
||||||
fairLaunchLotteryBitmap,
|
fairLaunchObj,
|
||||||
anchorProgram,
|
adjuster: ticket.model.buyer,
|
||||||
payer: walletKeyPair,
|
fairLaunch,
|
||||||
adjustMantissa: true,
|
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 {
|
} else {
|
||||||
const myByte =
|
const myByte =
|
||||||
fairLaunchLotteryBitmapObj.data[
|
fairLaunchLotteryBitmapObj.data[
|
||||||
|
@ -1418,24 +1445,40 @@ program
|
||||||
allIndexesInSlice[i],
|
allIndexesInSlice[i],
|
||||||
'before punching',
|
'before punching',
|
||||||
);
|
);
|
||||||
try {
|
let tries = 0;
|
||||||
await adjustTicket({
|
let done = false;
|
||||||
//@ts-ignore
|
while (tries < 3 && !done) {
|
||||||
amountNumber: fairLaunchObj.currentMedian.toNumber(),
|
try {
|
||||||
fairLaunchObj,
|
await adjustTicket({
|
||||||
adjuster: ticket.model.buyer,
|
//@ts-ignore
|
||||||
fairLaunch,
|
amountNumber: fairLaunchObj.currentMedian.toNumber(),
|
||||||
fairLaunchTicket: ticket.key,
|
fairLaunchObj,
|
||||||
fairLaunchLotteryBitmap,
|
adjuster: ticket.model.buyer,
|
||||||
anchorProgram,
|
fairLaunch,
|
||||||
payer: walletKeyPair,
|
fairLaunchTicket: ticket.key,
|
||||||
adjustMantissa: false,
|
fairLaunchLotteryBitmap,
|
||||||
});
|
anchorProgram,
|
||||||
} catch (e) {
|
payer: walletKeyPair,
|
||||||
console.log(
|
adjustMantissa: false,
|
||||||
'Adjusting ticket failed',
|
});
|
||||||
ticket.key.toBase58(),
|
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;
|
let tries = 0;
|
||||||
|
@ -1476,18 +1519,41 @@ program
|
||||||
ticket.model.buyer.toBase58(),
|
ticket.model.buyer.toBase58(),
|
||||||
'was eligible but lost lottery, refunding',
|
'was eligible but lost lottery, refunding',
|
||||||
);
|
);
|
||||||
await adjustTicket({
|
let tries = 0;
|
||||||
//@ts-ignore
|
let done = false;
|
||||||
amountNumber: 0,
|
while (tries < 3 && !done) {
|
||||||
fairLaunchObj,
|
try {
|
||||||
adjuster: ticket.model.buyer,
|
await adjustTicket({
|
||||||
fairLaunch,
|
//@ts-ignore
|
||||||
fairLaunchTicket: ticket.key,
|
amountNumber: 0,
|
||||||
fairLaunchLotteryBitmap,
|
fairLaunchObj,
|
||||||
anchorProgram,
|
adjuster: ticket.model.buyer,
|
||||||
payer: walletKeyPair,
|
fairLaunch,
|
||||||
adjustMantissa: true,
|
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.');
|
console.log('Refunded.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2153,10 +2219,18 @@ program
|
||||||
'--keypair not provided',
|
'--keypair not provided',
|
||||||
)
|
)
|
||||||
.option('-f, --fair-launch <string>', 'fair launch id')
|
.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) => {
|
.action(async (_, cmd) => {
|
||||||
const { env, keypair, fairLaunch } = cmd.opts();
|
const { env, keypair, fairLaunch, rpcUrl } = cmd.opts();
|
||||||
const walletKeyPair = loadWalletKey(keypair);
|
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 fairLaunchKey = new anchor.web3.PublicKey(fairLaunch);
|
||||||
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
const fairLaunchObj = await anchorProgram.account.fairLaunch.fetch(
|
||||||
|
|
|
@ -283,9 +283,15 @@ export async function loadCandyProgram(walletKeyPair: Keypair, env: string) {
|
||||||
export async function loadFairLaunchProgram(
|
export async function loadFairLaunchProgram(
|
||||||
walletKeyPair: Keypair,
|
walletKeyPair: Keypair,
|
||||||
env: string,
|
env: string,
|
||||||
|
customRpcUrl?: string,
|
||||||
) {
|
) {
|
||||||
|
if (customRpcUrl) console.log('USING CUSTOM URL', customRpcUrl);
|
||||||
|
|
||||||
// @ts-ignore
|
// @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 walletWrapper = new anchor.Wallet(walletKeyPair);
|
||||||
const provider = new anchor.Provider(solConnection, walletWrapper, {
|
const provider = new anchor.Provider(solConnection, walletWrapper, {
|
||||||
preflightCommitment: 'recent',
|
preflightCommitment: 'recent',
|
||||||
|
|
Loading…
Reference in New Issue