Skip to content

Commit

Permalink
Rollover vault - Audit fixes (#160)
Browse files Browse the repository at this point in the history
* pve-002

* pve-003

* Added comment clarifying q1

* Update spot-contracts/contracts/PerpetualTranche.sol

Co-authored-by: Brandon Iles <brandon@fragments.org>

* comment fix

---------

Co-authored-by: Brandon Iles <brandon@fragments.org>
  • Loading branch information
aalavandhan and brandoniles authored May 24, 2023
1 parent 901435c commit aa6e68a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions spot-contracts/contracts/PerpetualTranche.sol
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ contract PerpetualTranche is
//
//
// System reserve value:
// RV => t'1 . price(t1) + t'2 . price(t2) + .... + t'n . price(tn)
// => Σ t'i . price(ti)
// RV => b'1 . price(t1) + b'2 . price(t2) + .... + b'n . price(tn)
// => Σ b'i . price(ti)
//
//
// When `ai` tokens of type `ti` are deposited into the system:
Expand Down Expand Up @@ -639,6 +639,9 @@ contract PerpetualTranche is

// post-rollover checks
_enforceMatureValueTarget();
// NOTE: though the rollover operation does not change the perp token's total supply,
// we still enforce the supply cap here as the -ve rollover fees
// might mint more perp tokens which could increase the perp total supply.
_enforceTotalSupplyCap();
}

Expand Down Expand Up @@ -966,7 +969,7 @@ contract PerpetualTranche is
? _matureTrancheBalance.mulDiv(r.tokenOutAmt, tokenOutBalance)
: r.tokenOutAmt;
stdTrancheOutAmt = _toStdTrancheAmt(r.trancheOutAmt, trancheOutDiscount);
stdTrancheInAmt = stdTrancheOutAmt.mulDiv(trancheOutPrice, trancheInPrice);
stdTrancheInAmt = stdTrancheOutAmt.mulDiv(trancheOutPrice, trancheInPrice, MathUpgradeable.Rounding.Up);
r.trancheInAmt = _fromStdTrancheAmt(stdTrancheInAmt, trancheInDiscount);
}

Expand Down
1 change: 1 addition & 0 deletions spot-contracts/contracts/RouterV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ contract RouterV1 {
) private {
uint256 allowance = token.allowance(address(this), spender);
if (allowance < amount) {
token.safeApprove(spender, 0);
token.safeApprove(spender, type(uint256).max);
}
}
Expand Down
1 change: 1 addition & 0 deletions spot-contracts/contracts/vaults/RolloverVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ contract RolloverVault is
) private {
uint256 allowance = token.allowance(address(this), spender);
if (allowance < amount) {
token.safeApprove(spender, 0);
token.safeApprove(spender, type(uint256).max);
}
}
Expand Down

0 comments on commit aa6e68a

Please sign in to comment.