Asset quantities in StarkEx
In the Ethereum blockchain, token quantities are represented by a 256bit number. However, for the sake of efficiency, quantities in StarkEx are represented by a 64bit number. The largest number of digits that a 64bit number can represent is much less than that which a 256bit number can represent. So in order to support trading in significant volume, the smallest unit that StarkEx can use for an asset is larger than the smallest unit that Ethereum can use.
The inputs to all offchain transactions and some onchain requests are given in units of the offchain asset, so the code that generates the transaction signature must use the correct factor for converting 256bit quantities of onchain or synthetic ETH or ERC20 asset quantities to a 64bit StarkEx representation.
Converting onchain asset quantities 
This factor is called the quantization factor or quantum. The quantum represents the smallest amount of an asset that users can trade offchain, or with which they can pay offchain fees. 
Converting synthetic asset quantities 
This factor is called the resolution factor. The resolution is the total number of the smallest part of a single synthetic token in the StarkEx system. 
You decide the value of the quantum and resolution factor according to the requirements of your application’s business logic.
Balance of a synthetic asset
Every balance is a 64bit value, where one bit represents the sign indicating if the value is positive or negative, and 63bits represent the number. So every balance falls within the range (2^{63}, 2^{63}).
Quantization
The quantum is the smallest unit of a token in the StarkEx system. It is similar to an exchange rate that you use to find the onchain value of a quantity of a token in StarkEx, according to the following formula:
Consider one possible quantization for ETH, which is an onchain asset:
Onchain asset 
The smallest unit of ETH is 1 WEI, which is \(10^{18}\) ETH. 
Offchain asset 
The smallest unit with which you can conduct transactions of the offchain asset that corresponds to ETH represents \(10^{11}\) onchain ETH, or \(10^{7}\) onchain WEI. 
So the operator defines the quantum for ETH to be \(10^{7}\).
This example shows how to find how many units of onchain WEI are represented by 17 units of the corresponding offchain asset.

In Ethereum, 1 WEI = \(10^{18}\)ETH.

Let \(\text{quantum}=10^7\).

Let \(\text{StarkEx_amount}=17\). This is the number of corresponding assets in a StarkEx offchain position.
Plugging in these values to the formula above gives the following:
170,000,000 is the amount of WEI locked onchain that is associated with the corresponding StarkEx offchain vault, which is the same as \(10^{11} \cdot 17\) ETH.
The quantum is necessary for every asset that can be represented onchain. For example, in the deposit flow, the onchain deposit transaction gets an unquantized amount of tokens from the user, yet the parameter to the onchain call is a quantized amount. 
Resolution
In contrast to collateral, synthetic assets do not necessarily correspond to onchain assets. For example, a barrel of oil can be a synthetic asset. So quantization, which is specifically for working with onchain assets, does not apply to synthetic assets. However, it is still necessary to work with a representation of the synthetic asset within the StarkEx system that defines the smallest unit of the asset that users can trade.
In StarkEx, synthetic assets are converted to StarkEx units by applying a calculation called resolution that uses a constant called a resolution factor.
For collateral, resolution is also necessary to simplify certain calculations.
Resolution provides the following benefits:

Signed external oracle prices are given in round units, such as BTC or ETH, rather than satoshi or WEI, so resolution makes the translation to the price used in the StarkEx system valid.

Resolution enables trading in synthetic assets that do not necessarily correspond to ERC20 tokens, such as barrels of oil.
The resolution is the total number of a single asset in the StarkEx system that equals one synthetic token. For example, if the smallest unit of DOGE that you can trade on StarkEx is 10^{6} DOGE, that means that one synthetic DOGE = 10^{6} StarkEx units. This number, 10^{6}, is the resolution factor for DOGE in StarkEx.
The formula to find the amount of a synthetic asset is:
Because every balance is within the range (2^{63}, 2^{63}), then in the example above, each position can contain amounts of (10^{6}\(\cdot\)2^{63}, 10^{6}\(\cdot\)2^{63}) DOGE.
Consider synthetic ETH.
Consider that in Ethereum, 1 ETH = \(10^{18}\) WEI.

