near-safe 0.8.4 → 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/util.d.ts +10 -0
- package/dist/cjs/decode/util.js +2 -2
- package/dist/cjs/lib/multisend.d.ts +2 -0
- package/dist/cjs/lib/multisend.js +45 -0
- package/dist/esm/decode/util.d.ts +10 -0
- package/dist/esm/decode/util.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
@@ -5,3 +5,13 @@ export declare function decodeTransactionSerializable(chainId: number, tx: Trans
|
|
5
5
|
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
6
6
|
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
7
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
|
+
}
|
package/dist/cjs/decode/util.js
CHANGED
@@ -4,7 +4,7 @@ exports.decodeTransactionSerializable = decodeTransactionSerializable;
|
|
4
4
|
exports.decodeRlpHex = decodeRlpHex;
|
5
5
|
exports.decodeTypedData = decodeTypedData;
|
6
6
|
exports.decodeUserOperation = decodeUserOperation;
|
7
|
-
const
|
7
|
+
const decodeMulti_1 = require("ethers-multisend/build/cjs/decodeMulti");
|
8
8
|
const viem_1 = require("viem");
|
9
9
|
const deployments_1 = require("../_gen/deployments");
|
10
10
|
const multisend_1 = require("../lib/multisend");
|
@@ -52,7 +52,7 @@ function decodeUserOperation(chainId, userOp) {
|
|
52
52
|
});
|
53
53
|
// Determine if singular or double!
|
54
54
|
const transactions = (0, multisend_1.isMultisendTx)(args)
|
55
|
-
? (0,
|
55
|
+
? (0, decodeMulti_1.decodeMulti)(args[2])
|
56
56
|
: [
|
57
57
|
{
|
58
58
|
to: args[0],
|
@@ -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
|
+
}
|
@@ -5,3 +5,13 @@ export declare function decodeTransactionSerializable(chainId: number, tx: Trans
|
|
5
5
|
export declare function decodeRlpHex(chainId: number, tx: Hex): DecodedTxData;
|
6
6
|
export declare function decodeTypedData(chainId: number, data: EIP712TypedData): DecodedTxData;
|
7
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
|
+
}
|
package/dist/esm/decode/util.js
CHANGED
@@ -1,4 +1,4 @@
|
|
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
3
|
import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
|
4
4
|
import { isMultisendTx } from "../lib/multisend";
|
@@ -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
|
+
}
|