Skip to content
This repository was archived by the owner on Feb 25, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ npm-debug.log
*.env
*.env.*
# except the example .env.example
!.env.example
!.env.example

# Gateway API files
*.pem
20 changes: 13 additions & 7 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@ PORT=5000
# ipv6 format for locahost ["::ffff:127.0.0.1", "::ffff:1", "fe80::1", "::1"]
IP_WHITELIST=

HUMMINGBOT_CLIENT_ID={client_id}

# Celo

# Terra
TERRA_LCD_URL=https://tequila-lcd.terra.dev
TERRA_CHAIN=tequila-0004
# - mainnet: https://lcd.terra.dev
# - mainnet chain: columbus-4
# - testnet: https://tequila-lcd.terra.dev
# - testnet chain: tequila-0004
TERRA_LCD_URL={testnet_lcd_url}
TERRA_CHAIN={testnet_chain_id}

# Ethereum
# - network: mainnet, kovan, etc
# - chain: mainnet, kovan, etc
# - rpc url: infura or other rpc url
ETHEREUM CHAIN={network}
ETHEREUM_RPC_URL=https://{network}.infura.io/v3/{api_key}
ETHEREUM_CHAIN={chain}
ETHEREUM_RPC_URL=https://{chain}.infura.io/v3/{api_key}

# Balancer
# subgraph_network
# subgraph_chain
# Reference: https://docs.balancer.finance/sor/development#subgraph
# - mainnet: balancer
# - kovan: balancer-kovan
# Note: REACT_APP_SUBGRAPH_URL used by @balancer-labs/sor
REACT_APP_SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/balancer-labs/{subgraph_network}
REACT_APP_SUBGRAPH_URL=https://api.thegraph.com/subgraphs/name/balancer-labs/{subgraph_chain}

# exchange_proxy:
# Reference: https://docs.balancer.finance/smart-contracts/addresses
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ npm-debug.log
dist/

# cert
certs/
*.pem
*.srl
*.key
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM node:10.22.0-alpine

# Set labels
LABEL application="gateway-api"

# app directory
WORKDIR /usr/src/app

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ We created hummingbot to promote **decentralized market-making**: enabling membe

### Install Hummingbot

