@@ -30,11 +30,14 @@ import {
30
30
} from '@wormhole-foundation/connect-sdk' ;
31
31
import { Wormhole as WormholeCoreContract } from './types' ;
32
32
import {
33
+ BridgeData ,
34
+ createBridgeFeeTransferInstruction ,
33
35
createPostMessageInstruction ,
34
36
createPostVaaInstruction ,
35
37
createReadOnlyWormholeProgramInterface ,
36
38
createVerifySignaturesInstructions ,
37
39
derivePostedVaaKey ,
40
+ getWormholeBridgeData ,
38
41
} from './utils' ;
39
42
40
43
const SOLANA_SEQ_LOG = 'Program log: Sequence: ' ;
@@ -45,6 +48,7 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
45
48
readonly chainId : ChainId ;
46
49
readonly coreBridge : Program < WormholeCoreContract > ;
47
50
readonly address : string ;
51
+ protected bridgeData ?: BridgeData ;
48
52
49
53
constructor (
50
54
readonly network : N ,
@@ -86,6 +90,17 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
86
90
) ;
87
91
}
88
92
93
+ async getMessageFee ( ) : Promise < bigint > {
94
+ // cache lookups since this should not change frequently
95
+ if ( ! this . bridgeData )
96
+ this . bridgeData = await getWormholeBridgeData (
97
+ this . connection ,
98
+ this . coreBridge . programId ,
99
+ ) ;
100
+
101
+ return this . bridgeData . config . fee ;
102
+ }
103
+
89
104
async * publishMessage (
90
105
sender : AnySolanaAddress ,
91
106
message : Uint8Array ,
@@ -104,11 +119,18 @@ export class SolanaWormholeCore<N extends Network, C extends SolanaChains>
104
119
consistencyLevel ,
105
120
) ;
106
121
122
+ const fee = await this . getMessageFee ( ) ;
123
+ const feeTransferIx = createBridgeFeeTransferInstruction (
124
+ this . coreBridge . programId ,
125
+ payer ,
126
+ fee ,
127
+ ) ;
128
+
107
129
const { blockhash } = await SolanaPlatform . latestBlock ( this . connection ) ;
108
130
const transaction = new Transaction ( ) ;
109
131
transaction . recentBlockhash = blockhash ;
110
132
transaction . feePayer = payer ;
111
- transaction . add ( postMsgIx ) ;
133
+ transaction . add ( feeTransferIx , postMsgIx ) ;
112
134
transaction . partialSign ( messageAccount ) ;
113
135
114
136
yield this . createUnsignedTx ( transaction , 'Core.PublishMessage' ) ;
0 commit comments