All files / src/services types.ts

100% Statements 7/7
100% Branches 2/2
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115          42x 42x 42x 42x 42x 42x 42x                                                                                                                                                                                                              
import type { Bip32Account, GroupedAddress, WitnessedTx } from '@cardano-sdk/key-management';
import type { Cardano, Reward, Serialization } from '@cardano-sdk/core';
import type { Observable } from 'rxjs';
import type { Percent } from '@cardano-sdk/util';
 
export enum TransactionFailure {
  InvalidTransaction = 'INVALID_TRANSACTION',
  FailedToSubmit = 'FAILED_TO_SUBMIT',
  Unknown = 'UNKNOWN',
  CannotTrack = 'CANNOT_TRACK',
  Timeout = 'TIMEOUT',
  Phase2Validation = 'PHASE_2_VALIDATION'
}
 
export interface TransactionalObservables<T> {
  total$: Observable<T>;
  /** total - unspendable */
  available$: Observable<T>;
  unspendable$: Observable<T>;
}
 
export interface BalanceTracker {
  rewardAccounts: {
    rewards$: Observable<Cardano.Lovelace>;
    deposit$: Observable<Cardano.Lovelace>;
  };
  utxo: TransactionalObservables<Cardano.Value>;
}
 
export interface TransactionalTracker<T> extends TransactionalObservables<T> {
  shutdown(): void;
}
 
export interface UtxoTracker extends TransactionalTracker<Cardano.Utxo[]> {
  setUnspendable(utxo: Cardano.Utxo[]): Promise<void>;
}
 
/** The AddressDiscovery interface provides a mechanism to discover addresses in Hierarchical Deterministic (HD) wallets */
export interface AddressDiscovery {
  /**
   * Discover used addresses in the HD wallet.
   *
   * @param addressManager The address manager to be used to derive the addresses to be discovered.
   * @returns A promise that will be resolved into a GroupedAddress list containing the discovered addresses.
   */
  discover(addressManager: Bip32Account): Promise<GroupedAddress[]>;
}
 
export type Milliseconds = number;
 
export interface PollingConfig {
  readonly interval?: Milliseconds;
  /** Max timeout for exponential backoff on errors */
  readonly maxInterval?: Milliseconds;
  readonly consideredOutOfSyncAfter?: Milliseconds;
}
 
export interface OutgoingTx {
  cbor: Serialization.TxCBOR;
  body: Cardano.TxBody;
  id: Cardano.TransactionId;
  context?: WitnessedTx['context'];
}
 
export interface FailedTx extends OutgoingTx {
  reason: TransactionFailure;
  error?: unknown;
}
 
export interface OutgoingOnChainTx extends OutgoingTx {
  slot: Cardano.PartialBlockHeader['slot'];
}
 
export interface TxInFlight extends OutgoingTx {
  submittedAt?: Cardano.PartialBlockHeader['slot'];
}
 
export interface TransactionsTracker {
  readonly history$: Observable<Cardano.HydratedTx[]>;
  readonly rollback$: Observable<Cardano.HydratedTx>;
  readonly outgoing: {
    readonly inFlight$: Observable<TxInFlight[]>;
    readonly submitting$: Observable<OutgoingTx>;
    readonly pending$: Observable<OutgoingTx>;
    readonly signed$: Observable<WitnessedTx[]>;
    readonly failed$: Observable<FailedTx>;
    readonly onChain$: Observable<OutgoingOnChainTx>;
  };
}
 
export interface RewardsHistory {
  all: Reward[];
  lastReward: Reward | null;
  avgReward: Cardano.Lovelace | null;
  lifetimeRewards: Cardano.Lovelace;
}
 
/** Wallet delegated stake by pool. Multiple reward accounts could be delegated to the same pool */
export interface DelegatedStake {
  pool: Cardano.StakePool;
  /** How much from the total delegated stake is delegated to this pool */
  percentage: Percent;
  /** Absolute stake value */
  stake: bigint;
  /** Reward accounts delegated to this pool */
  rewardAccounts: Cardano.RewardAccount[];
}
 
export interface DelegationTracker {
  rewardsHistory$: Observable<RewardsHistory>;
  rewardAccounts$: Observable<Cardano.RewardAccountInfo[]>;
  distribution$: Observable<Map<Cardano.PoolId, DelegatedStake>>;
  portfolio$: Observable<Cardano.Cip17DelegationPortfolio | null>;
}