Skip to content

Commit e0c9b5b

Browse files
committed
Support for latest penumbra
1 parent 87d0868 commit e0c9b5b

File tree

3 files changed

+25
-46
lines changed

3 files changed

+25
-46
lines changed

.cargo/config config.toml

File renamed without changes.

src/opt/serve.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,12 @@ use directories::ProjectDirs;
55
use futures::TryStreamExt;
66
use penumbra_custody::soft_kms::SoftKms;
77
use penumbra_proto::{
8-
custody::v1alpha1::{
9-
custody_protocol_service_client::CustodyProtocolServiceClient,
10-
custody_protocol_service_server::CustodyProtocolServiceServer,
11-
},
12-
view::v1alpha1::{
13-
view_protocol_service_client::ViewProtocolServiceClient,
14-
view_protocol_service_server::ViewProtocolServiceServer,
8+
custody::v1::{
9+
custody_service_client::CustodyServiceClient, custody_service_server::CustodyServiceServer,
1510
},
11+
view::v1::{view_service_client::ViewServiceClient, view_service_server::ViewServiceServer},
1612
};
17-
use penumbra_view::{ViewClient, ViewService};
13+
use penumbra_view::{ViewClient, ViewServer};
1814
use std::path::PathBuf;
1915
use url::Url;
2016

@@ -102,8 +98,7 @@ impl Serve {
10298
let wallet =
10399
Wallet::load(custody_file).context("Failed to load wallet from local custody file")?;
104100
let soft_kms = SoftKms::new(wallet.spend_key.clone().into());
105-
let custody =
106-
CustodyProtocolServiceClient::new(CustodyProtocolServiceServer::new(soft_kms));
101+
let custody = CustodyServiceClient::new(CustodyServiceServer::new(soft_kms));
107102

108103
let fvk = wallet.spend_key.full_viewing_key().clone();
109104

@@ -113,11 +108,12 @@ impl Serve {
113108
let view_storage =
114109
penumbra_view::Storage::load_or_initialize(None::<&str>, &fvk, self.node.clone())
115110
.await?;
116-
let view_service = ViewService::new(view_storage, self.node.clone()).await?;
111+
117112
// Now build the view and custody clients, doing gRPC with ourselves
118-
let mut view = ViewProtocolServiceClient::new(ViewProtocolServiceServer::new(view_service));
113+
let view_server = ViewServer::new(view_storage, self.node.clone()).await?;
114+
let mut view = ViewServiceClient::new(ViewServiceServer::new(view_server));
119115

120-
ViewClient::status_stream(&mut view, fvk.wallet_id())
116+
ViewClient::status_stream(&mut view)
121117
.await?
122118
.try_collect::<Vec<_>>()
123119
.await?;

src/trader.rs

+16-33
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{collections::BTreeMap, future, str::FromStr};
33
use anyhow::Context;
44
use binance::model::BookTickerEvent;
55
use futures::{StreamExt, TryStreamExt};
6-
use penumbra_asset::asset::DenomMetadata;
6+
use penumbra_asset::asset::Metadata;
77
use penumbra_custody::{AuthorizeRequest, CustodyClient};
88
use penumbra_dex::{
99
lp::{
@@ -12,11 +12,10 @@ use penumbra_dex::{
1212
},
1313
DirectedUnitPair,
1414
};
15-
use penumbra_fee::Fee;
1615
use penumbra_keys::keys::{AddressIndex, FullViewingKey};
1716
use penumbra_num::Amount;
18-
use penumbra_proto::core::component::dex::v1alpha1::query_service_client::QueryServiceClient as DexQueryServiceClient;
19-
use penumbra_proto::core::component::dex::v1alpha1::{
17+
use penumbra_proto::core::component::dex::v1::query_service_client::QueryServiceClient as DexQueryServiceClient;
18+
use penumbra_proto::core::component::dex::v1::{
2019
LiquidityPositionsByPriceRequest, LiquidityPositionsRequest,
2120
};
2221
use penumbra_view::{Planner, ViewClient};
@@ -147,11 +146,7 @@ where
147146
tracing::debug!("trader received event: {:?}", book_ticker_event);
148147

149148
// Only update positions for a given symbol at most once per block
150-
let current_height = self
151-
.view
152-
.status(self.fvk.wallet_id())
153-
.await?
154-
.partial_sync_height;
149+
let current_height = self.view.status().await?.partial_sync_height;
155150
if let Some(last_updated_height) = self.last_updated_height.get(symbol) {
156151
if current_height <= *last_updated_height {
157152
tracing::debug!(?symbol, "skipping symbol, already updated this block");
@@ -258,18 +253,15 @@ where
258253
}
259254

260255
async fn finalize_and_submit(&mut self, planner: &mut Planner<OsRng>) -> anyhow::Result<()> {
261-
// Pay no fee for the transaction.
262-
let fee = Fee::from_staking_token_amount(0u32.into());
263-
264256
// Sometimes building the plan can fail with an error, because there were no actions
265257
// present. There's not an easy way to check this in the planner API right now.
258+
259+
// Fetch latest gas prices.
260+
let gas_prices = self.view.gas_prices().await?;
261+
262+
planner.set_gas_prices(gas_prices);
266263
let plan = planner
267-
.fee(fee)
268-
.plan(
269-
&mut self.view,
270-
self.fvk.wallet_id(),
271-
AddressIndex::from(self.account),
272-
)
264+
.plan(&mut self.view, AddressIndex::from(self.account))
273265
.await?;
274266

275267
// 2. Authorize and build the transaction.
@@ -283,7 +275,7 @@ where
283275
.data
284276
.ok_or_else(|| anyhow::anyhow!("no auth data"))?
285277
.try_into()?;
286-
let witness_data = self.view.witness(self.fvk.wallet_id(), &plan).await?;
278+
let witness_data = self.view.witness(&plan).await?;
287279
let tx = plan
288280
.build_concurrent(&self.fvk, &witness_data, &auth_data)
289281
.await?;
@@ -410,12 +402,9 @@ where
410402
market: &DirectedUnitPair,
411403
) -> anyhow::Result<Vec<Position>> {
412404
// We need to use the list of our notes to determine which positions we own.
413-
let notes = self
414-
.view
415-
.unspent_notes_by_address_and_asset(self.fvk.wallet_id())
416-
.await?;
405+
let notes = self.view.unspent_notes_by_address_and_asset().await?;
417406

418-
fn is_closed_position_nft(denom: &DenomMetadata) -> bool {
407+
fn is_closed_position_nft(denom: &Metadata) -> bool {
419408
let prefix = "lpnft_closed_".to_string();
420409

421410
denom.starts_with(&prefix)
@@ -476,12 +465,9 @@ where
476465
market: &DirectedUnitPair,
477466
) -> anyhow::Result<Vec<Position>> {
478467
// We need to use the list of our notes to determine which positions we own.
479-
let notes = self
480-
.view
481-
.unspent_notes_by_address_and_asset(self.fvk.wallet_id())
482-
.await?;
468+
let notes = self.view.unspent_notes_by_address_and_asset().await?;
483469

484-
fn is_opened_position_nft(denom: &DenomMetadata) -> bool {
470+
fn is_opened_position_nft(denom: &Metadata) -> bool {
485471
let prefix = "lpnft_opened_".to_string();
486472

487473
denom.starts_with(&prefix)
@@ -659,10 +645,7 @@ where
659645
// We could do this outside of the loop, but checking here
660646
// assures we have the latest data, and the in-memory gRPC interface
661647
// should be fast.
662-
let notes = self
663-
.view
664-
.unspent_notes_by_address_and_asset(self.fvk.wallet_id())
665-
.await?;
648+
let notes = self.view.unspent_notes_by_address_and_asset().await?;
666649

667650
let (mut reserves_1, mut reserves_2) = (Amount::from(0u32), Amount::from(0u32));
668651

0 commit comments

Comments
 (0)