Skip to content

Commit 29138a8

Browse files
committed
updates for value override, simulation + send Tx/UserOps using data
1 parent 62fe307 commit 29138a8

File tree

4 files changed

+16
-95
lines changed

4 files changed

+16
-95
lines changed

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ services:
3030
restart: always
3131
ports:
3232
- 6379:6379
33+
deploy:
34+
resources:
35+
limits:
36+
cpus: "1"
37+
memory: 1024M
3338
volumes:
3439
- redis_data:/data
3540

src/db/transactions/queueTx.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface QueueTxParams {
1818
gas?: string;
1919
maxFeePerGas?: string;
2020
maxPriorityFeePerGas?: string;
21+
value?: string;
2122
};
2223
}
2324

@@ -34,7 +35,9 @@ export const queueTx = async ({
3435
// Transaction Details
3536
const functionName = tx.getMethod();
3637
const encodedData = tx.encode();
37-
const value = BigInt(await tx.getValue().toString());
38+
const value = maybeBigInt(
39+
txOverrides?.value ?? (await tx.getValue().toString()),
40+
);
3841
const functionArgs = tx.getArgs();
3942
const baseTransaction = {
4043
chainId,
@@ -43,6 +46,9 @@ export const queueTx = async ({
4346
functionName,
4447
functionArgs,
4548
extension,
49+
gas: maybeBigInt(txOverrides?.gas),
50+
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
51+
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
4652
};
4753

4854
// TODO: We need a much safer way of detecting if the transaction should be a user operation
@@ -62,9 +68,6 @@ export const queueTx = async ({
6268
signerAddress,
6369
accountAddress: normalizeAddress(await tx.getSignerAddress()),
6470
target: normalizeAddress(tx.getTarget()),
65-
gas: maybeBigInt(txOverrides?.gas),
66-
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
67-
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
6871
},
6972
idempotencyKey,
7073
shouldSimulate: simulateTx,
@@ -85,9 +88,6 @@ export const queueTx = async ({
8588
to: normalizeAddress(
8689
isPublishedContractDeploy ? undefined : tx.getTarget(),
8790
),
88-
gas: maybeBigInt(txOverrides?.gas),
89-
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
90-
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
9191
},
9292
idempotencyKey,
9393
shouldSimulate: simulateTx,

src/utils/transaction/simulateQueuedTransaction.ts

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import {
2-
Address,
32
PreparedTransaction,
4-
getContract,
5-
prepareContractCall,
63
prepareTransaction,
7-
resolveMethod,
84
simulateTransaction,
95
} from "thirdweb";
106
import { stringify } from "thirdweb/utils";
@@ -26,15 +22,12 @@ export const doSimulateTransaction = async (
2622
const {
2723
chainId,
2824
to,
29-
functionName,
30-
functionArgs,
3125
data,
3226
value,
3327
gas,
3428
gasPrice,
3529
maxFeePerGas,
3630
maxPriorityFeePerGas,
37-
signerAddress,
3831
accountAddress,
3932
target,
4033
from,
@@ -43,61 +36,19 @@ export const doSimulateTransaction = async (
4336
const chain = await getChain(chainId);
4437

4538
let preparedTransaction: PreparedTransaction;
46-
if (data) {
39+
if (data && (to || target)) {
4740
// Resolve data.
4841
preparedTransaction = prepareTransaction({
4942
client: thirdwebClient,
5043
chain,
51-
to,
44+
to: to ?? target,
5245
data,
5346
value,
5447
gas,
5548
gasPrice,
5649
maxFeePerGas,
5750
maxPriorityFeePerGas,
5851
});
59-
} else if (
60-
from &&
61-
accountAddress &&
62-
signerAddress &&
63-
target &&
64-
functionName
65-
) {
66-
try {
67-
// Resolve Target Contract
68-
const targetContract = getContract({
69-
client: thirdwebClient,
70-
chain,
71-
address: target as Address,
72-
});
73-
74-
// Prepare UserOperation Transaction
75-
preparedTransaction = prepareContractCall({
76-
contract: targetContract,
77-
method: await resolveMethod(functionName),
78-
params: functionArgs ?? [],
79-
value: value,
80-
gas: gas,
81-
});
82-
} catch (error: any) {
83-
return error.toString();
84-
}
85-
} else if (to && functionName && functionArgs) {
86-
const contract = getContract({
87-
client: thirdwebClient,
88-
chain,
89-
address: to,
90-
});
91-
preparedTransaction = await prepareContractCall({
92-
contract,
93-
method: resolveMethod(functionName),
94-
params: functionArgs,
95-
value,
96-
gas,
97-
gasPrice,
98-
maxFeePerGas,
99-
maxPriorityFeePerGas,
100-
});
10152
} else {
10253
throw new Error(
10354
`Transaction cannot be simulated: ${stringify(transaction)}`,

src/utils/transaction/userOperation.ts

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ import {
44
getContract,
55
prepareContractCall,
66
readContract,
7-
resolveMethod,
87
} from "thirdweb";
9-
import { resolvePromisedValue } from "thirdweb/utils";
108
import {
119
UserOperation,
1210
createUnsignedUserOp,
1311
getPaymasterAndData,
1412
signUserOp,
1513
} from "thirdweb/wallets/smart";
1614
import { getAccount } from "../account";
17-
import { getSmartWalletV5 } from "../cache/getSmartWalletV5";
1815
import { getChain } from "../chain";
1916
import { thirdwebClient } from "../sdk";
2017
import { QueuedTransaction } from "./types";
@@ -24,8 +21,6 @@ export const generateSignedUserOperation = async (
2421
): Promise<UserOperation> => {
2522
const {
2623
chainId,
27-
functionName,
28-
functionArgs,
2924
value,
3025
gas,
3126
signerAddress,
@@ -41,13 +36,6 @@ export const generateSignedUserOperation = async (
4136

4237
const chain = await getChain(chainId);
4338

44-
// Resolve Target Contract
45-
const targetContract = getContract({
46-
client: thirdwebClient,
47-
chain,
48-
address: target as Address,
49-
});
50-
5139
// Resolve Smart-Account Contract
5240
const smartAccountContract = getContract({
5341
client: thirdwebClient,
@@ -69,28 +57,12 @@ export const generateSignedUserOperation = async (
6957
address: accountFactoryAddress as Address,
7058
});
7159

72-
// Prepare Transaction
73-
let preparedTransaction:
74-
| Awaited<ReturnType<typeof prepareContractCall>>
75-
| undefined;
76-
7760
let toAddress: string | undefined;
7861
let txValue: bigint | undefined;
7962
let txData: Hex | undefined;
8063

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) {
64+
// Handle UserOp Requests
65+
if (data && target) {
9466
toAddress = target;
9567
txValue = value || 0n;
9668
txData = data;
@@ -105,13 +77,6 @@ export const generateSignedUserOperation = async (
10577
params: [toAddress || "", txValue || 0n, txData || "0x"],
10678
});
10779

108-
// Get Smart Wallet
109-
const smartWallet = await getSmartWalletV5({
110-
from,
111-
chain,
112-
accountAddress,
113-
});
114-
11580
// Create Unsigned UserOperation
11681
// Todo: Future expose a way to skip paymaster
11782
let unsignedOp = await createUnsignedUserOp({

0 commit comments

Comments
 (0)