@cityofzion/blockchain-service 0.12.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>;
@@ -226,3 +230,59 @@ export interface LedgerService {
226
230
  getAddress(transport: Transport): Promise<string>;
227
231
  getPublicKey(transport: Transport): Promise<string>;
228
232
  }
233
+ export type SwapRoute = {
234
+ assetToUseSymbol: string;
235
+ reservesToUse: string;
236
+ assetToReceiveSymbol: string;
237
+ reservesToReceive: string;
238
+ };
239
+ export type SwapControllerServiceEvents = {
240
+ accountToUse: (account: Account | null) => void | Promise<void>;
241
+ amountToUse: (amount: string | null) => void | Promise<void>;
242
+ tokenToUse: (token: Token | null) => void | Promise<void>;
243
+ reservesToUse: (reserves: string | null) => void | Promise<void>;
244
+ amountToReceive: (amount: string | null) => void | Promise<void>;
245
+ tokenToReceive: (token: Token | null) => void | Promise<void>;
246
+ reservesToReceive: (reserves: string | null) => void | Promise<void>;
247
+ minimumReceived: (minimumReceived: string | null) => void | Promise<void>;
248
+ maximumSelling: (maximumSelling: string | null) => void | Promise<void>;
249
+ deadline: (deadline: string) => void | Promise<void>;
250
+ slippage: (slippage: number) => void | Promise<void>;
251
+ liquidityProviderFee: (liquidityProviderFee: string | null) => void | Promise<void>;
252
+ priceImpact: (priceImpact: string | null) => void | Promise<void>;
253
+ priceInverse: (priceInverse: string | null) => void | Promise<void>;
254
+ routes: (routes: SwapRoute[] | null) => void | Promise<void>;
255
+ lastAmountChanged: (lastAmountChanged: 'amountToUse' | 'amountToReceive' | null) => void | Promise<void>;
256
+ };
257
+ export type SwapControllerServiceSwapArgs<T extends string> = {
258
+ amountToUse: string;
259
+ amountToReceive: string;
260
+ tokenToUse: Token;
261
+ tokenToReceive: Token;
262
+ address: string;
263
+ deadline: string;
264
+ network: Network<T>;
265
+ };
266
+ export type SwapControllerServiceSwapToUseArgs<T extends string> = {
267
+ minimumReceived: string;
268
+ type: 'swapTokenToUse';
269
+ } & SwapControllerServiceSwapArgs<T>;
270
+ export type SwapControllerServiceSwapToReceiveArgs<T extends string> = {
271
+ maximumSelling: string;
272
+ type: 'swapTokenToReceive';
273
+ } & SwapControllerServiceSwapArgs<T>;
274
+ export interface SwapControllerService<AvailableNetworkIds extends string> {
275
+ eventEmitter: TypedEmitter<SwapControllerServiceEvents>;
276
+ setAccountToUse(account: Account | null): void;
277
+ setAmountToUse(amount: string | null): void;
278
+ setTokenToUse(token: Token | null): void;
279
+ setAmountToReceive(amount: string | null): void;
280
+ setTokenToReceive(token: Token | null): void;
281
+ setDeadline(deadline: string): void;
282
+ setSlippage(slippage: number): void;
283
+ swap(isLedger?: boolean): void;
284
+ buildSwapArgs(): SwapControllerServiceSwapToUseArgs<AvailableNetworkIds> | SwapControllerServiceSwapToReceiveArgs<AvailableNetworkIds>;
285
+ setReserves(): void;
286
+ startListeningBlockGeneration(): void;
287
+ stopListeningBlockGeneration(): void;
288
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cityofzion/blockchain-service",
3
- "version": "0.12.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",