@@ -46,32 +46,38 @@ const jupiterSwap = async ({
46
46
} )
47
47
: null ;
48
48
49
- if ( routes && routes . routesInfos ) {
50
- // Prepare execute exchange
51
- const { execute } = await jupiter . exchange ( {
52
- routeInfo : routes ! . routesInfos [ 0 ] ,
53
- } ) ;
54
- // Execute swap
55
- // Force any to ignore TS misidentifying SwapResult type
56
- const swapResult : any = await execute ( ) ;
57
- if ( swapResult . error ) {
58
- console . log ( swapResult . error ) ;
59
- } else {
60
- // trying to keep these on one line
61
- process . stdout . write (
62
- `${ swapResult . inputAmount / ( 10 ** inputToken . decimals ) } `
63
- ) ;
64
- process . stdout . write ( `${ inputToken . symbol } -> ` ) ;
65
- process . stdout . write (
66
- `${ swapResult . outputAmount / ( 10 ** outputToken . decimals ) } `
67
- ) ;
68
- process . stdout . write ( `${ outputToken . symbol } : ` ) ;
69
- console . log ( `https://solscan.io/tx/${ swapResult . txid } ` ) ;
70
- }
49
+ if ( tradingEnabled ) {
50
+ if ( routes && routes . routesInfos ) {
51
+ // Prepare execute exchange
52
+ const { execute } = await jupiter . exchange ( {
53
+ routeInfo : routes ! . routesInfos [ 0 ] ,
54
+ } ) ;
55
+ // Execute swap
56
+ // Force any to ignore TS misidentifying SwapResult type
57
+ const swapResult : any = await execute ( ) ;
58
+ if ( swapResult . error ) {
59
+ console . log ( swapResult . error ) ;
60
+ } else {
61
+ // trying to keep these on one line
62
+ process . stdout . write (
63
+ `${ swapResult . inputAmount / ( 10 ** inputToken . decimals ) } `
64
+ ) ;
65
+ process . stdout . write ( `${ inputToken . symbol } -> ` ) ;
66
+ process . stdout . write (
67
+ `${ swapResult . outputAmount / ( 10 ** outputToken . decimals ) } `
68
+ ) ;
69
+ process . stdout . write ( `${ outputToken . symbol } : ` ) ;
70
+ console . log ( `https://solscan.io/tx/${ swapResult . txid } ` ) ;
71
+ }
72
+ } else {
73
+ console . log ( "Error during jupiter.computeRoutes()." ) ;
74
+ }
71
75
} else {
72
- console . log ( "Error during jupiter.computeRoutes() ." ) ;
76
+ console . log ( "Trading not enabled. You need to enable it in the .env for swaps to take place ." ) ;
73
77
}
74
- } catch ( error ) {
78
+
79
+
80
+ } catch ( error ) {
75
81
throw error ;
76
82
}
77
83
} ;
0 commit comments