Skip to content

Commit c9fc594

Browse files
author
thegreat-vanderlinde
authored
Merge pull request #37 from vyper-protocol/feat/otc
Added method to fetch the otc state
2 parents e29360c + f928422 commit c9fc594

8 files changed

Lines changed: 208 additions & 21 deletions

File tree

Cargo.lock

Lines changed: 64 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ borsh = "0.9.3"
1414
vyper-core = { git = "https://github.com/vyper-protocol/vyper-core", branch = "dev", features = ["no-entrypoint"] }
1515
redeem-logic-forward = { git = "https://github.com/vyper-protocol/vyper-core", branch = "dev", features = ["no-entrypoint"] }
1616
rate-switchboard = { git = "https://github.com/vyper-protocol/vyper-core", branch = "dev", features = ["no-entrypoint"] }
17+
vyper-otc = { git = "https://github.com/vyper-protocol/vyper-otc", branch = "dev", features = ["no-entrypoint"] }
1718
console = "0.15.1"
1819
rust_decimal = "1.26"
19-
rust_decimal_macros = "1.26"
20+
rust_decimal_macros = "1.26"
21+
chrono = "0.4.23"

src/args.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pub mod core_args;
22
pub mod config_args;
33
pub mod redeem_logic_plugin_args;
44
pub mod rate_plugin_args;
5+
pub mod otc_args;
56
use {
67
core_args::CoreCommand,
78
config_args::ConfigOptions,
@@ -12,7 +13,8 @@ use {
1213
clap::{
1314
Parser,
1415
Subcommand
15-
}
16+
},
17+
otc_args::OtcCommand
1618
};
1719

1820

@@ -36,6 +38,8 @@ pub enum Vyper {
3638
/// Used to access redeem logic forward commands
3739
RedeemLogicForward(RedeemLogicForwardCommand),
3840
/// Used to access rate-switchboard plugin
39-
RateSwitchboard(RateSwitchboardCommand)
41+
RateSwitchboard(RateSwitchboardCommand),
42+
/// Used to access the vyper otc commands
43+
Otc(OtcCommand)
4044
}
4145

src/args/otc_args.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
use {
2+
clap::{
3+
Args,
4+
Subcommand
5+
},
6+
anchor_client:: {
7+
solana_sdk::{
8+
pubkey::Pubkey
9+
}
10+
}
11+
};
12+
13+
14+
15+
#[derive(Debug, Args)]
16+
pub struct OtcCommand {
17+
#[clap(subcommand)]
18+
pub command : OtcSubcommand
19+
}
20+
21+
#[derive(Debug, Subcommand)]
22+
pub enum OtcSubcommand {
23+
/// Gets the configuration of otc from given public key.
24+
Fetch(FetchOtc),
25+
}
26+
27+
#[derive(Debug, Args)]
28+
pub struct FetchOtc {
29+
/// Public key of otc state.
30+
pub state_id: Pubkey
31+
}

src/main.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use {
1414
ops::rate_plugin_ops::{
1515
rate_switchboard_ops::handle_rate_switchboard_command
1616
},
17+
ops::otc_ops::handle_otc_command,
1718
anchor_client::{
1819
Client,
1920
Cluster,
@@ -34,6 +35,7 @@ use {
3435
const VYPER_CORE_ID: &str = "vyPErCcGJKQQBeeQ59gXcWrDyU4vBrq8qQfacwmsAsp";
3536
const REDEEM_LOGIC_FORWARD: &str = "BrpV1re8MshA8qskKVxcEG8zXG3vf2uLX6myeTKAyhsK";
3637
const RATE_SWITCHBOARD: &str = "2hGXiH1oEQwjCXRx8bNdHTi49ScZp7Mj2bxcjxtULKe1";
38+
const OTC: &str = "8aHSkExY28qCvg4gnTLU7y1Ev6HnpJ1NxuWb9XtEesVt";
3739

3840
fn main() {
3941

@@ -102,5 +104,12 @@ fn main() {
102104
// command handler
103105
handle_rate_switchboard_command(rate_switchboard_command, &rate_switchboard_program);
104106
}
107+
Vyper::Otc(otc_command) => {
108+
// otc program
109+
let otc_program_id: Pubkey = Pubkey::new(&bs58::decode(&OTC).into_vec().expect("Invalid otc program id"));
110+
let otc_program = client.program(otc_program_id);
111+
// command handler
112+
handle_otc_command(otc_command, &otc_program);
113+
}
105114
}
106115
}

src/ops.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod core_ops;
22
pub mod redeem_logic_plugin_ops;
3-
pub mod rate_plugin_ops;
3+
pub mod rate_plugin_ops;
4+
pub mod otc_ops;

src/ops/otc_ops.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
}

src/utils.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use anchor_client::solana_sdk::{
1313

1414
use std::process::exit;
1515
use solana_cli_config::{CONFIG_FILE, Config};
16+
use chrono::prelude::*;
1617

1718

1819

@@ -108,3 +109,30 @@ pub fn println_switchboard_aggregators(name: &str, aggregators: &[Option<Pubkey>
108109
println!("]")
109110
}
110111

112+
pub fn println_date(name: &str, timestamp: &i64) {
113+
let naive = NaiveDateTime::from_timestamp_opt(*timestamp, 0).unwrap();
114+
let datetime: DateTime<Utc> = DateTime::from_utc(naive, Utc);
115+
let newdate = datetime.format("%Y-%m-%d %H:%M").to_string();
116+
println!(
117+
"{} : {:?} ",
118+
style(name).bold(),
119+
style(newdate),
120+
);
121+
}
122+
123+
pub fn println_beneficiary_value(name: &str, value: &Option<Pubkey>) {
124+
if !value.is_none() {
125+
println!(
126+
"{} : {:?} ",
127+
style(name).bold(),
128+
style(value.unwrap()),
129+
);
130+
} else {
131+
println!(
132+
"{} : {:?} ",
133+
style(name).bold(),
134+
style("None"),
135+
);
136+
}
137+
}
138+

0 commit comments

Comments
 (0)