Skip to content

Commit f4721c0

Browse files
committed
Send bridgeless deposits to auto-bot for submission
1 parent 025e49c commit f4721c0

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/swap/defi/bridgeless.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ import {
1515
EdgeCurrencyWallet,
1616
EdgeFetchFunction,
1717
EdgeSpendInfo,
18+
EdgeSwapApproveOptions,
1819
EdgeSwapInfo,
1920
EdgeSwapPlugin,
2021
EdgeSwapQuote,
2122
EdgeSwapRequest,
23+
EdgeSwapResult,
2224
EdgeToken,
2325
EdgeTokenId,
2426
EdgeTxActionSwap,
@@ -45,6 +47,7 @@ const swapInfo: EdgeSwapInfo = {
4547

4648
const BASE_URL = 'https://rpc-api.node0.mainnet.bridgeless.com'
4749
const ORDER_URL = 'https://tss1.mainnet.bridgeless.com'
50+
const AUTO_BOT_URL = 'https://autobot-wusa1.edge.app'
4851

4952
const EDGE_PLUGINID_CHAINID_MAP: Record<string, string> = {
5053
bitcoin: '0',
@@ -353,7 +356,50 @@ export function makeBridgelessPlugin(
353356

354357
const newRequest = await getMaxSwappable(fetchSwapQuoteInner, request)
355358
const swapOrder = await fetchSwapQuoteInner(newRequest)
356-
return await makeSwapPluginQuote(swapOrder)
359+
360+
const swapPluginQuote = await makeSwapPluginQuote(swapOrder)
361+
362+
// We'll save the swap result to avoid broadcasting the same transaction multiple times in case the autobot fetch fails
363+
let swapResult: EdgeSwapResult | undefined
364+
const out = {
365+
...swapPluginQuote,
366+
async approve(_opts?: EdgeSwapApproveOptions): Promise<EdgeSwapResult> {
367+
if (swapResult == null) {
368+
swapResult = await swapPluginQuote.approve(_opts)
369+
}
370+
const { txid } = swapResult.transaction
371+
372+
if (
373+
swapResult.transaction.savedAction?.actionType === 'swap' &&
374+
swapResult.transaction.savedAction.orderId != null
375+
) {
376+
swapResult.transaction.savedAction.orderId = swapResult.transaction.savedAction.orderId.replace(
377+
'{{TXID}}',
378+
txid
379+
)
380+
381+
const [
382+
chainId,
383+
,
384+
txNonce
385+
] = swapResult.transaction.savedAction.orderId.split('/')
386+
387+
const res = await opts.io.fetch(`${AUTO_BOT_URL}/api/bridgeless`, {
388+
method: 'PUT',
389+
headers: {
390+
'Content-Type': 'application/json'
391+
},
392+
body: JSON.stringify({ chainId, txHash: txid, txNonce })
393+
})
394+
if (!res.ok) {
395+
throw new Error('Failed to send txid to bridgeless submitter')
396+
}
397+
}
398+
return swapResult
399+
}
400+
}
401+
402+
return out
357403
}
358404
}
359405

0 commit comments

Comments
 (0)