@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,279 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addRules = addRules;
4
+ exports.assertRevokeTarget = assertRevokeTarget;
5
+ exports.revokeRules = revokeRules;
6
+ exports.updateRules = updateRules;
7
+ exports.setLabel = setLabel;
8
+ const duplicates_1 = require("./duplicates");
9
+ const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
10
+ const capabilities_1 = require("../capabilities");
11
+ const ids_1 = require("../codec/ids");
12
+ const prepare_1 = require("./prepare");
13
+ const label_1 = require("./label");
14
+ const errors_1 = require("../errors");
15
+ const rules_1 = require("../reads/rules");
16
+ const snapshot_1 = require("../reads/snapshot");
17
+ const common_1 = require("./common");
18
+ const MODE_NATIVE = 1;
19
+ async function finish(runtime, hook, operation, run) {
20
+ try {
21
+ const result = await run();
22
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_01, operation, result.tx.hash);
23
+ return result;
24
+ }
25
+ catch (err) {
26
+ const wrapped = (0, common_1.wrapSendError)(err);
27
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_02, operation, wrapped?.code ?? 'UNKNOWN', wrapped?.message ?? String(err), wrapped?.decodedError);
28
+ throw wrapped;
29
+ }
30
+ }
31
+ /** w.rules.add(rules): owner grants on an existing wallet, IDs in input order. */
32
+ async function addRules(runtime, gen, wallet, rules, hook) {
33
+ (0, common_1.assertCanSign)(runtime, 'rules.add');
34
+ if (!Array.isArray(rules) || rules.length === 0) {
35
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rules.add needs at least one rule');
36
+ }
37
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
38
+ const owner = await (0, common_1.assertOwner)(runtime, gen, wallet, snap);
39
+ const prepared = await (0, prepare_1.prepareWalletRules)(runtime, gen, owner, wallet, rules, snap);
40
+ (0, duplicates_1.assertNoDuplicateRules)(prepared, await (0, rules_1.readActiveRules)(snap, gen, wallet));
41
+ const nonce = BigInt(await snap.read(wallet, gen.contracts.abis.wallet, 'grantNonce'));
42
+ const predicted = prepared.map((p, i) => (0, ids_1.rulesId)({
43
+ validator: gen.addresses.sessionValidator,
44
+ agent: p.agent,
45
+ grantNonce: nonce + BigInt(i),
46
+ }));
47
+ // One rule: a direct owner grant (one RULES_GRANTED tick). Several: one
48
+ // owner `execute` batch of self-calls, so the grants are atomic and need a
49
+ // single signature on every signer type (each grant then also ticks one
50
+ // OWNER_ACTION before its RULES_GRANTED).
51
+ const grants = prepared.map((p) => gen.contracts.encodeGrantRules(p.session));
52
+ const calls = grants.length === 1
53
+ ? [{ to: wallet, value: BigInt(0), data: grants[0] }]
54
+ : [
55
+ {
56
+ to: wallet,
57
+ value: BigInt(0),
58
+ data: gen.contracts.encodeExecute(grants.map((data) => ({ target: wallet, value: BigInt(0), data }))),
59
+ },
60
+ ];
61
+ return finish(runtime, hook, 'rules.add', async () => {
62
+ const tx = await (0, common_1.sendOwnerCalls)(runtime, calls, hook);
63
+ const { logs } = await (0, common_1.confirmedLogs)(runtime, tx);
64
+ const granted = gen.contracts
65
+ .parseRulesGranted(logs, wallet)
66
+ .map((g) => g.rulesId);
67
+ if (!sameIds(granted, predicted)) {
68
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'RulesGranted events do not match the requested rules in order (a concurrent grant may have raced)', { details: { granted, predicted, txHash: tx.hash } });
69
+ }
70
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_104, granted);
71
+ return { rulesIds: granted, tx };
72
+ });
73
+ }
74
+ /** Bare revoke (no IDs, empty list, or anything but { all: true }) is refused. */
75
+ function assertRevokeTarget(target) {
76
+ const all = !!target &&
77
+ !Array.isArray(target) &&
78
+ target.all === true;
79
+ const ids = Array.isArray(target) ? target : undefined;
80
+ if (!all && (!ids || ids.length === 0)) {
81
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.DELETE_NEEDS_TARGET, 'rules.delete needs explicit rule IDs or { all: true }', {
82
+ hint: 'A bare revoke that wipes every rule is too easy to make by mistake.',
83
+ });
84
+ }
85
+ return { all, ids };
86
+ }
87
+ /** w.rules.delete(ids) / w.rules.delete({ all: true }). Bare revoke is refused. */
88
+ async function revokeRules(runtime, gen, wallet, target, hook) {
89
+ const { all, ids } = assertRevokeTarget(target);
90
+ if (all)
91
+ hook =
92
+ target.progressHook ?? hook;
93
+ (0, common_1.assertCanSign)(runtime, 'rules.delete');
94
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
95
+ await (0, common_1.assertOwner)(runtime, gen, wallet, snap);
96
+ let calls;
97
+ if (all) {
98
+ calls = [
99
+ {
100
+ to: wallet,
101
+ value: BigInt(0),
102
+ data: gen.contracts.encodeRevokeAllRules(),
103
+ },
104
+ ];
105
+ }
106
+ else {
107
+ const unique = new Set(ids.map((i) => i.toLowerCase()));
108
+ if (unique.size !== ids.length) {
109
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rules.delete got the same rule ID twice');
110
+ }
111
+ for (const id of ids) {
112
+ const enabled = await snap.read(gen.addresses.sessionEngine, gen.contracts.abis.engine, 'isPermissionEnabled', [id, wallet]);
113
+ if (!enabled) {
114
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_NOT_FOUND, `rule ${id} is not enabled on ${wallet}`);
115
+ }
116
+ }
117
+ // Several IDs go through one owner `execute` batch so revocation is atomic
118
+ // regardless of signer batching support.
119
+ calls =
120
+ ids.length === 1
121
+ ? [
122
+ {
123
+ to: wallet,
124
+ value: BigInt(0),
125
+ data: gen.contracts.encodeRevokeRules(ids[0]),
126
+ },
127
+ ]
128
+ : [
129
+ {
130
+ to: wallet,
131
+ value: BigInt(0),
132
+ data: gen.contracts.encodeExecute(ids.map((id) => ({
133
+ target: wallet,
134
+ value: BigInt(0),
135
+ data: gen.contracts.encodeRevokeRules(id),
136
+ }))),
137
+ },
138
+ ];
139
+ }
140
+ const result = await finish(runtime, hook, 'rules.delete', async () => {
141
+ const tx = await (0, common_1.sendOwnerCalls)(runtime, calls, hook);
142
+ const { logs } = await (0, common_1.confirmedLogs)(runtime, tx);
143
+ const revoked = gen.contracts
144
+ .parseRulesRevoked(logs, wallet)
145
+ .map((r) => r.rulesId);
146
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_105, all ? { all: true } : { rulesIds: revoked });
147
+ return { tx };
148
+ });
149
+ return result.tx;
150
+ }
151
+ /**
152
+ * w.rules.update({ rules: [{ rulesId, rule }] }): for every pair, inside ONE
153
+ * owner `execute` batch: assertSpent(expected) → revokeRules(old) →
154
+ * grantRules(new). Never falls back to sequential sends. An agent spending
155
+ * between the read and inclusion makes the whole batch revert; retry needs a
156
+ * fresh read and a new owner signature. New counters start at zero.
157
+ */
158
+ async function updateRules(runtime, gen, wallet, params) {
159
+ const hook = params?.progressHook;
160
+ (0, common_1.assertCanSign)(runtime, 'rules.update');
161
+ if (!params || !Array.isArray(params.rules) || params.rules.length === 0) {
162
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rules.update needs at least one { rulesId, rule } pair');
163
+ }
164
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.OWNER_EXECUTE);
165
+ const oldIds = params.rules.map((p) => p.rulesId.toLowerCase());
166
+ if (new Set(oldIds).size !== oldIds.length) {
167
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'rules.update names the same old rule twice');
168
+ }
169
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
170
+ const owner = await (0, common_1.assertOwner)(runtime, gen, wallet, snap);
171
+ const active = await (0, rules_1.readActiveRules)(snap, gen, wallet);
172
+ const byId = new Map(active.map((r) => [r.rulesId.toLowerCase(), r]));
173
+ const assertions = [];
174
+ for (const pair of params.rules) {
175
+ const old = byId.get(pair.rulesId.toLowerCase());
176
+ if (!old)
177
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RULE_NOT_FOUND, `rule ${pair.rulesId} is not enabled on ${wallet}`);
178
+ if (old.mode === MODE_NATIVE) {
179
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.ASSERT_SPENT_NATIVE);
180
+ const guards = [];
181
+ for (const action of old.actionIds) {
182
+ const spend = await (0, rules_1.readNativeSpend)(snap, gen, wallet, old, action);
183
+ guards.push({
184
+ configId: spend.configId,
185
+ data: gen.contracts.encodeAssertSpentNative(spend.configId, wallet, spend),
186
+ });
187
+ }
188
+ assertions.push(guards);
189
+ }
190
+ else {
191
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.ASSERT_SPENT_UNIVERSAL_MULTI);
192
+ const spend = await (0, rules_1.readUniversalSpend)(snap, gen, wallet, old);
193
+ assertions.push([
194
+ {
195
+ configId: spend.configId,
196
+ data: gen.contracts.encodeAssertSpentUniversal(spend.configId, wallet, spend.expectedSpent),
197
+ },
198
+ ]);
199
+ }
200
+ }
201
+ const prepared = await (0, prepare_1.prepareWalletRules)(runtime, gen, owner, wallet, params.rules.map((p) => p.rule), snap);
202
+ const nonce = BigInt(await snap.read(wallet, gen.contracts.abis.wallet, 'grantNonce'));
203
+ const predicted = prepared.map((p, i) => (0, ids_1.rulesId)({
204
+ validator: gen.addresses.sessionValidator,
205
+ agent: p.agent,
206
+ grantNonce: nonce + BigInt(i),
207
+ }));
208
+ const batch = params.rules.flatMap((pair, i) => [
209
+ ...assertions[i].map((a) => ({
210
+ target: gen.addresses.rulesPolicy,
211
+ value: BigInt(0),
212
+ data: a.data,
213
+ })),
214
+ {
215
+ target: wallet,
216
+ value: BigInt(0),
217
+ data: gen.contracts.encodeRevokeRules(pair.rulesId),
218
+ },
219
+ {
220
+ target: wallet,
221
+ value: BigInt(0),
222
+ data: gen.contracts.encodeGrantRules(prepared[i].session),
223
+ },
224
+ ]);
225
+ const call = {
226
+ to: wallet,
227
+ value: BigInt(0),
228
+ data: gen.contracts.encodeExecute(batch),
229
+ };
230
+ return finish(runtime, hook, 'rules.update', async () => {
231
+ const tx = await (0, common_1.sendOwnerCalls)(runtime, [call], hook);
232
+ const { logs } = await (0, common_1.confirmedLogs)(runtime, tx);
233
+ const granted = gen.contracts
234
+ .parseRulesGranted(logs, wallet)
235
+ .map((g) => g.rulesId);
236
+ const revoked = gen.contracts
237
+ .parseRulesRevoked(logs, wallet)
238
+ .map((r) => r.rulesId.toLowerCase());
239
+ if (!sameIds(granted, predicted) ||
240
+ !sameIds(revoked, oldIds)) {
241
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'rules.update receipt does not show the expected revoke/grant pairs', { details: { granted, predicted, revoked, txHash: tx.hash } });
242
+ }
243
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_105, {
244
+ rulesIds: params.rules.map((p) => p.rulesId),
245
+ });
246
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_104, granted);
247
+ return {
248
+ tx,
249
+ rules: granted.map((id, i) => ({
250
+ rulesId: id,
251
+ replaced: params.rules[i].rulesId,
252
+ })),
253
+ };
254
+ });
255
+ }
256
+ function sameIds(a, b) {
257
+ return (a.length === b.length &&
258
+ a.every((x, i) => x.toLowerCase() === b[i].toLowerCase()));
259
+ }
260
+ /** Direct owner rename; empty resets the default label without a checkpoint. */
261
+ async function setLabel(runtime, gen, wallet, label, hook) {
262
+ (0, label_1.assertLabel)(label);
263
+ (0, common_1.assertCanSign)(runtime, 'setLabel');
264
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.SET_LABEL);
265
+ return finish(runtime, hook, 'setLabel', async () => {
266
+ await (0, common_1.assertOwner)(runtime, gen, wallet, await snapshot_1.Snapshot.at(runtime.reader));
267
+ const tx = await (0, common_1.sendOwnerCalls)(runtime, [
268
+ {
269
+ to: wallet,
270
+ value: BigInt(0),
271
+ data: gen.contracts.encodeSetLabel(label),
272
+ },
273
+ ], hook);
274
+ await (0, common_1.confirmedLogs)(runtime, tx);
275
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_106, label);
276
+ return { tx };
277
+ }).then(({ tx }) => tx);
278
+ }
279
+ //# sourceMappingURL=rules-write.js.map
@@ -0,0 +1,25 @@
1
+ /** Internal resolved context; no public Rule schema or cluster assumptions. */
2
+ import { type Address, type Hex } from 'viem';
3
+ import { PUSH_NETWORK } from '../../constants/enums';
4
+ import { type SvmTokenAccountInput, type ResolvedSvmAsset } from '../codec/svm-accounts';
5
+ import type { AssetCapWire } from '../codec/universal-terms';
6
+ import type { Snapshot } from '../reads/snapshot';
7
+ export interface SvmMetadataProvider {
8
+ /** Must identify the requested full CAIP-2 cluster; no global gateway default. */
9
+ gateway(chainNamespace: `solana:${string}`): Promise<{
10
+ chainNamespace: string;
11
+ program: string;
12
+ }>;
13
+ /** RPC-backed mint owner (legacy SPL or Token-2022), not an assumed default. */
14
+ mint(chainNamespace: `solana:${string}`, address: Hex): Promise<{
15
+ mint: string;
16
+ tokenProgram: string;
17
+ }>;
18
+ }
19
+ export declare function resolveSvmAssets(snap: Snapshot, chain: `solana:${string}`, caps: readonly AssetCapWire[], metadata: SvmMetadataProvider, network?: PUSH_NETWORK): Promise<ResolvedSvmAsset[]>;
20
+ export declare function resolveSvmContext(snap: Snapshot, wallet: Address, chain: `solana:${string}`, caps: readonly AssetCapWire[], metadata: SvmMetadataProvider, outputs?: readonly SvmTokenAccountInput[], network?: PUSH_NETWORK): Promise<{
21
+ assets: AssetCapWire[];
22
+ expectedCEA: Hex;
23
+ gatewayProgram: Hex;
24
+ ceaAccounts: Hex[];
25
+ }>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveSvmAssets = resolveSvmAssets;
4
+ exports.resolveSvmContext = resolveSvmContext;
5
+ /** Internal resolved context; no public Rule schema or cluster assumptions. */
6
+ const viem_1 = require("viem");
7
+ const enums_1 = require("../../constants/enums");
8
+ const errors_1 = require("../errors");
9
+ const prc20_metadata_1 = require("../contracts/prc20-metadata");
10
+ const svm_accounts_1 = require("../codec/svm-accounts");
11
+ const ZERO_KEY = `0x${'00'.repeat(32)}`;
12
+ async function resolveSvmAssets(snap, chain, caps, metadata, network = enums_1.PUSH_NETWORK.TESTNET_DONUT) {
13
+ const gas = await (0, prc20_metadata_1.readGasPrc20)(snap, chain);
14
+ const out = [];
15
+ for (const cap of caps) {
16
+ const token = (0, viem_1.getAddress)(cap.token);
17
+ const namespace = await snap.read(token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE');
18
+ if (namespace !== chain)
19
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, `PRC20 ${token} belongs to ${namespace}, not ${chain}`);
20
+ const source = await (0, prc20_metadata_1.readSvmSourceToken)(snap, token, chain, network);
21
+ const native = source === ZERO_KEY;
22
+ if (native) {
23
+ if (token !== gas)
24
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'native marker is not the registered gas PRC20');
25
+ out.push({ kind: 'native', cap: { ...cap, token } });
26
+ }
27
+ else {
28
+ const key = (0, svm_accounts_1.svmKey)(source);
29
+ const mint = await metadata.mint(chain, key);
30
+ if ((0, svm_accounts_1.svmKey)(mint.mint) !== key)
31
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'mint resolver returned a different mint');
32
+ out.push({ kind: 'spl', cap: { ...cap, token }, ...mint });
33
+ }
34
+ }
35
+ return out;
36
+ }
37
+ async function resolveSvmContext(snap, wallet, chain, caps, metadata, outputs = [], network = enums_1.PUSH_NETWORK.TESTNET_DONUT) {
38
+ const gateway = await metadata.gateway(chain);
39
+ if (gateway.chainNamespace !== chain)
40
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'gateway registry cluster mismatch');
41
+ const assets = await resolveSvmAssets(snap, chain, caps, metadata, network);
42
+ const resolvedOutputs = [];
43
+ for (const output of outputs) {
44
+ const key = (0, svm_accounts_1.svmKey)(output.mint);
45
+ const resolved = await metadata.mint(chain, key);
46
+ if ((0, svm_accounts_1.svmKey)(resolved.mint) !== key ||
47
+ (output.tokenProgram &&
48
+ (0, svm_accounts_1.svmKey)(output.tokenProgram) !== (0, svm_accounts_1.svmKey)(resolved.tokenProgram)))
49
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'output mint/token-program mismatch');
50
+ resolvedOutputs.push(resolved);
51
+ }
52
+ // Derivation validates token programs and covers every mint/output.
53
+ return (0, svm_accounts_1.resolveAgwSvmRuleContext)(wallet, gateway.program, assets, resolvedOutputs);
54
+ }
55
+ //# sourceMappingURL=svm-context.js.map
@@ -0,0 +1,10 @@
1
+ import { Connection } from '@solana/web3.js';
2
+ import type { SvmMetadataProvider } from './svm-context';
3
+ export interface SvmClusterConfig {
4
+ gatewayProgram: string;
5
+ rpcUrls: readonly string[];
6
+ }
7
+ type MintRpc = Pick<Connection, 'getGenesisHash' | 'getAccountInfo'>;
8
+ /** Explicit cluster configuration; HTTP reads only, no signing/subscriptions. */
9
+ export declare function createSvmMetadataProvider(clusters: Readonly<Partial<Record<`solana:${string}`, SvmClusterConfig>>>, connect?: (url: string) => MintRpc): SvmMetadataProvider;
10
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createSvmMetadataProvider = createSvmMetadataProvider;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const svm_accounts_1 = require("../codec/svm-accounts");
6
+ const svm_terms_1 = require("../codec/svm-terms");
7
+ const errors_1 = require("../errors");
8
+ const SPL = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
9
+ const TOKEN_2022 = 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
10
+ /** Explicit cluster configuration; HTTP reads only, no signing/subscriptions. */
11
+ function createSvmMetadataProvider(clusters, connect = (url) => new web3_js_1.Connection(url, 'confirmed')) {
12
+ function config(chain) {
13
+ const c = clusters[chain];
14
+ if (!c || !c.rpcUrls.length)
15
+ throw (0, svm_terms_1.svmInvalid)(`no SVM registry/RPC configuration for ${chain}`);
16
+ (0, svm_accounts_1.svmKey)(c.gatewayProgram);
17
+ return c;
18
+ }
19
+ async function read(chain, fn) {
20
+ const c = config(chain);
21
+ let last;
22
+ for (const url of c.rpcUrls) {
23
+ try {
24
+ const rpc = connect(url);
25
+ // CAIP-2 Solana references are the first 32 characters of genesisHash.
26
+ if (`solana:${(await rpc.getGenesisHash()).slice(0, 32)}` !== chain)
27
+ throw (0, svm_terms_1.svmInvalid)('SVM RPC genesis/cluster mismatch');
28
+ return await fn(rpc);
29
+ }
30
+ catch (error) {
31
+ last = error;
32
+ }
33
+ }
34
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `SVM metadata lookup failed for ${chain}`, { cause: last });
35
+ }
36
+ return {
37
+ gateway: async (chain) => read(chain, async () => ({
38
+ chainNamespace: chain,
39
+ program: config(chain).gatewayProgram,
40
+ })),
41
+ mint: async (chain, address) => read(chain, async (rpc) => {
42
+ const mint = new web3_js_1.PublicKey(Buffer.from((0, svm_accounts_1.svmKey)(address).slice(2), 'hex'));
43
+ const info = await rpc.getAccountInfo(mint, 'confirmed');
44
+ if (!info || info.executable)
45
+ throw (0, svm_terms_1.svmInvalid)('mint account missing or executable');
46
+ const owner = info.owner.toBase58(), data = info.data;
47
+ const legacy = owner === SPL && data.length === 82;
48
+ const extended = owner === TOKEN_2022 &&
49
+ (data.length === 82 || (data.length >= 166 && data[165] === 1));
50
+ if ((!legacy && !extended) || data[45] !== 1)
51
+ throw (0, svm_terms_1.svmInvalid)('account is not an initialized supported SPL mint');
52
+ return { mint: mint.toBase58(), tokenProgram: owner };
53
+ }),
54
+ };
55
+ }
56
+ //# sourceMappingURL=svm-metadata.js.map
@@ -0,0 +1,6 @@
1
+ import type { Address } from 'viem';
2
+ import type { SolanaRule, DecodedSolanaRule } from '../agentic.types';
3
+ import type { AgenticRuntime } from '../runtime';
4
+ import type { Snapshot } from '../reads/snapshot';
5
+ export declare function svmMetadata(runtime: AgenticRuntime): import("./svm-context").SvmMetadataProvider;
6
+ export declare function preparePublicSvmRule(runtime: AgenticRuntime, snap: Snapshot, wallet: Address, rule: SolanaRule | DecodedSolanaRule): Promise<import("../codec/svm-terms").SvmTermsWire>;
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.svmMetadata = svmMetadata;
27
+ exports.preparePublicSvmRule = preparePublicSvmRule;
28
+ const web3_js_1 = require("@solana/web3.js");
29
+ const viem_1 = require("viem");
30
+ const enums_1 = require("../../constants/enums");
31
+ const chain_1 = require("../../constants/chain");
32
+ const prc20_metadata_1 = require("../contracts/prc20-metadata");
33
+ const svm_context_1 = require("./svm-context");
34
+ const svm_metadata_1 = require("./svm-metadata");
35
+ const svm_accounts_1 = require("../codec/svm-accounts");
36
+ const svm_idl_1 = require("../codec/svm-idl");
37
+ const svm_terms_1 = require("../codec/svm-terms");
38
+ const svm_terms_2 = require("../codec/svm-terms");
39
+ function svmMetadata(runtime) {
40
+ return (runtime.svmMetadata ??
41
+ (0, svm_metadata_1.createSvmMetadataProvider)({
42
+ [enums_1.CHAIN.SOLANA_DEVNET]: {
43
+ gatewayProgram: chain_1.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].lockerContract ?? '',
44
+ rpcUrls: chain_1.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
45
+ },
46
+ }));
47
+ }
48
+ async function preparePublicSvmRule(runtime, snap, wallet, rule) {
49
+ const chain = rule.chainNamespace;
50
+ if (chain_1.CHAIN_INFO[chain]?.vm !== enums_1.VM.SVM)
51
+ throw (0, svm_terms_1.svmInvalid)('unknown Solana chain');
52
+ if (!Array.isArray(rule.assets) || rule.assets.length > 8)
53
+ throw (0, svm_terms_1.svmInvalid)('assets must contain at most eight entries');
54
+ const raw = 'format' in rule && rule.format === 'decoded';
55
+ const outputTokens = 'outputTokens' in rule ? rule.outputTokens : undefined;
56
+ if (outputTokens !== undefined && !Array.isArray(outputTokens))
57
+ throw (0, svm_terms_1.svmInvalid)('outputTokens must be an array of mint addresses');
58
+ const metadata = svmMetadata(runtime);
59
+ const requested = rule.assets.length
60
+ ? rule.assets
61
+ : [{ token: viem_1.zeroAddress, maxPerCall: BigInt(0), maxTotal: BigInt(0) }];
62
+ const caps = [];
63
+ const tokenAccounts = new Map(), mints = new Set();
64
+ const sources = [];
65
+ for (const asset of requested) {
66
+ const source = typeof asset.token === 'string' ? asset.token : asset.token?.address;
67
+ if (typeof source !== 'string')
68
+ throw (0, svm_terms_1.svmInvalid)('asset token requires an address');
69
+ if (typeof asset.token !== 'string' &&
70
+ 'chain' in asset.token &&
71
+ asset.token.chain !== chain)
72
+ throw (0, svm_terms_1.svmInvalid)('asset token belongs to another chain');
73
+ const native = source === viem_1.zeroAddress ||
74
+ /^0x0{64}$/.test(source) ||
75
+ source === '11111111111111111111111111111111';
76
+ const key = native ? undefined : (0, svm_accounts_1.svmKey)(source);
77
+ const sourceToken = typeof asset.token === 'string' && key
78
+ ? new web3_js_1.PublicKey((0, viem_1.hexToBytes)(key)).toBase58()
79
+ : asset.token;
80
+ const token = native
81
+ ? await (0, prc20_metadata_1.readGasPrc20)(snap, chain)
82
+ : runtime.resolvePrc20(sourceToken, chain);
83
+ if (caps.some((c) => c.token === (0, viem_1.getAddress)(token)))
84
+ throw (0, svm_terms_1.svmInvalid)('duplicate SVM asset');
85
+ caps.push({
86
+ token: (0, viem_1.getAddress)(token),
87
+ maxPerCall: asset.maxPerCall,
88
+ maxTotal: asset.maxTotal ?? BigInt(0),
89
+ });
90
+ sources.push({ key, token });
91
+ if (key)
92
+ mints.add(key);
93
+ }
94
+ const outputs = (outputTokens ?? []).map((mint) => ({ mint }));
95
+ outputs.forEach((o) => mints.add((0, svm_accounts_1.svmKey)(o.mint)));
96
+ const ctx = await (0, svm_context_1.resolveSvmContext)(snap, wallet, rule.chainNamespace, caps, metadata, outputs, runtime.network);
97
+ // Validate the PRC20 actually represents the requested source mint, not merely its chain.
98
+ const { resolveSvmAssets } = await Promise.resolve().then(() => __importStar(require('./svm-context')));
99
+ const resolved = await resolveSvmAssets(snap, rule.chainNamespace, caps, metadata, runtime.network);
100
+ resolved.forEach((a, i) => {
101
+ if (sources[i].key
102
+ ? a.kind !== 'spl' || (0, svm_accounts_1.svmKey)(a.mint) !== sources[i].key
103
+ : a.kind !== 'native')
104
+ throw (0, svm_terms_1.svmInvalid)('PRC20 source does not match requested asset');
105
+ });
106
+ for (const mint of mints) {
107
+ const token = await metadata.mint(rule.chainNamespace, mint);
108
+ if ((0, svm_accounts_1.svmKey)(token.mint) !== mint)
109
+ throw (0, svm_terms_1.svmInvalid)('mint resolver returned another mint');
110
+ tokenAccounts.set(mint, (0, svm_accounts_1.deriveAgwSvmAta)(ctx.expectedCEA, token));
111
+ }
112
+ if (raw) {
113
+ const stored = rule;
114
+ if ((0, svm_accounts_1.svmKey)(stored.expectedCEA) !== ctx.expectedCEA ||
115
+ (0, svm_accounts_1.svmKey)(stored.gatewayProgram) !== ctx.gatewayProgram)
116
+ throw (0, svm_terms_1.svmInvalid)('decoded rule belongs to another wallet or gateway');
117
+ if (ctx.ceaAccounts.some((a) => !stored.ceaAccounts.some((s) => (0, svm_accounts_1.svmKey)(s) === a)))
118
+ throw (0, svm_terms_1.svmInvalid)('decoded rule omits a required wallet value account');
119
+ const terms = { ...stored, assets: caps };
120
+ (0, svm_terms_2.validateSvmTerms)(terms, runtime.nowSeconds());
121
+ return terms;
122
+ }
123
+ return (0, svm_idl_1.compileSvmIdlRule)(rule, { ...ctx, tokenAccounts }, runtime.nowSeconds());
124
+ }
125
+ //# sourceMappingURL=svm-public.js.map
@@ -0,0 +1,27 @@
1
+ /** Internal explicit-wire operations. Not exported by the SDK entry point. */
2
+ import { type Address, type Hex } from 'viem';
3
+ import type { AgenticRuntime } from '../runtime';
4
+ import { type AgenticGeneration } from '../deployments';
5
+ import { type SvmTermsWire } from '../codec/svm-terms';
6
+ export interface SvmWireGrant {
7
+ agent: Address;
8
+ chainNamespace: `solana:${string}`;
9
+ terms: SvmTermsWire;
10
+ }
11
+ export declare function verifySvmWallet(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address): Promise<void>;
12
+ export declare function grantSvmWire(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, input: SvmWireGrant): Promise<{
13
+ rulesId: `0x${string}`;
14
+ tx: import("../../orchestrator/orchestrator.types").UniversalTxResponse;
15
+ }>;
16
+ /** Snapshot -> all-asset assertion -> revoke -> grant. No sequential fallback. */
17
+ export declare function prepareSvmReplacement(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, oldId: Hex, input: SvmWireGrant): Promise<{
18
+ rulesId: `0x${string}`;
19
+ oldId: `0x${string}`;
20
+ snapshotBlock: bigint;
21
+ data: `0x${string}`;
22
+ }>;
23
+ export declare function replaceSvmWire(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, oldId: Hex, input: SvmWireGrant): Promise<{
24
+ rulesId: `0x${string}`;
25
+ replaced: `0x${string}`;
26
+ tx: import("../../orchestrator/orchestrator.types").UniversalTxResponse;
27
+ }>;