Skip to content

Commit 278c168

Browse files
committed
Import core source history
2 parents 8341b9e + 7ab99bd commit 278c168

2,500 files changed

Lines changed: 323860 additions & 0 deletions

File tree

Some content is hidden

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

core/.cargo/audit.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[advisories]
2+
ignore = [
3+
# ruint::algorithms::div::reciprocal_mg10 OOB; only reachable if low-level algorithms are called directly.
4+
# We only use ruint through alloy-primitives higher-level APIs.
5+
"RUSTSEC-2025-0137",
6+
]

core/.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Apple Silicon Macs (Homebrew in /opt/homebrew)
2+
[target.aarch64-apple-darwin]
3+
rustflags = ["-L", "/opt/homebrew/opt/libpq/lib"]
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
---
2+
name: review-changes
3+
description: Review and fix local git changes against Gem Wallet Core coding standards and patterns
4+
argument-hint: "[--subagent]"
5+
disable-model-invocation: true
6+
allowed-tools: Read, Edit, Write, Glob, Grep, Bash, Task
7+
---
8+
9+
# Review and Fix Local Changes
10+
11+
Review uncommitted changes against the coding standards and patterns defined in this repository, then fix any issues found.
12+
13+
## Arguments
14+
- `--subagent`: Run in a subagent (isolates context, runs in background)
15+
16+
## Mode Selection
17+
18+
Check if `--subagent` is in the arguments:
19+
- If `--subagent` is present: Use the Task tool with `subagent_type: "general-purpose"` to run this review in a subagent, passing all other arguments
20+
- If `--subagent` is NOT present: Run directly in current context (default)
21+
22+
## Context
23+
24+
Current git diff to review:
25+
!`git diff --no-color`
26+
27+
Changed files:
28+
!`git diff --name-only`
29+
30+
## Review Checklist
31+
32+
Analyze the diff above and check for the following issues:
33+
34+
### 1. Import Patterns
35+
- [ ] **No inline imports**: All imports must be at the top of the file, never inside functions
36+
- [ ] **No full paths inline**: Never use `storage::DatabaseClient::new()` inline; import types first
37+
- [ ] **Import order**: Standard library first, then external crates, then local crates, then `pub use` re-exports
38+
39+
### 2. Naming Conventions
40+
- [ ] **Files/modules**: `snake_case` (e.g., `asset_id.rs`)
41+
- [ ] **Functions/variables**: `snake_case`
42+
- [ ] **Structs/enums**: `PascalCase`
43+
- [ ] **Constants**: `SCREAMING_SNAKE_CASE`
44+
- [ ] **No generic names**: Avoid `util`, `utils`, `normalize`, or similar vague names
45+
- [ ] **Concise helper names**: Within a module, use scope-reliant names (prefer `is_spot_swap` over `is_hypercore_spot_swap`)
46+
- [ ] **No type suffixes**: Avoid `_str`, `_int`, `_vec` suffixes; Rust's type system makes them redundant
47+
48+
### 3. Error Handling
49+
- [ ] **Prefer plain `Error`**: Use plain Error types, not `thiserror` macros
50+
- [ ] **Implement `From` traits**: For error conversion between types
51+
- [ ] **Propagate with `?`**: Prefer `?` operator over manual `map_err` where possible
52+
- [ ] **Consistent `Result<T, Error>`**: Use consistent return types
53+
- [ ] **Constructor methods on errors**: Use `ErrorType::constructor(msg)` instead of verbose `ErrorType::Variant("redundant context".into())`
54+
55+
### 3b. JSON Parameter Extraction
56+
- [ ] **Use `primitives::ValueAccess`**: For `serde_json::Value` access, use composable trait methods (`get_value(key)`, `at(index)`, `string()`) instead of manual `.get().ok_or()` chains. Chain for compound access: `params.get_value("key")?.at(0)?.string()?`
57+
- [ ] **Accessor methods on parent types**: Add accessor methods (e.g., `TransactionLoadInput::get_data_extra()`) to avoid pattern-matching boilerplate at call sites
58+
59+
### 4. Code Style
60+
- [ ] **Line length**: Maximum 180 characters
61+
- [ ] **Avoid `matches!`**: Don't use `matches!` for pattern matching; it's easy to miss cases later
62+
- [ ] **No over-engineering**: Only make changes directly requested or clearly necessary
63+
- [ ] **No docstrings/comments/annotations**: Don't add docstrings, comments, or `///` docs unless explicitly asked; remove any that were added (including in mod.rs files)
64+
- [ ] **No `#[allow(dead_code)]`**: Remove dead code instead of suppressing warnings; if code is needed, use it
65+
- [ ] **No unused fields**: Remove unused fields from structs/models; don't keep fields "for future use"
66+
- [ ] **Constants for magic numbers**: Extract magic numbers into named constants with clear meaning
67+
- [ ] **Minimum interface**: Don't expose unnecessary functions; if client only needs one function, don't add multiple variants
68+
- [ ] **Use uniffi::remote**: For UniFFI wrapper types around external models, use `#[uniffi::remote]` instead of creating duplicate structs with `From` implementations:
69+
```rust
70+
// Record example
71+
use primitives::AuthNonce;
72+
pub type GemAuthNonce = AuthNonce;
73+
#[uniffi::remote(Record)]
74+
pub struct GemAuthNonce { pub nonce: String, pub timestamp: u32 }
75+
76+
// Enum example
77+
use primitives::SwapperMode;
78+
pub type GemSwapperMode = SwapperMode;
79+
#[uniffi::remote(Enum)]
80+
pub enum GemSwapperMode { ExactIn, ExactOut }
81+
```
82+
- [ ] **Simple solutions**: Three similar lines is better than a premature abstraction
83+
- [ ] **Avoid `mut`**: Prefer immutable bindings; use `mut` only when truly necessary
84+
- [ ] **Prefer one-liners**: Inline single-use variables; avoid creating variables used only once
85+
- [ ] **Avoid `#[serde(default)]`**: Only use when the field is genuinely optional in the API response; if the field is always present, omit it
86+
- [ ] **Use accessor methods for enum variants**: Instead of destructuring enum variants with `match`, use typed accessor methods (e.g., `metadata.get_sequence()?` instead of `match &metadata { Cosmos { sequence, .. } => ... }`)
87+
88+
### 5. Code Organization
89+
- [ ] **Modular structure**: Break down files into smaller, focused modules; separate models from clients/logic (e.g., `models.rs` + `client.rs`, not everything in one file)
90+
- [ ] **Folder modules for complexity**: When a module has multiple concerns (models, client, mappers), use a folder with `mod.rs` instead of a single file
91+
- [ ] **Avoid duplication**: Search for existing implementations before writing new code; reuse existing code or crates
92+
- [ ] **Shared crates**: Reusable logic belongs in shared crates (e.g., `gem_solana`, `gem_evm`), not in utility binaries; move shared code to appropriate crates
93+
- [ ] **Bird's eye view**: Step back and identify opportunities to simplify and consolidate
94+
95+
### 6. Async Patterns
96+
- [ ] **Tokio runtime**: Use `tokio` for async operations
97+
- [ ] **Shared state**: Use `Arc<tokio::sync::Mutex<T>>` for shared async state
98+
- [ ] **Async client structs**: Should return `Result<T, Error>`
99+
100+
### 7. Database Patterns
101+
- [ ] **Separate models**: Database models should be separate from domain primitives
102+
- [ ] **Use `as_primitive()`**: For conversion from database models
103+
- [ ] **Repository pattern**: Access via `DatabaseClient` methods
104+
105+
### 8. Blockchain/RPC Patterns
106+
- [ ] **Use `gem_jsonrpc::JsonRpcClient`**: For blockchain RPC interactions
107+
- [ ] **Use `primitives::hex`**: For hex encoding/decoding (not `alloy_primitives::hex`)
108+
- [ ] **U256 conversions**: Use `u256_to_biguint` and `biguint_to_u256` from `gem_evm/src/u256.rs`
109+
- [ ] **Provider pattern**: Fetch raw data via RPC, then use mapper functions for conversion
110+
- [ ] **Mapper files**: Place mapper functions in separate `*_mapper.rs` files
111+
112+
### 9. Testing
113+
- [ ] **`#[tokio::test]`**: Use for async tests
114+
- [ ] **Test naming**: Prefix with `test_` descriptively
115+
- [ ] **Error handling**: Use `Result<(), Box<dyn std::error::Error + Send + Sync>>`
116+
- [ ] **Test data**: For long JSON (>20 lines), store in `testdata/` and use `include_str!()`
117+
- [ ] **`.unwrap()` not `.expect()`**: Never use `.expect()` in tests; use `.unwrap()` for brevity
118+
- [ ] **No `assert!` with `contains`**: Use `assert_eq!` with concrete values; `assert!(x.contains(...))` gives useless failure messages
119+
- [ ] **No fallback, fail fast**: Don't silently return defaults on errors (e.g., `unwrap_or(0)`). Propagate errors with `?` or return `Result`. Fail rather than mask issues with fallbacks.
120+
- [ ] **Methods over free functions**: Helper functions should be methods on the relevant struct, not top-level free functions
121+
- [ ] **Mock methods in testkit**: Use `Type::mock()` constructors in `testkit/` modules instead of inline struct construction in tests
122+
- [ ] **`PartialEq` + `assert_eq!`**: Derive `PartialEq` on test-relevant enums and use direct `assert_eq!` with constructed expected values instead of destructuring with `let ... else { panic! }` or `match ... { _ => panic! }`
123+
- [ ] **Test helpers**: Create concise constructor functions (e.g., `fn object(json: &str) -> EnumType`, `fn sign_message(chain, sign_type, data) -> Action`) for frequently constructed enum variants in test modules
124+
125+
### 10. Security
126+
- [ ] **No hardcoded secrets**: Check for API keys, passwords, credentials
127+
- [ ] **Input validation**: Validate at system boundaries (user input, external APIs)
128+
- [ ] **OWASP top 10**: Watch for command injection, XSS, SQL injection vulnerabilities
129+
130+
## Workflow
131+
132+
Iterate at least 2-3 times to ensure all issues are caught and fixed:
133+
134+
### Each Iteration:
135+
1. **Analyze**: Review the diff against the checklist
136+
2. **Read**: Read the full content of each changed file to understand context
137+
3. **Fix**: Apply fixes directly using the Edit tool for each issue found
138+
4. **Format**: Run `rustfmt --edition 2024 <files>` on modified files
139+
5. **Verify**: Run `cargo clippy -p <crate> -- -D warnings` on affected crates
140+
6. **Check**: Review the changes again - new issues may have been introduced or revealed
141+
142+
### Stop when:
143+
- No more issues are found after a full review pass
144+
- Clippy passes with no warnings
145+
- Code is properly formatted
146+
147+
## Output Format
148+
149+
After fixing issues, provide a summary:
150+
151+
1. **Issues Fixed**: List each fix made with:
152+
- File and line reference
153+
- Category (from checklist above)
154+
- What was changed
155+
2. **Manual Review Needed**: Issues that require human decision (if any)
156+
3. **Verification**: Clippy/format results
157+
158+
Severity levels for reporting:
159+
- **CRITICAL**: Security issues or bugs - fix immediately
160+
- **WARNING**: Coding standard violations - fix automatically
161+
- **SUGGESTION**: Minor improvements - fix if straightforward, otherwise note for user

