Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
37 changes: 37 additions & 0 deletions script/CommitteeRegisterPeerId.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;

import {Script, console} from "forge-std/Script.sol";
import {CommitteeManagement} from "../src/CommitteeManagement.sol";
import {GatewayUpgradeable} from "../src/Gateway.sol";

/*
Script: Register a peer ID for the committee.
Required env vars:
- PRIVATE_KEY: uint256 private key to broadcast from (committee member)
- GATEWAY_ADDR: address of deployed Gateway (proxy)
- PEER_ID: bytes peer ID to register
*/
contract RegisterPeerId is Script {
function run() public {
uint256 committeePrivateKey = vm.envUint("PRIVATE_KEY");
address committee = vm.addr(committeePrivateKey);

address gatewayAddr = vm.envAddress("GATEWAY_ADDR");
address committeeManagementAddr = address(GatewayUpgradeable(payable(gatewayAddr)).committeeManagement());
bytes memory peerId = vm.envBytes("PEER_ID");

console.log("Committee:", committee);
console.log("Gateway:", gatewayAddr);
console.log("Committee Management:", committeeManagementAddr);
console.log("Peer ID:", vm.toString(peerId));

vm.startBroadcast(committeePrivateKey);

CommitteeManagement(committeeManagementAddr).registerPeerId(peerId);

console.log("Peer ID registered successfully");

vm.stopBroadcast();
}
}
36 changes: 0 additions & 36 deletions script/DebugCancelWithdraw.sol

This file was deleted.

41 changes: 0 additions & 41 deletions script/DebugMintPegBTC.sol

This file was deleted.

6 changes: 6 additions & 0 deletions script/DeployContractDebug.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ import {PegBTC} from "../src/PegBTC.sol";
import {UpgradeableProxy} from "../src/UpgradeableProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/*
Script: Deploy the GatewayDebug contract and related contracts.
Required env vars:
- PRIVATE_KEY: uint256 private key to broadcast from (deployer)
- BITCOINSPV_ADDR: address of the BitcoinSPV contract
*/
contract DeployGateway is Script {
address public deployer;
address public bitcoinSPV;
Expand Down
173 changes: 173 additions & 0 deletions script/DeployGateway.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";

import {IPegBTC} from "../src/interfaces/IPegBTC.sol";
import {IBitcoinSPV} from "../src/interfaces/IBitcoinSPV.sol";
import {CommitteeManagement} from "../src/CommitteeManagement.sol";
import {StakeManagement} from "../src/StakeManagement.sol";
import {ICommitteeManagement} from "../src/interfaces/ICommitteeManagement.sol";
import {IStakeManagement} from "../src/interfaces/IStakeManagement.sol";

import {GatewayUpgradeable} from "../src/Gateway.sol";
import {PegBTC} from "../src/PegBTC.sol";
import {UpgradeableProxy} from "../src/UpgradeableProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

/*
Script: Deploy the Gateway contract and related contracts.
Required env vars:
- PRIVATE_KEY: uint256 private key to broadcast from (deployer)
- BITCOINSPV_ADDR: address of the BitcoinSPV contract
*/
contract DeployGateway is Script {
address public deployer;
address public bitcoinSPV;

function setUp() public virtual {
bitcoinSPV = vm.envAddress("BITCOINSPV_ADDR");
}

function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
deployer = vm.createWallet(deployerPrivateKey).addr;
console.log("deployer address: ", deployer);
vm.startBroadcast(deployerPrivateKey);
deploy();
vm.stopBroadcast();
}

function deploy() public {
// deploy gateway implementation + proxy
GatewayUpgradeable gatewayImpl = new GatewayUpgradeable();
console.log(
"Gateway implementation contract address: ",
address(gatewayImpl)
);

UpgradeableProxy gatewayProxy = new UpgradeableProxy(
address(gatewayImpl),
deployer,
""
);
console.log("Gateway proxy contract address: ", address(gatewayProxy));
GatewayUpgradeable gateway = GatewayUpgradeable(payable(gatewayProxy));

PegBTC pegBTC = new PegBTC(address(gateway));
console.log("PegBTC contract address: ", address(pegBTC));

// Read committee config from env
address[] memory initialMembers = _readSequentialAddresses("COMMITTEE");
uint256 initialRequired = (initialMembers.length * 2 + 2) / 3;
bytes32[] memory initialWatchtowers = _readSequentialBytes32(
"WATCHTOWER"
);
require(initialMembers.length > 0, "COMMITTEE list empty");
require(initialWatchtowers.length > 0, "WATCHTOWER list empty");
address[] memory initialAuthorizedCallers = new address[](1);
initialAuthorizedCallers[0] = address(gateway);

// Deploy CommitteeManagement implementation + proxy
CommitteeManagement committeeImpl = new CommitteeManagement();
console.log(
"CommitteeManagement implementation contract address: ",
address(committeeImpl)
);
bytes memory committeeInitData = abi.encodeWithSelector(
CommitteeManagement.initialize.selector,
initialMembers,
initialRequired,
initialAuthorizedCallers,
initialWatchtowers
);
UpgradeableProxy committeeProxy = new UpgradeableProxy(
address(committeeImpl),
deployer,
committeeInitData
);
console.log(
"CommitteeManagement proxy contract address: ",
address(committeeProxy)
);
ICommitteeManagement committeeManagement = ICommitteeManagement(
address(committeeProxy)
);

// Deploy StakeManagement implementation + proxy
StakeManagement stakeImpl = new StakeManagement();
console.log(
"StakeManagement implementation contract address: ",
address(stakeImpl)
);
bytes memory stakeInitData = abi.encodeWithSelector(
StakeManagement.initialize.selector,
IERC20(address(pegBTC)),
address(gateway)
);
UpgradeableProxy stakeProxy = new UpgradeableProxy(
address(stakeImpl),
deployer,
stakeInitData
);
console.log(
"StakeManagement proxy contract address: ",
address(stakeProxy)
);
IStakeManagement stakeManagement = IStakeManagement(
address(stakeProxy)
);

gateway.initialize(
IPegBTC(address(pegBTC)),
IBitcoinSPV(bitcoinSPV),
committeeManagement,
stakeManagement
);
}

function _readSequentialAddresses(
string memory baseKey
) internal view returns (address[] memory out) {
uint256 count = 0;
while (true) {
string memory key = string(
abi.encodePacked(baseKey, "_", vm.toString(count))
);
address val = vm.envOr(key, address(0));
if (val == address(0)) break;
unchecked {
count++;
}
}
out = new address[](count);
for (uint256 i = 0; i < count; i++) {
string memory key = string(
abi.encodePacked(baseKey, "_", vm.toString(i))
);
out[i] = vm.envAddress(key);
}
}

function _readSequentialBytes32(
string memory baseKey
) internal view returns (bytes32[] memory out) {
uint256 count = 0;
while (true) {
string memory key = string(
abi.encodePacked(baseKey, "_", vm.toString(count))
);
bytes32 val = vm.envOr(key, bytes32(0));
if (val == bytes32(0)) break;
unchecked {
count++;
}
}
out = new bytes32[](count);
for (uint256 i = 0; i < count; i++) {
string memory key = string(
abi.encodePacked(baseKey, "_", vm.toString(i))
);
out[i] = vm.envBytes32(key);
}
}
}
Loading