@@ -22,6 +22,8 @@ use solana_program::{
22
22
program_error:: ProgramError ,
23
23
pubkey:: Pubkey ,
24
24
rent:: Rent ,
25
+ system_instruction,
26
+ sysvar:: Sysvar as SolanaSysvar ,
25
27
} ;
26
28
27
29
use p2w_sdk:: {
@@ -332,5 +334,42 @@ pub fn attest(ctx: &ExecutionContext, accs: &mut Attest, data: AttestData) -> So
332
334
. as_slice ( ) ,
333
335
) ?;
334
336
337
+ // NOTE: 2022-09-05
338
+ //
339
+ // This part is added to avoid rent exemption error that is introduced using
340
+ // a wrong implementation in solitaire
341
+ //
342
+ // This is done after the cross-contract call to get the proper account sizes
343
+ // and avoid breaking wormhole call.
344
+ //
345
+ // It can be removed once wormhole mitigates this problem and upgrades its contract
346
+
347
+ // Checking the message account balance
348
+ let wh_message_balance = accs. wh_message . info ( ) . lamports ( ) ;
349
+ let wh_message_rent_exempt = Rent :: get ( ) ?. minimum_balance ( accs. wh_message . info ( ) . data_len ( ) ) ;
350
+
351
+ if wh_message_balance < wh_message_rent_exempt {
352
+ let required_deposit = wh_message_rent_exempt - wh_message_balance;
353
+
354
+ let transfer_ix = system_instruction:: transfer (
355
+ accs. payer . key ,
356
+ accs. wh_message . info ( ) . key ,
357
+ required_deposit,
358
+ ) ;
359
+ invoke ( & transfer_ix, ctx. accounts ) ?
360
+ }
361
+
362
+ // Checking the sequence account balance
363
+ let wh_sequence_balance = accs. wh_sequence . info ( ) . lamports ( ) ;
364
+ let wh_sequence_rent_exempt = Rent :: get ( ) ?. minimum_balance ( accs. wh_sequence . data_len ( ) ) ;
365
+
366
+ if wh_sequence_balance < wh_sequence_rent_exempt {
367
+ let required_deposit = wh_sequence_rent_exempt - wh_sequence_balance;
368
+
369
+ let transfer_ix =
370
+ system_instruction:: transfer ( accs. payer . key , accs. wh_sequence . key , required_deposit) ;
371
+ invoke ( & transfer_ix, ctx. accounts ) ?
372
+ }
373
+
335
374
Ok ( ( ) )
336
375
}
0 commit comments