Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/dull-seahorses-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@audius/sdk': patch
---

Add ComputeBudget unit price instructions (priority fees) to Solana transactions
10 changes: 2 additions & 8 deletions packages/libs/src/sdk/api/albums/AlbumsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,7 @@ export class AlbumsApi {
routeInstruction,
memoInstruction,
locationMemoInstruction
],
priorityFee: {
microLamports: 100000
}
]
})
return transaction
} else {
Expand Down Expand Up @@ -397,10 +394,7 @@ export class AlbumsApi {
routeInstruction,
memoInstruction,
locationMemoInstruction
],
priorityFee: {
microLamports: 100000
}
]
})
return transaction
}
Expand Down
10 changes: 2 additions & 8 deletions packages/libs/src/sdk/api/tracks/TracksApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,7 @@ export class TracksApi extends GeneratedTracksApi {
routeInstruction,
memoInstruction,
locationMemoInstruction
],
priorityFee: {
microLamports: 100000
}
]
})
return transaction
} else {
Expand Down Expand Up @@ -553,10 +550,7 @@ export class TracksApi extends GeneratedTracksApi {
routeInstruction,
memoInstruction,
locationMemoInstruction
],
priorityFee: {
microLamports: 100000
}
]
})
return transaction
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Comment thread
rickyrombo marked this conversation as resolved.
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({
Expand Down
32 changes: 29 additions & 3 deletions packages/libs/src/sdk/services/Solana/programs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,7 @@ export const PayoutWalletModal = () => {
ataPubkey,
addressPubkey,
usdcMint
),
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: 100000
})
)
]
})

Expand Down