@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
@@ -24,168 +24,159 @@ const helpers_1 = require("./helpers");
24
24
  // ============================================================================
25
25
  // Fetch Latest UEA Version from Factory
26
26
  // ============================================================================
27
- function fetchLatestUEAVersion(ctx, vm) {
28
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
- const factoryAddress = chain_1.UEA_FACTORY[ctx.pushNetwork];
30
- if (!factoryAddress || factoryAddress === '0xTBD') {
31
- return '';
32
- }
33
- try {
34
- const vmHash = vm === enums_1.VM.EVM
35
- ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['EVM']))
36
- : (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['SVM']));
37
- return yield ctx.pushClient.readContract({
38
- address: factoryAddress,
39
- abi: uea_factory_1.UEA_FACTORY_ABI,
40
- functionName: 'UEA_VERSION',
41
- args: [vmHash],
42
- });
43
- }
44
- catch (_a) {
45
- return '';
46
- }
47
- });
27
+ async function fetchLatestUEAVersion(ctx, vm) {
28
+ const factoryAddress = chain_1.UEA_FACTORY[ctx.pushNetwork];
29
+ if (!factoryAddress || factoryAddress === '0xTBD') {
30
+ return '';
31
+ }
32
+ try {
33
+ const vmHash = vm === enums_1.VM.EVM
34
+ ? (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['EVM']))
35
+ : (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: 'string' }], ['SVM']));
36
+ return await ctx.pushClient.readContract({
37
+ address: factoryAddress,
38
+ abi: uea_factory_1.UEA_FACTORY_ABI,
39
+ functionName: 'UEA_VERSION',
40
+ args: [vmHash],
41
+ });
42
+ }
43
+ catch {
44
+ return '';
45
+ }
48
46
  }
49
47
  // ============================================================================
50
48
  // Account Status
51
49
  // ============================================================================
52
- function getAccountStatus(ctx, options) {
53
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
54
- if (ctx.accountStatusCache && !(options === null || options === void 0 ? void 0 : options.forceRefresh)) {
55
- return ctx.accountStatusCache;
56
- }
57
- const chain = ctx.universalSigner.account.chain;
58
- const { vm } = chain_1.CHAIN_INFO[chain];
59
- const { deployed } = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
60
- if (!deployed) {
61
- const status = {
62
- mode: 'signer',
63
- uea: {
64
- loaded: true,
65
- deployed: false,
66
- version: '',
67
- minRequiredVersion: '',
68
- requiresUpgrade: false,
69
- },
70
- };
71
- ctx.accountStatusCache = status;
72
- return status;
73
- }
74
- const [currentVersion, minRequiredVersion] = yield Promise.all([
75
- (0, uea_manager_1.fetchUEAVersion)(ctx),
76
- fetchLatestUEAVersion(ctx, vm),
77
- ]);
78
- const requiresUpgrade = (0, orchestrator_types_1.parseUEAVersion)(currentVersion) < (0, orchestrator_types_1.parseUEAVersion)(minRequiredVersion);
50
+ async function getAccountStatus(ctx, options) {
51
+ if (ctx.accountStatusCache && !options?.forceRefresh) {
52
+ return ctx.accountStatusCache;
53
+ }
54
+ const chain = ctx.universalSigner.account.chain;
55
+ const { vm } = chain_1.CHAIN_INFO[chain];
56
+ const { deployed } = await (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
57
+ if (!deployed) {
79
58
  const status = {
80
59
  mode: 'signer',
81
60
  uea: {
82
61
  loaded: true,
83
- deployed: true,
84
- version: currentVersion,
85
- minRequiredVersion,
86
- requiresUpgrade,
62
+ deployed: false,
63
+ version: '',
64
+ minRequiredVersion: '',
65
+ requiresUpgrade: false,
87
66
  },
88
67
  };
89
68
  ctx.accountStatusCache = status;
90
69
  return status;
91
- });
70
+ }
71
+ const [currentVersion, minRequiredVersion] = await Promise.all([
72
+ (0, uea_manager_1.fetchUEAVersion)(ctx),
73
+ fetchLatestUEAVersion(ctx, vm),
74
+ ]);
75
+ const requiresUpgrade = (0, orchestrator_types_1.parseUEAVersion)(currentVersion) < (0, orchestrator_types_1.parseUEAVersion)(minRequiredVersion);
76
+ const status = {
77
+ mode: 'signer',
78
+ uea: {
79
+ loaded: true,
80
+ deployed: true,
81
+ version: currentVersion,
82
+ minRequiredVersion,
83
+ requiresUpgrade,
84
+ },
85
+ };
86
+ ctx.accountStatusCache = status;
87
+ return status;
92
88
  }
