Skip to content
Open
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/rich-lizards-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@relayprotocol/relay-svm-wallet-adapter': patch
---

Poll for signature instead of waiting for confirmation
39 changes: 25 additions & 14 deletions packages/relay-svm-wallet-adapter/src/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,35 @@ export const adaptSolanaWallet = (
// So we don't need to handle onReplaced and onCancelled
assertBase58TransactionSignature(txHash)

const { blockhash, lastValidBlockHeight } =
await connection.getLatestBlockhash('confirmed')
const POLL_INTERVAL_MS = 200
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might get rate limited by public rpcs with this interval

const MAX_POLL_DURATION_MS = 120_000
const start = Date.now()

const result = await connection.confirmTransaction({
blockhash: blockhash,
lastValidBlockHeight: lastValidBlockHeight,
signature: txHash
})
while (Date.now() - start < MAX_POLL_DURATION_MS) {
const { value } = await connection.getSignatureStatuses([txHash])
const status = value?.[0]

if (result.value.err) {
throw new Error(`Transaction failed: ${result.value.err}`)
}
if (status?.err) {
throw new Error(`Transaction failed: ${JSON.stringify(status.err)}`)
}

if (
status?.confirmationStatus === 'confirmed' ||
status?.confirmationStatus === 'finalized'
) {
return {
blockHash: status.slot.toString(),
blockNumber: status.slot,
txHash
}
}

return {
blockHash: result.context.slot.toString(),
blockNumber: result.context.slot,
txHash
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS))
}

throw new Error(
`Transaction confirmation timeout: ${txHash} was not confirmed within ${MAX_POLL_DURATION_MS / 1000}s`
)
},
switchChain: (chainId: number) => {
_chainId = chainId
Expand Down