1
1
package solana
2
2
3
3
import (
4
- "encoding/binary"
5
4
"encoding/json"
6
5
"errors"
7
6
"fmt"
@@ -21,15 +20,13 @@ var ccipRouterIDL = idl.FetchCCIPRouterIDL()
21
20
22
21
const (
23
22
sourceChainSelectorPath = "Info.AbstractReports.Messages.Header.SourceChainSelector"
24
- destChainSelectorPath = "Info.AbstractReports.Messages.Header.DestChainSelector"
25
23
destTokenAddress = "Info.AbstractReports.Messages.TokenAmounts.DestTokenAddress"
26
24
receiverAddress = "Info.AbstractReports.Messages.Receiver"
27
25
merkleRootSourceChainSelector = "Info.MerkleRoots.ChainSel"
28
26
merkleRoot = "Info.MerkleRoots.MerkleRoot"
29
27
)
30
28
31
- func getCommitMethodConfig (fromAddress string , offrampProgramAddress string , destChainSelector uint64 , priceOnly bool ) chainwriter.MethodConfig {
32
- destChainSelectorBytes := binary .LittleEndian .AppendUint64 ([]byte {}, destChainSelector )
29
+ func getCommitMethodConfig (fromAddress string , offrampProgramAddress string , priceOnly bool ) chainwriter.MethodConfig {
33
30
chainSpecificName := "commit"
34
31
if priceOnly {
35
32
chainSpecificName = "commitPriceOnly"
@@ -45,17 +42,18 @@ func getCommitMethodConfig(fromAddress string, offrampProgramAddress string, des
45
42
},
46
43
},
47
44
ChainSpecificName : chainSpecificName ,
45
+ ArgsTransform : "CCIPCommit" ,
48
46
LookupTables : chainwriter.LookupTables {
49
47
DerivedLookupTables : []chainwriter.DerivedLookupTable {
50
48
getCommonAddressLookupTableConfig (offrampProgramAddress ),
51
49
},
52
50
},
53
- Accounts : buildCommitAccountsList (fromAddress , offrampProgramAddress , destChainSelectorBytes , priceOnly ),
51
+ Accounts : buildCommitAccountsList (fromAddress , offrampProgramAddress , priceOnly ),
54
52
DebugIDLocation : "" ,
55
53
}
56
54
}
57
55
58
- func buildCommitAccountsList (fromAddress , offrampProgramAddress string , destChainSelectorBytes [] byte , priceOnly bool ) []chainwriter.Lookup {
56
+ func buildCommitAccountsList (fromAddress , offrampProgramAddress string , priceOnly bool ) []chainwriter.Lookup {
59
57
accounts := []chainwriter.Lookup {}
60
58
accounts = append (accounts ,
61
59
getOfframpAccountConfig (offrampProgramAddress ),
@@ -98,9 +96,12 @@ func buildCommitAccountsList(fromAddress, offrampProgramAddress string, destChai
98
96
getFeeQuoterProgramAccount (offrampProgramAddress ),
99
97
getFeeQuoterAllowedPriceUpdater (offrampProgramAddress ),
100
98
getFeeQuoterConfigLookup (offrampProgramAddress ),
99
+ getRMNRemoteProgramAccount (offrampProgramAddress ),
100
+ getRMNRemoteCursesLookup (offrampProgramAddress ),
101
+ getRMNRemoteConfigLookup (offrampProgramAddress ),
101
102
getGlobalStateConfig (offrampProgramAddress ),
102
103
getBillingTokenConfig (offrampProgramAddress ),
103
- getChainConfigGasPriceConfig (offrampProgramAddress , destChainSelectorBytes ),
104
+ getChainConfigGasPriceConfig (offrampProgramAddress ),
104
105
)
105
106
return accounts
106
107
}
@@ -117,7 +118,7 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
117
118
},
118
119
},
119
120
ChainSpecificName : "execute" ,
120
- ArgsTransform : "CCIP " ,
121
+ ArgsTransform : "CCIPExecute " ,
121
122
LookupTables : chainwriter.LookupTables {
122
123
DerivedLookupTables : []chainwriter.DerivedLookupTable {
123
124
{
@@ -140,6 +141,7 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
140
141
},
141
142
},
142
143
},
144
+ Optional : true , // Lookup table is optional if DestTokenAddress is not present in report
143
145
},
144
146
getCommonAddressLookupTableConfig (offrampProgramAddress ),
145
147
},
@@ -155,6 +157,7 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
155
157
},
156
158
},
157
159
MintAddress : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destTokenAddress }},
160
+ Optional : true , // ATA lookup is optional if DestTokenAddress is not present in report
158
161
},
159
162
},
160
163
Accounts : []chainwriter.Lookup {
@@ -229,11 +232,14 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
229
232
IsWritable : false ,
230
233
},
231
234
},
235
+ getRMNRemoteProgramAccount (offrampProgramAddress ),
236
+ getRMNRemoteCursesLookup (offrampProgramAddress ),
237
+ getRMNRemoteConfigLookup (offrampProgramAddress ),
232
238
{
233
239
AccountLookup : & chainwriter.AccountLookup {
234
240
Name : "UserAccounts" ,
235
- Location : "Info.AbstractReports.Message .ExtraArgsDecoded.Accounts" ,
236
- IsWritable : chainwriter.MetaBool {BitmapLocation : "Info.AbstractReports.Message .ExtraArgsDecoded.IsWritableBitmap" },
241
+ Location : "Info.AbstractReports.Messages .ExtraArgsDecoded.Accounts" ,
242
+ IsWritable : chainwriter.MetaBool {BitmapLocation : "Info.AbstractReports.Messages .ExtraArgsDecoded.IsWritableBitmap" },
237
243
IsSigner : chainwriter.MetaBool {Value : false },
238
244
},
239
245
Optional : true ,
@@ -247,18 +253,18 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
247
253
},
248
254
},
249
255
Seeds : []chainwriter.Seed {
250
- {Static : []byte (fromAddress )},
251
256
{Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : "Info.AbstractReports.Messages.Receiver" }}},
257
+ // Token Program stored in PoolLookupTable
252
258
{Dynamic : chainwriter.Lookup {
253
259
AccountsFromLookupTable : & chainwriter.AccountsFromLookupTable {
254
260
LookupTableName : "PoolLookupTable" ,
255
261
IncludeIndexes : []int {6 },
256
- }} ,
257
- },
262
+ },
263
+ }} ,
258
264
{Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destTokenAddress }}},
259
265
},
260
266
IsSigner : false ,
261
- IsWritable : false ,
267
+ IsWritable : true ,
262
268
},
263
269
Optional : true ,
264
270
},
@@ -268,7 +274,7 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
268
274
PublicKey : getFeeQuoterProgramAccount (offrampProgramAddress ),
269
275
Seeds : []chainwriter.Seed {
270
276
{Static : []byte ("per_chain_per_token_config" )},
271
- {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destChainSelectorPath }}},
277
+ {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : sourceChainSelectorPath }}},
272
278
{Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destTokenAddress }}},
273
279
},
274
280
IsSigner : false ,
@@ -287,11 +293,11 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
287
293
},
288
294
Seeds : []chainwriter.Seed {
289
295
{Static : []byte ("ccip_tokenpool_chainconfig" )},
290
- {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destChainSelectorPath }}},
296
+ {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : sourceChainSelectorPath }}},
291
297
{Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : destTokenAddress }}},
292
298
},
293
299
IsSigner : false ,
294
- IsWritable : false ,
300
+ IsWritable : true ,
295
301
},
296
302
Optional : true ,
297
303
},
@@ -307,7 +313,7 @@ func getExecuteMethodConfig(fromAddress string, offrampProgramAddress string) ch
307
313
}
308
314
}
309
315
310
- func GetSolanaChainWriterConfig (offrampProgramAddress string , fromAddress string , destChainSelector uint64 ) (chainwriter.ChainWriterConfig , error ) {
316
+ func GetSolanaChainWriterConfig (offrampProgramAddress string , fromAddress string ) (chainwriter.ChainWriterConfig , error ) {
311
317
// check fromAddress
312
318
pk , err := solana .PublicKeyFromBase58 (fromAddress )
313
319
if err != nil {
@@ -325,23 +331,19 @@ func GetSolanaChainWriterConfig(offrampProgramAddress string, fromAddress string
325
331
}
326
332
// validate CCIP Router IDL, errors not expected
327
333
var routerIDL solanacodec.IDL
328
- if err = json .Unmarshal ([]byte (ccipOfframpIDL ), & routerIDL ); err != nil {
334
+ if err = json .Unmarshal ([]byte (ccipRouterIDL ), & routerIDL ); err != nil {
329
335
return chainwriter.ChainWriterConfig {}, fmt .Errorf ("unexpected error: invalid CCIP Router IDL, error: %w" , err )
330
336
}
331
337
solConfig := chainwriter.ChainWriterConfig {
332
338
Programs : map [string ]chainwriter.ProgramConfig {
333
339
ccipconsts .ContractNameOffRamp : {
334
340
Methods : map [string ]chainwriter.MethodConfig {
335
341
ccipconsts .MethodExecute : getExecuteMethodConfig (fromAddress , offrampProgramAddress ),
336
- ccipconsts .MethodCommit : getCommitMethodConfig (fromAddress , offrampProgramAddress , destChainSelector , false ),
337
- ccipconsts .MethodCommitPriceOnly : getCommitMethodConfig (fromAddress , offrampProgramAddress , destChainSelector , true ),
342
+ ccipconsts .MethodCommit : getCommitMethodConfig (fromAddress , offrampProgramAddress , false ),
343
+ ccipconsts .MethodCommitPriceOnly : getCommitMethodConfig (fromAddress , offrampProgramAddress , true ),
338
344
},
339
345
IDL : ccipOfframpIDL ,
340
346
},
341
- // Required for the CCIP args transform configured for the execute method which relies on the TokenAdminRegistry stored in the router
342
- ccipconsts .ContractNameRouter : {
343
- IDL : ccipRouterIDL ,
344
- },
345
347
},
346
348
}
347
349
@@ -475,6 +477,54 @@ func getFeeQuoterConfigLookup(offrampProgramAddress string) chainwriter.Lookup {
475
477
}
476
478
}
477
479
480
+ func getRMNRemoteProgramAccount (offrampProgramAddress string ) chainwriter.Lookup {
481
+ return chainwriter.Lookup {
482
+ PDALookups : & chainwriter.PDALookups {
483
+ Name : ccipconsts .ContractNameRMNRemote ,
484
+ PublicKey : getAddressConstant (offrampProgramAddress ),
485
+ Seeds : []chainwriter.Seed {
486
+ {Static : []byte ("reference_addresses" )},
487
+ },
488
+ IsSigner : false ,
489
+ IsWritable : false ,
490
+ // Reads the address from the reference addresses account
491
+ InternalField : chainwriter.InternalField {
492
+ TypeName : "ReferenceAddresses" ,
493
+ Location : "RmnRemote" ,
494
+ IDL : ccipOfframpIDL ,
495
+ },
496
+ },
497
+ }
498
+ }
499
+
500
+ func getRMNRemoteCursesLookup (offrampProgramAddress string ) chainwriter.Lookup {
501
+ return chainwriter.Lookup {
502
+ PDALookups : & chainwriter.PDALookups {
503
+ Name : "RMNRemoteCurses" ,
504
+ PublicKey : getRMNRemoteProgramAccount (offrampProgramAddress ),
505
+ Seeds : []chainwriter.Seed {
506
+ {Static : []byte ("curses" )},
507
+ },
508
+ IsSigner : false ,
509
+ IsWritable : false ,
510
+ },
511
+ }
512
+ }
513
+
514
+ func getRMNRemoteConfigLookup (offrampProgramAddress string ) chainwriter.Lookup {
515
+ return chainwriter.Lookup {
516
+ PDALookups : & chainwriter.PDALookups {
517
+ Name : "RMNRemoteConfig" ,
518
+ PublicKey : getRMNRemoteProgramAccount (offrampProgramAddress ),
519
+ Seeds : []chainwriter.Seed {
520
+ {Static : []byte ("config" )},
521
+ },
522
+ IsSigner : false ,
523
+ IsWritable : false ,
524
+ },
525
+ }
526
+ }
527
+
478
528
func getGlobalStateConfig (offrampProgramAddress string ) chainwriter.Lookup {
479
529
return chainwriter.Lookup {
480
530
PDALookups : & chainwriter.PDALookups {
@@ -484,7 +534,7 @@ func getGlobalStateConfig(offrampProgramAddress string) chainwriter.Lookup {
484
534
{Static : []byte ("state" )},
485
535
},
486
536
IsSigner : false ,
487
- IsWritable : false ,
537
+ IsWritable : true ,
488
538
},
489
539
Optional : true ,
490
540
}
@@ -497,26 +547,26 @@ func getBillingTokenConfig(offrampProgramAddress string) chainwriter.Lookup {
497
547
PublicKey : getFeeQuoterProgramAccount (offrampProgramAddress ),
498
548
Seeds : []chainwriter.Seed {
499
549
{Static : []byte ("fee_billing_token_config" )},
500
- {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : "Info.TokenPrices .TokenID" }}},
550
+ {Dynamic : chainwriter.Lookup {AccountLookup : & chainwriter.AccountLookup {Location : "Info.TokenPriceUpdates .TokenID" }}},
501
551
},
502
552
IsSigner : false ,
503
- IsWritable : false ,
553
+ IsWritable : true ,
504
554
},
505
555
Optional : true ,
506
556
}
507
557
}
508
558
509
- func getChainConfigGasPriceConfig (offrampProgramAddress string , destChainSelector [] byte ) chainwriter.Lookup {
559
+ func getChainConfigGasPriceConfig (offrampProgramAddress string ) chainwriter.Lookup {
510
560
return chainwriter.Lookup {
511
561
PDALookups : & chainwriter.PDALookups {
512
562
Name : "ChainConfigGasPrice" ,
513
563
PublicKey : getFeeQuoterProgramAccount (offrampProgramAddress ),
514
564
Seeds : []chainwriter.Seed {
515
565
{Static : []byte ("dest_chain" )},
516
- {Static : destChainSelector },
566
+ {Dynamic : chainwriter. Lookup { AccountLookup : & chainwriter. AccountLookup { Location : "Info.GasPriceUpdates.ChainSel" }} },
517
567
},
518
568
IsSigner : false ,
519
- IsWritable : false ,
569
+ IsWritable : true ,
520
570
},
521
571
Optional : true ,
522
572
}
0 commit comments