aboutsummaryrefslogtreecommitdiffstats
path: root/packages/pipeline/src/scripts/update_relayer_info.ts
blob: 051289992ddd0179dcf08986bd738e875a5ea663 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import 'reflect-metadata';
import { Connection, createConnection } from 'typeorm';

import { RelayerRegistrySource } from '../data_sources/relayer-registry';
import { Relayer } from '../entities';
import { deployConfig } from '../ormconfig';
import { parseRelayers } from '../parsers/relayer_registry';
import { handleError } from '../utils';

// NOTE(albrow): We need to manually update this URL for now. Fix this when we
// have the relayer-registry behind semantic versioning.
const RELAYER_REGISTRY_URL =
    'https://raw.githubusercontent.com/0xProject/0x-relayer-registry/4701c85677d161ea729a466aebbc1826c6aa2c0b/relayers.json';

let connection: Connection;

(async () => {
    connection = await createConnection(deployConfig);
    await getRelayers();
    process.exit(0);
})().catch(handleError);

async function getRelayers(): Promise<void> {
    console.log('Getting latest 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...');
    await relayerRepository.save(relayers);
    console.log('Done saving relayer info.');
}