From d5b641227fdf784ad4edb57f02aee7e028907e1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Alexandre=20Vaz=20Ferreira?= <30525975+joaoavf@users.noreply.github.com> Date: Fri, 14 Jul 2023 00:20:32 +0000 Subject: [PATCH 1/2] Checkpoint of improving logic of ratios --- contracts/bridges/Gamma/GammaDepositBridge.sol | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/bridges/Gamma/GammaDepositBridge.sol b/contracts/bridges/Gamma/GammaDepositBridge.sol index 99f681d..46f476d 100644 --- a/contracts/bridges/Gamma/GammaDepositBridge.sol +++ b/contracts/bridges/Gamma/GammaDepositBridge.sol @@ -87,10 +87,10 @@ contract GammaDepositBridge is IGammaDeposit { amountsIn[1] ); - if (startB > amountsIn[0]) { + if (startA > amountsIn[0]) { return (amountsIn[0], Math.min(amountsIn[1], endB)); } - else if (startA > amountsIn[1]) { + else if (startB > amountsIn[1]) { return (Math.min(amountsIn[0], endA), amountsIn[1]); } else { From b2a8cb1d25e5facb874d1ff44cd50c02a37167d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Alexandre=20Vaz=20Ferreira?= <30525975+joaoavf@users.noreply.github.com> Date: Fri, 14 Jul 2023 00:31:44 +0000 Subject: [PATCH 2/2] Little hack to deal with unprecise Math --- contracts/bridges/Gamma/GammaDepositBridge.sol | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contracts/bridges/Gamma/GammaDepositBridge.sol b/contracts/bridges/Gamma/GammaDepositBridge.sol index 46f476d..0d21f7b 100644 --- a/contracts/bridges/Gamma/GammaDepositBridge.sol +++ b/contracts/bridges/Gamma/GammaDepositBridge.sol @@ -85,16 +85,17 @@ contract GammaDepositBridge is IGammaDeposit { hypervisorAddress, tokens[1], amountsIn[1] - ); - + ); + + // * 9999 / 10000 is a hack to deal with unprecise math and avoid "improper ratio bug") if (startA > amountsIn[0]) { - return (amountsIn[0], Math.min(amountsIn[1], endB)); + return (amountsIn[0], Math.min(amountsIn[1], endB * 9999/10000 )); } else if (startB > amountsIn[1]) { - return (Math.min(amountsIn[0], endA), amountsIn[1]); + return (Math.min(amountsIn[0], endA * 9999/10000 ), amountsIn[1]); } else { - return (Math.min(amountsIn[0], endA), Math.min(amountsIn[1], endB)); + return (Math.min(amountsIn[0], endA * 9999/10000 ), Math.min(amountsIn[1], endB * 9999/10000 )); } } }