diff --git a/.github/workflows/check-code.yml b/.github/workflows/dealer-check-code.yml similarity index 88% rename from .github/workflows/check-code.yml rename to .github/workflows/dealer-check-code.yml index 44987506..1deb149d 100644 --- a/.github/workflows/check-code.yml +++ b/.github/workflows/dealer-check-code.yml @@ -11,4 +11,4 @@ jobs: - uses: actions/setup-node@v2 - run: yarn install - name: Run check code - run: make check-code + run: make dealer-check-code diff --git a/.github/workflows/integration-test.yml b/.github/workflows/dealer-integration-test.yml similarity index 82% rename from .github/workflows/integration-test.yml rename to .github/workflows/dealer-integration-test.yml index 360b1427..26d9f077 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/dealer-integration-test.yml @@ -14,4 +14,4 @@ jobs: - uses: actions/setup-node@v2 - run: yarn install - name: Run integration tests - run: docker-compose up -d && make integration-in-ci + run: docker-compose up -d && make dealer-integration-in-ci diff --git a/.github/workflows/unit-test.yml b/.github/workflows/dealer-unit-test.yml similarity index 88% rename from .github/workflows/unit-test.yml rename to .github/workflows/dealer-unit-test.yml index 5b6aaa1d..7c55aeb8 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/dealer-unit-test.yml @@ -13,4 +13,4 @@ jobs: - uses: actions/setup-node@v2 - run: yarn install - name: Run unit tests - run: make unit-in-ci + run: make dealer-unit-in-ci diff --git a/Makefile b/Makefile index 6c07cf57..4fe1d99e 100644 --- a/Makefile +++ b/Makefile @@ -1,32 +1,22 @@ BIN_DIR=node_modules/.bin +clean-deps: + docker compose down -test: unit integration - -unit: - yarn test:unit - -integration: - yarn test:integration - -test-in-ci: +start-deps: docker compose up -d - . ./.envrc && \ - LOG_LEVEL=error node_modules/.bin/jest --bail --runInBand --ci --reporters=default --reporters=jest-junit + direnv reload +reset-deps: clean-deps start-deps -integration-in-ci: - docker compose up -d - . ./.envrc && \ - sleep 10 && \ - yarn migrate-ts up && \ - LOG_LEVEL=error $(BIN_DIR)/jest --config ./test/jest-integration.config.js --bail --runInBand --ci --reporters=default --reporters=jest-junit +dealer-integration-in-ci: + sleep 10 + yarn dealer migrate-ts up + yarn dealer ci:test:integration -unit-in-ci: - . ./.envrc && \ - LOG_LEVEL=warn $(BIN_DIR)/jest --config ./test/jest-unit.config.js --ci --bail +dealer-check-code: + yarn dealer tsc-check + yarn dealer eslint-check + yarn dealer build -check-code: - yarn tsc-check - yarn eslint-check - yarn prettier-check - yarn build +dealer-unit-in-ci: + . ./.envrc && yarn dealer ci:test:unit diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 664faaf3..072e2a6b 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -213,8 +213,8 @@ jobs: outputs: - name: image params: - CONTEXT: repo - DOCKERFILE: "repo/src/servers/graphql/Dockerfile" + CONTEXT: repo/dealer + DOCKERFILE: "repo/dealer/Dockerfile" run: path: build - put: fake-galoyapi-image diff --git a/src/app/Dockerfile b/dealer/Dockerfile similarity index 100% rename from src/app/Dockerfile rename to dealer/Dockerfile diff --git a/default.yaml b/dealer/default.yaml similarity index 100% rename from default.yaml rename to dealer/default.yaml diff --git a/migrations/20210922124019376_in-flight.sql b/dealer/migrations/20210922124019376_in-flight.sql similarity index 100% rename from migrations/20210922124019376_in-flight.sql rename to dealer/migrations/20210922124019376_in-flight.sql diff --git a/migrations/20210929033428698_last-on-chain-address.sql b/dealer/migrations/20210929033428698_last-on-chain-address.sql similarity index 100% rename from migrations/20210929033428698_last-on-chain-address.sql rename to dealer/migrations/20210929033428698_last-on-chain-address.sql diff --git a/migrations/20210929033443504_wallet.sql b/dealer/migrations/20210929033443504_wallet.sql similarity index 100% rename from migrations/20210929033443504_wallet.sql rename to dealer/migrations/20210929033443504_wallet.sql diff --git a/migrations/20210929033457300_on-chain-pay.sql b/dealer/migrations/20210929033457300_on-chain-pay.sql similarity index 100% rename from migrations/20210929033457300_on-chain-pay.sql rename to dealer/migrations/20210929033457300_on-chain-pay.sql diff --git a/migrations/20210929053822631_init-wallet.sql b/dealer/migrations/20210929053822631_init-wallet.sql similarity index 100% rename from migrations/20210929053822631_init-wallet.sql rename to dealer/migrations/20210929053822631_init-wallet.sql diff --git a/migrations/20210929053851879_init-last-on-chain-address.sql b/dealer/migrations/20210929053851879_init-last-on-chain-address.sql similarity index 100% rename from migrations/20210929053851879_init-last-on-chain-address.sql rename to dealer/migrations/20210929053851879_init-last-on-chain-address.sql diff --git a/migrations/20211209040742691_exchange-account-types.sql b/dealer/migrations/20211209040742691_exchange-account-types.sql similarity index 100% rename from migrations/20211209040742691_exchange-account-types.sql rename to dealer/migrations/20211209040742691_exchange-account-types.sql diff --git a/migrations/20211209040912709_init-exchange-account-types.sql b/dealer/migrations/20211209040912709_init-exchange-account-types.sql similarity index 100% rename from migrations/20211209040912709_init-exchange-account-types.sql rename to dealer/migrations/20211209040912709_init-exchange-account-types.sql diff --git a/migrations/20211209093445264_destination-address-types.sql b/dealer/migrations/20211209093445264_destination-address-types.sql similarity index 100% rename from migrations/20211209093445264_destination-address-types.sql rename to dealer/migrations/20211209093445264_destination-address-types.sql diff --git a/migrations/20211209093500708_init-destination-address-types.sql b/dealer/migrations/20211209093500708_init-destination-address-types.sql similarity index 100% rename from migrations/20211209093500708_init-destination-address-types.sql rename to dealer/migrations/20211209093500708_init-destination-address-types.sql diff --git a/migrations/20211209101408260_order-types.sql b/dealer/migrations/20211209101408260_order-types.sql similarity index 100% rename from migrations/20211209101408260_order-types.sql rename to dealer/migrations/20211209101408260_order-types.sql diff --git a/migrations/20211209101442617_init-order-types.sql b/dealer/migrations/20211209101442617_init-order-types.sql similarity index 100% rename from migrations/20211209101442617_init-order-types.sql rename to dealer/migrations/20211209101442617_init-order-types.sql diff --git a/migrations/20211209120600617_bill-types.sql b/dealer/migrations/20211209120600617_bill-types.sql similarity index 100% rename from migrations/20211209120600617_bill-types.sql rename to dealer/migrations/20211209120600617_bill-types.sql diff --git a/migrations/20211209120605508_init-bill-types.sql b/dealer/migrations/20211209120605508_init-bill-types.sql similarity index 100% rename from migrations/20211209120605508_init-bill-types.sql rename to dealer/migrations/20211209120605508_init-bill-types.sql diff --git a/migrations/20211209120614037_bill-subtypes.sql b/dealer/migrations/20211209120614037_bill-subtypes.sql similarity index 100% rename from migrations/20211209120614037_bill-subtypes.sql rename to dealer/migrations/20211209120614037_bill-subtypes.sql diff --git a/migrations/20211209120618491_init-bill-subtypes.sql b/dealer/migrations/20211209120618491_init-bill-subtypes.sql similarity index 100% rename from migrations/20211209120618491_init-bill-subtypes.sql rename to dealer/migrations/20211209120618491_init-bill-subtypes.sql diff --git a/migrations/20211209134543066_transactions.sql b/dealer/migrations/20211209134543066_transactions.sql similarity index 100% rename from migrations/20211209134543066_transactions.sql rename to dealer/migrations/20211209134543066_transactions.sql diff --git a/migrations/20211209134612913_orders.sql b/dealer/migrations/20211209134612913_orders.sql similarity index 100% rename from migrations/20211209134612913_orders.sql rename to dealer/migrations/20211209134612913_orders.sql diff --git a/migrations/20211209134637842_internal-transfers.sql b/dealer/migrations/20211209134637842_internal-transfers.sql similarity index 100% rename from migrations/20211209134637842_internal-transfers.sql rename to dealer/migrations/20211209134637842_internal-transfers.sql diff --git a/migrations/20211209134648670_external-transfers.sql b/dealer/migrations/20211209134648670_external-transfers.sql similarity index 100% rename from migrations/20211209134648670_external-transfers.sql rename to dealer/migrations/20211209134648670_external-transfers.sql diff --git a/dealer/package.json b/dealer/package.json new file mode 100644 index 00000000..eea21541 --- /dev/null +++ b/dealer/package.json @@ -0,0 +1,63 @@ +{ + "name": "dealer", + "version": "1.0.0", + "main": "index.js", + "repository": "git@github.com:GaloyMoney/dealer.git", + "author": "Sebastien Verreault ", + "license": "MIT", + "scripts": { + "tsc-check": "tsc --noEmit --skipLibCheck", + "eslint-check": "eslint \"src/**/*.ts\"", + "eslint-fix": "eslint \"src/**/*.ts\" --fix", + "build-og": "tsc -p tsconfig-build.json --skipLibCheck", + "build": "tsc -p tsconfig-build.json --skipLibCheck; cp -r ./src/database/sql ./lib/database/ && cp -r ./src/servers/price/proto ./lib/servers/price/", + "test:unit": "jest --config ./test/jest-unit.config.js --bail --verbose $TEST | yarn pino-pretty -c -l", + "test:integration": "jest --config ./test/jest-integration.config.js --bail --verbose $TEST | yarn pino-pretty -c -l", + "ci:test:unit": "LOGLEVEL=warn yarn jest --config ./test/jest-unit.config.js --ci --bail", + "ci:test:integration": "LOGLEVEL=warn yarn jest --config ./test/jest-integration.config.js --ci --bail", + "servers:graphql:pretty": "yarn build && node lib/servers/graphql/WalletGraphqlServer.js | pino-pretty -c -l", + "servers:graphql:elk": "yarn build && node lib/servers/graphql/WalletGraphqlServer.js | pino-elasticsearch", + "servers:exporter:pretty": "yarn build && node lib/servers/exporter/exporter.js | pino-pretty -c -l", + "servers:exporter:elk": "yarn build && node lib/servers/exporter/exporter.js | pino-elasticsearch", + "servers:price:pretty": "yarn build && node lib/servers/price/index.js | pino-pretty -c -l", + "servers:price-client:pretty": "yarn build && node lib/servers/price/sample_client.js | pino-pretty -c -l", + "app:scheduler:pretty": "yarn build && node lib/app/scheduler.js | pino-pretty -c -l", + "app:scheduler:elk": "yarn build && node lib/app/scheduler.js | pino-elasticsearch", + "app:dealer:pretty": "yarn build && node lib/app/dealer.js | pino-pretty -c -l", + "app:dealer:elk": "yarn build && node lib/app/dealer.js | pino-elasticsearch", + "migrate-js": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language js", + "migrate-sql": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language sql", + "migrate-ts": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language ts --tsconfig ./tsconfig.json " + }, + "dependencies": { + "@apollo/client": "^3.3.21", + "@grpc/grpc-js": "^1.5.3", + "@opentelemetry/instrumentation-grpc": "^0.27.0", + "@profusion/apollo-validation-directives": "^2.1.5", + "apollo-server-errors": "^2.5.0", + "apollo-server-express": "^2.25.2", + "black-scholes-model": "^1.0.10", + "ccxt": "^1.61.93", + "csv-parse": "^4.16.0", + "dateformat": "^4.5.1", + "dotenv": "^10.0.0", + "express": "^4.17.1", + "graphql": "^15.5.1", + "graphql-middleware": "^6.1.3", + "graphql-tools": "^8.1.0", + "humps": "^2.0.1", + "js-yaml": "^4.1.0", + "lodash": "^4.17.21", + "node-cron": "^3.0.0", + "node-fetch": "^2.6.1", + "node-pg-migrate": "^6.0.0", + "pg": "^8.7.1", + "pg-promise": "^10.11.0", + "pino": "^7.0.0-rc.1", + "pino-http": "^5.6.0", + "prom-client": "^13.2.0", + "ts-md5": "^1.2.10", + "typescript": "^4.5.5", + "uuid": "^8.3.2" + } +} diff --git a/proto/buf.gen.yaml b/dealer/proto/buf.gen.yaml similarity index 100% rename from proto/buf.gen.yaml rename to dealer/proto/buf.gen.yaml diff --git a/proto/buf.yaml b/dealer/proto/buf.yaml similarity index 100% rename from proto/buf.yaml rename to dealer/proto/buf.yaml diff --git a/proto/services/price/v1/price_service.proto b/dealer/proto/services/price/v1/price_service.proto similarity index 100% rename from proto/services/price/v1/price_service.proto rename to dealer/proto/services/price/v1/price_service.proto diff --git a/src/Dealer.ts b/dealer/src/Dealer.ts similarity index 100% rename from src/Dealer.ts rename to dealer/src/Dealer.ts diff --git a/src/DealerRemoteWallet.ts b/dealer/src/DealerRemoteWallet.ts similarity index 100% rename from src/DealerRemoteWallet.ts rename to dealer/src/DealerRemoteWallet.ts diff --git a/src/DealerSimulatedWallet.ts b/dealer/src/DealerSimulatedWallet.ts similarity index 100% rename from src/DealerSimulatedWallet.ts rename to dealer/src/DealerSimulatedWallet.ts diff --git a/src/DealerWalletFactory.ts b/dealer/src/DealerWalletFactory.ts similarity index 100% rename from src/DealerWalletFactory.ts rename to dealer/src/DealerWalletFactory.ts diff --git a/src/ExchangeBase.ts b/dealer/src/ExchangeBase.ts similarity index 100% rename from src/ExchangeBase.ts rename to dealer/src/ExchangeBase.ts diff --git a/src/ExchangeConfiguration.ts b/dealer/src/ExchangeConfiguration.ts similarity index 100% rename from src/ExchangeConfiguration.ts rename to dealer/src/ExchangeConfiguration.ts diff --git a/src/ExchangeTradingType.ts b/dealer/src/ExchangeTradingType.ts similarity index 100% rename from src/ExchangeTradingType.ts rename to dealer/src/ExchangeTradingType.ts diff --git a/src/GaloyWalletTypes.ts b/dealer/src/GaloyWalletTypes.ts similarity index 100% rename from src/GaloyWalletTypes.ts rename to dealer/src/GaloyWalletTypes.ts diff --git a/src/HedgingStrategyFactory.ts b/dealer/src/HedgingStrategyFactory.ts similarity index 100% rename from src/HedgingStrategyFactory.ts rename to dealer/src/HedgingStrategyFactory.ts diff --git a/src/HedgingStrategyTypes.ts b/dealer/src/HedgingStrategyTypes.ts similarity index 100% rename from src/HedgingStrategyTypes.ts rename to dealer/src/HedgingStrategyTypes.ts diff --git a/src/OkexExchange.ts b/dealer/src/OkexExchange.ts similarity index 100% rename from src/OkexExchange.ts rename to dealer/src/OkexExchange.ts diff --git a/src/OkexExchangeConfiguration.ts b/dealer/src/OkexExchangeConfiguration.ts similarity index 100% rename from src/OkexExchangeConfiguration.ts rename to dealer/src/OkexExchangeConfiguration.ts diff --git a/src/OkexPerpetualSwapStrategy.ts b/dealer/src/OkexPerpetualSwapStrategy.ts similarity index 100% rename from src/OkexPerpetualSwapStrategy.ts rename to dealer/src/OkexPerpetualSwapStrategy.ts diff --git a/src/Result.ts b/dealer/src/Result.ts similarity index 100% rename from src/Result.ts rename to dealer/src/Result.ts diff --git a/src/app/dealer.ts b/dealer/src/app/dealer.ts similarity index 100% rename from src/app/dealer.ts rename to dealer/src/app/dealer.ts diff --git a/src/app/scheduler.ts b/dealer/src/app/scheduler.ts similarity index 100% rename from src/app/scheduler.ts rename to dealer/src/app/scheduler.ts diff --git a/src/config.ts b/dealer/src/config.ts similarity index 100% rename from src/config.ts rename to dealer/src/config.ts diff --git a/src/database/connector.ts b/dealer/src/database/connector.ts similarity index 100% rename from src/database/connector.ts rename to dealer/src/database/connector.ts diff --git a/src/database/index.ts b/dealer/src/database/index.ts similarity index 100% rename from src/database/index.ts rename to dealer/src/database/index.ts diff --git a/src/database/models.ts b/dealer/src/database/models.ts similarity index 100% rename from src/database/models.ts rename to dealer/src/database/models.ts diff --git a/src/database/repositories/ExternalTransfersRepository.ts b/dealer/src/database/repositories/ExternalTransfersRepository.ts similarity index 100% rename from src/database/repositories/ExternalTransfersRepository.ts rename to dealer/src/database/repositories/ExternalTransfersRepository.ts diff --git a/src/database/repositories/GraphqlRepository.ts b/dealer/src/database/repositories/GraphqlRepository.ts similarity index 100% rename from src/database/repositories/GraphqlRepository.ts rename to dealer/src/database/repositories/GraphqlRepository.ts diff --git a/src/database/repositories/InFlightTransfersRepository.ts b/dealer/src/database/repositories/InFlightTransfersRepository.ts similarity index 100% rename from src/database/repositories/InFlightTransfersRepository.ts rename to dealer/src/database/repositories/InFlightTransfersRepository.ts diff --git a/src/database/repositories/InternalTransfersRepository.ts b/dealer/src/database/repositories/InternalTransfersRepository.ts similarity index 100% rename from src/database/repositories/InternalTransfersRepository.ts rename to dealer/src/database/repositories/InternalTransfersRepository.ts diff --git a/src/database/repositories/OrdersRepository.ts b/dealer/src/database/repositories/OrdersRepository.ts similarity index 100% rename from src/database/repositories/OrdersRepository.ts rename to dealer/src/database/repositories/OrdersRepository.ts diff --git a/src/database/repositories/TransactionsRepository.ts b/dealer/src/database/repositories/TransactionsRepository.ts similarity index 100% rename from src/database/repositories/TransactionsRepository.ts rename to dealer/src/database/repositories/TransactionsRepository.ts diff --git a/src/database/repositories/index.ts b/dealer/src/database/repositories/index.ts similarity index 100% rename from src/database/repositories/index.ts rename to dealer/src/database/repositories/index.ts diff --git a/src/database/sql/external_transfers/clear.sql b/dealer/src/database/sql/external_transfers/clear.sql similarity index 100% rename from src/database/sql/external_transfers/clear.sql rename to dealer/src/database/sql/external_transfers/clear.sql diff --git a/src/database/sql/external_transfers/get_count.sql b/dealer/src/database/sql/external_transfers/get_count.sql similarity index 100% rename from src/database/sql/external_transfers/get_count.sql rename to dealer/src/database/sql/external_transfers/get_count.sql diff --git a/src/database/sql/external_transfers/insert.sql b/dealer/src/database/sql/external_transfers/insert.sql similarity index 100% rename from src/database/sql/external_transfers/insert.sql rename to dealer/src/database/sql/external_transfers/insert.sql diff --git a/src/database/sql/graphql/get_last_on_chain_address.sql b/dealer/src/database/sql/graphql/get_last_on_chain_address.sql similarity index 100% rename from src/database/sql/graphql/get_last_on_chain_address.sql rename to dealer/src/database/sql/graphql/get_last_on_chain_address.sql diff --git a/src/database/sql/graphql/get_on_chain_pay.sql b/dealer/src/database/sql/graphql/get_on_chain_pay.sql similarity index 100% rename from src/database/sql/graphql/get_on_chain_pay.sql rename to dealer/src/database/sql/graphql/get_on_chain_pay.sql diff --git a/src/database/sql/graphql/get_wallet.sql b/dealer/src/database/sql/graphql/get_wallet.sql similarity index 100% rename from src/database/sql/graphql/get_wallet.sql rename to dealer/src/database/sql/graphql/get_wallet.sql diff --git a/src/database/sql/graphql/set_on_chain_pay.sql b/dealer/src/database/sql/graphql/set_on_chain_pay.sql similarity index 100% rename from src/database/sql/graphql/set_on_chain_pay.sql rename to dealer/src/database/sql/graphql/set_on_chain_pay.sql diff --git a/src/database/sql/in_flight_transfers/clear.sql b/dealer/src/database/sql/in_flight_transfers/clear.sql similarity index 100% rename from src/database/sql/in_flight_transfers/clear.sql rename to dealer/src/database/sql/in_flight_transfers/clear.sql diff --git a/src/database/sql/in_flight_transfers/complete.sql b/dealer/src/database/sql/in_flight_transfers/complete.sql similarity index 100% rename from src/database/sql/in_flight_transfers/complete.sql rename to dealer/src/database/sql/in_flight_transfers/complete.sql diff --git a/src/database/sql/in_flight_transfers/get_all.sql b/dealer/src/database/sql/in_flight_transfers/get_all.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_all.sql rename to dealer/src/database/sql/in_flight_transfers/get_all.sql diff --git a/src/database/sql/in_flight_transfers/get_pending.sql b/dealer/src/database/sql/in_flight_transfers/get_pending.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_pending.sql rename to dealer/src/database/sql/in_flight_transfers/get_pending.sql diff --git a/src/database/sql/in_flight_transfers/get_pending_count.sql b/dealer/src/database/sql/in_flight_transfers/get_pending_count.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_pending_count.sql rename to dealer/src/database/sql/in_flight_transfers/get_pending_count.sql diff --git a/src/database/sql/in_flight_transfers/get_pending_deposit.sql b/dealer/src/database/sql/in_flight_transfers/get_pending_deposit.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_pending_deposit.sql rename to dealer/src/database/sql/in_flight_transfers/get_pending_deposit.sql diff --git a/src/database/sql/in_flight_transfers/get_pending_withdraw.sql b/dealer/src/database/sql/in_flight_transfers/get_pending_withdraw.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_pending_withdraw.sql rename to dealer/src/database/sql/in_flight_transfers/get_pending_withdraw.sql diff --git a/src/database/sql/in_flight_transfers/get_this.sql b/dealer/src/database/sql/in_flight_transfers/get_this.sql similarity index 100% rename from src/database/sql/in_flight_transfers/get_this.sql rename to dealer/src/database/sql/in_flight_transfers/get_this.sql diff --git a/src/database/sql/in_flight_transfers/insert.sql b/dealer/src/database/sql/in_flight_transfers/insert.sql similarity index 100% rename from src/database/sql/in_flight_transfers/insert.sql rename to dealer/src/database/sql/in_flight_transfers/insert.sql diff --git a/src/database/sql/index.ts b/dealer/src/database/sql/index.ts similarity index 100% rename from src/database/sql/index.ts rename to dealer/src/database/sql/index.ts diff --git a/src/database/sql/internal_transfers/clear.sql b/dealer/src/database/sql/internal_transfers/clear.sql similarity index 100% rename from src/database/sql/internal_transfers/clear.sql rename to dealer/src/database/sql/internal_transfers/clear.sql diff --git a/src/database/sql/internal_transfers/get_count.sql b/dealer/src/database/sql/internal_transfers/get_count.sql similarity index 100% rename from src/database/sql/internal_transfers/get_count.sql rename to dealer/src/database/sql/internal_transfers/get_count.sql diff --git a/src/database/sql/internal_transfers/insert.sql b/dealer/src/database/sql/internal_transfers/insert.sql similarity index 100% rename from src/database/sql/internal_transfers/insert.sql rename to dealer/src/database/sql/internal_transfers/insert.sql diff --git a/src/database/sql/orders/clear.sql b/dealer/src/database/sql/orders/clear.sql similarity index 100% rename from src/database/sql/orders/clear.sql rename to dealer/src/database/sql/orders/clear.sql diff --git a/src/database/sql/orders/get_count.sql b/dealer/src/database/sql/orders/get_count.sql similarity index 100% rename from src/database/sql/orders/get_count.sql rename to dealer/src/database/sql/orders/get_count.sql diff --git a/src/database/sql/orders/get_side_count.sql b/dealer/src/database/sql/orders/get_side_count.sql similarity index 100% rename from src/database/sql/orders/get_side_count.sql rename to dealer/src/database/sql/orders/get_side_count.sql diff --git a/src/database/sql/orders/insert.sql b/dealer/src/database/sql/orders/insert.sql similarity index 100% rename from src/database/sql/orders/insert.sql rename to dealer/src/database/sql/orders/insert.sql diff --git a/src/database/sql/transactions/clear.sql b/dealer/src/database/sql/transactions/clear.sql similarity index 100% rename from src/database/sql/transactions/clear.sql rename to dealer/src/database/sql/transactions/clear.sql diff --git a/src/database/sql/transactions/get_count.sql b/dealer/src/database/sql/transactions/get_count.sql similarity index 100% rename from src/database/sql/transactions/get_count.sql rename to dealer/src/database/sql/transactions/get_count.sql diff --git a/src/database/sql/transactions/get_funding_fees_metrics.sql b/dealer/src/database/sql/transactions/get_funding_fees_metrics.sql similarity index 100% rename from src/database/sql/transactions/get_funding_fees_metrics.sql rename to dealer/src/database/sql/transactions/get_funding_fees_metrics.sql diff --git a/src/database/sql/transactions/get_last_bill_id.sql b/dealer/src/database/sql/transactions/get_last_bill_id.sql similarity index 100% rename from src/database/sql/transactions/get_last_bill_id.sql rename to dealer/src/database/sql/transactions/get_last_bill_id.sql diff --git a/src/database/sql/transactions/get_trading_fees_metrics.sql b/dealer/src/database/sql/transactions/get_trading_fees_metrics.sql similarity index 100% rename from src/database/sql/transactions/get_trading_fees_metrics.sql rename to dealer/src/database/sql/transactions/get_trading_fees_metrics.sql diff --git a/src/database/sql/transactions/get_type_count.sql b/dealer/src/database/sql/transactions/get_type_count.sql similarity index 100% rename from src/database/sql/transactions/get_type_count.sql rename to dealer/src/database/sql/transactions/get_type_count.sql diff --git a/src/database/sql/transactions/insert.sql b/dealer/src/database/sql/transactions/insert.sql similarity index 100% rename from src/database/sql/transactions/insert.sql rename to dealer/src/database/sql/transactions/insert.sql diff --git a/src/servers/exporter/exporter.ts b/dealer/src/servers/exporter/exporter.ts similarity index 100% rename from src/servers/exporter/exporter.ts rename to dealer/src/servers/exporter/exporter.ts diff --git a/src/servers/graphql/Dockerfile b/dealer/src/servers/graphql/Dockerfile similarity index 100% rename from src/servers/graphql/Dockerfile rename to dealer/src/servers/graphql/Dockerfile diff --git a/src/servers/graphql/WalletGraphqlServer.ts b/dealer/src/servers/graphql/WalletGraphqlServer.ts similarity index 100% rename from src/servers/graphql/WalletGraphqlServer.ts rename to dealer/src/servers/graphql/WalletGraphqlServer.ts diff --git a/src/servers/price/client_service.ts b/dealer/src/servers/price/client_service.ts similarity index 100% rename from src/servers/price/client_service.ts rename to dealer/src/servers/price/client_service.ts diff --git a/src/servers/price/errors.ts b/dealer/src/servers/price/errors.ts similarity index 100% rename from src/servers/price/errors.ts rename to dealer/src/servers/price/errors.ts diff --git a/src/servers/price/index.ts b/dealer/src/servers/price/index.ts similarity index 100% rename from src/servers/price/index.ts rename to dealer/src/servers/price/index.ts diff --git a/src/servers/price/index.types.d.ts b/dealer/src/servers/price/index.types.d.ts similarity index 100% rename from src/servers/price/index.types.d.ts rename to dealer/src/servers/price/index.types.d.ts diff --git a/src/servers/price/price_fetcher.ts b/dealer/src/servers/price/price_fetcher.ts similarity index 100% rename from src/servers/price/price_fetcher.ts rename to dealer/src/servers/price/price_fetcher.ts diff --git a/src/servers/price/proto/services/price/v1/price_service_grpc_pb.d.ts b/dealer/src/servers/price/proto/services/price/v1/price_service_grpc_pb.d.ts similarity index 100% rename from src/servers/price/proto/services/price/v1/price_service_grpc_pb.d.ts rename to dealer/src/servers/price/proto/services/price/v1/price_service_grpc_pb.d.ts diff --git a/src/servers/price/proto/services/price/v1/price_service_grpc_pb.js b/dealer/src/servers/price/proto/services/price/v1/price_service_grpc_pb.js similarity index 100% rename from src/servers/price/proto/services/price/v1/price_service_grpc_pb.js rename to dealer/src/servers/price/proto/services/price/v1/price_service_grpc_pb.js diff --git a/src/servers/price/proto/services/price/v1/price_service_pb.d.ts b/dealer/src/servers/price/proto/services/price/v1/price_service_pb.d.ts similarity index 100% rename from src/servers/price/proto/services/price/v1/price_service_pb.d.ts rename to dealer/src/servers/price/proto/services/price/v1/price_service_pb.d.ts diff --git a/src/servers/price/proto/services/price/v1/price_service_pb.js b/dealer/src/servers/price/proto/services/price/v1/price_service_pb.js similarity index 100% rename from src/servers/price/proto/services/price/v1/price_service_pb.js rename to dealer/src/servers/price/proto/services/price/v1/price_service_pb.js diff --git a/src/servers/price/sample_client.ts b/dealer/src/servers/price/sample_client.ts similarity index 100% rename from src/servers/price/sample_client.ts rename to dealer/src/servers/price/sample_client.ts diff --git a/src/services/logger.ts b/dealer/src/services/logger.ts similarity index 100% rename from src/services/logger.ts rename to dealer/src/services/logger.ts diff --git a/src/utils.ts b/dealer/src/utils.ts similarity index 100% rename from src/utils.ts rename to dealer/src/utils.ts diff --git a/test/data/scenario_01.csv b/dealer/test/data/scenario_01.csv similarity index 100% rename from test/data/scenario_01.csv rename to dealer/test/data/scenario_01.csv diff --git a/test/data/scenario_02.csv b/dealer/test/data/scenario_02.csv similarity index 100% rename from test/data/scenario_02.csv rename to dealer/test/data/scenario_02.csv diff --git a/test/data/scenario_03.csv b/dealer/test/data/scenario_03.csv similarity index 100% rename from test/data/scenario_03.csv rename to dealer/test/data/scenario_03.csv diff --git a/test/data/scenario_04.csv b/dealer/test/data/scenario_04.csv similarity index 100% rename from test/data/scenario_04.csv rename to dealer/test/data/scenario_04.csv diff --git a/test/data/scenario_05.csv b/dealer/test/data/scenario_05.csv similarity index 100% rename from test/data/scenario_05.csv rename to dealer/test/data/scenario_05.csv diff --git a/test/integration/Dealer.spec.ts b/dealer/test/integration/Dealer.spec.ts similarity index 100% rename from test/integration/Dealer.spec.ts rename to dealer/test/integration/Dealer.spec.ts diff --git a/test/integration/DealerPriceService.spec.ts b/dealer/test/integration/DealerPriceService.spec.ts similarity index 100% rename from test/integration/DealerPriceService.spec.ts rename to dealer/test/integration/DealerPriceService.spec.ts diff --git a/test/integration/ExternalTransfersRepository.spec.ts b/dealer/test/integration/ExternalTransfersRepository.spec.ts similarity index 100% rename from test/integration/ExternalTransfersRepository.spec.ts rename to dealer/test/integration/ExternalTransfersRepository.spec.ts diff --git a/test/integration/GraphqlRepository.spec.ts b/dealer/test/integration/GraphqlRepository.spec.ts similarity index 100% rename from test/integration/GraphqlRepository.spec.ts rename to dealer/test/integration/GraphqlRepository.spec.ts diff --git a/test/integration/InFlightTransfersRepository.spec.ts b/dealer/test/integration/InFlightTransfersRepository.spec.ts similarity index 100% rename from test/integration/InFlightTransfersRepository.spec.ts rename to dealer/test/integration/InFlightTransfersRepository.spec.ts diff --git a/test/integration/InternalTransfersRepository.spec.ts b/dealer/test/integration/InternalTransfersRepository.spec.ts similarity index 100% rename from test/integration/InternalTransfersRepository.spec.ts rename to dealer/test/integration/InternalTransfersRepository.spec.ts diff --git a/test/integration/OrdersRepository.spec.ts b/dealer/test/integration/OrdersRepository.spec.ts similarity index 100% rename from test/integration/OrdersRepository.spec.ts rename to dealer/test/integration/OrdersRepository.spec.ts diff --git a/test/integration/TransactionsRepository.spec.ts b/dealer/test/integration/TransactionsRepository.spec.ts similarity index 100% rename from test/integration/TransactionsRepository.spec.ts rename to dealer/test/integration/TransactionsRepository.spec.ts diff --git a/test/jest-clean-env.ts b/dealer/test/jest-clean-env.ts similarity index 100% rename from test/jest-clean-env.ts rename to dealer/test/jest-clean-env.ts diff --git a/test/jest-integration.config.js b/dealer/test/jest-integration.config.js similarity index 100% rename from test/jest-integration.config.js rename to dealer/test/jest-integration.config.js diff --git a/test/jest-test-sequencer.js b/dealer/test/jest-test-sequencer.js similarity index 100% rename from test/jest-test-sequencer.js rename to dealer/test/jest-test-sequencer.js diff --git a/test/jest-unit.config.js b/dealer/test/jest-unit.config.js similarity index 100% rename from test/jest-unit.config.js rename to dealer/test/jest-unit.config.js diff --git a/test/jest.setup.js b/dealer/test/jest.setup.js similarity index 100% rename from test/jest.setup.js rename to dealer/test/jest.setup.js diff --git a/test/mocks/ExchangeApiResponseHelper.ts b/dealer/test/mocks/ExchangeApiResponseHelper.ts similarity index 100% rename from test/mocks/ExchangeApiResponseHelper.ts rename to dealer/test/mocks/ExchangeApiResponseHelper.ts diff --git a/test/mocks/OkexScenarioStepBuilder.ts b/dealer/test/mocks/OkexScenarioStepBuilder.ts similarity index 100% rename from test/mocks/OkexScenarioStepBuilder.ts rename to dealer/test/mocks/OkexScenarioStepBuilder.ts diff --git a/test/mocks/ScenarioReader.ts b/dealer/test/mocks/ScenarioReader.ts similarity index 100% rename from test/mocks/ScenarioReader.ts rename to dealer/test/mocks/ScenarioReader.ts diff --git a/test/mocks/dealer-price/index.ts b/dealer/test/mocks/dealer-price/index.ts similarity index 100% rename from test/mocks/dealer-price/index.ts rename to dealer/test/mocks/dealer-price/index.ts diff --git a/test/unit/HedgingStrategyFactory.spec.ts b/dealer/test/unit/HedgingStrategyFactory.spec.ts similarity index 100% rename from test/unit/HedgingStrategyFactory.spec.ts rename to dealer/test/unit/HedgingStrategyFactory.spec.ts diff --git a/test/unit/OkexExchange.spec.ts b/dealer/test/unit/OkexExchange.spec.ts similarity index 100% rename from test/unit/OkexExchange.spec.ts rename to dealer/test/unit/OkexExchange.spec.ts diff --git a/test/unit/OkexExchangeConfiguration.spec.ts b/dealer/test/unit/OkexExchangeConfiguration.spec.ts similarity index 100% rename from test/unit/OkexExchangeConfiguration.spec.ts rename to dealer/test/unit/OkexExchangeConfiguration.spec.ts diff --git a/test/unit/OkexPerpetualSwapStrategy.spec.ts b/dealer/test/unit/OkexPerpetualSwapStrategy.spec.ts similarity index 100% rename from test/unit/OkexPerpetualSwapStrategy.spec.ts rename to dealer/test/unit/OkexPerpetualSwapStrategy.spec.ts diff --git a/test/utils/ScenarioBuilder.ts b/dealer/test/utils/ScenarioBuilder.ts similarity index 100% rename from test/utils/ScenarioBuilder.ts rename to dealer/test/utils/ScenarioBuilder.ts diff --git a/tsconfig-build.json b/dealer/tsconfig-build.json similarity index 100% rename from tsconfig-build.json rename to dealer/tsconfig-build.json diff --git a/dealer/tsconfig.json b/dealer/tsconfig.json new file mode 100644 index 00000000..b34b6491 --- /dev/null +++ b/dealer/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../tsconfig.base.json", + "compilerOptions": { + "outDir": "lib", + "baseUrl": "./" + }, + "include": ["src/**/*", "migrations/**/*", "test/**/*"] +} diff --git a/eslintrc.base.json b/eslintrc.base.json new file mode 100644 index 00000000..bfe8e08c --- /dev/null +++ b/eslintrc.base.json @@ -0,0 +1,75 @@ +{ + "env": { + "browser": true, + "es6": true, + "node": true + }, + "ignorePatterns": ["/*.js", "dist", "coverage"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "project": "tsconfig.json", + "sourceType": "module" + }, + "plugins": ["eslint-plugin-import", "@typescript-eslint", "prettier"], + "extends": [ + "eslint:recommended", + "plugin:import/recommended", + "plugin:import/typescript", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "rules": { + // Customized rules + "@typescript-eslint/no-extra-semi": "off", // Prettier work + "@typescript-eslint/no-unused-vars": "error", + "@typescript-eslint/prefer-for-of": "error", + "@typescript-eslint/unified-signatures": "error", + + "import/no-deprecated": "error", + "import/no-extraneous-dependencies": "error", + "import/no-unassigned-import": "error", + "import/no-unresolved": "off", + "import/order": ["error", { "newlines-between": "always-and-inside-groups" }], + + "prettier/prettier": [ + "error", + { + "semi": false, + "trailingComma": "all", + "printWidth": 90, + "quoteProps": "consistent", + "singleQuote": false, + "tabWidth": 2, + "useTabs": false, + "bracketSpacing": true, + "arrowParens": "always", + "proseWrap": "preserve", + "endOfLine": "lf" + } + ], + + "arrow-body-style": "off", + + "prefer-arrow-callback": "error", + "no-duplicate-imports": "error", + "no-empty-function": "error", + "no-empty": ["error", { "allowEmptyCatch": true }], + "no-new-wrappers": "error", + "no-param-reassign": "error", + "no-return-await": "error", + "no-sequences": "error", + "no-throw-literal": "error", + "no-void": "error", + + // Temporarily disabled recommended rules + "@typescript-eslint/explicit-module-boundary-types": "off", + "no-async-promise-executor": "off" + }, + "settings": { + "import/resolver": { + "node": { + "paths": ["."] + } + } + } +} diff --git a/junit.xml b/junit.xml new file mode 100644 index 00000000..01277005 --- /dev/null +++ b/junit.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/package.json b/package.json index 1ce5ac7b..0fb1aa3a 100644 --- a/package.json +++ b/package.json @@ -1,64 +1,17 @@ { - "name": "dealer", + "name": "galoy-dealer", "version": "1.0.0", - "main": "index.js", + "private": true, + "workspaces": ["dealer"], + "scripts": { + "clean": "rm -rf dealer/dist", + "dealer": "yarn workspace dealer" + }, "repository": "git@github.com:GaloyMoney/dealer.git", "author": "Sebastien Verreault ", "license": "MIT", - "scripts": { - "tsc-check": "tsc --noEmit --skipLibCheck", - "eslint-check": "eslint \"src/**/*.ts\"", - "eslint-fix": "eslint \"src/**/*.ts\" --fix", - "prettier-check": "prettier --check .", - "prettier-write": "prettier --write .", - "build-og": "tsc -p tsconfig-build.json --skipLibCheck", - "build": "tsc -p tsconfig-build.json --skipLibCheck; cp -r ./src/database/sql ./lib/database/ && cp -r ./src/servers/price/proto ./lib/servers/price/", - "test:unit": "jest --config ./test/jest-unit.config.js --bail --verbose $TEST | yarn pino-pretty -c -l", - "test:integration": "jest --config ./test/jest-integration.config.js --bail --verbose $TEST | yarn pino-pretty -c -l", - "servers:graphql:pretty": "yarn build && node lib/servers/graphql/WalletGraphqlServer.js | pino-pretty -c -l", - "servers:graphql:elk": "yarn build && node lib/servers/graphql/WalletGraphqlServer.js | pino-elasticsearch", - "servers:exporter:pretty": "yarn build && node lib/servers/exporter/exporter.js | pino-pretty -c -l", - "servers:exporter:elk": "yarn build && node lib/servers/exporter/exporter.js | pino-elasticsearch", - "servers:price:pretty": "yarn build && node lib/servers/price/index.js | pino-pretty -c -l", - "servers:price-client:pretty": "yarn build && node lib/servers/price/sample_client.js | pino-pretty -c -l", - "app:scheduler:pretty": "yarn build && node lib/app/scheduler.js | pino-pretty -c -l", - "app:scheduler:elk": "yarn build && node lib/app/scheduler.js | pino-elasticsearch", - "app:dealer:pretty": "yarn build && node lib/app/dealer.js | pino-pretty -c -l", - "app:dealer:elk": "yarn build && node lib/app/dealer.js | pino-elasticsearch", - "migrate-js": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language js", - "migrate-sql": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language sql", - "migrate-ts": "node-pg-migrate --create-schema true --schema dealer --migration-filename-format utc --migration-file-language ts --tsconfig ./tsconfig.json " - }, - "dependencies": { - "@apollo/client": "^3.3.21", - "@grpc/grpc-js": "^1.5.3", - "@opentelemetry/instrumentation-grpc": "^0.27.0", - "@profusion/apollo-validation-directives": "^2.1.5", - "apollo-server-errors": "^2.5.0", - "apollo-server-express": "^2.25.2", - "black-scholes-model": "^1.0.10", - "ccxt": "^1.61.93", - "csv-parse": "^4.16.0", - "dateformat": "^4.5.1", - "dotenv": "^10.0.0", - "express": "^4.17.1", - "graphql": "^15.5.1", - "graphql-middleware": "^6.1.3", - "graphql-tools": "^8.1.0", - "humps": "^2.0.1", - "js-yaml": "^4.1.0", - "lodash": "^4.17.21", - "node-cron": "^3.0.0", - "node-fetch": "^2.6.1", - "node-pg-migrate": "^6.0.0", - "pg": "^8.7.1", - "pg-promise": "^10.11.0", - "pino": "^7.0.0-rc.1", - "pino-http": "^5.6.0", - "prom-client": "^13.2.0", - "ts-md5": "^1.2.10", - "typescript": "^4.5.5", - "uuid": "^8.3.2" + "engines": { + "node": "16" }, "devDependencies": { "@jest/test-sequencer": "^27.0.6", diff --git a/src/servers/exporter/Dockerfile b/src/servers/exporter/Dockerfile deleted file mode 100644 index a51b1e48..00000000 --- a/src/servers/exporter/Dockerfile +++ /dev/null @@ -1,32 +0,0 @@ -FROM node:14-alpine AS BUILD_IMAGE - -WORKDIR /app - -RUN apk update && apk add git - -COPY ./*.json ./yarn.lock ./ - -RUN yarn install --frozen-lockfile - -COPY ./src ./src - - - -RUN yarn build - - - -FROM gcr.io/distroless/nodejs:14-debug -COPY --from=BUILD_IMAGE /app/lib /app/lib -COPY --from=BUILD_IMAGE /app/node_modules /app/node_modules - -WORKDIR /app -COPY ./*.js ./default.yaml ./package.json ./tsconfig.json ./yarn.lock ./.env ./ - -### debug only -COPY --from=BUILD_IMAGE /app/src /app/src -### - -USER 1000 - -CMD ["lib/servers/exporter/exporter.js"] diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 00000000..7fd8d26f --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "sourceMap": true, + "strict": true, + "target": "es2020", + "noImplicitAny": false, + "useUnknownInCatchVariables": false, + "esModuleInterop": true, + "moduleResolution": "node", + "resolveJsonModule": true + }, + "compileOnSave": true +}