aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-10-25 09:34:20 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-12-05 06:24:48 +0800
commit5e22a862b77d4947361342972c28a8552d13018e (patch)
tree6ef99ff4d5b9d1f0c41e87c18b97d1987b5da9ab /packages/pipeline
parentbb440b683a7a4d966694de2b897f51f22dadb31c (diff)
downloaddexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar.gz
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar.bz2
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar.lz
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar.xz
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.tar.zst
dexon-sol-tools-5e22a862b77d4947361342972c28a8552d13018e.zip
Implement fetching and parsing relayer info
Diffstat (limited to 'packages/pipeline')
-rw-r--r--packages/pipeline/package.json1
-rw-r--r--packages/pipeline/src/data_sources/relayer-registry/index.ts33
-rw-r--r--packages/pipeline/src/entities/Relayer.ts22
-rw-r--r--packages/pipeline/src/index.ts29
-rw-r--r--packages/pipeline/src/parsers/relayer_registry/index.ts28
5 files changed, 107 insertions, 6 deletions
diff --git a/packages/pipeline/package.json b/packages/pipeline/package.json
index 47033bf33..253da3f19 100644
--- a/packages/pipeline/package.json
+++ b/packages/pipeline/package.json
@@ -27,6 +27,7 @@
"devDependencies": {
"@0x/tslint-config": "^1.0.9",
"@types/ramda": "^0.25.38",
+ "@types/axios": "^0.14.0",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2",
diff --git a/packages/pipeline/src/data_sources/relayer-registry/index.ts b/packages/pipeline/src/data_sources/relayer-registry/index.ts
new file mode 100644
index 000000000..c97b50d27
--- /dev/null
+++ b/packages/pipeline/src/data_sources/relayer-registry/index.ts
@@ -0,0 +1,33 @@
+import axios from 'axios';
+
+export interface RelayerResponse {
+ name: string;
+ homepage_url: string;
+ app_url: string;
+ header_img: string;
+ logo_img: string;
+ networks: RelayerResponseNetwork[];
+}
+
+export interface RelayerResponseNetwork {
+ networkId: number;
+ sra_http_endpoint?: string;
+ sra_ws_endpoint?: string;
+ static_order_fields?: {
+ fee_recipient_addresses?: string[];
+ taker_addresses?: string[];
+ };
+}
+
+export class RelayerRegistrySource {
+ private _url: string;
+
+ constructor(url: string) {
+ this._url = url;
+ }
+
+ public async getRelayerInfoAsync(): Promise<RelayerResponse[]> {
+ const resp = await axios.get<RelayerResponse[]>(this._url);
+ return resp.data;
+ }
+}
diff --git a/packages/pipeline/src/entities/Relayer.ts b/packages/pipeline/src/entities/Relayer.ts
new file mode 100644
index 000000000..ebdcbf345
--- /dev/null
+++ b/packages/pipeline/src/entities/Relayer.ts
@@ -0,0 +1,22 @@
+import { Column, Entity, PrimaryColumn } from 'typeorm';
+
+@Entity()
+export class Relayer {
+ @PrimaryColumn() public name!: string;
+
+ @Column() public url!: string;
+ @Column({ nullable: true, type: String })
+ public sraHttpEndpoint!: string | null;
+ @Column({ nullable: true, type: String })
+ public sraWsEndpoint!: string | null;
+ @Column({ nullable: true, type: String })
+ public appUrl!: string | null;
+
+ // TODO(albrow): Add exchange contract or protocol version?
+ // TODO(albrow): Add network ids for addresses?
+
+ @Column({ type: 'varchar', array: true })
+ public feeRecipientAddresses!: string[];
+ @Column({ type: 'varchar', array: true })
+ public takerAddresses!: string[];
+}
diff --git a/packages/pipeline/src/index.ts b/packages/pipeline/src/index.ts
index ad0e4c68f..9483eb257 100644
--- a/packages/pipeline/src/index.ts
+++ b/packages/pipeline/src/index.ts
@@ -4,27 +4,31 @@ import 'reflect-metadata';
import { Connection, createConnection } from 'typeorm';
import { ExchangeEventsSource } from './data_sources/contract-wrappers/exchange_events';
+import { RelayerRegistrySource } from './data_sources/relayer-registry';
import { Web3Source } from './data_sources/web3';
import { Block } from './entities/Block';
import { ExchangeFillEvent } from './entities/ExchangeFillEvent';
+import { Relayer } from './entities/Relayer';
import { Transaction } from './entities/Transaction';
-import { testConfig } from './ormconfig';
+import { deployConfig } from './ormconfig';
import { parseExchangeEvents } from './parsers/events';
+import { parseRelayers } from './parsers/relayer_registry';
import { parseBlock, parseTransaction } from './parsers/web3';
const EXCHANGE_START_BLOCK = 6271590; // Block number when the Exchange contract was deployed to mainnet.
+const RELAYER_REGISTRY_URL = 'https://raw.githubusercontent.com/0xProject/0x-relayer-registry/master/relayers.json';
let connection: Connection;
(async () => {
- connection = await createConnection(testConfig);
+ connection = await createConnection(deployConfig);
const provider = web3Factory.getRpcProvider({
rpcUrl: 'https://mainnet.infura.io',
});
- await getExchangeEventsAsync(provider);
- await getBlockAsync(provider);
- await getTransactionAsync(provider);
- console.log('Exiting process');
+ // await getExchangeEventsAsync(provider);
+ // await getBlockAsync(provider);
+ // await getTransactionAsync(provider);
+ await getRelayers(RELAYER_REGISTRY_URL);
process.exit(0);
})();
@@ -66,3 +70,16 @@ async function getTransactionAsync(provider: Web3ProviderEngine): Promise<void>
await txsRepository.save(tx);
console.log('Done saving tx.');
}
+
+async function getRelayers(url: string): Promise<void> {
+ console.log('Getting relayer info...');
+ const relayerRepository = connection.getRepository(Relayer);
+ const relayerSource = new RelayerRegistrySource(RELAYER_REGISTRY_URL);
+ const relayersResp = await relayerSource.getRelayerInfoAsync();
+ const relayers = parseRelayers(relayersResp);
+ console.log('Saving relayer info...');
+ // for (const relayer of relayers) {
+ await relayerRepository.save(relayers);
+ // }
+ console.log('Done saving relayers.');
+}
diff --git a/packages/pipeline/src/parsers/relayer_registry/index.ts b/packages/pipeline/src/parsers/relayer_registry/index.ts
new file mode 100644
index 000000000..6eca10167
--- /dev/null
+++ b/packages/pipeline/src/parsers/relayer_registry/index.ts
@@ -0,0 +1,28 @@
+import * as R from 'ramda';
+
+import { RelayerResponse, RelayerResponseNetwork } from '../../data_sources/relayer-registry';
+import { Relayer } from '../../entities/Relayer';
+
+export const parseRelayers = R.map(parseRelayer);
+
+function parseRelayer(relayerResp: RelayerResponse): Relayer {
+ const relayer = new Relayer();
+ relayer.name = relayerResp.name;
+ relayer.url = relayerResp.homepage_url;
+ relayer.appUrl = relayerResp.app_url;
+ const mainnet = getMainNetwork(relayerResp);
+ if (mainnet !== undefined) {
+ relayer.sraHttpEndpoint = mainnet.sra_http_endpoint || null;
+ relayer.sraWsEndpoint = mainnet.sra_ws_endpoint || null;
+ relayer.feeRecipientAddresses = R.path(['static_order_fields', 'fee_recipient_addresses'], mainnet) || [];
+ relayer.takerAddresses = R.path(['static_order_fields', 'taker_addresses'], mainnet) || [];
+ } else {
+ relayer.feeRecipientAddresses = [];
+ relayer.takerAddresses = [];
+ }
+ return relayer;
+}
+
+function getMainNetwork(relayerResp: RelayerResponse): RelayerResponseNetwork | undefined {
+ return R.find(network => network.networkId === 1, relayerResp.networks);
+}