@pushchain/core 6.0.25 → 6.0.27-alpha.0

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 (183) hide show
  1. package/AGW.md +194 -0
  2. package/CHANGELOG.md +74 -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 +409 -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 +15 -0
  14. package/src/lib/agentic/codec/abi-layout.js +121 -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 +75 -0
  20. package/src/lib/agentic/codec/native.js +328 -0
  21. package/src/lib/agentic/codec/rules.d.ts +45 -0
  22. package/src/lib/agentic/codec/rules.js +110 -0
  23. package/src/lib/agentic/codec/selectors.d.ts +19 -0
  24. package/src/lib/agentic/codec/selectors.js +60 -0
  25. package/src/lib/agentic/codec/session.d.ts +54 -0
  26. package/src/lib/agentic/codec/session.js +65 -0
  27. package/src/lib/agentic/codec/svm-accounts.d.ts +35 -0
  28. package/src/lib/agentic/codec/svm-accounts.js +68 -0
  29. package/src/lib/agentic/codec/svm-idl.d.ts +11 -0
  30. package/src/lib/agentic/codec/svm-idl.js +226 -0
  31. package/src/lib/agentic/codec/svm-terms.d.ts +157 -0
  32. package/src/lib/agentic/codec/svm-terms.js +242 -0
  33. package/src/lib/agentic/codec/universal-terms.d.ts +67 -0
  34. package/src/lib/agentic/codec/universal-terms.js +41 -0
  35. package/src/lib/agentic/codec/universal.d.ts +14 -0
  36. package/src/lib/agentic/codec/universal.js +157 -0
  37. package/src/lib/agentic/constants.d.ts +11 -0
  38. package/src/lib/agentic/constants.js +15 -0
  39. package/src/lib/agentic/context.d.ts +29 -0
  40. package/src/lib/agentic/context.js +56 -0
  41. package/src/lib/agentic/contracts/abi/v5/agent-validator.d.ts +105 -0
  42. package/src/lib/agentic/contracts/abi/v5/agent-validator.js +149 -0
  43. package/src/lib/agentic/contracts/abi/v5/agw-factory.d.ts +847 -0
  44. package/src/lib/agentic/contracts/abi/v5/agw-factory.js +1108 -0
  45. package/src/lib/agentic/contracts/abi/v5/agw.d.ts +1211 -0
  46. package/src/lib/agentic/contracts/abi/v5/agw.js +1588 -0
  47. package/src/lib/agentic/contracts/abi/v5/index.d.ts +6 -0
  48. package/src/lib/agentic/contracts/abi/v5/index.js +17 -0
  49. package/src/lib/agentic/contracts/abi/v5/smart-session.d.ts +1493 -0
  50. package/src/lib/agentic/contracts/abi/v5/smart-session.js +1965 -0
  51. package/src/lib/agentic/contracts/abi/v5/universal-rules-policy.d.ts +1640 -0
  52. package/src/lib/agentic/contracts/abi/v5/universal-rules-policy.js +2160 -0
  53. package/src/lib/agentic/contracts/donut-v5.d.ts +11 -0
  54. package/src/lib/agentic/contracts/donut-v5.js +15 -0
  55. package/src/lib/agentic/contracts/prc20-metadata.d.ts +26 -0
  56. package/src/lib/agentic/contracts/prc20-metadata.js +87 -0
  57. package/src/lib/agentic/contracts/reader.d.ts +35 -0
  58. package/src/lib/agentic/contracts/reader.js +16 -0
  59. package/src/lib/agentic/contracts/v5.d.ts +5323 -0
  60. package/src/lib/agentic/contracts/v5.js +316 -0
  61. package/src/lib/agentic/deployments.d.ts +61 -0
  62. package/src/lib/agentic/deployments.js +203 -0
  63. package/src/lib/agentic/errors.d.ts +71 -0
  64. package/src/lib/agentic/errors.js +92 -0
  65. package/src/lib/agentic/execution/guards.d.ts +9 -0
  66. package/src/lib/agentic/execution/guards.js +30 -0
  67. package/src/lib/agentic/execution/outbound.d.ts +55 -0
  68. package/src/lib/agentic/execution/outbound.js +187 -0
  69. package/src/lib/agentic/execution/send.d.ts +9 -0
  70. package/src/lib/agentic/execution/send.js +276 -0
  71. package/src/lib/agentic/execution/svm-instruction.d.ts +24 -0
  72. package/src/lib/agentic/execution/svm-instruction.js +40 -0
  73. package/src/lib/agentic/execution/svm-outbound.d.ts +18 -0
  74. package/src/lib/agentic/execution/svm-outbound.js +86 -0
  75. package/src/lib/agentic/execution/svm-payload.d.ts +18 -0
  76. package/src/lib/agentic/execution/svm-payload.js +136 -0
  77. package/src/lib/agentic/execution/svm-public.d.ts +5 -0
  78. package/src/lib/agentic/execution/svm-public.js +182 -0
  79. package/src/lib/agentic/execution/svm-quote.d.ts +11 -0
  80. package/src/lib/agentic/execution/svm-quote.js +24 -0
  81. package/src/lib/agentic/execution/svm-send.d.ts +44 -0
  82. package/src/lib/agentic/execution/svm-send.js +90 -0
  83. package/src/lib/agentic/index.d.ts +5 -0
  84. package/src/lib/agentic/index.js +10 -0
  85. package/src/lib/agentic/management/common.d.ts +29 -0
  86. package/src/lib/agentic/management/common.js +114 -0
  87. package/src/lib/agentic/management/create.d.ts +16 -0
  88. package/src/lib/agentic/management/create.js +271 -0
  89. package/src/lib/agentic/management/duplicates.d.ts +4 -0
  90. package/src/lib/agentic/management/duplicates.js +20 -0
  91. package/src/lib/agentic/management/label.d.ts +3 -0
  92. package/src/lib/agentic/management/label.js +17 -0
  93. package/src/lib/agentic/management/prepare.d.ts +7 -0
  94. package/src/lib/agentic/management/prepare.js +95 -0
  95. package/src/lib/agentic/management/rules-write.d.ts +42 -0
  96. package/src/lib/agentic/management/rules-write.js +279 -0
  97. package/src/lib/agentic/management/svm-context.d.ts +25 -0
  98. package/src/lib/agentic/management/svm-context.js +55 -0
  99. package/src/lib/agentic/management/svm-metadata.d.ts +10 -0
  100. package/src/lib/agentic/management/svm-metadata.js +56 -0
  101. package/src/lib/agentic/management/svm-public.d.ts +6 -0
  102. package/src/lib/agentic/management/svm-public.js +125 -0
  103. package/src/lib/agentic/management/svm.d.ts +27 -0
  104. package/src/lib/agentic/management/svm.js +150 -0
  105. package/src/lib/agentic/presets/catalog.d.ts +21 -0
  106. package/src/lib/agentic/presets/catalog.js +10 -0
  107. package/src/lib/agentic/presets/index.d.ts +5 -0
  108. package/src/lib/agentic/presets/index.js +190 -0
  109. package/src/lib/agentic/presets/types.d.ts +44 -0
  110. package/src/lib/agentic/presets/types.js +3 -0
  111. package/src/lib/agentic/public-rule.d.ts +9 -0
  112. package/src/lib/agentic/public-rule.js +342 -0
  113. package/src/lib/agentic/reads/checkpoints.d.ts +17 -0
  114. package/src/lib/agentic/reads/checkpoints.js +109 -0
  115. package/src/lib/agentic/reads/rules.d.ts +42 -0
  116. package/src/lib/agentic/reads/rules.js +286 -0
  117. package/src/lib/agentic/reads/snapshot.d.ts +28 -0
  118. package/src/lib/agentic/reads/snapshot.js +85 -0
  119. package/src/lib/agentic/reads/svm.d.ts +17 -0
  120. package/src/lib/agentic/reads/svm.js +52 -0
  121. package/src/lib/agentic/reads/wallets.d.ts +25 -0
  122. package/src/lib/agentic/reads/wallets.js +122 -0
  123. package/src/lib/agentic/response.d.ts +41 -0
  124. package/src/lib/agentic/response.js +358 -0
  125. package/src/lib/agentic/revert.d.ts +7 -0
  126. package/src/lib/agentic/revert.js +102 -0
  127. package/src/lib/agentic/runtime.d.ts +58 -0
  128. package/src/lib/agentic/runtime.js +95 -0
  129. package/src/lib/agentic/utils.d.ts +57 -0
  130. package/src/lib/agentic/utils.js +165 -0
  131. package/src/lib/agentic/wallet.d.ts +32 -0
  132. package/src/lib/agentic/wallet.js +130 -0
  133. package/src/lib/constants/chain.js +1 -1
  134. package/src/lib/constants/enums.d.ts +6 -3
  135. package/src/lib/constants/enums.js +6 -3
  136. package/src/lib/constants/index.d.ts +65 -7
  137. package/src/lib/constants/index.js +18 -3
  138. package/src/lib/constants/read-state.d.ts +15 -2
  139. package/src/lib/constants/read-state.js +19 -3
  140. package/src/lib/index.d.ts +9 -3
  141. package/src/lib/index.js +11 -2
  142. package/src/lib/orchestrator/internals/errors.d.ts +7 -0
  143. package/src/lib/orchestrator/internals/errors.js +13 -1
  144. package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
  145. package/src/lib/orchestrator/internals/execute-standard.js +3 -3
  146. package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
  147. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
  148. package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
  149. package/src/lib/orchestrator/orchestrator.d.ts +3 -0
  150. package/src/lib/orchestrator/orchestrator.js +13 -1
  151. package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
  152. package/src/lib/orchestrator/route-detector.js +3 -2
  153. package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
  154. package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
  155. package/src/lib/progress-hook/progress-hook.js +84 -0
  156. package/src/lib/progress-hook/progress-hook.types.d.ts +14 -2
  157. package/src/lib/progress-hook/progress-hook.types.js +13 -0
  158. package/src/lib/push-chain/push-chain.d.ts +58 -16
  159. package/src/lib/push-chain/push-chain.js +68 -8
  160. package/src/lib/push-client/push-client.d.ts +7 -0
  161. package/src/lib/push-client/push-client.js +41 -15
  162. package/src/lib/read-state/destination.js +6 -1
  163. package/src/lib/read-state/envelopes/evm.js +2 -3
  164. package/src/lib/read-state/envelopes/svm.js +11 -1
  165. package/src/lib/read-state/read-executor.js +4 -0
  166. package/src/lib/read-state/read-params.d.ts +71 -26
  167. package/src/lib/read-state/read-params.js +60 -15
  168. package/src/lib/read-state/read-state.types.d.ts +44 -1
  169. package/src/lib/read-state/read-state.types.js +23 -1
  170. package/src/lib/read-state/read-tracker.d.ts +6 -1
  171. package/src/lib/read-state/read-tracker.js +83 -17
  172. package/src/lib/read-state/registry.js +2 -3
  173. package/src/lib/read-state/result-decoder.js +6 -0
  174. package/src/lib/read-state/spec-builder.js +2 -2
  175. package/src/lib/read-state/svm-account.d.ts +20 -0
  176. package/src/lib/read-state/svm-account.js +114 -0
  177. package/src/lib/read-state/svm-pda.d.ts +13 -0
  178. package/src/lib/read-state/svm-pda.js +147 -0
  179. package/src/lib/universal/prc20-address.d.ts +15 -0
  180. package/src/lib/universal/prc20-address.js +135 -0
  181. package/src/lib/utils.d.ts +6 -13
  182. package/src/lib/utils.js +5 -128
  183. package/src/lib/vm-client/evm-client.js +34 -20
