@solana/subscriptions 0.0.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Solana Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @solana/subscriptions
2
+
3
+ TypeScript SDK for the [Subscriptions Solana program](https://github.com/solana-program/subscriptions): token delegation, recurring payments, and subscriptions. Ships as a [`@solana/kit`](https://github.com/anza-xyz/kit) plugin.
4
+
5
+ **Source & issues:** https://github.com/solana-program/subscriptions
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @solana/subscriptions
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ The SDK exports a `subscriptionsProgram()` Kit plugin. The plugin derives program PDAs, fills the configured identity/payer where possible, and can send transactions directly through Kit.
16
+
17
+ ```typescript
18
+ import { address, createClient } from '@solana/kit';
19
+ import { solanaLocalRpc } from '@solana/kit-plugin-rpc';
20
+ import { signer } from '@solana/kit-plugin-signer';
21
+ import { subscriptionsProgram } from '@solana/subscriptions';
22
+
23
+ const client = createClient()
24
+ .use(signer(walletSigner))
25
+ .use(solanaLocalRpc({ rpcUrl: 'http://127.0.0.1:8899' }))
26
+ .use(subscriptionsProgram());
27
+
28
+ // 1. Initialize the SubscriptionAuthority for a user's token account (once per mint)
29
+ await client.subscriptions.instructions
30
+ .initSubscriptionAuthority({
31
+ tokenMint: address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
32
+ userAta: address('...'),
33
+ tokenProgram: address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
34
+ })
35
+ .sendTransaction();
36
+
37
+ // 2. Create a fixed delegation (e.g., allow spending 1,000,000 tokens)
38
+ await client.subscriptions.instructions
39
+ .createFixedDelegation({
40
+ tokenMint: address('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v'),
41
+ delegatee: address('DelegateeAddress...'),
42
+ nonce: 0n,
43
+ amount: 1_000_000n,
44
+ expiryTs: BigInt(Math.floor(Date.now() / 1000) + 3600), // 1 hour
45
+ })
46
+ .sendTransaction();
47
+ ```
48
+
49
+ For custom wallet flows, use the exported `get*OverlayInstruction*` functions. They return a single Kit `Instruction` or `Promise<Instruction>` that you can add to your own transaction builder.
50
+
51
+ ## Capabilities
52
+
53
+ ### Delegation Management
54
+
55
+ | Plugin instruction / builder | Description |
56
+ | ------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- |
57
+ | `initSubscriptionAuthority` / `getInitSubscriptionAuthorityOverlayInstructionAsync` | Set up the per-mint SubscriptionAuthority PDA and token approval |
58
+ | `closeSubscriptionAuthority` / `getCloseSubscriptionAuthorityOverlayInstructionAsync` | Tear down SubscriptionAuthority, invalidating all delegations (kill switch) |
59
+ | `createFixedDelegation` / `getCreateFixedDelegationOverlayInstructionAsync` | One-time token allowance with optional expiry |
60
+ | `createRecurringDelegation` / `getCreateRecurringDelegationOverlayInstructionAsync` | Periodic allowance (amount per time period) |
61
+ | `revokeDelegation` / `getRevokeDelegationOverlayInstruction` | Permanently close any delegation and reclaim rent |
62
+
63
+ ### Transfers
64
+
65
+ | Plugin instruction / builder | Description |
66
+ | ------------------------------------------------------------------------- | ------------------------------------------ |
67
+ | `transferFixed` / `getTransferFixedOverlayInstructionAsync` | Pull tokens from a fixed delegation |
68
+ | `transferRecurring` / `getTransferRecurringOverlayInstructionAsync` | Pull tokens from a recurring delegation |
69
+ | `transferSubscription` / `getTransferSubscriptionOverlayInstructionAsync` | Pull tokens from a subscription delegation |
70
+
71
+ ### Subscription Plans
72
+
73
+ | Plugin instruction / builder | Description |
74
+ | --------------------------------------------------------------------- | ---------------------------------------------------------------- |
75
+ | `createPlan` / `getCreatePlanOverlayInstructionAsync` | Publish a subscription plan with billing terms |
76
+ | `updatePlan` / `getUpdatePlanOverlayInstruction` | Update plan status, end date, pullers, or metadata |
77
+ | `deletePlan` / `getDeletePlanOverlayInstruction` | Delete an expired plan and reclaim rent |
78
+ | `subscribe` / `getSubscribeOverlayInstructionAsync` | Subscribe to a plan |
79
+ | `cancelSubscription` / `getCancelSubscriptionOverlayInstructionAsync` | Cancel a subscription (grace period until end of billing period) |
80
+
81
+ ### Account Queries
82
+
83
+ | Function | Description |
84
+ | ----------------------------- | ---------------------------------------------------------- |
85
+ | `fetchDelegationsByDelegator` | All delegations where wallet is the delegator |
86
+ | `fetchDelegationsByDelegatee` | All delegations where wallet is the delegatee |
87
+ | `fetchPlansForOwner` | All plans owned by an address |
88
+ | `fetchSubscriptionsForUser` | All subscriptions for a user |
89
+ | `decodeDelegationAccount` | Decode raw delegation accounts (fans out by discriminator) |
90
+
91
+ ### PDA Helpers
92
+
93
+ Use the generated `find*Pda` helpers directly: `findSubscriptionAuthorityPda`,
94
+ `findFixedDelegationPda`, `findRecurringDelegationPda`, `findSubscriptionDelegationPda`,
95
+ `findPlanPda`, `findEventAuthorityPda`. All take a seeds object and return `[address, bump]`.
96
+
97
+ ### Types
98
+
99
+ - `Delegation` - discriminated union: `{ kind: "fixed" | "recurring" | "subscription"; address; data }`. Narrow with `d.kind === '...'`.
100
+ - `PlanWithAddress`, `DelegationKindId` (string union), `TransferParams`
101
+ - Error handling: client-side `ValidationError`; on-chain errors use the generated `SUBSCRIPTIONS_ERROR__*` constants and `isSubscriptionsError` / `getSubscriptionsErrorMessage`.
102
+
103
+ ## API Reference
104
+
105
+ Full API documentation is generated from source with [TypeDoc](https://typedoc.org/). Run `npx typedoc` to generate locally, or browse `./docs/`.
106
+
107
+ ## Development
108
+
109
+ Generated bindings in `src/generated/` are produced by [Codama](https://github.com/codama-idl/codama) and gitignored. Regenerate from the repo root:
110
+
111
+ ```bash
112
+ just generate-clients
113
+ ```
114
+
115
+ ## License
116
+
117
+ MIT