Skip to content

Commit da4ef24

Browse files
Update index.ts
Add in the tradingEnabled override
1 parent 91a790c commit da4ef24

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

src/index.ts

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,38 @@ const jupiterSwap = async ({
4646
})
4747
: null;
4848

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+
}
7175
} 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.");
7377
}
74-
} catch (error) {
78+
79+
80+
} catch (error) {
7581
throw error;
7682
}
7783
};

0 commit comments

Comments
 (0)