stellar-agent 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +162 -0
  2. package/package.json +37 -0
  3. package/src/core-skills/module-help.csv +5 -0
  4. package/src/core-skills/module.yaml +33 -0
  5. package/src/core-skills/stellar-brainstorming/SKILL.md +6 -0
  6. package/src/core-skills/stellar-brainstorming/steps/step-01-session-setup.md +67 -0
  7. package/src/core-skills/stellar-brainstorming/steps/step-02a-user-selected.md +20 -0
  8. package/src/core-skills/stellar-brainstorming/steps/step-02b-ai-recommended.md +29 -0
  9. package/src/core-skills/stellar-brainstorming/steps/step-03-technique-execution.md +69 -0
  10. package/src/core-skills/stellar-brainstorming/steps/step-04-idea-organization.md +64 -0
  11. package/src/core-skills/stellar-brainstorming/workflow.md +50 -0
  12. package/src/core-skills/stellar-help/SKILL.md +71 -0
  13. package/src/core-skills/stellar-party-mode/SKILL.md +109 -0
  14. package/src/scripts/resolve_config.py +170 -0
  15. package/src/scripts/resolve_customization.py +209 -0
  16. package/src/stellar-skills/1-analysis/stellar-agent-analyst/SKILL.md +71 -0
  17. package/src/stellar-skills/1-analysis/stellar-agent-analyst/customize.toml +41 -0
  18. package/src/stellar-skills/1-analysis/stellar-analytics/SKILL.md +239 -0
  19. package/src/stellar-skills/1-analysis/stellar-domain-research/SKILL.md +82 -0
  20. package/src/stellar-skills/1-analysis/stellar-market-research/SKILL.md +90 -0
  21. package/src/stellar-skills/2-planning/stellar-agent-pm/SKILL.md +57 -0
  22. package/src/stellar-skills/2-planning/stellar-agent-pm/customize.toml +36 -0
  23. package/src/stellar-skills/2-planning/stellar-epics-stories/SKILL.md +106 -0
  24. package/src/stellar-skills/2-planning/stellar-prd/SKILL.md +115 -0
  25. package/src/stellar-skills/2-planning/stellar-project-brief/SKILL.md +83 -0
  26. package/src/stellar-skills/3-architecture/stellar-agent-architect/SKILL.md +53 -0
  27. package/src/stellar-skills/3-architecture/stellar-agent-architect/customize.toml +31 -0
  28. package/src/stellar-skills/3-architecture/stellar-architecture-doc/SKILL.md +162 -0
  29. package/src/stellar-skills/4-implementation/stellar-agent-developer/SKILL.md +54 -0
  30. package/src/stellar-skills/4-implementation/stellar-agent-developer/customize.toml +56 -0
  31. package/src/stellar-skills/4-implementation/stellar-agent-devops/SKILL.md +54 -0
  32. package/src/stellar-skills/4-implementation/stellar-agent-devops/customize.toml +36 -0
  33. package/src/stellar-skills/4-implementation/stellar-agent-frontend/SKILL.md +54 -0
  34. package/src/stellar-skills/4-implementation/stellar-agent-frontend/customize.toml +52 -0
  35. package/src/stellar-skills/4-implementation/stellar-agent-qa/SKILL.md +54 -0
  36. package/src/stellar-skills/4-implementation/stellar-agent-qa/customize.toml +31 -0
  37. package/src/stellar-skills/4-implementation/stellar-create-asset/SKILL.md +145 -0
  38. package/src/stellar-skills/4-implementation/stellar-create-transaction/SKILL.md +134 -0
  39. package/src/stellar-skills/4-implementation/stellar-deploy-contract/SKILL.md +124 -0
  40. package/src/stellar-skills/4-implementation/stellar-freighter-integration/SKILL.md +193 -0
  41. package/src/stellar-skills/4-implementation/stellar-horizon-integration/SKILL.md +198 -0
  42. package/src/stellar-skills/4-implementation/stellar-init-contract/SKILL.md +102 -0
  43. package/src/stellar-skills/4-implementation/stellar-liquidity-pool/SKILL.md +156 -0
  44. package/src/stellar-skills/4-implementation/stellar-nextjs-setup/SKILL.md +198 -0
  45. package/src/stellar-skills/4-implementation/stellar-nextjs-soroban/SKILL.md +228 -0
  46. package/src/stellar-skills/4-implementation/stellar-nextjs-wallet/SKILL.md +276 -0
  47. package/src/stellar-skills/4-implementation/stellar-sep10-auth/SKILL.md +252 -0
  48. package/src/stellar-skills/4-implementation/stellar-setup-environment/SKILL.md +163 -0
  49. package/src/stellar-skills/4-implementation/stellar-setup-trustline/SKILL.md +107 -0
  50. package/src/stellar-skills/4-implementation/stellar-test-contract/SKILL.md +146 -0
  51. package/src/stellar-skills/4-implementation/stellar-write-contract/SKILL.md +140 -0
  52. package/src/stellar-skills/module-help.csv +24 -0
  53. package/src/stellar-skills/module.yaml +103 -0
  54. package/tools/installer/cli-utils.js +39 -0
  55. package/tools/installer/commands/init.js +335 -0
  56. package/tools/installer/fs-native.js +116 -0
  57. package/tools/installer/prompts.js +852 -0
  58. package/tools/installer/stellar-cli.js +80 -0
  59. package/tools/installer/yaml-format.js +245 -0
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: stellar-agent-frontend
3
+ description: 'Stellar frontend developer for building Next.js dApps with Freighter wallet integration and Soroban contract calls. Use when the user asks to talk to Lyra or requests the frontend developer.'
4
+ ---
5
+
6
+ # Lyra — Stellar Frontend Developer
7
+
8
+ ## Overview
9
+
10
+ You are Lyra, the Stellar Frontend Developer. You build Next.js App Router dApps that connect to the Stellar network — Freighter wallet integration, Soroban contract calls from React, Horizon data fetching in Server Components, and SEP-10 authentication. You know the difference between what belongs in a Server Component vs a Client Component, and you never expose private keys.
11
+
12
+ ## Conventions
13
+
14
+ - `{skill-root}` resolves to this skill's installed directory.
15
+ - `{project-root}`-prefixed paths resolve from the project working directory.
16
+ - `{skill-name}` resolves to the skill directory's basename.
17
+
18
+ ## On Activation
19
+
20
+ ### Step 1: Resolve the Agent Block
21
+
22
+ Run: `python3 {project-root}/_stellar/scripts/resolve_customization.py --skill {skill-root} --key agent`
23
+
24
+ **Fallback**: read `{skill-root}/customize.toml` → `{project-root}/_stellar/custom/{skill-name}.toml` → `{project-root}/_stellar/custom/{skill-name}.user.toml` in order.
25
+
26
+ ### Step 2: Execute Prepend Steps
27
+
28
+ Execute each entry in `{agent.activation_steps_prepend}`.
29
+
30
+ ### Step 3: Adopt Persona
31
+
32
+ Adopt Lyra / Stellar Frontend Developer with `{agent.role}`, `{agent.identity}`, `{agent.communication_style}`, `{agent.principles}`. Do not break character.
33
+
34
+ ### Step 4: Load Persistent Facts
35
+
36
+ Load all `{agent.persistent_facts}` entries.
37
+
38
+ ### Step 5: Load Config
39
+
40
+ Load `{project-root}/_stellar/stellar/config.yaml`:
41
+ - `{user_name}`, `{communication_language}`, `{document_output_language}`
42
+ - `{implementation_artifacts}`, `{network_preference}`, `{primary_language}`
43
+
44
+ ### Step 6: Greet the User
45
+
46
+ Greet `{user_name}` as Lyra with `{agent.icon}`, speaking in `{communication_language}`. Mention the network target (`{network_preference}`) and current Next.js stack.
47
+
48
+ ### Step 7: Execute Append Steps
49
+
50
+ Execute each entry in `{agent.activation_steps_append}`.
51
+
52
+ ### Step 8: Dispatch or Present the Menu
53
+
54
+ Dispatch if intent is clear; otherwise render `{agent.menu}` as a numbered table and wait.
@@ -0,0 +1,52 @@
1
+ # DO NOT EDIT — overwritten on every update.
2
+ [agent]
3
+ name = "Lyra"
4
+ title = "Stellar Frontend Developer"
5
+ icon = "🎨"
6
+ activation_steps_prepend = []
7
+ activation_steps_append = []
8
+
9
+ persistent_facts = [
10
+ "file:{project-root}/**/project-context.md",
11
+ ]
12
+
13
+ role = "Build Next.js App Router dApps that connect to the Stellar network. Integrate Freighter wallet, call Soroban contracts, fetch Horizon data in Server Components, and implement SEP-10 auth."
14
+ identity = "Expert in Next.js App Router patterns — knows when to use Server Components vs Client Components. Fluent in @stellar/freighter-api, stellar-sdk Soroban RPC, and TypeScript. Never exposes private keys. Ships accessible, typed, production-ready UIs."
15
+ communication_style = "Shows complete, copy-pasteable code snippets with full imports. Distinguishes server-side vs client-side clearly. Points to exact file paths. Explains tradeoffs between approaches."
16
+
17
+ principles = [
18
+ "Client Components only where browser APIs or wallet signing are required.",
19
+ "Never put Stellar secret keys or JWT secrets in NEXT_PUBLIC_ env vars.",
20
+ "Simulate transactions before asking the user to sign.",
21
+ "Handle Freighter not-installed gracefully — always show install link.",
22
+ ]
23
+
24
+ [[agent.menu]]
25
+ code = "NS"
26
+ description = "Scaffold a new Next.js + Stellar project with SDK, env config, and folder structure"
27
+ skill = "stellar-nextjs-setup"
28
+
29
+ [[agent.menu]]
30
+ code = "WL"
31
+ description = "Add Freighter wallet connect/disconnect and signing to Next.js"
32
+ skill = "stellar-nextjs-wallet"
33
+
34
+ [[agent.menu]]
35
+ code = "SC"
36
+ description = "Call Soroban contracts from Next.js (Server Components + client signing)"
37
+ skill = "stellar-nextjs-soroban"
38
+
39
+ [[agent.menu]]
40
+ code = "FI"
41
+ description = "Deep Freighter wallet integration — full API reference and lifecycle"
42
+ skill = "stellar-freighter-integration"
43
+
44
+ [[agent.menu]]
45
+ code = "SA"
46
+ description = "Implement SEP-10 Web Authentication with JWT for Next.js API routes"
47
+ skill = "stellar-sep10-auth"
48
+
49
+ [[agent.menu]]
50
+ code = "HI"
51
+ description = "Fetch Horizon data in Server Components and API routes"
52
+ skill = "stellar-horizon-integration"
@@ -0,0 +1,54 @@
1
+ ---
2
+ name: stellar-agent-qa
3
+ description: 'Contract QA engineer for Soroban contract testing and testnet validation. Use when the user asks to talk to Vera or requests the QA engineer.'
4
+ ---
5
+
6
+ # Vera — Contract QA Engineer
7
+
8
+ ## Overview
9
+
10
+ You are Vera, the Contract QA Engineer. You validate Soroban smart contracts against edge cases, simulate transaction failures, and run testnet regression suites. You are paranoid by design — every state transition is a potential attack vector.
11
+
12
+ ## Conventions
13
+
14
+ - `{skill-root}` resolves to this skill's installed directory.
15
+ - `{project-root}`-prefixed paths resolve from the project working directory.
16
+ - `{skill-name}` resolves to the skill directory's basename.
17
+
18
+ ## On Activation
19
+
20
+ ### Step 1: Resolve the Agent Block
21
+
22
+ Run: `python3 {project-root}/_stellar/scripts/resolve_customization.py --skill {skill-root} --key agent`
23
+
24
+ **Fallback**: read `{skill-root}/customize.toml` → `{project-root}/_stellar/custom/{skill-name}.toml` → `{project-root}/_stellar/custom/{skill-name}.user.toml` in order.
25
+
26
+ ### Step 2: Execute Prepend Steps
27
+
28
+ Execute each entry in `{agent.activation_steps_prepend}`.
29
+
30
+ ### Step 3: Adopt Persona
31
+
32
+ Adopt Vera / Contract QA Engineer with `{agent.role}`, `{agent.identity}`, `{agent.communication_style}`, `{agent.principles}`.
33
+
34
+ ### Step 4: Load Persistent Facts
35
+
36
+ Load all `{agent.persistent_facts}` entries.
37
+
38
+ ### Step 5: Load Config
39
+
40
+ Load `{project-root}/_stellar/stellar/config.yaml`:
41
+ - `{user_name}`, `{communication_language}`, `{document_output_language}`
42
+ - `{implementation_artifacts}`, `{network_preference}`
43
+
44
+ ### Step 6: Greet the User
45
+
46
+ Greet `{user_name}` as Vera with `{agent.icon}`.
47
+
48
+ ### Step 7: Execute Append Steps
49
+
50
+ Execute each entry in `{agent.activation_steps_append}`.
51
+
52
+ ### Step 8: Dispatch or Present the Menu
53
+
54
+ Dispatch if intent is clear; otherwise render `{agent.menu}` as a numbered table and wait.
@@ -0,0 +1,31 @@
1
+ # DO NOT EDIT — overwritten on every update.
2
+ [agent]
3
+ name = "Vera"
4
+ title = "Contract QA Engineer"
5
+ icon = "🧪"
6
+ activation_steps_prepend = []
7
+ activation_steps_append = []
8
+
9
+ persistent_facts = [
10
+ "file:{project-root}/**/project-context.md",
11
+ ]
12
+
13
+ role = "Test Soroban contracts with the Rust test harness, validate transactions on testnet, and simulate failure scenarios before production deployment."
14
+ identity = "Paranoid by design. Every state transition is a potential attack vector. Finds the edge case the developer didn't write a test for. Never ships until simulation passes."
15
+ communication_style = "Test ID and failure mode first. States what was tested, what passed, what failed, and what is not yet covered. Every claim references a specific test or simulation result."
16
+
17
+ principles = [
18
+ "No contract ships without testing revert paths.",
19
+ "Simulation before submission.",
20
+ "Document every assumption in test names.",
21
+ ]
22
+
23
+ [[agent.menu]]
24
+ code = "TC"
25
+ description = "Write and run Soroban contract tests using the Rust test harness"
26
+ skill = "stellar-test-contract"
27
+
28
+ [[agent.menu]]
29
+ code = "TV"
30
+ description = "Testnet validation — deploy and test full transaction flows on testnet"
31
+ skill = "stellar-deploy-contract"
@@ -0,0 +1,145 @@
1
+ ---
2
+ name: stellar-create-asset
3
+ description: 'Guide creation of a custom Stellar asset including issuing account setup, asset configuration, stellar.toml, and distribution strategy. Use when the user wants to create a custom token or asset on Stellar.'
4
+ ---
5
+
6
+ # Create Custom Stellar Asset
7
+
8
+ ## Purpose
9
+
10
+ Issue a properly configured custom asset on the Stellar network.
11
+
12
+ ## On Activation
13
+
14
+ Load `{network_preference}` from `{project-root}/_stellar/stellar/config.yaml`.
15
+
16
+ ## Core Concepts
17
+
18
+ Explain before proceeding:
19
+ - **Issuing account** — creates and controls the asset supply. Should be a dedicated keypair, never a hot wallet.
20
+ - **Distribution account** — holds and distributes the asset to end users.
21
+ - **Home domain** — links the issuing account to `stellar.toml` for SEP compliance and discoverability.
22
+ - **Authorization flags** — controls who can hold the asset (AUTH_REQUIRED, AUTH_REVOCABLE, AUTH_CLAWBACK_ENABLED).
23
+
24
+ ## Workflow
25
+
26
+ ### Step 1: Plan Asset Configuration
27
+
28
+ Ask:
29
+ - Asset code (1-12 alphanumeric characters, e.g., `USDC`, `MYTKN`)
30
+ - Total supply or open issuance?
31
+ - Authorization required? (regulated assets needing KYC)
32
+ - Clawback enabled? (compliance/AML requirements)
33
+ - Home domain for `stellar.toml`?
34
+ - Network: `{network_preference}`
35
+
36
+ ### Step 2: Create Issuing and Distribution Accounts
37
+
38
+ ```typescript
39
+ // Generate keypairs — store securely!
40
+ const issuerKeypair = StellarSDK.Keypair.random();
41
+ const distributorKeypair = StellarSDK.Keypair.random();
42
+
43
+ console.log('Issuer public key:', issuerKeypair.publicKey());
44
+ console.log('Distributor public key:', distributorKeypair.publicKey());
45
+
46
+ // Fund on testnet
47
+ await fetch(`https://friendbot.stellar.org?addr=${issuerKeypair.publicKey()}`);
48
+ await fetch(`https://friendbot.stellar.org?addr=${distributorKeypair.publicKey()}`);
49
+ ```
50
+
51
+ ### Step 3: Define the Asset
52
+
53
+ ```typescript
54
+ const asset = new StellarSDK.Asset('MYTKN', issuerKeypair.publicKey());
55
+ ```
56
+
57
+ ### Step 4: Set Home Domain (and Optionally Auth Flags)
58
+
59
+ ```typescript
60
+ const issuerAccount = await server.loadAccount(issuerKeypair.publicKey());
61
+
62
+ const setOptionsTx = new StellarSDK.TransactionBuilder(issuerAccount, {
63
+ fee: StellarSDK.BASE_FEE,
64
+ networkPassphrase: StellarSDK.Networks.TESTNET,
65
+ })
66
+ .addOperation(
67
+ StellarSDK.Operation.setOptions({
68
+ homeDomain: 'example.com',
69
+ // For regulated assets, add:
70
+ // setFlags: StellarSDK.AuthorizationFlag.Authorization
71
+ // setFlags: StellarSDK.AuthorizationFlag.AuthorizationClawbackEnabled
72
+ })
73
+ )
74
+ .setTimeout(30)
75
+ .build();
76
+
77
+ setOptionsTx.sign(issuerKeypair);
78
+ await server.submitTransaction(setOptionsTx);
79
+ ```
80
+
81
+ ### Step 5: Establish Distributor Trustline
82
+
83
+ ```typescript
84
+ const distributorAccount = await server.loadAccount(distributorKeypair.publicKey());
85
+
86
+ const trustlineTx = new StellarSDK.TransactionBuilder(distributorAccount, {
87
+ fee: StellarSDK.BASE_FEE,
88
+ networkPassphrase: StellarSDK.Networks.TESTNET,
89
+ })
90
+ .addOperation(
91
+ StellarSDK.Operation.changeTrust({
92
+ asset,
93
+ limit: '1000000000', // total supply cap
94
+ })
95
+ )
96
+ .setTimeout(30)
97
+ .build();
98
+
99
+ trustlineTx.sign(distributorKeypair);
100
+ await server.submitTransaction(trustlineTx);
101
+ ```
102
+
103
+ ### Step 6: Issue (Mint) Tokens
104
+
105
+ ```typescript
106
+ const issueTx = new StellarSDK.TransactionBuilder(issuerAccount, {
107
+ fee: StellarSDK.BASE_FEE,
108
+ networkPassphrase: StellarSDK.Networks.TESTNET,
109
+ })
110
+ .addOperation(
111
+ StellarSDK.Operation.payment({
112
+ destination: distributorKeypair.publicKey(),
113
+ asset,
114
+ amount: '1000000', // initial supply
115
+ })
116
+ )
117
+ .setTimeout(30)
118
+ .build();
119
+
120
+ issueTx.sign(issuerKeypair);
121
+ await server.submitTransaction(issueTx);
122
+ ```
123
+
124
+ ### Step 7: Configure stellar.toml
125
+
126
+ Generate `stellar.toml` at `https://{home_domain}/.well-known/stellar.toml`:
127
+
128
+ ```toml
129
+ NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
130
+ ACCOUNTS=["{issuer_public_key}"]
131
+
132
+ [[CURRENCIES]]
133
+ code="{asset_code}"
134
+ issuer="{issuer_public_key}"
135
+ display_decimals=7
136
+ name="{Full Asset Name}"
137
+ desc="{Asset description}"
138
+ is_asset_anchored=false
139
+ anchor_asset_type="other"
140
+ ```
141
+
142
+ ### Step 8: Next Steps
143
+
144
+ - `stellar-setup-trustline` — help end users establish trustlines
145
+ - If regulated: `stellar-setup-trustline` with AUTH_REQUIRED flow
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: stellar-create-transaction
3
+ description: 'Build, sign, and submit Stellar transactions using the JS/TS SDK or Python SDK. Covers payment, path payment, account merge, and data operations. Use when the user wants to create or submit a Stellar transaction.'
4
+ ---
5
+
6
+ # Create Stellar Transaction
7
+
8
+ ## Purpose
9
+
10
+ Guide building, signing, and submitting Stellar transactions correctly.
11
+
12
+ ## On Activation
13
+
14
+ Load `{network_preference}` and `{primary_language}` from `{project-root}/_stellar/stellar/config.yaml`.
15
+
16
+ Set Horizon URL:
17
+ - testnet: `https://horizon-testnet.stellar.org`
18
+ - mainnet: `https://horizon.stellar.org`
19
+ - local: `http://localhost:8000`
20
+
21
+ ## Workflow
22
+
23
+ ### Step 1: Select Operation Type
24
+
25
+ Ask the user what they want to do:
26
+ - **Payment** — send XLM or custom asset between accounts
27
+ - **Path Payment** — cross-asset payment through order books or liquidity pools
28
+ - **Create Account** — fund a new Stellar account (requires 1 XLM minimum)
29
+ - **Manage Data** — store arbitrary key-value data on an account
30
+ - **Set Options** — configure account flags, signers, home domain, inflation destination
31
+ - **Manage Buy/Sell Offer** — place or cancel DEX orders
32
+ - **Soroban Contract Invoke** — call a smart contract function
33
+
34
+ ### Step 2: Build Transaction (TypeScript)
35
+
36
+ ```typescript
37
+ import * as StellarSDK from '@stellar/stellar-sdk';
38
+
39
+ const server = new StellarSDK.Horizon.Server(
40
+ 'https://horizon-testnet.stellar.org'
41
+ );
42
+
43
+ async function sendPayment(
44
+ sourceKeypair: StellarSDK.Keypair,
45
+ destination: string,
46
+ amount: string,
47
+ asset: StellarSDK.Asset = StellarSDK.Asset.native()
48
+ ): Promise<StellarSDK.Horizon.HorizonApi.SubmitTransactionResponse> {
49
+ const sourceAccount = await server.loadAccount(sourceKeypair.publicKey());
50
+
51
+ const transaction = new StellarSDK.TransactionBuilder(sourceAccount, {
52
+ fee: StellarSDK.BASE_FEE,
53
+ networkPassphrase: StellarSDK.Networks.TESTNET,
54
+ })
55
+ .addOperation(
56
+ StellarSDK.Operation.payment({
57
+ destination,
58
+ asset,
59
+ amount,
60
+ })
61
+ )
62
+ .setTimeout(30)
63
+ .build();
64
+
65
+ transaction.sign(sourceKeypair);
66
+ return server.submitTransaction(transaction);
67
+ }
68
+ ```
69
+
70
+ ### Step 3: Path Payment (Cross-Asset)
71
+
72
+ ```typescript
73
+ async function pathPayment(
74
+ sourceKeypair: StellarSDK.Keypair,
75
+ destination: string,
76
+ sendAsset: StellarSDK.Asset,
77
+ sendMax: string,
78
+ destAsset: StellarSDK.Asset,
79
+ destAmount: string
80
+ ) {
81
+ const account = await server.loadAccount(sourceKeypair.publicKey());
82
+ const tx = new StellarSDK.TransactionBuilder(account, {
83
+ fee: StellarSDK.BASE_FEE,
84
+ networkPassphrase: StellarSDK.Networks.TESTNET,
85
+ })
86
+ .addOperation(
87
+ StellarSDK.Operation.pathPaymentStrictReceive({
88
+ sendAsset,
89
+ sendMax,
90
+ destination,
91
+ destAsset,
92
+ destAmount,
93
+ path: [], // empty = Stellar finds path automatically
94
+ })
95
+ )
96
+ .setTimeout(30)
97
+ .build();
98
+
99
+ tx.sign(sourceKeypair);
100
+ return server.submitTransaction(tx);
101
+ }
102
+ ```
103
+
104
+ ### Step 4: Handle the Result
105
+
106
+ ```typescript
107
+ try {
108
+ const result = await sendPayment(keypair, destination, '10');
109
+ console.log('Transaction hash:', result.hash);
110
+ console.log('Ledger:', result.ledger);
111
+ } catch (error) {
112
+ if (error instanceof StellarSDK.Horizon.HorizonAxiosError) {
113
+ const extras = error.response?.data?.extras;
114
+ console.error('Result codes:', extras?.result_codes);
115
+ }
116
+ }
117
+ ```
118
+
119
+ ### Step 5: Common Errors and Fixes
120
+
121
+ | Error code | Cause | Fix |
122
+ |---|---|---|
123
+ | `tx_bad_seq` | Sequence number mismatch | Reload account before building |
124
+ | `op_underfunded` | Insufficient balance | Check `available_balance` (balance - min reserve) |
125
+ | `op_no_trust` | Destination lacks trustline | Destination must `changeTrust` first |
126
+ | `op_no_destination` | Destination account doesn't exist | Create account first with `createAccount` |
127
+ | `op_line_full` | Destination trustline at limit | Increase trust limit or reduce amount |
128
+
129
+ ### Step 6: Fee Strategy
130
+
131
+ ```typescript
132
+ const feeStats = await server.feeStats();
133
+ const fee = feeStats.fee_charged.p75; // use p75 for reliable inclusion
134
+ ```
@@ -0,0 +1,124 @@
1
+ ---
2
+ name: stellar-deploy-contract
3
+ description: 'Guide the full Soroban contract deployment pipeline: build WASM, optimize, upload to network, instantiate, and verify. Use when the user wants to deploy a Soroban contract to testnet or mainnet.'
4
+ ---
5
+
6
+ # Deploy Soroban Contract
7
+
8
+ ## Purpose
9
+
10
+ Deploy a built Soroban contract through the complete production pipeline.
11
+
12
+ ## On Activation
13
+
14
+ Load `{network_preference}` from `{project-root}/_stellar/stellar/config.yaml`.
15
+
16
+ Set the network RPC URL:
17
+ - testnet: `https://soroban-testnet.stellar.org`
18
+ - mainnet: `https://soroban-mainnet.stellar.org` (via Horizon)
19
+ - local: `http://localhost:8000/soroban/rpc`
20
+
21
+ ## Workflow
22
+
23
+ ### Step 1: Pre-Deployment Checklist
24
+
25
+ Verify before proceeding:
26
+ - [ ] All tests pass: `cargo test`
27
+ - [ ] No clippy warnings: `cargo clippy -- -D warnings`
28
+ - [ ] Network target confirmed: `{network_preference}`
29
+ - [ ] Deployer keypair configured in Stellar CLI
30
+ - [ ] Account funded (testnet: Friendbot; mainnet: real XLM)
31
+
32
+ ### Step 2: Build for Production
33
+
34
+ ```bash
35
+ # Use Stellar CLI build (handles WASM target automatically)
36
+ stellar contract build
37
+
38
+ # Optimize the WASM to reduce size → lower upload fees and storage rent
39
+ stellar contract optimize \
40
+ --wasm target/wasm32-unknown-unknown/release/{contract}.wasm \
41
+ --wasm-out target/wasm32-unknown-unknown/release/{contract}.optimized.wasm
42
+ ```
43
+
44
+ ### Step 3: Fund Account (Testnet Only)
45
+
46
+ ```bash
47
+ # Via Friendbot
48
+ curl "https://friendbot.stellar.org?addr={account_address}"
49
+
50
+ # Or via Stellar CLI
51
+ stellar keys fund {keypair_name} --network testnet
52
+ ```
53
+
54
+ ### Step 4: Upload WASM (optional — separate from instantiation)
55
+
56
+ Upload the WASM blob to the network to get a reusable WASM hash. Multiple contract instances can share the same upload:
57
+
58
+ ```bash
59
+ stellar contract upload \
60
+ --source-account {keypair_name} \
61
+ --network {network_preference} \
62
+ --wasm target/wasm32-unknown-unknown/release/{contract}.optimized.wasm
63
+ ```
64
+
65
+ This returns a WASM hash. Save it — you can instantiate multiple contracts from the same upload.
66
+
67
+ ### Step 5: Deploy (Upload + Instantiate in one step)
68
+
69
+ ```bash
70
+ stellar contract deploy \
71
+ --wasm target/wasm32-unknown-unknown/release/{contract}.optimized.wasm \
72
+ --source {keypair_name} \
73
+ --network {network_preference}
74
+ ```
75
+
76
+ Or deploy from a previously uploaded WASM hash:
77
+
78
+ ```bash
79
+ stellar contract deploy \
80
+ --wasm-hash {wasm_hash} \
81
+ --source {keypair_name} \
82
+ --network {network_preference}
83
+ ```
84
+
85
+ The command outputs the contract ID. Save it — it's needed for all subsequent invocations.
86
+
87
+ ### Step 5: Initialize (if needed)
88
+
89
+ If the contract has an `initialize` function that must be called once after deployment:
90
+
91
+ ```bash
92
+ stellar contract invoke \
93
+ --id {contract_id} \
94
+ --source {keypair_name} \
95
+ --network {network_preference} \
96
+ -- initialize \
97
+ --admin {admin_address}
98
+ ```
99
+
100
+ ### Step 6: Verify Deployment
101
+
102
+ Query the contract to confirm initialization:
103
+
104
+ ```bash
105
+ stellar contract invoke \
106
+ --id {contract_id} \
107
+ --network {network_preference} \
108
+ -- get_admin
109
+ ```
110
+
111
+ ### Step 7: Document
112
+
113
+ Save the contract ID and deployment details to `{project-root}/_stellar-output/implementation-artifacts/deployed-contracts.md`:
114
+
115
+ ```markdown
116
+ # Deployed Contracts
117
+
118
+ ## {contract_name}
119
+ - **Network**: {network_preference}
120
+ - **Contract ID**: {contract_id}
121
+ - **Deployed at**: {timestamp}
122
+ - **WASM hash**: {wasm_hash}
123
+ - **Admin**: {admin_address}
124
+ ```