Skip to content

Commit

Permalink
Use node instead of ts-node (#49)
Browse files Browse the repository at this point in the history
* fix test

* use node instead of ts-node

* fix some filenames
  • Loading branch information
Vritra4 authored Apr 15, 2024
1 parent 1a49462 commit cc0a5e9
Show file tree
Hide file tree
Showing 49 changed files with 175 additions and 167 deletions.
13 changes: 9 additions & 4 deletions bots/dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
FROM node:20-alpine AS builder
WORKDIR /usr/src/app

COPY package*.json ./
COPY . .

RUN npm install
RUN npm run build

COPY . .

FROM node:20-alpine
WORKDIR /usr/src/app

COPY --from=builder /usr/src/app ./
COPY --from=builder /usr/src/app/dist ./dist
COPY package*.json ./
RUN npm install

COPY entrypoint.sh ./
RUN ["chmod", "+x", "./entrypoint.sh"]

EXPOSE 5000
EXPOSE 5001

RUN ["chmod", "+x", "./entrypoint.sh"]
ENTRYPOINT [ "./entrypoint.sh" ]
4 changes: 2 additions & 2 deletions bots/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions bots/package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
{
"name": "@initia/rollup",
"version": "0.1.0",
"version": "0.1.1",
"description": "Optimistic rollup for initia",
"main": "index.js",
"engines": {
"node": ">=16"
},
"scripts": {
"executor": "export WORKER_NAME=executor && node --stack_size=4096 --max-old-space-size=4096 -r ts-node/register/transpile-only -r tsconfig-paths/register src/worker/bridgeExecutor/index.ts",
"batch": "export WORKER_NAME=batch && node --stack_size=4096 --max-old-space-size=4096 -r ts-node/register/transpile-only -r tsconfig-paths/register src/worker/batchSubmitter/index.ts",
"challenge": "export WORKER_NAME=challenge && node --stack_size=4096 --max-old-space-size=4096 -r ts-node/register/transpile-only -r tsconfig-paths/register src/worker/challengeSubmitter/index.ts",
"output": "export WORKER_NAME=output && node --stack_size=4096 --max-old-space-size=4096 -r ts-node/register/transpile-only -r tsconfig-paths/register src/worker/outputSubmitter/index.ts",
"executor": "WORKER_NAME=executor node dist/worker/bridgeExecutor/index.js",
"batch": "WORKER_NAME=batch node dist/worker/batchSubmitter/index.js",
"challenge": "WORKER_NAME=challenge node dist/worker/challengeSubmitter/index.js",
"output": "WORKER_NAME=output node dist/worker/outputSubmitter/index.js",
"test": "jest",
"test:integration": "export NODE_ENV=test && node --stack_size=4096 --max-old-space-size=4096 -r ts-node/register/transpile-only -r tsconfig-paths/register src/test/integration.ts",
"prettier": "prettier --write ./src/**/**/**/**/*.ts",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
"do": "npm run build && node -r tsconfig-paths/register ./dist/loader/generateApiDoc.js",
"apidoc": "npm run do",
"prepublishOnly": "npm run build",
"build": "tsc --build",
"clean": "tsc --build --clean",
"l2setup": "export NODE_ENV=test && npm run build && node ./dist/scripts/setupL2.js"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion bots/src/celestia/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sequenceLenBytes, shareInfoBytes, shareSize } from './builder';
import { createCommitment } from './commitment';
import { namespaceSize } from './namespace';
import { config } from 'config';
import { config } from '../config';
import { Blob } from '@initia/initia.js';

// constants
Expand Down
2 changes: 1 addition & 1 deletion bots/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LCDClient } from '@initia/initia.js';
import { validateCelestiaConfig } from 'celestia/utils';
import { validateCelestiaConfig } from './celestia/utils';
import * as dotenv from 'dotenv';

const envFile =
Expand Down
8 changes: 4 additions & 4 deletions bots/src/controller/executor/ClaimTxController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
Get,
Controller,
} from 'koa-joi-controllers';
import { ErrorTypes } from 'lib/error';
import { error, success } from 'lib/response';
import { getClaimTxList } from 'service';
import { ErrorTypes } from '../../lib/error';
import { error, success } from '../../lib/response';
import { getClaimTxList } from '../../service';
import { responses, routeConfig, z } from 'koa-swagger-decorator'
import { GetClaimResponse } from 'sawgger/executor_model';
import { GetClaimResponse } from '../../swagger/executor_model';

