@solana/subscriptions 0.4.0-rc.1 → 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/README.md +20 -12
- package/dist/index.cjs +668 -260
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +298 -68
- package/dist/index.d.ts +298 -68
- package/dist/index.js +647 -226
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ const client = createClient()
|
|
|
28
28
|
// 1. Initialize the SubscriptionAuthority for a user's token account (once per mint)
|
|
29
29
|
await client.subscriptions.instructions
|
|
30
30
|
.initSubscriptionAuthority({
|
|
31
|
-
tokenMint: address('
|
|
31
|
+
tokenMint: address('TokenMintAddress...'),
|
|
32
32
|
userAta: address('...'),
|
|
33
33
|
tokenProgram: address('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
|
|
34
34
|
})
|
|
@@ -37,7 +37,7 @@ await client.subscriptions.instructions
|
|
|
37
37
|
// 2. Create a fixed delegation (e.g., allow spending 1,000,000 tokens)
|
|
38
38
|
await client.subscriptions.instructions
|
|
39
39
|
.createFixedDelegation({
|
|
40
|
-
tokenMint: address('
|
|
40
|
+
tokenMint: address('TokenMintAddress...'),
|
|
41
41
|
delegatee: address('DelegateeAddress...'),
|
|
42
42
|
nonce: 0n,
|
|
43
43
|
amount: 1_000_000n,
|
|
@@ -52,13 +52,17 @@ For custom wallet flows, use the exported `get*OverlayInstruction*` functions. T
|
|
|
52
52
|
|
|
53
53
|
### Delegation Management
|
|
54
54
|
|
|
55
|
-
| Plugin instruction / builder
|
|
56
|
-
|
|
|
57
|
-
| `initSubscriptionAuthority` / `getInitSubscriptionAuthorityOverlayInstructionAsync`
|
|
58
|
-
| `closeSubscriptionAuthority` / `getCloseSubscriptionAuthorityOverlayInstructionAsync`
|
|
59
|
-
| `createFixedDelegation` / `getCreateFixedDelegationOverlayInstructionAsync`
|
|
60
|
-
| `createRecurringDelegation` / `getCreateRecurringDelegationOverlayInstructionAsync`
|
|
61
|
-
| `revokeDelegation` / `getRevokeDelegationOverlayInstruction`
|
|
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 a fixed or recurring delegation and reclaim rent |
|
|
62
|
+
| `revokeSubscription` / `getRevokeSubscriptionOverlayInstruction` | Close a subscription delegation PDA (requires `planPda`) and reclaim rent |
|
|
63
|
+
| `revokeSubscriptionAuthority` / `getRevokeSubscriptionAuthorityOverlayInstructionAsync` | Revoke the per-mint SPL delegate and close the SubscriptionAuthority PDA, reclaiming rent (pass `receiver` when a sponsor funded it) |
|
|
64
|
+
|
|
65
|
+
Abandoned delegation and subscription PDAs (Subscription Authority closed or re-initialized) can be closed by the recorded payer via the generated `getRevokeAbandonedDelegationInstruction` / `getRevokeAbandonedSubscriptionInstruction` builders (no overlay wrapper).
|
|
62
66
|
|
|
63
67
|
### Transfers
|
|
64
68
|
|
|
@@ -68,6 +72,8 @@ For custom wallet flows, use the exported `get*OverlayInstruction*` functions. T
|
|
|
68
72
|
| `transferRecurring` / `getTransferRecurringOverlayInstructionAsync` | Pull tokens from a recurring delegation |
|
|
69
73
|
| `transferSubscription` / `getTransferSubscriptionOverlayInstructionAsync` | Pull tokens from a subscription delegation |
|
|
70
74
|
|
|
75
|
+
For Token-2022 mints with a configured transfer hook, the plugin resolves and appends the hook accounts automatically. For standalone overlay usage, call `resolveTransferHookAccounts` and pass the result as `transferHookAccounts`.
|
|
76
|
+
|
|
71
77
|
### Subscription Plans
|
|
72
78
|
|
|
73
79
|
| Plugin instruction / builder | Description |
|
|
@@ -93,17 +99,19 @@ For custom wallet flows, use the exported `get*OverlayInstruction*` functions. T
|
|
|
93
99
|
|
|
94
100
|
Use the generated `find*Pda` helpers directly: `findSubscriptionAuthorityPda`,
|
|
95
101
|
`findFixedDelegationPda`, `findRecurringDelegationPda`, `findSubscriptionDelegationPda`,
|
|
96
|
-
`findPlanPda`, `findEventAuthorityPda`.
|
|
102
|
+
`findPlanPda`, `findEventAuthorityPda`. They return `[address, bump]`. The first five take a
|
|
103
|
+
seeds object; `findEventAuthorityPda` takes only an optional `{ programAddress }` config (its
|
|
104
|
+
seed is the constant `"event_authority"`).
|
|
97
105
|
|
|
98
106
|
### Types
|
|
99
107
|
|
|
100
108
|
- `Delegation` - discriminated union: `{ kind: "fixed" | "recurring" | "subscription"; address; data }`. Narrow with `d.kind === '...'`.
|
|
101
|
-
- `PlanWithAddress`, `DelegationKindId` (string union)
|
|
109
|
+
- `PlanWithAddress`, `DelegationKindId` (string union); transfer input types are `TransferDelegationInput` / `TransferSubscriptionInput`
|
|
102
110
|
- Error handling: client-side `ValidationError`; on-chain errors use the generated `SUBSCRIPTIONS_ERROR__*` constants and `isSubscriptionsError` / `getSubscriptionsErrorMessage`.
|
|
103
111
|
|
|
104
112
|
## API Reference
|
|
105
113
|
|
|
106
|
-
Full API documentation is generated from source with [TypeDoc](https://typedoc.org/). Run `npx typedoc` to generate
|
|
114
|
+
Full API documentation is generated from source with [TypeDoc](https://typedoc.org/). Run `npx typedoc` to generate the reference into `./docs/` locally.
|
|
107
115
|
|
|
108
116
|
## Development
|
|
109
117
|
|