- [Installation](https://docs.hummingbot.io/installation/overview/)
- [Quickstart guide](https://docs.hummingbot.io/quickstart/)
- [All installation options](https://docs.hummingbot.io/installation/overview/)

### Get support
- Chat with our support team on [Discord](https://discord.hummingbot.io)
Expand Down
2 changes: 1 addition & 1 deletion certs/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
certs dir
certs dir for local testing only
2 changes: 1 addition & 1 deletion setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This can be used as a common API server to handle transactions that requires cus
## Development Requirements

- NodeJS
- Tested on Node v10.22.0
- Tested on Node v10.22.1
- https://docs.npmjs.com/downloading-and-installing-node-js-and-npm

```bash
Expand Down
24 changes: 10 additions & 14 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import bodyParser from 'body-parser'
import express from 'express'
import helmet from 'helmet'
import { statusMessages } from './services/utils';
import { validateAccess } from './services/access';
import { IpFilter } from 'express-ipfilter'

// Routes
Expand Down Expand Up @@ -35,23 +36,18 @@ if (ipWhitelist) {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.use(validateAccess)

// mount all routes to this path
app.use('/api', apiRoutes);
app.use('/eth', ethRoutes);
// app.use('/celo', celoRoutes);
app.use('/terra', terraRoutes);
app.use('/balancer', balancerRoutes);
app.use('/uniswap', uniswapRoutes);
app.use('/uniswap', validateAccess, uniswapRoutes);
app.use('/api', validateAccess, apiRoutes);
app.use('/eth', validateAccess, ethRoutes);
// app.use('/celo', validateAccess, celoRoutes);
app.use('/terra', validateAccess, terraRoutes);
app.use('/balancer', validateAccess, balancerRoutes);

app.get('/', (req, res, next) => {
const cert = req.connection.getPeerCertificate()
if (req.client.authorized) {
next()
} else if (cert.subject) {
res.status(403).send({ error: statusMessages.ssl_cert_invalid })
} else {
res.status(401).send({ error: statusMessages.ssl_cert_required })
}
res.send('ok')
})

/**
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const env = process.env.NODE_ENV
const port = process.env.PORT
const certPassphrase = process.env.CERT_PASSPHRASE
const ethereumChain = process.env.ETHEREUM_CHAIN
const terraChain = process.env.TERRA_CHAIN
let certPath = process.env.CERT_PATH

if ((typeof certPath === 'undefined' && certPath == null) || certPath === '') {
Expand Down Expand Up @@ -79,4 +80,6 @@ server.listen(port)
server.on('error', onError)
server.on('listening', onListening)

console.log('server: gateway-api | port:', port, '| ethereum-chain:', ethereumChain);
console.log('server: gateway-api | port:', port)
console.log(' - ethereum-chain:', ethereumChain)
console.log(' - terra-chain:', terraChain)
24 changes: 8 additions & 16 deletions src/routes/balancer.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { ethers } from 'ethers';
import express from 'express';

import { getParamData, latency, reportConnectionError, statusMessages } from '../services/utils';

import Balancer from '../services/balancer';

require('dotenv').config()
// require('dotenv').config()
const debug = require('debug')('router')

const router = express.Router()
Expand All @@ -15,17 +16,6 @@ const denomMultiplier = 1e18
const swapMoreThanMaxPriceError = 'Price too high'
const swapLessThanMaxPriceError = 'Price too low'

router.use((req, res, next) => {
const cert = req.connection.getPeerCertificate()
if (req.client.authorized) {
next()
} else if (cert.subject) {
res.status(403).send({ error: statusMessages.ssl_cert_invalid })
} else {
res.status(401).send({ error: statusMessages.ssl_cert_required })
}
})

router.post('/', async (req, res) => {
/*
POST /
Expand All @@ -34,7 +24,8 @@ router.post('/', async (req, res) => {
network: balancer.network,
provider: balancer.provider.connection.url,
exchangeProxy: balancer.exchangeProxy,
subgraphUrl: process.env.REACT_APP_SUBGRAPH_URL,
subgraphUrl: balancer.subgraphUrl,
gasLimit: balancer.gasLimit,
connection: true,
timestamp: Date.now(),
})
Expand All @@ -47,7 +38,7 @@ router.post('/sell-price', async (req, res) => {
"quote":"0x....."
"base":"0x....."
"amount":0.1
"swaps": 4 (optional)
"maxSwaps":4
}
*/
const initTime = Date.now()
Expand Down Expand Up @@ -105,6 +96,7 @@ router.post('/buy-price', async (req, res) => {
"quote":"0x....."
"base":"0x....."
"amount":0.1
"maxSwaps":4
}
*/
const initTime = Date.now()
Expand Down Expand Up @@ -163,6 +155,7 @@ router.post('/sell', async (req, res) => {
"amount":0.1
"minPrice":1
"gasPrice":10
"maxSwaps":4
"privateKey":{{privateKey}}
}
*/
Expand Down Expand Up @@ -214,8 +207,6 @@ router.post('/sell', async (req, res) => {
gasPrice,
)

debug(txObj)

// submit response
res.status(200).json({
network: balancer.network,
Expand Down Expand Up @@ -256,6 +247,7 @@ router.post('/buy', async (req, res) => {
"amount":0.1
"maxPrice":1
"gasPrice":10
"maxSwaps":4
"privateKey":{{privateKey}}
}
*/
Expand Down
12 changes: 1 addition & 11 deletions src/routes/index.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,10 @@ const express = require('express');

const router = express.Router();

router.use((req, res, next) => {
const cert = req.connection.getPeerCertificate()
if (req.client.authorized) {
next()
} else if (cert.subject) {
res.status(403).send({ error: statusMessages.ssl_cert_invalid })
} else {
res.status(401).send({ error: statusMessages.ssl_cert_required })
}
})

router.get('/', (req, res) => {
res.status(200).json({
app: process.env.APPNAME,
image: process.env.IMAGE,
status: 'ok',
});
})
Expand Down
Loading