@effectstream/sm 0.100.22 → 0.100.23
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/sm",
|
|
3
|
-
"version": "0.100.
|
|
3
|
+
"version": "0.100.23",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -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.23",
|
|
21
|
+
"@effectstream/config": "0.100.23",
|
|
22
|
+
"@effectstream/coroutine": "0.100.23",
|
|
23
|
+
"@effectstream/crypto": "0.100.23",
|
|
24
|
+
"@effectstream/db": "0.100.23",
|
|
25
|
+
"@effectstream/event-client": "0.100.23",
|
|
26
|
+
"@effectstream/log": "0.100.23",
|
|
27
|
+
"@effectstream/utils": "0.100.23",
|
|
28
28
|
"pg": "8.21.0",
|
|
29
29
|
"pg-tx": "^1.0.1",
|
|
30
30
|
"@sinclair/typebox": "0.34.41",
|
|
@@ -5,6 +5,7 @@ export const PrimitiveTypeMidnightNullifier = "Midnight:Nullifier" as const;
|
|
|
5
5
|
export const PrimitiveTypeMidnightUnshieldedSpend = "Midnight:UnshieldedSpend" as const;
|
|
6
6
|
export const PrimitiveTypeMidnightUnshieldedCreate = "Midnight:UnshieldedCreate" as const;
|
|
7
7
|
export const PrimitiveTypeMidnightZswapRoot = "Midnight:ZswapRoot" as const;
|
|
8
|
+
export const PrimitiveTypeMidnightTokenMint = "Midnight:TokenMint" as const;
|
|
8
9
|
|
|
9
10
|
export const PrimitiveTypeUtxorpcGeneric = "Utxorpc:Generic" as const;
|
|
10
11
|
export const PrimitiveTypeCardanoMintBurn = "Cardano:MintBurn" as const;
|
|
@@ -38,6 +39,7 @@ type BuiltInPrimitives =
|
|
|
38
39
|
typeof PrimitiveTypeMidnightUnshieldedSpend |
|
|
39
40
|
typeof PrimitiveTypeMidnightUnshieldedCreate |
|
|
40
41
|
typeof PrimitiveTypeMidnightZswapRoot |
|
|
42
|
+
typeof PrimitiveTypeMidnightTokenMint |
|
|
41
43
|
typeof PrimitiveTypeEVMEffectstreamL2 |
|
|
42
44
|
typeof PrimitiveTypeEVMERC721 |
|
|
43
45
|
typeof PrimitiveTypeEVMERC20 |
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Primitive } from "@effectstream/sm";
|
|
2
|
+
import {
|
|
3
|
+
type AddressAndType,
|
|
4
|
+
AddressType,
|
|
5
|
+
type EffectstreamBlockNumber,
|
|
6
|
+
} from "@effectstream/utils";
|
|
7
|
+
import type { StaticDecode } from "@sinclair/typebox";
|
|
8
|
+
import {
|
|
9
|
+
type CommandTuple,
|
|
10
|
+
generateRawStmInput,
|
|
11
|
+
type ParamToData,
|
|
12
|
+
} from "@effectstream/concise";
|
|
13
|
+
import type {
|
|
14
|
+
ConfigSyncProtocolType,
|
|
15
|
+
FlattenSyncProtocolIOFor,
|
|
16
|
+
ProtocolPrimitiveMap,
|
|
17
|
+
} from "@effectstream/config";
|
|
18
|
+
import type { SyncStateUpdateStream } from "@effectstream/coroutine";
|
|
19
|
+
import { PrimitiveTypeMidnightTokenMint } from "../builtin.ts";
|
|
20
|
+
import { midnightTokenMintGrammar } from "./midnight-token-mint-grammar.ts";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* MidnightTokenMintPrimitive
|
|
24
|
+
*
|
|
25
|
+
* Watches custom token *mints* on the Midnight ledger. A contract call's
|
|
26
|
+
* effects record minted tokens as `domain_sep → amount` maps (shielded and
|
|
27
|
+
* unshielded), and the resulting token type ("color") is derived as
|
|
28
|
+
* `rawTokenType(domain_sep, contract_address)` — so this primitive is the
|
|
29
|
+
* only way for a consumer to map a wallet-visible token id back to the
|
|
30
|
+
* contract that minted it. The fetcher deserializes each regular
|
|
31
|
+
* transaction's raw bytes with ledger-v8, walks the contract calls, and
|
|
32
|
+
* emits one state-machine input per `(tx, call, domainSep, kind)` — only
|
|
33
|
+
* for effects that actually applied on chain (failed segments roll back).
|
|
34
|
+
*
|
|
35
|
+
* The mint nonce is NOT part of token identity (it only randomizes coin
|
|
36
|
+
* commitments) and is never public for shielded mints, so it is not part
|
|
37
|
+
* of the payload.
|
|
38
|
+
*
|
|
39
|
+
* Usage:
|
|
40
|
+
* stm.addStateTransition("myPrefix", function* (data) {
|
|
41
|
+
* const { payload } = data.parsedInput;
|
|
42
|
+
* // payload = { txHash, contractAddress, domainSep, rawTokenType,
|
|
43
|
+
* // kind: "shielded" | "unshielded", amount, entryPoint }
|
|
44
|
+
* // amount is a decimal string (u64 mints can exceed MAX_SAFE_INTEGER)
|
|
45
|
+
* });
|
|
46
|
+
*/
|
|
47
|
+
export class MidnightTokenMintPrimitive extends Primitive<
|
|
48
|
+
ConfigSyncProtocolType.MIDNIGHT_PARALLEL,
|
|
49
|
+
typeof midnightTokenMintGrammar
|
|
50
|
+
> {
|
|
51
|
+
readonly internalTypeName = PrimitiveTypeMidnightTokenMint;
|
|
52
|
+
override readonly grammar = midnightTokenMintGrammar;
|
|
53
|
+
|
|
54
|
+
override dynamicTables = undefined;
|
|
55
|
+
override getIntermediatePrefix(): string[] {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
override getViewPrefix(): string[] {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
constructor(config: {
|
|
63
|
+
instanceName: string;
|
|
64
|
+
startBlockHeight: number;
|
|
65
|
+
stateMachinePrefix: string;
|
|
66
|
+
}) {
|
|
67
|
+
super(config);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
override *getPayload(
|
|
71
|
+
_: EffectstreamBlockNumber,
|
|
72
|
+
primitiveTransactionData: FlattenSyncProtocolIOFor<
|
|
73
|
+
ConfigSyncProtocolType.MIDNIGHT_PARALLEL
|
|
74
|
+
>,
|
|
75
|
+
): SyncStateUpdateStream<{
|
|
76
|
+
isBatched: boolean;
|
|
77
|
+
data: {
|
|
78
|
+
fromAddressAndType: AddressAndType;
|
|
79
|
+
stateMachinePayload:
|
|
80
|
+
| StaticDecode<CommandTuple<string, typeof midnightTokenMintGrammar>>
|
|
81
|
+
| null;
|
|
82
|
+
accountingPayload: ParamToData<typeof midnightTokenMintGrammar>;
|
|
83
|
+
}[];
|
|
84
|
+
}> {
|
|
85
|
+
const payload = primitiveTransactionData.output.payload;
|
|
86
|
+
|
|
87
|
+
const accountingPayload: ParamToData<typeof this.grammar> = {
|
|
88
|
+
payload,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const stateMachinePayload:
|
|
92
|
+
| StaticDecode<CommandTuple<string, typeof this.grammar>>
|
|
93
|
+
| null = this.stateMachinePrefix
|
|
94
|
+
? generateRawStmInput(
|
|
95
|
+
this.grammar,
|
|
96
|
+
this.stateMachinePrefix,
|
|
97
|
+
accountingPayload,
|
|
98
|
+
)
|
|
99
|
+
: null;
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
isBatched: false,
|
|
103
|
+
data: [
|
|
104
|
+
{
|
|
105
|
+
fromAddressAndType: {
|
|
106
|
+
type: AddressType.NONE,
|
|
107
|
+
address: "0x0",
|
|
108
|
+
},
|
|
109
|
+
accountingPayload,
|
|
110
|
+
stateMachinePayload,
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
override getConfig(): ProtocolPrimitiveMap[
|
|
117
|
+
ConfigSyncProtocolType.MIDNIGHT_PARALLEL
|
|
118
|
+
] {
|
|
119
|
+
return {
|
|
120
|
+
name: this.instanceName,
|
|
121
|
+
type: this.internalTypeName,
|
|
122
|
+
startBlockHeight: this.startBlockHeight,
|
|
123
|
+
scheduledPrefix: this.stateMachinePrefix ?? "",
|
|
124
|
+
} as const;
|
|
125
|
+
}
|
|
126
|
+
}
|
package/primitives/src/mod.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
PrimitiveTypeMidnightUnshieldedSpend,
|
|
5
5
|
PrimitiveTypeMidnightUnshieldedCreate,
|
|
6
6
|
PrimitiveTypeMidnightZswapRoot,
|
|
7
|
+
PrimitiveTypeMidnightTokenMint,
|
|
7
8
|
PrimitiveTypeEVMEffectstreamL2,
|
|
8
9
|
PrimitiveTypeEVMERC721,
|
|
9
10
|
PrimitiveTypeEVMERC20,
|
|
@@ -31,6 +32,7 @@ import { MidnightNullifierPrimitive } from "./midnight-nullifier/midnight-nullif
|
|
|
31
32
|
import { MidnightUnshieldedSpendPrimitive } from "./midnight-unshielded-spend/midnight-unshielded-spend.ts";
|
|
32
33
|
import { MidnightUnshieldedCreatePrimitive } from "./midnight-unshielded-create/midnight-unshielded-create.ts";
|
|
33
34
|
import { MidnightZswapRootPrimitive } from "./midnight-zswap-root/midnight-zswap-root.ts";
|
|
35
|
+
import { MidnightTokenMintPrimitive } from "./midnight-token-mint/midnight-token-mint.ts";
|
|
34
36
|
import { EffectstreamL2Primitive } from "./evm-effectstream-l2/effectstream-l2-primitive.ts";
|
|
35
37
|
import { Erc721Primitive } from "./evm-erc721/erc721-primitive.ts";
|
|
36
38
|
import { Erc20Primitive } from "./evm-erc20/erc20-primitive.ts";
|
|
@@ -58,6 +60,7 @@ const builtInPrimitivesMap = {
|
|
|
58
60
|
[PrimitiveTypeMidnightUnshieldedSpend]: MidnightUnshieldedSpendPrimitive,
|
|
59
61
|
[PrimitiveTypeMidnightUnshieldedCreate]: MidnightUnshieldedCreatePrimitive,
|
|
60
62
|
[PrimitiveTypeMidnightZswapRoot]: MidnightZswapRootPrimitive,
|
|
63
|
+
[PrimitiveTypeMidnightTokenMint]: MidnightTokenMintPrimitive,
|
|
61
64
|
[PrimitiveTypeEVMEffectstreamL2]: EffectstreamL2Primitive,
|
|
62
65
|
[PrimitiveTypeEVMERC721]: Erc721Primitive,
|
|
63
66
|
[PrimitiveTypeEVMERC20]: Erc20Primitive,
|
|
@@ -90,6 +93,7 @@ export {
|
|
|
90
93
|
MidnightUnshieldedSpendPrimitive,
|
|
91
94
|
MidnightUnshieldedCreatePrimitive,
|
|
92
95
|
MidnightZswapRootPrimitive,
|
|
96
|
+
MidnightTokenMintPrimitive,
|
|
93
97
|
EffectstreamL2Primitive,
|
|
94
98
|
Erc721Primitive,
|
|
95
99
|
Erc20Primitive,
|