Skip to content

Commit

Permalink
Merge branch 'main' into feat/MU08
Browse files Browse the repository at this point in the history
  • Loading branch information
philbow61 authored Aug 29, 2024
2 parents 971caa2 + 62e97df commit 990f4e9
Show file tree
Hide file tree
Showing 56 changed files with 3,906 additions and 1,033 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ yarn-error.log*

# broadcasts
!/broadcast
/broadcast/Dev-*
/broadcast/dev-*
!/broadcast/dev-DeployMockChainlinkAggregator.sol/
!/broadcast/ExecuteProposal*
/broadcast/PassProposal*
/broadcast/QueueProposal*
Expand Down
7 changes: 5 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
[submodule "lib/mento-core-2.3.1"]
path = lib/mento-core-2.3.1
url = https://github.com/mento-protocol/mento-core
[submodule "lib/mento-core-2.4.0"]
path = lib/mento-core-2.4.0
[submodule "lib/mento-core-develop"]
path = lib/mento-core-develop
url = https://github.com/mento-protocol/mento-core
[submodule "lib/mento-core-2.5.0"]
path = lib/mento-core-2.5.0
url = https://github.com/mento-protocol/mento-core
23 changes: 14 additions & 9 deletions bin/deploy.sh → bin/cgp-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

##############################################################################
# Script for running all deployment tasks for a protocol upgrade
# Usage: ./bin/deploy.sh
# Usage: ./bin/cgp-deploy.sh
# -n <baklava|alfajores|celo> -- network to submit the proposal to
# -u <upgrade_name> -- name of the upgrade (MU01)
# -s -- name of the script (optional)
# Example: ./bin/deploy.sh -n baklava -u MU01
# Example: ./bin/cgp-deploy.sh -n baklava -u MU01
##############################################################################

source "$(dirname "$0")/setup.sh"
Expand All @@ -27,19 +27,24 @@ parse_network "$NETWORK"
parse_upgrade "$UPGRADE"

if ! [ -z "$SCRIPT" ]; then # Pick the script by name
SCRIPT_FILE="script/upgrades/$UPGRADE/deploy/$SCRIPT"
if test -f "$SCRIPT_FILE"; then
echo "🔎 $SCRIPT_FILE found"
forge_script "$SCRIPT" "$SCRIPT_FILE" "$(forge_skip $UPGRADE)"
DEPLOY_SCRIPT="script/upgrades/$UPGRADE/deploy/$SCRIPT"
if test -f "$DEPLOY_SCRIPT"; then
echo "🔎 $DEPLOY_SCRIPT found"
echo "=================================================================="
echo " Running $(basename $DEPLOY_SCRIPT)"
echo "=================================================================="
forge script $(forge_skip $UPGRADE) --rpc-url $RPC_URL --legacy --verify --verifier sourcify --broadcast $DEPLOY_SCRIPT
exit 0
else
echo "🚨 Script $SCRIPT not found in $SCRIPT_FILE"
echo "🚨 Script $SCRIPT not found in $DEPLOY_SCRIPT"
exit 1
fi
fi

