PDX TeX — Secure virtual asset exchange platform following ERC20 specification

PDXbaap
PDXbaap
Nov 6 · 8 min read

PDX TeX (Token Exchange) is a secure virtual asset Exchange platform that follows ERC20 standard and is built on the basis of PDX Utopia block chain protocol stack. It provides service interface in the form of intelligent contract, runs in the way of complete desinalization, is safe and stable, and can completely prevent various data cheating means of traditional centralized Exchange.

PDX TeX is designed as a pluggable module, compatible with Ethereum protocol, compatible with solregulated ABI protocol, consistent with Web3. Js interface specification, and providing a friendly Dapp developer interface.The main development language of the software is based on golang and solnarration. For terminal access, Java and nodejs are also used to accomplish docking.

The target

1. Provide the ERC20 contract registry. When the contract is deployed, the system will automatically intercept the ERC20 contract and fill the address information into the registry, and provide the function of obtaining the registry information externally;

2 function, provides the deity, ASK/BID correspond sale and pay, when they are prices to trade sector as A benchmark, for example, in A B/A transaction on the trade sector, hang A “single” ASK prices for 600 B / 200 A, said to sell in return for 200 A, 600 B hang “BID list” for 100 A / 300 B, said to use 100 A price to buy 300 B, about the price we cannot use the decimal are cancelled, because complete the transaction in decentralized contract, contract doesn’t support floating point number,So we want to express the price in a definite conversion ratio;

3. Provide the function of retrieving the list of pending orders according to the category of “transaction pair”.For example, suppose that there are currently four trading zones: A, B, C and D. If you want to view the trading zone A, provide three groups of trading pairs: B/A, C/A and D/A.

4. Provide automatic matching function. When a group of ASK/BID meets matching conditions, the matching task will be generated and the matching transaction will be conducted in the next block.

Use cases

Publish assets

The Utopia main chain or sub-chain that starts the Tokenexchange module has the function of automatically identifying ERC20 contracts and adding them to the registry. The tradable “ERC20 virtual assets list” comes from this registry. Dapp terminals can generate transaction pairs according to this list in pairs.

As shown above, when A user deploits A contract at node M, A registry containing [A,B,C,D] is automatically identified and generated, and the same registry is created on node N when block “block N” synchronizes from node M to node N.

Top up

Assuming that user U1 holds ERC20 asset A, and the user wants to trade A through Tokenexchange, the user first needs to transfer to “0x123” (the contract address of Tokenexchange) on the A contract. The transfer amount will be the balance of user U1’s asset A in the Tokenexchange ledger data.

The above figure respectively demonstrates the processes of U1 recharge 100A and U2 recharge 700B to Tokenexchange.

Trading

When U1 and U2 have finished charging and want to exchange assets, the process shown in the figure above will be followed to complete the final asset exchange.

Architecture

Structure that

1. ERC20 registry

When operators deploy ERC20 contracts [A,B,C,D] to Utopia, the system will automatically identify and add ERC20 compliant contract addresses to the Tokenexchange module registry.

2. The Ledger

When the user passes the erc20 token to the tokenexchange address, the billing function of the recharge ledger is triggered, and the balance can be checked through balanceOf.

3. ERC20 trading pair

When the number of contracts in the registry is greater than or equal to 2, they can be processed into trading pairs. Each contract in the registry can become A separate trading area. The exchange with other contracts is called trading pair.

4. List of pending bills

Above by the BID/ASK the call list respectively in the deity of the interface “BID A → B” and “ASK B → A” data produced two deity, in the order is the BID in the former, ASK in the back, so you can see the Numbers for 1 “trigger” cross doesn’t create set tasks, and the number is 2 “trigger” cross will produce two set tasks, corresponding to the BID list according to the price of the former two data in reverse chronological order.

5, trigger matching

Trigger matching here is to generate a matching task. Only when the packager of the block finds that a matching task needs to be executed can the specific process of triggering a matching process be triggered.

Matching algorithm

Matching will be triggered automatically at the same time of listing the order, which can be triggered by ASK/BID order respectively and be settled in real time. The specific matching logic is executed according to the following rules:

1.ASK initiated a match

When a match is triggered by a ASK, the BIDList is filtered to filter out data that meets the matching criteria, such as bid.price >= ask.price.

2. BID initiated matchmaking

When the matchmaking is triggered by the BID list, the ASKList is filtered to filter out data that meets the matching condition, which is also bid.price >= ask.price.

3. Matching principle

The whole principle of matching is high price, by the high price clinched a deal.

Such as:

