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

Deploy CBridge to Gravity #856

Merged
merged 8 commits into from
Jan 9, 2025
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
10 changes: 9 additions & 1 deletion config/cbridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"0x01BA67AAC7f75f647D94220Cc98FB30FCc5105Bf",
"0x69af81e73A73B40adF4f3d4223Cd9b1ECE623074",
"0x4e352cF164E64ADCBad318C3a1e222E9EBa4Ce42",
"0xD69F306549e9d96f183B1AecA30B8f4353c2ECC3",
"0xa3BeD4E1c75D00fa6f4E5E6922DB7261B5E9AcD2",
"0x9E32b13ce7f2E80A01932B42553652E053D6ed8e",
"0x57f12FE6A4e5fe819eec699FAdf9Db2D06606bB4",
Expand Down Expand Up @@ -211,11 +212,18 @@
"linea": {
"cBridge": "0x9B36f165baB9ebe611d491180418d8De4b8f3a1f",
"tokensToApprove": [
"0xcf0f95E34F25d1BB3D9cad3Cbb2EB40dAb7c3841",
"0x0A3BB08b3a15A19b4De82F8AcFc862606FB69A2D",
"0x60D01EC2D5E98Ac51C8B4cF84DfCCE98D527c747",
"0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f"
]
},
"gravity": {
"cBridge": "0x9B36f165baB9ebe611d491180418d8De4b8f3a1f",
"tokensToApprove": [
"0xBB859E225ac8Fb6BE1C7e38D87b767e95Fef0EbD"
]
},
"base": {
"cBridge": "0x7d43AABC515C356145049227CeE54B608342c0ad",
"tokensToApprove": [
Expand Down Expand Up @@ -243,4 +251,4 @@
"0x4300000000000000000000000000000000000004"
]
}
}
}
24 changes: 24 additions & 0 deletions deployments/_deployments_log_file.json
Original file line number Diff line number Diff line change
Expand Up @@ -6935,6 +6935,20 @@
}
]
}
},
"gravity": {
"production": {
"1.0.0": [
{
"ADDRESS": "0x325DA62543447A48c7b044C5642B87CeA88B0fd3",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2024-11-12 14:01:08",
maxklenk marked this conversation as resolved.
Show resolved Hide resolved
"CONSTRUCTOR_ARGS": "0x0000000000000000000000009b36f165bab9ebe611d491180418d8de4b8f3a1f",
"SALT": "",
"VERIFIED": "true"
}
]
}
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
}
},
"GenericSwapFacet": {
Expand Down Expand Up @@ -16261,6 +16275,16 @@
]
}
},
"gravity": {
"production": {
"1.0.3": [
{
"ADDRESS": "0x49e93F6A99c590a8E70138D2710B9eDd88C077FF",
"OPTIMIZER_RUNS": "1000000",
"TIMESTAMP": "2024-11-12 14:01:58",
"CONSTRUCTOR_ARGS": "0x0000000000000000000000009b36f165bab9ebe611d491180418d8de4b8f3a1f00000000000000000000000011f1022ca6adef6400e5677528a80d49a069c00c",
"SALT": "",
"VERIFIED": "true"
"zksync": {
"production": {
"1.0.0": [
Expand Down
10 changes: 5 additions & 5 deletions deployments/gravity.diamond.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@
"Version": "2.0.0"
},
"0x49e93F6A99c590a8E70138D2710B9eDd88C077FF": {
"Name": "",
"Version": ""
"Name": "CBridgeFacetPacked",
"Version": "1.0.3"
},
"0x325DA62543447A48c7b044C5642B87CeA88B0fd3": {
"Name": "",
"Version": ""
"Name": "CBridgeFacet",
"Version": "1.0.0"
},
"0xbb44687E13B0DdB11682FA9299F5F982Ba3cc029": {
"Name": "SymbiosisFacet",
Expand All @@ -82,8 +82,8 @@
"LiFiDEXAggregator": "0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc",
"LiFuelFeeCollector": "0x134f525AC05E4724e55C363A9C4FA35ceB13F88d",
"Permit2Proxy": "",
"Receiver": "0x2DeB3bFa2b19024A0c1Ba299b6b79276f1F77b14",
"ReceiverAcrossV3": "",
"Receiver": "0x2DeB3bFa2b19024A0c1Ba299b6b79276f1F77b14",
"ReceiverStargateV2": "0x6A3d6652fb7be72200a47313C092342218aAeb72",
"RelayerCelerIM": "",
"TokenWrapper": "0x7fA60f4A59Dd8285C5Fcd8fd2A92A2Ca45ef8a0C"
Expand Down
2 changes: 2 additions & 0 deletions deployments/gravity.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"LiFiDEXAggregator": "0x6140b987d6B51Fd75b66C3B07733Beb5167c42fc",
"Receiver": "0x2DeB3bFa2b19024A0c1Ba299b6b79276f1F77b14",
"EmergencyPauseFacet": "0x6F2baA7cd5F156CA1B132F7FF11E0fa2aD775F61",
"CBridgeFacet": "0x325DA62543447A48c7b044C5642B87CeA88B0fd3",
"CBridgeFacetPacked": "0x49e93F6A99c590a8E70138D2710B9eDd88C077FF",
"GasZipFacet": "0xF5c923a087fb3c554579e2DD10AB6E37E0f6F849",
"GasZipPeriphery": "0x9a21E33F1a78b17DAd32010CeDB9Fd2F071C17d3",
"SymbiosisFacet": "0xbb44687E13B0DdB11682FA9299F5F982Ba3cc029"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import { UpdateScriptBase } from "../../deploy/facets/utils/UpdateScriptBase.sol
import { stdJson } from "forge-std/StdJson.sol";
import { DiamondCutFacet, IDiamondCut } from "lifi/Facets/DiamondCutFacet.sol";
import { CBridgeFacetPacked } from "lifi/Facets/CBridgeFacetPacked.sol";
import { ERC20 } from "solady/tokens/ERC20.sol";

contract DeployScript is UpdateScriptBase {
using stdJson for string;

address[] internal tokensToApprove;

ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
function run() public returns (address[] memory facets) {
address facet = json.readAddress(".CBridgeFacetPacked");

Expand All @@ -33,7 +36,21 @@ contract DeployScript is UpdateScriptBase {
bytes memory rawConfig = json.parseRaw(
string.concat(".", network, ".tokensToApprove")
);
address[] memory tokensToApprove = abi.decode(rawConfig, (address[]));
address[] memory tokens = abi.decode(rawConfig, (address[]));
address cBridge = json.readAddress(
string.concat(".", network, ".cBridge")
);

// Filter out any already approved tokens
for (uint256 i = 0; i < tokens.length; i++) {
if (ERC20(tokens[i]).allowance(facet, cBridge) == 0) {
tokensToApprove.push(tokens[i]);
}
}

if (tokensToApprove.length == 0) {
return loupe.facetAddresses();
}

vm.startBroadcast(refundPrivateKey);

Expand Down
135 changes: 65 additions & 70 deletions script/tasks/updateFacetConfig.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ updateFacetConfig() {

# read function arguments into variables
ENVIRONMENT="$2"
NETWORK="$3"
SCRIPT="$4"
DIAMOND_CONTRACT_NAME="$5"

# if no NETWORK was passed to this function, ask user to select it
if [[ -z "$NETWORK" ]]; then
# get user-selected network from list
NETWORK=$(cat ./networks | gum filter --placeholder "Network")
if [[ -z "$NETWORK" ]]; then
error "invalid selection - exiting script"
exit 1
fi
echo "[info] selected network: $NETWORK"
if [[ -z "$3" ]]; then
# get user-selected network from list
echo "Select Networks"
if command -v gum >/dev/null 2>&1; then
# Read the networks into an array, works on both Mac and Linux
IFS=$'\n' read -r -d '' -a NETWORKS < <(cat ./networks | gum choose --no-limit)

if [[ ${#NETWORKS[@]} -eq 0 ]]; then
error "No networks selected - exiting script"
exit 1
fi
echo "[info] selected networks: ${NETWORKS[*]}"
else
error "gum is not installed"
exit 1
fi
else
NETWORKS=("$3")
fi

# get deployer wallet balance
echo "[info] loading deployer wallet balance for network $NETWORK..."
BALANCE=$(getDeployerBalance "$NETWORK" "$ENVIRONMENT")
echo "[info] deployer wallet balance in this network: $BALANCE"
echo ""

# ensure all required .env values are set
checkRequiredVariablesInDotEnv $NETWORK

# if no SCRIPT was passed to this function, ask user to select it
# if no SCRIPT was passed to this function, ask user to select it
if [[ -z "$SCRIPT" ]]; then
# select which script to execute
local SCRIPT=$(ls -1 "$CONFIG_SCRIPT_DIRECTORY" | sed -e 's/\.s.sol$//' | gum filter --placeholder "Please select a script to execute")
Expand All @@ -42,64 +42,59 @@ updateFacetConfig() {
# determine full (relative) path of deploy script
SCRIPT_PATH=$CONFIG_SCRIPT_DIRECTORY"$SCRIPT.s.sol"

# if no DIAMOND_CONTRACT_NAME was passed to this function, ask user to select it
if [[ -z "$DIAMOND_CONTRACT_NAME" ]]; then
# ask user to select a diamond type for which to update the facet configuration
echo "[info] Please select the diamond type to be updated:"
DIAMOND_CONTRACT_NAME=$(gum choose \
"LiFiDiamond"\
"LiFiDiamondImmutable"\
)
echo "[info] selected diamond: $DIAMOND_CONTRACT_NAME"
fi

if [[ -z "$DIAMOND_CONTRACT_NAME" ]]; then
error "invalid selection - exiting script"
exit 1
fi
echo "[info] $DIAMOND_CONTRACT_NAME"
echo ""

DIAMOND_CONTRACT_NAME="LiFiDiamond"

# set flag for mutable/immutable diamond
USE_MUTABLE_DIAMOND=$( [[ "$DIAMOND_CONTRACT_NAME" == "LiFiDiamond" ]] && echo true || echo false )
USE_MUTABLE_DIAMOND="true"

# get file suffix based on value in variable ENVIRONMENT
FILE_SUFFIX=$(getFileSuffix "$ENVIRONMENT")

# repeatedly call selected script until it's succeeded or out of attempts
ATTEMPTS=1
while [ $ATTEMPTS -le "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; do
echo "[info] now executing $SCRIPT on $DIAMOND_CONTRACT_NAME in $ENVIRONMENT environment on $NETWORK (FILE_SUFFIX=$FILE_SUFFIX, USE_MUTABLE_DIAMOND=$USE_MUTABLE_DIAMOND)"

if [[ "$DEBUG" == *"true"* ]]; then
# print output to console
RAW_RETURN_DATA=$(NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") forge script "$SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy)
RETURN_CODE=$?

for NETWORK in "${NETWORKS[@]}"; do
# get deployer wallet balance
echo "[info] loading deployer wallet balance for network $NETWORK..."
BALANCE=$(getDeployerBalance "$NETWORK" "$ENVIRONMENT")
echo "[info] deployer wallet balance in this network: $BALANCE"
echo ""

# ensure all required .env values are set
checkRequiredVariablesInDotEnv $NETWORK


# repeatedly call selected script until it's succeeded or out of attempts
ATTEMPTS=1
while [ $ATTEMPTS -le "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; do
echo "[info] now executing $SCRIPT on $DIAMOND_CONTRACT_NAME in $ENVIRONMENT environment on $NETWORK (FILE_SUFFIX=$FILE_SUFFIX, USE_MUTABLE_DIAMOND=$USE_MUTABLE_DIAMOND)"

if [[ "$DEBUG" == *"true"* ]]; then
# print output to console
RAW_RETURN_DATA=$(NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") forge script "$SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy)
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
RETURN_CODE=$?
else
# do not print output to console
RAW_RETURN_DATA=$(NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") forge script "$SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy) 2>/dev/null
RETURN_CODE=$?
fi

echoDebug "RAW_RETURN_DATA: $RAW_RETURN_DATA"
# exit the loop if the operation was successful
if [ "$RETURN_CODE" -eq 0 ]; then
break
fi

ATTEMPTS=$(($ATTEMPTS + 1)) # increment attempts
sleep 1 # wait for 1 second before trying the operation again
done

# check if call was executed successfully or used all attempts
if [ $ATTEMPTS -gt "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; then
error "failed to execute $SCRIPT on $DIAMOND_CONTRACT_NAME in $ENVIRONMENT environment on $NETWORK"
return 1
else
# do not print output to console
RAW_RETURN_DATA=$(NETWORK=$NETWORK FILE_SUFFIX=$FILE_SUFFIX USE_DEF_DIAMOND=$USE_MUTABLE_DIAMOND PRIVATE_KEY=$(getPrivateKey "$NETWORK" "$ENVIRONMENT") forge script "$SCRIPT_PATH" -f $NETWORK -vvvv --json --silent --broadcast --skip-simulation --legacy) 2>/dev/null
RETURN_CODE=$?
fi

echoDebug "RAW_RETURN_DATA: $RAW_RETURN_DATA"
# exit the loop if the operation was successful
if [ "$RETURN_CODE" -eq 0 ]; then
break
echo "[info] script executed successfully"
return 0
ezynda3 marked this conversation as resolved.
Show resolved Hide resolved
fi

ATTEMPTS=$(($ATTEMPTS + 1)) # increment attempts
sleep 1 # wait for 1 second before trying the operation again
done

# check if call was executed successfully or used all attempts
if [ $ATTEMPTS -gt "$MAX_ATTEMPTS_PER_SCRIPT_EXECUTION" ]; then
error "failed to execute $SCRIPT on $DIAMOND_CONTRACT_NAME in $ENVIRONMENT environment on $NETWORK"
return 1
else
echo "[info] script executed successfully"
return 0
fi

}


Loading