The Tab Oracle module is a part of Tab Protocol that receives currrency rates from authorized providers, and supply signed median ratas on demand.
Name | Description | Scheduler |
---|---|---|
Feed submission | Authenticate, validate, and store currency rates sent by authorized provider | Adhoc |
On/off-chain params | Sync. on-chain and off-chain parameters/configuration | Run on every 11 minutes |
Median price aggregation | Group currency rates to determine median price rate | Run on every 5 minutes |
Provider performance | Track provider feed submissions and submit data on-chain used in payment calculation | Run on every 6 hours |
Reserve/Tab setting | Reserve and Tab configuration such as minimum reserve ratio, liquidation ratio and risk penalty fee rate | Run on every 6 hours |
Endpoint | Description |
---|---|
/api/v1/auth/create_or_reset_api_token/[provider_pub_address] | Authorized provider calls this endpoint to generate or reset API token to submit currrency rate data |
/api/v1/feed_provider/[provider_pub_address]/feed_submission | Authorized provider calls this endpoint to submit currency rate data |
/api/v1/tab/list | Retrieve Tab details |
/api/v1/peggedTab/list | Retrieve Pegged Tab details |
/api/v1/price_history/[currency] | Protected endpoint to retrieve historical prices |
/api/v1/median_price/[currency] | Protected endpoint to retrieve latest median price |
/api/v1/median_price/[wallet_address]/[currency] | Proteced endpoint to retrieve signed latest median price |
/api/v1/feed_provider/list | Protected endpoint reserved for internal usage (e.g. used by tab-ui module) |
- EVM blockchain with Node URL
- Tab protocol deployment, smart contract address for PriceOracleManager and TabRegistry.
- Registered / activated Tab Oracle Provider in smart contract. Provider is identified by an unique public address.
- Node.js
- PostgreSQL, or other databases supported by Prisma (refer this)
Refer steps below:
-
Clone the repo
git clone [repo]
-
cd into tab-oracle directory
cd tab-oracle
-
Install NPM packages
npm install
-
Edit .env.local file to suit your environment.
-
Initialize PostgreSQL database and ready to accept connection.
-
Introspect database with command
npx prisma db pull
then generate Prisma Client with command
npx prisma generate
-
Start application
npm run local
You may execute this module in docker environment.
Example below assumes that related dependencies (such as EVM blockchain or database) are running in dockerized container joined on same network(tab-net
).
Docker swarm mode is preferred so that we can utilize docker secret to hide sensitive data.
-
Install docker and run
docker swarm init docker network create --driver overlay tab-net
-
Clone the repo
git clone [repo]
-
Switch into tab-oracle directory
cd tab-oracle
-
Create and edit .env file by referring to .env.local file based on your environment. The .env file will be saved as docker secret in following step.
-
Run commands to start docker,
docker volume create tab-oracle-log docker secret create tab-oracle-env .env docker build . -t tab-oracle docker service create --name tab-oracle --network tab-net --replicas 1 \ --hostname tab-oracle --secret src=tab-oracle-env,target=".env" \ -p 9090:9090 --mount src=tab-oracle-log,dst=/usr/src/app/logs tab-oracle:latest
-
Visit Docker swarm for reference.
-
Remove
-p 9090:9090
option when running docker service create. Published port is used on Nginx container instead. -
Edit nginx.conf with sample proxy option:
real_ip_header X-Real-IP; real_ip_recursive on; server { server_name api.shiftctrl.money; location / { proxy_pass http://tab-oracle:9090; proxy_buffering off; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $host; proxy_pass_request_headers on; } listen 80; }
-
Run command to start nginx,
docker volume create tab-nginx docker service create --name tab-nginx -p 80:80 --network tab-net \ --replicas 1 --hostname tab-nginx --mount src=tab-nginx,dst=/etc/nginx tab-nginx:latest
- Create a new volume
docker volume create tabdb
- Create a DB password file and store it in docker secret
echo "my_DB_Secret_Password" >> postgres-passwd docker secret create postgres-passwd ./postgres-passwd
- Create a new volume to put database initialization script
docker volume create tabdb-init # assume docker volume in default location /var/lib/docker/volumes cp db/tabdb.sql /var/lib/docker/volumes/tabdb-init/_data
- Run docker service create command
docker service create --name tabdb --hostname tabdb -p 5432:5432 --network tab-net \ --replicas 1 --secret src=postgres-passwd,target="postgres-passwd" \ -e POSTGRES_PASSWORD_FILE=/run/secrets/postgres-passwd -e POSTGRES_USER=tabdb \ -e PGDATA=/var/lib/postgresql/data/pgdata -e LANG=en_US.utf8 \ -e POSTGRES_INITDB_ARGS="--locale-provider=icu --icu-locale=en-US" \ --mount src=tabdb,dst=/var/lib/postgresql/data/pgdata \ --mount src=tabdb-init,dst=/docker-entrypoint-initdb.d \ postgres:16.2-bullseye
- Verify service is running
# expected mode "replicated" docker service ls # expected status "up" docker ps -a
Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.md
for more information.
Project Link: https://shiftctrl.money - contact@shiftctrl.money
Twitter @shiftCTRL_money
Discord shiftctrl_money