Skip to content

Commit 36c21a2

Browse files
committed
fix: add reclaimTwapRent to recv contract
1 parent 7daa553 commit 36c21a2

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

target_chains/solana/programs/pyth-solana-receiver/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ pub mod pyth_solana_receiver {
283283
pub fn reclaim_rent(_ctx: Context<ReclaimRent>) -> Result<()> {
284284
Ok(())
285285
}
286+
pub fn reclaim_twap_rent(_ctx: Context<ReclaimTwapRent>) -> Result<()> {
287+
Ok(())
288+
}
286289
}
287290

288291
#[derive(Accounts)]
@@ -393,6 +396,14 @@ pub struct ReclaimRent<'info> {
393396
pub price_update_account: Account<'info, PriceUpdateV2>,
394397
}
395398

399+
#[derive(Accounts)]
400+
pub struct ReclaimTwapRent<'info> {
401+
#[account(mut)]
402+
pub payer: Signer<'info>,
403+
#[account(mut, close = payer, constraint = twap_update_account.write_authority == payer.key() @ ReceiverError::WrongWriteAuthority)]
404+
pub twap_update_account: Account<'info, TwapUpdate>,
405+
}
406+
396407
fn deserialize_guardian_set_checked(
397408
account_info: &AccountInfo<'_>,
398409
wormhole: &Pubkey,

target_chains/solana/sdk/js/pyth_solana_receiver/src/PythSolanaReceiver.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export class PythSolanaReceiver {
698698
"0x" + parseTwapMessage(startUpdate.message).feedId.toString("hex")
699699
] = twapUpdateKeypair.publicKey;
700700
closeInstructions.push(
701-
await this.buildClosePriceUpdateInstruction(twapUpdateKeypair.publicKey)
701+
await this.buildCloseTwapUpdateInstruction(twapUpdateKeypair.publicKey)
702702
);
703703
}
704704

@@ -836,6 +836,19 @@ export class PythSolanaReceiver {
836836
return { instruction, signers: [] };
837837
}
838838

839+
/**
840+
* Build an instruction to close a TWAP update account, recovering the rent.
841+
*/
842+
async buildCloseTwapUpdateInstruction(
843+
twapUpdateAccount: PublicKey
844+
): Promise<InstructionWithEphemeralSigners> {
845+
const instruction = await this.receiver.methods
846+
.reclaimTwapRent()
847+
.accounts({ twapUpdateAccount })
848+
.instruction();
849+
return { instruction, signers: [] };
850+
}
851+
839852
/**
840853
* Returns a set of versioned transactions that contain the provided instructions in the same order and with efficient batching
841854
*/

target_chains/solana/sdk/js/pyth_solana_receiver/src/idl/pyth_solana_receiver.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,22 @@ export type PythSolanaReceiver = {
350350
}
351351
];
352352
args: [];
353+
},
354+
{
355+
name: "reclaimTwapRent";
356+
accounts: [
357+
{
358+
name: "payer";
359+
isMut: true;
360+
isSigner: true;
361+
},
362+
{
363+
name: "twapUpdateAccount";
364+
isMut: true;
365+
isSigner: false;
366+
}
367+
];
368+
args: [];
353369
}
354370
];
355371
accounts: [
@@ -1118,6 +1134,22 @@ export const IDL: PythSolanaReceiver = {
11181134
],
11191135
args: [],
11201136
},
1137+
{
1138+
name: "reclaimTwapRent",
1139+
accounts: [
1140+
{
1141+
name: "payer",
1142+
isMut: true,
1143+
isSigner: true,
1144+
},
1145+
{
1146+
name: "twapUpdateAccount",
1147+
isMut: true,
1148+
isSigner: false,
1149+
},
1150+
],
1151+
args: [],
1152+
},
11211153
],
11221154
accounts: [
11231155
{

0 commit comments

Comments
 (0)