@pushchain/core 6.0.26 → 6.0.27-alpha.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.
Files changed (171) hide show
  1. package/AGW.md +226 -0
  2. package/CHANGELOG.md +18 -0
  3. package/README.md +2 -0
  4. package/package.json +7 -1
  5. package/src/lib/agentic/agentic.d.ts +23 -0
  6. package/src/lib/agentic/agentic.js +51 -0
  7. package/src/lib/agentic/agentic.types.d.ts +414 -0
  8. package/src/lib/agentic/agentic.types.js +3 -0
  9. package/src/lib/agentic/capabilities.d.ts +37 -0
  10. package/src/lib/agentic/capabilities.js +64 -0
  11. package/src/lib/agentic/chain.d.ts +3 -0
  12. package/src/lib/agentic/chain.js +15 -0
  13. package/src/lib/agentic/codec/abi-layout.d.ts +20 -0
  14. package/src/lib/agentic/codec/abi-layout.js +168 -0
  15. package/src/lib/agentic/codec/defaults.d.ts +51 -0
  16. package/src/lib/agentic/codec/defaults.js +53 -0
  17. package/src/lib/agentic/codec/ids.d.ts +35 -0
  18. package/src/lib/agentic/codec/ids.js +74 -0
  19. package/src/lib/agentic/codec/native.d.ts +73 -0
  20. package/src/lib/agentic/codec/native.js +341 -0
  21. package/src/lib/agentic/codec/pins.d.ts +20 -0
  22. package/src/lib/agentic/codec/pins.js +29 -0
  23. package/src/lib/agentic/codec/rules.d.ts +45 -0
  24. package/src/lib/agentic/codec/rules.js +110 -0
  25. package/src/lib/agentic/codec/selectors.d.ts +19 -0
  26. package/src/lib/agentic/codec/selectors.js +60 -0
  27. package/src/lib/agentic/codec/session.d.ts +54 -0
  28. package/src/lib/agentic/codec/session.js +65 -0
  29. package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
  30. package/src/lib/agentic/codec/svm-accounts.js +68 -0
  31. package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
  32. package/src/lib/agentic/codec/svm-idl.js +226 -0
  33. package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
  34. package/src/lib/agentic/codec/svm-terms.js +246 -0
  35. package/src/lib/agentic/codec/universal-terms.d.ts +82 -0
  36. package/src/lib/agentic/codec/universal-terms.js +43 -0
  37. package/src/lib/agentic/codec/universal.d.ts +14 -0
  38. package/src/lib/agentic/codec/universal.js +173 -0
  39. package/src/lib/agentic/constants.d.ts +12 -0
  40. package/src/lib/agentic/constants.js +16 -0
  41. package/src/lib/agentic/context.d.ts +29 -0
  42. package/src/lib/agentic/context.js +56 -0
  43. package/src/lib/agentic/contracts/abi/v6/agent-validator.d.ts +105 -0
  44. package/src/lib/agentic/contracts/abi/v6/agent-validator.js +149 -0
  45. package/src/lib/agentic/contracts/abi/v6/agw-factory.d.ts +1146 -0
  46. package/src/lib/agentic/contracts/abi/v6/agw-factory.js +1499 -0
  47. package/src/lib/agentic/contracts/abi/v6/agw.d.ts +1306 -0
  48. package/src/lib/agentic/contracts/abi/v6/agw.js +1713 -0
  49. package/src/lib/agentic/contracts/abi/v6/index.d.ts +6 -0
  50. package/src/lib/agentic/contracts/abi/v6/index.js +17 -0
  51. package/src/lib/agentic/contracts/abi/v6/smart-session.d.ts +1493 -0
  52. package/src/lib/agentic/contracts/abi/v6/smart-session.js +1965 -0
  53. package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.d.ts +1661 -0
  54. package/src/lib/agentic/contracts/abi/v6/universal-rules-policy.js +2187 -0
  55. package/src/lib/agentic/contracts/donut-v6.d.ts +11 -0
  56. package/src/lib/agentic/contracts/donut-v6.js +15 -0
  57. package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
  58. package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
  59. package/src/lib/agentic/contracts/reader.d.ts +35 -0
  60. package/src/lib/agentic/contracts/reader.js +16 -0
  61. package/src/lib/agentic/contracts/v6.d.ts +5739 -0
  62. package/src/lib/agentic/contracts/v6.js +343 -0
  63. package/src/lib/agentic/deployments.d.ts +61 -0
  64. package/src/lib/agentic/deployments.js +203 -0
  65. package/src/lib/agentic/errors.d.ts +65 -0
  66. package/src/lib/agentic/errors.js +84 -0
  67. package/src/lib/agentic/execution/guards.d.ts +9 -0
  68. package/src/lib/agentic/execution/guards.js +30 -0
  69. package/src/lib/agentic/execution/outbound.d.ts +55 -0
  70. package/src/lib/agentic/execution/outbound.js +187 -0
  71. package/src/lib/agentic/execution/send.d.ts +9 -0
  72. package/src/lib/agentic/execution/send.js +268 -0
  73. package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
  74. package/src/lib/agentic/execution/svm-instruction.js +40 -0
  75. package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
  76. package/src/lib/agentic/execution/svm-outbound.js +86 -0
  77. package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
  78. package/src/lib/agentic/execution/svm-payload.js +136 -0
  79. package/src/lib/agentic/execution/svm-public.d.ts +5 -0
  80. package/src/lib/agentic/execution/svm-public.js +176 -0
  81. package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
  82. package/src/lib/agentic/execution/svm-quote.js +24 -0
  83. package/src/lib/agentic/execution/svm-send.d.ts +44 -0
  84. package/src/lib/agentic/execution/svm-send.js +87 -0
  85. package/src/lib/agentic/index.d.ts +5 -0
  86. package/src/lib/agentic/index.js +10 -0
  87. package/src/lib/agentic/management/common.d.ts +29 -0
  88. package/src/lib/agentic/management/common.js +116 -0
  89. package/src/lib/agentic/management/create.d.ts +4 -0
  90. package/src/lib/agentic/management/create.js +138 -0
  91. package/src/lib/agentic/management/duplicates.d.ts +4 -0
  92. package/src/lib/agentic/management/duplicates.js +20 -0
  93. package/src/lib/agentic/management/label.d.ts +3 -0
  94. package/src/lib/agentic/management/label.js +17 -0
  95. package/src/lib/agentic/management/prepare.d.ts +7 -0
  96. package/src/lib/agentic/management/prepare.js +95 -0
  97. package/src/lib/agentic/management/rules-write.d.ts +42 -0
  98. package/src/lib/agentic/management/rules-write.js +279 -0
  99. package/src/lib/agentic/management/svm-context.d.ts +25 -0
  100. package/src/lib/agentic/management/svm-context.js +55 -0
  101. package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
  102. package/src/lib/agentic/management/svm-metadata.js +56 -0
  103. package/src/lib/agentic/management/svm-public.d.ts +6 -0
  104. package/src/lib/agentic/management/svm-public.js +125 -0
  105. package/src/lib/agentic/management/svm.d.ts +27 -0
  106. package/src/lib/agentic/management/svm.js +150 -0
  107. package/src/lib/agentic/presets/catalog.d.ts +26 -0
  108. package/src/lib/agentic/presets/catalog.js +307 -0
  109. package/src/lib/agentic/presets/index.d.ts +5 -0
  110. package/src/lib/agentic/presets/index.js +265 -0
  111. package/src/lib/agentic/presets/types.d.ts +48 -0
  112. package/src/lib/agentic/presets/types.js +3 -0
  113. package/src/lib/agentic/public-rule.d.ts +9 -0
  114. package/src/lib/agentic/public-rule.js +326 -0
  115. package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
  116. package/src/lib/agentic/reads/checkpoints.js +109 -0
  117. package/src/lib/agentic/reads/rules.d.ts +42 -0
  118. package/src/lib/agentic/reads/rules.js +302 -0
  119. package/src/lib/agentic/reads/snapshot.d.ts +28 -0
  120. package/src/lib/agentic/reads/snapshot.js +85 -0
  121. package/src/lib/agentic/reads/svm.d.ts +17 -0
  122. package/src/lib/agentic/reads/svm.js +52 -0
  123. package/src/lib/agentic/reads/wallets.d.ts +25 -0
  124. package/src/lib/agentic/reads/wallets.js +122 -0
  125. package/src/lib/agentic/response.d.ts +41 -0
  126. package/src/lib/agentic/response.js +358 -0
  127. package/src/lib/agentic/revert.d.ts +7 -0
  128. package/src/lib/agentic/revert.js +102 -0
  129. package/src/lib/agentic/runtime.d.ts +58 -0
  130. package/src/lib/agentic/runtime.js +104 -0
  131. package/src/lib/agentic/utils.d.ts +57 -0
  132. package/src/lib/agentic/utils.js +165 -0
  133. package/src/lib/agentic/wallet.d.ts +32 -0
  134. package/src/lib/agentic/wallet.js +130 -0
  135. package/src/lib/constants/enums.d.ts +6 -3
  136. package/src/lib/constants/enums.js +6 -3
  137. package/src/lib/constants/index.d.ts +61 -4
  138. package/src/lib/constants/index.js +17 -3
  139. package/src/lib/constants/read-state.d.ts +9 -0
  140. package/src/lib/constants/read-state.js +13 -1
  141. package/src/lib/index.d.ts +8 -2
  142. package/src/lib/index.js +9 -1
  143. package/src/lib/orchestrator/internals/errors.d.ts +7 -0
  144. package/src/lib/orchestrator/internals/errors.js +13 -1
  145. package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
  146. package/src/lib/orchestrator/internals/execute-standard.js +3 -3
  147. package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
  148. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
  149. package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
  150. package/src/lib/orchestrator/orchestrator.d.ts +3 -0
  151. package/src/lib/orchestrator/orchestrator.js +13 -1
  152. package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
  153. package/src/lib/orchestrator/route-detector.js +3 -2
  154. package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
  155. package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
  156. package/src/lib/progress-hook/progress-hook.js +63 -0
  157. package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
  158. package/src/lib/progress-hook/progress-hook.types.js +10 -0
  159. package/src/lib/push-chain/push-chain.d.ts +57 -15
  160. package/src/lib/push-chain/push-chain.js +66 -7
  161. package/src/lib/read-state/destination.js +6 -1
  162. package/src/lib/read-state/read-params.d.ts +3 -3
  163. package/src/lib/read-state/read-params.js +3 -2
  164. package/src/lib/read-state/read-state.types.d.ts +3 -1
  165. package/src/lib/read-state/read-tracker.js +2 -2
  166. package/src/lib/read-state/spec-builder.js +1 -1
  167. package/src/lib/universal/prc20-address.d.ts +15 -0
  168. package/src/lib/universal/prc20-address.js +135 -0
  169. package/src/lib/utils.d.ts +6 -13
  170. package/src/lib/utils.js +5 -128
  171. package/src/lib/vm-client/evm-client.js +34 -20
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.v6 = exports.UEA_MULTICALL_PREFIX = exports.SEND_OUTBOUND_SELECTOR = exports.MODE_BATCH = exports.MODE_SINGLE = void 0;
4
+ const viem_1 = require("viem");
5
+ const v6_1 = require("./abi/v6");
6
+ exports.MODE_SINGLE = `0x${'00'.repeat(32)}`;
7
+ exports.MODE_BATCH = `0x01${'00'.repeat(31)}`;
8
+ exports.SEND_OUTBOUND_SELECTOR = '0x77b86bec';
9
+ exports.UEA_MULTICALL_PREFIX = '0x2cc2842d';
10
+ const CHECKPOINT_KINDS = [
11
+ 'OWNER_ACTION',
12
+ 'RULES_GRANTED',
13
+ 'RULES_REVOKED',
14
+ ];
15
+ const EXECUTION_TUPLE = [
16
+ {
17
+ type: 'tuple[]',
18
+ components: [
19
+ { name: 'target', type: 'address' },
20
+ { name: 'value', type: 'uint256' },
21
+ { name: 'callData', type: 'bytes' },
22
+ ],
23
+ },
24
+ ];
25
+ exports.v6 = {
26
+ id: 'v6',
27
+ abis: {
28
+ wallet: v6_1.AGW_ABI,
29
+ factory: v6_1.AGW_FACTORY_ABI,
30
+ engine: v6_1.SMART_SESSION_ABI,
31
+ policy: v6_1.UNIVERSAL_RULES_POLICY_ABI,
32
+ },
33
+ events: {
34
+ walletDeployed: (0, viem_1.getAbiItem)({
35
+ abi: v6_1.AGW_FACTORY_ABI,
36
+ name: 'WalletDeployed',
37
+ }),
38
+ checkpointed: (0, viem_1.getAbiItem)({
39
+ abi: v6_1.AGW_ABI,
40
+ name: 'Checkpointed',
41
+ }),
42
+ rulesGranted: (0, viem_1.getAbiItem)({
43
+ abi: v6_1.AGW_ABI,
44
+ name: 'RulesGranted',
45
+ }),
46
+ rulesRevoked: (0, viem_1.getAbiItem)({
47
+ abi: v6_1.AGW_ABI,
48
+ name: 'RulesRevoked',
49
+ }),
50
+ },
51
+ // ---------------------------------------------------------------- encoders
52
+ encodeDeployWallet(label) {
53
+ return (0, viem_1.encodeFunctionData)({
54
+ abi: v6_1.AGW_FACTORY_ABI,
55
+ functionName: 'deployWallet',
56
+ args: [label],
57
+ });
58
+ },
59
+ /**
60
+ * Index-bound deployment for an owner calling the factory itself.
61
+ * deployWalletWithSig skips signature checks when msg.sender == intent.owner
62
+ * but still reverts IndexMismatch / IntentWalletMismatch unless the owner's
63
+ * next slot is exactly `index` and predicts to `wallet`. A concurrent
64
+ * creation therefore makes this call revert instead of deploying another
65
+ * slot while later calls in the batch target the predicted address.
66
+ */
67
+ encodeDeployWalletAt(owner, index, wallet, label) {
68
+ const zero32 = `0x${'00'.repeat(32)}`;
69
+ const zeroAddress = '0x0000000000000000000000000000000000000000';
70
+ return (0, viem_1.encodeFunctionData)({
71
+ abi: v6_1.AGW_FACTORY_ABI,
72
+ functionName: 'deployWalletWithSig',
73
+ args: [
74
+ {
75
+ owner,
76
+ wallet,
77
+ executor: zeroAddress,
78
+ index,
79
+ sessionHash: zero32,
80
+ mode: zero32,
81
+ execCalldataHash: zero32,
82
+ nonceKey: BigInt(0),
83
+ nonceSeq: BigInt(0),
84
+ grantNonce: BigInt(0),
85
+ deadline: 0,
86
+ signerChainId: BigInt(0),
87
+ },
88
+ '0x',
89
+ label,
90
+ ],
91
+ });
92
+ },
93
+ encodeCreateWalletAt(owner, index, wallet, label, rules) {
94
+ const zero32 = `0x${'00'.repeat(32)}`;
95
+ const zeroAddress = '0x0000000000000000000000000000000000000000';
96
+ return (0, viem_1.encodeFunctionData)({
97
+ abi: v6_1.AGW_FACTORY_ABI,
98
+ functionName: 'createWalletWithSig',
99
+ args: [
100
+ {
101
+ owner,
102
+ wallet,
103
+ executor: zeroAddress,
104
+ index,
105
+ sessionHash: zero32,
106
+ mode: zero32,
107
+ execCalldataHash: zero32,
108
+ nonceKey: BigInt(0),
109
+ nonceSeq: BigInt(0),
110
+ grantNonce: BigInt(0),
111
+ deadline: 0,
112
+ signerChainId: BigInt(0),
113
+ },
114
+ '0x',
115
+ label,
116
+ rules,
117
+ ],
118
+ });
119
+ },
120
+ encodeGrantRules(session) {
121
+ return (0, viem_1.encodeFunctionData)({
122
+ abi: v6_1.AGW_ABI,
123
+ functionName: 'grantRules',
124
+ args: [session],
125
+ });
126
+ },
127
+ encodeRevokeRules(rulesId) {
128
+ return (0, viem_1.encodeFunctionData)({
129
+ abi: v6_1.AGW_ABI,
130
+ functionName: 'revokeRules',
131
+ args: [rulesId],
132
+ });
133
+ },
134
+ encodeRevokeAllRules() {
135
+ return (0, viem_1.encodeFunctionData)({
136
+ abi: v6_1.AGW_ABI,
137
+ functionName: 'revokeAllRules',
138
+ args: [],
139
+ });
140
+ },
141
+ encodeSetLabel(label) {
142
+ return (0, viem_1.encodeFunctionData)({
143
+ abi: v6_1.AGW_ABI,
144
+ functionName: 'setLabel',
145
+ args: [label],
146
+ });
147
+ },
148
+ /** ERC-7579 single execution calldata: abi.encodePacked(target, value, callData). */
149
+ packSingle(call) {
150
+ return (0, viem_1.encodePacked)(['address', 'uint256', 'bytes'], [call.target, call.value, call.data]);
151
+ },
152
+ encodeExecute(calls) {
153
+ if (calls.length === 0)
154
+ throw new Error('execute needs at least one call');
155
+ if (calls.length === 1) {
156
+ return (0, viem_1.encodeFunctionData)({
157
+ abi: v6_1.AGW_ABI,
158
+ functionName: 'execute',
159
+ args: [exports.MODE_SINGLE, exports.v6.packSingle(calls[0])],
160
+ });
161
+ }
162
+ const batch = (0, viem_1.encodeAbiParameters)(EXECUTION_TUPLE, [
163
+ calls.map((c) => ({
164
+ target: c.target,
165
+ value: c.value,
166
+ callData: c.data,
167
+ })),
168
+ ]);
169
+ return (0, viem_1.encodeFunctionData)({
170
+ abi: v6_1.AGW_ABI,
171
+ functionName: 'execute',
172
+ args: [exports.MODE_BATCH, batch],
173
+ });
174
+ },
175
+ encodeExecuteAsAgent(rulesId, call) {
176
+ return (0, viem_1.encodeFunctionData)({
177
+ abi: v6_1.AGW_ABI,
178
+ functionName: 'executeAsAgent',
179
+ args: [rulesId, exports.MODE_SINGLE, exports.v6.packSingle(call)],
180
+ });
181
+ },
182
+ encodeAssertSpentNative(configId, wallet, expected) {
183
+ return (0, viem_1.encodeFunctionData)({
184
+ abi: v6_1.UNIVERSAL_RULES_POLICY_ABI,
185
+ functionName: 'assertSpent',
186
+ args: [
187
+ configId,
188
+ wallet,
189
+ expected.valueSpent,
190
+ expected.amountSpent,
191
+ expected.callsUsed,
192
+ ],
193
+ });
194
+ },
195
+ encodeAssertSpentUniversal(configId, wallet, expectedSpent) {
196
+ return (0, viem_1.encodeFunctionData)({
197
+ abi: v6_1.UNIVERSAL_RULES_POLICY_ABI,
198
+ functionName: 'assertSpent',
199
+ args: [configId, wallet, expectedSpent],
200
+ });
201
+ },
202
+ // ---------------------------------------------------------------- decoders
203
+ decodeWalletCall(data) {
204
+ let decoded;
205
+ try {
206
+ decoded = (0, viem_1.decodeFunctionData)({ abi: v6_1.AGW_ABI, data });
207
+ }
208
+ catch {
209
+ return null;
210
+ }
211
+ switch (decoded.functionName) {
212
+ case 'execute': {
213
+ const [mode, ecd] = decoded.args;
214
+ return { kind: 'execute', mode, calls: unpackExecution(mode, ecd) };
215
+ }
216
+ case 'executeAsAgent': {
217
+ const [rulesId, mode, ecd] = decoded.args;
218
+ return {
219
+ kind: 'executeAsAgent',
220
+ rulesId,
221
+ mode,
222
+ calls: unpackExecution(mode, ecd),
223
+ };
224
+ }
225
+ case 'grantRules':
226
+ return {
227
+ kind: 'grantRules',
228
+ session: decoded.args[0],
229
+ };
230
+ case 'revokeRules':
231
+ return { kind: 'revokeRules', rulesId: decoded.args[0] };
232
+ case 'revokeAllRules':
233
+ return { kind: 'revokeAllRules' };
234
+ default:
235
+ return null;
236
+ }
237
+ },
238
+ decodeCheckpointKind(kind) {
239
+ const k = CHECKPOINT_KINDS[kind];
240
+ if (!k)
241
+ throw new Error(`unknown checkpoint kind ${kind}`);
242
+ return k;
243
+ },
244
+ parseWalletDeployed(logs, factory) {
245
+ return decodeMatching(logs, factory, exports.v6.events.walletDeployed).map((args) => ({
246
+ owner: (0, viem_1.getAddress)(args['owner']),
247
+ index: BigInt(args['index']),
248
+ wallet: (0, viem_1.getAddress)(args['wallet']),
249
+ label: args['label'],
250
+ }));
251
+ },
252
+ parseRulesGranted(logs, wallet) {
253
+ return decodeMatching(logs, wallet, exports.v6.events.rulesGranted).map((args) => ({
254
+ rulesId: args['rulesId'],
255
+ mode: Number(args['mode']),
256
+ chainNamespace: args['chainNamespace'],
257
+ }));
258
+ },
259
+ parseRulesRevoked(logs, wallet) {
260
+ return decodeMatching(logs, wallet, exports.v6.events.rulesRevoked).map((args) => ({
261
+ rulesId: args['rulesId'],
262
+ }));
263
+ },
264
+ parseCheckpointed(logs, wallet) {
265
+ return logs
266
+ .filter((l) => sameAddress(l.address, wallet) &&
267
+ l.topics[0]?.toLowerCase() ===
268
+ (0, viem_1.toEventSelector)(exports.v6.events.checkpointed).toLowerCase())
269
+ .flatMap((log) => {
270
+ try {
271
+ const ev = (0, viem_1.decodeEventLog)({
272
+ abi: [exports.v6.events.checkpointed],
273
+ ...log,
274
+ strict: true,
275
+ });
276
+ return [{ log, args: ev.args }];
277
+ }
278
+ catch {
279
+ return [];
280
+ }
281
+ })
282
+ .map(({ log, args }) => ({
283
+ seq: Number(args['seq']),
284
+ kind: exports.v6.decodeCheckpointKind(Number(args['kind'])),
285
+ ref: args['ref'],
286
+ blockNumber: BigInt(log.blockNumber ?? BigInt(0)),
287
+ txHash: log.transactionHash,
288
+ logIndex: Number(log.logIndex ?? 0),
289
+ transactionIndex: Number(log.transactionIndex ?? 0),
290
+ }));
291
+ },
292
+ };
293
+ function unpackExecution(mode, ecd) {
294
+ const callType = mode.slice(2, 4);
295
+ if (callType === '00') {
296
+ const bytes = ecd.slice(2);
297
+ return [
298
+ {
299
+ target: (0, viem_1.getAddress)(`0x${bytes.slice(0, 40)}`),
300
+ value: BigInt(`0x${bytes.slice(40, 104) || '0'}`),
301
+ data: `0x${bytes.slice(104)}`,
302
+ },
303
+ ];
304
+ }
305
+ if (callType === '01') {
306
+ const [execs] = (0, viem_1.decodeAbiParameters)(EXECUTION_TUPLE, ecd);
307
+ return execs.map((e) => ({
308
+ target: (0, viem_1.getAddress)(e.target),
309
+ value: e.value,
310
+ data: e.callData,
311
+ }));
312
+ }
313
+ return [];
314
+ }
315
+ function sameAddress(a, b) {
316
+ return !!a && a.toLowerCase() === b.toLowerCase();
317
+ }
318
+ function decodeMatching(logs, emitter, event) {
319
+ // viem's decodeEventLog skips the topic0 check when given a one-event ABI,
320
+ // so the event signature is matched explicitly here.
321
+ const topic0 = (0, viem_1.toEventSelector)(event).toLowerCase();
322
+ const out = [];
323
+ for (const log of logs) {
324
+ if (!sameAddress(log.address, emitter))
325
+ continue;
326
+ if (log.topics[0]?.toLowerCase() !== topic0)
327
+ continue;
328
+ try {
329
+ const ev = (0, viem_1.decodeEventLog)({
330
+ abi: [event],
331
+ data: log.data,
332
+ topics: log.topics,
333
+ strict: true,
334
+ });
335
+ out.push(ev.args);
336
+ }
337
+ catch {
338
+ // not this event
339
+ }
340
+ }
341
+ return out;
342
+ }
343
+ //# sourceMappingURL=v6.js.map
@@ -0,0 +1,61 @@
1
+ import { type Address } from 'viem';
2
+ import { PUSH_NETWORK } from '../constants/enums';
3
+ import { AgenticCapability } from './capabilities';
4
+ import { type AgwContracts } from './contracts/v6';
5
+ import type { ChainReader } from './contracts/reader';
6
+ /**
7
+ * A verified AGW contract generation on one Push network. The registry is the
8
+ * ONLY source of AGW addresses in the SDK: no address is hard-coded anywhere
9
+ * else, and historical Donut deployments (generation 67929f2, grantMandate)
10
+ * are NOT registered because they do not implement this ABI.
11
+ */
12
+ export interface AgenticGeneration {
13
+ /** Stable identifier, e.g. 'v6'. */
14
+ id: string;
15
+ /** Contract source commit the ABI was generated from. */
16
+ sourceCommit: string;
17
+ network: PUSH_NETWORK;
18
+ /** false = review fixture (local harness); never advertised as a release deployment. */
19
+ advertised: boolean;
20
+ addresses: {
21
+ factory: Address;
22
+ walletImplementation: Address;
23
+ sessionEngine: Address;
24
+ rulesPolicy: Address;
25
+ sessionValidator: Address;
26
+ gateway: Address;
27
+ };
28
+ /** First block to scan for factory/wallet events. */
29
+ startBlock: bigint;
30
+ /** Expected wallet accountId(). */
31
+ accountId: string;
32
+ capabilities: ReadonlySet<AgenticCapability>;
33
+ contracts: AgwContracts;
34
+ }
35
+ /** Capabilities the v6 ABI actually implements. Target-only features are absent. */
36
+ export declare const V6_CAPABILITIES: ReadonlySet<AgenticCapability>;
37
+ /**
38
+ * @internal Register a generation that is NOT a verified release deployment —
39
+ * the local contract harness and E2E manifest loader use this. Not exported
40
+ * from the package entry point.
41
+ */
42
+ export declare function registerAgenticGeneration(input: Omit<AgenticGeneration, 'contracts' | 'capabilities'> & {
43
+ capabilities?: ReadonlySet<AgenticCapability>;
44
+ }): AgenticGeneration;
45
+ /** @internal Test/harness cleanup. Restores the checked Donut v6 registry. */
46
+ export declare function resetAgenticGenerations(): void;
47
+ /** Grant compatibility check; the unrestricted owner door does not consult URP. */
48
+ export declare function verifyPolicyVersion(reader: ChainReader, gen: AgenticGeneration): Promise<void>;
49
+ export declare function generationsFor(network: PUSH_NETWORK): readonly AgenticGeneration[];
50
+ /** The generation new wallets are created on for this network. */
51
+ export declare function currentGeneration(network: PUSH_NETWORK): AgenticGeneration;
52
+ /** Generation infrastructure a native rule may not target (the wallet itself is added per call). */
53
+ export declare function forbiddenTargets(gen: AgenticGeneration, wallet?: Address): Address[];
54
+ /** Confirms the factory still points at the registered implementation (cached per generation). */
55
+ export declare function verifyFactoryWiring(reader: ChainReader, gen: AgenticGeneration): Promise<void>;
56
+ /**
57
+ * Resolve and verify the generation of a deployed wallet:
58
+ * code present → factory() is a registered factory → factory.isWallet(wallet)
59
+ * → immutable wiring and accountId match the registered generation.
60
+ */
61
+ export declare function resolveWalletGeneration(reader: ChainReader, network: PUSH_NETWORK, wallet: Address): Promise<AgenticGeneration>;
@@ -0,0 +1,203 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.V6_CAPABILITIES = void 0;
4
+ exports.registerAgenticGeneration = registerAgenticGeneration;
5
+ exports.resetAgenticGenerations = resetAgenticGenerations;
6
+ exports.verifyPolicyVersion = verifyPolicyVersion;
7
+ exports.generationsFor = generationsFor;
8
+ exports.currentGeneration = currentGeneration;
9
+ exports.forbiddenTargets = forbiddenTargets;
10
+ exports.verifyFactoryWiring = verifyFactoryWiring;
11
+ exports.resolveWalletGeneration = resolveWalletGeneration;
12
+ const viem_1 = require("viem");
13
+ const enums_1 = require("../constants/enums");
14
+ const capabilities_1 = require("./capabilities");
15
+ const v6_1 = require("./contracts/v6");
16
+ const errors_1 = require("./errors");
17
+ const donut_v6_1 = require("./contracts/donut-v6");
18
+ /** Capabilities the v6 ABI actually implements. Target-only features are absent. */
19
+ exports.V6_CAPABILITIES = new Set([
20
+ capabilities_1.AgenticCapability.WALLET_READS,
21
+ capabilities_1.AgenticCapability.ACTIVE_RULE_READS,
22
+ capabilities_1.AgenticCapability.OWNER_EXECUTE,
23
+ capabilities_1.AgenticCapability.AGENT_EXECUTE,
24
+ capabilities_1.AgenticCapability.NATIVE_RULES,
25
+ capabilities_1.AgenticCapability.ASSERT_SPENT_NATIVE,
26
+ capabilities_1.AgenticCapability.CHECKPOINTS,
27
+ capabilities_1.AgenticCapability.UNIVERSAL_EVM_OUTBOUND,
28
+ capabilities_1.AgenticCapability.UNIVERSAL_EVM_RULES,
29
+ capabilities_1.AgenticCapability.UNIVERSAL_SVM_RULES,
30
+ capabilities_1.AgenticCapability.ASSERT_SPENT_UNIVERSAL_MULTI,
31
+ capabilities_1.AgenticCapability.SET_LABEL,
32
+ ]);
33
+ /**
34
+ * V6 only. Unsupported networks fail before signing; no legacy adapter fallback.
35
+ */
36
+ const VERIFIED_DEPLOYMENTS = [
37
+ {
38
+ id: 'v6',
39
+ sourceCommit: donut_v6_1.V6_SOURCE_COMMIT,
40
+ network: enums_1.PUSH_NETWORK.TESTNET_DONUT,
41
+ advertised: true,
42
+ addresses: donut_v6_1.DONUT_V6_ADDRESSES,
43
+ startBlock: donut_v6_1.DONUT_V6_START_BLOCK,
44
+ accountId: 'push.agw.1.0.0',
45
+ capabilities: exports.V6_CAPABILITIES,
46
+ contracts: v6_1.v6,
47
+ },
48
+ ];
49
+ const registry = [...VERIFIED_DEPLOYMENTS];
50
+ /**
51
+ * @internal Register a generation that is NOT a verified release deployment —
52
+ * the local contract harness and E2E manifest loader use this. Not exported
53
+ * from the package entry point.
54
+ */
55
+ function registerAgenticGeneration(input) {
56
+ if (input.id !== v6_1.v6.id || input.sourceCommit !== donut_v6_1.V6_SOURCE_COMMIT) {
57
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `no contract adapter for generation "${input.id}"`);
58
+ }
59
+ const gen = {
60
+ ...input,
61
+ addresses: {
62
+ factory: (0, viem_1.getAddress)(input.addresses.factory),
63
+ walletImplementation: (0, viem_1.getAddress)(input.addresses.walletImplementation),
64
+ sessionEngine: (0, viem_1.getAddress)(input.addresses.sessionEngine),
65
+ rulesPolicy: (0, viem_1.getAddress)(input.addresses.rulesPolicy),
66
+ sessionValidator: (0, viem_1.getAddress)(input.addresses.sessionValidator),
67
+ gateway: (0, viem_1.getAddress)(input.addresses.gateway),
68
+ },
69
+ capabilities: input.capabilities ?? exports.V6_CAPABILITIES,
70
+ contracts: v6_1.v6,
71
+ };
72
+ const existing = registry.findIndex((g) => g.network === gen.network && g.addresses.factory === gen.addresses.factory);
73
+ if (existing >= 0)
74
+ registry.splice(existing, 1);
75
+ registry.push(gen);
76
+ verifiedWiring.clear();
77
+ return gen;
78
+ }
79
+ /** @internal Test/harness cleanup. Restores the checked Donut v6 registry. */
80
+ function resetAgenticGenerations() {
81
+ registry.splice(0, registry.length, ...VERIFIED_DEPLOYMENTS);
82
+ verifiedWiring.clear();
83
+ }
84
+ /** Grant compatibility check; the unrestricted owner door does not consult URP. */
85
+ async function verifyPolicyVersion(reader, gen) {
86
+ const version = await reader.readContract({
87
+ address: gen.addresses.rulesPolicy,
88
+ abi: gen.contracts.abis.policy,
89
+ functionName: 'version',
90
+ });
91
+ if (version !== '3.1.0')
92
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `URP version ${String(version)} is not supported by the v6 adapter`);
93
+ }
94
+ function generationsFor(network) {
95
+ return registry.filter((g) => g.network === network);
96
+ }
97
+ /** The generation new wallets are created on for this network. */
98
+ function currentGeneration(network) {
99
+ const gens = generationsFor(network);
100
+ const gen = gens[gens.length - 1];
101
+ if (!gen) {
102
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `no verified AGW deployment is registered for ${network}`, {
103
+ hint: 'AGW v6 is configured on Donut only; this Push network has no registered v6 deployment.',
104
+ details: { network, assumption: 'A07' },
105
+ });
106
+ }
107
+ return gen;
108
+ }
109
+ /** Generation infrastructure a native rule may not target (the wallet itself is added per call). */
110
+ function forbiddenTargets(gen, wallet) {
111
+ const a = gen.addresses;
112
+ return [
113
+ a.factory,
114
+ a.sessionEngine,
115
+ a.rulesPolicy,
116
+ a.sessionValidator,
117
+ a.gateway,
118
+ ...(wallet ? [wallet] : []),
119
+ ];
120
+ }
121
+ const verifiedWiring = new Map();
122
+ /** Confirms the factory still points at the registered implementation (cached per generation). */
123
+ function verifyFactoryWiring(reader, gen) {
124
+ const key = `${gen.network}:${gen.addresses.factory}:${gen.addresses.walletImplementation}`;
125
+ let p = verifiedWiring.get(key);
126
+ if (!p) {
127
+ p = (async () => {
128
+ const impl = (await reader.readContract({
129
+ address: gen.addresses.factory,
130
+ abi: gen.contracts.abis.factory,
131
+ functionName: 'walletImplementation',
132
+ }));
133
+ if ((0, viem_1.getAddress)(impl) !== gen.addresses.walletImplementation) {
134
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `factory ${gen.addresses.factory} points at implementation ${impl}, not the registered ${gen.addresses.walletImplementation}`);
135
+ }
136
+ })();
137
+ p.catch(() => verifiedWiring.delete(key));
138
+ verifiedWiring.set(key, p);
139
+ }
140
+ return p;
141
+ }
142
+ /**
143
+ * Resolve and verify the generation of a deployed wallet:
144
+ * code present → factory() is a registered factory → factory.isWallet(wallet)
145
+ * → immutable wiring and accountId match the registered generation.
146
+ */
147
+ async function resolveWalletGeneration(reader, network, wallet) {
148
+ const gens = generationsFor(network);
149
+ if (gens.length === 0)
150
+ currentGeneration(network); // throws CAPABILITY_UNAVAILABLE (A07)
151
+ const code = await reader.getCode({ address: wallet });
152
+ if (!code || code === '0x') {
153
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_NOT_DEPLOYED, `no contract is deployed at ${wallet}`, {
154
+ hint: 'Deploy it with client.agentic.create, or check the address and network.',
155
+ });
156
+ }
157
+ let factory;
158
+ try {
159
+ factory = (0, viem_1.getAddress)((await reader.readContract({
160
+ address: wallet,
161
+ abi: v6_1.v6.abis.wallet,
162
+ functionName: 'factory',
163
+ })));
164
+ }
165
+ catch (cause) {
166
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.NOT_AGENTIC_WALLET, `${wallet} does not expose an AGW factory()`, { cause });
167
+ }
168
+ const gen = gens.find((g) => g.addresses.factory === factory);
169
+ if (!gen) {
170
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `${wallet} was created by factory ${factory}, which is not a verified AGW generation on ${network}`, { details: { factory, assumption: 'A07' } });
171
+ }
172
+ const isWallet = (await reader.readContract({
173
+ address: gen.addresses.factory,
174
+ abi: gen.contracts.abis.factory,
175
+ functionName: 'isWallet',
176
+ args: [wallet],
177
+ }));
178
+ if (!isWallet) {
179
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.NOT_AGENTIC_WALLET, `${wallet} is not a wallet of factory ${factory}`);
180
+ }
181
+ const [engine, policy, validator, gateway, accountId] = await Promise.all([
182
+ 'SESSION_ENGINE',
183
+ 'RULES_POLICY',
184
+ 'SESSION_VALIDATOR',
185
+ 'UNIVERSAL_GATEWAY_PC',
186
+ 'accountId',
187
+ ].map((functionName) => reader.readContract({
188
+ address: wallet,
189
+ abi: gen.contracts.abis.wallet,
190
+ functionName,
191
+ })));
192
+ const mismatch = (0, viem_1.getAddress)(engine) !== gen.addresses.sessionEngine ||
193
+ (0, viem_1.getAddress)(policy) !== gen.addresses.rulesPolicy ||
194
+ (0, viem_1.getAddress)(validator) !== gen.addresses.sessionValidator ||
195
+ (0, viem_1.getAddress)(gateway) !== gen.addresses.gateway ||
196
+ accountId !== gen.accountId;
197
+ if (mismatch) {
198
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, `${wallet} wiring does not match registered generation ${gen.id}`, { details: { engine, policy, validator, gateway, accountId } });
199
+ }
200
+ await verifyFactoryWiring(reader, gen);
201
+ return gen;
202
+ }
203
+ //# sourceMappingURL=deployments.js.map
@@ -0,0 +1,65 @@
1
+ import { PushChainExecutionError, type DecodedErrorPayload } from '../orchestrator/internals/errors';
2
+ /**
3
+ * Stable AGW error codes. The first groups are specified by the AGW SDK page
4
+ * (section 3.f); the remainder are SDK-owned codes that keep unsupported or
5
+ * unverified capabilities from being mistaken for success.
6
+ */
7
+ export declare const AGENTIC_ERROR_CODE: {
8
+ readonly DUPLICATE_RULE: "DUPLICATE_RULE";
9
+ readonly AGENT_IS_OWNER: "AGENT_IS_OWNER";
10
+ readonly AMBIGUOUS_RULE: "AMBIGUOUS_RULE";
11
+ readonly TARGET_NOT_ON_RULE_CHAIN: "TARGET_NOT_ON_RULE_CHAIN";
12
+ readonly ASSET_CHAIN_MISMATCH: "ASSET_CHAIN_MISMATCH";
13
+ readonly NOT_OWNER_OR_AGENT: "NOT_OWNER_OR_AGENT";
14
+ readonly WALLET_NOT_DEPLOYED: "WALLET_NOT_DEPLOYED";
15
+ readonly NOT_AGENTIC_WALLET: "NOT_AGENTIC_WALLET";
16
+ readonly DELETE_NEEDS_TARGET: "DELETE_NEEDS_TARGET";
17
+ readonly NO_RULES_FOR_CHAIN: "NO_RULES_FOR_CHAIN";
18
+ readonly FROM_NOT_ALLOWED: "FROM_NOT_ALLOWED";
19
+ readonly NOT_ALLOWED_IN_AGENTIC_MODE: "NOT_ALLOWED_IN_AGENTIC_MODE";
20
+ readonly INVALID_RULE: "INVALID_RULE";
21
+ readonly CAPABILITY_UNAVAILABLE: "CAPABILITY_UNAVAILABLE";
22
+ readonly READ_ONLY: "READ_ONLY";
23
+ readonly NOT_WALLET_OWNER: "NOT_WALLET_OWNER";
24
+ readonly RULE_NOT_FOUND: "RULE_NOT_FOUND";
25
+ readonly RULE_READ_FAILED: "RULE_READ_FAILED";
26
+ readonly INCONSISTENT_READ: "INCONSISTENT_READ";
27
+ readonly INDEX_RACE: "INDEX_RACE";
28
+ readonly RECEIPT_MISMATCH: "RECEIPT_MISMATCH";
29
+ readonly RECEIPT_UNAVAILABLE: "RECEIPT_UNAVAILABLE";
30
+ readonly AGENT_GAS_INSUFFICIENT: "AGENT_GAS_INSUFFICIENT";
31
+ readonly WALLET_BALANCE_INSUFFICIENT: "WALLET_BALANCE_INSUFFICIENT";
32
+ };
33
+ export type AgenticErrorCode = (typeof AGENTIC_ERROR_CODE)[keyof typeof AGENTIC_ERROR_CODE];
34
+ /**
35
+ * Pre-signature AGW failure: invalid input, unsupported capability, failed
36
+ * eligibility or a read that cannot be trusted. Nothing was signed or sent
37
+ * except receipt errors, which retain the submitted transaction hash.
38
+ */
39
+ export declare class AgenticError extends Error {
40
+ readonly code: AgenticErrorCode;
41
+ readonly hint?: string;
42
+ readonly details?: Readonly<Record<string, unknown>>;
43
+ readonly cause?: unknown;
44
+ constructor(code: AgenticErrorCode, message: string, opts?: {
45
+ hint?: string;
46
+ details?: Record<string, unknown>;
47
+ cause?: unknown;
48
+ });
49
+ }
50
+ /**
51
+ * On-chain AGW, URP, factory or engine revert surfaced from an agentic send.
52
+ * Extends core's structured execution error so `instanceof
53
+ * PushChainExecutionError` keeps working, and keeps the underlying cause plus
54
+ * any batch recovery hashes.
55
+ */
56
+ export declare class AgenticRevertError extends PushChainExecutionError {
57
+ readonly agenticCode?: string;
58
+ constructor(message: string, opts?: {
59
+ decodedError?: DecodedErrorPayload;
60
+ gatewayTxHash?: string;
61
+ agenticCode?: string;
62
+ cause?: unknown;
63
+ });
64
+ }
65
+ export declare function capabilityUnavailable(capability: string, dependency: string, hint?: string): AgenticError;