near-safe 0.8.5-beta.0 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/constants.d.ts +1 -0
- package/dist/cjs/constants.js +2 -1
- package/dist/cjs/decode/util.js +1 -2
- package/dist/cjs/lib/multisend.d.ts +1 -1
- package/dist/cjs/lib/multisend.js +3 -13
- package/dist/cjs/lib/safe.d.ts +2 -2
- package/dist/cjs/lib/safe.js +3 -3
- package/dist/cjs/near-safe.d.ts +6 -13
- package/dist/cjs/near-safe.js +11 -15
- package/dist/cjs/util.js +5 -0
- package/dist/esm/constants.d.ts +1 -0
- package/dist/esm/constants.js +1 -0
- package/dist/esm/decode/util.js +1 -2
- package/dist/esm/lib/multisend.d.ts +1 -1
- package/dist/esm/lib/multisend.js +2 -12
- package/dist/esm/lib/safe.d.ts +2 -2
- package/dist/esm/lib/safe.js +6 -6
- package/dist/esm/near-safe.d.ts +6 -13
- package/dist/esm/near-safe.js +13 -17
- package/dist/esm/util.js +6 -1
- package/package.json +2 -2
package/dist/cjs/constants.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare const USER_OP_IDENTIFIER: `0x${string}`;
|
2
2
|
export declare const DEFAULT_SAFE_SALT_NONCE: string;
|
3
3
|
export declare const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
|
4
|
+
export declare const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
|
package/dist/cjs/constants.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.SENTINEL_OWNERS = exports.DEFAULT_SAFE_SALT_NONCE = exports.USER_OP_IDENTIFIER = void 0;
|
3
|
+
exports.DEFAULT_SETUP_RPC = exports.SENTINEL_OWNERS = exports.DEFAULT_SAFE_SALT_NONCE = exports.USER_OP_IDENTIFIER = void 0;
|
4
4
|
const viem_1 = require("viem");
|
5
5
|
const DOMAIN_SEPARATOR = "bitte/near-safe";
|
6
6
|
// 0x62697474652f6e6561722d7361666500
|
@@ -8,3 +8,4 @@ exports.USER_OP_IDENTIFIER = (0, viem_1.toHex)(DOMAIN_SEPARATOR, { size: 16 });
|
|
8
8
|
// 130811896738364114529934864114944206080
|
9
9
|
exports.DEFAULT_SAFE_SALT_NONCE = BigInt(exports.USER_OP_IDENTIFIER).toString();
|
10
10
|
exports.SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
|
11
|
+
exports.DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
|
package/dist/cjs/decode/util.js
CHANGED
@@ -4,7 +4,6 @@ exports.decodeTransactionSerializable = decodeTransactionSerializable;
|
|
4
4
|
exports.decodeRlpHex = decodeRlpHex;
|
5
5
|
exports.decodeTypedData = decodeTypedData;
|
6
6
|
exports.decodeUserOperation = decodeUserOperation;
|
7
|
-
const decodeMulti_1 = require("ethers-multisend/build/cjs/decodeMulti");
|
8
7
|
const viem_1 = require("viem");
|
9
8
|
const deployments_1 = require("../_gen/deployments");
|
10
9
|
const multisend_1 = require("../lib/multisend");
|
@@ -52,7 +51,7 @@ function decodeUserOperation(chainId, userOp) {
|
|
52
51
|
});
|
53
52
|
// Determine if singular or double!
|
54
53
|
const transactions = (0, multisend_1.isMultisendTx)(args)
|
55
|
-
? (0,
|
54
|
+
? (0, multisend_1.decodeMulti)(args[2])
|
56
55
|
: [
|
57
56
|
{
|
58
57
|
to: args[0],
|
@@ -3,4 +3,4 @@ import { MetaTransaction } from "../types";
|
|
3
3
|
export declare const MULTI_SEND_ABI: string[];
|
4
4
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
5
5
|
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
6
|
-
export declare function
|
6
|
+
export declare function decodeMulti(data: Hex): MetaTransaction[];
|
@@ -3,7 +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.
|
6
|
+
exports.decodeMulti = decodeMulti;
|
7
7
|
const viem_1 = require("viem");
|
8
8
|
const types_1 = require("../types");
|
9
9
|
exports.MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
@@ -45,9 +45,6 @@ function isMultisendTx(args) {
|
|
45
45
|
return (to === MULTISEND_141.toLowerCase() ||
|
46
46
|
to === MULTISEND_CALLONLY_141.toLowerCase());
|
47
47
|
}
|
48
|
-
// import { Interface } from '@ethersproject/abi';
|
49
|
-
// import { getAddress } from '@ethersproject/address';
|
50
|
-
// import { BigNumber } from '@ethersproject/bignumber';
|
51
48
|
function unpack(packed, startIndex) {
|
52
49
|
// read operation from first 8 bits (= 2 hex digits)
|
53
50
|
const operation = parseInt(packed.substring(startIndex, startIndex + 2), 16);
|
@@ -67,16 +64,9 @@ function unpack(packed, startIndex) {
|
|
67
64
|
endIndex,
|
68
65
|
};
|
69
66
|
}
|
70
|
-
function
|
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
|
-
// });
|
67
|
+
function decodeMulti(data) {
|
78
68
|
const tx = (0, viem_1.decodeFunctionData)({
|
79
|
-
abi: exports.MULTI_SEND_ABI,
|
69
|
+
abi: (0, viem_1.parseAbi)(exports.MULTI_SEND_ABI),
|
80
70
|
data,
|
81
71
|
});
|
82
72
|
const [transactionsEncoded] = tx.args;
|
package/dist/cjs/lib/safe.d.ts
CHANGED
@@ -4,13 +4,13 @@ import { Deployment, GasPrice, MetaTransaction, UnsignedUserOperation, UserOpera
|
|
4
4
|
* All contracts used in account creation & execution
|
5
5
|
*/
|
6
6
|
export declare class SafeContractSuite {
|
7
|
-
|
7
|
+
setupClient: PublicClient;
|
8
8
|
singleton: Deployment;
|
9
9
|
proxyFactory: Deployment;
|
10
10
|
m4337: Deployment;
|
11
11
|
moduleSetup: Deployment;
|
12
12
|
entryPoint: Deployment;
|
13
|
-
constructor();
|
13
|
+
constructor(rpcUrl?: string);
|
14
14
|
addressForSetup(setup: Hex, saltNonce: string): Promise<Address>;
|
15
15
|
getSetup(owners: string[]): Hex;
|
16
16
|
addOwnerData(newOwner: Address): Hex;
|
package/dist/cjs/lib/safe.js
CHANGED
@@ -9,8 +9,8 @@ const util_1 = require("../util");
|
|
9
9
|
* All contracts used in account creation & execution
|
10
10
|
*/
|
11
11
|
class SafeContractSuite {
|
12
|
-
constructor() {
|
13
|
-
this.
|
12
|
+
constructor(rpcUrl = constants_1.DEFAULT_SETUP_RPC) {
|
13
|
+
this.setupClient = (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(rpcUrl) });
|
14
14
|
const deployments = deployments_1.SAFE_DEPLOYMENTS;
|
15
15
|
this.singleton = deployments.singleton;
|
16
16
|
this.proxyFactory = deployments.proxyFactory;
|
@@ -25,7 +25,7 @@ class SafeContractSuite {
|
|
25
25
|
// abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
|
26
26
|
// cf: https://github.com/safe-global/safe-smart-account/blob/499b17ad0191b575fcadc5cb5b8e3faeae5391ae/contracts/proxies/SafeProxyFactory.sol#L29
|
27
27
|
const initCode = (0, viem_1.encodePacked)(["bytes", "uint256"], [
|
28
|
-
(await this.
|
28
|
+
(await this.setupClient.readContract({
|
29
29
|
address: this.proxyFactory.address,
|
30
30
|
abi: this.proxyFactory.abi,
|
31
31
|
functionName: "proxyCreationCode",
|
package/dist/cjs/near-safe.d.ts
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
3
|
-
import { NearEthAdapter, SignRequestData, EncodedSignRequest } from "near-ca";
|
1
|
+
import { NearEthAdapter, SignRequestData, EncodedSignRequest, SetupConfig as MpcConfig } from "near-ca";
|
4
2
|
import { Address, Hash, Hex } from "viem";
|
5
3
|
import { SafeContractSuite } from "./lib/safe";
|
6
4
|
import { EncodedTxData, MetaTransaction, SponsorshipPolicyData, UserOperation, UserOperationReceipt } from "./types";
|
7
5
|
export interface NearSafeConfig {
|
8
|
-
|
9
|
-
mpcContractId: string;
|
10
|
-
nearConfig?: NearConfig;
|
11
|
-
privateKey?: string;
|
6
|
+
mpc: MpcConfig;
|
12
7
|
pimlicoKey: string;
|
13
8
|
safeSaltNonce?: string;
|
9
|
+
setupRpc?: string;
|
14
10
|
}
|
15
11
|
export declare class NearSafe {
|
16
12
|
readonly nearAdapter: NearEthAdapter;
|
@@ -99,15 +95,12 @@ export declare class NearSafe {
|
|
99
95
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
100
96
|
*
|
101
97
|
* @param {number} chainId - The ID of the EVM network to which the transaction should be broadcasted.
|
102
|
-
* @param {
|
98
|
+
* @param {Signature} signature - The valid signature of the unsignedUserOp.
|
103
99
|
* @param {UserOperation} unsignedUserOp - The unsigned user operation to be broadcasted. This includes transaction data such as the destination address and data payload.
|
104
|
-
* @returns {Promise<
|
100
|
+
* @returns {Promise<Hash>} - A promise that resolves hash of the executed user operation.
|
105
101
|
* @throws {Error} - Throws an error if the EVM broadcast fails, including the error message for debugging.
|
106
102
|
*/
|
107
|
-
|
108
|
-
signature: Hex;
|
109
|
-
opHash: Hash;
|
110
|
-
}>;
|
103
|
+
broadcastBundler(chainId: number, signatureHex: Hex, unsignedUserOp: UserOperation): Promise<Hash>;
|
111
104
|
/**
|
112
105
|
* Executes a user operation on the specified blockchain network.
|
113
106
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
package/dist/cjs/near-safe.js
CHANGED
@@ -17,11 +17,11 @@ class NearSafe {
|
|
17
17
|
* @returns {Promise<NearSafe>} - A promise that resolves to a new `NearSafe` instance.
|
18
18
|
*/
|
19
19
|
static async create(config) {
|
20
|
-
const { pimlicoKey } = config;
|
20
|
+
const { pimlicoKey, setupRpc } = config;
|
21
21
|
const safeSaltNonce = config.safeSaltNonce || constants_1.DEFAULT_SAFE_SALT_NONCE;
|
22
22
|
// const nearAdapter = await mockAdapter();
|
23
|
-
const nearAdapter = await (0, near_ca_1.setupAdapter)(
|
24
|
-
const safePack = new safe_1.SafeContractSuite();
|
23
|
+
const nearAdapter = await (0, near_ca_1.setupAdapter)(config.mpc);
|
24
|
+
const safePack = new safe_1.SafeContractSuite(setupRpc);
|
25
25
|
const setup = safePack.getSetup([nearAdapter.address]);
|
26
26
|
const safeAddress = await safePack.addressForSetup(setup, safeSaltNonce);
|
27
27
|
console.log(`
|
@@ -150,24 +150,20 @@ class NearSafe {
|
|
150
150
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
151
151
|
*
|
152
152
|
* @param {number} chainId - The ID of the EVM network to which the transaction should be broadcasted.
|
153
|
-
* @param {
|
153
|
+
* @param {Signature} signature - The valid signature of the unsignedUserOp.
|
154
154
|
* @param {UserOperation} unsignedUserOp - The unsigned user operation to be broadcasted. This includes transaction data such as the destination address and data payload.
|
155
|
-
* @returns {Promise<
|
155
|
+
* @returns {Promise<Hash>} - A promise that resolves hash of the executed user operation.
|
156
156
|
* @throws {Error} - Throws an error if the EVM broadcast fails, including the error message for debugging.
|
157
157
|
*/
|
158
|
-
async
|
159
|
-
const signature = (0, util_1.packSignature)((0, viem_1.serializeSignature)((0, near_ca_1.signatureFromOutcome)(outcome)));
|
158
|
+
async broadcastBundler(chainId, signatureHex, unsignedUserOp) {
|
160
159
|
try {
|
161
|
-
return {
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
signature,
|
166
|
-
}),
|
167
|
-
};
|
160
|
+
return this.executeTransaction(chainId, {
|
161
|
+
...unsignedUserOp,
|
162
|
+
signature: (0, util_1.packSignature)(signatureHex),
|
163
|
+
});
|
168
164
|
}
|
169
165
|
catch (error) {
|
170
|
-
throw new Error(`Failed
|
166
|
+
throw new Error(`Failed Bundler broadcast: ${error instanceof Error ? error.message : String(error)}`);
|
171
167
|
}
|
172
168
|
}
|
173
169
|
/**
|
package/dist/cjs/util.js
CHANGED
@@ -13,6 +13,7 @@ exports.raceToFirstResolve = raceToFirstResolve;
|
|
13
13
|
exports.assertUnique = assertUnique;
|
14
14
|
const near_ca_1 = require("near-ca");
|
15
15
|
const viem_1 = require("viem");
|
16
|
+
const constants_1 = require("./constants");
|
16
17
|
exports.PLACEHOLDER_SIG = (0, viem_1.encodePacked)(["uint48", "uint48"], [0, 0]);
|
17
18
|
const packGas = (hi, lo) => (0, viem_1.encodePacked)(["uint128", "uint128"], [BigInt(hi), BigInt(lo)]);
|
18
19
|
exports.packGas = packGas;
|
@@ -36,6 +37,10 @@ async function isContract(address, chainId) {
|
|
36
37
|
return (await getClient(chainId).getCode({ address })) !== undefined;
|
37
38
|
}
|
38
39
|
function getClient(chainId) {
|
40
|
+
// TODO(bh2smith)
|
41
|
+
if (chainId === 11155111) {
|
42
|
+
return (0, viem_1.createPublicClient)({ transport: (0, viem_1.http)(constants_1.DEFAULT_SETUP_RPC) });
|
43
|
+
}
|
39
44
|
return near_ca_1.Network.fromChainId(chainId).client;
|
40
45
|
}
|
41
46
|
function metaTransactionsFromRequest(params) {
|
package/dist/esm/constants.d.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
1
1
|
export declare const USER_OP_IDENTIFIER: `0x${string}`;
|
2
2
|
export declare const DEFAULT_SAFE_SALT_NONCE: string;
|
3
3
|
export declare const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
|
4
|
+
export declare const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
|
package/dist/esm/constants.js
CHANGED
@@ -5,3 +5,4 @@ export const USER_OP_IDENTIFIER = toHex(DOMAIN_SEPARATOR, { size: 16 });
|
|
5
5
|
// 130811896738364114529934864114944206080
|
6
6
|
export const DEFAULT_SAFE_SALT_NONCE = BigInt(USER_OP_IDENTIFIER).toString();
|
7
7
|
export const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";
|
8
|
+
export const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
|
package/dist/esm/decode/util.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
-
import { decodeMulti } from "ethers-multisend/build/cjs/decodeMulti";
|
2
1
|
import { decodeFunctionData, formatEther, parseTransaction, serializeTransaction, } from "viem";
|
3
2
|
import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
|
4
|
-
import { isMultisendTx } from "../lib/multisend";
|
3
|
+
import { decodeMulti, isMultisendTx } from "../lib/multisend";
|
5
4
|
export function decodeTransactionSerializable(chainId, tx) {
|
6
5
|
const { gas, maxFeePerGas, maxPriorityFeePerGas, to } = tx;
|
7
6
|
if (chainId !== tx.chainId) {
|
@@ -3,4 +3,4 @@ import { MetaTransaction } from "../types";
|
|
3
3
|
export declare const MULTI_SEND_ABI: string[];
|
4
4
|
export declare function encodeMulti(transactions: readonly MetaTransaction[], multiSendContractAddress?: string): MetaTransaction;
|
5
5
|
export declare function isMultisendTx(args: readonly unknown[]): boolean;
|
6
|
-
export declare function
|
6
|
+
export declare function decodeMulti(data: Hex): MetaTransaction[];
|
@@ -39,9 +39,6 @@ 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
42
|
function unpack(packed, startIndex) {
|
46
43
|
// read operation from first 8 bits (= 2 hex digits)
|
47
44
|
const operation = parseInt(packed.substring(startIndex, startIndex + 2), 16);
|
@@ -61,16 +58,9 @@ function unpack(packed, startIndex) {
|
|
61
58
|
endIndex,
|
62
59
|
};
|
63
60
|
}
|
64
|
-
export function
|
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
|
-
// });
|
61
|
+
export function decodeMulti(data) {
|
72
62
|
const tx = decodeFunctionData({
|
73
|
-
abi: MULTI_SEND_ABI,
|
63
|
+
abi: parseAbi(MULTI_SEND_ABI),
|
74
64
|
data,
|
75
65
|
});
|
76
66
|
const [transactionsEncoded] = tx.args;
|
package/dist/esm/lib/safe.d.ts
CHANGED
@@ -4,13 +4,13 @@ import { Deployment, GasPrice, MetaTransaction, UnsignedUserOperation, UserOpera
|
|
4
4
|
* All contracts used in account creation & execution
|
5
5
|
*/
|
6
6
|
export declare class SafeContractSuite {
|
7
|
-
|
7
|
+
setupClient: PublicClient;
|
8
8
|
singleton: Deployment;
|
9
9
|
proxyFactory: Deployment;
|
10
10
|
m4337: Deployment;
|
11
11
|
moduleSetup: Deployment;
|
12
12
|
entryPoint: Deployment;
|
13
|
-
constructor();
|
13
|
+
constructor(rpcUrl?: string);
|
14
14
|
addressForSetup(setup: Hex, saltNonce: string): Promise<Address>;
|
15
15
|
getSetup(owners: string[]): Hex;
|
16
16
|
addOwnerData(newOwner: Address): Hex;
|
package/dist/esm/lib/safe.js
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
import { concat, encodeFunctionData, encodePacked, getAddress, getCreate2Address, keccak256, parseAbi, toHex, zeroAddress, } from "viem";
|
1
|
+
import { concat, createPublicClient, encodeFunctionData, encodePacked, getAddress, getCreate2Address, http, keccak256, parseAbi, toHex, zeroAddress, } from "viem";
|
2
2
|
import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
|
3
|
-
import { SENTINEL_OWNERS, USER_OP_IDENTIFIER } from "../constants";
|
3
|
+
import { DEFAULT_SETUP_RPC, SENTINEL_OWNERS, USER_OP_IDENTIFIER, } from "../constants";
|
4
4
|
import { PLACEHOLDER_SIG, getClient, packGas, packPaymasterData, } from "../util";
|
5
5
|
/**
|
6
6
|
* All contracts used in account creation & execution
|
7
7
|
*/
|
8
8
|
export class SafeContractSuite {
|
9
9
|
// Used only for stateless contract reads.
|
10
|
-
|
10
|
+
setupClient;
|
11
11
|
singleton;
|
12
12
|
proxyFactory;
|
13
13
|
m4337;
|
14
14
|
moduleSetup;
|
15
15
|
entryPoint;
|
16
|
-
constructor() {
|
17
|
-
this.
|
16
|
+
constructor(rpcUrl = DEFAULT_SETUP_RPC) {
|
17
|
+
this.setupClient = createPublicClient({ transport: http(rpcUrl) });
|
18
18
|
const deployments = SAFE_DEPLOYMENTS;
|
19
19
|
this.singleton = deployments.singleton;
|
20
20
|
this.proxyFactory = deployments.proxyFactory;
|
@@ -29,7 +29,7 @@ export class SafeContractSuite {
|
|
29
29
|
// abi.encodePacked(type(SafeProxy).creationCode, uint256(uint160(_singleton)));
|
30
30
|
// cf: https://github.com/safe-global/safe-smart-account/blob/499b17ad0191b575fcadc5cb5b8e3faeae5391ae/contracts/proxies/SafeProxyFactory.sol#L29
|
31
31
|
const initCode = encodePacked(["bytes", "uint256"], [
|
32
|
-
(await this.
|
32
|
+
(await this.setupClient.readContract({
|
33
33
|
address: this.proxyFactory.address,
|
34
34
|
abi: this.proxyFactory.abi,
|
35
35
|
functionName: "proxyCreationCode",
|
package/dist/esm/near-safe.d.ts
CHANGED
@@ -1,16 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
3
|
-
import { NearEthAdapter, SignRequestData, EncodedSignRequest } from "near-ca";
|
1
|
+
import { NearEthAdapter, SignRequestData, EncodedSignRequest, SetupConfig as MpcConfig } from "near-ca";
|
4
2
|
import { Address, Hash, Hex } from "viem";
|
5
3
|
import { SafeContractSuite } from "./lib/safe";
|
6
4
|
import { EncodedTxData, MetaTransaction, SponsorshipPolicyData, UserOperation, UserOperationReceipt } from "./types";
|
7
5
|
export interface NearSafeConfig {
|
8
|
-
|
9
|
-
mpcContractId: string;
|
10
|
-
nearConfig?: NearConfig;
|
11
|
-
privateKey?: string;
|
6
|
+
mpc: MpcConfig;
|
12
7
|
pimlicoKey: string;
|
13
8
|
safeSaltNonce?: string;
|
9
|
+
setupRpc?: string;
|
14
10
|
}
|
15
11
|
export declare class NearSafe {
|
16
12
|
readonly nearAdapter: NearEthAdapter;
|
@@ -99,15 +95,12 @@ export declare class NearSafe {
|
|
99
95
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
100
96
|
*
|
101
97
|
* @param {number} chainId - The ID of the EVM network to which the transaction should be broadcasted.
|
102
|
-
* @param {
|
98
|
+
* @param {Signature} signature - The valid signature of the unsignedUserOp.
|
103
99
|
* @param {UserOperation} unsignedUserOp - The unsigned user operation to be broadcasted. This includes transaction data such as the destination address and data payload.
|
104
|
-
* @returns {Promise<
|
100
|
+
* @returns {Promise<Hash>} - A promise that resolves hash of the executed user operation.
|
105
101
|
* @throws {Error} - Throws an error if the EVM broadcast fails, including the error message for debugging.
|
106
102
|
*/
|
107
|
-
|
108
|
-
signature: Hex;
|
109
|
-
opHash: Hash;
|
110
|
-
}>;
|
103
|
+
broadcastBundler(chainId: number, signatureHex: Hex, unsignedUserOp: UserOperation): Promise<Hash>;
|
111
104
|
/**
|
112
105
|
* Executes a user operation on the specified blockchain network.
|
113
106
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
package/dist/esm/near-safe.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { setupAdapter,
|
2
|
-
import {
|
1
|
+
import { setupAdapter, toPayload, requestRouter as mpcRequestRouter, } from "near-ca";
|
2
|
+
import { zeroAddress } from "viem";
|
3
3
|
import { DEFAULT_SAFE_SALT_NONCE } from "./constants";
|
4
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
5
5
|
import { encodeMulti } from "./lib/multisend";
|
@@ -20,11 +20,11 @@ export class NearSafe {
|
|
20
20
|
* @returns {Promise<NearSafe>} - A promise that resolves to a new `NearSafe` instance.
|
21
21
|
*/
|
22
22
|
static async create(config) {
|
23
|
-
const { pimlicoKey } = config;
|
23
|
+
const { pimlicoKey, setupRpc } = config;
|
24
24
|
const safeSaltNonce = config.safeSaltNonce || DEFAULT_SAFE_SALT_NONCE;
|
25
25
|
// const nearAdapter = await mockAdapter();
|
26
|
-
const nearAdapter = await setupAdapter(
|
27
|
-
const safePack = new SafeContractSuite();
|
26
|
+
const nearAdapter = await setupAdapter(config.mpc);
|
27
|
+
const safePack = new SafeContractSuite(setupRpc);
|
28
28
|
const setup = safePack.getSetup([nearAdapter.address]);
|
29
29
|
const safeAddress = await safePack.addressForSetup(setup, safeSaltNonce);
|
30
30
|
console.log(`
|
@@ -153,24 +153,20 @@ export class NearSafe {
|
|
153
153
|
* Warning: Uses a private ethRPC with sensitive Pimlico API key (should be run server side).
|
154
154
|
*
|
155
155
|
* @param {number} chainId - The ID of the EVM network to which the transaction should be broadcasted.
|
156
|
-
* @param {
|
156
|
+
* @param {Signature} signature - The valid signature of the unsignedUserOp.
|
157
157
|
* @param {UserOperation} unsignedUserOp - The unsigned user operation to be broadcasted. This includes transaction data such as the destination address and data payload.
|
158
|
-
* @returns {Promise<
|
158
|
+
* @returns {Promise<Hash>} - A promise that resolves hash of the executed user operation.
|
159
159
|
* @throws {Error} - Throws an error if the EVM broadcast fails, including the error message for debugging.
|
160
160
|
*/
|
161
|
-
async
|
162
|
-
const signature = packSignature(serializeSignature(signatureFromOutcome(outcome)));
|
161
|
+
async broadcastBundler(chainId, signatureHex, unsignedUserOp) {
|
163
162
|
try {
|
164
|
-
return {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
signature,
|
169
|
-
}),
|
170
|
-
};
|
163
|
+
return this.executeTransaction(chainId, {
|
164
|
+
...unsignedUserOp,
|
165
|
+
signature: packSignature(signatureHex),
|
166
|
+
});
|
171
167
|
}
|
172
168
|
catch (error) {
|
173
|
-
throw new Error(`Failed
|
169
|
+
throw new Error(`Failed Bundler broadcast: ${error instanceof Error ? error.message : String(error)}`);
|
174
170
|
}
|
175
171
|
}
|
176
172
|
/**
|
package/dist/esm/util.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { getNetworkId, Network, signatureFromTxHash as sigFromHash, } from "near-ca";
|
2
|
-
import { concatHex, encodePacked, toHex, isHex, parseTransaction, zeroAddress, toBytes, keccak256, serializeSignature, } from "viem";
|
2
|
+
import { concatHex, encodePacked, toHex, isHex, parseTransaction, zeroAddress, toBytes, keccak256, serializeSignature, createPublicClient, http, } from "viem";
|
3
|
+
import { DEFAULT_SETUP_RPC } from "./constants";
|
3
4
|
export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);
|
4
5
|
export const packGas = (hi, lo) => encodePacked(["uint128", "uint128"], [BigInt(hi), BigInt(lo)]);
|
5
6
|
export function packSignature(signature, validFrom = 0, validTo = 0) {
|
@@ -22,6 +23,10 @@ export async function isContract(address, chainId) {
|
|
22
23
|
return (await getClient(chainId).getCode({ address })) !== undefined;
|
23
24
|
}
|
24
25
|
export function getClient(chainId) {
|
26
|
+
// TODO(bh2smith)
|
27
|
+
if (chainId === 11155111) {
|
28
|
+
return createPublicClient({ transport: http(DEFAULT_SETUP_RPC) });
|
29
|
+
}
|
25
30
|
return Network.fromChainId(chainId).client;
|
26
31
|
}
|
27
32
|
export function metaTransactionsFromRequest(params) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "near-safe",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.6",
|
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,7 +42,6 @@
|
|
42
42
|
},
|
43
43
|
"dependencies": {
|
44
44
|
"@safe-global/safe-gateway-typescript-sdk": "^3.22.2",
|
45
|
-
"ethers-multisend": "^3.1.0",
|
46
45
|
"near-api-js": "^5.0.0",
|
47
46
|
"near-ca": "^0.6.0",
|
48
47
|
"semver": "^7.6.3",
|
@@ -61,6 +60,7 @@
|
|
61
60
|
"eslint": "^9.6.0",
|
62
61
|
"eslint-plugin-import": "^2.30.0",
|
63
62
|
"ethers": "^6.13.1",
|
63
|
+
"ethers-multisend": "^3.1.0",
|
64
64
|
"jest": "^29.7.0",
|
65
65
|
"prettier": "^3.3.2",
|
66
66
|
"ts-jest": "^29.1.5",
|