Data Encoding
Custom data types
Sphinx uses several custom data types on top of the primitive types offered by Cairo.
We do not rely on the native signed integer type as we rely on math operations that are not currently implemented by the Cairo core lib.
i32
i32i32 {
val: u32
sign: bool
}The i32 type is used for storing unshifted limits.
i128
i128i128 {
val: u128
sign: bool
}The i128 type is used for storing liquidity deltas.
i256
i256i256 {
val: u256
sign: bool
}The i256 type is used for storing token amount deltas.
Limit shifting
For simplicity and efficiency, limits are stored in shifted form by mapping unshifted i32 limits to shifted u32 limits.
Specifically, an offset equal to the largest possible multiple of the market width is applied for shifting and unshifting.
Last updated