Skip to content

Commit ee919cf

Browse files
committed
Use new custody format
1 parent e0c9b5b commit ee919cf

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

Cargo.toml

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ rand = "0.8"
3636
reqwest = "0.11"
3737
indexmap = "1.8"
3838
chrono = { version = "0.4", features = ["serde"] }
39+
toml = "0.7"
3940
tonic = { version = "0.10", features = ["tls-webpki-roots", "tls"] }
4041
serde = { version = "1", features = ["derive"] }
41-
# The commit `17ba6f3cedec7f5908e4cc2b3c39f61a778df2ec` from 2023-12-03 broke compilation,
42-
# so we pin the prior git revision.
43-
# binance = { git = "https://github.com/wisespace-io/binance-rs.git", rev = "17ba6f3cedec7f5908e4cc2b3c39f61a778df2ec" }
44-
binance = { git = "https://github.com/wisespace-io/binance-rs.git", rev = "3017e136cc4439c9b6a67fdccb76a7c3a94f8440" }
42+
binance = { git = "https://github.com/wisespace-io/binance-rs.git", rev = "04a78c9272062a84029a612f3c9e8a5845480a4a" }
4543
url = "2"

src/binance_fetcher.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ impl BinanceFetcher {
3737

3838
/// Run the fetcher.
3939
pub async fn run(mut self) -> anyhow::Result<()> {
40+
tracing::info!("starting binance fetcher");
4041
let _fetcher_span = tracing::debug_span!("binance-fetcher").entered();
4142
let keep_running = AtomicBool::new(true); // Used to control the event loop
4243
let endpoints = self

src/opt/serve.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Serve {
5050
.iter()
5151
.flat_map(|s1| self.symbols.iter().map(move |s2| (s1, s2)))
5252
.filter(|(s1, s2)| s1 != s2)
53-
.map(|(s1, s2)| format!("{}{}", s1, s2))
53+
.map(|(s1, s2)| format!("{}{}", s2, s1))
5454
.collect::<Vec<_>>();
5555

5656
let mut symbols = Vec::new();
@@ -92,11 +92,10 @@ impl Serve {
9292
});
9393
std::fs::create_dir_all(&data_dir).context("can create data dir")?;
9494

95-
let custody_file = data_dir.clone().join("custody.json");
96-
9795
// Build a custody service...
98-
let wallet =
99-
Wallet::load(custody_file).context("Failed to load wallet from local custody file")?;
96+
let pcli_config_file = data_dir.clone().join("config.toml");
97+
let wallet = Wallet::load(pcli_config_file)
98+
.context("failed to load wallet from local custody file")?;
10099
let soft_kms = SoftKms::new(wallet.spend_key.clone().into());
101100
let custody = CustodyServiceClient::new(CustodyServiceServer::new(soft_kms));
102101

@@ -105,8 +104,15 @@ impl Serve {
105104
// Wait to synchronize the chain before doing anything else.
106105
tracing::info!(%self.node, "starting initial sync: ");
107106
// Instantiate an in-memory view service.
107+
let view_file = data_dir.join("pcli-view.sqlite");
108+
let view_filepath = Some(
109+
view_file
110+
.to_str()
111+
.ok_or_else(|| anyhow::anyhow!("Non-UTF8 view path"))?
112+
.to_string(),
113+
);
108114
let view_storage =
109-
penumbra_view::Storage::load_or_initialize(None::<&str>, &fvk, self.node.clone())
115+
penumbra_view::Storage::load_or_initialize(view_filepath, &fvk, self.node.clone())
110116
.await?;
111117

112118
// Now build the view and custody clients, doing gRPC with ourselves

src/trader.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,32 @@ lazy_static! {
3737
(
3838
// ETH priced in terms of BTC
3939
"ETHBTC".to_string(),
40-
DirectedUnitPair::from_str("test_btc:test_eth").unwrap()
40+
DirectedUnitPair::from_str("test_eth:test_btc").unwrap()
4141
),
4242
(
43-
// ETH priced in terms of USD
44-
"ETHUSD".to_string(),
45-
DirectedUnitPair::from_str("test_usd:test_eth").unwrap()
43+
// ETH priced in terms of USDT
44+
"ETHUSDT".to_string(),
45+
DirectedUnitPair::from_str("test_eth:test_usd").unwrap()
4646
),
4747
(
4848
// BTC priced in terms of USD
49-
"BTCUSD".to_string(),
50-
DirectedUnitPair::from_str("test_usd:test_btc").unwrap()
49+
"BTCUSDT".to_string(),
50+
DirectedUnitPair::from_str("test_btc:test_usd").unwrap()
5151
),
5252
(
5353
// ATOM priced in terms of BTC
5454
"ATOMBTC".to_string(),
55-
DirectedUnitPair::from_str("test_btc:test_atom").unwrap()
55+
DirectedUnitPair::from_str("test_atom:test_btc").unwrap()
5656
),
5757
(
58-
// ATOM priced in terms of USD
59-
"ATOMUSD".to_string(),
60-
DirectedUnitPair::from_str("test_usd:test_atom").unwrap()
58+
// ATOM priced in terms of USDT
59+
"ATOMUSDT".to_string(),
60+
DirectedUnitPair::from_str("test_atom:test_usd").unwrap()
61+
),
62+
(
63+
// OSMO priced in terms of USDT
64+
"OSMOUSDT".to_string(),
65+
DirectedUnitPair::from_str("test_osmo:test_usd").unwrap()
6166
),
6267
]);
6368
}
@@ -122,6 +127,7 @@ where
122127

123128
/// Run the trader.
124129
pub async fn run(mut self) -> anyhow::Result<()> {
130+
tracing::info!("starting trader");
125131
let trader_span = tracing::debug_span!("trader");
126132
// TODO figure out why this span doesn't display in logs
127133
let _ = trader_span.enter();
@@ -312,6 +318,13 @@ where
312318
quote: BookTickerEvent,
313319
plan: &mut Planner<OsRng>,
314320
) -> anyhow::Result<()> {
321+
tracing::debug!(
322+
?market,
323+
?reserves_1,
324+
?reserves_2,
325+
?quote,
326+
"opening liquidity position"
327+
);
315328
// put up half the available reserves
316329
// TODO: this isn't quite right as it's half the _remaining_ reserves
317330
// and there might be multiple positions involving reserves with the same

src/wallet.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ pub struct Wallet {
1212
impl Wallet {
1313
/// Read the wallet data from the provided path.
1414
pub fn load(path: impl AsRef<std::path::Path>) -> anyhow::Result<Self> {
15-
let custody_json: serde_json::Value =
16-
serde_json::from_slice(std::fs::read(path)?.as_slice())?;
17-
let sk_str = match custody_json["spend_key"].as_str() {
15+
let config_contents = std::fs::read_to_string(&path).context(
16+
"pcli config file not found. hint: run 'pcli init soft-kms import-phrase' to import key material",
17+
)?;
18+
let config_toml: toml::Table = toml::from_str(&config_contents)?;
19+
20+
let sk_str = match config_toml["custody"]["spend_key"].as_str() {
1821
Some(s) => s,
1922
None => {
2023
return Err(anyhow::anyhow!(
21-
"'spend_key' field not found in custody JSON file"
24+
"'spend_key' field not found in custody TOML file"
2225
))
2326
}
2427
};

0 commit comments

Comments
 (0)