@metamask-previews/smart-transactions-controller 19.2.1-preview-54c655a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +715 -0
- package/LICENSE +18 -0
- package/README.md +103 -0
- package/dist/SmartTransactionsController.cjs +694 -0
- package/dist/SmartTransactionsController.cjs.map +1 -0
- package/dist/SmartTransactionsController.d.cts +150 -0
- package/dist/SmartTransactionsController.d.cts.map +1 -0
- package/dist/SmartTransactionsController.d.mts +150 -0
- package/dist/SmartTransactionsController.d.mts.map +1 -0
- package/dist/SmartTransactionsController.mjs +702 -0
- package/dist/SmartTransactionsController.mjs.map +1 -0
- package/dist/constants.cjs +33 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.d.cts +23 -0
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +23 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +33 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/index.cjs +17 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +17 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.cjs +54 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +118 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +118 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +54 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +281 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +90 -0
- package/dist/utils.d.cts.map +1 -0
- package/dist/utils.d.mts +90 -0
- package/dist/utils.d.mts.map +1 -0
- package/dist/utils.mjs +289 -0
- package/dist/utils.mjs.map +1 -0
- package/package.json +135 -0
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { NetworkClientId } from "@metamask/network-controller";
|
|
2
|
+
/** API */
|
|
3
|
+
export declare enum APIType {
|
|
4
|
+
'GET_FEES' = 0,
|
|
5
|
+
'ESTIMATE_GAS' = 1,
|
|
6
|
+
'SUBMIT_TRANSACTIONS' = 2,
|
|
7
|
+
'CANCEL' = 3,
|
|
8
|
+
'BATCH_STATUS' = 4,
|
|
9
|
+
'LIVENESS' = 5
|
|
10
|
+
}
|
|
11
|
+
/** SmartTransactions */
|
|
12
|
+
export declare enum SmartTransactionMinedTx {
|
|
13
|
+
NOT_MINED = "not_mined",
|
|
14
|
+
SUCCESS = "success",
|
|
15
|
+
CANCELLED = "cancelled",
|
|
16
|
+
REVERTED = "reverted",
|
|
17
|
+
UNKNOWN = "unknown"
|
|
18
|
+
}
|
|
19
|
+
export declare enum SmartTransactionCancellationReason {
|
|
20
|
+
WOULD_REVERT = "would_revert",
|
|
21
|
+
TOO_CHEAP = "too_cheap",
|
|
22
|
+
DEADLINE_MISSED = "deadline_missed",
|
|
23
|
+
INVALID_NONCE = "invalid_nonce",
|
|
24
|
+
USER_CANCELLED = "user_cancelled",
|
|
25
|
+
NOT_CANCELLED = "not_cancelled"
|
|
26
|
+
}
|
|
27
|
+
export declare enum SmartTransactionStatuses {
|
|
28
|
+
PENDING = "pending",
|
|
29
|
+
SUCCESS = "success",
|
|
30
|
+
REVERTED = "reverted",
|
|
31
|
+
UNKNOWN = "unknown",
|
|
32
|
+
CANCELLED = "cancelled",
|
|
33
|
+
CANCELLED_USER_CANCELLED = "cancelled_user_cancelled",
|
|
34
|
+
RESOLVED = "resolved"
|
|
35
|
+
}
|
|
36
|
+
export declare enum ClientId {
|
|
37
|
+
Mobile = "mobile",
|
|
38
|
+
Extension = "extension"
|
|
39
|
+
}
|
|
40
|
+
export declare const cancellationReasonToStatusMap: {
|
|
41
|
+
would_revert: SmartTransactionStatuses;
|
|
42
|
+
too_cheap: SmartTransactionStatuses;
|
|
43
|
+
deadline_missed: SmartTransactionStatuses;
|
|
44
|
+
invalid_nonce: SmartTransactionStatuses;
|
|
45
|
+
user_cancelled: SmartTransactionStatuses;
|
|
46
|
+
};
|
|
47
|
+
export declare type SmartTransactionsStatus = {
|
|
48
|
+
error?: string;
|
|
49
|
+
cancellationFeeWei: number;
|
|
50
|
+
cancellationReason?: SmartTransactionCancellationReason;
|
|
51
|
+
deadlineRatio: number;
|
|
52
|
+
minedHash: string;
|
|
53
|
+
minedTx: SmartTransactionMinedTx;
|
|
54
|
+
isSettled: boolean;
|
|
55
|
+
duplicated?: boolean;
|
|
56
|
+
timedOut?: boolean;
|
|
57
|
+
proxied?: boolean;
|
|
58
|
+
};
|
|
59
|
+
export declare type SmartTransaction = {
|
|
60
|
+
uuid: string;
|
|
61
|
+
txHash?: string;
|
|
62
|
+
txHashes?: string[];
|
|
63
|
+
chainId?: string;
|
|
64
|
+
destinationTokenAddress?: string;
|
|
65
|
+
destinationTokenDecimals?: string;
|
|
66
|
+
destinationTokenSymbol?: string;
|
|
67
|
+
history?: any;
|
|
68
|
+
nonceDetails?: any;
|
|
69
|
+
origin?: string;
|
|
70
|
+
preTxBalance?: string;
|
|
71
|
+
status?: string;
|
|
72
|
+
statusMetadata?: SmartTransactionsStatus;
|
|
73
|
+
sourceTokenSymbol?: string;
|
|
74
|
+
swapMetaData?: any;
|
|
75
|
+
swapTokenValue?: string;
|
|
76
|
+
time?: number;
|
|
77
|
+
creationTime?: number;
|
|
78
|
+
txParams?: any;
|
|
79
|
+
type?: string;
|
|
80
|
+
confirmed?: boolean;
|
|
81
|
+
cancellable?: boolean;
|
|
82
|
+
accountHardwareType?: string;
|
|
83
|
+
accountType?: string;
|
|
84
|
+
deviceModel?: string;
|
|
85
|
+
transactionId?: string;
|
|
86
|
+
networkClientId?: NetworkClientId;
|
|
87
|
+
};
|
|
88
|
+
export declare type Fee = {
|
|
89
|
+
maxFeePerGas: number;
|
|
90
|
+
maxPriorityFeePerGas: number;
|
|
91
|
+
};
|
|
92
|
+
export declare type IndividualTxFees = {
|
|
93
|
+
fees: Fee[];
|
|
94
|
+
cancelFees: Fee[];
|
|
95
|
+
feeEstimate: number;
|
|
96
|
+
gasLimit: number;
|
|
97
|
+
gasUsed: number;
|
|
98
|
+
};
|
|
99
|
+
export declare type Fees = {
|
|
100
|
+
approvalTxFees: IndividualTxFees | null;
|
|
101
|
+
tradeTxFees: IndividualTxFees | null;
|
|
102
|
+
};
|
|
103
|
+
export declare type UnsignedTransaction = any;
|
|
104
|
+
export declare type SignedTransaction = any;
|
|
105
|
+
export declare type SignedCanceledTransaction = any;
|
|
106
|
+
export declare type Hex = `0x${string}`;
|
|
107
|
+
export declare type MetaMetricsProps = {
|
|
108
|
+
accountHardwareType?: string;
|
|
109
|
+
accountType?: string;
|
|
110
|
+
deviceModel?: string;
|
|
111
|
+
};
|
|
112
|
+
export declare type FeatureFlags = {
|
|
113
|
+
smartTransactions?: {
|
|
114
|
+
mobileReturnTxHashAsap?: boolean;
|
|
115
|
+
extensionReturnTxHashAsap?: boolean;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AAEpE,UAAU;AACV,oBAAY,OAAO;IACjB,UAAU,IAAA;IACV,cAAc,IAAA;IACd,qBAAqB,IAAA;IACrB,QAAQ,IAAA;IACR,cAAc,IAAA;IACd,UAAU,IAAA;CACX;AAED,wBAAwB;AACxB,oBAAY,uBAAuB;IACjC,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,OAAO,YAAY;CACpB;AAED,oBAAY,kCAAkC;IAC5C,YAAY,iBAAiB;IAC7B,SAAS,cAAc;IACvB,eAAe,oBAAoB;IACnC,aAAa,kBAAkB;IAC/B,cAAc,mBAAmB;IAC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oBAAY,YAAY,GAAG;IACzB,iBAAiB,CAAC,EAAE;QAClB,sBAAsB,CAAC,EAAE,OAAO,CAAC;QACjC,yBAAyB,CAAC,EAAE,OAAO,CAAC;KACrC,CAAC;CACH,CAAC"}
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cancellationReasonToStatusMap = exports.ClientId = exports.SmartTransactionStatuses = exports.SmartTransactionCancellationReason = exports.SmartTransactionMinedTx = exports.APIType = void 0;
|
|
4
|
+
/** API */
|
|
5
|
+
var APIType;
|
|
6
|
+
(function (APIType) {
|
|
7
|
+
APIType[APIType["GET_FEES"] = 0] = "GET_FEES";
|
|
8
|
+
APIType[APIType["ESTIMATE_GAS"] = 1] = "ESTIMATE_GAS";
|
|
9
|
+
APIType[APIType["SUBMIT_TRANSACTIONS"] = 2] = "SUBMIT_TRANSACTIONS";
|
|
10
|
+
APIType[APIType["CANCEL"] = 3] = "CANCEL";
|
|
11
|
+
APIType[APIType["BATCH_STATUS"] = 4] = "BATCH_STATUS";
|
|
12
|
+
APIType[APIType["LIVENESS"] = 5] = "LIVENESS";
|
|
13
|
+
})(APIType = exports.APIType || (exports.APIType = {}));
|
|
14
|
+
/** SmartTransactions */
|
|
15
|
+
var SmartTransactionMinedTx;
|
|
16
|
+
(function (SmartTransactionMinedTx) {
|
|
17
|
+
SmartTransactionMinedTx["NOT_MINED"] = "not_mined";
|
|
18
|
+
SmartTransactionMinedTx["SUCCESS"] = "success";
|
|
19
|
+
SmartTransactionMinedTx["CANCELLED"] = "cancelled";
|
|
20
|
+
SmartTransactionMinedTx["REVERTED"] = "reverted";
|
|
21
|
+
SmartTransactionMinedTx["UNKNOWN"] = "unknown";
|
|
22
|
+
})(SmartTransactionMinedTx = exports.SmartTransactionMinedTx || (exports.SmartTransactionMinedTx = {}));
|
|
23
|
+
var SmartTransactionCancellationReason;
|
|
24
|
+
(function (SmartTransactionCancellationReason) {
|
|
25
|
+
SmartTransactionCancellationReason["WOULD_REVERT"] = "would_revert";
|
|
26
|
+
SmartTransactionCancellationReason["TOO_CHEAP"] = "too_cheap";
|
|
27
|
+
SmartTransactionCancellationReason["DEADLINE_MISSED"] = "deadline_missed";
|
|
28
|
+
SmartTransactionCancellationReason["INVALID_NONCE"] = "invalid_nonce";
|
|
29
|
+
SmartTransactionCancellationReason["USER_CANCELLED"] = "user_cancelled";
|
|
30
|
+
SmartTransactionCancellationReason["NOT_CANCELLED"] = "not_cancelled";
|
|
31
|
+
})(SmartTransactionCancellationReason = exports.SmartTransactionCancellationReason || (exports.SmartTransactionCancellationReason = {}));
|
|
32
|
+
var SmartTransactionStatuses;
|
|
33
|
+
(function (SmartTransactionStatuses) {
|
|
34
|
+
SmartTransactionStatuses["PENDING"] = "pending";
|
|
35
|
+
SmartTransactionStatuses["SUCCESS"] = "success";
|
|
36
|
+
SmartTransactionStatuses["REVERTED"] = "reverted";
|
|
37
|
+
SmartTransactionStatuses["UNKNOWN"] = "unknown";
|
|
38
|
+
SmartTransactionStatuses["CANCELLED"] = "cancelled";
|
|
39
|
+
SmartTransactionStatuses["CANCELLED_USER_CANCELLED"] = "cancelled_user_cancelled";
|
|
40
|
+
SmartTransactionStatuses["RESOLVED"] = "resolved";
|
|
41
|
+
})(SmartTransactionStatuses = exports.SmartTransactionStatuses || (exports.SmartTransactionStatuses = {}));
|
|
42
|
+
var ClientId;
|
|
43
|
+
(function (ClientId) {
|
|
44
|
+
ClientId["Mobile"] = "mobile";
|
|
45
|
+
ClientId["Extension"] = "extension";
|
|
46
|
+
})(ClientId = exports.ClientId || (exports.ClientId = {}));
|
|
47
|
+
exports.cancellationReasonToStatusMap = {
|
|
48
|
+
[SmartTransactionCancellationReason.WOULD_REVERT]: SmartTransactionStatuses.CANCELLED,
|
|
49
|
+
[SmartTransactionCancellationReason.TOO_CHEAP]: SmartTransactionStatuses.CANCELLED,
|
|
50
|
+
[SmartTransactionCancellationReason.DEADLINE_MISSED]: SmartTransactionStatuses.CANCELLED,
|
|
51
|
+
[SmartTransactionCancellationReason.INVALID_NONCE]: SmartTransactionStatuses.CANCELLED,
|
|
52
|
+
[SmartTransactionCancellationReason.USER_CANCELLED]: SmartTransactionStatuses.CANCELLED_USER_CANCELLED,
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAEA,UAAU;AACV,IAAY,OAOX;AAPD,WAAY,OAAO;IACjB,6CAAU,CAAA;IACV,qDAAc,CAAA;IACd,mEAAqB,CAAA;IACrB,yCAAQ,CAAA;IACR,qDAAc,CAAA;IACd,6CAAU,CAAA;AACZ,CAAC,EAPW,OAAO,GAAP,eAAO,KAAP,eAAO,QAOlB;AAED,wBAAwB;AACxB,IAAY,uBAMX;AAND,WAAY,uBAAuB;IACjC,kDAAuB,CAAA;IACvB,8CAAmB,CAAA;IACnB,kDAAuB,CAAA;IACvB,gDAAqB,CAAA;IACrB,8CAAmB,CAAA;AACrB,CAAC,EANW,uBAAuB,GAAvB,+BAAuB,KAAvB,+BAAuB,QAMlC;AAED,IAAY,kCAOX;AAPD,WAAY,kCAAkC;IAC5C,mEAA6B,CAAA;IAC7B,6DAAuB,CAAA;IACvB,yEAAmC,CAAA;IACnC,qEAA+B,CAAA;IAC/B,uEAAiC,CAAA;IACjC,qEAA+B,CAAA;AACjC,CAAC,EAPW,kCAAkC,GAAlC,0CAAkC,KAAlC,0CAAkC,QAO7C;AAED,IAAY,wBAQX;AARD,WAAY,wBAAwB;IAClC,+CAAmB,CAAA;IACnB,+CAAmB,CAAA;IACnB,iDAAqB,CAAA;IACrB,+CAAmB,CAAA;IACnB,mDAAuB,CAAA;IACvB,iFAAqD,CAAA;IACrD,iDAAqB,CAAA;AACvB,CAAC,EARW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAQnC;AAED,IAAY,QAGX;AAHD,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,mCAAuB,CAAA;AACzB,CAAC,EAHW,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QAGnB;AAEY,QAAA,6BAA6B,GAAG;IAC3C,CAAC,kCAAkC,CAAC,YAAY,CAAC,EAC/C,wBAAwB,CAAC,SAAS;IACpC,CAAC,kCAAkC,CAAC,SAAS,CAAC,EAC5C,wBAAwB,CAAC,SAAS;IACpC,CAAC,kCAAkC,CAAC,eAAe,CAAC,EAClD,wBAAwB,CAAC,SAAS;IACpC,CAAC,kCAAkC,CAAC,aAAa,CAAC,EAChD,wBAAwB,CAAC,SAAS;IACpC,CAAC,kCAAkC,CAAC,cAAc,CAAC,EACjD,wBAAwB,CAAC,wBAAwB;CACpD,CAAC","sourcesContent":["import type { NetworkClientId } from '@metamask/network-controller';\n\n/** API */\nexport enum APIType {\n 'GET_FEES',\n 'ESTIMATE_GAS',\n 'SUBMIT_TRANSACTIONS',\n 'CANCEL',\n 'BATCH_STATUS',\n 'LIVENESS',\n}\n\n/** SmartTransactions */\nexport enum SmartTransactionMinedTx {\n NOT_MINED = 'not_mined',\n SUCCESS = 'success',\n CANCELLED = 'cancelled',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n}\n\nexport enum SmartTransactionCancellationReason {\n WOULD_REVERT = 'would_revert',\n TOO_CHEAP = 'too_cheap',\n DEADLINE_MISSED = 'deadline_missed',\n INVALID_NONCE = 'invalid_nonce',\n USER_CANCELLED = 'user_cancelled',\n NOT_CANCELLED = 'not_cancelled',\n}\n\nexport enum SmartTransactionStatuses {\n PENDING = 'pending',\n SUCCESS = 'success',\n REVERTED = 'reverted',\n UNKNOWN = 'unknown',\n CANCELLED = 'cancelled',\n CANCELLED_USER_CANCELLED = 'cancelled_user_cancelled',\n RESOLVED = 'resolved',\n}\n\nexport enum ClientId {\n Mobile = 'mobile',\n Extension = 'extension',\n}\n\nexport const cancellationReasonToStatusMap = {\n [SmartTransactionCancellationReason.WOULD_REVERT]:\n SmartTransactionStatuses.CANCELLED,\n [SmartTransactionCancellationReason.TOO_CHEAP]:\n SmartTransactionStatuses.CANCELLED,\n [SmartTransactionCancellationReason.DEADLINE_MISSED]:\n SmartTransactionStatuses.CANCELLED,\n [SmartTransactionCancellationReason.INVALID_NONCE]:\n SmartTransactionStatuses.CANCELLED,\n [SmartTransactionCancellationReason.USER_CANCELLED]:\n SmartTransactionStatuses.CANCELLED_USER_CANCELLED,\n};\n\nexport type SmartTransactionsStatus = {\n error?: string;\n cancellationFeeWei: number;\n cancellationReason?: SmartTransactionCancellationReason;\n deadlineRatio: number;\n minedHash: string;\n minedTx: SmartTransactionMinedTx;\n isSettled: boolean;\n duplicated?: boolean;\n timedOut?: boolean;\n proxied?: boolean;\n};\n\nexport type SmartTransaction = {\n uuid: string;\n txHash?: string;\n txHashes?: string[];\n chainId?: string;\n destinationTokenAddress?: string;\n destinationTokenDecimals?: string;\n destinationTokenSymbol?: string;\n history?: any;\n nonceDetails?: any;\n origin?: string;\n preTxBalance?: string;\n status?: string;\n statusMetadata?: SmartTransactionsStatus;\n sourceTokenSymbol?: string;\n swapMetaData?: any;\n swapTokenValue?: string;\n time?: number; // @deprecated We should use creationTime instead.\n creationTime?: number;\n txParams?: any;\n type?: string;\n confirmed?: boolean;\n cancellable?: boolean;\n accountHardwareType?: string;\n accountType?: string;\n deviceModel?: string;\n transactionId?: string; // It's an ID for a regular transaction from the TransactionController.\n networkClientId?: NetworkClientId;\n};\n\nexport type Fee = {\n maxFeePerGas: number;\n maxPriorityFeePerGas: number;\n};\n\nexport type IndividualTxFees = {\n fees: Fee[];\n cancelFees: Fee[];\n feeEstimate: number;\n gasLimit: number;\n gasUsed: number;\n};\n\nexport type Fees = {\n approvalTxFees: IndividualTxFees | null;\n tradeTxFees: IndividualTxFees | null;\n};\n\n// TODO\nexport type UnsignedTransaction = any;\n\n// TODO\nexport type SignedTransaction = any;\n\n// TODO\nexport type SignedCanceledTransaction = any;\n\nexport type Hex = `0x${string}`;\n\nexport type MetaMetricsProps = {\n accountHardwareType?: string;\n accountType?: string;\n deviceModel?: string;\n};\n\nexport type FeatureFlags = {\n smartTransactions?: {\n mobileReturnTxHashAsap?: boolean;\n extensionReturnTxHashAsap?: boolean;\n };\n};\n"]}
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.markRegularTransactionAsFailed = exports.shouldMarkRegularTransactionAsFailed = exports.getReturnTxHashAsap = exports.getSmartTransactionMetricsSensitiveProperties = exports.getSmartTransactionMetricsProperties = exports.getTxHash = exports.incrementNonceInHex = exports.isSmartTransactionCancellable = exports.handleFetch = exports.mapKeysToCamel = exports.getStxProcessingTime = exports.snapshotFromTxMeta = exports.replayHistory = exports.generateHistoryEntry = exports.calculateStatus = exports.getAPIRequestURL = exports.isSmartTransactionStatusResolved = exports.isSmartTransactionPending = void 0;
|
|
7
|
+
const bytes_1 = require("@ethersproject/bytes");
|
|
8
|
+
const keccak256_1 = require("@ethersproject/keccak256");
|
|
9
|
+
const transactions_1 = require("@ethersproject/transactions");
|
|
10
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
11
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
12
|
+
const fast_json_patch_1 = __importDefault(require("fast-json-patch"));
|
|
13
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
14
|
+
// Ignoring TypeScript errors here because this import is disallowed for production builds, because
|
|
15
|
+
// the `package.json` file is above the root directory.
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const package_json_1 = __importDefault(require("../package.json"));
|
|
19
|
+
const constants_1 = require("./constants.cjs");
|
|
20
|
+
const types_1 = require("./types.cjs");
|
|
21
|
+
function isSmartTransactionPending(smartTransaction) {
|
|
22
|
+
return smartTransaction.status === types_1.SmartTransactionStatuses.PENDING;
|
|
23
|
+
}
|
|
24
|
+
exports.isSmartTransactionPending = isSmartTransactionPending;
|
|
25
|
+
const isSmartTransactionStatusResolved = (stxStatus) => stxStatus === 'uuid_not_found';
|
|
26
|
+
exports.isSmartTransactionStatusResolved = isSmartTransactionStatusResolved;
|
|
27
|
+
// TODO use actual url once API is defined
|
|
28
|
+
function getAPIRequestURL(apiType, chainId) {
|
|
29
|
+
const chainIdDec = parseInt(chainId, 16);
|
|
30
|
+
switch (apiType) {
|
|
31
|
+
case types_1.APIType.GET_FEES: {
|
|
32
|
+
return `${constants_1.API_BASE_URL}/networks/${chainIdDec}/getFees`;
|
|
33
|
+
}
|
|
34
|
+
case types_1.APIType.ESTIMATE_GAS: {
|
|
35
|
+
return `${constants_1.API_BASE_URL}/networks/${chainIdDec}/estimateGas`;
|
|
36
|
+
}
|
|
37
|
+
case types_1.APIType.SUBMIT_TRANSACTIONS: {
|
|
38
|
+
return `${constants_1.API_BASE_URL}/networks/${chainIdDec}/submitTransactions?stxControllerVersion=${package_json_1.default.version}`;
|
|
39
|
+
}
|
|
40
|
+
case types_1.APIType.CANCEL: {
|
|
41
|
+
return `${constants_1.API_BASE_URL}/networks/${chainIdDec}/cancel`;
|
|
42
|
+
}
|
|
43
|
+
case types_1.APIType.BATCH_STATUS: {
|
|
44
|
+
return `${constants_1.API_BASE_URL}/networks/${chainIdDec}/batchStatus`;
|
|
45
|
+
}
|
|
46
|
+
case types_1.APIType.LIVENESS: {
|
|
47
|
+
return `${constants_1.SENTINEL_API_BASE_URL_MAP[chainIdDec]}/network`;
|
|
48
|
+
}
|
|
49
|
+
default: {
|
|
50
|
+
throw new Error(`Invalid APIType`); // It can never get here thanks to TypeScript.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.getAPIRequestURL = getAPIRequestURL;
|
|
55
|
+
const calculateStatus = (stxStatus) => {
|
|
56
|
+
if ((0, exports.isSmartTransactionStatusResolved)(stxStatus)) {
|
|
57
|
+
return types_1.SmartTransactionStatuses.RESOLVED;
|
|
58
|
+
}
|
|
59
|
+
const cancellations = [
|
|
60
|
+
types_1.SmartTransactionCancellationReason.WOULD_REVERT,
|
|
61
|
+
types_1.SmartTransactionCancellationReason.TOO_CHEAP,
|
|
62
|
+
types_1.SmartTransactionCancellationReason.DEADLINE_MISSED,
|
|
63
|
+
types_1.SmartTransactionCancellationReason.INVALID_NONCE,
|
|
64
|
+
types_1.SmartTransactionCancellationReason.USER_CANCELLED,
|
|
65
|
+
];
|
|
66
|
+
if ((stxStatus === null || stxStatus === void 0 ? void 0 : stxStatus.minedTx) === types_1.SmartTransactionMinedTx.NOT_MINED) {
|
|
67
|
+
if (stxStatus.cancellationReason ===
|
|
68
|
+
types_1.SmartTransactionCancellationReason.NOT_CANCELLED) {
|
|
69
|
+
return types_1.SmartTransactionStatuses.PENDING;
|
|
70
|
+
}
|
|
71
|
+
const isCancellation = cancellations.findIndex((cancellation) => cancellation === stxStatus.cancellationReason) > -1;
|
|
72
|
+
if (stxStatus.cancellationReason && isCancellation) {
|
|
73
|
+
if (!stxStatus.isSettled) {
|
|
74
|
+
return types_1.SmartTransactionStatuses.PENDING;
|
|
75
|
+
}
|
|
76
|
+
return types_1.cancellationReasonToStatusMap[stxStatus.cancellationReason];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else if ((stxStatus === null || stxStatus === void 0 ? void 0 : stxStatus.minedTx) === types_1.SmartTransactionMinedTx.SUCCESS) {
|
|
80
|
+
return types_1.SmartTransactionStatuses.SUCCESS;
|
|
81
|
+
}
|
|
82
|
+
else if ((stxStatus === null || stxStatus === void 0 ? void 0 : stxStatus.minedTx) === types_1.SmartTransactionMinedTx.CANCELLED) {
|
|
83
|
+
return types_1.SmartTransactionStatuses.CANCELLED;
|
|
84
|
+
}
|
|
85
|
+
else if ((stxStatus === null || stxStatus === void 0 ? void 0 : stxStatus.minedTx) === types_1.SmartTransactionMinedTx.REVERTED) {
|
|
86
|
+
return types_1.SmartTransactionStatuses.REVERTED;
|
|
87
|
+
}
|
|
88
|
+
else if ((stxStatus === null || stxStatus === void 0 ? void 0 : stxStatus.minedTx) === types_1.SmartTransactionMinedTx.UNKNOWN) {
|
|
89
|
+
return types_1.SmartTransactionStatuses.UNKNOWN;
|
|
90
|
+
}
|
|
91
|
+
return types_1.SmartTransactionStatuses.UNKNOWN;
|
|
92
|
+
};
|
|
93
|
+
exports.calculateStatus = calculateStatus;
|
|
94
|
+
/**
|
|
95
|
+
Generates an array of history objects sense the previous state.
|
|
96
|
+
The object has the keys
|
|
97
|
+
op (the operation performed),
|
|
98
|
+
path (the key and if a nested object then each key will be separated with a `/`)
|
|
99
|
+
value
|
|
100
|
+
with the first entry having the note and a timestamp when the change took place
|
|
101
|
+
@param previousState - the previous state of the object
|
|
102
|
+
@param newState - the update object
|
|
103
|
+
@param [note] - a optional note for the state change
|
|
104
|
+
@returns
|
|
105
|
+
*/
|
|
106
|
+
function generateHistoryEntry(previousState, newState, note) {
|
|
107
|
+
const entry = fast_json_patch_1.default.compare(previousState, newState);
|
|
108
|
+
// Add a note to the first op, since it breaks if we append it to the entry
|
|
109
|
+
if (entry[0]) {
|
|
110
|
+
if (note) {
|
|
111
|
+
entry[0].note = note;
|
|
112
|
+
}
|
|
113
|
+
entry[0].timestamp = Date.now();
|
|
114
|
+
}
|
|
115
|
+
return entry;
|
|
116
|
+
}
|
|
117
|
+
exports.generateHistoryEntry = generateHistoryEntry;
|
|
118
|
+
/**
|
|
119
|
+
Recovers previous txMeta state obj
|
|
120
|
+
@returns
|
|
121
|
+
*/
|
|
122
|
+
function replayHistory(_shortHistory) {
|
|
123
|
+
const shortHistory = lodash_1.default.cloneDeep(_shortHistory);
|
|
124
|
+
return shortHistory.reduce((val, entry) => fast_json_patch_1.default.applyPatch(val, entry).newDocument);
|
|
125
|
+
}
|
|
126
|
+
exports.replayHistory = replayHistory;
|
|
127
|
+
/**
|
|
128
|
+
* Snapshot {@code txMeta}
|
|
129
|
+
* @param txMeta - the tx metadata object
|
|
130
|
+
* @returns a deep clone without history
|
|
131
|
+
*/
|
|
132
|
+
function snapshotFromTxMeta(txMeta) {
|
|
133
|
+
const shallow = Object.assign({}, txMeta);
|
|
134
|
+
delete shallow.history;
|
|
135
|
+
return lodash_1.default.cloneDeep(shallow);
|
|
136
|
+
}
|
|
137
|
+
exports.snapshotFromTxMeta = snapshotFromTxMeta;
|
|
138
|
+
/**
|
|
139
|
+
* Returns processing time for an STX in seconds.
|
|
140
|
+
* @param smartTransactionSubmittedtime
|
|
141
|
+
* @returns Processing time in seconds.
|
|
142
|
+
*/
|
|
143
|
+
const getStxProcessingTime = (smartTransactionSubmittedtime) => {
|
|
144
|
+
if (!smartTransactionSubmittedtime) {
|
|
145
|
+
return undefined;
|
|
146
|
+
}
|
|
147
|
+
return Math.round((Date.now() - smartTransactionSubmittedtime) / 1000);
|
|
148
|
+
};
|
|
149
|
+
exports.getStxProcessingTime = getStxProcessingTime;
|
|
150
|
+
const mapKeysToCamel = (obj) => {
|
|
151
|
+
if (!lodash_1.default.isObject(obj)) {
|
|
152
|
+
return obj;
|
|
153
|
+
}
|
|
154
|
+
const mappedValues = lodash_1.default.mapValues(obj, (val) => {
|
|
155
|
+
if (lodash_1.default.isArray(val)) {
|
|
156
|
+
return val.map(exports.mapKeysToCamel);
|
|
157
|
+
}
|
|
158
|
+
else if (lodash_1.default.isObject(val)) {
|
|
159
|
+
return (0, exports.mapKeysToCamel)(val);
|
|
160
|
+
}
|
|
161
|
+
return val;
|
|
162
|
+
});
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
164
|
+
return lodash_1.default.mapKeys(mappedValues, (value, key) => lodash_1.default.camelCase(key));
|
|
165
|
+
};
|
|
166
|
+
exports.mapKeysToCamel = mapKeysToCamel;
|
|
167
|
+
async function handleFetch(request, options) {
|
|
168
|
+
const response = await fetch(request, options);
|
|
169
|
+
const json = await response.json();
|
|
170
|
+
if (!response.ok) {
|
|
171
|
+
console.log(`response`, response);
|
|
172
|
+
throw new Error(`Fetch error:${JSON.stringify(Object.assign({ status: response.status }, (0, exports.mapKeysToCamel)(json)))}`);
|
|
173
|
+
}
|
|
174
|
+
return json;
|
|
175
|
+
}
|
|
176
|
+
exports.handleFetch = handleFetch;
|
|
177
|
+
const isSmartTransactionCancellable = (stxStatus) => {
|
|
178
|
+
return (stxStatus.minedTx === types_1.SmartTransactionMinedTx.NOT_MINED &&
|
|
179
|
+
(!stxStatus.cancellationReason ||
|
|
180
|
+
stxStatus.cancellationReason ===
|
|
181
|
+
types_1.SmartTransactionCancellationReason.NOT_CANCELLED));
|
|
182
|
+
};
|
|
183
|
+
exports.isSmartTransactionCancellable = isSmartTransactionCancellable;
|
|
184
|
+
const incrementNonceInHex = (nonceInHex) => {
|
|
185
|
+
const nonceInDec = new bignumber_js_1.BigNumber(nonceInHex, 16).toString(10);
|
|
186
|
+
return (0, bytes_1.hexlify)(Number(nonceInDec) + 1);
|
|
187
|
+
};
|
|
188
|
+
exports.incrementNonceInHex = incrementNonceInHex;
|
|
189
|
+
const isType4Transaction = (signedTxHex) => {
|
|
190
|
+
return typeof signedTxHex === 'string' && signedTxHex.startsWith('0x04');
|
|
191
|
+
};
|
|
192
|
+
const getTxHash = (signedTxHex) => {
|
|
193
|
+
var _a;
|
|
194
|
+
if (!signedTxHex) {
|
|
195
|
+
return '';
|
|
196
|
+
}
|
|
197
|
+
try {
|
|
198
|
+
const parsed = (0, transactions_1.parse)(signedTxHex);
|
|
199
|
+
return (_a = parsed === null || parsed === void 0 ? void 0 : parsed.hash) !== null && _a !== void 0 ? _a : '';
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
if (isType4Transaction(signedTxHex)) {
|
|
203
|
+
return (0, bytes_1.hexlify)((0, keccak256_1.keccak256)((0, bytes_1.arrayify)(signedTxHex)));
|
|
204
|
+
}
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
exports.getTxHash = getTxHash;
|
|
209
|
+
const getSmartTransactionMetricsProperties = (smartTransaction) => {
|
|
210
|
+
if (!smartTransaction) {
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
213
|
+
const smartTransactionStatusMetadata = smartTransaction.statusMetadata;
|
|
214
|
+
return {
|
|
215
|
+
stx_status: smartTransaction.status,
|
|
216
|
+
type: smartTransaction.type,
|
|
217
|
+
processing_time: (0, exports.getStxProcessingTime)(smartTransaction.time),
|
|
218
|
+
is_smart_transaction: true,
|
|
219
|
+
stx_enabled: true,
|
|
220
|
+
current_stx_enabled: true,
|
|
221
|
+
stx_user_opt_in: true,
|
|
222
|
+
stx_duplicated: smartTransactionStatusMetadata === null || smartTransactionStatusMetadata === void 0 ? void 0 : smartTransactionStatusMetadata.duplicated,
|
|
223
|
+
stx_timed_out: smartTransactionStatusMetadata === null || smartTransactionStatusMetadata === void 0 ? void 0 : smartTransactionStatusMetadata.timedOut,
|
|
224
|
+
stx_proxied: smartTransactionStatusMetadata === null || smartTransactionStatusMetadata === void 0 ? void 0 : smartTransactionStatusMetadata.proxied,
|
|
225
|
+
};
|
|
226
|
+
};
|
|
227
|
+
exports.getSmartTransactionMetricsProperties = getSmartTransactionMetricsProperties;
|
|
228
|
+
const getSmartTransactionMetricsSensitiveProperties = (smartTransaction) => {
|
|
229
|
+
if (!smartTransaction) {
|
|
230
|
+
return {};
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
token_from_symbol: smartTransaction.sourceTokenSymbol,
|
|
234
|
+
token_to_symbol: smartTransaction.destinationTokenSymbol,
|
|
235
|
+
account_hardware_type: smartTransaction.accountHardwareType,
|
|
236
|
+
account_type: smartTransaction.accountType,
|
|
237
|
+
device_model: smartTransaction.deviceModel,
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
exports.getSmartTransactionMetricsSensitiveProperties = getSmartTransactionMetricsSensitiveProperties;
|
|
241
|
+
const getReturnTxHashAsap = (clientId, smartTransactionsFeatureFlags) => {
|
|
242
|
+
return clientId === types_1.ClientId.Extension
|
|
243
|
+
? smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.extensionReturnTxHashAsap
|
|
244
|
+
: smartTransactionsFeatureFlags === null || smartTransactionsFeatureFlags === void 0 ? void 0 : smartTransactionsFeatureFlags.mobileReturnTxHashAsap;
|
|
245
|
+
};
|
|
246
|
+
exports.getReturnTxHashAsap = getReturnTxHashAsap;
|
|
247
|
+
const shouldMarkRegularTransactionAsFailed = ({ smartTransaction, clientId, getFeatureFlags, }) => {
|
|
248
|
+
var _a;
|
|
249
|
+
const { status, transactionId } = smartTransaction;
|
|
250
|
+
const failureStatuses = [
|
|
251
|
+
types_1.SmartTransactionStatuses.CANCELLED,
|
|
252
|
+
types_1.SmartTransactionStatuses.CANCELLED_USER_CANCELLED,
|
|
253
|
+
types_1.SmartTransactionStatuses.UNKNOWN,
|
|
254
|
+
types_1.SmartTransactionStatuses.RESOLVED,
|
|
255
|
+
];
|
|
256
|
+
if (!status ||
|
|
257
|
+
!failureStatuses.includes(status)) {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
const { smartTransactions: smartTransactionsFeatureFlags } = (_a = getFeatureFlags()) !== null && _a !== void 0 ? _a : {};
|
|
261
|
+
const returnTxHashAsapEnabled = (0, exports.getReturnTxHashAsap)(clientId, smartTransactionsFeatureFlags);
|
|
262
|
+
return Boolean(returnTxHashAsapEnabled && transactionId);
|
|
263
|
+
};
|
|
264
|
+
exports.shouldMarkRegularTransactionAsFailed = shouldMarkRegularTransactionAsFailed;
|
|
265
|
+
const markRegularTransactionAsFailed = ({ smartTransaction, getRegularTransactions, updateTransaction, }) => {
|
|
266
|
+
const { transactionId, status } = smartTransaction;
|
|
267
|
+
const originalTransaction = getRegularTransactions().find((transaction) => transaction.id === transactionId);
|
|
268
|
+
if (!originalTransaction) {
|
|
269
|
+
throw new Error('Cannot find regular transaction to mark it as failed');
|
|
270
|
+
}
|
|
271
|
+
if (originalTransaction.status === transaction_controller_1.TransactionStatus.failed) {
|
|
272
|
+
return; // Already marked as failed.
|
|
273
|
+
}
|
|
274
|
+
const updatedTransaction = Object.assign(Object.assign({}, originalTransaction), { status: transaction_controller_1.TransactionStatus.failed, error: {
|
|
275
|
+
name: 'SmartTransactionFailed',
|
|
276
|
+
message: `Smart transaction failed with status: ${status}`,
|
|
277
|
+
} });
|
|
278
|
+
updateTransaction(updatedTransaction, `Smart transaction status: ${status}`);
|
|
279
|
+
};
|
|
280
|
+
exports.markRegularTransactionAsFailed = markRegularTransactionAsFailed;
|
|
281
|
+
//# sourceMappingURL=utils.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAyD;AACzD,wDAAqD;AACrD,8DAAoD;AAMpD,6EAAqE;AACrE,+CAAyC;AACzC,sEAAyC;AACzC,oDAAuB;AAEvB,mGAAmG;AACnG,uDAAuD;AACvD,6DAA6D;AAC7D,aAAa;AACb,mEAA0C;AAC1C,+CAAsE;AAMtE,uCAOiB;AAEjB,SAAgB,yBAAyB,CAAC,gBAAkC;IAC1E,OAAO,gBAAgB,CAAC,MAAM,KAAK,gCAAwB,CAAC,OAAO,CAAC;AACtE,CAAC;AAFD,8DAEC;AAEM,MAAM,gCAAgC,GAAG,CAC9C,SAA2C,EAC3C,EAAE,CAAC,SAAS,KAAK,gBAAgB,CAAC;AAFvB,QAAA,gCAAgC,oCAET;AAEpC,0CAA0C;AAC1C,SAAgB,gBAAgB,CAAC,OAAgB,EAAE,OAAe;IAChE,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;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E,yCAAyC,MAAM,EAAE;SAC3D,GACF,CAAC;IACF,iBAAiB,CAAC,kBAAkB,EAAE,6BAA6B,MAAM,EAAE,CAAC,CAAC;AAC/E,CAAC,CAAC;AA5BW,QAAA,8BAA8B,kCA4BzC","sourcesContent":["import { arrayify, hexlify } from '@ethersproject/bytes';\nimport { keccak256 } from '@ethersproject/keccak256';\nimport { parse } from '@ethersproject/transactions';\nimport type {\n TransactionControllerGetTransactionsAction,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\nimport jsonDiffer from 'fast-json-patch';\nimport _ from 'lodash';\n\n// Ignoring TypeScript errors here because this import is disallowed for production builds, because\n// the `package.json` file is above the root directory.\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport packageJson from '../package.json';\nimport { API_BASE_URL, SENTINEL_API_BASE_URL_MAP } from './constants';\nimport type {\n SmartTransaction,\n SmartTransactionsStatus,\n FeatureFlags,\n} from './types';\nimport {\n APIType,\n SmartTransactionStatuses,\n SmartTransactionCancellationReason,\n SmartTransactionMinedTx,\n cancellationReasonToStatusMap,\n ClientId,\n} from './types';\n\nexport function isSmartTransactionPending(smartTransaction: SmartTransaction) {\n return smartTransaction.status === SmartTransactionStatuses.PENDING;\n}\n\nexport const isSmartTransactionStatusResolved = (\n stxStatus: SmartTransactionsStatus | string,\n) => stxStatus === 'uuid_not_found';\n\n// TODO use actual url once API is defined\nexport function getAPIRequestURL(apiType: APIType, chainId: string): string {\n const chainIdDec = parseInt(chainId, 16);\n switch (apiType) {\n case APIType.GET_FEES: {\n return `${API_BASE_URL}/networks/${chainIdDec}/getFees`;\n }\n\n case APIType.ESTIMATE_GAS: {\n return `${API_BASE_URL}/networks/${chainIdDec}/estimateGas`;\n }\n\n case APIType.SUBMIT_TRANSACTIONS: {\n return `${API_BASE_URL}/networks/${chainIdDec}/submitTransactions?stxControllerVersion=${packageJson.version}`;\n }\n\n case APIType.CANCEL: {\n return `${API_BASE_URL}/networks/${chainIdDec}/cancel`;\n }\n\n case APIType.BATCH_STATUS: {\n return `${API_BASE_URL}/networks/${chainIdDec}/batchStatus`;\n }\n\n case APIType.LIVENESS: {\n return `${SENTINEL_API_BASE_URL_MAP[chainIdDec]}/network`;\n }\n\n default: {\n throw new Error(`Invalid APIType`); // It can never get here thanks to TypeScript.\n }\n }\n}\n\nexport const calculateStatus = (stxStatus: SmartTransactionsStatus) => {\n if (isSmartTransactionStatusResolved(stxStatus)) {\n return SmartTransactionStatuses.RESOLVED;\n }\n const cancellations = [\n SmartTransactionCancellationReason.WOULD_REVERT,\n SmartTransactionCancellationReason.TOO_CHEAP,\n SmartTransactionCancellationReason.DEADLINE_MISSED,\n SmartTransactionCancellationReason.INVALID_NONCE,\n SmartTransactionCancellationReason.USER_CANCELLED,\n ];\n if (stxStatus?.minedTx === SmartTransactionMinedTx.NOT_MINED) {\n if (\n stxStatus.cancellationReason ===\n SmartTransactionCancellationReason.NOT_CANCELLED\n ) {\n return SmartTransactionStatuses.PENDING;\n }\n\n const isCancellation =\n cancellations.findIndex(\n (cancellation) => cancellation === stxStatus.cancellationReason,\n ) > -1;\n if (stxStatus.cancellationReason && isCancellation) {\n if (!stxStatus.isSettled) {\n return SmartTransactionStatuses.PENDING;\n }\n return cancellationReasonToStatusMap[stxStatus.cancellationReason];\n }\n } else if (stxStatus?.minedTx === SmartTransactionMinedTx.SUCCESS) {\n return SmartTransactionStatuses.SUCCESS;\n } else if (stxStatus?.minedTx === SmartTransactionMinedTx.CANCELLED) {\n return SmartTransactionStatuses.CANCELLED;\n } else if (stxStatus?.minedTx === SmartTransactionMinedTx.REVERTED) {\n return SmartTransactionStatuses.REVERTED;\n } else if (stxStatus?.minedTx === SmartTransactionMinedTx.UNKNOWN) {\n return SmartTransactionStatuses.UNKNOWN;\n }\n return SmartTransactionStatuses.UNKNOWN;\n};\n\n/**\n Generates an array of history objects sense the previous state.\n The object has the keys\n op (the operation performed),\n path (the key and if a nested object then each key will be separated with a `/`)\n value\n with the first entry having the note and a timestamp when the change took place\n @param previousState - the previous state of the object\n @param newState - the update object\n @param [note] - a optional note for the state change\n @returns\n*/\nexport function generateHistoryEntry(\n previousState: any,\n newState: any,\n note: string,\n) {\n const entry: any = jsonDiffer.compare(previousState, newState);\n // Add a note to the first op, since it breaks if we append it to the entry\n if (entry[0]) {\n if (note) {\n entry[0].note = note;\n }\n\n entry[0].timestamp = Date.now();\n }\n return entry;\n}\n\n/**\n Recovers previous txMeta state obj\n @returns\n*/\nexport function replayHistory(_shortHistory: any) {\n const shortHistory = _.cloneDeep(_shortHistory);\n return shortHistory.reduce(\n (val: any, entry: any) => jsonDiffer.applyPatch(val, entry).newDocument,\n );\n}\n\n/**\n * Snapshot {@code txMeta}\n * @param txMeta - the tx metadata object\n * @returns a deep clone without history\n */\nexport function snapshotFromTxMeta(txMeta: any) {\n const shallow = { ...txMeta };\n delete shallow.history;\n return _.cloneDeep(shallow);\n}\n\n/**\n * Returns processing time for an STX in seconds.\n * @param smartTransactionSubmittedtime\n * @returns Processing time in seconds.\n */\nexport const getStxProcessingTime = (\n smartTransactionSubmittedtime: number | undefined,\n): number | undefined => {\n if (!smartTransactionSubmittedtime) {\n return undefined;\n }\n return Math.round((Date.now() - smartTransactionSubmittedtime) / 1000);\n};\n\nexport const mapKeysToCamel = (\n obj: Record<string, any>,\n): Record<string, any> => {\n if (!_.isObject(obj)) {\n return obj;\n }\n const mappedValues = _.mapValues(obj, (val: Record<string, any>) => {\n if (_.isArray(val)) {\n return val.map(mapKeysToCamel);\n } else if (_.isObject(val)) {\n return mapKeysToCamel(val);\n }\n return val;\n });\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return _.mapKeys(mappedValues, (value, key) => _.camelCase(key));\n};\n\nexport async function handleFetch(request: string, options?: RequestInit) {\n const response = await fetch(request, options);\n const json = await response.json();\n if (!response.ok) {\n console.log(`response`, response);\n throw new Error(\n `Fetch error:${JSON.stringify({\n status: response.status,\n ...mapKeysToCamel(json),\n })}`,\n );\n }\n return json;\n}\n\nexport const isSmartTransactionCancellable = (\n stxStatus: SmartTransactionsStatus,\n): boolean => {\n return (\n stxStatus.minedTx === SmartTransactionMinedTx.NOT_MINED &&\n (!stxStatus.cancellationReason ||\n stxStatus.cancellationReason ===\n SmartTransactionCancellationReason.NOT_CANCELLED)\n );\n};\n\nexport const incrementNonceInHex = (nonceInHex: string): string => {\n const nonceInDec = new BigNumber(nonceInHex, 16).toString(10);\n return hexlify(Number(nonceInDec) + 1);\n};\n\nconst isType4Transaction = (signedTxHex: string) => {\n return typeof signedTxHex === 'string' && signedTxHex.startsWith('0x04');\n};\n\nexport const getTxHash = (signedTxHex: any) => {\n if (!signedTxHex) {\n return '';\n }\n try {\n const parsed = parse(signedTxHex);\n return parsed?.hash ?? '';\n } catch (error) {\n if (isType4Transaction(signedTxHex)) {\n return hexlify(keccak256(arrayify(signedTxHex)));\n }\n throw error;\n }\n};\n\nexport const getSmartTransactionMetricsProperties = (\n smartTransaction: SmartTransaction,\n) => {\n if (!smartTransaction) {\n return {};\n }\n const smartTransactionStatusMetadata = smartTransaction.statusMetadata;\n return {\n stx_status: smartTransaction.status,\n type: smartTransaction.type,\n processing_time: getStxProcessingTime(smartTransaction.time),\n is_smart_transaction: true,\n stx_enabled: true,\n current_stx_enabled: true,\n stx_user_opt_in: true,\n stx_duplicated: smartTransactionStatusMetadata?.duplicated,\n stx_timed_out: smartTransactionStatusMetadata?.timedOut,\n stx_proxied: smartTransactionStatusMetadata?.proxied,\n };\n};\n\nexport const getSmartTransactionMetricsSensitiveProperties = (\n smartTransaction: SmartTransaction,\n) => {\n if (!smartTransaction) {\n return {};\n }\n return {\n token_from_symbol: smartTransaction.sourceTokenSymbol,\n token_to_symbol: smartTransaction.destinationTokenSymbol,\n account_hardware_type: smartTransaction.accountHardwareType,\n account_type: smartTransaction.accountType,\n device_model: smartTransaction.deviceModel,\n };\n};\n\nexport const getReturnTxHashAsap = (\n clientId: ClientId,\n smartTransactionsFeatureFlags: FeatureFlags['smartTransactions'],\n) => {\n return clientId === ClientId.Extension\n ? smartTransactionsFeatureFlags?.extensionReturnTxHashAsap\n : smartTransactionsFeatureFlags?.mobileReturnTxHashAsap;\n};\n\nexport const shouldMarkRegularTransactionAsFailed = ({\n smartTransaction,\n clientId,\n getFeatureFlags,\n}: {\n smartTransaction: SmartTransaction;\n clientId: ClientId;\n getFeatureFlags: () => FeatureFlags;\n}): boolean => {\n const { status, transactionId } = smartTransaction;\n const failureStatuses: SmartTransactionStatuses[] = [\n SmartTransactionStatuses.CANCELLED,\n SmartTransactionStatuses.CANCELLED_USER_CANCELLED,\n SmartTransactionStatuses.UNKNOWN,\n SmartTransactionStatuses.RESOLVED,\n ];\n if (\n !status ||\n !failureStatuses.includes(status as SmartTransactionStatuses)\n ) {\n return false;\n }\n const { smartTransactions: smartTransactionsFeatureFlags } =\n getFeatureFlags() ?? {};\n const returnTxHashAsapEnabled = getReturnTxHashAsap(\n clientId,\n smartTransactionsFeatureFlags,\n );\n return Boolean(returnTxHashAsapEnabled && transactionId);\n};\n\nexport const markRegularTransactionAsFailed = ({\n smartTransaction,\n getRegularTransactions,\n updateTransaction,\n}: {\n smartTransaction: SmartTransaction;\n getRegularTransactions: TransactionControllerGetTransactionsAction['handler'];\n updateTransaction: TransactionControllerUpdateTransactionAction['handler'];\n}) => {\n const { transactionId, status } = smartTransaction;\n const originalTransaction = getRegularTransactions().find(\n (transaction) => transaction.id === transactionId,\n );\n if (!originalTransaction) {\n throw new Error('Cannot find regular transaction to mark it as failed');\n }\n if (originalTransaction.status === TransactionStatus.failed) {\n return; // Already marked as failed.\n }\n const updatedTransaction: TransactionMeta = {\n ...originalTransaction,\n status: TransactionStatus.failed,\n error: {\n name: 'SmartTransactionFailed',\n message: `Smart transaction failed with status: ${status}`,\n },\n };\n updateTransaction(updatedTransaction, `Smart transaction status: ${status}`);\n};\n"]}
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { TransactionControllerGetTransactionsAction, TransactionControllerUpdateTransactionAction } from "@metamask/transaction-controller";
|
|
2
|
+
import type { SmartTransaction, SmartTransactionsStatus, FeatureFlags } from "./types.cjs";
|
|
3
|
+
import { APIType, SmartTransactionStatuses, ClientId } from "./types.cjs";
|
|
4
|
+
export declare function isSmartTransactionPending(smartTransaction: SmartTransaction): boolean;
|
|
5
|
+
export declare const isSmartTransactionStatusResolved: (stxStatus: SmartTransactionsStatus | string) => boolean;
|
|
6
|
+
export declare function getAPIRequestURL(apiType: APIType, chainId: string): string;
|
|
7
|
+
export declare const calculateStatus: (stxStatus: SmartTransactionsStatus) => SmartTransactionStatuses;
|
|
8
|
+
/**
|
|
9
|
+
Generates an array of history objects sense the previous state.
|
|
10
|
+
The object has the keys
|
|
11
|
+
op (the operation performed),
|
|
12
|
+
path (the key and if a nested object then each key will be separated with a `/`)
|
|
13
|
+
value
|
|
14
|
+
with the first entry having the note and a timestamp when the change took place
|
|
15
|
+
@param previousState - the previous state of the object
|
|
16
|
+
@param newState - the update object
|
|
17
|
+
@param [note] - a optional note for the state change
|
|
18
|
+
@returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateHistoryEntry(previousState: any, newState: any, note: string): any;
|
|
21
|
+
/**
|
|
22
|
+
Recovers previous txMeta state obj
|
|
23
|
+
@returns
|
|
24
|
+
*/
|
|
25
|
+
export declare function replayHistory(_shortHistory: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Snapshot {@code txMeta}
|
|
28
|
+
* @param txMeta - the tx metadata object
|
|
29
|
+
* @returns a deep clone without history
|
|
30
|
+
*/
|
|
31
|
+
export declare function snapshotFromTxMeta(txMeta: any): any;
|
|
32
|
+
/**
|
|
33
|
+
* Returns processing time for an STX in seconds.
|
|
34
|
+
* @param smartTransactionSubmittedtime
|
|
35
|
+
* @returns Processing time in seconds.
|
|
36
|
+
*/
|
|
37
|
+
export declare const getStxProcessingTime: (smartTransactionSubmittedtime: number | undefined) => number | undefined;
|
|
38
|
+
export declare const mapKeysToCamel: (obj: Record<string, any>) => Record<string, any>;
|
|
39
|
+
export declare function handleFetch(request: string, options?: RequestInit): Promise<any>;
|
|
40
|
+
export declare const isSmartTransactionCancellable: (stxStatus: SmartTransactionsStatus) => boolean;
|
|
41
|
+
export declare const incrementNonceInHex: (nonceInHex: string) => string;
|
|
42
|
+
export declare const getTxHash: (signedTxHex: any) => string;
|
|
43
|
+
export declare const getSmartTransactionMetricsProperties: (smartTransaction: SmartTransaction) => {
|
|
44
|
+
stx_status?: undefined;
|
|
45
|
+
type?: undefined;
|
|
46
|
+
processing_time?: undefined;
|
|
47
|
+
is_smart_transaction?: undefined;
|
|
48
|
+
stx_enabled?: undefined;
|
|
49
|
+
current_stx_enabled?: undefined;
|
|
50
|
+
stx_user_opt_in?: undefined;
|
|
51
|
+
stx_duplicated?: undefined;
|
|
52
|
+
stx_timed_out?: undefined;
|
|
53
|
+
stx_proxied?: undefined;
|
|
54
|
+
} | {
|
|
55
|
+
stx_status: string | undefined;
|
|
56
|
+
type: string | undefined;
|
|
57
|
+
processing_time: number | undefined;
|
|
58
|
+
is_smart_transaction: boolean;
|
|
59
|
+
stx_enabled: boolean;
|
|
60
|
+
current_stx_enabled: boolean;
|
|
61
|
+
stx_user_opt_in: boolean;
|
|
62
|
+
stx_duplicated: boolean | undefined;
|
|
63
|
+
stx_timed_out: boolean | undefined;
|
|
64
|
+
stx_proxied: boolean | undefined;
|
|
65
|
+
};
|
|
66
|
+
export declare const getSmartTransactionMetricsSensitiveProperties: (smartTransaction: SmartTransaction) => {
|
|
67
|
+
token_from_symbol?: undefined;
|
|
68
|
+
token_to_symbol?: undefined;
|
|
69
|
+
account_hardware_type?: undefined;
|
|
70
|
+
account_type?: undefined;
|
|
71
|
+
device_model?: undefined;
|
|
72
|
+
} | {
|
|
73
|
+
token_from_symbol: string | undefined;
|
|
74
|
+
token_to_symbol: string | undefined;
|
|
75
|
+
account_hardware_type: string | undefined;
|
|
76
|
+
account_type: string | undefined;
|
|
77
|
+
device_model: string | undefined;
|
|
78
|
+
};
|
|
79
|
+
export declare const getReturnTxHashAsap: (clientId: ClientId, smartTransactionsFeatureFlags: FeatureFlags['smartTransactions']) => boolean | undefined;
|
|
80
|
+
export declare const shouldMarkRegularTransactionAsFailed: ({ smartTransaction, clientId, getFeatureFlags, }: {
|
|
81
|
+
smartTransaction: SmartTransaction;
|
|
82
|
+
clientId: ClientId;
|
|
83
|
+
getFeatureFlags: () => FeatureFlags;
|
|
84
|
+
}) => boolean;
|
|
85
|
+
export declare const markRegularTransactionAsFailed: ({ smartTransaction, getRegularTransactions, updateTransaction, }: {
|
|
86
|
+
smartTransaction: SmartTransaction;
|
|
87
|
+
getRegularTransactions: TransactionControllerGetTransactionsAction['handler'];
|
|
88
|
+
updateTransaction: TransactionControllerUpdateTransactionAction['handler'];
|
|
89
|
+
}) => void;
|
|
90
|
+
//# sourceMappingURL=utils.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,0CAA0C,EAC1C,4CAA4C,EAE7C,yCAAyC;AAY1C,OAAO,KAAK,EACV,gBAAgB,EAChB,uBAAuB,EACvB,YAAY,EACb,oBAAgB;AACjB,OAAO,EACL,OAAO,EACP,wBAAwB,EAIxB,QAAQ,EACT,oBAAgB;AAEjB,wBAAgB,yBAAyB,CAAC,gBAAgB,EAAE,gBAAgB,WAE3E;AAED,eAAO,MAAM,gCAAgC,cAChC,uBAAuB,GAAG,MAAM,YACV,CAAC;AAGpC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CA+B1E;AAED,eAAO,MAAM,eAAe,cAAe,uBAAuB,6BAuCjE,CAAC;AAEF;;;;;;;;;;;EAWE;AACF,wBAAgB,oB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