export FOUNDRY_PROFILE=$NETWORK-deployment
for DEPLOY_SCRIPT in $UPGRADE_DIR/deploy/*; do
DEPLOY_FILE=$(basename $DEPLOY_SCRIPT)
forge_script "$DEPLOY_FILE" "$DEPLOY_SCRIPT" "$(forge_skip $UPGRADE)"
echo "=================================================================="
echo " Running $(basename $DEPLOY_SCRIPT)"
echo "=================================================================="
forge script $(forge_skip $UPGRADE) --rpc-url $RPC_URL --legacy --verify --verifier sourcify --broadcast $DEPLOY_SCRIPT
done
4 changes: 2 additions & 2 deletions bin/cgp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fi

if [ "$SIMULATE" = true ] ; then
yarn build -u $UPGRADE
echo "🥸 Simulating $CONTRACT"
forge script $(forge_skip $UPGRADE) --rpc-url $RPC_URL --skip .dev.sol --sig "run(string)" $UTILS_DIR/SimulateUpgrade.sol:SimulateUpgrade $CONTRACT
echo "🥸 Simulating $CONTRACT"
forge script $(forge_skip $UPGRADE) --rpc-url $RPC_URL --sig "run(string)" $UTILS_DIR/SimulateUpgrade.sol:SimulateUpgrade $CONTRACT
else
echo "🔥 Submitting $CONTRACT"
confirm_if_celo "$NETWORK"
Expand Down
32 changes: 24 additions & 8 deletions bin/dev-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# Script for running all deployment tasks for a protocol upgrade
# Usage: ./bin/dev-script.sh
# -n <baklava|alfajores|celo> -- network to submit the proposal to
# -i <script-index> -- index of the script (optional)
# -s <script-name> -- name of the script (optional)
# -i <script-index> -- index of the script (optional)
# -s <script-name> -- name of the script (optional)
# -r <run-signature> -- signature of the run function (optional)
# Example:
# To pick the script:
# ./bin/deploy.sh -n baklava
Expand All @@ -20,22 +21,30 @@ source "$(dirname "$0")/setup.sh"
NETWORK=""
INDEX=""
SCRIPT_NAME=""
while getopts n:i:s: flag
RUN_SIGNATURE="run()"
while getopts n:i:s:r: flag
do
case "${flag}" in
n) NETWORK=${OPTARG};;
i) INDEX=${OPTARG};;
s) SCRIPT_NAME=${OPTARG};;
r) RUN_SIGNATURE=${OPTARG};;
esac
done

shift "$((OPTIND - 1))"

parse_network "$NETWORK"

if ! [ -z "$SCRIPT_NAME" ]; then # Pick the script by name
SCRIPT_FILE="script/dev/dev-$SCRIPT_NAME.sol"
if test -f "$SCRIPT_FILE"; then
echo "🔎 $SCRIPT_FILE found"
forge_script "$SCRIPT_NAME" "$SCRIPT_FILE" $(forge_skip "dev")
echo "=================================================================="
echo " Running $SCRIPT_NAME"
echo "=================================================================="
confirm_if_celo "$NETWORK"
forge script $(forge_skip "dev") --rpc-url $RPC_URL --legacy --verify --verifier sourcify --broadcast -s $RUN_SIGNATURE $SCRIPT_FILE "$@"
exit 0
else
echo "🚨 Script $SCRIPT_NAME not found in $SCRIPT_FILE"
Expand All @@ -49,8 +58,12 @@ if ! [ -z "$INDEX" ]; then # Pick the script by index
echo "🚨 Index $INDEX is out of range or invalid"
exit 1
fi
SCRIPT=$(ls script/dev/* | head -n $INDEX | tail -n 1)
forge_script "$(basename $SCRIPT .sol | sed 's/dev-//g')" "$SCRIPT" $(forge_skip "dev")
SCRIPT_FILE=$(ls script/dev/* | head -n $INDEX | tail -n 1)
echo "=================================================================="
echo " Running $(basename SCRIPT_FILE)"
echo "=================================================================="
confirm_if_celo "$NETWORK"
forge script $(forge_skip "dev") --rpc-url $RPC_URL --legacy --verify --verifier sourcify --broadcast -s $RUN_SIGNATURE $SCRIPT_FILE "$@"
exit 0
fi

Expand All @@ -64,8 +77,11 @@ do
SCRIPT_FILE="script/dev/dev-$SCRIPT.sol"
if test -f "$SCRIPT_FILE"; then
echo "🔎 $SCRIPT_FILE found"
forge_script "$SCRIPT" "$SCRIPT_FILE" "$(forge_skip "dev")"
exit 0
echo "=================================================================="
echo " Running $(basename SCRIPT_FILE)"
echo "=================================================================="
confirm_if_celo "$NETWORK"
forge script $(forge_skip "dev") --rpc-url $RPC_URL --legacy --verify --verifier sourcify --broadcast $SCRIPT_FILE
else
echo "Invalid option, press Ctrl+C to exit"
fi
Expand Down
10 changes: 1 addition & 9 deletions bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ forge_skip () { # $1: target
fi
}

forge_script () { # $1: script name, $2: script file path
echo "=================================================================="
echo "🏃🏼 Running $1"
echo "=================================================================="
confirm_if_celo "$NETWORK"
forge script $3 --rpc-url $RPC_URL --legacy --broadcast --verify --verifier sourcify $2
}

confirm_if_celo () { # $1: network
if [ "celo" = $1 ]; then
while true; do
Expand All @@ -109,4 +101,4 @@ countdown() { # $1: seconds
echo -ne "$i seconds remaining...\033[0K\r"
sleep 1
done
}
}
24 changes: 24 additions & 0 deletions bin/utils/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,30 @@ type VerifyParams = {
version: string;
args: string;
};

type CheckParams = {
api: string;
apiKey: string | undefined;
contract: string;
}

export async function check({ api, apiKey, contract }: CheckParams): Promise<boolean> {
const params = new URLSearchParams();
if (apiKey) {
params.append("apikey", apiKey);
}
params.append("module", "contract");
params.append("action", "getabi");
params.append("address", contract);

const data = await fetch(api, {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded;charset=utf-8" },
body: params,
}).then(res => res.json());
return data['message'] === "OK" && data['status'] === "1";
}

export async function verify({ api, apiKey, contract, source, target, version, args }: VerifyParams): Promise<string> {
const params = new URLSearchParams();
if (apiKey) {
Expand Down
4 changes: 3 additions & 1 deletion bin/utils/sourcify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export async function check(chainId: number, contract: string): Promise<string>
if (!data || !data[0]) {
return "false";
}
return data[0].status;
return data[0].chainIds.find(
({ chainId }: { chainId: string, status: string }) => chainId === chainId
)?.status ?? "false";
}

export async function files(chainId: number, contract: string): Promise<any> {
Expand Down
43 changes: 29 additions & 14 deletions bin/verify-celoscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ interface BroadcastFile {
initCode: string;
}>;
transaction: {
data: string;
data?: string;
input?: string
};
}>;
chain: number;
Expand Down Expand Up @@ -81,7 +82,7 @@ async function run() {
if (tx.transactionType === "CREATE") {
createdContracts.push({
contract: tx.contractAddress,
initCode: tx.transaction.data,
initCode: tx.transaction.data || tx.transaction.input
});
}
if (tx.additionalContracts && tx.additionalContracts.length > 0) {
Expand Down Expand Up @@ -113,7 +114,7 @@ async function run() {
}

if (successful.length > 0) {
console.log(`✅ Successfully verified ${successful.length} contracts`);
console.log(`✅ ${successful.length} contracts are verified:`);
for (const contract of successful) {
console.log(" - ", contract);
}
Expand All @@ -132,18 +133,24 @@ async function run() {
}
}

async function verify({ contract, initCode }: { contract: string; initCode: string }) {
const status = await sourcify.check(broadcast.chain, contract);
if (status === "false") {
console.error(`🚨 Contract ${contract} not found on sourcify`);
return;
async function verify({ contract, initCode }: { contract: string; initCode?: string }) {
const isVerified = await etherscan.check({
api: celoscanApiUrl,
apiKey: celoscanApiKey,
contract: contract,
})
if (isVerified) {
console.log(`✅ Contract ${contract} verified on celoscan`);
return true;
}

if (status === "verified") {
console.log(`✅ Contract ${contract} verified on sourcify`);
const status = await sourcify.check(broadcast.chain, contract);
if (!(status == "partial" || status == "full")) {
console.error(`🚨 Contract ${contract} not found on sourcify`);
return false;
}

console.log(`🔍 Verifying ${contract} on celoscan...`);
console.log(`⌛ Contract ${contract} verified on sourcify, pushing to celoscan...`);
const files = await sourcify.files(broadcast.chain, contract);
const {
target,
Expand All @@ -156,7 +163,7 @@ async function verify({ contract, initCode }: { contract: string; initCode: stri
const standardJson = makeStandardJson(metadata, sources, libraryMap);

let constructorArgs = constructorArgsFromSourcify;
if (constructorArgs === "") {
if (constructorArgs === "" && !!initCode) {
constructorArgs = getConstructorArgs(target, contract, initCode);
}

Expand Down Expand Up @@ -191,8 +198,16 @@ async function verify({ contract, initCode }: { contract: string; initCode: stri
}

function getConstructorArgs(target: string, contract: string, initCode: string) {
const solidityFile = /([^\/]*.sol)/.exec(target)![0];
const contractName = solidityFile.split(".")[0];
// Target can be of the form "filename.sol:ContractName" or just "ContractName.sol"
// This regexp matches ((...).sol):(...) so:
// match[1] is the filename, i.e. the first larger bracket
// match[2] is the filename without termination
// match[3] is the optional contract name which can be empty
const match = /(([^\/]*).sol):?(.*)?/.exec(target);
if (!match) throw Error(`Error extracting filename and contract from: ${target}`)
const solidityFile = match[1]
const contractName = match[3] || match[2];

try {
const foundryJson = JSON.parse(fs.readFileSync(`out/${solidityFile}/${contractName}.json`, "utf8"));
let bytecode = foundryJson.bytecode.object;
Expand Down
Loading

0 comments on commit 990f4e9

Please sign in to comment.