Skip to content

Commit

Permalink
AccountRebasingEnalbed/Disabled whenever appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Dec 20, 2023
1 parent ab16bb0 commit 92e034d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
15 changes: 10 additions & 5 deletions contracts/contracts/token/OUSD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {
uint256 rebasingCredits,
uint256 rebasingCreditsPerToken
);
event RebaseOptIn(address account);
event RebaseOptOut(address account);
event AccountRebasingEnabled(address account);
event AccountRebasingDisabled(address account);

enum RebaseOptions {
NotSet,
Expand Down Expand Up @@ -471,6 +471,7 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {
*/
function _ensureRebasingMigration(address _account) internal {
if (nonRebasingCreditsPerToken[_account] == 0) {
emit AccountRebasingDisabled(_account);
if (_creditBalances[_account] == 0) {
// Since there is no existing balance, we can directly set to
// high resolution, and do not have to do any other bookkeeping
Expand All @@ -497,7 +498,11 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {
* to upside and downside.
* @param _account Address of the account.
*/
function governanceRebaseOptIn(address _account) public nonReentrant onlyGovernor {
function governanceRebaseOptIn(address _account)
public
nonReentrant
onlyGovernor
{
_rebaseOptIn(_account);
}

Expand Down Expand Up @@ -531,7 +536,7 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {

// Delete any fixed credits per token
delete nonRebasingCreditsPerToken[_account];
emit RebaseOptIn(_account);
emit AccountRebasingEnabled(_account);
}

/**
Expand All @@ -551,7 +556,7 @@ contract OUSD is Initializable, InitializableERC20Detailed, Governable {

// Mark explicitly opted out of rebasing
rebaseState[msg.sender] = RebaseOptions.OptOut;
emit RebaseOptOut(msg.sender);
emit AccountRebasingDisabled(msg.sender);
}

/**
Expand Down
18 changes: 13 additions & 5 deletions contracts/test/token/ousd.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ describe("Token", function () {

const rebaseTx = await mockNonRebasing.rebaseOptIn();
await expect(rebaseTx)
.to.emit(ousd, "RebaseOptIn")
.withArgs(mockNonRebasing.address);
.to.emit(ousd, "AccountRebasingEnabled")
.withArgs(mockNonRebasing.address);

await expect(mockNonRebasing).has.an.approxBalanceOf("99.50", ousd);
expect(await ousd.totalSupply()).to.equal(totalSupplyBefore);
Expand Down Expand Up @@ -477,8 +477,8 @@ describe("Token", function () {

const rebaseTx = await ousd.connect(matt).rebaseOptOut();
await expect(rebaseTx)
.to.emit(ousd, "RebaseOptOut")
.withArgs(matt.address);
.to.emit(ousd, "AccountRebasingDisabled")
.withArgs(matt.address);

// Received 100 from the rebase, the 200 simulated yield was split between
// Matt and Josh
Expand Down Expand Up @@ -682,7 +682,15 @@ describe("Token", function () {
vault.address,
daiUnits("100")
);
await mockNonRebasing.mintOusd(vault.address, dai.address, daiUnits("50"));
const tx = await mockNonRebasing.mintOusd(
vault.address,
dai.address,
daiUnits("50")
);
await expect(tx)
.to.emit(ousd, "AccountRebasingDisabled")
.withArgs(mockNonRebasing.address);

await expect(await ousd.totalSupply()).to.equal(
totalSupplyBefore.add(ousdUnits("50"))
);
Expand Down

0 comments on commit 92e034d

Please sign in to comment.