@@ -6,17 +6,23 @@ use anchor_lang::{
6
6
solana_program:: borsh:: get_packed_len,
7
7
system_program,
8
8
} ;
9
+ use error:: ExecutorError ;
9
10
use state:: {
10
11
claim_record:: ClaimRecord ,
11
12
posted_vaa:: AnchorVaa ,
12
13
} ;
14
+ use wormhole:: Chain :: {
15
+ self ,
16
+ Solana ,
17
+ } ;
13
18
14
19
mod error;
15
20
mod state;
16
21
17
- #[ cfg( test) ] //Conditional compilation of the tests
22
+ #[ cfg( test) ]
18
23
mod tests;
19
24
25
+ //Anchor requires the program to declare its own id
20
26
declare_id ! ( "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS" ) ;
21
27
22
28
#[ program]
@@ -25,32 +31,24 @@ pub mod remote_executor {
25
31
instruction:: Instruction ,
26
32
program:: invoke_signed,
27
33
} ;
28
- use boolinator:: Boolinator ;
29
- use wormhole:: Chain :: {
30
- self ,
31
- Solana ,
32
- } ;
33
34
34
- use crate :: {
35
- error:: ExecutorError ,
36
- state:: governance_payload:: ExecutorPayload ,
37
- } ;
35
+ use crate :: state:: governance_payload:: ExecutorPayload ;
38
36
39
37
use super :: * ;
40
38
41
39
pub fn execute_posted_vaa ( ctx : Context < ExecutePostedVaa > ) -> Result < ( ) > {
42
40
let posted_vaa = & ctx. accounts . posted_vaa ;
43
41
let claim_record = & mut ctx. accounts . claim_record ;
44
-
45
- ( Chain :: from ( posted_vaa. emitter_chain ) == Solana )
46
- . ok_or ( error ! ( ExecutorError :: EmitterChainNotSolana ) ) ?;
47
- ( posted_vaa. sequence > claim_record. sequence )
48
- . ok_or ( error ! ( ExecutorError :: NonIncreasingSequence ) ) ?;
49
42
claim_record. sequence = posted_vaa. sequence ;
50
43
51
44
let payload = ExecutorPayload :: try_from_slice ( & posted_vaa. payload ) ?;
52
45
payload. check_header ( ) ?;
53
46
47
+ let ( _, bump) = Pubkey :: find_program_address (
48
+ & [ EXECUTOR_KEY_SEED . as_bytes ( ) , & posted_vaa. emitter_address ] ,
49
+ & id ( ) ,
50
+ ) ;
51
+
54
52
for instruction in payload. instructions . iter ( ) . map ( Instruction :: from) {
55
53
// TO DO: We currently pass `remaining_accounts` down to the CPIs, is there a more efficient way to do it?
56
54
invoke_signed (
@@ -59,7 +57,7 @@ pub mod remote_executor {
59
57
& [ & [
60
58
EXECUTOR_KEY_SEED . as_bytes ( ) ,
61
59
& posted_vaa. emitter_address ,
62
- & [ * ctx . bumps . get ( "executor_key" ) . unwrap ( ) ] ,
60
+ & [ bump ] ,
63
61
] ] ,
64
62
) ?;
65
63
}
@@ -74,13 +72,16 @@ const CLAIM_RECORD_SEED: &str = "CLAIM_RECORD";
74
72
pub struct ExecutePostedVaa < ' info > {
75
73
#[ account( mut ) ]
76
74
pub payer : Signer < ' info > ,
75
+ #[ account( constraint = Chain :: from( posted_vaa. emitter_chain) == Solana @ ExecutorError :: EmitterChainNotSolana , constraint = posted_vaa. sequence > claim_record. sequence @ExecutorError :: NonIncreasingSequence ) ]
77
76
pub posted_vaa : Account < ' info , AnchorVaa > ,
78
- #[ account( seeds = [ EXECUTOR_KEY_SEED . as_bytes( ) , & posted_vaa. emitter_address] , bump) ]
79
- pub executor_key : UncheckedAccount < ' info > ,
80
- /// The reason claim record is separated from executor_key is that executor key might need to pay in the CPI, so we want it to be a wallet
77
+ /// The reason claim_record has different seeds than executor_key is that executor key might need to pay in the CPI, so we want it to be a native wallet
81
78
#[ account( init_if_needed, space = 8 + get_packed_len:: <ClaimRecord >( ) , payer=payer, seeds = [ CLAIM_RECORD_SEED . as_bytes( ) , & posted_vaa. emitter_address] , bump) ]
82
79
pub claim_record : Account < ' info , ClaimRecord > ,
83
80
pub system_program : Program < ' info , System > ,
81
+ // Additional accounts passed to the instruction will be passed down to the CPIs. Very importantly executor_key needs to be passed as it will be the signer of the CPIs.
82
+ // Below is the "anchor specification" of that account
83
+ // #[account(seeds = [EXECUTOR_KEY_SEED.as_bytes(), &posted_vaa.emitter_address], bump)]
84
+ // pub executor_key: UncheckedAccount<'info>,
84
85
}
85
86
86
87
impl crate :: accounts:: ExecutePostedVaa {
@@ -90,19 +91,13 @@ impl crate::accounts::ExecutePostedVaa {
90
91
emitter : & Pubkey ,
91
92
posted_vaa : & Pubkey ,
92
93
) -> Self {
93
- let executor_key = Pubkey :: find_program_address (
94
- & [ EXECUTOR_KEY_SEED . as_bytes ( ) , & emitter. to_bytes ( ) ] ,
95
- program_id,
96
- )
97
- . 0 ;
98
94
let claim_record = Pubkey :: find_program_address (
99
95
& [ CLAIM_RECORD_SEED . as_bytes ( ) , & emitter. to_bytes ( ) ] ,
100
96
program_id,
101
97
)
102
98
. 0 ;
103
99
crate :: accounts:: ExecutePostedVaa {
104
100
payer : * payer,
105
- executor_key,
106
101
claim_record,
107
102
posted_vaa : * posted_vaa,
108
103
system_program : system_program:: ID ,
0 commit comments