Skip to content

Commit 9bf8d80

Browse files
authored
Merge pull request #2 from macalinao/igm/changeset
Rename to Coda, add Quarry client
2 parents ad8d2e2 + 4af0b6f commit 9bf8d80

File tree

292 files changed

+27958
-191
lines changed

Some content is hidden

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

292 files changed

+27958
-191
lines changed

.changeset/early-turtles-joke.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@macalinao/clients-token-metadata": minor
3+
"@macalinao/coda": minor
4+
"@macalinao/codama-instruction-accounts-dedupe-visitor": minor
5+
"@macalinao/codama-renderers-js-esm": minor
6+
---
7+
8+
Rename to Coda

CLAUDE.md

Lines changed: 145 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Grill is a modern Solana development kit monorepo that provides React components and utilities for building Solana applications with automatic account batching and caching. It's built on top of gill-react and integrates with @solana/kit.
7+
Coda is an automated client generation tool for Solana programs. Built on top of [Codama](https://github.com/codama-idl/codama), Coda provides a zero-config CLI that transforms Anchor IDLs into modern TypeScript clients with full type safety and ES modules support.
8+
9+
The monorepo contains:
10+
- **Coda CLI** - The main tool for generating TypeScript clients from Anchor IDLs
11+
- **Codama utilities** - Custom visitors and renderers for enhanced code generation
12+
- **Generated clients** - Pre-built clients for popular Solana programs
813

914
## Technology Stack
1015

11-
- **Package Manager**: Bun (v1.2.19)
16+
- **Package Manager**: Bun (v1.2.20)
1217
- **Build System**: Turbo for monorepo orchestration
13-
- **Framework**: React 19 with TypeScript
14-
- **Solana**: @solana/kit, gill, gill-react
15-
- **State Management**: @tanstack/react-query for caching
16-
- **Routing**: @tanstack/react-router (in example-dapp)
17-
- **Styling**: Tailwind CSS v4 with shadcn/ui components
18+
- **Language**: TypeScript with ES modules
19+
- **Code Generation**: Codama for AST transformations
1820
- **Code Quality**: Biome for formatting, ESLint for linting
19-
- **Testing**: Vitest
21+
- **Testing**: Bun test runner
2022

2123
## Essential Commands
2224

@@ -27,6 +29,11 @@ bun run build # Build all packages
2729
bun run build:watch # Watch mode for all packages
2830
bun run build:watch:packages # Watch mode for packages only
2931

32+
# Code Generation
33+
bun run codegen # Run code generation for all clients
34+
bunx coda generate # Generate client with Coda CLI
35+
bunx coda init # Initialize coda.config.mjs
36+
3037
# Code Quality
3138
bun run lint # Run biome check + eslint
3239
bun run lint:fix # Fix linting issues
@@ -40,65 +47,76 @@ bun test # Run tests directly
4047
bun run changeset # Create changeset for version bumps
4148
bun run ci:publish # Publish packages to npm
4249

43-
# Example App Development
44-
cd apps/example-dapp
45-
bun run dev # Start Vite dev server
46-
bun run build # Build the app
47-
4850
# IMPORTANT: After making code changes
4951
bun run build # Build to check for TypeScript errors
5052
bun run lint:fix # Fix linting and formatting issues
5153
```
5254

53-
## Architecture
54-
55-
### Monorepo Structure
56-
57-
The project uses Bun workspaces with packages in two directories:
58-
- `packages/*` - Core library packages
59-
- `apps/*` - Example applications
60-
61-
### Core Packages
62-
63-
1. **@macalinao/grill** - Main package providing React context and hooks
64-
- `GrillProvider`: Creates DataLoader for batching account requests with sonner toast notifications
65-
- `GrillHeadlessProvider`: Headless version without UI features (for custom implementations)
66-
- `WalletProvider`: Kit wallet integration context
67-
- `useAccount`: Hook for fetching account data with batching
68-
- `useKitWallet`: Access wallet signer and RPC
69-
- Note: sonner is a required peer dependency for transaction toast notifications
70-
71-
2. **@macalinao/solana-batch-accounts-loader** - DataLoader implementation for batching Solana account fetches
72-
73-
3. **@macalinao/wallet-adapter-compat** - Compatibility layer between @solana/wallet-adapter and @solana/kit
55+
## Repository Structure
7456

75-
4. **dataloader-es** - ES module compatible DataLoader implementation
76-
77-
### Provider Hierarchy
78-
79-
When using Grill, providers must be set up in this order:
80-
```tsx
81-
QueryClientProvider
82-
SolanaProvider (gill-react)
83-
ConnectionProvider (@solana/wallet-adapter-react)
84-
WalletProvider (@solana/wallet-adapter-react)
85-
WalletModalProvider
86-
GrillProvider
57+
```
58+
coda/
59+
├── packages/ # Core packages
60+
│ ├── coda/ # Main CLI tool (@macalinao/coda)
61+
│ ├── codama-instruction-accounts-dedupe-visitor/ # Flattens nested accounts
62+
│ └── codama-renderers-js-esm/ # ESM-native renderer
63+
├── clients/ # Generated client libraries
64+
│ └── token-metadata/ # Metaplex Token Metadata client
65+
├── docs/ # Documentation
66+
└── scripts/ # Build and CI scripts
8767
```
8868

89-
### Account Batching Architecture
90-
91-
The core innovation is automatic batching of concurrent account requests:
92-
- Multiple `useAccount` calls in different components are automatically batched
93-
- Uses DataLoader pattern to coalesce requests within a tick
94-
- Single RPC call instead of multiple, improving performance
95-
- Integrated with React Query for caching
96-
97-
### Kit Wallet Integration
98-
99-
Provides two contexts:
100-
1. Account batching context (GrillProvider)
101-
2. Wallet context for TransactionSendingSigner (WalletProvider from grill)
69+
## Core Packages
70+
71+
### 1. **@macalinao/coda** - CLI for client generation
72+
- Zero-config by default (looks for `./target/idl/program.json`)
73+
- Configurable via `coda.config.mjs`
74+
- Generates TypeScript clients with full type safety
75+
- Built on Codama for extensibility
76+
77+
### 2. **@macalinao/codama-instruction-accounts-dedupe-visitor**
78+
- Flattens nested account structures from Anchor IDL
79+
- Preserves relationships through naming conventions
80+
- Updates PDA seeds when accounts are flattened
81+
82+
### 3. **@macalinao/codama-renderers-js-esm**
83+
- ESM-native TypeScript renderer for Codama
84+
- Adds `.js` extensions to all imports
85+
- Removes Node.js-specific environment checks
86+
- Ensures compatibility with `"type": "module"`
87+
88+
### 4. **@macalinao/clients-token-metadata**
89+
- Pre-generated client for Metaplex Token Metadata program
90+
- Includes custom PDAs and type definitions
91+
- Ready-to-use with `@solana/web3.js`
92+
93+
## How Coda Works
94+
95+
1. **Parse IDL**: Reads Anchor IDL file (JSON format)
96+
2. **Create AST**: Converts to Codama's node structure
97+
3. **Apply Visitors**: Transforms the AST (custom PDAs, flattening, etc.)
98+
4. **Generate Code**: Renders TypeScript with ESM support
99+
5. **Output Files**: Creates organized file structure with types, instructions, accounts, etc.
100+
101+
## Configuration (coda.config.mjs)
102+
103+
```javascript
104+
import { defineConfig } from "@macalinao/coda";
105+
import { addPdasVisitor } from "codama";
106+
107+
export default defineConfig({
108+
// Optional: Custom paths
109+
idlPath: "./idls/my_program.json",
110+
outputDir: "./src/generated",
111+
112+
// Optional: Codama visitors for customization
113+
visitors: [
114+
addPdasVisitor({
115+
// Add custom PDAs
116+
})
117+
]
118+
});
119+
```
102120

103121
## Code Style Guidelines
104122

@@ -108,19 +126,13 @@ Provides two contexts:
108126
- Use `import type` for type-only imports (enforced by Biome)
109127
- Arrays use shorthand syntax: `string[]` not `Array<string>`
110128
- **Use double quotes for strings** (not single quotes)
111-
- Follow default Prettier settings
129+
- ES modules with `.js` extensions for imports
112130

113131
### After Making Code Changes
114132
**Always run these commands to ensure code quality:**
115133
1. `bun run build` - Check for TypeScript errors
116134
2. `bun run lint:fix` - Fix linting and formatting issues
117135

118-
### React Components
119-
- Small, focused components
120-
- Use function components with hooks
121-
- Props interfaces should be explicitly defined
122-
- File structure: `components/category/component-name/index.tsx`
123-
124136
### Biome/ESLint Configuration
125137
- No floating promises (must be handled)
126138
- Use const assertions where applicable
@@ -129,42 +141,34 @@ Provides two contexts:
129141
- No double equals (use === instead)
130142
- Imports are auto-organized on save
131143

132-
## Example App (example-dapp)
133-
134-
The example-dapp demonstrates:
135-
- TanStack Router for routing
136-
- shadcn/ui component integration
137-
- Wallet connection with Solana wallet adapter
138-
- Layout system with navigation and sidebar
139-
- Dark mode support
140-
141-
Routes:
142-
- `/` - Home page
143-
- `/dashboard` - Simple dashboard
144-
- `/examples/*` - Examples section with sidebar navigation
145-
146144
## Turborepo Configuration
147145

148146
Tasks are defined in turbo.json:
149147
- `build`: Depends on upstream builds, outputs to `./dist/**`
150148
- `lint`: Depends on upstream builds
151149
- `test`: Depends on build, no caching
150+
- `codegen`: Outputs to `./src/generated/**`, no caching
152151
- Tasks run in topological order respecting dependencies
153152

154-
## Working with Providers
155-
156-
When creating new features that need account data:
157-
1. Ensure component is wrapped in GrillProvider
158-
2. Use `useAccount` hook for fetching account data
159-
3. Account requests are automatically batched
160-
4. React Query handles caching and refetching
161-
162-
## Vendor Documentation
163-
164-
The repository includes vendor documentation at `/docs/vendor/`:
165-
- `gill.md` - Complete documentation for the gill library (Solana client library)
166-
- Includes transaction builders, token operations, and program clients
167-
- Used as the foundation for Solana operations in Grill
153+
## Adding a New Client
154+
155+
1. **Add IDL file**: Place in `clients/[program-name]/idls/`
156+
2. **Create config**: Add `coda.config.mjs` with any custom visitors
157+
3. **Add package.json**: Include build and codegen scripts
158+
4. **Generate client**: Run `bun run codegen`
159+
5. **Build**: Run `bun run build`
160+
161+
Example package.json for a client:
162+
```json
163+
{
164+
"name": "@macalinao/clients-[program-name]",
165+
"scripts": {
166+
"build": "tsc",
167+
"codegen": "coda generate",
168+
"clean": "rm -fr dist/"
169+
}
170+
}
171+
```
168172

169173
## CI/CD
170174

@@ -187,6 +191,51 @@ GitHub Actions workflow runs on push/PR to main:
187191
When creating new packages:
188192
- Use TypeScript directly with `tsc` for building (no tsup/rollup/etc)
189193
- Follow the same structure as existing packages
190-
- Scripts should be: `build`, `build:watch`, `clean`, `typecheck`
194+
- Scripts should be: `build`, `clean`, `lint`, `test`, `codegen` (if applicable)
191195
- All packages use ES modules (`"type": "module"` in package.json)
192-
- Keep package.json scripts simple and consistent
196+
- Keep package.json scripts simple and consistent
197+
198+
## Working with Generated Code
199+
200+
Generated clients provide:
201+
- **Instructions**: Typed builders for all program instructions
202+
- **Accounts**: Decoders and fetchers for all account types
203+
- **Types**: All TypeScript types from the IDL
204+
- **PDAs**: Helper functions for program-derived addresses
205+
- **Errors**: Typed error enums and handlers
206+
207+
Example usage:
208+
```typescript
209+
import { createTransferInstruction } from "./generated";
210+
import { createSolanaRpc } from "@solana/web3.js";
211+
212+
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
213+
const instruction = createTransferInstruction({
214+
source: sourceAddress,
215+
destination: destAddress,
216+
authority: authorityAddress,
217+
amount: 1000n
218+
});
219+
```
220+
221+
## Troubleshooting
222+
223+
### Common Issues
224+
225+
1. **IDL not found**: Ensure Anchor program is built (`anchor build`)
226+
2. **Config not loading**: Check file is named `coda.config.mjs` with `.mjs` extension
227+
3. **Import errors**: Ensure all imports use `.js` extensions for local files
228+
4. **Type errors**: Run `bun run build` to check TypeScript compilation
229+
230+
### Debug Commands
231+
232+
```bash
233+
# Check generated files
234+
ls -la ./src/generated/
235+
236+
# Verify config is valid
237+
node -e "import('./coda.config.mjs').then(c => console.log(c.default))"
238+
239+
# Clean and rebuild
240+
bun run clean && bun run codegen && bun run build
241+
```

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
# Coda
1+
<h1 align="center">
2+
Coda
3+
</h1>
24

5+
<p align="center">
36
Automated client generation for Solana programs.
7+
</p>
8+
9+
<p align="center">
10+
<a href="https://www.npmjs.com/package/@macalinao/coda"><img src="https://img.shields.io/npm/v/@macalinao/coda?logo=npm&color=377CC0" /></a>
11+
<a href="https://www.npmjs.com/package/@macalinao/coda"><img src="https://img.shields.io/npm/dm/@macalinao/coda?color=377CC0" /></a>
12+
</p>
413

514
## Why Coda?
615

@@ -48,10 +57,7 @@ npm install -D @macalinao/coda
4857

4958
```bash
5059
# Using default paths
51-
bunx coda generate
52-
53-
# With custom paths
54-
bunx coda generate --idl ./target/idl/my_program.json --output ./src/generated
60+
coda generate
5561
```
5662

5763
By default, Coda looks for:

biome.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
"includes": [
7474
"**",
7575
"!**/bun.lock",
76-
"!apps/example-dapp/src/routeTree.gen.ts",
77-
"!clients/*/src/generated/**"
76+
"!apps/example-dapp/src/routeTree.gen.ts"
7877
]
7978
},
8079
"assist": {
@@ -100,5 +99,23 @@
10099
"bracketSameLine": false,
101100
"bracketSpacing": true
102101
}
103-
}
102+
},
103+
"overrides": [
104+
{
105+
"includes": ["clients/*/src/generated/**"],
106+
"linter": {
107+
"rules": {
108+
"suspicious": {
109+
"noEmptyInterface": "off"
110+
},
111+
"complexity": {
112+
"noBannedTypes": "off"
113+
},
114+
"correctness": {
115+
"noConstantCondition": "off"
116+
}
117+
}
118+
}
119+
}
120+
]
104121
}

0 commit comments

Comments
 (0)