Skip to content

Commit

Permalink
Refactor atomex builder, network option
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima-net committed Aug 11, 2022
1 parent e0ca591 commit cf7f7b4
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 61 deletions.
58 changes: 4 additions & 54 deletions src/atomexBuilder/atomexBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { AtomexBlockchainOptions } from '../atomex/models/index';
import type { AuthorizationManager } from '../authorization/index';
import { AtomexBlockchainProvider, SignersManager } from '../blockchain/index';
import type { DeepReadonly } from '../core/index';
import { EthereumBalancesProvider, EthereumBlockchainToolkitProvider, ethereumMainnetCurrencies, EthereumSwapTransactionsProvider, ethereumTestnetCurrencies } from '../ethereum/index';
import { createDefaultEthereumBlockchainOptions } from '../ethereum/index';
import { ExchangeManager, InMemoryExchangeSymbolsProvider } from '../exchange/index';
import { SwapManager } from '../swaps/swapManager';
import { TezosBalancesProvider, TezosBlockchainToolkitProvider, tezosMainnetCurrencies, TezosSwapTransactionsProvider, tezosTestnetCurrencies } from '../tezos/index';
import { createDefaultTezosBlockchainOptions } from '../tezos/index';
import type { AtomexBuilderOptions } from './atomexBuilderOptions';
import { createDefaultExchangeService } from './atomexComponents/exchangeService';
import { AuthorizationManagerDefaultComponentOptions, createDefaultAuthorizationManager } from './atomexComponents/index';
Expand Down Expand Up @@ -106,58 +106,8 @@ export class AtomexBuilder {

protected createDefaultBlockchainOptions(): Record<string, AtomexBlockchainOptions> {
return {
tezos: this.createDefaultTezosBlockchainOptions(),
ethereum: this.createDefaultEthereumBlockchainOptions()
tezos: createDefaultTezosBlockchainOptions(),
ethereum: createDefaultEthereumBlockchainOptions()
};
}

protected createDefaultTezosBlockchainOptions(): AtomexBlockchainOptions {
const balancesProvider = new TezosBalancesProvider();
const swapTransactionsProvider = new TezosSwapTransactionsProvider();
const blockchainToolkitProvider = new TezosBlockchainToolkitProvider();

const tezosOptions: AtomexBlockchainOptions = {
mainnet: {
currencies: tezosMainnetCurrencies,
balancesProvider,
swapTransactionsProvider,
blockchainToolkitProvider,
currencyOptions: {}
},
testnet: {
currencies: tezosTestnetCurrencies,
balancesProvider,
swapTransactionsProvider,
blockchainToolkitProvider,
currencyOptions: {}
}
};

return tezosOptions;
}

protected createDefaultEthereumBlockchainOptions(): AtomexBlockchainOptions {
const balancesProvider = new EthereumBalancesProvider();
const swapTransactionsProvider = new EthereumSwapTransactionsProvider();
const blockchainToolkitProvider = new EthereumBlockchainToolkitProvider();

const ethereumOptions: AtomexBlockchainOptions = {
mainnet: {
currencies: ethereumMainnetCurrencies,
balancesProvider,
swapTransactionsProvider,
blockchainToolkitProvider,
currencyOptions: {}
},
testnet: {
currencies: ethereumTestnetCurrencies,
balancesProvider,
swapTransactionsProvider,
blockchainToolkitProvider,
currencyOptions: {}
}
};

return ethereumOptions;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AtomexBlockchainNetworkOptions } from '../atomex/models/atomexOptions';
import type { EthereumCurrency } from './models/currency';
import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions';
import type { EthereumCurrency } from '../models/currency';

const ethereumNativeCurrency: EthereumCurrency = {
id: 'ETH',
Expand Down
31 changes: 31 additions & 0 deletions src/ethereum/config/defaultOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { AtomexBlockchainOptions } from '../../atomex/models/index';
import { EthereumBalancesProvider } from '../balancesProviders/index';
import { Web3BlockchainToolkitProvider } from '../blockchainToolkitProviders/index';
import { EthereumSwapTransactionsProvider } from '../swapTransactionsProviders/index';
import { ethereumMainnetCurrencies, ethereumTestnetCurrencies } from './currencies';

export const createDefaultEthereumBlockchainOptions = (): AtomexBlockchainOptions => {
const mainnetRpcUrl = 'https://mainnet.infura.io/v3/';
const testNetRpcUrl = 'https://goerli.infura.io/v3/';
const balancesProvider = new EthereumBalancesProvider();
const swapTransactionsProvider = new EthereumSwapTransactionsProvider();

const tezosOptions: AtomexBlockchainOptions = {
mainnet: {
currencies: ethereumMainnetCurrencies,
currencyOptions: {},
blockchainToolkitProvider: new Web3BlockchainToolkitProvider(mainnetRpcUrl),
balancesProvider,
swapTransactionsProvider,
},
testnet: {
currencies: ethereumTestnetCurrencies,
currencyOptions: {},
blockchainToolkitProvider: new Web3BlockchainToolkitProvider(testNetRpcUrl),
balancesProvider,
swapTransactionsProvider,
}
};

return tezosOptions;
};
2 changes: 2 additions & 0 deletions src/ethereum/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { ethereumMainnetCurrencies, ethereumTestnetCurrencies } from './currencies';
export { createDefaultEthereumBlockchainOptions } from './defaultOptions';
4 changes: 2 additions & 2 deletions src/ethereum/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { Web3EthereumSigner } from './signers';
export { ethereumMainnetCurrencies, ethereumTestnetCurrencies } from './currencies';
export { ethereumMainnetCurrencies, ethereumTestnetCurrencies, createDefaultEthereumBlockchainOptions } from './config/index';
export { EthereumBalancesProvider } from './balancesProviders';
export { EthereumSwapTransactionsProvider } from './swapTransactionsProviders';
export { EthereumBlockchainToolkitProvider } from './blockchainToolkitProviders';
export { Web3BlockchainToolkitProvider } from './blockchainToolkitProviders';
4 changes: 2 additions & 2 deletions src/tezos/currencies.ts → src/tezos/config/currencies.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AtomexBlockchainNetworkOptions } from '../atomex/models/atomexOptions';
import type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './models/index';
import type { AtomexBlockchainNetworkOptions } from '../../atomex/models/atomexOptions';
import type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from '../models/index';

const tezosNativeCurrency: TezosCurrency = {
id: 'XTZ',
Expand Down
31 changes: 31 additions & 0 deletions src/tezos/config/defaultOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { AtomexBlockchainOptions } from '../../atomex/models/index';
import { TezosBalancesProvider } from '../balancesProviders/index';
import { TezosBlockchainToolkitProvider } from '../blockchainToolkitProviders/index';
import { TezosSwapTransactionsProvider } from '../swapTransactionsProviders/index';
import { tezosMainnetCurrencies, tezosTestnetCurrencies } from './currencies';

export const createDefaultTezosBlockchainOptions = (): AtomexBlockchainOptions => {
const mainnetRpcUrl = 'https://mainnet.api.tez.ie';
const testNetRpcUrl = 'https://jakartanet.ecadinfra.com';
const balancesProvider = new TezosBalancesProvider();
const swapTransactionsProvider = new TezosSwapTransactionsProvider();

const tezosOptions: AtomexBlockchainOptions = {
mainnet: {
currencies: tezosMainnetCurrencies,
currencyOptions: {},
blockchainToolkitProvider: new TezosBlockchainToolkitProvider(mainnetRpcUrl),
balancesProvider,
swapTransactionsProvider,
},
testnet: {
currencies: tezosTestnetCurrencies,
currencyOptions: {},
blockchainToolkitProvider: new TezosBlockchainToolkitProvider(testNetRpcUrl),
balancesProvider,
swapTransactionsProvider,
}
};

return tezosOptions;
};
2 changes: 2 additions & 0 deletions src/tezos/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { tezosMainnetCurrencies, tezosTestnetCurrencies } from './currencies';
export { createDefaultTezosBlockchainOptions } from './defaultOptions';
2 changes: 1 addition & 1 deletion src/tezos/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export { WalletTezosSigner } from './walletTezosSigner/index';
export { InMemoryTezosSigner } from './inMemoryTezosSigner';
export type { TezosCurrency, TezosFA12Currency, TezosFA2Currency } from './models/index';
export { tezosMainnetCurrencies, tezosTestnetCurrencies } from './currencies';
export { tezosMainnetCurrencies, tezosTestnetCurrencies, createDefaultTezosBlockchainOptions } from './config/index';
export { TezosBalancesProvider } from './balancesProviders';
export { TezosSwapTransactionsProvider } from './swapTransactionsProviders';
export { TezosBlockchainToolkitProvider } from './blockchainToolkitProviders';

0 comments on commit cf7f7b4

Please sign in to comment.