Skip to content

Commit

Permalink
Merge pull request #3233 from Sifchain/pause-unpause-scripts
Browse files Browse the repository at this point in the history
New Pauser/UnPauser scripts for planned downtime on EVM bridges.
  • Loading branch information
khdegraaf authored Sep 14, 2022
2 parents 4fb2b95 + 2722d99 commit e4c814e
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 1 deletion.
2 changes: 1 addition & 1 deletion smart-contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const envconfig = dotenv.config();
const mainnetUrl = process.env["MAINNET_URL"] ?? "https://example.com";
const ropstenUrl = process.env["ROPSTEN_URL"] ?? "https://example.com";

const activePrivateKey = process.env[process.env["ACTIVE_PRIVATE_KEY"] ?? "0xabcd"] ?? "0xabcd";
const activePrivateKey = process.env["ACTIVE_PRIVATE_KEY"] ?? "0xabcd";
const keyList = activePrivateKey.indexOf(",") ? activePrivateKey.split(",") : [activePrivateKey];

const config: HardhatUserConfig = {
Expand Down
59 changes: 59 additions & 0 deletions smart-contracts/scripts/pauseBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This script will pause the bridgebank smart contract to shut down EVM imports.
* Use with care.
*
* To use this script make sure the environment variable ACTIVE_PRIVATE_KEY is set to the pauser private key before running
* Make sure you have environment variable MAINNET_URL set to a HTTP/HTTPS Full/Archive Node for the EVM chain in communication
* Make sure the pauser address has at least 1 ETH before running
*/

import { ethers } from "hardhat";
import { BridgeBank__factory } from "../build";

const bridgeBankAddress = process.env["BRIDGEBANK_ADDRESS"] ?? "0xB5F54ac4466f5ce7E0d8A5cB9FE7b8c0F35B7Ba8";

async function pauseBridge() {
// Connect to BridgeBank and get User Info
const bridgebankFactory = await ethers.getContractFactory("BridgeBank") as BridgeBank__factory;
const bridgebank = await bridgebankFactory.attach(bridgeBankAddress);
const userAddress = await bridgebank.signer.getAddress();
let paused = await bridgebank.paused();
const balance = await bridgebank.signer.getBalance();

// Sanity Condition Checks
if (paused) {
console.error("Bridgebank is already paused, no actions to do");
return;
}

if (!(await bridgebank.pausers(userAddress))) {
console.error(`Private key has public address: ${userAddress}, which is not a valid pauser address`);
return;
}

if (balance.lt(ethers.utils.parseEther("0.5"))) {
console.error(`Script requires a minimum of 0.5 ETH before it will attempt to run.`)
console.error(`Current balance is ${ethers.utils.formatEther(balance)} ETH`);
return;
}

// Pause The Bridge
console.log("Sending the pause transaction");
const tx = await bridgebank.pause();
console.log("Transaction sent, waiting for transaction receipt");
const receipt = await tx.wait();
console.log(`Received transaction receipt. Transaction Hash: ${receipt.transactionHash}`);

// Confirm the bridge is now paused
paused = await bridgebank.paused();
if (paused) {
console.log("Confirmed the BridgeBank is now paused");
} else {
console.error("We have received a pause transaction receipt but BridgeBank is not paused...");
console.error("!!!!!CRITICAL CONDITION REACHED, CONTACT PEGGY TEAM IMMEDIATELY!!!!!")
}
}

pauseBridge()
.then(() => console.log("Pauser Script has completed"))
.catch((error) => console.error("An error ocurred when attempting to pause bridgebank: ", error))
59 changes: 59 additions & 0 deletions smart-contracts/scripts/unPauseBridge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This script will resume the bridgebank smart contract and allow EVM imports.
* Only use after the cause of the pause has been resolved!
*
* To use this script make sure the environment variable ACTIVE_PRIVATE_KEY is set to the unpauser private key before running
* Make sure you have environment variable MAINNET_URL set to a HTTP/HTTPS Full/Archive Node for the EVM chain in communication
* Make sure the unpauser address has at least 1 ETH before running
*/

import { ethers } from "hardhat";
import { BridgeBank__factory } from "../build";

const bridgeBankAddress = process.env["BRIDGEBANK_ADDRESS"] ?? "0xB5F54ac4466f5ce7E0d8A5cB9FE7b8c0F35B7Ba8";

async function unpauseBridge() {
// Connect to BridgeBank and get User Info
const bridgebankFactory = await ethers.getContractFactory("BridgeBank") as BridgeBank__factory;
const bridgebank = await bridgebankFactory.attach(bridgeBankAddress);
const userAddress = await bridgebank.signer.getAddress();
let paused = await bridgebank.paused();
const balance = await bridgebank.signer.getBalance();

// Sanity Condition Checks
if (!paused) {
console.error("Bridgebank is not paused, no actions to do");
return;
}

if (!(await bridgebank.pausers(userAddress))) {
console.error(`Private key has public address: ${userAddress}, which is not a valid unpauser address`);
return;
}

if (balance.lt(ethers.utils.parseEther("0.5"))) {
console.error(`Script requires a minimum of 0.5 ETH before it will attempt to run.`)
console.error(`Current balance is ${ethers.utils.formatEther(balance)} ETH`);
return;
}

// Pause The Bridge
console.log("Sending the unpause transaction");
const tx = await bridgebank.unpause();
console.log("Transaction sent, waiting for transaction receipt");
const receipt = await tx.wait();
console.log(`Received transaction receipt. Transaction Hash: ${receipt.transactionHash}`);

// Confirm the bridge is now unpaused
paused = await bridgebank.paused();
if (!paused) {
console.log("Confirmed the BridgeBank is now unpaused");
} else {
console.error("We have received a unpause transaction receipt but BridgeBank is still paused...");
console.error("!!!!!CRITICAL CONDITION REACHED, CONTACT PEGGY TEAM IMMEDIATELY!!!!!")
}
}

unpauseBridge()
.then(() => console.log("Unpausing Script has completed"))
.catch((error) => console.error("An error ocurred when attempting to unpause bridgebank: ", error))

0 comments on commit e4c814e

Please sign in to comment.