Skip to content

Commit f57afd2

Browse files
authored
LastUsedNonce fix (#93)
* fixed lastUsedNonce 0 -> -1 for init * fixed wallets DB lastUsedNonce for wallets with 0 tx on a chain * updated comments * updated variable name
1 parent 75d3cd5 commit f57afd2

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

worker/controller/wallet.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const setupWalletsForWorker = async (
4545
server.log.warn(`Wallet address not found for chain ${slug}.`);
4646
continue;
4747
}
48-
const walletNonce = await getWalletNonce(
48+
const walletBlockchainNonce = await getWalletNonce(
4949
walletAddress,
5050
sdk.getProvider(),
5151
);
@@ -59,10 +59,20 @@ export const setupWalletsForWorker = async (
5959
lastUsedNonce = walletDataInDB.lastUsedNonce;
6060
}
6161

62+
// lastUsedNonce should be set to -1 if blockchainNonce is 0
63+
if (
64+
BigNumber.from(walletBlockchainNonce).eq(BigNumber.from(0)) &&
65+
BigNumber.from(lastUsedNonce).eq(BigNumber.from(0))
66+
) {
67+
lastUsedNonce = -1;
68+
}
69+
6270
const walletData = {
6371
walletAddress: walletAddress.toLowerCase(),
6472
chainId: getChainBySlug(slug).chainId.toString(),
65-
blockchainNonce: BigNumber.from(walletNonce ?? 0).toNumber(),
73+
blockchainNonce: BigNumber.from(
74+
walletBlockchainNonce ?? 0,
75+
).toNumber(),
6676
lastSyncedTimestamp: new Date(),
6777
lastUsedNonce,
6878
walletType: slug,

0 commit comments

Comments
 (0)