File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed
programs/pyth-solana-receiver/src
sdk/js/pyth_solana_receiver/src Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff 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+
396407fn deserialize_guardian_set_checked (
397408 account_info : & AccountInfo < ' _ > ,
398409 wormhole : & Pubkey ,
Original file line number Diff line number Diff 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 */
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments