Skip to content

Commit 8d93ef7

Browse files
authored
Merge pull request #19 from BibliothecaDAO/legacy-claim
add legacy reward claim contracts
2 parents f061130 + 05e2bd3 commit 8d93ef7

File tree

727 files changed

+136376
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

727 files changed

+136376
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Legacy Claim Contracts Workflow
2+
3+
on:
4+
push:
5+
branches: [main, dev]
6+
paths:
7+
- "legacyClaim/**"
8+
pull_request:
9+
branches: [main, dev]
10+
workflow_dispatch:
11+
12+
env:
13+
SCARB_VERSION: v0.6.0
14+
15+
jobs:
16+
test-starknet-contracts:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v3
20+
- uses: software-mansion/setup-scarb@v1
21+
with:
22+
tool-versions: legacyClaim/starknet/.tool-versions
23+
- uses: foundry-rs/setup-snfoundry@v3
24+
with:
25+
tool-versions: legacyClaim/starknet/.tool-versions
26+
- run: scarb build
27+
working-directory: legacyClaim/starknet
28+
- run: snforge test
29+
working-directory: legacyClaim/starknet
30+
31+
32+
test-ethereum-contracts:
33+
strategy:
34+
fail-fast: true
35+
36+
name: Foundry testing
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- uses: actions/checkout@v3
41+
with:
42+
submodules: recursive
43+
44+
- name: Install Foundry
45+
uses: foundry-rs/foundry-toolchain@v1
46+
with:
47+
version: nightly
48+
49+
- name: Run Forge build
50+
run: |
51+
forge --version
52+
forge build --sizes --root legacyClaim/ethereum/
53+
id: build
54+
55+
- name: Run Forge tests
56+
run: |
57+
forge test -vvv --root legacyClaim/ethereum/
58+
id: test
59+

legacyClaim/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules
2+
.env
3+
coverage
4+
coverage.json
5+
typechain
6+
typechain-types
7+
temp
8+
9+
#Hardhat files
10+
cache
11+
artifacts
12+
13+
deployments
14+
contracts/**/target/**/*

legacyClaim/deploy.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
cd starknet && \
4+
scarb --release build && \
5+
cd scripts/deployment && \
6+
node deployStageOne && \
7+
cp -r ./addresses/ ../../../ethereum/logs/ && \
8+
cd ../../../ethereum && \
9+
forge build && \
10+
make bridge_l1_deploy && \
11+
cp -r ./logs/ ../starknet/scripts/deployment/addresses/ && \
12+
cd ../starknet/scripts/deployment && \
13+
node deployStageTwo

legacyClaim/ethereum/.env.testnet

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# General config.
2+
ETH_RPC_URL=https://sepolia.infura.io/v3/abc
3+
ETHERSCAN_API_KEY=abc
4+
5+
6+
LOCAL_LOGS=logs/dev/ #change to "prod" in production
7+
8+
# Account related variables (EOA account).
9+
DEPLOYMENT_ACCOUNT_ADDRESS=0x0000000000000000000000000000000000000001
10+
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=0x0
11+
12+
BRIDGE_L1_OWNER_ADDRESS=0x00000000000000000000000000000000000000002
13+
BRIDGE_L1_TOKEN_ADDRESS=0x0A642270Cc73B2FC1605307F853712F944394564 #l1 realms
14+
15+
16+
# Bridge L2 variables.
17+
BRIDGE_L2_SELECTOR=0x03593216f3a8b22f4cf375e5486e3d13bfde9d0f26976d20ac6f653c73f7e507
18+
19+
# Starknet Core
20+
STARKNET_CORE_L1_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 #sepolia
21+
22+
# UNNECESSARY: TB REMOVED
23+
BRIDGE_L1_PROXY_ADDRESS=0x0000000000000000000000000000000000000000
24+
25+
26+
# forge verify-contract 0x47fee0f901Ad3aa5B980ccBF762F1160aCa593b8 Bridge --verifier etherscan --guess-constructor-args

