Skip to content

Commit

Permalink
Merge pull request #6531 from multiversx/sovereign-deploy-scripts-upd…
Browse files Browse the repository at this point in the history
…ate-11-oct

Sovereign deploy scripts update 11 oct
  • Loading branch information
axenteoctavian authored Nov 13, 2024
2 parents 4aac4a0 + 6e41277 commit f23df2a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 99 deletions.
7 changes: 1 addition & 6 deletions scripts/testnet/sovereignBridge/config/configs.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@ ESDT_SAFE_WASM="${CONTRACTS_DIRECTORY}/esdt-safe.wasm"
FEE_MARKET_WASM="${CONTRACTS_DIRECTORY}/fee-market.wasm"
HEADER_VERIFIER_WASM="${CONTRACTS_DIRECTORY}/header-verifier.wasm"

#============ FEE MARKET DEPLOY ARGUMENTS ==============
PRICE_AGGREGATOR_ADDRESS=erd1qqqqqqqqqqqqqpgqfsfcrxnlym0fjlnuvus2dmlz6ju9cpsfexks8wq4d4
WEGLD_TOKEN_ID=WEGLD-a28c59
USDC_TOKEN_ID=USDC-350c4e

#============ ISSUE MAIN CHAIN TOKEN SETTINGS ==============
TOKEN_TICKER=TKN
TOKEN_DISPLAY_NAME=Token
NR_DECIMALS=18
INITIAL_SUPPLY=111222333

#============ MAIN CHAIN TOKEN TO DEPOSIT ==============
DEPOSIT_TOKEN_IDENTIFIER=TKN-0022f4
DEPOSIT_TOKEN_IDENTIFIER=
DEPOSIT_TOKEN_NR_DECIMALS=18
DEPOSIT_TOKEN_AMOUNT_TO_TRANSFER=123

Expand Down
16 changes: 6 additions & 10 deletions scripts/testnet/sovereignBridge/config/deploy.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# - deploy all main chain contracts and update sovereign configs
# - deploy sovereign nodes with all services
deploySovereignWithCrossChainContracts() {
deployMainChainContractsAndSetupObserver || return
deployMainChainContractsAndSetupObserver $1 || return

sovereignDeploy
}
Expand All @@ -20,13 +20,11 @@ deployMainChainContractsAndSetupObserver() {

setFeeMarketAddress

disableFeeInFeeMarketContract

unpauseEsdtSafeContract

setGenesisContract

updateSovereignConfig
updateSovereignConfig $1

prepareObserver
}
Expand All @@ -48,18 +46,16 @@ sovereignDeploy() {

setEsdtSafeAddressInHeaderVerifier

setHeaderVerifierAddressInEsdtSafe

createObserver

sovereignStart

setHeaderVerifierAddressInEsdtSafe

getFundsInAddressSovereign

setFeeMarketAddressSovereign

disableFeeInFeeMarketContractSovereign

unpauseEsdtSafeContractSovereign
}

