From 19671bfff4f44efbab65971a6fa7d96edcba9044 Mon Sep 17 00:00:00 2001 From: kayibal Date: Thu, 2 Nov 2023 10:47:07 +0000 Subject: [PATCH] Add scripts to build runtime code --- evm/foundry.toml | 5 +++ evm/scripts/_buildRuntime.s.sol | 16 +++++++ evm/scripts/buildRuntime.sh | 43 +++++++++++++++++++ evm/src/uniswap-v2/UniswapV2PairFunctions.sol | 2 +- 4 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 evm/scripts/_buildRuntime.s.sol create mode 100755 evm/scripts/buildRuntime.sh diff --git a/evm/foundry.toml b/evm/foundry.toml index 488edaf..7010ce4 100644 --- a/evm/foundry.toml +++ b/evm/foundry.toml @@ -12,3 +12,8 @@ line_length = 80 [etherscan] mainnet = { key = "${ETHERSCAN_MAINNET_KEY}" } + + +[[profile.default.fs_permissions]] +access = "read-write" +path = "out" diff --git a/evm/scripts/_buildRuntime.s.sol b/evm/scripts/_buildRuntime.s.sol new file mode 100644 index 0000000..e057572 --- /dev/null +++ b/evm/scripts/_buildRuntime.s.sol @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: AGPL-3.0-or-later +pragma solidity ^0.8.13; + +import "forge-std/Script.sol"; + +contract buildRuntime is Script { + function run() external { + bytes memory args = vm.envBytes("__PROPELLER_DEPLOY_ARGS"); + string memory contractRef = vm.envString("__PROPELLER_CONTRACT"); + string memory outFilePath = vm.envString("__PROPELLER_OUT_FILE"); + address deployedContract = deployCode(contractRef, args); + + bytes memory deployedCode = deployedContract.code; + vm.writeFileBinary(outFilePath, deployedCode); + } +} diff --git a/evm/scripts/buildRuntime.sh b/evm/scripts/buildRuntime.sh new file mode 100755 index 0000000..27089a6 --- /dev/null +++ b/evm/scripts/buildRuntime.sh @@ -0,0 +1,43 @@ +#!/bin/bash +set -e + +# Initialize our own variables +CONTRACT_NAME="" +CONSTRUCTOR_SIGNATURE="" +CONSTRUCTOR_ARGUMENTS="" + +# Function to display usage +usage() { + echo "Usage: $0 -c contract_name [-s constructor_signature -a constructor_arguments]" 1>&2; exit 1; +} + +while getopts ":c:s:a:" opt; do + case "${opt}" in + c) + CONTRACT_NAME=${OPTARG};; + s) + CONSTRUCTOR_SIGNATURE=${OPTARG};; + a) + CONSTRUCTOR_ARGUMENTS=${OPTARG};; + *) + usage;; + esac +done +shift $((OPTIND-1)) + +echo "CONTRACT_NAME: $CONTRACT_NAME" +echo "CONSTRUCTOR_SIGNATURE: $CONSTRUCTOR_SIGNATURE" +echo "CONSTRUCTOR_ARGUMENTS: $CONSTRUCTOR_ARGUMENTS" + +# Perform operations if CONSTRUCTOR_SIGNATURE and CONSTRUCTOR_ARGUMENTS are set +if [[ ! -z "$CONSTRUCTOR_SIGNATURE" && ! -z "$CONSTRUCTOR_ARGUMENTS" ]]; then + # Do some operations here + export __PROPELLER_DEPLOY_ARGS=$(cast abi-encode $CONSTRUCTOR_SIGNATURE $CONSTRUCTOR_ARGUMENTS) +fi + +export __PROPELLER_CONTRACT="$CONTRACT_NAME.sol:$CONTRACT_NAME" +export __PROPELLER_OUT_FILE="out/$CONTRACT_NAME.sol/$CONTRACT_NAME.evm.runtime" + +forge script scripts/_buildRuntime.s.sol -v + +echo "Write: $__PROPELLER_OUT_FILE" \ No newline at end of file diff --git a/evm/src/uniswap-v2/UniswapV2PairFunctions.sol b/evm/src/uniswap-v2/UniswapV2PairFunctions.sol index 83f946a..12a9b78 100644 --- a/evm/src/uniswap-v2/UniswapV2PairFunctions.sol +++ b/evm/src/uniswap-v2/UniswapV2PairFunctions.sol @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: UNLICENSED +// SPDX-License-Identifier: AGPL-3.0-or-later pragma solidity ^0.8.13; import "interfaces/IPairFunctions.sol";