Skip to content

Commit

Permalink
Presto KYC (#1309)
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Tagirov <dev.mikhail.tagirov@outlook.com>
  • Loading branch information
wer1st authored Jan 23, 2025
1 parent 0a49922 commit f4fdf41
Show file tree
Hide file tree
Showing 53 changed files with 2,435 additions and 886 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
run: |
sudo rm -rf /usr/local/share/boost
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo apt-get update
sudo apt-get install protobuf-compiler -y
# v2.7.1
- uses: Swatinem/rust-cache@3cf7f8cc28d1b4e7d01e3783be10a97d55d483c8
Expand Down
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

0 comments on commit f4fdf41

Please sign in to comment.