@pushchain/core 6.0.20 → 6.0.22

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 (113) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/package.json +8 -2
  3. package/src/lib/cache/cache.js +2 -0
  4. package/src/lib/constants/abi/erc20.evm.d.ts +30 -0
  5. package/src/lib/constants/abi/erc20.evm.js +21 -0
  6. package/src/lib/constants/abi/index.d.ts +1 -0
  7. package/src/lib/constants/abi/index.js +7 -1
  8. package/src/lib/constants/abi/pc20.evm.d.ts +192 -0
  9. package/src/lib/constants/abi/pc20.evm.js +134 -0
  10. package/src/lib/constants/abi/prc20.evm.d.ts +172 -0
  11. package/src/lib/constants/abi/prc20.evm.js +97 -0
  12. package/src/lib/constants/abi/universalGatewayV0.json +1 -1
  13. package/src/lib/constants/chain.js +38 -8
  14. package/src/lib/constants/selectors.js +2 -2
  15. package/src/lib/constants/tokens.js +4 -3
  16. package/src/lib/formatters.js +16 -6
  17. package/src/lib/generated/uexecutor/v1/query.js +2 -4
  18. package/src/lib/generated/uexecutor/v1/types.d.ts +14 -0
  19. package/src/lib/generated/uexecutor/v1/types.js +90 -47
  20. package/src/lib/generated/uexecutor/v2/query.js +2 -4
  21. package/src/lib/generated/uexecutor/v2/types.d.ts +20 -0
  22. package/src/lib/generated/uexecutor/v2/types.js +49 -33
  23. package/src/lib/generated/v1/tx.js +30 -37
  24. package/src/lib/index.d.ts +3 -0
  25. package/src/lib/index.js +21 -3
  26. package/src/lib/internal/buffer.js +1 -2
  27. package/src/lib/orchestrator/cea-utils.js +89 -83
  28. package/src/lib/orchestrator/internals/account-manager.js +130 -139
  29. package/src/lib/orchestrator/internals/cascade.d.ts +0 -6
  30. package/src/lib/orchestrator/internals/cascade.js +1184 -1059
  31. package/src/lib/orchestrator/internals/confirmation.js +138 -148
  32. package/src/lib/orchestrator/internals/error-decoder.js +1 -1
  33. package/src/lib/orchestrator/internals/errors.js +12 -3
  34. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +2 -2
  35. package/src/lib/orchestrator/internals/execute-funds-only.js +297 -259
  36. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +2 -2
  37. package/src/lib/orchestrator/internals/execute-funds-payload.js +220 -220
  38. package/src/lib/orchestrator/internals/execute-standard.d.ts +0 -8
  39. package/src/lib/orchestrator/internals/execute-standard.js +339 -342
  40. package/src/lib/orchestrator/internals/gas-calculator.js +497 -520
  41. package/src/lib/orchestrator/internals/gas-usd-sizer.js +101 -110
  42. package/src/lib/orchestrator/internals/gateway-client.js +102 -103
  43. package/src/lib/orchestrator/internals/helpers.js +30 -27
  44. package/src/lib/orchestrator/internals/inbound-tracker.js +234 -238
  45. package/src/lib/orchestrator/internals/outbound-sync.js +463 -452
  46. package/src/lib/orchestrator/internals/outbound-tracker.js +27 -34
  47. package/src/lib/orchestrator/internals/payload-builder.d.ts +2 -2
  48. package/src/lib/orchestrator/internals/payload-builder.js +119 -100
  49. package/src/lib/orchestrator/internals/pc-usd-oracle.js +121 -129
  50. package/src/lib/orchestrator/internals/pc20/address-codec.d.ts +31 -0
  51. package/src/lib/orchestrator/internals/pc20/address-codec.js +124 -0
  52. package/src/lib/orchestrator/internals/pc20/chain-namespace.d.ts +68 -0
  53. package/src/lib/orchestrator/internals/pc20/chain-namespace.js +136 -0
  54. package/src/lib/orchestrator/internals/pc20/errors.d.ts +160 -0
  55. package/src/lib/orchestrator/internals/pc20/errors.js +236 -0
  56. package/src/lib/orchestrator/internals/pc20/export.d.ts +176 -0
  57. package/src/lib/orchestrator/internals/pc20/export.js +431 -0
  58. package/src/lib/orchestrator/internals/pc20/gate.d.ts +67 -0
  59. package/src/lib/orchestrator/internals/pc20/gate.js +184 -0
  60. package/src/lib/orchestrator/internals/pc20/resolver.d.ts +185 -0
  61. package/src/lib/orchestrator/internals/pc20/resolver.js +649 -0
  62. package/src/lib/orchestrator/internals/pc20/svm.d.ts +189 -0
  63. package/src/lib/orchestrator/internals/pc20/svm.js +286 -0
  64. package/src/lib/orchestrator/internals/pc20/tracking.d.ts +46 -0
  65. package/src/lib/orchestrator/internals/pc20/tracking.js +109 -0
  66. package/src/lib/orchestrator/internals/preflight.js +1 -1
  67. package/src/lib/orchestrator/internals/progress-route-hooks.js +2 -2
  68. package/src/lib/orchestrator/internals/push-chain-tx.js +319 -329
  69. package/src/lib/orchestrator/internals/quote.js +90 -94
  70. package/src/lib/orchestrator/internals/rescue.js +76 -79
  71. package/src/lib/orchestrator/internals/response-builder.d.ts +28 -1
  72. package/src/lib/orchestrator/internals/response-builder.js +817 -701
  73. package/src/lib/orchestrator/internals/route-handlers.d.ts +7 -15
  74. package/src/lib/orchestrator/internals/route-handlers.js +1522 -1176
  75. package/src/lib/orchestrator/internals/signing.js +78 -83
  76. package/src/lib/orchestrator/internals/svm-bridge.d.ts +2 -2
  77. package/src/lib/orchestrator/internals/svm-bridge.js +161 -93
  78. package/src/lib/orchestrator/internals/svm-helpers.d.ts +15 -1
  79. package/src/lib/orchestrator/internals/svm-helpers.js +68 -24
  80. package/src/lib/orchestrator/internals/svm-rent.d.ts +19 -1
  81. package/src/lib/orchestrator/internals/svm-rent.js +163 -141
  82. package/src/lib/orchestrator/internals/tx-transformer.js +26 -23
  83. package/src/lib/orchestrator/internals/uea-manager.js +89 -86
  84. package/src/lib/orchestrator/max-pc-for-gas.js +5 -6
  85. package/src/lib/orchestrator/orchestrator.js +217 -200
  86. package/src/lib/orchestrator/orchestrator.types.d.ts +121 -1
  87. package/src/lib/orchestrator/orchestrator.types.js +19 -0
  88. package/src/lib/orchestrator/payload-builders.d.ts +2 -2
  89. package/src/lib/orchestrator/payload-builders.js +26 -24
  90. package/src/lib/orchestrator/route-detector.js +26 -9
  91. package/src/lib/orchestrator/svm-idl/ix-encoder.js +1 -2
  92. package/src/lib/orchestrator/svm-idl/normalize-address.js +2 -2
  93. package/src/lib/orchestrator/svm-idl/resolve.js +1 -2
  94. package/src/lib/price-fetch/price-fetch.js +67 -68
  95. package/src/lib/progress-hook/progress-hook.js +124 -72
  96. package/src/lib/push-chain/push-chain.js +171 -153
  97. package/src/lib/push-client/push-client.js +223 -237
  98. package/src/lib/universal/account/account.js +349 -365
  99. package/src/lib/universal/signer/signer.js +306 -294
  100. package/src/lib/universal-tx-detector/auto-detect.js +55 -60
  101. package/src/lib/universal-tx-detector/cascade.js +160 -172
  102. package/src/lib/universal-tx-detector/child-inbounds.js +67 -75
  103. package/src/lib/universal-tx-detector/classify.js +2 -3
  104. package/src/lib/universal-tx-detector/detector-svm.js +139 -147
  105. package/src/lib/universal-tx-detector/detector.js +145 -157
  106. package/src/lib/universal-tx-detector/normalize.js +7 -7
  107. package/src/lib/utils/external-tx-hash.js +1 -2
  108. package/src/lib/utils.d.ts +44 -0
  109. package/src/lib/utils.js +762 -683
  110. package/src/lib/vm-client/evm-client.js +186 -202
  111. package/src/lib/vm-client/svm-client.d.ts +1 -1
  112. package/src/lib/vm-client/svm-client.js +220 -224
  113. package/src/lib/vm-client/vm-client.types.d.ts +14 -2
