Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/social-tires-search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-sdk': patch
---

Improve SolverStatusTimeout error log
6 changes: 4 additions & 2 deletions packages/sdk/src/errors/DepositTransactionTimeoutError.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export class DepositTransactionTimeoutError extends Error {
txHash: `0x${string}`
requestId: string

constructor(txHash: `0x${string}`, attemptCount: number) {
constructor(txHash: `0x${string}`, requestId: string, attemptCount: number) {
super(
`Deposit transaction with hash '${txHash}' is pending after ${attemptCount} attempt(s).`
`Deposit transaction with hash '${txHash}' and request id '${requestId}' is pending after ${attemptCount} attempt(s).`
)
this.name = 'DepositTransactionTimeoutError'
this.txHash = txHash
this.requestId = requestId
}
}
6 changes: 4 additions & 2 deletions packages/sdk/src/errors/SolverStatusTimeoutError.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
export class SolverStatusTimeoutError extends Error {
txHash: `0x${string}`
requestId: string

constructor(txHash: `0x${string}`, attemptCount: number) {
constructor(txHash: `0x${string}`, requestId: string, attemptCount: number) {
super(
`Failed to receive a successful response for solver status check with hash '${txHash}' after ${attemptCount} attempt(s).`
`Failed to receive a successful response for solver status check with hash '${txHash}' and request id '${requestId}' after ${attemptCount} attempt(s).`
)
this.name = 'SolverStatusTimeoutError'
this.txHash = txHash
this.requestId = requestId
}
}
15 changes: 9 additions & 6 deletions packages/sdk/src/utils/executeSteps/executeSteps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const mockAxiosRequest = () => {
}
if (
config.url?.includes('transactions/index') ||
config.url?.includes('/transactions/single') ||
config.url?.includes('/execute/permits')
) {
return Promise.resolve({
Expand Down Expand Up @@ -339,7 +340,7 @@ describe('Should test the executeSteps method.', () => {
undefined
)
).rejects.toThrow(
`Deposit transaction with hash '0x' is pending after 1 attempt(s).`
`Deposit transaction with hash '0x' and request id '0xabc' is pending after 1 attempt(s).`
)
vi.spyOn(axios, 'request').mockRestore()
vi.spyOn(axios, 'request').mockClear()
Expand Down Expand Up @@ -432,7 +433,7 @@ describe('Should test the executeSteps method.', () => {
undefined
)
).rejects.toThrow(
`Failed to receive a successful response for solver status check with hash '0x' after 1 attempt(s).`
`Failed to receive a successful response for solver status check with hash '0x' and request id '0xabc' after 1 attempt(s).`
)

vi.spyOn(axios, 'request').mockRestore()
Expand Down Expand Up @@ -495,6 +496,8 @@ describe('Should test the executeSteps method.', () => {
it('Should handle step with id of "approve" by waiting on receipt before polling for confirmation', async () => {
const axiosRequestSpy = vi.spyOn(axios, 'request')

client.logLevel = 4

await executeSteps(
1,
{},
Expand All @@ -506,12 +509,12 @@ describe('Should test the executeSteps method.', () => {

const waitForTransactionReceiptCallIndex =
wallet.handleConfirmTransactionStep.mock.invocationCallOrder[0]
const pollForConfirmationCallIndices = axiosRequestSpy.mock.calls
.filter((call) => call[0].url?.includes('/intents/status'))
.map((call, index) => axiosRequestSpy.mock.invocationCallOrder[index])
const pollForConfirmationCallIndex = axiosRequestSpy.mock.calls.findIndex(
(call) => call[0].url?.includes('/intents/status')
)

expect(waitForTransactionReceiptCallIndex).toBeLessThan(
Math.min(...pollForConfirmationCallIndices)
axiosRequestSpy.mock.invocationCallOrder[pollForConfirmationCallIndex]
)
expect(wallet.handleConfirmTransactionStep).toHaveBeenCalledTimes(2)
})
Expand Down
7 changes: 6 additions & 1 deletion packages/sdk/src/utils/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,15 @@ export async function sendTransactionSafely(

if (attemptCount >= maximumAttempts) {
if (receipt) {
throw new SolverStatusTimeoutError(txHash as Address, attemptCount)
throw new SolverStatusTimeoutError(
txHash as Address,
step.requestId ?? '',
attemptCount
)
} else {
throw new DepositTransactionTimeoutError(
txHash as Address,
step.requestId ?? '',
attemptCount
)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/sdk/tests/data/executeBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const executeBridge: Execute = {
"method": "GET"
}
}
]
],
"requestId": "0xabc"
}
],
"fees": {
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk/tests/data/swapWithApproval.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Execute } from '../../src/types'
import type { Execute } from '../../src/types'

export const swapWithApproval: Execute = {
steps: [
Expand All @@ -19,7 +19,8 @@ export const swapWithApproval: Execute = {
chainId: 1
}
}
]
],
requestId: '0xabc'
},
{
id: 'swap',
Expand All @@ -43,7 +44,8 @@ export const swapWithApproval: Execute = {
method: 'GET'
}
}
]
],
requestId: '0xabc'
}
],
fees: {
Expand Down