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

add legacy reward claim contracts #19

Merged
merged 21 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
59 changes: 59 additions & 0 deletions .github/workflows/test_legacyClaim.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Legacy Claim Contracts Workflow

on:
push:
branches: [main, dev]
paths:
- "legacyClaim/**"
pull_request:
branches: [main, dev]
workflow_dispatch:

env:
SCARB_VERSION: v0.6.0

jobs:
test-starknet-contracts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
tool-versions: legacyClaim/starknet/.tool-versions
- uses: foundry-rs/setup-snfoundry@v3
with:
tool-versions: legacyClaim/starknet/.tool-versions
- run: scarb build
working-directory: legacyClaim/starknet
- run: snforge test
working-directory: legacyClaim/starknet


test-ethereum-contracts:
strategy:
fail-fast: true

name: Foundry testing
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run Forge build
run: |
forge --version
forge build --sizes --root legacyClaim/ethereum/
id: build

- name: Run Forge tests
run: |
forge test -vvv --root legacyClaim/ethereum/
id: test

14 changes: 14 additions & 0 deletions legacyClaim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules
.env
coverage
coverage.json
typechain
typechain-types
temp

#Hardhat files
cache
artifacts

deployments
contracts/**/target/**/*
13 changes: 13 additions & 0 deletions legacyClaim/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cd starknet && \
scarb --release build && \
cd scripts/deployment && \
node deployStageOne && \
cp -r ./addresses/ ../../../ethereum/logs/ && \
cd ../../../ethereum && \
forge build && \
make bridge_l1_deploy && \
cp -r ./logs/ ../starknet/scripts/deployment/addresses/ && \
cd ../starknet/scripts/deployment && \
node deployStageTwo
26 changes: 26 additions & 0 deletions legacyClaim/ethereum/.env.testnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# General config.
ETH_RPC_URL=https://sepolia.infura.io/v3/abc
ETHERSCAN_API_KEY=abc


LOCAL_LOGS=logs/dev/ #change to "prod" in production

# Account related variables (EOA account).
DEPLOYMENT_ACCOUNT_ADDRESS=0x0000000000000000000000000000000000000001
DEPLOYMENT_ACCOUNT_PRIVATE_KEY=0x0

BRIDGE_L1_OWNER_ADDRESS=0x00000000000000000000000000000000000000002
BRIDGE_L1_TOKEN_ADDRESS=0x0A642270Cc73B2FC1605307F853712F944394564 #l1 realms


# Bridge L2 variables.
BRIDGE_L2_SELECTOR=0x03593216f3a8b22f4cf375e5486e3d13bfde9d0f26976d20ac6f653c73f7e507

# Starknet Core
STARKNET_CORE_L1_ADDRESS=0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057 #sepolia

# UNNECESSARY: TB REMOVED
BRIDGE_L1_PROXY_ADDRESS=0x0000000000000000000000000000000000000000


# forge verify-contract 0x47fee0f901Ad3aa5B980ccBF762F1160aCa593b8 Bridge --verifier etherscan --guess-constructor-args
19 changes: 19 additions & 0 deletions legacyClaim/ethereum/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Compiler files
cache/
out/

# Ignores all broadcasts
broadcast/
#/broadcast/*/31337/
#/broadcast/**/dry-run/

# Docs
docs/


# Dotenv file
**/*.env.*
**/*.env.sepolia

# Local logs folder
logs/
19 changes: 19 additions & 0 deletions legacyClaim/ethereum/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Only .env file is loaded by foundry, and we can't specify a file.
# TODO: need a better way to force config arg is given...!
# CLEAN_CONFIG:=$(shell rm .env)
# COPY_CONFIG:=$(shell cp $(config) .env)

include .env
export $(shell sed 's/=.*//' .env)

bold := $(shell tput bold)
sgr0 := $(shell tput sgr0)

# TODO: for upgrades, check how to force proxy arg.

# Bridge deploy impl + proxy.
bridge_l1_deploy:
forge script --broadcast --rpc-url ${ETH_RPC_URL} script/Bridge.s.sol:Deploy -vvvvvvvv

