Skip to content

Commit 519ce56

Browse files
authored
Initial commit
0 parents  commit 519ce56

File tree

745 files changed

+157591
-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.

745 files changed

+157591
-0
lines changed

.circleci/config.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
version: 2.1
2+
3+
orbs:
4+
node: circleci/[email protected]
5+
go: circleci/[email protected]
6+
python: circleci/[email protected]
7+
rust: circleci/[email protected]
8+
docker: circleci/[email protected]
9+
10+
jobs:
11+
integration-tests:
12+
machine:
13+
image: ubuntu-2204:current
14+
resource_class: large
15+
parallelism: 10
16+
steps:
17+
- checkout
18+
- docker/install-docker
19+
- run:
20+
name: Install essential tools
21+
command: |
22+
sudo apt-get update
23+
sudo apt-get install -y curl git software-properties-common python3 python3-pip
24+
- go/install:
25+
version: 1.22.5
26+
- node/install
27+
- rust/install:
28+
version: 1.75.0
29+
- run:
30+
name: Verify Python installation
31+
command: |
32+
python3 --version
33+
pip3 --version
34+
- run:
35+
name: Checkout submodules
36+
command: git submodule update --init --recursive
37+
- run:
38+
name: Diagnostic - Check directory structure
39+
command: |
40+
pwd
41+
ls -la
42+
- run:
43+
name: Diagnostic - Check boba directory
44+
command: |
45+
ls -la boba
46+
cat boba/go.mod || echo "go.mod not found in boba directory"
47+
- run:
48+
name: Go mod download in boba directory
49+
command: |
50+
go version && cd boba && go mod tidy -e && go mod download
51+
- rust/install:
52+
version: 1.75.0
53+
- restore_cache:
54+
name: Restore pnpm Package Cache
55+
keys:
56+
- pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
57+
- run:
58+
name: Install Foundry
59+
command: |
60+
curl -L https://foundry.paradigm.xyz | bash
61+
export PATH="$PATH:$HOME/.foundry/bin"
62+
foundryup
63+
- run:
64+
name: Install pnpm
65+
command: |
66+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
67+
sudo apt-get install -y nodejs
68+
npm i -g yarn pnpm
69+
echo "NPM version: $(npm --version)"
70+
echo "Yarn version: $(yarn --version)"
71+
echo "PNPM version: $(pnpm --version)"
72+
pnpm config set store-dir .pnpm-store
73+
74+
- save_cache:
75+
name: Save pnpm Package Cache
76+
key: pnpm-packages-{{ checksum "pnpm-lock.yaml" }}
77+
paths:
78+
- .pnpm-store
79+
- run:
80+
name: Install Make
81+
command: sudo apt-get install -y make
82+
- run:
83+
name: Install dependencies (root)
84+
command: pnpm install
85+
- run:
86+
name: Install dependencies (contracts)
87+
command: |
88+
cd ./contracts
89+
pnpm install
90+
- run:
91+
name: Start local environment
92+
command: |
93+
pnpm start:local:ci 2>&1 | tee local_env.log
94+
no_output_timeout: 60m
95+
environment:
96+
PRIVATE_KEY: ${PRIVATE_KEY}
97+
CONRANKING_API_KEY: ${CONRANKING_API_KEY}
98+
- run:
99+
name: Run Hardhat tests
100+
command: |
101+
cd ./contracts
102+
npx hardhat test
103+
environment:
104+
TOKEN_PRICE_CONTRACT: ${TOKEN_PRICE_CONTRACT}
105+
RPC_URL: ${RPC_URL}
106+
PRIVATE_KEY: ${PRIVATE_KEY}
107+
- run:
108+
name: Display full logs
109+
command: cat local_env.log
110+
when: always
111+
112+
workflows:
113+
version: 2
114+
test-workflow:
115+
jobs:
116+
- integration-tests:
117+
context: test-env

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
**/node_modules
3+
docker-compose.local.yml
4+
docker-compose.sepolia-localsnap.yml
5+
docker-compose.sepolia.yml
6+
Dockerfile*

