@solana/subscriptions 0.4.0-rc.2 → 0.5.0-beta.1
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 +29 -20
- package/dist/index.cjs +832 -551
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +197 -17
- package/dist/index.d.ts +197 -17
- package/dist/index.js +811 -522
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
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,
|
|
@@ -48,19 +48,25 @@ await client.subscriptions.instructions
|
|
|
48
48
|
|
|
49
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
50
|
|
|
51
|
+
### Sponsored (gasless) flows
|
|
52
|
+
|
|
53
|
+
Installing a distinct `payer()` alongside `identity()` makes that signer sponsor **rent**, not just fees, on every creation instruction (init-authority, create-delegation, subscribe, create-plan). Some sponsored rent is not unilaterally recoverable by the sponsor: an open `SubscriptionAuthority` closes only by the user, non-expiring delegations and perpetual subscriptions stay open indefinitely, and sponsored plan rent refunds to the merchant on delete. Prefer finite `expiryTs`/`endTs` when sponsoring, and enforce per-user and aggregate rent quotas relayer-side. To cover fees without sponsoring rent, set the instruction's `payer` to the user so rent is self-funded while `client.payer` still pays the fee.
|
|
54
|
+
|
|
51
55
|
## Capabilities
|
|
52
56
|
|
|
53
57
|
### Delegation Management
|
|
54
58
|
|
|
55
|
-
| Plugin instruction / builder | Description
|
|
56
|
-
| --------------------------------------------------------------------------------------- |
|
|
57
|
-
| `initSubscriptionAuthority` / `getInitSubscriptionAuthorityOverlayInstructionAsync` | Set up the per-mint SubscriptionAuthority PDA and token approval
|
|
58
|
-
| `closeSubscriptionAuthority` / `getCloseSubscriptionAuthorityOverlayInstructionAsync` |
|
|
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)
|
|
59
|
+
| Plugin instruction / builder | Description |
|
|
60
|
+
| --------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
61
|
+
| `initSubscriptionAuthority` / `getInitSubscriptionAuthorityOverlayInstructionAsync` | Set up the per-mint SubscriptionAuthority PDA and token approval |
|
|
62
|
+
| `closeSubscriptionAuthority` / `getCloseSubscriptionAuthorityOverlayInstructionAsync` | Close the SubscriptionAuthority PDA and reclaim rent. Does not revoke the ATA's SPL delegate — use `revokeSubscriptionAuthority` to stop spending. A same-slot re-init reuses `init_id` and keeps existing delegations live, so this is not a kill switch. |
|
|
63
|
+
| `createFixedDelegation` / `getCreateFixedDelegationOverlayInstructionAsync` | One-time token allowance with optional expiry |
|
|
64
|
+
| `createRecurringDelegation` / `getCreateRecurringDelegationOverlayInstructionAsync` | Periodic allowance (amount per time period) |
|
|
65
|
+
| `revokeDelegation` / `getRevokeDelegationOverlayInstruction` | Permanently close a fixed or recurring delegation and reclaim rent |
|
|
66
|
+
| `revokeSubscription` / `getRevokeSubscriptionOverlayInstruction` | Close a subscription delegation PDA (requires `planPda`) and reclaim rent |
|
|
67
|
+
| `revokeSubscriptionAuthority` / `getRevokeSubscriptionAuthorityOverlayInstructionAsync` | Revoke the per-mint SPL delegate and close the SubscriptionAuthority PDA, reclaiming rent (pass `receiver` when a sponsor funded it) |
|
|
68
|
+
|
|
69
|
+
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).
|
|
64
70
|
|
|
65
71
|
### Transfers
|
|
66
72
|
|
|
@@ -70,16 +76,19 @@ For custom wallet flows, use the exported `get*OverlayInstruction*` functions. T
|
|
|
70
76
|
| `transferRecurring` / `getTransferRecurringOverlayInstructionAsync` | Pull tokens from a recurring delegation |
|
|
71
77
|
| `transferSubscription` / `getTransferSubscriptionOverlayInstructionAsync` | Pull tokens from a subscription delegation |
|
|
72
78
|
|
|
79
|
+
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`.
|
|
80
|
+
|
|
73
81
|
### Subscription Plans
|
|
74
82
|
|
|
75
|
-
| Plugin instruction / builder
|
|
76
|
-
|
|
|
77
|
-
| `createPlan` / `getCreatePlanOverlayInstructionAsync`
|
|
78
|
-
| `updatePlan` / `getUpdatePlanOverlayInstruction`
|
|
79
|
-
| `deletePlan` / `getDeletePlanOverlayInstruction`
|
|
80
|
-
| `subscribe` / `getSubscribeOverlayInstructionAsync`
|
|
81
|
-
| `cancelSubscription` / `getCancelSubscriptionOverlayInstructionAsync`
|
|
82
|
-
| `
|
|
83
|
+
| Plugin instruction / builder | Description |
|
|
84
|
+
| --------------------------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
85
|
+
| `createPlan` / `getCreatePlanOverlayInstructionAsync` | Publish a subscription plan with billing terms |
|
|
86
|
+
| `updatePlan` / `getUpdatePlanOverlayInstruction` | Update plan status, end date, pullers, or metadata |
|
|
87
|
+
| `deletePlan` / `getDeletePlanOverlayInstruction` | Delete an expired plan and reclaim rent |
|
|
88
|
+
| `subscribe` / `getSubscribeOverlayInstructionAsync` | Subscribe to a plan |
|
|
89
|
+
| `cancelSubscription` / `getCancelSubscriptionOverlayInstructionAsync` | Cancel a subscription (grace period until end of billing period) |
|
|
90
|
+
| `cancelSubscriptionNow` / `getCancelSubscriptionNowOverlayInstructionAsync` | Cancel immediately with subscriber and plan-owner approval |
|
|
91
|
+
| `resumeSubscription` / `getResumeSubscriptionOverlayInstructionAsync` | Resume a cancelled subscription before revocation |
|
|
83
92
|
|
|
84
93
|
### Account Queries
|
|
85
94
|
|
|
@@ -107,7 +116,7 @@ seed is the constant `"event_authority"`).
|
|
|
107
116
|
|
|
108
117
|
## API Reference
|
|
109
118
|
|
|
110
|
-
Full API documentation is generated from source with [TypeDoc](https://typedoc.org/). Run `npx typedoc` to generate
|
|
119
|
+
Full API documentation is generated from source with [TypeDoc](https://typedoc.org/). Run `npx typedoc` to generate the reference into `./docs/` locally.
|
|
111
120
|
|
|
112
121
|
## Development
|
|
113
122
|
|