bridge_claim:
forge script --broadcast --rpc-url ${ETH_RPC_URL} script/Bridge.s.sol:ClaimOnStarknet
65 changes: 65 additions & 0 deletions legacyClaim/ethereum/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# NFT Bridge: Ethererum.

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.

### Key Features

1. **Token Deposit**: Users can deposit ERC721 tokens from L1 to L2 using the `depositTokens` function.
2. **Token Withdrawal**: Users can withdraw tokens received from L2 using the `withdrawTokens` function.
3. **Request Cancellation**: Users can initiate and complete cancellation of bridge requests using `startRequestCancellation` and `cancelRequest` functions.

### Main Functions

#### `initialize`
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).

#### `depositTokens`
Deposits tokens into escrow and initiates the transfer to Starknet. It requires:
- A salt for generating the request hash
- The new owner's address on Starknet
- An array of token IDs to transfer

#### `withdrawTokens`
Withdraws tokens received from L2. It consumes a message from L2 and transfers the tokens from escrow to the L1 recipient.

#### `startRequestCancellation` and `cancelRequest`
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.

See https://docs.starknet.io/architecture-and-concepts/network-architecture/messaging-mechanism on how messaging works on starknet.

### Security Features

- The contract uses OpenZeppelin's UUPS (Universal Upgradeable Proxy Standard) pattern for upgradeability.
- It implements access control to ensure only token owners or admins can initiate cancellations and set important addresses.
- The contract uses escrow mechanisms to hold tokens during the bridging process.




## Setup and Usage

[Foundry for ethereum](https://book.getfoundry.sh/) is used. Once foundry is installed:

1. Install the dependencies

```bash
forge install
```

2. Run the tests

```bash
forge test
```

## To deploy (anvil, testnet, etc...)

First, create a `.yourname.env` file copying the content from `.env.testnet`.
This file will remain ignored by git, and you can put there your credentials
to interact with the network.

Then, you can use the Makefile to operate. Most of variables are taken from
the environment file.

`make bridge_deploy config=.yourname.env`
<br><br><br><br>
19 changes: 19 additions & 0 deletions legacyClaim/ethereum/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]
gas_limit = 999999999
fs_permissions = [{ access = "read-write", path = "./"}]
evm_version="shanghai"
solc = "0.8.24"
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

[rpc_endpoints]
goerli = "${GOERLI_RPC_URL}"
anvil = "http://127.0.0.1:8545"


[etherscan]
goerli = { key = "${ETHERSCAN_API_KEY}" }
anvil = { key = "${ETHERSCAN_API_KEY", chainId=31337}

92 changes: 92 additions & 0 deletions legacyClaim/ethereum/lib/forge-std/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

# Backwards compatibility checks.
- name: Check compatibility with 0.8.0
if: always()
run: forge build --skip test --use solc:0.8.0

- name: Check compatibility with 0.7.6
if: always()
run: forge build --skip test --use solc:0.7.6

- name: Check compatibility with 0.7.0
if: always()
run: forge build --skip test --use solc:0.7.0

- name: Check compatibility with 0.6.12
if: always()
run: forge build --skip test --use solc:0.6.12

- name: Check compatibility with 0.6.2
if: always()
run: forge build --skip test --use solc:0.6.2

# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Run tests
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Check formatting
run: forge fmt --check
29 changes: 29 additions & 0 deletions legacyClaim/ethereum/lib/forge-std/.github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Sync Release Branch

on:
release:
types:
- created

jobs:
sync-release-branch:
runs-on: ubuntu-latest
if: startsWith(github.event.release.tag_name, 'v1')
steps:
- name: Check out the repo
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: v1

- name: Configure Git
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Sync Release Branch
run: |
git fetch --tags
git checkout v1
git reset --hard ${GITHUB_REF}
git push --force
4 changes: 4 additions & 0 deletions legacyClaim/ethereum/lib/forge-std/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache/
out/
.vscode
.idea
3 changes: 3 additions & 0 deletions legacyClaim/ethereum/lib/forge-std/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
Loading
Loading