Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presto KYC #1309

Merged
merged 11 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions common/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ pub const ASSET_ID_PREFIX_KENSETSU_PEGGED_TO_SORA: u8 = 4;
/// Kensetsu asset ids pegged to oracle start with 0x05...
pub const ASSET_ID_PREFIX_KENSETSU_PEGGED_TO_ORACLE: u8 = 5;

/// Predefined SBT asset ids start with 0x06...
pub const ASSET_ID_PREFIX_SBT_PREDEFINED: u8 = 6;

/// Wrapper type which extends Balance serialization, used for json in RPC's.
#[derive(Encode, Decode, Debug, Clone, PartialEq, Eq, scale_info::TypeInfo)]
pub struct BalanceWrapper(pub Balance);
Expand Down Expand Up @@ -270,6 +273,41 @@ impl Default for PredefinedAssetId {
}
}

/// Predefined SBT asset identifier.
#[derive(
Encode,
Decode,
Eq,
PartialEq,
Copy,
Clone,
PartialOrd,
Ord,
RuntimeDebug,
scale_info::TypeInfo,
MaxEncodedLen,
)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Hash))]
#[repr(u8)]
pub enum PredefinedSbtAssetId {
PRACS = 0,
PRINVST = 1,
PRCRDT = 2,
}

pub const SBT_PRACS: AssetId32<PredefinedSbtAssetId> =
AssetId32::from_sbt_asset_id(PredefinedSbtAssetId::PRACS);
pub const SBT_PRINVST: AssetId32<PredefinedSbtAssetId> =
AssetId32::from_sbt_asset_id(PredefinedSbtAssetId::PRINVST);
pub const SBT_PRCRDT: AssetId32<PredefinedSbtAssetId> =
AssetId32::from_sbt_asset_id(PredefinedSbtAssetId::PRCRDT);

impl IsRepresentation for PredefinedSbtAssetId {
fn is_representation(&self) -> bool {
false
}
}

/// This code is H256 like.
pub type AssetId32Code = [u8; 32];

Expand Down Expand Up @@ -373,6 +411,13 @@ impl<AssetId> AssetId32<AssetId> {
Self::from_bytes(bytes)
}

pub const fn from_sbt_asset_id(asset_id: PredefinedSbtAssetId) -> Self {
let mut bytes = [0u8; 32];
bytes[0] = ASSET_ID_PREFIX_SBT_PREDEFINED;
bytes[2] = asset_id as u8;
Self::from_bytes(bytes)
}

/// Construct asset id for synthetic asset using its `reference_symbol`
pub fn from_synthetic_reference_symbol<Symbol>(reference_symbol: &Symbol) -> Self
where
Expand Down Expand Up @@ -425,6 +470,12 @@ impl<AssetId> From<AssetId32<AssetId>> for AssetId32Code {
}
}

impl<AssetId> From<AssetId32Code> for AssetId32<AssetId> {
fn from(value: AssetId32Code) -> Self {
AssetId32::new(value, Default::default())
}
}

impl<AssetId: Default> Default for AssetId32<AssetId>
where
AssetId32<AssetId>: From<TechAssetId<AssetId>>,
Expand Down Expand Up @@ -455,6 +506,18 @@ where
}
}

impl From<AssetId32<PredefinedSbtAssetId>> for AssetId32<PredefinedAssetId> {
fn from(value: AssetId32<PredefinedSbtAssetId>) -> Self {
AssetId32::new(value.code, Default::default())
}
}

impl AssetId32<PredefinedSbtAssetId> {
pub fn into_predefined(self) -> AssetId32<PredefinedAssetId> {
self.into()
}
}

/// DEX identifier.
#[derive(
Encode,
Expand Down
35 changes: 35 additions & 0 deletions common/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,10 @@ pub trait OrderBookManager<AccountId, AssetId, DEXId, Moment> {
output_asset_id: &AssetId,
) -> Option<OrderBookId<AssetId, DEXId>>;

fn tech_account_id_for_order_book(
order_book_id: &OrderBookId<AssetId, DEXId>,
) -> Result<AccountId, DispatchError>;

fn initialize_orderbook(
order_book_id: &OrderBookId<AssetId, DEXId>,
tick_size: Balance,
Expand Down Expand Up @@ -1590,6 +1594,12 @@ impl<AccountId, AssetId, DEXId, Moment> OrderBookManager<AccountId, AssetId, DEX
None
}

fn tech_account_id_for_order_book(
_order_book_id: &OrderBookId<AssetId, DEXId>,
) -> Result<AccountId, DispatchError> {
unimplemented!()
}

fn initialize_orderbook(
_order_book_id: &OrderBookId<AssetId, DEXId>,
_tick_size: Balance,
Expand All @@ -1611,3 +1621,28 @@ impl<AccountId, AssetId, DEXId, Moment> OrderBookManager<AccountId, AssetId, DEX
Ok(())
}
}

pub trait ExtendedAssetsManager<AssetId, Moment, ContentSource> {
fn set_metadata(sbt_asset_id: &AssetId, external_url: Option<ContentSource>, issued_at: Moment);

fn bind_regulated_asset_to_sbt_asset(
sbt_asset_id: &AssetId,
regulated_asset_id: &AssetId,
) -> Result<(), DispatchError>;
}

impl<AssetId, Moment, ContentSource> ExtendedAssetsManager<AssetId, Moment, ContentSource> for () {
fn set_metadata(
_sbt_asset_id: &AssetId,
_external_url: Option<ContentSource>,
_issued_at: Moment,
) {
}

fn bind_regulated_asset_to_sbt_asset(
_sbt_asset_id: &AssetId,
_regulated_asset_id: &AssetId,
) -> Result<(), DispatchError> {
Ok(())
}
}
Loading