diff --git a/.changeset/dull-seahorses-kick.md b/.changeset/dull-seahorses-kick.md new file mode 100644 index 00000000000..a6d9cde97d6 --- /dev/null +++ b/.changeset/dull-seahorses-kick.md @@ -0,0 +1,5 @@ +--- +'@audius/sdk': patch +--- + +Add ComputeBudget unit price instructions (priority fees) to Solana transactions diff --git a/packages/libs/src/sdk/api/albums/AlbumsApi.ts b/packages/libs/src/sdk/api/albums/AlbumsApi.ts index 853c4acf065..880e6121366 100644 --- a/packages/libs/src/sdk/api/albums/AlbumsApi.ts +++ b/packages/libs/src/sdk/api/albums/AlbumsApi.ts @@ -356,10 +356,7 @@ export class AlbumsApi { routeInstruction, memoInstruction, locationMemoInstruction - ], - priorityFee: { - microLamports: 100000 - } + ] }) return transaction } else { @@ -397,10 +394,7 @@ export class AlbumsApi { routeInstruction, memoInstruction, locationMemoInstruction - ], - priorityFee: { - microLamports: 100000 - } + ] }) return transaction } diff --git a/packages/libs/src/sdk/api/tracks/TracksApi.ts b/packages/libs/src/sdk/api/tracks/TracksApi.ts index af1e78bde28..930c6e8e4c8 100644 --- a/packages/libs/src/sdk/api/tracks/TracksApi.ts +++ b/packages/libs/src/sdk/api/tracks/TracksApi.ts @@ -512,10 +512,7 @@ export class TracksApi extends GeneratedTracksApi { routeInstruction, memoInstruction, locationMemoInstruction - ], - priorityFee: { - microLamports: 100000 - } + ] }) return transaction } else { @@ -553,10 +550,7 @@ export class TracksApi extends GeneratedTracksApi { routeInstruction, memoInstruction, locationMemoInstruction - ], - priorityFee: { - microLamports: 100000 - } + ] }) return transaction } diff --git a/packages/libs/src/sdk/services/Solana/programs/BaseSolanaProgramClient.ts b/packages/libs/src/sdk/services/Solana/programs/BaseSolanaProgramClient.ts index c41ebb1e463..d59baecf8c6 100644 --- a/packages/libs/src/sdk/services/Solana/programs/BaseSolanaProgramClient.ts +++ b/packages/libs/src/sdk/services/Solana/programs/BaseSolanaProgramClient.ts @@ -106,7 +106,7 @@ export class BaseSolanaProgramClient { feePayer, recentBlockhash, addressLookupTables = [], - priorityFee + priorityFee = { priority: 'VERY_HIGH', minimumMicroLamports: 150_000 } } = await parseParams('buildTransaction', BuildTransactionSchema)(params) if (!recentBlockhash) { @@ -123,18 +123,21 @@ export class BaseSolanaProgramClient { ) } else { const res = await this.connection.getRecentPrioritizationFees() - const orderedFees = res.map((r) => r.prioritizationFee).sort() + const orderedFees = res + .map((r) => r.prioritizationFee) + .sort((a, b) => a - b) const percentile = 'percentile' in priorityFee ? priorityFee.percentile : priorityToPercentileMap[priorityFee.priority] - const microLamports = - orderedFees[ - Math.max( - Math.round((percentile / 100.0) * orderedFees.length - 1), - 0 - ) - ] + const percentileIndex = Math.max( + Math.round((percentile / 100.0) * orderedFees.length - 1), + 0 + ) + const microLamports = Math.max( + orderedFees[percentileIndex] ?? 0, + priorityFee.minimumMicroLamports ?? 0 + ) if (microLamports !== undefined) { instructions.push( ComputeBudgetProgram.setComputeUnitPrice({ diff --git a/packages/libs/src/sdk/services/Solana/programs/types.ts b/packages/libs/src/sdk/services/Solana/programs/types.ts index 178a5a51b89..6887251c286 100644 --- a/packages/libs/src/sdk/services/Solana/programs/types.ts +++ b/packages/libs/src/sdk/services/Solana/programs/types.ts @@ -49,16 +49,42 @@ export const BuildTransactionSchema = z .default([]) ]) .optional(), + /** + * Adds a ComputeBudget instruction to set the compute unit price for the + * transaction. Can specify a percentile or percentile enum to use recent + * prioritization fees to programatically set the price. + */ priorityFee: z .union([ z.object({ - microLamports: z.number() + /** + * The exact amount of microLamports to add per compute unit. + */ + microLamports: z.number().min(0) }), z.object({ - percentile: z.number().min(0).max(100) + /** + * Specify the precise percentile (0-100) of recent priority fees + * to use as this transactions priority fee per compute unit. + */ + percentile: z.number().min(0).max(100), + /** + * The minimum microLamports to use as the priority fee per compute + * unit, regardless of the percentiles. + */ + minimumMicroLamports: z.number().min(0).optional() }), z.object({ - priority: PrioritySchema + /** + * Specify an enum-based percentile of recent priority fees to use as + * this transactions priority fee per compute unit. + */ + priority: PrioritySchema, + /** + * The minimum microLamports to use as the priority fee per compute + * unit, regardless of the percentiles. + */ + minimumMicroLamports: z.number().min(0).optional() }) ]) .optional() diff --git a/packages/web/src/components/payout-wallet-modal/PayoutWalletModal.tsx b/packages/web/src/components/payout-wallet-modal/PayoutWalletModal.tsx index 06742605e44..152a0e7a3b5 100644 --- a/packages/web/src/components/payout-wallet-modal/PayoutWalletModal.tsx +++ b/packages/web/src/components/payout-wallet-modal/PayoutWalletModal.tsx @@ -244,10 +244,7 @@ export const PayoutWalletModal = () => { ataPubkey, addressPubkey, usdcMint - ), - ComputeBudgetProgram.setComputeUnitPrice({ - microLamports: 100000 - }) + ) ] })