Skip to content

Commit

Permalink
Update btc folder (#56)
Browse files Browse the repository at this point in the history
* [Fix]: Update rpc for arbitrium sepolia

* [update]: added try catch block to route handler

* [update]: added try catch block to route handler

* [deploy]: Preping for wbtc bridge

* [deploy]: Preping for wbtc bridge

* Update push-prod.yml

* change

* Update push.yml

* [Feature]: implemented WBTC on the frontend (#55)

---------

Co-authored-by: stephenson080 <[email protected]>
Co-authored-by: Stephen Udeh <[email protected]>
  • Loading branch information
3 people authored Mar 3, 2025
1 parent 131a7d1 commit 64c9277
Show file tree
Hide file tree
Showing 149 changed files with 94,900 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/push-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- 'backend-wbtc/**'
- 'backend-weth/**'
- 'backend-wnt/**'
- 'backend-btc/**
jobs:
deploy:
Expand Down Expand Up @@ -151,12 +152,19 @@ jobs:
scp -i id_rsa -o StrictHostKeyChecking=no -P ${{ secrets.ONPREM_SSH_PORT }} -r backend-usdc/parse-apps.config.js backend-usdc/yarn.lock backend-usdc/package.json backend-usdc/dist ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }}:/var/www/bridge.assetchain.org/backend-usdc/
ssh -i id_rsa -o StrictHostKeyChecking=no -p ${{ secrets.ONPREM_SSH_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }} "cd /var/www/bridge.assetchain.org/backend-usdc && yarn && pm2 restart parse-apps.config.js"
- name: Deploy Backend btc
if: steps.filter.outputs.backend-btc == 'true'
run: |
scp -i id_rsa -o StrictHostKeyChecking=no -P ${{ secrets.ONPREM_SSH_PORT }} -r backend-btc/parse-apps.config.js backend-btc/yarn.lock backend-btc/package.json backend-btc/dist ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }}:/var/www/bridge.assetchain.org/backend-btc/
ssh -i id_rsa -o StrictHostKeyChecking=no -p ${{ secrets.ONPREM_SSH_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }} "cd /var/www/bridge.assetchain.org/backend-btc && yarn && pm2 restart parse-apps.config.js"
- name: Deploy Backend wbtc
if: steps.filter.outputs.backend-wbtc == 'true'
run: |
scp -i id_rsa -o StrictHostKeyChecking=no -P ${{ secrets.ONPREM_SSH_PORT }} -r backend-wbtc/parse-apps.config.js backend-wbtc/yarn.lock backend-wbtc/package.json backend-wbtc/dist ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }}:/var/www/bridge.assetchain.org/backend-wbtc/
ssh -i id_rsa -o StrictHostKeyChecking=no -p ${{ secrets.ONPREM_SSH_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_PROD_IP }} "cd /var/www/bridge.assetchain.org/backend-wbtc && yarn && pm2 restart parse-apps.config.js"
- name: Deploy Backend weth
if: steps.filter.outputs.backend-weth == 'true'
run: |
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- 'backend-wbtc/**'
- 'backend-weth/**'
- 'backend-wnt/**'
- 'backend-btc/**
jobs:
deploy:
Expand Down Expand Up @@ -92,6 +93,11 @@ jobs:
run: |
ssh -i id_rsa -o StrictHostKeyChecking=no -p ${{ secrets.STAGING_SSH_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_STAGING_INTERNAL_IP }} "cd /var/www/bridge.assetchain.org/backend-usdt && git pull origin staging && yarn && yarn build && pm2 restart parse-apps.config.js"
- name: Deploy Backend btc
if: steps.filter.outputs.backend-btc == 'true'
run: |
ssh -i id_rsa -o StrictHostKeyChecking=no -p ${{ secrets.STAGING_SSH_PORT }} ${{ secrets.DEPLOY_USER }}@${{ secrets.ASSETCHAIN_BRIDGE_STAGING_INTERNAL_IP }} "cd /var/www/bridge.assetchain.org/backend-btc && git pull origin staging && yarn && yarn build && pm2 restart parse-apps.config.js"
- name: Deploy Backend wbtc
if: steps.filter.outputs.backend-wbtc == 'true'
run: |
Expand Down
8 changes: 8 additions & 0 deletions backend-btc/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules/
dist/

.gitignore
.git/
.env
.env.local

