Skip to content

Commit

Permalink
Merge pull request hummingbot#1 from hummingbot/feat/certs-2
Browse files Browse the repository at this point in the history
Feat/certs
  • Loading branch information
fengtality authored Feb 7, 2023
2 parents ecde46d + 465013c commit 19ab410
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 178 deletions.
10 changes: 9 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM node:18.10.0

# Set labels
LABEL application="gateway-v2"
LABEL application="gateway"
LABEL branch=${BRANCH}
LABEL commit=${COMMIT}
LABEL date=${BUILD_DATE}
Expand All @@ -23,6 +23,14 @@ RUN apt-get update && \
# app directory
WORKDIR /usr/src/app

# copy pwd file to container
COPY . .

# create sym links
RUN ln -s /conf /usr/src/app/conf && \
ln -s /logs /usr/src/app/logs && \
ln -s /certs /usr/src/app/certs

# create app writable directory for db files
RUN mkdir /var/lib/gateway
RUN chown -R hummingbot /var/lib/gateway
Expand Down
86 changes: 32 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,71 @@

# Hummingbot Gateway

---

Hummingbot Gateway is a REST API that exposes connections to various blockchains (wallet, node & chain interaction) and decentralized exchanges (pricing, trading & liquidity provision). It is written in Typescript and takes advantage of existing blockchain and DEX SDKs. The advantage of using gateway is it provideds a programming language agnostic approach to interacting with blockchains and DEXs.

Gateway may be used alongside the main Hummingbot client to enable trading on DEXs, or as a standalone module by external developers.

## Connectors

