Skip to content

Commit 6b930e2

Browse files
committed
add "x-account-factory-address" header
1 parent 70392ac commit 6b930e2

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
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 { queueTxRaw } from "../../../db/transactions/queueTxRaw";
5+
import { redis } from "../../../utils/redis/redis";
56
import {
67
requestQuerystringSchema,
78
standardResponseSchema,
@@ -72,9 +73,21 @@ export async function sendTransaction(fastify: FastifyInstance) {
7273
"x-backend-wallet-address": fromAddress,
7374
"x-idempotency-key": idempotencyKey,
7475
"x-account-address": accountAddress,
76+
"x-account-factory-address": factoryAddress,
7577
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7678
const chainId = await getChainIdFromChain(chain);
7779

80+
if (accountAddress && factoryAddress) {
81+
// Note: This is a temporary solution to cache the deployed address's factory for 7 days.
82+
// This is needed due to a potential race condition of submitting a transaction immediately after creating an account that is not yet mined onchain
83+
await redis.set(
84+
`account-factory:${accountAddress.toLowerCase()}`,
85+
factoryAddress,
86+
"EX",
87+
7 * 24 * 60 * 60,
88+
);
89+
}
90+
7891
let queueId: string;
7992
if (accountAddress) {
8093
const { id } = await queueTxRaw({

src/server/routes/contract/write/write.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
33
import { StatusCodes } from "http-status-codes";
44
import { queueTx } from "../../../../db/transactions/queueTx";
55
import { getContract } from "../../../../utils/cache/getContract";
6+
import { redis } from "../../../../utils/redis/redis";
67
import { abiSchema } from "../../../schemas/contract";
78
import {
89
contractParamSchema,
@@ -66,8 +67,20 @@ export async function writeToContract(fastify: FastifyInstance) {
6667
"x-backend-wallet-address": walletAddress,
6768
"x-account-address": accountAddress,
6869
"x-idempotency-key": idempotencyKey,
70+
"x-account-factory-address": factoryAddress,
6971
} = request.headers as Static<typeof walletWithAAHeaderSchema>;
7072

73+
if (accountAddress && factoryAddress) {
74+
// Note: This is a temporary solution to cache the deployed address's factory for 7 days.
75+
// This is needed due to a potential race condition of submitting a transaction immediately after creating an account that is not yet mined onchain
76+
await redis.set(
77+
`account-factory:${accountAddress.toLowerCase()}`,
78+
factoryAddress,
79+
"EX",
80+
7 * 24 * 60 * 60,
81+
);
82+
}
83+
7184
const chainId = await getChainIdFromChain(chain);
7285
const contract = await getContract({
7386
chainId,

src/server/schemas/wallet/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export const walletWithAAHeaderSchema = Type.Object({
1919
description: "Smart account address",
2020
}),
2121
),
22+
"x-account-factory-address": Type.Optional(
23+
Type.String({
24+
description: "Smart account factory address",
25+
}),
26+
),
2227
});
2328

2429
export const walletParamSchema = Type.Object({

0 commit comments

Comments
 (0)