Skip to content

Commit 79affa4

Browse files
committed
send-transaction userOp update
1 parent d0b372e commit 79affa4

File tree

3 files changed

+70
-44
lines changed

3 files changed

+70
-44
lines changed

src/server/routes/backend-wallet/sendTransaction.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,27 @@ export async function sendTransaction(fastify: FastifyInstance) {
7979

8080
let queueId: string;
8181
if (accountAddress) {
82-
throw new Error("@TODO: Unimplemented");
82+
queueId = await insertTransaction({
83+
insertedTransaction: {
84+
isUserOp: true,
85+
chainId,
86+
from: fromAddress as Address,
87+
to: toAddress as Address | undefined,
88+
data: data as Hex,
89+
value: BigInt(value),
90+
accountAddress: accountAddress as Address,
91+
signerAddress: fromAddress as Address,
92+
target: toAddress as Address | undefined,
93+
94+
gas: maybeBigInt(txOverrides?.gas),
95+
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
96+
maxPriorityFeePerGas: maybeBigInt(
97+
txOverrides?.maxPriorityFeePerGas,
98+
),
99+
},
100+
shouldSimulate: simulateTx,
101+
idempotencyKey,
102+
});
83103
} else {
84104
queueId = await insertTransaction({
85105
insertedTransaction: {

src/utils/transaction/simulateQueuedTransaction.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,26 @@ export const simulateQueuedTransaction = async (
4343
const chain = await getChain(chainId);
4444

4545
let transaction: PreparedTransaction;
46-
if (from && accountAddress && signerAddress && target && functionName) {
46+
if (data) {
47+
// Resolve data.
48+
transaction = prepareTransaction({
49+
client: thirdwebClient,
50+
chain,
51+
to,
52+
data,
53+
value,
54+
gas,
55+
gasPrice,
56+
maxFeePerGas,
57+
maxPriorityFeePerGas,
58+
});
59+
} else if (
60+
from &&
61+
accountAddress &&
62+
signerAddress &&
63+
target &&
64+
functionName
65+
) {
4766
try {
4867
// Resolve Target Contract
4968
const targetContract = getContract({
@@ -63,19 +82,6 @@ export const simulateQueuedTransaction = async (
6382
} catch (error: any) {
6483
return error.toString();
6584
}
66-
} else if (data) {
67-
// Resolve data.
68-
transaction = prepareTransaction({
69-
client: thirdwebClient,
70-
chain,
71-
to,
72-
data,
73-
value,
74-
gas,
75-
gasPrice,
76-
maxFeePerGas,
77-
maxPriorityFeePerGas,
78-
});
7985
} else if (to && functionName && functionArgs) {
8086
const contract = getContract({
8187
client: thirdwebClient,

src/utils/transaction/userOperation.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,10 @@ export const generateSignedUserOperation = async (
3232
accountAddress,
3333
target,
3434
from,
35+
data,
3536
} = queuedTransaction;
3637

37-
if (
38-
!from ||
39-
!accountAddress ||
40-
!signerAddress ||
41-
!target ||
42-
!functionName ||
43-
!functionArgs
44-
) {
38+
if (!from || !accountAddress || !signerAddress || !target) {
4539
throw new Error("Invalid UserOperation parameters");
4640
}
4741

@@ -76,16 +70,33 @@ export const generateSignedUserOperation = async (
7670
});
7771

7872
// Prepare Transaction
79-
const preparedTransaction = prepareContractCall({
80-
contract: targetContract,
81-
method: resolveMethod(functionName),
82-
params: functionArgs,
83-
value,
84-
});
85-
86-
const toAddress = await resolvePromisedValue(preparedTransaction.to);
87-
const txValue = await resolvePromisedValue(preparedTransaction.value);
88-
const txData = await resolvePromisedValue(preparedTransaction.data);
73+
let preparedTransaction:
74+
| Awaited<ReturnType<typeof prepareContractCall>>
75+
| undefined;
76+
77+
let toAddress: string | undefined;
78+
let txValue: bigint | undefined;
79+
let txData: Hex | undefined;
80+
81+
// Handle UserOp Requests with FunctionName & Args
82+
if (functionName && functionArgs) {
83+
preparedTransaction = prepareContractCall({
84+
contract: targetContract,
85+
method: resolveMethod(functionName),
86+
params: functionArgs,
87+
value,
88+
});
89+
toAddress = await resolvePromisedValue(preparedTransaction.to);
90+
txValue = await resolvePromisedValue(preparedTransaction.value);
91+
txData = await resolvePromisedValue(preparedTransaction.data);
92+
} // Handle UserOp Requests with Data & Target
93+
else if (data && target) {
94+
toAddress = target;
95+
txValue = value || 0n;
96+
txData = data;
97+
} else {
98+
throw new Error("Invalid UserOperation parameters");
99+
}
89100

90101
// Prepare UserOperation Call
91102
const userOpCall = prepareContractCall({
@@ -146,14 +157,3 @@ export const generateSignedUserOperation = async (
146157
// Return Signed UserOperation
147158
return signedUserOp;
148159
};
149-
150-
export const isUserOperation = (
151-
queuedTransaction: QueuedTransaction,
152-
): boolean => {
153-
const { from, accountAddress, signerAddress, target, functionName } =
154-
queuedTransaction;
155-
156-
return Boolean(
157-
from && accountAddress && signerAddress && target && functionName,
158-
);
159-
};

0 commit comments

Comments
 (0)