File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Static, Type } from "@sinclair/typebox";
2
2
import { FastifyInstance } from "fastify" ;
3
3
import { StatusCodes } from "http-status-codes" ;
4
4
import { queueTxRaw } from "../../../db/transactions/queueTxRaw" ;
5
+ import { redis } from "../../../utils/redis/redis" ;
5
6
import {
6
7
requestQuerystringSchema ,
7
8
standardResponseSchema ,
@@ -72,9 +73,21 @@ export async function sendTransaction(fastify: FastifyInstance) {
72
73
"x-backend-wallet-address" : fromAddress ,
73
74
"x-idempotency-key" : idempotencyKey ,
74
75
"x-account-address" : accountAddress ,
76
+ "x-account-factory-address" : factoryAddress ,
75
77
} = request . headers as Static < typeof walletWithAAHeaderSchema > ;
76
78
const chainId = await getChainIdFromChain ( chain ) ;
77
79
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
+
78
91
let queueId : string ;
79
92
if ( accountAddress ) {
80
93
const { id } = await queueTxRaw ( {
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { FastifyInstance } from "fastify";
3
3
import { StatusCodes } from "http-status-codes" ;
4
4
import { queueTx } from "../../../../db/transactions/queueTx" ;
5
5
import { getContract } from "../../../../utils/cache/getContract" ;
6
+ import { redis } from "../../../../utils/redis/redis" ;
6
7
import { abiSchema } from "../../../schemas/contract" ;
7
8
import {
8
9
contractParamSchema ,
@@ -66,8 +67,20 @@ export async function writeToContract(fastify: FastifyInstance) {
66
67
"x-backend-wallet-address" : walletAddress ,
67
68
"x-account-address" : accountAddress ,
68
69
"x-idempotency-key" : idempotencyKey ,
70
+ "x-account-factory-address" : factoryAddress ,
69
71
} = request . headers as Static < typeof walletWithAAHeaderSchema > ;
70
72
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
+
71
84
const chainId = await getChainIdFromChain ( chain ) ;
72
85
const contract = await getContract ( {
73
86
chainId,
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ export const walletWithAAHeaderSchema = Type.Object({
19
19
description : "Smart account address" ,
20
20
} ) ,
21
21
) ,
22
+ "x-account-factory-address" : Type . Optional (
23
+ Type . String ( {
24
+ description : "Smart account factory address" ,
25
+ } ) ,
26
+ ) ,
22
27
} ) ;
23
28
24
29
export const walletParamSchema = Type . Object ( {
You can’t perform that action at this time.
0 commit comments