93
89
  // ============================================================================
94
90
  // UEA Upgrade
95
91
  // ============================================================================
96
- function upgradeAccount(ctx, options) {
97
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
98
- const hook = (options === null || options === void 0 ? void 0 : options.progressHook) || ctx.progressHook;
99
- const fireHook = (hookId, ...args) => {
100
- const hookEntry = progress_hook_1.default[hookId];
101
- if (hookEntry && hook) {
102
- hook(hookEntry(...args));
103
- }
104
- };
105
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_01);
106
- const status = yield getAccountStatus(ctx, { forceRefresh: true });
107
- if (!status.uea.requiresUpgrade) {
108
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9903);
109
- return;
92
+ async function upgradeAccount(ctx, options) {
93
+ const hook = options?.progressHook || ctx.progressHook;
94
+ const fireHook = (hookId, ...args) => {
95
+ const hookEntry = progress_hook_1.default[hookId];
96
+ if (hookEntry && hook) {
97
+ hook(hookEntry(...args));
110
98
  }
111
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_02);
112
- try {
113
- const { chain, address } = ctx.universalSigner.account;
114
- const { vm, chainId } = chain_1.CHAIN_INFO[chain];
115
- const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
116
- const migrationContractAddress = chain_1.UEA_MIGRATION[ctx.pushNetwork];
117
- if (!migrationContractAddress || migrationContractAddress === '0xTBD') {
118
- throw new Error('UEA migration contract address not configured');
119
- }
120
- const { nonce } = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
121
- const deadline = BigInt(9999999999);
122
- const ueaVersion = status.uea.version || '0.1.0';
123
- const signatureBytes = yield (0, signing_1.signMigrationPayload)(ctx, {
124
- migrationContractAddress,
125
- nonce,
126
- deadline,
127
- ueaVersion,
128
- ueaAddress,
129
- });
130
- const signature = (0, viem_1.bytesToHex)(signatureBytes);
131
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_03);
132
- const universalAccountId = {
133
- chainNamespace: chain_1.VM_NAMESPACE[vm],
134
- chainId,
135
- owner: vm === enums_1.VM.EVM
136
- ? address
137
- : vm === enums_1.VM.SVM
138
- ? (0, viem_1.bytesToHex)(new Uint8Array(bs58_1.bs58.decode(address)))
139
- : address,
140
- };
141
- const { cosmosAddress: signer } = ctx.pushClient.getSignerAddress();
142
- const msg = ctx.pushClient.createMsgMigrateUEA({
143
- signer,
144
- universalAccountId,
145
- migrationPayload: {
146
- migration: migrationContractAddress,
147
- nonce: nonce.toString(),
148
- deadline: deadline.toString(),
149
- },
150
- signature,
151
- });
152
- const txBody = yield ctx.pushClient.createCosmosTxBody([msg]);
153
- const txRaw = yield ctx.pushClient.signCosmosTx(txBody);
154
- const tx = yield ctx.pushClient.broadcastCosmosTx(txRaw);
155
- if (tx.code !== 0) {
156
- throw new Error(tx.rawLog || 'UEA migration transaction failed');
157
- }
158
- ctx.ueaVersionCache = undefined;
159
- const updated = yield getAccountStatus(ctx, { forceRefresh: true });
160
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9901, updated.uea.version);
99
+ };
100
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_01);
101
+ const status = await getAccountStatus(ctx, { forceRefresh: true });
102
+ if (!status.uea.requiresUpgrade) {
103
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9903);
104
+ return;
105
+ }
106
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_02);
107
+ try {
108
+ const { chain, address } = ctx.universalSigner.account;
109
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
110
+ const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
111
+ const migrationContractAddress = chain_1.UEA_MIGRATION[ctx.pushNetwork];
112
+ if (!migrationContractAddress || migrationContractAddress === '0xTBD') {
113
+ throw new Error('UEA migration contract address not configured');
161
114
  }
162
- catch (err) {
163
- fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9902);
164
- throw err;
115
+ const { nonce } = await (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
116
+ const deadline = BigInt(9999999999);
117
+ const ueaVersion = status.uea.version || '0.1.0';
118
+ const signatureBytes = await (0, signing_1.signMigrationPayload)(ctx, {
119
+ migrationContractAddress,
120
+ nonce,
121
+ deadline,
122
+ ueaVersion,
123
+ ueaAddress,
124
+ });
125
+ const signature = (0, viem_1.bytesToHex)(signatureBytes);
126
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_03);
127
+ const universalAccountId = {
128
+ chainNamespace: chain_1.VM_NAMESPACE[vm],
129
+ chainId,
130
+ owner: vm === enums_1.VM.EVM
131
+ ? address
132
+ : vm === enums_1.VM.SVM
133
+ ? (0, viem_1.bytesToHex)(new Uint8Array(bs58_1.bs58.decode(address)))
134
+ : address,
135
+ };
136
+ const { cosmosAddress: signer } = ctx.pushClient.getSignerAddress();
137
+ const msg = ctx.pushClient.createMsgMigrateUEA({
138
+ signer,
139
+ universalAccountId,
140
+ migrationPayload: {
141
+ migration: migrationContractAddress,
142
+ nonce: nonce.toString(),
143
+ deadline: deadline.toString(),
144
+ },
145
+ signature,
146
+ });
147
+ const txBody = await ctx.pushClient.createCosmosTxBody([msg]);
148
+ const txRaw = await ctx.pushClient.signCosmosTx(txBody);
149
+ const tx = await ctx.pushClient.broadcastCosmosTx(txRaw);
150
+ if (tx.code !== 0) {
151
+ throw new Error(tx.rawLog || 'UEA migration transaction failed');
165
152
  }
166
- });
153
+ ctx.ueaVersionCache = undefined;
154
+ const updated = await getAccountStatus(ctx, { forceRefresh: true });
155
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9901, updated.uea.version);
156
+ }
157
+ catch (err) {
158
+ fireHook(progress_hook_types_1.PROGRESS_HOOK.UEA_MIG_9902);
159
+ throw err;
160
+ }
167
161
  }
