Skip to content

Commit c4238c7

Browse files
authored
Guibescos/expose attester instructions (#313)
* Add payload generators * Executor cli no longer a lib * Expose instructions in client * Format
1 parent 3176d6a commit c4238c7

File tree

2 files changed

+50
-26
lines changed

2 files changed

+50
-26
lines changed

solana/pyth2wormhole/client/src/lib.rs

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -125,78 +125,102 @@ pub fn gen_init_tx(
125125
Ok(tx_signed)
126126
}
127127

128-
pub fn gen_set_config_tx(
129-
payer: Keypair,
130-
p2w_addr: Pubkey,
131-
owner: Keypair,
128+
pub fn get_set_config_ix(
129+
p2w_addr: &Pubkey,
130+
owner_pubkey: &Pubkey,
131+
payer_pubkey: &Pubkey,
132132
new_config: Pyth2WormholeConfig,
133-
latest_blockhash: Hash,
134-
) -> Result<Transaction, ErrBox> {
135-
let payer_pubkey = payer.pubkey();
136-
133+
) -> Result<Instruction, ErrBox> {
137134
let acc_metas = vec![
138135
// config
139136
AccountMeta::new(
140137
P2WConfigAccount::<{ AccountState::Initialized }>::key(None, &p2w_addr),
141138
false,
142139
),
143140
// current_owner
144-
AccountMeta::new(owner.pubkey(), true),
141+
AccountMeta::new(*owner_pubkey, true),
145142
// payer
146-
AccountMeta::new(payer.pubkey(), true),
143+
AccountMeta::new(*payer_pubkey, true),
147144
// system_program
148145
AccountMeta::new(system_program::id(), false),
149146
];
150-
151147
let ix_data = (
152148
pyth2wormhole::instruction::Instruction::SetConfig,
153149
new_config,
154150
);
151+
Ok(Instruction::new_with_bytes(
152+
*p2w_addr,
153+
ix_data.try_to_vec()?.as_slice(),
154+
acc_metas,
155+
))
156+
}
155157

156-
let ix = Instruction::new_with_bytes(p2w_addr, ix_data.try_to_vec()?.as_slice(), acc_metas);
158+
pub fn gen_set_config_tx(
159+
payer: Keypair,
160+
p2w_addr: Pubkey,
161+
owner: Keypair,
162+
new_config: Pyth2WormholeConfig,
163+
latest_blockhash: Hash,
164+
) -> Result<Transaction, ErrBox> {
165+
let ix = get_set_config_ix(&p2w_addr, &owner.pubkey(), &payer.pubkey(), new_config)?;
157166

158167
let signers = vec![&owner, &payer];
159168
let tx_signed = Transaction::new_signed_with_payer::<Vec<&Keypair>>(
160169
&[ix],
161-
Some(&payer_pubkey),
170+
Some(&payer.pubkey()),
162171
&signers,
163172
latest_blockhash,
164173
);
165174
Ok(tx_signed)
166175
}
167176

168-
pub fn gen_set_is_active_tx(
169-
payer: Keypair,
170-
p2w_addr: Pubkey,
171-
ops_owner: Keypair,
177+
pub fn get_set_is_active_ix(
178+
p2w_addr: &Pubkey,
179+
ops_owner_pubkey: &Pubkey,
180+
payer_pubkey: &Pubkey,
172181
new_is_active: bool,
173-
latest_blockhash: Hash,
174-
) -> Result<Transaction, ErrBox> {
175-
let payer_pubkey = payer.pubkey();
176-
182+
) -> Result<Instruction, ErrBox> {
177183
let acc_metas = vec![
178184
// config
179185
AccountMeta::new(
180186
P2WConfigAccount::<{ AccountState::Initialized }>::key(None, &p2w_addr),
181187
false,
182188
),
183189
// ops_owner
184-
AccountMeta::new(ops_owner.pubkey(), true),
190+
AccountMeta::new(*ops_owner_pubkey, true),
185191
// payer
186-
AccountMeta::new(payer.pubkey(), true),
192+
AccountMeta::new(*payer_pubkey, true),
187193
];
188194

189195
let ix_data = (
190196
pyth2wormhole::instruction::Instruction::SetIsActive,
191197
new_is_active,
192198
);
199+
Ok(Instruction::new_with_bytes(
200+
*p2w_addr,
201+
ix_data.try_to_vec()?.as_slice(),
202+
acc_metas,
203+
))
204+
}
193205

194-
let ix = Instruction::new_with_bytes(p2w_addr, ix_data.try_to_vec()?.as_slice(), acc_metas);
206+
pub fn gen_set_is_active_tx(
207+
payer: Keypair,
208+
p2w_addr: Pubkey,
209+
ops_owner: Keypair,
210+
new_is_active: bool,
211+
latest_blockhash: Hash,
212+
) -> Result<Transaction, ErrBox> {
213+
let ix = get_set_is_active_ix(
214+
&p2w_addr,
215+
&ops_owner.pubkey(),
216+
&payer.pubkey(),
217+
new_is_active,
218+
)?;
195219

196220
let signers = vec![&ops_owner, &payer];
197221
let tx_signed = Transaction::new_signed_with_payer::<Vec<&Keypair>>(
198222
&[ix],
199-
Some(&payer_pubkey),
223+
Some(&payer.pubkey()),
200224
&signers,
201225
latest_blockhash,
202226
);

third_party/pyth/p2w-sdk/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ wasm = ["wasm-bindgen", "solana"]
1616
[dependencies]
1717
hex = "0.4.3"
1818
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
19-
pyth-sdk = "*"
19+
pyth-sdk = {version = "0.5.0"}
2020
pyth-sdk-solana = { version = "0.5.0", optional = true }
2121
wasm-bindgen = { version = "0.2.74", features = ["serde-serialize"], optional = true}
2222
solitaire = { git = "https://github.com/wormhole-foundation/wormhole", tag = "v2.8.9", optional = true}

0 commit comments

Comments
 (0)