Skip to content

Commit 37f6bb8

Browse files
Update index.ts
Updates for v3 compatibility with Jup v3, JNBI, have the env variable shared with the Jup module to read the production setting, add in flexibility to skip amms, specify fewer top route matches for efficiency and a few more optimizations.
1 parent 47aba81 commit 37f6bb8

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

src/index.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
require("dotenv").config();
2+
13
import fetch from "isomorphic-fetch";
2-
import { Jupiter, TOKEN_LIST_URL } from "@jup-ag/core";
4+
import { Jupiter, TOKEN_LIST_URL, SwapMode } from "@jup-ag/core";
35
import { PublicKey, Connection } from "@solana/web3.js";
46
import * as cron from "node-cron";
57
import cronstrue from "cronstrue";
6-
import {Token, MINT_ADDRESSES, USER_KEYPAIR, SOLANA_RPC_ENDPOINT} from "./constants";
8+
import {Token, MINT_ADDRESSES, USER_KEYPAIR, SOLANA_RPC_ENDPOINT, WRAP_UNWRAP_SOL} from "./constants";
79
import { dcaconfig } from './dcaconfig'
10+
import JSBI from 'jsbi';
811

912
const jupiterSwap = async ({
1013
jupiter,
@@ -24,16 +27,22 @@ const jupiterSwap = async ({
2427
return null;
2528
}
2629

27-
const inputAmountInSmallestUnits = inputToken
28-
? Math.round(inputAmount * 10 ** inputToken.decimals)
29-
: 0;
30+
const inputAmountInSmallestUnits = inputToken
31+
? JSBI.BigInt(Math.round(inputAmount * 10 ** inputToken.decimals))
32+
: JSBI.BigInt(0);
33+
3034
const routes = inputToken && outputToken
3135
? await jupiter.computeRoutes({
3236
inputMint: new PublicKey(inputToken.address),
3337
outputMint: new PublicKey(outputToken.address),
34-
inputAmount: inputAmountInSmallestUnits, // raw input amount of tokens
35-
slippage,
38+
amount: inputAmountInSmallestUnits,
39+
slippageBps: slippage,
40+
feeBps: 0,
3641
forceFetch: true,
42+
onlyDirectRoutes: false,
43+
filterTopNResult: 2,
44+
enforceSingleTx: false,
45+
swapMode: SwapMode.ExactIn,
3746
})
3847
: null;
3948

@@ -54,7 +63,7 @@ const jupiterSwap = async ({
5463
);
5564
process.stdout.write(`${inputToken.symbol} -> `);
5665
process.stdout.write(
57-
`${swapResult.outputAmount / (10 ** inputToken.decimals)} `
66+
`${swapResult.outputAmount / (10 ** outputToken.decimals)} `
5867
);
5968
process.stdout.write(`${outputToken.symbol}: `);
6069
console.log(`https://solscan.io/tx/${swapResult.txid}`);
@@ -77,12 +86,38 @@ const main = async () => {
7786
connection,
7887
cluster: cluster,
7988
user: USER_KEYPAIR,
89+
restrictIntermediateTokens: true,
90+
shouldLoadSerumOpenOrders: false,
91+
wrapUnwrapSOL: WRAP_UNWRAP_SOL,
92+
ammsToExclude: {
93+
Lifinity: false,
94+
GooseFX: true,
95+
'Raydium CLMM': false,
96+
Serum: true,
97+
Cropper: false,
98+
Cykura: false,
99+
Invariant: false,
100+
'Marco Polo': false,
101+
Openbook: false,
102+
Balansol: false,
103+
DeltaFi: false,
104+
Meteora: false,
105+
Crema: true,
106+
Step: false,
107+
Saber: false,
108+
Sencha: false,
109+
Raydium: false,
110+
Mercurial: false,
111+
Aldrin: false,
112+
Dradex: true,
113+
'Lifinity V2': false,
114+
}
80115
});
81116

82117
// Fetch token list from Jupiter API
83118
const tokens: Token[] = await (await fetch(TOKEN_LIST_URL[cluster])).json();
84119

85-
console.log("Warning! dcaconfig entries may be excluded due to:");
120+
console.log("Warning! dcaconfig entries may be excluded if there are errors with the:");
86121
console.log("- invalid cron expression");
87122
console.log("- inputToken or outputToken does not exist in MINT_ADDRESSES");
88123
console.log("Validating dcaconfig.ts ...");

0 commit comments

Comments
 (0)