Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MU07 - Chainlink Relayers #206

Merged
merged 49 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
98b4d23
forge install: mento-core-develop
bowd Aug 7, 2024
849cad2
feat: implement scripts for deploying and managing the chainlink rela…
bowd Aug 8, 2024
b6f1416
feat: add scripts for MockAggregator deployment and deploy PHP rates
bowd Aug 9, 2024
cf1c1c9
Apply suggestions from code review
bowd Aug 15, 2024
34bec4b
chore: wip
bowd Aug 13, 2024
020cc6b
Pass proposals on mento gov (#200)
baroooo Aug 8, 2024
ea5b093
chore: reproduce deployment broadcast files from on-chain data (#204)
bowd Aug 13, 2024
a6b2c31
feat: a huge commit that I can't really name well, sorry
bowd Aug 15, 2024
46ea912
feat: revert MU07 to 0.5 to not deal with that in this PR
bowd Aug 15, 2024
1eb2733
Merge branch 'main' into feat/deploy-chainlink-relayer
bowd Aug 15, 2024
c8d5b09
feat: improve RelayerReport script to show status of all relayers
bowd Aug 15, 2024
525717f
Merge branch 'main' into feat/deploy-chainlink-relayer
bowd Aug 19, 2024
865d71c
feat: bring it back to the classic structure
bowd Aug 19, 2024
1f0c70e
feat: refactor deployment scripts to match existing structure
bowd Aug 19, 2024
2f77cca
fix: lint
bowd Aug 19, 2024
84a6478
fix: remove submodule form another mother
bowd Aug 19, 2024
6cf5f58
fix: remove submodule form another mother
bowd Aug 19, 2024
7bf91ea
fix: submodule fun time
bowd Aug 19, 2024
3e2d048
fix: submodule fun time
bowd Aug 19, 2024
a21efde
forge install: mento-core-2.4.0
bowd Aug 19, 2024
5bc19cf
docs: add comments for regexp
bowd Aug 19, 2024
7ffd513
chore: some test broadcast files that shouldn't be here
bowd Aug 19, 2024
2a65b72
chore: keep the right broadcast file
bowd Aug 19, 2024
4fc774c
chore: fix typo in comment
bowd Aug 19, 2024
ffba620
chore: fix typoe in import
bowd Aug 19, 2024
9d28b96
fix: function visibility
bowd Aug 19, 2024
e465b35
docs: add clarifying comment
bowd Aug 19, 2024
485a8ea
Merge branch 'main' into feat/deploy-chainlink-relayer
chapati23 Aug 20, 2024
9a52708
feat: execute MU07 on baklava
philbow61 Aug 22, 2024
69e3360
feat: update deployment scripts for relayers with maxTimestampSpread
bowd Aug 25, 2024
c80b68f
feat: redeploy and whitelist relayers
bowd Aug 25, 2024
9bbb2f3
Merge branch 'main' into feat/deploy-chainlink-relayer
bowd Aug 26, 2024
c00c888
fix: update PUSO reference and remove old broadcast files
bowd Aug 26, 2024
1547ead
chore: remove develop submodule
bowd Aug 26, 2024
7bb97ca
forge install: mento-core-2.5.0
bowd Aug 26, 2024
a038eac
chore: cleanup
bowd Aug 26, 2024
93338bc
fix: typo in contract name
bowd Aug 26, 2024
667e60a
fix: naming in DeployMockChainlinkAggregator
bowd Aug 26, 2024
8bac484
fix: solhint warnings
bowd Aug 26, 2024
4aac981
feat: redeploy and cleanup
bowd Aug 26, 2024
a4dfb5d
chore: add broadcast file
bowd Aug 26, 2024
33d3452
fix: remove 2.4.0
bowd Aug 26, 2024
877796b
Update script/upgrades/MU07/MU07.sol
chapati23 Aug 26, 2024
dc8caaf
fix: make naming consistent and mock aggregator ownable
bowd Aug 27, 2024
50db5bf
fix: rename broadcast files to be consistent
bowd Aug 27, 2024
663bcd4
fix: rename broadcast files to be consistent
bowd Aug 27, 2024
e15d787
chore: rerun alfajores deployment
bowd Aug 27, 2024
d84a649
chore: deploy relayers to mainnet
bowd Aug 27, 2024
6d93bff
chore: add .md link
philbow61 Aug 28, 2024
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
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
5 changes: 3 additions & 2 deletions bin/cgp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ else
fi

if [ "$SIMULATE" = true ] ; then
echo "🥸 Simulating $CONTRACT"
forge script $(forge_skip $UPGRADE) --rpc-url $RPC_URL --skip .dev.sol --sig "run(string)" $UTILS_DIR/SimulateUpgrade.sol:SimulateUpgrade $CONTRACT
yarn build -u $UPGRADE
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
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 !== "verified") {
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
51 changes: 51 additions & 0 deletions broadcast/DeployMockChainlinkAggregator.sol/44787/run-PHPUSD.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"transactions": [
{
"hash": "0x2ff9d07f71a639b30cda5e3b13dd053517e229a2626d75e1bf09882ccb63766d",
"transactionType": "CREATE",
"contractName": "MockChainlinkAggregator",
"contractAddress": "0x995c827326bc7393bfa28785f98744548874b2f0",
"function": null,
"arguments": [
"\"PHPUSD\""
],
"transaction": {
"from": "0x56fd3f2bee130e9867942d0f463a16fbe49b8d81",
"gas": "0x55754",
"value": "0x0",
"input": "0x6080604052346101ec5761057080380380610019816101f1565b92833981019060209081818403126101ec5780516001600160401b03918282116101ec570191601f908482850112156101ec5783518381116101c257601f1994610068828501871684016101f1565b968288528383830101116101ec57829060005b8381106101d85750506000918701015284519283116101c25760019384548581811c911680156101b8575b838210146101a25783811161015c575b50819284116001146100fd5750508192936000926100f2575b5050600019600383901b1c191690821b1790555b60405161035990816102178239f35b0151905038806100cf565b6000858152828120918516969193925b8782106101455750508385961061012c575b505050811b0190556100e3565b015160001960f88460031b161c1916905538808061011f565b80878596829496860151815501950193019061010d565b85600052826000208480870160051c820192858810610199575b0160051c019086905b82811061018d5750506100b6565b6000815501869061017f565b92508192610176565b634e487b7160e01b600052602260045260246000fd5b90607f16906100a6565b634e487b7160e01b600052604160045260246000fd5b81810183015189820184015284920161007b565b600080fd5b6040519190601f01601f191682016001600160401b038111838210176101c25760405256fe60806040818152600436101561001457600080fd5b600091823560e01c908163313ce56714610313575080637284e4161461012257806399213cd8146100e7578063e1e244d8146100ad5763feaf968c1461005957600080fd5b346100a957817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100a957818060a093549280519382855260208501528301524260608301526080820152f35b5080fd5b50346100a957817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100a957602091549051908152f35b823461011f5760207ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011f57600435815580f35b80fd5b50903461011f57807ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc36011261011f57815191819260019283549485851c94808716968715610309575b60209788881081146102dc57878652889291811561029f575060011461024a575b505082939450601f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe094859203011682019482861067ffffffffffffffff87111761021d5785929391838652818452845191828186015281955b8387106102055750508394508582601f949501015201168101030190f35b868101820151898801890152958101958895506101e7565b6024827f4e487b710000000000000000000000000000000000000000000000000000000081526041600452fd5b80845290915082907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b87831061028c5750949550859450830101853861018d565b8054868401850152918301918101610274565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001683870152509495869550151560051b8401019050853861018d565b6024857f4e487b710000000000000000000000000000000000000000000000000000000081526022600452fd5b95607f169561016c565b8390346100a957817ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc3601126100a95780600860209252f3fea164736f6c6343000812000a000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000065048505553440000000000000000000000000000000000000000000000000000",
"nonce": "0x53a",
"chainId": "0xaef3"
},
"additionalContracts": [],
"isFixedGasLimit": false
}
],
"receipts": [
{
"status": "0x1",
"cumulativeGasUsed": "0x4debf",
"logs": [],
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"type": "0x0",
"transactionHash": "0x2ff9d07f71a639b30cda5e3b13dd053517e229a2626d75e1bf09882ccb63766d",
"transactionIndex": "0x1",
"blockHash": "0x5b20baf7869ba1c534452d7f878c55ef16481502fdb79c16edbf2d2b604f3ab9",
"blockNumber": "0x188a1e6",
"gasUsed": "0x41bcb",
"effectiveGasPrice": "0x2540be400",
"from": "0x56fd3f2bee130e9867942d0f463a16fbe49b8d81",
"to": null,
"contractAddress": "0x995c827326bc7393bfa28785f98744548874b2f0"
}
],
"libraries": [
"lib/mento-core-2.0.0/contracts/common/linkedlists/AddressLinkedList.sol:AddressLinkedList:0x2F0F7686fFFEfc3C266403Ad600035581deaedff",
"lib/mento-core-2.0.0/contracts/common/linkedlists/AddressSortedLinkedListWithMedian.sol:AddressSortedLinkedListWithMedian:0x29B1B5e05217c751038861aF2C77494EAB10A257"
],
"pending": [],
"returns": {},
"timestamp": 1724069971,
"chain": 44787,
"commit": "865d71c"
}
Loading
Loading