Skip to content

Commit

Permalink
Merge pull-request #401
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewkmin committed Oct 18, 2024
2 parents e612e04 + 26ef413 commit e72e74b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
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

0 comments on commit e72e74b

Please sign in to comment.