Skip to content

Instantly share code, notes, and snippets.

@CodingNameKiki
Created December 17, 2023 13:15
Show Gist options
  • Save CodingNameKiki/a3b887756e686de8361952536a931c8b to your computer and use it in GitHub Desktop.
Save CodingNameKiki/a3b887756e686de8361952536a931c8b to your computer and use it in GitHub Desktop.
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;

import "forge-std/Test.sol";
import {eBTCBaseInvariants} from "./BaseInvariants.sol";

contract simpler is eBTCBaseInvariants {

  address wallet = address(0xbad455);

  bytes32 first;
  bytes32 second;
  bytes32 third;

  uint256 totalStakesBeforeFirstCdp;
  uint256 totalCollBeforeFirstCdp;

  uint256 totalStakesBeforeSecondCdp;
  uint256 totalCollBeforeSecondCdp;

  uint256 totalStakesBeforeThirdCdp;
  uint256 totalCollBeforeThirdCdp;

  uint256 snapshotStakeFirstCdp;
  uint256 liveStakeFirstCdp;

  uint256 snapshotStakeSecondCdp;
  uint256 liveStakeSecondCdp;

  uint256 snapshotStakeThirdCdp;
  uint256 liveStakeThirdCdp;

  function setUp() public override {
    super.setUp();

    connectCoreContracts();
    connectLQTYContractsToCore();

  }

  function testSnapshotsVsLive() public {
    uint256 price = priceFeedMock.fetchPrice();

    // Neutral Cdp just to update snapshots
    _openTestCDP(wallet, 2e18 + 2e17, ((2e18 * price) / 125e16));

    vm.startPrank(address(borrowerOperations));
    uint256 stETHIndex = cdpManager.stEthIndex();
    collateral.setEthPerShare(stETHIndex + 1e1);
    cdpManager.syncGlobalAccounting();
    vm.stopPrank();

    totalStakesBeforeFirstCdp = cdpManager.totalStakes();
    totalCollBeforeFirstCdp = activePool.getSystemCollShares();    

    first = _openTestCDP(wallet, 2e18 + 2e17, ((2e18 * price) / 125e16));
    (, , snapshotStakeFirstCdp, , , ) = cdpManager.Cdps(first);
    liveStakeFirstCdp = (2e18 * totalStakesBeforeFirstCdp) / totalCollBeforeFirstCdp;

    totalStakesBeforeSecondCdp = cdpManager.totalStakes();
    totalCollBeforeSecondCdp = activePool.getSystemCollShares();

    second = _openTestCDP(wallet, 4e18 + 2e17, ((4e18 * price) / 125e16));
    (, , snapshotStakeSecondCdp, , , ) = cdpManager.Cdps(second);
    liveStakeSecondCdp = (4e18 * totalStakesBeforeSecondCdp) / totalCollBeforeSecondCdp;

    totalStakesBeforeThirdCdp = cdpManager.totalStakes();
    totalCollBeforeThirdCdp = activePool.getSystemCollShares();

    third = _openTestCDP(wallet, 8e18 + 2e17, ((8e18 * price) / 125e16));
    (, , snapshotStakeThirdCdp, , , ) = cdpManager.Cdps(third);
    liveStakeThirdCdp = (8e18 * totalStakesBeforeThirdCdp) / totalCollBeforeThirdCdp;

    console.log("---------------------------- First Cdp");
    console.log("Snapshot Stake   :  ", snapshotStakeFirstCdp);
    console.log("Live Stake       :  ", liveStakeFirstCdp);
    console.log("---------------------------- Second Cdp");
    console.log("Snapshot Stake   :  ", snapshotStakeSecondCdp);
    console.log("Live Stake       :  ", liveStakeSecondCdp);
    console.log("---------------------------- Third Cdp");
    console.log("Snapshot Stake   :  ", snapshotStakeThirdCdp);
    console.log("Live Stake       :  ", liveStakeThirdCdp);   
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment