@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,265 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.agenticPresets = void 0;
4
+ exports.buildPresetApi = buildPresetApi;
5
+ const viem_1 = require("viem");
6
+ const errors_1 = require("../errors");
7
+ const selectors_1 = require("../codec/selectors");
8
+ const catalog_1 = require("./catalog");
9
+ const MAX_UINT256 = (BigInt(1) << BigInt(256)) - BigInt(1);
10
+ const invalid = (message) => new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, message);
11
+ function cap(value, name) {
12
+ if (value === undefined)
13
+ return BigInt(0);
14
+ if (typeof value !== 'bigint' || value < BigInt(0) || value > MAX_UINT256)
15
+ throw invalid(`${name} must be a uint256 bigint`);
16
+ return value;
17
+ }
18
+ function copyCall(call) {
19
+ return {
20
+ ...call,
21
+ ...(call.pins
22
+ ? {
23
+ pins: call.pins.map((pin) => {
24
+ if (pin.account !== undefined)
25
+ return {
26
+ ...pin,
27
+ ...(pin.token && typeof pin.token === 'object'
28
+ ? { token: { ...pin.token } }
29
+ : {}),
30
+ };
31
+ return {
32
+ ...pin,
33
+ arg: typeof pin.arg === 'number' ? pin.arg : [...pin.arg],
34
+ };
35
+ }),
36
+ }
37
+ : {}),
38
+ };
39
+ }
40
+ function tokenAddress(token) {
41
+ const address = typeof token === 'string' ? token : token?.address;
42
+ if (typeof address !== 'string' || !address.trim())
43
+ throw invalid('preset asset requires a token address');
44
+ return address;
45
+ }
46
+ /** Not a public registration API. Tests inject fixtures; production uses the bundled catalog. */
47
+ function buildPresetApi(catalog) {
48
+ // Detach from the input so neither a returned template nor an input mutation changes the catalog.
49
+ const entries = catalog.map((p) => ({
50
+ ...p,
51
+ chains: p.chains.map((c) => ({
52
+ ...c,
53
+ allowedCalls: c.allowedCalls.map(copyCall),
54
+ approvals: c.approvals?.map((a) => ({ ...a })),
55
+ swapRouters: c.swapRouters?.map((r) => ({ ...r })),
56
+ })),
57
+ }));
58
+ if (new Set(entries.map((e) => e.constant)).size !== entries.length ||
59
+ entries.some((e) => new Set(e.chains.map((c) => c.chainNamespace)).size !== e.chains.length))
60
+ throw invalid('duplicate preset or chain in catalog');
61
+ const api = {
62
+ list(options) {
63
+ if (options?.type !== undefined && options.type !== 'CATEGORY')
64
+ throw invalid('only CATEGORY presets are supported');
65
+ return {
66
+ presets: entries.map((p) => ({
67
+ type: 'CATEGORY',
68
+ constant: p.constant,
69
+ name: p.name,
70
+ chains: p.chains.map((c) => c.chainNamespace),
71
+ })),
72
+ };
73
+ },
74
+ get(preset, options = {}) {
75
+ const entry = entries.find((p) => p.constant === preset);
76
+ if (!entry)
77
+ throw invalid(`unknown preset ${String(preset)}`);
78
+ if (!options || typeof options !== 'object' || Array.isArray(options))
79
+ throw invalid('preset options must be an object');
80
+ if (options.agent !== undefined &&
81
+ (!(0, viem_1.isAddress)(options.agent, { strict: false }) ||
82
+ (0, viem_1.getAddress)(options.agent) === viem_1.zeroAddress))
83
+ throw invalid('preset agent must be a nonzero Push address');
84
+ if (options.validUntil !== undefined &&
85
+ (!Number.isSafeInteger(options.validUntil) ||
86
+ options.validUntil <= Math.floor(Date.now() / 1000) ||
87
+ options.validUntil >= 2 ** 48))
88
+ throw invalid('preset validUntil must be a future uint48 timestamp');
89
+ if (options.maxGasPerCall !== undefined)
90
+ cap(options.maxGasPerCall, 'maxGasPerCall');
91
+ if (options.assets !== undefined && !Array.isArray(options.assets))
92
+ throw invalid('preset assets must be an array');
93
+ const chains = options.chainNamespace === undefined
94
+ ? entry.chains
95
+ : entry.chains.filter((c) => c.chainNamespace === options.chainNamespace);
96
+ if (options.chainNamespace !== undefined && !chains.length)
97
+ throw (0, errors_1.capabilityUnavailable)('presetChain', `preset ${preset} has no approved entry for ${options.chainNamespace}`);
98
+ if (!chains.length && options.assets?.length)
99
+ throw (0, errors_1.capabilityUnavailable)('presetCatalog', `preset ${preset} has no approved app entries`);
100
+ const assets = new Map();
101
+ for (const asset of options.assets ?? []) {
102
+ if (!asset || typeof asset !== 'object')
103
+ throw invalid('preset asset must be an object');
104
+ const chain = asset.chainNamespace ?? options.chainNamespace;
105
+ if (!chain)
106
+ throw invalid('each asset needs chainNamespace when no chain filter is supplied');
107
+ if (!chains.some((c) => c.chainNamespace === chain))
108
+ throw invalid(`asset chain ${chain} is outside the selected preset`);
109
+ const address = tokenAddress(asset.token);
110
+ if (chain.startsWith('eip155:') &&
111
+ !(0, viem_1.isAddress)(address, { strict: false }))
112
+ throw invalid('EVM preset asset requires an EVM address');
113
+ const group = assets.get(chain) ?? [];
114
+ const key = chain.startsWith('eip155:')
115
+ ? address.toLowerCase()
116
+ : address;
117
+ if (group.some((a) => (chain.startsWith('eip155:')
118
+ ? tokenAddress(a.token).toLowerCase()
119
+ : tokenAddress(a.token)) === key))
120
+ throw invalid('duplicate preset asset on the same chain');
121
+ group.push({
122
+ token: typeof asset.token === 'string' ? asset.token : { ...asset.token },
123
+ maxPerCall: cap(asset.maxPerCall, 'maxPerCall'),
124
+ maxTotal: cap(asset.maxTotal, 'maxTotal'),
125
+ });
126
+ assets.set(chain, group);
127
+ }
128
+ const rules = chains.map((chain) => {
129
+ const calls = chain.allowedCalls.map(copyCall);
130
+ if (chain.swapRouters?.length) {
131
+ const tokens = assets.get(chain.chainNamespace) ?? [];
132
+ if (tokens.some((a) => tokenAddress(a.token) === viem_1.zeroAddress ||
133
+ (typeof a.token !== 'string' && a.token.mechanism === 'native')))
134
+ throw invalid('DEX token pins require explicit ERC20 addresses; use wrapped-native tokens instead of the native marker');
135
+ // Keep discovery useful before a swap pair is selected. These review
136
+ // calls cannot spend input tokens: the amount maximum is explicitly zero.
137
+ // Re-run get with both tokens to generate the executable pair pins.
138
+ if (tokens.length < 2)
139
+ for (const router of chain.swapRouters)
140
+ for (const exactInput of [true, false])
141
+ calls.push({
142
+ target: router.address,
143
+ selector: `${exactInput ? 'exactInputSingle' : 'exactOutputSingle'}((address,address,uint24,address,uint256,uint256,uint160))`,
144
+ pins: [
145
+ ...(tokens.length
146
+ ? [
147
+ {
148
+ arg: [0, 0],
149
+ expected: (0, viem_1.getAddress)(tokenAddress(tokens[0].token)),
150
+ },
151
+ ]
152
+ : []),
153
+ { arg: [0, 3], expected: 'agentic:wallet' },
154
+ { arg: [0, exactInput ? 4 : 5], max: BigInt(0) },
155
+ ],
156
+ app: router.app,
157
+ label: `${exactInput ? 'Swap exact input' : 'Swap exact output'} (select two tokens to enable)`,
158
+ });
159
+ for (const router of chain.swapRouters)
160
+ for (const input of tokens)
161
+ for (const output of tokens) {
162
+ if (tokenAddress(input.token).toLowerCase() ===
163
+ tokenAddress(output.token).toLowerCase())
164
+ continue;
165
+ for (const exactInput of [true, false])
166
+ calls.push({
167
+ target: router.address,
168
+ selector: `${exactInput ? 'exactInputSingle' : 'exactOutputSingle'}((address,address,uint24,address,uint256,uint256,uint160))`,
169
+ pins: [
170
+ {
171
+ arg: [0, 0],
172
+ expected: (0, viem_1.getAddress)(tokenAddress(input.token)),
173
+ },
174
+ {
175
+ arg: [0, 1],
176
+ expected: (0, viem_1.getAddress)(tokenAddress(output.token)),
177
+ },
178
+ { arg: [0, 3], expected: 'agentic:wallet' },
179
+ { arg: [0, exactInput ? 4 : 5], max: input.maxPerCall },
180
+ ],
181
+ app: router.app,
182
+ label: exactInput
183
+ ? 'Swap exact input'
184
+ : 'Swap exact output',
185
+ });
186
+ }
187
+ }
188
+ const approvals = new Set();
189
+ for (const asset of assets.get(chain.chainNamespace) ?? []) {
190
+ const token = tokenAddress(asset.token);
191
+ if (token === viem_1.zeroAddress ||
192
+ (typeof asset.token !== 'string' &&
193
+ asset.token.mechanism === 'native'))
194
+ continue;
195
+ for (const approval of chain.approvals ?? []) {
196
+ if (!chain.chainNamespace.startsWith('eip155:'))
197
+ throw (0, errors_1.capabilityUnavailable)('presetApproval', 'Solana approvals require a separately reviewed instruction template');
198
+ if (approval.token &&
199
+ (0, viem_1.getAddress)(token) !== (0, viem_1.getAddress)(approval.token))
200
+ continue;
201
+ const spender = (0, viem_1.getAddress)(approval.spender);
202
+ const target = (0, viem_1.getAddress)(token);
203
+ const approvalKey = `${target}:${spender}`;
204
+ if (approvals.has(approvalKey))
205
+ continue;
206
+ approvals.add(approvalKey);
207
+ calls.push({
208
+ target,
209
+ selector: 'approve(address,uint256)',
210
+ pins: [
211
+ { arg: 0, expected: spender },
212
+ { arg: 1, max: asset.maxPerCall },
213
+ ],
214
+ app: approval.app,
215
+ label: 'Approve token spending',
216
+ });
217
+ }
218
+ }
219
+ if (!calls.length || calls.length > 32)
220
+ throw (0, errors_1.capabilityUnavailable)('presetCalls', 'preset must contain 1..32 allowed calls including approvals');
221
+ if (calls.reduce((n, c) => n + (c.pins?.length ?? 0), 0) > 32)
222
+ throw (0, errors_1.capabilityUnavailable)('presetPins', 'preset expansion exceeds 32 pins; reduce the token list or split rules across wallets');
223
+ const pairs = new Map();
224
+ for (const call of calls) {
225
+ if (!/^[A-Za-z_$][\w$]*\(.*\)$/.test(call.selector))
226
+ throw invalid('preset selectors must be full signatures');
227
+ const selector = chain.chainNamespace.startsWith('eip155:')
228
+ ? (0, selectors_1.parseSelector)(call.selector).selector
229
+ : call.selector;
230
+ const pair = `${chain.chainNamespace.startsWith('eip155:')
231
+ ? call.target.toLowerCase()
232
+ : call.target}:${selector}`;
233
+ if (pairs.has(pair) && !chain.chainNamespace.startsWith('eip155:'))
234
+ throw (0, errors_1.capabilityUnavailable)('presetCalls', 'Solana does not support alternative entries for one program/instruction');
235
+ if (pairs.has(pair) && (!call.pins?.length || !pairs.get(pair)))
236
+ throw (0, errors_1.capabilityUnavailable)('presetCalls', 'an unpinned alternative would bypass restrictions for this target/function');
237
+ pairs.set(pair, !!call.pins?.length);
238
+ }
239
+ return {
240
+ chainNamespace: chain.chainNamespace,
241
+ allowedCalls: calls,
242
+ ...(options.agent !== undefined
243
+ ? { agent: (0, viem_1.getAddress)(options.agent) }
244
+ : {}),
245
+ ...(options.validUntil !== undefined
246
+ ? { validUntil: options.validUntil }
247
+ : {}),
248
+ ...(options.assets !== undefined
249
+ ? { assets: assets.get(chain.chainNamespace) ?? [] }
250
+ : {}),
251
+ ...((options.maxGasPerCall ?? chain.maxGasPerCall) !== undefined
252
+ ? {
253
+ maxGasPerCall: cap(options.maxGasPerCall ?? chain.maxGasPerCall, 'maxGasPerCall'),
254
+ }
255
+ : {}),
256
+ };
257
+ });
258
+ return { rules };
259
+ },
260
+ };
261
+ // The overload narrows templates only when both required fields were supplied and validated.
262
+ return Object.freeze(api);
263
+ }
264
+ exports.agenticPresets = buildPresetApi(catalog_1.PRESET_CATALOG);
265
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,48 @@
1
+ import type { Address } from 'viem';
2
+ import type { Rule, RuleAsset, ForeignChainNamespace } from '../agentic.types';
3
+ export type PresetCategory = 'DEXES' | 'LENDING' | 'STAKING' | 'PREDICTION';
4
+ export interface Preset {
5
+ type: 'CATEGORY';
6
+ constant: PresetCategory;
7
+ name: string;
8
+ chains: ForeignChainNamespace[];
9
+ }
10
+ /** An editable review-screen template; both identity and expiry are required by create. */
11
+ export type PresetRuleTemplate = Omit<Rule, 'agent' | 'validUntil'> & {
12
+ agent?: Address;
13
+ validUntil?: number;
14
+ };
15
+ export interface PresetAsset {
16
+ chainNamespace?: ForeignChainNamespace;
17
+ token: RuleAsset['token'];
18
+ /** Omitted caps are zero, by the user's October 12 decision. */
19
+ maxPerCall?: bigint;
20
+ maxTotal?: bigint;
21
+ }
22
+ export interface PresetOptions {
23
+ /** Explicit Push-PC gas budget per outbound; omitted = zero. */
24
+ maxGasPerCall?: bigint;
25
+ chainNamespace?: ForeignChainNamespace;
26
+ agent?: Address;
27
+ validUntil?: number;
28
+ /** DEX swaps with fewer than two tokens are zero-input-cap review templates.
29
+ * Call get again with a complete pair to generate token pins and amount limits. */
30
+ assets?: PresetAsset[];
31
+ }
32
+ export interface ReadyPresetOptions extends PresetOptions {
33
+ agent: Address;
34
+ validUntil: number;
35
+ }
36
+ export interface AgenticPresets {
37
+ list(options?: {
38
+ type?: 'CATEGORY';
39
+ }): {
40
+ presets: Preset[];
41
+ };
42
+ get(preset: PresetCategory, options: ReadyPresetOptions): {
43
+ rules: Rule[];
44
+ };
45
+ get(preset: PresetCategory, options?: PresetOptions): {
46
+ rules: PresetRuleTemplate[];
47
+ };
48
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,9 @@
1
+ import { type Address } from 'viem';
2
+ import type { Rule, RuleInput, InternalRule, ArgumentPath } from './agentic.types';
3
+ import type { AgenticRuntime } from './runtime';
4
+ export declare const WALLET: "agentic:wallet";
5
+ /** Mark authored inputs for normalization after the wallet address is fixed. */
6
+ export declare function publicRules(rules: readonly RuleInput[]): InternalRule[];
7
+ export declare function isPublicRule(rule: InternalRule): boolean;
8
+ export declare function evmPinOffset(selector: Rule['allowedCalls'][number]['selector'], arg: ArgumentPath): number;
9
+ export declare function normalizePublicRule(input: InternalRule, wallet: Address, runtime: AgenticRuntime): Promise<InternalRule>;
@@ -0,0 +1,326 @@
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.WALLET = void 0;
27
+ exports.publicRules = publicRules;
28
+ exports.isPublicRule = isPublicRule;
29
+ exports.evmPinOffset = evmPinOffset;
30
+ exports.normalizePublicRule = normalizePublicRule;
31
+ const pins_1 = require("./codec/pins");
32
+ const web3_js_1 = require("@solana/web3.js");
33
+ const viem_1 = require("viem");
34
+ const errors_1 = require("./errors");
35
+ const selectors_1 = require("./codec/selectors");
36
+ const abi_layout_1 = require("./codec/abi-layout");
37
+ const defaults_1 = require("./codec/defaults");
38
+ const svm_accounts_1 = require("./codec/svm-accounts");
39
+ exports.WALLET = 'agentic:wallet';
40
+ const PUBLIC_INPUT = Symbol('AGW public rule');
41
+ /** Mark authored inputs for normalization after the wallet address is fixed. */
42
+ function publicRules(rules) {
43
+ if (!Array.isArray(rules))
44
+ throw invalid('rules must be an array');
45
+ return rules.map((rule) => {
46
+ if (!rule || typeof rule !== 'object')
47
+ throw invalid('rule must be an object');
48
+ return { ...rule, [PUBLIC_INPUT]: true };
49
+ });
50
+ }
51
+ function isPublicRule(rule) {
52
+ return !!rule && !!rule[PUBLIC_INPUT];
53
+ }
54
+ function invalid(message) {
55
+ return new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, message);
56
+ }
57
+ function rejectFields(obj, fields, where) {
58
+ for (const field of fields)
59
+ if (field in obj)
60
+ throw invalid(`${where}.${field} is not supported by the current rule shape`);
61
+ }
62
+ function uint(value, name) {
63
+ if (typeof value !== 'bigint' || value < BigInt(0) || value > defaults_1.UINT256_MAX)
64
+ throw invalid(`${name} must be a uint256 bigint`);
65
+ return value;
66
+ }
67
+ function evmPinOffset(selector, arg) {
68
+ const parsed = (0, selectors_1.parseSelector)(selector);
69
+ if (parsed.valueOnly)
70
+ throw invalid('value-only calls cannot have argument pins');
71
+ if (parsed.inputs)
72
+ return (0, abi_layout_1.argumentLocation)(parsed.inputs, arg, 'pin').offset;
73
+ if (typeof arg !== 'number' ||
74
+ !Number.isSafeInteger(arg) ||
75
+ arg < 0 ||
76
+ 4 + 32 * arg + 32 > 65535)
77
+ throw invalid('a raw selector needs a valid scalar ABI word index');
78
+ return 4 + 32 * arg;
79
+ }
80
+ function expectedWord(selector, arg, value) {
81
+ const parsed = (0, selectors_1.parseSelector)(selector);
82
+ if (parsed.inputs)
83
+ return (0, abi_layout_1.encodeArgWord)((0, abi_layout_1.argumentLocation)(parsed.inputs, arg, 'pin').param, value, 'pin');
84
+ if (typeof value === 'bigint')
85
+ return (0, viem_1.numberToHex)(uint(value, 'pin.expected'), { size: 32 });
86
+ if (typeof value === 'string' && (0, viem_1.isAddress)(value, { strict: false }))
87
+ return `0x${value.slice(2).padStart(64, '0')}`.toLowerCase();
88
+ if (typeof value === 'string' && (0, viem_1.isHex)(value) && value.length === 66)
89
+ return value.toLowerCase();
90
+ throw invalid('a raw EVM selector needs an address, uint256 or exact 32-byte expected word');
91
+ }
92
+ async function normalizePublicRule(input, wallet, runtime) {
93
+ const rule = input;
94
+ if ('format' in rule && rule.format === 'decoded')
95
+ return input;
96
+ const r = rule;
97
+ rejectFields(r, [
98
+ 'target',
99
+ 'selector',
100
+ 'actions',
101
+ 'pins',
102
+ 'amount',
103
+ 'maxCalls',
104
+ 'maxValuePerCall',
105
+ 'maxValueTotal',
106
+ 'ref',
107
+ 'allowedInstructions',
108
+ 'outputTokens',
109
+ ], 'rule');
110
+ if (!Number.isSafeInteger(r.validUntil) ||
111
+ r.validUntil <= runtime.nowSeconds() ||
112
+ r.validUntil >= 2 ** 48)
113
+ throw invalid('validUntil must be a future uint48 timestamp');
114
+ if (!Array.isArray(r.allowedCalls) ||
115
+ r.allowedCalls.length < 1 ||
116
+ r.allowedCalls.length > 32)
117
+ throw invalid('allowedCalls must contain 1..32 calls');
118
+ for (const c of r.allowedCalls) {
119
+ if (!c || typeof c !== 'object')
120
+ throw invalid('allowedCall must be an object');
121
+ rejectFields(c, [
122
+ 'beneficiary',
123
+ 'beneficiaryOffset',
124
+ 'amount',
125
+ 'maxCalls',
126
+ 'maxValuePerCall',
127
+ 'maxValueTotal',
128
+ 'validUntil',
129
+ ], 'allowedCall');
130
+ uint(c.maxValue ?? BigInt(0), 'allowedCall.maxValue');
131
+ if (c.pins !== undefined && !Array.isArray(c.pins))
132
+ throw invalid('pins must be an array');
133
+ for (const pin of c.pins ?? []) {
134
+ if (!pin || typeof pin !== 'object')
135
+ throw invalid('pin must be an object');
136
+ rejectFields(pin, ['offset', 'min'], 'pin');
137
+ if ('token' in pin && (!('account' in pin) || pin.expected !== exports.WALLET))
138
+ throw invalid('token is only valid on a WALLET account pin');
139
+ if ('arg' in pin === 'account' in pin)
140
+ throw invalid('pin must identify exactly one arg or account');
141
+ if ('expected' in pin === 'max' in pin)
142
+ throw invalid('pin must specify exactly one expected or max');
143
+ }
144
+ }
145
+ if (r.chainNamespace?.startsWith('solana:')) {
146
+ const { svmMetadata } = await Promise.resolve().then(() => __importStar(require('./management/svm-public')));
147
+ const gateway = await svmMetadata(runtime).gateway(r.chainNamespace);
148
+ if (gateway.chainNamespace !== r.chainNamespace)
149
+ throw invalid('gateway registry cluster mismatch');
150
+ return svmRule(r, (0, svm_accounts_1.deriveAgwSvmCea)(wallet, gateway.program).address);
151
+ }
152
+ const native = r.chainNamespace === undefined;
153
+ if (r.chainNamespace === runtime.pushChainNamespace)
154
+ throw invalid('omit chainNamespace for Push rules');
155
+ if (native && r.allowedCalls.length > 8)
156
+ throw (0, errors_1.capabilityUnavailable)('nativeActions', 'the deployed v6 wallet permits at most eight native actions');
157
+ if (native && (r.assets !== undefined || r.maxGasPerCall !== undefined))
158
+ throw invalid('native rules do not carry assets or maxGasPerCall');
159
+ const own = native
160
+ ? wallet
161
+ : (0, viem_1.getAddress)((await runtime.resolveCEA(wallet, r.chainNamespace)).cea);
162
+ const nativeActions = [];
163
+ const calls = [];
164
+ for (const call of r.allowedCalls) {
165
+ const pins = call.pins ?? [];
166
+ const wirePins = [];
167
+ const occupied = new Set();
168
+ for (const pin of pins) {
169
+ if ('account' in pin)
170
+ throw invalid('account pins only apply to Solana');
171
+ const offset = evmPinOffset(call.selector, pin.arg);
172
+ if (occupied.has(offset))
173
+ throw invalid('duplicate pin argument');
174
+ occupied.add(offset);
175
+ wirePins.push({
176
+ offset,
177
+ op: 'max' in pin ? 1 : 0,
178
+ value: 'max' in pin
179
+ ? (0, viem_1.numberToHex)(uint(pin.max, 'pin.max'), { size: 32 })
180
+ : expectedWord(call.selector, pin.arg, pin.expected === exports.WALLET ? own : pin.expected),
181
+ });
182
+ }
183
+ if (native)
184
+ nativeActions.push({
185
+ target: (0, viem_1.getAddress)(call.target),
186
+ selector: call.selector,
187
+ wirePins,
188
+ maxValuePerCall: call.maxValue ?? BigInt(0),
189
+ maxValueTotal: defaults_1.UINT256_MAX,
190
+ maxCalls: pins_1.UNLIMITED_CALLS,
191
+ });
192
+ else
193
+ calls.push({
194
+ target: (0, viem_1.getAddress)(call.target),
195
+ selector: call.selector,
196
+ pins: wirePins,
197
+ maxValue: call.maxValue ?? BigInt(0),
198
+ });
199
+ }
200
+ if (native)
201
+ return { agent: r.agent, validUntil: r.validUntil, actions: nativeActions };
202
+ return {
203
+ agent: r.agent,
204
+ validUntil: r.validUntil,
205
+ chainNamespace: r.chainNamespace,
206
+ assets: (r.assets ?? []).map((a) => ({
207
+ ...a,
208
+ token: a.token,
209
+ maxTotal: a.maxTotal ?? BigInt(0),
210
+ })),
211
+ maxGasPerCall: r.maxGasPerCall ?? BigInt(0),
212
+ allowedCalls: calls,
213
+ };
214
+ }
215
+ function svmType(text) {
216
+ const array = text.match(/^(.+)\[(\d+)\]$/);
217
+ if (array) {
218
+ const count = Number(array[2]);
219
+ if (!Number.isSafeInteger(count) || count < 1 || count > 128)
220
+ throw invalid('unsupported SVM fixed array size');
221
+ return { array: [svmType(array[1]), count] };
222
+ }
223
+ if ([
224
+ 'u8',
225
+ 'u16',
226
+ 'u32',
227
+ 'u64',
228
+ 'i8',
229
+ 'i16',
230
+ 'i32',
231
+ 'i64',
232
+ 'bool',
233
+ 'pubkey',
234
+ ].includes(text))
235
+ return text;
236
+ if (text === 'publicKey')
237
+ return 'pubkey';
238
+ throw (0, errors_1.capabilityUnavailable)('svmArgumentLayout', `unsupported fixed-size Solana type ${text}`);
239
+ }
240
+ function svmRule(rule, cea) {
241
+ return {
242
+ agent: rule.agent,
243
+ validUntil: rule.validUntil,
244
+ chainNamespace: rule.chainNamespace,
245
+ outputTokens: [
246
+ ...new Set(rule.allowedCalls.flatMap((c) => (c.pins ?? []).flatMap((p) => 'account' in p && 'token' in p && p.expected === exports.WALLET && p.token
247
+ ? [typeof p.token === 'string' ? p.token : p.token.address]
248
+ : []))),
249
+ ],
250
+ assets: (rule.assets ?? []).map((asset) => ({
251
+ ...asset,
252
+ maxTotal: asset.maxTotal ?? BigInt(0),
253
+ })),
254
+ maxGasPerCall: rule.maxGasPerCall ?? BigInt(0),
255
+ allowedInstructions: rule.allowedCalls.map((call) => {
256
+ if ((call.maxValue ?? BigInt(0)) !== BigInt(0))
257
+ throw (0, errors_1.capabilityUnavailable)('svmCallValue', 'native Solana instruction value is governed by its transfer/pin, not an EVM call value');
258
+ const full = String(call.selector).match(/^([A-Za-z_][A-Za-z0-9_]*)\((.*)\)$/);
259
+ const raw = /^0x[0-9a-fA-F]{16}$/.test(call.selector);
260
+ if (!full && !raw)
261
+ throw invalid('Solana selector needs a fixed-width signature or eight-byte discriminator');
262
+ const types = full && full[2] ? full[2].split(',').map((s) => svmType(s.trim())) : [];
263
+ const name = full?.[1] ?? 'raw';
264
+ const discriminator = raw
265
+ ? (0, viem_1.hexToBytes)(call.selector)
266
+ : (0, viem_1.hexToBytes)((0, viem_1.sha256)((0, viem_1.toHex)(`global:${name
267
+ .replace(/([a-z0-9])([A-Z])/g, '$1_$2')
268
+ .toLowerCase()}`))).slice(0, 8);
269
+ const pins = call.pins ?? [];
270
+ const accounts = pins.filter((p) => 'account' in p);
271
+ if (accounts.some((p) => !Number.isInteger(p.account) || p.account < 0 || p.account >= 64))
272
+ throw invalid('Solana account position must be 0..63');
273
+ const accountCount = Math.max(0, ...accounts.map((p) => p.account + 1));
274
+ const idl = {
275
+ address: new web3_js_1.PublicKey((0, viem_1.hexToBytes)((0, svm_accounts_1.svmKey)(call.target))).toBase58(),
276
+ metadata: { name: 'rule_layout', version: '1', spec: '0.1.0' },
277
+ instructions: [
278
+ {
279
+ name,
280
+ discriminator: Array.from(discriminator),
281
+ accounts: Array.from({ length: accountCount }, (_, i) => ({
282
+ name: `account${i}`,
283
+ })),
284
+ args: types.map((type, i) => ({ name: `arg${i}`, type })),
285
+ },
286
+ ],
287
+ };
288
+ return {
289
+ maxAccounts: pins_1.ANY_ACCOUNT_COUNT,
290
+ program: call.target,
291
+ instruction: { idl, name },
292
+ accounts: accounts.map((p) => ({
293
+ name: `account${p.account}`,
294
+ expected: p.expected === exports.WALLET
295
+ ? p.token
296
+ ? {
297
+ kind: 'walletATA',
298
+ token: typeof p.token === 'string' ? p.token : p.token.address,
299
+ }
300
+ : { kind: 'walletCEA' }
301
+ : { kind: 'address', address: p.expected },
302
+ })),
303
+ fields: pins
304
+ .filter((p) => 'arg' in p)
305
+ .map((p) => {
306
+ const arg = p.arg;
307
+ if (!Number.isInteger(arg) || arg < 0 || arg >= types.length)
308
+ throw (0, errors_1.capabilityUnavailable)('svmArgumentLayout', 'argument pins need a signature with the indexed argument type; use decoded raw constraints for stored rules');
309
+ if ('max' in p)
310
+ return { name: `arg${arg}`, max: uint(p.max, 'pin.max') };
311
+ const rawExpected = p.expected;
312
+ const eq = rawExpected === exports.WALLET ? cea : rawExpected;
313
+ return {
314
+ name: `arg${arg}`,
315
+ equals: typeof eq === 'bigint'
316
+ ? eq
317
+ : /^0x/.test(eq)
318
+ ? eq
319
+ : (0, svm_accounts_1.svmKey)(eq),
320
+ };
321
+ }),
322
+ };
323
+ }),
324
+ };
325
+ }
326
+ //# sourceMappingURL=public-rule.js.map
@@ -0,0 +1,17 @@
1
+ import type { Address } from 'viem';
2
+ import type { AgenticGeneration } from '../deployments';
3
+ import type { ChainReader } from '../contracts/reader';
4
+ import type { Checkpoint } from '../agentic.types';
5
+ /**
6
+ * w.checkpoints(): Checkpointed events in (block, tx, log) order, checked
7
+ * against the wallet's checkpointCount() at the same snapshot block.
8
+ * `sinceBlock` is inclusive. Evaluators should compare counts — one block can
9
+ * hold several ticks, and allowance pulls change balances without any tick.
10
+ */
11
+ export declare function readCheckpoints(reader: ChainReader, gen: AgenticGeneration, wallet: Address, sinceBlock?: bigint): Promise<{
12
+ checkpoints: Checkpoint[];
13
+ count: bigint;
14
+ blockNumber: bigint;
15
+ }>;
16
+ /** Sequence must be contiguous, end at `count`, and start at 1 for a full scan. */
17
+ export declare function validateSequence(seqs: number[], count: bigint, fullRange: boolean): string | null;