-
Notifications
You must be signed in to change notification settings - Fork 11
add stablecoin issuance cli #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Architecture Overview | ||
|
|
||
| Mosaic is a TypeScript monorepo for managing Token-2022 extensions on Solana, specifically designed for Stablecoin and Arcade Token use cases. The project uses pnpm workspaces with the following structure: | ||
|
|
||
| - **@mosaic/sdk** (`packages/sdk/`) - Core SDK with token templates and management utilities | ||
| - Uses `gill` library for Solana interactions | ||
| - Provides `Token` class for building token transactions with extensions | ||
| - Contains predefined templates for stablecoin and arcade tokens | ||
| - Token extensions include: Metadata, Pausable, Default Account State, Confidential Balances, Permanent Delegate | ||
| - **@mosaic/cli** (`packages/cli/`) - Command-line interface (scaffolded) | ||
| - **@mosaic/ui** (`packages/ui/`) - Next.js web interface with Tailwind CSS and Radix UI components | ||
|
|
||
| ## Token Types | ||
|
|
||
| ### Stablecoin | ||
|
|
||
| - Default Account State (SRFC blocklist for compliance) | ||
| - Metadata, Confidential Balances, Pausable, Permanent Delegate | ||
|
|
||
| ### Arcade Token | ||
|
|
||
| - Default Account State (SRFC allowlist for programs/users) | ||
| - Metadata (rich gaming metadata), Permanent Delegate, Pausable | ||
|
|
||
| ## Common Development Commands | ||
|
|
||
| ```bash | ||
| # Install dependencies | ||
| pnpm install | ||
|
|
||
| # Development (runs dev for all packages) | ||
| pnpm dev | ||
|
|
||
| # Build all packages | ||
| pnpm build | ||
|
|
||
| # Testing | ||
| pnpm test # Run all tests | ||
| pnpm test:watch # SDK watch mode (in packages/sdk/) | ||
| pnpm test:coverage # SDK coverage (in packages/sdk/) | ||
|
|
||
| # Code quality | ||
| pnpm lint # Lint all packages | ||
| pnpm lint:fix # Fix linting issues | ||
| pnpm format # Format with Prettier | ||
| pnpm format:check # Check formatting | ||
| pnpm type-check # TypeScript checking | ||
| pnpm check # Run format:check + lint + type-check | ||
|
|
||
| # Before committing | ||
| pnpm precommit # format + lint:fix | ||
| ``` | ||
|
|
||
| ## Package-Specific Commands | ||
|
|
||
| ### SDK (packages/sdk/) | ||
|
|
||
| - Uses Jest for testing | ||
| - Main entry point exports `Token` class and templates | ||
| - Test setup in `src/__tests__/setup.ts` | ||
|
|
||
| ### UI (packages/ui/) | ||
|
|
||
| - Next.js 14 with App Router | ||
| - Tailwind CSS + Radix UI components | ||
| - Theme support with next-themes | ||
|
|
||
| ## Development Notes | ||
|
|
||
| - Project is currently scaffolded - implementation depends on Token-2022 program stabilization and SRFC 37 spec | ||
| - Uses `gill` library for Solana RPC interactions | ||
| - All token creation functions return `FullTransaction` objects ready for signing | ||
| - Node.js 18+ and pnpm 9+ required | ||
| - TypeScript 5+ for all packages |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| { | ||
| "name": "@mosaic/cli", | ||
| "version": "0.1.0", | ||
| "description": "Command-line interface for managing Token-2022 tokens with extensions", | ||
| "type": "module", | ||
| "main": "./dist/index.js", | ||
| "bin": { | ||
| "mosaic": "./dist/index.js" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "scripts": { | ||
| "build": "tsc", | ||
| "dev": "tsx src/index.ts", | ||
| "start": "node dist/index.js", | ||
| "test": "echo 'Tests will be implemented'", | ||
| "lint": "eslint src --ext .ts", | ||
| "lint:fix": "eslint src --ext .ts --fix", | ||
| "type-check": "tsc --noEmit", | ||
| "clean": "rm -rf dist" | ||
| }, | ||
| "dependencies": { | ||
| "@mosaic/sdk": "workspace:*", | ||
| "commander": "^12.0.0", | ||
| "chalk": "^5.3.0", | ||
| "ora": "^8.0.1", | ||
| "gill": "^0.10.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.0.0", | ||
| "@typescript-eslint/eslint-plugin": "^8.34.0", | ||
| "@typescript-eslint/parser": "^8.34.0", | ||
| "eslint": "^9.32.0", | ||
| "tsx": "^4.0.0", | ||
| "typescript": "^5.0.0" | ||
| }, | ||
| "keywords": [ | ||
| "solana", | ||
| "token-2022", | ||
| "extensions", | ||
| "cli", | ||
| "stablecoin", | ||
| "arcade-token" | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| import { Command } from 'commander'; | ||
| import chalk from 'chalk'; | ||
| import ora from 'ora'; | ||
| import { createStablecoinInitTransaction } from '@mosaic/sdk'; | ||
| import { createSolanaClient } from '../../utils/rpc.js'; | ||
| import { loadKeypair } from '../../utils/solana.js'; | ||
| import { | ||
| generateKeyPairSigner, | ||
| signTransactionMessageWithSigners, | ||
| type Address, | ||
| } from 'gill'; | ||
|
|
||
| interface StablecoinOptions { | ||
| name: string; | ||
| symbol: string; | ||
| decimals: string; | ||
| uri?: string; | ||
| mintAuthority?: string; | ||
| metadataAuthority?: string; | ||
| pausableAuthority?: string; | ||
| confidentialBalancesAuthority?: string; | ||
| permanentDelegateAuthority?: string; | ||
| mintKeypair?: string; | ||
| rpcUrl?: string; | ||
| keypair?: string; | ||
| } | ||
|
|
||
| export const createStablecoinCommand = new Command('stablecoin') | ||
| .description('Create a new stablecoin with Token-2022 extensions') | ||
| .requiredOption('-n, --name <name>', 'Token name') | ||
| .requiredOption('-s, --symbol <symbol>', 'Token symbol') | ||
| .option('-d, --decimals <decimals>', 'Number of decimals', '6') | ||
| .option('-u, --uri <uri>', 'Metadata URI', '') | ||
| .option( | ||
| '--mint-authority <address>', | ||
| 'Mint authority address (defaults to signer)' | ||
| ) | ||
| .option( | ||
| '--metadata-authority <address>', | ||
| 'Metadata authority address (defaults to mint authority)' | ||
| ) | ||
| .option( | ||
| '--pausable-authority <address>', | ||
| 'Pausable authority address (defaults to mint authority)' | ||
| ) | ||
| .option( | ||
| '--confidential-balances-authority <address>', | ||
| 'Confidential balances authority address (defaults to mint authority)' | ||
| ) | ||
| .option( | ||
| '--permanent-delegate-authority <address>', | ||
| 'Permanent delegate authority address (defaults to mint authority)' | ||
| ) | ||
| .option( | ||
| '--mint-keypair <path>', | ||
| 'Path to mint keypair file (generates new one if not provided)' | ||
| ) | ||
| .action(async (options: StablecoinOptions, command) => { | ||
| const spinner = ora('Creating stablecoin...').start(); | ||
|
|
||
| try { | ||
| // Get global options from parent command | ||
| const parentOpts = command.parent?.opts() || {}; | ||
| const rpcUrl = options.rpcUrl || parentOpts.rpcUrl; | ||
| const keypairPath = options.keypair || parentOpts.keypair; | ||
|
|
||
| // Create Solana client with sendAndConfirmTransaction | ||
| const { rpc, sendAndConfirmTransaction } = createSolanaClient(rpcUrl); | ||
|
|
||
| // Load signer keypair | ||
| const signerKeypair = await loadKeypair(keypairPath); | ||
| const signerAddress = signerKeypair.address; | ||
|
|
||
| spinner.text = 'Loading keypairs...'; | ||
|
|
||
| // Generate or load mint keypair | ||
| let mintKeypair; | ||
| if (options.mintKeypair) { | ||
| mintKeypair = await loadKeypair(options.mintKeypair); | ||
| } else { | ||
| mintKeypair = await generateKeyPairSigner(); | ||
| } | ||
|
|
||
| // Parse decimals | ||
| const decimals = parseInt(options.decimals, 10); | ||
| if (isNaN(decimals) || decimals < 0 || decimals > 9) { | ||
| throw new Error('Decimals must be a number between 0 and 9'); | ||
| } | ||
|
|
||
| // Set authorities (default to signer if not provided) | ||
| const mintAuthority = (options.mintAuthority || signerAddress) as Address; | ||
| const metadataAuthority = (options.metadataAuthority || | ||
| mintAuthority) as Address; | ||
| const pausableAuthority = (options.pausableAuthority || | ||
| mintAuthority) as Address; | ||
| const confidentialBalancesAuthority = | ||
| (options.confidentialBalancesAuthority || mintAuthority) as Address; | ||
| const permanentDelegateAuthority = (options.permanentDelegateAuthority || | ||
| mintAuthority) as Address; | ||
|
|
||
| spinner.text = 'Building transaction...'; | ||
|
|
||
| // Create stablecoin using Token class | ||
| const transaction = await createStablecoinInitTransaction( | ||
| rpc, | ||
| options.name, | ||
| options.symbol, | ||
| decimals, | ||
| options.uri || '', | ||
| mintAuthority, | ||
| mintKeypair, | ||
| signerKeypair, | ||
| metadataAuthority, | ||
| pausableAuthority, | ||
| confidentialBalancesAuthority, | ||
| permanentDelegateAuthority | ||
| ); | ||
|
|
||
| spinner.text = 'Signing transaction...'; | ||
|
|
||
| // Sign the transaction (buildTransaction includes signers but doesn't auto-sign) | ||
| const signedTransaction = | ||
| await signTransactionMessageWithSigners(transaction); | ||
|
|
||
| spinner.text = 'Sending transaction...'; | ||
|
|
||
| // Send and confirm transaction | ||
| const signature = await sendAndConfirmTransaction(signedTransaction); | ||
|
|
||
| spinner.succeed('Stablecoin created successfully!'); | ||
|
|
||
| // Display results | ||
| console.log(chalk.green('β Stablecoin Creation Successful')); | ||
| console.log(chalk.cyan('π Details:')); | ||
| console.log(` ${chalk.bold('Name:')} ${options.name}`); | ||
| console.log(` ${chalk.bold('Symbol:')} ${options.symbol}`); | ||
| console.log(` ${chalk.bold('Decimals:')} ${decimals}`); | ||
| console.log(` ${chalk.bold('Mint Address:')} ${mintKeypair.address}`); | ||
| console.log(` ${chalk.bold('Transaction:')} ${signature}`); | ||
|
|
||
| console.log(chalk.cyan('π Authorities:')); | ||
| console.log(` ${chalk.bold('Mint Authority:')} ${mintAuthority}`); | ||
| console.log( | ||
| ` ${chalk.bold('Metadata Authority:')} ${metadataAuthority}` | ||
| ); | ||
| console.log( | ||
| ` ${chalk.bold('Pausable Authority:')} ${pausableAuthority}` | ||
| ); | ||
| console.log( | ||
| ` ${chalk.bold('Confidential Balances Authority:')} ${confidentialBalancesAuthority}` | ||
| ); | ||
| console.log( | ||
| ` ${chalk.bold('Permanent Delegate Authority:')} ${permanentDelegateAuthority}` | ||
| ); | ||
|
|
||
| console.log(chalk.cyan('π‘οΈ Token Extensions:')); | ||
| console.log(` ${chalk.green('β')} Metadata`); | ||
| console.log(` ${chalk.green('β')} Pausable`); | ||
| console.log(` ${chalk.green('β')} Default Account State (Blocklist)`); | ||
| console.log(` ${chalk.green('β')} Confidential Balances`); | ||
| console.log(` ${chalk.green('β')} Permanent Delegate`); | ||
|
|
||
| if (options.uri) { | ||
| console.log(`\\n${chalk.bold('Metadata URI:')} ${options.uri}`); | ||
| } | ||
| } catch (error) { | ||
| spinner.fail('Failed to create stablecoin'); | ||
| console.error( | ||
| chalk.red('\\nβ Error:'), | ||
| error instanceof Error ? error.message : 'Unknown error' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| import { Command } from 'commander'; | ||
| import { createStablecoinCommand } from './commands/create/stablecoin.js'; | ||
|
|
||
| const program = new Command(); | ||
|
|
||
| program | ||
| .name('mosaic') | ||
| .description('CLI for managing Token-2022 tokens with extensions') | ||
| .version('0.1.0'); | ||
|
|
||
| // Create command group | ||
| const createCommand = program | ||
| .command('create') | ||
| .description('Create new tokens with Token-2022 extensions'); | ||
|
|
||
| // Add stablecoin creation command | ||
| createCommand.addCommand(createStablecoinCommand); | ||
|
|
||
| // Global options | ||
| program | ||
| .option('--rpc-url <url>', 'Solana RPC URL', 'https://api.devnet.solana.com') | ||
| .option( | ||
| '--keypair <path>', | ||
| 'Path to keypair file (defaults to Solana CLI default)' | ||
| ); | ||
|
|
||
| program.parse(process.argv); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { | ||
| createSolanaRpc, | ||
| createSolanaClient as createClient, | ||
| type Rpc, | ||
| type SolanaRpcApi, | ||
| } from 'gill'; | ||
| import { getSolanaConfig } from './solana.js'; | ||
|
|
||
| export function createRpcClient(rpcUrl?: string): Rpc<SolanaRpcApi> { | ||
| const url = | ||
| rpcUrl || | ||
| getSolanaConfig()?.json_rpc_url || | ||
| 'https://api.devnet.solana.com'; | ||
| return createSolanaRpc(url); | ||
| } | ||
|
|
||
| export function createSolanaClient(rpcUrl?: string) { | ||
| const url = | ||
| rpcUrl || | ||
| getSolanaConfig()?.json_rpc_url || | ||
| 'https://api.devnet.solana.com'; | ||
| return createClient({ urlOrMoniker: url }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.