legacyClaim/ethereum/.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores all broadcasts
6+
broadcast/
7+
#/broadcast/*/31337/
8+
#/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
14+
# Dotenv file
15+
**/*.env.*
16+
**/*.env.sepolia
17+
18+
# Local logs folder
19+
logs/

legacyClaim/ethereum/Makefile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Only .env file is loaded by foundry, and we can't specify a file.
2+
# TODO: need a better way to force config arg is given...!
3+
# CLEAN_CONFIG:=$(shell rm .env)
4+
# COPY_CONFIG:=$(shell cp $(config) .env)
5+
6+
include .env
7+
export $(shell sed 's/=.*//' .env)
8+
9+
bold := $(shell tput bold)
10+
sgr0 := $(shell tput sgr0)
11+
12+
# TODO: for upgrades, check how to force proxy arg.
13+
14+
# Bridge deploy impl + proxy.
15+
bridge_l1_deploy:
16+
forge script --broadcast --rpc-url ${ETH_RPC_URL} script/Bridge.s.sol:Deploy -vvvvvvvv
17+
18+
bridge_claim:
19+
forge script --broadcast --rpc-url ${ETH_RPC_URL} script/Bridge.s.sol:ClaimOnStarknet

legacyClaim/ethereum/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# NFT Bridge: Ethererum.
2+
3+
This project implements a bridge for transferring ERC721 tokens between Ethereum (L1) and Starknet (L2). The main component is the `Bridge.sol` contract, which handles the deposit and withdrawal of tokens between the two layers from Ethereum.
4+
5+
### Key Features
6+
7+
1. **Token Deposit**: Users can deposit ERC721 tokens from L1 to L2 using the `depositTokens` function.
8+
2. **Token Withdrawal**: Users can withdraw tokens received from L2 using the `withdrawTokens` function.
9+
3. **Request Cancellation**: Users can initiate and complete cancellation of bridge requests using `startRequestCancellation` and `cancelRequest` functions.
10+
11+
### Main Functions
12+
13+
#### `initialize`
14+
Initializes the bridge contract with necessary parameters like the bridge owner address, L1 token(nft) address, Starknet core address, L2 bridge address (on starknet), and L2 bridge selector (on starknet).
15+
16+
#### `depositTokens`
17+
Deposits tokens into escrow and initiates the transfer to Starknet. It requires:
18+
- A salt for generating the request hash
19+
- The new owner's address on Starknet
20+
- An array of token IDs to transfer
21+
22+
#### `withdrawTokens`
23+
Withdraws tokens received from L2. It consumes a message from L2 and transfers the tokens from escrow to the L1 recipient.
24+
25+
#### `startRequestCancellation` and `cancelRequest`
26+
These functions allow users to cancel a bridge request in case of failures or errors in the bridging process. This failure will be as a result of a bug in the l2 bridge contract or where insufficient `msg.value` is given when `depositTokens` is called. Basically, the message must have not been consumed on L2.
27+
28+
See https://docs.starknet.io/architecture-and-concepts/network-architecture/messaging-mechanism on how messaging works on starknet.
29+
30+
### Security Features
31+
32+
- The contract uses OpenZeppelin's UUPS (Universal Upgradeable Proxy Standard) pattern for upgradeability.
33+
- It implements access control to ensure only token owners or admins can initiate cancellations and set important addresses.
34+
- The contract uses escrow mechanisms to hold tokens during the bridging process.
35+
36+
37+
38+
39+
## Setup and Usage
40+
41+
[Foundry for ethereum](https://book.getfoundry.sh/) is used. Once foundry is installed:
42+
43+
1. Install the dependencies
44+
45+
```bash
46+
forge install
47+
```
48+
49+
2. Run the tests
50+
51+
```bash
52+
forge test
53+
```
54+
55+
## To deploy (anvil, testnet, etc...)
56+
57+
First, create a `.yourname.env` file copying the content from `.env.testnet`.
58+
This file will remain ignored by git, and you can put there your credentials
59+
to interact with the network.
60+
61+
Then, you can use the Makefile to operate. Most of variables are taken from
62+
the environment file.
63+
64+
`make bridge_deploy config=.yourname.env`
65+
<br><br><br><br>

legacyClaim/ethereum/foundry.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
gas_limit = 999999999
6+
fs_permissions = [{ access = "read-write", path = "./"}]
7+
evm_version="shanghai"
8+
solc = "0.8.24"
9+
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
10+
11+
[rpc_endpoints]
12+
goerli = "${GOERLI_RPC_URL}"
13+
anvil = "http://127.0.0.1:8545"
14+
15+
16+
[etherscan]
17+
goerli = { key = "${ETHERSCAN_API_KEY}" }
18+
anvil = { key = "${ETHERSCAN_API_KEY", chainId=31337}
19+
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Install Foundry
17+
uses: onbjerg/foundry-toolchain@v1
18+
with:
19+
version: nightly
20+
21+
- name: Print forge version
22+
run: forge --version
23+
24+
# Backwards compatibility checks.
25+
- name: Check compatibility with 0.8.0
26+
if: always()
27+
run: forge build --skip test --use solc:0.8.0
28+
29+
- name: Check compatibility with 0.7.6
30+
if: always()
31+
run: forge build --skip test --use solc:0.7.6
32+
33+
- name: Check compatibility with 0.7.0
34+
if: always()
35+
run: forge build --skip test --use solc:0.7.0
36+
37+
- name: Check compatibility with 0.6.12
38+
if: always()
39+
run: forge build --skip test --use solc:0.6.12
40+
41+
- name: Check compatibility with 0.6.2
42+
if: always()
43+
run: forge build --skip test --use solc:0.6.2
44+
45+
# via-ir compilation time checks.
46+
- name: Measure compilation time of Test with 0.8.17 --via-ir
47+
if: always()
48+
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir
49+
50+
- name: Measure compilation time of TestBase with 0.8.17 --via-ir
51+
if: always()
52+
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir
53+
54+
- name: Measure compilation time of Script with 0.8.17 --via-ir
55+
if: always()
56+
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir
57+
58+
- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
59+
if: always()
60+
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir
61+
62+
test:
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v3
66+
67+
- name: Install Foundry
68+
uses: onbjerg/foundry-toolchain@v1
69+
with:
70+
version: nightly
71+
72+
- name: Print forge version
73+
run: forge --version
74+
75+
- name: Run tests
76+
run: forge test -vvv
77+
78+
fmt:
79+
runs-on: ubuntu-latest
80+
steps:
81+
- uses: actions/checkout@v3
82+
83+
- name: Install Foundry
84+
uses: onbjerg/foundry-toolchain@v1
85+
with:
86+
version: nightly
87+
88+
- name: Print forge version
89+
run: forge --version
90+
91+
- name: Check formatting
92+
run: forge fmt --check
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Sync Release Branch
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
8+
jobs:
9+
sync-release-branch:
10+
runs-on: ubuntu-latest
11+
if: startsWith(github.event.release.tag_name, 'v1')
12+
steps:
13+
- name: Check out the repo
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 0
17+
ref: v1
18+
19+
- name: Configure Git
20+
run: |
21+
git config user.name github-actions[bot]
22+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
23+
24+
- name: Sync Release Branch
25+
run: |
26+
git fetch --tags
27+
git checkout v1
28+
git reset --hard ${GITHUB_REF}
29+
git push --force
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
cache/
2+
out/
3+
.vscode
4+
.idea
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/ds-test"]
2+
path = lib/ds-test
3+
url = https://github.com/dapphub/ds-test

0 commit comments

Comments
 (0)