Skip to content

Commit 30e4588

Browse files
committed
init
1 parent ec86d3c commit 30e4588

18 files changed

+2179
-0
lines changed

.gitignore

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.DS_Store
2+
node_modules
3+
results
4+
temp
5+
.nyc_output
6+
coverage.json
7+
*.tsbuildinfo
8+
**/lcov.info
9+
10+
yarn-error.log
11+
.yarn/*
12+
!.yarn/releases
13+
!.yarn/plugins
14+
.pnp.*
15+
16+
dist
17+
artifacts
18+
cache
19+
20+
packages/contracts-bedrock/deployments/devnetL1
21+
packages/contracts-bedrock/deployments/anvil
22+
23+
# vim
24+
*.sw*
25+
26+
# jetbrains
27+
.idea/
28+
29+
.secrets
30+
.env
31+
.env*
32+
!.env.example
33+
*.log
34+
35+
.devnet
36+
37+
# Ignore local fuzzing results
38+
**/testdata/fuzz/
39+
40+
coverage.out
41+
42+
# Ignore bedrock go bindings local output files
43+
op-bindings/bin
44+
op-exporter
45+
46+
47+
__pycache__
48+
49+
# Ignore echidna artifacts
50+
crytic-export
51+
52+
# Ignore building artifacts
53+
build/
54+
bot
55+
56+
# Ignore the configuration files
57+
bot.toml

Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM --platform=$BUILDPLATFORM golang:1.21.1-alpine3.18 as builder
2+
3+
RUN apk add --no-cache make ca-certificates gcc musl-dev linux-headers git jq bash
4+
5+
COPY ./go.mod /app/go.mod
6+
COPY ./go.sum /app/go.sum
7+
8+
WORKDIR /app
9+
10+
RUN go mod download
11+
12+
COPY ./core /app/core
13+
COPY ./cmd /app/cmd
14+
COPY ./Makefile /app/Makefile
15+
COPY ./bot.toml /app/bot.toml
16+
17+
WORKDIR /app/
18+
19+
RUN make build-go
20+
21+
FROM alpine:3.18
22+
23+
COPY --from=builder /app/bot /usr/local/bin
24+
COPY --from=builder /app/bot.toml /app/bot.toml
25+
26+
WORKDIR /app
27+
28+
CMD ["bot", "run", "--config", "/app/bot.toml"]

Makefile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
GITCOMMIT := $(shell git rev-parse HEAD)
2+
GITDATE := $(shell git show -s --format='%ct')
3+
4+
LDFLAGSSTRING +=-X main.GitCommit=$(GITCOMMIT)
5+
LDFLAGSSTRING +=-X main.GitDate=$(GITDATE)
6+
LDFLAGS := -ldflags "$(LDFLAGSSTRING)"
7+
8+
build-go:
9+
env GO111MODULE=on go build -v $(LDFLAGS) ./cmd/bot
10+
11+
build-solidity:
12+
pushd contracts; \
13+
forge build; \
14+
popd;
15+
16+
.PHONY: \
17+
bot \
18+
build-go \
19+
build-solidity

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# opbnb-bridge-bot
2+
3+
## Description
4+
5+
The opbnb-bridge-bot project primarily maintains a Layer2 contract named `L2StandardBridgeBot`. This contract, when called, initiates withdrawal transactions and collects a fixed fee for every withdrawals. The project promises that after the withdrawal transaction has can be proven and finalized after the required time window, a third-party account would complete the corresponding L1 proven withdrawal transactions and L1 finalized withdrawal transactions, thus completing the entire withdrawal process.
6+
7+
## Design Principle and Working Mechanism
8+
9+
This project consists of an on-chain contract `contracts/src/L2StandardBridgeBot.sol` and an off-chain bot.
10+
11+
The `L2StandardBridgeBot` contract provides a `withdrawTo` function, which charges a fixed fee for every execution and then forwards the call to the `L2StandardBridge.withdraw`.
12+
13+
The off-chain bot watches the `L2StandardBridgeBot.WithdrawTo` events and based on these events, re-constructs the corresponding withdrawals. We name these withdrawals as **bot-delegated withdrawals**. As time go out of the bot-delegated withdrawal's proven and finalized time window, our bot will send proven and finalized transactions to complete the entire withdrawal process.
14+
15+
## User Guide
16+
17+
### Getting Started at opBNB testnet
18+
19+
1. Prepare a PostgreSQL database
20+
21+
```
22+
docker-compose up -d
23+
```
24+
25+
2. Compile the off-chain bot and output the artifact to `./bot`
26+
27+
```
28+
make build-go
29+
```
30+
31+
3. Run the off-chain bot
32+
33+
```
34+
OPBNB_BRIDGE_BOT_PRIVKEY=<bot privkey> ./bot --config ./bot.toml
35+
```
36+
37+
### Deploy Contracts
38+
39+
1. Compile the contract using `forge`
40+
41+
```
42+
make build-solidity
43+
```
44+
45+
2. Deploy contract
46+
47+
```
48+
cd contracts
49+
50+
forge create \
51+
--rpc-url $OPBNB_TESTNET \
52+
--private-key $OP_DEPLOYER_PRIVKEY \
53+
src/L2StandardBridgeBot.sol:L2StandardBridgeBot --constructor-args $OP_DEPLOYER_ADDRESS 1000000000000000
54+
```
55+
56+
## License
57+
58+
MIT

bot.toml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[rpcs]
2+
l1-rpc =
3+
l2-rpc =
4+
5+
[db]
6+
host = "0.0.0.0"
7+
port = 5434
8+
user = "db_username"
9+
password = "db_password"
10+
name = "db_name"
11+
12+
[l1-contracts]
13+
address-manager = "0x1111111111111111111111111111111111111111"
14+
system-config = "0x406ac857817708eaf4ca3a82317ef4ae3d1ea23b"
15+
optimism-portal = "0x4386c8abf2009ac0c263462da568dd9d46e52a31"
16+
l2-output-oracle = "0xff2394bb843012562f4349c6632a0ecb92fc8810"
17+
l1-cross-domain-messenger = "0xd506952e78eecd5d4424b1990a0c99b1568e7c2c"
18+
l1-standard-bridge = "0x1111111111111111111111111111111111111111"
19+
# l1-erc721-bridge = "0x17e1454015bfb3377c75be7b6d47b236fd2ddbe7"
20+
l1-erc721-bridge = "0x1111111111111111111111111111111111111111"
21+
22+
[misc]
23+
l2-standard-bridge-bot = "0x4c3171982cd7f62690f4d6e086b91f434b97332f"
24+
propose-time-window = 60
25+
challenge-time-window = 60

0 commit comments

Comments
 (0)