Skip to content

Commit 0393bd0

Browse files
committed
clean up
1 parent 7be11df commit 0393bd0

File tree

7 files changed

+32
-44
lines changed

7 files changed

+32
-44
lines changed

.env-example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RPC_ENDPOINT="https://ssc-dao.genesysgo.net"
2+
WALLET_PRIVATE_KEY=abc123def456

README.md

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,12 @@ Based on the [Jupiter Core Example](https://github.com/jup-ag/jupiter-core-examp
1010
yarn install
1111
```
1212
## Configure
13-
Create an `.env` file to store private info. Add the variables below.
14-
```
15-
CLUSTER=mainnet-beta
16-
WALLET_PRIVATE_KEY=abc123def456
17-
```
18-
Create your own `dcaconfig.ts`. See `dcaconfig-example.ts` for a template.
13+
1. Create an `.env` file at the project root. See `.env-example`.
14+
Can be obtained from Phantom via Settings -> Export Private Key.
15+
2. Create your own `dcaconfig.ts`. See `dcaconfig-example.ts` for a template.
1916

2017
To see example cron expressions, check out [crontab.guru](https://crontab.guru/).
2118
## Run
2219
```
2320
yarn start
2421
```
25-
## Development
26-
```
27-
yarn add --dev node-cron
28-
yarn add --dev @types/node-cron
29-
```

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "jup-dca-bot",
3-
"version": "1.0.0",
4-
"description": "dollar cost averaging bot",
3+
"version": "0.1.0",
4+
"description": "Dollar cost averaging bot on Solana",
55
"source": "src/index.ts",
66
"main": "src/index.ts",
77
"module": "dist/module.js",
@@ -15,18 +15,18 @@
1515
"dependencies": {
1616
"@jup-ag/core": "^1.0.0-beta.16",
1717
"@solana/wallet-adapter-base": "^0.7.1",
18+
"@solana/web3.js": "^1.36.0",
1819
"@types/bs58": "^4.0.1",
1920
"@types/isomorphic-fetch": "^0.0.35",
2021
"bs58": "^4.0.1",
2122
"dotenv": "^10.0.0",
2223
"isomorphic-fetch": "^3.0.0",
23-
"node-fetch": "^3.1.0",
24-
"ts-node": "^10.4.0"
24+
"node-cron": "^3.0.0",
25+
"node-fetch": "^3.1.0"
2526
},
2627
"devDependencies": {
27-
"@solana/web3.js": "^1.36.0",
2828
"@types/node-cron": "^3.0.1",
29-
"node-cron": "^3.0.0",
29+
"ts-node": "^10.7.0",
3030
"typescript": "^4.5.3"
3131
},
3232
"resolutions": {

src/constants/index.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
import { Cluster, Keypair } from "@solana/web3.js";
1+
import { Keypair } from "@solana/web3.js";
22
import bs58 from "bs58";
3-
43
import 'dotenv/config'
54

6-
// Endpoints, connection
7-
export const ENV: Cluster = (process.env.CLUSTER as Cluster) || "mainnet-beta";
8-
9-
// Sometimes, your RPC endpoint may reject you if you spam too many RPC calls. Sometimes, your PRC server
10-
// may have invalid cache and cause problems.
11-
export const SOLANA_RPC_ENDPOINT =
12-
ENV === "devnet"
13-
? "https://api.devnet.solana.com"
14-
: "https://ssc-dao.genesysgo.net";
5+
export const SOLANA_RPC_ENDPOINT: string = process.env.RPC_ENDPOINT!;
156

167
// Wallets
178
export const WALLET_PRIVATE_KEY =

src/dcaconfig-example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ export const dcaconfig: DcaConfig[] = [
2929
slippage: 1,
3030
cron: "* * * * *"
3131
},
32-
];
32+
];

src/index.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from "isomorphic-fetch";
2-
import { Jupiter, RouteInfo, TOKEN_LIST_URL } from "@jup-ag/core";
2+
import { Jupiter, TOKEN_LIST_URL } from "@jup-ag/core";
33
import { PublicKey, Connection } from "@solana/web3.js";
44
import * as cron from "node-cron";
55
import {
@@ -61,11 +61,11 @@ const jupiterSwap = async ({
6161
process.stdout.write(
6262
`${swapResult.outputAmount / (10 ** inputToken.decimals)} `
6363
);
64-
process.stdout.write(`${outputToken.symbol} -> `);
64+
process.stdout.write(`${outputToken.symbol}: `);
6565
console.log(`https://solscan.io/tx/${swapResult.txid}`);
6666
}
6767
} else {
68-
console.log("Error: Jupiter couldn't route.");
68+
console.log("Error during jupiter.computeRoutes().");
6969
}
7070
} catch (error) {
7171
throw error;
@@ -74,33 +74,36 @@ const jupiterSwap = async ({
7474

7575
const main = async () => {
7676
try {
77-
const connection = new Connection(SOLANA_RPC_ENDPOINT); // Setup Solana
77+
console.log("Starting Jupiter DCA Bot");
78+
79+
const cluster = "mainnet-beta"; // Force mainnet, as this uses Jupiter which is not deployed on devnet/testnet
80+
const connection = new Connection(SOLANA_RPC_ENDPOINT);
7881
const jupiter = await Jupiter.load({
7982
connection,
80-
cluster: ENV,
81-
user: USER_KEYPAIR, // or public key
83+
cluster: cluster,
84+
user: USER_KEYPAIR,
8285
});
8386

8487
// Fetch token list from Jupiter API
85-
const tokens: Token[] = await (await fetch(TOKEN_LIST_URL[ENV])).json();
88+
const tokens: Token[] = await (await fetch(TOKEN_LIST_URL[cluster])).json();
8689

87-
console.log("Validating dcaconfig.");
88-
console.log("A job may be excluded because:");
90+
console.log("Warning! dcaconfig entries may be excluded due to:");
8991
console.log("- invalid cron expression");
9092
console.log("- inputToken or outputToken does not exist in MINT_ADDRESSES");
93+
console.log("Validating dcaconfig.ts ...");
9194
const filteredJobs = dcaconfig.filter(job => {
9295
return (cron.validate(job.cron)
9396
&& job.inputToken in MINT_ADDRESSES
9497
&& job.outputToken in MINT_ADDRESSES
9598
);
9699
});
97100

98-
console.log("Scheduling the following jobs: ");
101+
console.log("Scheduling swaps:");
99102
filteredJobs.map(job => {
100103
console.log(`${job.amount} ${job.inputToken} -> ${job.outputToken}. cron: ${job.cron}`);
101104
});
102105

103-
const scheduledJobs = filteredJobs.map(job => {
106+
filteredJobs.forEach(job => {
104107
const inputToken = tokens.find((t) =>
105108
t.address == MINT_ADDRESSES[job.inputToken]
106109
);

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,10 +1235,10 @@ traverse-chain@~0.1.0:
12351235
resolved "https://registry.yarnpkg.com/traverse-chain/-/traverse-chain-0.1.0.tgz#61dbc2d53b69ff6091a12a168fd7d433107e40f1"
12361236
integrity sha1-YdvC1Ttp/2CRoSoWj9fUMxB+QPE=
12371237

1238-
ts-node@^10.4.0:
1239-
version "10.6.0"
1240-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.6.0.tgz#c3f4195d5173ce3affdc8f2fd2e9a7ac8de5376a"
1241-
integrity sha512-CJen6+dfOXolxudBQXnVjRVvYTmTWbyz7cn+xq2XTsvnaXbHqr4gXSCNbS2Jj8yTZMuGwUoBESLaOkLascVVvg==
1238+
ts-node@^10.7.0:
1239+
version "10.7.0"
1240+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.7.0.tgz#35d503d0fab3e2baa672a0e94f4b40653c2463f5"
1241+
integrity sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==
12421242
dependencies:
12431243
"@cspotcode/source-map-support" "0.7.0"
12441244
"@tsconfig/node10" "^1.0.7"

0 commit comments

Comments
 (0)