Skip to content

Commit

Permalink
Added missing bigAdd function
Browse files Browse the repository at this point in the history
  • Loading branch information
Sniezka1927 committed Apr 4, 2024
1 parent 8168467 commit 5372418
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contracts/math/clamm.ral
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ Contract CLAMM(
if (roundingUp) {
let denominator = mul(sqrtPriceA, sqrtPriceB, SqrtPriceScale)
let mut deltaXUp = uints.bigMul512(nominator, one(SqrtPriceScale))
deltaXUp = uints.bigAdd512(deltaXUp, uints.toU512(denominator - 1))
deltaXUp = uints.bigAdd(deltaXUp, denominator - 1)
deltaXUp = uints.bigDiv512(deltaXUp, denominator, 1)
deltaXUp = uints.bigAdd512(deltaXUp, uints.toU512(almostOne(SqrtPriceScale)))
deltaXUp = uints.bigAdd(deltaXUp, almostOne(SqrtPriceScale))
deltaXUp = uints.bigDiv512(deltaXUp, one(SqrtPriceScale), 1)
return uints.toU256(deltaXUp)
} else {
Expand Down
6 changes: 6 additions & 0 deletions contracts/math/uints.ral
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Contract Uints () {
}
}

pub fn bigAdd(a: U512, b: U256) -> U512 {
let (lower, overflow) = overflowingAdd(a.lower, b)
let higher = wrappingAdd(a.higher, overflow)
return U512 { lower: lower, higher: higher }
}

pub fn bigAdd512(a: U512, b: U512) -> U512 {
let (aLowerBLower, overflow) = overflowingAdd(a.lower, b.lower)
let aHigherBHigherOverflow = wrappingAdd(wrappingAdd(a.higher, b.higher), overflow)
Expand Down

0 comments on commit 5372418

Please sign in to comment.