diff --git a/js/packages/cli/src/fair-launch-cli.ts b/js/packages/cli/src/fair-launch-cli.ts index 8a24b50..881b6fe 100755 --- a/js/packages/cli/src/fair-launch-cli.ts +++ b/js/packages/cli/src/fair-launch-cli.ts @@ -1190,10 +1190,18 @@ program '--keypair not provided', ) .option('-f, --fair-launch ', 'fair launch id') + .option( + '-r, --rpc-url ', + '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 ', 'fair launch id') + .option( + '-r, --rpc-url ', + '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( diff --git a/js/packages/cli/src/helpers/accounts.ts b/js/packages/cli/src/helpers/accounts.ts index 2f50e79..ced74ce 100644 --- a/js/packages/cli/src/helpers/accounts.ts +++ b/js/packages/cli/src/helpers/accounts.ts @@ -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',