This is a list of DEX connections currently supported by Gateway.
Gateway may be used alongside the main [Hummingbot client](https://github.com/hummingbot/hummingbot) to enable trading on DEXs, or as a standalone module by external developers.

| Connector | Blockchain | Trading Interface |
| ----------- | ------------------- | ----------------- |
| UniswapV2 | Ethereum | AMM |
| Sushiswap | Ethereum | AMM |
| UniswapV3 | Ethereum | EVM_Range_AMM |
| Pangolin | Avalanche | AMM |
| PancakeSwap | Binance Smart Chain | AMM |
| Traderjoe | Avalanche | AMM |
| Quickswap | Polygon | AMM |
| Perp | Ethereum | EVM_Perpetual |
| Mad Meerkat | Cronos | AMM |
| VVS | Cronos | AMM |


## Contributing
## Install and run locally

There are a number of ways to contribute to gateway.
```bash
# Install dependencies
yarn

- Add a new blockchain.
# Complile Typescript into JS
$ yarn build

- Add a new connector/DEX.
# Generate the config files and edit as needed, especially server.yml
$ setup/generate_conf.sh

- Fix a bug.
# Start the server using the passphrase you used to generate the certs in Hummingbot
$ yarn start --passphrase=<passphrase>
```

- File an issue at [hummingbot issues](https://github.com/hummingbot/hummingbot/issues)
## Documentation

- Make a PR for anything useful on [hummingbot](https://github.com/hummingbot/hummingbot/).
See the [official Gateway docs](https://docs.hummingbot.org/gateway/).

- Vote on a snapshot proposal: [Hummingbot PRP](https://snapshot.org/#/hbot-prp.eth), [Hummingbot Foundation - HGP](https://snapshot.org/#/hbot.eth), [Hummingbot Improvement Proposals](https://snapshot.org/#/hbot-ip.eth).
The API is documented using [Swagger](./docs/swagger). When Gateway is started, it also generates Swagger API docs at: https://localhost:8080

## Configuration

Before running gateway, you need to setup some configs. You can start by copying all of the yml files from [src/templates](./src/templates) to [conf](./conf). The format of this files are dictated by [src/services/config-manager-v2.ts](./src/services/config-manager-v2.ts) and the corresponding schema files in [src/services/schema](./src/services/schema) .
## Contributing

### Useful configuration options
There are a number of ways to contribute to gateway.

- If you want to turn off `https`, set `unsafeDevModeWithHTTP` to `true` in [conf/server.yml](./conf/server.yml).
- File an issue at [hummingbot issues](https://github.com/hummingbot/gateway/issues)

- If you gateway to log to standard out, set `logToStdOut` to `true` in [conf/logging.yml](./conf/logging.yml).
- Make a [pull request](https://github.com/hummingbot/gateway/)

- Edit the path to the SSL files in [conf/ssl.yml](./conf/ssl.yml). This can be generated by hummingbot with `gateway generate-certs`.
- Edit the [docs](https://github.com/hummingbot/hummingbot-site/)

The hummingbot client is also able to edit this config files.
- Vote on a [Snapshot proposal](https://snapshot.org/#/hbot.eth)

## Install and run locally

Compile the Typescript code with `npm` or `yarn` .
### Configuration

```bash
yarn
yarn build
yarn dev --passphrase=<ssl-files-passphrase>
# the passphrase can be anything if unsafeDevModeWithHTTP is true
```
- Edit `certs_path` in [conf/server.yml](./conf/server.yml) and enter the absolute path to the folder where Hummingbot stored the certificates it created with `gateway generate-certs`. You can also edit this config inside the Hummingbot client by running the command: `gateway config server.certs_path`.

## Documentation
- If you want to turn off `https`, set `unsafeDevModeWithHTTP` to `true` in [conf/server.yml](./conf/server.yml).

The API is documented using swagger: [gateway swagger docs](./docs/swagger). You can run the gateway swagger UI by starting gateway and visiting [localhost:8080](localhost:8080).
- If you want Gateway to log to standard out, set `logToStdOut` to `true` in [conf/server.yml](./conf/server.yml).

You can follow details about [trading interfaces](https://hummingbot.notion.site/Gateway-v2-Trading-Interfaces-482e2684d48c450ebcfff5401ba806aa)
- The format of configuration files are dictated by [src/services/config-manager-v2.ts](./src/services/config-manager-v2.ts) and the corresponding schema files in [src/services/schema](./src/services/schema).

Also, we maintain docs on the official website about gateway [here](https://hummingbot.org/protocols/gateway/).

### Files to read
### Architecture

Here are some files we recommend you look at in order to get familiar with the gateway code base.
Here are some files we recommend you look at in order to get familiar with the Gateway codebase:

- [src/services/ethereum-base.ts](./src/services/ethereum-base.ts) is a base class for EVM chains.
- [src/services/ethereum-base.ts](./src/services/ethereum-base.ts): base class for EVM chains.

- [src/connectors/uniswap/uniswap.ts](./src/connectors/uniswap/uniswap.ts) has functionality for interacting with Uniswap V2.
- [src/connectors/uniswap/uniswap.ts](./src/connectors/uniswap/uniswap.ts): functionality for interacting with Uniswap.

- [src/services/validator.ts](./src/services/validator.ts) defines functions for validating request payloads.
- [src/services/validator.ts](./src/services/validator.ts): defines functions for validating request payloads.


### Testing

When making a PR, there are unit test coverage requirements. Look at our [github workflow](../.github/workflows/workflow.yml) for the exact definition. There are some more
For a pull request merged into the codebase, it has to pass unit test coverage requirements. Take a look at [Workflow](../.github/workflows/workflow.yml) for more details.

#### Unit tests

Expand Down
4 changes: 2 additions & 2 deletions src/chains/avalanche/avalanche.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class Avalanche extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = config.network.name;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
4 changes: 2 additions & 2 deletions src/chains/binance-smart-chain/binance-smart-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class BinanceSmartChain extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = config.network.name;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
4 changes: 2 additions & 2 deletions src/chains/cronos/cronos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export class Cronos extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = config.network.name;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
4 changes: 2 additions & 2 deletions src/chains/ethereum/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class Ethereum extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = network;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
4 changes: 2 additions & 2 deletions src/chains/harmony/harmony.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export class Harmony extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = network;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
2 changes: 1 addition & 1 deletion src/chains/near/near.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Near extends NearBase {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = config.network.name;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
4 changes: 2 additions & 2 deletions src/chains/polygon/polygon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class Polygon extends EthereumBase implements Ethereumish {
config.network.tokenListType,
config.manualGasPrice,
config.gasLimitTransaction,
ConfigManagerV2.getInstance().get('database.nonceDbPath'),
ConfigManagerV2.getInstance().get('database.transactionDbPath')
ConfigManagerV2.getInstance().get('server.nonceDbPath'),
ConfigManagerV2.getInstance().get('server.transactionDbPath')
);
this._chain = config.network.name;
this._nativeTokenSymbol = config.nativeCurrencySymbol;
Expand Down
33 changes: 21 additions & 12 deletions src/https.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,24 @@ import { ConfigManagerV2 } from './services/config-manager-v2';

export const addHttps = (app: Application) => {
const serverKey = fs.readFileSync(
ConfigManagerV2.getInstance().get('ssl.keyPath'),
{
encoding: 'utf-8',
}
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'server_key.pem',
{ encoding: 'utf-8' }
);

const serverCert = fs.readFileSync(
ConfigManagerV2.getInstance().get('ssl.certificatePath'),
{
encoding: 'utf-8',
}
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'server_cert.pem',
{ encoding: 'utf-8' }
);

const caCert = fs.readFileSync(
ConfigManagerV2.getInstance().get('ssl.caCertificatePath'),
{
encoding: 'utf-8',
}
addSlashToPath(
ConfigManagerV2.getInstance().get('server.certificatePath')
) + 'ca_cert.pem',
{ encoding: 'utf-8' }
);

return https.createServer(
Expand All @@ -39,3 +41,10 @@ export const addHttps = (app: Application) => {
app
);
};

const addSlashToPath = (path: string) => {
if (!path.endsWith('/')) {
path += '/';
}
return path;
};
6 changes: 3 additions & 3 deletions src/services/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const sdtoutFormat = winston.format.combine(
);

const getLogPath = () => {
let logPath = ConfigManagerV2.getInstance().get('logging.logPath');
let logPath = ConfigManagerV2.getInstance().get('server.logPath');
logPath = [appRoot.path, 'logs'].join('/');
return logPath;
};
Expand Down Expand Up @@ -77,13 +77,13 @@ const reportingProxy = new TelemetryTransport({
});

export const updateLoggerToStdout = () => {
ConfigManagerV2.getInstance().get('logging.logToStdOut') === true
ConfigManagerV2.getInstance().get('server.logToStdOut') === true
? logger.add(toStdout)
: logger.remove(toStdout);
};

export const telemetry = () => {
ConfigManagerV2.getInstance().get('telemetry.enabled') === true
ConfigManagerV2.getInstance().get('server.telemetry_enabled') === true
? logger.add(reportingProxy)
: logger.remove(reportingProxy);
};
Expand Down
10 changes: 0 additions & 10 deletions src/services/schema/database-schema.json

This file was deleted.

12 changes: 0 additions & 12 deletions src/services/schema/ethereum-gas-station-schema.json

This file was deleted.

20 changes: 17 additions & 3 deletions src/services/schema/server-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,26 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"certificatePath": { "type": "string" },
"logPath": { "type": "string" },
"port": { "type": "integer" },
"ipWhitelist": { "type": "array" },
"unsafeDevModeWithHTTP": { "type": "boolean" },
"GMTOffset": { "type": "number" },
"id": { "type": "string" }
"id": { "type": "string" },
"logToStdOut": { "type": "boolean" },
"unsafeDevModeWithHTTP": { "type": "boolean" },
"telemetry_enabled": { "type": "boolean" },
"nonceDbPath": { "type": "string" },
"transactionDbPath": { "type": "string" }
},
"additionalProperties": false,
"required": ["port", "unsafeDevModeWithHTTP"]
"required": [
"port",
"unsafeDevModeWithHTTP",
"certificatePath",
"telemetry_enabled",
"logPath",
"nonceDbPath",
"transactionDbPath"
]
}
11 changes: 0 additions & 11 deletions src/services/schema/ssl-schema.json

This file was deleted.

8 changes: 0 additions & 8 deletions src/services/schema/telemetry-schema.json

This file was deleted.

2 changes: 0 additions & 2 deletions src/templates/database.yml

This file was deleted.

6 changes: 0 additions & 6 deletions src/templates/logging.yml

This file was deleted.

Loading

0 comments on commit 19ab410

Please sign in to comment.