@gardenfi/orderbook 2.5.3-beta.4 → 2.5.3-beta.6
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.
- package/dist/index.cjs +1 -1
- package/dist/index.js +30 -25
- package/dist/index10.cjs +1 -0
- package/dist/index10.js +238 -0
- package/dist/index11.cjs +1 -0
- package/dist/index11.js +90 -0
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +659 -292
- package/dist/src/index.d.ts +5 -1
- package/dist/src/lib/assetManager/AssetManager.d.ts +96 -0
- package/dist/src/lib/assetManager/index.d.ts +2 -0
- package/dist/src/lib/assetManager/routeValidator/routeValidator.d.ts +31 -0
- package/dist/src/lib/assetManager/types.d.ts +39 -0
- package/dist/src/lib/constants/asset.d.ts +1188 -454
- package/dist/src/lib/constants/asset.types.d.ts +15 -9
- package/package.json +1 -1
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Orderbook } from './lib/orderbook/orderbook';
|
|
2
2
|
export type * from './lib/orderbook/orderbook.types';
|
|
3
3
|
export { BlockchainType } from './lib/constants/asset.types';
|
|
4
|
-
export type { Asset,
|
|
4
|
+
export type { Asset, BitcoinChains, Chain, ChainsByBlockchainType, ChainsByNetwork, EVMChains, LocalnetOnlyChains, MainnetOnlyChains, SolanaChains, SuiChains, StarknetChains, TestnetOnlyChains, } from './lib/constants/asset.types';
|
|
5
5
|
export * from './lib/constants/asset';
|
|
6
6
|
export * from './lib/constants/localnetConstants';
|
|
7
7
|
export * from './lib/constants/utils';
|
|
@@ -9,3 +9,7 @@ export { isSuiOrderResponse, ConstructUrl, discriminateOrderResponse, getOrderRe
|
|
|
9
9
|
export { ChainAsset } from './lib/chainAsset/chainAsset';
|
|
10
10
|
export type { ChainAssetString, AssetLike } from './lib/chainAsset/chainAsset';
|
|
11
11
|
export { OrderAction, ParseOrderStatus, isCompleted, isDeadlinePassed, parseAction, } from './lib/orderStatus/orderStatus';
|
|
12
|
+
export { AssetManager } from './lib/assetManager/AssetManager';
|
|
13
|
+
export type { ApiChainData, ApiChainsResponse, AssetManagerState, BaseChainData, ChainData, FiatResponse, } from './lib/assetManager/types';
|
|
14
|
+
export { RouteValidator, buildRouteMatrix, } from './lib/assetManager/routeValidator/routeValidator';
|
|
15
|
+
export type { RoutePolicy } from './lib/assetManager/routeValidator/routeValidator';
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { RouteValidator } from './routeValidator/routeValidator';
|
|
2
|
+
import { Assets, ChainData, Chains } from './types';
|
|
3
|
+
import { ChainAsset } from '../chainAsset/chainAsset';
|
|
4
|
+
import { Asset, Chain } from '../constants/asset.types';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* AssetManager
|
|
8
|
+
*
|
|
9
|
+
* A comprehensive manager for handling asset and chain data across the application.
|
|
10
|
+
* Responsibilities:
|
|
11
|
+
* - Fetching and caching asset/chain data from API
|
|
12
|
+
* - Managing route validation between assets
|
|
13
|
+
* - Managing asset selection state
|
|
14
|
+
* - Building and maintaining route matrices for performance optimization
|
|
15
|
+
*/
|
|
16
|
+
export declare class AssetManager {
|
|
17
|
+
private _allChains;
|
|
18
|
+
private _allAssets;
|
|
19
|
+
private _assets;
|
|
20
|
+
private _chains;
|
|
21
|
+
private _routeValidator;
|
|
22
|
+
private _routeMatrix;
|
|
23
|
+
private _isLoading;
|
|
24
|
+
private _error;
|
|
25
|
+
private readonly url;
|
|
26
|
+
private apiKey;
|
|
27
|
+
constructor(url: string, apiKey: string);
|
|
28
|
+
get allChains(): Chains | null;
|
|
29
|
+
get allAssets(): Assets | null;
|
|
30
|
+
get assets(): Assets | null;
|
|
31
|
+
get chains(): Chains | null;
|
|
32
|
+
get routeValidator(): RouteValidator | null;
|
|
33
|
+
get routeMatrix(): Record<string, ChainAsset[]> | null;
|
|
34
|
+
get isLoading(): boolean;
|
|
35
|
+
get error(): string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Initialize the AssetManager by fetching all required data
|
|
38
|
+
*/
|
|
39
|
+
initialize(): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Fetch and cache asset and chain data from API
|
|
42
|
+
*/
|
|
43
|
+
fetchAndSetAssetsAndChains(): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a swap route from one asset to another is valid
|
|
46
|
+
*/
|
|
47
|
+
isRouteValid(from: Asset, to: Asset): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Get all valid destination assets for a given source asset
|
|
50
|
+
*/
|
|
51
|
+
getValidDestinations(fromAsset: Asset): Asset[];
|
|
52
|
+
/**
|
|
53
|
+
* Get asset by chain and token address
|
|
54
|
+
*/
|
|
55
|
+
getAsset(asset: string | Asset | ChainAsset): Asset | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Get all assets for a specific chain
|
|
58
|
+
*/
|
|
59
|
+
getAssetsByChain(chain: Chain): Asset[];
|
|
60
|
+
/**
|
|
61
|
+
* Search assets by symbol or name
|
|
62
|
+
*/
|
|
63
|
+
searchAssets(query: string): Asset[];
|
|
64
|
+
/**
|
|
65
|
+
* Get chain data by chain identifier
|
|
66
|
+
*/
|
|
67
|
+
getChain(chain: Chain): ChainData | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Initialize the route validator
|
|
70
|
+
*/
|
|
71
|
+
private initializeRouteValidator;
|
|
72
|
+
/**
|
|
73
|
+
* Build route matrix for fast O(1) route lookups
|
|
74
|
+
*/
|
|
75
|
+
private buildRouteMatrix;
|
|
76
|
+
/**
|
|
77
|
+
* Process raw API data into structured format
|
|
78
|
+
*/
|
|
79
|
+
private processApiData;
|
|
80
|
+
/**
|
|
81
|
+
* Parse chain identifier from string
|
|
82
|
+
*/
|
|
83
|
+
private parseChainIdentifier;
|
|
84
|
+
/**
|
|
85
|
+
* Format chain name for display
|
|
86
|
+
*/
|
|
87
|
+
private formatChainName;
|
|
88
|
+
/**
|
|
89
|
+
* Refresh all data
|
|
90
|
+
*/
|
|
91
|
+
refresh(): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Clear all cached data
|
|
94
|
+
*/
|
|
95
|
+
clear(): void;
|
|
96
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ChainAsset } from '../../chainAsset/chainAsset';
|
|
2
|
+
|
|
3
|
+
interface RoutePolicy {
|
|
4
|
+
default: 'open' | 'closed';
|
|
5
|
+
isolation_groups: string[];
|
|
6
|
+
blacklist_pairs: string[];
|
|
7
|
+
whitelist_overrides: string[];
|
|
8
|
+
}
|
|
9
|
+
declare class RouteValidator {
|
|
10
|
+
private readonly apiBaseUrl;
|
|
11
|
+
private readonly apiKey;
|
|
12
|
+
private policy;
|
|
13
|
+
constructor(apiBaseUrl: string, apiKey: string);
|
|
14
|
+
loadPolicy(): Promise<void>;
|
|
15
|
+
isValidRoute(fromAsset: ChainAsset, toAsset: ChainAsset): boolean;
|
|
16
|
+
isAssetInIsolationGroup(asset: ChainAsset): boolean;
|
|
17
|
+
getValidDestinations(fromAsset: ChainAsset, allAssets: ChainAsset[]): ChainAsset[];
|
|
18
|
+
getAllValidRoutes(assets: ChainAsset[]): Array<{
|
|
19
|
+
from: ChainAsset;
|
|
20
|
+
to: ChainAsset;
|
|
21
|
+
}>;
|
|
22
|
+
private ensurePolicyLoaded;
|
|
23
|
+
private findIsolationGroup;
|
|
24
|
+
private matchesIsolationGroup;
|
|
25
|
+
private matchesPatternList;
|
|
26
|
+
private matchesRoutePattern;
|
|
27
|
+
private parsePattern;
|
|
28
|
+
private matchesAssetPattern;
|
|
29
|
+
}
|
|
30
|
+
declare function buildRouteMatrix(assets: ChainAsset[], validator: RouteValidator): Record<string, ChainAsset[]>;
|
|
31
|
+
export { RouteValidator, buildRouteMatrix, type RoutePolicy };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Asset, Chain } from '../constants/asset.types';
|
|
2
|
+
|
|
3
|
+
export type BaseChainData = {
|
|
4
|
+
id: string;
|
|
5
|
+
chain: string | Chain;
|
|
6
|
+
icon: string;
|
|
7
|
+
explorer_url: string;
|
|
8
|
+
confirmation_target: number;
|
|
9
|
+
source_timelock: string;
|
|
10
|
+
destination_timelock: string;
|
|
11
|
+
supported_htlc_schemas: string[];
|
|
12
|
+
supported_token_schemas: string[];
|
|
13
|
+
};
|
|
14
|
+
export type ChainData = BaseChainData & {
|
|
15
|
+
chain: Chain;
|
|
16
|
+
name: string;
|
|
17
|
+
};
|
|
18
|
+
export type ApiChainData = BaseChainData & {
|
|
19
|
+
assets: Asset[];
|
|
20
|
+
};
|
|
21
|
+
export type ApiChainsResponse = {
|
|
22
|
+
status: string;
|
|
23
|
+
result: ApiChainData[];
|
|
24
|
+
};
|
|
25
|
+
export type FiatResponse = {
|
|
26
|
+
status: string;
|
|
27
|
+
result: Record<string, string>;
|
|
28
|
+
};
|
|
29
|
+
export type Assets = Record<string, Asset>;
|
|
30
|
+
export type Chains = Partial<Record<Chain, ChainData>>;
|
|
31
|
+
export type AssetManagerState = {
|
|
32
|
+
allChains: Chains | null;
|
|
33
|
+
allAssets: Assets | null;
|
|
34
|
+
assets: Assets | null;
|
|
35
|
+
chains: Chains | null;
|
|
36
|
+
fiatData: Record<string, number | undefined>;
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
error: string | null;
|
|
39
|
+
};
|