75 lines
3.2 KiB
Solidity
75 lines
3.2 KiB
Solidity
// SPDX-License-Identifier: MIT
|
|
pragma solidity 0.8.35;
|
|
|
|
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 DeployV1 is DemoScript {
|
|
function run() external returns (address tokenAddress, address proxy, address implementation) {
|
|
_requireSupportedChain(block.chainid);
|
|
_printEducationalWarning();
|
|
address sender = vm.envAddress("SCRIPT_SENDER");
|
|
address recipient;
|
|
string memory publicRpcUrl;
|
|
|
|
if (block.chainid == BASE_SEPOLIA_CHAIN_ID) {
|
|
(, recipient, publicRpcUrl) = _requireBaseConfig(sender);
|
|
}
|
|
|
|
if (block.chainid == ANVIL_CHAIN_ID) {
|
|
(uint256 ownerKey, address derivedOwner) = _deriveLocalActor(block.chainid, 0);
|
|
_assertAddress("SCRIPT_SENDER", derivedOwner, sender);
|
|
vm.startBroadcast(ownerKey);
|
|
} else {
|
|
vm.startBroadcast(sender);
|
|
}
|
|
|
|
MockUSDC token = new MockUSDC(sender);
|
|
proxy =
|
|
Upgrades.deployUUPSProxy("BankV1.sol:BankV1", abi.encodeCall(BankV1.initialize, (address(token), sender)));
|
|
vm.stopBroadcast();
|
|
|
|
tokenAddress = address(token);
|
|
implementation = Upgrades.getImplementationAddress(proxy);
|
|
_requireCode("token", tokenAddress);
|
|
_requireCode("proxy", proxy);
|
|
_requireCode("implementation", implementation);
|
|
_assertAddress("owner", sender, BankV1(proxy).owner());
|
|
_assertAddress("asset", tokenAddress, address(BankV1(proxy).asset()));
|
|
_assertUint("version", 1, BankV1(proxy).contractVersion());
|
|
_assertAddress("implementation", implementation, Upgrades.getImplementationAddress(proxy));
|
|
|
|
Manifest memory manifest;
|
|
manifest.schemaVersion = 1;
|
|
manifest.network = block.chainid == ANVIL_CHAIN_ID ? "anvil" : "baseSepolia";
|
|
manifest.chainId = block.chainid;
|
|
manifest.deploymentBlock = 0;
|
|
manifest.rpcUrl = block.chainid == ANVIL_CHAIN_ID ? "http://127.0.0.1:8545" : publicRpcUrl;
|
|
manifest.explorerBaseUrl = block.chainid == BASE_SEPOLIA_CHAIN_ID ? "https://sepolia.basescan.org" : "";
|
|
manifest.token = tokenAddress;
|
|
manifest.proxy = proxy;
|
|
manifest.implementation = implementation;
|
|
manifest.owner = sender;
|
|
manifest.actors = _actors(sender, recipient);
|
|
|
|
_writeManifest(_manifestPath(PENDING_MANIFEST_PATH), manifest);
|
|
}
|
|
|
|
function _actors(address sender, address recipient) private view returns (Actor[] memory actors) {
|
|
if (block.chainid == ANVIL_CHAIN_ID) {
|
|
actors = new Actor[](3);
|
|
actors[0] = Actor({label: "owner", address_: sender});
|
|
(, actors[1].address_) = _deriveLocalActor(block.chainid, 1);
|
|
(, actors[2].address_) = _deriveLocalActor(block.chainid, 2);
|
|
actors[1].label = "Alice";
|
|
actors[2].label = "Bob";
|
|
} else {
|
|
actors = new Actor[](2);
|
|
actors[0] = Actor({label: "Presenter", address_: sender});
|
|
actors[1] = Actor({label: "Recipient", address_: recipient});
|
|
}
|
|
}
|
|
}
|