Skip to content

Commit

Permalink
update app name to bot and init services
Browse files Browse the repository at this point in the history
  • Loading branch information
vasemkin committed Jan 30, 2024
1 parent 683f233 commit 484ad8d
Show file tree
Hide file tree
Showing 31 changed files with 10,383 additions and 13,705 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ testem.log
.DS_Store
Thumbs.db

.nx/cache
.nx/cache

.env
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "all",
"printWidth": 100,
"printWidth": 80,
"useTabs": true,
"singleQuote": true,
"bracketSpacing": true,
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions apps/ddca/jest.config.ts → apps/bot/jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/* eslint-disable */
export default {
displayName: 'ddca',
displayName: 'bot',
preset: '../../jest.preset.js',
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
'^.+\\.[tj]s$': [
'ts-jest',
{ tsconfig: '<rootDir>/tsconfig.spec.json' },
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/apps/ddca',
coverageDirectory: '../../coverage/apps/bot',
}
22 changes: 11 additions & 11 deletions apps/ddca/project.json → apps/bot/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ddca",
"name": "bot",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "apps/ddca/src",
"sourceRoot": "apps/bot/src",
"projectType": "application",
"targets": {
"build": {
Expand All @@ -11,11 +11,11 @@
"options": {
"target": "node",
"compiler": "tsc",
"outputPath": "dist/apps/ddca",
"main": "apps/ddca/src/main.ts",
"tsConfig": "apps/ddca/tsconfig.app.json",
"assets": ["apps/ddca/src/assets"],
"webpackConfig": "apps/ddca/webpack.config.js"
"outputPath": "dist/apps/bot",
"main": "apps/bot/src/main.ts",
"tsConfig": "apps/bot/tsconfig.app.json",
"assets": ["apps/bot/src/assets"],
"webpackConfig": "apps/bot/webpack.config.js"
},
"configurations": {
"development": {},
Expand All @@ -26,14 +26,14 @@
"executor": "@nx/js:node",
"defaultConfiguration": "development",
"options": {
"buildTarget": "ddca:build"
"buildTarget": "bot:build"
},
"configurations": {
"development": {
"buildTarget": "ddca:build:development"
"buildTarget": "bot:build:development"
},
"production": {
"buildTarget": "ddca:build:production"
"buildTarget": "bot:build:production"
}
}
},
Expand All @@ -45,7 +45,7 @@
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "apps/ddca/jest.config.ts"
"jestConfig": "apps/bot/jest.config.ts"
}
}
},
Expand Down
12 changes: 12 additions & 0 deletions apps/bot/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Strategy } from '@jupjup/constants'
import { parseUSDC } from '@jupjup/utils'

export type AppConfig = {
tradingStrategy: Strategy
startingFundsUSDC: string
}

export const DEFAULT_CONFIG: AppConfig = {
tradingStrategy: Strategy.DDCA,
startingFundsUSDC: parseUSDC(10).result,
}
17 changes: 17 additions & 0 deletions apps/bot/src/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'
import { ScheduleModule } from '@nestjs/schedule'

import { AppService } from './app.service'
import { TradingModule } from '../trading/trading.module'

@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
ScheduleModule.forRoot(),
TradingModule,
],
controllers: [],
providers: [AppService],
})
export class AppModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { Test } from '@nestjs/testing'

import { AppService } from './app.service'

import { SOLANA_NATIVE_SOL_ADDRESS, SOLANA_WEN_ADDRESS } from '@jupjup/constants'
import {
SOLANA_NATIVE_SOL_ADDRESS,
SOLANA_WEN_ADDRESS,
} from '@jupjup/constants'
import { getQuote } from '@jupjup/jupiter-client'

