From d3f2f67d41dada16553f445acd0133bc23db74d1 Mon Sep 17 00:00:00 2001 From: SocLu Date: Tue, 14 May 2024 14:36:05 +0800 Subject: [PATCH] add forge deploy script --- deploy/config.json | 16 +++++ deploy/deploy.sh | 117 +++++++++++++++++++++++++++++++++ deploy/deployed_addresses.json | 8 +++ 3 files changed, 141 insertions(+) create mode 100644 deploy/config.json create mode 100755 deploy/deploy.sh create mode 100644 deploy/deployed_addresses.json diff --git a/deploy/config.json b/deploy/config.json new file mode 100644 index 0000000..4b8c8a3 --- /dev/null +++ b/deploy/config.json @@ -0,0 +1,16 @@ +{ + "optimism-sepolia": { + "rpcUrl": "https://public.stackup.sh/api/v1/node/optimism-sepolia", + "mestBaseUrl": "https://mest.io/share/", + "weth": "0x4200000000000000000000000000000000000006", + "scanUrl": "https://api-sepolia-optimism.etherscan.io/api", + "aavePool": "0xb50201558B00496A145fE76f7424749556E326D8", + "aaveGateWay": "0x589750BA8aF186cE5B55391B0b7148cAD43a1619", + "curveSetting": { + "basePrice": "5000000000000000", + "inflectionPoint": "1500", + "inflectionPrice": "102500000000000000", + "linearPriceSlope": "0" + } + } +} \ No newline at end of file diff --git a/deploy/deploy.sh b/deploy/deploy.sh new file mode 100755 index 0000000..1dd821c --- /dev/null +++ b/deploy/deploy.sh @@ -0,0 +1,117 @@ +#!/bin/bash + +# run from top level:mest-protocol + +# receive command line parameter, setting network name +# use: ./deploy/deploy.sh optimism-sepolia +NETWORK_NAME=$1 + +OUTPUT_JSON="./deploy/deployed_addresses.json" + +RPC_URL=$(jq -r --arg net "$NETWORK_NAME" '.[$net].rpcUrl' ./deploy/config.json) +MEST_BASE_URL=$(jq -r --arg net "$NETWORK_NAME" '.[$net].mestBaseUrl' ./deploy/config.json) +WETH=$(jq -r --arg net "$NETWORK_NAME" '.[$net].weth' ./deploy/config.json) +SCAN_URL=$(jq -r --arg net "$NETWORK_NAME" '.[$net].scanUrl' ./deploy/config.json) +AAVE_POOL=$(jq -r --arg net "$NETWORK_NAME" '.[$net].aavePool' ./deploy/config.json) +AAVE_GATEWAY=$(jq -r --arg net "$NETWORK_NAME" '.[$net].aaveGateWay' ./deploy/config.json) + +# curve setting +BASE_PRICE=$(jq -r --arg net "$NETWORK_NAME" '.[$net].curveSetting.basePrice' ./deploy/config.json) +INFLECTION_POINT=$(jq -r --arg net "$NETWORK_NAME" '.[$net].curveSetting.inflectionPoint' ./deploy/config.json) +INFLECTION_PRICE=$(jq -r --arg net "$NETWORK_NAME" '.[$net].curveSetting.inflectionPrice' ./deploy/config.json) +LINEAR_PRICE_SLOPE=$(jq -r --arg net "$NETWORK_NAME" '.[$net].curveSetting.linearPriceSlope' ./deploy/config.json) + +# deploy mestERC1155 +MESTERC1155_ADDRESS=$(forge create contracts/core/MestERC1155.sol:MestERC1155 \ + --rpc-url $RPC_URL \ + --private-key $PRIVATE_KEY \ + --constructor-args $MEST_BASE_URL \ + --etherscan-api-key $API_KEY \ + --verifier-url $SCAN_URL \ + --json | jq -r '.deployedTo') +echo "MestERC1155 deployed at address: $MESTERC1155_ADDRESS" +echo "Using RPC URL: $RPC_URL" + +# deploy mestFactory +MESTFACTORY_ADDRESS=$(forge create contracts/core/MestSharesFactoryV1.sol:MestSharesFactoryV1 \ + --constructor-args $MESTERC1155_ADDRESS $BASE_PRICE $INFLECTION_POINT $INFLECTION_PRICE $LINEAR_PRICE_SLOPE\ + --rpc-url $RPC_URL \ + --private-key $PRIVATE_KEY \ + --etherscan-api-key $API_KEY \ + --verifier-url $SCAN_URL \ + --json | jq -r '.deployedTo') +echo "MestFactory deployed at address: $MESTFACTORY_ADDRESS" +echo "Using RPC URL: $RPC_URL" + +# deploy aave yieldAggregator +AAVE_YIELDAGGREGATOR_ADDRESS=$(forge create contracts/core/aggregator/AaveYieldAggregator.sol:AaveYieldAggregator \ + --constructor-args $MESTFACTORY_ADDRESS $WETH $AAVE_POOL $AAVE_GATEWAY \ + --rpc-url $RPC_URL \ + --private-key $PRIVATE_KEY \ + --etherscan-api-key $API_KEY \ + --verifier-url $SCAN_URL \ + --json | jq -r '.deployedTo') +echo "Aave YieldAggregator deployed at address: $AAVE_YIELDAGGREGATOR_ADDRESS" +echo "Using RPC URL: $RPC_URL" + +# deploy blank yieldAggregator +BLANK_YIELDAGGREGATOR_ADDRESS=$(forge create contracts/core/aggregator/BlankYieldAggregator.sol:BlankYieldAggregator \ + --constructor-args $MESTFACTORY_ADDRESS $WETH \ + --rpc-url $RPC_URL \ + --private-key $PRIVATE_KEY \ + --etherscan-api-key $API_KEY \ + --verifier-url $SCAN_URL \ + --json | jq -r '.deployedTo') +echo "Blank YieldAggregator deployed at address: $BLANK_YIELDAGGREGATOR_ADDRESS" +echo "Using RPC URL: $RPC_URL" + +# record address +echo "{ + \"$NETWORK_NAME\" : { + \"MestERC1155\": \"$MESTERC1155_ADDRESS\", + \"MestFactory\": \"$MESTFACTORY_ADDRESS\", + \"YieldAggregator For Aave\": \"$AAVE_YIELDAGGREGATOR_ADDRESS\", + \"YieldAggregator For Blank\": \"$BLANK_YIELDAGGREGATOR_ADDRESS\" + } +}" > $OUTPUT_JSON + +# set factory for 1155 +cast send $MESTERC1155_ADDRESS "setFactory(address)" $MESTFACTORY_ADDRESS --rpc-url $RPC_URL --private-key $PRIVATE_KEY +echo "Erc1155 set factory: $MESTFACTORY_ADDRESS" + +# set yieldTool for factory +cast send $MESTFACTORY_ADDRESS "migrate(address)" $AAVE_YIELDAGGREGATOR_ADDRESS --rpc-url $RPC_URL --private-key $PRIVATE_KEY +echo "Factory set yield tool: $AAVE_YIELDAGGREGATOR_ADDRESS" + +# verify, if verifier in create didn't work. +forge verify-contract \ + --verifier-url $SCAN_URL \ + --watch \ + --constructor-args $(cast abi-encode "constructor(string)" $MEST_BASE_URL) \ + --etherscan-api-key $API_KEY \ + $MESTERC1155_ADDRESS \ + contracts/core/MestERC1155.sol:MestERC1155 + +forge verify-contract \ + --verifier-url $SCAN_URL \ + --watch \ + --constructor-args $(cast abi-encode "constructor(address,uint256,uint256,uint256,uint256)" $MESTERC1155_ADDRESS $BASE_PRICE $INFLECTION_POINT $INFLECTION_PRICE $LINEAR_PRICE_SLOPE) \ + --etherscan-api-key $API_KEY \ + $MESTFACTORY_ADDRESS \ + contracts/core/MestSharesFactoryV1.sol:MestSharesFactoryV1 + +forge verify-contract \ + --verifier-url $SCAN_URL \ + --watch \ + --constructor-args $(cast abi-encode "constructor(address,address,address,address)" $MESTFACTORY_ADDRESS $WETH $AAVE_POOL $AAVE_GATEWAY) \ + --etherscan-api-key $API_KEY \ + $AAVE_YIELDAGGREGATOR_ADDRESS \ + contracts/core/aggregator/AaveYieldAggregator.sol:AaveYieldAggregator + +forge verify-contract \ + --verifier-url $SCAN_URL \ + --watch \ + --constructor-args $(cast abi-encode "constructor(address,address)" $MESTFACTORY_ADDRESS $WETH) \ + --etherscan-api-key $API_KEY \ + $BLANK_YIELDAGGREGATOR_ADDRESS \ + contracts/core/aggregator/BlankYieldAggregator.sol:BlankYieldAggregator \ No newline at end of file diff --git a/deploy/deployed_addresses.json b/deploy/deployed_addresses.json new file mode 100644 index 0000000..628b689 --- /dev/null +++ b/deploy/deployed_addresses.json @@ -0,0 +1,8 @@ +{ + "optimism-sepolia" : { + "MestERC1155": "0x27DB12865d94288F97f6d8c9a4865e8207a23D05", + "MestFactory": "0x26c6f7FA1Fe03193D1Fb759Aac5Bda8e4b5fB4F8", + "YieldAggregator For Aave": "0x41a710CfB2CC4641FEabCDe8D882D2B476953418", + "YieldAggregator For Blank": "0x4Cbc4f4228eB3a2293CF7e746C6A5d0D5CaA286e" + } +}