UNPKG

@metamask/keyring-api

Version:
323 lines 8.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransactionsPageStruct = exports.TransactionStruct = exports.TransactionEventStruct = exports.TransactionType = exports.TransactionStatus = exports.FeeType = void 0; const keyring_utils_1 = require("@metamask/keyring-utils"); const superstruct_1 = require("@metamask/superstruct"); const asset_1 = require("./asset.cjs"); const caip_1 = require("./caip.cjs"); /** * This struct represents a participant in a transaction. * * @example * ```ts * { * address: '0x1234...', * asset: { * fungible: true, * type: 'eip155:1/slip44:60', * unit: 'ETH', * amount: '0.01', * }, * }, * ``` * * @example * ```ts * { * address: '0x1234...', * asset: { * fungible: false, * id: 'eip155:1/erc721:0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/771769', * }, * }, * ``` * * @example * ```ts * { * address: '0x1234...', * asset: null, * }, * ``` */ const ParticipantStruct = (0, keyring_utils_1.object)({ /** * Participant address. */ address: (0, superstruct_1.string)(), /** * Asset being transferred. */ asset: (0, superstruct_1.nullable)(asset_1.AssetStruct), }); /** * Fee types. */ var FeeType; (function (FeeType) { /** * Base fee. It is the minimum fee required to include a transaction in the * blockchain. * * For non-confirmed transactions, it must be the maximum base fee. For * confirmed transactions, it must be the actual base fee paid. */ FeeType["Base"] = "base"; /** * Priority fee. It is an optional fee used to prioritize the transaction. * * For non-confirmed transactions, it must be the maximum priority fee. For * confirmed transactions, it must be the actual priority fee paid. */ FeeType["Priority"] = "priority"; })(FeeType || (exports.FeeType = FeeType = {})); /** * This struct represents a transaction fee. */ const FeeStruct = (0, keyring_utils_1.object)({ /** * Fee type {@see FeeType}. */ type: (0, superstruct_1.enums)([`${FeeType.Base}`, `${FeeType.Priority}`]), /** * Asset used to pay for the fee. */ asset: asset_1.AssetStruct, }); /** * Transaction statuses. */ var TransactionStatus; (function (TransactionStatus) { /** * The transaction has been submitted but is not yet in the * blockchain. For example, it can be in the mempool. */ TransactionStatus["Submitted"] = "submitted"; /** * The transaction is in the blockchain but has not been * confirmed yet. */ TransactionStatus["Unconfirmed"] = "unconfirmed"; /** * The transaction has been confirmed. */ TransactionStatus["Confirmed"] = "confirmed"; /** * The transaction has failed. For example, it has been reverted. */ TransactionStatus["Failed"] = "failed"; })(TransactionStatus || (exports.TransactionStatus = TransactionStatus = {})); /** * Transaction types. */ var TransactionType; (function (TransactionType) { /** * The transaction was originated by the account. If the transaction * has a change output that goes back to the same account, it must be tagged * as a send transaction. */ TransactionType["Send"] = "send"; /** * The transaction was received by the account, but originated by * another account. */ TransactionType["Receive"] = "receive"; /** * The transaction is a swap. It decreases the balance of one asset and * increases the balance of another asset in a single transaction. * * A swap transaction must be originated by the account. */ TransactionType["Swap"] = "swap"; /** * Represents an outgoing bridge transaction, transferring assets from * the account to another blockchain. */ TransactionType["BridgeSend"] = "bridge:send"; /** * Represents an incoming bridge transaction, transferring assets from * another blockchain to the account. */ TransactionType["BridgeReceive"] = "bridge:receive"; /** * The transaction type is unknown. It's not possible to determine the * transaction type based on the information available. */ TransactionType["Unknown"] = "unknown"; })(TransactionType || (exports.TransactionType = TransactionType = {})); /** * This struct represents a transaction event. */ exports.TransactionEventStruct = (0, keyring_utils_1.object)({ /** * New status of the transaction. */ status: (0, superstruct_1.enums)([ `${TransactionStatus.Submitted}`, `${TransactionStatus.Unconfirmed}`, `${TransactionStatus.Confirmed}`, `${TransactionStatus.Failed}`, ]), /** * UNIX timestamp of when the event occurred. */ timestamp: (0, superstruct_1.nullable)((0, superstruct_1.number)()), }); /** * This struct represents a blockchain transaction. * * @example * ```ts * const tx = { * id: 'f5d8ee39a430901c91a5917b9f2dc19d6d1a0e9cea205b009ca73dd04470b9a6', * chain: 'bip122:000000000019d6689c085ae165831e93', * account: 'b9beb861-9761-4b97-89ce-d992be5f34da', * status: 'confirmed', * timestamp: 1716367781, * type: 'send', * from: [ * { * address: 'bc1qrp0yzgkf8rawkuvdlhnjfj2fnjwm0m8727kgah', * asset: { * fungible: true, * type: 'bip122:000000000019d6689c085ae165831e93/slip44:0', * unit: 'BTC', * amount: '0.1', * }, * }, * ], * to: [ * { * address: 'bc1qrp0yzgkf8rawkuvdlhnjfj2fnjwm0m8727kgah', * asset: { * fungible: true, * type: 'bip122:000000000019d6689c085ae165831e93/slip44:0', * unit: 'BTC', * amount: '0.1', * }, * }, * { * address: 'bc1qwl8399fz829uqvqly9tcatgrgtwp3udnhxfq4k', * asset: { * fungible: true, * type: 'bip122:000000000019d6689c085ae165831e93/slip44:0', * unit: 'BTC', * amount: '0.1', * }, * }, * ], * fees: [ * { * type: 'priority', * asset: { * fungible: true, * type: 'bip122:000000000019d6689c085ae165831e93/slip44:0', * unit: 'BTC', * amount: '0.1', * }, * }, * ], * }; * ``` */ exports.TransactionStruct = (0, keyring_utils_1.object)({ /** * Chain-specific transaction ID. */ id: (0, superstruct_1.string)(), /** * Chain ID (CAIP-2). */ chain: caip_1.CaipChainIdStruct, /** * Account ID (UUIDv4). */ account: keyring_utils_1.UuidStruct, /** * Transaction status {@see TransactionStatus}. */ status: (0, superstruct_1.enums)([ `${TransactionStatus.Submitted}`, `${TransactionStatus.Unconfirmed}`, `${TransactionStatus.Confirmed}`, `${TransactionStatus.Failed}`, ]), /** * UNIX timestamp of when the transaction was added to the blockchain. The * timestamp can be null if the transaction has not been included in the * blockchain yet. */ timestamp: (0, superstruct_1.nullable)((0, superstruct_1.number)()), /** * Transaction type {@see TransactionType}. This will be used by MetaMask to enrich the transaction * details on the UI. */ type: (0, superstruct_1.enums)([ `${TransactionType.Send}`, `${TransactionType.Receive}`, `${TransactionType.Swap}`, `${TransactionType.BridgeSend}`, `${TransactionType.BridgeReceive}`, `${TransactionType.Unknown}`, ]), /** * Transaction sender addresses and amounts. */ from: (0, superstruct_1.array)(ParticipantStruct), /** * Transaction receiver addresses and amounts. */ to: (0, superstruct_1.array)(ParticipantStruct), /** * Total transaction fee. */ fees: (0, superstruct_1.array)(FeeStruct), /** * List of events related to the transaction {@see TransactionEventStruct}. * * The events are tracked in a best-effort basis and may not be available for * all transactions. */ events: (0, superstruct_1.array)(exports.TransactionEventStruct), }); /** * This struct represents a page of transactions. * * @example * ```ts * { * data: [ * { * // Transaction object * } * ], * next: 'c3y1Q6QtqtstbxKX+oqVdEW6', * } * ``` * * @example * ```ts * { * data: [ * { * // Transaction object * } * ], * next: null, // No more results * }** * ``` */ exports.TransactionsPageStruct = (0, keyring_utils_1.object)({ /** * List of transactions. */ data: (0, superstruct_1.array)(exports.TransactionStruct), /** * Next cursor to iterate over the results. If null, there are no more * results. */ next: (0, superstruct_1.nullable)((0, superstruct_1.string)()), }); //# sourceMappingURL=transaction.cjs.map