near-safe 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +5 -4
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/lib/bundler.d.ts +1 -1
- package/dist/cjs/lib/bundler.js +2 -2
- package/dist/cjs/lib/multisend.d.ts +3 -0
- package/dist/cjs/lib/multisend.js +40 -0
- package/dist/cjs/lib/safe.d.ts +1 -2
- package/dist/cjs/lib/safe.js +1 -1
- package/dist/cjs/tx-manager.d.ts +10 -4
- package/dist/cjs/tx-manager.js +24 -5
- package/dist/cjs/types.d.ts +10 -0
- package/dist/cjs/types.js +6 -0
- package/dist/cjs/util.d.ts +1 -2
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/lib/bundler.d.ts +1 -1
- package/dist/esm/lib/bundler.js +1 -1
- package/dist/esm/lib/multisend.d.ts +3 -0
- package/dist/esm/lib/multisend.js +36 -0
- package/dist/esm/lib/safe.d.ts +1 -2
- package/dist/esm/lib/safe.js +1 -1
- package/dist/esm/tx-manager.d.ts +10 -4
- package/dist/esm/tx-manager.js +24 -5
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/types.js +5 -1
- package/dist/esm/util.d.ts +1 -2
- package/package.json +3 -3
package/README.md
CHANGED
@@ -27,15 +27,16 @@ yarn install
|
|
27
27
|
Create a `.env` (or use our `.env.sample`) file in the root of the project and add the following environment variables:
|
28
28
|
|
29
29
|
```sh
|
30
|
-
ETH_RPC=https://rpc2.sepolia.org
|
31
|
-
|
32
30
|
NEAR_ACCOUNT_ID=
|
33
|
-
NEAR_ACCOUNT_PRIVATE_KEY=
|
34
|
-
|
35
31
|
# Head to https://www.pimlico.io/ for an API key
|
36
32
|
PIMLICO_KEY=
|
37
33
|
```
|
38
34
|
|
35
|
+
To use the CLI tool provided here in `examples/*` you will also need to provide a privateKey for your Near account.
|
36
|
+
|
37
|
+
```sh
|
38
|
+
NEAR_ACCOUNT_PRIVATE_KEY=
|
39
|
+
```
|
39
40
|
|
40
41
|
## Usage
|
41
42
|
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/index.js
CHANGED
@@ -14,6 +14,10 @@ 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.populateTx = exports.Network = void 0;
|
17
18
|
__exportStar(require("./tx-manager"), exports);
|
18
19
|
__exportStar(require("./types"), exports);
|
19
20
|
__exportStar(require("./util"), exports);
|
21
|
+
var near_ca_1 = require("near-ca");
|
22
|
+
Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return near_ca_1.Network; } });
|
23
|
+
Object.defineProperty(exports, "populateTx", { enumerable: true, get: function () { return near_ca_1.populateTx; } });
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrices, PaymasterData, UnsignedUserOperation, UserOperation, UserOperationReceipt } from "../types
|
2
|
+
import { GasPrices, PaymasterData, UnsignedUserOperation, UserOperation, UserOperationReceipt } from "../types";
|
3
3
|
export declare class Erc4337Bundler {
|
4
4
|
provider: ethers.JsonRpcProvider;
|
5
5
|
entryPointAddress: string;
|
package/dist/cjs/lib/bundler.js
CHANGED
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Erc4337Bundler = void 0;
|
4
4
|
// TODO: Ethers dependency is only for Generic HTTP Provider
|
5
5
|
const ethers_1 = require("ethers");
|
6
|
-
const util_js_1 = require("../util.js");
|
7
6
|
const viem_1 = require("viem");
|
7
|
+
const util_1 = require("../util");
|
8
8
|
function bundlerUrl(chainId, apikey) {
|
9
9
|
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=${apikey}`;
|
10
10
|
}
|
@@ -23,7 +23,7 @@ class Erc4337Bundler {
|
|
23
23
|
if (usePaymaster) {
|
24
24
|
console.log("Requesting paymaster data...");
|
25
25
|
const data = this.provider.send("pm_sponsorUserOperation", [
|
26
|
-
{ ...rawUserOp, signature:
|
26
|
+
{ ...rawUserOp, signature: util_1.PLACEHOLDER_SIG },
|
27
27
|
this.entryPointAddress,
|
28
28
|
]);
|
29
29
|
return data;
|
@@ -0,0 +1,40 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.MULTI_SEND_ABI = void 0;
|
4
|
+
exports.encodeMulti = encodeMulti;
|
5
|
+
const viem_1 = require("viem");
|
6
|
+
const types_1 = require("../types");
|
7
|
+
exports.MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
8
|
+
const MULTISEND_141 = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526";
|
9
|
+
const MULTISEND_CALLONLY_141 = "0x9641d764fc13c8B624c04430C7356C1C7C8102e2";
|
10
|
+
/// Encodes the transaction as packed bytes of:
|
11
|
+
/// - `operation` as a `uint8` with `0` for a `call` or `1` for a `delegatecall` (=> 1 byte),
|
12
|
+
/// - `to` as an `address` (=> 20 bytes),
|
13
|
+
/// - `value` as a `uint256` (=> 32 bytes),
|
14
|
+
/// - length of `data` as a `uint256` (=> 32 bytes),
|
15
|
+
/// - `data` as `bytes`.
|
16
|
+
const encodeMetaTx = (tx) => (0, viem_1.encodePacked)(["uint8", "address", "uint256", "uint256", "bytes"], [
|
17
|
+
tx.operation || types_1.OperationType.Call,
|
18
|
+
tx.to,
|
19
|
+
BigInt(tx.value),
|
20
|
+
BigInt((0, viem_1.size)(tx.data)),
|
21
|
+
tx.data,
|
22
|
+
]);
|
23
|
+
const remove0x = (hexString) => hexString.slice(2);
|
24
|
+
// Encodes a batch of module transactions into a single multiSend module transaction.
|
25
|
+
// A module transaction is an object with fields corresponding to a Gnosis Safe's (i.e., Zodiac IAvatar's) `execTransactionFromModule` method parameters.
|
26
|
+
function encodeMulti(transactions, multiSendContractAddress = transactions.some((t) => t.operation === types_1.OperationType.DelegateCall)
|
27
|
+
? MULTISEND_141
|
28
|
+
: MULTISEND_CALLONLY_141) {
|
29
|
+
const encodedTransactions = "0x" + transactions.map(encodeMetaTx).map(remove0x).join("");
|
30
|
+
return {
|
31
|
+
operation: types_1.OperationType.DelegateCall,
|
32
|
+
to: multiSendContractAddress,
|
33
|
+
value: "0x00",
|
34
|
+
data: (0, viem_1.encodeFunctionData)({
|
35
|
+
abi: (0, viem_1.parseAbi)(exports.MULTI_SEND_ABI),
|
36
|
+
functionName: "multiSend",
|
37
|
+
args: [encodedTransactions],
|
38
|
+
}),
|
39
|
+
};
|
40
|
+
}
|
package/dist/cjs/lib/safe.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
|
3
|
-
import { MetaTransaction } from "ethers-multisend";
|
4
2
|
import { Address, Hash, Hex } from "viem";
|
3
|
+
import { GasPrice, MetaTransaction, UnsignedUserOperation, UserOperation } from "../types";
|
5
4
|
/**
|
6
5
|
* All contracts used in account creation & execution
|
7
6
|
*/
|
package/dist/cjs/lib/safe.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.ContractSuite = void 0;
|
4
|
-
const ethers_1 = require("ethers");
|
5
4
|
const safe_deployments_1 = require("@safe-global/safe-deployments");
|
6
5
|
const safe_modules_deployments_1 = require("@safe-global/safe-modules-deployments");
|
6
|
+
const ethers_1 = require("ethers");
|
7
7
|
const util_1 = require("../util");
|
8
8
|
/**
|
9
9
|
* All contracts used in account creation & execution
|
package/dist/cjs/tx-manager.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
1
2
|
import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
|
3
|
+
import { Address, Hash, Hex } from "viem";
|
2
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
3
|
-
import { UserOperation, UserOperationReceipt } from "./types";
|
4
|
-
import { MetaTransaction } from "ethers-multisend";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
-
import {
|
6
|
+
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export declare class TransactionManager {
|
8
8
|
readonly nearAdapter: NearEthAdapter;
|
9
9
|
readonly address: Address;
|
@@ -15,8 +15,10 @@ export declare class TransactionManager {
|
|
15
15
|
private deployedChains;
|
16
16
|
constructor(nearAdapter: NearEthAdapter, safePack: ContractSuite, pimlicoKey: string, setup: string, safeAddress: Address, entryPointAddress: Address, safeSaltNonce: string);
|
17
17
|
static create(config: {
|
18
|
+
accountId: string;
|
19
|
+
mpcContractId: string;
|
18
20
|
pimlicoKey: string;
|
19
|
-
|
21
|
+
privateKey?: string;
|
20
22
|
safeSaltNonce?: string;
|
21
23
|
}): Promise<TransactionManager>;
|
22
24
|
get mpcAddress(): Address;
|
@@ -34,4 +36,8 @@ export declare class TransactionManager {
|
|
34
36
|
safeDeployed(chainId: number): Promise<boolean>;
|
35
37
|
addOwnerTx(address: string): MetaTransaction;
|
36
38
|
safeSufficientlyFunded(chainId: number, transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
39
|
+
broadcastEvm(chainId: number, outcome: FinalExecutionOutcome, unsignedUserOp: UserOperation): Promise<{
|
40
|
+
signature: Hex;
|
41
|
+
receipt: UserOperationReceipt;
|
42
|
+
}>;
|
37
43
|
}
|
package/dist/cjs/tx-manager.js
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.TransactionManager = void 0;
|
4
4
|
const near_ca_1 = require("near-ca");
|
5
|
+
const viem_1 = require("viem");
|
5
6
|
const bundler_1 = require("./lib/bundler");
|
6
|
-
const
|
7
|
-
const ethers_multisend_1 = require("ethers-multisend");
|
7
|
+
const multisend_1 = require("./lib/multisend");
|
8
8
|
const safe_1 = require("./lib/safe");
|
9
|
+
const util_1 = require("./util");
|
9
10
|
class TransactionManager {
|
10
11
|
constructor(nearAdapter, safePack, pimlicoKey, setup, safeAddress, entryPointAddress, safeSaltNonce) {
|
11
12
|
this.nearAdapter = nearAdapter;
|
@@ -18,8 +19,11 @@ class TransactionManager {
|
|
18
19
|
this.deployedChains = new Set();
|
19
20
|
}
|
20
21
|
static async create(config) {
|
21
|
-
const {
|
22
|
-
const safePack = await
|
22
|
+
const { pimlicoKey } = config;
|
23
|
+
const [nearAdapter, safePack] = await Promise.all([
|
24
|
+
(0, near_ca_1.setupAdapter)({ ...config }),
|
25
|
+
safe_1.ContractSuite.init(),
|
26
|
+
]);
|
23
27
|
console.log(`Near Adapter: ${nearAdapter.nearAccountId()} <> ${nearAdapter.address}`);
|
24
28
|
const setup = await safePack.getSetup([nearAdapter.address]);
|
25
29
|
const safeAddress = await safePack.addressForSetup(setup, config.safeSaltNonce);
|
@@ -45,7 +49,7 @@ class TransactionManager {
|
|
45
49
|
if (transactions.length === 0) {
|
46
50
|
throw new Error("Empty transaction set!");
|
47
51
|
}
|
48
|
-
const tx = transactions.length > 1 ? (0,
|
52
|
+
const tx = transactions.length > 1 ? (0, multisend_1.encodeMulti)(transactions) : transactions[0];
|
49
53
|
const safeNotDeployed = !(await this.safeDeployed(chainId));
|
50
54
|
const rawUserOp = await this.safePack.buildUserOp(tx, this.address, gasFees, this.setup, safeNotDeployed, this.safeSaltNonce);
|
51
55
|
const paymasterData = await bundler.getPaymasterData(rawUserOp, usePaymaster, safeNotDeployed);
|
@@ -118,5 +122,20 @@ class TransactionManager {
|
|
118
122
|
const safeBalance = await this.getBalance(chainId);
|
119
123
|
return txValue + gasCost < safeBalance;
|
120
124
|
}
|
125
|
+
async broadcastEvm(chainId, outcome, unsignedUserOp) {
|
126
|
+
const signature = (0, util_1.packSignature)((0, viem_1.serializeSignature)((0, near_ca_1.signatureFromOutcome)(outcome)));
|
127
|
+
try {
|
128
|
+
return {
|
129
|
+
signature,
|
130
|
+
receipt: await this.executeTransaction(chainId, {
|
131
|
+
...unsignedUserOp,
|
132
|
+
signature,
|
133
|
+
}),
|
134
|
+
};
|
135
|
+
}
|
136
|
+
catch (error) {
|
137
|
+
throw new Error(`Failed EVM broadcast: ${error instanceof Error ? error.message : String(error)}`);
|
138
|
+
}
|
139
|
+
}
|
121
140
|
}
|
122
141
|
exports.TransactionManager = TransactionManager;
|
package/dist/cjs/types.d.ts
CHANGED
@@ -79,4 +79,14 @@ export interface GasPrice {
|
|
79
79
|
maxFeePerGas: Hex;
|
80
80
|
maxPriorityFeePerGas: Hex;
|
81
81
|
}
|
82
|
+
export declare enum OperationType {
|
83
|
+
Call = 0,
|
84
|
+
DelegateCall = 1
|
85
|
+
}
|
86
|
+
export interface MetaTransaction {
|
87
|
+
readonly to: string;
|
88
|
+
readonly value: string;
|
89
|
+
readonly data: string;
|
90
|
+
readonly operation?: OperationType;
|
91
|
+
}
|
82
92
|
export {};
|
package/dist/cjs/types.js
CHANGED
@@ -1,2 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.OperationType = void 0;
|
4
|
+
var OperationType;
|
5
|
+
(function (OperationType) {
|
6
|
+
OperationType[OperationType["Call"] = 0] = "Call";
|
7
|
+
OperationType[OperationType["DelegateCall"] = 1] = "DelegateCall";
|
8
|
+
})(OperationType || (exports.OperationType = OperationType = {}));
|
package/dist/cjs/util.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import { PaymasterData } from "./types.js";
|
2
|
-
import { MetaTransaction } from "ethers-multisend";
|
3
1
|
import { Hex } from "viem";
|
2
|
+
import { PaymasterData, MetaTransaction } from "./types";
|
4
3
|
export declare const PLACEHOLDER_SIG: `0x${string}`;
|
5
4
|
type IntLike = Hex | bigint | string | number;
|
6
5
|
export declare const packGas: (hi: IntLike, lo: IntLike) => string;
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrices, PaymasterData, UnsignedUserOperation, UserOperation, UserOperationReceipt } from "../types
|
2
|
+
import { GasPrices, PaymasterData, UnsignedUserOperation, UserOperation, UserOperationReceipt } from "../types";
|
3
3
|
export declare class Erc4337Bundler {
|
4
4
|
provider: ethers.JsonRpcProvider;
|
5
5
|
entryPointAddress: string;
|
package/dist/esm/lib/bundler.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
// TODO: Ethers dependency is only for Generic HTTP Provider
|
2
2
|
import { ethers } from "ethers";
|
3
|
-
import { PLACEHOLDER_SIG } from "../util.js";
|
4
3
|
import { toHex } from "viem";
|
4
|
+
import { PLACEHOLDER_SIG } from "../util";
|
5
5
|
function bundlerUrl(chainId, apikey) {
|
6
6
|
return `https://api.pimlico.io/v2/${chainId}/rpc?apikey=${apikey}`;
|
7
7
|
}
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { encodeFunctionData, encodePacked, parseAbi, size, } from "viem";
|
2
|
+
import { OperationType } from "../types";
|
3
|
+
export const MULTI_SEND_ABI = ["function multiSend(bytes memory transactions)"];
|
4
|
+
const MULTISEND_141 = "0x38869bf66a61cF6bDB996A6aE40D5853Fd43B526";
|
5
|
+
const MULTISEND_CALLONLY_141 = "0x9641d764fc13c8B624c04430C7356C1C7C8102e2";
|
6
|
+
/// Encodes the transaction as packed bytes of:
|
7
|
+
/// - `operation` as a `uint8` with `0` for a `call` or `1` for a `delegatecall` (=> 1 byte),
|
8
|
+
/// - `to` as an `address` (=> 20 bytes),
|
9
|
+
/// - `value` as a `uint256` (=> 32 bytes),
|
10
|
+
/// - length of `data` as a `uint256` (=> 32 bytes),
|
11
|
+
/// - `data` as `bytes`.
|
12
|
+
const encodeMetaTx = (tx) => encodePacked(["uint8", "address", "uint256", "uint256", "bytes"], [
|
13
|
+
tx.operation || OperationType.Call,
|
14
|
+
tx.to,
|
15
|
+
BigInt(tx.value),
|
16
|
+
BigInt(size(tx.data)),
|
17
|
+
tx.data,
|
18
|
+
]);
|
19
|
+
const remove0x = (hexString) => hexString.slice(2);
|
20
|
+
// Encodes a batch of module transactions into a single multiSend module transaction.
|
21
|
+
// A module transaction is an object with fields corresponding to a Gnosis Safe's (i.e., Zodiac IAvatar's) `execTransactionFromModule` method parameters.
|
22
|
+
export function encodeMulti(transactions, multiSendContractAddress = transactions.some((t) => t.operation === OperationType.DelegateCall)
|
23
|
+
? MULTISEND_141
|
24
|
+
: MULTISEND_CALLONLY_141) {
|
25
|
+
const encodedTransactions = "0x" + transactions.map(encodeMetaTx).map(remove0x).join("");
|
26
|
+
return {
|
27
|
+
operation: OperationType.DelegateCall,
|
28
|
+
to: multiSendContractAddress,
|
29
|
+
value: "0x00",
|
30
|
+
data: encodeFunctionData({
|
31
|
+
abi: parseAbi(MULTI_SEND_ABI),
|
32
|
+
functionName: "multiSend",
|
33
|
+
args: [encodedTransactions],
|
34
|
+
}),
|
35
|
+
};
|
36
|
+
}
|
package/dist/esm/lib/safe.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
|
3
|
-
import { MetaTransaction } from "ethers-multisend";
|
4
2
|
import { Address, Hash, Hex } from "viem";
|
3
|
+
import { GasPrice, MetaTransaction, UnsignedUserOperation, UserOperation } from "../types";
|
5
4
|
/**
|
6
5
|
* All contracts used in account creation & execution
|
7
6
|
*/
|
package/dist/esm/lib/safe.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { ethers } from "ethers";
|
2
1
|
import { getProxyFactoryDeployment, getSafeL2SingletonDeployment, } from "@safe-global/safe-deployments";
|
3
2
|
import { getSafe4337ModuleDeployment, getSafeModuleSetupDeployment, } from "@safe-global/safe-modules-deployments";
|
3
|
+
import { ethers } from "ethers";
|
4
4
|
import { PLACEHOLDER_SIG, packGas, packPaymasterData } from "../util";
|
5
5
|
/**
|
6
6
|
* All contracts used in account creation & execution
|
package/dist/esm/tx-manager.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
+
import { FinalExecutionOutcome } from "near-api-js/lib/providers";
|
1
2
|
import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
|
3
|
+
import { Address, Hash, Hex } from "viem";
|
2
4
|
import { Erc4337Bundler } from "./lib/bundler";
|
3
|
-
import { UserOperation, UserOperationReceipt } from "./types";
|
4
|
-
import { MetaTransaction } from "ethers-multisend";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
-
import {
|
6
|
+
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
|
7
7
|
export declare class TransactionManager {
|
8
8
|
readonly nearAdapter: NearEthAdapter;
|
9
9
|
readonly address: Address;
|
@@ -15,8 +15,10 @@ export declare class TransactionManager {
|
|
15
15
|
private deployedChains;
|
16
16
|
constructor(nearAdapter: NearEthAdapter, safePack: ContractSuite, pimlicoKey: string, setup: string, safeAddress: Address, entryPointAddress: Address, safeSaltNonce: string);
|
17
17
|
static create(config: {
|
18
|
+
accountId: string;
|
19
|
+
mpcContractId: string;
|
18
20
|
pimlicoKey: string;
|
19
|
-
|
21
|
+
privateKey?: string;
|
20
22
|
safeSaltNonce?: string;
|
21
23
|
}): Promise<TransactionManager>;
|
22
24
|
get mpcAddress(): Address;
|
@@ -34,4 +36,8 @@ export declare class TransactionManager {
|
|
34
36
|
safeDeployed(chainId: number): Promise<boolean>;
|
35
37
|
addOwnerTx(address: string): MetaTransaction;
|
36
38
|
safeSufficientlyFunded(chainId: number, transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
39
|
+
broadcastEvm(chainId: number, outcome: FinalExecutionOutcome, unsignedUserOp: UserOperation): Promise<{
|
40
|
+
signature: Hex;
|
41
|
+
receipt: UserOperationReceipt;
|
42
|
+
}>;
|
37
43
|
}
|
package/dist/esm/tx-manager.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Network } from "near-ca";
|
1
|
+
import { Network, setupAdapter, signatureFromOutcome, } from "near-ca";
|
2
|
+
import { serializeSignature } from "viem";
|
2
3
|
import { Erc4337Bundler } from "./lib/bundler";
|
3
|
-
import {
|
4
|
-
import { encodeMulti } from "ethers-multisend";
|
4
|
+
import { encodeMulti } from "./lib/multisend";
|
5
5
|
import { ContractSuite } from "./lib/safe";
|
6
|
+
import { packSignature } from "./util";
|
6
7
|
export class TransactionManager {
|
7
8
|
nearAdapter;
|
8
9
|
address;
|
@@ -23,8 +24,11 @@ export class TransactionManager {
|
|
23
24
|
this.deployedChains = new Set();
|
24
25
|
}
|
25
26
|
static async create(config) {
|
26
|
-
const {
|
27
|
-
const safePack = await
|
27
|
+
const { pimlicoKey } = config;
|
28
|
+
const [nearAdapter, safePack] = await Promise.all([
|
29
|
+
setupAdapter({ ...config }),
|
30
|
+
ContractSuite.init(),
|
31
|
+
]);
|
28
32
|
console.log(`Near Adapter: ${nearAdapter.nearAccountId()} <> ${nearAdapter.address}`);
|
29
33
|
const setup = await safePack.getSetup([nearAdapter.address]);
|
30
34
|
const safeAddress = await safePack.addressForSetup(setup, config.safeSaltNonce);
|
@@ -123,4 +127,19 @@ export class TransactionManager {
|
|
123
127
|
const safeBalance = await this.getBalance(chainId);
|
124
128
|
return txValue + gasCost < safeBalance;
|
125
129
|
}
|
130
|
+
async broadcastEvm(chainId, outcome, unsignedUserOp) {
|
131
|
+
const signature = packSignature(serializeSignature(signatureFromOutcome(outcome)));
|
132
|
+
try {
|
133
|
+
return {
|
134
|
+
signature,
|
135
|
+
receipt: await this.executeTransaction(chainId, {
|
136
|
+
...unsignedUserOp,
|
137
|
+
signature,
|
138
|
+
}),
|
139
|
+
};
|
140
|
+
}
|
141
|
+
catch (error) {
|
142
|
+
throw new Error(`Failed EVM broadcast: ${error instanceof Error ? error.message : String(error)}`);
|
143
|
+
}
|
144
|
+
}
|
126
145
|
}
|
package/dist/esm/types.d.ts
CHANGED
@@ -79,4 +79,14 @@ export interface GasPrice {
|
|
79
79
|
maxFeePerGas: Hex;
|
80
80
|
maxPriorityFeePerGas: Hex;
|
81
81
|
}
|
82
|
+
export declare enum OperationType {
|
83
|
+
Call = 0,
|
84
|
+
DelegateCall = 1
|
85
|
+
}
|
86
|
+
export interface MetaTransaction {
|
87
|
+
readonly to: string;
|
88
|
+
readonly value: string;
|
89
|
+
readonly data: string;
|
90
|
+
readonly operation?: OperationType;
|
91
|
+
}
|
82
92
|
export {};
|
package/dist/esm/types.js
CHANGED
package/dist/esm/util.d.ts
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
import { PaymasterData } from "./types.js";
|
2
|
-
import { MetaTransaction } from "ethers-multisend";
|
3
1
|
import { Hex } from "viem";
|
2
|
+
import { PaymasterData, MetaTransaction } from "./types";
|
4
3
|
export declare const PLACEHOLDER_SIG: `0x${string}`;
|
5
4
|
type IntLike = Hex | bigint | string | number;
|
6
5
|
export declare const packGas: (hi: IntLike, lo: IntLike) => string;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "near-safe",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.1",
|
4
4
|
"license": "MIT",
|
5
5
|
"description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
|
6
6
|
"author": "bh2smith",
|
@@ -36,14 +36,13 @@
|
|
36
36
|
"example": "tsx examples/send-tx.ts",
|
37
37
|
"lint": "eslint . --ignore-pattern dist/",
|
38
38
|
"test": "jest",
|
39
|
-
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}'",
|
39
|
+
"fmt": "prettier --write '{src,examples,tests}/**/*.{js,jsx,ts,tsx}' && yarn lint --fix",
|
40
40
|
"all": "yarn fmt && yarn lint && yarn build"
|
41
41
|
},
|
42
42
|
"dependencies": {
|
43
43
|
"@safe-global/safe-deployments": "^1.37.0",
|
44
44
|
"@safe-global/safe-modules-deployments": "^2.2.0",
|
45
45
|
"ethers": "^6.13.1",
|
46
|
-
"ethers-multisend": "^3.1.0",
|
47
46
|
"near-api-js": "^5.0.0",
|
48
47
|
"near-ca": "^0.5.2",
|
49
48
|
"viem": "^2.16.5",
|
@@ -57,6 +56,7 @@
|
|
57
56
|
"@typescript-eslint/parser": "^8.1.0",
|
58
57
|
"dotenv": "^16.4.5",
|
59
58
|
"eslint": "^9.6.0",
|
59
|
+
"eslint-plugin-import": "^2.30.0",
|
60
60
|
"jest": "^29.7.0",
|
61
61
|
"prettier": "^3.3.2",
|
62
62
|
"ts-jest": "^29.1.5",
|