Skip to content

Commit

Permalink
asset: add asset.v1.Metadata.priority_score
Browse files Browse the repository at this point in the history
This is intended to help support clients that need to display lists of assets.
An asset registry can assign rankings to tokens, and frontend software can
consume them without needing to have its own opinions about what the ranking
should be. For instance, a registry could have hardcoded "tiers" or priorities,
or priorities assigned by market cap, or the user's balances, etc.
  • Loading branch information
hdevalence authored and conorsch committed May 24, 2024
1 parent dd849db commit 974dd5d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/core/asset/src/asset/denom_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub(super) struct Inner {
// For now, don't bother with a domain type here,
// since we don't render images from Rust code.
images: Vec<pb::AssetImage>,
priority_score: u64,

/// Sorted by priority order.
pub(super) units: Vec<BareDenomUnit>,
Expand All @@ -64,6 +65,7 @@ impl From<&Inner> for pb::Metadata {
penumbra_asset_id: Some(inner.id.into()),
denom_units: inner.units.clone().into_iter().map(|x| x.into()).collect(),
images: inner.images.clone(),
priority_score: inner.priority_score,
}
}
}
Expand Down Expand Up @@ -129,6 +131,7 @@ impl TryFrom<pb::Metadata> for Inner {
name: value.name,
symbol: value.symbol,
images: value.images,
priority_score: value.priority_score,
})
}
}
Expand Down Expand Up @@ -250,6 +253,7 @@ impl Inner {
name: String::new(),
symbol: String::new(),
images: Vec::new(),
priority_score: 0,
}
}
}
Expand Down Expand Up @@ -416,13 +420,15 @@ impl Debug for Metadata {
display_index,
name,
symbol,
priority_score,
} = inner.as_ref();

f.debug_struct("Metadata")
.field("id", id)
.field("base_denom", base_denom)
.field("description", description)
.field("images", images)
.field("priority_score", priority_score)
.field("units", units)
.field("display_index", display_index)
.field("name", name)
Expand Down
5 changes: 5 additions & 0 deletions crates/proto/src/gen/penumbra.core.asset.v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ pub struct Metadata {
pub penumbra_asset_id: ::core::option::Option<AssetId>,
#[prost(message, repeated, tag = "1985")]
pub images: ::prost::alloc::vec::Vec<AssetImage>,
/// An optional "score" used to prioritize token lists.
///
/// This is solely for use in client-side registries.
#[prost(uint64, tag = "1986")]
pub priority_score: u64,
}
impl ::prost::Name for Metadata {
const NAME: &'static str = "Metadata";
Expand Down
21 changes: 21 additions & 0 deletions crates/proto/src/gen/penumbra.core.asset.v1.serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,9 @@ impl serde::Serialize for Metadata {
if !self.images.is_empty() {
len += 1;
}
if self.priority_score != 0 {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.asset.v1.Metadata", len)?;
if !self.description.is_empty() {
struct_ser.serialize_field("description", &self.description)?;
Expand All @@ -1061,6 +1064,10 @@ impl serde::Serialize for Metadata {
if !self.images.is_empty() {
struct_ser.serialize_field("images", &self.images)?;
}
if self.priority_score != 0 {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("priorityScore", ToString::to_string(&self.priority_score).as_str())?;
}
struct_ser.end()
}
}
Expand All @@ -1081,6 +1088,8 @@ impl<'de> serde::Deserialize<'de> for Metadata {
"penumbra_asset_id",
"penumbraAssetId",
"images",
"priority_score",
"priorityScore",
];

#[allow(clippy::enum_variant_names)]
Expand All @@ -1093,6 +1102,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
Symbol,
PenumbraAssetId,
Images,
PriorityScore,
__SkipField__,
}
impl<'de> serde::Deserialize<'de> for GeneratedField {
Expand Down Expand Up @@ -1123,6 +1133,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
"symbol" => Ok(GeneratedField::Symbol),
"penumbraAssetId" | "penumbra_asset_id" => Ok(GeneratedField::PenumbraAssetId),
"images" => Ok(GeneratedField::Images),
"priorityScore" | "priority_score" => Ok(GeneratedField::PriorityScore),
_ => Ok(GeneratedField::__SkipField__),
}
}
Expand Down Expand Up @@ -1150,6 +1161,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
let mut symbol__ = None;
let mut penumbra_asset_id__ = None;
let mut images__ = None;
let mut priority_score__ = None;
while let Some(k) = map_.next_key()? {
match k {
GeneratedField::Description => {
Expand Down Expand Up @@ -1200,6 +1212,14 @@ impl<'de> serde::Deserialize<'de> for Metadata {
}
images__ = Some(map_.next_value()?);
}
GeneratedField::PriorityScore => {
if priority_score__.is_some() {
return Err(serde::de::Error::duplicate_field("priorityScore"));
}
priority_score__ =
Some(map_.next_value::<::pbjson::private::NumberDeserialize<_>>()?.0)
;
}
GeneratedField::__SkipField__ => {
let _ = map_.next_value::<serde::de::IgnoredAny>()?;
}
Expand All @@ -1214,6 +1234,7 @@ impl<'de> serde::Deserialize<'de> for Metadata {
symbol: symbol__.unwrap_or_default(),
penumbra_asset_id: penumbra_asset_id__,
images: images__.unwrap_or_default(),
priority_score: priority_score__.unwrap_or_default(),
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
5 changes: 5 additions & 0 deletions proto/penumbra/penumbra/core/asset/v1/asset.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ message Metadata {
AssetId penumbra_asset_id = 1984;

repeated AssetImage images = 1985;

// An optional "score" used to prioritize token lists.
//
// This is solely for use in client-side registries.
uint64 priority_score = 1986;
}

// DenomUnit represents a struct that describes a given denomination unit of the basic token.
Expand Down

0 comments on commit 974dd5d

Please sign in to comment.