build: update deployment scripts, add rinkeby deployment

This commit is contained in:
ZeframLou
2021-12-12 21:40:27 -08:00
parent 95a58e94b5
commit 66e1849096
12 changed files with 213 additions and 110 deletions
+2 -2
View File
@@ -1,7 +1,7 @@
# Make dependencies available
export DAPP_REMAPPINGS=$(cat remappings.txt)
export DAPP_SOLC_VERSION=0.8.10z
export DAPP_SOLC_VERSION=0.8.10
export DAPP_BUILD_OPTIMIZE=1
export DAPP_BUILD_OPTIMIZE_RUNS=1000000
export DAPP_LINK_TEST_LIBRARIES=0
@@ -14,7 +14,7 @@ export ETH_RPC_ACCOUNTS=true
# only run test files that end in .t.sol
export DAPP_TEST_MATCH=src/test/.*\.t\.sol
if [ "$DEEP_FUZZ" == "true" ]
if [ "$DEEP_FUZZ" = "true" ]
then
export DAPP_TEST_FUZZ_RUNS=50000 # Fuzz for a long time if DEEP_FUZZ is set to true.
else
+3
View File
@@ -1,2 +1,5 @@
export ALCHEMY_API_KEY=YOUR_API_KEY
export ETH_FROM=YOUR_DEFAULT_SENDER_ACCOUNT
export ADMIN=YOUR_ADMIN
export PROTOCOL_FEE_RECIPIENT=YOUR_FEE_RECIPIENT
export PROTOCOL_FEE_MULTIPLIER=YOUR_FEE_MULRIPLIER
+14 -14
View File
@@ -1,14 +1,14 @@
test_createPairETH() (gas: 2925419)
test_swap5NFTsForETH() (gas: 376058)
test_swapETHfor5NFTs() (gas: 136921)
test_swapETHForSingleAnyNFT() (gas: 87548)
test_swapSingleNFTForAnyNFT() (gas: 199541)
test_swapETHForSingleSpecificNFT() (gas: 89610)
test_swapSingleNFTForETH() (gas: 140718)
test_swapSingleNFTForSpecificNFT() (gas: 201733)
test_robustSwapETHForAnyNFTs() (gas: 338637)
test_robustSwapETHForAnyNFTs() (gas: 185039)
test_getSellInfoExample() (gas: 5144)
test_getBuyInfoExample() (gas: 5342)
test_getSellInfoExample() (gas: 3749)
test_getBuyInfoExample() (gas: 3759)
test_createPairETH() (gas: 2918829)
test_swap5NFTsForETH() (gas: 374295)
test_swapETHfor5NFTs() (gas: 134740)
test_swapETHForSingleAnyNFT() (gas: 86135)
test_swapSingleNFTForAnyNFT() (gas: 196961)
test_swapETHForSingleSpecificNFT() (gas: 88183)
test_swapSingleNFTForETH() (gas: 139419)
test_swapSingleNFTForSpecificNFT() (gas: 199111)
test_robustSwapETHForAnyNFTs() (gas: 334506)
test_robustSwapETHForAnyNFTs() (gas: 181420)
test_getSellInfoExample() (gas: 5016)
test_getBuyInfoExample() (gas: 5214)
test_getSellInfoExample() (gas: 3621)
test_getBuyInfoExample() (gas: 3631)
+2
View File
@@ -3,3 +3,5 @@ node_modules
# Dapptools
out/
.env
+2 -1
View File
@@ -24,6 +24,7 @@ lint :; yarn run lint
estimate :; ./scripts/estimate-gas.sh ${contract}
size :; ./scripts/contract-size.sh ${contract}
snapshot :; dapp snapshot
test-deploy :; ./scripts/test-deploy.sh
# Deployment helpers
deploy :; @./scripts/deploy.sh
@@ -45,5 +46,5 @@ endif
# Requires the ALCHEMY_API_KEY env var to be set.
# The first argument determines the network (mainnet / rinkeby / ropsten / kovan / goerli)
define network
https://eth-$1.alchemyapi.io/v2/${ALCHEMY_API_KEY}
https://eth-$1.alchemyapi.io/v2/${ALCHEMY_API_KEY}
endef
+11
View File
@@ -0,0 +1,11 @@
{
"DEPLOYER": "0x000000004b60a12164e6942dCd3e007F079b725B",
"LSSVMPairEnumerableETH": "0xcb00b2848C6E3EC25d9eF6740E160D99FCCde457",
"LSSVMPairMissingEnumerableETH": "0xBD16088611054fce04711Aa9509D1D86E04dCe2c",
"LSSVMPairEnumerableERC20": "0xE3D12a35962778becfc731AD73642539C4edF548",
"LSSVMPairMissingEnumerableERC20": "0x36b49ebF089BE8860d7fC60f2553461E9Cc8e9e2",
"LSSVMPairFactory": "0xD95045f720708150B5488DE7D645CF546Ac940Da",
"LSSVMRouter": "0xBb443D6740322293Fcee4414d03978C7E4bF5d55",
"ExponentialCurve": "0x983dfd698BBbF72e585DBacdA5b242221306565f",
"LinearCurve": "0x3b0b319d70605440fBE6454EBa3750ce20D47478"
}
+113 -83
View File
@@ -1,5 +1,11 @@
#!/usr/bin/env bash
set -eo pipefail
if [[ ${DEBUG} ]]; then
set -x
fi
# All contracts are output to `out/addresses.json` by default
OUT_DIR=${OUT_DIR:-$PWD/out}
ADDRESSES_FILE=${ADDRESSES_FILE:-$OUT_DIR/"addresses.json"}
@@ -10,132 +16,156 @@ ETH_RPC_URL=${ETH_RPC_URL:-http://localhost:8545}
GREEN='\033[0;32m'
NC='\033[0m' # No Color
log() {
printf '%b\n' "${GREEN}${*}${NC}"
echo ""
printf '%b\n' "${GREEN}${*}${NC}"
echo ""
}
# Coloured output helpers
if command -v tput > /dev/null 2>&1; then
if [ $(($(tput colors 2> /dev/null))) -ge 8 ]; then
# Enable colors
TPUT_RESET="$(tput sgr 0)"
TPUT_YELLOW="$(tput setaf 3)"
TPUT_RED="$(tput setaf 1)"
TPUT_BLUE="$(tput setaf 4)"
TPUT_GREEN="$(tput setaf 2)"
TPUT_WHITE="$(tput setaf 7)"
TPUT_BOLD="$(tput bold)"
fi
if command -v tput >/dev/null 2>&1; then
if [ $(($(tput colors 2>/dev/null))) -ge 8 ]; then
# Enable colors
TPUT_RESET="$(tput sgr 0)"
TPUT_YELLOW="$(tput setaf 3)"
TPUT_RED="$(tput setaf 1)"
TPUT_BLUE="$(tput setaf 4)"
TPUT_GREEN="$(tput setaf 2)"
TPUT_WHITE="$(tput setaf 7)"
TPUT_BOLD="$(tput bold)"
fi
fi
# ensure ETH_FROM is set and give a meaningful error message
if [[ -z ${ETH_FROM} ]]; then
echo "ETH_FROM not found, please set it and re-run the last command."
exit 1
echo "ETH_FROM not found, please set it and re-run the last command."
exit 1
fi
# Make sure address is checksummed
if [ "$ETH_FROM" != "$(seth --to-checksum-address "$ETH_FROM")" ]; then
echo "ETH_FROM not checksummed, please format it with 'seth --to-checksum-address <address>'"
exit 1
fi
# Setup addresses file
cat > "$ADDRESSES_FILE" <<EOF
cat >"$ADDRESSES_FILE" <<EOF
{
"DEPLOYER": "$(seth --to-checksum-address "$ETH_FROM")"
"DEPLOYER": "$ETH_FROM"
}
EOF
# Call as `ETH_FROM=0x... ETH_RPC_URL=<url> deploy ContractName arg1 arg2 arg3`
# (or omit the env vars if you have already set them)
deploy() {
NAME=$1
ARGS=${@:2}
# select the filename and the contract in it
PATTERN=".contracts[\"src/$NAME.sol\"].$NAME"
NAME=$1
ARGS=${@:2}
# get the constructor's signature
ABI=$(jq -r "$PATTERN.abi" out/dapp.sol.json)
SIG=$(echo $ABI | seth --abi-constructor)
# find file path
CONTRACT_PATH=$(find . -name $NAME.sol)
CONTRACT_PATH=${CONTRACT_PATH:2}
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
# select the filename and the contract in it
PATTERN=".contracts[\"$CONTRACT_PATH\"].$NAME"
# estimate gas
GAS=$(seth estimate --create $BYTECODE $SIG $ARGS --rpc-url $ETH_RPC_URL)
# get the constructor's signature
ABI=$(jq -r "$PATTERN.abi" out/dapp.sol.json)
SIG=$(echo "$ABI" | seth --abi-constructor)
# deploy
ADDRESS=$(dapp create $NAME $ARGS -- --gas $GAS --rpc-url $ETH_RPC_URL)
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
# save the addrs to the json
# TODO: It'd be nice if we could evolve this into a minimal versioning system
# e.g. via commit / chainid etc.
saveContract $NAME $ADDRESS
# estimate gas
GAS=$(seth estimate --create "$BYTECODE" "$SIG" $ARGS --rpc-url "$ETH_RPC_URL")
echo $ADDRESS
# deploy
ADDRESS=$(dapp create "$NAME" $ARGS -- --gas "$GAS" --rpc-url "$ETH_RPC_URL")
# save the addrs to the json
# TODO: It'd be nice if we could evolve this into a minimal versioning system
# e.g. via commit / chainid etc.
saveContract "$NAME" "$ADDRESS"
echo "$ADDRESS"
}
send() {
ADDRESS=$1
SIG=$2
ARGS=${@:3}
# estimate gas
GAS=$(seth estimate "$ADDRESS" "$SIG" $ARGS --rpc-url "$ETH_RPC_URL")
# send tx
seth send "$ADDRESS" "$SIG" $ARGS --gas "$GAS" --rpc-url "$ETH_RPC_URL"
}
# Call as `saveContract ContractName 0xYourAddress` to store the contract name
# & address to the addresses json file
saveContract() {
# create an empty json if it does not exist
if [[ ! -e $ADDRESSES_FILE ]]; then
echo "{}" > $ADDRESSES_FILE
fi
result=$(cat $ADDRESSES_FILE | jq -r ". + {\"$1\": \"$2\"}")
printf %s "$result" > "$ADDRESSES_FILE"
# create an empty json if it does not exist
if [[ ! -e $ADDRESSES_FILE ]]; then
echo "{}" >"$ADDRESSES_FILE"
fi
result=$(cat "$ADDRESSES_FILE" | jq -r ". + {\"$1\": \"$2\"}")
printf %s "$result" >"$ADDRESSES_FILE"
}
estimate_gas() {
NAME=$1
ARGS=${@:2}
# select the filename and the contract in it
PATTERN=".contracts[\"src/$NAME.sol\"].$NAME"
NAME=$1
ARGS=${@:2}
# select the filename and the contract in it
PATTERN=".contracts[\"src/$NAME.sol\"].$NAME"
# get the constructor's signature
ABI=$(jq -r "$PATTERN.abi" out/dapp.sol.json)
SIG=$(echo $ABI | seth --abi-constructor)
# get the constructor's signature
ABI=$(jq -r "$PATTERN.abi" out/dapp.sol.json)
SIG=$(echo "$ABI" | seth --abi-constructor)
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
# estimate gas
GAS=$(seth estimate --create $BYTECODE $SIG $ARGS --rpc-url $ETH_RPC_URL)
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
# estimate gas
GAS=$(seth estimate --create "$BYTECODE" "$SIG" $ARGS --rpc-url "$ETH_RPC_URL")
GASNOW_RESPONSE=$(curl -s https://www.gasnow.org/api/v3/gas/price)
response=$(jq '.code' <<< $GASNOW_RESPONSE)
if [[ $response != "200" ]]; then
echo "Could not get gas information from ${TPUT_BOLD}gasnow.org${TPUT_RESET}: https://www.gasnow.org"
echo "response code: $response"
else
rapid=$(( $(jq '.data.rapid' <<< $GASNOW_RESPONSE) / 1000000000 ))
fast=$(( $(jq '.data.fast' <<< $GASNOW_RESPONSE) / 1000000000 ))
standard=$(( $(jq '.data.standard' <<< $GASNOW_RESPONSE) / 1000000000 ))
slow=$(( $(jq '.data.slow' <<< $GASNOW_RESPONSE) / 1000000000 ))
echo "Gas prices from ${TPUT_BOLD}gasnow.org${TPUT_RESET}: https://www.gasnow.org"
echo " \
TXPRICE_RESPONSE=$(curl -sL https://api.txprice.com/v1)
response=$(jq '.code' <<<"$TXPRICE_RESPONSE")
if [[ $response != "200" ]]; then
echo "Could not get gas information from ${TPUT_BOLD}txprice.com${TPUT_RESET}: https://api.txprice.com/v1"
echo "response code: $response"
else
rapid=$(($(jq '.blockPrices[0].estimatedPrices[0].maxFeePerGas' <<<"$TXPRICE_RESPONSE")))
fast=$(($(jq '.blockPrices[0].estimatedPrices[1].maxFeePerGas' <<<"$TXPRICE_RESPONSE")))
standard=$(($(jq '.blockPrices[0].estimatedPrices[2].maxFeePerGas' <<<"$TXPRICE_RESPONSE")))
slow=$(($(jq '.blockPrices[0].estimatedPrices[3].maxFeePerGas' <<<"$TXPRICE_RESPONSE")))
basefee$(($(jq '.blockPrices[0].baseFeePerGas' <<<"$TXPRICE_RESPONSE")))
echo "Gas prices from ${TPUT_BOLD}txprice.com${TPUT_RESET}: https://api.txprice.com/v1"
echo " \
${TPUT_RED}Rapid: $rapid gwei ${TPUT_RESET} \n
${TPUT_YELLOW}Fast: $fast gwei \n
${TPUT_BLUE}Standard: $standard gwei \n
${TPUT_GREEN}Slow: $slow gwei${TPUT_RESET}" | column -t
size=$(contract_size $NAME)
echo "Estimated Gas cost for deployment of $NAME: ${TPUT_BOLD}$GAS${TPUT_RESET} units of gas"
echo "Contract Size: ${size} bytes"
echo "Total cost for deployment:"
rapid_cost=$(echo "scale=5; $GAS*$rapid/1000000000" | bc)
fast_cost=$(echo "scale=5; $GAS*$fast/1000000000" | bc)
standard_cost=$(echo "scale=5; $GAS*$standard/1000000000" | bc)
slow_cost=$(echo "scale=5; $GAS*$slow/1000000000" | bc)
echo " \
size=$(contract_size "$NAME")
echo "Estimated Gas cost for deployment of $NAME: ${TPUT_BOLD}$GAS${TPUT_RESET} units of gas"
echo "Contract Size: ${size} bytes"
echo "Total cost for deployment:"
rapid_cost=$(echo "scale=5; $GAS*$rapid" | bc)
fast_cost=$(echo "scale=5; $GAS*$fast" | bc)
standard_cost=$(echo "scale=5; $GAS*$standard" | bc)
slow_cost=$(echo "scale=5; $GAS*$slow" | bc)
echo " \
${TPUT_RED}Rapid: $rapid_cost ETH ${TPUT_RESET} \n
${TPUT_YELLOW}Fast: $fast_cost ETH \n
${TPUT_BLUE}Standard: $standard_cost ETH \n
${TPUT_GREEN}Slow: $slow_cost ETH ${TPUT_RESET}" | column -t
fi
fi
}
contract_size(){
NAME=$1
ARGS=${@:2}
# select the filename and the contract in it
PATTERN=".contracts[\"src/$NAME.sol\"].$NAME"
contract_size() {
NAME=$1
ARGS=${@:2}
# select the filename and the contract in it
PATTERN=".contracts[\"src/$NAME.sol\"].$NAME"
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
length=$(echo $BYTECODE | wc -m )
echo $(( $length / 2 ))
# get the bytecode from the compiled file
BYTECODE=0x$(jq -r "$PATTERN.evm.bytecode.object" out/dapp.sol.json)
length=$(echo "$BYTECODE" | wc -m)
echo $(($length / 2))
}
+6 -2
View File
@@ -1,8 +1,12 @@
#!/usr/bin/env bash
set -eo pipefail
. $(dirname $0)/common.sh
if [[ -z $contract ]]; then
if [[ -z ${1} ]];then
echo '"$contract" env variable is not set. Set it to the name of the contract you want to estimate gas cost for.'
echo '"$contract" env variable is not set. Set it to the name of the contract you want to estimate size for.'
exit 1
else
contract=${1}
@@ -11,4 +15,4 @@ fi
contract_size=$(contract_size ${contract})
echo "Contract Name: ${contract}"
echo "Contract Size: ${contract_size} bytes"
echo "$(( 24576 - ${contract_size} )) bytes left to reach the smart contract size limit of 24576 bytes."
echo "$(( 24576 - ${contract_size} )) bytes left to reach the smart contract size limit of 24576 bytes."
+43 -3
View File
@@ -1,8 +1,48 @@
#!/usr/bin/env bash
set -eo pipefail
# import the deployment helpers
. $(dirname $0)/common.sh
# Deploy.
# GreeterAddr=$(deploy Greeter)
# log "Greeter deployed at:" $GreeterAddr
# Deploy pair templates
LSSVMPairEnumerableETHAddr=$(deploy LSSVMPairEnumerableETH)
log "LSSVMPairEnumerableETH deployed at:" $LSSVMPairEnumerableETHAddr
LSSVMPairMissingEnumerableETHAddr=$(deploy LSSVMPairMissingEnumerableETH)
log "LSSVMPairMissingEnumerableETH deployed at:" $LSSVMPairMissingEnumerableETHAddr
LSSVMPairEnumerableERC20Addr=$(deploy LSSVMPairEnumerableERC20)
log "LSSVMPairEnumerableERC20 deployed at:" $LSSVMPairEnumerableERC20Addr
LSSVMPairMissingEnumerableERC20Addr=$(deploy LSSVMPairMissingEnumerableERC20)
log "LSSVMPairMissingEnumerableERC20 deployed at:" $LSSVMPairMissingEnumerableERC20Addr
# Deploy factory
LSSVMPairFactoryAddr=$(deploy LSSVMPairFactory $LSSVMPairEnumerableETHAddr $LSSVMPairMissingEnumerableETHAddr $LSSVMPairEnumerableERC20Addr $LSSVMPairMissingEnumerableERC20Addr $PROTOCOL_FEE_RECIPIENT $PROTOCOL_FEE_MULTIPLIER)
log "LSSVMPairFactory deployed at:" $LSSVMPairFactoryAddr
# Deploy router
LSSVMRouterAddr=$(deploy LSSVMRouter $LSSVMPairFactoryAddr)
log "LSSVMRouter deployed at:" $LSSVMRouterAddr
# Whitelist router in factory
send $LSSVMPairFactoryAddr "setRouterAllowed(address,bool)" $LSSVMRouterAddr true
log "Whitelisted router in factory"
# Deploy bonding curves
ExponentialCurveAddr=$(deploy ExponentialCurve)
log "ExponentialCurve deployed at:" $ExponentialCurveAddr
LinearCurveAddr=$(deploy LinearCurve)
log "LinearCurve deployed at:" $LinearCurveAddr
# Whitelist bonding curves in factory
send $LSSVMPairFactoryAddr "setBondingCurveAllowed(address,bool)" $ExponentialCurveAddr true
log "Whitelisted exponential curve in factory"
send $LSSVMPairFactoryAddr "setBondingCurveAllowed(address,bool)" $LinearCurveAddr true
log "Whitelisted linear curve in factory"
# Transfer factory ownership to admin
send $LSSVMPairFactoryAddr "transferOwnership(address)" $ADMIN
log "Transferred factory ownership to:" $ADMIN
+5 -3
View File
@@ -1,3 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail
. $(dirname $0)/common.sh
if [[ -z $contract ]]; then
@@ -9,6 +13,4 @@ if [[ -z $contract ]]; then
fi
fi
estimate_gas $contract
estimate_gas $contract
Regular → Executable
+10 -2
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail
# Utility for running a temporary dapp testnet w/ an ephemeral account
# to be used for deployment tests
@@ -7,7 +9,7 @@
export TMPDIR=$(mktemp -d)
# clean up
trap 'killall geth && rm -rf "$TMPDIR"' EXIT
trap 'killall geth && sleep 3 && rm -rf "$TMPDIR"' EXIT
trap "exit 1" SIGINT SIGTERM
# test helper
@@ -22,5 +24,11 @@ dapp testnet --dir "$TMPDIR" &
# wait for it to launch (can't go <3s)
sleep 3
# set the RPC URL to the local testnet
export ETH_RPC_URL=http://127.0.0.1:8545
export ETH_KEYSTORE=$TMPDIR/8545/keystore
export ETH_PASSWORD=/dev/null
# get the created account (it's unlocked so we only need to set the address)
export ETH_FROM=$(seth ls --keystore $TMPDIR/8545/keystore | cut -f1)
export ETH_FROM=$(seth ls --keystore $ETH_KEYSTORE | cut -f1)
+2
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail
# bring up the network
. $(dirname $0)/run-temp-testnet.sh