@@ -0,0 +1,185 @@
1
+ /**
2
+ * PC20 registry resolver — the one module that reads PC20 state.
3
+ *
4
+ * Used by `sendTransaction`, `prepareTransaction`, cascade construction,
5
+ * `getPC20Address`, and the outbound tracking fallback.
6
+ * Nothing else may read the registry directly; a second reader is how the
7
+ * validation tiers and the cache policy drift apart.
8
+ *
9
+ * ## Read budget
10
+ *
11
+ * Validation is tiered so a send does not pay for the full identity sweep:
12
+ *
13
+ * Tier A (every send) — `getPC20Source` then `getPC20Wrapper`. Forward and
14
+ * reverse agreement proves the address is registered
15
+ * for that exact namespace, which is what defeats a
16
+ * wrapper address copied onto the wrong chain.
17
+ * Tier B (prepare-time, first use per session, or strict mode) — live gateway
18
+ * factory identity, `isPC20Wrapper`, `wrapperToSource`,
19
+ * `SOURCE_ASSET`, deployed bytecode. Largely redundant
20
+ * once Tier A holds, but it is what catches a
21
+ * misconfigured deployment where the gateway would not
22
+ * take the PC20 burn path at all.
23
+ *
24
+ * Each tier is one multicall against one chain. Budget: at most 2 sequential
25
+ * round trips warm, 4 cold. `__readCount` exists so tests can assert that.
26
+ *
27
+ * ## Cache policy
28
+ *
29
+ * Positive results are cached for the client's lifetime, keyed by
30
+ * `(pushNetwork, chain, address)`. Registered mappings are immutable in
31
+ * practice — a factory reconfiguration is a redeploy-level event.
32
+ *
33
+ * Negative results are NEVER cached. The first successful export creates a
34
+ * mapping that did not previously exist, and a cached "not registered" would
35
+ * make the SDK permanently wrong about a token that now works.
36
+ */
37
+ import { type Hex } from 'viem';
38
+ import { CHAIN, PUSH_NETWORK, VM } from '../../../constants/enums';
39
+ /** Standard ERC-20 metadata forwarded when exporting a Push-native PC20. */
40
+ export type PC20Metadata = {
41
+ name: string;
42
+ symbol: string;
43
+ decimals: number;
44
+ };
45
+ /** A confirmed wrapper deployment on one external chain. */
46
+ export type PC20DeploymentInfo = {
47
+ chain: CHAIN;
48
+ chainNamespace: string;
49
+ vm: VM;
50
+ /** Chain-native form: checksummed hex (EVM) or base58 (SVM). */
51
+ address: string;
52
+ /** Registry form, as stored in UniversalCore. */
53
+ rawAddress: Hex;
54
+ };
55
+ /** Everything the execution path needs about a resolved funds token. */
56
+ export type ResolvedPC20 = {
57
+ direction: 'import' | 'export';
58
+ /** Chain the token the caller named lives on. */
59
+ originChain: CHAIN;
60
+ /** Chain-native address of the token the caller named. */
61
+ originAddress: string;
62
+ /** Canonical Push-native PC20. */
63
+ pushAddress: `0x${string}`;
64
+ name: string;
65
+ symbol: string;
66
+ decimals: number;
67
+ /** External wrapper, when one is registered. Absent before a first export. */
68
+ wrapperAddress?: string;
69
+ /** Namespace of the external side (origin for import, destination for export). */
70
+ chainNamespace?: string;
71
+ };
72
+ export type PC20ResolverOptions = {
73
+ network: PUSH_NETWORK;
74
+ /** Per-chain RPC overrides. Falls back to `CHAIN_INFO[chain].defaultRPC`. */
75
+ rpcUrls?: Partial<Record<CHAIN, string[]>>;
76
+ /** Run Tier B factory-identity checks even on a warm path. */
77
+ strict?: boolean;
78
+ /** Re-read the wrapper/source registry even when a positive cache entry exists. */
79
+ bypassCache?: boolean;
80
+ };
81
+ /**
82
+ * Instrumentation for the round-trip budget assertion. Incremented once per
83
+ * network round trip (a batch counts as one, which is the whole point).
84
+ */
85
+ export declare const __readCount: {
86
+ n: number;
87
+ };
88
+ /**
89
+ * Resolve UniversalCore through the UGPC precompile, matching how
90
+ * `gas-calculator.queryOutboundGasFee` does it. Cached per network — the
91
+ * precompile's `universalCore` pointer does not move within a session.
92
+ */
93
+ export declare function getUniversalCoreAddress(opts: PC20ResolverOptions): Promise<`0x${string}`>;
94
+ /** Test seam. Never call from product code — it would drop verified Tier B state. */
95
+ export declare function __clearPC20Caches(): void;
96
+ /**
97
+ * Resolve an external wrapper to its canonical Push-native source.
98
+ *
99
+ * One multicall: `getPC20Source(wrapper, ns)` and, in the same batch, the
100
+ * reverse `getPC20Wrapper` cannot be issued because it depends on the source.
101
+ * The reverse read is therefore a second round trip — this is the "2 sequential
102
+ * round trips" in the budget, and it is not collapsible: the registry has no
103
+ * combined accessor.
104
+ *
105
+ * @throws {PC20WrapperNotRegisteredError} when the wrapper is unknown.
106
+ * @throws {PC20RegistryMismatchError} when forward and reverse disagree.
107
+ */
108
+ export declare function resolveWrapperToSource(chain: CHAIN, address: string, opts: PC20ResolverOptions): Promise<{
109
+ pushAddress: `0x${string}`;
110
+ chainNamespace: string;
111
+ rawWrapper: Hex;
112
+ }>;
113
+ /**
114
+ * Verify the live external gateway will actually take the PC20 burn path for
115
+ * this wrapper, and that its factory is the one UniversalCore knows about.
116
+ *
117
+ * Two multicalls: the gateway's factory pointer must be read before the
118
+ * factory-scoped calls can be addressed.
119
+ *
120
+ * @throws {PC20FactoryMismatchError} on any identity disagreement.
121
+ */
122
+ export declare function verifyEvmWrapperIdentity(chain: CHAIN, address: string, pushAddress: `0x${string}`, opts: PC20ResolverOptions): Promise<void>;
123
+ /**
124
+ * Read and validate standard ERC-20 metadata on a Push-native token.
125
+ *
126
+ * Every metadata-compatible ERC-20 born on Push Chain is eligible for PC20
127
+ * export. Synthetic PRC20s expose `CHAIN_NAMESPACE()` and are rejected even
128
+ * though they also implement the standard metadata functions.
129
+ */
130
+ export declare function readPushPC20Metadata(pushAddress: `0x${string}`, opts: PC20ResolverOptions): Promise<PC20Metadata>;
131
+ /**
132
+ * Confirmed wrapper deployments for a Push-native PC20.
133
+ *
134
+ * One multicall regardless of chain count — every `getPC20Wrapper` read targets
135
+ * UniversalCore on Push Chain, so fanning out per chain would be N round trips
136
+ * to the same endpoint for no reason.
137
+ *
138
+ * Returns confirmed deployments only. A predicted first-export address is the
139
+ * outbound builder's concern, not discovery's.
140
+ */
141
+ export declare function listPC20Deployments(pushAddress: `0x${string}`, opts: PC20ResolverOptions & {
142
+ chains?: CHAIN[];
143
+ }): Promise<PC20DeploymentInfo[]>;
144
+ /**
145
+ * Registered wrapper for a Push PC20 on one destination chain.
146
+ *
147
+ * `undefined` means not yet deployed — a legitimate state before a first
148
+ * export, not an error. Callers that need an address for a first export must go
149
+ * through the prediction path, which verifies against the live factory.
150
+ */
151
+ export declare function getRegisteredWrapper(pushAddress: `0x${string}`, destinationChain: CHAIN, opts: PC20ResolverOptions): Promise<PC20DeploymentInfo | undefined>;
152
+ /**
153
+ * Work out which chain an address belongs to, when the caller did not say.
154
+ *
155
+ * Used ONLY by the read-only `getPC20Address` utility. The transaction path
156
+ * never calls this — `funds.token` requires an explicit `chain`, and
157
+ * `gate.ts` rejects one that disagrees with where the funds actually are. A
158
+ * wrapper address copied from the wrong chain still fails on send; it merely
159
+ * resolves informationally on lookup.
160
+ *
161
+ * Order is cheapest-first:
162
+ * 1. narrow candidates by address format (local, free);
163
+ * 2. try Push-native, which short-circuits with no registry read at all;
164
+ * 3. probe every remaining namespace in one multicall.
165
+ *
166
+ * @throws {PC20AmbiguousAddressError} when several chains claim the address
167
+ * with different Push sources.
168
+ */
169
+ export declare function discoverPC20Chain(address: string, opts: PC20ResolverOptions): Promise<{
170
+ chain: CHAIN;
171
+ pushAddress: `0x${string}`;
172
+ } | null>;
173
+ /**
174
+ * Resolve a `{ chain, address }` PC20 reference into everything the execution
175
+ * path needs, exactly once per transaction.
176
+ *
177
+ * `expectedChain` is where the funds actually are — the signer's chain for a
178
+ * direct external route, `params.from.chain` for a CEA-origin route, the Push
179
+ * chain for an export. Chain-ownership validation is the caller's job because
180
+ * only the caller knows which of those applies; this function assumes it has
181
+ * already passed.
182
+ */
183
+ export declare function resolvePC20Token(chain: CHAIN, address: string, opts: PC20ResolverOptions & {
184
+ tierB?: boolean;
185
+ }): Promise<ResolvedPC20>;