@ledgerhq/coin-hedera
Version:
Ledger Hedera Coin integration
92 lines • 5.07 kB
TypeScript
import { TransactionId } from "@hashgraph/sdk";
import type { Currency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import type { Operation } from "@ledgerhq/types-live";
import BigNumber from "bignumber.js";
import type { HederaCoinConfig } from "../config";
import type { HederaMirrorTokenTransfer, HederaMirrorCoinTransfer, HederaERC20TokenBalance, ERC20TokenTransfer, EnrichedERC20Transfer, HederaMirrorTransaction, StakingAnalysis } from "../types";
export declare function createTransactionId(accountId: string, config: HederaCoinConfig): Promise<TransactionId>;
export declare function parseTransfers(mirrorTransfers: (HederaMirrorCoinTransfer | HederaMirrorTokenTransfer)[], address: string, stakingReward?: BigNumber): Pick<Operation, "type" | "value" | "senders" | "recipients">;
export declare function getERC20BalancesForAccountV2({ configOrCurrencyId, address, }: {
configOrCurrencyId: HederaCoinConfig | string;
address: string;
}): Promise<HederaERC20TokenBalance[]>;
/**
* Enriches raw ERC20 transfers from Hgraph with additional data needed for operations:
* - fetches contract call result containing gas metrics and block hash
* - finds the corresponding Mirror Node transaction by consensus timestamp
*
* @param erc20Transfers - Raw ERC20 transfers from Hgraph API
* @returns Array of enriched transfers with complete operation data, filtered to supported tokens only
*/
export declare const enrichERC20Transfers: ({ configOrCurrencyId, erc20Transfers, }: {
configOrCurrencyId: HederaCoinConfig | string;
erc20Transfers: ERC20TokenTransfer[];
}) => Promise<EnrichedERC20Transfer[]>;
export declare const getCurrencyToUSDRate: import("@ledgerhq/live-network/cache").CacheRes<[currency: Currency], BigNumber | null>;
export declare const checkAccountTokenAssociationStatus: import("@ledgerhq/live-network/cache").CacheRes<[accountId: string, token: TokenCurrency], boolean>;
export declare const safeParseAccountId: ({ configOrCurrencyId, address, }: {
configOrCurrencyId: HederaCoinConfig | string;
address: string;
}) => Promise<[Error, null] | [null, {
accountId: string;
checksum: string | null;
}]>;
/**
* Fetches EVM address for given Hedera account ID (e.g. "0.0.1234").
* It returns null if the fetch fails.
*
* @param accountId - Hedera account ID in the format `shard.realm.num`
* @returns EVM address (`0x...`) or null if fetch fails
*/
export declare const toEVMAddress: ({ configOrCurrencyId, accountId, }: {
configOrCurrencyId: HederaCoinConfig | string;
accountId: string;
}) => Promise<string | null>;
/**
* Calculates the uncommitted balance change for an account between two timestamps.
*
* This function handles the timing mismatch between Mirror Node balance snapshots and actual transactions.
* Balance snapshots are taken at regular intervals, not at every transaction, so querying by exact timestamp
* may return a snapshot from before moment you need.
*
* @param address - Hedera account ID (e.g., "0.0.12345")
* @param startTimestamp - Start of the time range (exclusive, format: "1234567890.123456789")
* @param endTimestamp - End of the time range (inclusive, format: "1234567890.123456789")
* @returns The net balance change as BigInt (sum of all transfers to/from the account)
*/
export declare const calculateUncommittedBalanceChange: ({ configOrCurrencyId, address, startTimestamp, endTimestamp, }: {
configOrCurrencyId: HederaCoinConfig | string;
address: string;
startTimestamp: string;
endTimestamp: string;
}) => Promise<BigNumber>;
/**
* Hedera uses the AccountUpdateTransaction for multiple purposes, including staking operations.
* Mirror node classifies all such transactions under the same name: "CRYPTOUPDATEACCOUNT".
*
* This function distinguishes between:
* - DELEGATE: Account started staking (staked_node_id changed from null to a node ID)
* - UNDELEGATE: Account stopped staking (staked_node_id changed from a node ID to null)
* - REDELEGATE: Account changed staking node (staked_node_id changed from one node to another)
*
* The analysis works by:
* 1. Fetching the account state BEFORE the transaction (using lt: timestamp filter)
* 2. Fetching the account state AFTER the transaction (using eq: timestamp filter)
* 3. Comparing the staked_node_id field to determine what changed
* 4. Calculating the actual staked amount by replaying uncommitted transactions between
* the latest balance snapshot and the staking operation to handle snapshot timing mismatches
*
* @performance
* Makes 3 API calls per operation:
* - account state before
* - account state after
* - transaction history based on latest balance snapshot
*
* Batching would complicate code for minimal gain given low staking op frequency.
*/
export declare const analyzeStakingOperation: ({ configOrCurrencyId, address, mirrorTx, }: {
configOrCurrencyId: HederaCoinConfig | string;
address: string;
mirrorTx: HederaMirrorTransaction;
}) => Promise<StakingAnalysis | null>;
//# sourceMappingURL=utils.d.ts.map