Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jackpooleywc committed Sep 3, 2024
0 parents commit 2aee4a1
Show file tree
Hide file tree
Showing 86 changed files with 4,824 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
TENDERLY_API_KEY=""
BUNDLER_API_KEY=""
BUNDLER_BASE_URL=""
RPC_API_KEY=""
RPC_BASE_URL=""
PIMLICO_API_KEY=""
PIMLICO_BUNDLER_URL=""
PIMLICO_RPC_URL=""
25 changes: 25 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Rust CI

on:
pull_request:
push:
branches:
- main

env:
CARGO_TERM_COLOR: always

jobs:
build_rust_and_test:
name: Rust project - latest
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: rustup update stable && rustup default stable
- run: rustup toolchain install nightly -c rustfmt
- run: git submodule update --init --recursive
- run: make setup-thirdparty
- run: cargo test --all-features --lib --bins
# - run: cargo clippy --workspace --all-features --all-targets -- -D warnings
# - run: cargo +nightly fmt --all -- --check
# - run: cargo +nightly udeps --workspace
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/target
/Cargo.lock
.vscode
.env
.DS_Store
.direnv/*

.build
DerivedData
/.previous-build
xcuserdata
.DS_Store
*~
\#*
.\#*
.*.sw[nop]
*.xcscmblueprint
/default.profraw
*.xcodeproj
Utilities/Docker/*.tar.gz
.swiftpm
Package.resolved
/build
*.pyc
.docc-build
.vscode
Utilities/InstalledSwiftPMConfiguration/config.json
.devcontainer
.cursorignore
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "crates/yttrium/src/contracts"]
path = crates/yttrium/src/contracts
url = [email protected]:eth-infinitism/account-abstraction.git
35 changes: 35 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.1.0"
edition = "2021"
rust-version = "1.79"

[workspace.dependencies]
# Errors/Result
eyre = "0.6.12"
thiserror = "1.0"

# Async
tokio = { version = "1.17", features = ["full"] }

# Networking
reqwest = { version = "0.12.5", features = ["json"] }

# Serialization
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

# Logging
oslog = "0.2.0"
log = "0.4.20"

# [profile.release]
# lto = true
# codegen-units = 1
# panic = "abort"

# [profile.dev]
# debug = 0
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.PHONY: build setup build-ios-bindings fetch-thirdparty setup-thirdparty test format clean local-infra local-infra-forked local-infra-7702

build:
cargo build --release

setup: fetch-thirdparty setup-thirdparty build-debug-mode build-ios-bindings

build-debug-mode:
cargo build

fetch-thirdparty:
git submodule update --init

setup-thirdparty:
cd crates/yttrium/src/contracts/ && yarn install --frozen-lockfile --immutable && yarn compile

build-ios-bindings:
sh crates/ffi/build-rust-ios.sh
open Package.swift

test:
cargo test --workspace

format:
cargo +nightly fmt --all
cargo sort --workspace --grouped

lint:
cargo +nightly fmt --all -- --check
cargo clippy --all -- -D warnings -A clippy::derive_partial_eq_without_eq -D clippy::unwrap_used -D clippy::uninlined_format_args
cargo sort --check --workspace --grouped
cargo +nightly udeps --workspace

clean:
cd crates/account/src/contracts && yarn clean && cd ../../../../
cargo clean

local-infra:
cd test/scripts/local_infra && sh local-infra.sh

local-infra-forked:
cd test/scripts/forked_state && sh local-infra.sh

local-infra-7702:
cd test/scripts/7702 && sh local-infra.sh
33 changes: 33 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// swift-tools-version: 5.10
import PackageDescription

let package = Package(
name: "yttrium",
platforms: [
.macOS(.v14),
.iOS(.v13),
.watchOS(.v10),
.tvOS(.v17)
],
products: [
.library(
name: "Yttrium",
targets: ["Yttrium"]),
],
dependencies: [
.package(path: "crates/ffi/YttriumCore")
],
targets: [
.target(
name: "Yttrium",
dependencies: [
"YttriumCore"
],
path: "platforms/swift/Sources/Yttrium")
,
.testTarget(
name: "YttriumTests",
dependencies: ["Yttrium"],
path: "platforms/swift/Tests/YttriumTests"),
]
)
90 changes: 90 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Yttrium

Yttrium is a cross-platform library designed for working with smart accounts, currently focused on the Ethereum ecosystem.

> [!CAUTION]
> This project is under heavy development and is currently in a pre-alpha state.
## Overview

Yttrium simplifies the process of building applications that utilize account abstraction. It provides essential abstractions and primitives for Wallets and DApps to interact with and implement smart account functionality.

A primary goal of this project is to enable externally owned account (EOA) wallets to offer advanced features such as batch transactions and transaction sponsorship to their users.

While initially focused on Ethereum, Yttrium aims to be a cross-chain account abstraction library.

## Architecture

The following diagram provides an overview of the Yttrium architecture:

```mermaid
graph TD;
CoreRustLibrary[Core Rust Library] -->|Compiled to| NativeLibrary[Native Library]
NativeLibrary --> |Is consumed by| SwiftWrapper[Swift Wrapper]
NativeLibrary -.-> OtherNativePlatform["Other Native Platform"]
CoreRustLibrary -->|Compiled to| WebAssemblyModule[WebAssembly Module]
WebAssemblyModule --> |Is consumed by| TypeScriptWrapper[TypeScript Wrapper]
WebAssemblyModule -.-> OtherWebAssemblyPlatform["Other WebAssembly Platform"]
style CoreRustLibrary color:#fff,fill:#CE422B,stroke:#fff,stroke-width:2px
style NativeLibrary fill:#0000FF,stroke:#fff,stroke-width:2px
style SwiftWrapper color:#fff,fill:#F05138,stroke:#fff,stroke-width:2px
style WebAssemblyModule fill:#654ff0,stroke:#fff,stroke-width:2px,color:#fff
style TypeScriptWrapper color:#fff,fill:#3178c6,stroke:#fff,stroke-width:2px
style OtherNativePlatform color:#333,fill:#ccc,stroke:#ccc,stroke-dasharray: 5,5
style OtherWebAssemblyPlatform color:#333,fill:#ccc,stroke:#ccc,stroke-dasharray: 5,5
```

## Standards

In the near future, Yttrium will implement the following standards:
* ERC-4337 (in development)
* ERC-7702 (in development)

Additional standards and features will be added as the project evolves.

## Available APIs

Yttrium currently provides APIs for:
* Swift
* Rust

Planned future APIs include:
* JavaScript/TypeScript (via WebAssembly)
* Kotlin
* Flutter
* C#/Unity

## Target Platforms

Currently supported platforms:
* Apple platforms (iOS, macOS)
* Linux

Planned future support includes:
* WebAssembly
* Android
* Web
* Windows

## Installation and Setup

### Development Dependencies

To contribute to this project, ensure you have the following dependencies installed:

- `rustup`
- `cargo`
- `rustc`
- `swiftc` and Xcode
- `foundry`

### Setup

After installing the dependencies, clone the repository and run the following command to set up the project:

```bash
make setup
```

This will fetch the third party dependencies and build the project, including the Swift bindings.
10 changes: 10 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "cli"
version.workspace = true
edition.workspace = true
rust-version.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
yttrium = { path = "../yttrium" }
3 changes: 3 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello world");
}
6 changes: 6 additions & 0 deletions crates/ffi/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# swift-bridge
generated/
YttriumCore/RustXcframework.xcframework/
YttriumCore/.swiftpm/
YttriumCore/Sources/YttriumCore/ffi.swift
YttriumCore/Sources/YttriumCore/SwiftBridgeCore.swift
39 changes: 39 additions & 0 deletions crates/ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[package]
name = "ffi"
version.workspace = true
edition.workspace = true
rust-version.workspace = true

[lib]
crate-type = ["staticlib"]

[build-dependencies]
swift-bridge-build = { git = "https://github.com/wooden-worm/swift-bridge.git", branch = "derive_debug_serde" }

[dependencies]
# See: https://github.com/kornelski/rust-security-framework/pull/204
security-framework = "2.10.0"

swift-bridge = { git = "https://github.com/wooden-worm/swift-bridge.git", branch = "derive_debug_serde", features = [
"async",
] }
yttrium = { path = "../yttrium" }

# Errors
eyre.workspace = true

# Async
tokio.workspace = true

# Serialization
serde.workspace = true
serde_json.workspace = true

# Networking
reqwest.workspace = true

# Logging
log.workspace = true

[target.'cfg(target_os = "ios")'.dependencies]
oslog.workspace = true
36 changes: 36 additions & 0 deletions crates/ffi/YttriumCore/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// swift-tools-version:5.9.0
import PackageDescription
let package = Package(
name: "YttriumCore",
platforms: [
.macOS(.v14),
.iOS(.v13),
.watchOS(.v10),
.tvOS(.v17)
],
products: [
.library(
name: "YttriumCore",
targets: ["YttriumCore"]
),
],
dependencies: [],
targets: [
.binaryTarget(
name: "RustXcframework",
path: "RustXcframework.xcframework"
),
.target(
name: "YttriumCore",
dependencies: [
"RustXcframework"
]
),
.testTarget(
name: "YttriumCoreTests",
dependencies: [
"YttriumCore"
]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Foundation

extension FFIError: @unchecked Sendable {}
extension FFIError: Error {}
Loading

0 comments on commit 2aee4a1

Please sign in to comment.