@gardenfi/orderbook 2.5.3-beta.3 → 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/index7.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@gardenfi/utils"),i=require("./index3.cjs"),p=(t,r,d)=>{const a=t.endpoint(r);return d&&Object.entries(d).forEach(([l,n])=>{n!==void 0&&(Array.isArray(n)?a.searchParams.append(l,n.join(",")):a.searchParams.append(l,n.toString()))}),a},c=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","value","data","gas_limit","chain_id"]),o=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","selector","calldata"]),s=t=>e.hasKeys(t,["to","amount"])&&typeof t.to=="string"&&typeof t.amount=="number",y=t=>e.hasKeys(t,["versioned_tx"])&&typeof t.versioned_tx=="string",u=t=>e.hasKeys(t,["ptb_bytes"])&&Array.isArray(t.ptb_bytes)&&t.ptb_bytes.every(r=>typeof r=="number"),f=t=>e.hasKeys(t,["source_swap","destination_swap"])&&typeof t.source_swap=="object"&&typeof t.destination_swap=="object";function h(t){return c(t)?{type:i.BlockchainType.evm,...t}:o(t)?{type:i.BlockchainType.starknet,...t}:s(t)?{type:i.BlockchainType.bitcoin,...t}:y(t)?{type:i.BlockchainType.solana,...t}:u(t)?{type:i.BlockchainType.sui,...t}:null}function _(t){return c(t)?i.BlockchainType.evm:o(t)?i.BlockchainType.starknet:s(t)?i.BlockchainType.bitcoin:y(t)?i.BlockchainType.solana:u(t)?i.BlockchainType.sui:null}exports.ConstructUrl=p;exports.discriminateOrderResponse=h;exports.getOrderResponseType=_;exports.isBitcoinOrderResponse=s;exports.isEvmOrderResponse=c;exports.isOrder=f;exports.isSolanaOrderResponse=y;exports.isStarknetOrderResponse=o;exports.isSuiOrderResponse=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@gardenfi/utils"),i=require("./index3.cjs"),p=(t,r,d)=>{const a=t.endpoint(r);return d&&Object.entries(d).forEach(([l,n])=>{n!==void 0&&(Array.isArray(n)?a.searchParams.append(l,n.join(",")):a.searchParams.append(l,n.toString()))}),a},c=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","value","data","gas_limit","chain_id"]),s=t=>e.hasKeys(t,["typed_data","initiate_transaction"])&&typeof t.initiate_transaction=="object"&&t.initiate_transaction&&e.hasKeys(t.initiate_transaction,["to","selector","calldata"]),o=t=>e.hasKeys(t,["to","amount"])&&typeof t.to=="string"&&typeof t.amount=="string",y=t=>e.hasKeys(t,["versioned_tx"])&&typeof t.versioned_tx=="string",u=t=>e.hasKeys(t,["ptb_bytes"])&&Array.isArray(t.ptb_bytes)&&t.ptb_bytes.every(r=>typeof r=="number"),f=t=>e.hasKeys(t,["source_swap","destination_swap"])&&typeof t.source_swap=="object"&&typeof t.destination_swap=="object";function h(t){return c(t)?{type:i.BlockchainType.evm,...t}:s(t)?{type:i.BlockchainType.starknet,...t}:o(t)?{type:i.BlockchainType.bitcoin,...t}:y(t)?{type:i.BlockchainType.solana,...t}:u(t)?{type:i.BlockchainType.sui,...t}:null}function _(t){return c(t)?i.BlockchainType.evm:s(t)?i.BlockchainType.starknet:o(t)?i.BlockchainType.bitcoin:y(t)?i.BlockchainType.solana:u(t)?i.BlockchainType.sui:null}exports.ConstructUrl=p;exports.discriminateOrderResponse=h;exports.getOrderResponseType=_;exports.isBitcoinOrderResponse=o;exports.isEvmOrderResponse=c;exports.isOrder=f;exports.isSolanaOrderResponse=y;exports.isStarknetOrderResponse=s;exports.isSuiOrderResponse=u;
package/dist/index7.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { hasKeys as r } from "@gardenfi/utils";
2
2
  import { BlockchainType as i } from "./index3.js";
3
- const m = (t, a, o) => {
3
+ const l = (t, a, o) => {
4
4
  const e = t.endpoint(a);
5
5
  return o && Object.entries(o).forEach(([c, n]) => {
6
6
  n !== void 0 && (Array.isArray(n) ? e.searchParams.append(c, n.join(",")) : e.searchParams.append(c, n.toString()));
@@ -11,7 +11,7 @@ const m = (t, a, o) => {
11
11
  "data",
12
12
  "gas_limit",
13
13
  "chain_id"
14
- ]), f = (t) => r(t, ["typed_data", "initiate_transaction"]) && typeof t.initiate_transaction == "object" && t.initiate_transaction && r(t.initiate_transaction, ["to", "selector", "calldata"]), y = (t) => r(t, ["to", "amount"]) && typeof t.to == "string" && typeof t.amount == "number", d = (t) => r(t, ["versioned_tx"]) && typeof t.versioned_tx == "string", _ = (t) => r(t, ["ptb_bytes"]) && Array.isArray(t.ptb_bytes) && t.ptb_bytes.every((a) => typeof a == "number"), l = (t) => r(t, ["source_swap", "destination_swap"]) && typeof t.source_swap == "object" && typeof t.destination_swap == "object";
14
+ ]), f = (t) => r(t, ["typed_data", "initiate_transaction"]) && typeof t.initiate_transaction == "object" && t.initiate_transaction && r(t.initiate_transaction, ["to", "selector", "calldata"]), y = (t) => r(t, ["to", "amount"]) && typeof t.to == "string" && typeof t.amount == "string", d = (t) => r(t, ["versioned_tx"]) && typeof t.versioned_tx == "string", _ = (t) => r(t, ["ptb_bytes"]) && Array.isArray(t.ptb_bytes) && t.ptb_bytes.every((a) => typeof a == "number"), m = (t) => r(t, ["source_swap", "destination_swap"]) && typeof t.source_swap == "object" && typeof t.destination_swap == "object";
15
15
  function p(t) {
16
16
  return u(t) ? {
17
17
  type: i.evm,
@@ -34,12 +34,12 @@ function O(t) {
34
34
  return u(t) ? i.evm : f(t) ? i.starknet : y(t) ? i.bitcoin : d(t) ? i.solana : _(t) ? i.sui : null;
35
35
  }
36
36
  export {
37
- m as ConstructUrl,
37
+ l as ConstructUrl,
38
38
  p as discriminateOrderResponse,
39
39
  O as getOrderResponseType,
40
40
  y as isBitcoinOrderResponse,
41
41
  u as isEvmOrderResponse,
42
- l as isOrder,
42
+ m as isOrder,
43
43
  d as isSolanaOrderResponse,
44
44
  f as isStarknetOrderResponse,
45
45
  _ as isSuiOrderResponse
@@ -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, AssetCommon, AssetToken, BitcoinChains, Chain, ChainsByBlockchainType, ChainsByNetwork, EVMChains, LocalnetOnlyChains, MainnetOnlyChains, SolanaChains, SuiChains, StarknetChains, TestnetOnlyChains, } from './lib/constants/asset.types';
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,2 @@
1
+ export { AssetManager } from './AssetManager';
2
+ export * from './types';
@@ -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
+ };