1- import {
2- Account ,
3- Mint ,
4- Pubkey ,
5- Result ,
6- Signer ,
7- SystemAccount ,
8- SystemProgram ,
9- u8 ,
10- u64 ,
11- UncheckedAccount ,
12- } from "@solanaturbine/poseidon" ;
1+ import { Account , Mint , Pubkey , Result , Signer , SystemAccount , SystemProgram , UncheckedAccount , u8 , u64 } from '@solanaturbine/poseidon' ;
132
143export default class PdaRentPayer {
15- static PROGRAM_ID = new Pubkey (
16- "BYj8GpV9hpv9PAVdwoWFCTMkysJkk5jstYjuCrw4pxem"
17- ) ;
4+ static PROGRAM_ID = new Pubkey ( 'BYj8GpV9hpv9PAVdwoWFCTMkysJkk5jstYjuCrw4pxem' ) ;
185
196 // When lamports are transferred to a new address (without and existing account),
207 // An account owned by the system program is created by default
21- initRentVault (
22- owner : Signer ,
23- vault : RentVault ,
24- state : RentAccountState ,
25- auth : UncheckedAccount ,
26- ) {
8+ initRentVault ( owner : Signer , vault : RentVault , state : RentAccountState , auth : UncheckedAccount ) {
279 //Derive the accounts with bump and seeds
28- vault . derive ( [ " vault" , auth . key ] ) . init ( ) ;
29- state . derive ( [ " state" , owner . key ] ) . init ( )
30- auth . derive ( [ " auth" , state . key ] ) ;
10+ vault . derive ( [ ' vault' , auth . key ] ) . init ( ) ;
11+ state . derive ( [ ' state' , owner . key ] ) . init ( ) ;
12+ auth . derive ( [ ' auth' , state . key ] ) ;
3113
3214 state . owner = owner . key ;
3315
@@ -37,24 +19,17 @@ export default class PdaRentPayer {
3719 state . vaultBump = vault . getBump ( ) ;
3820 }
3921
40-
41- depositToRentVault (
42- owner : Signer ,
43- state : RentAccountState ,
44- auth : UncheckedAccount ,
45- vault : RentVault ,
46- amount : u64
47- ) {
22+ depositToRentVault ( owner : Signer , state : RentAccountState , auth : UncheckedAccount , vault : RentVault , amount : u64 ) {
4823 //Since we have stored bumps in the RentAccountState we can derive PDAs with stored bumps by passing that as the second argument
49- state . deriveWithBump ( [ " state" , owner . key ] , state . stateBump ) ;
50- auth . deriveWithBump ( [ " auth" , state . key ] , state . authBump ) ;
51- vault . deriveWithBump ( [ " vault" , auth . key ] , state . vaultBump ) ;
24+ state . deriveWithBump ( [ ' state' , owner . key ] , state . stateBump ) ;
25+ auth . deriveWithBump ( [ ' auth' , state . key ] , state . authBump ) ;
26+ vault . deriveWithBump ( [ ' vault' , auth . key ] , state . vaultBump ) ;
5227
5328 // Transfer specified lamports from owner to the rent vault
5429 SystemProgram . transfer (
5530 owner , //from
5631 vault , //to
57- amount //amount to be sent
32+ amount , //amount to be sent
5833 ) ;
5934 }
6035
@@ -65,23 +40,20 @@ export default class PdaRentPayer {
6540 auth : UncheckedAccount ,
6641 vault : SystemAccount ,
6742 new_account_state : NewAccountState ,
68- amount : u64
43+ amount : u64 ,
6944 ) : Result {
70- new_account_state . derive ( [ " new_account" , owner . key ] ) . init ( ) ;
45+ new_account_state . derive ( [ ' new_account' , owner . key ] ) . init ( ) ;
7146
72- state . deriveWithBump ( [ " state" , owner . key ] , state . stateBump ) ;
73- auth . deriveWithBump ( [ " auth" , state . key ] , state . authBump ) ;
74- vault . deriveWithBump ( [ " vault" , auth . key ] , state . vaultBump ) ;
47+ state . deriveWithBump ( [ ' state' , owner . key ] , state . stateBump ) ;
48+ auth . deriveWithBump ( [ ' auth' , state . key ] , state . authBump ) ;
49+ vault . deriveWithBump ( [ ' vault' , auth . key ] , state . vaultBump ) ;
7550
7651 // state.newAccountBump = new_account.getBump(); // we don't need the new_account bump
7752
7853 new_account_state . owner = owner . key ;
7954
8055 // We now transfer the lamports from the rent_vault to the new account
81- SystemProgram . transfer ( vault , new_account_state , amount , [
82- "vault" ,
83- auth . key ,
84- ] ) ;
56+ SystemProgram . transfer ( vault , new_account_state , amount , [ 'vault' , auth . key ] ) ;
8557 }
8658}
8759
@@ -96,6 +68,6 @@ export interface RentAccountState extends Account {
9668export interface RentVault extends Account { }
9769
9870export interface NewAccountState extends Account {
99- owner :Pubkey ,
71+ owner : Pubkey ;
10072 newAccountBump : u8 ; // Bump for the newly created account
10173}
0 commit comments