describe('AppService', () => {
Expand All @@ -16,7 +19,7 @@ describe('AppService', () => {
service = app.get<AppService>(AppService)
})

describe.only('getData', () => {
describe('getData', () => {
it('should get data from jupiter client', async () => {
expect(
await getQuote({
Expand Down
4 changes: 4 additions & 0 deletions apps/bot/src/app/app.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Injectable } from '@nestjs/common'

@Injectable()
export class AppService {}
File renamed without changes.
4 changes: 3 additions & 1 deletion apps/ddca/src/main.ts → apps/bot/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ async function bootstrap() {
app.setGlobalPrefix(globalPrefix)
const port = process.env.PORT || 3000
await app.listen(port)
Logger.log(`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`)
Logger.log(
`🚀 Application is running on: http://localhost:${port}/${globalPrefix}`,
)
}

bootstrap()
18 changes: 18 additions & 0 deletions apps/bot/src/trading/trading.controller.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing'
import { TradingController } from './trading.controller'

describe('TradingController', () => {
let controller: TradingController

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [TradingController],
}).compile()

controller = module.get<TradingController>(TradingController)
})

it('should be defined', () => {
expect(controller).toBeDefined()
})
})
4 changes: 4 additions & 0 deletions apps/bot/src/trading/trading.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common'

@Controller('trading')
export class TradingController {}
11 changes: 11 additions & 0 deletions apps/bot/src/trading/trading.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common'
import { ConfigModule } from '@nestjs/config'

import { TradingService } from './trading.service'
import { TradingController } from './trading.controller'

@Module({
controllers: [TradingController],
providers: [TradingService],
})
export class TradingModule {}
25 changes: 25 additions & 0 deletions apps/bot/src/trading/trading.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing'
import { ConfigModule } from '@nestjs/config'
import { ScheduleModule } from '@nestjs/schedule'

import { TradingService } from './trading.service'

describe('TradingService', () => {
let service: TradingService

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [TradingService],
imports: [
ConfigModule.forRoot({ isGlobal: true }),
ScheduleModule.forRoot(),
],
}).compile()

service = module.get<TradingService>(TradingService)
})

it('should be defined', () => {
expect(service).toBeDefined()
})
})
26 changes: 26 additions & 0 deletions apps/bot/src/trading/trading.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'

import { Connection, Keypair, VersionedTransaction } from '@solana/web3.js'
import { Wallet } from '@coral-xyz/anchor'
import bs58 from 'bs58'

type RouteMap = Record<string, string[]>

@Injectable()
export class TradingService {
wallet: Wallet

constructor(private configService: ConfigService) {
// this is set in the monorepo root
const pk = this.configService.get('NX_SOLANA_PK') || ''

this.wallet = new Wallet(Keypair.fromSecretKey(bs58.decode(pk)))

const address = this.wallet.publicKey

Logger.log(
`Wallet at address ${address.toString()} loaded successfully!`,
)
}
}
File renamed without changes.
File renamed without changes.
7 changes: 6 additions & 1 deletion apps/ddca/tsconfig.spec.json → apps/bot/tsconfig.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
]
}
File renamed without changes.
6 changes: 0 additions & 6 deletions apps/ddca/src/app/app.config.ts

This file was deleted.

22 changes: 0 additions & 22 deletions apps/ddca/src/app/app.controller.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions apps/ddca/src/app/app.controller.ts

This file was deleted.

11 changes: 0 additions & 11 deletions apps/ddca/src/app/app.module.ts

This file was deleted.

8 changes: 0 additions & 8 deletions apps/ddca/src/app/app.service.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './lib/utils'
export * from './lib/spl'
30 changes: 0 additions & 30 deletions libs/utils/src/lib/slp.spec.ts

This file was deleted.

30 changes: 30 additions & 0 deletions libs/utils/src/lib/spl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { parseUSDC } from './spl'

describe('parseUSDC', () => {
it('should correctly parse a whole number amount', () => {
expect(parseUSDC(10).result).toBe('10000000')
})

it('should correctly parse floats', () => {
expect(parseUSDC(10.5).result).toBe('10500000')
})

it('should correctly handle zero', () => {
expect(parseUSDC(0).result).toBe('0')
})

it('should handle very large numbers', () => {
expect(parseUSDC(123456789.123456).result).toBe('123456789123456')
})

it('should throw an error for negative numbers', () => {
expect(parseUSDC(-1).error).toBe('Invalid input')
})

it('should throw an error for non-numeric inputs', () => {
// @ts-ignore
expect(parseUSDC('abc').error).toBe('Invalid input')
// @ts-ignore
expect(parseUSDC(undefined).error).toBe('Invalid input')
})
})
Loading

0 comments on commit 484ad8d

Please sign in to comment.