diff --git a/spot-contracts/contracts/PerpetualTranche.sol b/spot-contracts/contracts/PerpetualTranche.sol index 01e26535..c96eb92a 100644 --- a/spot-contracts/contracts/PerpetualTranche.sol +++ b/spot-contracts/contracts/PerpetualTranche.sol @@ -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: @@ -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(); } @@ -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); } diff --git a/spot-contracts/contracts/RouterV1.sol b/spot-contracts/contracts/RouterV1.sol index fc942881..a2857a3c 100644 --- a/spot-contracts/contracts/RouterV1.sol +++ b/spot-contracts/contracts/RouterV1.sol @@ -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); } } diff --git a/spot-contracts/contracts/vaults/RolloverVault.sol b/spot-contracts/contracts/vaults/RolloverVault.sol index fdddaf12..0e6dc0c6 100644 --- a/spot-contracts/contracts/vaults/RolloverVault.sol +++ b/spot-contracts/contracts/vaults/RolloverVault.sol @@ -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); } }