Skip to content

feat: token marketplace #2518

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

Draft
wants to merge 6 commits into
base: v2.0-dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .github/package-filters/js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
- .github/workflows/tests*
- packages/token-history-contract/**

'@dashevo/token-marketplace-contract': &token-marketplace-contract
- .github/workflows/tests*
- packages/token-marketplace-contract/**

'@dashevo/dashpay-contract': &dashpay-contract
- .github/workflows/tests*
- packages/dashpay-contract/**
Expand Down Expand Up @@ -35,6 +39,7 @@
- *withdrawals-contract
- *wallet-utils-contract
- *token-history-contract
- *token-marketplace-contract
- packages/rs-platform-serialization/**
- packages/rs-platform-serialization-derive/**
- packages/rs-platform-value/**
Expand Down Expand Up @@ -86,6 +91,7 @@ dashmate:
- *dpns-contract
- *withdrawals-contract
- *token-history-contract
- *token-marketplace-contract
- *wallet-lib
- *dapi-client

Expand Down
5 changes: 5 additions & 0 deletions .github/package-filters/rs-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ token-history-contract: &token-history-contract
- .github/workflows/tests*
- packages/token-history-contract/**

token-marketplace-contract: &token-marketplace-contract
- .github/workflows/tests*
- packages/token-marketplace-contract/**

dashpay-contract: &dashpay-contract
- .github/workflows/tests*
- packages/dashpay-contract/**
Expand Down Expand Up @@ -35,6 +39,7 @@ dpp: &dpp
- *withdrawals-contract
- *wallet-utils-contract
- *token-history-contract
- *token-marketplace-contract
- *json-schema-compatibility-validator
- packages/rs-platform-serialization/**
- packages/rs-platform-serialization-derive/**
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ members = [
"packages/rs-json-schema-compatibility-validator",
"packages/check-features",
"packages/wallet-utils-contract",
"packages/token-history-contract"
"packages/token-history-contract",
"packages/token-marketplace-contract"
]

exclude = ["packages/wasm-sdk"] # This one is experimental and not ready for use
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@
"packages/dash-spv",
"packages/wasm-dpp",
"packages/withdrawals-contract",
"packages/token-history-contract"
"packages/token-history-contract",
"packages/token-marketplace-contract"
],
"resolutions": {
"elliptic": "6.5.7",
Expand Down
1 change: 1 addition & 0 deletions packages/data-contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ feature-flags-contract = { path = "../feature-flags-contract" }
platform-value = { path = "../rs-platform-value" }
wallet-utils-contract = { path = "../wallet-utils-contract" }
token-history-contract = { path = "../token-history-contract" }
token-marketplace-contract = { path = "../token-marketplace-contract" }
17 changes: 17 additions & 0 deletions packages/data-contracts/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,20 @@ impl From<token_history_contract::Error> for Error {
}
}
}

impl From<token_marketplace_contract::Error> for Error {
fn from(e: token_marketplace_contract::Error) -> Self {
match e {
token_marketplace_contract::Error::UnknownVersionMismatch {
method,
known_versions,
received,
} => Error::UnknownVersionMismatch {
method,
known_versions,
received,
},
token_marketplace_contract::Error::InvalidSchemaJson(e) => Error::InvalidSchemaJson(e),
}
}
}
13 changes: 12 additions & 1 deletion packages/data-contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub enum SystemDataContract {
Dashpay = 4,
WalletUtils = 5,
TokenHistory = 6,
TokenMarket = 7,
}

pub struct DataContractSource {
Expand All @@ -43,6 +44,7 @@ impl SystemDataContract {
SystemDataContract::Dashpay => dashpay_contract::ID_BYTES,
SystemDataContract::WalletUtils => wallet_utils_contract::ID_BYTES,
SystemDataContract::TokenHistory => token_history_contract::ID_BYTES,
SystemDataContract::TokenMarket => token_marketplace_contract::ID_BYTES,
};
Identifier::new(bytes)
}
Expand Down Expand Up @@ -98,10 +100,19 @@ impl SystemDataContract {
SystemDataContract::TokenHistory => DataContractSource {
id_bytes: token_history_contract::ID_BYTES,
owner_id_bytes: token_history_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.wallet as u32,
version: platform_version.system_data_contracts.token_history as u32,
definitions: token_history_contract::load_definitions(platform_version)?,
document_schemas: token_history_contract::load_documents_schemas(platform_version)?,
},
SystemDataContract::TokenMarket => DataContractSource {
id_bytes: token_marketplace_contract::ID_BYTES,
owner_id_bytes: token_marketplace_contract::OWNER_ID_BYTES,
version: platform_version.system_data_contracts.token_marketplace as u32,
definitions: token_marketplace_contract::load_definitions(platform_version)?,
document_schemas: token_marketplace_contract::load_documents_schemas(
platform_version,
)?,
},
};

Ok(data)
Expand Down
6 changes: 5 additions & 1 deletion packages/rs-dpp/src/balances/credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ pub type SumTokenAmount = i128;
pub type SignedCredits = i64;

/// Maximum value of credits
pub const MAX_CREDITS: Credits = 9223372036854775807 as Credits; //i64 Max
pub const MAX_CREDITS: Credits = i64::MAX as Credits; //i64 Max

/// Maximum token amount
pub const TOKEN_MAX_AMOUNT: TokenAmount = i64::MAX as TokenAmount;

/// Number of credits in 1 duff
pub const CREDITS_PER_DUFF: Credits = 1000;

/// Trait for signed and unsigned credits
Expand Down
12 changes: 11 additions & 1 deletion packages/rs-dpp/src/errors/consensus/basic/basic_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ use crate::consensus::basic::token::{
ChoosingTokenMintRecipientNotAllowedError, ContractHasNoTokensError,
DestinationIdentityForTokenMintingNotSetError, InvalidActionIdError, InvalidTokenAmountError,
InvalidTokenConfigUpdateNoChangeError, InvalidTokenIdError, InvalidTokenNoteTooBigError,
InvalidTokenPositionError, MissingDefaultLocalizationError, TokenTransferToOurselfError,
InvalidTokenPositionError, InvalidTokenPriceError, MissingDefaultLocalizationError,
TokenTransferToOurselfError, ZeroTokenAmountError, ZeroTokenPriceError,
};
use crate::consensus::basic::unsupported_version_error::UnsupportedVersionError;
use crate::consensus::basic::value_error::ValueError;
Expand Down Expand Up @@ -501,6 +502,15 @@ pub enum BasicError {

#[error(transparent)]
MissingDefaultLocalizationError(MissingDefaultLocalizationError),

#[error(transparent)]
ZeroTokenAmountError(ZeroTokenAmountError),

#[error(transparent)]
ZeroTokenPriceError(ZeroTokenPriceError),

#[error(transparent)]
InvalidTokenPriceError(InvalidTokenPriceError),
}

impl From<BasicError> for ConsensusError {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error(
"Invalid token price {}, exceeds maximum allowed {}",
token_price,
max_token_price
)]
#[platform_serialize(unversioned)]
pub struct InvalidTokenPriceError {
max_token_price: u64,
token_price: u64,
}

impl InvalidTokenPriceError {
/// Creates a new `InvalidTokenPriceError`.
pub fn new(max_token_price: u64, token_price: u64) -> Self {
Self {
max_token_price,
token_price,
}
}

/// Returns the maximum allowed token price.
pub fn max_token_price(&self) -> u64 {
self.max_token_price
}

/// Returns the invalid token price that was provided.
pub fn token_price(&self) -> u64 {
self.token_price
}
}

impl From<InvalidTokenPriceError> for ConsensusError {
fn from(err: InvalidTokenPriceError) -> Self {
Self::BasicError(BasicError::InvalidTokenPriceError(err))
}
}
6 changes: 6 additions & 0 deletions packages/rs-dpp/src/errors/consensus/basic/token/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ mod invalid_token_config_update_no_change_error;
mod invalid_token_id_error;
mod invalid_token_note_too_big_error;
mod invalid_token_position_error;
mod invalid_token_price_error;
mod missing_default_localization;
mod token_transfer_to_ourselves_error;
mod zero_token_amount_error;
mod zero_token_price_error;

pub use choosing_token_mint_recipient_not_allowed_error::*;
pub use contract_has_no_tokens_error::*;
Expand All @@ -19,5 +22,8 @@ pub use invalid_token_config_update_no_change_error::*;
pub use invalid_token_id_error::*;
pub use invalid_token_note_too_big_error::*;
pub use invalid_token_position_error::*;
pub use invalid_token_price_error::*;
pub use missing_default_localization::*;
pub use token_transfer_to_ourselves_error::*;
pub use zero_token_amount_error::*;
pub use zero_token_price_error::*;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error("Token amount can't be 0")]
#[platform_serialize(unversioned)]
pub struct ZeroTokenAmountError {}

impl Default for ZeroTokenAmountError {
fn default() -> Self {
Self::new()
}
}

impl ZeroTokenAmountError {
/// Creates a new `ZeroTokenAmountError`.
pub fn new() -> Self {
Self {}
}
}

impl From<ZeroTokenAmountError> for ConsensusError {
fn from(err: ZeroTokenAmountError) -> Self {
Self::BasicError(BasicError::ZeroTokenAmountError(err))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::consensus::basic::BasicError;
use crate::consensus::ConsensusError;
use crate::ProtocolError;
use bincode::{Decode, Encode};
use platform_serialization_derive::{PlatformDeserialize, PlatformSerialize};
use thiserror::Error;

#[derive(
Error, Debug, Clone, PartialEq, Eq, Encode, Decode, PlatformSerialize, PlatformDeserialize,
)]
#[error("Token price can't be 0")]
#[platform_serialize(unversioned)]
pub struct ZeroTokenPriceError {}

impl Default for ZeroTokenPriceError {
fn default() -> Self {
Self::new()
}
}

impl ZeroTokenPriceError {
/// Creates a new `ZeroTokenPriceError`.
pub fn new() -> Self {
Self {}
}
}

impl From<ZeroTokenPriceError> for ConsensusError {
fn from(err: ZeroTokenPriceError) -> Self {
Self::BasicError(BasicError::ZeroTokenPriceError(err))
}
}
3 changes: 3 additions & 0 deletions packages/rs-dpp/src/errors/consensus/codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ impl ErrorWithCode for BasicError {
Self::InvalidTokenConfigUpdateNoChangeError(_) => 10457,
Self::InvalidTokenAmountError(_) => 10458,
Self::InvalidTokenNoteTooBigError(_) => 10459,
Self::ZeroTokenAmountError(_) => 10460,
Self::ZeroTokenPriceError(_) => 10461,
Self::InvalidTokenPriceError(_) => 10462,

// Identity Errors: 10500-10599
Self::DuplicatedIdentityPublicKeyBasicError(_) => 10500,
Expand Down
12 changes: 12 additions & 0 deletions packages/rs-dpp/src/state_transition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,18 @@ impl StateTransition {
"TokenConfigUpdate"
}
BatchedTransitionRef::Token(TokenTransition::Claim(_)) => "TokenClaim",
BatchedTransitionRef::Token(TokenTransition::OrderBuyLimit(_)) => {
"TokenOrderBuyLimit"
}
BatchedTransitionRef::Token(TokenTransition::OrderSellLimit(_)) => {
"TokenOrderSellLimit"
}
BatchedTransitionRef::Token(TokenTransition::OrderCancel(_)) => {
"TokenOrderCancel"
}
BatchedTransitionRef::Token(TokenTransition::OrderAdjustPrice(_)) => {
"TokenOrderAdjustPrice"
}
};
document_transition_types.push(document_transition_name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use crate::data_contract::document_type::DocumentTypeRef;
use crate::document::Document;
use crate::prelude::IdentityNonce;
use crate::state_transition::batch_transition::batched_transition::DocumentCreateTransition;
use crate::state_transition::batch_transition::batched_transition::{
DocumentCreateTransition, Entropy,
};
use crate::state_transition::batch_transition::document_create_transition::DocumentCreateTransitionV0;
use crate::ProtocolError;
use platform_version::version::{FeatureVersion, PlatformVersion};
Expand All @@ -10,7 +12,7 @@ impl DocumentCreateTransition {
pub fn from_document(
document: Document,
document_type: DocumentTypeRef,
entropy: [u8; 32],
entropy: Entropy,
identity_contract_nonce: IdentityNonce,
platform_version: &PlatformVersion,
feature_version: Option<FeatureVersion>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::data_contract::document_type::methods::DocumentTypeV0Methods;
use crate::data_contract::document_type::DocumentTypeRef;
use crate::document::{Document, DocumentV0Getters};
use crate::prelude::IdentityNonce;
use crate::state_transition::batch_transition::batched_transition::Entropy;
use crate::state_transition::batch_transition::document_base_transition::DocumentBaseTransition;
use crate::state_transition::batch_transition::document_create_transition::DocumentCreateTransitionV0;
use crate::ProtocolError;
Expand All @@ -11,7 +12,7 @@ impl DocumentCreateTransitionV0 {
pub(crate) fn from_document(
document: Document,
document_type: DocumentTypeRef,
entropy: [u8; 32],
entropy: Entropy,
identity_contract_nonce: IdentityNonce,
platform_version: &PlatformVersion,
base_feature_version: Option<FeatureVersion>,
Expand Down
Loading