Skip to content

Commit b2cec11

Browse files
committed
cleanup and comments
1 parent 5d51010 commit b2cec11

19 files changed

+234
-209
lines changed

.eslintrc.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
"@typescript-eslint/no-unused-vars": [
1414
"error",
1515
{ "argsIgnorePattern": "^_" }
16-
],
17-
"require-await": "off",
18-
"@typescript-eslint/require-await": "error"
16+
]
1917
}
2018
}

src/db/transactions/getSentUserOps.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/db/transactions/queueTx.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { DeployTransaction, Transaction } from "@thirdweb-dev/sdk";
22
import { ERC4337EthersSigner } from "@thirdweb-dev/wallets/dist/declarations/src/evm/connectors/smart-wallet/lib/erc4337-signer";
3-
import { Address } from "thirdweb";
3+
import { Address, ZERO_ADDRESS } from "thirdweb";
44
import type { ContractExtension } from "../../schema/extension";
5-
import { maybeBigInt } from "../../utils/primitiveTypes";
5+
import { maybeBigInt, normalizeAddress } from "../../utils/primitiveTypes";
66
import { insertTransaction } from "../../utils/transaction/insertTransaction";
77

88
interface QueueTxParams {
@@ -49,50 +49,42 @@ export const queueTx = async ({
4949
const isUserOp = !!(tx.getSigner as ERC4337EthersSigner).erc4337provider;
5050

5151
if (isUserOp) {
52-
const signerAddress = (
53-
await (tx.getSigner as ERC4337EthersSigner).originalSigner.getAddress()
54-
).toLowerCase() as Address;
55-
const accountAddress = (
56-
await tx.getSignerAddress()
57-
).toLowerCase() as Address;
58-
const target = tx.getTarget().toLowerCase() as Address;
52+
const signer = (tx.getSigner as ERC4337EthersSigner).originalSigner;
53+
const signerAddress = normalizeAddress(await signer.getAddress());
5954

60-
const queueId = await insertTransaction({
55+
return await insertTransaction({
6156
insertedTransaction: {
6257
...baseTransaction,
6358
isUserOp: true,
6459
deployedContractAddress,
6560
deployedContractType,
61+
from: signerAddress,
6662
signerAddress,
67-
accountAddress,
68-
target,
63+
accountAddress: normalizeAddress(await tx.getSignerAddress()),
64+
target: normalizeAddress(tx.getTarget()),
6965
gas: maybeBigInt(txOverrides?.gas),
7066
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
7167
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),
72-
from: signerAddress,
7368
},
7469
idempotencyKey,
7570
shouldSimulate: simulateTx,
7671
});
77-
78-
return queueId;
7972
} else {
80-
const fromAddress = await tx.getSignerAddress();
81-
const toAddress =
82-
tx.getTarget() === "0x0000000000000000000000000000000000000000" &&
73+
const isPublishedContractDeploy =
74+
tx.getTarget() === ZERO_ADDRESS &&
8375
functionName === "deploy" &&
84-
extension === "deploy-published"
85-
? null
86-
: tx.getTarget();
76+
extension === "deploy-published";
8777

8878
const queueId = await insertTransaction({
8979
insertedTransaction: {
9080
...baseTransaction,
9181
isUserOp: false,
9282
deployedContractAddress,
9383
deployedContractType,
94-
from: fromAddress.toLowerCase() as Address,
95-
to: toAddress?.toLowerCase() as Address,
84+
from: normalizeAddress(await tx.getSignerAddress()),
85+
to: normalizeAddress(
86+
isPublishedContractDeploy ? undefined : tx.getTarget(),
87+
),
9688
gas: maybeBigInt(txOverrides?.gas),
9789
maxFeePerGas: maybeBigInt(txOverrides?.maxFeePerGas),
9890
maxPriorityFeePerGas: maybeBigInt(txOverrides?.maxPriorityFeePerGas),

src/db/wallets/walletNonce.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
import { Address, eth_getTransactionCount, getRpcClient } from "thirdweb";
22
import { getChain } from "../../utils/chain";
3+
import { normalizeAddress } from "../../utils/primitiveTypes";
34
import { redis } from "../../utils/redis/redis";
45
import { thirdwebClient } from "../../utils/sdk";
56

6-
// Data type: String
7+
/**
8+
* The "last used nonce" stores the last nonce submitted onchain.
9+
* Example: "25"
10+
*/
711
const lastUsedNonceKey = (chainId: number, walletAddress: Address) =>
8-
`nonce:${chainId}:${walletAddress}`;
12+
`nonce:${chainId}:${normalizeAddress(walletAddress)}`;
913

10-
// Data type: Array of String
14+
/**
15+
* The "unused nonces" list stores unsorted nonces to be reused or cancelled.
16+
* Example: [ "25", "23", "24" ]
17+
*/
1118
const unusedNoncesKey = (chainId: number, walletAddress: Address) =>
12-
`nonce-unused:${chainId}:${walletAddress}`;
19+
`nonce-unused:${chainId}:${normalizeAddress(walletAddress)}`;
1320

1421
/**
1522
* Acquire an unused nonce.
@@ -89,7 +96,7 @@ const _syncNonce = async (
8996
* Use `incrWalletNonce` if using this nonce to send a transaction.
9097
* @param chainId
9198
* @param walletAddress
92-
* @returns number - The last used nonce value for this wallet.
99+
* @returns number
93100
*/
94101
export const inspectNonce = async (chainId: number, walletAddress: Address) => {
95102
const key = lastUsedNonceKey(chainId, walletAddress);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Static, Type } from "@sinclair/typebox";
22
import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { TransactionDB } from "../../../db/transactions/db";
5+
import { normalizeAddress } from "../../../utils/primitiveTypes";
56
import { standardResponseSchema } from "../../schemas/sharedApiSchemas";
67
import {
78
TransactionSchema,
@@ -39,7 +40,7 @@ export async function getAllTransactions(fastify: FastifyInstance) {
3940
handler: async (req, res) => {
4041
const { chain, walletAddress: _walletAddress } = req.params;
4142
const chainId = await getChainIdFromChain(chain);
42-
const walletAddress = _walletAddress.toLowerCase();
43+
const walletAddress = normalizeAddress(_walletAddress);
4344

4445
// @TODO: This query is not optimized. Cap the results to the most recent 1000 total transactions for performance reasons.
4546
const { transactions } = await TransactionDB.listByStatus({

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function simulateTransaction(fastify: FastifyInstance) {
8888
status: "queued",
8989
queueId: randomUUID(),
9090
queuedAt: new Date(),
91-
retryCount: 0,
91+
resendCount: 0,
9292

9393
chainId,
9494
from: walletAddress as Address,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
import { transfer as transferERC20 } from "thirdweb/extensions/erc20";
1313
import { isContractDeployed, resolvePromisedValue } from "thirdweb/utils";
1414
import { getChain } from "../../../utils/chain";
15-
import { maybeBigInt } from "../../../utils/primitiveTypes";
15+
import { maybeBigInt, normalizeAddress } from "../../../utils/primitiveTypes";
1616
import { thirdwebClient } from "../../../utils/sdk";
1717
import { insertTransaction } from "../../../utils/transaction/insertTransaction";
1818
import { InsertedTransaction } from "../../../utils/transaction/types";
@@ -87,7 +87,7 @@ export async function transfer(fastify: FastifyInstance) {
8787
const { simulateTx: shouldSimulate } = request.query;
8888

8989
// Resolve inputs.
90-
const currencyAddress = _currencyAddress.toLowerCase();
90+
const currencyAddress = normalizeAddress(_currencyAddress);
9191
const chainId = await getChainIdFromChain(chain);
9292
const gasOverrides = {
9393
gas: maybeBigInt(txOverrides?.gas),

src/server/routes/transaction/cancel.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ export async function cancelTransaction(fastify: FastifyInstance) {
9393
// Remove all retries from the SEND_TRANSACTION queue.
9494
const config = await getConfig();
9595
for (
96-
let retryCount = 0;
97-
retryCount < config.maxRetriesPerTx;
98-
retryCount++
96+
let resendCount = 0;
97+
resendCount < config.maxRetriesPerTx;
98+
resendCount++
9999
) {
100-
await SendTransactionQueue.remove({ queueId, retryCount });
100+
await SendTransactionQueue.remove({ queueId, resendCount });
101101
}
102102

103103
cancelledTransaction = {

src/server/routes/transaction/retry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function retryTransaction(fastify: FastifyInstance) {
8080
await TransactionDB.set(sentTransaction);
8181
await SendTransactionQueue.add({
8282
queueId: sentTransaction.queueId,
83-
retryCount: sentTransaction.retryCount + 1,
83+
resendCount: sentTransaction.resendCount + 1,
8484
});
8585

8686
reply.status(StatusCodes.OK).send({

src/server/routes/transaction/syncRetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export async function syncRetryTransaction(fastify: FastifyInstance) {
102102
// Update state if the send was successful.
103103
const sentTransaction: SentTransaction = {
104104
...transaction,
105-
retryCount: transaction.retryCount + 1,
105+
resendCount: transaction.resendCount + 1,
106106
sentAt: new Date(),
107107
sentAtBlock: await getBlockNumberish(chainId),
108108
sentTransactionHashes: [

0 commit comments

Comments
 (0)