UNPKG

@moralisweb3/common-streams-utils

Version:

1,282 lines (1,267 loc) 149 kB
'use strict'; var commonAptosUtils = require('@moralisweb3/common-aptos-utils'); var commonCore = require('@moralisweb3/common-core'); var commonEvmUtils = require('@moralisweb3/common-evm-utils'); var abi = require('@ethersproject/abi'); /****************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ var __assign = function() { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } /** * The AptosStream class is a representation of an Aptos Stream that is returned by the Moralis Stream API * * @category DataType */ var AptosStream = /** @class */ (function () { function AptosStream(data) { this._data = AptosStream.parse(data); } /** * Create a new instance of AptosStream * * @param data - the AptosStreamish type * @example * ```ts * const aptosStream = AptosStream.create(data); * ``` * @returns an instance of AptosStream */ AptosStream.create = function (data) { if (data instanceof AptosStream) { return data; } return new AptosStream(data); }; /** * Compares two AptosStream data. It checks a deep equality check of both values. * @param valueA - the first AptosStreamish data to compare * @param valueB - the second AptosStreamish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * AptosStream.equals(valueA, valueB); * ``` */ AptosStream.equals = function (valueA, valueB) { var aptosStreamA = AptosStream.create(valueA); var aptosStreamB = AptosStream.create(valueB); if (aptosStreamA.id !== aptosStreamB.id) { return false; } return true; }; /** * Compares an AptosStreamish data to this AptosStream instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * aptosStream.equals(value); * ``` */ AptosStream.prototype.equals = function (value) { return AptosStream.equals(this, value); }; /** * Converts the AptosStream instance to a JSON object. * @returns JSON object of the AptosStream instance * @example `aptosStream.toJSON()` */ AptosStream.prototype.toJSON = function () { return __assign(__assign({}, this._data), { network: this.network.map(function (network) { return network.toJSON(); }) }); }; /** * Converts the AptosStream instance to a JSON object. * @returns JSON object of the AptosStream instance * @example `aptosStream.format()` */ AptosStream.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(AptosStream.prototype, "network", { get: function () { return this._data.network; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "webhookUrl", { get: function () { return this._data.webhookUrl; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "description", { get: function () { return this._data.description; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "tag", { get: function () { return this._data.tag; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "allAddresses", { get: function () { return this._data.allAddresses; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "id", { get: function () { return this._data.id; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "status", { get: function () { return this._data.status; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "statusMessage", { get: function () { return this._data.statusMessage; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "demo", { get: function () { return this._data.demo; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "includeChanges", { get: function () { return this._data.includeChanges; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "includeEvents", { get: function () { return this._data.includeEvents; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "includePayload", { get: function () { return this._data.includePayload; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "isErrorSince", { get: function () { return this._data.isErrorSince; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "events", { get: function () { return this._data.events; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "functions", { get: function () { return this._data.functions; }, enumerable: false, configurable: true }); Object.defineProperty(AptosStream.prototype, "amountOfAddresses", { get: function () { return this._data.amountOfAddresses; }, enumerable: false, configurable: true }); AptosStream.parse = function (data) { return __assign(__assign({}, data), { network: data.network.map(function (network) { return commonAptosUtils.AptosNetwork.create(network); }) }); }; return AptosStream; }()); /** * The StreamSelector class is a representation of a stream selector * * Use this class any time you want to use a value in your stream trigger data that is not a static value * * @category DataType */ var StreamSelector = /** @class */ (function () { /** * Create a new instance of StreamSelector from any valid stream data field * * @example * ``` * const receiverSelector = StreamSelector.create('$to') * const selector = StreamSelector.create('$contract') * ``` */ function StreamSelector(data) { this._value = StreamSelector.parse(data); } StreamSelector.isSelectorString = function (selector) { if (selector instanceof StreamSelector) { return true; } return selector.startsWith('$'); }; StreamSelector.create = function (streamSelector) { if (streamSelector instanceof StreamSelector) { return streamSelector; } return new StreamSelector(streamSelector); }; StreamSelector.parse = function (streamSelector) { if (!StreamSelector.isSelectorString(streamSelector)) { throw new commonCore.CoreError({ code: commonCore.CoreErrorCode.INVALID_ARGUMENT, message: 'Invalid selector string provided', }); } return streamSelector; }; /** * Compares two StreamSelector data. It checks a deep equality check of both values. * @param valueA - the first StreamSelectorish data to compare * @param valueB - the second StreamSelectorish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * StreamSelector.equals(valueA, valueB); * ``` */ StreamSelector.equals = function (valueA, valueB) { var streamSelectorA = StreamSelector.create(valueA); var streamSelectorB = StreamSelector.create(valueB); return streamSelectorA.value === streamSelectorB.value; }; /** * Compares an StreamSelectorish data to this StreamSelector instance. * @param streamSelector - the streamSelector to compare * @returns true if the streamSelector is equal to the current instance, false otherwise * @example * ```ts * streamSelector.equals(streamSelector); * ``` */ StreamSelector.prototype.equals = function (streamSelector) { return StreamSelector.equals(this, streamSelector); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ StreamSelector.prototype.format = function () { return this.value; }; Object.defineProperty(StreamSelector.prototype, "value", { /** * @returns the selector path * @example '$from' */ get: function () { return this._value; }, enumerable: false, configurable: true }); StreamSelector.prototype.toJSON = function () { return this.value; }; return StreamSelector; }()); /** * The StreamTrigger class is a representation of a stream trigger that is used by the Moralis Stream API * * @category DataType */ var StreamTrigger = /** @class */ (function () { function StreamTrigger(data) { this._data = StreamTrigger.parse(data); } StreamTrigger.create = function (data) { if (data instanceof StreamTrigger) { return data; } return new StreamTrigger(data); }; StreamTrigger.parseSelectorOrAddress = function (input) { var result; // If it is not an EvmAddress, it can be a string, but only the ones that are selectors should be treated that way if (!(input instanceof commonEvmUtils.EvmAddress) && StreamSelector.isSelectorString(input)) { result = StreamSelector.create(input); } else { result = commonEvmUtils.EvmAddress.create(input); } return result; }; // eslint-disable-next-line complexity StreamTrigger.equals = function (valueA, valueB) { var _a, _b; var streamTriggerA = StreamTrigger.create(valueA); var streamTriggerB = StreamTrigger.create(valueB); if (streamTriggerA.type !== streamTriggerB.type) { return false; } // contractAddress can be a StreamSelector or an EvmAddress. It is easier to compare them as strings if (streamTriggerA.contractAddress.toJSON() !== streamTriggerB.contractAddress.toJSON()) { return false; } if (streamTriggerA.functionAbi !== streamTriggerB.functionAbi) { return false; } if (((_a = streamTriggerA.inputs) === null || _a === void 0 ? void 0 : _a.length) !== ((_b = streamTriggerB.inputs) === null || _b === void 0 ? void 0 : _b.length)) { return false; } var triggerInputsA = streamTriggerA.inputs || []; var triggerInputsB = streamTriggerB.inputs || []; for (var i = 0; i < (triggerInputsA === null || triggerInputsA === void 0 ? void 0 : triggerInputsA.length); i++) { if (triggerInputsA[i] !== triggerInputsB[i]) { return false; } } if (streamTriggerA.topic0 !== streamTriggerB.topic0) { return false; } if (streamTriggerA.callFrom !== streamTriggerB.callFrom) { return false; } return true; }; /** * Compares two StreamTrigger arrays. It checks a deep equality check of both values, meaning that all the values have to be on both arrays. * @param valueA - the first StreamTriggerish[] data to compare * @param valueB - the second StreamTriggerish[] data to compare * @returns true if all values are equal, false otherwise * @example * ```ts * StreamTrigger.arrayEquals(valueA, valueB); * ``` */ StreamTrigger.arrayEquals = function (valueA, valueB) { if (valueA.length !== valueB.length) { return false; } var triggersA = valueA.map(function (trigger) { return StreamTrigger.create(trigger); }); var triggersB = valueB.map(function (trigger) { return StreamTrigger.create(trigger); }); var seenTriggersB = Array(triggersB.length).fill(false); var _loop_1 = function (i) { var indexB = triggersB.findIndex(function (triggerB) { return triggerB.equals(triggersA[i]); }); if (indexB < 0) { return { value: false }; } seenTriggersB[indexB] = true; }; for (var i = 0; i < triggersA.length; i++) { var state_1 = _loop_1(i); if (typeof state_1 === "object") return state_1.value; } if (seenTriggersB.some(function (seen) { return !seen; })) { return false; } return true; }; /** * Compares an StreamTrigger data to this StreamTrigger instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * streamTrigger.equals(value); * ``` */ StreamTrigger.prototype.equals = function (value) { return StreamTrigger.equals(this, value); }; /** * Converts the StreamTrigger instance to a JSON object. * @returns JSON object of the StreamTrigger instance * @example `streamTrigger.toJSON()` */ StreamTrigger.prototype.toJSON = function () { var _a = this._data, contractAddress = _a.contractAddress, callFrom = _a.callFrom, data = __rest(_a, ["contractAddress", "callFrom"]); return __assign(__assign({}, data), { contractAddress: contractAddress.toJSON(), callFrom: callFrom === null || callFrom === void 0 ? void 0 : callFrom.toJSON() }); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ StreamTrigger.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(StreamTrigger.prototype, "type", { get: function () { return this._data.type; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTrigger.prototype, "contractAddress", { get: function () { return this._data.contractAddress; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTrigger.prototype, "functionAbi", { get: function () { return this._data.functionAbi; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTrigger.prototype, "inputs", { get: function () { return this._data.inputs; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTrigger.prototype, "topic0", { get: function () { return this._data.topic0; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTrigger.prototype, "callFrom", { get: function () { return this._data.callFrom; }, enumerable: false, configurable: true }); StreamTrigger.parse = function (data) { var contractAddressInput = data.contractAddress, callFromInput = data.callFrom, input = __rest(data, ["contractAddress", "callFrom"]); var contractAddress = StreamTrigger.parseSelectorOrAddress(contractAddressInput); var callFrom = commonCore.maybe(callFromInput, function (value) { return StreamTrigger.parseSelectorOrAddress(value); }); return __assign(__assign({}, input), { contractAddress: contractAddress, callFrom: callFrom }); }; return StreamTrigger; }()); /** * The EvmStream class is a representation of Moralis Stream that is returned by the Moralis Stream API * * @category DataType */ var EvmStream = /** @class */ (function () { function EvmStream(data) { this._data = EvmStream.parse(data); } /** * Create a new instance of EvmStream * * @param data - the EvmStreamish type * @example * ```ts * const evmStream = EvmStream.create(data); * ``` * @returns an instance of EvmStream */ EvmStream.create = function (data) { if (data instanceof EvmStream) { return data; } return new EvmStream(data); }; /** * Compares two EvmStream data. It checks a deep equality check of both values. * @param valueA - the first EvmStreamish data to compare * @param valueB - the second EvmStreamish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * EvmStream.equals(valueA, valueB); * ``` */ EvmStream.equals = function (valueA, valueB) { var _a, _b; var evmStreamA = EvmStream.create(valueA); var evmStreamB = EvmStream.create(valueB); if (evmStreamA.id !== evmStreamB.id) { return false; } if (((_a = evmStreamA.triggers) === null || _a === void 0 ? void 0 : _a.length) !== ((_b = evmStreamB.triggers) === null || _b === void 0 ? void 0 : _b.length) || !StreamTrigger.arrayEquals(evmStreamA.triggers || [], evmStreamB.triggers || [])) { return false; } return true; }; /** * Compares an EvmStreamish data to this EvmStream instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * evmStream.equals(value); * ``` */ EvmStream.prototype.equals = function (value) { return EvmStream.equals(this, value); }; /** * Converts the EvmStream instance to a JSON object. * @returns JSON object of the EvmStream instance * @example `evmStream.toJSON()` */ EvmStream.prototype.toJSON = function () { var _a = this._data, chains = _a.chains, triggers = _a.triggers, data = __rest(_a, ["chains", "triggers"]); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return __assign(__assign({}, data), { chainIds: chains.map(function (chain) { return chain.toJSON(); }), triggers: triggers === null || triggers === void 0 ? void 0 : triggers.map(function (trigger) { return trigger.format(); }) }); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ EvmStream.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(EvmStream.prototype, "chains", { get: function () { return this._data.chains; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "chainIds", { get: function () { return this._data.chains.map(function (chain) { return chain.hex; }); }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "webhookUrl", { get: function () { return this._data.webhookUrl; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "description", { get: function () { return this._data.description; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "tag", { get: function () { return this._data.tag; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "topic0", { get: function () { return this._data.topic0; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "allAddresses", { get: function () { return this._data.allAddresses; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "includeNativeTxs", { get: function () { return this._data.includeNativeTxs; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "includeContractLogs", { get: function () { return this._data.includeContractLogs; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "includeInternalTxs", { get: function () { return this._data.includeInternalTxs; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "includeAllTxLogs", { get: function () { return this._data.includeAllTxLogs; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "abi", { get: function () { return this._data.abi; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "advancedOptions", { get: function () { return this._data.advancedOptions; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "id", { get: function () { return this._data.id; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "status", { get: function () { return this._data.status; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "statusMessage", { get: function () { return this._data.statusMessage; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "triggers", { get: function () { return this._data.triggers; }, enumerable: false, configurable: true }); Object.defineProperty(EvmStream.prototype, "getNativeBalances", { get: function () { return this._data.getNativeBalances; }, enumerable: false, configurable: true }); EvmStream.parse = function (data) { var _a, _b, _c, _d, _e; return __assign(__assign({}, data), { chains: data.chainIds.map(function (chainId) { return commonEvmUtils.EvmChain.create(chainId); }), topic0: commonCore.maybe(data.topic0), allAddresses: (_a = data.allAddresses) !== null && _a !== void 0 ? _a : false, includeContractLogs: (_b = data.includeContractLogs) !== null && _b !== void 0 ? _b : false, includeInternalTxs: (_c = data.includeInternalTxs) !== null && _c !== void 0 ? _c : false, includeAllTxLogs: (_d = data.includeAllTxLogs) !== null && _d !== void 0 ? _d : false, includeNativeTxs: (_e = data.includeNativeTxs) !== null && _e !== void 0 ? _e : false, advancedOptions: commonCore.maybe(data.advancedOptions), abi: commonCore.maybe(data.abi), triggers: commonCore.maybe(data.triggers, function (triggers) { return triggers.map(function (trigger) { return StreamTrigger.create(trigger); }); }), getNativeBalances: commonCore.maybe(data.getNativeBalances) }); }; return EvmStream; }()); var EvmStreamResultFormatter = /** @class */ (function () { function EvmStreamResultFormatter() { } EvmStreamResultFormatter.toJSON = function (data) { return __assign(__assign({}, data), { erc20Transfers: data.erc20Transfers.map(function (value) { return value.toJSON(); }), erc20Approvals: data.erc20Approvals.map(function (value) { return value.toJSON(); }), nftTransfers: data.nftTransfers.map(function (value) { return value.toJSON(); }), nftApprovals: { ERC721: data.nftApprovals.ERC721.map(function (value) { return value.toJSON(); }), ERC1155: data.nftApprovals.ERC1155.map(function (value) { return value.toJSON(); }), }, ntfTokenApprovals: data.ntfTokenApprovals.map(function (value) { return value.toJSON(); }), chain: data.chain.toJSON(), block: data.block.toJSON(), logs: data.logs.map(function (value) { return value.toJSON(); }), txs: data.txs.map(function (value) { return value.toJSON(); }), txsInternal: data.txsInternal.map(function (value) { return value.toJSON(); }), abi: data.abi, nativeBalances: data.nativeBalances.map(function (nativeBalance) { return nativeBalance.toJSON(); }) }); }; return EvmStreamResultFormatter; }()); /** * The StreamTrigger class is a representation of a stream trigger that is used by the Moralis Stream API * * @category DataType */ var StreamTriggerOutput = /** @class */ (function () { function StreamTriggerOutput(data) { this._data = StreamTriggerOutput.parse(data); } StreamTriggerOutput.create = function (data) { if (data instanceof StreamTriggerOutput) { return data; } return new StreamTriggerOutput(data); }; /** * Compares two StreamTriggerOutput data. It checks a deep equality check of both values. * @param valueA - the first StreamTriggerOutputish data to compare * @param valueB - the second StreamTriggerOutputish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * StreamTriggerOutput.equals(valueA, valueB); * ``` */ StreamTriggerOutput.equals = function (valueA, valueB) { var streamTriggerOutputA = StreamTriggerOutput.create(valueA); var streamTriggerOutputB = StreamTriggerOutput.create(valueB); return (streamTriggerOutputA.name === streamTriggerOutputB.name && streamTriggerOutputA.value === streamTriggerOutputB.value); }; /** * Compares two StreamTriggerOutput arrays. It checks a deep equality check of both values, meaning that all the values have to be on both arrays. * @param valueA - the first StreamTriggerOutputish[] data to compare * @param valueB - the second StreamTriggerOutputish[] data to compare * @returns true if all values are equal, false otherwise * @example * ```ts * StreamTriggerOutput.arrayEquals(valueA, valueB); * ``` */ StreamTriggerOutput.arrayEquals = function (valueA, valueB) { if (valueA.length !== valueB.length) { return false; } var triggerOutputsA = valueA.map(function (triggerOutput) { return StreamTriggerOutput.create(triggerOutput); }); var triggerOutputsB = valueB.map(function (triggerOutput) { return StreamTriggerOutput.create(triggerOutput); }); triggerOutputsA.sort(function (a, b) { return (b.name > a.name ? 1 : -1); }); triggerOutputsB.sort(function (a, b) { return (b.name > a.name ? 1 : -1); }); for (var i = 0; i < (triggerOutputsA === null || triggerOutputsA === void 0 ? void 0 : triggerOutputsA.length); i++) { if (!triggerOutputsA[i].equals(triggerOutputsB[i])) { return false; } } return true; }; /** * Compares an StreamTriggerOutputish data to this StreamTriggerOutput instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * streamTriggerOutput.equals(value); * ``` */ StreamTriggerOutput.prototype.equals = function (value) { return StreamTriggerOutput.equals(this, value); }; /** * Converts the StreamTriggerOutput instance to a JSON object. * @returns JSON object of the StreamTriggerOutput instance * @example `streamTriggerOutput.toJSON()` */ StreamTriggerOutput.prototype.toJSON = function () { var data = __rest(this._data, []); return __assign({}, data); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ StreamTriggerOutput.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(StreamTriggerOutput.prototype, "name", { get: function () { return this._data.name; }, enumerable: false, configurable: true }); Object.defineProperty(StreamTriggerOutput.prototype, "value", { get: function () { return this._data.value; }, enumerable: false, configurable: true }); StreamTriggerOutput.parse = function (data) { return __assign({}, data); }; return StreamTriggerOutput; }()); /** * The StreamErc1155Approval class is a representation of a nft approval (ERC1155) that is returned by the Moralis Stream API * * @category DataType */ var StreamErc1155Approval = /** @class */ (function () { function StreamErc1155Approval(data) { this._data = StreamErc1155Approval.parse(data); } /** * Create a new instance of StreamErc1155Approval * * @param data - the StreamErc1155Approvalish type * @example * ```ts * const evmNftApproval = StreamErc1155Approval.create(data); * ``` * @returns an instance of StreamErc1155Approval */ StreamErc1155Approval.create = function (data) { if (data instanceof StreamErc1155Approval) { return data; } return new StreamErc1155Approval(data); }; /** * Compares two StreamErc1155Approval data. It checks a deep equality check of both values. * @param valueA - the first StreamErc1155Approvalish data to compare * @param valueB - the second StreamErc1155Approvalish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * StreamErc1155Approval.equals(valueA, valueB); * ``` */ // eslint-disable-next-line complexity StreamErc1155Approval.equals = function (valueA, valueB) { var _a, _b; var evmNftApprovalA = StreamErc1155Approval.create(valueA); var evmNftApprovalB = StreamErc1155Approval.create(valueB); if (!evmNftApprovalA.chain.equals(evmNftApprovalB.chain)) { return false; } if (evmNftApprovalA.transactionHash !== evmNftApprovalB.transactionHash) { return false; } if (!evmNftApprovalA.account.equals(evmNftApprovalB.account)) { return false; } if (!evmNftApprovalA.contract.equals(evmNftApprovalB.contract)) { return false; } if (!evmNftApprovalA.operator.equals(evmNftApprovalB.operator)) { return false; } if (evmNftApprovalA.approved !== evmNftApprovalB.approved) { return false; } if (((_a = evmNftApprovalA.triggers) === null || _a === void 0 ? void 0 : _a.length) !== ((_b = evmNftApprovalB.triggers) === null || _b === void 0 ? void 0 : _b.length) || !StreamTriggerOutput.arrayEquals(evmNftApprovalA.triggers || [], evmNftApprovalB.triggers || [])) { return false; } return true; }; /** * Compares an StreamErc1155Approvalish data to this StreamErc1155Approval instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * evmNftApproval.equals(value); * ``` */ StreamErc1155Approval.prototype.equals = function (value) { return StreamErc1155Approval.equals(this, value); }; /** * Converts the StreamErc1155Approval instance to a JSON object. * @returns JSON object of the StreamErc1155Approval instance * @example `evmNftApproval.toJSON()` */ StreamErc1155Approval.prototype.toJSON = function () { var _a; var data = this._data; return __assign(__assign({}, data), { chain: data.chain.toJSON(), contract: data.contract.toJSON(), account: data.account.toJSON(), operator: data.operator.toJSON(), triggers: (_a = data.triggers) === null || _a === void 0 ? void 0 : _a.map(function (trigger) { return trigger.format(); }) }); }; /** * Converts the StreamErc1155Approval instance to a JSON object. * @returns JSON object of the StreamErc1155Approval instance * @example `evmNftApproval.format()` */ StreamErc1155Approval.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(StreamErc1155Approval.prototype, "chain", { get: function () { return this._data.chain; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "approved", { get: function () { return this._data.approved; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "transactionHash", { get: function () { return this._data.transactionHash; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "contract", { get: function () { return this._data.contract; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "logIndex", { get: function () { return this._data.logIndex; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "account", { get: function () { return this._data.account; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "operator", { get: function () { return this._data.operator; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "tokenContractType", { get: function () { return this._data.tokenContractType; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "tokenName", { get: function () { return this._data.tokenName; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "tokenSymbol", { get: function () { return this._data.tokenSymbol; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc1155Approval.prototype, "triggers", { get: function () { return this._data.triggers; }, enumerable: false, configurable: true }); StreamErc1155Approval.parse = function (data) { var chain = commonEvmUtils.EvmChain.create(data.chain); return __assign(__assign({}, data), { chain: chain, logIndex: +data.logIndex, account: commonEvmUtils.EvmAddress.create(data.account), operator: commonEvmUtils.EvmAddress.create(data.operator), contract: commonEvmUtils.EvmAddress.create(data.contract), tokenContractType: data.tokenContractType, triggers: commonCore.maybe(data.triggers, function (triggers) { return triggers.map(function (trigger) { return StreamTriggerOutput.create(trigger); }); }) }); }; return StreamErc1155Approval; }()); /** * The StreamErc20Transfer class is a representation of a erc20 approval that is returned by the Moralis Stream API * * @category DataTypexw */ var StreamErc20Approval = /** @class */ (function () { function StreamErc20Approval(data) { this._data = StreamErc20Approval.parse(data); } /** * Create a new instance of StreamErc20Approval * * @param data - the StreamErc20Approvalish type * @example * ```ts * const erc20Approval = StreamErc20Approval.create(data); * ``` * @returns an instance of StreamErc20Approval */ StreamErc20Approval.create = function (data) { if (data instanceof StreamErc20Approval) { return data; } return new StreamErc20Approval(data); }; /** * Compares two StreamErc20Approval data. It checks a deep equality check of both values. * @param valueA - the first StreamErc20Approvalish data to compare * @param valueB - the second StreamErc20Approvalish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * StreamErc20Approval.equals(valueA, valueB); * ``` */ StreamErc20Approval.equals = function (valueA, valueB) { var _a, _b; var erc20ApprovalA = StreamErc20Approval.create(valueA); var erc20ApprovalB = StreamErc20Approval.create(valueB); if (!erc20ApprovalA.chain.equals(erc20ApprovalB.chain)) { return false; } if (erc20ApprovalA.transactionHash !== erc20ApprovalB.transactionHash) { return false; } if (erc20ApprovalA.logIndex !== erc20ApprovalB.logIndex) { return false; } if (((_a = erc20ApprovalA.triggers) === null || _a === void 0 ? void 0 : _a.length) !== ((_b = erc20ApprovalB.triggers) === null || _b === void 0 ? void 0 : _b.length) || !StreamTriggerOutput.arrayEquals(erc20ApprovalA.triggers || [], erc20ApprovalB.triggers || [])) { return false; } return true; }; /** * Compares an StreamErc20Approvalish data to this StreamErc20Approval instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * erc20Approval.equals(value); * ``` */ StreamErc20Approval.prototype.equals = function (value) { return StreamErc20Approval.equals(this, value); }; /** * Converts the StreamErc20Approval instance to a JSON object. * @returns JSON object of the StreamErc20Approval instance * @example `erc20Approval.toJSON()` */ StreamErc20Approval.prototype.toJSON = function () { var _a = this._data, chain = _a.chain, owner = _a.owner, spender = _a.spender, contract = _a.contract, value = _a.value, triggers = _a.triggers, data = __rest(_a, ["chain", "owner", "spender", "contract", "value", "triggers"]); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return __assign(__assign({}, data), { chain: chain.toJSON(), owner: owner.toJSON(), spender: spender.toJSON(), contract: contract.toJSON(), value: value.toString(), triggers: triggers === null || triggers === void 0 ? void 0 : triggers.map(function (trigger) { return trigger.format(); }) }); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ StreamErc20Approval.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(StreamErc20Approval.prototype, "chain", { get: function () { return this._data.chain; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "transactionHash", { get: function () { return this._data.transactionHash; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "logIndex", { get: function () { return this._data.logIndex; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "owner", { get: function () { return this._data.owner; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "spender", { get: function () { return this._data.spender; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "value", { get: function () { return this._data.value; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "contract", { get: function () { return this._data.contract; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "tokenName", { get: function () { return this._data.tokenName; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "tokenSymbol", { get: function () { return this._data.tokenSymbol; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "tokenDecimals", { get: function () { return this._data.tokenDecimals; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "valueWithDecimals", { get: function () { return this._data.valueWithDecimals; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Approval.prototype, "triggers", { get: function () { return this._data.triggers; }, enumerable: false, configurable: true }); StreamErc20Approval.parse = function (data) { var chain = commonEvmUtils.EvmChain.create(data.chain); return __assign(__assign({}, data), { chain: chain, spender: commonEvmUtils.EvmAddress.create(data.spender), owner: commonEvmUtils.EvmAddress.create(data.owner), logIndex: +data.logIndex, contract: commonEvmUtils.EvmAddress.create(data.contract), value: commonCore.BigNumber.create(data.value), valueWithDecimals: commonCore.maybe(data.valueWithDecimals), tokenDecimals: data.tokenDecimals === '' ? undefined : +data.tokenDecimals, triggers: commonCore.maybe(data.triggers, function (triggers) { return triggers.map(function (trigger) { return StreamTriggerOutput.create(trigger); }); }) }); }; return StreamErc20Approval; }()); /** * The StreamErc20Transfer class is a representation of a erc20 transfer that is returned by the Moralis Stream API * * @category DataType */ var StreamErc20Transfer = /** @class */ (function () { function StreamErc20Transfer(data) { this._data = StreamErc20Transfer.parse(data); } /** * Create a new instance of StreamErc20Transfer * * @param data - the StreamErc20Transferish type * @example * ```ts * const erc20Transfer = StreamErc20Transfer.create(data); * ``` * @returns an instance of StreamErc20Transfer */ StreamErc20Transfer.create = function (data) { if (data instanceof StreamErc20Transfer) { return data; } return new StreamErc20Transfer(data); }; /** * Compares two StreamErc20Transfer data. It checks a deep equality check of both values. * @param valueA - the first StreamErc20Transferish data to compare * @param valueB - the second StreamErc20Transferish data to compare * @returns true if the values are equal, false otherwise * @example * ```ts * StreamErc20Transfer.equals(valueA, valueB); * ``` */ StreamErc20Transfer.equals = function (valueA, valueB) { var _a, _b; var erc20TransferA = StreamErc20Transfer.create(valueA); var erc20TransferB = StreamErc20Transfer.create(valueB); if (!erc20TransferA.chain.equals(erc20TransferB.chain)) { return false; } if (erc20TransferA.transactionHash !== erc20TransferB.transactionHash) { return false; } if (erc20TransferA.logIndex !== erc20TransferB.logIndex) { return false; } if (((_a = erc20TransferA.triggers) === null || _a === void 0 ? void 0 : _a.length) !== ((_b = erc20TransferB.triggers) === null || _b === void 0 ? void 0 : _b.length) || !StreamTriggerOutput.arrayEquals(erc20TransferA.triggers || [], erc20TransferB.triggers || [])) { return false; } return true; }; /** * Compares an StreamErc20Transferish data to this StreamErc20Transfer instance. * @param value - the value to compare * @returns true if the value is equal to the current instance, false otherwise * @example * ```ts * erc20Transfer.equals(value); * ``` */ StreamErc20Transfer.prototype.equals = function (value) { return StreamErc20Transfer.equals(this, value); }; /** * Converts the StreamErc20Transfer instance to a JSON object. * @returns JSON object of the StreamErc20Transfer instance * @example `erc20Transfer.toJSON()` */ StreamErc20Transfer.prototype.toJSON = function () { var _a = this._data, chain = _a.chain, from = _a.from, to = _a.to, contract = _a.contract, value = _a.value, triggers = _a.triggers, data = __rest(_a, ["chain", "from", "to", "contract", "value", "triggers"]); // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return __assign(__assign({}, data), { chain: chain.toJSON(), from: from.toJSON(), to: to.toJSON(), contract: contract.toJSON(), value: value.toString(), triggers: triggers === null || triggers === void 0 ? void 0 : triggers.map(function (trigger) { return trigger.format(); }) }); }; /** * @deprecated This method will be removed soon. To format the value, use one of the properties. */ StreamErc20Transfer.prototype.format = function () { return this.toJSON(); }; Object.defineProperty(StreamErc20Transfer.prototype, "chain", { get: function () { return this._data.chain; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Transfer.prototype, "transactionHash", { get: function () { return this._data.transactionHash; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Transfer.prototype, "logIndex", { get: function () { return this._data.logIndex; }, enumerable: false, configurable: true }); Object.defineProperty(StreamErc20Transfer.prototype, "from", { get: function () { return this._data.from; }, enumerable: false, configurable: true }); Object.defineProperty(St