3 changes: 3 additions & 0 deletions backend-btc/.env.examle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PROD=false
PRIVATE_KEY="7eb433edd85f1774c4a15f460e822071729b6177bdb2418f67e3d9e50c773d2a"
VITE_BACKEND_LINK="https://gotbit-xend-multitoken-backend-dev.dev.gotbit.app"
4 changes: 4 additions & 0 deletions backend-btc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
.env
node_modules/
coverage
26 changes: 26 additions & 0 deletions backend-btc/.gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
stages:
- test
- build
- deploy

# variables:
# SKIP_COMPONENTS_TEST: 'true'
# SKIP_BUILD_TEST: 'true'
# SKIP_TYPECHECK_TEST: 'true'

include:
- project: '$DEVOPS_PROJECT_PATH'
ref: 'main'
file: 'gitlabci/build/backend/.gitlab-ci.yml'

- project: '$DEVOPS_PROJECT_PATH'
ref: 'main'
file: 'clients/build/backend/aws/.gitlab-ci.yml'

- project: '$DEVOPS_PROJECT_PATH'
ref: 'main'
file: 'gitlabci/deploy/backend/.gitlab-ci.yml'

- project: '$DEVOPS_PROJECT_PATH'
ref: 'main'
file: 'gitlabci/test/backend/.gitlab-ci.yml'
14 changes: 14 additions & 0 deletions backend-btc/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"semi": false,
"printWidth": 90,
"singleQuote": true,
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 90,
"tabWidth": 4
}
}
]
}
15 changes: 15 additions & 0 deletions backend-btc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM node:16

ARG PROD
ARG PRIVATE_KEY
COPY package.json ./
COPY yarn.lock ./

RUN yarn

COPY . .
RUN yarn build


EXPOSE 3000
CMD yarn serve
117 changes: 117 additions & 0 deletions backend-btc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# Asset Chain Bridge backend for BTC

## Description

Bridge is a decentralized application that consists of front-end, back-end, and smart contracts on every blockchain network used in the Bridge.

## Table of Contents

