near-safe 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/tx-manager.d.ts +3 -5
- package/dist/cjs/tx-manager.js +20 -14
- package/dist/esm/tx-manager.d.ts +3 -5
- package/dist/esm/tx-manager.js +20 -14
- package/package.json +1 -1
package/dist/cjs/tx-manager.d.ts
CHANGED
@@ -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
|
-
|
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
|
-
|
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>;
|
package/dist/cjs/tx-manager.js
CHANGED
@@ -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
|
25
|
-
|
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([
|
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,
|
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
|
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
|
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
|
-
...
|
77
|
-
evmMessage: unsignedUserOp,
|
82
|
+
...signRequest,
|
83
|
+
evmMessage: JSON.stringify(unsignedUserOp),
|
78
84
|
};
|
79
85
|
}
|
80
86
|
async executeTransaction(userOp) {
|
package/dist/esm/tx-manager.d.ts
CHANGED
@@ -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
|
-
|
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
|
-
|
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>;
|
package/dist/esm/tx-manager.js
CHANGED
@@ -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
|
30
|
-
|
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([
|
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,
|
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
|
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
|
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
|
-
...
|
82
|
-
evmMessage: unsignedUserOp,
|
87
|
+
...signRequest,
|
88
|
+
evmMessage: JSON.stringify(unsignedUserOp),
|
83
89
|
};
|
84
90
|
}
|
85
91
|
async executeTransaction(userOp) {
|