168
162
  // ============================================================================
169
163
  // CEA Migration
170
164
  // ============================================================================
171
- function migrateCEA(ctx, chain, executeFn) {
172
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
173
- var _a;
174
- if ((0, helpers_1.isPushChain)(chain)) {
175
- throw new Error('Cannot migrate CEA on Push Chain');
176
- }
177
- if (!(0, cea_utils_1.chainSupportsCEA)(chain)) {
178
- throw new Error(`Chain ${chain} does not support CEA`);
179
- }
180
- const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
181
- const { cea, isDeployed } = yield (0, cea_utils_1.getCEAAddress)(ueaAddress, chain, (_a = ctx.rpcUrls[chain]) === null || _a === void 0 ? void 0 : _a[0]);
182
- if (!isDeployed) {
183
- throw new Error(`CEA not deployed on chain ${chain}. Deploy CEA first.`);
184
- }
185
- return executeFn({
186
- to: { address: cea, chain },
187
- migration: true,
188
- });
165
+ async function migrateCEA(ctx, chain, executeFn) {
166
+ if ((0, helpers_1.isPushChain)(chain)) {
167
+ throw new Error('Cannot migrate CEA on Push Chain');
168
+ }
169
+ if (!(0, cea_utils_1.chainSupportsCEA)(chain)) {
170
+ throw new Error(`Chain ${chain} does not support CEA`);
171
+ }
172
+ const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
173
+ const { cea, isDeployed } = await (0, cea_utils_1.getCEAAddress)(ueaAddress, chain, ctx.rpcUrls[chain]?.[0]);
174
+ if (!isDeployed) {
175
+ throw new Error(`CEA not deployed on chain ${chain}. Deploy CEA first.`);
176
+ }
177
+ return executeFn({
178
+ to: { address: cea, chain },
179
+ migration: true,
189
180
  });
190
181
  }
191
182
  //# sourceMappingURL=account-manager.js.map
@@ -1,9 +1,3 @@
1
- /**
2
- * Cascade composition functions extracted from Orchestrator.
3
- *
4
- * Covers: prepareTransaction, buildHopDescriptor, classifyIntoSegments,
5
- * getSegmentType, composeCascade, createCascadedBuilder, createChainedBuilder.
6
- */
7
1
  import { TransactionRoute } from '../route-detector';
8
2
  import type { HopDescriptor, CascadeSegment, CascadeSegmentType, PreparedUniversalTx, CascadedTxResponse, CascadeHopInfo, UniversalTxResponse, UniversalExecuteParams, MultiCall, CascadeExecutionOptions, WaitForOutboundOptions, OutboundTxDetails } from '../orchestrator.types';
9
3
  import type { OrchestratorContext } from './context';