From 44638e9a28d70998d990d7e43027eaf069d8e46f Mon Sep 17 00:00:00 2001 From: mpoplavkov Date: Mon, 21 Oct 2024 20:49:49 +0100 Subject: [PATCH] Remove unnecessary division --- libraries/math/src/pool_math.sw | 8 ++++---- tools/fetch_abis.sh | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/math/src/pool_math.sw b/libraries/math/src/pool_math.sw index 8bb07d2..323c470 100644 --- a/libraries/math/src/pool_math.sw +++ b/libraries/math/src/pool_math.sw @@ -247,7 +247,7 @@ 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 } @@ -255,7 +255,7 @@ fn 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 { @@ -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 { diff --git a/tools/fetch_abis.sh b/tools/fetch_abis.sh index ca70ffe..6295159 100755 --- a/tools/fetch_abis.sh +++ b/tools/fetch_abis.sh @@ -11,6 +11,7 @@ git clone git@github.com:mira-amm/mira-v1-core.git echo "Building Mira v1 core" cd mira-v1-core +git checkout mainnet-deployment forc build --release cd ../..