near-safe 0.0.4 → 0.1.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.
@@ -1,10 +1,9 @@
1
1
  import { ethers } from "ethers";
2
- import { NearEthAdapter, NearEthTxData } from "near-ca";
2
+ import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
3
3
  import { Erc4337Bundler } from "./lib/bundler";
4
4
  import { UserOperation, UserOperationReceipt } from "./types";
5
5
  import { MetaTransaction } from "ethers-multisend";
6
6
  import { ContractSuite } from "./lib/safe";
7
- import { Account } from "near-api-js";
8
7
  export declare class TransactionManager {
9
8
  readonly provider: ethers.JsonRpcProvider;
10
9
  readonly nearAdapter: NearEthAdapter;
@@ -18,8 +17,7 @@ export declare class TransactionManager {
18
17
  static create(config: {
19
18
  ethRpc: string;
20
19
  erc4337BundlerUrl: string;
21
- nearAccount: Account;
22
- mpcContractId: string;
20
+ nearAdapter: NearEthAdapter;
23
21
  safeSaltNonce?: string;
24
22
  }): Promise<TransactionManager>;
25
23
  get safeNotDeployed(): boolean;
@@ -31,7 +29,7 @@ export declare class TransactionManager {
31
29
  }): Promise<UserOperation>;
32
30
  signTransaction(safeOpHash: string): Promise<string>;
33
31
  opHash(userOp: UserOperation): Promise<string>;
34
- encodeSignatureRequest(unsignedUserOp: UserOperation): Promise<NearEthTxData>;
32
+ encodeSignRequest(tx: BaseTx): Promise<NearEthTxData>;
35
33
  executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
36
34
  addOwnerTx(address: string): MetaTransaction;
37
35
  safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TransactionManager = void 0;
4
4
  const ethers_1 = require("ethers");
5
- const near_ca_1 = require("near-ca");
6
5
  const bundler_1 = require("./lib/bundler");
7
6
  const util_1 = require("./util");
8
7
  const near_1 = require("./lib/near");
@@ -20,20 +19,16 @@ class TransactionManager {
20
19
  this._safeNotDeployed = safeNotDeployed;
21
20
  }
22
21
  static async create(config) {
22
+ const adapter = config.nearAdapter;
23
23
  const provider = new ethers_1.ethers.JsonRpcProvider(config.ethRpc);
24
- const [nearAdapter, safePack] = await Promise.all([
25
- near_ca_1.NearEthAdapter.fromConfig({
26
- mpcContract: new near_ca_1.MpcContract(config.nearAccount, config.mpcContractId),
27
- }),
28
- safe_1.ContractSuite.init(provider),
29
- ]);
30
- console.log(`Near Adapter: ${nearAdapter.nearAccountId()} <> ${nearAdapter.address}`);
24
+ const safePack = await safe_1.ContractSuite.init(provider);
25
+ console.log(`Near Adapter: ${adapter.nearAccountId()} <> ${adapter.address}`);
31
26
  const bundler = new bundler_1.Erc4337Bundler(config.erc4337BundlerUrl, await safePack.entryPoint.getAddress());
32
- const setup = await safePack.getSetup([nearAdapter.address]);
27
+ const setup = await safePack.getSetup([adapter.address]);
33
28
  const safeAddress = await safePack.addressForSetup(setup, config.safeSaltNonce);
34
29
  const safeNotDeployed = (await provider.getCode(safeAddress)) === "0x";
35
30
  console.log(`Safe Address: ${safeAddress} - deployed? ${!safeNotDeployed}`);
36
- return new TransactionManager(provider, nearAdapter, safePack, bundler, setup, safeAddress, config.safeSaltNonce || "0", safeNotDeployed);
31
+ return new TransactionManager(provider, adapter, safePack, bundler, setup, safeAddress, config.safeSaltNonce || "0", safeNotDeployed);
37
32
  }
38
33
  get safeNotDeployed() {
39
34
  return this._safeNotDeployed;
@@ -65,16 +60,27 @@ class TransactionManager {
65
60
  async opHash(userOp) {
66
61
  return this.safePack.getOpHash(userOp);
67
62
  }
68
- async encodeSignatureRequest(unsignedUserOp) {
63
+ async encodeSignRequest(tx) {
64
+ // TODO - This is sloppy and ignores ChainId!
65
+ const unsignedUserOp = await this.buildTransaction({
66
+ transactions: [
67
+ {
68
+ to: tx.to,
69
+ value: (tx.value || 0n).toString(),
70
+ data: tx.data || "0x",
71
+ },
72
+ ],
73
+ usePaymaster: true,
74
+ });
69
75
  const safeOpHash = (await this.opHash(unsignedUserOp));
70
- const txData = this.nearAdapter.encodeSignRequest({
76
+ const signRequest = await this.nearAdapter.encodeSignRequest({
71
77
  method: "hash",
72
78
  chainId: 0,
73
79
  params: safeOpHash,
74
80
  });
75
81
  return {
76
- ...txData,
77
- evmMessage: unsignedUserOp,
82
+ ...signRequest,
83
+ evmMessage: JSON.stringify(unsignedUserOp),
78
84
  };
79
85
  }
80
86
  async executeTransaction(userOp) {
@@ -1,10 +1,9 @@
1
1
  import { ethers } from "ethers";
2
- import { NearEthAdapter, NearEthTxData } from "near-ca";
2
+ import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
3
3
  import { Erc4337Bundler } from "./lib/bundler";
4
4
  import { UserOperation, UserOperationReceipt } from "./types";
5
5
  import { MetaTransaction } from "ethers-multisend";
6
6
  import { ContractSuite } from "./lib/safe";
7
- import { Account } from "near-api-js";
8
7
  export declare class TransactionManager {
9
8
  readonly provider: ethers.JsonRpcProvider;
10
9
  readonly nearAdapter: NearEthAdapter;
@@ -18,8 +17,7 @@ export declare class TransactionManager {
18
17
  static create(config: {
19
18
  ethRpc: string;
20
19
  erc4337BundlerUrl: string;
21
- nearAccount: Account;
22
- mpcContractId: string;
20
+ nearAdapter: NearEthAdapter;
23
21
  safeSaltNonce?: string;
24
22
  }): Promise<TransactionManager>;
25
23
  get safeNotDeployed(): boolean;
@@ -31,7 +29,7 @@ export declare class TransactionManager {
31
29
  }): Promise<UserOperation>;
32
30
  signTransaction(safeOpHash: string): Promise<string>;
33
31
  opHash(userOp: UserOperation): Promise<string>;
34
- encodeSignatureRequest(unsignedUserOp: UserOperation): Promise<NearEthTxData>;
32
+ encodeSignRequest(tx: BaseTx): Promise<NearEthTxData>;
35
33
  executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
36
34
  addOwnerTx(address: string): MetaTransaction;
37
35
  safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
@@ -1,5 +1,4 @@
1
1
  import { ethers } from "ethers";
2
- import { NearEthAdapter, MpcContract } from "near-ca";
3
2
  import { Erc4337Bundler } from "./lib/bundler";
4
3
  import { packSignature } from "./util";
5
4
  import { getNearSignature } from "./lib/near";
@@ -25,20 +24,16 @@ export class TransactionManager {
25
24
  this._safeNotDeployed = safeNotDeployed;
26
25
  }
27
26
  static async create(config) {
27
+ const adapter = config.nearAdapter;
28
28
  const provider = new ethers.JsonRpcProvider(config.ethRpc);
29
- const [nearAdapter, safePack] = await Promise.all([
30
- NearEthAdapter.fromConfig({
31
- mpcContract: new MpcContract(config.nearAccount, config.mpcContractId),
32
- }),
33
- ContractSuite.init(provider),
34
- ]);
35
- console.log(`Near Adapter: ${nearAdapter.nearAccountId()} <> ${nearAdapter.address}`);
29
+ const safePack = await ContractSuite.init(provider);
30
+ console.log(`Near Adapter: ${adapter.nearAccountId()} <> ${adapter.address}`);
36
31
  const bundler = new Erc4337Bundler(config.erc4337BundlerUrl, await safePack.entryPoint.getAddress());
37
- const setup = await safePack.getSetup([nearAdapter.address]);
32
+ const setup = await safePack.getSetup([adapter.address]);
38
33
  const safeAddress = await safePack.addressForSetup(setup, config.safeSaltNonce);
39
34
  const safeNotDeployed = (await provider.getCode(safeAddress)) === "0x";
40
35
  console.log(`Safe Address: ${safeAddress} - deployed? ${!safeNotDeployed}`);
41
- return new TransactionManager(provider, nearAdapter, safePack, bundler, setup, safeAddress, config.safeSaltNonce || "0", safeNotDeployed);
36
+ return new TransactionManager(provider, adapter, safePack, bundler, setup, safeAddress, config.safeSaltNonce || "0", safeNotDeployed);
42
37
  }
43
38
  get safeNotDeployed() {
44
39
  return this._safeNotDeployed;
@@ -70,16 +65,27 @@ export class TransactionManager {
70
65
  async opHash(userOp) {
71
66
  return this.safePack.getOpHash(userOp);
72
67
  }
73
- async encodeSignatureRequest(unsignedUserOp) {
68
+ async encodeSignRequest(tx) {
69
+ // TODO - This is sloppy and ignores ChainId!
70
+ const unsignedUserOp = await this.buildTransaction({
71
+ transactions: [
72
+ {
73
+ to: tx.to,
74
+ value: (tx.value || 0n).toString(),
75
+ data: tx.data || "0x",
76
+ },
77
+ ],
78
+ usePaymaster: true,
79
+ });
74
80
  const safeOpHash = (await this.opHash(unsignedUserOp));
75
- const txData = this.nearAdapter.encodeSignRequest({
81
+ const signRequest = await this.nearAdapter.encodeSignRequest({
76
82
  method: "hash",
77
83
  chainId: 0,
78
84
  params: safeOpHash,
79
85
  });
80
86
  return {
81
- ...txData,
82
- evmMessage: unsignedUserOp,
87
+ ...signRequest,
88
+ evmMessage: JSON.stringify(unsignedUserOp),
83
89
  };
84
90
  }
85
91
  async executeTransaction(userOp) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "near-safe",
3
- "version": "0.0.4",
3
+ "version": "0.1.0",
4
4
  "license": "MIT",
5
5
  "description": "An SDK for controlling Ethereum Smart Accounts via ERC4337 from a Near Account.",
6
6
  "author": "bh2smith",