Expand All @@ -68,11 +64,11 @@ sovereignDeploy() {
# - start sovereign nodes
# - deploy main chain observer
sovereignStart() {
deployObserver

updateAndStartBridgeService

$TESTNET_DIR/sovereignStart.sh

deployObserver
}

# This function will restart sovereign:
Expand Down
79 changes: 20 additions & 59 deletions scripts/testnet/sovereignBridge/config/fee-market.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ deployFeeMarketContract() {
--gas-limit=200000000 \
--arguments \
${ESDT_SAFE_ADDRESS} \
${PRICE_AGGREGATOR_ADDRESS} \
str:${USDC_TOKEN_ID} \
str:${WEGLD_TOKEN_ID} \
00 \
--outfile=${OUTFILE} \
--recall-nonce \
--wait-result \
Expand Down Expand Up @@ -77,19 +75,19 @@ upgradeFeeMarketContractCall() {
printTxStatus ${OUTFILE}
}

enableFeeMarketContract() {
echo "Enabling Fee Market contract on main chain..."
removeFeeInFeeMarketContract() {
echo "Removing fee in Fee Market contract on main chain..."

local OUTFILE="${OUTFILE_PATH}/enable-feemarket-contract.interaction.json"
enableFeeMarketContractCall ${FEE_MARKET_ADDRESS} ${PROXY} ${CHAIN_ID} ${OUTFILE}
local OUTFILE="${OUTFILE_PATH}/remove-fee-fee-market-contract.interaction.json"
removeFeeInFeeMarketContractCall ${FEE_MARKET_ADDRESS} ${PROXY} ${CHAIN_ID} ${OUTFILE}
}
enableFeeMarketContractSovereign() {
echo "Enabling Fee Market contract on sovereign chain..."
removeFeeInFeeMarketContractSovereign() {
echo "Removing fee in Fee Market contract on sovereign chain..."

local OUTFILE="${OUTFILE_PATH}/enable-feemarket-contract-sovereign.interaction.json"
enableFeeMarketContractCall ${FEE_MARKET_ADDRESS_SOVEREIGN} ${PROXY_SOVEREIGN} ${CHAIN_ID_SOVEREIGN} ${OUTFILE}
local OUTFILE="${OUTFILE_PATH}/remove-fee-fee-market-contract-sovereign.interaction.json"
removeFeeInFeeMarketContractCall ${FEE_MARKET_ADDRESS_SOVEREIGN} ${PROXY_SOVEREIGN} ${CHAIN_ID_SOVEREIGN} ${OUTFILE}
}
enableFeeMarketContractCall() {
removeFeeInFeeMarketContractCall() {
if [ $# -lt 4 ]; then
echo "Usage: $0 <arg1> <arg2> <arg3> <arg4>"
exit 1
Expand All @@ -105,44 +103,7 @@ enableFeeMarketContractCall() {
--proxy=${URL} \
--chain=${CHAIN} \
--gas-limit=10000000 \
--function="enableFee" \
--outfile=${OUTFILE} \
--recall-nonce \
--wait-result \
--send || return

printTxStatus ${OUTFILE}
}

disableFeeInFeeMarketContract() {
echo "Disabling Fee in Fee Market contract on main chain..."

local OUTFILE="${OUTFILE_PATH}/disable-feemarket-contract.interaction.json"
disableFeeInFeeMarketContractCall ${FEE_MARKET_ADDRESS} ${PROXY} ${CHAIN_ID} ${OUTFILE}
}
disableFeeInFeeMarketContractSovereign() {
echo "Disabling Fee in Fee Market contract on sovereign chain..."

local OUTFILE="${OUTFILE_PATH}/disable-feemarket-contract-sovereign.interaction.json"
disableFeeInFeeMarketContractCall ${FEE_MARKET_ADDRESS_SOVEREIGN} ${PROXY_SOVEREIGN} ${CHAIN_ID_SOVEREIGN} ${OUTFILE}
}
disableFeeInFeeMarketContractCall() {
if [ $# -lt 4 ]; then
echo "Usage: $0 <arg1> <arg2> <arg3> <arg4>"
exit 1
fi

local ADDRESS=$1
local URL=$2
local CHAIN=$3
local OUTFILE=$4

mxpy contract call ${ADDRESS} \
--pem=${WALLET} \
--proxy=${URL} \
--chain=${CHAIN} \
--gas-limit=10000000 \
--function="disableFee" \
--function="removeFee" \
--outfile=${OUTFILE} \
--recall-nonce \
--wait-result \
Expand All @@ -152,15 +113,15 @@ disableFeeInFeeMarketContractCall() {
}

setFixedFeeMarketContract() {
echo "Setting fixed fee in market contract on main chain..."
echo "Setting fixed fee in Fee Market contract on main chain..."

local OUTFILE="${OUTFILE_PATH}/set-fixed-feemarket-contract.interaction.json"
local OUTFILE="${OUTFILE_PATH}/set-fixed-fee-fee-market-contract.interaction.json"
setFixedFeeMarketContractCall ${FEE_MARKET_ADDRESS} ${PROXY} ${CHAIN_ID} ${OUTFILE}
}
setFixedFeeMarketContractSovereign() {
echo "Setting fixed fee in market contract on sovereign chain..."
echo "Setting fixed fee in Fee Market contract on sovereign chain..."

local OUTFILE="${OUTFILE_PATH}/set-fixed-feemarket-contract-sovereign.interaction.json"
local OUTFILE="${OUTFILE_PATH}/set-fixed-fee-fee-market-contract-sovereign.interaction.json"
setFixedFeeMarketContractCall ${FEE_MARKET_ADDRESS_SOVEREIGN} ${PROXY_SOVEREIGN} ${CHAIN_ID_SOVEREIGN} ${OUTFILE}
}
setFixedFeeMarketContractCall() {
Expand All @@ -179,7 +140,7 @@ setFixedFeeMarketContractCall() {
--proxy=${URL} \
--chain=${CHAIN} \
--gas-limit=10000000 \
--function="addFee" \
--function="setFee" \
--arguments \
str:SVN-c53da0 \
0x010000000a53564e2d6335336461300000000901314fb370629800000000000901c9f78d2893e40000 \
Expand All @@ -192,15 +153,15 @@ setFixedFeeMarketContractCall() {
}

setAnyTokenFeeMarketContract() {
echo "Setting any token fee in market contract on main chain..."
echo "Setting any token fee in Fee Market contract on main chain..."

local OUTFILE="${OUTFILE_PATH}/set-anytoken-feemarket-contract.interaction.json"
local OUTFILE="${OUTFILE_PATH}/set-anytoken-fee-fee-market-contract.interaction.json"
setAnyTokenFeeMarketContractCall ${FEE_MARKET_ADDRESS} ${PROXY} ${CHAIN_ID} ${OUTFILE}
}
setAnyTokenFeeMarketContractSovereign() {
echo "Setting any token fee in market contract on sovereign chain..."
echo "Setting any token fee in Fee Market contract on sovereign chain..."

local OUTFILE="${OUTFILE_PATH}/set-anytoken-feemarket-contract-sovereign.interaction.json"
local OUTFILE="${OUTFILE_PATH}/set-anytoken-fee-fee-market-contract-sovereign.interaction.json"
setAnyTokenFeeMarketContractCall ${FEE_MARKET_ADDRESS_SOVEREIGN} ${PROXY_SOVEREIGN} ${CHAIN_ID_SOVEREIGN} ${OUTFILE}
}
setAnyTokenFeeMarketContractCall() {
Expand Down
17 changes: 15 additions & 2 deletions scripts/testnet/sovereignBridge/config/py.snippets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,24 @@ updateNotifierNotarizationRound() {

setGenesisContract() {
local ESDT_SAFE_INIT_PARAMS="01"
local FEE_MARKET_INIT_PARAMS="$(bech32ToHex $ESDT_SAFE_ADDRESS_SOVEREIGN)@$(bech32ToHex $PRICE_AGGREGATOR_ADDRESS)@555344432d333530633465@5745474c442d613238633539"
local FEE_MARKET_INIT_PARAMS="$(bech32ToHex $ESDT_SAFE_ADDRESS_SOVEREIGN)@00"

python3 $SCRIPT_PATH/pyScripts/genesis_contract.py $WALLET_ADDRESS $ESDT_SAFE_WASM $ESDT_SAFE_INIT_PARAMS $FEE_MARKET_WASM $FEE_MARKET_INIT_PARAMS
}

updateSovereignConfig() {
python3 $SCRIPT_PATH/pyScripts/update_toml.py $ESDT_SAFE_ADDRESS $ESDT_SAFE_ADDRESS_SOVEREIGN
if [ -z "$1" ]; then
ESDT_PREFIX=$(generateRandomEsdtPrefix)
else
ESDT_PREFIX=$1
fi

python3 $SCRIPT_PATH/pyScripts/update_toml.py $ESDT_SAFE_ADDRESS $ESDT_SAFE_ADDRESS_SOVEREIGN $ESDT_PREFIX
}

generateRandomEsdtPrefix() {
LEN=$(shuf -i 1-4 -n 1)
RANDOM_PREFIX=$(cat /dev/urandom | tr -dc 'a-z0-9' | head -c $LEN)

echo $RANDOM_PREFIX
}
6 changes: 4 additions & 2 deletions scripts/testnet/sovereignBridge/pyScripts/bridge_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import subprocess
import sys
from datetime import datetime


def update_env(lines, identifier, value) -> []:
Expand All @@ -21,7 +22,8 @@ def build_and_run_bridge_server(server_path):

build_command = "go build"
kill_screen_service = "screen -ls | grep 'sovereignBridgeService' | awk -F. '{print $1}' | xargs -I{} screen -X -S {} quit"
run_service = "screen -dmS sovereignBridgeService -L -Logfile sovereignBridgeService.log ./server"
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
run_service = f"screen -dmS sovereignBridgeService -L -Logfile sovereignBridgeService_{current_time}.log ./server"

build_process = subprocess.run(build_command, shell=True, capture_output=True, text=True)
if build_process.returncode == 0:
Expand Down Expand Up @@ -61,7 +63,7 @@ def main():

updated_lines = update_env(lines, "WALLET_PATH", os.path.expanduser(wallet))
updated_lines = update_env(updated_lines, "MULTIVERSX_PROXY", os.path.expanduser(proxy))
updated_lines = update_env(updated_lines, "MULTI_SIG_SC_ADDRESS", header_verifier_address)
updated_lines = update_env(updated_lines, "HEADER_VERIFIER_SC_ADDRESS", header_verifier_address)
updated_lines = update_env(updated_lines, "ESDT_SAFE_SC_ADDRESS", esdt_safe_address)
updated_lines = update_env(updated_lines, "CERT_FILE", os.path.expanduser("~/MultiversX/testnet/node/config/certificate.crt"))
updated_lines = update_env(updated_lines, "CERT_PK_FILE", os.path.expanduser("~/MultiversX/testnet/node/config/private_key.pem"))
Expand Down
15 changes: 4 additions & 11 deletions scripts/testnet/sovereignBridge/pyScripts/notifier_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,17 @@ def update_notarization_round(lines, section, identifier, round) -> []:


def get_current_round(proxy, shard):
params = {
"size": 1,
"shard": shard,
"fields": "round"
}

api = proxy.replace("gateway", "api")
response = requests.get(api + f"/blocks?size=1&shard={shard}&fields=round")
response = requests.get(proxy + f"/network/status/{shard}")

if response.status_code == 200:
data = response.json()
if data:
return data[0]["round"]
return data["data"]["status"]["erd_current_round"]
else:
print("No data returned from the API.")
print("No data returned from proxy.")
return -1
else:
print("Failed to retrieve data from the API. Status code:", response.status_code)
print("Failed to retrieve data from the proxy. Status code:", response.status_code)
return -1


Expand Down
63 changes: 54 additions & 9 deletions scripts/testnet/sovereignBridge/pyScripts/update_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,71 @@ def update_subscribed_addresses(lines, section, identifier, main_chain_address)
return updated_lines


def update_key(lines, key, value) -> []:
updated_lines = []

for line in lines:
if key in line:
line = re.sub(rf'{re.escape(key)}\s*=\s*".*?"', f'{key} = "{value}"', line)
updated_lines.append(line)

return updated_lines


def update_sovereign_config(file_path, main_chain_address, sovereign_chain_address):
with open(file_path, 'r') as file:
lines = file.readlines()

updated_lines = update_subscribed_addresses(lines, "OutgoingSubscribedEvents", "deposit", sovereign_chain_address)
updated_lines = update_subscribed_addresses(updated_lines, "NotifierConfig", "deposit", main_chain_address)
updated_lines = update_subscribed_addresses(updated_lines, "NotifierConfig", "execute", main_chain_address)

with open(file_path, 'w') as file:
file.writelines(updated_lines)


def update_esdt_prefix(file_path, esdt_prefix):
with open(file_path, 'r') as file:
lines = file.readlines()

updated_lines = update_key(lines, "ESDTPrefix", esdt_prefix)

with open(file_path, 'w') as file:
file.writelines(updated_lines)


def update_transfer_and_execute_address(file_path, address):
with open(file_path, 'r') as file:
lines = file.readlines()

for i, line in enumerate(lines):
if "TransferAndExecuteByUserAddresses" in line:
lines[i + 1] = re.sub(r'".*?"', f'"{address}"', lines[i + 1])

with open(file_path, 'w') as file:
file.writelines(lines)


def update_node_configs(config_path, esdt_prefix, sovereign_chain_address):
update_esdt_prefix(config_path + "/systemSmartContractsConfig.toml", esdt_prefix)
update_transfer_and_execute_address(config_path + "/config.toml", sovereign_chain_address)


def main():
# input arguments
main_chain_address = sys.argv[1]
sovereign_chain_address = sys.argv[2]
esdt_prefix = sys.argv[3]

current_path = os.getcwd()
project = 'mx-chain-go'
index = current_path.find(project)
project_path = current_path[:index + len(project)]
toml_path = project_path + "/cmd/sovereignnode/config/sovereignConfig.toml"
update_sovereign_config(toml_path, main_chain_address, sovereign_chain_address)

with open(toml_path, 'r') as file:
lines = file.readlines()

updated_lines = update_subscribed_addresses(lines, "OutgoingSubscribedEvents", "deposit", sovereign_chain_address)
updated_lines = update_subscribed_addresses(updated_lines, "NotifierConfig", "deposit", main_chain_address)
updated_lines = update_subscribed_addresses(updated_lines, "NotifierConfig", "execute", main_chain_address)

with open(toml_path, 'w') as file:
file.writelines(updated_lines)
config_path = project_path + "/cmd/node/config"
update_node_configs(config_path, esdt_prefix, sovereign_chain_address)


if __name__ == "__main__":
Expand Down

0 comments on commit f23df2a

Please sign in to comment.