Skip to content

Commit

Permalink
Remove unnecessary division
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoplavkov committed Oct 21, 2024
1 parent e1a19a1 commit 44638e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libraries/math/src/pool_math.sw
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ fn k(
let _y: u256 = y * ONE_E_18 / pow_decimals_y;
let _a: u256 = (_x * _y) / ONE_E_18;
let _b: u256 = ((_x * _x) / ONE_E_18 + (_y * _y) / ONE_E_18);
return _a * _b / ONE_E_18; // x3y+y3x >= k
return _a * _b; // x3y+y3x >= k
} else {
return x * y; // xy >= k
}
}

// TODO: combine with `k` above?
fn f(x_0: u256, y: u256) -> u256 {
x_0 * (y * y / ONE_E_18 * y / ONE_E_18) / ONE_E_18 + (x_0 * x_0 / ONE_E_18 * x_0 / ONE_E_18) * y / ONE_E_18
x_0 * (y * y / ONE_E_18 * y / ONE_E_18) + (x_0 * x_0 / ONE_E_18 * x_0 / ONE_E_18) * y
}

fn d(x_0: u256, y: u256) -> u256 {
Expand All @@ -269,10 +269,10 @@ fn get_y(x_0: u256, xy: u256, y: u256) -> u256 {
let y_prev = y;
let k = f(x_0, y);
if k < xy {
let dy = (xy - k) * ONE_E_18 / d(x_0, y);
let dy = (xy - k) / d(x_0, y);
y = y + dy;
} else {
let dy = (k - xy) * ONE_E_18 / d(x_0, y);
let dy = (k - xy) / d(x_0, y);
y = y - dy;
}
if y > y_prev {
Expand Down
1 change: 1 addition & 0 deletions tools/fetch_abis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ git clone [email protected]:mira-amm/mira-v1-core.git
echo "Building Mira v1 core"

cd mira-v1-core
git checkout mainnet-deployment
forc build --release

cd ../..
Expand Down

0 comments on commit 44638e9

Please sign in to comment.