BID={A:100,B:100} is equivalent to price P = 1.0

Sell order ASK={A:100,B:200} equivalent price P = 0.5

So the matching is going to be

The BID = {A: 100, B: 100} {RA: 0, RB: 100}

ASK = {A: 100, B: 200} {RA: 100, RB: 100}

We saw that ASK’s target was to sell 200B for 100A, but when the bidding was matched, ASK got 100A and still had 100B left.

Functional description

TokenList

A list of contract addresses that conform to the ERC20 specification on the current chain, from which developers can generate trade pairs.

Such as:

Tokenlist returns [A,B,C,D];

With A as the trading area, we can show three trading pairs: B/A, C/A and D/A.

In the interface parameters, we will use ‘address region’ to represent the transaction region, ‘address target’ to represent the transaction target, and the transaction pair ‘B/A’ is equivalent to ‘{region:A, target:B}’.

TokenInfo

According to the ERC20 contract address, obtain the summary information, which can be used to display the trade area and trade pairs, the details will include at least: asset name, asset symbol, circulation, accuracy, etc.

Bid

When the user holds ERC20 asset region and wants to exchange an amount of target assets on the target/region trading pair in the region trading region, he/she can purchase target assets in the form of hang purchase.

Parameter design:

Region: erc20 contract address;

Target: trade target erc20 contract address;

RegionAmount: want to trade regionAmount region token for targetAmount target token;

TargetAmount: want to trade regionAmount region token for targetAmount target token.

Ask

When the user holds the ERC20 asset target and wants to exchange an amount of region assets on the target/region trading pair in the region trading region, the target asset can be sold by placing a sale order.

Parameter design:

Region: erc20 contract address;

Target: trade target erc20 contract address;

RegionAmount: wants to trade targetAmount target token for regionAmount region token;

TargetAmount: want to trade targetAmount target token for regionAmount region token.

Top up

Tokenexchange will provide an address in the form of a contract for Dapp developers and end users to use, so this address is also used to recharge the user account. We assume that the address of the Tokenexchange contract is 0x123, and the ERC20 asset held by the user is M, then the user needs to perform transfer transaction to 0x123 on the contract M to complete the recharge.

Withdrawal

Corresponding to the Withdrawal, the user can complete the Withdrawal operation by executing the Withdrawal method on the Tokenexchange contract. If the asset prepaid by the user is M, the remaining asset will return to the M contract.

BalanceOf

Check the balance. Check the balance in tokenexchange according to the erc20 contract address. The balance is obtained by charging the token corresponding to region to the tokenexchange contract address.

For example: user U A assets, then U to perform: A.t ransfer tokenexchange. The address and the amount after the success, the user U again to carry out;Tokenexchange. BalanceOf (A) will be (A.n ame, A symbol, amount, decimals) yuan group.

OrderList

Query the list of pending orders, query on the specified transaction pair, and only return the list of order ids. Pay attention to not changing the order of the list, the list has been sorted by price, the ask order is in ascending order, and the bid order is in descending order.

Parameter design:

OrderType: orderType, the optional value of “bid”/”ask” respectively means purchase/sale order;

Region: erc20 contract address;

Target: trade target erc20 contract address.

OrderInfo

Details include all the information when placing the order, and the current status of the order. RegionComplete/targetComplete is the quantity of the order that has been put together at present. When isFinal == true, it means the order is changed into the final status and no longer participates in the matching.

Cancel

Orders can be cancelled before reaching the final state. After the cancellation, the state becomes final and no longer participates in the matching.

OwnerOrder

Bid & ask

Parameter design:

Addrs:

Is an array whose length must be 1 or 3;

When is 1, addrs = [owner] means to query all the list information of owner;

When is 3, addrs = [owner,region,target] means to query the list information of owner in the target/region transaction region.

PageNum: used to represent the page number when paging, 20 pieces of information per page.

- About the PDX public chain -

PDX public chain aims to build a public blockchain ecosystem. As a public blockchain IaaS, it helps enterprise customers, developer groups and ordinary users to enjoy the convenience and fun brought by blockchain with powerful underlying patented technology.

The PDX public link claims data sovereignty for the user.

- join the community

The official Telegram:

https://t.me/PDXann

https://t.me/PDXbaap

https://t.me/PDX_EngVIP

Official English twitter

https://twitter.com/PDXbaap

The official Facebook

https://www.facebook.com/PDXbaap

PDXbaap

Written by

PDXbaap

PDX BaaP is the world’s first real reconstruction blockchain, the blockbuster really make the key practical applications, but also the world’s only support in t

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade