@effectstream/sm 0.100.15 → 0.100.17
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 +18 -13
- package/package.json +11 -11
- package/primitives/src/cardano-mint-burn/mint-burn-primitive.ts +15 -6
package/README.md
CHANGED
|
@@ -5,6 +5,11 @@ of commands, register one generator per command, and `Stm` parses each
|
|
|
5
5
|
incoming batcher input, dispatches it to the right handler, and yields
|
|
6
6
|
SQL updates through the runtime.
|
|
7
7
|
|
|
8
|
+
- State-machine DSL: define a typed grammar, register one generator per command.
|
|
9
|
+
- Parses each batcher input, dispatches to the handler, yields SQL through the runtime.
|
|
10
|
+
- `@effectstream/sm/builtin` ships common on-chain event primitives (ERC-20/721/1155, Cardano, Midnight, ...).
|
|
11
|
+
- DSL is directly testable in a pure-TS unit test, without a database.
|
|
12
|
+
|
|
8
13
|
## Install
|
|
9
14
|
|
|
10
15
|
```bash
|
|
@@ -22,8 +27,8 @@ it inside a per-block postgres transaction. You author the DSL here;
|
|
|
22
27
|
the runtime executes it.
|
|
23
28
|
|
|
24
29
|
The DSL is also directly testable in a pure-TS unit test (parse + dispatch
|
|
25
|
-
without a database)
|
|
26
|
-
[`primitives/src/evm-erc20/erc20-primitive.test.ts`](https://github.com/
|
|
30
|
+
without a database) - see
|
|
31
|
+
[`primitives/src/evm-erc20/erc20-primitive.test.ts`](https://github.com/effectstream/effectstream/blob/main/packages/node-sdk/sm/primitives/src/evm-erc20/erc20-primitive.test.ts).
|
|
27
32
|
|
|
28
33
|
```typescript
|
|
29
34
|
import { Stm } from "@effectstream/sm";
|
|
@@ -57,29 +62,29 @@ yields `World.resolve(...)` so the runtime can execute the pgtyped queries.
|
|
|
57
62
|
loop wires each user input through the corresponding `Stm` instance,
|
|
58
63
|
collects yielded SQL, and commits it inside the per-block transaction.
|
|
59
64
|
The built-in primitives package (`@effectstream/sm/builtin`) covers
|
|
60
|
-
common on-chain events
|
|
61
|
-
Midnight events, etc.
|
|
65
|
+
common on-chain events - ERC-20/721/1155 transfers, Cardano transfers,
|
|
66
|
+
Midnight events, etc. - so you don't re-implement them.
|
|
62
67
|
|
|
63
68
|
## Key exports
|
|
64
69
|
|
|
65
|
-
- `Stm<Grammar, Events
|
|
66
|
-
- `ParamToData<Params>`
|
|
67
|
-
- `BaseStfInput
|
|
68
|
-
- `delegate-wallet` helpers
|
|
70
|
+
- `Stm<Grammar, Events>`: the state machine. `.addStateTransition(prefix, handler)`, `.processInput(input)`, `.grammar`, `.fullJsonGrammar`, `.keyedJsonGrammar`.
|
|
71
|
+
- `ParamToData<Params>` derives the typed argument shape from a grammar entry.
|
|
72
|
+
- `BaseStfInput`: input shape passed to every handler. Includes `msTimestamp`, `blockHeight`, etc.
|
|
73
|
+
- `delegate-wallet` helpers - account delegation primitives reused by built-ins.
|
|
69
74
|
|
|
70
75
|
`MessageListener<Events, Params>` is exported as the handler type but is
|
|
71
76
|
inferred at call sites rather than imported directly.
|
|
72
77
|
|
|
73
78
|
Subpath exports:
|
|
74
79
|
|
|
75
|
-
- `@effectstream/sm/builtin
|
|
76
|
-
- `@effectstream/sm/grammar
|
|
80
|
+
- `@effectstream/sm/builtin`: `PrimitiveTypeERC20`, `PrimitiveTypeERC721`, `PrimitiveTypeERC1155`, `PrimitiveTypeCardanoTransfer`, `PrimitiveTypeMidnightGeneric`, and 20+ more chain-specific event tags.
|
|
81
|
+
- `@effectstream/sm/grammar`: the underlying grammar/parsing utilities, also re-exported from `@effectstream/concise`.
|
|
77
82
|
|
|
78
83
|
## Examples
|
|
79
84
|
|
|
80
|
-
- [`primitives/src/evm-erc20/erc20-primitive.test.ts`](https://github.com/
|
|
85
|
+
- [`primitives/src/evm-erc20/erc20-primitive.test.ts`](https://github.com/effectstream/effectstream/blob/main/packages/node-sdk/sm/primitives/src/evm-erc20/erc20-primitive.test.ts) - a real primitive's behavior unit-tested.
|
|
81
86
|
- Game logic in
|
|
82
|
-
[`templates/dice/packages/node/`](https://github.com/
|
|
87
|
+
[`templates/dice/packages/node/`](https://github.com/effectstream/effectstream/tree/main/templates/dice/packages/node)
|
|
83
88
|
shows the full `new Stm(...).addStateTransition(...)` pattern.
|
|
84
89
|
|
|
85
90
|
Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
|
|
@@ -87,4 +92,4 @@ Runnable: [`test/examples.test.ts`](./test/examples.test.ts).
|
|
|
87
92
|
## Links
|
|
88
93
|
|
|
89
94
|
- Docs: https://effectstream.github.io/docs/packages/node/sm
|
|
90
|
-
- Source: https://github.com/
|
|
95
|
+
- Source: https://github.com/effectstream/effectstream/tree/main/packages/node-sdk/sm
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/sm",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/
|
|
8
|
+
"url": "https://github.com/effectstream/effectstream",
|
|
9
9
|
"directory": "packages/node-sdk/sm"
|
|
10
10
|
},
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/effectstream/effectstream/issues"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./mod.ts",
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"./grammar": "./primitives/src/grammar.ts"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@effectstream/concise": "0.100.
|
|
21
|
-
"@effectstream/config": "0.100.
|
|
22
|
-
"@effectstream/coroutine": "0.100.
|
|
23
|
-
"@effectstream/crypto": "0.100.
|
|
24
|
-
"@effectstream/db": "0.100.
|
|
25
|
-
"@effectstream/event-client": "0.100.
|
|
26
|
-
"@effectstream/log": "0.100.
|
|
27
|
-
"@effectstream/utils": "0.100.
|
|
20
|
+
"@effectstream/concise": "0.100.17",
|
|
21
|
+
"@effectstream/config": "0.100.17",
|
|
22
|
+
"@effectstream/coroutine": "0.100.17",
|
|
23
|
+
"@effectstream/crypto": "0.100.17",
|
|
24
|
+
"@effectstream/db": "0.100.17",
|
|
25
|
+
"@effectstream/event-client": "0.100.17",
|
|
26
|
+
"@effectstream/log": "0.100.17",
|
|
27
|
+
"@effectstream/utils": "0.100.17",
|
|
28
28
|
"pg": "8.17.2",
|
|
29
29
|
"pg-tx": "^1.0.1",
|
|
30
30
|
"@sinclair/typebox": "0.34.41",
|
|
@@ -63,14 +63,23 @@ export class CardanoMintBurnPrimitive extends Primitive<
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
override getConfig(): ProtocolPrimitiveMap[ConfigSyncProtocolType.CARDANO_UTXORPC_PARALLEL] {
|
|
66
|
+
// UTxO-RPC's `mints_asset` predicate is interpreted by Dolos as
|
|
67
|
+
// "creates new supply" — it matches only positive-quantity mints and
|
|
68
|
+
// silently filters burns. To catch burns we also match `moves_asset`,
|
|
69
|
+
// which fires when the asset appears in any input/output of the tx
|
|
70
|
+
// (true for burns, since the asset is in the input UTxO being spent).
|
|
71
|
+
// Downstream consumers see both mint and burn payloads through the
|
|
72
|
+
// same primitive; sign-of-quantity discriminates.
|
|
73
|
+
const matchPolicy = (pid: string): UtxorpcTxPredicate => ({
|
|
74
|
+
any_of: [
|
|
75
|
+
{ match: { cardano: { mints_asset: { policy_id: pid } } } },
|
|
76
|
+
{ match: { cardano: { moves_asset: { policy_id: pid } } } },
|
|
77
|
+
],
|
|
78
|
+
});
|
|
66
79
|
const predicate: UtxorpcTxPredicate =
|
|
67
80
|
this.policyIds.length === 1
|
|
68
|
-
?
|
|
69
|
-
: {
|
|
70
|
-
any_of: this.policyIds.map((pid) => ({
|
|
71
|
-
match: { cardano: { mints_asset: { policy_id: pid } } },
|
|
72
|
-
})),
|
|
73
|
-
};
|
|
81
|
+
? matchPolicy(this.policyIds[0])
|
|
82
|
+
: { any_of: this.policyIds.map(matchPolicy) };
|
|
74
83
|
|
|
75
84
|
return {
|
|
76
85
|
name: this.instanceName,
|