# 4.2 Architecture and technology

1xBinary architecture is based on two major parts:&#x20;

▸ Smart contract systems (to ensure transparency of bets).

&#x20;▸ An oracle providing the reliable data on occurring events to a smart contract (in particular, exchange rates).&#x20;

SMART CONTRACTS ARCHITECTURE&#x20;

Main purpose of smart contracts is ensuring a transparent betting mechanism for the common pool of liquidity. Smart contracts were built under the following restrictions:

&#x20;▸ The bet occurs by the means of transferring the SBT token into a common liquidity pool for a given event in the system;

&#x20;▸ The network commission (Ethereum) should be as small as possible;&#x20;

▸ Reward payout (including the transfer of the commission) is realized by a smart contract based on the data received from the oracle.&#x20;

The architectural system is based on the following smart contracts:&#x20;

▸ SBT token contract complies with ERC-20 standard. SBT is a stable (relatively to the USD rate) token, the exchange rate of which is artificially maintained, with emissions and burning made during the exchange operations.&#x20;

▸ Exchange contract is a smart contract for automatic exchange of ETH to SBT and vice versa. ETH/SBT rate is regularly updated with an oracle and artificially maintained at 1:1 / USD level. When crediting ETH, the required amount of SBT is being emitted. When withdrawing ETH, a corresponding amount of SBT tokens is being burned.&#x20;

▸ It is also planned to implement time restrictions on the token use. If the token is not used in the 1xBinary system for a certain period of time, it is automatically exchanged back to the ETH source address. This may prevent speculation with tokens.&#x20;

▸ 1xBinary smart contract is a management system for liquidity pools (betting baskets). It accepts bids by moving SBT to a specific pool (basket) for a limited period of time. After the waiting time has expired, the payout is redistributed among the players based on the oracle data.

&#x20;▸ Commission smart contract is the contract-aggregator of commission fees. It charges the entire commission from operations in the system. The distribution of the commission is made by this contract once in a certain period of time (currently, once in 24 hours).&#x20;

▸ Referral smart contract is contract managing the referral program. 1xBinary supports a single level referral program and redistributes part of the commission to the referral addresses. This smart contract stores the necessary dependencies. The implementation of smart contracts is carried out considering all modern practices and approaches, including the overflow checks, 100% test coverage and statistical control of Gas used. MANAGEMENT OF LIQUIDITY POOLS. POOL‟S LIFECYCLE. Each pool of liquidity (basket) in the 1xBinary system has following time characteristics:

&#x20;▹ Time for bet placements;&#x20;

▹ Waiting time for exit; These time intervals are limited by:&#x20;

▹ The moment of opening;&#x20;

▹ The moment of closing;

&#x20;▹ The moment of payment; From the point of view of a smart contract, each of these moments is implemented using a special system transaction.

&#x20;The problem here is the uncontrolled time of the transaction (from the time it hits the Tx pool to the time it was confirmed), as well as the allowable deviation of the system variable (solidity block. Timestamp) in 900 seconds compared to the real time.&#x20;

The lifecycle of a pool includes the following:

&#x20;▹ Opening/creating a pool

&#x20;During realization of the 1xBinary smart contract it was decided to give up transaction at the moment of opening the pool for the sake of creating a system of identifiers. Thus, in order to execute a bet, you only need to know the pool ID. If there is no pool at the time of the bet, it will be created automatically.

&#x20;▹ Closing the pool&#x20;

Closing the pool is implemented using a system transaction, which is carried out from a predetermined address (and is part of the 1xBinary smart contract management system). The closure essentially means a ban on accepting bets from a certain moment. Closing the pool should occur faster with respect to other transactions (including bets), so this transaction is conducted with an increased gas price.&#x20;

▹ Payouts&#x20;

Payouts are realized using a system transaction (or series of transactions), which is conducted from a predefined address. The calculation of winnings and the transfer of tokens is carried out inside the smart contract, so, potentially, such a transaction may not be invested in the gas limit of the block (with a large number of bets), so the system has the opportunity to pay winnings by sending a series of transactions, which makes it possible to work with a large number of users.&#x20;

