bitshares / bsips

BitShares Improvement Proposals and Protocols. These technical documents describe the process of updating and improving the BitShares blockchain and technical ecosystem.
https://bitshares.github.io
63 stars 86 forks source link

New BSIP: Resource exchange #286

Open syalon opened 4 years ago

syalon commented 4 years ago
BSIP: TODO:
Title: Resource exchange
Authors: syalon
Status: Draft
Type: Protocol
Created: 2020-08-07

Abstract

This BSIP describes an implementation of Resource Exchange operations.

Motivation

Now many people have invested in many asset names and account names. The BSIP provides these people with the possibility of on-chain exchange.

Rational

Although, it can currently be achieved by combining multiple operations such as proposal transfer. However, since the proposal needs to be approved by both parties, the experience is not very friendly. Therefore, the design here is to provide a merchant/customer purchase model on the chain.

Specifications

Describe implementation details.

New object id

GRAPHENE_DEFINE_IDS(resource_exchange)

New global parameter

Add a new global parameter resource_exchange_fee_percent which can be updated by the committee only after the protocol upgrade. Initial value of that parameter is 0%. Valid range of that parameter is [0%, 20%].

resource_exchange_object

class resource_exchange_object : public graphene::db::abstract_object<resource_exchange_object>
{
public:
  static const uint8_t space_id = protocol_ids;
  static const uint8_t type_id  = resource_exchange_object_type;

  account_id_type   merchant_id;
  object_id_type    res_id;         ///< account id or asset id
  asset             price;          ///< desired price
}

resx_create_operation

struct resx_create_operation : public base_operation
{
    struct fee_parameters_type
    {
        share_type fee             = 100 * GRAPHENE_BLOCKCHAIN_PRECISION;
        uint32_t   price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION;
    };

    asset                       fee;
    account_id_type             merchant_id;
    object_id_type              sell_res_id;
    asset                       price;

    extensions_type             extensions; 

    account_id_type fee_payer()const { return merchant; }

    void       validate()const;
    share_type calculate_fee( const fee_parameters_type& k )const;

    void get_required_owner_authorities( flat_set<account_id_type>& a )const
    { ... }

    void get_required_active_authorities( flat_set<account_id_type>& a )const
    { ... }
};

resx_take_operation

struct resx_take_operation : public base_operation
{
    struct fee_parameters_type
    {
        share_type fee             = 20 * GRAPHENE_BLOCKCHAIN_PRECISION;
        uint32_t   price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION;
    };

    asset                       fee;
    account_id_type             account;
    resource_exchange_id_type   resx_id;

    extensions_type             extensions; 

    account_id_type fee_payer()const { return merchant; }

    ///< ...
};

resx_cancel_operation

struct resx_cancel_operation : public base_operation
{
    struct fee_parameters_type
    {
        share_type fee             = 20 * GRAPHENE_BLOCKCHAIN_PRECISION;
        uint32_t   price_per_kbyte = GRAPHENE_BLOCKCHAIN_PRECISION;
    };

    asset                       fee;
    account_id_type             merchant;
    resource_exchange_id_type   resx_id;

    extensions_type             extensions; 

    ///< ...
};

APIs

TODO:

Discussion

if resource_exchange_fee_percent is set too high, users may consider offline transactions. Should consider setting a reasonable value.

Copyright

This document is placed in the public domain.

See Also

abitmore commented 4 years ago

Good idea.

Just like domain name trading, users on the chain could be able to list anything they own for sale, including account ownership, asset ownership, vesting balances, debt positions and etc. The chain is able to settle the deals automatically.

On the other hand, for account ownership trading, it could be a challenge for asset owners who enabled whitelisting and etc.

xiao93 commented 4 years ago

support