@Controller('')
export class ClaimTxController extends KoaController {
Expand Down
8 changes: 4 additions & 4 deletions bots/src/controller/executor/DepositTxController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
Get,
Controller,
} from 'koa-joi-controllers';
import { ErrorTypes } from 'lib/error';
import { error, success } from 'lib/response';
import { getDepositTxList } from 'service';
import { ErrorTypes } from '../../lib/error';
import { error, success } from '../../lib/response';
import { getDepositTxList } from '../../service';
import { responses, routeConfig, z } from 'koa-swagger-decorator'
import { GetDepositResponse } from 'sawgger/executor_model';
import { GetDepositResponse } from '../../swagger/executor_model';

@Controller('')
export class DepositTxController extends KoaController {
Expand Down
8 changes: 4 additions & 4 deletions bots/src/controller/executor/OutputController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
Get,
Controller,
} from 'koa-joi-controllers';
import { ErrorTypes } from 'lib/error';
import { error, success } from 'lib/response';
import { ErrorTypes } from '../../lib/error';
import { error, success } from '../../lib/response';
import { responses, routeConfig, z } from 'koa-swagger-decorator'
import { getOutputList } from 'service';
import { GetOutputResponse } from 'sawgger/executor_model';
import { getOutputList } from '../../service';
import { GetOutputResponse } from '../../swagger/executor_model';

