Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for burn address recipient when executing a quote #419

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
6 changes: 6 additions & 0 deletions .changeset/nasty-terms-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@reservoir0x/relay-sdk': patch
'@reservoir0x/relay-kit-ui': patch
---

Fix dead address being allowed as burn address
5 changes: 5 additions & 0 deletions packages/sdk/src/actions/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '../utils/index.js'
import { type WalletClient } from 'viem'
import { isViemWalletClient } from '../utils/viemWallet.js'
import { isDeadAddress } from '../constants/address.js'

export type ExecuteActionParameters = {
quote: Execute
Expand Down Expand Up @@ -49,6 +50,10 @@ export async function execute(data: ExecuteActionParameters) {
throw new Error('Missing chainId from quote')
}

if (isDeadAddress(quote?.details?.recipient)) {
throw new Error('Recipient should never be burn address')
}

const { request, ...restOfQuote } = quote
const _quote = safeStructuredClone(restOfQuote)

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/actions/getQuote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ describe('Should test the getQuote action.', () => {
expect.objectContaining({
url: expect.stringContaining('quote'),
data: expect.objectContaining({
user: '0x0000000000000000000000000000000000000000',
user: '0x000000000000000000000000000000000000dead',
destinationCurrency: '0x0000000000000000000000000000000000000000',
destinationChainId: 1,
originCurrency: '0x0000000000000000000000000000000000000000',
originChainId: 8453,
amount: '1000000000000000',
recipient: '0x0000000000000000000000000000000000000000',
recipient: '0x000000000000000000000000000000000000dead',
tradeType: 'EXACT_INPUT'
})
})
Expand Down Expand Up @@ -106,13 +106,13 @@ describe('Should test the getQuote action.', () => {
expect.objectContaining({
url: expect.stringContaining('quote'),
data: expect.objectContaining({
user: '0x0000000000000000000000000000000000000000',
user: '0x000000000000000000000000000000000000dead',
destinationCurrency: '0x0000000000000000000000000000000000000000',
destinationChainId: 1,
originCurrency: '0x0000000000000000000000000000000000000000',
originChainId: 8453,
amount: '1000000000000000',
recipient: '0x0000000000000000000000000000000000000000',
recipient: '0x000000000000000000000000000000000000dead',
tradeType: 'EXACT_INPUT',
txs: [{ data: '0x', value: '0', to: '0x' }]
})
Expand Down
17 changes: 15 additions & 2 deletions packages/sdk/src/actions/getQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { isViemWalletClient } from '../utils/viemWallet.js'
import { getClient } from '../client.js'
import type { AdaptedWallet, Execute, paths } from '../types/index.js'
import { getDeadAddress } from '../constants/address.js'

export type QuoteBody = NonNullable<
paths['/quote']['post']['requestBody']['content']['application/json']
Expand Down Expand Up @@ -85,14 +86,26 @@ export async function getQuote(
})
}

const fromChain = client.chains.find((chain) => chain.id === chainId)
const toChain = client.chains.find((chain) => chain.id === toChainId)

const originDeadAddress = fromChain
? getDeadAddress(fromChain.vmType, fromChain.id)
: undefined
const destinationDeadAddress = toChain
? getDeadAddress(toChain.vmType, toChain.id)
: undefined

const query: QuoteBody = {
user: caller || zeroAddress,
user: caller || originDeadAddress || zeroAddress,
destinationCurrency: toCurrency,
destinationChainId: toChainId,
originCurrency: currency,
originChainId: chainId,
amount,
recipient: recipient ? (recipient as string) : caller ?? zeroAddress,
recipient: recipient
? (recipient as string)
: caller || destinationDeadAddress || zeroAddress,
tradeType,
referrer: client.source || undefined,
txs: preparedTransactions,
Expand Down
17 changes: 17 additions & 0 deletions packages/sdk/src/constants/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ export const getDeadAddress = (vmType?: ChainVM, chainId?: number) => {
return evmDeadAddress
}
}

export const isDeadAddress = (address?: string) => {
if (!address) {
return false
}

if (
address === eclipseDeadAddress ||
address === solDeadAddress ||
address === bitcoinDeadAddress ||
address === evmDeadAddress
) {
return true
}

return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ export const TransactionModalRenderer: FC<Props> = ({
wallet ?? adaptViemWallet(walletClient.data as WalletClient)

const activeWalletChainId = await _wallet?.getChainId()

if (fromToken && fromToken?.chainId !== activeWalletChainId) {
onAnalyticEvent?.(EventNames.SWAP_SWITCH_NETWORK, {
activeWalletChainId,
Expand Down
Loading