@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.
- package/package.json +29 -6
- package/src/lib/constants/abi/prc20.evm.d.ts +22 -2
- package/src/lib/constants/abi/prc20.evm.js +11 -3
- package/src/lib/constants/abi/universalGatewayPC.evm.d.ts +59 -0
- package/src/lib/constants/abi/universalGatewayPC.evm.js +26 -0
- package/src/lib/constants/chain.d.ts +4 -0
- package/src/lib/constants/chain.js +6 -2
- package/src/lib/index.d.ts +2 -2
- package/src/lib/internal/bs58.d.ts +2 -0
- package/src/lib/internal/bs58.js +7 -0
- package/src/lib/orchestrator/cea-utils.d.ts +0 -9
- package/src/lib/orchestrator/cea-utils.js +15 -4
- package/src/lib/orchestrator/internals/account-manager.d.ts +16 -0
- package/src/lib/orchestrator/internals/account-manager.js +191 -0
- package/src/lib/orchestrator/internals/cascade.d.ts +23 -0
- package/src/lib/orchestrator/internals/cascade.js +945 -0
- package/src/lib/orchestrator/internals/confirmation.d.ts +9 -0
- package/src/lib/orchestrator/internals/confirmation.js +123 -0
- package/src/lib/orchestrator/internals/context.d.ts +38 -0
- package/src/lib/orchestrator/internals/context.js +49 -0
- package/src/lib/orchestrator/internals/execute-funds-only.d.ts +11 -0
- package/src/lib/orchestrator/internals/execute-funds-only.js +219 -0
- package/src/lib/orchestrator/internals/execute-funds-payload.d.ts +11 -0
- package/src/lib/orchestrator/internals/execute-funds-payload.js +222 -0
- package/src/lib/orchestrator/internals/execute-standard.d.ts +13 -0
- package/src/lib/orchestrator/internals/execute-standard.js +225 -0
- package/src/lib/orchestrator/internals/gas-calculator.d.ts +38 -0
- package/src/lib/orchestrator/internals/gas-calculator.js +424 -0
- package/src/lib/orchestrator/internals/gateway-client.d.ts +24 -0
- package/src/lib/orchestrator/internals/gateway-client.js +191 -0
- package/src/lib/orchestrator/internals/helpers.d.ts +26 -0
- package/src/lib/orchestrator/internals/helpers.js +181 -0
- package/src/lib/orchestrator/internals/index.d.ts +24 -0
- package/src/lib/orchestrator/internals/index.js +132 -0
- package/src/lib/orchestrator/internals/outbound-sync.d.ts +49 -0
- package/src/lib/orchestrator/internals/outbound-sync.js +357 -0
- package/src/lib/orchestrator/internals/outbound-tracker.d.ts +8 -0
- package/src/lib/orchestrator/internals/outbound-tracker.js +64 -0
- package/src/lib/orchestrator/internals/payload-builder.d.ts +24 -0
- package/src/lib/orchestrator/internals/payload-builder.js +178 -0
- package/src/lib/orchestrator/internals/push-chain-tx.d.ts +32 -0
- package/src/lib/orchestrator/internals/push-chain-tx.js +207 -0
- package/src/lib/orchestrator/internals/quote.d.ts +9 -0
- package/src/lib/orchestrator/internals/quote.js +114 -0
- package/src/lib/orchestrator/internals/rescue.d.ts +20 -0
- package/src/lib/orchestrator/internals/rescue.js +112 -0
- package/src/lib/orchestrator/internals/response-builder.d.ts +26 -0
- package/src/lib/orchestrator/internals/response-builder.js +504 -0
- package/src/lib/orchestrator/internals/route-handlers.d.ts +77 -0
- package/src/lib/orchestrator/internals/route-handlers.js +1192 -0
- package/src/lib/orchestrator/internals/signing.d.ts +27 -0
- package/src/lib/orchestrator/internals/signing.js +258 -0
- package/src/lib/orchestrator/internals/svm-bridge.d.ts +21 -0
- package/src/lib/orchestrator/internals/svm-bridge.js +122 -0
- package/src/lib/orchestrator/internals/svm-helpers.d.ts +35 -0
- package/src/lib/orchestrator/internals/svm-helpers.js +143 -0
- package/src/lib/orchestrator/internals/tx-transformer.d.ts +12 -0
- package/src/lib/orchestrator/internals/tx-transformer.js +120 -0
- package/src/lib/orchestrator/internals/uea-manager.d.ts +17 -0
- package/src/lib/orchestrator/internals/uea-manager.js +164 -0
- package/src/lib/orchestrator/orchestrator.d.ts +33 -431
- package/src/lib/orchestrator/orchestrator.js +124 -6125
- package/src/lib/orchestrator/orchestrator.types.d.ts +11 -10
- package/src/lib/orchestrator/payload-builders.js +34 -8
- package/src/lib/price-fetch/price-fetch.js +19 -7
- package/src/lib/push-chain/push-chain.d.ts +6 -0
- package/src/lib/push-chain/push-chain.js +10 -2
- package/src/lib/push-client/push-client.d.ts +3 -0
- package/src/lib/push-client/push-client.js +21 -31
- package/src/lib/universal/account/account.d.ts +35 -16
- package/src/lib/universal/account/account.js +298 -16
- package/src/lib/universal/signer/signer.d.ts +2 -3
- package/src/lib/universal/signer/signer.js +65 -115
- package/src/lib/universal/universal.types.d.ts +41 -0
- package/src/lib/utils.d.ts +7 -2
- package/src/lib/utils.js +65 -34
- package/src/lib/vm-client/evm-client.js +3 -11
- package/src/lib/vm-client/svm-client.d.ts +0 -4
- package/src/lib/vm-client/svm-client.js +2 -8
- package/src/index.js.map +0 -1
- package/src/lib/cache/cache.js.map +0 -1
- package/src/lib/constants/abi/cea.evm.js.map +0 -1
- package/src/lib/constants/abi/ceaFactory.evm.js.map +0 -1
- package/src/lib/constants/abi/erc20.evm.js.map +0 -1
- package/src/lib/constants/abi/factoryV1.js.map +0 -1
- package/src/lib/constants/abi/feeLocker.evm.js.map +0 -1
- package/src/lib/constants/abi/index.js.map +0 -1
- package/src/lib/constants/abi/prc20.evm.js.map +0 -1
- package/src/lib/constants/abi/uea-factory.js.map +0 -1
- package/src/lib/constants/abi/uea.evm.js.map +0 -1
- package/src/lib/constants/abi/uea.svm.js.map +0 -1
- package/src/lib/constants/abi/universalGateway.evm.js.map +0 -1
- package/src/lib/constants/abi/universalGatewayPC.evm.js.map +0 -1
- package/src/lib/constants/abi/universalGatewayV0.evm.js.map +0 -1
- package/src/lib/constants/chain.js.map +0 -1
- package/src/lib/constants/enums.js.map +0 -1
- package/src/lib/constants/index.js.map +0 -1
- package/src/lib/constants/selectors.js.map +0 -1
- package/src/lib/constants/tokens.js.map +0 -1
- package/src/lib/generated/uexecutor/v1/query.js.map +0 -1
- package/src/lib/generated/uexecutor/v1/types.js.map +0 -1
- package/src/lib/generated/uexecutor/v2/index.js.map +0 -1
- package/src/lib/generated/uexecutor/v2/query.js.map +0 -1
- package/src/lib/generated/uexecutor/v2/types.js.map +0 -1
- package/src/lib/generated/v1/tx.js.map +0 -1
- package/src/lib/index.js.map +0 -1
- package/src/lib/internal/buffer.js.map +0 -1
- package/src/lib/internal/global-buffer-polyfill.js.map +0 -1
- package/src/lib/orchestrator/cea-utils.js.map +0 -1
- package/src/lib/orchestrator/orchestrator.js.map +0 -1
- package/src/lib/orchestrator/orchestrator.types.js.map +0 -1
- package/src/lib/orchestrator/payload-builders.js.map +0 -1
- package/src/lib/orchestrator/route-detector.js.map +0 -1
- package/src/lib/price-fetch/price-fetch.js.map +0 -1
- package/src/lib/progress-hook/progress-hook.js.map +0 -1
- package/src/lib/progress-hook/progress-hook.types.js.map +0 -1
- package/src/lib/push-chain/helpers/abis.js.map +0 -1
- package/src/lib/push-chain/helpers/addresses.js.map +0 -1
- package/src/lib/push-chain/push-chain.js.map +0 -1
- package/src/lib/push-client/push-client.js.map +0 -1
- package/src/lib/push-client/push-client.types.js.map +0 -1
- package/src/lib/universal/account/account.js.map +0 -1
- package/src/lib/universal/account/index.js.map +0 -1
- package/src/lib/universal/signer/index.js.map +0 -1
- package/src/lib/universal/signer/signer.js.map +0 -1
- package/src/lib/universal/signer/signer.types.js.map +0 -1
- package/src/lib/universal/universal.types.js.map +0 -1
- package/src/lib/utils.js.map +0 -1
- package/src/lib/vm-client/evm-client.js.map +0 -1
- package/src/lib/vm-client/svm-client.js.map +0 -1
- package/src/lib/vm-client/vm-client.types.js.map +0 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction confirmation polling functions extracted from Orchestrator.
|
|
3
|
+
*/
|
|
4
|
+
import { EvmClient } from '../../vm-client/evm-client';
|
|
5
|
+
import { SvmClient } from '../../vm-client/svm-client';
|
|
6
|
+
import type { OrchestratorContext } from './context';
|
|
7
|
+
export declare function waitForEvmConfirmationsWithCountdown(ctx: OrchestratorContext, evmClient: EvmClient, txHash: `0x${string}`, confirmations: number, timeoutMs: number): Promise<void>;
|
|
8
|
+
export declare function waitForSvmConfirmationsWithCountdown(ctx: OrchestratorContext, svmClient: SvmClient, txSignature: string, confirmations: number, timeoutMs: number): Promise<void>;
|
|
9
|
+
export declare function waitForLockerFeeConfirmation(ctx: OrchestratorContext, txHashBytes: Uint8Array): Promise<void>;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Transaction confirmation polling functions extracted from Orchestrator.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.waitForEvmConfirmationsWithCountdown = waitForEvmConfirmationsWithCountdown;
|
|
7
|
+
exports.waitForSvmConfirmationsWithCountdown = waitForSvmConfirmationsWithCountdown;
|
|
8
|
+
exports.waitForLockerFeeConfirmation = waitForLockerFeeConfirmation;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const bs58_1 = require("../../internal/bs58");
|
|
11
|
+
const viem_1 = require("viem");
|
|
12
|
+
const chain_1 = require("../../constants/chain");
|
|
13
|
+
const context_1 = require("./context");
|
|
14
|
+
const enums_1 = require("../../constants/enums");
|
|
15
|
+
const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
|
|
16
|
+
const svm_client_1 = require("../../vm-client/svm-client");
|
|
17
|
+
const context_2 = require("./context");
|
|
18
|
+
function waitForEvmConfirmationsWithCountdown(ctx, evmClient, txHash, confirmations, timeoutMs) {
|
|
19
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
if (confirmations <= 0) {
|
|
21
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
25
|
+
const start = Date.now();
|
|
26
|
+
const receipt = yield evmClient.publicClient.waitForTransactionReceipt({
|
|
27
|
+
hash: txHash,
|
|
28
|
+
});
|
|
29
|
+
const targetBlock = receipt.blockNumber + BigInt(confirmations);
|
|
30
|
+
let lastEmitted = 0;
|
|
31
|
+
// eslint-disable-next-line no-constant-condition
|
|
32
|
+
while (true) {
|
|
33
|
+
const currentBlock = yield evmClient.publicClient.getBlockNumber();
|
|
34
|
+
if (currentBlock >= targetBlock) {
|
|
35
|
+
if (lastEmitted < confirmations) {
|
|
36
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, confirmations, confirmations);
|
|
37
|
+
}
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const remaining = Number(targetBlock - currentBlock);
|
|
41
|
+
const completed = Math.max(1, confirmations - remaining + 1);
|
|
42
|
+
if (completed > lastEmitted) {
|
|
43
|
+
(0, context_2.fireProgressHook)(ctx, completed >= confirmations
|
|
44
|
+
? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02
|
|
45
|
+
: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_01, completed, confirmations);
|
|
46
|
+
lastEmitted = completed;
|
|
47
|
+
if (completed >= confirmations)
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (Date.now() - start > timeoutMs) {
|
|
51
|
+
throw new Error(`Timeout: transaction ${txHash} not confirmed with ${confirmations} confirmations within ${timeoutMs} ms`);
|
|
52
|
+
}
|
|
53
|
+
yield new Promise((r) => setTimeout(r, 12000));
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function waitForSvmConfirmationsWithCountdown(ctx, svmClient, txSignature, confirmations, timeoutMs) {
|
|
58
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
if (confirmations <= 0) {
|
|
60
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, 0, 0);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, confirmations);
|
|
64
|
+
const start = Date.now();
|
|
65
|
+
let lastConfirmed = 0;
|
|
66
|
+
// eslint-disable-next-line no-constant-condition
|
|
67
|
+
while (true) {
|
|
68
|
+
const connection = svmClient.connections[svmClient.currentConnectionIndex];
|
|
69
|
+
const { value } = yield connection.getSignatureStatuses([txSignature]);
|
|
70
|
+
const status = value[0];
|
|
71
|
+
if (status) {
|
|
72
|
+
if (status.err) {
|
|
73
|
+
throw new Error(`SVM transaction ${txSignature} failed: ${JSON.stringify(status.err)}`);
|
|
74
|
+
}
|
|
75
|
+
const rawConfirmations = status.confirmations;
|
|
76
|
+
const hasNumericConfirmations = rawConfirmations != null;
|
|
77
|
+
const currentConfirms = hasNumericConfirmations ? rawConfirmations : 0;
|
|
78
|
+
const isFinalized = status.err === null &&
|
|
79
|
+
(status.confirmationStatus === 'finalized' || status.confirmations === null);
|
|
80
|
+
const hasEnoughConfirmations = hasNumericConfirmations && currentConfirms >= confirmations;
|
|
81
|
+
if (currentConfirms > lastConfirmed) {
|
|
82
|
+
const clamped = currentConfirms >= confirmations ? confirmations : currentConfirms;
|
|
83
|
+
(0, context_2.fireProgressHook)(ctx, clamped >= confirmations
|
|
84
|
+
? progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02
|
|
85
|
+
: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_01, Math.max(1, clamped), confirmations);
|
|
86
|
+
lastConfirmed = currentConfirms;
|
|
87
|
+
}
|
|
88
|
+
if (hasEnoughConfirmations || isFinalized) {
|
|
89
|
+
if (lastConfirmed < confirmations) {
|
|
90
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, confirmations, confirmations);
|
|
91
|
+
}
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (Date.now() - start > timeoutMs) {
|
|
96
|
+
throw new Error(`Timeout: transaction ${txSignature} not confirmed with ${confirmations} confirmations within ${timeoutMs} ms`);
|
|
97
|
+
}
|
|
98
|
+
yield new Promise((r) => setTimeout(r, 500));
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function waitForLockerFeeConfirmation(ctx, txHashBytes) {
|
|
103
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const chain = ctx.universalSigner.account.chain;
|
|
105
|
+
const { vm, defaultRPC, fastConfirmations, timeout } = chain_1.CHAIN_INFO[chain];
|
|
106
|
+
const rpcUrls = ctx.rpcUrls[chain] || defaultRPC;
|
|
107
|
+
switch (vm) {
|
|
108
|
+
case enums_1.VM.EVM: {
|
|
109
|
+
const evmClient = (0, context_1.getOriginEvmClient)(ctx);
|
|
110
|
+
yield waitForEvmConfirmationsWithCountdown(ctx, evmClient, (0, viem_1.bytesToHex)(txHashBytes), fastConfirmations, timeout);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
case enums_1.VM.SVM: {
|
|
114
|
+
const svmClient = new svm_client_1.SvmClient({ rpcUrls });
|
|
115
|
+
yield waitForSvmConfirmationsWithCountdown(ctx, svmClient, bs58_1.bs58.encode(Buffer.from(txHashBytes)), fastConfirmations, timeout);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
default:
|
|
119
|
+
throw new Error(`Unsupported VM for tx confirmation: ${vm}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=confirmation.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared context for orchestrator submodules.
|
|
3
|
+
*
|
|
4
|
+
* Instead of passing `this` or 5+ parameters to every extracted function,
|
|
5
|
+
* submodules receive this context object. The Orchestrator class implements
|
|
6
|
+
* this interface and passes itself.
|
|
7
|
+
*/
|
|
8
|
+
import type { PushClient } from '../../push-client/push-client';
|
|
9
|
+
import type { UniversalSigner } from '../../universal/universal.types';
|
|
10
|
+
import type { CHAIN, PUSH_NETWORK } from '../../constants/enums';
|
|
11
|
+
import type { ProgressEvent } from '../../progress-hook/progress-hook.types';
|
|
12
|
+
import type { AccountStatus } from '../orchestrator.types';
|
|
13
|
+
import { EvmClient } from '../../vm-client/evm-client';
|
|
14
|
+
export interface OrchestratorContext {
|
|
15
|
+
readonly pushClient: PushClient;
|
|
16
|
+
readonly universalSigner: UniversalSigner;
|
|
17
|
+
readonly pushNetwork: PUSH_NETWORK;
|
|
18
|
+
readonly rpcUrls: Partial<Record<CHAIN, string[]>>;
|
|
19
|
+
readonly printTraces: boolean;
|
|
20
|
+
progressHook?: (progress: ProgressEvent) => void;
|
|
21
|
+
ueaVersionCache?: string;
|
|
22
|
+
accountStatusCache: AccountStatus | null;
|
|
23
|
+
/** Cached origin chain EvmClient — avoids creating new clients per call site */
|
|
24
|
+
_originEvmClient?: EvmClient;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Returns (and caches) an EvmClient for the signer's origin chain.
|
|
28
|
+
* Avoids creating new EvmClient instances in lockFee, confirmation, fetchOriginTx, etc.
|
|
29
|
+
*/
|
|
30
|
+
export declare function getOriginEvmClient(ctx: OrchestratorContext): EvmClient;
|
|
31
|
+
/**
|
|
32
|
+
* Logs a message to console when printTraces is enabled.
|
|
33
|
+
*/
|
|
34
|
+
export declare function printLog(ctx: OrchestratorContext, msg: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* Fires a progress hook event by ID, forwarding args to the hook factory.
|
|
37
|
+
*/
|
|
38
|
+
export declare function fireProgressHook(ctx: OrchestratorContext, hookId: string, ...args: any[]): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Shared context for orchestrator submodules.
|
|
4
|
+
*
|
|
5
|
+
* Instead of passing `this` or 5+ parameters to every extracted function,
|
|
6
|
+
* submodules receive this context object. The Orchestrator class implements
|
|
7
|
+
* this interface and passes itself.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getOriginEvmClient = getOriginEvmClient;
|
|
11
|
+
exports.printLog = printLog;
|
|
12
|
+
exports.fireProgressHook = fireProgressHook;
|
|
13
|
+
const tslib_1 = require("tslib");
|
|
14
|
+
const chain_1 = require("../../constants/chain");
|
|
15
|
+
const evm_client_1 = require("../../vm-client/evm-client");
|
|
16
|
+
const progress_hook_1 = tslib_1.__importDefault(require("../../progress-hook/progress-hook"));
|
|
17
|
+
/**
|
|
18
|
+
* Returns (and caches) an EvmClient for the signer's origin chain.
|
|
19
|
+
* Avoids creating new EvmClient instances in lockFee, confirmation, fetchOriginTx, etc.
|
|
20
|
+
*/
|
|
21
|
+
function getOriginEvmClient(ctx) {
|
|
22
|
+
if (!ctx._originEvmClient) {
|
|
23
|
+
const chain = ctx.universalSigner.account.chain;
|
|
24
|
+
const { defaultRPC } = chain_1.CHAIN_INFO[chain];
|
|
25
|
+
const rpcUrls = ctx.rpcUrls[chain] || defaultRPC;
|
|
26
|
+
ctx._originEvmClient = new evm_client_1.EvmClient({ rpcUrls });
|
|
27
|
+
}
|
|
28
|
+
return ctx._originEvmClient;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Logs a message to console when printTraces is enabled.
|
|
32
|
+
*/
|
|
33
|
+
function printLog(ctx, msg) {
|
|
34
|
+
if (ctx.printTraces) {
|
|
35
|
+
console.log(`[Orchestrator] ${msg}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Fires a progress hook event by ID, forwarding args to the hook factory.
|
|
40
|
+
*/
|
|
41
|
+
function fireProgressHook(ctx, hookId, ...args) {
|
|
42
|
+
const hookEntry = progress_hook_1.default[hookId];
|
|
43
|
+
const hookPayload = hookEntry(...args);
|
|
44
|
+
printLog(ctx, hookPayload.message);
|
|
45
|
+
if (ctx.progressHook) {
|
|
46
|
+
ctx.progressHook(hookPayload);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funds-only execution flow (no payload) — extracted from Orchestrator.execute().
|
|
3
|
+
*
|
|
4
|
+
* Handles bridging funds from an external chain to Push Chain
|
|
5
|
+
* for both EVM and SVM origin chains.
|
|
6
|
+
*/
|
|
7
|
+
import { ProgressEvent } from '../../progress-hook/progress-hook.types';
|
|
8
|
+
import type { ExecuteParams, UniversalTxResponse } from '../orchestrator.types';
|
|
9
|
+
import type { OrchestratorContext } from './context';
|
|
10
|
+
import type { ResponseBuilderCallbacks } from './response-builder';
|
|
11
|
+
export declare function executeFundsOnly(ctx: OrchestratorContext, execute: ExecuteParams, eventBuffer: ProgressEvent[], getResponseCallbacks: () => ResponseBuilderCallbacks): Promise<UniversalTxResponse>;
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Funds-only execution flow (no payload) — extracted from Orchestrator.execute().
|
|
4
|
+
*
|
|
5
|
+
* Handles bridging funds from an external chain to Push Chain
|
|
6
|
+
* for both EVM and SVM origin chains.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.executeFundsOnly = executeFundsOnly;
|
|
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 tokens_1 = require("../../constants/tokens");
|
|
17
|
+
const progress_hook_types_1 = require("../../progress-hook/progress-hook.types");
|
|
18
|
+
const context_1 = require("./context");
|
|
19
|
+
const svm_client_1 = require("../../vm-client/svm-client");
|
|
20
|
+
const context_2 = require("./context");
|
|
21
|
+
const gas_calculator_1 = require("./gas-calculator");
|
|
22
|
+
const gateway_client_1 = require("./gateway-client");
|
|
23
|
+
const helpers_1 = require("./helpers");
|
|
24
|
+
const payload_builder_1 = require("./payload-builder");
|
|
25
|
+
const uea_manager_1 = require("./uea-manager");
|
|
26
|
+
const confirmation_1 = require("./confirmation");
|
|
27
|
+
const response_builder_1 = require("./response-builder");
|
|
28
|
+
const push_chain_tx_1 = require("./push-chain-tx");
|
|
29
|
+
const svm_helpers_1 = require("./svm-helpers");
|
|
30
|
+
const helpers_2 = require("./helpers");
|
|
31
|
+
const response_builder_2 = require("./response-builder");
|
|
32
|
+
function executeFundsOnly(ctx, execute, eventBuffer, getResponseCallbacks) {
|
|
33
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const transformFn = (tx, buf = []) => (0, response_builder_2.transformToUniversalTxResponse)(ctx, tx, buf, getResponseCallbacks());
|
|
35
|
+
const chain = ctx.universalSigner.account.chain;
|
|
36
|
+
const { vm } = chain_1.CHAIN_INFO[chain];
|
|
37
|
+
if (!helpers_1.SUPPORTED_GATEWAY_CHAINS.includes(chain)) {
|
|
38
|
+
throw new Error(`Funds bridging is not supported on chain ${chain}. Supported chains: ${helpers_1.SUPPORTED_GATEWAY_CHAINS.join(', ')}`);
|
|
39
|
+
}
|
|
40
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_01, chain, ctx.universalSigner.account.address);
|
|
41
|
+
const { defaultRPC, lockerContract } = chain_1.CHAIN_INFO[chain];
|
|
42
|
+
const rpcUrls = ctx.rpcUrls[chain] || defaultRPC;
|
|
43
|
+
// Resolve token: default to native token based on VM
|
|
44
|
+
if (!execute.funds.token) {
|
|
45
|
+
const available = tokens_1.MOVEABLE_TOKENS[chain] || [];
|
|
46
|
+
const preferredSymbol = vm === enums_1.VM.EVM ? 'ETH' : vm === enums_1.VM.SVM ? 'SOL' : undefined;
|
|
47
|
+
const nativeToken = preferredSymbol
|
|
48
|
+
? available.find((t) => t.symbol === preferredSymbol)
|
|
49
|
+
: undefined;
|
|
50
|
+
if (!nativeToken) {
|
|
51
|
+
throw new Error('Native token not configured for this chain');
|
|
52
|
+
}
|
|
53
|
+
execute.funds.token = nativeToken;
|
|
54
|
+
}
|
|
55
|
+
const amount = execute.funds.amount;
|
|
56
|
+
const symbol = execute.funds.token.symbol;
|
|
57
|
+
const bridgeAmount = amount;
|
|
58
|
+
if (vm === enums_1.VM.EVM) {
|
|
59
|
+
return executeFundsOnlyEvm(ctx, execute, eventBuffer, transformFn, chain, rpcUrls, lockerContract, bridgeAmount, symbol);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return executeFundsOnlySvm(ctx, execute, eventBuffer, transformFn, chain, rpcUrls, bridgeAmount, symbol);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// ============================================================================
|
|
67
|
+
// EVM funds-only path
|
|
68
|
+
// ============================================================================
|
|
69
|
+
function executeFundsOnlyEvm(ctx, execute, eventBuffer, transformFn, chain, rpcUrls, lockerContract, bridgeAmount, symbol) {
|
|
70
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
const evmClient = (0, context_1.getOriginEvmClient)(ctx);
|
|
73
|
+
const gatewayAddress = lockerContract;
|
|
74
|
+
const tokenAddr = execute.funds.token.address;
|
|
75
|
+
const isNative = execute.funds.token.mechanism === 'native';
|
|
76
|
+
// Skip getCode if accountStatusCache already confirmed deployment
|
|
77
|
+
let nonce;
|
|
78
|
+
let deployed;
|
|
79
|
+
const deployedHint = (_b = (_a = ctx.accountStatusCache) === null || _a === void 0 ? void 0 : _a.uea) === null || _b === void 0 ? void 0 : _b.deployed;
|
|
80
|
+
if (deployedHint) {
|
|
81
|
+
deployed = true;
|
|
82
|
+
nonce = yield (0, uea_manager_1.getUEANonce)(ctx, (0, uea_manager_1.computeUEAOffchain)(ctx));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
const status = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
|
|
86
|
+
nonce = status.nonce;
|
|
87
|
+
deployed = status.deployed;
|
|
88
|
+
}
|
|
89
|
+
const { payload: universalPayload, req } = yield (0, payload_builder_1.buildGatewayPayloadAndGas)(ctx, execute, nonce, 'sendFunds', bridgeAmount);
|
|
90
|
+
const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
|
|
91
|
+
(0, context_2.printLog)(ctx, 'sendFunds — buildGatewayPayloadAndGas result: ' + JSON.stringify({
|
|
92
|
+
recipient: execute.to, ueaAddress,
|
|
93
|
+
isSelfBridge: execute.to.toLowerCase() === ueaAddress.toLowerCase(),
|
|
94
|
+
bridgeAmount: bridgeAmount.toString(), isNative, tokenAddr,
|
|
95
|
+
nonce: nonce.toString(), deployed,
|
|
96
|
+
}, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
97
|
+
const ueaBalanceForGas = yield ctx.pushClient.getBalance(ueaAddress);
|
|
98
|
+
const nativeAmount = yield (0, gas_calculator_1.calculateNativeAmountForDeposit)(ctx, chain, BigInt(0), ueaBalanceForGas);
|
|
99
|
+
(0, context_2.printLog)(ctx, `sendFunds — nativeAmount: ${nativeAmount.toString()}, ueaBalanceForGas: ${ueaBalanceForGas.toString()}`);
|
|
100
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01);
|
|
101
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, ueaAddress, deployed);
|
|
102
|
+
(0, context_2.printLog)(ctx, `UEA resolved: ${ueaAddress}, deployed: ${deployed}`);
|
|
103
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01, execute.funds.amount, execute.funds.token.decimals, symbol);
|
|
104
|
+
// Approve gateway to pull tokens if ERC-20
|
|
105
|
+
if (execute.funds.token.mechanism === 'approve') {
|
|
106
|
+
yield (0, gas_calculator_1.ensureErc20Allowance)(ctx, evmClient, tokenAddr, gatewayAddress, execute.funds.amount);
|
|
107
|
+
}
|
|
108
|
+
else if (execute.funds.token.mechanism === 'permit2') {
|
|
109
|
+
throw new Error('Permit2 is not supported yet');
|
|
110
|
+
}
|
|
111
|
+
let txHash;
|
|
112
|
+
try {
|
|
113
|
+
(0, context_2.printLog)(ctx, (execute.to.toLowerCase() === ueaAddress.toLowerCase() ? 'FUNDS ONLY SELF' : 'FUNDS ONLY OTHER') +
|
|
114
|
+
' — gateway call payload: ' + JSON.stringify({
|
|
115
|
+
gatewayAddress, functionName: 'sendUniversalTx', req,
|
|
116
|
+
value: (isNative ? nativeAmount + bridgeAmount : nativeAmount).toString(),
|
|
117
|
+
isNative, bridgeAmount: bridgeAmount.toString(), nativeAmount: nativeAmount.toString(),
|
|
118
|
+
}, (_, v) => typeof v === 'bigint' ? v.toString() : v, 2));
|
|
119
|
+
txHash = yield (0, gateway_client_1.sendGatewayTxWithFallback)(ctx, evmClient, gatewayAddress, req, ctx.universalSigner, isNative ? nativeAmount + bridgeAmount : nativeAmount);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_04);
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
const originTx = yield (0, helpers_2.fetchOriginChainTransactionForProgress)(ctx, chain, txHash, txHash);
|
|
126
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, txHash, bridgeAmount, execute.funds.token.decimals, symbol, originTx);
|
|
127
|
+
yield (0, confirmation_1.waitForEvmConfirmationsWithCountdown)(ctx, evmClient, txHash, chain_1.CHAIN_INFO[chain].confirmations, chain_1.CHAIN_INFO[chain].timeout);
|
|
128
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
129
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
130
|
+
(0, context_2.printLog)(ctx, 'sendFunds — querying Push Chain status: ' + JSON.stringify({
|
|
131
|
+
txHash, evmGatewayMethod: execute.to === ueaAddress ? 'sendFunds' : 'sendTxWithFunds',
|
|
132
|
+
}));
|
|
133
|
+
const pushChainUniversalTx = yield (0, response_builder_1.queryUniversalTxStatusFromGatewayTx)(ctx, evmClient, gatewayAddress, txHash, execute.to === ueaAddress ? 'sendFunds' : 'sendTxWithFunds');
|
|
134
|
+
const response = yield (0, push_chain_tx_1.extractPcTxAndTransform)(ctx, pushChainUniversalTx, txHash, eventBuffer, 'sendFunds', transformFn);
|
|
135
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
136
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
137
|
+
return response;
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
// ============================================================================
|
|
141
|
+
// SVM funds-only path
|
|
142
|
+
// ============================================================================
|
|
143
|
+
function executeFundsOnlySvm(ctx, execute, eventBuffer, transformFn, chain, rpcUrls, bridgeAmount, symbol) {
|
|
144
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const svmClient = new svm_client_1.SvmClient({ rpcUrls });
|
|
146
|
+
const programId = new web3_js_1.PublicKey(universalGatewayV0_json_1.default.address);
|
|
147
|
+
const [configPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('config')], programId);
|
|
148
|
+
const [vaultPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('vault')], programId);
|
|
149
|
+
const { feeVaultPda, protocolFeeLamports } = yield (0, svm_helpers_1.getSvmProtocolFee)(svmClient, programId);
|
|
150
|
+
const [rateLimitConfigPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit_config')], programId);
|
|
151
|
+
const userPk = new web3_js_1.PublicKey(ctx.universalSigner.account.address);
|
|
152
|
+
const priceUpdatePk = new web3_js_1.PublicKey(chain_1.SVM_PYTH_PRICE_FEED);
|
|
153
|
+
if (execute.payGasWith !== undefined) {
|
|
154
|
+
throw new Error('Pay-with token is not supported on Solana');
|
|
155
|
+
}
|
|
156
|
+
const recipientEvm20 = Array.from(Buffer.from(execute.to.slice(2).padStart(40, '0'), 'hex').subarray(0, 20));
|
|
157
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01);
|
|
158
|
+
const ueaAddress = (0, uea_manager_1.computeUEAOffchain)(ctx);
|
|
159
|
+
const { nonce, deployed } = yield (0, uea_manager_1.getUeaStatusAndNonce)(ctx);
|
|
160
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, ueaAddress, deployed);
|
|
161
|
+
let txSignature;
|
|
162
|
+
if (execute.funds.token.mechanism === 'native') {
|
|
163
|
+
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), web3_js_1.PublicKey.default.toBuffer()], programId);
|
|
164
|
+
const reqNative = (0, svm_helpers_1.buildSvmUniversalTxRequest)({
|
|
165
|
+
recipient: recipientEvm20, token: web3_js_1.PublicKey.default, amount: bridgeAmount,
|
|
166
|
+
payload: '0x', revertRecipient: userPk, signatureData: '0x',
|
|
167
|
+
});
|
|
168
|
+
txSignature = yield svmClient.writeContract({
|
|
169
|
+
abi: universalGatewayV0_json_1.default, address: programId.toBase58(), functionName: 'sendUniversalTx',
|
|
170
|
+
args: [reqNative, bridgeAmount + protocolFeeLamports], signer: ctx.universalSigner,
|
|
171
|
+
accounts: {
|
|
172
|
+
config: configPda, vault: vaultPda, feeVault: feeVaultPda,
|
|
173
|
+
userTokenAccount: vaultPda, gatewayTokenAccount: vaultPda, user: userPk,
|
|
174
|
+
priceUpdate: priceUpdatePk, rateLimitConfig: rateLimitConfigPda,
|
|
175
|
+
tokenRateLimit: tokenRateLimitPda,
|
|
176
|
+
tokenProgram: new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'),
|
|
177
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
178
|
+
},
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
else if (execute.funds.token.mechanism === 'approve') {
|
|
182
|
+
const mintPk = new web3_js_1.PublicKey(execute.funds.token.address);
|
|
183
|
+
const TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA');
|
|
184
|
+
const ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js_1.PublicKey('ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL');
|
|
185
|
+
const userAta = web3_js_1.PublicKey.findProgramAddressSync([userPk.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
186
|
+
const vaultAta = web3_js_1.PublicKey.findProgramAddressSync([vaultPda.toBuffer(), TOKEN_PROGRAM_ID.toBuffer(), mintPk.toBuffer()], ASSOCIATED_TOKEN_PROGRAM_ID)[0];
|
|
187
|
+
const [tokenRateLimitPda] = web3_js_1.PublicKey.findProgramAddressSync([(0, viem_1.stringToBytes)('rate_limit'), mintPk.toBuffer()], programId);
|
|
188
|
+
const reqSpl = (0, svm_helpers_1.buildSvmUniversalTxRequest)({
|
|
189
|
+
recipient: recipientEvm20, token: mintPk, amount: bridgeAmount,
|
|
190
|
+
payload: '0x', revertRecipient: userPk, signatureData: '0x',
|
|
191
|
+
});
|
|
192
|
+
txSignature = yield svmClient.writeContract({
|
|
193
|
+
abi: universalGatewayV0_json_1.default, address: programId.toBase58(), functionName: 'sendUniversalTx',
|
|
194
|
+
args: [reqSpl, protocolFeeLamports], signer: ctx.universalSigner,
|
|
195
|
+
accounts: {
|
|
196
|
+
config: configPda, vault: vaultPda, feeVault: feeVaultPda,
|
|
197
|
+
userTokenAccount: userAta, gatewayTokenAccount: vaultAta, user: userPk,
|
|
198
|
+
tokenProgram: TOKEN_PROGRAM_ID, priceUpdate: priceUpdatePk,
|
|
199
|
+
rateLimitConfig: rateLimitConfigPda, tokenRateLimit: tokenRateLimitPda,
|
|
200
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
throw new Error('Unsupported token mechanism on Solana');
|
|
206
|
+
}
|
|
207
|
+
const originTx = yield (0, helpers_2.fetchOriginChainTransactionForProgress)(ctx, chain, '0x', txSignature);
|
|
208
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, txSignature, bridgeAmount, execute.funds.token.decimals, symbol, originTx);
|
|
209
|
+
yield (0, confirmation_1.waitForSvmConfirmationsWithCountdown)(ctx, svmClient, txSignature, chain_1.CHAIN_INFO[chain].confirmations, chain_1.CHAIN_INFO[chain].timeout);
|
|
210
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04);
|
|
211
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05);
|
|
212
|
+
const pushChainUniversalTx = yield (0, response_builder_1.queryUniversalTxStatusFromGatewayTx)(ctx, undefined, undefined, txSignature, 'sendFunds');
|
|
213
|
+
const response = yield (0, push_chain_tx_1.extractPcTxAndTransform)(ctx, pushChainUniversalTx, txSignature, eventBuffer, 'sendFunds (SVM)', transformFn);
|
|
214
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_06, bridgeAmount, execute.funds.token.decimals, symbol);
|
|
215
|
+
(0, context_2.fireProgressHook)(ctx, progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, [response]);
|
|
216
|
+
return response;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=execute-funds-only.js.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Funds+payload execution flow — extracted from Orchestrator.execute().
|
|
3
|
+
*
|
|
4
|
+
* Handles bridging funds AND executing a payload on Push Chain
|
|
5
|
+
* for both EVM and SVM origin chains.
|
|
6
|
+
*/
|
|
7
|
+
import { ProgressEvent } from '../../progress-hook/progress-hook.types';
|
|
8
|
+
import type { ExecuteParams, UniversalTxResponse } from '../orchestrator.types';
|
|
9
|
+
import type { OrchestratorContext } from './context';
|
|
10
|
+
import { type ResponseBuilderCallbacks } from './response-builder';
|
|
11
|
+
export declare function executeFundsWithPayload(ctx: OrchestratorContext, execute: ExecuteParams, eventBuffer: ProgressEvent[], getResponseCallbacks: () => ResponseBuilderCallbacks): Promise<UniversalTxResponse>;
|