Skip to content

Commit 889d82e

Browse files
committed
waitForReceipt flag + minor fixes
1 parent ebe5995 commit 889d82e

File tree

34 files changed

+2544
-2187
lines changed

34 files changed

+2544
-2187
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
"tsx": "^4.19.2"
3333
},
3434
"dependencies": {
35-
"@0xsequence/auth": "^2.2.11",
35+
"@0xsequence/auth": "^2.3.27",
3636
"@0xsequence/aws-kms-signer": "^0.1.1",
37-
"@0xsequence/core": "^2.3.16",
37+
"@0xsequence/core": "^2.3.27",
3838
"@0xsequence/google-kms-signer": "^0.2.0",
39-
"@0xsequence/indexer": "^2.2.13",
40-
"@0xsequence/network": "^2.2.11",
39+
"@0xsequence/indexer": "^2.3.27",
40+
"@0xsequence/network": "^2.3.27",
4141
"@aws-sdk/client-kms": "^3.750.0",
4242
"@bull-board/api": "^6.7.8",
4343
"@bull-board/fastify": "^6.7.8",

pnpm-lock.yaml

Lines changed: 1633 additions & 1277 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/bull-board/bull-board.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ export default fp(async (fastify: FastifyInstance) => {
1414

1515
serverAdapter.setBasePath('/admin/queues')
1616
fastify.register(serverAdapter.registerPlugin(), {
17-
prefix: '/admin/queues',
18-
basePath: '/admin/queues'
17+
prefix: '/admin/queues'
1918
})
2019

2120
fastify.log.info('Bull Board available at /admin/queues')

src/queues/rewardQueue.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function createRewardQueue(fastify: FastifyInstance) {
2828

2929
// Handle failed jobs
3030
rewardQueue.on('failed', (job, err) => {
31-
fastify.log.error(`Job ${job.id} has failed:`, err)
31+
fastify.log.error(`Job ${job.id} has failed: ${err}`)
3232
})
3333

3434
// Process rewards distribution
@@ -90,13 +90,12 @@ export function createRewardQueue(fastify: FastifyInstance) {
9090
}
9191
} catch (error) {
9292
fastify.log.error(
93-
`Failed to distribute rewards to ${recipients}:`,
94-
error
93+
`Failed to distribute rewards to ${recipients}: ${error}`
9594
)
9695
throw error // This will mark the job as failed
9796
}
9897
} catch (error) {
99-
fastify.log.error('Error processing rewards:', error)
98+
fastify.log.error(`Error processing rewards: ${error}`)
10099
throw error
101100
}
102101
})

src/routes/contract/deploy/contract.ts

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type DeployContractRequestBody = {
1515
abi: Array<ethers.InterfaceAbi>
1616
bytecode: string
1717
args: Array<string>
18+
waitForReceipt?: boolean
1819
}
1920

