Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #57 .Env + Readme fixes #58

Merged
merged 39 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
34fac42
various fixes
uri-99 Jan 5, 2024
0b9180a
rewrite .env.exampole formats
Jan 8, 2024
4019988
fix .env lowercase
Jan 8, 2024
359523b
add foundry usage to write the starknet address to eth contract
Jan 8, 2024
489a32d
fix ENVIRONMENT var in .env.example
Jan 8, 2024
daab42a
Merge branch 'main' into 57-fix-envs
Jan 8, 2024
cd1e8e2
revert mm.env.example
Jan 8, 2024
29b1a14
fix .env comment format
Jan 8, 2024
113a307
revert env import fix
Jan 8, 2024
bda0538
set-escrow in makefile
Jan 9, 2024
0dff589
improve make and .sh of post-deploy functions
Jan 9, 2024
d8d82ba
update readme with new make functions
Jan 9, 2024
e544c87
fix .env comments
Jan 9, 2024
0912eda
fix .env comments
Jan 9, 2024
7503efc
Update contracts/cairo/.env.example
uri-99 Jan 9, 2024
929d330
Update README.md
uri-99 Jan 9, 2024
871c654
remove unnesecary print
Jan 9, 2024
edb8cd6
run set escrow after cairo deploy
Jan 10, 2024
49cfcbf
Update contracts/cairo/.env.example
uri-99 Jan 10, 2024
d6e2554
clarify how to get withdraw-selector value
Jan 10, 2024
c75577a
NTH print
Jan 10, 2024
3418b9f
set-withdraw-selector executes automatically in cairo/deploy.sh
Jan 10, 2024
8f67e10
format
Jan 10, 2024
b8a69f8
ignore comments fix in .env import
Jan 10, 2024
2436a58
added env vars, removed them from deploy.sh
Jan 10, 2024
32abb05
created make starknet-deploy-and-connect
Jan 10, 2024
bc1c61f
Add available herodotus addresses in readme
Jan 11, 2024
f328d3f
read snMessagingAddress from .env
Jan 11, 2024
39b3c6d
update readme
Jan 11, 2024
21a112f
add herodotus registry addresses on readme
Jan 11, 2024
7a4df41
add keystore abs path clarification
Jan 11, 2024
dae1764
update readme
Jan 11, 2024
885db85
fix ETH_CONTRACT_ADDR format in env.example
Jan 11, 2024
3990708
add clarification in readme
Jan 11, 2024
b54a9b3
update readme address format
Jan 11, 2024
f59a3e6
add possible values in env.example
Jan 11, 2024
2bbbdfd
clarify WITHDRAW_NAME in readme
Jan 11, 2024
8656c20
final details on readme.md
Jan 11, 2024
80ba11b
eof in .gitignore
Jan 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
.env
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,35 @@ 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 nedded"
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
@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
uri-99 marked this conversation as resolved.
Show resolved Hide resolved


starknet-clean:
@cd ./contracts/cairo/ && scarb clean

Expand Down
74 changes: 51 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,47 +101,75 @@ 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
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved

```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/creating-an-account).
- 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
network
- 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:

uri-99 marked this conversation as resolved.
Show resolved Hide resolved
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=<STARKNET_RPC_HTTPS_URL> // Infura or Alchemy RPC URL
ETH_CONTRACT_ADDR=0xdd69db25f6d620a7bad3023c5d32761d353d3de9 // GoerliETH
SN_CONTRACT_ADDR=<STARKNET_MM_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, the variable _EscrowAddress_ 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=<ETH_RPC_URL> // Infura or Alchemy RPC URL
ETH_PRIVATE_KEY=<ETH_PRIVATE_KEY>
ETHERSCAN_API_KEY=<ETHERSCAN_API_KEY>
..
```
To do this, you can use
```
make ethereum-set-escrow <new_escrow_address>
```

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 <new_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

rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
- 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

```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.
5 changes: 5 additions & 0 deletions contracts/cairo/.env.example
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
STARKNET_ACCOUNT=<starkli_account_path>
STARKNET_KEYSTORE=<starkli_keystore_path>
SN_RPC_URL=<starknet_rpc_url>
ETH_CONTRACT_ADDR=<ethereum_contract_address> #in lowercase hexa with the 0x prefix
JuArce marked this conversation as resolved.
Show resolved Hide resolved
MM_SN_WALLET_ADDR=<marketmaker_starknet_contract_address> #in lowercase hexa with the 0x prefix
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 15 additions & 6 deletions contracts/cairo/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,37 @@ cd "$(dirname "$0")"
load_env() {
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export $(grep -v '^#' ../../mm-bot/.env | xargs -d '\n')
export $(grep -v '^#' .env | xargs -d '\n')
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export $(grep -v '^#' ../../mm-bot/.env | xargs -0)
export $(grep -v '^#' .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)
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}"

cd ../..
contracts/solidity/set_escrow.sh $ESCROW_CONTRACT_ADDRESS


6 changes: 3 additions & 3 deletions contracts/solidity/.env.example
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
GOERLI_RPC_URL=
PRIVATE_KEY=
ETHERSCAN_API_KEY=
ETH_RPC_URL=<ethereum_rpc_url>
ETH_PRIVATE_KEY=<eth_private_key> #in lowercase hexa with the 0x prefix
ETHERSCAN_API_KEY=<etherscan_api_key>
6 changes: 3 additions & 3 deletions contracts/solidity/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ cd "$(dirname "$0")"
load_env() {
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export $(grep -v '^#' ./.env | xargs -d '\n')
export $(grep -v '^#' .env | xargs -d '\n')
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export $(grep -v '^#' ./.env | xargs -0)
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
forge script ./script/Deploy.s.sol --fork-url $ETH_RPC_URL --broadcast --verify -vvvv
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 4 additions & 1 deletion contracts/solidity/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions contracts/solidity/set_escrow.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/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
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
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
fi
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved

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
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
27 changes: 27 additions & 0 deletions contracts/solidity/set_withdraw_selector.sh
uri-99 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -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!"
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved

# 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
2 changes: 1 addition & 1 deletion contracts/solidity/test/Transfer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract TransferTest is Test {
function setUp() public {
address snMessagingAddress = 0xde29d060D45901Fb19ED6C6e959EB22d8626708e;
uint256 snEscrowAddress = 0x0;
uint256 snEscrowWithdrawSelector = 0x0;
uint256 snEscrowWithdrawSelector = 0x15511cc3694f64379908437d6d64458dc76d02482052bfb8a5b33a72c054c77;
rcatalan98 marked this conversation as resolved.
Show resolved Hide resolved
yab = new YABTransfer(snMessagingAddress, snEscrowAddress, snEscrowWithdrawSelector);
}

Expand Down