Skip to content

FatKidddd/tokkalabs

Repository files navigation

Getting Started

  1. Clone this repository: git clone [email protected]:FatKidddd/tokkalabs.git
  2. Navigate to the project directory: cd tokkalabs
  3. Create a .env file from .env.local cp .env.local .env, fill in missing API key

Development (preferred)

  1. Start db: sudo docker-compose -f db-only.yml up -d
  2. Install deps: yarn install
  3. Run tests to verify: yarn test
  4. Run express server & script: yarn start:dev
  5. Visit http://localhost:3000/api-docs to interact with Swagger UI
  6. sudo docker-compose down to stop all services

Note: to set up pre-commit linting + prettier yarn husky:prepare

Database commands (to view live addition of txn fees in db)

  1. To access db: sudo docker exec -it txnfeesdb psql -U user -d txnfeesdb
  2. To view all txnfees SELECT * from txnfees;

Production (takes a while to build & can't see tests log)

  1. Start db & express server (takes 3 mins to build): sudo docker-compose up --build
  2. Visit http://localhost:3000/api-docs to interact with Swagger UI
  3. sudo docker-compose down to stop all services

Planning

Functionality

  • (txn hash) -> USDT txn fee

    • find in db
      • if found:
        • retrieve from db
        • return USDT txn fee
      • else:
        • query txn hash from etherscan
          • parse fields
        • using timeStamp, query binance API klines with startTime = timeStamp - epsilon, endTime = timeStamp + epsilon, where epsilon is probably some seconds
          • mid = (low + high) / 2
        • add to db
        • return USDT txn fee
  • (Batch job) (startBlock, endBlock) -> transactions with all their prices

    • function that takes in (startBlock, endBlock) -> populate db

DB schema

  1. txn hash
  2. timeStamp
  3. gasUsed
  4. gasPrice
  5. binance ETHUSDT price
  6. txn fee in USDT

Notes

Useful Binance API live data - websocket current avg price historical data - use klines / candlesticks OHLC

Useful Etherscan API live data - websocket ERC20 transfers historical - convert timestamps into closest blocks, query using start and end blocks

Further improvements

  • Use Redis for caching
  • (not implemented) making batch processing more efficient by avoiding repeated queries
  • (not implemented) make batch processing able to handle larger query range
  • Inaccurate pricing dependent on timeframe given to binance API -> should add in uncertainty / another field for resolution

License

This project is licensed under the MIT License - see the LICENSE file for details

Boilerplate with TypeScript, Express, ESLint, Prettier, Husky + Lint-staged, and Vitest

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published