@pushchain/core 6.0.26 → 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 (169) hide show
  1. package/AGW.md +194 -0
  2. package/CHANGELOG.md +8 -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/enums.d.ts +6 -3
  134. package/src/lib/constants/enums.js +6 -3
  135. package/src/lib/constants/index.d.ts +60 -4
  136. package/src/lib/constants/index.js +17 -3
  137. package/src/lib/constants/read-state.d.ts +9 -0
  138. package/src/lib/constants/read-state.js +13 -1
  139. package/src/lib/index.d.ts +8 -2
  140. package/src/lib/index.js +9 -1
  141. package/src/lib/orchestrator/internals/errors.d.ts +7 -0
  142. package/src/lib/orchestrator/internals/errors.js +13 -1
  143. package/src/lib/orchestrator/internals/execute-standard.d.ts +3 -1
  144. package/src/lib/orchestrator/internals/execute-standard.js +3 -3
  145. package/src/lib/orchestrator/internals/outbound-sync.js +52 -7
  146. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +1 -1
  147. package/src/lib/orchestrator/internals/push-chain-tx.js +13 -1
  148. package/src/lib/orchestrator/orchestrator.d.ts +3 -0
  149. package/src/lib/orchestrator/orchestrator.js +13 -1
  150. package/src/lib/orchestrator/orchestrator.types.d.ts +8 -0
  151. package/src/lib/orchestrator/route-detector.js +3 -2
  152. package/src/lib/orchestrator/svm-idl/resolve.d.ts +2 -0
  153. package/src/lib/orchestrator/svm-idl/resolve.js +11 -1
  154. package/src/lib/progress-hook/progress-hook.js +63 -0
  155. package/src/lib/progress-hook/progress-hook.types.d.ts +10 -1
  156. package/src/lib/progress-hook/progress-hook.types.js +10 -0
  157. package/src/lib/push-chain/push-chain.d.ts +56 -15
  158. package/src/lib/push-chain/push-chain.js +66 -7
  159. package/src/lib/read-state/destination.js +6 -1
  160. package/src/lib/read-state/read-params.d.ts +3 -3
  161. package/src/lib/read-state/read-params.js +3 -2
  162. package/src/lib/read-state/read-state.types.d.ts +3 -1
  163. package/src/lib/read-state/read-tracker.js +2 -2
  164. package/src/lib/read-state/spec-builder.js +1 -1
  165. package/src/lib/universal/prc20-address.d.ts +15 -0
  166. package/src/lib/universal/prc20-address.js +135 -0
  167. package/src/lib/utils.d.ts +6 -13
  168. package/src/lib/utils.js +5 -128
  169. package/src/lib/vm-client/evm-client.js +34 -20
@@ -13,6 +13,12 @@ const evm_client_1 = require("../vm-client/evm-client");
13
13
  const tokens_1 = require("../constants/tokens");
14
14
  const read_params_1 = require("../read-state/read-params");
15
15
  const read_executor_1 = require("../read-state/read-executor");
