From 34fac428c7009b310b8e874d03fca3545cfe61e5 Mon Sep 17 00:00:00 2001 From: Uri Date: Fri, 5 Jan 2024 16:13:04 -0300 Subject: [PATCH 01/38] various fixes --- .gitignore | 1 + README.md | 70 +++++++++++++++++--------- contracts/cairo/.env.example | 5 ++ contracts/cairo/deploy.sh | 33 ++++++------ contracts/solidity/.env.example | 6 +-- contracts/solidity/deploy.sh | 19 +++---- contracts/solidity/script/Deploy.s.sol | 5 +- contracts/solidity/test/Transfer.sol | 2 +- mm-bot/.env.example | 36 ++++++------- 9 files changed, 105 insertions(+), 72 deletions(-) create mode 100644 contracts/cairo/.env.example diff --git a/.gitignore b/.gitignore index 485dee64..3bf780b6 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea +.env \ No newline at end of file diff --git a/README.md b/README.md index dfa16843..3ab95cfc 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,31 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ## Declare and Deploy Contracts in Testnet +### Ethereum smart contract +First, the Ethereum smart contracts must be deployed. For Ethereum the deployment process you will need to: + +1. Create your `.env` file: you need to configure the following variables in your own .env file on the contracts/solidity/ folder. You can use the env.example file as a template for creating your .env file, paying special attention to the formats provided + + ```bash + ETH_RPC_URL = Infura or Alchemy RPC URL + ETH_PRIVATE_KEY = private key of your ETH wallet + ETHERSCAN_API_KEY = API Key to use etherscan to read the Ethereum blockchain + ``` + **NOTE**: + + - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics). + - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). + + +2. Deploy Solidity contract + + ```bash + make ethereum-deploy + ``` + +### Starknet smart contracts + +After the Ethereum smart contract is deployed, the Starknet smart contracts must be declared and deployed. On Starknet, the deployment process is in two steps: - Declaring the class of your contract, or sending your contract’s code to the @@ -108,40 +133,37 @@ On Starknet, the deployment process is in two steps: - Deploying a contract or creating an instance of the previously declared code with the necessary parameters -1. Updated `.env` file: Please modify the variables with your Testnet account and your RPC provider. +For this, you will need to: + +1. Create your `.env` file: you need to configure the following variables in your own .env file on the contracts/solidity folder. You can use the env.example file as a template for creating your .env file, paying special attention to the formats provided ```bash - // For the deploy, you just need to configure the following variables in the .env file on the mm-bot folder - .. - SN_RPC_URL= // Infura or Alchemy RPC URL - ETH_CONTRACT_ADDR=0xdd69db25f6d620a7bad3023c5d32761d353d3de9 // GoerliETH - SN_CONTRACT_ADDR= - .. + STARKNET_ACCOUNT = location of your starknet testnet account, created at the start of this README + STARKNET_KEYSTORE = location of your starknet testnet keystore, created at the start of this README + SN_RPC_URL = Infura or Alchemy RPC URL + ETH_CONTRACT_ADDR = newly created ETH contract address + MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker + ``` + 2. Declare and Deploy: We sequentially declare and deploy the contracts. ```bash make starknet-deploy ``` -For Ethereum the deployment process you will need: +### Finalize connection between both chains -3. Updated `.env` file: Please modify the variables with your Testnet account and your RPC provider. +After the Starknet smart contracts are declared and deployed, one variable from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. - ```bash - // For the deploy, you just need to configure the following variables in the .env file on the contracts/solidity/ folder - .. - ETH_RPC_URL= // Infura or Alchemy RPC URL - ETH_PRIVATE_KEY= - ETHERSCAN_API_KEY= - .. - ``` - **NOTE**: +For now, to do this you must go to the ETH explorer and find your ETH smart contract, for example: +https://goerli.etherscan.io/address/0x8C78111CCDd368345c7d6A7bb6A7c887b1093f7A#writeContract +Then, under the "contract/Write Contract" section, you must run the function, with your newly created Starknet escrow contract address as the parameter +``` +snEscrowAddress(uint256) +``` - - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics). - - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). -4. Deploy Solidity contract +This manual solution is temporary and wil be done automatically in the cairo deploy script. - ```bash - make ethereum-deploy - ``` +## Recap +After following this complete README, we should have an ETH smart contract as well as a Starknet smart contract, both connected to act as a bridge between these two chains. diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example new file mode 100644 index 00000000..b171f72c --- /dev/null +++ b/contracts/cairo/.env.example @@ -0,0 +1,5 @@ +STARKNET_ACCOUNT=~/.starkli-wallets/account.json +STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json +SN_RPC_URL=https://starknet-goerli.g.alchemy.com/v2/Oo-H7YBqtJrt4UCUYIad3KFYIPaDWXtB +ETH_CONTRACT_ADDR=0xA7D66ab47E22255E4c72E5F07A511f31b53beb68 +SN_CONTRACT_ADDR=0x05F9CfC57bbdB7190F275F832fbc261f711c1c509088ef191e7AE9F385361e7b \ No newline at end of file diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index a40eabba..d226ebbb 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -1,4 +1,11 @@ #!/bin/bash +if [ -f ./contracts/cairo/.env ]; then + echo "Sourcing .env file..." + source ./contracts/cairo/.env +else + echo "Error: .env file not found!" + exit 1 +fi # ANSI format GREEN='\e[32m' @@ -12,31 +19,29 @@ NATIVE_TOKEN_ETH_STARKNET=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562 cd "$(dirname "$0")" -load_env() { - unamestr=$(uname) - if [ "$unamestr" = 'Linux' ]; then - export $(grep -v '^#' ../../mm-bot/.env | xargs -d '\n') - elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then - export $(grep -v '^#' ../../mm-bot/.env | xargs -0) - fi -} -load_env - echo -e "${GREEN}\n=> [SN] Declare Escrow${COLOR_RESET}" -ESCROW_CLASS_HASH=$(starkli declare --watch --rpc $SN_RPC_URL target/dev/yab_Escrow.contract_class.json) +echo SN_RPC_URL +echo $SN_RPC_URL +ESCROW_CLASS_HASH=$(starkli declare \ + --account $STARKNET_ACCOUNT --keystore $STARKNET_KEYSTORE \ + --watch target/dev/yab_Escrow.contract_class.json) echo -e "- ${PURPLE}[SN] Escrow ClassHash: $ESCROW_CLASS_HASH${COLOR_RESET}" echo -e "- ${PURPLE}[SN] Herodotus Facts Registry: $HERODOTUS_FACTS_REGISTRY${COLOR_RESET}" -echo -e "- ${PURPLE}[SN] Market Maker: $SN_WALLET_ADDR${COLOR_RESET}" +echo -e "- ${PURPLE}[SN] Market Maker: $MM_SN_WALLET_ADDR${COLOR_RESET}" echo -e "- ${PURPLE}[SN] Ethereum ContractAddress $NATIVE_TOKEN_ETH_STARKNET${COLOR_RESET}" echo -e "- ${PINK}[ETH] Ethereum ContractAddress: $ETH_CONTRACT_ADDR${COLOR_RESET}" echo -e "- ${PINK}[ETH] Market Maker: $MM_ETHEREUM_WALLET${COLOR_RESET}" echo -e "${GREEN}\n=> [SN] Deploy Escrow${COLOR_RESET}" -ESCROW_CONTRACT_ADDRESS=$(starkli deploy --watch --rpc $SN_RPC_URL $ESCROW_CLASS_HASH \ +ESCROW_CONTRACT_ADDRESS=$(starkli deploy \ + --account $STARKNET_ACCOUNT --keystore $STARKNET_KEYSTORE \ + --watch $ESCROW_CLASS_HASH \ $HERODOTUS_FACTS_REGISTRY \ $ETH_CONTRACT_ADDR \ $MM_ETHEREUM_WALLET \ - $SN_WALLET_ADDR \ + $MM_SN_WALLET_ADDR \ $NATIVE_TOKEN_ETH_STARKNET) echo -e "- ${PURPLE}[SN] Escrow ContractAddress: $ESCROW_CONTRACT_ADDRESS${COLOR_RESET}" + + diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index c3b42c15..2184b111 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,3 +1,3 @@ -GOERLI_RPC_URL= -PRIVATE_KEY= -ETHERSCAN_API_KEY= +ETH_RPC_URL=https://eth-goerli.g.alchemy.com/v2/5-D7rxtDQ26IHdX9s-NPOBGgvWIKiW69 +ETH_PRIVATE_KEY=0xa159e1249359fa38c6c5e755f36f76fe5719d64794732a40259cd7fbc7132a3d +ETHERSCAN_API_KEY=NHCKN32BAH54WZJKNCZVYTGT6U73MJJ842 diff --git a/contracts/solidity/deploy.sh b/contracts/solidity/deploy.sh index a397406d..aab0846c 100755 --- a/contracts/solidity/deploy.sh +++ b/contracts/solidity/deploy.sh @@ -1,4 +1,11 @@ #!/bin/bash +if [ -f ./contracts/solidity/.env ]; then + echo "Sourcing .env file..." + source ./contracts/solidity/.env +else + echo "Error: .env file not found!" + exit 1 +fi # ANSI format GREEN='\e[32m' @@ -6,15 +13,5 @@ COLOR_RESET='\033[0m' cd "$(dirname "$0")" -load_env() { - unamestr=$(uname) - if [ "$unamestr" = 'Linux' ]; then - export $(grep -v '^#' ./.env | xargs -d '\n') - elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then - export $(grep -v '^#' ./.env | xargs -0) - fi -} -load_env - echo -e "${GREEN}\n=> [ETH] Deploy Escrow${COLOR_RESET}" -forge script ./script/Deploy.s.sol --fork-url $GOERLI_RPC_URL --broadcast --verify -vvvv \ No newline at end of file +forge script ./script/Deploy.s.sol --fork-url $ETH_RPC_URL --broadcast --verify -vvvv \ No newline at end of file diff --git a/contracts/solidity/script/Deploy.s.sol b/contracts/solidity/script/Deploy.s.sol index 00c069c4..672e0272 100644 --- a/contracts/solidity/script/Deploy.s.sol +++ b/contracts/solidity/script/Deploy.s.sol @@ -11,7 +11,10 @@ contract Deploy is Script { address snMessagingAddress = 0xde29d060D45901Fb19ED6C6e959EB22d8626708e; uint256 snEscrowAddress = 0x0; - uint256 snEscrowWithdrawSelector = 0x0; + //this is always the same value as long as starknet's function's name is "withdraw" + //this being the case, the function to overwrite this value should be deprecated + uint256 snEscrowWithdrawSelector = 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77; + new YABTransfer( snMessagingAddress, diff --git a/contracts/solidity/test/Transfer.sol b/contracts/solidity/test/Transfer.sol index 6f16df4d..96c4b99b 100644 --- a/contracts/solidity/test/Transfer.sol +++ b/contracts/solidity/test/Transfer.sol @@ -10,7 +10,7 @@ contract TransferTest is Test { function setUp() public { address snMessagingAddress = 0xde29d060D45901Fb19ED6C6e959EB22d8626708e; uint256 snEscrowAddress = 0x0; - uint256 snEscrowWithdrawSelector = 0x0; + uint256 snEscrowWithdrawSelector = 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77; yab = new YABTransfer(snMessagingAddress, snEscrowAddress, snEscrowWithdrawSelector); } diff --git a/mm-bot/.env.example b/mm-bot/.env.example index 0b5a459c..42b4abe9 100644 --- a/mm-bot/.env.example +++ b/mm-bot/.env.example @@ -1,18 +1,18 @@ -ENVIRONMENT= -ETH_RPC_URL= -SN_RPC_URL= -ETH_FALLBACK_RPC_URL= -SN_FALLBACK_RPC_URL= -ETH_CONTRACT_ADDR= -SN_CONTRACT_ADDR= -ETH_PRIVATE_KEY= -SN_WALLET_ADDR= -SN_PRIVATE_KEY= -HERODOTUS_API_KEY= -POSTGRES_HOST= -POSTGRES_USER= -POSTGRES_PASSWORD= -POSTGRES_DB= -LOGGING_LEVEL= -LOGGING_DIR= -WITHDRAWER= \ No newline at end of file +ENVIRONMENT=goerli +ETH_RPC_URL=https://eth-goerli.g.alchemy.com/v2/5-D7rxtDQ26IHdX9s-NPOBGgvWIKiW69 +SN_RPC_URL=https://starknet-goerli.g.alchemy.com/v2/Oo-H7YBqtJrt4UCUYIad3KFYIPaDWXtB +ETH_FALLBACK_RPC_URL= +SN_FALLBACK_RPC_URL= +ETH_CONTRACT_ADDR=0xA7D66ab47E22255E4c72E5F07A511f31b53beb68 +SN_CONTRACT_ADDR= +ETH_PRIVATE_KEY= +SN_WALLET_ADDR=0x05F9CfC57bbdB7190F275F833fbc261f711c1c509088ef191e7AE9F385361e7b +SN_PRIVATE_KEY= +HERODOTUS_API_KEY= +POSTGRES_HOST= +POSTGRES_USER= +POSTGRES_PASSWORD= +POSTGRES_DB= +LOGGING_LEVEL= +LOGGING_DIR= +WITHDRAWER= \ No newline at end of file From 0b9180af1ea7f04a390e33e0de0ed8994f5a812c Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 16:27:07 -0300 Subject: [PATCH 02/38] rewrite .env.exampole formats --- contracts/cairo/.env.example | 6 +++--- contracts/solidity/.env.example | 6 +++--- mm-bot/.env.example | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index b171f72c..7f925d0f 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,5 +1,5 @@ STARKNET_ACCOUNT=~/.starkli-wallets/account.json STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json -SN_RPC_URL=https://starknet-goerli.g.alchemy.com/v2/Oo-H7YBqtJrt4UCUYIad3KFYIPaDWXtB -ETH_CONTRACT_ADDR=0xA7D66ab47E22255E4c72E5F07A511f31b53beb68 -SN_CONTRACT_ADDR=0x05F9CfC57bbdB7190F275F832fbc261f711c1c509088ef191e7AE9F385361e7b \ No newline at end of file +SN_RPC_URL= +ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, as given by etherscan +MM_SN_WALLET_ADDR= #in hexa with the 0x prefix, as given by starkscan \ No newline at end of file diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index 2184b111..39355fa5 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,3 +1,3 @@ -ETH_RPC_URL=https://eth-goerli.g.alchemy.com/v2/5-D7rxtDQ26IHdX9s-NPOBGgvWIKiW69 -ETH_PRIVATE_KEY=0xa159e1249359fa38c6c5e755f36f76fe5719d64794732a40259cd7fbc7132a3d -ETHERSCAN_API_KEY=NHCKN32BAH54WZJKNCZVYTGT6U73MJJ842 +ETH_RPC_URL= +ETH_PRIVATE_KEY= #in lowercase hexa with the 0x prefix +ETHERSCAN_API_KEY= diff --git a/mm-bot/.env.example b/mm-bot/.env.example index 42b4abe9..69f9cbb0 100644 --- a/mm-bot/.env.example +++ b/mm-bot/.env.example @@ -1,12 +1,12 @@ ENVIRONMENT=goerli -ETH_RPC_URL=https://eth-goerli.g.alchemy.com/v2/5-D7rxtDQ26IHdX9s-NPOBGgvWIKiW69 -SN_RPC_URL=https://starknet-goerli.g.alchemy.com/v2/Oo-H7YBqtJrt4UCUYIad3KFYIPaDWXtB +ETH_RPC_URL= +SN_RPC_URL= ETH_FALLBACK_RPC_URL= SN_FALLBACK_RPC_URL= -ETH_CONTRACT_ADDR=0xA7D66ab47E22255E4c72E5F07A511f31b53beb68 +ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, as given by etherscan SN_CONTRACT_ADDR= ETH_PRIVATE_KEY= -SN_WALLET_ADDR=0x05F9CfC57bbdB7190F275F833fbc261f711c1c509088ef191e7AE9F385361e7b +SN_WALLET_ADDR= #in hexa with the 0x prefix, as given by etherscan SN_PRIVATE_KEY= HERODOTUS_API_KEY= POSTGRES_HOST= From 401998807f0565be05735f3586573623a1252cb8 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 16:43:18 -0300 Subject: [PATCH 03/38] fix .env lowercase --- contracts/cairo/.env.example | 4 ++-- mm-bot/.env.example | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 7f925d0f..f7fc95f3 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,5 +1,5 @@ STARKNET_ACCOUNT=~/.starkli-wallets/account.json STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json SN_RPC_URL= -ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, as given by etherscan -MM_SN_WALLET_ADDR= #in hexa with the 0x prefix, as given by starkscan \ No newline at end of file +ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix +MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file diff --git a/mm-bot/.env.example b/mm-bot/.env.example index 69f9cbb0..6d52a656 100644 --- a/mm-bot/.env.example +++ b/mm-bot/.env.example @@ -3,10 +3,10 @@ ETH_RPC_URL= SN_RPC_URL= ETH_FALLBACK_RPC_URL= SN_FALLBACK_RPC_URL= -ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, as given by etherscan +ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix SN_CONTRACT_ADDR= ETH_PRIVATE_KEY= -SN_WALLET_ADDR= #in hexa with the 0x prefix, as given by etherscan +SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix SN_PRIVATE_KEY= HERODOTUS_API_KEY= POSTGRES_HOST= From 359523baa92c507d1b6a3fb45d511be446001246 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 17:18:19 -0300 Subject: [PATCH 04/38] add foundry usage to write the starknet address to eth contract --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 3ab95cfc..c2eae44d 100644 --- a/README.md +++ b/README.md @@ -165,5 +165,18 @@ snEscrowAddress(uint256) This manual solution is temporary and wil be done automatically in the cairo deploy script. +To do this, you can also use Foundry's **cast** function, as follows: + +``` +cast send \ +--rpc-url \ +--private-key \ + "setEscrowAddress(uint256)" +``` + +This will send a transaction, using the specified rpc, from the specified address, to the specified smart contract, calling the "setEscrowAddress" function, with your new SN contract address. + + + ## Recap After following this complete README, we should have an ETH smart contract as well as a Starknet smart contract, both connected to act as a bridge between these two chains. From 489a32d4dbd24e4391966426aa07e7d1592f9c72 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 19:07:53 -0300 Subject: [PATCH 05/38] fix ENVIRONMENT var in .env.example --- mm-bot/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm-bot/.env.example b/mm-bot/.env.example index 6d52a656..7a083efe 100644 --- a/mm-bot/.env.example +++ b/mm-bot/.env.example @@ -1,4 +1,4 @@ -ENVIRONMENT=goerli +ENVIRONMENT= ETH_RPC_URL= SN_RPC_URL= ETH_FALLBACK_RPC_URL= From cd1e8e208c7272a3be068d7821dc9361872b7be3 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 20:13:57 -0300 Subject: [PATCH 06/38] revert mm.env.example --- mm-bot/.env.example | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mm-bot/.env.example b/mm-bot/.env.example index ce766c71..b88cab55 100644 --- a/mm-bot/.env.example +++ b/mm-bot/.env.example @@ -3,18 +3,18 @@ ETH_CHAIN_ID=<1=mainnet|5=goerli|11155111=sepolia> SN_CHAIN_ID= ETH_RPC_URL= SN_RPC_URL= -ETH_FALLBACK_RPC_URL= -SN_FALLBACK_RPC_URL= -ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix -SN_CONTRACT_ADDR= -ETH_PRIVATE_KEY= -SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix -SN_PRIVATE_KEY= -HERODOTUS_API_KEY= -POSTGRES_HOST= -POSTGRES_USER= -POSTGRES_PASSWORD= -POSTGRES_DB= -LOGGING_LEVEL= -LOGGING_DIR= -WITHDRAWER= \ No newline at end of file +ETH_FALLBACK_RPC_URL= +SN_FALLBACK_RPC_URL= +ETH_CONTRACT_ADDR= +SN_CONTRACT_ADDR= +ETH_PRIVATE_KEY= +SN_WALLET_ADDR= +SN_PRIVATE_KEY= +HERODOTUS_API_KEY= +POSTGRES_HOST= +POSTGRES_USER= +POSTGRES_PASSWORD= +POSTGRES_DB= +LOGGING_LEVEL= +LOGGING_DIR= +WITHDRAWER= \ No newline at end of file From 29b1a14a10825d5b9789126acf9eb6865c562b19 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 20:15:16 -0300 Subject: [PATCH 07/38] fix .env comment format --- contracts/cairo/.env.example | 4 ++-- contracts/solidity/.env.example | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index f7fc95f3..c848e368 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,5 +1,5 @@ STARKNET_ACCOUNT=~/.starkli-wallets/account.json STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json SN_RPC_URL= -ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix -MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file +ETH_CONTRACT_ADDR= ;in lowercase hexa with the 0x prefix +MM_SN_WALLET_ADDR= ;in lowercase hexa with the 0x prefix \ No newline at end of file diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index 39355fa5..af7265d7 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,3 +1,3 @@ ETH_RPC_URL= -ETH_PRIVATE_KEY= #in lowercase hexa with the 0x prefix +ETH_PRIVATE_KEY= ;in lowercase hexa with the 0x prefix ETHERSCAN_API_KEY= From 113a30713cb9f1e3289fa12f79376e1feb25788a Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 20:47:26 -0300 Subject: [PATCH 08/38] revert env import fix --- contracts/cairo/deploy.sh | 19 ++++++++++--------- contracts/solidity/deploy.sh | 19 ++++++++++++------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index d226ebbb..c269c1dc 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -1,11 +1,4 @@ #!/bin/bash -if [ -f ./contracts/cairo/.env ]; then - echo "Sourcing .env file..." - source ./contracts/cairo/.env -else - echo "Error: .env file not found!" - exit 1 -fi # ANSI format GREEN='\e[32m' @@ -19,9 +12,17 @@ NATIVE_TOKEN_ETH_STARKNET=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562 cd "$(dirname "$0")" +load_env() { + unamestr=$(uname) + if [ "$unamestr" = 'Linux' ]; then + export $(grep -v '^#' .env | xargs -d '\n') + elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then + export $(grep -v '^#' .env | xargs -0) + fi +} +load_env + echo -e "${GREEN}\n=> [SN] Declare Escrow${COLOR_RESET}" -echo SN_RPC_URL -echo $SN_RPC_URL ESCROW_CLASS_HASH=$(starkli declare \ --account $STARKNET_ACCOUNT --keystore $STARKNET_KEYSTORE \ --watch target/dev/yab_Escrow.contract_class.json) diff --git a/contracts/solidity/deploy.sh b/contracts/solidity/deploy.sh index aab0846c..0b9cb3af 100755 --- a/contracts/solidity/deploy.sh +++ b/contracts/solidity/deploy.sh @@ -1,11 +1,4 @@ #!/bin/bash -if [ -f ./contracts/solidity/.env ]; then - echo "Sourcing .env file..." - source ./contracts/solidity/.env -else - echo "Error: .env file not found!" - exit 1 -fi # ANSI format GREEN='\e[32m' @@ -13,5 +6,17 @@ COLOR_RESET='\033[0m' cd "$(dirname "$0")" +pwd + +load_env() { + unamestr=$(uname) + if [ "$unamestr" = 'Linux' ]; then + export $(grep -v '^#' .env | xargs -d '\n') + elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then + export $(grep -v '^#' .env | xargs -0) + fi +} +load_env + echo -e "${GREEN}\n=> [ETH] Deploy Escrow${COLOR_RESET}" forge script ./script/Deploy.s.sol --fork-url $ETH_RPC_URL --broadcast --verify -vvvv \ No newline at end of file From bda0538d44c38aec780f18d3b85373d7568e7448 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Mon, 8 Jan 2024 21:03:59 -0300 Subject: [PATCH 09/38] set-escrow in makefile --- Makefile | 3 +++ contracts/solidity/set_escrow.sh | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100755 contracts/solidity/set_escrow.sh diff --git a/Makefile b/Makefile index 9d3cf070..f921a819 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ ethereum-test: ethereum-clean ethereum-deploy: ethereum-clean @./contracts/solidity/deploy.sh +ethereum-set-escrow: + @./contracts/solidity/set_escrow.sh + starknet-clean: @cd ./contracts/cairo/ && scarb clean diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh new file mode 100755 index 00000000..30dc329d --- /dev/null +++ b/contracts/solidity/set_escrow.sh @@ -0,0 +1,25 @@ +#!/bin/bash +if [ -f ./contracts/solidity/.env ]; then + echo "Sourcing .env file..." + source ./contracts/solidity/.env +else + echo "Error: .env file not found!" + exit 1 +fi +if [ -f ./contracts/cairo/.env ]; then + echo "Sourcing .env file..." + source ./contracts/cairo/.env +else + echo "Error: .env file not found!" + exit 1 +fi + +# ANSI format +GREEN='\e[32m' +COLOR_RESET='\033[0m' + +cd "$(dirname "$0")" + +echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" + +cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f \ No newline at end of file From 0dff589151e4c24de34e4042a56e7b30455911b2 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Tue, 9 Jan 2024 15:34:02 -0300 Subject: [PATCH 10/38] improve make and .sh of post-deploy functions --- Makefile | 28 ++++++++++++++++++++- contracts/solidity/set_escrow.sh | 5 +++- contracts/solidity/set_withdraw_selector.sh | 27 ++++++++++++++++++++ 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 contracts/solidity/set_withdraw_selector.sh diff --git a/Makefile b/Makefile index f921a819..296d47b3 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,34 @@ ethereum-test: ethereum-clean ethereum-deploy: ethereum-clean @./contracts/solidity/deploy.sh + +Command := $(firstword $(MAKECMDGOALS)) +PARAM := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) ethereum-set-escrow: - @./contracts/solidity/set_escrow.sh +ifneq ($(PARAM),) + @./contracts/solidity/set_escrow.sh $(PARAM) +else + @echo "Error: New Escrow address nedded" + @echo "Example of usage:" + @echo "make ethereum-set-escrow 0x01234..." +endif +%:: + @true + + +Command := $(firstword $(MAKECMDGOALS)) +PARAM := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) +ethereum-set-withdraw-selector: +ifneq ($(PARAM),) + @./contracts/solidity/set_withdraw_selector.sh $(PARAM) +else + @echo "Error: New withdraw selector nedded" + @echo "Example of usage:" + @echo "make ethereum-set-withdraw-selector 0x01234..." +endif +%:: + @true + starknet-clean: @cd ./contracts/cairo/ && scarb clean diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index 30dc329d..47172b4b 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -21,5 +21,8 @@ COLOR_RESET='\033[0m' cd "$(dirname "$0")" echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" +echo "Smart contract being modified:" $ETH_CONTRACT_ADDR +echo "New Escrow address:" $1 -cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f \ No newline at end of file +cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" $1 +# example param: 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f \ No newline at end of file diff --git a/contracts/solidity/set_withdraw_selector.sh b/contracts/solidity/set_withdraw_selector.sh new file mode 100755 index 00000000..e4536654 --- /dev/null +++ b/contracts/solidity/set_withdraw_selector.sh @@ -0,0 +1,27 @@ +#!/bin/bash +if [ -f ./contracts/solidity/.env ]; then + echo "Sourcing .env file..." + source ./contracts/solidity/.env +else + echo "Error: .env file not found!" + exit 1 +fi +if [ -f ./contracts/cairo/.env ]; then + echo "Sourcing .env file..." + source ./contracts/cairo/.env +else + echo "Error: .env file not found!" + exit 1 +fi + +# ANSI format +GREEN='\e[32m' +COLOR_RESET='\033[0m' + +cd "$(dirname "$0")" + +echo -e "${GREEN}\n=> [ETH] Setting Starknet Withdraw Selector on ETH Smart Contract${COLOR_RESET}" +echo "Smart contract being modified:" $ETH_CONTRACT_ADDR +echo "New Withdraw Selector:" $1 +cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowWithdrawSelector(uint256)" $1 +# example param: 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77 \ No newline at end of file From d8d82ba4a65562ed32916116a401aa3c43ce872f Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Tue, 9 Jan 2024 15:41:18 -0300 Subject: [PATCH 11/38] update readme with new make functions --- README.md | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c2eae44d..84e17cce 100644 --- a/README.md +++ b/README.md @@ -154,29 +154,18 @@ For this, you will need to: ### Finalize connection between both chains -After the Starknet smart contracts are declared and deployed, one variable from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. +After the Starknet smart contracts are declared and deployed, the variable _EscrowAddress_ from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. -For now, to do this you must go to the ETH explorer and find your ETH smart contract, for example: -https://goerli.etherscan.io/address/0x8C78111CCDd368345c7d6A7bb6A7c887b1093f7A#writeContract -Then, under the "contract/Write Contract" section, you must run the function, with your newly created Starknet escrow contract address as the parameter +To do this, you can use ``` -snEscrowAddress(uint256) +make ethereum-set-escrow ``` -This manual solution is temporary and wil be done automatically in the cairo deploy script. - -To do this, you can also use Foundry's **cast** function, as follows: - +You can also set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: ``` -cast send \ ---rpc-url \ ---private-key \ - "setEscrowAddress(uint256)" +make ethereum-set-withdraw-selector ``` -This will send a transaction, using the specified rpc, from the specified address, to the specified smart contract, calling the "setEscrowAddress" function, with your new SN contract address. - - ## Recap After following this complete README, we should have an ETH smart contract as well as a Starknet smart contract, both connected to act as a bridge between these two chains. From e544c8741526ff3032a4155df230067758e6b7c3 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Tue, 9 Jan 2024 15:43:06 -0300 Subject: [PATCH 12/38] fix .env comments --- contracts/cairo/.env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index c848e368..f7fc95f3 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,5 +1,5 @@ STARKNET_ACCOUNT=~/.starkli-wallets/account.json STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json SN_RPC_URL= -ETH_CONTRACT_ADDR= ;in lowercase hexa with the 0x prefix -MM_SN_WALLET_ADDR= ;in lowercase hexa with the 0x prefix \ No newline at end of file +ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix +MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file From 0912eda6f033744ba41beae69c47f242ca296ee5 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Tue, 9 Jan 2024 15:43:13 -0300 Subject: [PATCH 13/38] fix .env comments --- contracts/solidity/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index af7265d7..39355fa5 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,3 +1,3 @@ ETH_RPC_URL= -ETH_PRIVATE_KEY= ;in lowercase hexa with the 0x prefix +ETH_PRIVATE_KEY= #in lowercase hexa with the 0x prefix ETHERSCAN_API_KEY= From 7503efc9eb5cb87c2f1a27f0acdc51e4415e6f1f Mon Sep 17 00:00:00 2001 From: urimihura <43704209+uri-99@users.noreply.github.com> Date: Tue, 9 Jan 2024 17:58:49 -0300 Subject: [PATCH 14/38] Update contracts/cairo/.env.example Co-authored-by: Roberto J Catalan --- contracts/cairo/.env.example | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index f7fc95f3..226e687c 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,5 +1,5 @@ -STARKNET_ACCOUNT=~/.starkli-wallets/account.json -STARKNET_KEYSTORE=~/.starkli-wallets/keystore.json +STARKNET_ACCOUNT= +STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file From 929d330c84dbf51c01671af00d4520fcc2757e5b Mon Sep 17 00:00:00 2001 From: urimihura <43704209+uri-99@users.noreply.github.com> Date: Tue, 9 Jan 2024 18:00:08 -0300 Subject: [PATCH 15/38] Update README.md Co-authored-by: Roberto J Catalan --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 84e17cce..2f91a5d1 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen ``` **NOTE**: - - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/viewing-api-usage-statistics). + - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/creating-an-account). - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). From 871c654d3ebd6f339308c332337ad09e066c320c Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Tue, 9 Jan 2024 18:04:04 -0300 Subject: [PATCH 16/38] remove unnesecary print --- contracts/solidity/deploy.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/solidity/deploy.sh b/contracts/solidity/deploy.sh index 0b9cb3af..e2322035 100755 --- a/contracts/solidity/deploy.sh +++ b/contracts/solidity/deploy.sh @@ -6,8 +6,6 @@ COLOR_RESET='\033[0m' cd "$(dirname "$0")" -pwd - load_env() { unamestr=$(uname) if [ "$unamestr" = 'Linux' ]; then From edb8cd6ebf3e9cef6a648e702d8031133b37da48 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 12:29:44 -0300 Subject: [PATCH 17/38] run set escrow after cairo deploy --- contracts/cairo/deploy.sh | 3 +++ contracts/solidity/set_escrow.sh | 16 +++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index c269c1dc..07c9a27f 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -45,4 +45,7 @@ ESCROW_CONTRACT_ADDRESS=$(starkli deploy \ $NATIVE_TOKEN_ETH_STARKNET) echo -e "- ${PURPLE}[SN] Escrow ContractAddress: $ESCROW_CONTRACT_ADDRESS${COLOR_RESET}" +cd ../.. +contracts/solidity/set_escrow.sh $ESCROW_CONTRACT_ADDRESS + diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index 47172b4b..3e95e974 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -1,4 +1,13 @@ #!/bin/bash + +# ANSI format +GREEN='\e[32m' +COLOR_RESET='\033[0m' + +cd "$(dirname "$0")" + +echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" + if [ -f ./contracts/solidity/.env ]; then echo "Sourcing .env file..." source ./contracts/solidity/.env @@ -14,13 +23,6 @@ else exit 1 fi -# ANSI format -GREEN='\e[32m' -COLOR_RESET='\033[0m' - -cd "$(dirname "$0")" - -echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" echo "Smart contract being modified:" $ETH_CONTRACT_ADDR echo "New Escrow address:" $1 From 49cfcbf6ab5c0aca92c44078afe9671ccc50f54f Mon Sep 17 00:00:00 2001 From: urimihura <43704209+uri-99@users.noreply.github.com> Date: Wed, 10 Jan 2024 12:34:27 -0300 Subject: [PATCH 18/38] Update contracts/cairo/.env.example Co-authored-by: Roberto J Catalan --- contracts/cairo/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 226e687c..867f6bf8 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -2,4 +2,4 @@ STARKNET_ACCOUNT= STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix -MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file +MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file From d6e25543f6a239909c6ef8501603286a705afa68 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 13:04:54 -0300 Subject: [PATCH 19/38] clarify how to get withdraw-selector value --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2f91a5d1..477cd6f3 100644 --- a/README.md +++ b/README.md @@ -161,10 +161,14 @@ To do this, you can use make ethereum-set-escrow ``` -You can also set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: +Also, Ethereum's smart contract has a variable, _EscrowWithdrawSelector_, which is for specifying the _withdraw_ function's name in the Starknet Escrow smart contract. +You can set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: ``` make ethereum-set-withdraw-selector ``` + **NOTE**: + - In able to get a formated selector name, you can type the function's name (for example, _withdraw_) in https://www.stark-utils.xyz/converter , change the _selector_ row to hex, and copy its value + ## Recap From c75577a534690c6876b8ff795b8cf577c0f7de23 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 15:08:10 -0300 Subject: [PATCH 20/38] NTH print --- contracts/solidity/set_escrow.sh | 8 ++++---- contracts/solidity/set_withdraw_selector.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index 3e95e974..8d90ce3a 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -9,17 +9,17 @@ cd "$(dirname "$0")" echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" if [ -f ./contracts/solidity/.env ]; then - echo "Sourcing .env file..." + echo "Sourcing solidity/.env file..." source ./contracts/solidity/.env else - echo "Error: .env file not found!" + echo "Error: solidity/.env file not found!" exit 1 fi if [ -f ./contracts/cairo/.env ]; then - echo "Sourcing .env file..." + echo "Sourcing cairo/.env file..." source ./contracts/cairo/.env else - echo "Error: .env file not found!" + echo "Error: cairo/.env file not found!" exit 1 fi diff --git a/contracts/solidity/set_withdraw_selector.sh b/contracts/solidity/set_withdraw_selector.sh index e4536654..87b21296 100755 --- a/contracts/solidity/set_withdraw_selector.sh +++ b/contracts/solidity/set_withdraw_selector.sh @@ -1,16 +1,16 @@ #!/bin/bash if [ -f ./contracts/solidity/.env ]; then - echo "Sourcing .env file..." + echo "Sourcing solidity/.env file..." source ./contracts/solidity/.env else - echo "Error: .env file not found!" + echo "Error: solidity/.env file not found!" exit 1 fi if [ -f ./contracts/cairo/.env ]; then - echo "Sourcing .env file..." + echo "Sourcing cairo/.env file..." source ./contracts/cairo/.env else - echo "Error: .env file not found!" + echo "Error: cairo/.env file not found!" exit 1 fi From 3418b9f8847c1b0a6630ecdff927c89fb189d2e3 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 16:57:49 -0300 Subject: [PATCH 21/38] set-withdraw-selector executes automatically in cairo/deploy.sh --- README.md | 2 +- contracts/cairo/.env.example | 3 ++- contracts/cairo/deploy.sh | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 477cd6f3..fc90c5da 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ For this, you will need to: SN_RPC_URL = Infura or Alchemy RPC URL ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker - + ESCROW_WITHDRAW_SELECTOR = 'Withdraw' function selector from the Escrow smart contract ``` 2. Declare and Deploy: We sequentially declare and deploy the contracts. diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 867f6bf8..e1737961 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -2,4 +2,5 @@ STARKNET_ACCOUNT= STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix -MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix \ No newline at end of file +MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix +ESCROW_WITHDRAW_SELECTOR= #in lowercase hexa with the 0x prefix \ No newline at end of file diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index 07c9a27f..5d4a7f08 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -47,5 +47,6 @@ echo -e "- ${PURPLE}[SN] Escrow ContractAddress: $ESCROW_CONTRACT_ADDRESS${COLOR cd ../.. contracts/solidity/set_escrow.sh $ESCROW_CONTRACT_ADDRESS +contracts/solidity/set_withdraw_selector.sh $ESCROW_WITHDRAW_SELECTOR From 8f67e103af1378a90068ea32376f10c12af99959 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 17:00:08 -0300 Subject: [PATCH 22/38] format --- Makefile | 4 ++-- contracts/cairo/.env.example | 2 +- contracts/cairo/deploy.sh | 2 -- contracts/solidity/deploy.sh | 2 +- contracts/solidity/set_escrow.sh | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 296d47b3..25e17da8 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ ethereum-set-escrow: ifneq ($(PARAM),) @./contracts/solidity/set_escrow.sh $(PARAM) else - @echo "Error: New Escrow address nedded" + @echo "Error: New Escrow address needed" @echo "Example of usage:" @echo "make ethereum-set-escrow 0x01234..." endif @@ -45,7 +45,7 @@ ethereum-set-withdraw-selector: ifneq ($(PARAM),) @./contracts/solidity/set_withdraw_selector.sh $(PARAM) else - @echo "Error: New withdraw selector nedded" + @echo "Error: New withdraw selector needed" @echo "Example of usage:" @echo "make ethereum-set-withdraw-selector 0x01234..." endif diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index e1737961..7cefc039 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -3,4 +3,4 @@ STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix -ESCROW_WITHDRAW_SELECTOR= #in lowercase hexa with the 0x prefix \ No newline at end of file +ESCROW_WITHDRAW_SELECTOR= #in lowercase hexa with the 0x prefix diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index 5d4a7f08..8cfb5563 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -48,5 +48,3 @@ echo -e "- ${PURPLE}[SN] Escrow ContractAddress: $ESCROW_CONTRACT_ADDRESS${COLOR cd ../.. contracts/solidity/set_escrow.sh $ESCROW_CONTRACT_ADDRESS contracts/solidity/set_withdraw_selector.sh $ESCROW_WITHDRAW_SELECTOR - - diff --git a/contracts/solidity/deploy.sh b/contracts/solidity/deploy.sh index e2322035..afdf66a9 100755 --- a/contracts/solidity/deploy.sh +++ b/contracts/solidity/deploy.sh @@ -17,4 +17,4 @@ load_env() { load_env echo -e "${GREEN}\n=> [ETH] Deploy Escrow${COLOR_RESET}" -forge script ./script/Deploy.s.sol --fork-url $ETH_RPC_URL --broadcast --verify -vvvv \ No newline at end of file +forge script ./script/Deploy.s.sol --fork-url $ETH_RPC_URL --broadcast --verify -vvvv diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index 8d90ce3a..18b6cabf 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -27,4 +27,4 @@ echo "Smart contract being modified:" $ETH_CONTRACT_ADDR echo "New Escrow address:" $1 cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" $1 -# example param: 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f \ No newline at end of file +# example param: 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f From b8a69f8b2d04d91f06573282cba25d264cc423d1 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 17:33:57 -0300 Subject: [PATCH 23/38] ignore comments fix in .env import --- contracts/cairo/deploy.sh | 4 ++-- contracts/solidity/deploy.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index 8cfb5563..ba781e40 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -15,9 +15,9 @@ cd "$(dirname "$0")" load_env() { unamestr=$(uname) if [ "$unamestr" = 'Linux' ]; then - export $(grep -v '^#' .env | xargs -d '\n') + export $(sed '/^#/d; s/#.*$//' .env | xargs -d '\n') elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then - export $(grep -v '^#' .env | xargs -0) + export $(sed '/^#/d; s/#.*$//' .env | xargs -0) fi } load_env diff --git a/contracts/solidity/deploy.sh b/contracts/solidity/deploy.sh index afdf66a9..053ce958 100755 --- a/contracts/solidity/deploy.sh +++ b/contracts/solidity/deploy.sh @@ -9,9 +9,9 @@ cd "$(dirname "$0")" load_env() { unamestr=$(uname) if [ "$unamestr" = 'Linux' ]; then - export $(grep -v '^#' .env | xargs -d '\n') + export $(sed '/^#/d; s/#.*$//' .env | xargs -d '\n') elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then - export $(grep -v '^#' .env | xargs -0) + export $(sed '/^#/d; s/#.*$//' .env | xargs -0) fi } load_env From 2436a58d743bc2acc86679f494b8fd187bf492dc Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 17:55:47 -0300 Subject: [PATCH 24/38] added env vars, removed them from deploy.sh --- README.md | 3 +++ contracts/cairo/.env.example | 5 ++++- contracts/cairo/deploy.sh | 4 ---- contracts/solidity/set_escrow.sh | 1 - contracts/solidity/set_withdraw_selector.sh | 2 -- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fc90c5da..90c67f88 100644 --- a/README.md +++ b/README.md @@ -144,6 +144,9 @@ For this, you will need to: ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker ESCROW_WITHDRAW_SELECTOR = 'Withdraw' function selector from the Escrow smart contract + HERODOTUS_FACTS_REGISTRY = Herodotus' Facts Registry Smart Contract in Starknet + MM_ETHEREUM_WALLET = Ethereum wallet of the MArketMaker + NATIVE_TOKEN_ETH_STARKNET = Ethereum's erc20 token handler contract in Starkent ``` 2. Declare and Deploy: We sequentially declare and deploy the contracts. diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 7cefc039..495bb50f 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -2,5 +2,8 @@ STARKNET_ACCOUNT= STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix -MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix +MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix ESCROW_WITHDRAW_SELECTOR= #in lowercase hexa with the 0x prefix +HERODOTUS_FACTS_REGISTRY= #in lowercase hexa with the 0x prefix +MM_ETHEREUM_WALLET= #in lowercase hexa with the 0x prefix +NATIVE_TOKEN_ETH_STARKNET= #in lowercase hexa with the 0x prefix diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index ba781e40..94609f72 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -6,10 +6,6 @@ PURPLE='\033[1;34m' PINK='\033[1;35m' COLOR_RESET='\033[0m' -HERODOTUS_FACTS_REGISTRY=0x01b2111317EB693c3EE46633edd45A4876db14A3a53ACDBf4E5166976d8e869d -MM_ETHEREUM_WALLET=0xE8504996d2e25735FA88B3A0a03B4ceD2d3086CC -NATIVE_TOKEN_ETH_STARKNET=0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 - cd "$(dirname "$0")" load_env() { diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index 18b6cabf..aed4bcb8 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -4,7 +4,6 @@ GREEN='\e[32m' COLOR_RESET='\033[0m' -cd "$(dirname "$0")" echo -e "${GREEN}\n=> [ETH] Setting Starknet Escrow Address on ETH Smart Contract${COLOR_RESET}" diff --git a/contracts/solidity/set_withdraw_selector.sh b/contracts/solidity/set_withdraw_selector.sh index 87b21296..40141563 100755 --- a/contracts/solidity/set_withdraw_selector.sh +++ b/contracts/solidity/set_withdraw_selector.sh @@ -18,8 +18,6 @@ fi GREEN='\e[32m' COLOR_RESET='\033[0m' -cd "$(dirname "$0")" - echo -e "${GREEN}\n=> [ETH] Setting Starknet Withdraw Selector on ETH Smart Contract${COLOR_RESET}" echo "Smart contract being modified:" $ETH_CONTRACT_ADDR echo "New Withdraw Selector:" $1 From 32abb05d8c8c9aa421612de4034f778177fae05f Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 20:29:49 -0300 Subject: [PATCH 25/38] created make starknet-deploy-and-connect This commit also adds 2 new .env vars, so that the 3 steps in deploying a starknet contract must have parameter passing between them --- Makefile | 39 +++++++-------------- README.md | 33 ++++++++++++----- contracts/cairo/.env.example | 3 +- contracts/cairo/deploy.sh | 4 +-- contracts/solidity/set_escrow.sh | 5 ++- contracts/solidity/set_withdraw_selector.sh | 8 +++-- 6 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Makefile b/Makefile index 25e17da8..41009482 100644 --- a/Makefile +++ b/Makefile @@ -24,34 +24,11 @@ ethereum-test: ethereum-clean ethereum-deploy: ethereum-clean @./contracts/solidity/deploy.sh - -Command := $(firstword $(MAKECMDGOALS)) -PARAM := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) ethereum-set-escrow: -ifneq ($(PARAM),) - @./contracts/solidity/set_escrow.sh $(PARAM) -else - @echo "Error: New Escrow address needed" - @echo "Example of usage:" - @echo "make ethereum-set-escrow 0x01234..." -endif -%:: - @true - - -Command := $(firstword $(MAKECMDGOALS)) -PARAM := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) -ethereum-set-withdraw-selector: -ifneq ($(PARAM),) - @./contracts/solidity/set_withdraw_selector.sh $(PARAM) -else - @echo "Error: New withdraw selector needed" - @echo "Example of usage:" - @echo "make ethereum-set-withdraw-selector 0x01234..." -endif -%:: - @true + @./contracts/solidity/set_escrow.sh +ethereum-set-withdraw-selector: + @./contracts/solidity/set_withdraw_selector.sh starknet-clean: @cd ./contracts/cairo/ && scarb clean @@ -63,4 +40,12 @@ starknet-test: starknet-clean @cd ./contracts/cairo/ && snforge test starknet-deploy: starknet-build - @./contracts/cairo/deploy.sh \ No newline at end of file + @./contracts/cairo/deploy.sh + +starknet-deploy-and-connect: starknet-build + @$(MAKE) starknet-deploy + @$(MAKE) ethereum-set-escrow + @$(MAKE) ethereum-set-withdraw-selector + + + \ No newline at end of file diff --git a/README.md b/README.md index 90c67f88..eee16181 100644 --- a/README.md +++ b/README.md @@ -143,35 +143,50 @@ For this, you will need to: SN_RPC_URL = Infura or Alchemy RPC URL ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker - ESCROW_WITHDRAW_SELECTOR = 'Withdraw' function selector from the Escrow smart contract + WITHDRAW_NAME = The exact name of the function that withdraws from the starknet smart contract HERODOTUS_FACTS_REGISTRY = Herodotus' Facts Registry Smart Contract in Starknet MM_ETHEREUM_WALLET = Ethereum wallet of the MArketMaker NATIVE_TOKEN_ETH_STARKNET = Ethereum's erc20 token handler contract in Starkent + ESCROW_CONTRACT_ADDRESS = Address of the Starknet smart contract, this value is automatically updated after deploy.sh is run ``` -2. Declare and Deploy: We sequentially declare and deploy the contracts. +2. Declare and Deploy: We sequentially declare and deploy the contracts, and connect it to our Ethereum smart contract. + + ```bash + make starknet-deploy-and-connect + ``` + + + +### ALternative to make starknet-deploy-and-connect + +1. Declare and Deploy: We sequentially declare and deploy the contracts. ```bash make starknet-deploy ``` -### Finalize connection between both chains + This script also sets an important .env variable, **ESCROW_CONTRACT_ADDRESS** + +2. Setting _EscrowAddress_ After the Starknet smart contracts are declared and deployed, the variable _EscrowAddress_ from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. To do this, you can use ``` -make ethereum-set-escrow +make ethereum-set-escrow ``` -Also, Ethereum's smart contract has a variable, _EscrowWithdrawSelector_, which is for specifying the _withdraw_ function's name in the Starknet Escrow smart contract. +This script uses the previously set .env variable, **ESCROW_CONTRACT_ADDRESS** + +3. Setting _EscrowWithdrawSelector_ + +Ethereum's smart contract has another variable that must be configured, _EscrowWithdrawSelector_, which is for specifying the _withdraw_ function's name in the Starknet Escrow smart contract. You can set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: ``` -make ethereum-set-withdraw-selector +make ethereum-set-withdraw-selector ``` - **NOTE**: - - In able to get a formated selector name, you can type the function's name (for example, _withdraw_) in https://www.stark-utils.xyz/converter , change the _selector_ row to hex, and copy its value - +This script uses the WITHDRAW_NAME .env variable to automatically generate the selector in the necesary format ## Recap diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 495bb50f..9dc534b6 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -3,7 +3,8 @@ STARKNET_KEYSTORE= SN_RPC_URL= ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix -ESCROW_WITHDRAW_SELECTOR= #in lowercase hexa with the 0x prefix +WITHDRAW_NAME= #must match the exact name of the function that withdraws from the starknet smart contract HERODOTUS_FACTS_REGISTRY= #in lowercase hexa with the 0x prefix MM_ETHEREUM_WALLET= #in lowercase hexa with the 0x prefix NATIVE_TOKEN_ETH_STARKNET= #in lowercase hexa with the 0x prefix +ESCROW_CONTRACT_ADDRESS= #this value is automatically updated after deploy.sh is run diff --git a/contracts/cairo/deploy.sh b/contracts/cairo/deploy.sh index 94609f72..e729abde 100755 --- a/contracts/cairo/deploy.sh +++ b/contracts/cairo/deploy.sh @@ -41,6 +41,4 @@ ESCROW_CONTRACT_ADDRESS=$(starkli deploy \ $NATIVE_TOKEN_ETH_STARKNET) echo -e "- ${PURPLE}[SN] Escrow ContractAddress: $ESCROW_CONTRACT_ADDRESS${COLOR_RESET}" -cd ../.. -contracts/solidity/set_escrow.sh $ESCROW_CONTRACT_ADDRESS -contracts/solidity/set_withdraw_selector.sh $ESCROW_WITHDRAW_SELECTOR +sed -i "s/^ESCROW_CONTRACT_ADDRESS=.*/ESCROW_CONTRACT_ADDRESS=$ESCROW_CONTRACT_ADDRESS/" ".env" || echo "ESCROW_CONTRACT_ADDRESS=$ESCROW_CONTRACT_ADDRESS" >> ".env" \ No newline at end of file diff --git a/contracts/solidity/set_escrow.sh b/contracts/solidity/set_escrow.sh index aed4bcb8..f76f532e 100755 --- a/contracts/solidity/set_escrow.sh +++ b/contracts/solidity/set_escrow.sh @@ -23,7 +23,6 @@ else fi echo "Smart contract being modified:" $ETH_CONTRACT_ADDR -echo "New Escrow address:" $1 +echo "New Escrow address:" $ESCROW_CONTRACT_ADDRESS -cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" $1 -# example param: 0x067393d445cfd2c1f5285d4624708ea0dd61aaf8c6aa99004a561577e490d36f +cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowAddress(uint256)" $ESCROW_CONTRACT_ADDRESS diff --git a/contracts/solidity/set_withdraw_selector.sh b/contracts/solidity/set_withdraw_selector.sh index 40141563..bd4bdfaa 100755 --- a/contracts/solidity/set_withdraw_selector.sh +++ b/contracts/solidity/set_withdraw_selector.sh @@ -20,6 +20,8 @@ COLOR_RESET='\033[0m' echo -e "${GREEN}\n=> [ETH] Setting Starknet Withdraw Selector on ETH Smart Contract${COLOR_RESET}" echo "Smart contract being modified:" $ETH_CONTRACT_ADDR -echo "New Withdraw Selector:" $1 -cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowWithdrawSelector(uint256)" $1 -# example param: 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77 \ No newline at end of file + +WITHDRAW_SELECTOR=$(starkli selector $WITHDRAW_NAME) +echo "New Withdraw Selector: ${WITHDRAW_SELECTOR}" + +cast send --rpc-url $ETH_RPC_URL --private-key $ETH_PRIVATE_KEY $ETH_CONTRACT_ADDR "setEscrowWithdrawSelector(uint256)" "${WITHDRAW_SELECTOR}" From bc1c61fc48726f099746ab6270f570e705db22c8 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Wed, 10 Jan 2024 21:27:02 -0300 Subject: [PATCH 26/38] Add available herodotus addresses in readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index eee16181..86953719 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,12 @@ For this, you will need to: ESCROW_CONTRACT_ADDRESS = Address of the Starknet smart contract, this value is automatically updated after deploy.sh is run ``` + **Note** + - Herodotus Facts Registry: + - Starknet Goerli: 0x031653659964bc969905e1b1c18deb69c65efb2e22ff7f4102044d432c91b82d + - Starknet Sepolia: + - Starknet Mainnet: + 2. Declare and Deploy: We sequentially declare and deploy the contracts, and connect it to our Ethereum smart contract. ```bash From f328d3f374ca3518bc437e7fbf6e2551e296f0ce Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 09:51:57 -0300 Subject: [PATCH 27/38] read snMessagingAddress from .env + un-hardcode snEscrowWithdrawSelector --- README.md | 7 ++++++- contracts/solidity/.env.example | 1 + contracts/solidity/script/Deploy.s.sol | 8 +++----- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 86953719..3a8c927a 100644 --- a/README.md +++ b/README.md @@ -110,11 +110,16 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen ETH_RPC_URL = Infura or Alchemy RPC URL ETH_PRIVATE_KEY = private key of your ETH wallet ETHERSCAN_API_KEY = API Key to use etherscan to read the Ethereum blockchain + SN_MESSAGING_ADDRESS = Starknet Messaging address ``` **NOTE**: - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/creating-an-account). - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). + - Current SN_MESSAGING_ADDRESS values: + - Mainnet 0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4 + - Goerli: 0xde29d060D45901Fb19ED6C6e959EB22d8626708e + - Sepolia: 0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 2. Deploy Solidity contract @@ -164,7 +169,7 @@ For this, you will need to: -### ALternative to make starknet-deploy-and-connect +### Alternative to _make starknet-deploy-and-connect_ 1. Declare and Deploy: We sequentially declare and deploy the contracts. diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index 39355fa5..f5900e67 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,3 +1,4 @@ ETH_RPC_URL= ETH_PRIVATE_KEY= #in lowercase hexa with the 0x prefix ETHERSCAN_API_KEY= +SN_MESSAGING_ADDRESS= diff --git a/contracts/solidity/script/Deploy.s.sol b/contracts/solidity/script/Deploy.s.sol index 672e0272..5005cf52 100644 --- a/contracts/solidity/script/Deploy.s.sol +++ b/contracts/solidity/script/Deploy.s.sol @@ -9,11 +9,9 @@ contract Deploy is Script { uint256 deployerPrivateKey = vm.envUint("ETH_PRIVATE_KEY"); vm.startBroadcast(deployerPrivateKey); - address snMessagingAddress = 0xde29d060D45901Fb19ED6C6e959EB22d8626708e; - uint256 snEscrowAddress = 0x0; - //this is always the same value as long as starknet's function's name is "withdraw" - //this being the case, the function to overwrite this value should be deprecated - uint256 snEscrowWithdrawSelector = 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77; + address snMessagingAddress = vm.envAddress("SN_MESSAGING_ADDRESS"); + uint256 snEscrowAddress = 0x0; //this value is set in a call to the smart contract, once deployed + uint256 snEscrowWithdrawSelector = 0x0; //this value is set in a call to the smart contract, once deployed new YABTransfer( From 39b3c6d21fae0479cf09073297908394c12a931f Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 09:56:56 -0300 Subject: [PATCH 28/38] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3a8c927a..2f6782ba 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/creating-an-account). - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). - Current SN_MESSAGING_ADDRESS values: + - SN_MESSAGING_ADDRESS is for when a L1 contract initiates a message to a L2 contract on Starknet. It does so by calling the sendMessageToL2 function on the Starknet Core Contract with the message parameters. Starknet Core Contracts are the following: - Mainnet 0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4 - Goerli: 0xde29d060D45901Fb19ED6C6e959EB22d8626708e - Sepolia: 0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 From 21a112f0aed729f090d6b5e17ead90b11de5f126 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 10:54:50 -0300 Subject: [PATCH 29/38] add herodotus registry addresses on readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 2f6782ba..127bd795 100644 --- a/README.md +++ b/README.md @@ -158,9 +158,9 @@ For this, you will need to: **Note** - Herodotus Facts Registry: - - Starknet Goerli: 0x031653659964bc969905e1b1c18deb69c65efb2e22ff7f4102044d432c91b82d - - Starknet Sepolia: - - Starknet Mainnet: + - Starknet Goerli: 0x01b2111317EB693c3EE46633edd45A4876db14A3a53ACDBf4E5166976d8e869d + - Starknet Sepolia: 0x07d3550237ecf2d6ddef9b78e59b38647ee511467fe000ce276f245a006b40bc + - Starknet Mainnet: 0x014bf62fadb41d8f899bb5afeeb2da486fcfd8431852def56c5f10e45ae72765 2. Declare and Deploy: We sequentially declare and deploy the contracts, and connect it to our Ethereum smart contract. From 7a4df41775f9da23417d59ad9b29b68d1d17db0b Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 11:30:45 -0300 Subject: [PATCH 30/38] add keystore abs path clarification --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 127bd795..dbe1987b 100644 --- a/README.md +++ b/README.md @@ -144,8 +144,8 @@ For this, you will need to: 1. Create your `.env` file: you need to configure the following variables in your own .env file on the contracts/solidity folder. You can use the env.example file as a template for creating your .env file, paying special attention to the formats provided ```bash - STARKNET_ACCOUNT = location of your starknet testnet account, created at the start of this README - STARKNET_KEYSTORE = location of your starknet testnet keystore, created at the start of this README + STARKNET_ACCOUNT = Absolute path of your starknet testnet account, created at the start of this README + STARKNET_KEYSTORE = Absolute path of your starknet testnet keystore, created at the start of this README SN_RPC_URL = Infura or Alchemy RPC URL ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker From dae17645412bcb119ad006c05d8adcdc484917f8 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:27:43 -0300 Subject: [PATCH 31/38] update readme --- Makefile | 3 --- README.md | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 41009482..92019ee1 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,3 @@ starknet-deploy-and-connect: starknet-build @$(MAKE) starknet-deploy @$(MAKE) ethereum-set-escrow @$(MAKE) ethereum-set-withdraw-selector - - - \ No newline at end of file diff --git a/README.md b/README.md index dbe1987b..12b1901f 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ For this, you will need to: HERODOTUS_FACTS_REGISTRY = Herodotus' Facts Registry Smart Contract in Starknet MM_ETHEREUM_WALLET = Ethereum wallet of the MArketMaker NATIVE_TOKEN_ETH_STARKNET = Ethereum's erc20 token handler contract in Starkent - ESCROW_CONTRACT_ADDRESS = Address of the Starknet smart contract, this value is automatically updated after deploy.sh is run + ESCROW_CONTRACT_ADDRESS = Address of the Starknet smart contract, this value should be empty, and is automatically updated after deploy.sh is run ``` **Note** From 885db85121b9b988f2a332445a19a826c11b90a0 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:33:07 -0300 Subject: [PATCH 32/38] fix ETH_CONTRACT_ADDR format in env.example --- contracts/cairo/.env.example | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 9dc534b6..0a565076 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -1,7 +1,7 @@ STARKNET_ACCOUNT= STARKNET_KEYSTORE= SN_RPC_URL= -ETH_CONTRACT_ADDR= #in lowercase hexa with the 0x prefix +ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, with upper and lower cases like shown by etherscan MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix WITHDRAW_NAME= #must match the exact name of the function that withdraws from the starknet smart contract HERODOTUS_FACTS_REGISTRY= #in lowercase hexa with the 0x prefix From 39907089bd03078bf0c9e86116afb6b822c1a0a1 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:34:45 -0300 Subject: [PATCH 33/38] add clarification in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 12b1901f..553ccb02 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ For this, you will need to: SN_RPC_URL = Infura or Alchemy RPC URL ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker - WITHDRAW_NAME = The exact name of the function that withdraws from the starknet smart contract + WITHDRAW_NAME = The exact name of the function that withdraws from the starknet smart contract, case sensitive HERODOTUS_FACTS_REGISTRY = Herodotus' Facts Registry Smart Contract in Starknet MM_ETHEREUM_WALLET = Ethereum wallet of the MArketMaker NATIVE_TOKEN_ETH_STARKNET = Ethereum's erc20 token handler contract in Starkent From b54a9b39e237858ba65a734b6cf9c104e2cd8c63 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:36:07 -0300 Subject: [PATCH 34/38] update readme address format --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 553ccb02..54e7427a 100644 --- a/README.md +++ b/README.md @@ -118,9 +118,9 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). - Current SN_MESSAGING_ADDRESS values: - SN_MESSAGING_ADDRESS is for when a L1 contract initiates a message to a L2 contract on Starknet. It does so by calling the sendMessageToL2 function on the Starknet Core Contract with the message parameters. Starknet Core Contracts are the following: - - Mainnet 0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4 - - Goerli: 0xde29d060D45901Fb19ED6C6e959EB22d8626708e - - Sepolia: 0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 + - Mainnet: `0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4` + - Goerli: `0xde29d060D45901Fb19ED6C6e959EB22d8626708e` + - Sepolia: `0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057` 2. Deploy Solidity contract @@ -158,9 +158,9 @@ For this, you will need to: **Note** - Herodotus Facts Registry: - - Starknet Goerli: 0x01b2111317EB693c3EE46633edd45A4876db14A3a53ACDBf4E5166976d8e869d - - Starknet Sepolia: 0x07d3550237ecf2d6ddef9b78e59b38647ee511467fe000ce276f245a006b40bc - - Starknet Mainnet: 0x014bf62fadb41d8f899bb5afeeb2da486fcfd8431852def56c5f10e45ae72765 + - Starknet Goerli: `0x01b2111317EB693c3EE46633edd45A4876db14A3a53ACDBf4E5166976d8e869d` + - Starknet Sepolia: `0x07d3550237ecf2d6ddef9b78e59b38647ee511467fe000ce276f245a006b40bc` + - Starknet Mainnet: `0x014bf62fadb41d8f899bb5afeeb2da486fcfd8431852def56c5f10e45ae72765` 2. Declare and Deploy: We sequentially declare and deploy the contracts, and connect it to our Ethereum smart contract. From f59a3e65817104b0095fd8fba4aa60d5ad64d385 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:43:40 -0300 Subject: [PATCH 35/38] add possible values in env.example --- README.md | 2 +- contracts/cairo/.env.example | 2 +- contracts/solidity/.env.example | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 54e7427a..109c2fd3 100644 --- a/README.md +++ b/README.md @@ -118,9 +118,9 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen - For the deploy, you will need some GoerliETH that you can get from this [faucet](https://goerlifaucet.com/). - Current SN_MESSAGING_ADDRESS values: - SN_MESSAGING_ADDRESS is for when a L1 contract initiates a message to a L2 contract on Starknet. It does so by calling the sendMessageToL2 function on the Starknet Core Contract with the message parameters. Starknet Core Contracts are the following: - - Mainnet: `0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4` - Goerli: `0xde29d060D45901Fb19ED6C6e959EB22d8626708e` - Sepolia: `0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057` + - Mainnet: `0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4` 2. Deploy Solidity contract diff --git a/contracts/cairo/.env.example b/contracts/cairo/.env.example index 0a565076..34bfcff6 100644 --- a/contracts/cairo/.env.example +++ b/contracts/cairo/.env.example @@ -4,7 +4,7 @@ SN_RPC_URL= ETH_CONTRACT_ADDR= #in hexa with the 0x prefix, with upper and lower cases like shown by etherscan MM_SN_WALLET_ADDR= #in lowercase hexa with the 0x prefix WITHDRAW_NAME= #must match the exact name of the function that withdraws from the starknet smart contract -HERODOTUS_FACTS_REGISTRY= #in lowercase hexa with the 0x prefix +HERODOTUS_FACTS_REGISTRY=<0x01b2111317EB693c3EE46633edd45A4876db14A3a53ACDBf4E5166976d8e869d|0x07d3550237ecf2d6ddef9b78e59b38647ee511467fe000ce276f245a006b40bc|0x014bf62fadb41d8f899bb5afeeb2da486fcfd8431852def56c5f10e45ae72765> # Goerli | Sepolia | Mainnet MM_ETHEREUM_WALLET= #in lowercase hexa with the 0x prefix NATIVE_TOKEN_ETH_STARKNET= #in lowercase hexa with the 0x prefix ESCROW_CONTRACT_ADDRESS= #this value is automatically updated after deploy.sh is run diff --git a/contracts/solidity/.env.example b/contracts/solidity/.env.example index f5900e67..ea79dc80 100644 --- a/contracts/solidity/.env.example +++ b/contracts/solidity/.env.example @@ -1,4 +1,4 @@ ETH_RPC_URL= ETH_PRIVATE_KEY= #in lowercase hexa with the 0x prefix ETHERSCAN_API_KEY= -SN_MESSAGING_ADDRESS= +SN_MESSAGING_ADDRESS=<0xde29d060D45901Fb19ED6C6e959EB22d8626708e|0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057|0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4> # Goerli | Sepolia | Mainnet From 2bbbdfd5827b33ae4469dae8a86b24dfec324c1a Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 12:47:23 -0300 Subject: [PATCH 36/38] clarify WITHDRAW_NAME in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 109c2fd3..4bcb138b 100644 --- a/README.md +++ b/README.md @@ -143,13 +143,13 @@ For this, you will need to: 1. Create your `.env` file: you need to configure the following variables in your own .env file on the contracts/solidity folder. You can use the env.example file as a template for creating your .env file, paying special attention to the formats provided - ```bash + ``` STARKNET_ACCOUNT = Absolute path of your starknet testnet account, created at the start of this README STARKNET_KEYSTORE = Absolute path of your starknet testnet keystore, created at the start of this README SN_RPC_URL = Infura or Alchemy RPC URL ETH_CONTRACT_ADDR = newly created ETH contract address MM_SN_WALLET_ADDR = Starknet wallet of the MarketMaker - WITHDRAW_NAME = The exact name of the function that withdraws from the starknet smart contract, case sensitive + WITHDRAW_NAME = The exact name of the withdraw function that is called from L1, case sensitive. Example: withdraw_fallback HERODOTUS_FACTS_REGISTRY = Herodotus' Facts Registry Smart Contract in Starknet MM_ETHEREUM_WALLET = Ethereum wallet of the MArketMaker NATIVE_TOKEN_ETH_STARKNET = Ethereum's erc20 token handler contract in Starkent From 8656c2091e4f2a639c0043cab9db07d160172058 Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 13:56:54 -0300 Subject: [PATCH 37/38] final details on readme.md --- README.md | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4bcb138b..33a75e79 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ```bash export STARKNET_RPC="" ``` + 2. **Create a Keystore**: A Keystore is a encrypted `json` file that stores the private keys. @@ -57,6 +58,7 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ```bash mkdir -p ~/.starkli-wallets ``` + 2. **Generate a new Keystore file**: Run the following command to create a new private key stored in the file. It will **ask for a password** to encrypt the file: @@ -72,6 +74,7 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ```bash export STARKNET_KEYSTORE="~/.starkli-wallets/keystore.json" ``` + 3. **Account Creation**: In Starknet every account is a smart contract, so to create one it will need to be deployed. @@ -80,6 +83,7 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ```bash starkli account oz init --keystore ~/.starkli-wallets/keystore.json ~/.starkli-wallets/account.json ``` + 2. **Deploy the account by running**: ```bash @@ -102,6 +106,7 @@ Follow the steps below to set up a testnet smart wallet using `starkli`: ## Declare and Deploy Contracts in Testnet ### Ethereum smart contract + First, the Ethereum smart contracts must be deployed. For Ethereum the deployment process you will need to: 1. Create your `.env` file: you need to configure the following variables in your own .env file on the contracts/solidity/ folder. You can use the env.example file as a template for creating your .env file, paying special attention to the formats provided @@ -112,6 +117,7 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen ETHERSCAN_API_KEY = API Key to use etherscan to read the Ethereum blockchain SN_MESSAGING_ADDRESS = Starknet Messaging address ``` + **NOTE**: - You can generate ETHERSCAN_API_KEY [following this steps](https://docs.etherscan.io/getting-started/creating-an-account). @@ -119,10 +125,9 @@ First, the Ethereum smart contracts must be deployed. For Ethereum the deploymen - Current SN_MESSAGING_ADDRESS values: - SN_MESSAGING_ADDRESS is for when a L1 contract initiates a message to a L2 contract on Starknet. It does so by calling the sendMessageToL2 function on the Starknet Core Contract with the message parameters. Starknet Core Contracts are the following: - Goerli: `0xde29d060D45901Fb19ED6C6e959EB22d8626708e` - - Sepolia: `0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057` + - Sepolia: `0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057` - Mainnet: `0xc662c410C0ECf747543f5bA90660f6ABeBD9C8c4` - 2. Deploy Solidity contract ```bash @@ -164,13 +169,22 @@ For this, you will need to: 2. Declare and Deploy: We sequentially declare and deploy the contracts, and connect it to our Ethereum smart contract. +### First alternative: automatic deploy and connect of Escrow and YABTransfer. + ```bash make starknet-deploy-and-connect ``` + This make target consists of 4 steps: + 1. make starknet-build; builds the project + 2. make starknet-deploy; deploys the smart contract on the blockchain + 3. make ethereum-set-escrow; sets the newly created Starknet contract address on the Ethereum smart contract, so that the L1 contract can communicate with the L2 contract + 4. make ethereum-set-withdraw-selector; sets the Starknet _withdraw_ function name on the Ethereum smart contract, so that the L1 contract can communicate with the L2 contract -### Alternative to _make starknet-deploy-and-connect_ +### Second alternative: manual deploy and connect of Escrow and YABTransfer + +This may be better suited for you if you plan to change some of the automatically declared .env vars, or if you simply want to make sure you understand the process. 1. Declare and Deploy: We sequentially declare and deploy the contracts. @@ -182,24 +196,27 @@ For this, you will need to: 2. Setting _EscrowAddress_ -After the Starknet smart contracts are declared and deployed, the variable _EscrowAddress_ from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. + After the Starknet smart contracts are declared and deployed, the variable _EscrowAddress_ from the Ethereum smart contract must be updated with the newly created Starknet smart contract address. -To do this, you can use -``` -make ethereum-set-escrow -``` + To do this, you can use -This script uses the previously set .env variable, **ESCROW_CONTRACT_ADDRESS** + ``` + make ethereum-set-escrow + ``` -3. Setting _EscrowWithdrawSelector_ + This script uses the previously set .env variable, **ESCROW_CONTRACT_ADDRESS** -Ethereum's smart contract has another variable that must be configured, _EscrowWithdrawSelector_, which is for specifying the _withdraw_ function's name in the Starknet Escrow smart contract. -You can set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: -``` -make ethereum-set-withdraw-selector -``` -This script uses the WITHDRAW_NAME .env variable to automatically generate the selector in the necesary format +3. Setting _EscrowWithdrawSelector_ + Ethereum's smart contract has another variable that must be configured, _EscrowWithdrawSelector_, which is for specifying the _withdraw_ function's name in the Starknet Escrow smart contract. + You can set and change Ethereum's _EscrowWithdrawSelector_ variable, doing the following: + + ``` + make ethereum-set-withdraw-selector + ``` + + This script uses the WITHDRAW_NAME .env variable to automatically generate the selector in the necesary format ## Recap + After following this complete README, we should have an ETH smart contract as well as a Starknet smart contract, both connected to act as a bridge between these two chains. From 80ba11bb13ce71476840c693d7f3440b37c2a5ca Mon Sep 17 00:00:00 2001 From: Uriel Mihura Date: Thu, 11 Jan 2024 14:22:04 -0300 Subject: [PATCH 38/38] eof in .gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3bf780b6..de03f380 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ .idea -.env \ No newline at end of file +.env