Skip to content

Commit e60355b

Browse files
authored
Bump deps and improve getRecentPriorityFee for Orca (#68)
* Add Jito tip support and priority fee tweaks Introduce Jito tipping utilities and wire them into Solana swap flow, plus improve priority-fee retrieval. - Add packages/swapper/src/chain/solana/jito.ts: new JITO_TIP_ACCOUNTS, fetchTipFloorLamports(), getJitoBudget(), and createJitoTipInstruction() to compute/construct Jito tips (with a minimum tip fallback and recommended split logic). - Add tests packages/swapper/src/mayan/solana.test.ts covering getJitoBudget() behavior and createJitoTipInstruction() correctness. - Update tx_builder.ts: let getRecentPriorityFee accept lockedWritableAccounts when calling connection.getRecentPrioritizationFees(), and use the desired percentile index (with bounds) when computing a recommended fee. - Wire Jito into swap construction (mayan/solana.ts): fetch tip floor earlier, append a Jito tip transfer when applicable, then fetch recent blockhash and build the MessageV0 with the swapper as fee payer. Adjust imports accordingly. - Update orca/provider.ts to pass the Whirlpool program address as a locked writable account when querying recent priority fees. These changes enable optional on-chain tipping to Jito, make priority-fee estimation respect locked accounts and percentile selection, and include unit tests for the new Jito helpers. * bump packages * Cache Jito tip PublicKeys and use randomInt Cache JITO tip account PublicKey instances and use node:crypto.randomInt for selection instead of recreating PublicKey objects on each call. Add a JitoTipFloorEntry interface and cast the fetched JSON to improve typing for fetchTipFloorLamports. Also add the required randomInt import. These changes reduce allocations and improve type safety when creating Jito tip transfer instructions. * Update AGENTS.md * remove jito support
1 parent 66194f1 commit e60355b

File tree

7 files changed

+134
-132
lines changed

7 files changed

+134
-132
lines changed

AGENTS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
- TypeScript strict mode; ES2020+/ESNext modules.
2020
- 2‑space indent, double quotes, named exports when practical.
2121
- Files: kebab‑case; tests end with `.test.ts`; entry files `index.ts`.
22-
- Follow .windsurf style guide (imports grouped, explicit types for public APIs).
22+
- Group imports; use explicit types for public APIs.
23+
- Use `node:crypto` (`randomInt`) instead of `Math.random()` when selecting from security‑relevant sets (e.g. tip accounts, signers).
24+
- Type all external API responses with explicit interfaces; never leave `fetch` JSON as `any`.
25+
- Pre‑compute expensive objects (e.g. `PublicKey`) at module level when the inputs are static constants.
2326

2427
## Testing Guidelines
2528
- Jest + `ts-jest` (Node env, ESM enabled).

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"overrides": {
3030
"@types/jest": "30.0.0",
3131
"jest": "30.2.0",
32-
"ts-jest": "29.4.5",
32+
"ts-jest": "29.4.6",
3333
"typescript": "^5.8.2"
3434
}
3535
}
36-
}
36+
}

