Skip to content

Commit

Permalink
fix: update tolerances, tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
lucas-manuel committed Jul 3, 2024
1 parent 1d6aace commit 7cd1c87
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/PSM3.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@ contract PSM3 is IPSM3 {
/*** Asset value functions ***/
/**********************************************************************************************/

// Rename to getTotalValue or totalAssets
function getPsmTotalValue() public view override returns (uint256) {
return _getAsset0Value(asset0.balanceOf(address(this)))
+ _getAsset1Value(asset1.balanceOf(address(this)))
Expand Down
1 change: 0 additions & 1 deletion test/invariant/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,6 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas
}

function invariant_A() public view {

_checkInvariant_A();
}

Expand Down
6 changes: 0 additions & 6 deletions test/invariant/handlers/LpHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,3 @@ contract LpHandler is HandlerBase {
}

}

/**
* Add before/after value assertions for all
* Add APY calc for after hook in timebased
* Add ghost variable for swapper and transfer and sum those
*/
20 changes: 12 additions & 8 deletions test/invariant/handlers/SwapperHandler.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.13;

import { MockERC20 } from "erc20-helpers/MockERC20.sol";

import { HandlerBase, PSM3 } from "test/invariant/handlers/HandlerBase.sol";
import { console, HandlerBase, PSM3 } from "test/invariant/handlers/HandlerBase.sol";

contract SwapperHandler is HandlerBase {

Expand Down Expand Up @@ -105,7 +105,8 @@ contract SwapperHandler is HandlerBase {

// 4. Perform action-specific assertions

// Rounding because of USDC precision, a user's position can fluctuate by 2e12 per 1e18 shares
// Rounding because of USDC precision, a the conversion rate of a
// user's position can fluctuate by up to 2e12 per 1e18 shares
assertApproxEqAbs(
psm.convertToAssetValue(1e18),
startingConversion,
Expand All @@ -114,25 +115,28 @@ contract SwapperHandler is HandlerBase {
);

// Demonstrate rounding scales with shares
// TODO: Reinvestigate this assertion once swap fuzz tests are in place
assertApproxEqAbs(
psm.convertToAssetValue(1_000_000e18),
startingConversionMillion,
2_000_000e12, // 2e18 of value
"SwapperHandler/swap/conversion-rate-change"
"SwapperHandler/swap/conversion-rate-change-million"
);

// Position values can fluctuate by 0.00000002% on swaps
// Position values can fluctuate by up to 0.00000002% on swaps
assertApproxEqRel(
psm.convertToAssetValue(psm.shares(lp0)),
startingConversionLp0,
0.000002e18,
"SwapperHandler/swap/conversion-rate-change"
"SwapperHandler/swap/conversion-rate-change-lp"
);

// Rounding because of USDC precision
assertGe(
psm.getPsmTotalValue() + 2e12,
// PSM value can fluctuate by up to 0.00000001% on swaps because of USDC rounding
// (conversion not performed so 1 instead of 2)
assertApproxEqRel(
psm.getPsmTotalValue(),
startingValue,
0.000001e18,
"SwapperHandler/swap/psm-total-value-change"
);

Expand Down

0 comments on commit 7cd1c87

Please sign in to comment.