Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions contracts/contracts/token/OUSD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,31 +404,32 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {
}

bool isNonRebasingAccount = _isNonRebasingAccount(_account);
// creditAmount is rounded down, so may remove fewer credits
uint256 creditAmount = _amount.mulTruncate(_creditsPerToken(_account));
uint256 currentCredits = _creditBalances[_account];

// Remove the credits, burning rounding errors
if (
currentCredits == creditAmount || currentCredits - 1 == creditAmount
) {
// Handle dust from rounding

if (_amount == balanceOf(_account)) {
// Remove all account credits, burning rounding dust
_creditBalances[_account] = 0;
} else if (currentCredits > creditAmount) {
_creditBalances[_account] = _creditBalances[_account].sub(
creditAmount
);
_creditBalances[_account] -= creditAmount;
} else {
revert("Remove exceeds balance");
}

// Remove from the credit tallies and non-rebasing supply
if (isNonRebasingAccount) {
nonRebasingSupply = nonRebasingSupply.sub(_amount);
nonRebasingSupply -= _amount;
} else {
_rebasingCredits = _rebasingCredits.sub(creditAmount);
// Given that creditAmount could be rounded down, this could leave
// the contract with slightly more rebasing credits. This is the
// best side to round to, since this slows rebasing rather than
// speed it up
_rebasingCredits -= creditAmount;
}

_totalSupply = _totalSupply.sub(_amount);
_totalSupply -= _amount;

emit Transfer(_account, address(0), _amount);
}
Expand Down
4 changes: 1 addition & 3 deletions contracts/test/vault/redeem.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,7 @@ describe("Vault Redeem", function () {
await dai.connect(anna).approve(vault.address, newDaiBalance);
await vault.connect(anna).mint(dai.address, newDaiBalance, 0);
await vault.connect(anna).redeemAll(0);
// FIXME - this is failing as a balance of 1 is being returned instead of 0
// Tracking issue https://github.com/OriginProtocol/origin-dollar/issues/1495
// await expect(anna).has.a.balanceOf("0.00", ousd);
await expect(anna).has.a.balanceOf("0.00", ousd);
});

it("Should respect minimum unit amount argument in redeem", async () => {
Expand Down