Skip to content

Commit

Permalink
use _adjustGlobals function to adjust globals in yield delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Nov 18, 2024
1 parent f8280d1 commit ab460b8
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions contracts/contracts/token/OUSD.sol
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,8 @@ contract OUSD is Governable {
_rebaseOptIn(to);
}

uint256 balanceFrom = balanceOf(from);
uint256 creditsFrom = _balanceToRebasingCredits(balanceFrom);
uint256 fromBalance = balanceOf(from);
uint256 creditsFrom = _balanceToRebasingCredits(fromBalance);

// Set up the bidirectional links
yieldTo[from] = to;
Expand All @@ -642,13 +642,11 @@ contract OUSD is Governable {
rebaseState[to] = RebaseOptions.YieldDelegationTarget;

// Local
_creditBalances[from] = balanceFrom;
_creditBalances[from] = fromBalance;
alternativeCreditsPerToken[from] = 1e18;
_creditBalances[to] += creditsFrom;

// Global
nonRebasingSupply -= balanceFrom;
_rebasingCredits += creditsFrom;
_adjustGlobals(creditsFrom.toInt256(), -fromBalance.toInt256());
}

function undelegateYield(address from) external onlyGovernor {
Expand All @@ -671,8 +669,6 @@ contract OUSD is Governable {
_creditBalances[from] = fromBalance;
_creditBalances[to] = toNewCredits;

// Global
nonRebasingSupply += fromBalance;
_rebasingCredits -= (toCreditsBefore - toNewCredits); // Should always go down or stay the same
_adjustGlobals(-(toCreditsBefore - toNewCredits).toInt256(), fromBalance.toInt256());
}
}

0 comments on commit ab460b8

Please sign in to comment.