Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make solana broadcasting script more resilient #401

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/with-solana/src/jupiterSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const createSwap = async () => {
console.log(`\nUsing existing Solana address from ENV: "${solAddress}"`);
}

// Swapping SOL to USDC with input 0.05 SOL and 1% slippage
// Swapping SOL to USDC with input 0.01 SOL and 1% slippage
// See example here: https://station.jup.ag/docs/apis/swap-api
const quoteResponse = await (
await fetch(
"https://quote-api.jup.ag/v6/quote?inputMint=So11111111111111111111111111111111111111112\
&outputMint=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v\
&amount=50000000\
&amount=10000000\
&slippageBps=100"
)
).json();
Expand All @@ -73,6 +73,9 @@ const createSwap = async () => {
wrapAndUnwrapSol: true,
// feeAccount is optional. Use if you want to charge a fee. feeBps must have been passed in /quote API.
// feeAccount: "fee_account_public_key"
dynamicComputeUnitLimit: true, // allow dynamic compute limit instead of max 1,400,000
// custom priority fee
prioritizationFeeLamports: "auto", // or custom lamports: 1000
}),
})
).json();
Expand Down
6 changes: 4 additions & 2 deletions examples/with-solana/src/utils/retrySender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type TransactionSenderAndConfirmationWaiterArgs = {

const SEND_OPTIONS = {
skipPreflight: true,
maxRetries: 3,
};

export async function transactionSenderAndConfirmationWaiter({
Expand All @@ -38,7 +39,7 @@ export async function transactionSenderAndConfirmationWaiter({

const abortableResender = async () => {
while (true) {
await wait(2_000);
await wait(1_000);
if (abortSignal.aborted) return;
try {
await connection.sendRawTransaction(
Expand Down Expand Up @@ -70,7 +71,7 @@ export async function transactionSenderAndConfirmationWaiter({
new Promise(async (resolve) => {
// in case ws socket died
while (!abortSignal.aborted) {
await wait(2_000);
await wait(1_000);
const tx = await connection.getSignatureStatus(txid, {
searchTransactionHistory: false,
});
Expand All @@ -83,6 +84,7 @@ export async function transactionSenderAndConfirmationWaiter({
} catch (e) {
if (e instanceof TransactionExpiredBlockheightExceededError) {
// we consume this error and getTransaction would return null
console.warn(`failed to confirm transaction: ${e}`);
return;
} else {
// invalid state from web3.js
Expand Down
Loading