Skip to content

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 (248×0.00001=28e92^{48} \times 0.00001 = 28e9) $28B in value.

AssetUSD PriceUnitMaximum Value
ETH$4,0001e-8 ETH2.8M ETH
USDC$10.0001 USDC28B USDC
BTC$100,0001e-8 BTC 12.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);
//      ^1e8

When going from stored amount to raw amount, we will multiply the stored amount and ceil the result.

uint64 rawAmount = storedAmount * units;

Footnotes

  1. BTC unit size will actually be the smallest possible unit as BTC only has 8 decimals precision.