near-safe 0.7.2 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -110,7 +110,7 @@ class SafeContractSuite {
110
110
  abi: this.m4337.abi,
111
111
  functionName: "executeUserOp",
112
112
  args: [
113
- txData.to,
113
+ (0, viem_1.getAddress)(txData.to),
114
114
  BigInt(txData.value),
115
115
  txData.data,
116
116
  txData.operation || 0,
@@ -160,7 +160,7 @@ export declare class NearSafe {
160
160
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
161
161
  *
162
162
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
163
- * @returns {{ chainId: number; costEstimate: string; transactions: MetaTransaction[] }} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
163
+ * @returns {DecodedMultisend} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
164
164
  */
165
165
  decodeTxData(data: EvmTransactionData): DecodedMultisend;
166
166
  /**
@@ -244,34 +244,49 @@ class NearSafe {
244
244
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
245
245
  *
246
246
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
247
- * @returns {{ chainId: number; costEstimate: string; transactions: MetaTransaction[] }} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
247
+ * @returns {DecodedMultisend} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
248
248
  */
249
249
  decodeTxData(data) {
250
- // TODO: data.data may not always parse to UserOperation. We will have to handle the other cases.
251
- const userOp = JSON.parse(data.data);
252
- const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
253
- const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
254
- const { args } = (0, viem_1.decodeFunctionData)({
255
- abi: this.safePack.m4337.abi,
256
- data: userOp.callData,
257
- });
258
- // Determine if singular or double!
259
- const transactions = (0, multisend_1.isMultisendTx)(args)
260
- ? (0, ethers_multisend_1.decodeMulti)(args[2])
261
- : [
262
- {
263
- to: args[0],
264
- value: args[1],
265
- data: args[2],
266
- operation: args[3],
267
- },
268
- ];
269
- return {
270
- chainId: data.chainId,
271
- // This is an upper bound on the gas fees (could be lower)
272
- costEstimate: (0, viem_1.formatEther)(BigInt(callGasLimit) * maxGasPrice),
273
- transactions,
274
- };
250
+ try {
251
+ const userOp = JSON.parse(data.data);
252
+ const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
253
+ const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
254
+ const { args } = (0, viem_1.decodeFunctionData)({
255
+ abi: this.safePack.m4337.abi,
256
+ data: userOp.callData,
257
+ });
258
+ // Determine if singular or double!
259
+ const transactions = (0, multisend_1.isMultisendTx)(args)
260
+ ? (0, ethers_multisend_1.decodeMulti)(args[2])
261
+ : [
262
+ {
263
+ to: args[0],
264
+ value: args[1],
265
+ data: args[2],
266
+ operation: args[3],
267
+ },
268
+ ];
269
+ return {
270
+ chainId: data.chainId,
271
+ // This is an upper bound on the gas fees (could be lower)
272
+ costEstimate: (0, viem_1.formatEther)(BigInt(callGasLimit) * maxGasPrice),
273
+ transactions,
274
+ };
275
+ }
276
+ catch (error) {
277
+ if (error instanceof SyntaxError) {
278
+ return {
279
+ chainId: data.chainId,
280
+ costEstimate: "0",
281
+ transactions: [],
282
+ message: data.data,
283
+ };
284
+ }
285
+ else {
286
+ const message = error instanceof Error ? error.message : String(error);
287
+ throw new Error(`decodeTxData: Unexpected error - ${message}`);
288
+ }
289
+ }
275
290
  }
276
291
  /**
277
292
  * Handles routing of signature requests based on the provided method, chain ID, and parameters.
@@ -308,7 +323,8 @@ class NearSafe {
308
323
  const [messageHash, _] = params;
309
324
  const message = (0, safe_message_1.decodeSafeMessage)(messageHash, safeInfo);
310
325
  return {
311
- evmMessage: message.safeMessageMessage,
326
+ // TODO(bh2smith) this is a bit of a hack.
327
+ evmMessage: message.decodedMessage,
312
328
  payload: (0, near_ca_1.toPayload)(message.safeMessageHash),
313
329
  hash: message.safeMessageHash,
314
330
  };
@@ -234,6 +234,8 @@ export interface DecodedMultisend {
234
234
  costEstimate: string;
235
235
  /** The list of meta-transactions included in the multisend. */
236
236
  transactions: MetaTransaction[];
237
+ /** Raw Message to sign if no transactions present. */
238
+ message?: string;
237
239
  }
238
240
  /**
239
241
  * Represents encoded transaction data for both NEAR and EVM networks.
@@ -1,4 +1,4 @@
1
- import { concat, encodeFunctionData, encodePacked, getCreate2Address, keccak256, toHex, zeroAddress, } from "viem";
1
+ import { concat, encodeFunctionData, encodePacked, getAddress, getCreate2Address, keccak256, toHex, zeroAddress, } from "viem";
2
2
  import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
3
3
  import { USER_OP_IDENTIFIER } from "../constants";
4
4
  import { PLACEHOLDER_SIG, getClient, packGas, packPaymasterData, } from "../util";
@@ -114,7 +114,7 @@ export class SafeContractSuite {
114
114
  abi: this.m4337.abi,
115
115
  functionName: "executeUserOp",
116
116
  args: [
117
- txData.to,
117
+ getAddress(txData.to),
118
118
  BigInt(txData.value),
119
119
  txData.data,
120
120
  txData.operation || 0,
@@ -160,7 +160,7 @@ export declare class NearSafe {
160
160
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
161
161
  *
162
162
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
163
- * @returns {{ chainId: number; costEstimate: string; transactions: MetaTransaction[] }} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
163
+ * @returns {DecodedMultisend} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
164
164
  */
165
165
  decodeTxData(data: EvmTransactionData): DecodedMultisend;
166
166
  /**
@@ -247,34 +247,49 @@ export class NearSafe {
247
247
  * Decodes transaction data for a given EVM transaction and extracts relevant details.
248
248
  *
249
249
  * @param {EvmTransactionData} data - The raw transaction data to be decoded.
250
- * @returns {{ chainId: number; costEstimate: string; transactions: MetaTransaction[] }} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
250
+ * @returns {DecodedMultisend} - An object containing the chain ID, estimated cost, and a list of decoded meta-transactions.
251
251
  */
252
252
  decodeTxData(data) {
253
- // TODO: data.data may not always parse to UserOperation. We will have to handle the other cases.
254
- const userOp = JSON.parse(data.data);
255
- const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
256
- const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
257
- const { args } = decodeFunctionData({
258
- abi: this.safePack.m4337.abi,
259
- data: userOp.callData,
260
- });
261
- // Determine if singular or double!
262
- const transactions = isMultisendTx(args)
263
- ? decodeMulti(args[2])
264
- : [
265
- {
266
- to: args[0],
267
- value: args[1],
268
- data: args[2],
269
- operation: args[3],
270
- },
271
- ];
272
- return {
273
- chainId: data.chainId,
274
- // This is an upper bound on the gas fees (could be lower)
275
- costEstimate: formatEther(BigInt(callGasLimit) * maxGasPrice),
276
- transactions,
277
- };
253
+ try {
254
+ const userOp = JSON.parse(data.data);
255
+ const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
256
+ const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
257
+ const { args } = decodeFunctionData({
258
+ abi: this.safePack.m4337.abi,
259
+ data: userOp.callData,
260
+ });
261
+ // Determine if singular or double!
262
+ const transactions = isMultisendTx(args)
263
+ ? decodeMulti(args[2])
264
+ : [
265
+ {
266
+ to: args[0],
267
+ value: args[1],
268
+ data: args[2],
269
+ operation: args[3],
270
+ },
271
+ ];
272
+ return {
273
+ chainId: data.chainId,
274
+ // This is an upper bound on the gas fees (could be lower)
275
+ costEstimate: formatEther(BigInt(callGasLimit) * maxGasPrice),
276
+ transactions,
277
+ };
278
+ }
279
+ catch (error) {
280
+ if (error instanceof SyntaxError) {
281
+ return {
282
+ chainId: data.chainId,
283
+ costEstimate: "0",
284
+ transactions: [],
285
+ message: data.data,
286
+ };
287
+ }
288
+ else {
289
+ const message = error instanceof Error ? error.message : String(error);
290
+ throw new Error(`decodeTxData: Unexpected error - ${message}`);
291
+ }
292
+ }
278
293
  }
279
294
  /**
280
295
  * Handles routing of signature requests based on the provided method, chain ID, and parameters.
@@ -311,7 +326,8 @@ export class NearSafe {
311
326
  const [messageHash, _] = params;
312
327
  const message = decodeSafeMessage(messageHash, safeInfo);
313
328
  return {
314
- evmMessage: message.safeMessageMessage,
329
+ // TODO(bh2smith) this is a bit of a hack.
330
+ evmMessage: message.decodedMessage,
315
331
  payload: toPayload(message.safeMessageHash),
316
332
  hash: message.safeMessageHash,
317
333
  };
@@ -234,6 +234,8 @@ export interface DecodedMultisend {
234
234
  costEstimate: string;
235
235
  /** The list of meta-transactions included in the multisend. */
236
236
  transactions: MetaTransaction[];
237
+ /** Raw Message to sign if no transactions present. */
238
+ message?: string;
237
239
  }
238
240
  /**
239
241
  * Represents encoded transaction data for both NEAR and EVM networks.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",