@cityofzion/blockchain-service 0.13.0 → 1.0.1

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,8 @@
1
- import { AccountWithDerivationPath, BlockchainService, Network, PartialBy } from './interfaces';
1
+ import { AccountWithDerivationPath, BlockchainService } 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;
7
6
  addBlockchain(name: BSCustomName, blockchain: BSCustom): void;
8
7
  validateAddressAllBlockchains(address: string): boolean;
9
8
  validateTextAllBlockchains(text: string): boolean;
@@ -28,9 +28,6 @@ class BSAggregator {
28
28
  this.blockchainServicesByName = blockchainServices;
29
29
  __classPrivateFieldSet(this, _BSAggregator_blockchainServices, Object.values(blockchainServices), "f");
30
30
  }
31
- setNetwork(network) {
32
- __classPrivateFieldGet(this, _BSAggregator_blockchainServices, "f").forEach(bs => bs.setNetwork(network));
33
- }
34
31
  addBlockchain(name, blockchain) {
35
32
  if (this.blockchainServicesByName[name])
36
33
  throw new Error(`The blockchain ${name} already exist`);
@@ -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,9 +14,9 @@ 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
  };
23
22
  export type IntentTransferParam = {
@@ -33,15 +32,15 @@ export type TransferParam = {
33
32
  priorityFee?: string;
34
33
  isLedger?: boolean;
35
34
  };
36
- export interface BlockchainService<BSCustomName extends string = string> {
35
+ export interface BlockchainService<BSCustomName extends string = string, BSAvailableNetworks extends string = string> {
37
36
  readonly blockchainName: BSCustomName;
38
37
  readonly derivationPath: string;
39
38
  readonly feeToken: Token;
40
39
  exchangeDataService: ExchangeDataService;
41
40
  blockchainDataService: BlockchainDataService;
42
41
  tokens: Token[];
43
- network: Network;
44
- setNetwork: (network: PartialBy<Network, 'url'>) => void;
42
+ network: Network<BSAvailableNetworks>;
43
+ setNetwork: (partialNetwork: Network<BSAvailableNetworks>) => void;
45
44
  generateAccountFromMnemonic(mnemonic: string | string, index: number): AccountWithDerivationPath;
46
45
  generateAccountFromKey(key: string): Account;
47
46
  decrypt(keyOrJson: string, password: string): Promise<Account>;
@@ -214,6 +213,7 @@ export type BuildNftUrlParams = {
214
213
  };
215
214
  export interface ExplorerService {
216
215
  buildTransactionUrl(hash: string): string;
216
+ buildContractUrl(contractHash: string): string;
217
217
  buildNftUrl(params: BuildNftUrlParams): string;
218
218
  }
219
219
  export type LedgerServiceEmitter = TypedEmitter<{
@@ -250,24 +250,24 @@ export type SwapControllerServiceEvents = {
250
250
  routes: (routes: SwapRoute[] | null) => void | Promise<void>;
251
251
  lastAmountChanged: (lastAmountChanged: 'amountToUse' | 'amountToReceive' | null) => void | Promise<void>;
252
252
  };
253
- export type SwapControllerServiceSwapArgs = {
253
+ export type SwapControllerServiceSwapArgs<T extends string> = {
254
254
  amountToUse: string;
255
255
  amountToReceive: string;
256
256
  tokenToUse: Token;
257
257
  tokenToReceive: Token;
258
258
  address: string;
259
259
  deadline: string;
260
- network: Network;
260
+ network: Network<T>;
261
261
  };
262
- export type SwapControllerServiceSwapToUseArgs = {
262
+ export type SwapControllerServiceSwapToUseArgs<T extends string> = {
263
263
  minimumReceived: string;
264
264
  type: 'swapTokenToUse';
265
- } & SwapControllerServiceSwapArgs;
266
- export type SwapControllerServiceSwapToReceiveArgs = {
265
+ } & SwapControllerServiceSwapArgs<T>;
266
+ export type SwapControllerServiceSwapToReceiveArgs<T extends string> = {
267
267
  maximumSelling: string;
268
268
  type: 'swapTokenToReceive';
269
- } & SwapControllerServiceSwapArgs;
270
- export interface SwapControllerService {
269
+ } & SwapControllerServiceSwapArgs<T>;
270
+ export interface SwapControllerService<AvailableNetworkIds extends string> {
271
271
  eventEmitter: TypedEmitter<SwapControllerServiceEvents>;
272
272
  setAccountToUse(account: Account | null): void;
273
273
  setAmountToUse(amount: string | null): void;
@@ -277,7 +277,7 @@ export interface SwapControllerService {
277
277
  setDeadline(deadline: string): void;
278
278
  setSlippage(slippage: number): void;
279
279
  swap(isLedger?: boolean): void;
280
- buildSwapArgs(): SwapControllerServiceSwapToUseArgs | SwapControllerServiceSwapToReceiveArgs;
280
+ buildSwapArgs(): SwapControllerServiceSwapToUseArgs<AvailableNetworkIds> | SwapControllerServiceSwapToReceiveArgs<AvailableNetworkIds>;
281
281
  setReserves(): void;
282
282
  startListeningBlockGeneration(): void;
283
283
  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.1",
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",