From dc854bcbf99959ecbba0d37f336e2b6e98d1d12a Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Mon, 2 Dec 2024 00:50:31 +0100 Subject: [PATCH 1/2] round down when calculating credits from balances --- contracts/contracts/token/OUSD.sol | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/contracts/contracts/token/OUSD.sol b/contracts/contracts/token/OUSD.sol index 8bd07380bf..21880e350e 100644 --- a/contracts/contracts/token/OUSD.sol +++ b/contracts/contracts/token/OUSD.sol @@ -432,13 +432,8 @@ contract OUSD is Governable { returns (uint256 rebasingCredits, uint256 actualBalance) { uint256 rebasingCreditsPerTokenMem = rebasingCreditsPerToken_; - // Rounds up, because we need to ensure that accounts always have - // at least the balance that they should have. - // Note this should always be used on an absolute account value, - // not on a possibly negative diff, because then the rounding would be wrong. - rebasingCredits = - ((_balance) * rebasingCreditsPerTokenMem + 1e18 - 1) / - 1e18; + // Round down in favour of the protocol + rebasingCredits = ((_balance) * rebasingCreditsPerTokenMem) / 1e18; actualBalance = (rebasingCredits * 1e18) / rebasingCreditsPerTokenMem; } From 63ee2ba0c5f3b96b9c672f3d67d07c4cd5981cef Mon Sep 17 00:00:00 2001 From: Domen Grabec Date: Mon, 2 Dec 2024 13:57:58 +0100 Subject: [PATCH 2/2] Revert "round down when calculating credits from balances" This reverts commit dc854bcbf99959ecbba0d37f336e2b6e98d1d12a. --- contracts/contracts/token/OUSD.sol | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contracts/contracts/token/OUSD.sol b/contracts/contracts/token/OUSD.sol index 21880e350e..8bd07380bf 100644 --- a/contracts/contracts/token/OUSD.sol +++ b/contracts/contracts/token/OUSD.sol @@ -432,8 +432,13 @@ contract OUSD is Governable { returns (uint256 rebasingCredits, uint256 actualBalance) { uint256 rebasingCreditsPerTokenMem = rebasingCreditsPerToken_; - // Round down in favour of the protocol - rebasingCredits = ((_balance) * rebasingCreditsPerTokenMem) / 1e18; + // Rounds up, because we need to ensure that accounts always have + // at least the balance that they should have. + // Note this should always be used on an absolute account value, + // not on a possibly negative diff, because then the rounding would be wrong. + rebasingCredits = + ((_balance) * rebasingCreditsPerTokenMem + 1e18 - 1) / + 1e18; actualBalance = (rebasingCredits * 1e18) / rebasingCreditsPerTokenMem; }