@vocdoni/skills 0.5.3 → 0.7.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/.claude-plugin/marketplace.json +29 -27
- package/CHANGELOG.md +38 -0
- package/README.md +66 -41
- package/bin/install.js +13 -2
- package/package.json +1 -1
- package/plugins/agentic-dev/.claude-plugin/plugin.json +2 -2
- package/plugins/agentic-dev/agents/model-router.md +105 -0
- package/plugins/agentic-dev/skills/subagent-driven-development/SKILL.md +25 -13
- package/plugins/agentic-dev/skills/subagent-driven-development/references/audits.md +20 -13
- package/plugins/agentic-dev/skills/subagent-driven-development/references/dispatch.md +42 -1
- package/plugins/agentic-dev/skills/subagent-driven-development/references/ledger.md +11 -6
- package/plugins/agentic-dev/skills/subagent-driven-development/references/model-catalog.md +118 -0
- package/plugins/agentic-dev/skills/subagent-driven-development/references/models.md +126 -71
- package/plugins/agentic-dev/skills/subagent-driven-development/scripts/init-workspace.sh +2 -1
- package/plugins/agentic-dev/skills/subagent-driven-development/scripts/model-inventory.sh +142 -0
- package/plugins/claude-pi-subagent/plugins/pi-subagent/package-lock.json +4 -3
- package/plugins/vocdoni-comments/.claude-plugin/plugin.json +2 -2
- package/plugins/vocdoni-comments/hooks/hooks.json +28 -0
- package/plugins/vocdoni-comments/hooks/session-start.sh +45 -0
- package/plugins/vocdoni-contributing/.claude-plugin/plugin.json +3 -2
- package/plugins/vocdoni-contributing/hooks/hooks.json +14 -2
- package/plugins/vocdoni-contributing/hooks/session-start.sh +18 -6
- package/plugins/vocdoni-contributing/skills/contributing/SKILL.md +41 -7
- package/plugins/vocdoni-go/.claude-plugin/plugin.json +2 -2
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/SKILL.md +522 -0
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/references/prompts.md +260 -0
- package/plugins/vocdoni-go/skills/vocdoni-backend-review/scripts/untracked-list.sh +35 -0
- package/plugins/vocdoni-sdk/.claude-plugin/plugin.json +4 -5
- package/plugins/vocdoni-sdk/skills/vocdoni-ballot-protocol/SKILL.md +61 -38
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/SKILL.md +35 -21
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/approval-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/basic-poll.ts +6 -6
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/csp-vote.ts +12 -7
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/multichoice-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/quadratic-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/ranked-vote.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/weighted-census.ts +3 -3
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/accounts.md +26 -15
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/census.md +9 -10
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/client.md +15 -13
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/csp.md +43 -18
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/elections.md +4 -4
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/errors.md +24 -21
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/removed-features.md +98 -0
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/results.md +0 -1
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/voting.md +30 -34
- package/plugins/vocdoni-sequencer/.claude-plugin/plugin.json +21 -0
- package/plugins/vocdoni-sequencer/skills/vocdoni-sequencer/SKILL.md +169 -0
- package/plugins/vocdoni-sequencer/skills/vocdoni-sequencer/references/removed-routes.md +60 -0
- package/plugins/davinci-sdk/.claude-plugin/plugin.json +0 -13
- package/plugins/davinci-sdk/skills/davinci-sdk/SKILL.md +0 -120
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/bootstrap.ts +0 -61
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/cast-vote.ts +0 -78
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/create-process.ts +0 -102
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/full-election.ts +0 -128
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/read-results.ts +0 -73
- package/plugins/davinci-sdk/skills/davinci-sdk/recipes/token-census.ts +0 -111
- package/plugins/davinci-sdk/skills/davinci-sdk/references/ballot-modes.md +0 -125
- package/plugins/davinci-sdk/skills/davinci-sdk/references/census.md +0 -168
- package/plugins/davinci-sdk/skills/davinci-sdk/references/contracts.md +0 -133
- package/plugins/davinci-sdk/skills/davinci-sdk/references/errors.md +0 -83
- package/plugins/davinci-sdk/skills/davinci-sdk/references/process.md +0 -225
- package/plugins/davinci-sdk/skills/davinci-sdk/references/protocol.md +0 -65
- package/plugins/davinci-sdk/skills/davinci-sdk/references/sequencer.md +0 -135
- package/plugins/davinci-sdk/skills/davinci-sdk/references/setup.md +0 -123
- package/plugins/davinci-sdk/skills/davinci-sdk/references/voting.md +0 -128
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/anonymous-vote.ts +0 -108
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/recipes/token-census.ts +0 -121
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/anonymous.md +0 -183
- package/plugins/vocdoni-sdk/skills/vocdoni-sdk/references/census3.md +0 -308
- package/plugins/vocdoni-stripe/.claude-plugin/plugin.json +0 -22
- package/plugins/vocdoni-stripe/skills/stripe-subscription/SKILL.md +0 -276
- package/plugins/vocdoni-stripe/skills/stripe-subscription/references/backend-contract.md +0 -142
- package/plugins/vocdoni-stripe/skills/stripe-subscription/references/product-templates.md +0 -132
- package/plugins/vocdoni-stripe/skills/stripe-subscription/references/stripe-cli.md +0 -212
- package/plugins/vocdoni-stripe/skills/stripe-subscription/scripts/clone-product.sh +0 -247
- package/plugins/vocdoni-stripe/skills/stripe-subscription/scripts/stripe-json.sh +0 -223
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
# `references/census3.md` — Census3 (token-holder censuses)
|
|
2
|
-
|
|
3
|
-
Companion to the [[vocdoni-sdk]] skill. Use this when the user wants a census derived from on-chain token holdings — ERC20, ERC721, multi-token predicates ("(A OR B) AND C"), or any case involving `VocdoniCensus3Client`.
|
|
4
|
-
|
|
5
|
-
## What Census3 is
|
|
6
|
-
|
|
7
|
-
[Census3](https://github.com/vocdoni/census3) is a separate Vocdoni service that:
|
|
8
|
-
|
|
9
|
-
- Indexes token-holder balances for tracked tokens on supported chains (Ethereum, Polygon, etc.).
|
|
10
|
-
- Lets you define **strategies** — boolean predicates over tokens with optional minimum-balance requirements.
|
|
11
|
-
- Produces a Vocdoni-compatible **merkle census** of the holders matching a strategy, with their balances as voting weights.
|
|
12
|
-
|
|
13
|
-
It's exposed via `VocdoniCensus3Client` from the same `@vocdoni/sdk` npm package. The censuses it produces (`TokenCensus`, `StrategyCensus`) plug directly into a normal `Election` via `Election.from({ census, … })`.
|
|
14
|
-
|
|
15
|
-
## Client setup
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { EnvOptions, VocdoniCensus3Client } from '@vocdoni/sdk';
|
|
19
|
-
|
|
20
|
-
const census3 = new VocdoniCensus3Client({
|
|
21
|
-
env: EnvOptions.PROD, // DEV / STG / PROD; default API URLs match
|
|
22
|
-
});
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
Constructor options:
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
type Census3ClientOptions = {
|
|
29
|
-
env: EnvOptions; // required
|
|
30
|
-
api_url?: string; // override default
|
|
31
|
-
tx_wait?: { retry_time?: number; attempts?: number }; // queue polling; default { 2000, 10 }
|
|
32
|
-
};
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
Default API URLs:
|
|
36
|
-
|
|
37
|
-
| Env | URL |
|
|
38
|
-
| ---- | ----------------------------------------- |
|
|
39
|
-
| DEV | `https://census3-dev.vocdoni.net/api` |
|
|
40
|
-
| STG | `https://census3-stg.vocdoni.net/api` |
|
|
41
|
-
| PROD | `https://census3.vocdoni.io/api` |
|
|
42
|
-
|
|
43
|
-
## Discovery: what's supported
|
|
44
|
-
|
|
45
|
-
```ts
|
|
46
|
-
await census3.getSupportedChains();
|
|
47
|
-
// [{ chainID: 1, shortName: 'eth', name: 'Ethereum Mainnet' }, …]
|
|
48
|
-
|
|
49
|
-
await census3.getSupportedTypes();
|
|
50
|
-
// ['erc20', 'erc721', 'erc777', 'erc1155', 'poap', 'nation3', 'want', 'erc721burned', 'unknown']
|
|
51
|
-
|
|
52
|
-
await census3.getSupportedOperators();
|
|
53
|
-
// [{ tag: 'AND', description: '…' }, { tag: 'OR', … }, { tag: 'AND:sum', … }, { tag: 'AND:mul', … }, …]
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Tokens
|
|
57
|
-
|
|
58
|
-
### List all tracked tokens
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
const tokens = await census3.getSupportedTokens(); // TokenSummary[]
|
|
62
|
-
// Each: { ID, name, type, chainID, symbol, decimals, totalSupply, defaultStrategy, tags, iconURI? }
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Get one token
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
const token = await census3.getToken(
|
|
69
|
-
'0x0AaCfbeC6a24756c20D41914F2caba817C0d8521', // address
|
|
70
|
-
1, // chainID
|
|
71
|
-
/* externalId? */ '',
|
|
72
|
-
);
|
|
73
|
-
// {
|
|
74
|
-
// ID, name, type, chainID, chainAddress, startBlock, symbol, decimals,
|
|
75
|
-
// totalSupply, defaultStrategy, tags, iconURI?, externalID?,
|
|
76
|
-
// status: { synced, atBlock, progress },
|
|
77
|
-
// size, // number of holders
|
|
78
|
-
// }
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Check `token.status.synced` before creating a token census from it — see "Pitfalls".
|
|
82
|
-
|
|
83
|
-
### Register a new token to track
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
await census3.createToken(
|
|
87
|
-
'0xMyNewToken',
|
|
88
|
-
'erc20',
|
|
89
|
-
/* chainID */ 1,
|
|
90
|
-
/* externalId? */ '',
|
|
91
|
-
/* tags? */ [],
|
|
92
|
-
);
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
The service then starts indexing holders asynchronously; it can take minutes/hours depending on contract age. Poll `getToken(...).status.synced` to know when it's ready.
|
|
96
|
-
|
|
97
|
-
### Holder queries
|
|
98
|
-
|
|
99
|
-
```ts
|
|
100
|
-
await census3.isHolderInToken(tokenId, chainId, holderAddress, externalId?); // boolean
|
|
101
|
-
await census3.tokenHolderBalance(tokenId, chainId, holderAddress, externalId?); // bigint
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
## Strategies
|
|
105
|
-
|
|
106
|
-
A **strategy** is a named predicate over one or more tokens. Strategies are the unit of census creation when you want anything more interesting than "single-token holders."
|
|
107
|
-
|
|
108
|
-
### List, fetch
|
|
109
|
-
|
|
110
|
-
```ts
|
|
111
|
-
await census3.getStrategies();
|
|
112
|
-
// [{ ID, alias, predicate, uri, tokens: { [name]: { ID, chainID, chainAddress, minBalance?, … } } }, …]
|
|
113
|
-
|
|
114
|
-
await census3.getStrategy(19);
|
|
115
|
-
await census3.getStrategiesByToken('0xToken', 1);
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### Create a strategy
|
|
119
|
-
|
|
120
|
-
```ts
|
|
121
|
-
const id = await census3.createStrategy(
|
|
122
|
-
'My governance strategy', // alias
|
|
123
|
-
'(wANT OR ANT) AND USDC', // predicate over symbols
|
|
124
|
-
{
|
|
125
|
-
wANT: { ID: '0xWANT…', chainID: 1, minBalance: '10000' },
|
|
126
|
-
ANT: { ID: '0xANT…', chainID: 5 },
|
|
127
|
-
USDC: { ID: '0xUSDC…', chainID: 1, minBalance: '50' },
|
|
128
|
-
},
|
|
129
|
-
);
|
|
130
|
-
// id: number — the new strategy ID
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
The keys in the `tokens` object are *predicate aliases* — they appear in the predicate string by name. The `ID` field is the contract address.
|
|
134
|
-
|
|
135
|
-
### Predicate syntax
|
|
136
|
-
|
|
137
|
-
| Operator | Behaviour |
|
|
138
|
-
| ---------- | ----------------------------------------------------------------------------------------------- |
|
|
139
|
-
| `AND` | Holder must satisfy each side's `minBalance` (weight set to a fixed 1). |
|
|
140
|
-
| `OR` | Holder must satisfy at least one side's `minBalance`. |
|
|
141
|
-
| `AND:sum` | Sum of token balances must satisfy threshold; weight = sum of balances. |
|
|
142
|
-
| `AND:mul` | Product of token balances must satisfy threshold; weight = product of balances. |
|
|
143
|
-
|
|
144
|
-
Examples:
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
TOKENA // single-token strategy (just a literal)
|
|
148
|
-
TOKENA AND TOKENB // intersection
|
|
149
|
-
(TOKENA OR TOKENB) AND TOKENC // grouped
|
|
150
|
-
TOKENA AND:sum TOKENB // weighted by sum of A + B balances
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
Use `validatePredicate(predicate)` to see the parsed tree before saving a strategy:
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
const parsed = await census3.validatePredicate('(YAM OR API3) AND 1INCH');
|
|
157
|
-
// { result: { childs: { operator: 'AND', tokens: [ … ] } } }
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
### Estimate before you commit
|
|
161
|
-
|
|
162
|
-
Building a census for a large strategy can take minutes. Estimate first:
|
|
163
|
-
|
|
164
|
-
```ts
|
|
165
|
-
await census3.getStrategyEstimation(strategyId);
|
|
166
|
-
// { size: 5516, timeToCreateCensus: 3296 /* ms */, accuracy: 100 /* for anonymous */ }
|
|
167
|
-
|
|
168
|
-
// Or for a not-yet-created predicate
|
|
169
|
-
await census3.getPredicateEstimation(predicate, tokens, /* anonymous? */ false);
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
### Import a strategy from IPFS
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
const strategy = await census3.importStrategy('bafy…cid');
|
|
176
|
-
// Returns the full Strategy object after the service materialises it.
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
### Inspect the holder set
|
|
180
|
-
|
|
181
|
-
```ts
|
|
182
|
-
const holders = await census3.getStrategyHolders(strategyId);
|
|
183
|
-
// [{ holder: '0xabc…', weight: 100n }, … ]
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
This is long-running (queue-polled).
|
|
187
|
-
|
|
188
|
-
## Censuses
|
|
189
|
-
|
|
190
|
-
Census3 censuses are immutable snapshots — each `createCensus*` call produces a new census ID and merkle root.
|
|
191
|
-
|
|
192
|
-
### List / get
|
|
193
|
-
|
|
194
|
-
```ts
|
|
195
|
-
await census3.getCensuses(strategyId);
|
|
196
|
-
// [{ ID, strategyID, merkleRoot, uri, size, weight, anonymous, accuracy }, …]
|
|
197
|
-
|
|
198
|
-
await census3.getCensus(censusId);
|
|
199
|
-
```
|
|
200
|
-
|
|
201
|
-
### Create from a strategy
|
|
202
|
-
|
|
203
|
-
```ts
|
|
204
|
-
const c = await census3.createCensus(strategyId, /* anonymous? */ false);
|
|
205
|
-
// Census3Census: { ID, strategyID, merkleRoot, uri, size, weight, anonymous, accuracy }
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
### Create a `TokenCensus` from a single token (uses the token's default strategy)
|
|
209
|
-
|
|
210
|
-
```ts
|
|
211
|
-
import { TokenCensus } from '@vocdoni/sdk';
|
|
212
|
-
|
|
213
|
-
const tokenCensus: TokenCensus = await census3.createTokenCensus(
|
|
214
|
-
'0xMyTokenAddress',
|
|
215
|
-
/* chainID */ 1,
|
|
216
|
-
/* anonymous? */ false,
|
|
217
|
-
/* externalId? */ '',
|
|
218
|
-
);
|
|
219
|
-
// Throws "Token is not yet synced" if status.synced is false.
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
`TokenCensus` extends `PublishedCensus`. The relevant properties for plugging into an election:
|
|
223
|
-
|
|
224
|
-
| Property | Source | Used for |
|
|
225
|
-
| ------------- | ----------------------- | ----------------------------------------- |
|
|
226
|
-
| `censusId` | `merkleRoot` | Merkle root for proof verification. |
|
|
227
|
-
| `censusURI` | `uri` | IPFS URI of merkle tree. |
|
|
228
|
-
| `type` | `WEIGHTED` or `ANONYMOUS` | Election census-type binding. |
|
|
229
|
-
| `size` | Holder count | `maxCensusSize` upper bound. |
|
|
230
|
-
| `weight` | Sum of balances | Total voting power. |
|
|
231
|
-
| `token` | Full `Token` object | Embedded into `election.meta` for tools. |
|
|
232
|
-
|
|
233
|
-
### Create a `StrategyCensus` from a strategy
|
|
234
|
-
|
|
235
|
-
```ts
|
|
236
|
-
import { StrategyCensus } from '@vocdoni/sdk';
|
|
237
|
-
|
|
238
|
-
const strategyCensus: StrategyCensus = await census3.createStrategyCensus(
|
|
239
|
-
strategyId,
|
|
240
|
-
/* anonymous? */ false,
|
|
241
|
-
);
|
|
242
|
-
// Same shape as TokenCensus, with .strategy instead of .token.
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
## Plug Census3 into a Vocdoni election
|
|
246
|
-
|
|
247
|
-
```ts
|
|
248
|
-
import { Election, EnvOptions, VocdoniCensus3Client, VocdoniSDKClient } from '@vocdoni/sdk';
|
|
249
|
-
import { Wallet } from '@ethersproject/wallet';
|
|
250
|
-
|
|
251
|
-
const census3 = new VocdoniCensus3Client({ env: EnvOptions.PROD });
|
|
252
|
-
const vocdoni = new VocdoniSDKClient({ env: EnvOptions.PROD, wallet: Wallet.createRandom() });
|
|
253
|
-
|
|
254
|
-
await vocdoni.createAccount(); // assumes you have a faucet pkg on PROD
|
|
255
|
-
|
|
256
|
-
const tokenCensus = await census3.createTokenCensus('0xToken', 1);
|
|
257
|
-
|
|
258
|
-
const election = Election.from({
|
|
259
|
-
title: 'Token holders vote',
|
|
260
|
-
endDate: new Date(Date.now() + 7 * 24 * 3600 * 1000),
|
|
261
|
-
census: tokenCensus, // plugs in directly
|
|
262
|
-
maxCensusSize: tokenCensus.size, // recommended: pin to the snapshot size
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
election.addQuestion('Proposal X?', '', [
|
|
266
|
-
{ title: 'Yes', value: 0 },
|
|
267
|
-
{ title: 'No', value: 1 },
|
|
268
|
-
]);
|
|
269
|
-
|
|
270
|
-
const electionId = await vocdoni.createElection(election);
|
|
271
|
-
```
|
|
272
|
-
|
|
273
|
-
`createElectionSteps` (and `createElection` internally) detects `instanceof TokenCensus` / `StrategyCensus` and embeds the token/strategy metadata into `election.meta` so downstream readers can introspect.
|
|
274
|
-
|
|
275
|
-
## Error types
|
|
276
|
-
|
|
277
|
-
Errors thrown by `VocdoniCensus3Client` are typed `Error` subclasses with static `code` numbers. Common ones:
|
|
278
|
-
|
|
279
|
-
| Class | Code | When |
|
|
280
|
-
| ------------------------------ | ----- | --------------------------------------------- |
|
|
281
|
-
| `ErrNotFoundToken` | 4003 | Token isn't tracked by the service. |
|
|
282
|
-
| `ErrChainIDNotSupported` | 4013 | Chain not in `getSupportedChains()`. |
|
|
283
|
-
| `ErrTokenAlreadyExists` | 4009 | `createToken` for one already tracked. |
|
|
284
|
-
| `ErrInvalidStrategyPredicate` | 4015 | Predicate doesn't parse. |
|
|
285
|
-
| `ErrNoStrategyHolders` | 4017 | Strategy matches zero holders. |
|
|
286
|
-
| `ErrNotFoundStrategy` | 4005 | Strategy ID doesn't exist. |
|
|
287
|
-
| `ErrCantImportStrategy` | 5028 | IPFS import failed or queue timeout. |
|
|
288
|
-
| `ErrCensusAlreadyExists` | 4012 | Already created. |
|
|
289
|
-
| `ErrCantCreateCensus` | 5001 | Backend error building merkle tree. |
|
|
290
|
-
|
|
291
|
-
Long-running operations (`createCensus`, `createStrategyCensus`, `createTokenCensus`, `getStrategyHolders`, `getStrategyEstimation`, `importStrategy`) all poll an internal queue using `tx_wait` and reject with `"Time out waiting for queue with id: <id>"` if they exhaust attempts. Bump `tx_wait.attempts` for large censuses (15+ for >100k holders).
|
|
292
|
-
|
|
293
|
-
## Pitfalls
|
|
294
|
-
|
|
295
|
-
- **Tokens must be synced before census creation.** Call `getToken(...).then(t => t.status.synced)` and wait/poll if false. `createTokenCensus` explicitly errors with `"Token is not yet synced"` otherwise.
|
|
296
|
-
- **Strategy predicates reference tokens by alias, not address.** The aliases are the keys in the `tokens` map; pick them deliberately and use the same in your predicate string.
|
|
297
|
-
- **`minBalance` is a string (decimal of raw units).** For 100 USDC (6 decimals), pass `"100000000"`. The service does *no* decimal conversion.
|
|
298
|
-
- **Anonymous Census3 censuses use ZK with bounded accuracy.** `accuracy` < 100 means proof generation may occasionally fail; size the strategy accordingly. For exact-set anonymous censuses, use the off-chain `WeightedCensus` path from `census.md`.
|
|
299
|
-
- **`maxCensusSize` on the election should be at least the Census3 `size`.** Recommended: pin them equal.
|
|
300
|
-
- **PROD costs PROD tokens.** Census3 is free to query, but the resulting election still costs tokens on the vochain. Estimate first via `client.estimateElectionCost(election)`.
|
|
301
|
-
|
|
302
|
-
## Cross-references
|
|
303
|
-
|
|
304
|
-
- `client.md` — also covers `VocdoniSDKClient` setup which Census3 censuses ultimately feed into.
|
|
305
|
-
- `census.md` — comparison with `PlainCensus`, `WeightedCensus`, `CspCensus`.
|
|
306
|
-
- `elections.md` — `Election.from({ census: tokenCensus })` plugs Census3 in.
|
|
307
|
-
- `recipes/token-census.ts` — runnable example.
|
|
308
|
-
- [Census3 API docs](https://github.com/vocdoni/census3/blob/main/api/README.md) — raw HTTP surface.
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vocdoni-stripe",
|
|
3
|
-
"version": "0.1.1",
|
|
4
|
-
"description": "Stripe operations for the Vocdoni SaaS, run through the Stripe CLI (or a Stripe MCP server). Creates subscriptions for existing customers with the org-address metadata the backend needs, clones per-customer Custom / Integrator Starter plan products from the catalog templates, handles discounts and payment collection, and always confirms before writing. Ships an environment-guarding CLI wrapper, a product-cloning script and a verified reference of what the SaaS backend reads from Stripe.",
|
|
5
|
-
"author": {
|
|
6
|
-
"name": "Vocdoni",
|
|
7
|
-
"url": "https://vocdoni.io"
|
|
8
|
-
},
|
|
9
|
-
"homepage": "https://github.com/vocdoni/skills",
|
|
10
|
-
"repository": "https://github.com/vocdoni/skills",
|
|
11
|
-
"license": "AGPL-3.0-or-later",
|
|
12
|
-
"keywords": [
|
|
13
|
-
"claude-code",
|
|
14
|
-
"skills",
|
|
15
|
-
"vocdoni",
|
|
16
|
-
"stripe",
|
|
17
|
-
"billing",
|
|
18
|
-
"subscriptions",
|
|
19
|
-
"saas",
|
|
20
|
-
"stripe-cli"
|
|
21
|
-
]
|
|
22
|
-
}
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: stripe-subscription
|
|
3
|
-
description: Creates a Stripe subscription for an existing Vocdoni SaaS customer, including per-customer "Custom" and "Integrator Starter" plans cloned from template products, with the org-address metadata the backend needs, an optional discount, and a chosen payment-collection mode. Use this whenever the user wants to give an organization a plan, assign or create a subscription, make a subscription free or discounted, set up a custom or integrator plan for a client, or asks anything about creating subscriptions, coupons, or plan products in Stripe for Vocdoni, even if they only mention a customer email, a product name, or a 0x organization address.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Stripe subscription for a Vocdoni org
|
|
7
|
-
|
|
8
|
-
You are about to move real money settings on a live billing account. The
|
|
9
|
-
workflow below is shaped by mistakes that already happened once: the CLI
|
|
10
|
-
silently pointing at a sandbox instead of live, a subscription created for a
|
|
11
|
-
customer without a card (it dies `incomplete` after 23 hours), a discount
|
|
12
|
-
applied after creation so the first invoice had to be patched by hand, and a
|
|
13
|
-
coupon left open for anyone to reuse. Every step exists to make one of those
|
|
14
|
-
impossible.
|
|
15
|
-
|
|
16
|
-
Work through the phases in order. Never write to Stripe before the user has
|
|
17
|
-
confirmed the table in Phase 3.
|
|
18
|
-
|
|
19
|
-
## Phase 0: preflight
|
|
20
|
-
|
|
21
|
-
**Tooling.** You need `jq` (the scripts and every cookbook command parse
|
|
22
|
-
JSON with it) and one of:
|
|
23
|
-
|
|
24
|
-
- The Stripe CLI, installed and with a started session. Check with
|
|
25
|
-
`scripts/stripe-json.sh env` (without `STRIPE_ENV` it only reports the
|
|
26
|
-
account and mode; the environment is chosen in Phase 1). If it fails it prints what is missing and how
|
|
27
|
-
to fix it: install `jq`, install the CLI, `stripe login`, and
|
|
28
|
-
`stripe agent setup` to install the Stripe CLI agent skill. Install what
|
|
29
|
-
you can yourself (a package manager the user already uses is fine) and ask
|
|
30
|
-
the user for anything that needs their credentials or privileges. Do not
|
|
31
|
-
continue until it prints a mode.
|
|
32
|
-
- A connected Stripe MCP server (tools named `mcp__…stripe…`) with its skill.
|
|
33
|
-
The phases are the same; `references/stripe-cli.md` maps every CLI call to
|
|
34
|
-
the MCP equivalent and says which calls still need the CLI.
|
|
35
|
-
|
|
36
|
-
**Environment.** The environment is an input like any other, collected in
|
|
37
|
-
Phase 1 and shown in the confirmation table; do not infer it from what the CLI
|
|
38
|
-
happens to be pointing at. Once known, prefix every Stripe command with it and
|
|
39
|
-
with the account name `env` printed (`STRIPE_ENV=live STRIPE_ACCOUNT_NAME='…'
|
|
40
|
-
scripts/stripe-json.sh …`, same for `clone-product.sh`; the mode alone cannot
|
|
41
|
-
tell two live accounts apart):
|
|
42
|
-
agent shells usually do not keep an `export` between tool calls, and the
|
|
43
|
-
wrapper refuses to run without it rather than guess. Run every Stripe command
|
|
44
|
-
through `scripts/stripe-json.sh`, which reads the CLI's own banner to check
|
|
45
|
-
the mode and refuses on mismatch. If it reports a mismatch, compare against
|
|
46
|
-
the environment the user chose, not against whatever the error suggests. The CLI keeps one active account and a
|
|
47
|
-
`stripe switch` in another terminal changes it under you, so run
|
|
48
|
-
`scripts/stripe-json.sh env` again right before Phase 4. On mismatch tell the
|
|
49
|
-
user to run `! stripe switch` (it is interactive) and re-check.
|
|
50
|
-
|
|
51
|
-
**Sandbox is not isolated.** A sandbox account is wired to the dev and
|
|
52
|
-
staging backends through its webhook endpoints, so every write there changes
|
|
53
|
-
real org records in those backends. List them with
|
|
54
|
-
`webhook_endpoints list` and show the enabled URLs in the confirmation table.
|
|
55
|
-
When any is enabled, a subscription created for an org address moves that org
|
|
56
|
-
to the new plan in each of those backends at once, and canceling or deleting
|
|
57
|
-
it afterwards does not bring the previous plan back. Only use an org address
|
|
58
|
-
the user has confirmed is disposable in every listed backend, and do not
|
|
59
|
-
create "test" subscriptions to clean up later: there is no cleanup.
|
|
60
|
-
|
|
61
|
-
Read `references/stripe-cli.md` now for the command cookbook. Read
|
|
62
|
-
`references/backend-contract.md` if you need to know why a field matters.
|
|
63
|
-
|
|
64
|
-
## Phase 1: collect the minimum
|
|
65
|
-
|
|
66
|
-
Six things are required. Take what the user gave, then ask for the rest in a
|
|
67
|
-
single `AskUserQuestion` call (one question per missing item):
|
|
68
|
-
|
|
69
|
-
0. **Environment**: `live` or `sandbox`. Ask unless the user said it; offer
|
|
70
|
-
`live` first since that is what a real customer request means, but never
|
|
71
|
-
assume it silently. Whatever the answer, it is what `STRIPE_ENV` gets and
|
|
72
|
-
what the confirmation table shows.
|
|
73
|
-
1. **Customer**: email (or `cus_…` id). The customer must already exist.
|
|
74
|
-
2. **Org type**: integrator or regular. The new subscription replaces the
|
|
75
|
-
org's plan in the backend, and an integrator org is often on
|
|
76
|
-
`Integrator Free`, which has no Stripe subscription, so Stripe cannot tell
|
|
77
|
-
you. Take it from the user's wording ("integrator", "Integrator Free",
|
|
78
|
-
"managed orgs") or from an existing subscription on a product with
|
|
79
|
-
`integratorLimits.maxManagedOrgs > 0`; otherwise ask. Never guess regular.
|
|
80
|
-
3. **Product**: a catalog name (`Free`, `Starter`, `Professional`, `Custom`,
|
|
81
|
-
`Integrator Starter`, `Integrator Free`) or a `prod_…` id. `Custom` and
|
|
82
|
-
`Integrator Starter` are templates and go through Phase 2b. The product
|
|
83
|
-
keeps the org's type unless the user explicitly asks to change it: for an
|
|
84
|
-
integrator org, "upgrade", "custom plan" or no product at all means a copy
|
|
85
|
-
of `Integrator Starter`, never plain `Custom`; for a regular org, `Custom`.
|
|
86
|
-
A product of the other type is a type change: show it as such in the
|
|
87
|
-
Phase 3 table and only proceed if the user named that product.
|
|
88
|
-
4. **Billing interval**: `yearly` or `monthly` (or a `price_…` id). If the user
|
|
89
|
-
said nothing and the product's default price is yearly, propose yearly.
|
|
90
|
-
5. **Organization address**: `0x` + 40 hex chars. It becomes the subscription
|
|
91
|
-
metadata key `address`, the only thing linking the subscription to the org
|
|
92
|
-
in the backend. A missing or malformed value makes every webhook for that
|
|
93
|
-
subscription fail forever, so validate the shape before doing anything
|
|
94
|
-
else.
|
|
95
|
-
|
|
96
|
-
## Phase 2: resolve and validate (read-only)
|
|
97
|
-
|
|
98
|
-
- **Customer**: `customers list --email <email>`. Exactly one match, or stop
|
|
99
|
-
and report what you found. Note name, currency, `invoice_settings.default_payment_method`
|
|
100
|
-
and `payment_methods list --customer` (together they decide the collection
|
|
101
|
-
default: a card that is attached but not the customer's default is only
|
|
102
|
-
charged if you pass it as the subscription's `default_payment_method`).
|
|
103
|
-
A customer metadata `address` pointing to another org is not a blocker and
|
|
104
|
-
not a sign of the wrong customer (one customer may own several orgs'
|
|
105
|
-
subscriptions); note it in the Phase 3 table and leave it untouched.
|
|
106
|
-
- **Product and price**: search by name, then filter to the exact name because
|
|
107
|
-
search is a substring match and `Custom - someone@…` copies would otherwise
|
|
108
|
-
win. Then `prices list --product <id> --active` and pick the recurring price
|
|
109
|
-
for the chosen interval. Show amount, currency, nickname.
|
|
110
|
-
- **One org, one subscription**: list every non-canceled subscription
|
|
111
|
-
(active, trialing, past_due, unpaid, paused, incomplete), every page, and compare `metadata.address` case-insensitively
|
|
112
|
-
(see the cookbook; use the list, not search, because search lags by up to a
|
|
113
|
-
minute). If one exists,
|
|
114
|
-
stop and name it: the user should update or cancel that one instead.
|
|
115
|
-
- **Org type matches the product**: read the resolved product's
|
|
116
|
-
`integratorLimits`. An integrator org given a product without
|
|
117
|
-
`integratorLimits.maxManagedOrgs > 0` (plain `Custom`, `Starter`,
|
|
118
|
-
`Professional`) stops being an integrator, and a regular org given an
|
|
119
|
-
integrator product becomes one. If that does not match the Phase 1 type
|
|
120
|
-
and the user did not name the product explicitly, switch to the matching
|
|
121
|
-
template before going further.
|
|
122
|
-
- **Customer's other subscriptions**: warn, do not block.
|
|
123
|
-
- **Currency**: the price currency must match the customer's currency when the
|
|
124
|
-
customer already has one, or Stripe rejects the create.
|
|
125
|
-
|
|
126
|
-
## Phase 2b: template flow (Custom / Integrator Starter)
|
|
127
|
-
|
|
128
|
-
The backend reads plan limits from the product's metadata, so a customized
|
|
129
|
-
plan needs its own product. Read `references/product-templates.md` and:
|
|
130
|
-
|
|
131
|
-
1. Resolve the template by exact name and show its `organization`, `features`,
|
|
132
|
-
`votingTypes` (and `integratorLimits`) blocks as pretty JSON.
|
|
133
|
-
2. Ask what to change: per-block overrides (for example `2FAemail: 10000`), the
|
|
134
|
-
yearly/monthly amounts (custom plans are negotiated; default is the template
|
|
135
|
-
amount), a short client label for names, and the org email (defaults to the
|
|
136
|
-
customer email). Show a before/after of every block you change.
|
|
137
|
-
3. Run `scripts/clone-product.sh … --dry-run` and include its output in the
|
|
138
|
-
Phase 3 table so the user sees the exact product and prices to be created.
|
|
139
|
-
4. After confirmation, run it without `--dry-run`. It writes the copy with
|
|
140
|
-
`visibility=private`, `orgAddress`, `orgEmail`, `copiedFrom`, `copiedAt`,
|
|
141
|
-
creates one price per interval the template has (yearly and/or monthly),
|
|
142
|
-
and never sets a default price.
|
|
143
|
-
5. Read the product back and check: all metadata blocks parse as JSON, visibility
|
|
144
|
-
is private, one active recurring price per template interval, and for integrator copies
|
|
145
|
-
`integratorLimits.maxManagedOrgs > 0`. Then continue with its price.
|
|
146
|
-
|
|
147
|
-
## Phase 3: confirmation table
|
|
148
|
-
|
|
149
|
-
Render one table with everything chosen, then everything optional that is
|
|
150
|
-
still at its default, and ask a single `AskUserQuestion`: "Create it as shown?"
|
|
151
|
-
with options `Yes`, `Change something`. On `Change something`, collect the
|
|
152
|
-
change, re-render, ask again. Never proceed on silence or an implicit yes.
|
|
153
|
-
|
|
154
|
-
```
|
|
155
|
-
| Setting | Value |
|
|
156
|
-
|--------------------|---------------------------------------------------|
|
|
157
|
-
| Environment | live · Account Name |
|
|
158
|
-
| Backends notified | every enabled webhook endpoint URL |
|
|
159
|
-
| Customer | cus_xxx · Client Name · client@example.org |
|
|
160
|
-
| Product | prod_xxx · Professional |
|
|
161
|
-
| Org plan change | Integrator Free → Professional (not integrator) |
|
|
162
|
-
| Price | price_xxx · yearly · 1 890,00 EUR |
|
|
163
|
-
| metadata.address | 0x0000000000000000000000000000000000000000 |
|
|
164
|
-
| Customer address | 0x… (another org, left untouched) (or: empty) |
|
|
165
|
-
| Org billing email | becomes client@example.org (the customer email) |
|
|
166
|
-
| --- not defined (defaults) --- |
|
|
167
|
-
| Collection | send_invoice, due in 30 days (no card on file) |
|
|
168
|
-
| Discount | none |
|
|
169
|
-
| Trial | none |
|
|
170
|
-
| Start / anchor | now |
|
|
171
|
-
| Scheduled cancel | none |
|
|
172
|
-
| Description / meta | none |
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
What each optional row means and its alternatives:
|
|
176
|
-
|
|
177
|
-
- **Collection**. Default `send_invoice` with `days_until_due=30` when the
|
|
178
|
-
customer has no default payment method, else `charge_automatically`. If
|
|
179
|
-
the customer has saved payment methods but none is the default, ask which
|
|
180
|
-
one to charge and pass it as `default_payment_method`; without it Stripe
|
|
181
|
-
has nothing to charge and the subscription is left `incomplete`.
|
|
182
|
-
Alternatives: the other one, or a **checkout link** (a hosted Checkout
|
|
183
|
-
Session the customer pays; Stripe then creates the subscription itself, so
|
|
184
|
-
Phase 5 verifies the session instead). `charge_automatically` with no card
|
|
185
|
-
needs `payment_behavior=default_incomplete` and the user must know the
|
|
186
|
-
subscription expires in 23 hours unless the invoice gets paid.
|
|
187
|
-
- **Discount**. Only when the user asks for one. Before creating anything,
|
|
188
|
-
look for an existing fit: `coupons list` (valid, same percent/amount and
|
|
189
|
-
duration, redemptions left) and, if the user named a code,
|
|
190
|
-
`promotion_codes list --active`. Show matches in a small table and let the
|
|
191
|
-
user pick one or "create new". Otherwise create a single-use coupon
|
|
192
|
-
(`max_redemptions=1`, name tied to the client and reason). Either way it is
|
|
193
|
-
passed on the create call through `discounts[0][coupon]` so the first invoice
|
|
194
|
-
is already discounted; there is nothing to patch afterwards and nothing to
|
|
195
|
-
delete later. If the user does not want a discount, skip the lookup.
|
|
196
|
-
- **Trial**: `trial_period_days` or `trial_end`. If the chosen price carries
|
|
197
|
-
`freeTrialDays` metadata (copied onto a cloned price from its template),
|
|
198
|
-
that metadata alone does not create a Stripe trial — it is read by other
|
|
199
|
-
parts of the Vocdoni stack, not by `subscriptions create`. Ask the user
|
|
200
|
-
whether this subscription should also get that many days as a real Stripe
|
|
201
|
-
trial, or the customer is billed immediately.
|
|
202
|
-
- **Start / anchor**: `backdate_start_date`, `billing_cycle_anchor`.
|
|
203
|
-
- **Scheduled cancel**: `cancel_at` or `cancel_at_period_end`.
|
|
204
|
-
- **Description / extra metadata**: `description`, extra `metadata[...]`.
|
|
205
|
-
Never add customer metadata; the backend writes the customer's `address`
|
|
206
|
-
itself when it is empty and leaves an existing one alone.
|
|
207
|
-
|
|
208
|
-
## Phase 4: execute
|
|
209
|
-
|
|
210
|
-
1. `scripts/stripe-json.sh env` again. Stop on mismatch.
|
|
211
|
-
2. Template flow: `clone-product.sh` for real, then the read-back checks.
|
|
212
|
-
3. Discount: create the coupon now if a new one was chosen; capture its id.
|
|
213
|
-
4. `subscriptions create` with every chosen flag in one call (or
|
|
214
|
-
`checkout sessions create` for the link mode). See the cookbook for the
|
|
215
|
-
exact flags.
|
|
216
|
-
5. `send_invoice`: finalize the first invoice right away
|
|
217
|
-
(`invoices finalize_invoice`), but only if the create response's
|
|
218
|
-
`latest_invoice` exists and is still `draft`. A trial's zero invoice is
|
|
219
|
-
already `paid`, and a future `billing_cycle_anchor` may leave no invoice
|
|
220
|
-
at all; finalizing those fails after the subscription already exists, so
|
|
221
|
-
skip this step instead. A zero-total invoice becomes `paid` on the
|
|
222
|
-
spot; a real one gets a `hosted_invoice_url`. Finalizing by hand does not
|
|
223
|
-
email it: run `invoices send_invoice` too if the customer should get
|
|
224
|
-
Stripe's email. `finalize_invoice` and `send_invoice` each return a
|
|
225
|
-
different token in that URL for the same invoice; hand the customer the
|
|
226
|
-
one from whichever call you made last (or from the Phase 5 read-back),
|
|
227
|
-
not the finalize-time one if you also sent it.
|
|
228
|
-
|
|
229
|
-
Destructive CLI commands (`delete`, `delete_*`, `cancel`, `void_invoice`,
|
|
230
|
-
`mark_uncollectible`, `detach`) can prompt interactively and hang inside an
|
|
231
|
-
agent; the wrapper refuses them without `--confirm`, so always pass it.
|
|
232
|
-
|
|
233
|
-
## Phase 5: verify and report
|
|
234
|
-
|
|
235
|
-
Re-read from Stripe; never report from the create response.
|
|
236
|
-
`subscriptions retrieve <id> -d expand[0]=discounts -d expand[1]=latest_invoice`
|
|
237
|
-
(plus `coupons retrieve` for the discount row, since the discount only
|
|
238
|
-
carries the coupon id, and `products retrieve` and `prices list` for a cloned
|
|
239
|
-
product) and print:
|
|
240
|
-
|
|
241
|
-
```
|
|
242
|
-
| Item | Value |
|
|
243
|
-
|-------------------|---------------------------------------------------------|
|
|
244
|
-
| Subscription | sub_xxx · active |
|
|
245
|
-
| Customer | cus_xxx · Client Name · client@example.org |
|
|
246
|
-
| Product | prod_xxx · Professional (or: copy of Custom, private) |
|
|
247
|
-
| Price | price_xxx · yearly · 1 890,00 EUR |
|
|
248
|
-
| metadata.address | 0x0000000000000000000000000000000000000000 |
|
|
249
|
-
| Discount | coupon_xxx · 100% · forever · redeemed 1/1 (or none) |
|
|
250
|
-
| First invoice | in_xxx · paid · total 0,00 EUR · hosted URL |
|
|
251
|
-
| Collection | send_invoice · due in 30 days |
|
|
252
|
-
| Current period | until 2027-01-01 |
|
|
253
|
-
| Environment | live |
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
Follow with two or three sentences: what happens next (invoice emailed if you
|
|
257
|
-
sent it, link to hand over, backend picks a cloned product up on the
|
|
258
|
-
`product.updated` webhook fired by its activation, or at the next restart), and anything left at a default the user should know about
|
|
259
|
-
(for example, a free subscription still emits zero-value invoices in revenue
|
|
260
|
-
reports).
|
|
261
|
-
|
|
262
|
-
## When to stop instead of continuing
|
|
263
|
-
|
|
264
|
-
- The environment check fails or flips between phases.
|
|
265
|
-
- The customer is missing or ambiguous, the product name matches several
|
|
266
|
-
active products, or the address is malformed.
|
|
267
|
-
- Another active subscription already carries that address.
|
|
268
|
-
- The environment is sandbox, it has enabled webhook endpoints, and the user
|
|
269
|
-
has not confirmed the org address is disposable in those backends.
|
|
270
|
-
- The org is an integrator and the chosen product is not, and the user has
|
|
271
|
-
not confirmed the downgrade.
|
|
272
|
-
- The user asked for something this skill does not do: changing an existing
|
|
273
|
-
subscription, refunds, cancellations. Say so and offer the CLI command.
|
|
274
|
-
|
|
275
|
-
Related: [[stripe-best-practices]] for general Stripe API choices,
|
|
276
|
-
[[stripe-docs]] to look up a parameter this skill does not cover.
|