1+ use {
2+ std:: process:: exit,
3+ crate :: args:: otc_args,
4+ crate :: utils:: {
5+ println_name_value,
6+ println_version,
7+ println_error,
8+ println_date,
9+ println_beneficiary_value
10+ } ,
11+ otc_args:: {
12+ OtcCommand ,
13+ OtcSubcommand
14+ } ,
15+ anchor_client:: {
16+ Program ,
17+ ClientError
18+ } ,
19+ vyper_otc:: state:: OtcState ,
20+ console:: style
21+ } ;
22+
23+
24+
25+ pub fn handle_otc_command ( otc_command : OtcCommand , program : & Program ) {
26+ let command = otc_command. command ;
27+ match command {
28+ OtcSubcommand :: Fetch ( fetch_otc) => {
29+ let account: Result < OtcState , ClientError > = program. account ( fetch_otc. state_id ) ;
30+ let account = match account {
31+ Ok ( otc_state) => otc_state,
32+ Err ( err) => {
33+ match err {
34+ ClientError :: AccountNotFound => println_error ( "Could not otc state with given public key" ) ,
35+ ClientError :: AnchorError ( err) => println ! ( "{} : {}" , style( "error" ) . red( ) . bold( ) , err) ,
36+ ClientError :: ProgramError ( err) => println ! ( "{} : {}" , style( "error" ) . red( ) . bold( ) , err) ,
37+ ClientError :: SolanaClientError ( err) => println ! ( "{} : {}" , style( "error" ) . red( ) . bold( ) , err) ,
38+ ClientError :: SolanaClientPubsubError ( err) => println ! ( "{} : {}" , style( "error" ) . red( ) . bold( ) , err) ,
39+ ClientError :: LogParseError ( err) => println_error ( & err)
40+ }
41+ exit ( 1 ) ;
42+ }
43+ } ;
44+ println_date ( "created" , & account. created ) ;
45+ println_date ( "deposit start" , & account. deposit_start ) ;
46+ println_date ( "deposit end" , & account. deposit_end ) ;
47+ println_date ( "settle start" , & account. settle_start ) ;
48+ println_name_value ( "settle executed" , & account. settle_executed ) ;
49+ println_name_value ( "junior deposit amount" , & account. junior_deposit_amount ) ;
50+ println_name_value ( "senior deposit amount" , & account. senior_deposit_amount ) ;
51+ println_beneficiary_value ( "junior side beneficiary" , & account. junior_side_beneficiary ) ;
52+ println_beneficiary_value ( "senior side beneficiary" , & account. senior_side_beneficiary ) ;
53+ println_name_value ( "vyper tranche config" , & account. vyper_tranche_config ) ;
54+ println_name_value ( "vyper core" , & account. vyper_core ) ;
55+ println_name_value ( "senior reserve token account" , & account. otc_senior_reserve_token_account ) ;
56+ println_name_value ( "junior reserve token account" , & account. otc_junior_reserve_token_account ) ;
57+ println_name_value ( "senior tranche token account" , & account. otc_senior_tranche_token_account ) ;
58+ println_name_value ( "junior tranche token account" , & account. otc_junior_tranche_token_account ) ;
59+ println_name_value ( "otc authority" , & account. otc_authority ) ;
60+ println_name_value ( "authority seed" , & account. authority_seed ) ;
61+ println_name_value ( "authority bump" , & account. authority_bump ) ;
62+ println_version ( "version" , & account. version ) ;
63+ }
64+ }
65+ }
0 commit comments