16
+ const agentic_1 = require("../agentic/agentic");
17
+ const context_1 = require("../agentic/context");
18
+ const send_1 = require("../agentic/execution/send");
19
+ const guards_1 = require("../agentic/execution/guards");
20
+ const response_1 = require("../agentic/response");
21
+ const runtime_1 = require("../agentic/runtime");
16
22
  /**
17
23
  * @class PushChain
18
24
  *
@@ -52,6 +58,14 @@ class PushChain {
52
58
  moveable;
53
59
  payable;
54
60
  funds;
61
+ /**
62
+ * Agentic wallet management (AGW): derive, create, list and per-wallet
63
+ * handles. Ownership is the connected signer's Push identity.
64
+ */
65
+ agentic;
66
+ /** @internal AGW execution context when initialized with `agenticWallet`. */
67
+ agenticContext;
68
+ agenticRuntime;
55
69
  /**
56
70
  * Account status including UEA deployment state and version info.
57
71
  * Initially unloaded — call getAccountStatus() to populate.
@@ -81,62 +95,96 @@ class PushChain {
81
95
  };
82
96
  // Default — overwritten in createInstance() with the background fetch
83
97
  this.accountStatusReady = Promise.resolve();
98
+ this.agenticRuntime = (0, runtime_1.createAgenticRuntime)(orchestrator, isReadMode);
99
+ this.agentic = new agentic_1.AgenticNamespaceImpl(this.agenticRuntime);
100
+ // eslint-disable-next-line @typescript-eslint/no-this-alias -- getters below need the instance
101
+ const self = this;
102
+ // In agenticWallet mode, request transactions execute through the wallet
103
+ // and the wallet pays the request value, so its balance gates the read.
104
+ const readDeps = () => {
105
+ const actx = self.agenticContext;
106
+ if (!actx)
107
+ return orchestrator;
108
+ return {
109
+ execute: (params, options) => (0, send_1.agenticSend)(self.agenticRuntime, actx, params, options),
110
+ trackRead: orchestrator.trackRead.bind(orchestrator),
111
+ revalidateRead: orchestrator.revalidateRead.bind(orchestrator),
112
+ getProgressHook: orchestrator.getProgressHook.bind(orchestrator),
113
+ getReadBalance: () => self.agenticRuntime.reader.getBalance({ address: actx.wallet }),
114
+ };
115
+ };
116
+ // Unspent read budget returns to whoever paid it: the wallet in agentic mode.
117
+ const withReadRefund = (options) => self.agenticContext && options.refundTo === undefined
118
+ ? { ...options, refundTo: self.agenticContext.wallet }
119
+ : options;
84
120
  this.universal = {
85
121
  get origin() {
86
122
  return orchestrator.getUOA();
87
123
  },
88
124
  get account() {
89
- return orchestrator.computeUEAOffchain();
125
+ return self.agenticContext?.wallet ?? orchestrator.computeUEAOffchain();
90
126
  },
91
127
  sendTransaction: (...args) => {
92
128
  if (this.isReadMode) {
93
129
  throw new Error('Read only mode cannot call sendTransaction function');
94
130
  }
131
+ if (this.agenticContext) {
132
+ return (0, send_1.agenticSend)(this.agenticRuntime, this.agenticContext, ...args);
133
+ }
95
134
  return orchestrator.execute.bind(orchestrator)(...args);
96
135
  },
97
136
  prepareTransaction: (params, options) => {
137
+ if (this.agenticContext)
138
+ throw (0, guards_1.notAllowedInAgenticMode)('prepareTransaction');
98
139
  return orchestrator.prepareTransaction.bind(orchestrator)(params, options);
99
140
  },
100
141
  executeTransactions: async (txs, options) => {
101
142
  if (this.isReadMode) {
102
143
  throw new Error('Read only mode cannot call executeTransactions function');
103
144
  }
145
+ if (this.agenticContext)
146
+ throw (0, guards_1.notAllowedInAgenticMode)('executeTransactions');
104
147
  return orchestrator.createCascadedBuilder(txs, options).send();
105
148
  },
106
- trackTransaction: (txHash, options) => {
107
- return orchestrator.trackTransaction.bind(orchestrator)(txHash, options);
149
+ trackTransaction: async (txHash, options) => {
150
+ const tracked = await orchestrator.trackTransaction.bind(orchestrator)(txHash, options);
151
+ return (0, response_1.adaptTrackedResponse)(this.agenticRuntime, tracked);
108
152
  },
109
153
  migrateCEA: (chain) => {
110
154
  if (this.isReadMode) {
111
155
  throw new Error('Read only mode cannot call migrateCEA function');
112
156
  }
157
+ if (this.agenticContext)
158
+ throw (0, guards_1.notAllowedInAgenticMode)('migrateCEA');
113
159
  return orchestrator.migrateCEA.bind(orchestrator)(chain);
114
160
  },
115
161
  rescueFunds: (params) => {
116
162
  if (this.isReadMode) {
117
163
  throw new Error('Read only mode cannot call rescueFunds function');
118
164
  }
165
+ if (this.agenticContext)
166
+ throw (0, guards_1.notAllowedInAgenticMode)('rescueFunds');
119
167
  return orchestrator.rescueFunds.bind(orchestrator)(params);
120
168
  },
121
169
  // Only read()/executeReads() send transactions; prepare/simulate/track remain read-only.
122
170
  read: async (subject, options) => {
123
- const params = await (0, read_params_1.resolveReadSpecParams)(subject, options, orchestrator.getNetwork(), orchestrator.getRpcUrls());
171
+ const params = await (0, read_params_1.resolveReadSpecParams)(subject, withReadRefund(options), orchestrator.getNetwork(), orchestrator.getRpcUrls());
124
172
  (0, read_executor_1.assertRequestEntrypoint)(params.callback, 'read');
125
173
  if (this.isReadMode)
126
174
  throw new Error('Read only mode cannot call read function');
127
175
  const prepared = await orchestrator.prepareRead(params, options.progressHook);
128
- const { reads: [response] } = await (0, read_executor_1.executeReads)(orchestrator, [prepared], options);
176
+ const { reads: [response] } = await (0, read_executor_1.executeReads)(readDeps(), [prepared], options);
129
177
  return response;
130
178
  },
131
179
  prepareRead: async (subject, options) => {
132
- const params = await (0, read_params_1.resolveReadSpecParams)(subject, options, orchestrator.getNetwork(), orchestrator.getRpcUrls());
180
+ const params = await (0, read_params_1.resolveReadSpecParams)(subject, withReadRefund(options), orchestrator.getNetwork(), orchestrator.getRpcUrls());
133
181
  return orchestrator.prepareRead(params);
134
182
  },
135
183
  executeReads: (async (reads, options) => {
136
184
  reads.forEach((r) => (0, read_executor_1.assertRequestEntrypoint)(r.callback));
137
185
  if (this.isReadMode)
138
186
  throw new Error('Read only mode cannot call executeReads function');
139
- return (0, read_executor_1.executeReads)(orchestrator, reads, options);
187
+ return (0, read_executor_1.executeReads)(readDeps(), reads, options);
140
188
  }),
141
189
  trackRead: ((ref, options) => {
142
190
  const opts = { ...(0, read_params_1.toLifecycleOptions)(options), progressHook: options?.progressHook };
@@ -451,6 +499,12 @@ class PushChain {
451
499
  });
452
500
  // Let execute() await the background fetch instead of re-fetching
453
501
  orchestrator.accountStatusReadyPromise = instance.accountStatusReady;
502
+ // Agentic mode: validate the wallet, its generation and the signer's door
503
+ // before returning a client. A read-only client may hold the context (so
504
+ // universal.account shows the wallet) but every signing path stays closed.
505
+ if (options?.agenticWallet !== undefined) {
506
+ instance.agenticContext = await (0, context_1.resolveAgenticContext)(instance.agenticRuntime, options.agenticWallet);
507
+ }
454
508
  return instance;
455
509
  }
456
510
  /**
@@ -481,12 +535,17 @@ class PushChain {
481
535
  * @returns A new initialized instance of PushChain.
482
536
  */
