@@ -11,14 +11,25 @@ use {
1111 base64:: Engine ,
1212 integration_tests:: {
1313 integrity_pool:: pda:: {
14+ get_delegation_record_address,
1415 get_pool_config_address,
1516 get_pool_reward_custody_address,
17+ get_slash_event_address,
18+ } ,
19+ staking:: pda:: {
20+ get_config_address,
21+ get_stake_account_custody_address,
22+ get_stake_account_custody_authority_address,
23+ get_stake_account_metadata_address,
24+ get_target_address,
1625 } ,
17- staking:: pda:: get_config_address,
1826 } ,
19- integrity_pool:: state:: pool:: {
20- PoolConfig ,
21- PoolData ,
27+ integrity_pool:: state:: {
28+ delegation_record:: DelegationRecord ,
29+ pool:: {
30+ PoolConfig ,
31+ PoolData ,
32+ } ,
2233 } ,
2334 publisher_caps:: PublisherCaps ,
2435 pythnet_sdk:: wire:: v1:: {
5061 std:: {
5162 cmp:: min,
5263 convert:: TryInto ,
64+ mem:: size_of,
5365 } ,
5466 wormhole_core_bridge_solana:: sdk:: {
5567 WriteEncodedVaaArgs ,
@@ -487,3 +499,210 @@ pub fn update_delegation_fee(rpc_client: &RpcClient, payer: &Keypair, delegation
487499
488500 process_transaction ( rpc_client, & [ instruction] , & [ payer] ) ;
489501}
502+
503+ pub fn set_publisher_stake_account (
504+ rpc_client : & RpcClient ,
505+ signer : & Keypair ,
506+ publisher : & Pubkey ,
507+ stake_account_positions : & Pubkey ,
508+ ) {
509+ let pool_config = get_pool_config_address ( ) ;
510+
511+ let PoolConfig { pool_data, .. } = PoolConfig :: try_deserialize (
512+ & mut rpc_client
513+ . get_account_data ( & pool_config)
514+ . unwrap ( )
515+ . as_slice ( ) ,
516+ )
517+ . unwrap ( ) ;
518+
519+ let accounts = integrity_pool:: accounts:: SetPublisherStakeAccount {
520+ signer : signer. pubkey ( ) ,
521+ publisher : * publisher,
522+ current_stake_account_positions_option : None ,
523+ new_stake_account_positions_option : Some ( * stake_account_positions) ,
524+ pool_config,
525+ pool_data,
526+ } ;
527+
528+ let instruction_data = integrity_pool:: instruction:: SetPublisherStakeAccount { } ;
529+
530+ let instruction = Instruction {
531+ program_id : integrity_pool:: ID ,
532+ accounts : accounts. to_account_metas ( None ) ,
533+ data : instruction_data. data ( ) ,
534+ } ;
535+
536+ process_transaction ( rpc_client, & [ instruction] , & [ signer] ) ;
537+ }
538+
539+ pub fn create_slash_event (
540+ rpc_client : & RpcClient ,
541+ signer : & Keypair ,
542+ publisher : & Pubkey ,
543+ slash_ratio : u64 ,
544+ ) {
545+ let pool_config = get_pool_config_address ( ) ;
546+
547+ let PoolConfig {
548+ pool_data : pool_data_address,
549+ slash_custody,
550+ ..
551+ } = PoolConfig :: try_deserialize (
552+ & mut rpc_client
553+ . get_account_data ( & pool_config)
554+ . unwrap ( )
555+ . as_slice ( ) ,
556+ )
557+ . unwrap ( ) ;
558+
559+ let pool_data = PoolData :: try_deserialize (
560+ & mut rpc_client. get_account_data ( & pool_data_address) . unwrap ( ) [ ..8 + size_of :: < PoolData > ( ) ]
561+ . as_ref ( ) ,
562+ )
563+ . unwrap ( ) ;
564+
565+ let publisher_index = pool_data. get_publisher_index ( publisher) . unwrap ( ) ;
566+ let index = pool_data. num_slash_events [ publisher_index] ;
567+
568+ let accounts = integrity_pool:: accounts:: CreateSlashEvent {
569+ payer : signer. pubkey ( ) ,
570+ reward_program_authority : signer. pubkey ( ) ,
571+ publisher : * publisher,
572+ slash_custody,
573+ pool_config,
574+ pool_data : pool_data_address,
575+ slash_event : get_slash_event_address ( index, * publisher) ,
576+ system_program : system_program:: ID ,
577+ } ;
578+
579+ let instruction_data = integrity_pool:: instruction:: CreateSlashEvent { index, slash_ratio } ;
580+
581+ let instruction = Instruction {
582+ program_id : integrity_pool:: ID ,
583+ accounts : accounts. to_account_metas ( None ) ,
584+ data : instruction_data. data ( ) ,
585+ } ;
586+
587+ process_transaction ( rpc_client, & [ instruction] , & [ signer] ) ;
588+ }
589+
590+ pub fn update_reward_program_authority (
591+ rpc_client : & RpcClient ,
592+ signer : & Keypair ,
593+ new_reward_program_authority : & Pubkey ,
594+ ) {
595+ let pool_config = get_pool_config_address ( ) ;
596+
597+ let accounts = integrity_pool:: accounts:: UpdateRewardProgramAuthority {
598+ reward_program_authority : signer. pubkey ( ) ,
599+ pool_config,
600+ system_program : system_program:: ID ,
601+ } ;
602+
603+ let instruction_data = integrity_pool:: instruction:: UpdateRewardProgramAuthority {
604+ reward_program_authority : * new_reward_program_authority,
605+ } ;
606+
607+ let instruction = Instruction {
608+ program_id : integrity_pool:: ID ,
609+ accounts : accounts. to_account_metas ( None ) ,
610+ data : instruction_data. data ( ) ,
611+ } ;
612+
613+ process_transaction ( rpc_client, & [ instruction] , & [ signer] ) ;
614+ }
615+
616+ pub fn slash (
617+ rpc_client : & RpcClient ,
618+ signer : & Keypair ,
619+ publisher : & Pubkey ,
620+ stake_account_positions : & Pubkey ,
621+ ) {
622+ let pool_config = get_pool_config_address ( ) ;
623+ let PoolConfig {
624+ pool_data,
625+ slash_custody,
626+ ..
627+ } = PoolConfig :: try_deserialize (
628+ & mut rpc_client
629+ . get_account_data ( & pool_config)
630+ . unwrap ( )
631+ . as_slice ( ) ,
632+ )
633+ . unwrap ( ) ;
634+
635+ let delegation_record = get_delegation_record_address ( * publisher, * stake_account_positions) ;
636+ let DelegationRecord {
637+ next_slash_event_index,
638+ ..
639+ } = {
640+ let delegation_record_account_data = rpc_client. get_account_data ( & delegation_record) ;
641+ if let Ok ( data) = delegation_record_account_data {
642+ DelegationRecord :: try_deserialize ( & mut data. as_slice ( ) ) . unwrap ( )
643+ } else {
644+ DelegationRecord {
645+ last_epoch : 0 ,
646+ next_slash_event_index : 0 ,
647+ }
648+ }
649+ } ;
650+
651+
652+ let stake_account_metadata = get_stake_account_metadata_address ( * stake_account_positions) ;
653+ let stake_account_custody = get_stake_account_custody_address ( * stake_account_positions) ;
654+ let custody_authority = get_stake_account_custody_authority_address ( * stake_account_positions) ;
655+ let config_account = get_config_address ( ) ;
656+ let governance_target_account = get_target_address ( ) ;
657+
658+
659+ let accounts = integrity_pool:: accounts:: Slash {
660+ signer : signer. pubkey ( ) ,
661+ pool_data,
662+ pool_config,
663+ slash_event : get_slash_event_address ( next_slash_event_index, * publisher) ,
664+ delegation_record,
665+ publisher : * publisher,
666+ stake_account_positions : * stake_account_positions,
667+ stake_account_metadata,
668+ stake_account_custody,
669+ config_account,
670+ governance_target_account,
671+ slash_custody,
672+ custody_authority,
673+ staking_program : staking:: ID ,
674+ token_program : spl_token:: ID ,
675+ } ;
676+
677+ let instruction_data = integrity_pool:: instruction:: Slash {
678+ index : next_slash_event_index,
679+ } ;
680+
681+ let instruction = Instruction {
682+ program_id : integrity_pool:: ID ,
683+ accounts : accounts. to_account_metas ( None ) ,
684+ data : instruction_data. data ( ) ,
685+ } ;
686+
687+ process_transaction ( rpc_client, & [ instruction] , & [ signer] ) ;
688+ }
689+
690+ pub fn update_y ( rpc_client : & RpcClient , signer : & Keypair , y : u64 ) {
691+ let pool_config = get_pool_config_address ( ) ;
692+
693+ let accounts = integrity_pool:: accounts:: UpdateY {
694+ reward_program_authority : signer. pubkey ( ) ,
695+ pool_config,
696+ system_program : system_program:: ID ,
697+ } ;
698+
699+ let instruction_data = integrity_pool:: instruction:: UpdateY { y } ;
700+
701+ let instruction = Instruction {
702+ program_id : integrity_pool:: ID ,
703+ accounts : accounts. to_account_metas ( None ) ,
704+ data : instruction_data. data ( ) ,
705+ } ;
706+
707+ process_transaction ( rpc_client, & [ instruction] , & [ signer] ) ;
708+ }
0 commit comments