Skip to content

Commit

Permalink
fix: optimise isFee
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSolDev authored and azat-hafizov committed Feb 21, 2025
1 parent 5a3da22 commit b5b9278
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/SelfPeggingAsset.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1103,23 +1103,19 @@ contract SelfPeggingAsset is Initializable, ReentrancyGuardUpgradeable, OwnableU
balances = _balances;
totalSupply = newD;

if (isFee) {
if (oldD > newD && (oldD - newD) < feeErrorMargin) {
return 0;
} else if (oldD > newD) {
// Cover losses using the buffer
poolToken.removeTotalSupply(oldD - newD, true, true);
return 0;
}
} else {
if (oldD > newD && (oldD - newD) < yieldErrorMargin) {
return 0;
} else if (oldD > newD) {
// Cover losses using the buffer
poolToken.removeTotalSupply(oldD - newD, true, true);
if (oldD > newD) {
uint256 delta = oldD - newD;
uint256 margin = isFee ? feeErrorMargin : yieldErrorMargin;

if (delta < margin) {
return 0;
}

// Cover losses using the buffer
poolToken.removeTotalSupply(delta, true, true);
return 0;
}

uint256 feeAmount = newD - oldD;
if (feeAmount == 0) {
return 0;
Expand Down

0 comments on commit b5b9278

Please sign in to comment.