Let \(\text{resolution} = 10^8\). This means that the operator decided that the smallest unit of ETH their application supports is 10^{8} synthetic ETH.

Alice has 2.25 synthetic ETH in her position.
What is the StarkEx amount of ETH in her position?
Plugging in these values to the formula above gives the following:
225,000,000 is the number of StarkEx units Alice holds that correspond to synthetic ETH in her position.
Prices: Calculating StarkEx internal values
When calculating values to send to the StarkEx gateway, be aware that the StarkEx system represents prices as 64bit fixedpoint unsigned numbers, with 32 bits after the decimal point.
Consider the following values:

The quantization of USDC is 1.

The resolution of USDC is 10^{6}, which means that the smallest unit of USDC in the StarkEx system is 10^{6} USDC.

The resolution of synthetic ETH is 10^{8}.

A signature from the oracle provider sets the price of ETH to 383.3456178219832 USDC, which the oracle provider notates as 383345617821983200000.
The internal price of ETH in StarkEx is calculated as follows:
Where \(\text{ROUND_PRICE}\) rounds the quotient to the nearest integer.
Plugging in the values gives the following:
Which simplifies to:
Rounding this price to the nearest integer gives 16464568916
, which is the value that the StarkEx system uses for the price of ETH.
Total value: Calculating StarkEx internal values

Collateral and synthetic asset values have resolution applied.

Total value is a 96bit fixedpoint signed integer, with 32 bits after the decimal point.
Consider the following applies to Alice’s position:
collateral: 
Alice holds 500 USDC. 
synthetic: 
Alice holds 6 ETH, where 1 ETH = 1,000 USDC. 
The total value of Alice’s position in enduser terms is:
500 + (6 * 1,000) = 6,500
To convert this value to a StarkEx internal value:
Plugging in the values above gives:
So total value, expressed as a 96bit fixedpoint signed integer, with 32 bits after the decimal point, is 10809264835600000000
.
Total risk: Calculating StarkEx internal values
When StarkEx calculates total risk:

The risk factor is a positive number between 0 and 1. It is similar to the maintenance margin. For more information, see Margin and Total value and total risk.

The risk factor and prices are represented as 64bit unsigned integers, with 32 bits after the decimal point.

Total risk is a 128bit fixedpoint unsigned integer, with 64 bits after the decimal point.
To calculate the internal representation of the risk factor:
For example, if the risk_factor for ETH is 0.1, the internal representation is 0.1 * 2^{32} = 429496729.6
. This number is rounded to 429496730
, which is the value for risk_factor
in the configuration file.
Calculating total risk results in a 128bit fixedpoint unsigned number, with 64 bits to the right of the decimal point.
The risk factor for ETH is 0.1. The internal StarkEx value is 0.1 * 2^{32}= 429496729.6
, which rounds to 429496730
.
The resolution factors for USDC, BTC, and ETH are as follows:

USDC: 10^{6}

BTC: 10^{7}

ETH: 10^{8}
So the internal values of Alice’s USDC, BTC, and ETH positions are as follows:

500 USDC * 10^{6} = 500000000

4 BTC * 10^{7} = 40000000

6 ETH * 10^{8} = 600000000
Consider Alice’s total risk from Example: Total risk is 40,600:
collateral: 
500 USDC 
synthetic: 
4 BTC. 1 BTC = 20,000 USDC. 
(4 * 20,000 * 0.5) + (6 * 1,000 * 0.1) = 40,600
Now convert the risk factors to 32bit numbers:

\(\text{BTC_risk_factor}\) = 0.5 * 2^{32} = 2147483648

\(\text{ETH_risk_factor}\) = 0.1 * 2^{32} = 429496730
The internal StarkEx value of Alice’s total risk is calculated as follows:
\(\text{BTC_risk_factor}\) is the internal StarkEx value of this risk factor, so it already has been multiplied by 2^{32}. 
Plugging in the values from the example:
( (4 * 20,000) * 10^{7} * 2147483648 ) + ((6 * 1,000) * 10^{8} * 429496730) = 197568495600000000000
So the internal value of Alice’s total risk is 197568495600000000000.