core/.clippy.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
too-many-arguments-threshold = 18 # lower this until we fix current code, ideally 8~10
2+
type-complexity-threshold = 384

core/.dockerignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
target/
2+
.git/
3+
.github/
4+
.gitignore
5+
.dockerignore
6+
*.md
7+
Dockerfile
8+
docker-compose*.yml

core/.gitattributes

Whitespace-only changes.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Setup Rust CI
2+
description: Restore Rust cache, configure sccache, and install just.
3+
4+
inputs:
5+
restore-cache:
6+
description: Restore the shared Rust cargo cache.
7+
required: false
8+
default: "true"
9+
shared-key:
10+
description: Shared key for Swatinem/rust-cache.
11+
required: false
12+
default: ci-rust
13+
sccache:
14+
description: Configure sccache.
15+
required: false
16+
default: "true"
17+
runs:
18+
using: composite
19+
steps:
20+
- name: Restore cargo cache
21+
if: ${{ inputs.restore-cache == 'true' }}
22+
uses: Swatinem/rust-cache@v2
23+
with:
24+
shared-key: ${{ inputs.shared-key }}
25+
26+
- name: Run sccache-cache
27+
if: ${{ inputs.sccache == 'true' }}
28+
uses: mozilla-actions/sccache-action@v0.0.9
29+
30+
- name: Install just
31+
uses: extractions/setup-just@v4
32+
with:
33+
just-version: "1.50.0"