.env-template

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ENTRY_POINTS=
2+
NODE_HTTP=
3+
CHAIN_ID=
4+
BUILDER_PRIVATE_KEY=
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Backend Tests
2+
on:
3+
push:
4+
branches: [ main ]
5+
pull_request:
6+
branches: [ main ]
7+
jobs:
8+
test:
9+
runs-on: ubuntu-latest
10+
environment: tests
11+
steps:
12+
- uses: actions/checkout@v4
13+
- name: Use Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: '18.x'
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v2
19+
with:
20+
version: 8
21+
- name: Install dependencies
22+
run: pnpm install
23+
working-directory: ./backend
24+
- name: Run tests
25+
run: pnpm test
26+
working-directory: ./backend
27+
env:
28+
OC_LISTEN_PORT: ${{ vars.OC_LISTEN_PORT }}
29+
COINRANKING_API_KEY: ${{ secrets.COINRANKING_API_KEY }}
30+
OC_HYBRID_ACCOUNT: ${{ vars.OC_HYBRID_ACCOUNT }}
31+
ENTRY_POINTS: ${{ vars.ENTRY_POINT }}
32+
CHAIN_ID: ${{ vars.CHAIN_ID }}
33+
OC_PRIVKEY: ${{ secrets.OC_PRIVKEY }}
34+
HC_HELPER_ADDR: ${{ vars.HC_HELPER_ADDR }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Smart Contract Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Forge and Hardhat Tests
12+
runs-on: ubuntu-latest
13+
environment: tests
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
submodules: recursive
18+
19+
- name: Install Foundry
20+
uses: foundry-rs/foundry-toolchain@v1
21+
22+
- name: Use Node.js
23+
uses: actions/setup-node@v3
24+
with:
25+
node-version: "18.x"
26+
27+
- name: Install pnpm
28+
uses: pnpm/action-setup@v2
29+
with:
30+
version: 9
31+
32+
- name: Install dependencies (root)
33+
run: pnpm install
34+
35+
- name: Install dependencies (contracts)
36+
run: pnpm install
37+
working-directory: ./contracts
38+
39+
- name: Run Forge tests
40+
run: forge test -vvv
41+
working-directory: ./contracts

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
node_modules
2+
.env
3+
broadcast/
4+
contracts/broadcast
5+
cache_forge/
6+
dist/
7+
8+
# Hardhat files
9+
/cache
10+
/artifacts
11+
12+
# TypeChain files
13+
/typechain
14+
/typechain-types
15+
16+
# solidity-coverage files
17+
/coverage
18+
/coverage.json
19+
20+
# Hardhat Ignition default folder for deployments against a local node
21+
ignition/deployments/chain-31337
22+
23+
.DS_STORE
24+
/target
25+
out/
26+
out.json
27+
.idea
28+
.vscode
29+
bloat*
30+
31+
logs
32+
*.log
33+
npm-debug.log*
34+
yarn-debug.log*
35+
yarn-error.log*
36+
pnpm-debug.log*
37+
lerna-debug.log*
38+
39+
# dist
40+
dist-ssr
41+
*.local
42+
node_modules

.gitmodules

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[submodule "contracts/lib/forge-std"]
2+
path = contracts/lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "contracts/lib/openzeppelin-contracts"]
5+
path = contracts/lib/openzeppelin-contracts
6+
url = https://github.com/OpenZeppelin/openzeppelin-contracts
7+
branch = release-v4.9
8+
[submodule "boba"]
9+
path = boba
10+
url = https://github.com/bobanetwork/boba.git
11+
[submodule "snap-account-abstraction-keyring"]
12+
path = snap-account-abstraction-keyring
13+
url = https://github.com/bobanetwork/snap-account-abstraction-keyring.git

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
[![Backend Tests](https://github.com/bobanetwork/aa-hc-example/actions/workflows/backend-tests.yml/badge.svg)](https://github.com/bobanetwork/aa-hc-example/actions/workflows/backend-tests.yml)
2+
[![Smart Contract Tests](https://github.com/bobanetwork/aa-hc-example/actions/workflows/contract-tests.yml/badge.svg)](https://github.com/bobanetwork/aa-hc-example/actions/workflows/contract-tests.yml)
3+
4+
# What is this?
5+
This is a (hopefully) easy to use example of how you can use [Hybrid Compute](https://docs.boba.network/developer/features/aa-basics/hybrid-compute) with [Account Abstraction](https://docs.boba.network/developer/features/aa-basics) to build powerful Web3 Apps!
6+
7+
This "Hello World" example allows you to fetch the current price of any cryptocurrency from an off-chain API such as CoinRanking into your smart contract within 1 single, atomic transaction!
8+
9+
You can run this repo in 2 ways:
10+
- On our official testnet "Boba Sepolia"
11+
- or spin up the local stack end-to-end (including the local chain, the bundler for Account Abstraction, the snap, etc.)
12+
13+
# Get started
14+
Clone this repo with `git clone --recurse-submodules -j8 [email protected]:bobanetwork/aa-hc-example.git`
15+
16+
## Installation
17+
You will need a handful of tools to run the full stack (local):
18+
- `cargo` [[Download]](https://doc.rust-lang.org/cargo/getting-started/installation.html)
19+
- `forge` [[Download]](https://book.getfoundry.sh/getting-started/installation)
20+
- `npm` | `yarn` or `pnpm` [[Download]](https://nodejs.org/en/download/package-manager)
21+
- `golang` [[Download]](https://go.dev/doc/install)
22+
- `Metamask Flask` (Development build of Metamask) [[Download]](https://chromewebstore.google.com/detail/metamask-flask-developmen/ljfoeinjpaedjfecbmggjgodbgkmjkjk)
23+
24+
To run the stack on Boba Sepolia you can skip `cargo` and `golang` which is only required to run the local stack.
25+
26+
## Local
27+
All contracts and services are deployed and environment variables are substituted across all services automatically to ensure a convenient developer experience.
28+
29+
1. Make sure you have the dependencies as outlined above installed and Docker running.
30+
2. Run `pnpm start:local` to spin the local stack up. Make sure you have [Docker](https://www.docker.com/products/docker-desktop/) running.
31+
3. Head over to [localhost:8001](http://localhost:8001) to create your Smart Wallet.
32+
4. Once you created your account, try it out by using the "Transfer Funds" section. Make sure you funded your new "Snap Account" with some `ETH` on Boba Sepolia.
33+
5. Congrats you sent your first `UserOp` on your local devnet using Account Abstraction! This is the moment your smart account gets deployed on-chain (on the first UserOp).
34+
6. Navigate now to [localhost:8000](http://localhost:8000) to interact with your local DApp which utilizes Hybrid Compute via Account Abstraction to fetch off-chain data to your smart contract! In our example we fetch the current price of a cryptocurrency asset.
35+
36+
37+
Please note, that the local stack actually spins up the Boba L2 locally, the Bundler ("Rundler") along with other local services. This might take a while to startup.
38+
39+
## Boba Sepolia
40+
41+
1. Copy `/contracts/.env-example` and name it `.env`. All necessary variables are pre-filled except of `PRIVATE_KEY`.
42+
2. Add your own private key, that contains some ETH on Boba Sepolia in order to deploy the contracts on testnet. You can obtain some SepETH on Sepolia (L1) from any [faucet](https://cloud.google.com/application/web3/faucet/ethereum/sepolia) and bridge them to L2 through our [Gateway](https://gateway.boba.network/).
43+
3. Run `pnpm start:sepolia` to spin up the reduced local stack to use the existing infrastructure on Boba Sepolia.
44+
4. Head over to [hc-wallet.sepolia.boba.network](https://hc-wallet.sepolia.boba.network/) to create your Smart Wallet.
45+
5. Once you created your account, try it out by using the "Transfer Funds" section. Make sure you funded your new "Snap Account" with some `ETH` on Boba Sepolia.
46+
6. Congrats you sent your first `UserOp` on Boba Sepolia using Account Abstraction! If you navigate to the [Block-Explorer](https://testnet.bobascan.com/) you should see your contract wallet.
47+
7. Navigate now to [localhost:8000](http://localhost:8000) to interact with your local DApp which utilizes Hybrid Compute via Account Abstraction to fetch off-chain data to your smart contract! In our example we fetch the current price of a cryptocurrency asset.
48+
49+
When you follow the steps above your application will use the already deployed backend below for simplification. If you want to deploy your own backend instead follow these steps:
50+
1. Deploy the backend to your cloud of your choosing [[here is more documentation on that](./backend/README.md)]. We've provided you with a [Dockerfile](./backend/Dockerfile) and [Docker Compose](./backend/docker-compose.yml) to make this as easy as possible.
51+
2. Once your backend is live, change the `BACKEND_URL` in your [.env](./contracts/.env) (if the file doesn't exist, you skipped the steps above) within your `contracts folder`.
52+
3. Rerun the script `pnpm start:sepolia` and try it out as described above.
53+
54+
| Name | Address | Explainer |
55+
|------------------|--------------------------------------------------|-------------------------------------|
56+
| BACKEND | https://aa-hc-example.onrender.com/hc | |
57+
| FRONTEND | https://aa-hc-example-fe.onrender.com | |
58+
| HC_HELPER_ADDR | 0x1c64EC0A5E2C58295c3208a63209A2A719dF68D8 | HC Helper is system-wide available |
59+
| TOKEN_PRICE_ADDR | 0xcad49c0381c1B0779A318c2326Db43A6073adC1e |
60+
| RPC_URL | https://gateway.tenderly.co/public/boba-sepolia | |
61+
| -> More RPC URls | https://chainlist.org/chain/28882 | |
62+
63+
64+
This is what a successful transaction will look like: [0x30056b3ff720f4d824422bd077b88c4333e86fbe5522bcdba96cfc8fa2a69b52](https://testnet.bobascan.com/tx/0x30056b3ff720f4d824422bd077b88c4333e86fbe5522bcdba96cfc8fa2a69b52?chainid=28882)
65+
66+
This is what it will look like on the frontend provided:
67+
![Successful userOp](./assets/successful_userop.png "Successful userOp")
68+
69+
# How does it work?
70+
This example utilizes [Hybrid Compute 2.0](https://docs.boba.network/developer/features/aa-basics/hybrid-compute) based on [Account Abstraction](https://docs.boba.network/developer/features/aa-basics#what-is-account-abstraction).
71+
72+
Here is a high level overview of what happens:
73+
74+
![High level arch](./assets/HC-AA-SimplifiedFlow.drawio.png "Rough architecture")
75+
76+
77+
The actual API call happens when the gas estimation happens (click for full page view):
78+
79+
[![Gas estimation flow](./assets/aa_hc_estimation.png "Gas estimation flow")](./assets/aa_hc_estimation.png)
80+
81+
82+
If the gas estimation was successful, then we can submit our user operation (click for full page view):
83+
84+
[![Submit flow](./assets/aa_hc_submit.png "Submit flow")](./assets/aa_hc_submit.png)
85+
86+
# Testing
87+
Whenever you make changes and push to `main` on your Github repository relevant tests are being run by Github actions to make sure everything works as expected.
88+
89+
If you want to run tests locally, execute `pnpm test`.

0 commit comments

Comments
 (0)