-
Notifications
You must be signed in to change notification settings - Fork 202
feat: add BOB Gateway swapper (BTC ↔ BOB) #12275
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
Open
twblack88
wants to merge
1
commit into
develop
Choose a base branch
from
bob-swapper
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { Csp } from '../../../types' | ||
|
|
||
| export const csp: Csp = { | ||
| 'connect-src': ['https://gateway-api-mainnet.gobob.xyz'], | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/swapper/src/swappers/BobGatewaySwapper/BobGatewaySwapper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import type { Swapper } from '../../types' | ||
| import { executeEvmTransaction } from '../../utils' | ||
|
|
||
| export const bobGatewaySwapper: Swapper = { | ||
| executeEvmTransaction, | ||
| } |
163 changes: 163 additions & 0 deletions
163
packages/swapper/src/swappers/BobGatewaySwapper/endpoints.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,163 @@ | ||
| import { Configuration, V1Api } from '@gobob/bob-sdk' | ||
| import { evm } from '@shapeshiftoss/chain-adapters' | ||
| import { TxStatus } from '@shapeshiftoss/unchained-client' | ||
|
|
||
| import type { SwapperApi, UtxoFeeData } from '../../types' | ||
| import { getExecutableTradeStep, isExecutableTradeQuote } from '../../utils' | ||
| import { getTradeQuote } from './swapperApi/getTradeQuote' | ||
| import { getTradeRate } from './swapperApi/getTradeRate' | ||
| import { BOB_GATEWAY_BASE_URL } from './utils/constants' | ||
| import { mapBobGatewayOrderStatusToTxStatus } from './utils/helpers/helpers' | ||
|
|
||
| export const bobGatewayApi: SwapperApi = { | ||
| getTradeQuote, | ||
| getTradeRate, | ||
|
|
||
| getUnsignedUtxoTransaction: ({ | ||
| stepIndex, | ||
| tradeQuote, | ||
| xpub, | ||
| accountType, | ||
| assertGetUtxoChainAdapter, | ||
| }) => { | ||
| if (!isExecutableTradeQuote(tradeQuote)) | ||
| throw new Error('[BobGateway] unable to execute a trade rate') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
| const { accountNumber, bobSpecific, sellAsset } = step | ||
|
|
||
| if (!bobSpecific?.depositAddress) | ||
| throw new Error('[BobGateway] missing depositAddress in step metadata') | ||
| if (!bobSpecific?.orderId) throw new Error('[BobGateway] missing orderId in step metadata') | ||
|
|
||
| const adapter = assertGetUtxoChainAdapter(sellAsset.chainId) | ||
|
|
||
| return adapter.buildSendApiTransaction({ | ||
| value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit, | ||
| xpub, | ||
| to: bobSpecific.depositAddress, | ||
| accountNumber, | ||
| skipToAddressValidation: true, | ||
| chainSpecific: { | ||
| accountType, | ||
| satoshiPerByte: (step.feeData.chainSpecific as UtxoFeeData).satsPerByte, | ||
| }, | ||
| }) | ||
| }, | ||
|
|
||
| getUtxoTransactionFees: async ({ stepIndex, tradeQuote, xpub, assertGetUtxoChainAdapter }) => { | ||
| if (!isExecutableTradeQuote(tradeQuote)) | ||
| throw new Error('[BobGateway] unable to execute a trade rate') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
| const { bobSpecific, sellAsset } = step | ||
|
|
||
| if (!bobSpecific?.depositAddress) | ||
| throw new Error('[BobGateway] missing depositAddress in step metadata') | ||
|
|
||
| const adapter = assertGetUtxoChainAdapter(sellAsset.chainId) | ||
| const { fast } = await adapter.getFeeData({ | ||
| to: bobSpecific.depositAddress, | ||
| value: step.sellAmountIncludingProtocolFeesCryptoBaseUnit, | ||
| chainSpecific: { pubkey: xpub }, | ||
| sendMax: false, | ||
| }) | ||
|
|
||
| return fast.txFee | ||
| }, | ||
|
|
||
| getUnsignedEvmTransaction: async ({ | ||
| from, | ||
| stepIndex, | ||
| tradeQuote, | ||
| assertGetEvmChainAdapter, | ||
| supportsEIP1559, | ||
| }) => { | ||
| if (!isExecutableTradeQuote(tradeQuote)) | ||
| throw new Error('[BobGateway] unable to execute a trade rate') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
| const { accountNumber, bobSpecific, sellAsset } = step | ||
|
|
||
| if (!bobSpecific?.evmTx) throw new Error('[BobGateway] missing evmTx in step metadata') | ||
| if (!bobSpecific?.orderId) throw new Error('[BobGateway] missing orderId in step metadata') | ||
|
|
||
| const adapter = assertGetEvmChainAdapter(sellAsset.chainId) | ||
| const { to, data, value } = bobSpecific.evmTx | ||
|
|
||
| const feeData = await evm.getFees({ | ||
| adapter, | ||
| data: data || '0x', | ||
| to, | ||
| value, | ||
| from, | ||
| supportsEIP1559, | ||
| }) | ||
|
|
||
| return adapter.buildCustomApiTx({ | ||
| accountNumber, | ||
| from, | ||
| to, | ||
| value, | ||
| data: data || '0x', | ||
| ...feeData, | ||
| }) | ||
| }, | ||
|
|
||
| getEvmTransactionFees: async ({ | ||
| from, | ||
| stepIndex, | ||
| tradeQuote, | ||
| supportsEIP1559, | ||
| assertGetEvmChainAdapter, | ||
| }) => { | ||
| if (!isExecutableTradeQuote(tradeQuote)) | ||
| throw new Error('[BobGateway] unable to execute a trade rate') | ||
|
|
||
| const step = getExecutableTradeStep(tradeQuote, stepIndex) | ||
| const { bobSpecific, sellAsset } = step | ||
|
|
||
| if (!bobSpecific?.evmTx) throw new Error('[BobGateway] missing evmTx in step metadata') | ||
|
|
||
| const adapter = assertGetEvmChainAdapter(sellAsset.chainId) | ||
| const { to, data, value } = bobSpecific.evmTx | ||
|
|
||
| const { networkFeeCryptoBaseUnit } = await evm.getFees({ | ||
| adapter, | ||
| data: data || '0x', | ||
| to, | ||
| value, | ||
| from, | ||
| supportsEIP1559, | ||
| }) | ||
|
|
||
| return networkFeeCryptoBaseUnit | ||
| }, | ||
|
|
||
| checkTradeStatus: async ({ swap }) => { | ||
| const orderId = swap?.metadata.bobSpecific?.orderId | ||
| if (!orderId) throw new Error('[BobGateway] orderId is required for status check') | ||
|
|
||
| const api = new V1Api(new Configuration({ basePath: BOB_GATEWAY_BASE_URL })) | ||
|
|
||
| let orderInfo | ||
| try { | ||
| orderInfo = await api.getOrder({ id: orderId }) | ||
| } catch { | ||
| return { | ||
| buyTxHash: undefined, | ||
| status: TxStatus.Unknown, | ||
| message: 'Waiting for deposit...', | ||
| } | ||
| } | ||
|
|
||
| const status = mapBobGatewayOrderStatusToTxStatus(orderInfo.status) | ||
| const buyTxHash = orderInfo.dstInfo.txHash ?? undefined | ||
|
|
||
| return { | ||
| buyTxHash, | ||
| status, | ||
| message: undefined, | ||
| } | ||
| }, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export { bobGatewayApi } from './endpoints' | ||
| export { bobGatewaySwapper } from './BobGatewaySwapper' | ||
| export * from './utils/constants' |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't map every order lookup failure to “Waiting for deposit...”.
This masks real Bob Gateway/API failures as a user-actionable pending state. Only a true not-found/not-yet-indexed response should become
"Waiting for deposit..."; transport/server errors should surface as an error or at least preserve the last known status.🤖 Prompt for AI Agents