BETS&#x20;

The betting process is a transaction of transferring tokens to the address of the 1xBinary smart contract, indicating the type of bet and the pool ID. The bet is accepted by the system until the pool is closed.

&#x20;Bet options&#x20;

At the moment, the system supports 2 types of bets — on growth and falling. In the future, we plan to expand this list to support bets for other types of events.

SYSTEM RESTRICTIONS&#x20;

Since transactions are accepted and confirmed by the network in asynchronous mode, it creates a number of problems when the system is running. Let's view them in more detail using the figure below.

![](https://992940973-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyYxif7u0GuIZYuA7JLYX%2Fuploads%2F2jSoPWD7i7xjcy6g8Gii%2Fimage.png?alt=media\&token=73f0aad9-986b-4cb1-8b99-2e930c8f0d5d)

When processing the transaction Bet 1, the pool is in the open state, and it’s long enough will the closing time for the transaction to get the network confirmation. As we, technically, do not limit users in the bets until the basket is closed (it's possible to bet earlier, not later), the bet will be considered successful.&#x20;

When processing the Bet 2 transaction, the pool is also in the open state, but the transaction may fail to receive confirmation before the pool is closed. In this case, transactions Bet 2 and close are in the Tx pool simultaneously at a certain point of time.&#x20;

The gas price of the close transaction is selected by the 1xBinary system higher than the rest of the transactions (including the bet transactions), so the probability of confirming the transaction close is higher than that of the Bet 2 transaction. If the pool has time to close before confirmation of the Bet 2 transaction, the bet will not occur, even if formally the user sent the transaction until the pool was closed.&#x20;

When processing the transaction Bet 3, the pool is still in the open state, because transaction close is not yet approved by the network. But, as in the case of Bet 2, the probability of Bet 3 confirmation is lower than that of transaction close, so the probability of Bet 3 rejection will be higher than its acceptance.&#x20;

POOL CLOSING ATTACK&#x20;

The only way to place a bet into the pool at the time when the close transaction has already been sent is to set a larger gas price for the bet transaction than the close transaction. In the same way, you can hammer the Tx pool of the Ethereum network with transactions with a large gas price, without giving the opportunity to confirm the transaction close. In general, this kind of user behavior is possible, yet it is costly and time-consuming. To protect 1xBinary system from such attacks, we have implemented two principles:&#x20;

▸ The time intervals chosen for waiting for pools are sufficiently large;

&#x20;▸ Gas price of the close transaction is determined by total bet amount in a pool.&#x20;

Thus, the price of attack increases until it gets unreasonable in terms of costs.

ORACLE The basis for deciding the outcome of each round in the 1xBinary system is the resulting composite rate (Outcome Rate) provided by the oracle, so the oracle is a critical component of the system that is located separately from the rest of its parts. The work of the oracle is built on the principle of publicity and transparency. The results of its work (in the form of payment transactions) will be available for verification through the blockchain explorer (etherescan.io for the Ethereum network).&#x20;

Every time, the 1xBinary composite rate is calculated as the average weighted of the exchange rates on the main exchanges. Each trading pair has a separate list of exchanges with significant volume for this particular pair. Thereby, the weight factor is trade volume on each of the exchanges.&#x20;

In case one of the exchanges stops delivering data on the rates, its rate (the latter value) continues to participate in determining the composite rate, the strike rate of which includes the data of this exchange. This prevents sharp artificial jumps of the composite rate due to the redistribution of weight values.&#x20;

With a fixed rate from one data provider, the courses of the remaining suppliers continue to move the composite course according to the current market situation. This is how we smooth out such an abnormal situation as correctly as possible.&#x20;

If the data supplied by this exchange is not resumed by the start of the new round, the strike rate will be calculated without considering the rate from this exchange. Thus, such data provider will be temporarily "disqualified" in the 1xBinary system.

&#x20;For each oracle in the 1xBinary system, we also plan to publish the source data and the methodology for obtaining the result, according to which the composite rate was calculated at each time point.
