@@ -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 ,
@@ -40,11 +42,12 @@ const swapInfo: EdgeSwapInfo = {
4042 pluginId,
4143 displayName : 'Bridgeless' ,
4244 isDex : true ,
43- orderUri : undefined ,
44454546}
4647
4748const BASE_URL = 'https://rpc-api.node0.mainnet.bridgeless.com'
49+ const ORDER_URL = 'https://tss1.mainnet.bridgeless.com'
50+ const AUTO_BOT_URL = 'https://autobot-wusa1.edge.app'
4851
4952const EDGE_PLUGINID_CHAINID_MAP : Record < string , string > = {
5053 bitcoin : '0' ,
@@ -237,11 +240,18 @@ export function makeBridgelessPlugin(
237240 }
238241 }
239242
243+ // chainId/txid/outputIndex
244+ // output index is 0 for both Bitcoin (output of actual deposit) and Zano (index of serviceEntries with deposit instructions)
245+ // txid must be 0x prefixed
246+ const orderId = `${ fromChainId } /0x{{TXID}}/0`
247+
240248 const assetAction : EdgeAssetAction = {
241249 assetActionType : 'swap'
242250 }
243251 const savedAction : EdgeTxActionSwap = {
244252 actionType : 'swap' ,
253+ orderId,
254+ orderUri : `${ ORDER_URL } /check/${ orderId } ` ,
245255 swapInfo,
246256 isEstimate : false ,
247257 toAsset : {
@@ -267,6 +277,7 @@ export function makeBridgelessPlugin(
267277
268278 const spendInfo : EdgeSpendInfo = {
269279 otherParams : {
280+ outputSort : 'targets' ,
270281 memoIndex : 1
271282 } ,
272283 tokenId : request . fromTokenId ,
@@ -290,8 +301,6 @@ export function makeBridgelessPlugin(
290301 }
291302 case 'zano' : {
292303 const bodyData = {
293- service_id : 'B' ,
294- instruction : 'BI' ,
295304 dst_add : toAddress ,
296305 dst_net_id : toChainId ,
297306 uniform_padding : ' '
@@ -309,10 +318,8 @@ export function makeBridgelessPlugin(
309318 {
310319 body : bodyHex ,
311320 flags : 0 ,
312- instruction : 'K' ,
313- security :
314- 'd8f6e37f28a632c06b0b3466db1b9d2d1b36a580ee35edfd971dc1423bc412a5' ,
315- service_id : 'C'
321+ instruction : 'BI' ,
322+ service_id : 'B'
316323 }
317324 ]
318325 }
@@ -350,7 +357,50 @@ export function makeBridgelessPlugin(
350357
351358 const newRequest = await getMaxSwappable ( fetchSwapQuoteInner , request )
352359 const swapOrder = await fetchSwapQuoteInner ( newRequest )
353- return await makeSwapPluginQuote ( swapOrder )
360+
361+ const swapPluginQuote = await makeSwapPluginQuote ( swapOrder )
362+
363+ // We'll save the swap result to avoid broadcasting the same transaction multiple times in case the autobot fetch fails
364+ let swapResult : EdgeSwapResult | undefined
365+ const out = {
366+ ...swapPluginQuote ,
367+ async approve ( _opts ?: EdgeSwapApproveOptions ) : Promise < EdgeSwapResult > {
368+ if ( swapResult == null ) {
369+ swapResult = await swapPluginQuote . approve ( _opts )
370+ }
371+ const { txid } = swapResult . transaction
372+
373+ if (
374+ swapResult . transaction . savedAction ?. actionType === 'swap' &&
375+ swapResult . transaction . savedAction . orderId != null
376+ ) {
377+ swapResult . transaction . savedAction . orderId = swapResult . transaction . savedAction . orderId . replace (
378+ '{{TXID}}' ,
379+ txid
380+ )
381+
382+ const [
383+ chainId ,
384+ ,
385+ txNonce
386+ ] = swapResult . transaction . savedAction . orderId . split ( '/' )
387+
388+ const res = await opts . io . fetch ( `${ AUTO_BOT_URL } /api/bridgeless` , {
389+ method : 'PUT' ,
390+ headers : {
391+ 'Content-Type' : 'application/json'
392+ } ,
393+ body : JSON . stringify ( { chainId, txHash : txid , txNonce } )
394+ } )
395+ if ( ! res . ok ) {
396+ throw new Error ( 'Failed to send txid to bridgeless submitter' )
397+ }
398+ }
399+ return swapResult
400+ }
401+ }
402+
403+ return out
354404 }
355405 }
356406
0 commit comments