Skip to content

Commit f090316

Browse files
authored
Feat/relayer wait for receipt (#52)
* add relayer wait for receipt endpoint * update version * add TransactionReceipt type * linting
1 parent 9305fa6 commit f090316

File tree

31 files changed

+1628
-797
lines changed

31 files changed

+1628
-797
lines changed

src/constants/abis/erc1155Items.ts

Lines changed: 524 additions & 1 deletion
Large diffs are not rendered by default.

src/routes/contract/deploy/contract.ts

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
import { prepareTransactionsForTenderlySimulation } from '~/routes/contract/utils/tenderly/getSimulationUrl'
99
import { TransactionService } from '~/services/transaction.service'
1010
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
11-
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
11+
import {
12+
extractTxHashFromErrorReceipt,
13+
getBlockExplorerUrl,
14+
getContractAddressFromEvent
15+
} from '~/utils/other'
1216
import { getSigner } from '~/utils/wallet'
1317

1418
type DeployContractRequestBody = {
@@ -94,7 +98,7 @@ export async function deployContract(fastify: FastifyInstance) {
9498
async (request, reply) => {
9599
logRequest(request)
96100

97-
let tenderlyUrl: string | null = null
101+
const tenderlyUrl: string | null = null
98102
let txHash: string | null = null
99103
const { chainId } = request.params
100104

@@ -132,60 +136,65 @@ export async function deployContract(fastify: FastifyInstance) {
132136
to: zeroAddress
133137
}
134138

135-
const { simulationData, signedTx } =
136-
await prepareTransactionsForTenderlySimulation(
137-
signer,
138-
[deploymentTx],
139-
Number(chainId)
139+
const { simulationData, signedTx } =
140+
await prepareTransactionsForTenderlySimulation(
141+
signer,
142+
[deploymentTx],
143+
Number(chainId)
144+
)
145+
const tenderlyUrl = getTenderlySimulationUrl({
146+
chainId: chainId,
147+
gas: 3000000,
148+
block: await signer.provider.getBlockNumber(),
149+
contractAddress: signedTx.entrypoint,
150+
blockIndex: 0,
151+
rawFunctionInput: simulationData
152+
})
153+
154+
logStep(request, 'Sending deploy transaction...')
155+
const tx = await signer.sendTransaction(
156+
{
157+
data
158+
},
159+
{ waitForReceipt: true }
140160
)
141-
const tenderlyUrl = getTenderlySimulationUrl({
142-
chainId: chainId,
143-
gas: 3000000,
144-
block: await signer.provider.getBlockNumber(),
145-
contractAddress: signedTx.entrypoint,
146-
blockIndex: 0,
147-
rawFunctionInput: simulationData
148-
})
149-
150-
logStep(request, 'Sending deploy transaction...')
151-
const tx = await signer.sendTransaction({
152-
data
153-
}, {waitForReceipt: true})
154-
txHash = tx.hash
155-
logStep(request, 'Deploy transaction sent', { txHash: tx.hash })
156-
157-
if (tx.receipt?.status === 0) {
158-
logError(request, new Error('Transaction reverted'), { receipt: tx.receipt })
159-
throw new Error('Transaction reverted', { cause: tx.receipt })
160-
}
161+
txHash = tx.hash
162+
logStep(request, 'Deploy transaction sent', { txHash: tx.hash })
161163

162-
const deployedContractAddress = getContractAddressFromEvent(
163-
tx.receipt,
164-
'CreatedContract(address)'
165-
)
166-
167-
await txService.createTransaction({
168-
chainId,
169-
contractAddress: deployedContractAddress,
170-
abi,
171-
data,
172-
txHash: txHash,
173-
isDeployTx: true,
174-
args
175-
})
176-
logStep(request, 'Transaction added in db', { txHash: txHash })
177-
178-
logStep(request, 'Deploy transaction success', {
179-
txHash: txHash
180-
})
181-
return reply.code(200).send({
182-
result: {
183-
txHash: txHash,
184-
txUrl: getBlockExplorerUrl(Number(chainId), txHash),
185-
txSimulationUrl: tenderlyUrl,
186-
deployedContractAddress: deployedContractAddress
164+
if (tx.receipt?.status === 0) {
165+
logError(request, new Error('Transaction reverted'), {
166+
receipt: tx.receipt
167+
})
168+
throw new Error('Transaction reverted', { cause: tx.receipt })
187169
}
188-
})
170+
171+
const deployedContractAddress = getContractAddressFromEvent(
172+
tx.receipt,
173+
'CreatedContract(address)'
174+
)
175+
176+
await txService.createTransaction({
177+
chainId,
178+
contractAddress: deployedContractAddress,
179+
abi,
180+
data,
181+
txHash: txHash,
182+
isDeployTx: true,
183+
args
184+
})
185+
logStep(request, 'Transaction added in db', { txHash: txHash })
186+
187+
logStep(request, 'Deploy transaction success', {
188+
txHash: txHash
189+
})
190+
return reply.code(200).send({
191+
result: {
192+
txHash: txHash,
193+
txUrl: getBlockExplorerUrl(Number(chainId), txHash),
194+
txSimulationUrl: tenderlyUrl,
195+
deployedContractAddress: deployedContractAddress
196+
}
197+
})
189198
} catch (error) {
190199
// Extract transaction hash from error receipt if available
191200
const errorTxHash = extractTxHashFromErrorReceipt(error)
@@ -198,13 +207,13 @@ export async function deployContract(fastify: FastifyInstance) {
198207
})
199208

200209
const errorMessage =
201-
error instanceof Error
202-
? error.message
203-
: 'Failed to deploy contract'
210+
error instanceof Error ? error.message : 'Failed to deploy contract'
204211
return reply.code(500).send({
205212
result: {
206213
txHash: finalTxHash,
207-
txUrl: finalTxHash ? getBlockExplorerUrl(Number(chainId), finalTxHash) : null,
214+
txUrl: finalTxHash
215+
? getBlockExplorerUrl(Number(chainId), finalTxHash)
216+
: null,
208217
txSimulationUrl: tenderlyUrl,
209218
deployedContractAddress: null,
210219
error: errorMessage

src/routes/contract/deploy/erc1155.ts

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import {
1010
import { TransactionService } from '~/services/transaction.service'
1111
import { verifyContract } from '~/utils/contractVerification'
1212
import { logError, logRequest, logStep } from '~/utils/loggingUtils'
13-
import { extractTxHashFromErrorReceipt, getBlockExplorerUrl, getContractAddressFromEvent } from '~/utils/other'
13+
import {
14+
extractTxHashFromErrorReceipt,
15+
getBlockExplorerUrl,
16+
getContractAddressFromEvent
17+
} from '~/utils/other'
1418
import { getSigner } from '~/utils/wallet'
1519

1620
type ERC1155DeployRequestBody = {
@@ -93,7 +97,7 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
9397
async (request, reply) => {
9498
logRequest(request)
9599

96-
let tenderlyUrl: string | null = null
100+
const tenderlyUrl: string | null = null
97101
let txHash: string | null = null
98102
const { chainId } = request.params
99103

@@ -123,35 +127,39 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
123127
data
124128
}
125129

126-
const { simulationData, signedTx } =
127-
await prepareTransactionsForTenderlySimulation(
128-
signer,
129-
[deploymentTx],
130-
Number(chainId)
131-
)
132-
const tenderlyUrl = getTenderlySimulationUrl({
133-
chainId: chainId,
134-
gas: 3000000,
135-
block: await signer.provider.getBlockNumber(),
136-
contractAddress: signedTx.entrypoint,
137-
blockIndex: 0,
138-
rawFunctionInput: simulationData
139-
})
140-
141-
logStep(request, 'Sending deploy transaction')
142-
const tx = await signer.sendTransaction(deploymentTx, {waitForReceipt: true})
143-
txHash = tx.hash
144-
logStep(request, 'Deploy transaction sent', { tx })
145-
146-
if (tx.receipt?.status === 0) {
147-
logError(request, new Error('Transaction reverted'), { receipt: tx.receipt })
148-
throw new Error('Transaction reverted', { cause: tx.receipt })
149-
}
130+
const { simulationData, signedTx } =
131+
await prepareTransactionsForTenderlySimulation(
132+
signer,
133+
[deploymentTx],
134+
Number(chainId)
135+
)
136+
const tenderlyUrl = getTenderlySimulationUrl({
137+
chainId: chainId,
138+
gas: 3000000,
139+
block: await signer.provider.getBlockNumber(),
140+
contractAddress: signedTx.entrypoint,
141+
blockIndex: 0,
142+
rawFunctionInput: simulationData
143+
})
150144

151-
const deployedContractAddress = getContractAddressFromEvent(
152-
tx.receipt,
153-
'CreatedContract(address)'
154-
)
145+
logStep(request, 'Sending deploy transaction')
146+
const tx = await signer.sendTransaction(deploymentTx, {
147+
waitForReceipt: true
148+
})
149+
txHash = tx.hash
150+
logStep(request, 'Deploy transaction sent', { tx })
151+
152+
if (tx.receipt?.status === 0) {
153+
logError(request, new Error('Transaction reverted'), {
154+
receipt: tx.receipt
155+
})
156+
throw new Error('Transaction reverted', { cause: tx.receipt })
157+
}
158+
159+
const deployedContractAddress = getContractAddressFromEvent(
160+
tx.receipt,
161+
'CreatedContract(address)'
162+
)
155163

156164
logStep(request, 'Creating transaction record in db')
157165
const txService = new TransactionService(fastify)
@@ -164,9 +172,9 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
164172
isDeployTx: true
165173
})
166174

167-
logStep(request, 'Deploy transaction success', {
168-
txHash: txHash
169-
})
175+
logStep(request, 'Deploy transaction success', {
176+
txHash: txHash
177+
})
170178

171179
// --- Verification logic (added) ---
172180
if (process.env.VERIFY_CONTRACT_ON_DEPLOY === 'true') {
@@ -205,14 +213,14 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
205213
}
206214
// --- End verification logic ---
207215

208-
return reply.code(200).send({
209-
result: {
210-
txHash: txHash,
211-
txUrl: getBlockExplorerUrl(Number(chainId), txHash),
212-
txSimulationUrl: tenderlyUrl,
213-
deployedContractAddress: deployedContractAddress
214-
}
215-
})
216+
return reply.code(200).send({
217+
result: {
218+
txHash: txHash,
219+
txUrl: getBlockExplorerUrl(Number(chainId), txHash),
220+
txSimulationUrl: tenderlyUrl,
221+
deployedContractAddress: deployedContractAddress
222+
}
223+
})
216224
} catch (error) {
217225
// Extract transaction hash from error receipt if available
218226
const errorTxHash = extractTxHashFromErrorReceipt(error)
@@ -225,13 +233,13 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
225233
})
226234

227235
const errorMessage =
228-
error instanceof Error
229-
? error.message
230-
: 'Failed to deploy ERC1155'
236+
error instanceof Error ? error.message : 'Failed to deploy ERC1155'
231237
return reply.code(500).send({
232238
result: {
233239
txHash: finalTxHash,
234-
txUrl: finalTxHash ? getBlockExplorerUrl(Number(chainId), finalTxHash) : null,
240+
txUrl: finalTxHash
241+
? getBlockExplorerUrl(Number(chainId), finalTxHash)
242+
: null,
235243
txSimulationUrl: tenderlyUrl,
236244
deployedContractAddress: null,
237245
error: errorMessage

0 commit comments

Comments
 (0)