@galacticcouncil/sdk 0.0.6 → 0.0.7

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.
Files changed (43) hide show
  1. package/dist/index.esm.js +17 -1
  2. package/dist/index.js +3 -1
  3. package/dist/types/api/{router.d.ts → Router.d.ts} +1 -1
  4. package/dist/types/api/{tradeRouter.d.ts → TradeRouter.d.ts} +23 -17
  5. package/dist/types/api/index.d.ts +2 -2
  6. package/dist/types/client/index.d.ts +1 -1
  7. package/dist/types/errors.d.ts +12 -0
  8. package/dist/types/index.d.ts +3 -0
  9. package/dist/types/pool/{polkadotApiPoolService.d.ts → PolkadotApiPoolService.d.ts} +3 -3
  10. package/dist/types/pool/index.d.ts +8 -8
  11. package/dist/types/pool/lbp/{lbpPool.d.ts → LbpPool.d.ts} +3 -3
  12. package/dist/types/pool/omni/{omniPool.d.ts → OmniPool.d.ts} +3 -3
  13. package/dist/types/registry/Registry.d.ts +20 -0
  14. package/dist/types/registry/index.d.ts +2 -0
  15. package/dist/types/registry/types.d.ts +22 -0
  16. package/dist/types/route/bfs.d.ts +2 -2
  17. package/dist/types/route/graph.d.ts +2 -2
  18. package/dist/types/storage/Storage.d.ts +18 -0
  19. package/dist/types/storage/index.d.ts +1 -0
  20. package/dist/types/types.d.ts +21 -15
  21. package/dist/types/wallet/Wallet.d.ts +21 -0
  22. package/dist/types/wallet/balance/Erc20BalanceAdapter.d.ts +11 -0
  23. package/dist/types/wallet/balance/NativeBalanceAdapter.d.ts +14 -0
  24. package/dist/types/wallet/balance/TokenBalanceAdapter.d.ts +12 -0
  25. package/dist/types/wallet/evm/AcalaEvmProvider.d.ts +9 -0
  26. package/dist/types/wallet/evm/DefaultEvmProvider.d.ts +7 -0
  27. package/dist/types/wallet/index.d.ts +5 -0
  28. package/dist/types/wallet/types.d.ts +10 -0
  29. package/dist/types/wallet/utils.d.ts +19 -0
  30. package/package.json +15 -4
  31. package/xcmgr.sync.mjs +65 -0
  32. package/dist/types/client/cApi.d.ts +0 -0
  33. /package/dist/types/client/{polkadotApi.d.ts → PolkadotApi.d.ts} +0 -0
  34. /package/dist/types/pool/{poolFactory.d.ts → PoolFactory.d.ts} +0 -0
  35. /package/dist/types/pool/lbp/{lbpMath.d.ts → LbpMath.d.ts} +0 -0
  36. /package/dist/types/pool/lbp/{lbpPolkadotApiClient.d.ts → LbpPolkadotApiClient.d.ts} +0 -0
  37. /package/dist/types/pool/omni/{omniMath.d.ts → OmniMath.d.ts} +0 -0
  38. /package/dist/types/pool/omni/{omniPolkadotApiClient.d.ts → OmniPolkadotApiClient.d.ts} +0 -0
  39. /package/dist/types/pool/xyk/{xykMath.d.ts → XykMath.d.ts} +0 -0
  40. /package/dist/types/pool/xyk/{xykPolkadotApiClient.d.ts → XykPolkadotApiClient.d.ts} +0 -0
  41. /package/dist/types/pool/xyk/{xykPool.d.ts → XykPool.d.ts} +0 -0
  42. /package/dist/types/utils/{queue.d.ts → Queue.d.ts} +0 -0
  43. /package/dist/types/utils/{stack.d.ts → Stack.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import { PoolService, PoolBase, Hop, Pool, PoolAsset, PoolType } from '../types';
2
- export declare type RouterOptions = {
2
+ export type RouterOptions = {
3
3
  includeOnly?: PoolType[];
4
4
  };
5
5
  export declare class Router {
@@ -1,23 +1,7 @@
1
- import { Router } from './router';
1
+ import { Router } from './Router';
2
2
  import { Trade, Amount } from '../types';
3
3
  import { BigNumber } from '../utils/bignumber';
4
4
  export declare class TradeRouter extends Router {
5
- /**
6
- * Calculate and return best possible spot price for tokenIn>tokenOut
7
- *
8
- * @param {string} assetIn - Storage key of tokenIn
9
- * @param {string} assetOut - Storage key of tokenOut
10
- * @return Best possible spot price of given token pair
11
- */
12
- getBestSpotPrice(assetIn: string, assetOut: string): Promise<Amount>;
13
- /**
14
- * Calculate and return spot price for given path
15
- *
16
- * @param path - current path
17
- * @param poolsMap - pools map
18
- * @returns Spot price for given path
19
- */
20
- private getSpotPrice;
21
5
  /**
22
6
  * Check whether trade is direct or not
23
7
  *
@@ -25,6 +9,13 @@ export declare class TradeRouter extends Router {
25
9
  * @returns true if direct trade, otherwise false
26
10
  */
27
11
  private isDirectTrade;
12
+ /**
13
+ * Find best sell swap without errors, if there is none return first one found
14
+ *
15
+ * @param swaps - All possible sell routes
16
+ * @returns best sell swap if exist, otherwise first one found
17
+ */
18
+ private findBestSellRoute;
28
19
  /**
29
20
  * Calculate and return best possible sell trade for assetIn>assetOut
30
21
  *
@@ -53,6 +44,21 @@ export declare class TradeRouter extends Router {
53
44
  * @returns Sell swaps for given path with corresponding pool pairs
54
45
  */
55
46
  private toSellSwaps;
47
+ /**
48
+ * Calculate and return best possible spot price for tokenIn>tokenOut
49
+ *
50
+ * @param {string} assetIn - Storage key of tokenIn
51
+ * @param {string} assetOut - Storage key of tokenOut
52
+ * @return Best possible spot price of given token pair
53
+ */
54
+ getBestSpotPrice(assetIn: string, assetOut: string): Promise<Amount>;
55
+ /**
56
+ * Find best buy swap without errors, if there is none return first one found
57
+ *
58
+ * @param swaps - All possible sell routes
59
+ * @returns best sell swap if exist, otherwise first one found
60
+ */
61
+ private findBestBuyRoute;
56
62
  /**
57
63
  * Calculate and return best possible buy trade for assetIn>assetOut
58
64
  *
@@ -1,2 +1,2 @@
1
- export { Router } from './router';
2
- export { TradeRouter } from './tradeRouter';
1
+ export { Router } from './Router';
2
+ export { TradeRouter } from './TradeRouter';
@@ -1 +1 @@
1
- export { PolkadotApiClient } from './polkadotApi';
1
+ export { PolkadotApiClient } from './PolkadotApi';
@@ -5,3 +5,15 @@ export declare class PoolConfigNotFound extends Error {
5
5
  export declare class RouteNotFound extends Error {
6
6
  constructor(assetIn: string, assetOut: string);
7
7
  }
8
+ export declare class AssetNotFound extends Error {
9
+ constructor(asset: string);
10
+ }
11
+ export declare class StorageConfigNotFound extends Error {
12
+ constructor(param: string);
13
+ }
14
+ export declare class SubscriptionNotSupported extends Error {
15
+ constructor(subscriptionType: string);
16
+ }
17
+ export declare class ProviderConfigNotFound extends Error {
18
+ constructor(message: string);
19
+ }
@@ -1,5 +1,8 @@
1
1
  export { Router, TradeRouter } from './api';
2
2
  export * from './pool';
3
+ export * from './registry';
4
+ export * from './storage';
5
+ export * from './wallet';
3
6
  export * from './types';
4
7
  export * from './errors';
5
8
  export * from './consts';
@@ -1,7 +1,7 @@
1
1
  import { Hop, PoolBase, PoolService, PoolType, Transaction } from '../types';
2
- import { XykPolkadotApiClient } from './xyk/xykPolkadotApiClient';
3
- import { LbpPolkadotApiClient } from './lbp/lbpPolkadotApiClient';
4
- import { OmniPolkadotApiClient } from './omni/omniPolkadotApiClient';
2
+ import { XykPolkadotApiClient } from './xyk/XykPolkadotApiClient';
3
+ import { LbpPolkadotApiClient } from './lbp/LbpPolkadotApiClient';
4
+ import { OmniPolkadotApiClient } from './omni/OmniPolkadotApiClient';
5
5
  import { BigNumber } from '../utils/bignumber';
6
6
  import { ApiPromise } from '@polkadot/api';
7
7
  export declare class PolkadotApiPoolService implements PoolService {
@@ -1,8 +1,8 @@
1
- export { PolkadotApiPoolService } from './polkadotApiPoolService';
2
- export { PoolFactory } from './poolFactory';
3
- export { XykPool } from './xyk/xykPool';
4
- export { XykMath } from './xyk/xykMath';
5
- export { OmniPool } from './omni/omniPool';
6
- export { OmniMath } from './omni/omniMath';
7
- export { LbpPool } from './lbp/lbpPool';
8
- export { LbpMath } from './lbp/lbpMath';
1
+ export { PolkadotApiPoolService } from './PolkadotApiPoolService';
2
+ export { PoolFactory } from './PoolFactory';
3
+ export { XykPool } from './xyk/XykPool';
4
+ export { XykMath } from './xyk/XykMath';
5
+ export { OmniPool } from './omni/OmniPool';
6
+ export { OmniMath } from './omni/OmniMath';
7
+ export { LbpPool } from './lbp/LbpPool';
8
+ export { LbpMath } from './lbp/LbpMath';
@@ -1,13 +1,13 @@
1
1
  import { BuyTransfer, Pool, PoolBase, PoolFee, PoolPair, PoolToken, PoolType, SellTransfer } from '../../types';
2
2
  import { BigNumber } from '../../utils/bignumber';
3
- export declare type WeightedPoolPair = PoolPair & {
3
+ export type WeightedPoolPair = PoolPair & {
4
4
  weightIn: BigNumber;
5
5
  weightOut: BigNumber;
6
6
  };
7
- export declare type WeightedPoolToken = PoolToken & {
7
+ export type WeightedPoolToken = PoolToken & {
8
8
  weight: BigNumber;
9
9
  };
10
- export declare type LbpPoolBase = PoolBase & {
10
+ export type LbpPoolBase = PoolBase & {
11
11
  repayFee: PoolFee;
12
12
  repayFeeApply: boolean;
13
13
  };
@@ -1,16 +1,16 @@
1
1
  import { BuyTransfer, Pool, PoolBase, PoolFee, PoolPair, PoolToken, PoolType, SellTransfer } from '../../types';
2
2
  import { BigNumber } from '../../utils/bignumber';
3
- export declare type OmniPoolPair = PoolPair & {
3
+ export type OmniPoolPair = PoolPair & {
4
4
  hubReservesIn: BigNumber;
5
5
  hubReservesOut: BigNumber;
6
6
  sharesIn: BigNumber;
7
7
  sharesOut: BigNumber;
8
8
  };
9
- export declare type OmniPoolToken = PoolToken & {
9
+ export type OmniPoolToken = PoolToken & {
10
10
  hubReserves: BigNumber;
11
11
  shares: BigNumber;
12
12
  };
13
- export declare type OmniPoolBase = PoolBase & {
13
+ export type OmniPoolBase = PoolBase & {
14
14
  assetFee: PoolFee;
15
15
  protocolFee: PoolFee;
16
16
  hubAssetId: string;
@@ -0,0 +1,20 @@
1
+ import { Chain, ChainAsset } from './types';
2
+ declare abstract class Registry {
3
+ protected chains: Chain[];
4
+ protected assets: Record<number, ChainAsset[]>;
5
+ constructor();
6
+ protected abstract initChains(): void;
7
+ protected abstract initAssets(): void;
8
+ getChains(): Chain[];
9
+ getChain(chainId: number): Chain;
10
+ getAssets(chainId: number): ChainAsset[];
11
+ }
12
+ export declare class PolkadotRegistry extends Registry {
13
+ protected initChains(): void;
14
+ protected initAssets(): void;
15
+ }
16
+ export declare class KusamaRegistry extends Registry {
17
+ protected initChains(): void;
18
+ protected initAssets(): void;
19
+ }
20
+ export {};
@@ -0,0 +1,2 @@
1
+ export { PolkadotRegistry, KusamaRegistry } from './Registry';
2
+ export { Chain, ChainAsset, ChainAssetType } from './types';
@@ -0,0 +1,22 @@
1
+ export interface Chain {
2
+ chainkey: string;
3
+ name: string;
4
+ id: string;
5
+ paraID: number;
6
+ WSEndpoints: string[];
7
+ relaychain: string;
8
+ }
9
+ export interface ChainAssetType {
10
+ Erc20: string;
11
+ ForeignAsset: string;
12
+ LiquidCrowdloan: string;
13
+ StableAsset: string;
14
+ Token: string;
15
+ }
16
+ export interface ChainAsset {
17
+ asset: ChainAssetType;
18
+ name: string;
19
+ symbol: string;
20
+ decimals: number;
21
+ xcmInteriorKey: string;
22
+ }
@@ -1,5 +1,5 @@
1
- export declare type Path = Node[];
2
- export declare type Node = [id: number, from: string];
1
+ export type Path = Node[];
2
+ export type Node = [id: number, from: string];
3
3
  /**
4
4
  * Breadth First Search.
5
5
  *
@@ -1,6 +1,6 @@
1
1
  import { PoolBase } from '../types';
2
- export declare type Edge = [address: string, from: string, to: string];
3
- export declare type NodeEdges = {
2
+ export type Edge = [address: string, from: string, to: string];
3
+ export type NodeEdges = {
4
4
  [node: string]: Edge[];
5
5
  };
6
6
  /**
@@ -0,0 +1,18 @@
1
+ import { ApiPromise, ApiRx } from '@polkadot/api';
2
+ import { Observable } from 'rxjs';
3
+ export type StorageOptions = {
4
+ api: ApiPromise | ApiRx;
5
+ path: string;
6
+ params: any[];
7
+ };
8
+ export declare class Storage<T> {
9
+ readonly options: StorageOptions;
10
+ private subject;
11
+ constructor(options: StorageOptions);
12
+ static create<T>(options: StorageOptions): Storage<T>;
13
+ get observable(): Observable<T>;
14
+ private subscribeWithApiPromise;
15
+ private subscribeWithApiRx;
16
+ private getQuery;
17
+ private subscribe;
18
+ }
@@ -0,0 +1 @@
1
+ export { Storage } from './Storage';
@@ -1,5 +1,5 @@
1
1
  import { BigNumber } from './utils/bignumber';
2
- export declare type PoolAsset = {
2
+ export type PoolAsset = {
3
3
  id: string;
4
4
  symbol: string;
5
5
  };
@@ -22,7 +22,7 @@ export interface PoolPair {
22
22
  balanceIn: BigNumber;
23
23
  balanceOut: BigNumber;
24
24
  }
25
- export declare type PoolBase = {
25
+ export type PoolBase = {
26
26
  address: string;
27
27
  type: PoolType;
28
28
  tradeFee: PoolFee;
@@ -31,26 +31,26 @@ export declare type PoolBase = {
31
31
  maxOutRatio: number;
32
32
  minTradingLimit: number;
33
33
  };
34
- export declare type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
35
- export declare type PoolFee = [numerator: number, denominator: number];
36
- export declare type PoolToken = PoolAsset & {
34
+ export type PoolLimits = Pick<PoolBase, 'maxInRatio' | 'maxOutRatio' | 'minTradingLimit'>;
35
+ export type PoolFee = [numerator: number, denominator: number];
36
+ export type PoolToken = PoolAsset & {
37
37
  balance: string;
38
38
  decimals: number;
39
39
  };
40
- export declare type PoolSell = {
40
+ export type PoolSell = {
41
41
  calculatedOut: BigNumber;
42
42
  };
43
- export declare type PoolBuy = {
43
+ export type PoolBuy = {
44
44
  calculatedIn: BigNumber;
45
45
  };
46
- export declare type Transfer = {
46
+ export type Transfer = {
47
47
  amountIn: BigNumber;
48
48
  amountOut: BigNumber;
49
49
  feePct: number;
50
50
  errors: PoolError[];
51
51
  };
52
- export declare type SellTransfer = Transfer & PoolSell;
53
- export declare type BuyTransfer = Transfer & PoolBuy;
52
+ export type SellTransfer = Transfer & PoolSell;
53
+ export type BuyTransfer = Transfer & PoolBuy;
54
54
  export interface Pool extends PoolBase {
55
55
  validPair(tokenIn: string, tokenOut: string): boolean;
56
56
  parsePoolPair(tokenIn: string, tokenOut: string): PoolPair;
@@ -72,13 +72,13 @@ export interface Transaction {
72
72
  name?: string;
73
73
  get<T>(): T;
74
74
  }
75
- export declare type Hop = {
75
+ export type Hop = {
76
76
  poolType: PoolType;
77
77
  poolId: string;
78
78
  assetIn: string;
79
79
  assetOut: string;
80
80
  };
81
- export declare type Swap = Hop & Humanizer & {
81
+ export type Swap = Hop & Humanizer & {
82
82
  assetInDecimals: number;
83
83
  assetOutDecimals: number;
84
84
  amountIn: BigNumber;
@@ -88,8 +88,8 @@ export declare type Swap = Hop & Humanizer & {
88
88
  priceImpactPct: number;
89
89
  errors: PoolError[];
90
90
  };
91
- export declare type SellSwap = Swap & PoolSell;
92
- export declare type BuySwap = Swap & PoolBuy;
91
+ export type SellSwap = Swap & PoolSell;
92
+ export type BuySwap = Swap & PoolBuy;
93
93
  export declare enum TradeType {
94
94
  Buy = "Buy",
95
95
  Sell = "Sell"
@@ -108,7 +108,13 @@ export interface Trade extends Humanizer {
108
108
  export interface Humanizer {
109
109
  toHuman(): any;
110
110
  }
111
- export declare type Amount = {
111
+ export type Amount = {
112
112
  amount: BigNumber;
113
113
  decimals: number;
114
114
  };
115
+ export interface AssetBalance {
116
+ free: BigNumber;
117
+ locked: BigNumber;
118
+ reserved: BigNumber;
119
+ available: BigNumber;
120
+ }
@@ -0,0 +1,21 @@
1
+ import { ApiPromise, ApiRx } from '@polkadot/api';
2
+ import { ChainAsset } from '../registry';
3
+ import { BalanceAdapter, EvmProvider } from './types';
4
+ import { Observable } from 'rxjs';
5
+ import { AssetBalance } from '../types';
6
+ interface WalletConfigs {
7
+ evmProvider?: EvmProvider;
8
+ }
9
+ export declare class Wallet {
10
+ readonly api: ApiPromise | ApiRx;
11
+ readonly assets: ChainAsset[];
12
+ readonly adapters: Record<string, BalanceAdapter>;
13
+ constructor(api: ApiPromise | ApiRx, assets: ChainAsset[], cfg?: WalletConfigs);
14
+ getAssets(): ChainAsset[];
15
+ getAsset(assetSymbol: string, assetType?: string): ChainAsset | undefined;
16
+ subscribeBalance(assetSymbol: string, assetType: string | undefined, address: string): Observable<AssetBalance>;
17
+ getBalance(assetSymbol: string, assetType: string | undefined, address: string): Promise<AssetBalance>;
18
+ private validateAsset;
19
+ private validateAdapter;
20
+ }
21
+ export {};
@@ -0,0 +1,11 @@
1
+ import { AbstractProvider } from 'ethers';
2
+ import { Observable } from 'rxjs';
3
+ import { AssetBalance } from '../../types';
4
+ import { ChainAsset } from '../../registry';
5
+ import { BalanceAdapter, EvmProvider } from '../types';
6
+ export declare class Erc20BalanceAdapter implements BalanceAdapter {
7
+ readonly client: AbstractProvider;
8
+ readonly evmProvider: EvmProvider;
9
+ constructor(evmProvider: EvmProvider);
10
+ getObserver(asset: ChainAsset, address: string): Observable<AssetBalance>;
11
+ }
@@ -0,0 +1,14 @@
1
+ import { ApiPromise, ApiRx } from '@polkadot/api';
2
+ import { AssetBalance } from '../../types';
3
+ import { BigNumber } from '../../utils/bignumber';
4
+ import { Observable } from 'rxjs';
5
+ import { ChainAsset } from '../../registry';
6
+ import { BalanceAdapter } from '../types';
7
+ export declare abstract class NativeBalanceAdapter implements BalanceAdapter {
8
+ readonly nativeToken: string;
9
+ readonly decimals: number;
10
+ readonly ed: BigNumber;
11
+ constructor(api: ApiPromise | ApiRx);
12
+ private getDeposit;
13
+ abstract getObserver(token: ChainAsset, address: string): Observable<AssetBalance>;
14
+ }
@@ -0,0 +1,12 @@
1
+ import { ApiPromise, ApiRx } from '@polkadot/api';
2
+ import { AssetBalance } from '../../types';
3
+ import { Observable } from 'rxjs';
4
+ import { ChainAsset } from '../../registry';
5
+ import { NativeBalanceAdapter } from './NativeBalanceAdapter';
6
+ export declare class TokenBalanceAdapter extends NativeBalanceAdapter {
7
+ private storages;
8
+ constructor(api: ApiPromise | ApiRx);
9
+ getObserver(asset: ChainAsset, address: string): Observable<AssetBalance>;
10
+ private getSystemAccountBalanceObserver;
11
+ private getTokenAccountBalanceObserver;
12
+ }
@@ -0,0 +1,9 @@
1
+ import { ApiPromise, ApiRx } from '@polkadot/api';
2
+ import { EvmProvider } from '../types';
3
+ export declare class AcalaEvmProvider implements EvmProvider {
4
+ readonly api: ApiPromise | ApiRx;
5
+ readonly endpoint: string;
6
+ constructor(api: ApiPromise | ApiRx, endpoint: string);
7
+ toEvmAddress(address: string): Promise<string>;
8
+ getEndpoint(): string;
9
+ }
@@ -0,0 +1,7 @@
1
+ import { EvmProvider } from '../types';
2
+ export declare class DefaultEvmProvider implements EvmProvider {
3
+ readonly endpoint: string;
4
+ constructor(endpoint: string);
5
+ toEvmAddress(address: string): Promise<string>;
6
+ getEndpoint(): string;
7
+ }
@@ -0,0 +1,5 @@
1
+ export { Wallet } from './Wallet';
2
+ export { TokenBalanceAdapter } from './balance/TokenBalanceAdapter';
3
+ export { Erc20BalanceAdapter } from './balance/Erc20BalanceAdapter';
4
+ export { DefaultEvmProvider } from './evm/DefaultEvmProvider';
5
+ export { AcalaEvmProvider } from './evm/AcalaEvmProvider';
@@ -0,0 +1,10 @@
1
+ import { Observable } from 'rxjs';
2
+ import { AssetBalance } from '../types';
3
+ import { ChainAsset } from '../registry';
4
+ export interface BalanceAdapter {
5
+ getObserver(asset: ChainAsset, address: string): Observable<AssetBalance>;
6
+ }
7
+ export interface EvmProvider {
8
+ toEvmAddress(address: string): Promise<string>;
9
+ getEndpoint(): string;
10
+ }
@@ -0,0 +1,19 @@
1
+ export declare const ADDRESS_FORMAT: {
2
+ ss58: string;
3
+ h160: string;
4
+ snow: string;
5
+ arctic: string;
6
+ pubKey: string;
7
+ };
8
+ export declare const CHAIN_PREFIX: {
9
+ snow: number;
10
+ ss58: number;
11
+ arctic: number;
12
+ };
13
+ export declare function convertH160ToSs58(h160Addr: string): string;
14
+ export declare function convertSs58ToH160(ss58Addr: string): string;
15
+ export declare function getPubKey(ss58addr: string): string;
16
+ export declare function encodePubKey(pubKey: string, prefix: number): string;
17
+ export declare function encodePolkadotAddress(addr: string, prefix: number): string;
18
+ export declare function validateSs58(ss58Addr: string): void;
19
+ export declare function validatePubKey(pubkey: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galacticcouncil/sdk",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "private": false,
5
5
  "description": "Galactic SDK",
6
6
  "author": "Pavol Noha <palo@hydradx.io>",
@@ -8,10 +8,19 @@
8
8
  "module": "dist/index.esm.js",
9
9
  "types": "dist/types/index.d.ts",
10
10
  "scripts": {
11
+ "build": "node ./esbuild.mjs && tsc --emitDeclarationOnly --outDir dist/types/",
12
+ "cleanup": "rimraf out && rimraf dist",
11
13
  "test": "jest",
12
14
  "test:coverage": "jest --coverage",
13
- "build": "node ./esbuild.mjs && tsc --emitDeclarationOnly --outDir dist/types/",
14
- "cleanup": "rimraf out && rimraf dist"
15
+ "pckg:build": "npm run cleanup && npm run build",
16
+ "pckg:release": "npm run pckg:build && standard-version --tag-prefix=''",
17
+ "pckg:publish": "git push --follow-tags origin master && npm publish",
18
+ "xcmgr:sync": "node ./xcmgr.sync.mjs"
19
+ },
20
+ "standard-version": {
21
+ "skip": {
22
+ "changelog": true
23
+ }
15
24
  },
16
25
  "devDependencies": {
17
26
  "@types/jest": "^28.1.8",
@@ -21,6 +30,7 @@
21
30
  "fs-extra": "^10.1.0",
22
31
  "prettier": "^2.3.2",
23
32
  "rimraf": "^3.0.2",
33
+ "standard-version": "^9.5.0",
24
34
  "ts-jest": "^28.0.8",
25
35
  "tsx": "^3.8.2",
26
36
  "typescript": "^4.7.4"
@@ -34,6 +44,7 @@
34
44
  },
35
45
  "peerDependencies": {
36
46
  "@polkadot/api": "^9.9.1",
37
- "capi": "^0.1.0-beta.12"
47
+ "capi": "^0.1.0-beta.12",
48
+ "ethers": "^6.0.5"
38
49
  }
39
50
  }
package/xcmgr.sync.mjs ADDED
@@ -0,0 +1,65 @@
1
+ import { mkdirSync, existsSync, writeFileSync } from 'fs';
2
+
3
+ const XCMGAR_REPO = 'https://raw.githubusercontent.com/colorfulnotion/xcm-global-registry/main';
4
+ const RELAY_CHAINS = ['kusama', 'polkadot'];
5
+ const DEST = './src/registry/data';
6
+
7
+ function pairs2Map(pairs) {
8
+ const result = new Map();
9
+ pairs.forEach((pair) => result.set(pair[0], pair[1]));
10
+ return result;
11
+ }
12
+
13
+ const writeJsonSync = (path, data) => {
14
+ writeFileSync(path, JSON.stringify(data, null, 4));
15
+ };
16
+
17
+ const fetchPublicEndpoints = async (relay) => {
18
+ const response = await fetch(`${XCMGAR_REPO}/publicEndpoints/${relay}_publicEndpoints.json`);
19
+ return await response.json();
20
+ };
21
+
22
+ // TODO: Fetch XcAssets
23
+ const fetchXcAssets = async (relay, chainKey) => {
24
+ const response = await fetch(`${XCMGAR_REPO}/xcAssets/${relay}/${chainKey}_xcAssets.json`);
25
+ return await response.json();
26
+ };
27
+
28
+ const fetchAssets = async (relay, chainKey) => {
29
+ const response = await fetch(`${XCMGAR_REPO}/assets/${relay}/${chainKey}_assets.json`);
30
+ return await response.json();
31
+ };
32
+
33
+ const syncAssets = async (relay, chainKeys) => {
34
+ const assets = await Promise.all(
35
+ chainKeys
36
+ .map((chainKey) => chainKey.replace('-', '_'))
37
+ .map(async (chainKey) => {
38
+ let assets = [];
39
+ try {
40
+ assets = await fetchAssets(relay, chainKey);
41
+ } catch (err) {}
42
+ return [chainKey.replace(`${relay}_`, ''), assets];
43
+ })
44
+ );
45
+
46
+ const assetMap = pairs2Map(assets);
47
+ const ASSETS_FILE_PATH = `${DEST}/${relay}/assets.json`;
48
+ writeJsonSync(ASSETS_FILE_PATH, Object.fromEntries(assetMap));
49
+ };
50
+
51
+ (async () => {
52
+ RELAY_CHAINS.forEach(async (relay) => {
53
+ const fld = `${DEST}/${relay}`;
54
+ if (!existsSync(fld)) {
55
+ mkdirSync(fld);
56
+ }
57
+ const ENDPOINT_FILE_PATH = `${DEST}/${relay}/endpoints.json`;
58
+ const endpoints = await fetchPublicEndpoints(relay);
59
+
60
+ await syncAssets(relay, Object.keys(endpoints));
61
+
62
+ writeJsonSync(ENDPOINT_FILE_PATH, Object.values(endpoints));
63
+ console.log(`${relay} done ✅`);
64
+ });
65
+ })();
File without changes
File without changes
File without changes