core/.github/dependabot.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
open-pull-requests-limit: 2
6+
schedule:
7+
interval: "daily"
8+
ignore:
9+
- dependency-name: "*"
10+
update-types:
11+
- "version-update:semver-patch"
12+
13+
- package-ecosystem: "github-actions"
14+
directory: "/"
15+
schedule:
16+
interval: "weekly"
17+
ignore:
18+
- dependency-name: "*"
19+
update-types:
20+
- "version-update:semver-patch"
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: CI - Gemstone Android
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "gemstone/**"
8+
pull_request:
9+
branches: ["main"]
10+
paths:
11+
- "gemstone/**"
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
CARGO_TERM_COLOR: always
19+
SCCACHE_GHA_ENABLED: "true"
20+
RUSTC_WRAPPER: "sccache"
21+
22+
jobs:
23+
android:
24+
runs-on: ubuntu-latest
25+
env:
26+
ANDROID_NDK_HOME: /usr/local/lib/android/sdk/ndk/28.1.13356709
27+
ANDROID_NDK_ROOT: /usr/local/lib/android/sdk/ndk/28.1.13356709
28+
defaults:
29+
run:
30+
working-directory: gemstone
31+
steps:
32+
- uses: actions/checkout@v6
33+
34+
- name: Free disk space
35+
run: |
36+
df -h
37+
sudo rm -rf /usr/share/dotnet /opt/ghc /opt/hostedtoolcache/CodeQL /usr/local/lib/node_modules
38+
sudo apt-get clean
39+
df -h
40+
41+
- name: Set up JDK 17
42+
uses: actions/setup-java@v5
43+
with:
44+
java-version: "17"
45+
distribution: "zulu"
46+
47+
- name: Setup Android SDK
48+
uses: android-actions/setup-android@v4
49+
with:
50+
packages: 'build-tools;36.0.0 platforms;android-36 ndk;28.1.13356709 system-images;android-29;default;x86_64 emulator'
51+
52+
- name: Setup Rust
53+
uses: ./.github/actions/setup-rust-ci
54+
55+
- name: Setup Gradle
56+
uses: gradle/actions/setup-gradle@v6
57+
58+
- name: Cache AVD
59+
uses: actions/cache@v5
60+
id: avd-cache
61+
with:
62+
path: |
63+
~/.android/avd/*
64+
~/.android/adb*
65+
key: avd-29-2g-${{ runner.os }}
66+
67+
- name: Install Android Targets
68+
run: just install-android-targets
69+
70+
- name: Build Android Bindings
71+
run: just build-android
72+
73+
- name: Enable KVM
74+
run: |
75+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
76+
sudo udevadm control --reload-rules
77+
sudo udevadm trigger --name-match=kvm
78+
79+
- name: Run Android Instrumented Tests
80+
uses: reactivecircus/android-emulator-runner@v2
81+
with:
82+
api-level: 29
83+
arch: x86_64
84+
force-avd-creation: false
85+
disk-size: 2048M
86+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
87+
disable-animations: true
88+
script: cd gemstone/android && ./gradlew connectedDebugAndroidTest
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI - Gemstone iOS
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "gemstone/**"
8+
pull_request:
9+
branches: ["main"]
10+
paths:
11+
- "gemstone/**"
12+
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.ref }}
15+
cancel-in-progress: true
16+
17+
env:
18+
CARGO_TERM_COLOR: always
19+
SCCACHE_GHA_ENABLED: "true"
20+
RUSTC_WRAPPER: "sccache"
21+
22+
jobs:
23+
build_ios:
24+
runs-on: macos-26
25+
defaults:
26+
run:
27+
working-directory: gemstone
28+
steps:
29+
- uses: actions/checkout@v6
30+
31+
- name: Setup Rust
32+
uses: ./.github/actions/setup-rust-ci
33+
34+
- name: Install iOS targets
35+
run: just install-ios-targets
36+
37+
- name: Build iOS
38+
run: just build-ios
39+
40+
- name: Test iOS
41+
run: just test-ios

0 commit comments

Comments
 (0)