Skip to content

Commit

Permalink
propagate exception
Browse files Browse the repository at this point in the history
  • Loading branch information
kev1n-peters committed Jan 20, 2025
1 parent 395d17d commit 5b646e0
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions platforms/solana/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,12 @@ export async function getWritableAccounts(
return msg.compiledInstructions
.flatMap((ix) => ix.accountKeyIndexes)
.map((k) => (msg.isAccountWritable(k) ? keys.get(k) : null))
.filter((k) => !!k) as PublicKey[];
.filter(Boolean) as PublicKey[];
} else {
return transaction.instructions
.flatMap((ix) => ix.keys)
.map((k) => (k.isWritable ? k.pubkey : null))
.filter((k) => !!k) as PublicKey[];
.filter(Boolean) as PublicKey[];
}
}

Expand Down Expand Up @@ -481,6 +481,7 @@ interface RpcResponse {

// Helper function to calculate the priority fee using the Triton One API
// See https://docs.triton.one/chains/solana/improved-priority-fees-api
// NOTE: this is currently an experimental feature
export async function determinePriorityFeeTritonOne(
connection: Connection,
transaction: Transaction | VersionedTransaction,
Expand All @@ -504,42 +505,39 @@ export async function determinePriorityFeeTritonOne(
},
];

try {
const response = (await rpcRequest(
'getRecentPrioritizationFees',
args,
)) as RpcResponse;
const response = (await rpcRequest(
'getRecentPrioritizationFees',
args,
)) as RpcResponse;

if (response.error) {
throw new Error(response.error);
}
if (response.error) {
// Allow the error to propagate so the caller can handle it and fall-back if needed
throw new Error(response.error);
}

const recentPrioritizationFees =
response.result as RecentPrioritizationFees[];
const recentPrioritizationFees =
response.result as RecentPrioritizationFees[];

if (recentPrioritizationFees.length > 0) {
const sortedFees = recentPrioritizationFees.sort(
(a, b) => a.prioritizationFee - b.prioritizationFee,
);
if (recentPrioritizationFees.length > 0) {
const sortedFees = recentPrioritizationFees.sort(
(a, b) => a.prioritizationFee - b.prioritizationFee,
);

// Calculate the median
const half = Math.floor(sortedFees.length / 2);
if (sortedFees.length % 2 === 0) {
fee = Math.floor(
(sortedFees[half - 1]!.prioritizationFee +
sortedFees[half]!.prioritizationFee) /
2,
);
} else {
fee = sortedFees[half]!.prioritizationFee;
}
// Calculate the median
const half = Math.floor(sortedFees.length / 2);
if (sortedFees.length % 2 === 0) {
fee = Math.floor(
(sortedFees[half - 1]!.prioritizationFee +
sortedFees[half]!.prioritizationFee) /
2,
);
} else {
fee = sortedFees[half]!.prioritizationFee;
}

if (multiple > 0) {
fee *= multiple;
}
if (multiple > 0) {
fee *= multiple;
}
} catch (e) {
console.error('Error fetching Triton One Solana recent fees', e);
}

// Bound the return value by the parameters passed
Expand Down

0 comments on commit 5b646e0

Please sign in to comment.