@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,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.walletCount = walletCount;
4
+ exports.deriveForOwner = deriveForOwner;
5
+ exports.rulesCount = rulesCount;
6
+ exports.listForOwner = listForOwner;
7
+ exports.walletOwner = walletOwner;
8
+ exports.walletInfo = walletInfo;
9
+ const viem_1 = require("viem");
10
+ const ids_1 = require("../codec/ids");
11
+ const errors_1 = require("../errors");
12
+ const snapshot_1 = require("./snapshot");
13
+ /** Factory-predicted address for (owner, index), cross-checked against the pure mirror. */
14
+ async function predict(snap, gen, owner, index) {
15
+ const [address, deployed] = await snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'predictWallet', [owner, index]);
16
+ const mirror = (0, ids_1.deriveWallet)({
17
+ factory: gen.addresses.factory,
18
+ walletImplementation: gen.addresses.walletImplementation,
19
+ owner,
20
+ index,
21
+ });
22
+ if ((0, viem_1.getAddress)(address) !== mirror) {
23
+ // Derivation drift between the SDK mirror and the factory (obligation 13).
24
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INCONSISTENT_READ, `factory predicted ${address} for (${owner}, ${index}) but the SDK derives ${mirror}`, { details: { generation: gen.id } });
25
+ }
26
+ return { address: (0, viem_1.getAddress)(address), deployed };
27
+ }
28
+ async function walletCount(snap, gen, owner) {
29
+ return BigInt(await snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'walletCount', [owner]));
30
+ }
31
+ /** client.agentic.derive: default index is the owner's next unused slot. */
32
+ async function deriveForOwner(reader, gen, owner, index) {
33
+ const snap = await snapshot_1.Snapshot.at(reader);
34
+ const next = await walletCount(snap, gen, owner);
35
+ let target = next;
36
+ if (index !== undefined) {
37
+ if (!Number.isInteger(index) || index < 0) {
38
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, 'index must be a non-negative integer');
39
+ }
40
+ target = BigInt(index);
41
+ if (target > next) {
42
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INVALID_RULE, `index ${index} is beyond the owner's next unused index ${next}; the factory only predicts up to the next slot`);
43
+ }
44
+ }
45
+ const p = await predict(snap, gen, owner, target);
46
+ return { address: p.address, index: Number(target), deployed: p.deployed };
47
+ }
48
+ async function rulesCount(snap, gen, wallet) {
49
+ const ids = await snap.read(gen.addresses.sessionEngine, gen.contracts.abis.engine, 'getPermissionIDs', [wallet]);
50
+ return ids.length;
51
+ }
52
+ /**
53
+ * client.agentic.list: every deployed slot plus the next undeployed slot
54
+ * (deployed=false, rulesCount=0), as in the spec example.
55
+ */
56
+ async function listForOwner(reader, gen, owner) {
57
+ const snap = await snapshot_1.Snapshot.at(reader);
58
+ const count = await walletCount(snap, gen, owner);
59
+ const out = [];
60
+ for (let i = BigInt(0); i <= count; i++) {
61
+ const p = await predict(snap, gen, owner, i);
62
+ const deployed = i < count;
63
+ if (deployed !== p.deployed) {
64
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.INCONSISTENT_READ, `factory reports slot ${i} deployed=${p.deployed} but walletCount is ${count}`);
65
+ }
66
+ const label = deployed
67
+ ? await snap.read(p.address, gen.contracts.abis.wallet, 'label')
68
+ : '';
69
+ out.push({
70
+ address: p.address,
71
+ index: Number(i),
72
+ label,
73
+ deployed,
74
+ rulesCount: deployed ? await rulesCount(snap, gen, p.address) : 0,
75
+ });
76
+ }
77
+ return out;
78
+ }
79
+ /** w.owner(): the owner as the wallet stores it. */
80
+ async function walletOwner(reader, gen, wallet) {
81
+ const snap = await snapshot_1.Snapshot.at(reader);
82
+ return (0, viem_1.getAddress)(await snap.read(wallet, gen.contracts.abis.wallet, 'owner'));
83
+ }
84
+ /**
85
+ * w.info(). A deployed wallet is read from chain. An undeployed address is
86
+ * only describable when it is `signerIdentity`'s next predicted slot.
87
+ */
88
+ async function walletInfo(reader, gen, wallet, signerIdentity) {
89
+ const snap = await snapshot_1.Snapshot.at(reader);
90
+ const deployed = await snap.code(wallet);
91
+ if (!deployed) {
92
+ if (signerIdentity) {
93
+ const next = await walletCount(snap, gen, signerIdentity);
94
+ const p = await predict(snap, gen, signerIdentity, next);
95
+ if (p.address === (0, viem_1.getAddress)(wallet)) {
96
+ return {
97
+ address: p.address,
98
+ label: '',
99
+ index: Number(next),
100
+ owner: (0, viem_1.getAddress)(signerIdentity),
101
+ deployed: false,
102
+ rulesCount: 0,
103
+ };
104
+ }
105
+ }
106
+ throw new errors_1.AgenticError(errors_1.AGENTIC_ERROR_CODE.WALLET_NOT_DEPLOYED, `${wallet} is not deployed and is not the connected owner's next wallet slot`);
107
+ }
108
+ const [owner, index] = await Promise.all([
109
+ snap.read(wallet, gen.contracts.abis.wallet, 'owner'),
110
+ snap.read(gen.addresses.factory, gen.contracts.abis.factory, 'indexOf', [wallet]),
111
+ ]);
112
+ const label = await snap.read(wallet, gen.contracts.abis.wallet, 'label');
113
+ return {
114
+ address: (0, viem_1.getAddress)(wallet),
115
+ label,
116
+ index: Number(index),
117
+ owner: (0, viem_1.getAddress)(owner),
118
+ deployed: true,
119
+ rulesCount: await rulesCount(snap, gen, wallet),
120
+ };
121
+ }
122
+ //# sourceMappingURL=wallets.js.map
@@ -0,0 +1,41 @@
1
+ import { type Address, type Hex } from 'viem';
2
+ import { CHAIN } from '../constants/enums';
3
+ import type { TransactionRouteType, UniversalTxResponse } from '../orchestrator/orchestrator.types';
4
+ import type { AgenticRuntime } from './runtime';
5
+ import type { AgenticTxMetadata } from './agentic.types';
6
+ export interface LogicalCall {
7
+ to: string;
8
+ data: string;
9
+ value: bigint;
10
+ }
11
+ /**
12
+ * Present an AGW send as the wallet's own transaction: `from` is the AGW and
13
+ * `to`/`data`/`value` are the logical call. The signer's `origin`, hashes,
14
+ * nonce, gas and the on-chain `raw` fields are kept untouched; the wrapped
15
+ * call the signer actually sent is recorded in `agentic.rawTo/rawData`.
16
+ * Mutates in place so `wait()` (which reads these fields) reports the same
17
+ * identity on the receipt.
18
+ */
19
+ export declare function adaptAgenticResponse(resp: UniversalTxResponse, meta: Omit<AgenticTxMetadata, 'rawTo' | 'rawData'> & {
20
+ logical: LogicalCall;
21
+ route?: TransactionRouteType;
22
+ chain?: CHAIN;
23
+ }): UniversalTxResponse;
24
+ /**
25
+ * trackTransaction replay: if the tracked Push tx called execute/executeAsAgent
26
+ * on a wallet of a registered, verified generation, restore the same logical
27
+ * identity a live send reports. Anything unrecognised is returned unchanged.
28
+ */
29
+ export declare function adaptTrackedResponse(runtime: Pick<AgenticRuntime, 'reader' | 'network'>, resp: UniversalTxResponse): Promise<UniversalTxResponse>;
30
+ /**
31
+ * Canonical outbound summary for both send and replay: the first actual
32
+ * destination call. The complete ordered calls live in agentic.destinationCalls.
33
+ * Identical calldata can come from explicit calls or generated transfers, so
34
+ * never infer the original input shape from a selector. For an unrecognized
35
+ * historical payload, retain the actual gateway call instead of inventing one.
36
+ */
37
+ export declare function outboundResponseCall(calls: readonly {
38
+ to: Address;
39
+ value: bigint;
40
+ data: Hex;
41
+ }[], fallback: LogicalCall): LogicalCall;
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.adaptAgenticResponse = adaptAgenticResponse;
4
+ exports.adaptTrackedResponse = adaptTrackedResponse;
5
+ exports.outboundResponseCall = outboundResponseCall;
6
+ const snapshot_1 = require("./reads/snapshot");
7
+ const prc20_metadata_1 = require("./contracts/prc20-metadata");
8
+ const svm_payload_1 = require("./execution/svm-payload");
9
+ const svm_accounts_1 = require("./codec/svm-accounts");
10
+ const chain_1 = require("../constants/chain");
11
+ const viem_1 = require("viem");
12
+ const viem_2 = require("viem");
13
+ const chain_2 = require("../constants/chain");
14
+ const helpers_1 = require("../orchestrator/internals/helpers");
15
+ const account_1 = require("../universal/account/account");
16
+ const chain_3 = require("./chain");
17
+ const abi_1 = require("../constants/abi");
18
+ const v6_1 = require("./contracts/v6");
19
+ const deployments_1 = require("./deployments");
20
+ /**
21
+ * Present an AGW send as the wallet's own transaction: `from` is the AGW and
22
+ * `to`/`data`/`value` are the logical call. The signer's `origin`, hashes,
23
+ * nonce, gas and the on-chain `raw` fields are kept untouched; the wrapped
24
+ * call the signer actually sent is recorded in `agentic.rawTo/rawData`.
25
+ * Mutates in place so `wait()` (which reads these fields) reports the same
26
+ * identity on the receipt.
27
+ */
28
+ function adaptAgenticResponse(resp, meta) {
29
+ const rawTo = resp.to;
30
+ const rawData = resp.data;
31
+ if (!resp.raw) {
32
+ resp.raw = {
33
+ from: resp.from,
34
+ to: resp.to,
35
+ nonce: resp.nonce,
36
+ data: resp.data,
37
+ value: resp.value,
38
+ };
39
+ }
40
+ resp.from = (0, viem_2.getAddress)(meta.wallet);
41
+ resp.to = meta.logical.to;
42
+ resp.data = meta.logical.data;
43
+ resp.value = meta.logical.value;
44
+ if (meta.route)
45
+ resp.route = meta.route;
46
+ if (meta.chain) {
47
+ resp.chain = meta.chain;
48
+ resp.chainNamespace = meta.chain;
49
+ }
50
+ resp.agentic = {
51
+ wallet: (0, viem_2.getAddress)(meta.wallet),
52
+ door: meta.door,
53
+ ...(meta.rulesId ? { rulesId: meta.rulesId } : {}),
54
+ ...(meta.chainNamespace ? { chainNamespace: meta.chainNamespace } : {}),
55
+ ...(meta.destinationAccount
56
+ ? { destinationAccount: meta.destinationAccount }
57
+ : {}),
58
+ ...(meta.destinationCalls
59
+ ? { destinationCalls: meta.destinationCalls.map((call) => ({ ...call })) }
60
+ : {}),
61
+ ...(meta.destinationInstruction
62
+ ? { destinationInstruction: meta.destinationInstruction }
63
+ : {}),
64
+ ...(meta.destinationTransfer
65
+ ? { destinationTransfer: { ...meta.destinationTransfer } }
66
+ : {}),
67
+ ...(meta.nativeCalls
68
+ ? { nativeCalls: meta.nativeCalls.map((call) => ({ ...call })) }
69
+ : {}),
70
+ rawTo,
71
+ rawData,
72
+ };
73
+ return resp;
74
+ }
75
+ /**
76
+ * trackTransaction replay: if the tracked Push tx called execute/executeAsAgent
77
+ * on a wallet of a registered, verified generation, restore the same logical
78
+ * identity a live send reports. Anything unrecognised is returned unchanged.
79
+ */
80
+ async function adaptTrackedResponse(runtime, resp) {
81
+ if (resp.agentic || (0, deployments_1.generationsFor)(runtime.network).length === 0)
82
+ return resp;
83
+ const batch = await adaptNativeAgentBatch(runtime, resp);
84
+ if (batch)
85
+ return batch;
86
+ const decoded = v6_1.v6.decodeWalletCall(resp.data);
87
+ if (!decoded ||
88
+ (decoded.kind !== 'execute' && decoded.kind !== 'executeAsAgent'))
89
+ return resp;
90
+ let wallet;
91
+ try {
92
+ wallet = (0, viem_2.getAddress)(resp.to);
93
+ }
94
+ catch {
95
+ return resp;
96
+ }
97
+ let gen;
98
+ try {
99
+ gen = await (0, deployments_1.resolveWalletGeneration)(runtime.reader, runtime.network, wallet);
100
+ }
101
+ catch {
102
+ return resp;
103
+ }
104
+ const door = decoded.kind === 'execute' ? 'owner' : 'agent';
105
+ const rulesId = decoded.kind === 'executeAsAgent'
106
+ ? decoded.rulesId
107
+ : undefined;
108
+ const calls = decoded.calls;
109
+ const outbound = calls.find((c) => (0, viem_2.getAddress)(c.target) === gen.addresses.gateway &&
110
+ c.data.toLowerCase().startsWith(v6_1.SEND_OUTBOUND_SELECTOR));
111
+ if (outbound) {
112
+ const out = decodeOutbound(outbound.data);
113
+ const chain = await tokenChain(runtime, out.token);
114
+ if (chain?.startsWith('solana:')) {
115
+ if (door === 'owner' &&
116
+ out.payload === '0x' &&
117
+ out.amount > BigInt(0) &&
118
+ /^0x[0-9a-fA-F]{64}$/.test(out.recipient)) {
119
+ try {
120
+ const gas = await (0, prc20_metadata_1.readGasPrc20)(new snapshot_1.Snapshot(runtime.reader, resp.blockNumber), chain);
121
+ return adaptAgenticResponse(resp, {
122
+ wallet,
123
+ door,
124
+ chainNamespace: chain,
125
+ chain: chain,
126
+ route: 'UOA_TO_CEA',
127
+ destinationTransfer: {
128
+ recipient: out.recipient,
129
+ token: out.token,
130
+ amount: out.amount,
131
+ },
132
+ logical: {
133
+ to: out.recipient,
134
+ data: '0x',
135
+ value: (0, viem_2.getAddress)(gas) === out.token ? out.amount : BigInt(0),
136
+ },
137
+ });
138
+ }
139
+ catch {
140
+ // Preserve the actual gateway summary when historical token metadata
141
+ // cannot be read; destination polling below still uses the known chain.
142
+ }
143
+ }
144
+ try {
145
+ const instruction = (0, svm_payload_1.parseAgwSvmPayload)(out.payload);
146
+ const destinationInstruction = {
147
+ program: instruction.program,
148
+ accounts: instruction.accounts.map(({ pubkey, isWritable }) => ({
149
+ pubkey,
150
+ isWritable,
151
+ })),
152
+ data: (0, viem_1.bytesToHex)(instruction.instructionData),
153
+ };
154
+ return adaptAgenticResponse(resp, {
155
+ wallet,
156
+ door,
157
+ rulesId,
158
+ chainNamespace: chain,
159
+ chain: chain,
160
+ route: 'UOA_TO_CEA',
161
+ destinationInstruction,
162
+ destinationAccount: (0, svm_accounts_1.deriveAgwSvmCea)(wallet, chain_1.CHAIN_INFO[chain].lockerContract ?? '').address,
163
+ logical: {
164
+ to: instruction.program,
165
+ data: destinationInstruction.data,
166
+ value: BigInt(0),
167
+ },
168
+ });
169
+ }
170
+ catch {
171
+ // Historical owner calls may use another payload format. Preserve the
172
+ // actual gateway call below instead of inventing instruction metadata.
173
+ }
174
+ }
175
+ // The decoded wallet call is authoritative: core may have inferred a
176
+ // Push-only route from an incomplete Cosmos record, which would stop
177
+ // wait() from polling the destination leg.
178
+ return adaptAgenticResponse(resp, {
179
+ wallet,
180
+ door,
181
+ rulesId,
182
+ chainNamespace: chain,
183
+ logical: outboundResponseCall(out.calls, {
184
+ to: outbound.target,
185
+ data: outbound.data,
186
+ value: outbound.value,
187
+ }),
188
+ ...(out.calls.length > 0 ? { destinationCalls: out.calls } : {}),
189
+ route: 'UOA_TO_CEA',
190
+ chain: chain ?? resp.chain,
191
+ });
192
+ }
193
+ const single = calls.length === 1 ? calls[0] : undefined;
194
+ return adaptAgenticResponse(resp, {
195
+ wallet,
196
+ door,
197
+ rulesId,
198
+ chainNamespace: undefined,
199
+ logical: single
200
+ ? { to: single.target, data: single.data, value: single.value }
201
+ : { to: wallet, data: resp.data, value: BigInt(0) },
202
+ });
203
+ }
204
+ /** Decode only supported sender-account batches, never an arbitrary forwarding helper. */
205
+ async function adaptNativeAgentBatch(runtime, resp) {
206
+ let outer;
207
+ const isUea = resp.data.toLowerCase().startsWith(v6_1.UEA_MULTICALL_PREFIX);
208
+ try {
209
+ if (isUea) {
210
+ const [entries] = (0, viem_2.decodeAbiParameters)([
211
+ {
212
+ type: 'tuple[]',
213
+ components: [
214
+ { name: 'to', type: 'address' },
215
+ { name: 'value', type: 'uint256' },
216
+ { name: 'data', type: 'bytes' },
217
+ ],
218
+ },
219
+ ], `0x${resp.data.slice(10)}`);
220
+ outer = entries.map((c) => ({
221
+ target: (0, viem_2.getAddress)(c.to),
222
+ value: c.value,
223
+ data: c.data,
224
+ }));
225
+ }
226
+ else {
227
+ const batch = v6_1.v6.decodeWalletCall(resp.data);
228
+ if (batch?.kind !== 'execute' || batch.mode !== `0x01${'00'.repeat(31)}`)
229
+ return;
230
+ outer = batch.calls;
231
+ }
232
+ if (outer.length < 2 ||
233
+ outer.some((c) => c.value !== BigInt(0) || c.target !== outer[0].target))
234
+ return;
235
+ const inner = outer.map((c) => v6_1.v6.decodeWalletCall(c.data));
236
+ const first = inner[0];
237
+ if (first?.kind !== 'executeAsAgent' || first.calls.length !== 1)
238
+ return;
239
+ const nativeCalls = [];
240
+ for (const c of inner) {
241
+ if (c?.kind !== 'executeAsAgent' ||
242
+ c.calls.length !== 1 ||
243
+ c.rulesId !== first.rulesId ||
244
+ c.mode !== `0x${'00'.repeat(32)}`)
245
+ return;
246
+ const call = c.calls[0];
247
+ nativeCalls.push({ to: call.target, value: call.value, data: call.data });
248
+ }
249
+ const senderAccount = (0, viem_2.getAddress)(resp.from);
250
+ if (isUea) {
251
+ if ((0, viem_2.getAddress)(resp.raw?.to ?? resp.to) !== senderAccount)
252
+ return;
253
+ const origin = await (0, account_1.convertExecutorToOrigin)(senderAccount, {
254
+ _internal: true,
255
+ });
256
+ if (!origin.exists)
257
+ return;
258
+ }
259
+ else {
260
+ if ((0, viem_2.getAddress)(resp.to) !== senderAccount)
261
+ return;
262
+ const executor = (0, chain_2.getBatchExecutorAddress)((0, helpers_1.getPushChainForNetwork)(runtime.network));
263
+ if (!executor)
264
+ return;
265
+ const code = await runtime.reader.getCode({
266
+ address: senderAccount,
267
+ blockNumber: resp.blockNumber,
268
+ });
269
+ if (code?.toLowerCase() !== `0xef0100${executor.slice(2).toLowerCase()}`)
270
+ return;
271
+ }
272
+ const wallet = outer[0].target;
273
+ const gen = await (0, deployments_1.resolveWalletGeneration)(runtime.reader, runtime.network, wallet);
274
+ // This recognizer is only for native arrays; keep mixed/outbound batches raw.
275
+ if (nativeCalls.some((c) => c.to === gen.addresses.gateway))
276
+ return;
277
+ return adaptAgenticResponse(resp, {
278
+ wallet,
279
+ door: 'agent',
280
+ rulesId: first.rulesId,
281
+ chainNamespace: (0, chain_3.pushChainNamespaceFor)(runtime.network),
282
+ nativeCalls,
283
+ logical: { ...nativeCalls[0] },
284
+ });
285
+ }
286
+ catch {
287
+ // Unsupported payload or unverified sender/wallet: preserve the original response.
288
+ return;
289
+ }
290
+ }
291
+ /**
292
+ * Canonical outbound summary for both send and replay: the first actual
293
+ * destination call. The complete ordered calls live in agentic.destinationCalls.
294
+ * Identical calldata can come from explicit calls or generated transfers, so
295
+ * never infer the original input shape from a selector. For an unrecognized
296
+ * historical payload, retain the actual gateway call instead of inventing one.
297
+ */
298
+ function outboundResponseCall(calls, fallback) {
299
+ const first = calls[0];
300
+ return first
301
+ ? { to: first.to, data: first.data, value: first.value }
302
+ : fallback;
303
+ }
304
+ function decodeOutbound(data) {
305
+ const { args } = (0, viem_2.decodeFunctionData)({ abi: abi_1.UNIVERSAL_GATEWAY_PC, data });
306
+ const req = args?.[0];
307
+ let calls = [];
308
+ if (req.payload.toLowerCase().startsWith(v6_1.UEA_MULTICALL_PREFIX)) {
309
+ try {
310
+ const [decodedCalls] = (0, viem_2.decodeAbiParameters)([
311
+ {
312
+ type: 'tuple[]',
313
+ components: [
314
+ { name: 'to', type: 'address' },
315
+ { name: 'value', type: 'uint256' },
316
+ { name: 'data', type: 'bytes' },
317
+ ],
318
+ },
319
+ ], `0x${req.payload.slice(10)}`);
320
+ calls = decodedCalls.map((c) => ({
321
+ to: (0, viem_2.getAddress)(c.to),
322
+ value: c.value,
323
+ data: c.data,
324
+ }));
325
+ }
326
+ catch {
327
+ calls = [];
328
+ }
329
+ }
330
+ return {
331
+ token: (0, viem_2.getAddress)(req.token),
332
+ payload: req.payload,
333
+ recipient: req.recipient,
334
+ amount: req.amount,
335
+ calls,
336
+ };
337
+ }
338
+ async function tokenChain(runtime, token) {
339
+ try {
340
+ return (await runtime.reader.readContract({
341
+ address: token,
342
+ abi: [
343
+ {
344
+ type: 'function',
345
+ name: 'SOURCE_CHAIN_NAMESPACE',
346
+ inputs: [],
347
+ outputs: [{ type: 'string' }],
348
+ stateMutability: 'view',
349
+ },
350
+ ],
351
+ functionName: 'SOURCE_CHAIN_NAMESPACE',
352
+ }));
353
+ }
354
+ catch {
355
+ return undefined;
356
+ }
357
+ }
358
+ //# sourceMappingURL=response.js.map
@@ -0,0 +1,7 @@
1
+ import { type Hex } from 'viem';
2
+ import type { DecodedErrorPayload } from '../orchestrator/internals/errors';
3
+ /** URP reverts reached through the engine are truncated to this wrapper. */
4
+ export declare const POLICY_CHECK_REVERTED_SELECTOR = "0xf4270752";
5
+ /** Decode raw revert data against the AGW/URP/factory/engine error ABIs. */
6
+ export declare function decodeAgwErrorData(data: Hex): DecodedErrorPayload | undefined;
7
+ export declare function decodeAgenticRevert(err: unknown): DecodedErrorPayload | undefined;
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.POLICY_CHECK_REVERTED_SELECTOR = void 0;
4
+ exports.decodeAgwErrorData = decodeAgwErrorData;
5
+ exports.decodeAgenticRevert = decodeAgenticRevert;
6
+ const viem_1 = require("viem");
7
+ const utils_1 = require("viem/utils");
8
+ const v6_1 = require("./contracts/abi/v6");
9
+ /** URP reverts reached through the engine are truncated to this wrapper. */
10
+ exports.POLICY_CHECK_REVERTED_SELECTOR = '0xf4270752';
11
+ const ERROR_ABIS = [
12
+ v6_1.AGW_ABI,
13
+ v6_1.UNIVERSAL_RULES_POLICY_ABI,
14
+ v6_1.AGW_FACTORY_ABI,
15
+ v6_1.SMART_SESSION_ABI,
16
+ ];
17
+ /** selector → error name across the AGW/URP/factory/engine ABIs. */
18
+ const ERROR_NAMES = new Map(ERROR_ABIS.flatMap((abi) => abi
19
+ .filter((item) => item.type === 'error')
20
+ .map((item) => {
21
+ const err = item;
22
+ return [
23
+ (0, viem_1.toFunctionSelector)((0, utils_1.formatAbiItem)(err)).toLowerCase(),
24
+ err.name,
25
+ ];
26
+ })));
27
+ const HEX_DATA = /0x[0-9a-fA-F]{8,}/g;
28
+ const CUSTOM_ERROR_TEXT = /custom error (0x[0-9a-fA-F]{8}):?\s*([0-9a-fA-F]*)/g;
29
+ /** Pull candidate revert data out of an error (viem chains, nested causes, messages). */
30
+ function revertDataCandidates(err, depth = 0) {
31
+ if (!err || depth > 6)
32
+ return [];
33
+ const out = [];
34
+ const e = err;
35
+ if (typeof e.raw === 'string' && /^0x[0-9a-fA-F]{8,}$/.test(e.raw))
36
+ out.push(e.raw);
37
+ if (typeof e.data === 'string' && /^0x[0-9a-fA-F]{8,}$/.test(e.data))
38
+ out.push(e.data);
39
+ if (e.data &&
40
+ typeof e.data === 'object' &&
41
+ typeof e.data.data === 'string') {
42
+ out.push(e.data.data);
43
+ }
44
+ for (const text of [e.message, e.details]) {
45
+ if (typeof text !== 'string')
46
+ continue;
47
+ // viem renders unknown custom errors as "custom error 0x<selector>: <args hex>".
48
+ for (const m of text.matchAll(CUSTOM_ERROR_TEXT))
49
+ out.push(`${m[1]}${m[2] ?? ''}`);
50
+ out.push(...(text.match(HEX_DATA) ?? []));
51
+ }
52
+ out.push(...revertDataCandidates(e.cause, depth + 1));
53
+ return out;
54
+ }
55
+ /** Decode raw revert data against the AGW/URP/factory/engine error ABIs. */
56
+ function decodeAgwErrorData(data) {
57
+ const selector = data.slice(0, 10).toLowerCase();
58
+ if (selector === exports.POLICY_CHECK_REVERTED_SELECTOR && data.length >= 10 + 64) {
59
+ // bytes32 = 4-byte policy error selector ‖ 28 bytes of its first argument.
60
+ // The arguments are truncated, so the inner error is named by selector only.
61
+ const word = `0x${data.slice(10, 74)}`;
62
+ const innerName = ERROR_NAMES.get(word.slice(0, 10).toLowerCase());
63
+ return {
64
+ name: innerName
65
+ ? `PolicyCheckReverted(${innerName})`
66
+ : 'PolicyCheckReverted',
67
+ selector,
68
+ decoded: word,
69
+ hint: 'URP rejected the action (truncated through the session engine). The inner selector names the gate; arguments are truncated to 28 bytes.',
70
+ };
71
+ }
72
+ for (const abi of ERROR_ABIS) {
73
+ try {
74
+ const r = (0, viem_1.decodeErrorResult)({ abi, data });
75
+ return {
76
+ name: r.errorName,
77
+ selector,
78
+ decoded: r.args && r.args.length ? stringifyArgs(r.args) : undefined,
79
+ };
80
+ }
81
+ catch {
82
+ // try the next ABI
83
+ }
84
+ }
85
+ // Arguments lost (e.g. a node rendered them as text): name the error by its selector.
86
+ const name = ERROR_NAMES.get(selector);
87
+ return name
88
+ ? { name, selector, hint: 'Error arguments were not available.' }
89
+ : undefined;
90
+ }
91
+ function decodeAgenticRevert(err) {
92
+ for (const data of revertDataCandidates(err)) {
93
+ const decoded = decodeAgwErrorData(data);
94
+ if (decoded)
95
+ return decoded;
96
+ }
97
+ return undefined;
98
+ }
99
+ function stringifyArgs(args) {
100
+ return JSON.stringify(args, (_k, v) => typeof v === 'bigint' ? v.toString() : v);
101
+ }
102
+ //# sourceMappingURL=revert.js.map