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

fix: dropped jupiter sol swap transactions #562

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 11 additions & 4 deletions packages/swap/src/providers/jupiter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ async function getJupiterTokens(abortable?: {
const url = JUPITER_TOKENS_URL;
let failed = false;
let tokens: JupiterTokenInfo[];
const backoff = [0, 100, 500, 1000, 2_500, 5_000];
const backoff = [0, 100, 500, 1000, 2_000, 4_000];
let backoffi = 0;
let errRef: undefined | { err: Error };

Expand Down Expand Up @@ -795,7 +795,7 @@ async function getJupiterQuote(

let failed = false;
let quote: JupiterQuoteResponse;
const backoff = [0, 100, 500, 1000, 2_500, 5_000];
const backoff = [0, 100, 500, 1000, 2_000, 4_000];
let backoffi = 0;
let errRef: undefined | { err: Error };

Expand Down Expand Up @@ -936,12 +936,19 @@ async function getJupiterSwap(
feeAccount: referrerATAPubkey?.toBase58(),
quoteResponse: quote,
destinationTokenAccount: dstATAPubkey?.toBase58(),
prioritizationFeeLamports: {
/**
* The automatic fee seems low and frequently causes transactions
* to be dropped when traffic is high
*/
autoMultiplier: 3,
},
};

const url = `${JUPITER_API_URL}swap`;
let failed = false;
let swap: JupiterSwapResponse;
const backoff = [0, 100, 500, 1000, 2_500, 5_000];
const backoff = [0, 100, 500, 1000, 2_000, 4_000];
let backoffi = 0;
let errRef: undefined | { err: Error };

Expand Down Expand Up @@ -1197,6 +1204,6 @@ function sleep(
clearTimeout(timeout);
}
abortable?.signal?.addEventListener("abort", onAbortDuringSleep);
const timeout = setTimeout(onTimeout);
const timeout = setTimeout(onTimeout, duration);
});
}
9 changes: 8 additions & 1 deletion packages/swap/src/providers/jupiter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export type JupiterSwapParams = {
trackingAccount?: string;
/** Integer */
computeUnitPriceMicroLamports?: number;
prioritizationFeeLamports?: number;
/** Integer */
prioritizationFeeLamports?:
| number
| "auto"
| {
/** Integer */
autoMultiplier: number;
};
/** Default: false */
asLegacyTransaction?: boolean;
/** Default: false */
Expand Down
52 changes: 52 additions & 0 deletions packages/swap/src/utils/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,58 @@ export function extractComputeBudget(
);
}

/**
* @see https://solana.com/docs/core/fees#prioritization-fees
*/
export function extractComputeUnitPriceMicroLamports(
tx: VersionedTransaction,
): undefined | number | bigint {
/** Compute unit price */
let computeUnitPriceMicroLamports: undefined | number | bigint;

// eslint-disable-next-line no-restricted-syntax, no-labels
instructionLoop: for (
let i = 0, len = tx.message.compiledInstructions.length;
i < len;
i++
) {
const instr = tx.message.compiledInstructions[i];
const program = tx.message.staticAccountKeys[instr.programIdIndex];
if (!ComputeBudgetProgram.programId.equals(program)) continue;

const keys = instr.accountKeyIndexes.map(
(accountKeyIndex): AccountMeta => ({
pubkey: tx.message.staticAccountKeys[accountKeyIndex],
isSigner: tx.message.isAccountSigner(accountKeyIndex),
isWritable: tx.message.isAccountWritable(accountKeyIndex),
}),
);

// Decompile the instruction
const instruction = new TransactionInstruction({
keys,
programId: program,
data: Buffer.from(instr.data),
});

const type = ComputeBudgetInstruction.decodeInstructionType(instruction);
switch (type) {
case "SetComputeUnitPrice": {
// Compute limit
const command =
ComputeBudgetInstruction.decodeSetComputeUnitPrice(instruction);
computeUnitPriceMicroLamports = command.microLamports;
kvhnuke marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line no-labels
break instructionLoop;
}
default: /** noop */
break;
}
}

return computeUnitPriceMicroLamports;
}

/**
* Insert new instructions at the start of a transaction, after compute budget and compute limit instructions
*/
Expand Down
Loading