-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a524902
commit fb99fb5
Showing
2 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.6.12; | ||
pragma experimental ABIEncoderV2; | ||
|
||
import {SynapseERC20} from "../../contracts/bridge/SynapseERC20.sol"; | ||
|
||
import {BasicSynapseScript, StringUtils} from "../templates/BasicSynapse.s.sol"; | ||
|
||
contract VerifySynapseERC20 is BasicSynapseScript { | ||
struct Address { | ||
string label; | ||
address addr; | ||
} | ||
|
||
uint256 public constant NOT_FOUND = type(uint256).max; | ||
|
||
SynapseERC20 public token; | ||
|
||
Address[] public admins; | ||
Address[] public minters; | ||
|
||
function run(string memory symbol) external { | ||
// Setup the BasicSynapseScript | ||
setUp(); | ||
printLog(StringUtils.concat("Current chain: ", activeChain)); | ||
token = SynapseERC20(getDeploymentAddress(symbol)); | ||
addAddress(admins, "DevMultisig"); | ||
addAddress(admins, "DevMultisigLegacy"); | ||
addAddress(minters, "SynapseBridge"); | ||
// Log Metadata | ||
printMetadata(symbol); | ||
// Check roles | ||
checkRole(admins, "Admin", token.DEFAULT_ADMIN_ROLE()); | ||
checkRole(minters, "Minter", token.MINTER_ROLE()); | ||
} | ||
|
||
function printMetadata(string memory symbol) internal { | ||
printLog(StringUtils.concat("Checking ", symbol, ": ", vm.toString(address(token)))); | ||
increaseIndent(); | ||
printLog(StringUtils.concat("Name: ", token.name())); | ||
printLog(StringUtils.concat("Symbol: ", token.symbol())); | ||
printLog(StringUtils.concat("Decimals: ", vm.toString(uint256(token.decimals())))); | ||
decreaseIndent(); | ||
} | ||
|
||
function addAddress(Address[] storage addresses, string memory label) internal { | ||
address addr = tryGetDeploymentAddress(label); | ||
if (addr != address(0)) { | ||
addresses.push(Address(label, addr)); | ||
} | ||
} | ||
|
||
function checkRole( | ||
Address[] storage potentialMembers, | ||
string memory roleName, | ||
bytes32 role | ||
) internal { | ||
uint256 count = token.getRoleMemberCount(role); | ||
printLog(StringUtils.concat("Role ", roleName, " has ", vm.toString(count), " members")); | ||
increaseIndent(); | ||
if (count == 0) { | ||
printCondition(false, "No members"); | ||
} | ||
for (uint256 i = 0; i < count; i++) { | ||
address member = token.getRoleMember(role, i); | ||
uint256 index = findMember(potentialMembers, member); | ||
if (index != NOT_FOUND) { | ||
printCondition(true, StringUtils.concat(vm.toString(member), " [", potentialMembers[index].label, "]")); | ||
} else { | ||
printCondition(false, StringUtils.concat(vm.toString(member), " is not an expected member")); | ||
} | ||
} | ||
decreaseIndent(); | ||
} | ||
|
||
function findMember(Address[] storage potentialMembers, address member) internal view returns (uint256) { | ||
for (uint256 i = 0; i < potentialMembers.length; i++) { | ||
if (potentialMembers[i].addr == member) { | ||
return i; | ||
} | ||
} | ||
return NOT_FOUND; | ||
} | ||
|
||
function printCondition(bool condition, string memory message) internal { | ||
printLog(StringUtils.concat(condition ? "✅ " : "❌ ", message)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
# Usage: ./script/bridge/check-synERC20.sh <symbol> | ||
|
||
symbol=$1 | ||
# Check that all required args exist | ||
if [ -z "$symbol" ]; then | ||
echo "Usage: ./script/bridge/check-synERC20.sh <symbol>" | ||
exit 1 | ||
fi | ||
# Find all <symbol>.json files in ./deployments | ||
deployments=$(find ./deployments -name "${symbol}.json") | ||
# Extract chain name from the list of filenames, sort alphabetically | ||
chainNames=$(echo "$deployments" | sed 's/.*\/\(.*\)\/'$symbol'.json/\1/' | sort) | ||
# Print the comma separated list of chain aliases, don't put a comma after the last one | ||
chainNamesFormatted=$(echo "$chainNames" | sed ':a;N;$!ba;s/\n/, /g') | ||
echo "Checking $symbol on chains: [$chainNamesFormatted]" | ||
# Run the script for each chain | ||
for chainName in $chainNames; do | ||
forge script ./script/bridge/VerifySynapseERC20.s.sol -f "$chainName" --sig "run(string)" "$symbol" | ||
done |