Storage Formats
Price Storage Format and conversion
export function encodePriceSqrt(reserve1: bigint, reserve0: bigint): bigint
{
BigNumber.set({DECIMAL_PLACES: 60})
let result = BigNumber(reserve1.toString())
.div(reserve0.toString())
.sqrt()
.multipliedBy(new BigNumber(2).pow(96))
.integerValue(3);
return BigInt(result.toFixed(0));
}
export function encodePriceSqrt(price: number): bigint
{
BigNumber.set({DECIMAL_PLACES: 60})
let result = BigNumber(price.toString())
.sqrt()
.multipliedBy(new BigNumber(2).pow(96))
.integerValue(3);
return BigInt(result.toFixed(0));
}Last updated