@gardenfi/orderbook 2.5.3-beta.2 → 2.5.3-beta.20

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 } from './lib/assetManager/routeValidator/routeValidator';
15
+ export type { RoutePolicy } from './lib/assetManager/routeValidator/routeValidator';
@@ -0,0 +1,82 @@
1
+ import { Url, AsyncResult, IAuth } from '@gardenfi/utils';
2
+ import { RouteValidator } from './routeValidator/routeValidator';
3
+ import { Assets, ChainData, Chains } from './types';
4
+ import { ChainAsset } from '../chainAsset/chainAsset';
5
+ import { Asset, Chain } from '../constants/asset.types';
6
+
7
+ type AssetManagerUrlConfig = {
8
+ baseUrl: string | Url;
9
+ assetsUrl?: string | Url;
10
+ policyUrl?: string | Url;
11
+ };
12
+ /**
13
+ * AssetManager
14
+ *
15
+ * It fetches asset data from our API, caches it locally, and provides methods
16
+ * to check if routes between assets are valid. Also builds a route matrix
17
+ * to make route lookups fast.
18
+ */
19
+ export declare class AssetManager {
20
+ assets: Assets | null;
21
+ chains: Chains | null;
22
+ routeValidator: RouteValidator;
23
+ routeMatrix: Record<string, ChainAsset[]> | null;
24
+ isLoading: boolean;
25
+ error: string | null;
26
+ private readonly urls;
27
+ private auth;
28
+ constructor(urlConfig: AssetManagerUrlConfig, apiKey: IAuth | string);
29
+ /**
30
+ * Initialize the AssetManager by fetching all required data
31
+ */
32
+ initialize(): Promise<void>;
33
+ /**
34
+ * Fetch and cache asset and chain data from API
35
+ */
36
+ fetchAndSetAssetsAndChains(): AsyncResult<string, string>;
37
+ /**
38
+ * Check if a swap route from one asset to another is valid
39
+ */
40
+ isRouteValid(from: Asset, to: Asset): Promise<boolean>;
41
+ /**
42
+ * Get all valid destination assets for a given source asset
43
+ */
44
+ getValidDestinations(asset: Asset): Asset[];
45
+ /**
46
+ * Get asset by chain and token address
47
+ */
48
+ getAsset(asset: string | Asset | ChainAsset): Asset | undefined;
49
+ /**
50
+ * Get all assets for a specific chain
51
+ */
52
+ getAssetsByChain(chain: Chain): Asset[];
53
+ /**
54
+ * Search assets by symbol or name
55
+ */
56
+ searchAssets(query: string): Asset[];
57
+ /**
58
+ * Get chain data by chain identifier
59
+ */
60
+ getChain(chain: Chain): ChainData | undefined;
61
+ /**
62
+ * Build route matrix for fast O(1) route lookups
63
+ */
64
+ buildRouteMatrix(): Promise<void>;
65
+ /**
66
+ * Process raw API data into structured format
67
+ */
68
+ private processApiData;
69
+ /**
70
+ * Parse chain identifier from string
71
+ */
72
+ private parseChainIdentifier;
73
+ /**
74
+ * Format chain name for display
75
+ */
76
+ private formatChainName;
77
+ /**
78
+ * Refresh all data
79
+ */
80
+ refresh(): Promise<void>;
81
+ }
82
+ export {};
@@ -0,0 +1,2 @@
1
+ export { AssetManager } from './AssetManager';
2
+ export * from './types';
@@ -0,0 +1,76 @@
1
+ import { AsyncResult, IAuth } from '@gardenfi/utils';
2
+ import { ChainAsset } from '../../chainAsset/chainAsset';
3
+ import { default as NodeCache } from 'node-cache';
4
+
5
+ type RoutePolicy = {
6
+ default: 'open' | 'closed';
7
+ isolation_groups: string[];
8
+ blacklist_pairs: string[];
9
+ whitelist_overrides: string[];
10
+ };
11
+ declare class RouteValidator {
12
+ policy: NodeCache;
13
+ private static readonly POLICY_CACHE_KEY;
14
+ private apiBaseUrl;
15
+ private auth;
16
+ constructor(apiBaseUrl: string, apiKey: string | IAuth);
17
+ getPolicy(): RoutePolicy | undefined;
18
+ setPolicy(policy: RoutePolicy): RoutePolicy;
19
+ /**
20
+ * Loads the current route policy, cached or via API.
21
+ */
22
+ loadPolicy(): AsyncResult<RoutePolicy, string>;
23
+ /**
24
+ * Checks if a given route is valid based on all route rules.
25
+ */
26
+ isValidRoute(fromAsset: ChainAsset, toAsset: ChainAsset): Promise<boolean>;
27
+ /**
28
+ * Returns all valid destinations for a given source asset.
29
+ */
30
+ getValidDestinations(fromAsset: ChainAsset, allAssets: ChainAsset[]): Promise<ChainAsset[]>;
31
+ /**
32
+ * Returns every valid route (from-to pair) among the provided assets.
33
+ */
34
+ getAllValidRoutes(assets: ChainAsset[]): Promise<Array<{
35
+ from: ChainAsset;
36
+ to: ChainAsset;
37
+ }>>;
38
+ /**
39
+ * Turns policy string rules into sorted ParsedRule objects.
40
+ */
41
+ private preprocessRules;
42
+ /**
43
+ * Parses a rule string (e.g. "ethereum:usdc -> base:usdt") into parts.
44
+ */
45
+ private parseRule;
46
+ /**
47
+ * Gives a specificity score to a rule pattern for prioritizing.
48
+ */
49
+ private calculateSpecificity;
50
+ /**
51
+ * Finds the first matching rule for an asset given the rule "side".
52
+ */
53
+ private findMatchingRule;
54
+ /**
55
+ * Checks if a given toAsset matches the rule's destination side.
56
+ */
57
+ private matchesRuleDestination;
58
+ /**
59
+ * Checks if a given fromAsset matches the rule's source side.
60
+ */
61
+ private matchesRuleSource;
62
+ /**
63
+ * Checks if any rule in a list matches fromAsset and toAsset.
64
+ */
65
+ private matchesRuleList;
66
+ /**
67
+ * Checks if a rule matches fromAsset and toAsset (forward or backward if bidirectional).
68
+ */
69
+ private matchesRule;
70
+ /**
71
+ * Checks if an asset string matches a rule's pattern (wildcards supported).
72
+ */
73
+ private matchesAssetPattern;
74
+ buildRouteMatrix(assets: ChainAsset[]): Promise<Record<string, ChainAsset[]>>;
75
+ }
76
+ export { RouteValidator, 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
+ };
@@ -0,0 +1,9 @@
1
+ import { Url } from '@gardenfi/utils';
2
+ import { ChainAsset } from '../chainAsset/chainAsset';
3
+
4
+ export declare function parseAssetNameSymbol(input: string | undefined, assetId?: string | ChainAsset, fallbackSymbol?: string): {
5
+ name: string;
6
+ symbol: string;
7
+ };
8
+ export declare function ensureUrl(value: string | Url): Url;
9
+ export declare function buildDefaultEndpoint(baseUrl: Url, path: string): string;