packages/swapper/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@
1818
"@mayanfinance/swap-sdk": "12.2.5",
1919
"@mysten/sui": "1.35.0",
2020
"@orca-so/whirlpools": "6.0.0",
21-
"@orca-so/whirlpools-client": "6.0.0",
21+
"@orca-so/whirlpools-client": "6.2.0",
2222
"@orca-so/whirlpools-core": "3.0.0",
2323
"@panoraexchange/swap-sdk": "^1.3.1",
2424
"@solana-program/token-2022": "0.6.1",
2525
"@solana/instructions": "5.0.0",
2626
"@solana/kit": "5.0.0",
27-
"@solana/spl-token": "0.4.13",
28-
"@solana/web3.js": "1.98.0",
27+
"@solana/spl-token": "0.4.14",
28+
"@solana/web3.js": "1.98.4",
2929
"@ston-fi/api": "0.30.0",
3030
"@ston-fi/sdk": "2.7.0",
3131
"@ton/ton": "16.1.0",
32-
"@types/bn.js": "5.1.6",
33-
"bn.js": "5.2.1",
32+
"@types/bn.js": "5.2.0",
33+
"bn.js": "5.2.2",
3434
"js-sha3": "0.9.3"
3535
},
3636
"files": [

packages/swapper/src/chain/solana/tx_builder.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Connection,
33
ComputeBudgetProgram,
4+
PublicKey,
45
TransactionInstruction,
56
VersionedTransaction,
67
Transaction,
@@ -14,9 +15,10 @@ export async function getRecentBlockhash(connection: Connection, commitment?: "c
1415
return await connection.getLatestBlockhash(commitment || "confirmed");
1516
}
1617

17-
export async function getRecentPriorityFee(connection: Connection): Promise<number> {
18+
export async function getRecentPriorityFee(connection: Connection, lockedWritableAccounts?: PublicKey[]): Promise<number> {
1819
try {
19-
const recentFees = await connection.getRecentPrioritizationFees();
20+
const config = lockedWritableAccounts ? { lockedWritableAccounts } : undefined;
21+
const recentFees = await connection.getRecentPrioritizationFees(config);
2022

2123
if (!recentFees || recentFees.length === 0) {
2224
return DEFAULT_COMPUTE_UNIT_PRICE_MICRO_LAMPORTS;
@@ -31,11 +33,11 @@ export async function getRecentPriorityFee(connection: Connection): Promise<numb
3133
return DEFAULT_COMPUTE_UNIT_PRICE_MICRO_LAMPORTS;
3234
}
3335

34-
const medianIndex = Math.floor(fees.length * (PRIORITY_FEE_PERCENTILE / 100));
35-
const medianFee = fees[medianIndex];
36+
const percentileIndex = Math.floor(fees.length * (PRIORITY_FEE_PERCENTILE / 100));
37+
const percentileFee = fees[Math.min(percentileIndex, fees.length - 1)];
3638

3739
const recommendedFee = Math.max(
38-
Math.ceil(medianFee * 1.2),
40+
Math.ceil(percentileFee * 1.2),
3941
1000
4042
);
4143

packages/swapper/src/mayan/solana.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ async function prepareSolanaSwapTransaction(
4242
feePayer: string,
4343
}
4444
}> {
45-
// Fetch instructions and blockhash in parallel
4645
const [swapData, { blockhash, lastValidBlockHeight }] = await Promise.all([
4746
createSwapFromSolanaInstructions(
4847
quote, swapperWalletAddress, destinationAddress,
@@ -52,19 +51,17 @@ async function prepareSolanaSwapTransaction(
5251
getRecentBlockhash(connection, DEFAULT_COMMITMENT),
5352
]);
5453

55-
let { instructions, signers, lookupTables } = swapData;
56-
5754
if (quote.gasless) {
5855
throw new Error("Gasless swaps are not currently supported");
5956
}
6057

58+
const { instructions, signers, lookupTables } = swapData;
59+
6160
const swapper = new PublicKey(swapperWalletAddress);
62-
const feePayer = swapper;
6361

64-
// Use MessageV0.compile as per the latest SDK pattern
6562
const message = MessageV0.compile({
6663
instructions,
67-
payerKey: feePayer,
64+
payerKey: swapper,
6865
recentBlockhash: blockhash,
6966
addressLookupTableAccounts: lookupTables,
7067
});
@@ -79,7 +76,7 @@ async function prepareSolanaSwapTransaction(
7976
blockhash,
8077
lastValidBlockHeight,
8178
isVersionedTransaction: true,
82-
feePayer: feePayer.toBase58(),
79+
feePayer: swapper.toBase58(),
8380
}
8481
};
8582
}

packages/swapper/src/orca/provider.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
getOracleAddress,
4646
getTickArrayAddress,
4747
getWhirlpoolAddress,
48+
WHIRLPOOL_PROGRAM_ADDRESS,
4849
type Whirlpool,
4950
} from "@orca-so/whirlpools-client";
5051
import {
@@ -236,7 +237,9 @@ export class OrcaWhirlpoolProvider implements Protocol {
236237
return this.priorityFeeCache.value;
237238
}
238239

239-
const value = await getRecentPriorityFee(this.connection);
240+
const value = await getRecentPriorityFee(this.connection, [
241+
new PublicKey(WHIRLPOOL_PROGRAM_ADDRESS),
242+
]);
240243
this.priorityFeeCache = {
241244
value,
242245
expiresAt: now + 3_000,

0 commit comments

Comments
 (0)