@cityofzion/blockchain-service 0.13.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- import { AccountWithDerivationPath, BlockchainService, Network, PartialBy } from './interfaces';
1
+ import { AccountWithDerivationPath, BlockchainService, PartialNetwork } from './interfaces';
2
2
  export declare class BSAggregator<BSCustomName extends string = string, BSCustom extends BlockchainService<BSCustomName> = BlockchainService<BSCustomName>> {
3
3
  #private;
4
4
  readonly blockchainServicesByName: Record<BSCustomName, BSCustom>;
5
5
  constructor(blockchainServices: Record<BSCustomName, BSCustom>);
6
- setNetwork(network: PartialBy<Network, 'url'>): void;
6
+ setNetwork(network: PartialNetwork): void;
7
7
  addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
8
8
  validateAddressAllBlockchains(address: string): boolean;
9
9
  validateTextAllBlockchains(text: string): boolean;
@@ -1,8 +1,7 @@
1
- import { Currency, ExchangeDataService, GetTokenPriceHistory, NetworkType, Token, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
1
+ import { Currency, ExchangeDataService, GetTokenPriceHistory, Token, TokenPricesHistoryResponse, TokenPricesResponse } from './interfaces';
2
2
  export declare class CryptoCompareEDS implements ExchangeDataService {
3
3
  #private;
4
- networkType: NetworkType;
5
- constructor(network: NetworkType, tokens?: Token[]);
4
+ constructor(tokens?: Token[]);
6
5
  getTokenPrices(currency: Currency): Promise<TokenPricesResponse[]>;
7
6
  getTokenPriceHistory(params: GetTokenPriceHistory): Promise<TokenPricesHistoryResponse[]>;
8
7
  }
@@ -27,17 +27,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
27
27
  exports.CryptoCompareEDS = void 0;
28
28
  const axios_1 = __importDefault(require("axios"));
29
29
  class CryptoCompareEDS {
30
- constructor(network, tokens = []) {
30
+ constructor(tokens = []) {
31
31
  _CryptoCompareEDS_axiosInstance.set(this, void 0);
32
32
  _CryptoCompareEDS_tokens.set(this, void 0);
33
- this.networkType = network;
34
33
  __classPrivateFieldSet(this, _CryptoCompareEDS_tokens, tokens, "f");
35
34
  __classPrivateFieldSet(this, _CryptoCompareEDS_axiosInstance, axios_1.default.create({ baseURL: 'https://min-api.cryptocompare.com' }), "f");
36
35
  }
37
36
  getTokenPrices(currency) {
38
37
  return __awaiter(this, void 0, void 0, function* () {
39
- if (this.networkType !== 'mainnet')
40
- throw new Error('Exchange is only available on mainnet');
41
38
  const tokenSymbols = __classPrivateFieldGet(this, _CryptoCompareEDS_tokens, "f").map(token => token.symbol);
42
39
  const { data: prices } = yield __classPrivateFieldGet(this, _CryptoCompareEDS_axiosInstance, "f").get('/data/pricemultifull', {
43
40
  params: {
@@ -1,6 +1,5 @@
1
1
  import Transport from '@ledgerhq/hw-transport';
2
2
  import TypedEmitter from 'typed-emitter';
3
- export type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4
3
  export type Account = {
5
4
  key: string;
6
5
  type: 'wif' | 'privateKey' | 'publicKey';
@@ -15,11 +14,16 @@ export interface Token {
15
14
  hash: string;
16
15
  decimals: number;
17
16
  }
18
- export type NetworkType = 'mainnet' | 'testnet' | 'custom';
19
- export type Network = {
20
- type: NetworkType;
17
+ export type Network<T extends string = string> = {
18
+ id: T;
19
+ name: string;
21
20
  url: string;
22
21
  };
22
+ export type PartialNetwork<T extends string = string> = {
23
+ id: T;
24
+ name?: string;
25
+ url?: string;
26
+ };
23
27
  export type IntentTransferParam = {
24
28
  receiverAddress: string;
25
29
  tokenHash: string;
@@ -33,15 +37,15 @@ export type TransferParam = {
33
37
  priorityFee?: string;
34
38
  isLedger?: boolean;
35
39
  };
36
- export interface BlockchainService<BSCustomName extends string = string> {
40
+ export interface BlockchainService<BSCustomName extends string = string, BSAvailableNetworks extends string = string> {
37
41
  readonly blockchainName: BSCustomName;
38
42
  readonly derivationPath: string;
39
43
  readonly feeToken: Token;
40
44
  exchangeDataService: ExchangeDataService;
41
45
  blockchainDataService: BlockchainDataService;
42
46
  tokens: Token[];
43
- network: Network;
44
- setNetwork: (network: PartialBy<Network, 'url'>) => void;
47
+ network: Network<BSAvailableNetworks>;
48
+ setNetwork: (partialNetwork: PartialNetwork<BSAvailableNetworks>) => void;
45
49
  generateAccountFromMnemonic(mnemonic: string | string, index: number): AccountWithDerivationPath;
46
50
  generateAccountFromKey(key: string): Account;
47
51
  decrypt(keyOrJson: string, password: string): Promise<Account>;
@@ -250,24 +254,24 @@ export type SwapControllerServiceEvents = {
250
254
  routes: (routes: SwapRoute[] | null) => void | Promise<void>;
251
255
  lastAmountChanged: (lastAmountChanged: 'amountToUse' | 'amountToReceive' | null) => void | Promise<void>;
252
256
  };
253
- export type SwapControllerServiceSwapArgs = {
257
+ export type SwapControllerServiceSwapArgs<T extends string> = {
254
258
  amountToUse: string;
255
259
  amountToReceive: string;
256
260
  tokenToUse: Token;
257
261
  tokenToReceive: Token;
258
262
  address: string;
259
263
  deadline: string;
260
- network: Network;
264
+ network: Network<T>;
261
265
  };
262
- export type SwapControllerServiceSwapToUseArgs = {
266
+ export type SwapControllerServiceSwapToUseArgs<T extends string> = {
263
267
  minimumReceived: string;
264
268
  type: 'swapTokenToUse';
265
- } & SwapControllerServiceSwapArgs;
266
- export type SwapControllerServiceSwapToReceiveArgs = {
269
+ } & SwapControllerServiceSwapArgs<T>;
270
+ export type SwapControllerServiceSwapToReceiveArgs<T extends string> = {
267
271
  maximumSelling: string;
268
272
  type: 'swapTokenToReceive';
269
- } & SwapControllerServiceSwapArgs;
270
- export interface SwapControllerService {
273
+ } & SwapControllerServiceSwapArgs<T>;
274
+ export interface SwapControllerService<AvailableNetworkIds extends string> {
271
275
  eventEmitter: TypedEmitter<SwapControllerServiceEvents>;
272
276
  setAccountToUse(account: Account | null): void;
273
277
  setAmountToUse(amount: string | null): void;
@@ -277,7 +281,7 @@ export interface SwapControllerService {
277
281
  setDeadline(deadline: string): void;
278
282
  setSlippage(slippage: number): void;
279
283
  swap(isLedger?: boolean): void;
280
- buildSwapArgs(): SwapControllerServiceSwapToUseArgs | SwapControllerServiceSwapToReceiveArgs;
284
+ buildSwapArgs(): SwapControllerServiceSwapToUseArgs<AvailableNetworkIds> | SwapControllerServiceSwapToReceiveArgs<AvailableNetworkIds>;
281
285
  setReserves(): void;
282
286
  startListeningBlockGeneration(): void;
283
287
  stopListeningBlockGeneration(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "0.13.0",
3
+ "version": "1.0.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": "https://github.com/CityOfZion/blockchain-services",
@@ -15,12 +15,12 @@
15
15
  "@typescript-eslint/parser": "^6.5.0",
16
16
  "eslint": "^8.48.0",
17
17
  "ts-node": "10.9.1",
18
- "typescript": "4.9.5"
18
+ "typescript": "4.9.5",
19
+ "typed-emitter": "~2.1.0"
19
20
  },
20
21
  "dependencies": {
21
22
  "@ledgerhq/hw-transport": "~6.30.5",
22
- "axios": "1.5.1",
23
- "typed-emitter": "~2.1.0"
23
+ "axios": "1.5.1"
24
24
  },
25
25
  "scripts": {
26
26
  "build": "tsc",