near-safe 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/lib/safe.d.ts +2 -2
- package/dist/cjs/lib/safe.js +4 -2
- package/dist/cjs/tx-manager.d.ts +6 -7
- package/dist/cjs/tx-manager.js +29 -7
- package/dist/esm/lib/safe.d.ts +2 -2
- package/dist/esm/lib/safe.js +4 -2
- package/dist/esm/tx-manager.d.ts +6 -7
- package/dist/esm/tx-manager.js +29 -7
- package/package.json +1 -1
package/dist/cjs/lib/safe.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrice,
|
2
|
+
import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
|
3
3
|
import { MetaTransaction } from "ethers-multisend";
|
4
4
|
/**
|
5
5
|
* All contracts used in account creation & execution
|
@@ -15,7 +15,7 @@ export declare class ContractSuite {
|
|
15
15
|
static init(provider: ethers.JsonRpcProvider): Promise<ContractSuite>;
|
16
16
|
addressForSetup(setup: ethers.BytesLike, saltNonce?: string): Promise<string>;
|
17
17
|
getSetup(owners: string[]): Promise<string>;
|
18
|
-
getOpHash(unsignedUserOp: UserOperation
|
18
|
+
getOpHash(unsignedUserOp: UserOperation): Promise<string>;
|
19
19
|
factoryDataForSetup(safeNotDeployed: boolean, setup: string, safeSaltNonce: string): {
|
20
20
|
factory?: ethers.AddressLike;
|
21
21
|
factoryData?: string;
|
package/dist/cjs/lib/safe.js
CHANGED
@@ -58,7 +58,9 @@ class ContractSuite {
|
|
58
58
|
]);
|
59
59
|
return setup;
|
60
60
|
}
|
61
|
-
async getOpHash(unsignedUserOp
|
61
|
+
async getOpHash(unsignedUserOp
|
62
|
+
// paymasterData: PaymasterData
|
63
|
+
) {
|
62
64
|
return this.m4337.getOperationHash({
|
63
65
|
...unsignedUserOp,
|
64
66
|
initCode: unsignedUserOp.factory
|
@@ -66,7 +68,7 @@ class ContractSuite {
|
|
66
68
|
: "0x",
|
67
69
|
accountGasLimits: (0, util_1.packGas)(unsignedUserOp.verificationGasLimit, unsignedUserOp.callGasLimit),
|
68
70
|
gasFees: (0, util_1.packGas)(unsignedUserOp.maxPriorityFeePerGas, unsignedUserOp.maxFeePerGas),
|
69
|
-
paymasterAndData: (0, util_1.packPaymasterData)(
|
71
|
+
paymasterAndData: (0, util_1.packPaymasterData)(unsignedUserOp),
|
70
72
|
signature: util_1.PLACEHOLDER_SIG,
|
71
73
|
});
|
72
74
|
}
|
package/dist/cjs/tx-manager.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { NearEthAdapter } from "near-ca";
|
2
|
+
import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
|
3
3
|
import { Erc4337Bundler } from "./lib/bundler";
|
4
|
-
import { UserOperation, UserOperationReceipt
|
4
|
+
import { UserOperation, UserOperationReceipt } from "./types";
|
5
5
|
import { MetaTransaction } from "ethers-multisend";
|
6
6
|
import { ContractSuite } from "./lib/safe";
|
7
7
|
import { Account } from "near-api-js";
|
@@ -27,12 +27,11 @@ export declare class TransactionManager {
|
|
27
27
|
getSafeBalance(): Promise<bigint>;
|
28
28
|
buildTransaction(args: {
|
29
29
|
transactions: MetaTransaction[];
|
30
|
-
|
31
|
-
}): Promise<
|
32
|
-
safeOpHash: string;
|
33
|
-
unsignedUserOp: UserOperation;
|
34
|
-
}>;
|
30
|
+
usePaymaster: boolean;
|
31
|
+
}): Promise<UserOperation>;
|
35
32
|
signTransaction(safeOpHash: string): Promise<string>;
|
33
|
+
opHash(userOp: UserOperation): Promise<string>;
|
34
|
+
encodeSignRequest(tx: BaseTx): Promise<NearEthTxData>;
|
36
35
|
executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
|
37
36
|
addOwnerTx(address: string): MetaTransaction;
|
38
37
|
safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
package/dist/cjs/tx-manager.js
CHANGED
@@ -45,7 +45,7 @@ class TransactionManager {
|
|
45
45
|
return await this.provider.getBalance(this.safeAddress);
|
46
46
|
}
|
47
47
|
async buildTransaction(args) {
|
48
|
-
const { transactions,
|
48
|
+
const { transactions, usePaymaster } = args;
|
49
49
|
const gasFees = (await this.bundler.getGasPrice()).fast;
|
50
50
|
// const gasFees = await this.provider.getFeeData();
|
51
51
|
// Build Singular MetaTransaction for Multisend from transaction list.
|
@@ -54,18 +54,40 @@ class TransactionManager {
|
|
54
54
|
}
|
55
55
|
const tx = transactions.length > 1 ? (0, ethers_multisend_1.encodeMulti)(transactions) : transactions[0];
|
56
56
|
const rawUserOp = await this.safePack.buildUserOp(tx, this.safeAddress, gasFees, this.setup, this.safeNotDeployed, this.safeSaltNonce);
|
57
|
-
const paymasterData = await this.bundler.getPaymasterData(rawUserOp,
|
57
|
+
const paymasterData = await this.bundler.getPaymasterData(rawUserOp, usePaymaster, this.safeNotDeployed);
|
58
58
|
const unsignedUserOp = { ...rawUserOp, ...paymasterData };
|
59
|
-
|
60
|
-
return {
|
61
|
-
safeOpHash,
|
62
|
-
unsignedUserOp,
|
63
|
-
};
|
59
|
+
return unsignedUserOp;
|
64
60
|
}
|
65
61
|
async signTransaction(safeOpHash) {
|
66
62
|
const signature = await (0, near_1.getNearSignature)(this.nearAdapter, safeOpHash);
|
67
63
|
return (0, util_1.packSignature)(signature);
|
68
64
|
}
|
65
|
+
async opHash(userOp) {
|
66
|
+
return this.safePack.getOpHash(userOp);
|
67
|
+
}
|
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
|
+
});
|
80
|
+
const safeOpHash = (await this.opHash(unsignedUserOp));
|
81
|
+
const signRequest = await this.nearAdapter.encodeSignRequest({
|
82
|
+
method: "hash",
|
83
|
+
chainId: 0,
|
84
|
+
params: safeOpHash,
|
85
|
+
});
|
86
|
+
return {
|
87
|
+
...signRequest,
|
88
|
+
evmMessage: JSON.stringify(unsignedUserOp),
|
89
|
+
};
|
90
|
+
}
|
69
91
|
async executeTransaction(userOp) {
|
70
92
|
const userOpHash = await this.bundler.sendUserOperation(userOp);
|
71
93
|
console.log("UserOp Hash", userOpHash);
|
package/dist/esm/lib/safe.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { GasPrice,
|
2
|
+
import { GasPrice, UnsignedUserOperation, UserOperation } from "../types";
|
3
3
|
import { MetaTransaction } from "ethers-multisend";
|
4
4
|
/**
|
5
5
|
* All contracts used in account creation & execution
|
@@ -15,7 +15,7 @@ export declare class ContractSuite {
|
|
15
15
|
static init(provider: ethers.JsonRpcProvider): Promise<ContractSuite>;
|
16
16
|
addressForSetup(setup: ethers.BytesLike, saltNonce?: string): Promise<string>;
|
17
17
|
getSetup(owners: string[]): Promise<string>;
|
18
|
-
getOpHash(unsignedUserOp: UserOperation
|
18
|
+
getOpHash(unsignedUserOp: UserOperation): Promise<string>;
|
19
19
|
factoryDataForSetup(safeNotDeployed: boolean, setup: string, safeSaltNonce: string): {
|
20
20
|
factory?: ethers.AddressLike;
|
21
21
|
factoryData?: string;
|
package/dist/esm/lib/safe.js
CHANGED
@@ -61,7 +61,9 @@ export class ContractSuite {
|
|
61
61
|
]);
|
62
62
|
return setup;
|
63
63
|
}
|
64
|
-
async getOpHash(unsignedUserOp
|
64
|
+
async getOpHash(unsignedUserOp
|
65
|
+
// paymasterData: PaymasterData
|
66
|
+
) {
|
65
67
|
return this.m4337.getOperationHash({
|
66
68
|
...unsignedUserOp,
|
67
69
|
initCode: unsignedUserOp.factory
|
@@ -69,7 +71,7 @@ export class ContractSuite {
|
|
69
71
|
: "0x",
|
70
72
|
accountGasLimits: packGas(unsignedUserOp.verificationGasLimit, unsignedUserOp.callGasLimit),
|
71
73
|
gasFees: packGas(unsignedUserOp.maxPriorityFeePerGas, unsignedUserOp.maxFeePerGas),
|
72
|
-
paymasterAndData: packPaymasterData(
|
74
|
+
paymasterAndData: packPaymasterData(unsignedUserOp),
|
73
75
|
signature: PLACEHOLDER_SIG,
|
74
76
|
});
|
75
77
|
}
|
package/dist/esm/tx-manager.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { ethers } from "ethers";
|
2
|
-
import { NearEthAdapter } from "near-ca";
|
2
|
+
import { NearEthAdapter, NearEthTxData, BaseTx } from "near-ca";
|
3
3
|
import { Erc4337Bundler } from "./lib/bundler";
|
4
|
-
import { UserOperation, UserOperationReceipt
|
4
|
+
import { UserOperation, UserOperationReceipt } from "./types";
|
5
5
|
import { MetaTransaction } from "ethers-multisend";
|
6
6
|
import { ContractSuite } from "./lib/safe";
|
7
7
|
import { Account } from "near-api-js";
|
@@ -27,12 +27,11 @@ export declare class TransactionManager {
|
|
27
27
|
getSafeBalance(): Promise<bigint>;
|
28
28
|
buildTransaction(args: {
|
29
29
|
transactions: MetaTransaction[];
|
30
|
-
|
31
|
-
}): Promise<
|
32
|
-
safeOpHash: string;
|
33
|
-
unsignedUserOp: UserOperation;
|
34
|
-
}>;
|
30
|
+
usePaymaster: boolean;
|
31
|
+
}): Promise<UserOperation>;
|
35
32
|
signTransaction(safeOpHash: string): Promise<string>;
|
33
|
+
opHash(userOp: UserOperation): Promise<string>;
|
34
|
+
encodeSignRequest(tx: BaseTx): Promise<NearEthTxData>;
|
36
35
|
executeTransaction(userOp: UserOperation): Promise<UserOperationReceipt>;
|
37
36
|
addOwnerTx(address: string): MetaTransaction;
|
38
37
|
safeSufficientlyFunded(transactions: MetaTransaction[], gasCost: bigint): Promise<boolean>;
|
package/dist/esm/tx-manager.js
CHANGED
@@ -50,7 +50,7 @@ export class TransactionManager {
|
|
50
50
|
return await this.provider.getBalance(this.safeAddress);
|
51
51
|
}
|
52
52
|
async buildTransaction(args) {
|
53
|
-
const { transactions,
|
53
|
+
const { transactions, usePaymaster } = args;
|
54
54
|
const gasFees = (await this.bundler.getGasPrice()).fast;
|
55
55
|
// const gasFees = await this.provider.getFeeData();
|
56
56
|
// Build Singular MetaTransaction for Multisend from transaction list.
|
@@ -59,18 +59,40 @@ export class TransactionManager {
|
|
59
59
|
}
|
60
60
|
const tx = transactions.length > 1 ? encodeMulti(transactions) : transactions[0];
|
61
61
|
const rawUserOp = await this.safePack.buildUserOp(tx, this.safeAddress, gasFees, this.setup, this.safeNotDeployed, this.safeSaltNonce);
|
62
|
-
const paymasterData = await this.bundler.getPaymasterData(rawUserOp,
|
62
|
+
const paymasterData = await this.bundler.getPaymasterData(rawUserOp, usePaymaster, this.safeNotDeployed);
|
63
63
|
const unsignedUserOp = { ...rawUserOp, ...paymasterData };
|
64
|
-
|
65
|
-
return {
|
66
|
-
safeOpHash,
|
67
|
-
unsignedUserOp,
|
68
|
-
};
|
64
|
+
return unsignedUserOp;
|
69
65
|
}
|
70
66
|
async signTransaction(safeOpHash) {
|
71
67
|
const signature = await getNearSignature(this.nearAdapter, safeOpHash);
|
72
68
|
return packSignature(signature);
|
73
69
|
}
|
70
|
+
async opHash(userOp) {
|
71
|
+
return this.safePack.getOpHash(userOp);
|
72
|
+
}
|
73
|
+
async encodeSignRequest(tx) {
|
74
|
+
// TODO - This is sloppy and ignores ChainId!
|
75
|
+
const unsignedUserOp = await this.buildTransaction({
|
76
|
+
transactions: [
|
77
|
+
{
|
78
|
+
to: tx.to,
|
79
|
+
value: (tx.value || 0n).toString(),
|
80
|
+
data: tx.data || "0x",
|
81
|
+
},
|
82
|
+
],
|
83
|
+
usePaymaster: true,
|
84
|
+
});
|
85
|
+
const safeOpHash = (await this.opHash(unsignedUserOp));
|
86
|
+
const signRequest = await this.nearAdapter.encodeSignRequest({
|
87
|
+
method: "hash",
|
88
|
+
chainId: 0,
|
89
|
+
params: safeOpHash,
|
90
|
+
});
|
91
|
+
return {
|
92
|
+
...signRequest,
|
93
|
+
evmMessage: JSON.stringify(unsignedUserOp),
|
94
|
+
};
|
95
|
+
}
|
74
96
|
async executeTransaction(userOp) {
|
75
97
|
const userOpHash = await this.bundler.sendUserOperation(userOp);
|
76
98
|
console.log("UserOp Hash", userOpHash);
|