@@ -23,7 +23,6 @@ import {
23
23
import {
24
24
clusterApiUrl ,
25
25
Commitment ,
26
- ComputeBudgetProgram ,
27
26
Connection ,
28
27
Keypair ,
29
28
PublicKey ,
@@ -66,6 +65,7 @@ import {
66
65
getClaim ,
67
66
getPostedMessage ,
68
67
} from './utils/wormhole' ;
68
+ import { addComputeBudget } from './utils/computeBudget' ;
69
69
import { ForeignAssetCache } from '../../utils' ;
70
70
import { RelayerAbstract } from '../abstracts/relayer' ;
71
71
import {
@@ -78,9 +78,6 @@ import {
78
78
const SOLANA_SEQ_LOG = 'Program log: Sequence: ' ;
79
79
const SOLANA_CHAIN_NAME = MAINNET_CONFIG . chains . solana ! . key ;
80
80
81
- // Add priority fee according to 75th percentile of recent fees paid
82
- const SOLANA_FEE_PERCENTILE = 0.75 ;
83
-
84
81
const SOLANA_MAINNET_EMMITER_ID =
85
82
'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5' ;
86
83
const SOLANA_TESTNET_EMITTER_ID =
@@ -277,18 +274,15 @@ export class SolanaContext<
277
274
payerPublicKey ,
278
275
tokenPublicKey ,
279
276
) ;
280
- const transaction = new Transaction ( ) ;
281
- transaction . add (
282
- ...( await this . determineComputeBudget ( [
283
- tokenPublicKey ,
284
- associatedPublicKey ,
285
- ] ) ) ,
277
+ const transaction = new Transaction (
278
+ await this . connection ?. getLatestBlockhash ( commitment ) ,
286
279
) ;
287
280
transaction . add ( createAccountInst ) ;
288
-
289
- const { blockhash } = await this . connection . getLatestBlockhash ( commitment ) ;
290
- transaction . recentBlockhash = blockhash ;
291
281
transaction . feePayer = payerPublicKey ;
282
+ await addComputeBudget ( this . connection ! , transaction , [
283
+ tokenPublicKey ,
284
+ associatedPublicKey ,
285
+ ] ) ;
292
286
return transaction ;
293
287
}
294
288
@@ -397,12 +391,9 @@ export class SolanaContext<
397
391
payerPublicKey , //authority
398
392
) ;
399
393
400
- const { blockhash } = await this . connection . getLatestBlockhash ( commitment ) ;
401
- const transaction = new Transaction ( ) ;
402
- transaction . add ( ...( await this . determineComputeBudget ( [ NATIVE_MINT ] ) ) ) ;
403
-
404
- transaction . recentBlockhash = blockhash ;
405
- transaction . feePayer = payerPublicKey ;
394
+ const transaction = new Transaction (
395
+ await this . connection ?. getLatestBlockhash ( commitment ) ,
396
+ ) ;
406
397
transaction . add (
407
398
createAncillaryAccountIx ,
408
399
initialBalanceTransferIx ,
@@ -411,6 +402,9 @@ export class SolanaContext<
411
402
tokenBridgeTransferIx ,
412
403
closeAccountIx ,
413
404
) ;
405
+
406
+ transaction . feePayer = payerPublicKey ;
407
+ await addComputeBudget ( this . connection ! , transaction , [ NATIVE_MINT ] ) ;
414
408
transaction . partialSign ( message , ancillaryKeypair ) ;
415
409
return transaction ;
416
410
}
@@ -531,17 +525,16 @@ export class SolanaContext<
531
525
recipientAddress ,
532
526
recipientChainId ,
533
527
) ;
534
- const transaction = new Transaction ( ) ;
535
- transaction . add (
536
- ...( await this . determineComputeBudget ( [
537
- new PublicKey ( fromAddress ) ,
538
- new PublicKey ( mintAddress ) ,
539
- ] ) ) ,
528
+
529
+ const transaction = new Transaction (
530
+ await this . connection ?. getLatestBlockhash ( commitment ) ,
540
531
) ;
541
532
transaction . add ( approvalIx , tokenBridgeTransferIx ) ;
542
- const { blockhash } = await this . connection . getLatestBlockhash ( commitment ) ;
543
- transaction . recentBlockhash = blockhash ;
544
533
transaction . feePayer = new PublicKey ( senderAddress ) ;
534
+ await addComputeBudget ( this . connection ! , transaction , [
535
+ new PublicKey ( fromAddress ) ,
536
+ new PublicKey ( mintAddress ) ,
537
+ ] ) ;
545
538
transaction . partialSign ( message ) ;
546
539
return transaction ;
547
540
}
@@ -901,26 +894,30 @@ export class SolanaContext<
901
894
}
902
895
903
896
const parsed = parseTokenTransferVaa ( signedVAA ) ;
897
+ const tokenKey = new PublicKey ( parsed . tokenAddress ) ;
904
898
const isNativeSol =
905
899
parsed . tokenChain === MAINNET_CHAINS . solana &&
906
- new PublicKey ( parsed . tokenAddress ) . equals ( NATIVE_MINT ) ;
907
- if ( isNativeSol ) {
908
- return await redeemAndUnwrapOnSolana (
909
- this . connection ,
910
- contracts . core ,
911
- contracts . token_bridge ,
912
- payerAddr ,
913
- signedVAA ,
914
- ) ;
915
- } else {
916
- return await redeemOnSolana (
917
- this . connection ,
918
- contracts . core ,
919
- contracts . token_bridge ,
920
- payerAddr ,
921
- signedVAA ,
922
- ) ;
923
- }
900
+ tokenKey . equals ( NATIVE_MINT ) ;
901
+
902
+ const transaction = isNativeSol
903
+ ? await redeemAndUnwrapOnSolana (
904
+ this . connection ,
905
+ contracts . core ,
906
+ contracts . token_bridge ,
907
+ payerAddr ,
908
+ signedVAA ,
909
+ )
910
+ : await redeemOnSolana (
911
+ this . connection ,
912
+ contracts . core ,
913
+ contracts . token_bridge ,
914
+ payerAddr ,
915
+ signedVAA ,
916
+ ) ;
917
+
918
+ await addComputeBudget ( this . connection ! , transaction , [ tokenKey ] ) ;
919
+
920
+ return transaction ;
924
921
}
925
922
926
923
async redeemRelay (
@@ -953,8 +950,10 @@ export class SolanaContext<
953
950
parsed . tokenChain ,
954
951
parsed . tokenAddress ,
955
952
) ;
956
- const transaction = new Transaction ( ) ;
957
- transaction . add ( ...( await this . determineComputeBudget ( [ mint ] ) ) ) ;
953
+
954
+ const transaction = new Transaction (
955
+ await this . connection ?. getLatestBlockhash ( 'finalized' ) ,
956
+ ) ;
958
957
const recipientTokenAccount = getAssociatedTokenAddressSync (
959
958
mint ,
960
959
recipient ,
@@ -996,9 +995,8 @@ export class SolanaContext<
996
995
) ;
997
996
}
998
997
transaction . add ( redeemIx ) ;
999
- const { blockhash } = await this . connection . getLatestBlockhash ( 'finalized' ) ;
1000
- transaction . recentBlockhash = blockhash ;
1001
998
transaction . feePayer = new PublicKey ( recipient ) ;
999
+ await addComputeBudget ( this . connection ! , transaction , [ mint ] ) ;
1002
1000
return transaction ;
1003
1001
}
1004
1002
@@ -1065,7 +1063,10 @@ export class SolanaContext<
1065
1063
) ;
1066
1064
const recipientChainId = this . context . toChainId ( recipientChain ) ;
1067
1065
const nonce = createNonce ( ) . readUint32LE ( ) ;
1068
- const transaction = new Transaction ( ) ;
1066
+ const transaction = new Transaction (
1067
+ await this . connection ?. getLatestBlockhash ( 'finalized' ) ,
1068
+ ) ;
1069
+ transaction . feePayer = new PublicKey ( senderAddress ) ;
1069
1070
1070
1071
if ( token === NATIVE || token . chain === SOLANA_CHAIN_NAME ) {
1071
1072
const mint = token === NATIVE ? NATIVE_MINT : token . address ;
@@ -1099,9 +1100,6 @@ export class SolanaContext<
1099
1100
}
1100
1101
}
1101
1102
1102
- transaction . add (
1103
- ...( await this . determineComputeBudget ( writableAddresses ) ) ,
1104
- ) ;
1105
1103
transaction . add (
1106
1104
await createTransferNativeTokensWithRelayInstruction (
1107
1105
this . connection ,
@@ -1118,12 +1116,11 @@ export class SolanaContext<
1118
1116
wrapToken ,
1119
1117
) ,
1120
1118
) ;
1119
+
1120
+ await addComputeBudget ( this . connection ! , transaction , writableAddresses ) ;
1121
1121
} else {
1122
1122
const mint = await this . mustGetForeignAsset ( token , sendingChain ) ;
1123
1123
1124
- transaction . add (
1125
- ...( await this . determineComputeBudget ( [ new PublicKey ( mint ) ] ) ) ,
1126
- ) ;
1127
1124
transaction . add (
1128
1125
await createTransferWrappedTokensWithRelayInstruction (
1129
1126
this . connection ,
@@ -1139,11 +1136,11 @@ export class SolanaContext<
1139
1136
nonce ,
1140
1137
) ,
1141
1138
) ;
1142
- }
1143
1139
1144
- const { blockhash } = await this . connection . getLatestBlockhash ( 'finalized' ) ;
1145
- transaction . recentBlockhash = blockhash ;
1146
- transaction . feePayer = new PublicKey ( senderAddress ) ;
1140
+ await addComputeBudget ( this . connection ! , transaction , [
1141
+ new PublicKey ( mint ) ,
1142
+ ] ) ;
1143
+ }
1147
1144
return transaction ;
1148
1145
}
1149
1146
@@ -1213,38 +1210,4 @@ export class SolanaContext<
1213
1210
chain : 'solana' ,
1214
1211
} ;
1215
1212
}
1216
-
1217
- async determineComputeBudget (
1218
- lockedWritableAccounts : PublicKey [ ] = [ ] ,
1219
- ) : Promise < TransactionInstruction [ ] > {
1220
- let fee = 100_000 ; // Set fee to 100,000 microlamport by default
1221
-
1222
- try {
1223
- const recentFeesResponse =
1224
- await this . connection ?. getRecentPrioritizationFees ( {
1225
- lockedWritableAccounts,
1226
- } ) ;
1227
-
1228
- if ( recentFeesResponse ) {
1229
- // Get 75th percentile fee paid in recent slots
1230
- const recentFees = recentFeesResponse
1231
- . map ( ( dp ) => dp . prioritizationFee )
1232
- . sort ( ( a , b ) => a - b ) ;
1233
- fee = recentFees [ Math . floor ( recentFees . length * SOLANA_FEE_PERCENTILE ) ] ;
1234
- }
1235
- } catch ( e ) {
1236
- console . error ( 'Error fetching Solana recent fees' , e ) ;
1237
- }
1238
-
1239
- console . info ( `Setting Solana compute unit price to ${ fee } microLamports` ) ;
1240
-
1241
- return [
1242
- ComputeBudgetProgram . setComputeUnitLimit ( {
1243
- units : 250_000 ,
1244
- } ) ,
1245
- ComputeBudgetProgram . setComputeUnitPrice ( {
1246
- microLamports : fee ,
1247
- } ) ,
1248
- ] ;
1249
- }
1250
1213
}
0 commit comments