Skip to content

Commit

Permalink
chore: remove Unsafe*
Browse files Browse the repository at this point in the history
  • Loading branch information
r3v4s committed Mar 7, 2024
1 parent 4dc5b34 commit c6b53ab
Show file tree
Hide file tree
Showing 19 changed files with 118 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/big/int256/int256.gno
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func FromDecimal(s string) (*Int, error) {
return new(Int).SetString(s)
}

func UnsafeFromDecimal(s string) *Int {
func MustFromDecimal(s string) *Int {
z, err := FromDecimal(s)
if err != nil {
panic(err)
Expand Down
26 changes: 6 additions & 20 deletions packages/big/uint256/uint256.gno
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,6 @@ func (z *Uint) Add(x, y *Uint) *Uint {
return z
}

func (z *Uint) UnsafeAdd(x, y *Uint) *Uint {
var carry uint64
z.arr[0], carry = Add64(x.arr[0], y.arr[0], 0)
z.arr[1], carry = Add64(x.arr[1], y.arr[1], carry)
z.arr[2], carry = Add64(x.arr[2], y.arr[2], carry)
z.arr[3], _ = Add64(x.arr[3], y.arr[3], carry)
// Different from the original implementation!
// // We panic on overflow
// if carry != 0 {
// panic("U256 Add overflow")
// }
return z
}

// AddOverflow sets z to the sum x+y, and returns z and whether overflow occurred
func (z *Uint) AddOverflow(x, y *Uint) (*Uint, bool) {
var carry uint64
Expand Down Expand Up @@ -850,13 +836,13 @@ func FromDecimal(decimal string) (*Uint, error) {
return &z, nil
}

// UnsafeFromDecimal is a convenience-constructor to create an Uint from a
// decimal (base 10) string. Numbers larger than 256 bits are not accepted.
// panic if the input is invalid
func UnsafeFromDecimal(decimal string) *Uint {
// MustFromDecimal is a convenience-constructor to create an Int from a
// decimal (base 10) string.
// Returns a new Int and panics if any error occurred.
func MustFromDecimal(decimal string) *Uint {
var z Uint
if err := z.SetFromDecimal(decimal); err != nil {
panic("UNSAFE FROM DECIMAL")
panic(err)
}
return &z
}
Expand Down Expand Up @@ -972,7 +958,7 @@ func (z *Uint) fromDecimal(bs string) error {
z.SetUint64(num)
} else {
base := NewUint(num)
z.UnsafeAdd(z, base.Mul(base, mult))
z.Add(z, base.Mul(base, mult))
}
// Chop off another 19 characters
if remaining > 19 {
Expand Down
42 changes: 21 additions & 21 deletions packages/big/uint256/uint256_overflow_calculation.gno
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
package uint256

func fullMul(
x Uint,
y Uint,
) (Uint, Uint) { // l, h
mm := new(*Uint).MulMod(x, y, UnsafeFromDecimal(MAX_UINT256))
x *Uint,
y *Uint,
) (*Uint, *Uint) { // l, h
mm := new(Uint).MulMod(x, y, MustFromDecimal(MAX_UINT256))

l := new(Uint).Mul(x, y)
h := new(Uint).Sub(mm, l)
Expand All @@ -18,10 +18,10 @@ func fullMul(
}

func fullDiv(
l Uint,
h Uint,
d Uint,
) Uint {
l *Uint,
h *Uint,
d *Uint,
) *Uint {
// uint256 pow2 = d & -d;
// d
_negD := new(Uint).Neg(d)
Expand All @@ -31,10 +31,10 @@ func fullDiv(

_negPow2 := new(Uint).Neg(pow2)

value1 := new(Uint).Div(_negPow2, pow2) // (-pow2) / pow2
value2 := new(Uint).UnsafeAdd(value1, One()) // (-pow2) / pow2 + 1)
value3 := new(Uint).Mul(h, value2) // h * ((-pow2) / pow2 + 1);
l = new(Uint).UnsafeAdd(l, value3)
value1 := new(Uint).Div(_negPow2, pow2) // (-pow2) / pow2
value2 := new(Uint).Add(value1, One()) // (-pow2) / pow2 + 1)
value3 := new(Uint).Mul(h, value2) // h * ((-pow2) / pow2 + 1);
l = new(Uint).Add(l, value3)

r := One()
for i := 0; i < 8; i++ {
Expand All @@ -47,10 +47,10 @@ func fullDiv(
}

func MulDiv(
x Uint,
y Uint,
d Uint,
) Uint {
x *Uint,
y *Uint,
d *Uint,
) *Uint {
l, h := fullMul(x, y)
mm := new(Uint).MulMod(x, y, d)

Expand All @@ -71,25 +71,25 @@ func MulDiv(
}

func DivRoundingUp(
x Uint,
y Uint,
) Uint {
x *Uint,
y *Uint,
) *Uint {
div := new(Uint).Div(x, y)

mod := new(Uint).Mod(x, y)
return new(Uint).Add(div, gt(mod, Zero()))
}

// HELPERs
func lt(x, y Uint) Uint {
func lt(x, y *Uint) *Uint {
if x.Lt(y) {
return One()
} else {
return Zero()
}
}

func gt(x, y Uint) Uint {
func gt(x, y *Uint) *Uint {
if x.Gt(y) {
return One()
} else {
Expand Down
5 changes: 3 additions & 2 deletions packages/big/uint256/uint256_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import (
)

func TestFuncs(t *testing.T) {
x := UnsafeFromDecimal("79188548433007205424747178")
y := UnsafeFromDecimal("130406999485845074795897568971")
x := MustFromDecimal("79188548433007205424747178")
y := MustFromDecimal("130406999485845074795897568971")

z := new(Uint).Add(x, y)
println("z:", z.ToString()) // 130486188034278082001322316149

if z.ToString() != "130486188034278082001322316149" {
t.Error("Expected 130486188034278082001322316149, got ", z.ToString())
Expand Down
6 changes: 3 additions & 3 deletions packages/common/liquidity_amounts.gno
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func toAscendingOrder(a, b *u256.Uint) (*u256.Uint, *u256.Uint) {
func calcIntermediateValue(sqrtRatioAX96, sqrtRatioBX96 *u256.Uint) *u256.Uint {

res := new(u256.Uint).Mul(sqrtRatioAX96, sqrtRatioBX96)
res = res.Div(res, u256.UnsafeFromDecimal(consts.Q96))
res = res.Div(res, u256.MustFromDecimal(consts.Q96))
return res
}

Expand All @@ -42,7 +42,7 @@ func computeLiquidityForAmount1(sqrtRatioAX96, sqrtRatioBX96, amount1 *u256.Uint
sqrtRatioAX96, sqrtRatioBX96 = toAscendingOrder(sqrtRatioAX96, sqrtRatioBX96)
diff := new(u256.Uint).Sub(sqrtRatioBX96, sqrtRatioAX96)

res := new(u256.Uint).Mul(amount1, u256.UnsafeFromDecimal(consts.Q96))
res := new(u256.Uint).Mul(amount1, u256.MustFromDecimal(consts.Q96))
res = res.Div(res, diff)
return res
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func computeAmount1ForLiquidity(sqrtRatioAX96, sqrtRatioBX96, liquidity *u256.Ui
diff := new(u256.Uint).Sub(sqrtRatioBX96, sqrtRatioAX96)

res := new(u256.Uint).Mul(liquidity, diff)
res = res.Div(res, u256.UnsafeFromDecimal(consts.Q96))
res = res.Div(res, u256.MustFromDecimal(consts.Q96))

return res
}
Expand Down
68 changes: 34 additions & 34 deletions packages/common/tick_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@ import (
)

var tickRatioMap = map[int32]*u256.Uint{
0x1: u256.UnsafeFromDecimal("340265354078544963557816517032075149313"), // 0xfffcb933bd6fad37aa2d162d1a594001,
0x2: u256.UnsafeFromDecimal("340248342086729790484326174814286782778"), // 0xfff97272373d413259a46990580e213a,
0x4: u256.UnsafeFromDecimal("340214320654664324051920982716015181260"), // 0xfff2e50f5f656932ef12357cf3c7fdcc,
0x8: u256.UnsafeFromDecimal("340146287995602323631171512101879684304"), // 0xffe5caca7e10e4e61c3624eaa0941cd0,
0x10: u256.UnsafeFromDecimal("340010263488231146823593991679159461444"), // 0xffcb9843d60f6159c9db58835c926644,
0x20: u256.UnsafeFromDecimal("339738377640345403697157401104375502016"), // 0xff973b41fa98c081472e6896dfb254c0,
0x40: u256.UnsafeFromDecimal("339195258003219555707034227454543997025"), // 0xff2ea16466c96a3843ec78b326b52861,
0x80: u256.UnsafeFromDecimal("338111622100601834656805679988414885971"), // 0xfe5dee046a99a2a811c461f1969c3053,
0x100: u256.UnsafeFromDecimal("335954724994790223023589805789778977700"), // 0xfcbe86c7900a88aedcffc83b479aa3a4,
0x200: u256.UnsafeFromDecimal("331682121138379247127172139078559817300"), // 0xf987a7253ac413176f2b074cf7815e54,
0x400: u256.UnsafeFromDecimal("323299236684853023288211250268160618739"), // 0xf3392b0822b70005940c7a398e4b70f3,
0x800: u256.UnsafeFromDecimal("307163716377032989948697243942600083929"), // 0xe7159475a2c29b7443b29c7fa6e889d9,
0x1000: u256.UnsafeFromDecimal("277268403626896220162999269216087595045"), // 0xd097f3bdfd2022b8845ad8f792aa5825,
0x2000: u256.UnsafeFromDecimal("225923453940442621947126027127485391333"), // 0xa9f746462d870fdf8a65dc1f90e061e5,
0x4000: u256.UnsafeFromDecimal("149997214084966997727330242082538205943"), // 0x70d869a156d2a1b890bb3df62baf32f7,
0x8000: u256.UnsafeFromDecimal("66119101136024775622716233608466517926"), // 0x31be135f97d08fd981231505542fcfa6,
0x10000: u256.UnsafeFromDecimal("12847376061809297530290974190478138313"), // 0x9aa508b5b7a84e1c677de54f3e99bc9,
0x20000: u256.UnsafeFromDecimal("485053260817066172746253684029974020"), // 0x5d6af8dedb81196699c329225ee604,
0x40000: u256.UnsafeFromDecimal("691415978906521570653435304214168"), // 0x2216e584f5fa1ea926041bedfe98,
0x80000: u256.UnsafeFromDecimal("1404880482679654955896180642"), // 0x48a170391f7dc42444e8fa2,
0x1: u256.MustFromDecimal("340265354078544963557816517032075149313"), // 0xfffcb933bd6fad37aa2d162d1a594001,
0x2: u256.MustFromDecimal("340248342086729790484326174814286782778"), // 0xfff97272373d413259a46990580e213a,
0x4: u256.MustFromDecimal("340214320654664324051920982716015181260"), // 0xfff2e50f5f656932ef12357cf3c7fdcc,
0x8: u256.MustFromDecimal("340146287995602323631171512101879684304"), // 0xffe5caca7e10e4e61c3624eaa0941cd0,
0x10: u256.MustFromDecimal("340010263488231146823593991679159461444"), // 0xffcb9843d60f6159c9db58835c926644,
0x20: u256.MustFromDecimal("339738377640345403697157401104375502016"), // 0xff973b41fa98c081472e6896dfb254c0,
0x40: u256.MustFromDecimal("339195258003219555707034227454543997025"), // 0xff2ea16466c96a3843ec78b326b52861,
0x80: u256.MustFromDecimal("338111622100601834656805679988414885971"), // 0xfe5dee046a99a2a811c461f1969c3053,
0x100: u256.MustFromDecimal("335954724994790223023589805789778977700"), // 0xfcbe86c7900a88aedcffc83b479aa3a4,
0x200: u256.MustFromDecimal("331682121138379247127172139078559817300"), // 0xf987a7253ac413176f2b074cf7815e54,
0x400: u256.MustFromDecimal("323299236684853023288211250268160618739"), // 0xf3392b0822b70005940c7a398e4b70f3,
0x800: u256.MustFromDecimal("307163716377032989948697243942600083929"), // 0xe7159475a2c29b7443b29c7fa6e889d9,
0x1000: u256.MustFromDecimal("277268403626896220162999269216087595045"), // 0xd097f3bdfd2022b8845ad8f792aa5825,
0x2000: u256.MustFromDecimal("225923453940442621947126027127485391333"), // 0xa9f746462d870fdf8a65dc1f90e061e5,
0x4000: u256.MustFromDecimal("149997214084966997727330242082538205943"), // 0x70d869a156d2a1b890bb3df62baf32f7,
0x8000: u256.MustFromDecimal("66119101136024775622716233608466517926"), // 0x31be135f97d08fd981231505542fcfa6,
0x10000: u256.MustFromDecimal("12847376061809297530290974190478138313"), // 0x9aa508b5b7a84e1c677de54f3e99bc9,
0x20000: u256.MustFromDecimal("485053260817066172746253684029974020"), // 0x5d6af8dedb81196699c329225ee604,
0x40000: u256.MustFromDecimal("691415978906521570653435304214168"), // 0x2216e584f5fa1ea926041bedfe98,
0x80000: u256.MustFromDecimal("1404880482679654955896180642"), // 0x48a170391f7dc42444e8fa2,
}

var binaryLogConsts = [8]*u256.Uint{
u256.UnsafeFromDecimal("0"), // 0x0,
u256.UnsafeFromDecimal("3"), // 0x3,
u256.UnsafeFromDecimal("15"), // 0xF,
u256.UnsafeFromDecimal("255"), // 0xFF,
u256.UnsafeFromDecimal("65535"), // 0xFFFF,
u256.UnsafeFromDecimal("4294967295"), // 0xFFFFFFFF,
u256.UnsafeFromDecimal("18446744073709551615"), // 0xFFFFFFFFFFFFFFFF,
u256.UnsafeFromDecimal("340282366920938463463374607431768211455"), // 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
u256.MustFromDecimal("0"), // 0x0,
u256.MustFromDecimal("3"), // 0x3,
u256.MustFromDecimal("15"), // 0xF,
u256.MustFromDecimal("255"), // 0xFF,
u256.MustFromDecimal("65535"), // 0xFFFF,
u256.MustFromDecimal("4294967295"), // 0xFFFFFFFF,
u256.MustFromDecimal("18446744073709551615"), // 0xFFFFFFFFFFFFFFFF,
u256.MustFromDecimal("340282366920938463463374607431768211455"), // 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF,
}

var (
shift1By32Left = u256.UnsafeFromDecimal("4294967296") // (1 << 32)
shift1By32Left = u256.MustFromDecimal("4294967296") // (1 << 32)
)

func TickMathGetSqrtRatioAtTick(tick int32) *u256.Uint { // uint160 sqrtPriceX96
absTick := abs(tick)
ratio := u256.UnsafeFromDecimal("340282366920938463463374607431768211456") // consts.Q128
ratio := u256.MustFromDecimal("340282366920938463463374607431768211456") // consts.Q128

for mask, value := range tickRatioMap {
if absTick&mask != 0 {
Expand All @@ -56,7 +56,7 @@ func TickMathGetSqrtRatioAtTick(tick int32) *u256.Uint { // uint160 sqrtPriceX96
}

if tick > 0 {
_maxUint256 := u256.UnsafeFromDecimal("115792089237316195423570985008687907853269984665640564039457584007913129639935") // consts.MAX_UINT256
_maxUint256 := u256.MustFromDecimal("115792089237316195423570985008687907853269984665640564039457584007913129639935") // consts.MAX_UINT256
_tmp := new(u256.Uint).Div(_maxUint256, ratio)
ratio = _tmp.Clone()
}
Expand Down Expand Up @@ -160,17 +160,17 @@ func calculateLog2(msb, ratio *u256.Uint) *i256.Int {
func getTickValue(log2 *i256.Int, sqrtPriceX96 *u256.Uint) int32 {
// ref: https://github.com/Uniswap/v3-core/issues/500
// 2^64 / log2 (√1.0001) = 255738958999603826347141
log_sqrt10001 := i256.Zero().Mul(log2, i256.UnsafeFromDecimal("255738958999603826347141"))
log_sqrt10001 := i256.Zero().Mul(log2, i256.MustFromDecimal("255738958999603826347141"))

// ref: https://ethereum.stackexchange.com/questions/113844/how-does-uniswap-v3s-logarithm-library-tickmath-sol-work/113912#113912
// 0.010000497 x 2^128 = 3402992956809132418596140100660247210
tickLow256 := i256.Zero().Sub(log_sqrt10001, i256.UnsafeFromDecimal("3402992956809132418596140100660247210"))
tickLow256 := i256.Zero().Sub(log_sqrt10001, i256.MustFromDecimal("3402992956809132418596140100660247210"))
tickLow256 = tickLow256.Rsh(tickLow256, 128)
tickLow := int32(tickLow256.Int64())

// ref: https://ethereum.stackexchange.com/questions/113844/how-does-uniswap-v3s-logarithm-library-tickmath-sol-work/113912#113912
// 0.856 x 2^128 = 291339464771989622907027621153398088495
tickHi256 := i256.Zero().Add(log_sqrt10001, i256.UnsafeFromDecimal("291339464771989622907027621153398088495"))
tickHi256 := i256.Zero().Add(log_sqrt10001, i256.MustFromDecimal("291339464771989622907027621153398088495"))
tickHi256 = tickHi256.Rsh(tickHi256, 128)
tickHi := int32(tickHi256.Int64())

Expand Down
6 changes: 3 additions & 3 deletions pool/_RPC_dry.gno
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func DrySwap(
slot0Start := pool.slot0

if zeroForOne {
min_sqrt_ratio := u256.UnsafeFromDecimal(consts.MIN_SQRT_RATIO)
min_sqrt_ratio := u256.MustFromDecimal(consts.MIN_SQRT_RATIO)
cond1 := sqrtPriceLimitX96.Lt(slot0Start.sqrtPriceX96)
cond2 := sqrtPriceLimitX96.Gt(min_sqrt_ratio)

if !(cond1 && cond2) {
return "0", "0", false
}
} else {
max_sqrt_ratio := u256.UnsafeFromDecimal(consts.MAX_SQRT_RATIO)
max_sqrt_ratio := u256.MustFromDecimal(consts.MAX_SQRT_RATIO)
cond1 := sqrtPriceLimitX96.Gt(slot0Start.sqrtPriceX96)
cond2 := sqrtPriceLimitX96.Lt(max_sqrt_ratio)

Expand Down Expand Up @@ -153,7 +153,7 @@ func DrySwap(

// update global fee tracker
if state.liquidity.Gt(u256.Zero()) {
_q128 := u256.UnsafeFromDecimal(consts.Q128)
_q128 := u256.MustFromDecimal(consts.Q128)

value1 := new(u256.Uint).Mul(step.feeAmount, _q128)
value2 := new(u256.Uint).Div(value1, state.liquidity)
Expand Down
14 changes: 7 additions & 7 deletions pool/bit_math.gno
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ type bitShift struct {

func bitMathMostSignificantBit(x *u256.Uint) uint8 {
shifts := []bitShift{
{u256.UnsafeFromDecimal(consts.Q128), 128}, // 2^128
{u256.UnsafeFromDecimal(consts.Q64), 64}, // 2^64
{u256.MustFromDecimal(consts.Q128), 128}, // 2^128
{u256.MustFromDecimal(consts.Q64), 64}, // 2^64
{u256.NewUint(0x100000000), 32},
{u256.NewUint(0x10000), 16},
{u256.NewUint(0x100), 8},
Expand All @@ -36,11 +36,11 @@ func bitMathMostSignificantBit(x *u256.Uint) uint8 {

func bitMathLeastSignificantBit(x *u256.Uint) uint8 {
shifts := []bitShift{
{u256.UnsafeFromDecimal(consts.MAX_UINT128), 128},
{u256.UnsafeFromDecimal(consts.MAX_UINT64), 64},
{u256.UnsafeFromDecimal(consts.MAX_UINT32), 32},
{u256.UnsafeFromDecimal(consts.MAX_UINT16), 16},
{u256.UnsafeFromDecimal(consts.MAX_UINT8), 8},
{u256.MustFromDecimal(consts.MAX_UINT128), 128},
{u256.MustFromDecimal(consts.MAX_UINT64), 64},
{u256.MustFromDecimal(consts.MAX_UINT32), 32},
{u256.MustFromDecimal(consts.MAX_UINT16), 16},
{u256.MustFromDecimal(consts.MAX_UINT8), 8},
{u256.NewUint(0xf), 4},
{u256.NewUint(0x3), 2},
{u256.NewUint(0x1), 1},
Expand Down
6 changes: 3 additions & 3 deletions pool/pool.gno
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@ func Swap(
var feeGrowthGlobalX128 *u256.Uint

if zeroForOne {
min_sqrt_ratio := u256.UnsafeFromDecimal(consts.MIN_SQRT_RATIO)
min_sqrt_ratio := u256.MustFromDecimal(consts.MIN_SQRT_RATIO)
cond1 := sqrtPriceLimitX96.Lt(slot0Start.sqrtPriceX96)
cond2 := sqrtPriceLimitX96.Gt(min_sqrt_ratio)
require(cond1 && cond2, ufmt.Sprintf("[POOL] pool.gno__Swap() || sqrtPriceLimitX96(%s) < slot0Start.sqrtPriceX96(%s) && sqrtPriceLimitX96(%s) > consts.MIN_SQRT_RATIO(%s)", sqrtPriceLimitX96.ToString(), slot0Start.sqrtPriceX96.ToString(), sqrtPriceLimitX96.ToString(), consts.MIN_SQRT_RATIO))

feeProtocol = slot0Start.feeProtocol % 16
feeGrowthGlobalX128 = pool.feeGrowthGlobal0X128.Clone()
} else {
max_sqrt_ratio := u256.UnsafeFromDecimal(consts.MAX_SQRT_RATIO)
max_sqrt_ratio := u256.MustFromDecimal(consts.MAX_SQRT_RATIO)
cond1 := sqrtPriceLimitX96.Gt(slot0Start.sqrtPriceX96)
cond2 := sqrtPriceLimitX96.Lt(max_sqrt_ratio)
require(cond1 && cond2, ufmt.Sprintf("[POOL] pool.gno__Swap() || sqrtPriceLimitX96(%s) > slot0Start.sqrtPriceX96(%s) && sqrtPriceLimitX96(%s) < consts.MAX_SQRT_RATIO(%s)", sqrtPriceLimitX96.ToString(), slot0Start.sqrtPriceX96.ToString(), sqrtPriceLimitX96.ToString(), consts.MAX_SQRT_RATIO))
Expand Down Expand Up @@ -333,7 +333,7 @@ func Swap(

// update global fee tracker
if state.liquidity.Gt(u256.Zero()) {
_q128 := u256.UnsafeFromDecimal(consts.Q128)
_q128 := u256.MustFromDecimal(consts.Q128)

value1 := new(u256.Uint).Mul(step.feeAmount, _q128)
value2 := new(u256.Uint).Div(value1, state.liquidity)
Expand Down
4 changes: 2 additions & 2 deletions pool/position.gno
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ func positionUpdate(

tokensOwed0 := new(u256.Uint).Sub(feeGrowthInside0X128, self.feeGrowthInside0LastX128)
tokensOwed0 = tokensOwed0.Mul(tokensOwed0, self.liquidity)
tokensOwed0 = tokensOwed0.Div(tokensOwed0, u256.UnsafeFromDecimal(consts.Q128))
tokensOwed0 = tokensOwed0.Div(tokensOwed0, u256.MustFromDecimal(consts.Q128))

tokensOwed1 := new(u256.Uint).Sub(feeGrowthInside1X128, self.feeGrowthInside1LastX128)
tokensOwed1 = tokensOwed1.Mul(tokensOwed1, self.liquidity)
tokensOwed1 = tokensOwed1.Div(tokensOwed1, u256.UnsafeFromDecimal(consts.Q128))
tokensOwed1 = tokensOwed1.Div(tokensOwed1, u256.MustFromDecimal(consts.Q128))

if !(liquidityDelta.IsZero()) {
self.liquidity = liquidityNext
Expand Down
Loading

0 comments on commit c6b53ab

Please sign in to comment.