- [Getting Started](#getting-started)
- [Project Structure](#project-structure)
- [Contracts](#contracts)
- [Confirmations blocks](#confirmations-blocks)
- [Endpoints](#endpoints)
- [Backend structure](#backend-structure)
- [SecurityBackend structure](#security)

## Getting Started

Recommended Node version is 16.20.0.

Generate `.env` file

```bash
$ cp .env.example .env
```

Add .env file to the project root.

To add the private key of a relayer account, assign the following variable and add `PROD` variable (`true` to setup mainnet or `false` to setup testnet)

```
PRIVATE_KEY=
PROD=
```

```bash
$ yarn
$ yarn build
$ yarn serve
```

## Project Structure

This a typescript backend with `express`.

This backend does not use the database and does not listen to events

Endpoint `/transactions` receiving the user's address from the frontend at the moment of request runs through all used networks and gets the user's transactions using the `getUserTransactions()` function on the contract. After that, the backend finds pairs among them, which indicates that the transaction is labeled and the remaining transactions are not picked up on the destined networks. Having received the final list of transactions, the backend gives them to the frontend

Endpoint `/sign` receiving as input the parameters
`fromChain: string`,
`fromUser: string`,
`index: string`,
`toBridgeAssistAddress: string`,
`fromBridgeAddress: string`
finds the required transaction on the source network, checks that the required number of confirmation blocks has passed and if the check has passed, signs it and returns it to the user.

### Contracts

Smart contracts abis are found in `./src/contracts/contracts.json`.

### Confirmations blocks

List of amount confirmations block are found in `./src/confirmations.json`.
You can change them by replace `0` to anoter number for the corresponding chainId.

For example if you set `"1": 15` - after send to Ethereum mainnet you need to wait `15` blocks before `claim`

### Endpoints

/transactions - get all transactions by user
params:
user - address

/sign - get signature of selected transaction
params:
fromChain - source chain (evm.1)
fromUser - sender address
index - transaction index
toBridgeAssistAddress - Destination chain Bridge Assist Contract address
fromBridgeAddress - Source chain Bridge Assist Contract address

/health - check server health

### Backend structure

This is a backend written in typesctipt using gotbit tools template.

You have 2 environment variables that must be defined in the .env file.

All networks, contracts and rpc supported by the project are defined in the ./src/gotbit-config.ts file.

There are 2 sets of rpc "universalRpc" and "extraRpc".
The first set is defined in src/gotbit-tools/node/rpc.ts
The second is defined in src/gotbit-tools/node/utils/node.ts
You can change them as you wish

All endpoints are located in the src/routes folder

There is also a file confirmations.json in which the number of confirmations blocks for each chainId is defined.
You can increase the number of confirmations blocks to prevent frontrunner attacks.
Increasing the number of blocks will allow the user to pick up the money on the receiving network only after it has passed.


You can see more details about gotbit-tools in /frontend/src/gotbit-tools/README.md

### Security

Do not show the private key used to sign transactions to anyone.
If an intruder gets this key, he can sign a fake transaction with it and withdraw all the money from your bridge.







13 changes: 13 additions & 0 deletions backend-btc/docker/backend.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:16

COPY package.json ./
COPY yarn.lock ./

RUN yarn

COPY . .
RUN yarn build


EXPOSE 3000
CMD yarn serve
77 changes: 77 additions & 0 deletions backend-btc/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"name": "kyc-app",
"scripts": {
"dev": "yarn build && concurrently 'tsc -w' 'DEBUG=true node-dev --respawn dist/app.js'",
"win": "rd /s /q dist && tsc -p .",
"build": "rm -rf dist && tsc -p .",
"serve": "node dist/app.js",
"\n# TESTING SCRIPTS:": "",
"type": "tsc -p . --noEmit",
"test": "TEST=true jest",
"coverage": "yarn test --coverage",
"test:gotbit-tools": "yarn test --dir src/gotbit-tools",
"test:build": "yarn build",
"test:full": "yarn type && yarn test && yarn test:build",
"\n# GOTBIT-TOOLS SCRIPTS:": "",
"update": "cd src && npx gotbit-tools@latest install node -d ./src",
"contracts": "yarn contracts:sync && yarn contracts:typings",
"contracts:sync": "SCRIPT=./src/gotbit-tools/scripts/shell/import-contracts.sh yarn script",
"contracts:typings": "node ./src/gotbit-tools/scripts/typings.js",
"\n# UTILS SCRIPTS:": "",
"script": "chmod +x $SCRIPT && $SCRIPT"
},
"jest": {
"preset": "ts-jest",
"testEnvironment": "node",
"moduleNameMapper": {
"@/(.*)": "<rootDir>/src/$1"
},
"testMatch": [
"<rootDir>/src/__tests__/**/*.test.ts"
],
"testTimeout": 600000
},
"engines": {
"node": ">=16.0.0"
},
"_moduleAliases": {
"@": "dist/"
},
"version": "1.0.0",
"main": "src/app.ts",
"author": "kotsmile",
"license": "MIT",
"dependencies": {
"axios": "^0.27.2",
"body-parser": "^1.20.0",
"cors": "^2.8.5",
"dotenv": "^16.0.0",
"ethers": "^5.6.6",
"ethers-multicall": "^0.2.3",
"express": "^4.18.1",
"express-automatic-routes": "^1.1.0",
"helmet": "^5.0.2",
"module-alias": "^2.2.2",
"moment": "^2.29.3",
"morgan": "^1.10.0"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/cors": "^2.8.12",
"@types/express": "^4.17.13",
"@types/jest": "^29.0.1",
"@types/mocha": "^9.1.1",
"@types/morgan": "^1.9.3",
"@types/node": "^17.0.31",
"@types/supertest": "^2.0.12",
"c8": "^7.11.3",
"chai": "^4.3.6",
"concurrently": "^7.1.0",
"jest": "^29.0.3",
"mocha": "^10.0.0",
"node-dev": "^7.4.3",
"supertest": "^6.2.4",
"ts-jest": "^29.0.0",
"typescript": "^4.6.4"
}
}
12 changes: 12 additions & 0 deletions backend-btc/parse-apps.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
apps: [
{
name: 'backend-wbtc', // Application name
script: 'dist/app.js', // Script to be run
instances: 1, // Number of instances to be started
autorestart: true, // Automatically restart crashed application
watch: false, // Watch files for changes
max_memory_restart: '1G', // Restart the application if it reaches this memory usage
}
]
};
12 changes: 12 additions & 0 deletions backend-btc/src/__tests__/routes/health.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'mocha'
import { expect } from 'chai'

import app from '@/app'
import request from 'supertest'

describe('health route', () => {
it('should', async () => {
const response = await request(app).get('/health')
expect(response.text).eq('Server is Healthy')
})
})
Loading

0 comments on commit 64c9277

Please sign in to comment.