61 lines
2.6 KiB
Solidity
61 lines
2.6 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.35;
|
|
|
|
import {console2} from "forge-std/console2.sol";
|
|
import {Upgrades} from "openzeppelin-foundry-upgrades/Upgrades.sol";
|
|
import {BankV1} from "../src/BankV1.sol";
|
|
import {MockUSDC} from "../src/MockUSDC.sol";
|
|
import {DemoScript} from "./lib/DemoScript.sol";
|
|
|
|
contract CheckState is DemoScript {
|
|
error Insolvent(uint256 reserves, uint256 liabilities);
|
|
error UnknownStage(string stage);
|
|
|
|
function run() external view {
|
|
_requireSupportedChain(block.chainid);
|
|
_printEducationalWarning();
|
|
string memory stage = vm.envOr("DEMO_EXPECTED_STAGE", string("v1"));
|
|
bool deployedStage = keccak256(bytes(stage)) == keccak256("deployed");
|
|
Manifest memory manifest = _readManifest(_manifestPath(ACTIVE_MANIFEST_PATH), !deployedStage);
|
|
BankV1 bank = BankV1(manifest.proxy);
|
|
MockUSDC token = MockUSDC(manifest.token);
|
|
|
|
address actualImplementation = Upgrades.getImplementationAddress(manifest.proxy);
|
|
_assertAddress("implementation", manifest.implementation, actualImplementation);
|
|
_assertAddress("owner", manifest.owner, bank.owner());
|
|
_assertAddress("asset", manifest.token, address(bank.asset()));
|
|
|
|
uint256 reserves = token.balanceOf(manifest.proxy);
|
|
uint256 liabilities = bank.totalLiabilities();
|
|
if (reserves < liabilities) revert Insolvent(reserves, liabilities);
|
|
uint256 surplus = reserves - liabilities;
|
|
|
|
console2.log("network", manifest.network);
|
|
console2.log("block", block.number);
|
|
console2.log("token", manifest.token);
|
|
console2.log("proxy", manifest.proxy);
|
|
console2.log("implementation", actualImplementation);
|
|
console2.log("owner", bank.owner());
|
|
console2.log("paused", bank.paused());
|
|
console2.log("version", bank.contractVersion());
|
|
for (uint256 i; i < manifest.actors.length; ++i) {
|
|
console2.log(manifest.actorLabels[i], manifest.actors[i]);
|
|
console2.log(" bank balance", bank.balanceOf(manifest.actors[i]));
|
|
console2.log(" token balance", token.balanceOf(manifest.actors[i]));
|
|
}
|
|
console2.log("reserves", reserves);
|
|
console2.log("liabilities", liabilities);
|
|
console2.log("surplus", surplus);
|
|
|
|
bytes32 stageHash = keccak256(bytes(stage));
|
|
if (deployedStage) {
|
|
_assertDeployedState(manifest);
|
|
} else if (stageHash == keccak256("v1")) {
|
|
_assertV1State(manifest);
|
|
_assertUint("surplus", 0, surplus);
|
|
} else if (stageHash != keccak256("invariants")) {
|
|
revert UnknownStage(stage);
|
|
}
|
|
}
|
|
}
|