Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add ghost variables and inline assertions (SC-485) #17

Merged
merged 186 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 175 commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
822694a
feat: first test working
lucas-manuel May 18, 2024
d6530e1
feat: use larger numbers:
lucas-manuel May 18, 2024
8f11df4
feat: test with initial burn amount passing
lucas-manuel May 18, 2024
78fb4ad
feat: update tests to work with updated burn logic, move conversion f…
lucas-manuel May 21, 2024
d32fd2f
feat: remove todos
lucas-manuel May 21, 2024
2290417
fix: update to remove console and update comment
lucas-manuel May 21, 2024
1fe351b
feat: get swap tests working
lucas-manuel May 22, 2024
cbea0ee
feat: get all swap tests working
lucas-manuel May 22, 2024
7d1101d
fix: update for three assets in logic
lucas-manuel May 22, 2024
80440e0
feat: all tests passing
lucas-manuel May 22, 2024
51b980d
fix: rm commented out test
lucas-manuel May 22, 2024
e6b67c6
feat: add preview swap tests
lucas-manuel May 22, 2024
ffa4513
feat: move logic out of single use internal and use conversion rate e…
lucas-manuel May 22, 2024
e9c519b
feat: move divRoundUp out of single use internal
lucas-manuel May 22, 2024
6ec2b23
feat: add full coverage for conversion tests
lucas-manuel May 22, 2024
2be5afc
feat: add more preview cases
lucas-manuel May 22, 2024
4299e03
feat: refactor PSM to use three assets
lucas-manuel May 22, 2024
64c9939
fix: rm comment
lucas-manuel May 22, 2024
2c43f92
feat: add interface, natspec, events, referral code, tests passing
lucas-manuel May 22, 2024
57c65d6
fix: update to rm consolegp
lucas-manuel May 22, 2024
c0616bf
Merge branch 'sc-447-build-threeway-swap' into sc-448-add-referral-code
lucas-manuel May 22, 2024
416034f
feat: add events testing
lucas-manuel May 23, 2024
114f92b
feat: make precisions internal and add state var natspec
lucas-manuel May 23, 2024
8c2f83b
feat: finish natspec
lucas-manuel May 23, 2024
61443c8
feat: add readme
lucas-manuel May 23, 2024
6ca25a8
feat: add referral code note
lucas-manuel May 23, 2024
c4f8c78
fix: update constructor test
lucas-manuel May 23, 2024
b070a44
fix: update links
lucas-manuel May 23, 2024
6947398
fix: reformatting
lucas-manuel May 23, 2024
9bdcfc5
fix: update testing section
lucas-manuel May 23, 2024
d69bc8b
fix: improve overview
lucas-manuel May 23, 2024
04cc6ac
feat: add emojis
lucas-manuel May 23, 2024
54a4afe
feat: remove all share burn logic, get all non inflation attack tests…
May 30, 2024
ce5653d
fix: cleanup diff
May 30, 2024
259cf16
fix: update to use initial deposit instead of burn
May 30, 2024
62ef5c2
feat: add readme section explaining attack
May 30, 2024
0720150
fix: minimize diff
May 30, 2024
5a03fde
feat: fix conflicts
May 30, 2024
c5f7cf0
feat: rm all references to initial burn, update tests
May 30, 2024
e6c654d
fix: address bartek comments
May 30, 2024
e540afa
feat: update all tests to work with new interfaces
May 30, 2024
c41b010
feat: add deposit failure mode tests
May 30, 2024
847a1db
feat: update to add assertions for return in deposit
May 30, 2024
ecbf99b
feat: add withdraw failure tests
May 30, 2024
44a5d52
feat: update to address comments outside sharesToBurn
Jun 3, 2024
9c3958e
feat: update inflation attack test and readme
Jun 3, 2024
4c9cf09
fix: update readme
Jun 3, 2024
cb9931a
feat: update test to constrain deposit/withdraw
Jun 3, 2024
e576672
feat: update to add both cases
Jun 3, 2024
e994287
fix: merge conflicts
Jun 3, 2024
9688892
fix: merge conflicts
Jun 3, 2024
b80ed6e
fix: merge conflicts
Jun 3, 2024
108624a
fix: merge conflicts
Jun 4, 2024
73d8c8c
feat: update per review
lucas-manuel Jun 4, 2024
d6c6f03
fix: merge conflicts
lucas-manuel Jun 4, 2024
5319255
Merge branch 'sc-448-add-referral-code' into sc-453-add-receiver-depo…
lucas-manuel Jun 4, 2024
0f182b2
feat: update to use underscore bound, fix test
lucas-manuel Jun 5, 2024
dfab7ec
Merge branch 'sc-447-build-threeway-swap' into sc-448-add-referral-code
lucas-manuel Jun 5, 2024
b288568
fix: merge conflicts
lucas-manuel Jun 5, 2024
ba44086
fix: typo
lucas-manuel Jun 5, 2024
62f5423
fix: merge conflicts
lucas-manuel Jun 5, 2024
9a243f9
feat: add overrides, remove referrals, update referral type
lucas-manuel Jun 10, 2024
cc68ed3
fix: update expect emit
lucas-manuel Jun 10, 2024
9862a53
feat: update name and remove todos
lucas-manuel Jun 10, 2024
376fa83
feat: move files and set up structure
lucas-manuel Jun 10, 2024
73cb854
feat: update to rename files, contracts, and errors
lucas-manuel Jun 10, 2024
f711954
fix: merge conflicts
lucas-manuel Jun 10, 2024
23c870d
fix: merge conflicts
lucas-manuel Jun 10, 2024
ce0949f
fix: merge conflicts
lucas-manuel Jun 10, 2024
81d2e37
fix: rm dup file, update toml
lucas-manuel Jun 10, 2024
fbff8d3
feat: get deposits working
lucas-manuel Jun 10, 2024
3e5a3eb
chore: refactor into proper inheritance structure
lucas-manuel Jun 10, 2024
2e60593
feat: get all functions working with reverts
lucas-manuel Jun 10, 2024
14fdf08
fix: cofnlicts
lucas-manuel Jun 13, 2024
defc84e
feat: update conversion
lucas-manuel Jun 13, 2024
bbc3e8e
feat: get swaps working without reverts
lucas-manuel Jun 13, 2024
4c04863
feat: add fully working deposit/withdraw/swaps, invariant_B failing
lucas-manuel Jun 13, 2024
d23bfbe
ci: update for ci
lucas-manuel Jun 13, 2024
7ba3e16
fix: update name
lucas-manuel Jun 13, 2024
499afae
chore: rm basly cased file
lucas-manuel Jun 13, 2024
d1daf4b
chore: re add
lucas-manuel Jun 13, 2024
84c3787
fix: re add invariant
lucas-manuel Jun 13, 2024
3814067
ci: experiment with 2 million total calls
lucas-manuel Jun 13, 2024
9215a29
ci: add show progress flag
lucas-manuel Jun 13, 2024
9caf3c6
fix: move file back
lucas-manuel Jun 13, 2024
094d613
ci: update verbosity
lucas-manuel Jun 13, 2024
2085360
ci: add PR profile
lucas-manuel Jun 13, 2024
0605586
fix: rm redundant files
lucas-manuel Jun 13, 2024
74dba88
feat: update from review changes
lucas-manuel Jun 14, 2024
fa3a232
feat: add afterInvariant hook
lucas-manuel Jun 19, 2024
ba9b5fe
Merge branch 'master' into sc-459-add-basic-invariant-testing
lucas-manuel Jun 20, 2024
608daf5
Merge branch 'master' into sc-459-add-basic-invariant-testing
lucas-manuel Jun 20, 2024
c4bf0cc
fix: update invariant
lucas-manuel Jun 20, 2024
df65c1b
fix: add fuzz failure
lucas-manuel Jun 20, 2024
42581aa
chore: rm indexing comment
lucas-manuel Jun 21, 2024
49fdc1f
Merge branch 'sc-459-add-basic-invariant-testing' into sc-481-add-inv…
lucas-manuel Jun 21, 2024
1b07d93
feat: refactor structure
lucas-manuel Jun 21, 2024
e5153a0
feat: both invariants working
lucas-manuel Jun 21, 2024
c664f2c
fix: update comment
lucas-manuel Jun 21, 2024
3bcb0d0
feat: add rate setting logic
lucas-manuel Jun 21, 2024
54e8ae9
fix: update toml
lucas-manuel Jun 21, 2024
f982ff3
fix: rm redundant files from merge
lucas-manuel Jun 21, 2024
1c3c450
Merge branch 'sc-459-add-basic-invariant-testing' into sc-481-add-inv…
lucas-manuel Jun 21, 2024
ffa6eee
fix: update tolerances
lucas-manuel Jun 21, 2024
a2e6f05
feat: update to add seeding as part of invariants
lucas-manuel Jun 21, 2024
68f41ab
fix: merge branch
lucas-manuel Jun 21, 2024
adf11a5
fix: update toml
lucas-manuel Jun 21, 2024
07d372e
fix: rm redundant files from merge
lucas-manuel Jun 21, 2024
7b1bf35
fix: update tolerances
lucas-manuel Jun 21, 2024
6ed0f85
Merge branch 'sc-481-add-invariant-hooks-more-suites' into sc-483-add…
lucas-manuel Jun 21, 2024
d78c024
fix: rm invariant logs
lucas-manuel Jun 21, 2024
e358437
fix: update tolerance
lucas-manuel Jun 24, 2024
da05a92
forge install: xchain-dsr-oracle
lucas-manuel Jun 24, 2024
62578bb
feat: setup timebased handler, refactor rate provider structure
lucas-manuel Jun 24, 2024
b1212b7
feat: tests passing
lucas-manuel Jun 24, 2024
30e5094
feat: add first inline assertions
lucas-manuel Jun 25, 2024
4256b98
feat: tests passing with inline assertions
lucas-manuel Jun 26, 2024
d5f1edf
feat: all tests passing
lucas-manuel Jun 26, 2024
9bfb3b6
fix: increase tolerance
lucas-manuel Jun 27, 2024
c27f144
feat: gaa
lucas-manuel Jun 27, 2024
8e20594
feat: update swap to swapExactAmountIn
lucas-manuel Jul 2, 2024
b3a2d67
feat: add preview test coverage
lucas-manuel Jul 2, 2024
1c42d99
feat: add new function
lucas-manuel Jul 3, 2024
c3503e0
fix: merge conflicts
lucas-manuel Jul 3, 2024
ae6c47b
chore: first cleanup
lucas-manuel Jul 3, 2024
5f1e228
fix: test names
lucas-manuel Jul 3, 2024
cf4dda2
fix: merge conflicts
lucas-manuel Jul 3, 2024
1d6aace
feat: tests passing
lucas-manuel Jul 3, 2024
7cd1c87
fix: update tolerances, tests passing
lucas-manuel Jul 3, 2024
d97b8cd
feat: add ge assertions
lucas-manuel Jul 3, 2024
e0eb555
fix: refactor invariants to use loops
lucas-manuel Jul 3, 2024
cef1abf
feat: update to get aggregate ghost variables working
lucas-manuel Jul 3, 2024
b813c19
feat: update to add more invariants
lucas-manuel Jul 3, 2024
278d99e
feat: create new file, failure tests passing
lucas-manuel Jul 4, 2024
4a1e43d
fix: update dsr value, change chi approach
lucas-manuel Jul 4, 2024
299b69f
fix: conflicts
lucas-manuel Jul 4, 2024
3846be3
ci: update ci params
lucas-manuel Jul 4, 2024
db667d1
fix: increase invariant D tolerance
lucas-manuel Jul 4, 2024
54ca402
ci: add coverage backgp
lucas-manuel Jul 4, 2024
3552234
fix: update rho usage
lucas-manuel Jul 4, 2024
95c9654
Merge branch 'master' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
1a426da
Merge branch 'add-coverage-back' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
02074d0
feat: get new swap tests passing
lucas-manuel Jul 4, 2024
93220d5
feat: set up initial test
lucas-manuel Jul 4, 2024
7a9c76e
feat: refactor code to add returns
lucas-manuel Jul 4, 2024
8279856
feat: add return value assertions
lucas-manuel Jul 4, 2024
389c859
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
2aabbf8
feat: working fuzz test
lucas-manuel Jul 4, 2024
e810447
feat: add swap exact out, show that rounding is against user
lucas-manuel Jul 4, 2024
3484433
fix: update natspec
lucas-manuel Jul 4, 2024
86cf19d
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
d736ad1
feat: refactor to round up on swap exact out
lucas-manuel Jul 4, 2024
4bffb0e
feat: all tests passing
lucas-manuel Jul 4, 2024
2ec107e
fix: merge conflicts
lucas-manuel Jul 4, 2024
747eb61
Merge branch 'master' into add-coverage-back
lucas-manuel Jul 4, 2024
869ccdc
Merge branch 'add-coverage-back' into sc-490-add-exact-amount-out-swap
lucas-manuel Jul 4, 2024
113cd97
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
132d11b
fix: merge conflicts
lucas-manuel Jul 4, 2024
c76f76c
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
6b5b94b
fix: cleanup
lucas-manuel Jul 4, 2024
b3db93e
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
7b6cd3b
fix: merge conflicts
lucas-manuel Jul 4, 2024
281637b
chore: merge sc-482 branch
lucas-manuel Jul 4, 2024
09c95b2
feat: invariant tests passing
lucas-manuel Jul 4, 2024
74b3363
fix: update tolerances
lucas-manuel Jul 4, 2024
226c8db
feat: update tolerances
lucas-manuel Jul 4, 2024
c30dc9e
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
7ad6dae
fix: merge conflicts
lucas-manuel Jul 4, 2024
da5ce84
fix: update tolerance
lucas-manuel Jul 4, 2024
777b8e0
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
057b057
fix: increase fuzz tolerance
lucas-manuel Jul 4, 2024
82aa91b
Merge branch 'sc-490-add-exact-amount-out-swap' into sc-482-swap-fuzz…
lucas-manuel Jul 4, 2024
0dc30fb
Merge branch 'sc-482-swap-fuzz-testing' into sc-485-ghost-variables-i…
lucas-manuel Jul 4, 2024
e4bdecb
fix: merge conflicts
lucas-manuel Jul 17, 2024
3ccf166
Merge branch 'master' into sc-485-ghost-variables-inline-assertions
lucas-manuel Jul 23, 2024
e290f9a
fix: first fixes, failint tests
lucas-manuel Jul 24, 2024
74102d8
fix; update to match for before/after assertions
lucas-manuel Jul 24, 2024
a37376c
fix: update to show invariant_F failure
lucas-manuel Jul 24, 2024
d0827f4
feat: add more assertions, make invariant helpers more efficient
lucas-manuel Jul 25, 2024
56e1896
fix: merge conflicts
lucas-manuel Jul 29, 2024
058004f
feat: update to fix invariant F
lucas-manuel Jul 29, 2024
5928b25
fix: rm old todos, reduce rates and warping to reflect more realistic…
lucas-manuel Jul 29, 2024
2c12a60
fix: remove negative tolerances in swap handler
lucas-manuel Jul 29, 2024
c580954
foix: increase hook tolerances
lucas-manuel Jul 29, 2024
d4dbb00
fix: udpate comment
lucas-manuel Jul 29, 2024
034fd7e
fix: typo
lucas-manuel Jul 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ runs = 1000
runs = 20
depth = 1000
shrink_run_limit = 1000
fail_on_revert = true

[profile.pr.invariant]
runs = 200
depth = 1000
shrink_run_limit = 50_000

[profile.pr.fuzz]
runs = 100_000

[profile.master.invariant]
runs = 200
depth = 10_000
shrink_run_limit = 100_000

[profile.master.fuzz]
runs = 1_000_000
Expand Down
231 changes: 209 additions & 22 deletions test/invariant/Invariants.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ abstract contract PSMInvariantTestBase is PSMTestBase {
/**********************************************************************************************/

function _checkInvariant_A() public view {
assertEq(
psm.shares(address(lpHandler.lps(0))) +
psm.shares(address(lpHandler.lps(1))) +
psm.shares(address(lpHandler.lps(2))) +
1e18, // Seed amount
psm.totalShares()
);
uint256 lpShares = 1e18; // Seed amount

// TODO: Update to be dynamic
for (uint256 i = 0; i < 3; i++) {
lpShares += psm.shares(lpHandler.lps(i));
}

assertEq(lpShares, psm.totalShares());
}

function _checkInvariant_B() public view {
Expand All @@ -60,14 +61,104 @@ abstract contract PSMInvariantTestBase is PSMTestBase {
}

function _checkInvariant_C() public view {
assertApproxEqAbs(
psm.convertToAssetValue(psm.shares(address(lpHandler.lps(0)))) +
psm.convertToAssetValue(psm.shares(address(lpHandler.lps(1)))) +
psm.convertToAssetValue(psm.shares(address(lpHandler.lps(2)))) +
psm.convertToAssetValue(1e18), // Seed amount
psm.totalAssets(),
4
);
uint256 lpAssetValue = psm.convertToAssetValue(1e18); // Seed amount

for (uint256 i = 0; i < 3; i++) {
lpAssetValue += psm.convertToAssetValue(psm.shares(lpHandler.lps(i)));
}

assertApproxEqAbs(lpAssetValue, psm.totalAssets(), 4);
}

// This might be failing because of swap rounding errors.
function _checkInvariant_D() public view {
// Seed amounts
uint256 lpDeposits = 1e18;
uint256 lpAssetValue = psm.convertToAssetValue(1e18);

for (uint256 i = 0; i < 3; i++) {
address lp = lpHandler.lps(i);

lpDeposits += _getLpDepositsValue(lp);
lpAssetValue += psm.convertToAssetValue(psm.shares(lp));
}

// LPs position value can increase from transfers into the PSM and from swapping rounding
// errors increasing the value of the PSM slightly.
// Allow a 2e12 tolerance for negative rounding on conversion calculations.
assertGe(lpAssetValue + 2e12, lpDeposits);

// Include seed deposit, allow for 2e12 negative tolerance.
assertGe(psm.totalAssets() + 2e12, lpDeposits);
}

function _checkInvariant_E() public view {
uint256 expectedUsdcBalance = 0;
uint256 expectedDaiBalance = 1e18; // Seed amount
uint256 expectedSDaiBalance = 0;

for(uint256 i; i < 3; i++) {
address lp = lpHandler.lps(i);
address swapper = swapperHandler.swappers(i);

expectedUsdcBalance += lpHandler.lpDeposits(lp, address(usdc));
expectedDaiBalance += lpHandler.lpDeposits(lp, address(dai));
expectedSDaiBalance += lpHandler.lpDeposits(lp, address(sDai));

expectedUsdcBalance += swapperHandler.swapsIn(swapper, address(usdc));
expectedDaiBalance += swapperHandler.swapsIn(swapper, address(dai));
expectedSDaiBalance += swapperHandler.swapsIn(swapper, address(sDai));
}

if (address(transferHandler) != address(0)) {
expectedUsdcBalance += transferHandler.transfersIn(address(usdc));
expectedDaiBalance += transferHandler.transfersIn(address(dai));
expectedSDaiBalance += transferHandler.transfersIn(address(sDai));
}

// Loop twice to avoid underflows between LPs
for(uint256 i; i < 3; i++) {
address lp = lpHandler.lps(i);
address swapper = swapperHandler.swappers(i);

expectedUsdcBalance -= lpHandler.lpWithdrawals(lp, address(usdc));
expectedDaiBalance -= lpHandler.lpWithdrawals(lp, address(dai));
expectedSDaiBalance -= lpHandler.lpWithdrawals(lp, address(sDai));

expectedUsdcBalance -= swapperHandler.swapsOut(swapper, address(usdc));
expectedDaiBalance -= swapperHandler.swapsOut(swapper, address(dai));
expectedSDaiBalance -= swapperHandler.swapsOut(swapper, address(sDai));
}

assertEq(usdc.balanceOf(address(psm)), expectedUsdcBalance);
assertEq(dai.balanceOf(address(psm)), expectedDaiBalance);
assertEq(sDai.balanceOf(address(psm)), expectedSDaiBalance);
}

function _checkInvariant_F() public view {
uint256 totalValueSwappedIn;
uint256 totalValueSwappedOut;

for(uint256 i; i < 3; i++) {
address swapper = swapperHandler.swappers(i);

totalValueSwappedIn +=
swapperHandler.swapsIn(swapper, address(usdc)) * 1e12 +
swapperHandler.swapsIn(swapper, address(dai)) +
swapperHandler.swapsIn(swapper, address(sDai)) * rateProvider.getConversionRate() / 1e27;
}

// Loop twice to avoid underflows between LPs
for(uint256 i; i < 3; i++) {
address swapper = swapperHandler.swappers(i);

totalValueSwappedOut +=
swapperHandler.swapsIn(swapper, address(usdc)) * 1e12 +
swapperHandler.swapsIn(swapper, address(dai)) +
swapperHandler.swapsIn(swapper, address(sDai)) * rateProvider.getConversionRate() / 1e27;
hexonaut marked this conversation as resolved.
Show resolved Hide resolved
}

assertEq(totalValueSwappedIn, totalValueSwappedOut);
}

/**********************************************************************************************/
Expand Down Expand Up @@ -98,6 +189,20 @@ abstract contract PSMInvariantTestBase is PSMTestBase {
return daiValue + usdcValue + sDaiValue;
}

function _getLpDepositsValue(address lp) internal view returns (uint256) {
uint256 depositValue =
lpHandler.lpDeposits(lp, address(dai)) +
lpHandler.lpDeposits(lp, address(usdc)) * 1e12 +
lpHandler.lpDeposits(lp, address(sDai)) * rateProvider.getConversionRate() / 1e27;

uint256 withdrawValue =
lpHandler.lpWithdrawals(lp, address(dai)) +
lpHandler.lpWithdrawals(lp, address(usdc)) * 1e12 +
lpHandler.lpWithdrawals(lp, address(sDai)) * rateProvider.getConversionRate() / 1e27;

return withdrawValue > depositValue ? 0 : depositValue - withdrawValue;
}

/**********************************************************************************************/
/*** After invariant hook functions ***/
/**********************************************************************************************/
Expand Down Expand Up @@ -210,6 +315,9 @@ contract PSMInvariants_ConstantRate_NoTransfer is PSMInvariantTestBase {

targetContract(address(lpHandler));
targetContract(address(swapperHandler));

// Check that LPs used for swap assertions are correct to not get zero values
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
Expand All @@ -224,6 +332,18 @@ contract PSMInvariants_ConstantRate_NoTransfer is PSMInvariantTestBase {
_checkInvariant_C();
}

function invariant_D() public view {
_checkInvariant_D();
}

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand Down Expand Up @@ -256,6 +376,17 @@ contract PSMInvariants_ConstantRate_WithTransfers is PSMInvariantTestBase {
_checkInvariant_C();
}

// No invariant D because rate changes lead to large rounding errors when compared with
// ghost variables

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand All @@ -268,12 +399,15 @@ contract PSMInvariants_RateSetting_NoTransfer is PSMInvariantTestBase {
super.setUp();

lpHandler = new LpHandler(psm, dai, usdc, sDai, 3);
rateSetterHandler = new RateSetterHandler(address(rateProvider), 1.25e27);
rateSetterHandler = new RateSetterHandler(psm, address(rateProvider), 1.25e27);
swapperHandler = new SwapperHandler(psm, dai, usdc, sDai, 3);

targetContract(address(lpHandler));
targetContract(address(rateSetterHandler));
targetContract(address(swapperHandler));

// Check that LPs used for swap assertions are correct to not get zero values
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
Expand All @@ -288,6 +422,17 @@ contract PSMInvariants_RateSetting_NoTransfer is PSMInvariantTestBase {
_checkInvariant_C();
}

// No invariant D because rate changes lead to large rounding errors when compared with
// ghost variables

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand All @@ -300,14 +445,17 @@ contract PSMInvariants_RateSetting_WithTransfers is PSMInvariantTestBase {
super.setUp();

lpHandler = new LpHandler(psm, dai, usdc, sDai, 3);
rateSetterHandler = new RateSetterHandler(address(rateProvider), 1.25e27);
rateSetterHandler = new RateSetterHandler(psm, address(rateProvider), 1.25e27);
swapperHandler = new SwapperHandler(psm, dai, usdc, sDai, 3);
transferHandler = new TransferHandler(psm, dai, usdc, sDai);

targetContract(address(lpHandler));
targetContract(address(rateSetterHandler));
targetContract(address(swapperHandler));
targetContract(address(transferHandler));

// Check that LPs used for swap assertions are correct to not get zero values
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
Expand All @@ -322,6 +470,17 @@ contract PSMInvariants_RateSetting_WithTransfers is PSMInvariantTestBase {
_checkInvariant_C();
}

// No invariant D because rate changes lead to large rounding errors when compared with
// ghost variables

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand All @@ -343,7 +502,7 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase {

lpHandler = new LpHandler(psm, dai, usdc, sDai, 3);
swapperHandler = new SwapperHandler(psm, dai, usdc, sDai, 3);
timeBasedRateHandler = new TimeBasedRateHandler(dsrOracle);
timeBasedRateHandler = new TimeBasedRateHandler(psm, dsrOracle);

// Handler acts in the same way as a receiver on L2, so add as a data provider to the
// oracle.
Expand All @@ -352,14 +511,17 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase {
rateProvider = IRateProviderLike(address(dsrOracle));

// Manually set initial values for the oracle through the handler to start
timeBasedRateHandler.setPotData(1e27, block.timestamp);
timeBasedRateHandler.setPotData(1e27);

targetContract(address(lpHandler));
targetContract(address(swapperHandler));
targetContract(address(timeBasedRateHandler));

// Check that LPs used for swap assertions are correct to not get zero values
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
function invariant_A_test() public view {
hexonaut marked this conversation as resolved.
Show resolved Hide resolved
_checkInvariant_A();
}

Expand All @@ -371,6 +533,17 @@ contract PSMInvariants_TimeBasedRateSetting_NoTransfer is PSMInvariantTestBase {
_checkInvariant_C();
}

// No invariant D because rate changes lead to large rounding errors when compared with
// ghost variables

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand All @@ -392,7 +565,7 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas

lpHandler = new LpHandler(psm, dai, usdc, sDai, 3);
swapperHandler = new SwapperHandler(psm, dai, usdc, sDai, 3);
timeBasedRateHandler = new TimeBasedRateHandler(dsrOracle);
timeBasedRateHandler = new TimeBasedRateHandler(psm, dsrOracle);
transferHandler = new TransferHandler(psm, dai, usdc, sDai);

// Handler acts in the same way as a receiver on L2, so add as a data provider to the
Expand All @@ -402,12 +575,15 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas
rateProvider = IRateProviderLike(address(dsrOracle));

// Manually set initial values for the oracle through the handler to start
timeBasedRateHandler.setPotData(1e27, block.timestamp);
timeBasedRateHandler.setPotData(1e27);

targetContract(address(lpHandler));
targetContract(address(swapperHandler));
targetContract(address(timeBasedRateHandler));
targetContract(address(transferHandler));

// Check that LPs used for swap assertions are correct to not get zero values
assertEq(swapperHandler.lp0(), lpHandler.lps(0));
}

function invariant_A() public view {
Expand All @@ -422,6 +598,17 @@ contract PSMInvariants_TimeBasedRateSetting_WithTransfers is PSMInvariantTestBas
_checkInvariant_C();
}

// No invariant D because rate changes lead to large rounding errors when compared with
// ghost variables

function invariant_E() public view {
_checkInvariant_E();
}

function invariant_F() public view {
_checkInvariant_F();
}

function afterInvariant() public {
_withdrawAllPositions();
}
Expand Down
Loading
Loading