-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b789bf7
Showing
20 changed files
with
350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: main | ||
pull_request: | ||
|
||
jobs: | ||
my-job: | ||
name: Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Setup Bun | ||
uses: oven-sh/setup-bun@v1 | ||
|
||
- name: Install dependencies | ||
run: bun i -p --frozen-lockfile | ||
|
||
- name: Run tests | ||
run: bun test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Dependencies | ||
/node_modules | ||
|
||
# Environment variables | ||
/.env* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"recommendations": ["biomejs.biome", "oven.bun-vscode"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"internalConsoleOptions": "openOnSessionStart", | ||
"name": "Debug", | ||
"program": "${workspaceFolder}/src/index.ts", | ||
"request": "launch", | ||
"type": "bun", | ||
"watchMode": "hot" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": "always" | ||
}, | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Use the official Bun image as the base | ||
FROM oven/bun:1 as base | ||
WORKDIR /usr/src/app | ||
|
||
# Install dependencies into a temporary directory to cache them and speed up future builds | ||
FROM base AS install | ||
RUN mkdir -p /temp/dev | ||
COPY package.json bun.lockb /temp/dev/ | ||
RUN cd /temp/dev && bun install --frozen-lockfile | ||
|
||
RUN cd /usr/src/app && ls | ||
|
||
# Install production dependencies only | ||
RUN mkdir -p /temp/prod | ||
COPY package.json bun.lockb /temp/prod/ | ||
RUN cd /temp/prod && bun install --frozen-lockfile --production | ||
|
||
RUN cd /usr/src/app && ls | ||
|
||
# Copy node_modules from the temporary directory, then copy all project files into the image | ||
FROM base AS prerelease | ||
COPY --from=install /temp/dev/node_modules /usr/src/app/node_modules | ||
COPY . /usr/src/app | ||
|
||
RUN cd /usr/src/app && ls | ||
|
||
# Copy production dependencies and source code into the final image | ||
FROM base AS release | ||
COPY --from=install /temp/prod/node_modules /usr/src/app/node_modules | ||
COPY --from=prerelease /usr/src/app/ /usr/src/app/ | ||
|
||
RUN cd /usr/src/app && ls | ||
|
||
# Set the user to 'bun', expose the application's port, and define the entry point | ||
USER bun | ||
EXPOSE 3000/tcp | ||
ENTRYPOINT ["bun", "run", "index.ts"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Bun WebSockets | ||
|
||
A simple WebSocket server to get started using Bun. | ||
|
||
![](../../actions/workflows/ci.yml/badge.svg) | ||
|
||
[![](https://railway.app/button.svg)](https://railway.app/template/BLofAq?referralCode=bonus) | ||
|
||
## Prerequisites | ||
|
||
- [<img src="https://github-production-user-asset-6210df.s3.amazonaws.com/17180392/266803654-ac5f086c-71ec-493a-a377-784cec2dc525.svg" height=19.2 align=center /> Bun](https://bun.sh/) `>=1.0.0` | ||
- [All-in-one toolkit](https://bun.sh/blog/bun-v1.0#bun-is-an-all-in-one-toolkit) | ||
- [JavaScript runtime](https://bun.sh/blog/bun-v1.0#bun-is-a-javascript-runtime) | ||
- [Package manager](https://bun.sh/blog/bun-v1.0#bun-is-a-package-manager) | ||
- [Test runner](https://bun.sh/blog/bun-v1.0#bun-is-a-test-runner) | ||
- [Bundler](https://bun.sh/blog/bun-v1.0#bun-is-a-bundler) | ||
|
||
## Getting Started | ||
|
||
1. **[Deploy on Railway](https://railway.app/template/BLofAq?referralCode=bonus)** or **[use this template](https://github.com/dayblox/bun-ws/generate)** | ||
|
||
2. **Clone** the repository | ||
|
||
3. **Install** dependencies | ||
|
||
```sh | ||
bun i | ||
``` | ||
|
||
## Usage | ||
|
||
- **Development** mode (**debug**) | ||
|
||
`F5` | ||
|
||
- Connecting to the Server using a WebSocket client | ||
|
||
```sh | ||
bunx wscat -c ws://localhost:3000 | ||
``` | ||
|
||
- Running **tests** (**watch** mode) | ||
|
||
```sh | ||
bun test --watch | ||
``` | ||
|
||
- **Production** mode | ||
|
||
```sh | ||
bun src/index.ts | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"files": { "ignore": ["node_modules/*"] }, | ||
"javascript": { | ||
"formatter": { | ||
"semicolons": "asNeeded" | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { app } from "./src"; | ||
|
||
app(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "bun-ts", | ||
"author": "dayblox", | ||
"description": "Bun + TypeScript starter", | ||
"devDependencies": { | ||
"bun-types": "latest" | ||
}, | ||
"scripts": { | ||
"start": "bun run src/index.ts" | ||
}, | ||
"dependencies": { | ||
"@coral-xyz/anchor": "^0.29.0", | ||
"@hxronetwork/dexterity-ts": "^1.6.33", | ||
"@solana/web3.js": "^1.90.0", | ||
"node-telegram-bot-api": "^0.64.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import dexterity, { Trader } from "@hxronetwork/dexterity-ts"; | ||
import { TransactionInstruction } from "@solana/web3.js"; | ||
|
||
export const accountPositioningHandler = async ( | ||
AppState: Map<string, any>, | ||
copiedTrader: Trader, | ||
trader: Trader | ||
) => { | ||
|
||
}; | ||
|
||
const tradeInfoHandler = async (trader: Trader) => { | ||
|
||
}; | ||
|
||
const copyInitialAccountHandler = async ( | ||
trader: Trader, | ||
traderPositions: Map<any, any>, | ||
copiedTraderPositions: Map<any, any>, | ||
positioningRatio: number | ||
) => { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Manifest, Trader } from "@hxronetwork/dexterity-ts"; | ||
import { PublicKey } from "@solana/web3.js"; | ||
import { accountPositioningHandler } from "./accountPositioningHandler"; | ||
|
||
export const handleNewSubscription = async ( | ||
trader: Trader, | ||
manifest: Manifest, | ||
newTrg: string | null, | ||
AppState: Map<string, any> | ||
) => { | ||
|
||
}; | ||
|
||
export const handleCancelSubscription = async ( | ||
AppState: Map<string, any> | ||
) => { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import dexterity, { Trader } from "@hxronetwork/dexterity-ts"; | ||
import { sendTradeMessageToUser } from "../bot"; | ||
import { Trade } from "./types"; | ||
|
||
export const tradeHandler = async ( | ||
req: Request, | ||
trader: Trader, | ||
CopiedTrader: undefined | Trader, | ||
AppState: Map<string, any> | ||
) => { | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export type Trade = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function cancelTraderSub() { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export async function newTraderSubHandler(trader: string) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import TelegramBot from "node-telegram-bot-api"; | ||
import { cancelTraderSub } from "./bot-utils/cancelTraderSubHandler"; | ||
import { newTraderSubHandler } from "./bot-utils/newTraderSubHandler"; | ||
|
||
const token = ""; | ||
const chatId = 1000000; | ||
|
||
const bot = new TelegramBot(token, { polling: true }); | ||
|
||
console.log("Bot is live"); | ||
|
||
bot.onText(/\/start/, (msg) => { | ||
const welcomeMessage = `Welcome to the Trade Copy Bot! 🤖 Here's how you can get started: | ||
- Use /help to view all the commands. | ||
- Use /newcopy {trg-pubkey} to subscribe to a new trader. | ||
- Use /cancelcopy to cancel the subscription. | ||
Feel free to explore and let me know if you have any questions!`; | ||
|
||
bot.sendMessage(msg.chat.id, welcomeMessage); | ||
}); | ||
|
||
bot.onText(/\/help/, (msg) => { | ||
const helpMessage = `Here's how to use the bot commands: | ||
- Use /help to view all the commands. | ||
- Use /newcopy {trg-pubkey} to subscribe to a new trader. | ||
- Use /cancelcopy to cancel the subscription. | ||
If you have any questions or need further assistance, please reach out!`; | ||
|
||
bot.sendMessage(msg.chat.id, helpMessage); | ||
}); | ||
|
||
bot.onText(/\/newcopy (.+)/, async (msg, match) => { | ||
if (msg.chat.id !== chatId) return; | ||
|
||
if (!match || !match[1]) { | ||
return bot.sendMessage( | ||
chatId, | ||
"Please provide the trader's TRG pubkey in the correct format: /newcopy {trg-pubkey}" | ||
); | ||
} | ||
|
||
bot.sendMessage(chatId, "Subscribing to trader..."); | ||
|
||
// handle subscribe to trader | ||
// send response to user | ||
}); | ||
|
||
bot.onText(/\/cancelcopy/, async (msg, match) => { | ||
if (msg.chat.id != chatId) return; | ||
|
||
if (!match) return bot.sendMessage(chatId, "Wrong format"); | ||
|
||
// handle cancel subscription | ||
// send response to user | ||
}); | ||
|
||
export const sendTradeMessageToUser = async (tradeInfo: any) => { | ||
// parse tradeInfo into message | ||
// send response to user | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Wallet } from "@coral-xyz/anchor"; | ||
import dexterity from "@hxronetwork/dexterity-ts"; | ||
import { Keypair, PublicKey } from "@solana/web3.js"; | ||
import { | ||
handleCancelSubscription, | ||
handleNewSubscription, | ||
} from "./api-utils/subscritionHandler"; | ||
import { tradeHandler } from "./api-utils/tradeHandler"; | ||
|
||
const AppState = new Map<string, any>(); | ||
|
||
export const app = async () => { | ||
const server = Bun.serve({ | ||
async fetch(req, server) { | ||
const url = new URL(req.url); | ||
const { pathname, searchParams } = url; | ||
|
||
let response: Response | undefined = new Response( | ||
JSON.stringify({ status: 200 }) | ||
); | ||
|
||
switch (pathname) { | ||
case "/process-trade": | ||
break; | ||
case "/new-subscription": | ||
break; | ||
case "/cancel-subscription": | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
if (!response) return new Response(JSON.stringify({ status: 200 })); | ||
return response; | ||
}, | ||
}); | ||
console.log(`${server.url}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowImportingTsExtensions": true, | ||
"allowJs": true, | ||
"allowSyntheticDefaultImports": true, | ||
"composite": true, | ||
"downlevelIteration": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react-jsx", | ||
"lib": ["ESNext"], | ||
"module": "ESNext", | ||
"moduleDetection": "force", | ||
"moduleResolution": "bundler", | ||
"noEmit": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"target": "ESNext", | ||
"types": ["bun-types"] | ||
} | ||
} |