UNPKG

@pushchain/core

Version:

Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.

172 lines 7.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); const progress_hook_types_1 = require("./progress-hook.types"); // Helper to wrap a hook function with timestamp const withTimestamp = (fn) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any return (...args) => (Object.assign(Object.assign({}, fn(...args)), { timestamp: new Date().toISOString() })); }; const RAW_HOOKS = { [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_01]: (originChainNamespace, originChainAddress) => { var _a; return ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_01, title: 'Origin Chain Detected', message: `Origin chain: ${(_a = utils_1.Utils.chains.getChainName(originChainNamespace)) !== null && _a !== void 0 ? _a : originChainNamespace} - Origin Address: ${originChainAddress}`, response: null, level: 'INFO', }); }, [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_01, title: 'Estimating Gas', message: 'Estimating and fetching gas limit, gas price for TX', response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_02]: (executionCost) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_02_02, title: 'Gas Estimated', message: `Total execution cost (Gas cost + value): ${executionCost} UPC`, response: null, level: 'SUCCESS', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_01, title: 'Resolving UEA', message: 'Resolving Execution Account (UEA) – computing address, checking deployment status and balance', response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02]: (ueaAddress, deployed) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_03_02, title: 'UEA Resolved', message: `UEA: ${ueaAddress}, Deployed: ${deployed}`, response: null, level: 'SUCCESS', }), // Payload flow (04-x) [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_01]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_01, title: 'Awaiting Transaction', message: 'Awaiting user transaction on origin chain', response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_02]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_02, title: 'Awaiting Signature', message: 'Awaiting user signature for universal payload', response: null, level: 'INFO', }), // V2 Payload flow [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_03]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_03, title: 'Verification Success', message: 'Verification completed via Transaction or Signature', response: null, level: 'SUCCESS', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_04]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_04_04, title: 'Verification Declined', message: 'Verification declined by user', response: null, level: 'ERROR', }), // Gas flow (05-x) [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_01]: (originChainTxHash, originChainTx) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_01, title: 'Gas Funding In Progress', message: `Gas funding tx sent: ${originChainTxHash}`, // Attach the full origin-chain transaction object when provided response: originChainTx !== null && originChainTx !== void 0 ? originChainTx : null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_02]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_05_02, title: 'Gas Funding Confirmed', message: 'Gas funding confirmed on origin chain', response: null, level: 'SUCCESS', }), // V2 Funds flow (06-x) [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01]: (amount, decimals, symbol) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_01, title: 'Preparing Funds Transfer', message: `Preparing to move ${utils_1.Utils.helpers.formatUnits(amount, decimals)} ${symbol} from origin chain`, response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02]: (txHash, amount, decimals, symbol, originChainTx) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_02, title: 'Funds Lock Submitted', message: `Locking ${utils_1.Utils.helpers.formatUnits(amount, decimals)} ${symbol} for transfer (Tx hash: ${txHash})`, // Attach the full origin-chain transaction object when available response: originChainTx !== null && originChainTx !== void 0 ? originChainTx : null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03]: (required) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03, title: 'Awaiting Confirmations', message: `Waiting for ${required} confirmations`, response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_01]: (current, required) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_01, title: `Confirmation ${current}/${required} received`, message: `${current}/${required} confirmations received`, response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02]: (current, required) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_03_02, title: `Confirmation ${current}/${required} received`, message: `${current}/${required} confirmations received`, response: null, level: 'SUCCESS', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_04, title: 'Funds Confirmed', message: 'Origin chain lock confirmed', response: null, level: 'SUCCESS', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05]: (amount, decimals, symbol) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_06_05, title: 'Funds Credited on Push Chain', message: `Funds credited: ${utils_1.Utils.helpers.formatUnits(amount, decimals)} ${symbol}`, response: null, level: 'SUCCESS', }), // Execution flow (07-x) [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07]: () => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_07, title: 'Broadcasting to Push Chain', message: 'Sending Tx to Push Chain', response: null, level: 'INFO', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01]: (txResponse) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_01, title: 'Push Chain Tx Success', message: 'Tx executed successfully on Push Chain', response: txResponse, level: 'SUCCESS', }), [progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02]: (errMessage) => ({ id: progress_hook_types_1.PROGRESS_HOOK.SEND_TX_99_02, title: 'Push Chain Tx Failed', message: errMessage, response: null, level: 'ERROR', }), }; // Build final hooks with timestamp injection const PROGRESS_HOOKS = Object.fromEntries(Object.entries(RAW_HOOKS).map(([key, value]) => [key, withTimestamp(value)])); exports.default = PROGRESS_HOOKS; //# sourceMappingURL=progress-hook.js.map