@occa/sdk 0.4.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,238 @@
1
+ # Changelog
2
+
3
+ All notable changes to `occa-sdk` will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.4.0] - 2026-05-26
9
+
10
+ Phase 1 close-out coverage. SDK now exposes the full Treasury operations
11
+ lifecycle, the autonomous routine payout path, the over-threshold
12
+ privileged payout path, and the daily anchor commit used by the Registry
13
+ audit trail. `SetPolicy` gains the second-signer / threshold fields that
14
+ back the privileged disbursement class.
15
+
16
+ No breaking changes — all additions. Existing `buildSetPolicyInstruction`
17
+ callers keep working: the new `secondarySigner` and `privilegedThreshold`
18
+ params default to "no change" when omitted.
19
+
20
+ ### Added
21
+
22
+ #### Treasury — operations lifecycle
23
+ Operations accounts hold the per-company signer-capability metadata
24
+ (Disbursement vs Anchor). Both kinds share the same lifecycle builders:
25
+
26
+ - `buildRegisterCompanyOperationsInstruction(...)`
27
+ - `buildUpdateOperationsCapabilityInstruction(...)`
28
+ - `buildRevokeOperationsInstruction(...)`
29
+ - `buildCloseOperationsInstruction(...)`
30
+ - `OPERATIONS_KIND` enum (`Disbursement` | `Anchor`) + `OperationsKind` type
31
+ - `deriveOperationsPda(companyPda, kind)`
32
+
33
+ #### Treasury — payouts
34
+ - `buildDisburseRoutineInstruction(...)` — flagship autonomous payout
35
+ signed by the registered Disbursement Wallet; settles within the
36
+ per-month routine budget set by `SetPolicy`
37
+ - `buildDisbursePrivilegedInstruction(...)` — over-threshold disbursement
38
+ requiring controlling authority + Disbursement Wallet co-signature
39
+
40
+ #### Treasury — protocol fees
41
+ - `buildInitProtocolFeeAccountInstruction(...)` — one-time singleton
42
+ initializer for the protocol fee collection PDA
43
+
44
+ #### Registry — daily anchor
45
+ - `buildCommitDailyAnchorInstruction(...)` — commit a per-deployment
46
+ per-UTC-day Merkle root of canonical trace bytes
47
+ - `deriveDailyAnchorPda(deploymentPda, dayIndex)`
48
+ - `DailyAnchorAccount` entry in `ACCOUNT_DISCRIMINATOR`
49
+
50
+ ### Changed
51
+
52
+ - **`buildSetPolicyInstruction`** params extended with optional
53
+ `secondarySigner` (three-valued: `undefined` = no change, `null` =
54
+ clear, `PublicKey` = set), `privilegedThresholdLamports` (`bigint`),
55
+ and `privilegedThresholdPerToken` (`AssetBudget[]`). Existing calls
56
+ compile and behave identically — the previous hard-coded `None` is
57
+ now the default when these are omitted.
58
+ - **Treasury IDL** synced to the redeployed program covering the new
59
+ operations + privileged disbursement instructions and accounts.
60
+ - **`devnet-smoke`** script updated for the prior
61
+ `set_operating_wallet` → `set_receiving_address` rename.
62
+
63
+ ## [0.3.0] - 2026-05-16
64
+
65
+ Treasury program support. The SDK now covers the **Treasury program** in
66
+ addition to Registry — set spending policy and disburse funds to agents
67
+ on-chain. Also aligns `create_company` + the receiving-address setter
68
+ with the latest deployed program account layouts.
69
+
70
+ ### ⚠️ Breaking Changes
71
+
72
+ - **Renamed** `buildSetOperatingWalletInstruction` → `buildSetReceivingAddressInstruction`,
73
+ `SetOperatingWalletParams` → `SetReceivingAddressParams`, and the param
74
+ field `newOperatingWallet` → `newReceivingAddress`. The on-chain
75
+ instruction was renamed `set_operating_wallet` → `set_receiving_address`;
76
+ the old discriminator is rejected by the deployed program.
77
+ - **`buildCreateCompanyInstruction`** now appends the `treasury`, `policy`,
78
+ and `treasury_program` accounts the redeployed `create_company` requires
79
+ (it CPIs into `treasury::init_treasury`). Its return value gains
80
+ `treasuryPda` and `policyPda`. Callers passing a hand-built account list
81
+ must adopt the builder.
82
+
83
+ ### Added
84
+
85
+ #### Treasury program
86
+ - `buildSetPolicyInstruction(...)` — set per-month routine / discretionary
87
+ budgets, accepted assets, and the Agent Operating Fee
88
+ - `buildDisburseDiscretionaryInstruction(...)` — controlling-authority
89
+ payout to an agent's receiving address; 3% fee deducted on-chain
90
+ - `deriveTreasuryPda(companyPda)`, `derivePolicyPda(companyPda)`,
91
+ `deriveProtocolFeePda()`
92
+ - `TREASURY_INSTRUCTION_DISCRIMINATOR`, `TREASURY_ACCOUNT_DISCRIMINATOR`
93
+ - `TREASURY_PROGRAM_ID` / `TREASURY_PROGRAM_ID_BASE58`
94
+ - `SOL_PSEUDO_MINT` — the all-zero pubkey marker for native SOL
95
+ - Seeds `TREASURY_SEED`, `POLICY_SEED`, `PROTOCOL_FEES_SEED`
96
+ - `AssetBudget` type — `{ mint, amount }` per-asset budget entry
97
+
98
+ ### Migration guide (v0.2.x → v0.3.0)
99
+
100
+ ```ts
101
+ // Before
102
+ import { buildSetOperatingWalletInstruction } from "occa-sdk";
103
+ buildSetOperatingWalletInstruction({ deploymentPda, owner, newOperatingWallet });
104
+
105
+ // After
106
+ import { buildSetReceivingAddressInstruction } from "occa-sdk";
107
+ buildSetReceivingAddressInstruction({ deploymentPda, owner, newReceivingAddress });
108
+ ```
109
+
110
+ `buildCreateCompanyInstruction` callers: no code change needed if you use
111
+ the returned `instruction` directly — the extra accounts are added
112
+ internally. Stop hand-assembling the account list.
113
+
114
+ ## [0.2.1] - 2026-05-07
115
+
116
+ Devnet program redeploy. No API changes — consumers only need to refresh the bundled IDL/program ID.
117
+
118
+ ### Changed
119
+
120
+ - **Devnet `REGISTRY_PROGRAM_ID`** rotated to `occaTHMv5eYG5aZ85jimxTvHkBfsDCvndXC6J2k8kxr` after a fresh Registry redeploy. IDL `address` field updated to match.
121
+
122
+ ## [0.2.0] - 2026-05-06
123
+
124
+ Sync to OCCA Registry program v3. Introduces the **Deployment** primitive — Agent is now a standalone on-chain identity (`AgentIdentity`) bound to a Company through a separate `Deployment` PDA, replacing the v0.1.0 model where agents were directly company-scoped.
125
+
126
+ ### ⚠️ Breaking Changes
127
+
128
+ - **Removed** `buildRegisterAgentInstruction` / `RegisterAgentParams`. Agent registration is now a two-step flow: call `buildRegisterAgentIdentityInstruction` to create the agent, then `buildCreateDeploymentInstruction` to bind it to a company.
129
+ - **Removed** `deriveAgentPda(companyPda, agentIndex)`. Use `deriveAgentIdentityPda(agentPubkey)` for the agent's identity PDA, and `deriveDeploymentPda(companyPda, deploymentIndex)` for the company-agent binding PDA.
130
+ - **Removed** custody model concepts:
131
+ - `CUSTODY_MODEL`, `CUSTODY_MODEL_ON_CHAIN`
132
+ - `custodyModelStringToU8()`
133
+ - `CURRENT_DERIVATION_MSG_VERSION`
134
+ - These responsibilities moved out of the SDK; custody is now handled at the runtime layer.
135
+ - **Renamed** seed constant `AGENT_SEED` → `AGENT_IDENTITY_SEED`. New seed `DEPLOYMENT_SEED` added.
136
+ - **Removed** `src/derivation.ts`. Its responsibilities split into `src/pda.ts` (PDA helpers) and `src/instructions.ts` (instruction builders).
137
+ - **Removed dependency** `@noble/hashes` — no longer needed after custody model removal. SDK now only depends on `@solana/web3.js`.
138
+
139
+ ### Added
140
+
141
+ #### AgentIdentity primitive
142
+ - `buildRegisterAgentIdentityInstruction(...)` — create a standalone on-chain agent identity
143
+ - `buildUpdateAgentIdentityMetadataInstruction(...)` — update agent metadata
144
+ - `deriveAgentIdentityPda(agentPubkey)` — derive the AgentIdentity PDA
145
+
146
+ #### Deployment primitive (NEW concept)
147
+ - `buildCreateDeploymentInstruction(...)` — bind an AgentIdentity to a Company
148
+ - `buildUpdateDeploymentMetadataInstruction(...)`
149
+ - `buildUpdateDeploymentStatusInstruction(...)`
150
+ - `buildRetireDeploymentInstruction(...)`
151
+ - `deriveDeploymentPda(companyPda, deploymentIndex)`
152
+
153
+ #### Company management
154
+ - `buildUpdateCompanyMetadataInstruction(...)`
155
+ - `buildUpdateCompanyStatusInstruction(...)`
156
+
157
+ #### Operational
158
+ - `buildSetOperatingWalletInstruction(...)` — assign an operating wallet to a deployment
159
+
160
+ #### Constants & types
161
+ - `INSTRUCTION_DISCRIMINATOR` — map of all 10 instruction discriminators
162
+ - `COMPANY_STATUS` enum + `CompanyStatus` type
163
+ - `DEPLOYMENT_STATUS` enum + `DeploymentStatus` type
164
+ - Length bounds: `MAX_NAME_LEN`, `MAX_LOCALE_LEN`, `MAX_ROLE_LEN`, `MAX_METADATA_URI_LEN`, `MAX_REPUTATION_URI_LEN`
165
+ - New seeds: `AGENT_IDENTITY_SEED`, `DEPLOYMENT_SEED`
166
+
167
+ ### Changed
168
+
169
+ - **IDL** refreshed to cover all 10 Registry v3 instructions and 3 account types (CompanyAccount, AgentIdentity, Deployment).
170
+ - **Devnet smoke script** rewritten to exercise the new register-identity → create-deployment flow.
171
+ - **tsup config** updated for new module entrypoints.
172
+
173
+ ### Migration guide (v0.1.0 → v0.2.0)
174
+
175
+ **Before (v0.1.0):**
176
+ ```ts
177
+ import { buildRegisterAgentInstruction, deriveAgentPda } from "occa-sdk";
178
+
179
+ const [agentPda] = deriveAgentPda(companyPda, agentIndex);
180
+ const ix = buildRegisterAgentInstruction({
181
+ companyPda,
182
+ owner,
183
+ payer,
184
+ agentIndex,
185
+ roleId,
186
+ adapterId,
187
+ });
188
+ ```
189
+
190
+ **After (v0.2.0):**
191
+ ```ts
192
+ import {
193
+ buildRegisterAgentIdentityInstruction,
194
+ buildCreateDeploymentInstruction,
195
+ deriveAgentIdentityPda,
196
+ deriveDeploymentPda,
197
+ } from "occa-sdk";
198
+
199
+ // Step 1 — register the standalone agent identity
200
+ const [identityPda] = deriveAgentIdentityPda(agentPubkey);
201
+ const registerIx = buildRegisterAgentIdentityInstruction({
202
+ agentPubkey,
203
+ owner,
204
+ payer,
205
+ name,
206
+ metadataUri,
207
+ metadataHash,
208
+ });
209
+
210
+ // Step 2 — bind the agent to a company via a Deployment
211
+ const [deploymentPda] = deriveDeploymentPda(companyPda, deploymentIndex);
212
+ const deployIx = buildCreateDeploymentInstruction({
213
+ companyPda,
214
+ identityPda,
215
+ deploymentIndex,
216
+ /* ...role, status, metadata */
217
+ });
218
+ ```
219
+
220
+ ## [0.1.0] - 2026-05-05
221
+
222
+ Initial release. Provided PDA helpers, instruction builders, and types for the OCCA Registry program v1.
223
+
224
+ ### Added
225
+
226
+ - `buildCreateCompanyInstruction(...)` — create a Company PDA
227
+ - `buildRegisterAgentInstruction(...)` — register an agent directly under a company
228
+ - `deriveCompanyPda(owner, nonce)`
229
+ - `deriveAgentPda(companyPda, agentIndex)`
230
+ - Sign-to-derive custody model with `CUSTODY_MODEL` enum and helpers
231
+ - Initial IDL bundle for Registry program v1
232
+ - Devnet smoke script
233
+
234
+ [0.4.0]: https://github.com/Occa-Labs/occa-core/compare/occa-sdk@0.3.0...occa-sdk@0.4.0
235
+ [0.3.0]: https://github.com/Occa-Labs/occa-core/compare/occa-sdk@0.2.1...occa-sdk@0.3.0
236
+ [0.2.1]: https://github.com/Occa-Labs/occa-core/compare/occa-sdk@0.2.0...occa-sdk@0.2.1
237
+ [0.2.0]: https://github.com/Occa-Labs/occa-core/compare/occa-sdk@0.1.0...occa-sdk@0.2.0
238
+ [0.1.0]: https://github.com/Occa-Labs/occa-core/releases/tag/occa-sdk@0.1.0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OCCA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,102 @@
1
+ # occa-sdk
2
+
3
+ OCCA on-chain protocol SDK for Solana. PDA helpers, instruction builders, and the **sign-to-derive** custody model for the OCCA Registry program.
4
+
5
+ > Status: **devnet**. Program `oCCAYWgH3KTWccrdHUkrGZQK8YAGTNVQp4V4Hxsv8LQ`. APIs may change before 1.0.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install occa-sdk @solana/web3.js
11
+ # or: pnpm add occa-sdk @solana/web3.js
12
+ ```
13
+
14
+ ## What's inside
15
+
16
+ - **`buildCreateCompanyInstruction` / `buildRegisterAgentInstruction`** — Borsh-encoded `TransactionInstruction` builders. No Anchor runtime dependency.
17
+ - **`deriveCompanyPda` / `deriveAgentPda`** — PDA derivation that mirrors the on-chain seeds byte-for-byte.
18
+ - **`buildAgentDerivationMessage` / `deriveAgentKeypairFromSignature`** — sign-to-derive custody. The user's wallet signs a deterministic message; the signature is hashed (blake3) into a 32-byte seed and turned into an Ed25519 keypair. The SDK never holds the agent privkey.
19
+ - **`REGISTRY_PROGRAM_ID`, `CUSTODY_MODEL_ON_CHAIN`** — constants pinned to the deployed program.
20
+
21
+ ## Quick start
22
+
23
+ ```ts
24
+ import { Connection, Keypair, PublicKey, Transaction } from "@solana/web3.js";
25
+ import {
26
+ buildCreateCompanyInstruction,
27
+ buildRegisterAgentInstruction,
28
+ buildAgentDerivationMessage,
29
+ deriveAgentKeypairFromSignature,
30
+ CURRENT_DERIVATION_MSG_VERSION,
31
+ CUSTODY_MODEL_ON_CHAIN,
32
+ REGISTRY_PROGRAM_ID,
33
+ } from "occa-sdk";
34
+
35
+ const conn = new Connection("https://api.devnet.solana.com", "confirmed");
36
+ const operator = Keypair.generate(); // funded payer + controlling_authority
37
+
38
+ // 1. create_company
39
+ const nonce = Math.floor(Date.now() / 1000) & 0xffffffff;
40
+ const { instruction: createIx, companyPda } = buildCreateCompanyInstruction({
41
+ authority: operator.publicKey,
42
+ payer: operator.publicKey,
43
+ nonce,
44
+ metadataUri: "ipfs://...",
45
+ });
46
+ // sign + send `createIx` with operator as feePayer
47
+
48
+ // 2. derive an agent address from the user's wallet signature
49
+ const message = buildAgentDerivationMessage({
50
+ companyPda: companyPda.toBase58(),
51
+ agentIndex: 0,
52
+ version: CURRENT_DERIVATION_MSG_VERSION,
53
+ });
54
+ const walletSignature = await wallet.signMessage(
55
+ new TextEncoder().encode(message),
56
+ );
57
+ const agentKeypair = deriveAgentKeypairFromSignature(walletSignature);
58
+
59
+ // 3. register_agent
60
+ const { instruction: registerIx } = buildRegisterAgentInstruction({
61
+ companyPda,
62
+ controllingAuthority: operator.publicKey,
63
+ payer: operator.publicKey,
64
+ agentIndex: 0,
65
+ agentAddress: agentKeypair.publicKey,
66
+ custodyModel: CUSTODY_MODEL_ON_CHAIN.SignToDerive,
67
+ roleId: 0,
68
+ adapterId: PublicKey.default,
69
+ });
70
+ // sign + send `registerIx` with operator as feePayer
71
+ ```
72
+
73
+ ## Sign-to-derive in one line
74
+
75
+ ```
76
+ agentKeypair = ed25519(blake3(walletSignature(canonicalMessage)))
77
+ ```
78
+
79
+ Properties:
80
+
81
+ - **Deterministic** — same wallet + same `(companyPda, agentIndex)` → same agent keypair every time.
82
+ - **Recoverable** — as long as the user holds the wallet, the agent keypair can be re-derived. OCCA stores nothing.
83
+ - **Phantom-compatible** — uses `wallet.signMessage`, no exotic derivation paths required.
84
+
85
+ ## Subpath imports
86
+
87
+ ```ts
88
+ import { deriveCompanyPda } from "occa-sdk/pda";
89
+ import { REGISTRY_PROGRAM_ID } from "occa-sdk/constants";
90
+ import { buildAgentDerivationMessage } from "occa-sdk/derivation";
91
+ import { buildCreateCompanyInstruction } from "occa-sdk/instructions";
92
+ ```
93
+
94
+ ## Devnet program
95
+
96
+ ```
97
+ oCCAYWgH3KTWccrdHUkrGZQK8YAGTNVQp4V4Hxsv8LQ
98
+ ```
99
+
100
+ ## License
101
+
102
+ MIT