near-safe 0.4.1 → 0.4.2
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/lib/multisend.d.ts +1 -0
- package/dist/cjs/lib/multisend.js +6 -0
- package/dist/cjs/near-safe.d.ts +6 -1
- package/dist/cjs/near-safe.js +28 -0
- package/dist/cjs/types.d.ts +7 -6
- package/dist/esm/lib/multisend.d.ts +1 -0
- package/dist/esm/lib/multisend.js +5 -0
- package/dist/esm/near-safe.d.ts +6 -1
- package/dist/esm/near-safe.js +30 -2
- package/dist/esm/types.d.ts +7 -6
- package/package.json +3 -3
@@ -1,3 +1,4 @@
|
|
1
1
|
import { MetaTransaction } from "../types";
|
2
2
|
export declare const MULTI_SEND_ABI: string[];
|
3
3
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
4
|
+
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
@@ -2,6 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.MULTI_SEND_ABI = void 0;
|
4
4
|
exports.encodeMulti = encodeMulti;
|
5
|
+
exports.isMultisendTx = isMultisendTx;
|
5
6
|
const viem_1 = require("viem");
|
6
7
|
const types_1 = require("../types");
|
7
8
|
exports.MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
@@ -38,3 +39,8 @@ function encodeMulti(transactions, multiSendContractAddress = transactions.some(
|
|
38
39
|
}),
|
39
40
|
};
|
40
41
|
}
|
42
|
+
function isMultisendTx(args) {
|
43
|
+
const to = args[0].toLowerCase();
|
44
|
+
return (to === MULTISEND_141.toLowerCase() ||
|
45
|
+
to === MULTISEND_CALLONLY_141.toLowerCase());
|
46
|
+
}
|
package/dist/cjs/near-safe.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
|
3
3
|
import { NearEthAdapter, SignRequestData } from "near-ca";
|
4
4
|
import { Address, Hash, Hex } from "viem";
|
5
5
|
import { SafeContractSuite } from "./lib/safe";
|
6
|
-
import { EncodedTxData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
6
|
+
import { EncodedTxData, EvmTransactionData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export interface NearSafeConfig {
|
8
8
|
accountId: string;
|
9
9
|
mpcContractId: string;
|
@@ -41,6 +41,11 @@ export declare class NearSafe {
|
|
41
41
|
sufficientlyFunded(chainId: number, transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
42
42
|
addOwnerTx(address: Address): MetaTransaction;
|
43
43
|
private bundlerForChainId;
|
44
|
+
decodeTxData(data: EvmTransactionData): {
|
45
|
+
chainId: number;
|
46
|
+
costEstimate: string;
|
47
|
+
transactions: MetaTransaction[];
|
48
|
+
};
|
44
49
|
/**
|
45
50
|
* Handles routing of signature requests based on the provided method, chain ID, and parameters.
|
46
51
|
*
|
package/dist/cjs/near-safe.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.NearSafe = void 0;
|
4
|
+
const ethers_multisend_1 = require("ethers-multisend");
|
4
5
|
const near_ca_1 = require("near-ca");
|
5
6
|
const viem_1 = require("viem");
|
6
7
|
const bundler_1 = require("./lib/bundler");
|
@@ -126,6 +127,33 @@ class NearSafe {
|
|
126
127
|
bundlerForChainId(chainId) {
|
127
128
|
return new bundler_1.Erc4337Bundler(this.safePack.entryPoint.address, this.pimlicoKey, chainId);
|
128
129
|
}
|
130
|
+
decodeTxData(data) {
|
131
|
+
// TODO: data.data may not always parse to UserOperation. We will have to handle the other cases.
|
132
|
+
const userOp = JSON.parse(data.data);
|
133
|
+
const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
|
134
|
+
const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
|
135
|
+
const { args } = (0, viem_1.decodeFunctionData)({
|
136
|
+
abi: this.safePack.m4337.abi,
|
137
|
+
data: userOp.callData,
|
138
|
+
});
|
139
|
+
// Determine if sungular or double!
|
140
|
+
const transactions = (0, multisend_1.isMultisendTx)(args)
|
141
|
+
? (0, ethers_multisend_1.decodeMulti)(args[2])
|
142
|
+
: [
|
143
|
+
{
|
144
|
+
to: args[0],
|
145
|
+
value: args[1],
|
146
|
+
data: args[2],
|
147
|
+
operation: args[3],
|
148
|
+
},
|
149
|
+
];
|
150
|
+
return {
|
151
|
+
chainId: data.chainId,
|
152
|
+
// This is an upper bound on the gas fees (could be lower)
|
153
|
+
costEstimate: (0, viem_1.formatEther)(BigInt(callGasLimit) * maxGasPrice),
|
154
|
+
transactions,
|
155
|
+
};
|
156
|
+
}
|
129
157
|
/**
|
130
158
|
* Handles routing of signature requests based on the provided method, chain ID, and parameters.
|
131
159
|
*
|
package/dist/cjs/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FunctionCallTransaction, SignArgs } from "near-ca";
|
2
|
-
import { Address,
|
2
|
+
import { Address, Hex, ParseAbi } from "viem";
|
3
3
|
export type SafeDeployments = {
|
4
4
|
singleton: Deployment;
|
5
5
|
proxyFactory: Deployment;
|
@@ -101,12 +101,13 @@ export interface MetaTransaction {
|
|
101
101
|
readonly data: string;
|
102
102
|
readonly operation?: OperationType;
|
103
103
|
}
|
104
|
+
export interface EvmTransactionData {
|
105
|
+
chainId: number;
|
106
|
+
data: string;
|
107
|
+
hash: string;
|
108
|
+
}
|
104
109
|
export interface EncodedTxData {
|
105
|
-
evmData:
|
106
|
-
chainId: number;
|
107
|
-
data: string | TransactionSerializable;
|
108
|
-
hash: Hash;
|
109
|
-
};
|
110
|
+
evmData: EvmTransactionData;
|
110
111
|
nearPayload: FunctionCallTransaction<{
|
111
112
|
request: SignArgs;
|
112
113
|
}>;
|
@@ -1,3 +1,4 @@
|
|
1
1
|
import { MetaTransaction } from "../types";
|
2
2
|
export declare const MULTI_SEND_ABI: string[];
|
3
3
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
4
|
+
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
@@ -34,3 +34,8 @@ export function encodeMulti(transactions, multiSendContractAddress = transaction
|
|
34
34
|
}),
|
35
35
|
};
|
36
36
|
}
|
37
|
+
export function isMultisendTx(args) {
|
38
|
+
const to = args[0].toLowerCase();
|
39
|
+
return (to === MULTISEND_141.toLowerCase() ||
|
40
|
+
to === MULTISEND_CALLONLY_141.toLowerCase());
|
41
|
+
}
|
package/dist/esm/near-safe.d.ts
CHANGED
@@ -3,7 +3,7 @@ import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
|
3
3
|
import { NearEthAdapter, SignRequestData } from "near-ca";
|
4
4
|
import { Address, Hash, Hex } from "viem";
|
5
5
|
import { SafeContractSuite } from "./lib/safe";
|
6
|
-
import { EncodedTxData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
6
|
+
import { EncodedTxData, EvmTransactionData, MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export interface NearSafeConfig {
|
8
8
|
accountId: string;
|
9
9
|
mpcContractId: string;
|
@@ -41,6 +41,11 @@ export declare class NearSafe {
|
|
41
41
|
sufficientlyFunded(chainId: number, transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
42
42
|
addOwnerTx(address: Address): MetaTransaction;
|
43
43
|
private bundlerForChainId;
|
44
|
+
decodeTxData(data: EvmTransactionData): {
|
45
|
+
chainId: number;
|
46
|
+
costEstimate: string;
|
47
|
+
transactions: MetaTransaction[];
|
48
|
+
};
|
44
49
|
/**
|
45
50
|
* Handles routing of signature requests based on the provided method, chain ID, and parameters.
|
46
51
|
*
|
package/dist/esm/near-safe.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
+
import { decodeMulti } from "ethers-multisend";
|
1
2
|
import { setupAdapter, signatureFromOutcome, toPayload, } from "near-ca";
|
2
|
-
import { serializeSignature } from "viem";
|
3
|
+
import { decodeFunctionData, formatEther, serializeSignature, } from "viem";
|
3
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
4
|
-
import { encodeMulti } from "./lib/multisend";
|
5
|
+
import { encodeMulti, isMultisendTx } from "./lib/multisend";
|
5
6
|
import { SafeContractSuite } from "./lib/safe";
|
6
7
|
import { decodeSafeMessage } from "./lib/safe-message";
|
7
8
|
import { getClient, isContract, metaTransactionsFromRequest, packSignature, } from "./util";
|
@@ -129,6 +130,33 @@ export class NearSafe {
|
|
129
130
|
bundlerForChainId(chainId) {
|
130
131
|
return new Erc4337Bundler(this.safePack.entryPoint.address, this.pimlicoKey, chainId);
|
131
132
|
}
|
133
|
+
decodeTxData(data) {
|
134
|
+
// TODO: data.data may not always parse to UserOperation. We will have to handle the other cases.
|
135
|
+
const userOp = JSON.parse(data.data);
|
136
|
+
const { callGasLimit, maxFeePerGas, maxPriorityFeePerGas } = userOp;
|
137
|
+
const maxGasPrice = BigInt(maxFeePerGas) + BigInt(maxPriorityFeePerGas);
|
138
|
+
const { args } = decodeFunctionData({
|
139
|
+
abi: this.safePack.m4337.abi,
|
140
|
+
data: userOp.callData,
|
141
|
+
});
|
142
|
+
// Determine if sungular or double!
|
143
|
+
const transactions = isMultisendTx(args)
|
144
|
+
? decodeMulti(args[2])
|
145
|
+
: [
|
146
|
+
{
|
147
|
+
to: args[0],
|
148
|
+
value: args[1],
|
149
|
+
data: args[2],
|
150
|
+
operation: args[3],
|
151
|
+
},
|
152
|
+
];
|
153
|
+
return {
|
154
|
+
chainId: data.chainId,
|
155
|
+
// This is an upper bound on the gas fees (could be lower)
|
156
|
+
costEstimate: formatEther(BigInt(callGasLimit) * maxGasPrice),
|
157
|
+
transactions,
|
158
|
+
};
|
159
|
+
}
|
132
160
|
/**
|
133
161
|
* Handles routing of signature requests based on the provided method, chain ID, and parameters.
|
134
162
|
*
|
package/dist/esm/types.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { FunctionCallTransaction, SignArgs } from "near-ca";
|
2
|
-
import { Address,
|
2
|
+
import { Address, Hex, ParseAbi } from "viem";
|
3
3
|
export type SafeDeployments = {
|
4
4
|
singleton: Deployment;
|
5
5
|
proxyFactory: Deployment;
|
@@ -101,12 +101,13 @@ export interface MetaTransaction {
|
|
101
101
|
readonly data: string;
|
102
102
|
readonly operation?: OperationType;
|
103
103
|
}
|
104
|
+
export interface EvmTransactionData {
|
105
|
+
chainId: number;
|
106
|
+
data: string;
|
107
|
+
hash: string;
|
108
|
+
}
|
104
109
|
export interface EncodedTxData {
|
105
|
-
evmData:
|
106
|
-
chainId: number;
|
107
|
-
data: string | TransactionSerializable;
|
108
|
-
hash: Hash;
|
109
|
-
};
|
110
|
+
evmData: EvmTransactionData;
|
110
111
|
nearPayload: FunctionCallTransaction<{
|
111
112
|
request: SignArgs;
|
112
113
|
}>;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "near-safe",
|
3
|
-
"version": "0.4.
|
3
|
+
"version": "0.4.2",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
|
6
6
|
"author": "bh2smith",
|
@@ -42,6 +42,7 @@
|
|
42
42
|
},
|
43
43
|
"dependencies": {
|
44
44
|
"@safe-global/safe-gateway-typescript-sdk": "^3.22.2",
|
45
|
+
"ethers-multisend": "^3.1.0",
|
45
46
|
"near-api-js": "^5.0.0",
|
46
47
|
"near-ca": "^0.5.6",
|
47
48
|
"semver": "^7.6.3",
|
@@ -68,7 +69,6 @@
|
|
68
69
|
"yargs": "^17.7.2"
|
69
70
|
},
|
70
71
|
"resolutions": {
|
71
|
-
"glob": "^
|
72
|
-
"base-x": "^3.0.0"
|
72
|
+
"glob": "^11.0.0"
|
73
73
|
}
|
74
74
|
}
|