near-safe 0.8.3 → 0.8.5-beta.0
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/dist/cjs/decode/index.d.ts +8 -0
- package/dist/cjs/decode/index.js +52 -0
- package/dist/cjs/decode/util.d.ts +17 -0
- package/dist/cjs/{decode.js → decode/util.js} +4 -53
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/lib/multisend.d.ts +2 -0
- package/dist/cjs/lib/multisend.js +45 -0
- package/dist/esm/decode/index.d.ts +8 -0
- package/dist/esm/decode/index.js +49 -0
- package/dist/esm/decode/util.d.ts +17 -0
- package/dist/esm/{decode.js → decode/util.js} +3 -51
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/multisend.d.ts +2 -0
- package/dist/esm/lib/multisend.js +45 -1
- package/package.json +1 -1
- package/dist/cjs/decode.d.ts +0 -14
- package/dist/esm/decode.d.ts +0 -14
@@ -0,0 +1,8 @@
|
|
1
|
+
import { DecodedTxData, SafeEncodedSignRequest } from "../types";
|
2
|
+
/**
|
3
|
+
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
4
|
+
*
|
5
|
+
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
6
|
+
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
7
|
+
*/
|
8
|
+
export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.decodeTxData = decodeTxData;
|
4
|
+
const safe_message_1 = require("../lib/safe-message");
|
5
|
+
const util_1 = require("./util");
|
6
|
+
/**
|
7
|
+
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
8
|
+
*
|
9
|
+
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
10
|
+
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
11
|
+
*/
|
12
|
+
function decodeTxData({ evmMessage, chainId, }) {
|
13
|
+
const data = evmMessage;
|
14
|
+
if ((0, safe_message_1.isRlpHex)(evmMessage)) {
|
15
|
+
return (0, util_1.decodeRlpHex)(chainId, evmMessage);
|
16
|
+
}
|
17
|
+
if ((0, safe_message_1.isTransactionSerializable)(data)) {
|
18
|
+
return (0, util_1.decodeTransactionSerializable)(chainId, data);
|
19
|
+
}
|
20
|
+
if (typeof data !== "string") {
|
21
|
+
return (0, util_1.decodeTypedData)(chainId, data);
|
22
|
+
}
|
23
|
+
try {
|
24
|
+
// Stringified UserOperation.
|
25
|
+
const userOp = JSON.parse(data);
|
26
|
+
return (0, util_1.decodeUserOperation)(chainId, userOp);
|
27
|
+
}
|
28
|
+
catch (error) {
|
29
|
+
if (error instanceof SyntaxError) {
|
30
|
+
// Raw message string.
|
31
|
+
return {
|
32
|
+
chainId,
|
33
|
+
costEstimate: "0",
|
34
|
+
transactions: [],
|
35
|
+
message: data,
|
36
|
+
};
|
37
|
+
}
|
38
|
+
else {
|
39
|
+
// TODO: This shouldn't happen anymore and can probably be reverted.
|
40
|
+
// We keep it here now, because near-ca might not have adapted its router.
|
41
|
+
console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
|
42
|
+
try {
|
43
|
+
const typedData = JSON.parse(data);
|
44
|
+
return (0, util_1.decodeTypedData)(chainId, typedData);
|
45
|
+
}
|
46
|
+
catch (error) {
|
47
|
+
const message = error instanceof Error ? error.message : String(error);
|
48
|
+
throw new Error(`decodeTxData: Unexpected error - ${message}`);
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { EIP712TypedData } from "near-ca";
|
2
|
+
import { Hex, TransactionSerializable } from "viem";
|
3
|
+
import { DecodedTxData, UserOperation } from "../types";
|
4
|
+
export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
|
5
|
+
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
6
|
+
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
7
|
+
export declare function decodeUserOperation(chainId: number, userOp: UserOperation): DecodedTxData;
|
8
|
+
export declare enum OperationType {
|
9
|
+
Call = 0,
|
10
|
+
DelegateCall = 1
|
11
|
+
}
|
12
|
+
export interface MetaTransaction {
|
13
|
+
readonly to: string;
|
14
|
+
readonly value: string;
|
15
|
+
readonly data: string;
|
16
|
+
readonly operation?: OperationType;
|
17
|
+
}
|
@@ -1,62 +1,13 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decodeTxData = decodeTxData;
|
4
3
|
exports.decodeTransactionSerializable = decodeTransactionSerializable;
|
5
4
|
exports.decodeRlpHex = decodeRlpHex;
|
6
5
|
exports.decodeTypedData = decodeTypedData;
|
7
6
|
exports.decodeUserOperation = decodeUserOperation;
|
8
|
-
const
|
7
|
+
const decodeMulti_1 = require("ethers-multisend/build/cjs/decodeMulti");
|
9
8
|
const viem_1 = require("viem");
|
10
|
-
const deployments_1 = require("
|
11
|
-
const multisend_1 = require("
|
12
|
-
const safe_message_1 = require("./lib/safe-message");
|
13
|
-
/**
|
14
|
-
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
15
|
-
*
|
16
|
-
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
17
|
-
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
18
|
-
*/
|
19
|
-
function decodeTxData({ evmMessage, chainId, }) {
|
20
|
-
const data = evmMessage;
|
21
|
-
if ((0, safe_message_1.isRlpHex)(evmMessage)) {
|
22
|
-
return decodeRlpHex(chainId, evmMessage);
|
23
|
-
}
|
24
|
-
if ((0, safe_message_1.isTransactionSerializable)(data)) {
|
25
|
-
return decodeTransactionSerializable(chainId, data);
|
26
|
-
}
|
27
|
-
if (typeof data !== "string") {
|
28
|
-
return decodeTypedData(chainId, data);
|
29
|
-
}
|
30
|
-
try {
|
31
|
-
// Stringified UserOperation.
|
32
|
-
const userOp = JSON.parse(data);
|
33
|
-
return decodeUserOperation(chainId, userOp);
|
34
|
-
}
|
35
|
-
catch (error) {
|
36
|
-
if (error instanceof SyntaxError) {
|
37
|
-
// Raw message string.
|
38
|
-
return {
|
39
|
-
chainId,
|
40
|
-
costEstimate: "0",
|
41
|
-
transactions: [],
|
42
|
-
message: data,
|
43
|
-
};
|
44
|
-
}
|
45
|
-
else {
|
46
|
-
// TODO: This shouldn't happen anymore and can probably be reverted.
|
47
|
-
// We keep it here now, because near-ca might not have adapted its router.
|
48
|
-
console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
|
49
|
-
try {
|
50
|
-
const typedData = JSON.parse(data);
|
51
|
-
return decodeTypedData(chainId, typedData);
|
52
|
-
}
|
53
|
-
catch (error) {
|
54
|
-
const message = error instanceof Error ? error.message : String(error);
|
55
|
-
throw new Error(`decodeTxData: Unexpected error - ${message}`);
|
56
|
-
}
|
57
|
-
}
|
58
|
-
}
|
59
|
-
}
|
9
|
+
const deployments_1 = require("../_gen/deployments");
|
10
|
+
const multisend_1 = require("../lib/multisend");
|
60
11
|
function decodeTransactionSerializable(chainId, tx) {
|
61
12
|
const { gas, maxFeePerGas, maxPriorityFeePerGas, to } = tx;
|
62
13
|
if (chainId !== tx.chainId) {
|
@@ -101,7 +52,7 @@ function decodeUserOperation(chainId, userOp) {
|
|
101
52
|
});
|
102
53
|
// Determine if singular or double!
|
103
54
|
const transactions = (0, multisend_1.isMultisendTx)(args)
|
104
|
-
? (0,
|
55
|
+
? (0, decodeMulti_1.decodeMulti)(args[2])
|
105
56
|
: [
|
106
57
|
{
|
107
58
|
to: args[0],
|
package/dist/cjs/index.d.ts
CHANGED
@@ -2,6 +2,6 @@ export * from "./near-safe";
|
|
2
2
|
export * from "./types";
|
3
3
|
export * from "./util";
|
4
4
|
export * from "./constants";
|
5
|
-
export
|
5
|
+
export { decodeTxData } from "./decode";
|
6
6
|
export * from "./lib/safe-message";
|
7
7
|
export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, } from "near-ca";
|
package/dist/cjs/index.js
CHANGED
@@ -14,12 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
exports.mpcRequestRouter = exports.signatureFromTxHash = exports.signatureFromOutcome = exports.populateTx = exports.Network = void 0;
|
17
|
+
exports.mpcRequestRouter = exports.signatureFromTxHash = exports.signatureFromOutcome = exports.populateTx = exports.Network = exports.decodeTxData = void 0;
|
18
18
|
__exportStar(require("./near-safe"), exports);
|
19
19
|
__exportStar(require("./types"), exports);
|
20
20
|
__exportStar(require("./util"), exports);
|
21
21
|
__exportStar(require("./constants"), exports);
|
22
|
-
|
22
|
+
var decode_1 = require("./decode");
|
23
|
+
Object.defineProperty(exports, "decodeTxData", { enumerable: true, get: function () { return decode_1.decodeTxData; } });
|
23
24
|
__exportStar(require("./lib/safe-message"), exports);
|
24
25
|
var near_ca_1 = require("near-ca");
|
25
26
|
Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return near_ca_1.Network; } });
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import { Hex } from "viem";
|
1
2
|
import { MetaTransaction } from "../types";
|
2
3
|
export declare const MULTI_SEND_ABI: string[];
|
3
4
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
4
5
|
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
6
|
+
export declare function decodeMultiViem(data: Hex): MetaTransaction[];
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MULTI_SEND_ABI = void 0;
|
4
4
|
exports.encodeMulti = encodeMulti;
|
5
5
|
exports.isMultisendTx = isMultisendTx;
|
6
|
+
exports.decodeMultiViem = decodeMultiViem;
|
6
7
|
const viem_1 = require("viem");
|
7
8
|
const types_1 = require("../types");
|
8
9
|
exports.MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
@@ -44,3 +45,47 @@ function isMultisendTx(args) {
|
|
44
45
|
return (to === MULTISEND_141.toLowerCase() ||
|
45
46
|
to === MULTISEND_CALLONLY_141.toLowerCase());
|
46
47
|
}
|
48
|
+
// import { Interface } from '@ethersproject/abi';
|
49
|
+
// import { getAddress } from '@ethersproject/address';
|
50
|
+
// import { BigNumber } from '@ethersproject/bignumber';
|
51
|
+
function unpack(packed, startIndex) {
|
52
|
+
// read operation from first 8 bits (= 2 hex digits)
|
53
|
+
const operation = parseInt(packed.substring(startIndex, startIndex + 2), 16);
|
54
|
+
// the next 40 characters are the to address
|
55
|
+
const to = (0, viem_1.getAddress)(`0x${packed.substring(startIndex + 2, startIndex + 42)}`);
|
56
|
+
// then comes the uint256 value (= 64 hex digits)
|
57
|
+
const value = (0, viem_1.toHex)(BigInt(`0x${packed.substring(startIndex + 42, startIndex + 106)}`));
|
58
|
+
// and the uint256 data length (= 64 hex digits)
|
59
|
+
const hexDataLength = parseInt(packed.substring(startIndex + 106, startIndex + 170), 16);
|
60
|
+
const endIndex = startIndex + 170 + hexDataLength * 2; // * 2 because each hex item is represented with 2 digits
|
61
|
+
const data = `0x${packed.substring(startIndex + 170, endIndex)}`;
|
62
|
+
return {
|
63
|
+
operation,
|
64
|
+
to,
|
65
|
+
value,
|
66
|
+
data,
|
67
|
+
endIndex,
|
68
|
+
};
|
69
|
+
}
|
70
|
+
function decodeMultiViem(data) {
|
71
|
+
// const multiSendContract = new Interface(MULTI_SEND_ABI);
|
72
|
+
// const tx = multiSendContract.parseTransaction({ data });
|
73
|
+
// const multiSendAbiItem = parseAbiItem({
|
74
|
+
// type: "function",
|
75
|
+
// name: "multiSend",
|
76
|
+
// inputs: [{ name: "data", type: "bytes" }],
|
77
|
+
// });
|
78
|
+
const tx = (0, viem_1.decodeFunctionData)({
|
79
|
+
abi: exports.MULTI_SEND_ABI,
|
80
|
+
data,
|
81
|
+
});
|
82
|
+
const [transactionsEncoded] = tx.args;
|
83
|
+
const result = [];
|
84
|
+
let startIndex = 2; // skip over 0x
|
85
|
+
while (startIndex < transactionsEncoded.length) {
|
86
|
+
const { endIndex, ...tx } = unpack(transactionsEncoded, startIndex);
|
87
|
+
result.push(tx);
|
88
|
+
startIndex = endIndex;
|
89
|
+
}
|
90
|
+
return result;
|
91
|
+
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { DecodedTxData, SafeEncodedSignRequest } from "../types";
|
2
|
+
/**
|
3
|
+
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
4
|
+
*
|
5
|
+
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
6
|
+
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
7
|
+
*/
|
8
|
+
export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import { isRlpHex, isTransactionSerializable } from "../lib/safe-message";
|
2
|
+
import { decodeRlpHex, decodeTransactionSerializable, decodeTypedData, decodeUserOperation, } from "./util";
|
3
|
+
/**
|
4
|
+
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
5
|
+
*
|
6
|
+
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
7
|
+
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
8
|
+
*/
|
9
|
+
export function decodeTxData({ evmMessage, chainId, }) {
|
10
|
+
const data = evmMessage;
|
11
|
+
if (isRlpHex(evmMessage)) {
|
12
|
+
return decodeRlpHex(chainId, evmMessage);
|
13
|
+
}
|
14
|
+
if (isTransactionSerializable(data)) {
|
15
|
+
return decodeTransactionSerializable(chainId, data);
|
16
|
+
}
|
17
|
+
if (typeof data !== "string") {
|
18
|
+
return decodeTypedData(chainId, data);
|
19
|
+
}
|
20
|
+
try {
|
21
|
+
// Stringified UserOperation.
|
22
|
+
const userOp = JSON.parse(data);
|
23
|
+
return decodeUserOperation(chainId, userOp);
|
24
|
+
}
|
25
|
+
catch (error) {
|
26
|
+
if (error instanceof SyntaxError) {
|
27
|
+
// Raw message string.
|
28
|
+
return {
|
29
|
+
chainId,
|
30
|
+
costEstimate: "0",
|
31
|
+
transactions: [],
|
32
|
+
message: data,
|
33
|
+
};
|
34
|
+
}
|
35
|
+
else {
|
36
|
+
// TODO: This shouldn't happen anymore and can probably be reverted.
|
37
|
+
// We keep it here now, because near-ca might not have adapted its router.
|
38
|
+
console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
|
39
|
+
try {
|
40
|
+
const typedData = JSON.parse(data);
|
41
|
+
return decodeTypedData(chainId, typedData);
|
42
|
+
}
|
43
|
+
catch (error) {
|
44
|
+
const message = error instanceof Error ? error.message : String(error);
|
45
|
+
throw new Error(`decodeTxData: Unexpected error - ${message}`);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import { EIP712TypedData } from "near-ca";
|
2
|
+
import { Hex, TransactionSerializable } from "viem";
|
3
|
+
import { DecodedTxData, UserOperation } from "../types";
|
4
|
+
export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
|
5
|
+
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
6
|
+
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
7
|
+
export declare function decodeUserOperation(chainId: number, userOp: UserOperation): DecodedTxData;
|
8
|
+
export declare enum OperationType {
|
9
|
+
Call = 0,
|
10
|
+
DelegateCall = 1
|
11
|
+
}
|
12
|
+
export interface MetaTransaction {
|
13
|
+
readonly to: string;
|
14
|
+
readonly value: string;
|
15
|
+
readonly data: string;
|
16
|
+
readonly operation?: OperationType;
|
17
|
+
}
|
@@ -1,55 +1,7 @@
|
|
1
|
-
import { decodeMulti } from "ethers-multisend";
|
1
|
+
import { decodeMulti } from "ethers-multisend/build/cjs/decodeMulti";
|
2
2
|
import { decodeFunctionData, formatEther, parseTransaction, serializeTransaction, } from "viem";
|
3
|
-
import { SAFE_DEPLOYMENTS } from "
|
4
|
-
import { isMultisendTx } from "
|
5
|
-
import { isRlpHex, isTransactionSerializable } from "./lib/safe-message";
|
6
|
-
/**
|
7
|
-
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
8
|
-
*
|
9
|
-
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
10
|
-
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
11
|
-
*/
|
12
|
-
export function decodeTxData({ evmMessage, chainId, }) {
|
13
|
-
const data = evmMessage;
|
14
|
-
if (isRlpHex(evmMessage)) {
|
15
|
-
return decodeRlpHex(chainId, evmMessage);
|
16
|
-
}
|
17
|
-
if (isTransactionSerializable(data)) {
|
18
|
-
return decodeTransactionSerializable(chainId, data);
|
19
|
-
}
|
20
|
-
if (typeof data !== "string") {
|
21
|
-
return decodeTypedData(chainId, data);
|
22
|
-
}
|
23
|
-
try {
|
24
|
-
// Stringified UserOperation.
|
25
|
-
const userOp = JSON.parse(data);
|
26
|
-
return decodeUserOperation(chainId, userOp);
|
27
|
-
}
|
28
|
-
catch (error) {
|
29
|
-
if (error instanceof SyntaxError) {
|
30
|
-
// Raw message string.
|
31
|
-
return {
|
32
|
-
chainId,
|
33
|
-
costEstimate: "0",
|
34
|
-
transactions: [],
|
35
|
-
message: data,
|
36
|
-
};
|
37
|
-
}
|
38
|
-
else {
|
39
|
-
// TODO: This shouldn't happen anymore and can probably be reverted.
|
40
|
-
// We keep it here now, because near-ca might not have adapted its router.
|
41
|
-
console.warn("Failed UserOp Parsing, try TypedData Parsing", error);
|
42
|
-
try {
|
43
|
-
const typedData = JSON.parse(data);
|
44
|
-
return decodeTypedData(chainId, typedData);
|
45
|
-
}
|
46
|
-
catch (error) {
|
47
|
-
const message = error instanceof Error ? error.message : String(error);
|
48
|
-
throw new Error(`decodeTxData: Unexpected error - ${message}`);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
3
|
+
import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
|
4
|
+
import { isMultisendTx } from "../lib/multisend";
|
53
5
|
export function decodeTransactionSerializable(chainId, tx) {
|
54
6
|
const { gas, maxFeePerGas, maxPriorityFeePerGas, to } = tx;
|
55
7
|
if (chainId !== tx.chainId) {
|
package/dist/esm/index.d.ts
CHANGED
@@ -2,6 +2,6 @@ export * from "./near-safe";
|
|
2
2
|
export * from "./types";
|
3
3
|
export * from "./util";
|
4
4
|
export * from "./constants";
|
5
|
-
export
|
5
|
+
export { decodeTxData } from "./decode";
|
6
6
|
export * from "./lib/safe-message";
|
7
7
|
export { Network, BaseTx, SignRequestData, populateTx, NetworkFields, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, EthTransactionParams, } from "near-ca";
|
package/dist/esm/index.js
CHANGED
@@ -2,6 +2,6 @@ export * from "./near-safe";
|
|
2
2
|
export * from "./types";
|
3
3
|
export * from "./util";
|
4
4
|
export * from "./constants";
|
5
|
-
export
|
5
|
+
export { decodeTxData } from "./decode";
|
6
6
|
export * from "./lib/safe-message";
|
7
7
|
export { Network, populateTx, signatureFromOutcome, signatureFromTxHash, requestRouter as mpcRequestRouter, } from "near-ca";
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import { Hex } from "viem";
|
1
2
|
import { MetaTransaction } from "../types";
|
2
3
|
export declare const MULTI_SEND_ABI: string[];
|
3
4
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
4
5
|
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
6
|
+
export declare function decodeMultiViem(data: Hex): MetaTransaction[];
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { encodeFunctionData, encodePacked, parseAbi, size, } from "viem";
|
1
|
+
import { decodeFunctionData, encodeFunctionData, encodePacked, getAddress, parseAbi, size, toHex, } from "viem";
|
2
2
|
import { OperationType } from "../types";
|
3
3
|
export const MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
4
4
|
const MULTISEND_141 = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526";
|
@@ -39,3 +39,47 @@ export function isMultisendTx(args) {
|
|
39
39
|
return (to === MULTISEND_141.toLowerCase() ||
|
40
40
|
to === MULTISEND_CALLONLY_141.toLowerCase());
|
41
41
|
}
|
42
|
+
// import { Interface } from '@ethersproject/abi';
|
43
|
+
// import { getAddress } from '@ethersproject/address';
|
44
|
+
// import { BigNumber } from '@ethersproject/bignumber';
|
45
|
+
function unpack(packed, startIndex) {
|
46
|
+
// read operation from first 8 bits (= 2 hex digits)
|
47
|
+
const operation = parseInt(packed.substring(startIndex, startIndex + 2), 16);
|
48
|
+
// the next 40 characters are the to address
|
49
|
+
const to = getAddress(`0x${packed.substring(startIndex + 2, startIndex + 42)}`);
|
50
|
+
// then comes the uint256 value (= 64 hex digits)
|
51
|
+
const value = toHex(BigInt(`0x${packed.substring(startIndex + 42, startIndex + 106)}`));
|
52
|
+
// and the uint256 data length (= 64 hex digits)
|
53
|
+
const hexDataLength = parseInt(packed.substring(startIndex + 106, startIndex + 170), 16);
|
54
|
+
const endIndex = startIndex + 170 + hexDataLength * 2; // * 2 because each hex item is represented with 2 digits
|
55
|
+
const data = `0x${packed.substring(startIndex + 170, endIndex)}`;
|
56
|
+
return {
|
57
|
+
operation,
|
58
|
+
to,
|
59
|
+
value,
|
60
|
+
data,
|
61
|
+
endIndex,
|
62
|
+
};
|
63
|
+
}
|
64
|
+
export function decodeMultiViem(data) {
|
65
|
+
// const multiSendContract = new Interface(MULTI_SEND_ABI);
|
66
|
+
// const tx = multiSendContract.parseTransaction({ data });
|
67
|
+
// const multiSendAbiItem = parseAbiItem({
|
68
|
+
// type: "function",
|
69
|
+
// name: "multiSend",
|
70
|
+
// inputs: [{ name: "data", type: "bytes" }],
|
71
|
+
// });
|
72
|
+
const tx = decodeFunctionData({
|
73
|
+
abi: MULTI_SEND_ABI,
|
74
|
+
data,
|
75
|
+
});
|
76
|
+
const [transactionsEncoded] = tx.args;
|
77
|
+
const result = [];
|
78
|
+
let startIndex = 2; // skip over 0x
|
79
|
+
while (startIndex < transactionsEncoded.length) {
|
80
|
+
const { endIndex, ...tx } = unpack(transactionsEncoded, startIndex);
|
81
|
+
result.push(tx);
|
82
|
+
startIndex = endIndex;
|
83
|
+
}
|
84
|
+
return result;
|
85
|
+
}
|
package/package.json
CHANGED
package/dist/cjs/decode.d.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { EIP712TypedData } from "near-ca";
|
2
|
-
import { Hex, TransactionSerializable } from "viem";
|
3
|
-
import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "./types";
|
4
|
-
/**
|
5
|
-
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
6
|
-
*
|
7
|
-
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
8
|
-
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
9
|
-
*/
|
10
|
-
export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
|
11
|
-
export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
|
12
|
-
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
13
|
-
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
14
|
-
export declare function decodeUserOperation(chainId: number, userOp: UserOperation): DecodedTxData;
|
package/dist/esm/decode.d.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { EIP712TypedData } from "near-ca";
|
2
|
-
import { Hex, TransactionSerializable } from "viem";
|
3
|
-
import { DecodedTxData, SafeEncodedSignRequest, UserOperation } from "./types";
|
4
|
-
/**
|
5
|
-
* Decodes transaction data for a given EVM transaction and extracts relevant details.
|
6
|
-
*
|
7
|
-
* @param {EvmTransactionData} data - The raw transaction data to be decoded.
|
8
|
-
* @returns {DecodedTxData} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
|
9
|
-
*/
|
10
|
-
export declare function decodeTxData({ evmMessage, chainId, }: Omit<SafeEncodedSignRequest, "hashToSign">): DecodedTxData;
|
11
|
-
export declare function decodeTransactionSerializable(chainId: number, tx: TransactionSerializable): DecodedTxData;
|
12
|
-
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
13
|
-
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
14
|
-
export declare function decodeUserOperation(chainId: number, userOp: UserOperation): DecodedTxData;
|