@pushchain/core 5.1.3 → 5.1.4-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 (131) hide show
  1. package/package.json +29 -6
  2. package/src/lib/constants/abi/prc20.evm.d.ts +22 -2
  3. package/src/lib/constants/abi/prc20.evm.js +11 -3
  4. package/src/lib/constants/abi/universalGatewayPC.evm.d.ts +59 -0
  5. package/src/lib/constants/abi/universalGatewayPC.evm.js +26 -0
  6. package/src/lib/constants/chain.d.ts +4 -0
  7. package/src/lib/constants/chain.js +6 -2
  8. package/src/lib/index.d.ts +2 -2
  9. package/src/lib/internal/bs58.d.ts +2 -0
  10. package/src/lib/internal/bs58.js +7 -0
  11. package/src/lib/orchestrator/cea-utils.d.ts +0 -9
  12. package/src/lib/orchestrator/cea-utils.js +15 -4
  13. package/src/lib/orchestrator/internals/account-manager.d.ts +16 -0
  14. package/src/lib/orchestrator/internals/account-manager.js +191 -0
  15. package/src/lib/orchestrator/internals/cascade.d.ts +23 -0
  16. package/src/lib/orchestrator/internals/cascade.js +945 -0
  17. package/src/lib/orchestrator/internals/confirmation.d.ts +9 -0
  18. package/src/lib/orchestrator/internals/confirmation.js +123 -0
  19. package/src/lib/orchestrator/internals/context.d.ts +38 -0
  20. package/src/lib/orchestrator/internals/context.js +49 -0
  21. package/src/lib/orchestrator/internals/execute-funds-only.d.ts +11 -0
  22. package/src/lib/orchestrator/internals/execute-funds-only.js +219 -0
  23. package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +11 -0
  24. package/src/lib/orchestrator/internals/execute-funds-payload.js +222 -0
  25. package/src/lib/orchestrator/internals/execute-standard.d.ts +13 -0
  26. package/src/lib/orchestrator/internals/execute-standard.js +225 -0
  27. package/src/lib/orchestrator/internals/gas-calculator.d.ts +38 -0
  28. package/src/lib/orchestrator/internals/gas-calculator.js +424 -0
  29. package/src/lib/orchestrator/internals/gateway-client.d.ts +24 -0
  30. package/src/lib/orchestrator/internals/gateway-client.js +191 -0
  31. package/src/lib/orchestrator/internals/helpers.d.ts +26 -0
  32. package/src/lib/orchestrator/internals/helpers.js +181 -0
  33. package/src/lib/orchestrator/internals/index.d.ts +24 -0
  34. package/src/lib/orchestrator/internals/index.js +132 -0
  35. package/src/lib/orchestrator/internals/outbound-sync.d.ts +49 -0
  36. package/src/lib/orchestrator/internals/outbound-sync.js +357 -0
  37. package/src/lib/orchestrator/internals/outbound-tracker.d.ts +8 -0
  38. package/src/lib/orchestrator/internals/outbound-tracker.js +64 -0
  39. package/src/lib/orchestrator/internals/payload-builder.d.ts +24 -0
  40. package/src/lib/orchestrator/internals/payload-builder.js +178 -0
  41. package/src/lib/orchestrator/internals/push-chain-tx.d.ts +32 -0
  42. package/src/lib/orchestrator/internals/push-chain-tx.js +207 -0
  43. package/src/lib/orchestrator/internals/quote.d.ts +9 -0
  44. package/src/lib/orchestrator/internals/quote.js +114 -0
  45. package/src/lib/orchestrator/internals/rescue.d.ts +20 -0
  46. package/src/lib/orchestrator/internals/rescue.js +112 -0
  47. package/src/lib/orchestrator/internals/response-builder.d.ts +26 -0
  48. package/src/lib/orchestrator/internals/response-builder.js +504 -0
  49. package/src/lib/orchestrator/internals/route-handlers.d.ts +77 -0
  50. package/src/lib/orchestrator/internals/route-handlers.js +1192 -0
  51. package/src/lib/orchestrator/internals/signing.d.ts +27 -0
  52. package/src/lib/orchestrator/internals/signing.js +258 -0
  53. package/src/lib/orchestrator/internals/svm-bridge.d.ts +21 -0
  54. package/src/lib/orchestrator/internals/svm-bridge.js +122 -0
  55. package/src/lib/orchestrator/internals/svm-helpers.d.ts +35 -0
  56. package/src/lib/orchestrator/internals/svm-helpers.js +143 -0
  57. package/src/lib/orchestrator/internals/tx-transformer.d.ts +12 -0
  58. package/src/lib/orchestrator/internals/tx-transformer.js +120 -0
  59. package/src/lib/orchestrator/internals/uea-manager.d.ts +17 -0
  60. package/src/lib/orchestrator/internals/uea-manager.js +164 -0
  61. package/src/lib/orchestrator/orchestrator.d.ts +33 -431
  62. package/src/lib/orchestrator/orchestrator.js +124 -6125
  63. package/src/lib/orchestrator/orchestrator.types.d.ts +11 -10
  64. package/src/lib/orchestrator/payload-builders.js +34 -8
  65. package/src/lib/price-fetch/price-fetch.js +19 -7
  66. package/src/lib/push-chain/push-chain.d.ts +6 -0
  67. package/src/lib/push-chain/push-chain.js +10 -2
  68. package/src/lib/push-client/push-client.d.ts +3 -0
  69. package/src/lib/push-client/push-client.js +21 -31
  70. package/src/lib/universal/account/account.d.ts +35 -16
  71. package/src/lib/universal/account/account.js +298 -16
  72. package/src/lib/universal/signer/signer.d.ts +2 -3
  73. package/src/lib/universal/signer/signer.js +65 -115
  74. package/src/lib/universal/universal.types.d.ts +41 -0
  75. package/src/lib/utils.d.ts +7 -2
  76. package/src/lib/utils.js +65 -34
  77. package/src/lib/vm-client/evm-client.js +3 -11
  78. package/src/lib/vm-client/svm-client.d.ts +0 -4
  79. package/src/lib/vm-client/svm-client.js +2 -8
  80. package/src/index.js.map +0 -1
  81. package/src/lib/cache/cache.js.map +0 -1
  82. package/src/lib/constants/abi/cea.evm.js.map +0 -1
  83. package/src/lib/constants/abi/ceaFactory.evm.js.map +0 -1
  84. package/src/lib/constants/abi/erc20.evm.js.map +0 -1
  85. package/src/lib/constants/abi/factoryV1.js.map +0 -1
  86. package/src/lib/constants/abi/feeLocker.evm.js.map +0 -1
  87. package/src/lib/constants/abi/index.js.map +0 -1
  88. package/src/lib/constants/abi/prc20.evm.js.map +0 -1
  89. package/src/lib/constants/abi/uea-factory.js.map +0 -1
  90. package/src/lib/constants/abi/uea.evm.js.map +0 -1
  91. package/src/lib/constants/abi/uea.svm.js.map +0 -1
  92. package/src/lib/constants/abi/universalGateway.evm.js.map +0 -1
  93. package/src/lib/constants/abi/universalGatewayPC.evm.js.map +0 -1
  94. package/src/lib/constants/abi/universalGatewayV0.evm.js.map +0 -1
  95. package/src/lib/constants/chain.js.map +0 -1
  96. package/src/lib/constants/enums.js.map +0 -1
  97. package/src/lib/constants/index.js.map +0 -1
  98. package/src/lib/constants/selectors.js.map +0 -1
  99. package/src/lib/constants/tokens.js.map +0 -1
  100. package/src/lib/generated/uexecutor/v1/query.js.map +0 -1
  101. package/src/lib/generated/uexecutor/v1/types.js.map +0 -1
  102. package/src/lib/generated/uexecutor/v2/index.js.map +0 -1
  103. package/src/lib/generated/uexecutor/v2/query.js.map +0 -1
  104. package/src/lib/generated/uexecutor/v2/types.js.map +0 -1
  105. package/src/lib/generated/v1/tx.js.map +0 -1
  106. package/src/lib/index.js.map +0 -1
  107. package/src/lib/internal/buffer.js.map +0 -1
  108. package/src/lib/internal/global-buffer-polyfill.js.map +0 -1
  109. package/src/lib/orchestrator/cea-utils.js.map +0 -1
  110. package/src/lib/orchestrator/orchestrator.js.map +0 -1
  111. package/src/lib/orchestrator/orchestrator.types.js.map +0 -1
  112. package/src/lib/orchestrator/payload-builders.js.map +0 -1
  113. package/src/lib/orchestrator/route-detector.js.map +0 -1
  114. package/src/lib/price-fetch/price-fetch.js.map +0 -1
  115. package/src/lib/progress-hook/progress-hook.js.map +0 -1
  116. package/src/lib/progress-hook/progress-hook.types.js.map +0 -1
  117. package/src/lib/push-chain/helpers/abis.js.map +0 -1
  118. package/src/lib/push-chain/helpers/addresses.js.map +0 -1
  119. package/src/lib/push-chain/push-chain.js.map +0 -1
  120. package/src/lib/push-client/push-client.js.map +0 -1
  121. package/src/lib/push-client/push-client.types.js.map +0 -1
  122. package/src/lib/universal/account/account.js.map +0 -1
  123. package/src/lib/universal/account/index.js.map +0 -1
  124. package/src/lib/universal/signer/index.js.map +0 -1
  125. package/src/lib/universal/signer/signer.js.map +0 -1
  126. package/src/lib/universal/signer/signer.types.js.map +0 -1
  127. package/src/lib/universal/universal.types.js.map +0 -1
  128. package/src/lib/utils.js.map +0 -1
  129. package/src/lib/vm-client/evm-client.js.map +0 -1
  130. package/src/lib/vm-client/svm-client.js.map +0 -1
  131. package/src/lib/vm-client/vm-client.types.js.map +0 -1
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Signing and payload encoding functions extracted from Orchestrator.
3
+ */
4
+ import type { UniversalPayload } from '../../generated/v1/tx';
5
+ import type { OrchestratorContext } from './context';
6
+ export declare function computeExecutionHash(ctx: OrchestratorContext, { verifyingContract, payload, version, }: {
7
+ verifyingContract: `0x${string}`;
8
+ version?: string;
9
+ payload: UniversalPayload;
10
+ }): `0x${string}`;
11
+ export declare function computeMigrationHash(ctx: OrchestratorContext, { verifyingContract, migrationContractAddress, nonce, deadline, version, }: {
12
+ verifyingContract: `0x${string}`;
13
+ migrationContractAddress: `0x${string}`;
14
+ nonce: bigint;
15
+ deadline: bigint;
16
+ version?: string;
17
+ }): `0x${string}`;
18
+ export declare function signUniversalPayload(ctx: OrchestratorContext, universalPayload: UniversalPayload, verifyingContract: `0x${string}`, version?: string): Promise<Uint8Array>;
19
+ export declare function signMigrationPayload(ctx: OrchestratorContext, { migrationContractAddress, nonce, deadline, ueaVersion, ueaAddress, }: {
20
+ migrationContractAddress: `0x${string}`;
21
+ nonce: bigint;
22
+ deadline: bigint;
23
+ ueaVersion: string;
24
+ ueaAddress: `0x${string}`;
25
+ }): Promise<Uint8Array>;
26
+ export declare function encodeUniversalPayload(payload: UniversalPayload): `0x${string}`;
27
+ export declare function encodeUniversalPayloadSvm(payload: UniversalPayload): Buffer;
@@ -0,0 +1,258 @@
1
+ "use strict";
2
+ /**
3
+ * Signing and payload encoding functions extracted from Orchestrator.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.computeExecutionHash = computeExecutionHash;
7
+ exports.computeMigrationHash = computeMigrationHash;
8
+ exports.signUniversalPayload = signUniversalPayload;
9
+ exports.signMigrationPayload = signMigrationPayload;
10
+ exports.encodeUniversalPayload = encodeUniversalPayload;
11
+ exports.encodeUniversalPayloadSvm = encodeUniversalPayloadSvm;
12
+ const tslib_1 = require("tslib");
13
+ const viem_1 = require("viem");
14
+ const chain_1 = require("../../constants/chain");
15
+ const enums_1 = require("../../constants/enums");
16
+ // ============================================================================
17
+ // EIP-712 Domain Separator (shared by execution & migration hashes)
18
+ // ============================================================================
19
+ function buildDomainSeparator(vm, chainId, version, verifyingContract) {
20
+ const domainTypeHash = (0, viem_1.keccak256)((0, viem_1.toBytes)(vm === enums_1.VM.EVM
21
+ ? 'EIP712Domain(string version,uint256 chainId,address verifyingContract)'
22
+ : 'EIP712Domain_SVM(string version,string chainId,address verifyingContract)'));
23
+ return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
24
+ { name: 'typeHash', type: 'bytes32' },
25
+ { name: 'version', type: 'bytes32' },
26
+ { name: 'chainId', type: vm === enums_1.VM.EVM ? 'uint256' : 'string' },
27
+ { name: 'verifyingContract', type: 'address' },
28
+ ], [
29
+ domainTypeHash,
30
+ (0, viem_1.keccak256)((0, viem_1.toBytes)(version)),
31
+ vm === enums_1.VM.EVM ? BigInt(chainId) : chainId,
32
+ verifyingContract,
33
+ ]));
34
+ }
35
+ // ============================================================================
36
+ // EIP-712 Hash Computation
37
+ // ============================================================================
38
+ function computeExecutionHash(ctx, { verifyingContract, payload, version = '0.1.0', }) {
39
+ const chain = ctx.universalSigner.account.chain;
40
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
41
+ const typeHash = (0, viem_1.keccak256)((0, viem_1.toBytes)('UniversalPayload(address to,uint256 value,bytes data,uint256 gasLimit,uint256 maxFeePerGas,uint256 maxPriorityFeePerGas,uint256 nonce,uint256 deadline,uint8 vType)'));
42
+ const domainSeparator = buildDomainSeparator(vm, chainId, version, verifyingContract);
43
+ const structHash = (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
44
+ { name: 'typeHash', type: 'bytes32' },
45
+ { name: 'to', type: 'address' },
46
+ { name: 'value', type: 'uint256' },
47
+ { name: 'data', type: 'bytes32' },
48
+ { name: 'gasLimit', type: 'uint256' },
49
+ { name: 'maxFeePerGas', type: 'uint256' },
50
+ { name: 'maxPriorityFeePerGas', type: 'uint256' },
51
+ { name: 'nonce', type: 'uint256' },
52
+ { name: 'deadline', type: 'uint256' },
53
+ { name: 'vType', type: 'uint8' },
54
+ ], [
55
+ typeHash,
56
+ payload.to,
57
+ BigInt(payload.value),
58
+ (0, viem_1.keccak256)(payload.data),
59
+ BigInt(payload.gasLimit),
60
+ BigInt(payload.maxFeePerGas),
61
+ BigInt(payload.maxPriorityFeePerGas),
62
+ BigInt(payload.nonce),
63
+ BigInt(payload.deadline),
64
+ payload.vType,
65
+ ]));
66
+ return (0, viem_1.keccak256)((0, viem_1.encodePacked)(['string', 'bytes32', 'bytes32'], ['\x19\x01', domainSeparator, structHash]));
67
+ }
68
+ function computeMigrationHash(ctx, { verifyingContract, migrationContractAddress, nonce, deadline, version = '0.1.0', }) {
69
+ const chain = ctx.universalSigner.account.chain;
70
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
71
+ const typeHash = (0, viem_1.keccak256)((0, viem_1.toBytes)('MigrationPayload(address migration,uint256 nonce,uint256 deadline)'));
72
+ const domainSeparator = buildDomainSeparator(vm, chainId, version, verifyingContract);
73
+ const structHash = (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([
74
+ { name: 'typeHash', type: 'bytes32' },
75
+ { name: 'migration', type: 'address' },
76
+ { name: 'nonce', type: 'uint256' },
77
+ { name: 'deadline', type: 'uint256' },
78
+ ], [typeHash, migrationContractAddress, nonce, deadline]));
79
+ return (0, viem_1.keccak256)((0, viem_1.encodePacked)(['string', 'bytes32', 'bytes32'], ['\x19\x01', domainSeparator, structHash]));
80
+ }
81
+ // ============================================================================
82
+ // Payload Signing
83
+ // ============================================================================
84
+ function signUniversalPayload(ctx, universalPayload, verifyingContract, version) {
85
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
86
+ const chain = ctx.universalSigner.account.chain;
87
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
88
+ switch (vm) {
89
+ case enums_1.VM.EVM: {
90
+ if (!ctx.universalSigner.signTypedData) {
91
+ throw new Error('signTypedData is not defined');
92
+ }
93
+ return ctx.universalSigner.signTypedData({
94
+ domain: {
95
+ version: version || '0.1.0',
96
+ chainId: Number(chainId),
97
+ verifyingContract,
98
+ },
99
+ types: {
100
+ UniversalPayload: [
101
+ { name: 'to', type: 'address' },
102
+ { name: 'value', type: 'uint256' },
103
+ { name: 'data', type: 'bytes' },
104
+ { name: 'gasLimit', type: 'uint256' },
105
+ { name: 'maxFeePerGas', type: 'uint256' },
106
+ { name: 'maxPriorityFeePerGas', type: 'uint256' },
107
+ { name: 'nonce', type: 'uint256' },
108
+ { name: 'deadline', type: 'uint256' },
109
+ { name: 'vType', type: 'uint8' },
110
+ ],
111
+ },
112
+ primaryType: 'UniversalPayload',
113
+ message: universalPayload,
114
+ });
115
+ }
116
+ case enums_1.VM.SVM: {
117
+ const digest = computeExecutionHash(ctx, {
118
+ verifyingContract,
119
+ payload: universalPayload,
120
+ version: version || '0.1.0',
121
+ });
122
+ return ctx.universalSigner.signMessage((0, viem_1.stringToBytes)(digest));
123
+ }
124
+ default:
125
+ throw new Error(`Unsupported VM type: ${vm}`);
126
+ }
127
+ });
128
+ }
129
+ function signMigrationPayload(ctx_1, _a) {
130
+ return tslib_1.__awaiter(this, arguments, void 0, function* (ctx, { migrationContractAddress, nonce, deadline, ueaVersion, ueaAddress, }) {
131
+ const chain = ctx.universalSigner.account.chain;
132
+ const { vm, chainId } = chain_1.CHAIN_INFO[chain];
133
+ switch (vm) {
134
+ case enums_1.VM.EVM: {
135
+ if (!ctx.universalSigner.signTypedData) {
136
+ throw new Error('signTypedData is not defined');
137
+ }
138
+ return ctx.universalSigner.signTypedData({
139
+ domain: {
140
+ version: ueaVersion,
141
+ chainId: Number(chainId),
142
+ verifyingContract: ueaAddress,
143
+ },
144
+ types: {
145
+ MigrationPayload: [
146
+ { name: 'migration', type: 'address' },
147
+ { name: 'nonce', type: 'uint256' },
148
+ { name: 'deadline', type: 'uint256' },
149
+ ],
150
+ },
151
+ primaryType: 'MigrationPayload',
152
+ message: {
153
+ migration: migrationContractAddress,
154
+ nonce: nonce.toString(),
155
+ deadline: deadline.toString(),
156
+ },
157
+ });
158
+ }
159
+ case enums_1.VM.SVM: {
160
+ const digest = computeMigrationHash(ctx, {
161
+ verifyingContract: ueaAddress,
162
+ migrationContractAddress,
163
+ nonce,
164
+ deadline,
165
+ version: ueaVersion,
166
+ });
167
+ return ctx.universalSigner.signMessage((0, viem_1.stringToBytes)(digest));
168
+ }
169
+ default:
170
+ throw new Error(`Unsupported VM type for migration: ${vm}`);
171
+ }
172
+ });
173
+ }
174
+ // ============================================================================
175
+ // Payload Encoding
176
+ // ============================================================================
177
+ function encodeUniversalPayload(payload) {
178
+ return (0, viem_1.encodeAbiParameters)([
179
+ { name: 'to', type: 'address' },
180
+ { name: 'value', type: 'uint256' },
181
+ { name: 'data', type: 'bytes' },
182
+ { name: 'gasLimit', type: 'uint256' },
183
+ { name: 'maxFeePerGas', type: 'uint256' },
184
+ { name: 'maxPriorityFeePerGas', type: 'uint256' },
185
+ { name: 'nonce', type: 'uint256' },
186
+ { name: 'deadline', type: 'uint256' },
187
+ { name: 'vType', type: 'uint8' },
188
+ ], [
189
+ payload.to,
190
+ BigInt(payload.value),
191
+ payload.data,
192
+ BigInt(payload.gasLimit),
193
+ BigInt(payload.maxFeePerGas),
194
+ BigInt(payload.maxPriorityFeePerGas),
195
+ BigInt(payload.nonce),
196
+ BigInt(payload.deadline),
197
+ Number(payload.vType),
198
+ ]);
199
+ }
200
+ function encodeUniversalPayloadSvm(payload) {
201
+ const writeU64 = (val) => {
202
+ const b = Buffer.alloc(8);
203
+ b.writeBigUInt64LE(BigInt(val), 0);
204
+ return b;
205
+ };
206
+ const writeI64 = (val) => {
207
+ const b = Buffer.alloc(8);
208
+ b.writeBigInt64LE(BigInt(val), 0);
209
+ return b;
210
+ };
211
+ const writeVecU8 = (val) => {
212
+ const bytes = Buffer.isBuffer(val)
213
+ ? val
214
+ : Buffer.from(val);
215
+ const len = Buffer.alloc(4);
216
+ len.writeUInt32LE(bytes.length, 0);
217
+ return Buffer.concat([len, bytes]);
218
+ };
219
+ const writeU8 = (val) => Buffer.from([val]);
220
+ const toAddrBytes = (() => {
221
+ const to = payload.to;
222
+ const hex = to.slice(2).padStart(40, '0');
223
+ return Buffer.from(hex, 'hex');
224
+ })();
225
+ const valueBytes = writeU64(payload.value);
226
+ const dataBytes = (() => {
227
+ const data = payload.data;
228
+ const hex = data.slice(2);
229
+ const buf = hex.length ? Buffer.from(hex, 'hex') : Buffer.alloc(0);
230
+ return writeVecU8(buf);
231
+ })();
232
+ const gasLimitBytes = writeU64(payload.gasLimit);
233
+ const maxFeePerGasBytes = writeU64(payload.maxFeePerGas);
234
+ const maxPriorityFeePerGasBytes = writeU64(payload.maxPriorityFeePerGas);
235
+ const nonceBytes = writeU64(payload.nonce);
236
+ const deadlineBytes = writeI64(payload.deadline);
237
+ const vTypeVal = (() => {
238
+ const v = payload.vType;
239
+ if (typeof v === 'number')
240
+ return v;
241
+ if (typeof v === 'string')
242
+ return Number(v);
243
+ return 0;
244
+ })();
245
+ const vTypeBytes = writeU8(vTypeVal);
246
+ return Buffer.concat([
247
+ toAddrBytes,
248
+ valueBytes,
249
+ dataBytes,
250
+ gasLimitBytes,
251
+ maxFeePerGasBytes,
252
+ maxPriorityFeePerGasBytes,
253
+ nonceBytes,
254
+ deadlineBytes,
255
+ vTypeBytes,
256
+ ]);
257
+ }
258
+ //# sourceMappingURL=signing.js.map
@@ -0,0 +1,21 @@
1
+ /**
2
+ * SVM (Solana) bridge transaction for funds+payload flow —
3
+ * extracted from Orchestrator._sendSVMTxWithFunds.
4
+ *
5
+ * Handles both native SOL and SPL token bridging with universal payload signing.
6
+ */
7
+ import type { UniversalPayload } from '../../generated/v1/tx';
8
+ import type { ExecuteParams, UniversalTxRequest } from '../orchestrator.types';
9
+ import type { OrchestratorContext } from './context';
10
+ /**
11
+ * Sends a Solana gateway transaction for the funds+payload bridge path.
12
+ * Handles native SOL and SPL token mechanisms.
13
+ */
14
+ export declare function sendSVMTxWithFunds(ctx: OrchestratorContext, params: {
15
+ execute: ExecuteParams;
16
+ mechanism: 'native' | 'approve' | 'permit2' | string;
17
+ universalPayload: UniversalPayload;
18
+ bridgeAmount: bigint;
19
+ nativeAmount: bigint;
20
+ req: UniversalTxRequest;
21
+ }): Promise<string>;
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /**
3
+ * SVM (Solana) bridge transaction for funds+payload flow —
4
+ * extracted from Orchestrator._sendSVMTxWithFunds.
5
+ *
6
+ * Handles both native SOL and SPL token bridging with universal payload signing.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.sendSVMTxWithFunds = sendSVMTxWithFunds;
10
+ const tslib_1 = require("tslib");
11
+ const web3_js_1 = require("@solana/web3.js");
12
+ const viem_1 = require("viem");
13
+ const universalGatewayV0_json_1 = tslib_1.__importDefault(require("../../constants/abi/universalGatewayV0.json"));
14
+ const chain_1 = require("../../constants/chain");
15
+ const enums_1 = require("../../constants/enums");
16
+ const svm_client_1 = require("../../vm-client/svm-client");
17
+ const svm_helpers_1 = require("./svm-helpers");
18
+ const signing_1 = require("./signing");
19
+ const uea_manager_1 = require("./uea-manager");
20
+ // ============================================================================
21
+ // sendSVMTxWithFunds
22
+ // ============================================================================
23
+ /**
24
+ * Sends a Solana gateway transaction for the funds+payload bridge path.
25
+ * Handles native SOL and SPL token mechanisms.
26
+ */
27
+ function sendSVMTxWithFunds(ctx, params) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ var _a, _b;
30
+ const { execute, mechanism, universalPayload, bridgeAmount, nativeAmount, req } = params;
31
+ const svmClient = new svm_client_1.SvmClient({
32
+ rpcUrls: ctx.rpcUrls[enums_1.CHAIN.SOLANA_DEVNET] ||
33
+ chain_1.CHAIN_INFO[enums_1.CHAIN.SOLANA_DEVNET].defaultRPC,
34
+ });
35
+ const programId = new web3_js_1.PublicKey(universalGatewayV0_json_1.default.address);
36
+ const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
37
+ const [vaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('vault')], programId);
38
+ const userPk = new web3_js_1.PublicKey(ctx.universalSigner.account.address);
39
+ const priceUpdatePk = new web3_js_1.PublicKey(chain_1.SVM_PYTH_PRICE_FEED);
40
+ const [rateLimitConfigPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit_config')], programId);
41
+ if (execute.payGasWith !== undefined) {
42
+ throw new Error('Pay-with token is not supported on Solana');
43
+ }
44
+ if (!((_b = (_a = execute.funds) === null || _a === void 0 ? void 0 : _a.token) === null || _b === void 0 ? void 0 : _b.address)) {
45
+ throw new Error('Token address is required for bridge path');
46
+ }
47
+ const isNative = mechanism === 'native' || execute.funds.token.symbol === 'SOL';
48
+ const { feeVaultPda, protocolFeeLamports } = yield (0, svm_helpers_1.getSvmProtocolFee)(svmClient, programId);
49
+ const ueaAddressSvm = (0, uea_manager_1.computeUEAOffchain)(ctx);
50
+ const ueaVersion = yield (0, uea_manager_1.fetchUEAVersion)(ctx);
51
+ const svmSignature = yield (0, signing_1.signUniversalPayload)(ctx, universalPayload, ueaAddressSvm, ueaVersion);
52
+ if (isNative) {
53
+ const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), web3_js_1.PublicKey.default.toBuffer()], programId);
54
+ const nativeReq = (0, svm_helpers_1.buildSvmUniversalTxRequest)({
55
+ recipient: Array.from(Buffer.alloc(20, 0)),
56
+ token: web3_js_1.PublicKey.default,
57
+ amount: bridgeAmount,
58
+ payload: Uint8Array.from((0, signing_1.encodeUniversalPayloadSvm)(universalPayload)),
59
+ revertRecipient: userPk,
60
+ signatureData: svmSignature,
61
+ });
62
+ return yield svmClient.writeContract({
63
+ abi: universalGatewayV0_json_1.default,
64
+ address: programId.toBase58(),
65
+ functionName: 'sendUniversalTx',
66
+ args: [nativeReq, nativeAmount + protocolFeeLamports],
67
+ signer: ctx.universalSigner,
68
+ accounts: {
69
+ config: configPda,
70
+ vault: vaultPda,
71
+ feeVault: feeVaultPda,
72
+ userTokenAccount: vaultPda,
73
+ gatewayTokenAccount: vaultPda,
74
+ user: userPk,
75
+ priceUpdate: priceUpdatePk,
76
+ tokenProgram: new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
77
+ rateLimitConfig: rateLimitConfigPda,
78
+ tokenRateLimit: tokenRateLimitPda,
79
+ systemProgram: web3_js_1.SystemProgram.programId,
80
+ },
81
+ });
82
+ }
83
+ else {
84
+ // Token address already validated above (line 67)
85
+ const mintPk = new web3_js_1.PublicKey(execute.funds.token.address);
86
+ const TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
87
+ const ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
88
+ const userAta = web3_js_1.PublicKey.findProgramAddressSync([userPk.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
89
+ const vaultAta = web3_js_1.PublicKey.findProgramAddressSync([vaultPda.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
90
+ const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), mintPk.toBuffer()], programId);
91
+ const splReq = (0, svm_helpers_1.buildSvmUniversalTxRequest)({
92
+ recipient: Array.from(Buffer.alloc(20, 0)),
93
+ token: mintPk,
94
+ amount: bridgeAmount,
95
+ payload: Uint8Array.from((0, signing_1.encodeUniversalPayloadSvm)(universalPayload)),
96
+ revertRecipient: userPk,
97
+ signatureData: svmSignature,
98
+ });
99
+ return yield svmClient.writeContract({
100
+ abi: universalGatewayV0_json_1.default,
101
+ address: programId.toBase58(),
102
+ functionName: 'sendUniversalTx',
103
+ args: [splReq, nativeAmount + protocolFeeLamports],
104
+ signer: ctx.universalSigner,
105
+ accounts: {
106
+ config: configPda,
107
+ vault: vaultPda,
108
+ feeVault: feeVaultPda,
109
+ userTokenAccount: userAta,
110
+ gatewayTokenAccount: vaultAta,
111
+ user: userPk,
112
+ priceUpdate: priceUpdatePk,
113
+ tokenProgram: TOKEN_PROGRAM_ID,
114
+ rateLimitConfig: rateLimitConfigPda,
115
+ tokenRateLimit: tokenRateLimitPda,
116
+ systemProgram: web3_js_1.SystemProgram.programId,
117
+ },
118
+ });
119
+ }
120
+ });
121
+ }
122
+ //# sourceMappingURL=svm-bridge.js.map
@@ -0,0 +1,35 @@
1
+ /**
2
+ * SVM (Solana) specific helper functions extracted from Orchestrator.
3
+ */
4
+ import { PublicKey } from '@solana/web3.js';
5
+ import type { UniversalTxRequest } from '../orchestrator.types';
6
+ export declare function buildSvmUniversalTxRequest({ recipient, token, amount, payload, revertRecipient, signatureData, }: {
7
+ recipient: number[];
8
+ token: PublicKey;
9
+ amount: bigint;
10
+ payload: `0x${string}` | Uint8Array;
11
+ revertRecipient: PublicKey;
12
+ signatureData?: Uint8Array | `0x${string}`;
13
+ }): {
14
+ recipient: number[];
15
+ token: PublicKey;
16
+ amount: bigint;
17
+ payload: Buffer;
18
+ revertRecipient: PublicKey;
19
+ signatureData: Buffer;
20
+ };
21
+ export declare function buildSvmUniversalTxRequestFromReq(req: UniversalTxRequest, revertRecipient: PublicKey, signatureDataOverride?: Uint8Array | `0x${string}`): {
22
+ recipient: number[];
23
+ token: PublicKey;
24
+ amount: bigint;
25
+ payload: Buffer;
26
+ revertRecipient: PublicKey;
27
+ signatureData: Buffer;
28
+ };
29
+ export declare function getSvmProtocolFee(svmClient: {
30
+ readContract: (args: any) => Promise<any>;
31
+ }, programId: PublicKey): Promise<{
32
+ feeVaultPda: PublicKey;
33
+ protocolFeeLamports: bigint;
34
+ }>;
35
+ export declare function getSvmGatewayLogIndexFromTx(txResp: any): number;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ /**
3
+ * SVM (Solana) specific helper functions extracted from Orchestrator.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.buildSvmUniversalTxRequest = buildSvmUniversalTxRequest;
7
+ exports.buildSvmUniversalTxRequestFromReq = buildSvmUniversalTxRequestFromReq;
8
+ exports.getSvmProtocolFee = getSvmProtocolFee;
9
+ exports.getSvmGatewayLogIndexFromTx = getSvmGatewayLogIndexFromTx;
10
+ const tslib_1 = require("tslib");
11
+ const web3_js_1 = require("@solana/web3.js");
12
+ const viem_1 = require("viem");
13
+ const universalGatewayV0_json_1 = tslib_1.__importDefault(require("../../constants/abi/universalGatewayV0.json"));
14
+ // ============================================================================
15
+ // SVM Request Builders
16
+ // ============================================================================
17
+ function buildSvmUniversalTxRequest({ recipient, token, amount, payload, revertRecipient, signatureData, }) {
18
+ const payloadBuf = typeof payload === 'string' && payload.startsWith('0x')
19
+ ? (() => {
20
+ const hex = payload.slice(2);
21
+ if (!hex.length)
22
+ return Buffer.alloc(0);
23
+ const normalized = hex.length % 2 === 1 ? `0${hex}` : hex;
24
+ return Buffer.from(normalized, 'hex');
25
+ })()
26
+ : Buffer.from(payload);
27
+ let signatureBuf;
28
+ if (!signatureData) {
29
+ signatureBuf = Buffer.alloc(0);
30
+ }
31
+ else if (typeof signatureData === 'string' &&
32
+ signatureData.startsWith('0x')) {
33
+ const hex = signatureData.slice(2);
34
+ if (!hex.length) {
35
+ signatureBuf = Buffer.alloc(0);
36
+ }
37
+ else {
38
+ const normalized = hex.length % 2 === 1 ? `0${hex}` : hex;
39
+ signatureBuf = Buffer.from(normalized, 'hex');
40
+ }
41
+ }
42
+ else {
43
+ signatureBuf = Buffer.from(signatureData);
44
+ }
45
+ return {
46
+ recipient,
47
+ token,
48
+ amount,
49
+ payload: payloadBuf,
50
+ revertRecipient,
51
+ signatureData: signatureBuf,
52
+ };
53
+ }
54
+ function buildSvmUniversalTxRequestFromReq(req, revertRecipient, signatureDataOverride) {
55
+ const recipientBytes = (0, viem_1.hexToBytes)(req.recipient);
56
+ const recipient = Array.from(recipientBytes.subarray(0, 20));
57
+ const tokenAddress = req.token;
58
+ let token;
59
+ if (tokenAddress === viem_1.zeroAddress || tokenAddress === 'solana-native') {
60
+ token = web3_js_1.PublicKey.default;
61
+ }
62
+ else {
63
+ if (!tokenAddress.startsWith('0x')) {
64
+ throw new Error('Unsupported token format for SVM UniversalTxRequest: ' + tokenAddress);
65
+ }
66
+ const token20 = (0, viem_1.hexToBytes)(tokenAddress);
67
+ const token32 = new Uint8Array(32);
68
+ token32.set(token20, 12);
69
+ token = new web3_js_1.PublicKey(token32);
70
+ }
71
+ return buildSvmUniversalTxRequest({
72
+ recipient,
73
+ token,
74
+ amount: req.amount,
75
+ payload: req.payload,
76
+ revertRecipient,
77
+ signatureData: signatureDataOverride !== null && signatureDataOverride !== void 0 ? signatureDataOverride : req.signatureData,
78
+ });
79
+ }
80
+ // ============================================================================
81
+ // SVM Protocol Fee
82
+ // ============================================================================
83
+ function getSvmProtocolFee(svmClient, programId) {
84
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
85
+ var _a, _b, _c;
86
+ const [feeVaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('fee_vault')], programId);
87
+ try {
88
+ const feeVault = yield svmClient.readContract({
89
+ abi: universalGatewayV0_json_1.default,
90
+ address: universalGatewayV0_json_1.default.address,
91
+ functionName: 'feeVault',
92
+ args: [feeVaultPda.toBase58()],
93
+ });
94
+ const protocolFeeLamports = BigInt((_c = (_b = ((_a = feeVault.protocolFeeLamports) !== null && _a !== void 0 ? _a : feeVault.protocol_fee_lamports)) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '0');
95
+ return { feeVaultPda, protocolFeeLamports };
96
+ }
97
+ catch (_d) {
98
+ return { feeVaultPda, protocolFeeLamports: BigInt(0) };
99
+ }
100
+ });
101
+ }
102
+ // ============================================================================
103
+ // SVM Log Parsing
104
+ // ============================================================================
105
+ /** Anchor event discriminator for the SVM gateway's UniversalTxSent event */
106
+ const SVM_GATEWAY_EVENT_DISCRIMINATOR = '6c9ad829b5ea1d7c';
107
+ // ============================================================================
108
+ // ============================================================================
109
+ function getSvmGatewayLogIndexFromTx(txResp) {
110
+ var _a;
111
+ const logs = (((_a = txResp === null || txResp === void 0 ? void 0 : txResp.meta) === null || _a === void 0 ? void 0 : _a.logMessages) || []);
112
+ if (!Array.isArray(logs) || logs.length === 0)
113
+ return 0;
114
+ const prefix = 'Program data: ';
115
+ let matchCount = 0;
116
+ let lastMatchIndex = -1;
117
+ for (let i = 0; i < logs.length; i++) {
118
+ const log = logs[i] || '';
119
+ if (!log.startsWith(prefix))
120
+ continue;
121
+ const base64Data = log.slice(prefix.length).trim();
122
+ let decoded = null;
123
+ try {
124
+ decoded = new Uint8Array(Buffer.from(base64Data, 'base64'));
125
+ }
126
+ catch (_b) {
127
+ continue;
128
+ }
129
+ if (!decoded || decoded.length < 8)
130
+ continue;
131
+ const discriminatorHex = (0, viem_1.bytesToHex)(decoded.slice(0, 8)).slice(2);
132
+ if (discriminatorHex === SVM_GATEWAY_EVENT_DISCRIMINATOR) {
133
+ matchCount++;
134
+ lastMatchIndex = i;
135
+ if (matchCount === 2)
136
+ return i;
137
+ }
138
+ }
139
+ if (lastMatchIndex !== -1)
140
+ return lastMatchIndex;
141
+ return 0;
142
+ }
143
+ //# sourceMappingURL=svm-helpers.js.map
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Transaction response/receipt transformation and progress reconstruction,
3
+ * extracted from Orchestrator.
4
+ */
5
+ import { TransactionReceipt } from 'viem';
6
+ import type { UniversalTxV2 } from '../../generated/uexecutor/v2/types';
7
+ import { ProgressEvent } from '../../progress-hook/progress-hook.types';
8
+ import { TransactionRoute } from '../route-detector';
9
+ import type { UniversalTxReceipt, UniversalTxResponse } from '../orchestrator.types';
10
+ export declare function transformToUniversalTxReceipt(receipt: TransactionReceipt, originalTxResponse: UniversalTxResponse): UniversalTxReceipt;
11
+ export declare function reconstructProgressEvents(universalTxResponse: UniversalTxResponse, universalTxData?: UniversalTxV2): ProgressEvent[];
12
+ export declare function detectRouteFromUniversalTxData(universalTxData: UniversalTxV2 | undefined): TransactionRoute | undefined;