1
1
import { ethers } from "ethers" ;
2
- import { NearEthAdapter , MpcContract } from "near-ca" ;
2
+ import { NearEthAdapter , MpcContract , NearEthTxData } from "near-ca" ;
3
3
import { Erc4337Bundler } from "./lib/bundler" ;
4
4
import { packSignature } from "./util" ;
5
5
import { getNearSignature } from "./lib/near" ;
6
- import { UserOperation , UserOperationReceipt , UserOptions } from "./types" ;
6
+ import { UserOperation , UserOperationReceipt } from "./types" ;
7
7
import { MetaTransaction , encodeMulti } from "ethers-multisend" ;
8
8
import { ContractSuite } from "./lib/safe" ;
9
9
import { Account } from "near-api-js" ;
@@ -92,9 +92,9 @@ export class TransactionManager {
92
92
93
93
async buildTransaction ( args : {
94
94
transactions : MetaTransaction [ ] ;
95
- options : UserOptions ;
96
- } ) : Promise < { safeOpHash : string ; unsignedUserOp : UserOperation } > {
97
- const { transactions, options } = args ;
95
+ usePaymaster : boolean ;
96
+ } ) : Promise < UserOperation > {
97
+ const { transactions, usePaymaster } = args ;
98
98
const gasFees = ( await this . bundler . getGasPrice ( ) ) . fast ;
99
99
// const gasFees = await this.provider.getFeeData();
100
100
// Build Singular MetaTransaction for Multisend from transaction list.
@@ -114,27 +114,39 @@ export class TransactionManager {
114
114
115
115
const paymasterData = await this . bundler . getPaymasterData (
116
116
rawUserOp ,
117
- options . usePaymaster ,
117
+ usePaymaster ,
118
118
this . safeNotDeployed
119
119
) ;
120
120
121
121
const unsignedUserOp = { ...rawUserOp , ...paymasterData } ;
122
- const safeOpHash = await this . safePack . getOpHash (
123
- unsignedUserOp ,
124
- paymasterData
125
- ) ;
126
122
127
- return {
128
- safeOpHash,
129
- unsignedUserOp,
130
- } ;
123
+ return unsignedUserOp ;
131
124
}
132
125
133
126
async signTransaction ( safeOpHash : string ) : Promise < string > {
134
127
const signature = await getNearSignature ( this . nearAdapter , safeOpHash ) ;
135
128
return packSignature ( signature ) ;
136
129
}
137
130
131
+ async opHash ( userOp : UserOperation ) : Promise < string > {
132
+ return this . safePack . getOpHash ( userOp ) ;
133
+ }
134
+ async encodeSignatureRequest (
135
+ unsignedUserOp : UserOperation
136
+ ) : Promise < NearEthTxData > {
137
+ const safeOpHash = ( await this . opHash ( unsignedUserOp ) ) as `0x${string } `;
138
+ const txData = this . nearAdapter . encodeSignRequest ( {
139
+ method : "hash" ,
140
+ chainId : 0 ,
141
+ params : safeOpHash as `0x${string } `,
142
+ } ) ;
143
+
144
+ return {
145
+ ...txData ,
146
+ evmMessage : unsignedUserOp ,
147
+ } ;
148
+ }
149
+
138
150
async executeTransaction (
139
151
userOp : UserOperation
140
152
) : Promise < UserOperationReceipt > {
0 commit comments