483
537
  reinitialize = async (universalSigner, options) => {
538
+ // agenticWallet is NOT inherited: an omitted value yields an ordinary
539
+ // client, and a supplied one reruns every wallet/role check.
484
540
  const mergedOptions = {
485
541
  network: options?.network ?? this.orchestrator.getNetwork(),
486
542
  rpcUrls: options?.rpcUrls ?? this.orchestrator.getRpcUrls(),
487
543
  blockExplorers: options?.blockExplorers ?? this.blockExplorers,
488
544
  printTraces: options?.printTraces ?? this.orchestrator.getPrintTraces(),
489
545
  progressHook: options?.progressHook ?? this.orchestrator.getProgressHook(),
546
+ ...(options?.agenticWallet !== undefined
547
+ ? { agenticWallet: options.agenticWallet }
548
+ : {}),
490
549
  };
491
550
  return PushChain.createInstance(universalSigner, mergedOptions);
492
551
  };
@@ -17,7 +17,12 @@ const KNOWN = new Set(Object.values(read_state_1.READ_NAMESPACE));
17
17
  function resolveDestination(dest) {
18
18
  let chainNamespace;
19
19
  let chainId;
20
- if ('chain' in dest) {
20
+ if ('chain' in dest && dest.chain === read_state_1.WEB2_READ_CHAIN) {
21
+ // The public 'web2' spelling has no ':'; its wire identity is web2:https.
22
+ chainNamespace = read_state_1.WEB2_DESTINATION.chainNamespace;
23
+ chainId = read_state_1.WEB2_DESTINATION.chainId;
24
+ }
25
+ else if ('chain' in dest) {
21
26
  const idx = dest.chain.indexOf(':');
22
27
  if (idx <= 0) {
23
28
  throw new errors_1.UnsupportedReadDestinationError(`chain is not CAIP-2: ${dest.chain}`);
@@ -15,7 +15,7 @@ import type { Abi, AbiStateMutability, Address, Hex, ContractFunctionReturnType,
15
15
  import type { Idl, IdlAccounts } from '@coral-xyz/anchor';
16
16
  import { PublicKey } from '@solana/web3.js';
17
17
  import { CHAIN, PUSH_NETWORK } from '../constants/enums';
18
- import type { BuildReadSpecParams, ReadChain, ReadDestination, ReadLifecycleOptions, ReadQuery, ReadResultShape, Web2Extract } from './read-state.types';
18
+ import type { BuildReadSpecParams, ReadChain, ReadDestination, ReadLifecycleOptions, ReadQuery, ReadResultShape, Web2Extract, Web2ReadChain } from './read-state.types';
19
19
  import type { ReadCallback } from './read-state.types';
20
20
  import type { ProgressEvent } from '../progress-hook/progress-hook.types';
21
21
  export interface ReadWeb2Options {
@@ -116,7 +116,7 @@ export type ReadQueryOptions = ({
116
116
  } & Query<'storageSlot', {
117
117
  storageSlot: Hex | bigint;
118
118
  }>) | ({
119
- chain: typeof CHAIN.WEB2;
119
+ chain: Web2ReadChain;
120
120
  } & Query<'web2', {
121
121
  web2: ReadWeb2Options;
122
122
  }>);
@@ -146,7 +146,7 @@ type FinalizedDestinationOptions = {
146
146
  export type ReadPrepareOptions = SharedPrepareOptions & ((Extract<ReadQueryOptions, {
147
147
  chain: EvmChain;
148
148
  }> & EvmPinningOptions) | (Extract<ReadQueryOptions, {
149
- chain: SvmChain | typeof CHAIN.WEB2;
149
+ chain: SvmChain | Web2ReadChain;
150
150
  }> & FinalizedDestinationOptions));
151
151
  export type ReadExecuteOptions = Pick<ReadOptionsInput, 'advanced' | 'waitForCompletion' | 'progressHook'>;
152
152
  type WithExecutionOptions<T> = T extends unknown ? Omit<T, 'advanced' | 'waitForCompletion' | 'progressHook'> & ReadExecuteOptions : never;
@@ -43,7 +43,8 @@ function queryKind(o) {
43
43
  return present[0] ?? 'native';
44
44
  }
45
45
  function toReadDestination(chain) {
46
- return chain === enums_1.CHAIN.WEB2 ? read_state_1.WEB2_DESTINATION : { chain };
46
+ // Both public spellings normalize to the unchanged wire identity web2:https.
47
+ return (0, read_state_1.isWeb2ReadChain)(chain) ? read_state_1.WEB2_DESTINATION : { chain };
47
48
  }
48
49
  /** Build the internal query from the public grammar. Pure. */
49
50
  function toReadQuery(subject, o, resolvedTokenProgram) {
@@ -57,7 +58,7 @@ function toReadQuery(subject, o, resolvedTokenProgram) {
57
58
  return { type: 'http', url: subject, ...o.web2 };
58
59
  }
59
60
  if (kind === 'web2')
60
- throw new errors_1.InvalidReadQueryError('`web2` is only valid with chain CHAIN.WEB2');
61
+ throw new errors_1.InvalidReadQueryError('`web2` is only valid with chain READ.CHAIN.WEB2');
61
62
  if (dest.namespace === read_state_1.READ_NAMESPACE.EVM) {
62
63
  if (!(0, viem_1.isAddress)(subject))
63
64
  throw new errors_1.InvalidReadQueryError(`EVM subject must be an address, got ${subject}`);
@@ -6,7 +6,9 @@ import type { ReadNamespace } from '../constants/read-state';
6
6
  * Where a read goes. `CHAIN` enum values are CAIP-2 and split cleanly; the
7
7
  * explicit form is the low-level escape hatch; the public API uses `CHAIN.WEB2`.
8
8
  */
9
- export type ReadChain = CHAIN | typeof CHAIN.WEB2;
9
+ /** Web2 read source: `READ.CHAIN.WEB2` (`'web2'`) or the legacy `'web2:https'` literal. */
10
+ export type Web2ReadChain = 'web2' | 'web2:https';
11
+ export type ReadChain = CHAIN | Web2ReadChain;
10
12
  export type ReadDestination = {
11
13
  chain: ReadChain;
12
14
  } | {
@@ -309,8 +309,8 @@ function inferResultShape(namespace, query) {
309
309
  }
310
310
  }
311
311
  function chainFromCaip2(caip2) {
312
- if (caip2 === enums_1.CHAIN.WEB2)
313
- return enums_1.CHAIN.WEB2;
312
+ if ((0, read_state_1.isWeb2ReadChain)(caip2))
313
+ return read_state_1.WEB2_READ_CHAIN;
314
314
  return Object.values(enums_1.CHAIN).includes(caip2) ? caip2 : undefined;
315
315
  }
316
316
  function explorerTxUrl(network, txHash) {
@@ -106,7 +106,7 @@ function buildReadSpecFromPreflight(preflight, params, defaults = {}) {
106
106
  return {
107
107
  callback: params.callback,
108
108
  queryKey: (0, registry_1.computeReadQueryKey)(params.destination, params.query),
109
- chain: dest.caip2,
109
+ chain: (isWeb2 ? read_state_1.WEB2_READ_CHAIN : dest.caip2),
110
110
  spec,
111
111
  specTuple: toTuple(spec),
112
112
  encodedSpec: encodeSpec(spec),
@@ -0,0 +1,15 @@
1
+ import { CHAIN, PUSH_NETWORK } from '../constants/enums';
2
+ import { type MoveableToken } from '../constants/tokens';
3
+ /** Shared pure origin-to-PRC20 mapping; no signer or network reads. */
4
+ export declare function getPRC20Address(token: MoveableToken | {
5
+ chain: string;
6
+ address: string;
7
+ }, options?: {
8
+ network?: PUSH_NETWORK;
9
+ }): {
10
+ address: `0x${string}`;
11
+ chain: CHAIN;
12
+ symbol: string;
13
+ decimals: number;
14
+ network: PUSH_NETWORK;
15
+ };
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPRC20Address = getPRC20Address;
4
+ const enums_1 = require("../constants/enums");
5
+ const tokens_1 = require("../constants/tokens");
6
+ const chain_1 = require("../constants/chain");
7
+ /** Shared pure origin-to-PRC20 mapping; no signer or network reads. */
8
+ function getPRC20Address(token, options) {
9
+ const network = options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
10
+ const assertDeployed = (addr, ctx) => {
11
+ if (!addr || addr === '0xTBD') {
12
+ throw new Error(`PRC20 address not available for ${ctx} on network ${network}`);
13
+ }
14
+ return addr;
15
+ };
16
+ // PushChainMoveableToken (pETH, pSOL, pUSDT(BNB), …) carries its PRC-20 address
17
+ // and origin `sourceChain` directly — no registry lookup needed.
18
+ const pcToken = token;
19
+ if (pcToken.prc20Address) {
20
+ return {
21
+ address: assertDeployed(pcToken.prc20Address, `${pcToken.symbol ?? 'token'} (${pcToken.sourceChain ?? 'unknown'})`),
22
+ chain: pcToken.sourceChain,
23
+ symbol: pcToken.symbol,
24
+ decimals: pcToken.decimals,
25
+ network,
26
+ };
27
+ }
28
+ // Infer origin chain, symbol, decimals by matching against MOVEABLE_TOKENS
29
+ let originChain;
30
+ let tokenSymbol;
31
+ let tokenDecimals;
32
+ if ('symbol' in token) {
33
+ // MoveableToken path: infer chain by symbol + address
34
+ for (const [key, list] of Object.entries(tokens_1.MOVEABLE_TOKENS)) {
35
+ const k = key;
36
+ const match = (list ?? []).find((t) => t.symbol === token.symbol && t.address === token.address);
37
+ if (match) {
38
+ originChain = k;
39
+ tokenSymbol = match.symbol;
40
+ tokenDecimals = match.decimals;
41
+ break;
42
+ }
43
+ }
44
+ }
45
+ else {
46
+ // { chain, address } path: trust the provided chain and resolve symbol via registry
47
+ originChain = token.chain;
48
+ const list = tokens_1.MOVEABLE_TOKENS[originChain] ?? [];
49
+ const match = list.find((t) => t.address === token.address);
50
+ if (match) {
51
+ tokenSymbol = match.symbol;
52
+ tokenDecimals = match.decimals;
53
+ }
54
+ }
55
+ if (!originChain || !tokenSymbol || tokenDecimals === undefined) {
56
+ throw new Error('Unable to infer origin chain or token symbol for token');
57
+ }
58
+ const map = chain_1.SYNTHETIC_PUSH_ERC20[network];
59
+ if (!map) {
60
+ throw new Error(`No PRC20 address map configured for network: ${network}`);
61
+ }
62
+ // Map token → synthetic key by origin chain family
63
+ const isEthFamily = originChain === enums_1.CHAIN.ETHEREUM_MAINNET ||
64
+ originChain === enums_1.CHAIN.ETHEREUM_SEPOLIA;
65
+ const isArbFamily = originChain === enums_1.CHAIN.ARBITRUM_SEPOLIA;
66
+ const isBaseFamily = originChain === enums_1.CHAIN.BASE_SEPOLIA;
67
+ const isBnbFamily = originChain === enums_1.CHAIN.BNB_TESTNET;
68
+ const isSolFamily = originChain === enums_1.CHAIN.SOLANA_DEVNET;
69
+ let key;
70
+ switch (tokenSymbol) {
71
+ case 'ETH': {
72
+ if (isEthFamily)
73
+ key = 'pETH';
74
+ else if (isArbFamily)
75
+ key = 'pETH_ARB';
76
+ else if (isBaseFamily)
77
+ key = 'pETH_BASE';
78
+ else
79
+ throw new Error('Unsupported ETH origin chain for synthetic mapping');
80
+ break;
81
+ }
82
+ case 'SOL': {
83
+ if (!isSolFamily)
84
+ throw new Error('SOL token provided but origin is not Solana');
85
+ key = 'pSOL';
86
+ break;
87
+ }
88
+ case 'BNB': {
89
+ if (!isBnbFamily)
90
+ throw new Error('BNB token provided but origin is not BNB Testnet');
91
+ key = 'pBNB';
92
+ break;
93
+ }
94
+ case 'USDT': {
95
+ if (isEthFamily)
96
+ key = 'USDT_ETH';
97
+ else if (isArbFamily)
98
+ key = 'USDT_ARB';
99
+ else if (isBaseFamily)
100
+ key = 'USDT_BASE';
101
+ else if (isBnbFamily)
102
+ key = 'USDT_BSC';
103
+ else if (isSolFamily)
104
+ key = 'USDT_SOL';
105
+ else
106
+ throw new Error('Unsupported USDT origin chain for synthetic mapping');
107
+ break;
108
+ }
109
+ case 'USDC': {
110
+ if (isEthFamily)
111
+ key = 'USDC_ETH';
112
+ else if (isArbFamily)
113
+ key = 'USDC_ARB';
114
+ else if (isBaseFamily)
115
+ key = 'USDC_BASE';
116
+ else if (isBnbFamily)
117
+ key = 'USDC_BSC';
118
+ else if (isSolFamily)
119
+ key = 'USDC_SOL';
120
+ else
121
+ throw new Error('Unsupported USDC origin chain for synthetic mapping');
122
+ break;
123
+ }
124
+ default:
125
+ throw new Error(`Unsupported token symbol: ${tokenSymbol}`);
126
+ }
127
+ return {
128
+ address: assertDeployed(map[key], `${tokenSymbol} on ${originChain}`),
129
+ chain: originChain,
130
+ symbol: tokenSymbol,
131
+ decimals: tokenDecimals,
132
+ network,
133
+ };
134
+ }
135
+ //# sourceMappingURL=prc20-address.js.map
@@ -1,7 +1,7 @@
1
1
  import { convertOriginToExecutor, fromChainAgnostic, convertExecutorToOriginAccount, toChainAgnostic, toUniversal, deriveExecutorAccount, resolveControllerAccount } from './universal/account';
2
2
  import { construct, toUniversal as toUniversalSigner, toUniversalFromKeypair } from './universal/signer';
3
3
  import { CHAIN, PUSH_NETWORK } from './constants/enums';
4
- import { type MoveableToken } from './constants/tokens';
4
+ import { getPRC20Address } from './universal/prc20-address';
5
5
  import type { PushChain } from './push-chain/push-chain';
6
6
  import type { PC20AddressResult } from './orchestrator/orchestrator.types';
7
7
  import type { Idl } from '@coral-xyz/anchor';
@@ -274,18 +274,7 @@ export declare class Utils {
274
274
  * });
275
275
  * ```
276
276
  */
277
- getPRC20Address(token: MoveableToken | {
278
- chain: string;
279
- address: string;
280
- }, options?: {
281
- network?: PUSH_NETWORK;
282
- }): {
283
- address: `0x${string}`;
284
- chain: CHAIN;
285
- symbol: string;
286
- decimals: number;
287
- network: PUSH_NETWORK;
288
- };
277
+ getPRC20Address: typeof getPRC20Address;
289
278
  /**
290
279
  * Resolve a PC20 token against UniversalCore's on-chain registry, and list
291
280
  * every confirmed address it has across chains.
@@ -330,6 +319,10 @@ export declare class Utils {
330
319
  strict?: boolean;
331
320
  }): Promise<PC20AddressResult>;
332
321
  };
322
+ /** Pure preset discovery/templates; internal encoders and identifiers stay private. */
323
+ static readonly agentic: Readonly<{
324
+ presets: import("./agentic").AgenticPresets;
325
+ }>;
333
326
  /**
334
327
  * Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
335
328
  */
package/src/lib/utils.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Utils = void 0;
4
+ const presets_1 = require("./agentic/presets");
4
5
  const account_1 = require("./universal/account");
5
6
  const signer_1 = require("./universal/signer");
6
7
  const enums_1 = require("./constants/enums");
7
8
  const tokens_1 = require("./constants/tokens");
8
- const chain_1 = require("./constants/chain");
9
+ const prc20_address_1 = require("./universal/prc20-address");
9
10
  const viem_1 = require("viem");
10
11
  const resolver_1 = require("./orchestrator/internals/pc20/resolver");
11
12
  const errors_1 = require("./orchestrator/internals/pc20/errors");
@@ -584,133 +585,7 @@ class Utils {
584
585
  * });
585
586
  * ```
586
587
  */
587
- getPRC20Address(token, options) {
588
- const network = options?.network ?? enums_1.PUSH_NETWORK.TESTNET_DONUT;
589
- const assertDeployed = (addr, ctx) => {
590
- if (!addr || addr === '0xTBD') {
591
- throw new Error(`PRC20 address not available for ${ctx} on network ${network}`);
592
- }
593
- return addr;
594
- };
595
- // PushChainMoveableToken (pETH, pSOL, pUSDT(BNB), …) carries its PRC-20 address
596
- // and origin `sourceChain` directly — no registry lookup needed.
597
- const pcToken = token;
598
- if (pcToken.prc20Address) {
599
- return {
600
- address: assertDeployed(pcToken.prc20Address, `${pcToken.symbol ?? 'token'} (${pcToken.sourceChain ?? 'unknown'})`),
601
- chain: pcToken.sourceChain,
602
- symbol: pcToken.symbol,
603
- decimals: pcToken.decimals,
604
- network,
605
- };
606
- }
607
- // Infer origin chain, symbol, decimals by matching against MOVEABLE_TOKENS
608
- let originChain;
609
- let tokenSymbol;
610
- let tokenDecimals;
611
- if ('symbol' in token) {
612
- // MoveableToken path: infer chain by symbol + address
613
- for (const [key, list] of Object.entries(tokens_1.MOVEABLE_TOKENS)) {
614
- const k = key;
615
- const match = (list ?? []).find((t) => t.symbol === token.symbol && t.address === token.address);
616
- if (match) {
617
- originChain = k;
618
- tokenSymbol = match.symbol;
619
- tokenDecimals = match.decimals;
620
- break;
621
- }
622
- }
623
- }
624
- else {
625
- // { chain, address } path: trust the provided chain and resolve symbol via registry
626
- originChain = token.chain;
627
- const list = tokens_1.MOVEABLE_TOKENS[originChain] ?? [];
628
- const match = list.find((t) => t.address === token.address);
629
- if (match) {
630
- tokenSymbol = match.symbol;
631
- tokenDecimals = match.decimals;
632
- }
633
- }
634
- if (!originChain || !tokenSymbol || tokenDecimals === undefined) {
635
- throw new Error('Unable to infer origin chain or token symbol for token');
636
- }
637
- const map = chain_1.SYNTHETIC_PUSH_ERC20[network];
638
- if (!map) {
639
- throw new Error(`No PRC20 address map configured for network: ${network}`);
640
- }
641
- // Map token → synthetic key by origin chain family
642
- const isEthFamily = originChain === enums_1.CHAIN.ETHEREUM_MAINNET ||
643
- originChain === enums_1.CHAIN.ETHEREUM_SEPOLIA;
644
- const isArbFamily = originChain === enums_1.CHAIN.ARBITRUM_SEPOLIA;
645
- const isBaseFamily = originChain === enums_1.CHAIN.BASE_SEPOLIA;
646
- const isBnbFamily = originChain === enums_1.CHAIN.BNB_TESTNET;
647
- const isSolFamily = originChain === enums_1.CHAIN.SOLANA_DEVNET;
648
- let key;
649
- switch (tokenSymbol) {
650
- case 'ETH': {
651
- if (isEthFamily)
652
- key = 'pETH';
653
- else if (isArbFamily)
654
- key = 'pETH_ARB';
655
- else if (isBaseFamily)
656
- key = 'pETH_BASE';
657
- else
658
- throw new Error('Unsupported ETH origin chain for synthetic mapping');
659
- break;
660
- }
661
- case 'SOL': {
662
- if (!isSolFamily)
663
- throw new Error('SOL token provided but origin is not Solana');
664
- key = 'pSOL';
665
- break;
666
- }
667
- case 'BNB': {
668
- if (!isBnbFamily)
669
- throw new Error('BNB token provided but origin is not BNB Testnet');
670
- key = 'pBNB';
671
- break;
672
- }
673
- case 'USDT': {
674
- if (isEthFamily)
675
- key = 'USDT_ETH';
676
- else if (isArbFamily)
677
- key = 'USDT_ARB';
678
- else if (isBaseFamily)
679
- key = 'USDT_BASE';
680
- else if (isBnbFamily)
681
- key = 'USDT_BSC';
682
- else if (isSolFamily)
683
- key = 'USDT_SOL';
684
- else
685
- throw new Error('Unsupported USDT origin chain for synthetic mapping');
686
- break;
687
- }
688
- case 'USDC': {
689
- if (isEthFamily)
690
- key = 'USDC_ETH';
691
- else if (isArbFamily)
692
- key = 'USDC_ARB';
693
- else if (isBaseFamily)
694
- key = 'USDC_BASE';
695
- else if (isBnbFamily)
696
- key = 'USDC_BSC';
697
- else if (isSolFamily)
698
- key = 'USDC_SOL';
699
- else
700
- throw new Error('Unsupported USDC origin chain for synthetic mapping');
701
- break;
702
- }
703
- default:
704
- throw new Error(`Unsupported token symbol: ${tokenSymbol}`);
705
- }
706
- return {
707
- address: assertDeployed(map[key], `${tokenSymbol} on ${originChain}`),
708
- chain: originChain,
709
- symbol: tokenSymbol,
710
- decimals: tokenDecimals,
711
- network,
712
- };
713
- },
588
+ getPRC20Address: prc20_address_1.getPRC20Address,
714
589
  /**
715
590
  * Resolve a PC20 token against UniversalCore's on-chain registry, and list
716
591
  * every confirmed address it has across chains.
@@ -788,6 +663,8 @@ class Utils {
788
663
  };
789
664
  },
790
665
  };
666
+ /** Pure preset discovery/templates; internal encoders and identifiers stay private. */
667
+ static agentic = Object.freeze({ presets: presets_1.agenticPresets });
791
668
  /**
792
669
  * Internal: resolves a CHAIN enum from either a CHAIN value or a PushChain client instance.
793
670
  */