Units
In order to save gas and space while storing offer details, we decided not to use the usual 128 bits to store an amount, but rather 48 bits to store received and sent amounts, and 64 bits for market orders.
In order to do this, we had to define units. Units are the multiplier to go from raw amount to the stored amount.
Example Units
Most likely, we'll use a units amount equivalent to $0.0001, but only the closest one to a power of 10. This way it is still human readable - we believe it does not make sense to try to sell less than $0.0001 and we can sell up to () $28B in value.
| Asset | USD Price | Unit | Maximum Value |
|---|---|---|---|
| ETH | $4,000 | 1e-8 ETH | 2.8M ETH |
| USDC | $1 | 0.0001 USDC | 28B USDC |
| BTC | $100,000 | 1e-8 BTC 1 | 2.8M BTC |
Example conversion
When going from raw amount to stored amount, we will divide the raw amount and floor the result.
uint256 rawAmount = 1.000000001 ether;
uint256 units = 1e10; // because ETH has 18 decimals precision
uint48 storedAmount = uint48(rawAmount / units);
// ^1e8When going from stored amount to raw amount, we will multiply the stored amount and ceil the result.
uint64 rawAmount = storedAmount * units;Footnotes
-
BTC unit size will actually be the smallest possible unit as BTC only has 8 decimals precision. ↩