Skip to content

Commit 29d6479

Browse files
author
Karl Ranna
committed
feat(db): add simnet default currencies and pairs
1 parent e73ec4b commit 29d6479

File tree

9 files changed

+182
-53
lines changed

9 files changed

+182
-53
lines changed

β€Žlib/db/DB.tsβ€Ž

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import Sequelize from 'sequelize';
33
import Bluebird from 'bluebird';
44
import Logger from '../Logger';
55
import * as db from './types';
6-
import { SwapClientType, XuNetwork } from '../constants/enums';
6+
import { XuNetwork } from '../constants/enums';
77
import { promises as fs } from 'fs';
8-
import seeds from '../p2p/seeds';
8+
import {
9+
defaultNodes,
10+
defaultCurrencies,
11+
defaultPairs,
12+
} from '../db/seeds';
913

1014
type Models = {
1115
Node: Sequelize.Model<db.NodeInstance, db.NodeAttributes>;
@@ -71,20 +75,22 @@ class DB {
7175

7276
if (shouldInitDb) {
7377
// initialize database with the seed nodes for the configured network
74-
const nodes = seeds.get(network);
78+
const nodes = defaultNodes(network);
7579
if (nodes) {
7680
await Node.bulkCreate(nodes);
7781
}
7882

79-
// initialize new databases with default data.
80-
await Currency.bulkCreate(<db.CurrencyAttributes[]>[
81-
{ id: 'BTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
82-
{ id: 'LTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
83-
]);
83+
// initialize database with the default currencies for the configured network
84+
const currencies = defaultCurrencies(network);
85+
if (currencies) {
86+
await Currency.bulkCreate(currencies);
87+
}
8488

85-
await Pair.bulkCreate(<db.PairAttributes[]>[
86-
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
87-
]);
89+
// initialize database with the default trading pairs for the configured network
90+
const pairs = defaultPairs(network);
91+
if (pairs) {
92+
await Pair.bulkCreate(pairs);
93+
}
8894
}
8995
}
9096

β€Žlib/db/seeds/index.tsβ€Ž

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {
2+
nodes as mainnetNodes,
3+
currencies as mainnetCurrencies,
4+
pairs as mainnetPairs,
5+
} from './mainnet';
6+
import {
7+
nodes as testnetNodes,
8+
currencies as testnetCurrencies,
9+
pairs as testnetPairs,
10+
} from './testnet';
11+
import {
12+
nodes as simnetNodes,
13+
currencies as simnetCurrencies,
14+
pairs as simnetPairs,
15+
} from './simnet';
16+
import * as db from '../../db/types';
17+
import { XuNetwork } from '../../constants/enums';
18+
19+
const nodes: { [network: string]: db.NodeAttributes[] | undefined } = {
20+
[XuNetwork.MainNet]: mainnetNodes,
21+
[XuNetwork.TestNet]: testnetNodes,
22+
[XuNetwork.SimNet]: simnetNodes,
23+
};
24+
25+
const currencies: { [network: string]: db.CurrencyAttributes[] | undefined } = {
26+
[XuNetwork.MainNet]: mainnetCurrencies,
27+
[XuNetwork.TestNet]: testnetCurrencies,
28+
[XuNetwork.SimNet]: simnetCurrencies,
29+
};
30+
31+
const pairs: { [network: string]: db.PairAttributes[] | undefined } = {
32+
[XuNetwork.MainNet]: mainnetPairs,
33+
[XuNetwork.TestNet]: testnetPairs,
34+
[XuNetwork.SimNet]: simnetPairs,
35+
};
36+
37+
const defaultNodes = (xuNetwork: XuNetwork): db.NodeAttributes[] | undefined => nodes[xuNetwork];
38+
const defaultCurrencies = (xuNetwork: XuNetwork): db.CurrencyAttributes[] | undefined => currencies[xuNetwork];
39+
const defaultPairs = (xuNetwork: XuNetwork): db.PairAttributes[] | undefined => pairs[xuNetwork];
40+
41+
export {
42+
defaultNodes,
43+
defaultCurrencies,
44+
defaultPairs,
45+
};

β€Žlib/db/seeds/mainnet.tsβ€Ž

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import * as db from '../../db/types';
2+
import { SwapClientType } from '../../constants/enums';
3+
4+
const nodes = [] as db.NodeAttributes[];
5+
6+
const currencies = [
7+
{ id: 'BTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
8+
{ id: 'LTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
9+
{
10+
id: 'WETH',
11+
swapClient: SwapClientType.Raiden,
12+
decimalPlaces: 18,
13+
tokenAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
14+
},
15+
{
16+
id: 'DAI',
17+
swapClient: SwapClientType.Raiden,
18+
decimalPlaces: 18,
19+
tokenAddress: '0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359',
20+
},
21+
] as db.CurrencyAttributes[];
22+
23+
const pairs = [
24+
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
25+
{ baseCurrency: 'WETH', quoteCurrency: 'BTC' },
26+
{ baseCurrency: 'BTC', quoteCurrency: 'DAI' },
27+
{ baseCurrency: 'LTC', quoteCurrency: 'DAI' },
28+
] as db.PairAttributes[];
29+
30+
export {
31+
nodes,
32+
currencies,
33+
pairs,
34+
};

β€Žlib/db/seeds/simnet.tsβ€Ž

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as db from '../../db/types';
2+
import { SwapClientType } from '../../constants/enums';
3+
4+
const nodes = [
5+
{
6+
nodePubKey: '02b66438730d1fcdf4a4ae5d3d73e847a272f160fee2938e132b52cab0a0d9cfc6',
7+
addresses: [{ host: 'xud1.simnet.exchangeunion.com', port: 8885 }],
8+
},
9+
{
10+
nodePubKey: '028599d05b18c0c3f8028915a17d603416f7276c822b6b2d20e71a3502bd0f9e0a',
11+
addresses: [{ host: 'xud2.simnet.exchangeunion.com', port: 8885 }],
12+
},
13+
{
14+
nodePubKey: '03fd337659e99e628d0487e4f87acf93e353db06f754dccc402f2de1b857a319d0',
15+
addresses: [{ host: 'xud3.simnet.exchangeunion.com', port: 8885 }],
16+
},
17+
] as db.NodeAttributes[];
18+
19+
const currencies = [
20+
{ id: 'BTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
21+
{ id: 'LTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
22+
{
23+
id: 'WETH',
24+
swapClient: SwapClientType.Raiden,
25+
decimalPlaces: 18,
26+
tokenAddress: '0x9F50cEA29307d7D91c5176Af42f3aB74f0190dD3',
27+
},
28+
{
29+
id: 'DAI',
30+
swapClient: SwapClientType.Raiden,
31+
decimalPlaces: 18,
32+
tokenAddress: '0x76671A2831Dc0aF53B09537dea57F1E22899655d',
33+
},
34+
] as db.CurrencyAttributes[];
35+
36+
const pairs = [
37+
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
38+
{ baseCurrency: 'WETH', quoteCurrency: 'BTC' },
39+
{ baseCurrency: 'BTC', quoteCurrency: 'DAI' },
40+
{ baseCurrency: 'LTC', quoteCurrency: 'DAI' },
41+
] as db.PairAttributes[];
42+
43+
export {
44+
nodes,
45+
currencies,
46+
pairs,
47+
};

β€Žlib/db/seeds/testnet.tsβ€Ž

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as db from '../../db/types';
2+
import { SwapClientType } from '../../constants/enums';
3+
4+
const nodes = [
5+
{
6+
nodePubKey: '02ee43f389523d7947e6a456eeb70f8429535f216654d1b1fdc753e48a96ca1469',
7+
addresses: [{ host: 'xud1.testnet.exchangeunion.com', port: 8885 }],
8+
},
9+
] as db.NodeAttributes[];
10+
11+
const currencies = [
12+
{ id: 'BTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
13+
{ id: 'LTC', swapClient: SwapClientType.Lnd, decimalPlaces: 8 },
14+
{
15+
id: 'WETH',
16+
swapClient: SwapClientType.Raiden,
17+
decimalPlaces: 18,
18+
tokenAddress: '0xc778417e063141139fce010982780140aa0cd5ab',
19+
},
20+
{
21+
id: 'DAI',
22+
swapClient: SwapClientType.Raiden,
23+
decimalPlaces: 18,
24+
tokenAddress: '0x6d56f1c68356a147897d4f9a3dc63b97a275b8fa',
25+
},
26+
] as db.CurrencyAttributes[];
27+
28+
const pairs = [
29+
{ baseCurrency: 'LTC', quoteCurrency: 'BTC' },
30+
{ baseCurrency: 'WETH', quoteCurrency: 'BTC' },
31+
{ baseCurrency: 'BTC', quoteCurrency: 'DAI' },
32+
{ baseCurrency: 'LTC', quoteCurrency: 'DAI' },
33+
] as db.PairAttributes[];
34+
35+
export {
36+
nodes,
37+
currencies,
38+
pairs,
39+
};

β€Žlib/p2p/seeds/index.tsβ€Ž

Lines changed: 0 additions & 15 deletions
This file was deleted.

β€Žlib/p2p/seeds/mainnet.tsβ€Ž

Lines changed: 0 additions & 3 deletions
This file was deleted.

β€Žlib/p2p/seeds/simnet.tsβ€Ž

Lines changed: 0 additions & 16 deletions
This file was deleted.

β€Žlib/p2p/seeds/testnet.tsβ€Ž

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
Β (0)