@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,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareSvmAgentExecution = prepareSvmAgentExecution;
4
+ exports.sendSvmAgentWire = sendSvmAgentWire;
5
+ const svm_quote_1 = require("./svm-quote");
6
+ /** Prepared-wire agent execution used by the public Solana route. */
7
+ const viem_1 = require("viem");
8
+ const common_1 = require("../management/common");
9
+ const snapshot_1 = require("../reads/snapshot");
10
+ const svm_1 = require("../reads/svm");
11
+ const svm_context_1 = require("../management/svm-context");
12
+ const svm_outbound_1 = require("./svm-outbound");
13
+ const svm_instruction_1 = require("./svm-instruction");
14
+ const errors_1 = require("../errors");
15
+ const svm_2 = require("../management/svm");
16
+ async function prepareSvmAgentExecution(runtime, gen, input, metadata) {
17
+ (0, common_1.assertCanSign)(runtime, 'internal SVM send');
18
+ await (0, svm_2.verifySvmWallet)(runtime, gen, input.wallet);
19
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
20
+ const stored = await (0, svm_1.readSvmRule)(snap, gen, input.wallet, input.rulesId, runtime.pushChainNamespace);
21
+ if ((0, viem_1.getAddress)(stored.agent) !== (0, viem_1.getAddress)(runtime.signerPushAccount()))
22
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.NOT_OWNER_OR_AGENT, 'signer is not this SVM rule agent');
23
+ const chain = stored.chainNamespace;
24
+ const resolved = await (0, svm_context_1.resolveSvmContext)(snap, input.wallet, stored.chainNamespace, stored.config.assets, metadata);
25
+ if (resolved.expectedCEA.toLowerCase() !==
26
+ stored.config.expectedCEA.toLowerCase() ||
27
+ resolved.gatewayProgram.toLowerCase() !==
28
+ stored.config.gatewayProgram.toLowerCase() ||
29
+ resolved.ceaAccounts.some((a) => !stored.config.ceaAccounts.some((b) => a.toLowerCase() === b.toLowerCase())))
30
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'stored SVM context does not cover the wallet and every asset');
31
+ const instruction = (0, svm_instruction_1.resolveAgwSvmInstruction)({
32
+ wallet: input.wallet,
33
+ chain,
34
+ program: input.program,
35
+ instructionData: input.instructionData,
36
+ accounts: input.accounts,
37
+ }, stored.config);
38
+ const quote = await (0, svm_quote_1.quoteSvmRequest)(runtime, snap, input.wallet, (0, viem_1.getAddress)(input.token), chain, input.gasLimit, input.amount);
39
+ const call = (0, svm_outbound_1.buildAgwSvmAction)({
40
+ ...input,
41
+ gateway: gen.addresses.gateway,
42
+ recipient: instruction.recipient,
43
+ payload: instruction.payload,
44
+ gasLimit: quote.gasLimitUsed,
45
+ protocolFee: quote.protocolFee,
46
+ maxPCForGas: quote.nativeValueForGas,
47
+ });
48
+ const walletPc = await runtime.reader.getBalance({
49
+ address: input.wallet,
50
+ blockNumber: snap.blockNumber,
51
+ });
52
+ if (walletPc < call.value)
53
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_BALANCE_INSUFFICIENT, 'wallet PC is below the SVM outbound quote');
54
+ if (input.amount > BigInt(0)) {
55
+ const balance = await snap.read(input.token, viem_1.erc20Abi, 'balanceOf', [input.wallet]);
56
+ if (balance < input.amount)
57
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_BALANCE_INSUFFICIENT, 'wallet token balance is below the SVM amount');
58
+ const allowance = await snap.read(input.token, viem_1.erc20Abi, 'allowance', [input.wallet, gen.addresses.gateway]);
59
+ if (allowance < input.amount)
60
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.GATEWAY_ALLOWANCE_INSUFFICIENT, 'owner must establish the SVM gateway allowance separately');
61
+ }
62
+ const signerPc = await runtime.signerBalance();
63
+ const gasReserve = (await runtime.getGasPrice()) * BigInt(10_000_000);
64
+ if ((await runtime.signerAccountDeployed()) && signerPc < gasReserve)
65
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.AGENT_GAS_INSUFFICIENT, 'deployed SVM agent identity has no Push gas balance');
66
+ return {
67
+ stored,
68
+ call,
69
+ instruction,
70
+ quote,
71
+ data: gen.contracts.encodeExecuteAsAgent(input.rulesId, call),
72
+ };
73
+ }
74
+ async function sendSvmAgentWire(runtime, gen, input, metadata) {
75
+ const prepared = await prepareSvmAgentExecution(runtime, gen, input, metadata);
76
+ try {
77
+ const tx = await runtime.execute({
78
+ to: input.wallet,
79
+ value: BigInt(0),
80
+ data: prepared.data,
81
+ });
82
+ // Return the ordinary signer response and explicit wire context internally.
83
+ // The public wrapper applies the response presentation.
84
+ return { tx, context: prepared.stored, instruction: prepared.instruction };
85
+ }
86
+ catch (error) {
87
+ throw (0, common_1.wrapSendError)(error);
88
+ }
89
+ }
90
+ //# sourceMappingURL=svm-send.js.map
@@ -0,0 +1,5 @@
1
+ export type { AgenticAddress, AgenticHex, AgenticDoor, AgenticNamespace, AgenticProgressHook, AgenticTxMetadata, AgenticWallet, RuleCall as AllowedCall, RuleAsset as AssetCap, Checkpoint, CheckpointKind, CreateOptions, CreateResult, ForeignChainNamespace, DecodedSolanaRule, Rule, RuleInput, Pin, Spent, WalletMarker, RulesRecord, Selector, WalletInfo, WalletSummary, } from './agentic.types';
2
+ export { AGENTIC_ERROR_CODE, AgenticError, AgenticRevertError } from './errors';
3
+ export type { AgenticErrorCode } from './errors';
4
+ export { AGENTIC } from './constants';
5
+ export type { Preset, PresetCategory, PresetAsset, PresetOptions, ReadyPresetOptions, PresetRuleTemplate, AgenticPresets, } from './presets/types';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AGENTIC = exports.AgenticRevertError = exports.AgenticError = exports.AGENTIC_ERROR_CODE = void 0;
4
+ var errors_1 = require("./errors");
5
+ Object.defineProperty(exports, "AGENTIC_ERROR_CODE", { enumerable: true, get: function () { return errors_1.AGENTIC_ERROR_CODE; } });
6
+ Object.defineProperty(exports, "AgenticError", { enumerable: true, get: function () { return errors_1.AgenticError; } });
7
+ Object.defineProperty(exports, "AgenticRevertError", { enumerable: true, get: function () { return errors_1.AgenticRevertError; } });
8
+ var constants_1 = require("./constants");
9
+ Object.defineProperty(exports, "AGENTIC", { enumerable: true, get: function () { return constants_1.AGENTIC; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,29 @@
1
+ import { type Address, type Hex, type Log } from 'viem';
2
+ import type { MultiCall, UniversalTxResponse } from '../../orchestrator/orchestrator.types';
3
+ import { PROGRESS_HOOK } from '../../progress-hook/progress-hook.types';
4
+ import type { AgenticGeneration } from '../deployments';
5
+ import type { AgenticRuntime } from '../runtime';
6
+ import type { AgenticProgressHook } from '../agentic.types';
7
+ import { Snapshot } from '../reads/snapshot';
8
+ export declare function emitAgentic(runtime: AgenticRuntime, perCall: AgenticProgressHook | undefined, id: PROGRESS_HOOK, ...args: unknown[]): void;
9
+ export declare function assertCanSign(runtime: AgenticRuntime, operation: string): void;
10
+ /** Owner-only management writes: the connected signer's Push identity must be the stored owner. */
11
+ export declare function assertOwner(runtime: AgenticRuntime, gen: AgenticGeneration, wallet: Address, snap: Snapshot): Promise<Address>;
12
+ /**
13
+ * Send owner calls through the signer's ordinary transaction path: one call
14
+ * as a plain transaction, several as the signer's batch (UEA multicall,
15
+ * EIP-7702 atomic batch, or the documented sequential fallback for a Push EOA
16
+ * without 7702 — reported through `atomic` / `transactionHashes`).
17
+ */
18
+ export declare function sendOwnerCalls(runtime: AgenticRuntime, calls: MultiCall[], progressHook: AgenticProgressHook | undefined): Promise<UniversalTxResponse>;
19
+ /**
20
+ * Wait for every Push transaction the operation produced and return their
21
+ * logs in submission order. A reverted transaction raises AgenticRevertError
22
+ * carrying all hashes.
23
+ */
24
+ export declare function confirmedLogs(runtime: AgenticRuntime, tx: UniversalTxResponse): Promise<{
25
+ logs: Log[];
26
+ hashes: Hex[];
27
+ }>;
28
+ /** Normalize a send failure: keep batch hashes and decoded revert data. */
29
+ export declare function wrapSendError(err: unknown): unknown;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.emitAgentic = emitAgentic;
4
+ exports.assertCanSign = assertCanSign;
5
+ exports.assertOwner = assertOwner;
6
+ exports.sendOwnerCalls = sendOwnerCalls;
7
+ exports.confirmedLogs = confirmedLogs;
8
+ exports.wrapSendError = wrapSendError;
9
+ const tslib_1 = require("tslib");
10
+ const viem_1 = require("viem");
11
+ const errors_1 = require("../../orchestrator/internals/errors");
12
+ const progress_hook_1 = tslib_1.__importDefault(require("../../progress-hook/progress-hook"));
13
+ const errors_2 = require("../errors");
14
+ const revert_1 = require("../revert");
15
+ function emitAgentic(runtime, perCall, id, ...args) {
16
+ runtime.emit(progress_hook_1.default[id](...args), perCall);
17
+ }
18
+ function assertCanSign(runtime, operation) {
19
+ if (runtime.isReadOnly) {
20
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.READ_ONLY, `${operation} needs a signer; this client was initialized read-only`);
21
+ }
22
+ }
23
+ /** Owner-only management writes: the connected signer's Push identity must be the stored owner. */
24
+ async function assertOwner(runtime, gen, wallet, snap) {
25
+ const owner = (0, viem_1.getAddress)(await snap.read(wallet, gen.contracts.abis.wallet, 'owner'));
26
+ const signer = runtime.signerPushAccount();
27
+ if (owner !== signer) {
28
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.NOT_WALLET_OWNER, `${signer} is not the owner of ${wallet} (owner is ${owner})`, { hint: 'Rule and label writes are owner-only. Initialize with the owner signer.' });
29
+ }
30
+ return owner;
31
+ }
32
+ /**
33
+ * Send owner calls through the signer's ordinary transaction path: one call
34
+ * as a plain transaction, several as the signer's batch (UEA multicall,
35
+ * EIP-7702 atomic batch, or the documented sequential fallback for a Push EOA
36
+ * without 7702 — reported through `atomic` / `transactionHashes`).
37
+ */
38
+ async function sendOwnerCalls(runtime, calls, progressHook) {
39
+ if (calls.length === 0)
40
+ throw new Error('sendOwnerCalls needs at least one call');
41
+ const options = progressHook ? { progressHook } : undefined;
42
+ if (calls.length === 1) {
43
+ return runtime.execute({ to: calls[0].to, value: calls[0].value, data: calls[0].data }, options);
44
+ }
45
+ return runtime.execute({ to: calls[0].to, value: BigInt(0), data: calls }, options);
46
+ }
47
+ /**
48
+ * Wait for every Push transaction the operation produced and return their
49
+ * logs in submission order. A reverted transaction raises AgenticRevertError
50
+ * carrying all hashes.
51
+ */
52
+ async function confirmedLogs(runtime, tx) {
53
+ const hashes = (tx.transactionHashes ?? [tx.hash]);
54
+ const unavailable = (cause) => new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.RECEIPT_UNAVAILABLE, `submitted ${tx.hash} but could not read its receipt: ${cause instanceof Error ? cause.message : String(cause)}`, {
55
+ hint: 'The transaction may still land. Check these hashes before retrying.',
56
+ details: { txHash: tx.hash, transactionHashes: hashes },
57
+ cause,
58
+ });
59
+ let receipt;
60
+ try {
61
+ receipt = await tx.wait();
62
+ }
63
+ catch (cause) {
64
+ throw unavailable(cause);
65
+ }
66
+ if (hashes.length === 1) {
67
+ if (receipt.status !== 1) {
68
+ throw new errors_2.AgenticRevertError(`Push transaction ${tx.hash} reverted`, {
69
+ transactionHashes: hashes,
70
+ });
71
+ }
72
+ return { logs: receipt.logs, hashes };
73
+ }
74
+ const logs = [];
75
+ for (const hash of hashes) {
76
+ let r;
77
+ try {
78
+ r = await runtime.reader.getTransactionReceipt({ hash });
79
+ }
80
+ catch (cause) {
81
+ throw unavailable(cause);
82
+ }
83
+ if (r.status !== 'success') {
84
+ throw new errors_2.AgenticRevertError(`Push transaction ${hash} reverted`, { transactionHashes: hashes });
85
+ }
86
+ logs.push(...r.logs);
87
+ }
88
+ return { logs, hashes };
89
+ }
90
+ /** Normalize a send failure: keep batch hashes and decoded revert data. */
91
+ function wrapSendError(err) {
92
+ if (err instanceof errors_2.AgenticError || err instanceof errors_2.AgenticRevertError)
93
+ return err;
94
+ const decoded = (0, revert_1.decodeAgenticRevert)(err);
95
+ if (err instanceof errors_1.PushChainBatchExecutionError) {
96
+ return new errors_2.AgenticRevertError(err.message, {
97
+ decodedError: decoded ?? err.decodedError,
98
+ transactionHashes: err.transactionHashes,
99
+ pendingTransactionHash: err.pendingTransactionHash,
100
+ cause: err,
101
+ });
102
+ }
103
+ if (decoded || err instanceof errors_1.PushChainExecutionError) {
104
+ const e = err;
105
+ return new errors_2.AgenticRevertError(e?.message ?? decoded?.name ?? 'AGW revert', {
106
+ decodedError: decoded ?? e?.decodedError,
107
+ gatewayTxHash: e?.gatewayTxHash,
108
+ agenticCode: decoded?.name,
109
+ cause: err,
110
+ });
111
+ }
112
+ return err;
113
+ }
114
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1,16 @@
1
+ import type { AgenticRuntime } from '../runtime';
2
+ import type { InternalCreateOptions, CreateResult } from '../agentic.types';
3
+ /**
4
+ * client.agentic.create(label, { rules }): deploy + grants only. Funding and
5
+ * approvals are separate ordinary sends. Every input is validated and every
6
+ * prediction re-read immediately before signing; IDs are returned from
7
+ * receipts in input order.
8
+ *
9
+ * Strategy follows the signer: an external owner's UEA batches atomically, a
10
+ * Push EOA uses an EIP-7702 batch when available and otherwise the documented
11
+ * sequential fallback. A sequential failure raises CREATE_PARTIAL with the
12
+ * deployed wallet, confirmed/pending hashes and granted IDs so the caller can
13
+ * finish with `wallet(w).rules.add(remaining)` — the SDK never deploys another
14
+ * wallet on its own.
15
+ */
16
+ export declare function createWallet(runtime: AgenticRuntime, label: string, options: InternalCreateOptions): Promise<CreateResult>;
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createWallet = createWallet;
4
+ const duplicates_1 = require("./duplicates");
5
+ const viem_1 = require("viem");
6
+ const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
7
+ const errors_1 = require("../../orchestrator/internals/errors");
8
+ const capabilities_1 = require("../capabilities");
9
+ const deployments_1 = require("../deployments");
10
+ const ids_1 = require("../codec/ids");
11
+ const prepare_1 = require("./prepare");
12
+ const label_1 = require("./label");
13
+ const errors_2 = require("../errors");
14
+ const snapshot_1 = require("../reads/snapshot");
15
+ const wallets_1 = require("../reads/wallets");
16
+ const common_1 = require("./common");
17
+ /**
18
+ * client.agentic.create(label, { rules }): deploy + grants only. Funding and
19
+ * approvals are separate ordinary sends. Every input is validated and every
20
+ * prediction re-read immediately before signing; IDs are returned from
21
+ * receipts in input order.
22
+ *
23
+ * Strategy follows the signer: an external owner's UEA batches atomically, a
24
+ * Push EOA uses an EIP-7702 batch when available and otherwise the documented
25
+ * sequential fallback. A sequential failure raises CREATE_PARTIAL with the
26
+ * deployed wallet, confirmed/pending hashes and granted IDs so the caller can
27
+ * finish with `wallet(w).rules.add(remaining)` — the SDK never deploys another
28
+ * wallet on its own.
29
+ */
30
+ async function createWallet(runtime, label, options) {
31
+ const hook = options?.progressHook;
32
+ (0, label_1.assertLabel)(label);
33
+ if (!options || !Array.isArray(options.rules)) {
34
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INVALID_RULE, 'options.rules is required (use [] for a bare wallet)');
35
+ }
36
+ (0, common_1.assertCanSign)(runtime, 'agentic.create');
37
+ const gen = (0, deployments_1.currentGeneration)(runtime.network);
38
+ (0, capabilities_1.requireCapability)(gen.capabilities, capabilities_1.AgenticCapability.WALLET_READS);
39
+ await (0, deployments_1.verifyFactoryWiring)(runtime.reader, gen);
40
+ const owner = runtime.signerPushAccount();
41
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
42
+ const index = await (0, wallets_1.walletCount)(snap, gen, owner);
43
+ const [predicted, deployed] = await snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'predictWallet', [owner, index]);
44
+ const wallet = (0, viem_1.getAddress)(predicted);
45
+ const mirror = (0, ids_1.deriveWallet)({
46
+ factory: gen.addresses.factory,
47
+ walletImplementation: gen.addresses.walletImplementation,
48
+ owner,
49
+ index,
50
+ });
51
+ if (wallet !== mirror || deployed || (await snap.code(wallet))) {
52
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `next wallet slot ${index} for ${owner} is not a fresh counterfactual address`, { details: { wallet, mirror, deployed } });
53
+ }
54
+ const prepared = await (0, prepare_1.prepareWalletRules)(runtime, gen, owner, wallet, options.rules, snap);
55
+ (0, duplicates_1.assertNoDuplicateRules)(prepared);
56
+ const selfTarget = prepared.findIndex((p) => p.nativeTerms?.some((t) => t.target === wallet));
57
+ if (selfTarget >= 0) {
58
+ throw new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INVALID_RULE, `rules[${selfTarget}].target is the wallet being created; the contracts refuse it as a native target`);
59
+ }
60
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_101, wallet, Number(index), false);
61
+ // A fresh wallet's grant nonce starts at 0 and increments per grant.
62
+ const predictedIds = prepared.map((p, i) => (0, ids_1.rulesId)({
63
+ validator: gen.addresses.sessionValidator,
64
+ agent: p.agent,
65
+ grantNonce: BigInt(i),
66
+ }));
67
+ const calls = [
68
+ // Index-bound: reverts (nothing committed) if another creation took this slot.
69
+ {
70
+ to: gen.addresses.factory,
71
+ value: BigInt(0),
72
+ data: gen.contracts.encodeDeployWalletAt(owner, index, wallet, label),
73
+ },
74
+ ...prepared.map((p) => ({
75
+ to: wallet,
76
+ value: BigInt(0),
77
+ data: gen.contracts.encodeGrantRules(p.session),
78
+ })),
79
+ ];
80
+ const strategy = calls.length === 1
81
+ ? 'single'
82
+ : runtime.signerIsPushNative()
83
+ ? 'push-eoa-batch'
84
+ : 'uea-multicall';
85
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_102, wallet, strategy);
86
+ let tx;
87
+ try {
88
+ tx = await (0, common_1.sendOwnerCalls)(runtime, calls, hook);
89
+ }
90
+ catch (err) {
91
+ const wrapped = await createFailure(runtime, gen, wallet, Number(index), owner, label, err);
92
+ emitFailure(runtime, hook, wrapped);
93
+ throw wrapped;
94
+ }
95
+ let logs;
96
+ try {
97
+ ({ logs } = await (0, common_1.confirmedLogs)(runtime, tx));
98
+ }
99
+ catch (err) {
100
+ const wrapped = await createFailure(runtime, gen, wallet, Number(index), owner, label, err);
101
+ emitFailure(runtime, hook, wrapped);
102
+ throw wrapped;
103
+ }
104
+ const deployedEv = gen.contracts.parseWalletDeployed(logs, gen.addresses.factory);
105
+ const granted = gen.contracts
106
+ .parseRulesGranted(logs, wallet)
107
+ .map((g) => g.rulesId);
108
+ if (deployedEv.length !== 1 ||
109
+ deployedEv[0].wallet !== wallet ||
110
+ deployedEv[0].index !== index) {
111
+ const err = new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `deployWallet produced ${deployedEv.map((d) => `${d.wallet}#${d.index}`).join(', ') ||
112
+ 'no wallet'}, expected ${wallet}#${index}; grants targeted ${wallet}`, {
113
+ hint: 'Another deployment by this owner raced this call. Inspect both wallets with client.agentic.list() before retrying.',
114
+ details: {
115
+ expected: wallet,
116
+ deployed: deployedEv,
117
+ grantedRulesIds: granted,
118
+ txHash: tx.hash,
119
+ },
120
+ });
121
+ emitFailure(runtime, hook, err);
122
+ throw err;
123
+ }
124
+ if (!sameIds(granted, predictedIds)) {
125
+ const err = new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.RECEIPT_MISMATCH, 'RulesGranted events do not match the requested rules in order', { details: { granted, predicted: predictedIds, txHash: tx.hash } });
126
+ emitFailure(runtime, hook, err);
127
+ throw err;
128
+ }
129
+ if (granted.length > 0)
130
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_104, granted);
131
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_01, 'create', tx.hash);
132
+ return {
133
+ wallet,
134
+ index: Number(index),
135
+ rulesIds: granted,
136
+ tx,
137
+ };
138
+ }
139
+ function sameIds(a, b) {
140
+ return (a.length === b.length &&
141
+ a.every((x, i) => x.toLowerCase() === b[i].toLowerCase()));
142
+ }
143
+ const RACE_ERRORS = new Set(['IndexMismatch', 'IntentWalletMismatch']);
144
+ /**
145
+ * Turn a create failure into an exact report. What committed is derived from
146
+ * THIS operation's own receipts, never from a later state read; when those
147
+ * receipts cannot be fetched the outcome is reported as unknown so callers do
148
+ * not retry a creation that may have landed.
149
+ */
150
+ async function createFailure(runtime, gen, wallet, index, owner, label, err) {
151
+ const wrapped = (0, common_1.wrapSendError)(err);
152
+ const batch = err instanceof errors_1.PushChainBatchExecutionError ? err : undefined;
153
+ const confirmed = (batch?.transactionHashes ?? []);
154
+ const pending = batch?.pendingTransactionHash;
155
+ const receiptUnavailable = wrapped instanceof errors_2.AgenticError &&
156
+ wrapped.code === errors_2.AGENTIC_ERROR_CODE.RECEIPT_UNAVAILABLE;
157
+ // The index-bound deploy reverted: another creation took the slot first and
158
+ // nothing from this call committed.
159
+ const decodedName = wrapped
160
+ .decodedError?.name;
161
+ if (confirmed.length === 0 &&
162
+ !pending &&
163
+ decodedName &&
164
+ RACE_ERRORS.has(decodedName)) {
165
+ return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, `wallet slot ${index} (${wallet}) was taken by a concurrent creation; nothing was committed`, {
166
+ hint: 'Retry agentic.create; it re-reads the next slot.',
167
+ details: { wallet, index, committed: false },
168
+ cause: wrapped,
169
+ });
170
+ }
171
+ if (confirmed.length === 0 && !pending && !receiptUnavailable) {
172
+ // Some send paths flatten the factory revert to a generic execution
173
+ // error, losing the IndexMismatch selector. If the owner's next index has
174
+ // moved and immutable deployment metadata proves another label owns the
175
+ // predicted slot, this call could not have deployed or granted.
176
+ try {
177
+ const snap = await snapshot_1.Snapshot.at(runtime.reader);
178
+ const next = await (0, wallets_1.walletCount)(snap, gen, owner);
179
+ if (next > BigInt(index)) {
180
+ const competing = await (0, wallets_1.walletInfo)(runtime.reader, gen, wallet);
181
+ // label() is mutable in v5: only the immutable deploy event proves
182
+ // which creation occupied this slot. A later rename proves nothing.
183
+ const logs = await (0, snapshot_1.scanLogs)(runtime.reader, {
184
+ address: gen.addresses.factory,
185
+ event: gen.contracts.events.walletDeployed,
186
+ args: { wallet },
187
+ }, gen.startBlock, snap.blockNumber);
188
+ const deployed = gen.contracts
189
+ .parseWalletDeployed(logs, gen.addresses.factory)
190
+ .find((entry) => entry.wallet === wallet);
191
+ const competingLabel = deployed?.label;
192
+ if (competing.deployed &&
193
+ competing.index === index &&
194
+ (0, viem_1.getAddress)(competing.owner) === owner &&
195
+ competingLabel !== undefined &&
196
+ competingLabel !== label) {
197
+ return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.INDEX_RACE, 'wallet slot ' + index + ' was consumed by a concurrent deployment', {
198
+ hint: 'Slot ' +
199
+ index +
200
+ ' belongs to "' +
201
+ competingLabel +
202
+ '". No wallet or rules from this create call were committed; retry agentic.create to use the next slot.',
203
+ details: {
204
+ wallet,
205
+ index,
206
+ committed: false,
207
+ competingLabel,
208
+ },
209
+ cause: wrapped,
210
+ });
211
+ }
212
+ }
213
+ }
214
+ catch {
215
+ // If the owner counter/event cannot be reconciled, preserve the original
216
+ // error; never infer that a retry is safe from an incomplete read.
217
+ }
218
+ // Nothing was confirmed (pre-broadcast failure or a reverted atomic batch).
219
+ return wrapped;
220
+ }
221
+ let walletDeployed = 'unknown';
222
+ let grantedRulesIds;
223
+ let recoveryError;
224
+ if (!receiptUnavailable) {
225
+ try {
226
+ const logs = [];
227
+ for (const hash of confirmed) {
228
+ const r = await runtime.reader.getTransactionReceipt({ hash });
229
+ if (r.status === 'success')
230
+ logs.push(...r.logs);
231
+ }
232
+ const deployed = gen.contracts
233
+ .parseWalletDeployed(logs, gen.addresses.factory)
234
+ .some((d) => d.wallet === wallet);
235
+ grantedRulesIds = gen.contracts
236
+ .parseRulesGranted(logs, wallet)
237
+ .map((g) => g.rulesId);
238
+ // A pending hash may itself be the deployment; only a confirmed deploy is certain.
239
+ walletDeployed = deployed ? true : pending ? 'unknown' : false;
240
+ }
241
+ catch (e) {
242
+ recoveryError = e instanceof Error ? e.message : String(e);
243
+ }
244
+ }
245
+ const hint = walletDeployed === true
246
+ ? `Wallet ${wallet} is deployed. Do not call create again; once any pending hash settles, finish with client.agentic.wallet('${wallet}').rules.add(<remaining rules>).`
247
+ : walletDeployed === false
248
+ ? 'No wallet was deployed by this call; it is safe to retry.'
249
+ : 'The outcome is unknown. Do not retry create until the listed hashes are reconciled (client.agentic.list() shows deployed wallets).';
250
+ return new errors_2.AgenticError(errors_2.AGENTIC_ERROR_CODE.CREATE_PARTIAL, `agentic.create did not complete: ${wrapped?.message ?? String(err)}`, {
251
+ hint,
252
+ details: {
253
+ wallet,
254
+ index,
255
+ walletDeployed,
256
+ grantedRulesIds,
257
+ confirmedHashes: confirmed,
258
+ pendingHash: pending,
259
+ ...(receiptUnavailable
260
+ ? { submitted: wrapped.details }
261
+ : {}),
262
+ ...(recoveryError ? { recoveryError } : {}),
263
+ },
264
+ cause: wrapped,
265
+ });
266
+ }
267
+ function emitFailure(runtime, hook, err) {
268
+ const e = err;
269
+ (0, common_1.emitAgentic)(runtime, hook, progress_hook_types_1.PROGRESS_HOOK.AGENTIC_TX_199_02, 'create', e?.code ?? 'UNKNOWN', e?.message ?? String(err), e?.decodedError);
270
+ }
271
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1,4 @@
1
+ import type { PreparedRule } from '../codec/rules';
2
+ import type { ActiveRule } from '../reads/rules';
3
+ /** SDK creation policy; existing contract overlaps still use AMBIGUOUS_RULE at send. */
4
+ export declare function assertNoDuplicateRules(prepared: readonly PreparedRule[], existing?: readonly ActiveRule[]): void;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertNoDuplicateRules = assertNoDuplicateRules;
4
+ const viem_1 = require("viem");
5
+ const rules_1 = require("../codec/rules");
6
+ const errors_1 = require("../errors");
7
+ /** SDK creation policy; existing contract overlaps still use AMBIGUOUS_RULE at send. */
8
+ function assertNoDuplicateRules(prepared, existing = []) {
9
+ const keys = new Set(existing.map((r) => `${(0, viem_1.getAddress)(r.agent)}:${r.chainHash}`));
10
+ for (const rule of prepared) {
11
+ const key = `${(0, viem_1.getAddress)(rule.agent)}:${(0, rules_1.chainHash)(rule.chainNamespace)}`;
12
+ if (keys.has(key))
13
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.DUPLICATE_RULE, `an enabled rule already names ${rule.agent} for ${rule.chainNamespace}`, {
14
+ hint: 'Put multiple allowed calls in one rule or update the existing rule.',
15
+ details: { agent: rule.agent, chainNamespace: rule.chainNamespace },
16
+ });
17
+ keys.add(key);
18
+ }
19
+ }
20
+ //# sourceMappingURL=duplicates.js.map
@@ -0,0 +1,3 @@
1
+ /** AGW MAX_LABEL_BYTES. Empty resets the default; lengths count UTF-8 bytes. */
2
+ export declare const MAX_LABEL_BYTES = 64;
3
+ export declare function assertLabel(label: string): void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAX_LABEL_BYTES = void 0;
4
+ exports.assertLabel = assertLabel;
5
+ const errors_1 = require("../errors");
6
+ /** AGW MAX_LABEL_BYTES. Empty resets the default; lengths count UTF-8 bytes. */
7
+ exports.MAX_LABEL_BYTES = 64;
8
+ function assertLabel(label) {
9
+ if (typeof label !== 'string') {
10
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'label must be a string');
11
+ }
12
+ const length = new TextEncoder().encode(label).length;
13
+ if (length > exports.MAX_LABEL_BYTES) {
14
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `label must be at most ${exports.MAX_LABEL_BYTES} UTF-8 bytes (received ${length})`, { details: { length, maxLength: exports.MAX_LABEL_BYTES } });
15
+ }
16
+ }
17
+ //# sourceMappingURL=label.js.map
@@ -0,0 +1,7 @@
1
+ import { type Address } from 'viem';
2
+ import { type AgenticGeneration } from '../deployments';
3
+ import type { InternalRule } from '../agentic.types';
4
+ import type { AgenticRuntime } from '../runtime';
5
+ import { Snapshot } from '../reads/snapshot';
6
+ /** Resolve wallet-dependent wire inputs without signing or mutating authority. */
7
+ export declare function prepareWalletRules(runtime: AgenticRuntime, gen: AgenticGeneration, owner: Address, wallet: Address, inputs: readonly InternalRule[], snap: Snapshot): Promise<import("../codec/rules").PreparedRule[]>;