@Controller('')
export class OutputController extends KoaController {
Expand Down
8 changes: 4 additions & 4 deletions bots/src/controller/executor/WithdrawalTxController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {
Get,
Controller,
} from 'koa-joi-controllers';
import { ErrorTypes } from 'lib/error';
import { error, success } from 'lib/response';
import { getWithdrawalTxList } from 'service';
import { ErrorTypes } from '../../lib/error';
import { error, success } from '../../lib/response';
import { getWithdrawalTxList } from '../../service';
import { responses, routeConfig, z } from 'koa-swagger-decorator'
import { GetWithdrawalResponse } from 'sawgger/executor_model';
import { GetWithdrawalResponse } from '../../swagger/executor_model';

@Controller('')
export class WithdrawalTxController extends KoaController {
Expand Down
4 changes: 2 additions & 2 deletions bots/src/worker/batchSubmitter/db.ts → bots/src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import {
DataSourceOptions
} from 'typeorm';
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
import CamelToSnakeNamingStrategy from 'orm/CamelToSnakeNamingStrategy';
import CamelToSnakeNamingStrategy from '../orm/CamelToSnakeNamingStrategy';

const debug = require('debug')('orm');

import { RecordEntity, ExecutorOutputEntity } from 'orm';
import { RecordEntity, ExecutorOutputEntity } from '../orm';

const staticOptions = {
supportBigNumbers: true,
Expand Down
2 changes: 1 addition & 1 deletion bots/src/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as winston from 'winston';
import DailyRotateFile from 'winston-daily-rotate-file';
import { config } from 'config';
import { config } from '../config';

function createLogger(name: string) {
const formats = [winston.format.errors({ stack: true })];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { BlockInfo, Event, LCDClient, TxInfo } from '@initia/initia.js';
import { getLatestOutputFromExecutor, getOutputFromExecutor } from 'lib/query';
import { WithdrawStorage } from 'lib/storage';
import { WithdrawalTx } from 'lib/types';
import { sha3_256 } from 'lib/util';
import OutputEntity from 'orm/executor/OutputEntity';
import { getLatestOutputFromExecutor, getOutputFromExecutor } from '../query';
import { WithdrawStorage } from '../storage';
import { WithdrawalTx } from '../types';
import { sha3_256 } from '../util';
import OutputEntity from '../../orm/executor/OutputEntity';
import { EntityManager, EntityTarget, ObjectLiteral } from 'typeorm';

class MonitorHelper {
Expand Down
1 change: 1 addition & 0 deletions bots/src/lib/monitor/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Monitor } from './monitor';
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Monitor } from './Monitor';
import { Monitor } from './monitor';
import { Coin, Msg, MsgFinalizeTokenDeposit } from '@initia/initia.js';
import {
ExecutorDepositTxEntity,
ExecutorUnconfirmedTxEntity,
ExecutorOutputEntity,
} from 'orm';
} from '../../orm';
import { EntityManager } from 'typeorm';
import { RPCClient, RPCSocket } from 'lib/rpc';
import { getDB } from './db';
import { RPCClient, RPCSocket } from '../rpc';
import { getDB } from '../../worker/bridgeExecutor/db';
import winston from 'winston';
import { config } from 'config';
import { TxWallet, WalletType, getWallet, initWallet } from 'lib/wallet';
import { config } from '../../config';
import { TxWallet, WalletType, getWallet, initWallet } from '../wallet';

export class L1Monitor extends Monitor {
executor: TxWallet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ExecutorOutputEntity, ExecutorWithdrawalTxEntity } from 'orm';
import { Monitor } from './Monitor';
import { WithdrawStorage } from 'lib/storage';
import { WithdrawalTx } from 'lib/types';
import { ExecutorOutputEntity, ExecutorWithdrawalTxEntity } from '../../orm';
import { Monitor } from './monitor';
import { WithdrawStorage } from '../storage';
import { WithdrawalTx } from '../types';
import { EntityManager } from 'typeorm';
import { BlockInfo } from '@initia/initia.js';
import { getDB } from './db';
import { RPCClient, RPCSocket } from 'lib/rpc';
import { getDB } from '../../worker/bridgeExecutor/db';
import { RPCClient, RPCSocket } from '../rpc';
import winston from 'winston';
import { config } from 'config';
import { getBridgeInfo } from 'lib/query';
import { config } from '../../config';
import { getBridgeInfo } from '../query';

export class L2Monitor extends Monitor {
submissionInterval: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Bluebird from 'bluebird';
import { RPCClient, RPCSocket } from 'lib/rpc';
import { StateEntity } from 'orm';
import { RPCClient, RPCSocket } from '../rpc';
import { StateEntity } from '../../orm';
import { DataSource, EntityManager } from 'typeorm';
import MonitorHelper from './MonitorHelper';
import MonitorHelper from './helper';
import winston from 'winston';
import { INTERVAL_MONITOR, config } from 'config';
import { INTERVAL_MONITOR, config } from '../../config';

const MAX_BLOCKS = 20; // DO NOT CHANGE THIS, hard limit is 20 in cometbft.
const MAX_RETRY_INTERVAL = 30_000;
Expand Down
2 changes: 1 addition & 1 deletion bots/src/lib/query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BridgeInfo, OutputInfo, TokenPair } from '@initia/initia.js';
import { config } from 'config';
import { config } from '../config';
import {
DepositTxResponse,
OutputResponse,
Expand Down
6 changes: 3 additions & 3 deletions bots/src/lib/slack.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Wallet } from '@initia/initia.js';
import axios from 'axios';
import BigNumber from 'bignumber.js';
import { config } from 'config';
import { config } from '../config';
import * as http from 'http';
import * as https from 'https';
import UnconfirmedTxEntity from 'orm/executor/UnconfirmedTxEntity';
import { ChallengedOutputEntity } from 'orm/index';
import UnconfirmedTxEntity from '../orm/executor/UnconfirmedTxEntity';
import { ChallengedOutputEntity } from '../orm/index';

const ax = axios.create({
httpAgent: new http.Agent({ keepAlive: true }),
Expand Down
6 changes: 3 additions & 3 deletions bots/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import DepositTxEntity from 'orm/executor/DepositTxEntity';
import WithdrawalTxEntity from 'orm/executor/WithdrawalTxEntity';
import { ExecutorOutputEntity } from 'orm/index';
import DepositTxEntity from '../orm/executor/DepositTxEntity';
import WithdrawalTxEntity from '../orm/executor/WithdrawalTxEntity';
import { ExecutorOutputEntity } from '../orm/index';

export interface WithdrawalTx {
bridge_id: bigint;
Expand Down
2 changes: 1 addition & 1 deletion bots/src/lib/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Coins
} from '@initia/initia.js';
import { sendTx } from './tx';
import { config } from 'config';
import { config } from '../config';
import { buildNotEnoughBalanceNotification, notifySlack } from './slack';

export enum WalletType {
Expand Down
6 changes: 3 additions & 3 deletions bots/src/loader/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import morgan from 'koa-morgan'
// import helmet from 'koa-helmet'
import serve from 'koa-static'
import mount from 'koa-mount'
import { APIError, ErrorTypes, errorHandler } from 'lib/error'
import { error } from 'lib/response'
import { APIError, ErrorTypes, errorHandler } from '../lib/error'
import { error } from '../lib/response'
import { KoaController, configureRoutes } from 'koa-joi-controllers'
import { router as swaggerRouter } from 'sawgger/swagger'
import { router as swaggerRouter } from '../swagger/swagger'

const notFoundMiddleware: Koa.Middleware = (ctx) => {
ctx.status = 404
Expand Down
4 changes: 2 additions & 2 deletions bots/src/scripts/setupL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
BridgeInfo,
MsgSetBridgeInfo
} from '@initia/initia.js';
import { sendTx } from 'lib/tx';
import { config } from 'config';
import { sendTx } from '../lib/tx';
import { config } from '../config';

export const executor = new Wallet(
config.l1lcd,
Expand Down
8 changes: 4 additions & 4 deletions bots/src/service/batch/BatchService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RecordEntity } from 'orm';
import { APIError, ErrorTypes } from 'lib/error';
import { getDB } from 'worker/batchSubmitter/db';
import { config } from 'config';
import { RecordEntity } from '../../orm';
import { APIError, ErrorTypes } from '../../lib/error';
import { getDB } from '../../lib/db';
import { config } from '../../config';

interface L1BatchInfo {
type: 'l1';
Expand Down
8 changes: 4 additions & 4 deletions bots/src/service/executor/ClaimTxService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
ExecutorWithdrawalTxEntity,
ExecutorOutputEntity,
} from 'orm';
import { getDB } from 'worker/bridgeExecutor/db';
import { APIError, ErrorTypes } from 'lib/error';
import { sha3_256 } from 'lib/util';
} from '../../orm';
import { getDB } from '../../lib/db';
import { APIError, ErrorTypes } from '../../lib/error';
import { sha3_256 } from '../../lib/util';


interface ClaimTx {
Expand Down
4 changes: 2 additions & 2 deletions bots/src/service/executor/DepositTxService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorDepositTxEntity } from 'orm';
import { getDB } from 'worker/bridgeExecutor/db';
import { ExecutorDepositTxEntity } from '../../orm';
import { getDB } from '../../lib/db';

export interface GetDepositTxListParam {
sequence?: number
Expand Down
4 changes: 2 additions & 2 deletions bots/src/service/executor/OutputService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorOutputEntity } from 'orm';
import { getDB } from 'worker/bridgeExecutor/db';
import { ExecutorOutputEntity } from '../../orm';
import { getDB } from '../../lib/db';

export interface GetOutputListParam {
output_index?: number
Expand Down
4 changes: 2 additions & 2 deletions bots/src/service/executor/WithdrawalTxService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ExecutorWithdrawalTxEntity } from 'orm';
import { getDB } from 'worker/bridgeExecutor/db';
import { ExecutorWithdrawalTxEntity } from '../../orm';
import { getDB } from '../../lib/db';

export interface GetWithdrawalTxListParam {
sequence?: number
Expand Down
File renamed without changes.
File renamed without changes.
8 changes: 4 additions & 4 deletions bots/src/sawgger/swagger.ts → bots/src/swagger/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SwaggerRouter } from 'koa-swagger-decorator'
import { DepositTxController } from 'controller/executor/DepositTxController'
import { OutputController } from 'controller/executor/OutputController'
import { WithdrawalTxController } from 'controller/executor/WithdrawalTxController'
import { ClaimTxController } from 'controller/executor/ClaimTxController'
import { DepositTxController } from '../controller/executor/DepositTxController'
import { OutputController } from '../controller/executor/OutputController'
import { WithdrawalTxController } from '../controller/executor/WithdrawalTxController'
import { ClaimTxController } from '../controller/executor/ClaimTxController'

const router = new SwaggerRouter({
spec: {
Expand Down
Loading

0 comments on commit cc0a5e9

Please sign in to comment.