2021
type DeployContractRequestParams = {
@@ -45,7 +46,8 @@ const DeployContractSchema = {
4546
type: 'string',
4647
description:
4748
'String representation of the bytecode without the 0x prefix'
48-
}
49+
},
50+
waitForReceipt: { type: 'boolean', nullable: true }
4951
}
5052
},
5153
params: {
@@ -97,7 +99,7 @@ export async function deployContract(fastify: FastifyInstance) {
9799
const { chainId } = request.params
98100

99101
try {
100-
const { args, abi, bytecode } = request.body
102+
const { args, abi, bytecode, waitForReceipt } = request.body
101103

102104
if (!bytecode.startsWith('0x')) {
103105
logError(request, new Error('Bytecode must start with 0x'), {
@@ -130,63 +132,60 @@ export async function deployContract(fastify: FastifyInstance) {
130132
to: zeroAddress
131133
}
132134

133-
logStep(request, 'Sending deploy transaction...')
134-
const tx = await signer.sendTransaction({
135-
data
136-
})
137-
txHash = tx.hash
138-
logStep(request, 'Deploy transaction sent', { txHash: tx.hash })
139-
140-
const { simulationData, signedTx } =
141-
await prepareTransactionsForTenderlySimulation(
142-
signer,
143-
[deploymentTx],
144-
Number(chainId)
145-
)
146-
const tenderlyUrl = getTenderlySimulationUrl({
147-
chainId: chainId,
148-
gas: 3000000,
149-
block: await signer.provider.getBlockNumber(),
150-
contractAddress: signedTx.entrypoint,
151-
blockIndex: 0,
152-
rawFunctionInput: simulationData
153-
})
154-
155-
const receipt = await tx.wait()
156-
logStep(request, 'Deploy transaction mined', { receipt })
157-
158-
const deployedContractAddress = getContractAddressFromEvent(
159-
receipt,
160-
'CreatedContract(address)'
135+
const { simulationData, signedTx } =
136+
await prepareTransactionsForTenderlySimulation(
137+
signer,
138+
[deploymentTx],
139+
Number(chainId)
161140
)
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+
}
162161

163-
if (receipt?.status === 0) {
164-
logError(request, new Error('Transaction reverted'), { receipt })
165-
throw new Error('Transaction reverted')
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
166187
}
167-
168-
await txService.createTransaction({
169-
chainId,
170-
contractAddress: deployedContractAddress,
171-
abi,
172-
data,
173-
txHash: receipt?.hash ?? '',
174-
isDeployTx: true,
175-
args
176-
})
177-
logStep(request, 'Transaction added in db', { txHash: receipt?.hash })
178-
179-
logStep(request, 'Deploy transaction success', {
180-
txHash: receipt?.hash
181-
})
182-
return reply.code(200).send({
183-
result: {
184-
txHash: receipt?.hash ?? null,
185-
txUrl: getBlockExplorerUrl(Number(chainId), receipt?.hash ?? ''),
186-
txSimulationUrl: tenderlyUrl,
187-
deployedContractAddress: deployedContractAddress
188-
}
189-
})
188+
})
190189
} catch (error) {
191190
// Extract transaction hash from error receipt if available
192191
const errorTxHash = extractTxHashFromErrorReceipt(error)

src/routes/contract/deploy/erc1155.ts

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type ERC1155DeployRequestBody = {
1717
defaultAdmin: string
1818
minter: string
1919
name: string
20+
waitForReceipt?: boolean
2021
}
2122

2223
type ERC1155DeployRequestParams = {
@@ -43,7 +44,8 @@ const ERC1155DeploySchema = {
4344
properties: {
4445
defaultAdmin: { type: 'string' },
4546
minter: { type: 'string' },
46-
name: { type: 'string' }
47+
name: { type: 'string' },
48+
waitForReceipt: { type: 'boolean', nullable: true }
4749
}
4850
},
4951
params: {
@@ -96,7 +98,7 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
9698
const { chainId } = request.params
9799

98100
try {
99-
const { defaultAdmin, minter, name } = request.body
101+
const { defaultAdmin, minter, name, waitForReceipt } = request.body
100102

101103
logStep(request, 'Getting tx signer', { chainId })
102104
const signer = await getSigner(chainId)
@@ -121,39 +123,35 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
121123
data
122124
}
123125

124-
logStep(request, 'Sending deploy transaction')
125-
const tx = await signer.sendTransaction(deploymentTx)
126-
txHash = tx.hash
127-
logStep(request, 'Deploy transaction sent', { tx })
128-
129-
const { simulationData, signedTx } =
130-
await prepareTransactionsForTenderlySimulation(
131-
signer,
132-
[deploymentTx],
133-
Number(chainId)
134-
)
135-
const tenderlyUrl = getTenderlySimulationUrl({
136-
chainId: chainId,
137-
gas: 3000000,
138-
block: await signer.provider.getBlockNumber(),
139-
contractAddress: signedTx.entrypoint,
140-
blockIndex: 0,
141-
rawFunctionInput: simulationData
142-
})
143-
144-
logStep(request, 'Waiting for deploy receipt', { txHash: tx.hash })
145-
const receipt = await tx.wait()
146-
logStep(request, 'Deploy receipt received', { receipt })
147-
148-
const deployedContractAddress = getContractAddressFromEvent(
149-
receipt,
150-
'CreatedContract(address)'
126+
const { simulationData, signedTx } =
127+
await prepareTransactionsForTenderlySimulation(
128+
signer,
129+
[deploymentTx],
130+
Number(chainId)
151131
)
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+
}
152150

153-
if (receipt?.status === 0) {
154-
logError(request, new Error('Transaction reverted'), { receipt })
155-
throw new Error('Transaction reverted')
156-
}
151+
const deployedContractAddress = getContractAddressFromEvent(
152+
tx.receipt,
153+
'CreatedContract(address)'
154+
)
157155

158156
logStep(request, 'Creating transaction record in db')
159157
const txService = new TransactionService(fastify)
@@ -162,13 +160,13 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
162160
contractAddress: deployedContractAddress,
163161
abi: erc1155Abi,
164162
data,
165-
txHash: receipt?.hash ?? '',
163+
txHash: txHash,
166164
isDeployTx: true
167165
})
168166

169-
logStep(request, 'Deploy transaction success', {
170-
txHash: receipt?.hash
171-
})
167+
logStep(request, 'Deploy transaction success', {
168+
txHash: txHash
169+
})
172170

173171
// --- Verification logic (added) ---
174172
if (process.env.VERIFY_CONTRACT_ON_DEPLOY === 'true') {
@@ -207,14 +205,14 @@ export async function erc1155Deploy(fastify: FastifyInstance) {
207205
}
208206
// --- End verification logic ---
209207

210-
return reply.code(200).send({
211-
result: {
212-
txHash: receipt?.hash ?? null,
213-
txUrl: getBlockExplorerUrl(Number(chainId), receipt?.hash ?? ''),
214-
txSimulationUrl: tenderlyUrl,
215-
deployedContractAddress: deployedContractAddress
216-
}
217-
})
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+
})
218216
} catch (error) {
219217
// Extract transaction hash from error receipt if available
220218
const errorTxHash = extractTxHashFromErrorReceipt(error)

0 commit comments

Comments
 (0)