@@ -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
+ }>;
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.verifySvmWallet = verifySvmWallet;
4
+ exports.grantSvmWire = grantSvmWire;
5
+ exports.prepareSvmReplacement = prepareSvmReplacement;
6
+ exports.replaceSvmWire = replaceSvmWire;
7
+ /** Internal explicit-wire operations. Not exported by the SDK entry point. */
8
+ const viem_1 = require("viem");
9
+ const deployments_1 = require("../deployments");
10
+ const snapshot_1 = require("../reads/snapshot");
11
+ const svm_1 = require("../reads/svm");
12
+ const common_1 = require("./common");
13
+ const svm_terms_1 = require("../codec/svm-terms");
14
+ const session_1 = require("../codec/session");
15
+ const ids_1 = require("../codec/ids");
16
+ const v5_1 = require("../contracts/v5");
17
+ const svm_accounts_1 = require("../codec/svm-accounts");
18
+ const errors_1 = require("../errors");
19
+ const prc20_metadata_1 = require("../contracts/prc20-metadata");
20
+ async function verifyAssets(snap, input) {
21
+ if (!/^solana:[1-9A-HJ-NP-Za-km-z]{32}$/.test(input.chainNamespace))
22
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'SVM chain must be a full Solana CAIP-2 namespace');
23
+ for (const cap of input.terms.assets) {
24
+ if ((await snap.read(cap.token, prc20_metadata_1.PRC20_SOURCE_ABI, 'SOURCE_CHAIN_NAMESPACE')) !== input.chainNamespace)
25
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.ASSET_CHAIN_MISMATCH, 'SVM asset source-chain mismatch');
26
+ }
27
+ }
28
+ async function verifySvmWallet(runtime, gen, wallet) {
29
+ const actual = await (0, deployments_1.resolveWalletGeneration)(runtime.reader, runtime.network, wallet);
30
+ if (actual.addresses.factory !== gen.addresses.factory)
31
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.CAPABILITY_UNAVAILABLE, 'SVM wallet generation mismatch');
32
+ await (0, deployments_1.verifyPolicyVersion)(runtime.reader, gen);
33
+ }
34
+ function session(gen, wallet, owner, input, now) {
35
+ const agent = (0, viem_1.getAddress)(input.agent);
36
+ if (agent === owner)
37
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.AGENT_IS_OWNER, 'agent must differ from owner');
38
+ const cea = (0, svm_accounts_1.deriveAgwSvmCea)(wallet, input.terms.gatewayProgram).address;
39
+ if (cea.toLowerCase() !== input.terms.expectedCEA.toLowerCase())
40
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'SVM expectedCEA does not belong to this wallet/gateway');
41
+ return (0, session_1.buildSession)({
42
+ validator: gen.addresses.sessionValidator,
43
+ rulesPolicy: gen.addresses.rulesPolicy,
44
+ agent,
45
+ actions: [
46
+ {
47
+ target: gen.addresses.gateway,
48
+ selector: v5_1.SEND_OUTBOUND_SELECTOR,
49
+ initData: (0, session_1.encodeEnvelope)(input.chainNamespace, (0, svm_terms_1.encodeSvmTerms)(input.terms, now)),
50
+ },
51
+ ],
52
+ });
53
+ }
54
+ async function grantSvmWire(runtime, gen, wallet, input) {
55
+ (0, common_1.assertCanSign)(runtime, 'internal SVM grant');
56
+ await verifySvmWallet(runtime, gen, wallet);
57
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
58
+ const owner = await (0, common_1.assertOwner)(runtime, gen, wallet, snap);
59
+ await verifyAssets(snap, input);
60
+ const s = session(gen, wallet, owner, input, runtime.nowSeconds());
61
+ const nonce = await snap.read(wallet, gen.contracts.abis.wallet, 'grantNonce');
62
+ const expected = (0, ids_1.rulesId)({
63
+ validator: gen.addresses.sessionValidator,
64
+ agent: (0, viem_1.getAddress)(input.agent),
65
+ grantNonce: nonce,
66
+ });
67
+ let tx;
68
+ try {
69
+ tx = await runtime.execute({
70
+ to: wallet,
71
+ value: BigInt(0),
72
+ data: gen.contracts.encodeGrantRules(s),
73
+ });
74
+ }
75
+ catch (error) {
76
+ throw (0, common_1.wrapSendError)(error);
77
+ }
78
+ const { logs } = await (0, common_1.confirmedLogs)(runtime, tx);
79
+ const granted = gen.contracts.parseRulesGranted(logs, wallet);
80
+ if (granted.length !== 1 ||
81
+ granted[0].mode !== 0 ||
82
+ granted[0].chainNamespace !== input.chainNamespace)
83
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'SVM grant receipt did not match this operation', { details: { txHash: tx.hash, expected } });
84
+ // Another owner grant can advance grantNonce between read and inclusion.
85
+ // The sole matching event from this receipt is the authoritative ID.
86
+ return { rulesId: granted[0].rulesId, tx };
87
+ }
88
+ /** Snapshot -> all-asset assertion -> revoke -> grant. No sequential fallback. */
89
+ async function prepareSvmReplacement(runtime, gen, wallet, oldId, input) {
90
+ (0, common_1.assertCanSign)(runtime, 'internal SVM replacement');
91
+ await verifySvmWallet(runtime, gen, wallet);
92
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
93
+ const owner = await (0, common_1.assertOwner)(runtime, gen, wallet, snap);
94
+ await verifyAssets(snap, input);
95
+ const old = await (0, svm_1.readSvmRule)(snap, gen, wallet, oldId, runtime.pushChainNamespace);
96
+ const s = session(gen, wallet, owner, input, runtime.nowSeconds());
97
+ const nonce = await snap.read(wallet, gen.contracts.abis.wallet, 'grantNonce');
98
+ const rulesId = (0, ids_1.rulesId)({
99
+ validator: gen.addresses.sessionValidator,
100
+ agent: (0, viem_1.getAddress)(input.agent),
101
+ grantNonce: nonce,
102
+ });
103
+ const calls = [
104
+ {
105
+ target: gen.addresses.rulesPolicy,
106
+ value: BigInt(0),
107
+ data: gen.contracts.encodeAssertSpentUniversal(old.configId, wallet, old.config.assets.map((a) => a.spent)),
108
+ },
109
+ {
110
+ target: wallet,
111
+ value: BigInt(0),
112
+ data: gen.contracts.encodeRevokeRules(oldId),
113
+ },
114
+ {
115
+ target: wallet,
116
+ value: BigInt(0),
117
+ data: gen.contracts.encodeGrantRules(s),
118
+ },
119
+ ];
120
+ return {
121
+ rulesId,
122
+ oldId,
123
+ snapshotBlock: snap.blockNumber,
124
+ data: gen.contracts.encodeExecute(calls),
125
+ };
126
+ }
127
+ async function replaceSvmWire(runtime, gen, wallet, oldId, input) {
128
+ const prepared = await prepareSvmReplacement(runtime, gen, wallet, oldId, input);
129
+ let tx;
130
+ try {
131
+ tx = await runtime.execute({
132
+ to: wallet,
133
+ value: BigInt(0),
134
+ data: prepared.data,
135
+ });
136
+ }
137
+ catch (error) {
138
+ throw (0, common_1.wrapSendError)(error);
139
+ }
140
+ const { logs } = await (0, common_1.confirmedLogs)(runtime, tx);
141
+ const grants = gen.contracts.parseRulesGranted(logs, wallet);
142
+ const revokes = gen.contracts.parseRulesRevoked(logs, wallet);
143
+ if (grants.length !== 1 ||
144
+ grants[0].mode !== 0 ||
145
+ grants[0].chainNamespace !== input.chainNamespace ||
146
+ !revokes.some((r) => r.rulesId.toLowerCase() === oldId.toLowerCase()))
147
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'SVM replacement receipt mismatch', { details: { txHash: tx.hash } });
148
+ return { rulesId: grants[0].rulesId, replaced: oldId, tx };
149
+ }
150
+ //# sourceMappingURL=svm.js.map
@@ -0,0 +1,21 @@
1
+ import type { Address } from 'viem';
2
+ import type { RuleCall, ForeignChainNamespace } from '../agentic.types';
3
+ import type { PresetCategory } from './types';
4
+ /** Internal catalog: reviewed addresses and explicit calls only; never fetched at runtime. */
5
+ export interface PresetChainDefinition {
6
+ chainNamespace: ForeignChainNamespace;
7
+ allowedCalls: readonly RuleCall[];
8
+ /** Exact spenders that need an approval for each non-native supplied asset. */
9
+ approvals?: readonly {
10
+ spender: Address;
11
+ app: string;
12
+ }[];
13
+ maxGasPerCall?: bigint;
14
+ }
15
+ export interface PresetDefinition {
16
+ constant: PresetCategory;
17
+ name: string;
18
+ chains: readonly PresetChainDefinition[];
19
+ }
20
+ /** No approved app/address catalog yet. Empty categories must be hidden by UIs. */
21
+ export declare const PRESET_CATALOG: readonly PresetDefinition[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PRESET_CATALOG = void 0;
4
+ /** No approved app/address catalog yet. Empty categories must be hidden by UIs. */
5
+ exports.PRESET_CATALOG = [
6
+ { constant: 'DEXES', name: 'Popular DEXes', chains: [] },
7
+ { constant: 'LENDING', name: 'Lending', chains: [] },
8
+ { constant: 'PREDICTION', name: 'Prediction markets', chains: [] },
9
+ ];
10
+ //# sourceMappingURL=catalog.js.map
@@ -0,0 +1,5 @@
1
+ import type { AgenticPresets } from './types';
2
+ import { type PresetDefinition } from './catalog';
3
+ /** Not a public registration API. Tests inject fixtures; production uses the bundled catalog. */
4
+ export declare function buildPresetApi(catalog: readonly PresetDefinition[]): AgenticPresets;
5
+ export declare const agenticPresets: AgenticPresets;
@@ -0,0 +1,190 @@
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((p) => ({
24
+ ...p,
25
+ ...('token' in p && p.token && typeof p.token === 'object'
26
+ ? { token: { ...p.token } }
27
+ : {}),
28
+ })),
29
+ }
30
+ : {}),
31
+ };
32
+ }
33
+ function tokenAddress(token) {
34
+ const address = typeof token === 'string' ? token : token?.address;
35
+ if (typeof address !== 'string' || !address.trim())
36
+ throw invalid('preset asset requires a token address');
37
+ return address;
38
+ }
39
+ /** Not a public registration API. Tests inject fixtures; production uses the bundled catalog. */
40
+ function buildPresetApi(catalog) {
41
+ // Detach from the input so neither a returned template nor an input mutation changes the catalog.
42
+ const entries = catalog.map((p) => ({
43
+ ...p,
44
+ chains: p.chains.map((c) => ({
45
+ ...c,
46
+ allowedCalls: c.allowedCalls.map(copyCall),
47
+ approvals: c.approvals?.map((a) => ({ ...a })),
48
+ })),
49
+ }));
50
+ if (new Set(entries.map((e) => e.constant)).size !== entries.length ||
51
+ entries.some((e) => new Set(e.chains.map((c) => c.chainNamespace)).size !== e.chains.length))
52
+ throw invalid('duplicate preset or chain in catalog');
53
+ const api = {
54
+ list(options) {
55
+ if (options?.type !== undefined && options.type !== 'CATEGORY')
56
+ throw invalid('only CATEGORY presets are supported');
57
+ return {
58
+ presets: entries.map((p) => ({
59
+ type: 'CATEGORY',
60
+ constant: p.constant,
61
+ name: p.name,
62
+ chains: p.chains.map((c) => c.chainNamespace),
63
+ })),
64
+ };
65
+ },
66
+ get(preset, options = {}) {
67
+ const entry = entries.find((p) => p.constant === preset);
68
+ if (!entry)
69
+ throw invalid(`unknown preset ${String(preset)}`);
70
+ if (!options || typeof options !== 'object' || Array.isArray(options))
71
+ throw invalid('preset options must be an object');
72
+ if (options.agent !== undefined &&
73
+ (!(0, viem_1.isAddress)(options.agent, { strict: false }) ||
74
+ (0, viem_1.getAddress)(options.agent) === viem_1.zeroAddress))
75
+ throw invalid('preset agent must be a nonzero Push address');
76
+ if (options.validUntil !== undefined &&
77
+ (!Number.isSafeInteger(options.validUntil) ||
78
+ options.validUntil <= Math.floor(Date.now() / 1000) ||
79
+ options.validUntil >= 2 ** 48))
80
+ throw invalid('preset validUntil must be a future uint48 timestamp');
81
+ if (options.assets !== undefined && !Array.isArray(options.assets))
82
+ throw invalid('preset assets must be an array');
83
+ const chains = options.chainNamespace === undefined
84
+ ? entry.chains
85
+ : entry.chains.filter((c) => c.chainNamespace === options.chainNamespace);
86
+ if (options.chainNamespace !== undefined && !chains.length)
87
+ throw (0, errors_1.capabilityUnavailable)('presetChain', `preset ${preset} has no approved entry for ${options.chainNamespace}`);
88
+ if (!chains.length && options.assets?.length)
89
+ throw (0, errors_1.capabilityUnavailable)('presetCatalog', `preset ${preset} has no approved app entries`);
90
+ const assets = new Map();
91
+ for (const asset of options.assets ?? []) {
92
+ if (!asset || typeof asset !== 'object')
93
+ throw invalid('preset asset must be an object');
94
+ const chain = asset.chainNamespace ?? options.chainNamespace;
95
+ if (!chain)
96
+ throw invalid('each asset needs chainNamespace when no chain filter is supplied');
97
+ if (!chains.some((c) => c.chainNamespace === chain))
98
+ throw invalid(`asset chain ${chain} is outside the selected preset`);
99
+ const address = tokenAddress(asset.token);
100
+ if (chain.startsWith('eip155:') &&
101
+ !(0, viem_1.isAddress)(address, { strict: false }))
102
+ throw invalid('EVM preset asset requires an EVM address');
103
+ const group = assets.get(chain) ?? [];
104
+ const key = chain.startsWith('eip155:')
105
+ ? address.toLowerCase()
106
+ : address;
107
+ if (group.some((a) => (chain.startsWith('eip155:')
108
+ ? tokenAddress(a.token).toLowerCase()
109
+ : tokenAddress(a.token)) === key))
110
+ throw invalid('duplicate preset asset on the same chain');
111
+ group.push({
112
+ token: typeof asset.token === 'string' ? asset.token : { ...asset.token },
113
+ maxPerCall: cap(asset.maxPerCall, 'maxPerCall'),
114
+ maxTotal: cap(asset.maxTotal, 'maxTotal'),
115
+ });
116
+ assets.set(chain, group);
117
+ }
118
+ const rules = chains.map((chain) => {
119
+ const calls = chain.allowedCalls.map(copyCall);
120
+ const approvals = new Map();
121
+ for (const asset of assets.get(chain.chainNamespace) ?? []) {
122
+ const token = tokenAddress(asset.token);
123
+ if (token === viem_1.zeroAddress ||
124
+ (typeof asset.token !== 'string' &&
125
+ asset.token.mechanism === 'native'))
126
+ continue;
127
+ for (const approval of chain.approvals ?? []) {
128
+ if (!chain.chainNamespace.startsWith('eip155:'))
129
+ throw (0, errors_1.capabilityUnavailable)('presetApproval', 'Solana approvals require a separately reviewed instruction template');
130
+ const spender = (0, viem_1.getAddress)(approval.spender);
131
+ const target = (0, viem_1.getAddress)(token);
132
+ const previous = approvals.get(target);
133
+ if (previous && previous !== spender)
134
+ throw (0, errors_1.capabilityUnavailable)('presetApproval', 'multiple spenders for one token need a reviewed policy representation; no unrestricted approval is generated');
135
+ if (previous)
136
+ continue;
137
+ approvals.set(target, spender);
138
+ calls.push({
139
+ target,
140
+ selector: 'approve(address,uint256)',
141
+ pins: [
142
+ { arg: 0, expected: spender },
143
+ { arg: 1, max: asset.maxPerCall },
144
+ ],
145
+ app: approval.app,
146
+ label: 'Approve token spending',
147
+ });
148
+ }
149
+ }
150
+ if (!calls.length || calls.length > 32)
151
+ throw (0, errors_1.capabilityUnavailable)('presetCalls', 'preset must contain 1..32 allowed calls including approvals');
152
+ const pairs = new Set();
153
+ for (const call of calls) {
154
+ if (!/^[A-Za-z_$][\w$]*\(.*\)$/.test(call.selector))
155
+ throw invalid('preset selectors must be full signatures');
156
+ const selector = chain.chainNamespace.startsWith('eip155:')
157
+ ? (0, selectors_1.parseSelector)(call.selector).selector
158
+ : call.selector;
159
+ const pair = `${chain.chainNamespace.startsWith('eip155:')
160
+ ? call.target.toLowerCase()
161
+ : call.target}:${selector}`;
162
+ if (pairs.has(pair))
163
+ throw (0, errors_1.capabilityUnavailable)('presetCalls', 'duplicate target/function entries need a reviewed policy representation');
164
+ pairs.add(pair);
165
+ }
166
+ return {
167
+ chainNamespace: chain.chainNamespace,
168
+ allowedCalls: calls,
169
+ ...(options.agent !== undefined
170
+ ? { agent: (0, viem_1.getAddress)(options.agent) }
171
+ : {}),
172
+ ...(options.validUntil !== undefined
173
+ ? { validUntil: options.validUntil }
174
+ : {}),
175
+ ...(options.assets !== undefined
176
+ ? { assets: assets.get(chain.chainNamespace) ?? [] }
177
+ : {}),
178
+ ...(chain.maxGasPerCall !== undefined
179
+ ? { maxGasPerCall: cap(chain.maxGasPerCall, 'maxGasPerCall') }
180
+ : {}),
181
+ };
182
+ });
183
+ return { rules };
184
+ },
185
+ };
186
+ // The overload narrows templates only when both required fields were supplied and validated.
187
+ return Object.freeze(api);
188
+ }
189
+ exports.agenticPresets = buildPresetApi(catalog_1.PRESET_CATALOG);
190
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,44 @@
1
+ import type { Address } from 'viem';
2
+ import type { Rule, RuleAsset, ForeignChainNamespace } from '../agentic.types';
3
+ export type PresetCategory = 'DEXES' | 'LENDING' | '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
+ chainNamespace?: ForeignChainNamespace;
24
+ agent?: Address;
25
+ validUntil?: number;
26
+ assets?: PresetAsset[];
27
+ }
28
+ export interface ReadyPresetOptions extends PresetOptions {
29
+ agent: Address;
30
+ validUntil: number;
31
+ }
32
+ export interface AgenticPresets {
33
+ list(options?: {
34
+ type?: 'CATEGORY';
35
+ }): {
36
+ presets: Preset[];
37
+ };
38
+ get(preset: PresetCategory, options: ReadyPresetOptions): {
39
+ rules: Rule[];
40
+ };
41
+ get(preset: PresetCategory, options?: PresetOptions): {
42
+ rules: PresetRuleTemplate[];
43
+ };
44
+ }
@@ -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 } 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: number): number;
9
+ export declare function normalizePublicRule(input: InternalRule, wallet: Address, runtime: AgenticRuntime): Promise<InternalRule>;