@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.
171 lines (170 loc) • 6.9 kB
TypeScript
import { CHAIN, PUSH_NETWORK } from '../constants/enums';
import { ConversionQuote, MoveableToken, PayableToken } from '../constants/tokens';
import { ProgressEvent } from '../progress-hook/progress-hook.types';
import { UniversalAccount, UniversalSigner } from '../universal/universal.types';
import { ExecuteParams, UniversalTxResponse } from './orchestrator.types';
export declare class Orchestrator {
private readonly universalSigner;
private pushNetwork;
private readonly rpcUrls;
private readonly printTraces;
private progressHook?;
private pushClient;
private ueaVersionCache?;
constructor(universalSigner: UniversalSigner, pushNetwork: PUSH_NETWORK, rpcUrls?: Partial<Record<CHAIN, string[]>>, printTraces?: boolean, progressHook?: ((progress: ProgressEvent) => void) | undefined);
/**
* Read-only accessors for current Orchestrator configuration
*/
getNetwork(): PUSH_NETWORK;
getRpcUrls(): Partial<Record<CHAIN, string[]>>;
getPrintTraces(): boolean;
getProgressHook(): ((progress: ProgressEvent) => void) | undefined;
/**
* Executes an interaction on Push Chain
*/
execute(execute: ExecuteParams): Promise<UniversalTxResponse>;
/**
* Locks a fee on the origin chain by interacting with the chain's fee-locker contract.
*
* @param amount - Fee amount in USDC (8 Decimals)
* @param executionHash - Optional execution payload hash (default: zeroHash)
* @returns Transaction hash bytes
*/
private lockFee;
private _buildUniversalTxRequest;
/**
* Builds the SVM UniversalTxRequest object from an existing EVM-style UniversalTxRequest.
* This allows reusing the same request shape for both EVM and SVM while only translating
* field encodings (addresses, bytes) to the Solana program format.
*/
private _buildSvmUniversalTxRequestFromReq;
/**
* Builds the SVM UniversalTxRequest object expected by the Solana gateway program.
* Shape mirrors the request used in `svm-gateway` tests.
*/
private _buildSvmUniversalTxRequest;
private signUniversalPayload;
/**
* Sends a custom Cosmos tx to Push Chain (gasless) to execute user intent.
*/
private sendUniversalTx;
/**
* Sends a EVM trx on Push Chain
* @dev - Only to be used from universal signer is on Push chain
* @param execute
* @returns Cosmos Tx Response for a given Evm Tx
*/
private sendPushTx;
/**
* Computes the EIP-712 digest hash for the UniversalPayload structure.
* This is the message that should be signed by the user's wallet (e.g., Solana signer).
*
* The resulting hash is equivalent to:
* keccak256("\x19\x01" || domainSeparator || structHash)
*
* @param chainId - EVM chain ID of the destination chain (Push Chain)
* @param verifyingContract - Address of the verifying contract (i.e., the user's UEA smart wallet)
* @param version - Optional EIP-712 domain version (default: '0.1.0')
* @param payload - Execution details encoded into the UniversalPayload struct
* @returns keccak256 digest to be signed by the user
*/
private computeExecutionHash;
/**
* ABI-encodes a UniversalPayload struct to bytes, matching the Solidity layout.
* This mirrors abi.encode(UniversalPayload) in the EVM contracts.
*/
private encodeUniversalPayload;
/**
* Encodes a UniversalPayload into Borsh bytes for the SVM universal gateway.
* Layout mirrors Rust `UniversalPayload`:
* to: [u8; 20],
* value: u64,
* data: Vec<u8> (u32 LE len + bytes),
* gas_limit: u64,
* max_fee_per_gas: u64,
* max_priority_fee_per_gas: u64,
* nonce: u64,
* deadline: i64,
* v_type: u8 (0 = SignedVerification, 1 = UniversalTxVerification)
*/
private encodeUniversalPayloadSvm;
/**
* Computes UEA for given UniversalAccount
* @dev - This fn calls a view fn of Factory Contract
* @dev - Don't use this fn in production - only used for testing
* @returns UEA Address with Deployment Status
*/
computeUEA(): Promise<{
address: `0x${string}`;
deployed: boolean;
}>;
private _buildMulticallPayloadData;
private _sendSVMTxWithFunds;
computeUEAOffchain(): `0x${string}`;
/**
* @dev - Although as of now nonce var is same in evm & svm so switch conditions does not matter
* @param address UEA address
* @returns UEA current nonce
*/
private getUEANonce;
getUOA(): UniversalAccount;
private waitForLockerFeeConfirmation;
/**
* Internal helper: fetches the full origin-chain transaction for a given hash,
* used only for progress-hook context (EVM or Solana).
*/
private fetchOriginChainTransactionForProgress;
/**
* Quotes exact-output on Uniswap V3 for EVM origin chains using QuoterV2.
* Returns the minimum required input (amountIn) to receive the target amountOut.
*/
_quoteExactOutput(amountOut: bigint, { from, to, }: {
from: PayableToken | undefined;
to: MoveableToken | undefined;
}): Promise<ConversionQuote>;
private ensureErc20Allowance;
/**
* Ensures we're on Sepolia, returns EVM client and gateway address.
*/
private getOriginGatewayContext;
/**
* Computes UEA and fetches its nonce if deployed; returns 0 otherwise.
*/
private getUeaNonceForExecution;
/**
* Returns UEA deployment status and nonce (0 if not deployed).
*/
private getUeaStatusAndNonce;
/**
* For sendFunds, we will call internally the sendTxWithFunds.
*/
private buildGatewayPayloadAndGas;
/********************************** HELPER FUNCTIONS **************************************************/
/**
* Transforms a TransactionReceipt to UniversalTxReceipt format
*/
private transformToUniversalTxReceipt;
/**
* Transforms a TxResponse to the new UniversalTxResponse format
*/
private transformToUniversalTxResponse;
private bigintReplacer;
/**
* Checks if the given chain belongs to the Push Chain ecosystem.
* Used to differentiate logic for Push-native interactions vs external chains.
*
* @param chain - The chain identifier (e.g., PUSH_MAINNET, PUSH_TESTNET_DONUT)
* @returns True if the chain is a Push chain, false otherwise.
*/
private isPushChain;
private validateMainnetConnection;
private printLog;
private executeProgressHook;
private getSvmGatewayLogIndexFromTx;
private queryUniversalTxStatusFromGatewayTx;
private waitForEvmConfirmationsWithCountdown;
private waitForSvmConfirmationsWithCountdown;
private fetchUEAVersion;
private calculateGasAmountFromAmountOutMinETH;
private calculateNativeAmountForDeposit;
}