-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add Bridge example #36
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "examples/bridge/l1/lib/forge-std"] | ||
path = examples/bridge/l1/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "examples/bridge/l1/lib/create3-factory"] | ||
path = examples/bridge/l1/lib/create3-factory | ||
url = https://github.com/zeframlou/create3-factory |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
in /l1 & /sn Makefile, import the right .env | ||
use `make` without argument to check current env vars | ||
|
||
## L1 | ||
|
||
- set STARKNET_ADDRESS (for goerli & mainnet) | ||
- set TOKEN_ADDRESS (for mainnet) | ||
- Pre-compute L1DojoBridge address with create3 | ||
|
||
## Starknet | ||
|
||
- set L1_BRIDGE_ADDRESS in sn/ .env | ||
- Deploy contracts | ||
- Set auth | ||
- Initialize contracts | ||
|
||
## L1 | ||
|
||
- set L2_BRIDGE_ADDRESS in l1/ .env | ||
- Deploy L1DojoBridge | ||
|
||
|
||
|
||
## Constructor / initiliazers | ||
|
||
### L1 | ||
L1DojoBridge constructor : | ||
|
||
`constructor(address _starknet, address _l1Token, uint256 _l2Bridge)` | ||
|
||
### SN | ||
|
||
dojo_bridge initializer : | ||
|
||
`fn initializer(ref self: ContractState, l1_bridge: felt252, l2_token: ContractAddress)` | ||
|
||
dojo_token initializer : | ||
|
||
`fn initializer(ref self: ContractState, name: felt252, symbol: felt252, l2_bridge_address: ContractAddress)` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
For local use | ||
Make sure both Makefiles use .env.local | ||
You can just use `make` without argument to check current env vars | ||
|
||
# ETH | ||
|
||
### Terminal 1 | ||
|
||
Launch anvil | ||
|
||
```sh | ||
cd l1 | ||
make anvil | ||
``` | ||
|
||
### Terminal 2 | ||
|
||
Deploy create3 contract for deterministic contract address | ||
```sh | ||
cd l1 | ||
make create3 | ||
``` | ||
|
||
Deploy eth $TOKEN & L1DojoBridge | ||
```sh | ||
make deploy | ||
``` | ||
|
||
# Starknet | ||
|
||
### Terminal 1 | ||
|
||
Launch katana with messaging | ||
|
||
```sh | ||
cd sn | ||
make katana_msg | ||
# or | ||
katana --messaging anvil.messaging.json | ||
``` | ||
|
||
### Terminal 2 | ||
|
||
Migrate & initialize contracts | ||
```sh | ||
cd sn | ||
make migrate_and_init | ||
# or | ||
make migrate | ||
make initialize | ||
``` | ||
|
||
Fund an address in ETH | ||
```sh | ||
./scripts/fund.sh 0x1234 | ||
``` | ||
|
||
# Bridging | ||
|
||
## from ETH to Starknet | ||
|
||
it mint tokens & approve bridge & call deposit on ETH bridge | ||
```sh | ||
make deposit | ||
``` | ||
|
||
## from Starknet to ETH | ||
|
||
get balance on Starknet | ||
```sh | ||
scarb run get_balance | ||
``` | ||
|
||
withdraw from Starknet to ETH | ||
```sh | ||
scarb run withdraw | ||
``` | ||
|
||
## after | ||
|
||
withdraw tokens from ETH bridge | ||
```sh | ||
make withdraw | ||
``` | ||
|
||
check token balance on ETH | ||
```sh | ||
make get_balance | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## DOJO BRIDGE | ||
|
||
Adaptation of https://github.com/BibliothecaDAO/Starknet-ERC20-bridge & https://github.com/glihm/starknet-messaging-dev for Dojo. | ||
|
||
|
||
## Requirements | ||
|
||
Please before starting, install: | ||
|
||
- [scarb](https://docs.swmansion.com/scarb/) to build cairo contracts. | ||
- [starkli](https://github.com/xJonathanLEI/starkli) to interact with Katana. | ||
- [foundry](https://book.getfoundry.sh/getting-started/installation) to interact with Anvil. | ||
- git submodules forge-std & create3-factory. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
ENV=local | ||
|
||
ETH_RPC_URL=http://127.0.0.1:8545 | ||
|
||
ACCOUNT_PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 | ||
ACCOUNT_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 | ||
|
||
# local | ||
CREATE3_FACTORY_ADDRESS=0x5FbDB2315678afecb367f032d93F642f64180aa3 | ||
STARKNET_ADDRESS=0x0000000000000000000000000000000000000000 | ||
TOKEN_ADDRESS=0x0000000000000000000000000000000000000000 | ||
|
||
L2_BRIDGE_ADDRESS=0x2ff2f9994ba7e039f50190cb3b3dc538d9abf7201acbe5a6a7aff686dd40d89 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Dotenv file | ||
.env | ||
|
||
# Compiler files | ||
cache/ | ||
out/ | ||
broadcast/ | ||
|
||
|
||
lib/forge-std | ||
|
||
/logs | ||
|
||
.gas-snapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
include .env.local | ||
|
||
export | ||
|
||
PARAMS := --broadcast --rpc-url ${ETH_RPC_URL} -v | ||
|
||
all: | ||
@echo "********************************************************************" | ||
@echo "ENV : ${ENV}" | ||
@echo "********************************************************************" | ||
@echo "ETH_RPC_URL : ${ETH_RPC_URL}" | ||
@echo "ACCOUNT_ADDRESS : ${ACCOUNT_ADDRESS}" | ||
@echo "CREATE3_FACTORY_ADDRESS : ${CREATE3_FACTORY_ADDRESS}" | ||
@echo "STARKNET_ADDRESS : ${STARKNET_ADDRESS}" | ||
@echo "TOKEN_ADDRESSS : ${TOKEN_ADDRESSS}" | ||
@echo "L2_BRIDGE_ADDRESS : ${L2_BRIDGE_ADDRESS}" | ||
@echo "********************************************************************" | ||
|
||
anvil: | ||
anvil --chain-id 1337 | ||
|
||
anvil_slow: | ||
anvil --chain-id 1337 --block-time 10 | ||
|
||
create3: | ||
forge script ./script/Deploy.s.sol:Create3 ${PARAMS} | ||
|
||
get_bridge_address: | ||
forge script ./script/Deploy.s.sol:GetBridgeAddress ${PARAMS} | ||
|
||
deploy: | ||
forge script ./script/Deploy.s.sol:Deploy ${PARAMS} | ||
|
||
deposit: | ||
forge script ./script/Calls.s.sol:Deposit ${PARAMS} | ||
|
||
withdraw: | ||
forge script ./script/Calls.s.sol:Withdraw ${PARAMS} | ||
|
||
get_balance: | ||
forge script ./script/Calls.s.sol:GetBalance ${PARAMS} | ||
|
||
mint_token: | ||
forge script ./script/Calls.s.sol:MintToken ${PARAMS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[profile.default] | ||
solc-version = "0.8.13" | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
fs_permissions = [{ access = "read-write", path = "./logs"}] | ||
remappings = [ | ||
"@forge-std/=lib/forge-std/src/", | ||
"@create3-factory/=lib/create3-factory/src/", | ||
"@openzeppelin/=lib/@openzeppelin/", | ||
"@starknet/=lib/starknet/", | ||
] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options | ||
|
||
|
||
# since the foundry.toml is commited it's not recommened to have the api key explicitly | ||
# [rpc_endpoints] | ||
# local = "${ETH_RPC_URL}" | ||
|
71 changes: 71 additions & 0 deletions
71
examples/bridge/l1/lib/@openzeppelin/contracts/access/Ownable.sol
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should use submodules and no embed these |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "../utils/Context.sol"; | ||
|
||
/** | ||
* @dev Contract module which provides a basic access control mechanism, where | ||
* there is an account (an owner) that can be granted exclusive access to | ||
* specific functions. | ||
* | ||
* By default, the owner account will be the one that deploys the contract. This | ||
* can later be changed with {transferOwnership}. | ||
* | ||
* This module is used through inheritance. It will make available the modifier | ||
* `onlyOwner`, which can be applied to your functions to restrict their use to | ||
* the owner. | ||
*/ | ||
abstract contract Ownable is Context { | ||
address private _owner; | ||
|
||
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); | ||
|
||
/** | ||
* @dev Initializes the contract setting the deployer as the initial owner. | ||
*/ | ||
constructor() { | ||
_setOwner(_msgSender()); | ||
} | ||
|
||
/** | ||
* @dev Returns the address of the current owner. | ||
*/ | ||
function owner() public view virtual returns (address) { | ||
return _owner; | ||
} | ||
|
||
/** | ||
* @dev Throws if called by any account other than the owner. | ||
*/ | ||
modifier onlyOwner() { | ||
require(owner() == _msgSender(), "Ownable: caller is not the owner"); | ||
_; | ||
} | ||
|
||
/** | ||
* @dev Leaves the contract without owner. It will not be possible to call | ||
* `onlyOwner` functions anymore. Can only be called by the current owner. | ||
* | ||
* NOTE: Renouncing ownership will leave the contract without an owner, | ||
* thereby removing any functionality that is only available to the owner. | ||
*/ | ||
function renounceOwnership() public virtual onlyOwner { | ||
_setOwner(address(0)); | ||
} | ||
|
||
/** | ||
* @dev Transfers ownership of the contract to a new account (`newOwner`). | ||
* Can only be called by the current owner. | ||
*/ | ||
function transferOwnership(address newOwner) public virtual onlyOwner { | ||
require(newOwner != address(0), "Ownable: new owner is the zero address"); | ||
_setOwner(newOwner); | ||
} | ||
|
||
function _setOwner(address newOwner) private { | ||
address oldOwner = _owner; | ||
_owner = newOwner; | ||
emit OwnershipTransferred(oldOwner, newOwner); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.