@gardenfi/orderbook 2.5.3-beta.16 → 2.5.3-beta.18

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/index10.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),A=require("./index11.cjs"),g=require("./index4.cjs"),n=require("./index8.cjs"),C=require("./index12.cjs"),u=Object.keys(g.Config);class m{constructor(t,s){this.assets=null,this.chains=null,this.routeMatrix=null,this.isLoading=!1,this.error=null,this.url=new r.Url(t),typeof s=="string"?this.auth=new r.ApiKey(s):this.auth=s,this.routeValidator=new A.RouteValidator(this.url.toString(),this.auth)}async initialize(){await this.fetchAndSetAssetsAndChains(),await this.routeValidator.loadPolicy()}async fetchAndSetAssetsAndChains(){try{this.isLoading=!0,this.error=null;const t=await this.auth.getAuthHeaders();if(!t.ok)return r.Err("Failed to get auth headers");const s=this.url.endpoint("/v2/chains"),e=await r.Fetcher.get(s,{headers:{...t.val}});if(!e.result)return r.Err(`Failed to fetch chains data: ${e.error}`);const{assets:a,chains:i}=this.processApiData(e.result);return this.assets=a,this.chains=i,await this.buildRouteMatrix(),r.Ok("AssetManager initialized successfully")}catch(t){return r.Err(`Failed to fetch assets data: ${t}`)}finally{this.isLoading=!1}}async isRouteValid(t,s){return await this.routeValidator.isValidRoute(n.ChainAsset.from(t.id),n.ChainAsset.from(s.id))}getValidDestinations(t){if(!this.routeMatrix||!this.assets||!t.id)return console.warn("Missing routeMatrix, assets, or asset. Returning all assets."),[];const s=this.routeMatrix[t.id.toString().toLowerCase()];return s?s.map(e=>{const a=e.toString();return Object.values(this.assets).find(i=>n.ChainAsset.from(i).toString()===a)}).filter(Boolean):[]}getAsset(t){if(!this.assets)return;const s=n.ChainAsset.from(t).toString();return this.assets[s]}getAssetsByChain(t){return this.assets?Object.values(this.assets).filter(s=>s.chain===t):[]}searchAssets(t){if(!this.assets)return[];const s=t.toLowerCase();return Object.values(this.assets).filter(e=>e.symbol.toLowerCase().includes(s)||e.name.toLowerCase().includes(s))}getChain(t){if(this.chains)return this.chains[t]}async buildRouteMatrix(){if(!this.assets||!this.routeValidator)return;const t=Object.values(this.assets).map(s=>{if(!s.id)return null;try{return n.ChainAsset.from(s.id)}catch{return null}}).filter(s=>s!==null);this.routeMatrix=await this.routeValidator.buildRouteMatrix(t)}processApiData(t){const s={},e={};for(const a of t){const i=this.parseChainIdentifier(a.chain);if(!i||!u.includes(i))continue;const h={...a,name:this.formatChainName(a.chain),chain:i};for(const o of a.assets){const l=n.ChainAsset.from(o.id).toString(),{name:c,symbol:d}=C.parseAssetNameSymbol(o.name,o.id),f={...o,id:n.ChainAsset.from(o.id),chain:i,name:c,symbol:d};s[l]=f,e[i]||(e[i]=h)}}return{assets:s,chains:e}}parseChainIdentifier(t){return u.includes(t)?t:null}formatChainName(t){return t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}async refresh(){await this.initialize()}}exports.AssetManager=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@gardenfi/utils"),y=require("./index11.cjs"),p=require("./index4.cjs"),r=require("./index8.cjs"),o=require("./index12.cjs"),h=Object.keys(p.Config);class g{constructor(t,s){this.assets=null,this.chains=null,this.routeMatrix=null,this.isLoading=!1,this.error=null,typeof s=="string"?this.auth=new n.ApiKey(s):this.auth=s;const e=o.ensureUrl(t.baseUrl),i=o.buildDefaultEndpoint(e,"/v2/chains"),a=o.buildDefaultEndpoint(e,"/v2/policy");this.urls={base:e,assets:o.ensureUrl(t.assetsUrl??i),policy:o.ensureUrl(t.policyUrl??a)},this.routeValidator=new y.RouteValidator(this.urls.policy.toString(),this.auth)}async initialize(){await this.fetchAndSetAssetsAndChains(),await this.routeValidator.loadPolicy()}async fetchAndSetAssetsAndChains(){try{this.isLoading=!0,this.error=null;const t=await this.auth.getAuthHeaders();if(!t.ok)return n.Err("Failed to get auth headers");const s=await n.Fetcher.get(this.urls.assets,{headers:{...t.val}});if(!s.result)return n.Err(`Failed to fetch chains data: ${s.error}`);const{assets:e,chains:i}=this.processApiData(s.result);return this.assets=e,this.chains=i,await this.buildRouteMatrix(),n.Ok("AssetManager initialized successfully")}catch(t){return n.Err(`Failed to fetch assets data: ${t}`)}finally{this.isLoading=!1}}async isRouteValid(t,s){return await this.routeValidator.isValidRoute(r.ChainAsset.from(t.id),r.ChainAsset.from(s.id))}getValidDestinations(t){if(!this.routeMatrix||!this.assets||!t.id)return console.warn("Missing routeMatrix, assets, or asset. Returning all assets."),[];const s=this.routeMatrix[t.id.toString().toLowerCase()];return s?s.map(e=>{const i=e.toString();return Object.values(this.assets).find(a=>r.ChainAsset.from(a).toString()===i)}).filter(Boolean):[]}getAsset(t){if(!this.assets)return;const s=r.ChainAsset.from(t).toString();return this.assets[s]}getAssetsByChain(t){return this.assets?Object.values(this.assets).filter(s=>s.chain===t):[]}searchAssets(t){if(!this.assets)return[];const s=t.toLowerCase();return Object.values(this.assets).filter(e=>e.symbol.toLowerCase().includes(s)||e.name.toLowerCase().includes(s))}getChain(t){if(this.chains)return this.chains[t]}async buildRouteMatrix(){if(!this.assets||!this.routeValidator)return;const t=Object.values(this.assets).map(s=>{if(!s.id)return null;try{return r.ChainAsset.from(s.id)}catch{return null}}).filter(s=>s!==null);this.routeMatrix=await this.routeValidator.buildRouteMatrix(t)}processApiData(t){const s={},e={};for(const i of t){const a=this.parseChainIdentifier(i.chain);if(!a||!h.includes(a))continue;const u={...i,name:this.formatChainName(i.chain),chain:a};for(const l of i.assets){const c=r.ChainAsset.from(l.id).toString(),{name:d,symbol:f}=o.parseAssetNameSymbol(l.name,l.id),A={...l,id:r.ChainAsset.from(l.id),chain:a,name:d,symbol:f};s[c]=A,e[a]||(e[a]=u)}}return{assets:s,chains:e}}parseChainIdentifier(t){return h.includes(t)?t:null}formatChainName(t){return t.split("_").map(s=>s.charAt(0).toUpperCase()+s.slice(1)).join(" ")}async refresh(){await this.initialize()}}exports.AssetManager=g;
package/dist/index10.js CHANGED
@@ -1,12 +1,21 @@
1
- import { Url as m, ApiKey as A, Err as o, Fetcher as g, Ok as p } from "@gardenfi/utils";
1
+ import { ApiKey as A, Err as o, Fetcher as y, Ok as g } from "@gardenfi/utils";
2
2
  import { RouteValidator as C } from "./index11.js";
3
- import { Config as y } from "./index4.js";
3
+ import { Config as b } from "./index4.js";
4
4
  import { ChainAsset as r } from "./index8.js";
5
- import { parseAssetNameSymbol as w } from "./index12.js";
6
- const u = Object.keys(y);
7
- class R {
5
+ import { ensureUrl as l, buildDefaultEndpoint as u, parseAssetNameSymbol as w } from "./index12.js";
6
+ const c = Object.keys(b);
7
+ class I {
8
8
  constructor(t, s) {
9
- this.assets = null, this.chains = null, this.routeMatrix = null, this.isLoading = !1, this.error = null, this.url = new m(t), typeof s == "string" ? this.auth = new A(s) : this.auth = s, this.routeValidator = new C(this.url.toString(), this.auth);
9
+ this.assets = null, this.chains = null, this.routeMatrix = null, this.isLoading = !1, this.error = null, typeof s == "string" ? this.auth = new A(s) : this.auth = s;
10
+ const i = l(t.baseUrl), e = u(i, "/v2/chains"), a = u(i, "/v2/policy");
11
+ this.urls = {
12
+ base: i,
13
+ assets: l(t.assetsUrl ?? e),
14
+ policy: l(t.policyUrl ?? a)
15
+ }, this.routeValidator = new C(
16
+ this.urls.policy.toString(),
17
+ this.auth
18
+ );
10
19
  }
11
20
  // ============================================
12
21
  // Initialization Methods
@@ -25,14 +34,17 @@ class R {
25
34
  this.isLoading = !0, this.error = null;
26
35
  const t = await this.auth.getAuthHeaders();
27
36
  if (!t.ok) return o("Failed to get auth headers");
28
- const s = this.url.endpoint("/v2/chains"), i = await g.get(s, {
29
- headers: {
30
- ...t.val
37
+ const s = await y.get(
38
+ this.urls.assets,
39
+ {
40
+ headers: {
41
+ ...t.val
42
+ }
31
43
  }
32
- });
33
- if (!i.result) return o(`Failed to fetch chains data: ${i.error}`);
34
- const { assets: a, chains: e } = this.processApiData(i.result);
35
- return this.assets = a, this.chains = e, await this.buildRouteMatrix(), p("AssetManager initialized successfully");
44
+ );
45
+ if (!s.result) return o(`Failed to fetch chains data: ${s.error}`);
46
+ const { assets: i, chains: e } = this.processApiData(s.result);
47
+ return this.assets = i, this.chains = e, await this.buildRouteMatrix(), g("AssetManager initialized successfully");
36
48
  } catch (t) {
37
49
  return o(`Failed to fetch assets data: ${t}`);
38
50
  } finally {
@@ -61,8 +73,8 @@ class R {
61
73
  ), [];
62
74
  const s = this.routeMatrix[t.id.toString().toLowerCase()];
63
75
  return s ? s.map((i) => {
64
- const a = i.toString();
65
- return Object.values(this.assets).find((e) => r.from(e).toString() === a);
76
+ const e = i.toString();
77
+ return Object.values(this.assets).find((a) => r.from(a).toString() === e);
66
78
  }).filter(Boolean) : [];
67
79
  }
68
80
  // ============================================
@@ -124,27 +136,27 @@ class R {
124
136
  */
125
137
  processApiData(t) {
126
138
  const s = {}, i = {};
127
- for (const a of t) {
128
- const e = this.parseChainIdentifier(a.chain);
129
- if (!e || !u.includes(e))
139
+ for (const e of t) {
140
+ const a = this.parseChainIdentifier(e.chain);
141
+ if (!a || !c.includes(a))
130
142
  continue;
131
143
  const h = {
132
- ...a,
133
- name: this.formatChainName(a.chain),
134
- chain: e
144
+ ...e,
145
+ name: this.formatChainName(e.chain),
146
+ chain: a
135
147
  };
136
- for (const n of a.assets) {
137
- const l = r.from(n.id).toString(), { name: c, symbol: d } = w(
148
+ for (const n of e.assets) {
149
+ const d = r.from(n.id).toString(), { name: f, symbol: m } = w(
138
150
  n.name,
139
151
  n.id
140
- ), f = {
152
+ ), p = {
141
153
  ...n,
142
154
  id: r.from(n.id),
143
- chain: e,
144
- name: c,
145
- symbol: d
155
+ chain: a,
156
+ name: f,
157
+ symbol: m
146
158
  };
147
- s[l] = f, i[e] || (i[e] = h);
159
+ s[d] = p, i[a] || (i[a] = h);
148
160
  }
149
161
  }
150
162
  return { assets: s, chains: i };
@@ -153,7 +165,7 @@ class R {
153
165
  * Parse chain identifier from string
154
166
  */
155
167
  parseChainIdentifier(t) {
156
- return u.includes(t) ? t : null;
168
+ return c.includes(t) ? t : null;
157
169
  }
158
170
  /**
159
171
  * Format chain name for display
@@ -172,5 +184,5 @@ class R {
172
184
  }
173
185
  }
174
186
  export {
175
- R as AssetManager
187
+ I as AssetManager
176
188
  };
package/dist/index11.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@gardenfi/utils"),h=require("node-cache"),a=class a{constructor(e,t){this.policy=new h({stdTTL:36e3,checkperiod:3600}),typeof t=="string"?this.auth=new o.ApiKey(t):this.auth=t,typeof e=="string"?this.apiBaseUrl=new o.Url(e):this.apiBaseUrl=e}getPolicy(){return this.policy.get(a.POLICY_CACHE_KEY)}setPolicy(e){const t=this.getPolicy(),s={default:e.default||(t==null?void 0:t.default)||"open",isolation_groups:[...new Set([...(t==null?void 0:t.isolation_groups)||[],...e.isolation_groups])],blacklist_pairs:[...new Set([...(t==null?void 0:t.blacklist_pairs)||[],...e.blacklist_pairs])],whitelist_overrides:[...new Set([...(t==null?void 0:t.whitelist_overrides)||[],...e.whitelist_overrides])]};return this.policy.set(a.POLICY_CACHE_KEY,s),s}async loadPolicy(){const e=this.getPolicy();if(e)return o.Ok(e);try{const t=await this.auth.getAuthHeaders();if(!t.ok)return o.Err(`Failed to get auth headers: ${t.error}`);const s=await o.Fetcher.get(this.apiBaseUrl.endpoint("v2/policy"),{headers:{"Content-Type":"application/json",...t.val}});return s.result?o.Ok(this.setPolicy(s.result)):o.Err(`API Error: ${s.error}`)}catch(t){return o.Err(`Failed to load policy: ${t}`)}}async isValidRoute(e,t){const s=await this.loadPolicy();if(!s.ok||e.toString()===t.toString())return!1;const{sortedIsolationRules:r,sortedBlacklistRules:i,sortedWhitelistRules:n}=this.preprocessRules(s.val),c=this.findMatchingRule(e,r);if(c&&!this.matchesRuleDestination(t,c))return!1;const l=this.findMatchingRule(t,r);return l&&l.rule.direction==="<->"&&!this.matchesRuleSource(e,l)?!1:this.matchesRuleList(e,t,i)?!!this.matchesRuleList(e,t,n):s.val.default==="open"}async getValidDestinations(e,t){const s=[];for(const r of t)await this.isValidRoute(e,r)&&s.push(r);return s}async getAllValidRoutes(e){const t=[];for(const s of e)for(const r of e)await this.isValidRoute(s,r)&&t.push({from:s,to:r});return t}preprocessRules(e){const t=e.isolation_groups.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),s=e.blacklist_pairs.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),r=e.whitelist_overrides.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity);return{sortedIsolationRules:t,sortedBlacklistRules:s,sortedWhitelistRules:r}}parseRule(e){const s=e.includes("<->")?"<->":"->",[r,i]=e.split(s).map(n=>n.trim());return{pattern:e,fromPattern:r,toPattern:i,direction:s,specificity:this.calculateSpecificity(r,i)}}calculateSpecificity(e,t){const s=r=>{const i=r.toLowerCase();return i==="*"?0:i.includes("*")?1:2};return s(e)*10+s(t)}findMatchingRule(e,t){for(const s of t){if(this.matchesAssetPattern(e,s.fromPattern))return{rule:s,matchedAs:"from"};if(s.direction==="<->"&&this.matchesAssetPattern(e,s.toPattern))return{rule:s,matchedAs:"to"}}return null}matchesRuleDestination(e,t){return t.matchedAs==="from"?this.matchesAssetPattern(e,t.rule.toPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.fromPattern)}matchesRuleSource(e,t){return t.matchedAs==="to"?this.matchesAssetPattern(e,t.rule.fromPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.toPattern)}matchesRuleList(e,t,s){return s.some(r=>this.matchesRule(e,t,r))}matchesRule(e,t,s){const r=this.matchesAssetPattern(e,s.fromPattern)&&this.matchesAssetPattern(t,s.toPattern);if(s.direction==="<->"){const i=this.matchesAssetPattern(e,s.toPattern)&&this.matchesAssetPattern(t,s.fromPattern);return r||i}return r}matchesAssetPattern(e,t){const[s="",r=""]=t.split(":").map(c=>c.trim().toLowerCase()),i=s===""||s==="*"||s===e.chain.toLowerCase(),n=r===""||r==="*"||r===e.symbol.toLowerCase();return i&&n}async buildRouteMatrix(e){const t={};for(const s of e){const r=[];for(const i of e)await this.isValidRoute(s,i)&&r.push(i);t[s.toString()]=r}return t}};a.POLICY_CACHE_KEY="route_policy";let u=a;exports.RouteValidator=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@gardenfi/utils"),h=require("node-cache"),o=class o{constructor(e,t){this.policy=new h({stdTTL:36e3,checkperiod:3600}),typeof t=="string"?this.auth=new a.ApiKey(t):this.auth=t,typeof e=="string"?this.apiBaseUrl=new a.Url(e):this.apiBaseUrl=e}getPolicy(){return this.policy.get(o.POLICY_CACHE_KEY)}setPolicy(e){const t=this.getPolicy(),s={default:e.default||(t==null?void 0:t.default)||"open",isolation_groups:[...new Set([...(t==null?void 0:t.isolation_groups)||[],...e.isolation_groups])],blacklist_pairs:[...new Set([...(t==null?void 0:t.blacklist_pairs)||[],...e.blacklist_pairs])],whitelist_overrides:[...new Set([...(t==null?void 0:t.whitelist_overrides)||[],...e.whitelist_overrides])]};return this.policy.set(o.POLICY_CACHE_KEY,s),s}async loadPolicy(){const e=this.getPolicy();if(e)return a.Ok(e);try{const t=await this.auth.getAuthHeaders();if(!t.ok)return a.Err(`Failed to get auth headers: ${t.error}`);const s=await a.Fetcher.get(this.apiBaseUrl,{headers:{"Content-Type":"application/json",...t.val}});return s.result?a.Ok(this.setPolicy(s.result)):a.Err(`API Error: ${s.error}`)}catch(t){return a.Err(`Failed to load policy: ${t}`)}}async isValidRoute(e,t){const s=await this.loadPolicy();if(!s.ok||e.toString()===t.toString())return!1;const{sortedIsolationRules:r,sortedBlacklistRules:i,sortedWhitelistRules:n}=this.preprocessRules(s.val),c=this.findMatchingRule(e,r);if(c&&!this.matchesRuleDestination(t,c))return!1;const l=this.findMatchingRule(t,r);return l&&l.rule.direction==="<->"&&!this.matchesRuleSource(e,l)?!1:this.matchesRuleList(e,t,i)?!!this.matchesRuleList(e,t,n):s.val.default==="open"}async getValidDestinations(e,t){const s=[];for(const r of t)await this.isValidRoute(e,r)&&s.push(r);return s}async getAllValidRoutes(e){const t=[];for(const s of e)for(const r of e)await this.isValidRoute(s,r)&&t.push({from:s,to:r});return t}preprocessRules(e){const t=e.isolation_groups.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),s=e.blacklist_pairs.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity),r=e.whitelist_overrides.map(i=>this.parseRule(i)).sort((i,n)=>n.specificity-i.specificity);return{sortedIsolationRules:t,sortedBlacklistRules:s,sortedWhitelistRules:r}}parseRule(e){const s=e.includes("<->")?"<->":"->",[r,i]=e.split(s).map(n=>n.trim());return{pattern:e,fromPattern:r,toPattern:i,direction:s,specificity:this.calculateSpecificity(r,i)}}calculateSpecificity(e,t){const s=r=>{const i=r.toLowerCase();return i==="*"?0:i.includes("*")?1:2};return s(e)*10+s(t)}findMatchingRule(e,t){for(const s of t){if(this.matchesAssetPattern(e,s.fromPattern))return{rule:s,matchedAs:"from"};if(s.direction==="<->"&&this.matchesAssetPattern(e,s.toPattern))return{rule:s,matchedAs:"to"}}return null}matchesRuleDestination(e,t){return t.matchedAs==="from"?this.matchesAssetPattern(e,t.rule.toPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.fromPattern)}matchesRuleSource(e,t){return t.matchedAs==="to"?this.matchesAssetPattern(e,t.rule.fromPattern):t.rule.direction!=="<->"?!1:this.matchesAssetPattern(e,t.rule.toPattern)}matchesRuleList(e,t,s){return s.some(r=>this.matchesRule(e,t,r))}matchesRule(e,t,s){const r=this.matchesAssetPattern(e,s.fromPattern)&&this.matchesAssetPattern(t,s.toPattern);if(s.direction==="<->"){const i=this.matchesAssetPattern(e,s.toPattern)&&this.matchesAssetPattern(t,s.fromPattern);return r||i}return r}matchesAssetPattern(e,t){const[s="",r=""]=t.split(":").map(c=>c.trim().toLowerCase()),i=s===""||s==="*"||s===e.chain.toLowerCase(),n=r===""||r==="*"||r===e.symbol.toLowerCase();return i&&n}async buildRouteMatrix(e){const t={};for(const s of e){const r=[];for(const i of e)await this.isValidRoute(s,i)&&r.push(i);t[s.toString()]=r}return t}};o.POLICY_CACHE_KEY="route_policy";let u=o;exports.RouteValidator=u;
package/dist/index11.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ApiKey as f, Url as p, Ok as u, Err as l, Fetcher as d } from "@gardenfi/utils";
2
2
  import m from "node-cache";
3
- const o = class o {
3
+ const a = class a {
4
4
  constructor(e, t) {
5
5
  this.policy = new m({
6
6
  stdTTL: 36e3,
@@ -10,7 +10,7 @@ const o = class o {
10
10
  }), typeof t == "string" ? this.auth = new f(t) : this.auth = t, typeof e == "string" ? this.apiBaseUrl = new p(e) : this.apiBaseUrl = e;
11
11
  }
12
12
  getPolicy() {
13
- return this.policy.get(o.POLICY_CACHE_KEY);
13
+ return this.policy.get(a.POLICY_CACHE_KEY);
14
14
  }
15
15
  setPolicy(e) {
16
16
  const t = this.getPolicy(), s = {
@@ -34,7 +34,7 @@ const o = class o {
34
34
  ])
35
35
  ]
36
36
  };
37
- return this.policy.set(o.POLICY_CACHE_KEY, s), s;
37
+ return this.policy.set(a.POLICY_CACHE_KEY, s), s;
38
38
  }
39
39
  /**
40
40
  * Loads the current route policy, cached or via API.
@@ -47,7 +47,7 @@ const o = class o {
47
47
  if (!t.ok)
48
48
  return l(`Failed to get auth headers: ${t.error}`);
49
49
  const s = await d.get(
50
- this.apiBaseUrl.endpoint("v2/policy"),
50
+ this.apiBaseUrl,
51
51
  {
52
52
  headers: {
53
53
  "Content-Type": "application/json",
@@ -66,25 +66,25 @@ const o = class o {
66
66
  async isValidRoute(e, t) {
67
67
  const s = await this.loadPolicy();
68
68
  if (!s.ok || e.toString() === t.toString()) return !1;
69
- const { sortedIsolationRules: i, sortedBlacklistRules: r, sortedWhitelistRules: n } = this.preprocessRules(s.val), a = this.findMatchingRule(
69
+ const { sortedIsolationRules: r, sortedBlacklistRules: i, sortedWhitelistRules: n } = this.preprocessRules(s.val), o = this.findMatchingRule(
70
70
  e,
71
- i
71
+ r
72
72
  );
73
- if (a && !this.matchesRuleDestination(t, a))
73
+ if (o && !this.matchesRuleDestination(t, o))
74
74
  return !1;
75
75
  const c = this.findMatchingRule(
76
76
  t,
77
- i
77
+ r
78
78
  );
79
- return c && c.rule.direction === "<->" && !this.matchesRuleSource(e, c) ? !1 : this.matchesRuleList(e, t, r) ? !!this.matchesRuleList(e, t, n) : s.val.default === "open";
79
+ return c && c.rule.direction === "<->" && !this.matchesRuleSource(e, c) ? !1 : this.matchesRuleList(e, t, i) ? !!this.matchesRuleList(e, t, n) : s.val.default === "open";
80
80
  }
81
81
  /**
82
82
  * Returns all valid destinations for a given source asset.
83
83
  */
84
84
  async getValidDestinations(e, t) {
85
85
  const s = [];
86
- for (const i of t)
87
- await this.isValidRoute(e, i) && s.push(i);
86
+ for (const r of t)
87
+ await this.isValidRoute(e, r) && s.push(r);
88
88
  return s;
89
89
  }
90
90
  /**
@@ -93,16 +93,16 @@ const o = class o {
93
93
  async getAllValidRoutes(e) {
94
94
  const t = [];
95
95
  for (const s of e)
96
- for (const i of e)
97
- await this.isValidRoute(s, i) && t.push({ from: s, to: i });
96
+ for (const r of e)
97
+ await this.isValidRoute(s, r) && t.push({ from: s, to: r });
98
98
  return t;
99
99
  }
100
100
  /**
101
101
  * Turns policy string rules into sorted ParsedRule objects.
102
102
  */
103
103
  preprocessRules(e) {
104
- const t = e.isolation_groups.map((r) => this.parseRule(r)).sort((r, n) => n.specificity - r.specificity), s = e.blacklist_pairs.map((r) => this.parseRule(r)).sort((r, n) => n.specificity - r.specificity), i = e.whitelist_overrides.map((r) => this.parseRule(r)).sort((r, n) => n.specificity - r.specificity);
105
- return { sortedIsolationRules: t, sortedBlacklistRules: s, sortedWhitelistRules: i };
104
+ const t = e.isolation_groups.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity), s = e.blacklist_pairs.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity), r = e.whitelist_overrides.map((i) => this.parseRule(i)).sort((i, n) => n.specificity - i.specificity);
105
+ return { sortedIsolationRules: t, sortedBlacklistRules: s, sortedWhitelistRules: r };
106
106
  }
107
107
  /**
108
108
  * Parses a rule string (e.g. "ethereum:usdc -> base:usdt") into parts.
@@ -111,22 +111,22 @@ const o = class o {
111
111
  const s = e.includes(
112
112
  "<->"
113
113
  /* Bidirectional */
114
- ) ? "<->" : "->", [i, r] = e.split(s).map((n) => n.trim());
114
+ ) ? "<->" : "->", [r, i] = e.split(s).map((n) => n.trim());
115
115
  return {
116
116
  pattern: e,
117
- fromPattern: i,
118
- toPattern: r,
117
+ fromPattern: r,
118
+ toPattern: i,
119
119
  direction: s,
120
- specificity: this.calculateSpecificity(i, r)
120
+ specificity: this.calculateSpecificity(r, i)
121
121
  };
122
122
  }
123
123
  /**
124
124
  * Gives a specificity score to a rule pattern for prioritizing.
125
125
  */
126
126
  calculateSpecificity(e, t) {
127
- const s = (i) => {
128
- const r = i.toLowerCase();
129
- return r === "*" ? 0 : r.includes(
127
+ const s = (r) => {
128
+ const i = r.toLowerCase();
129
+ return i === "*" ? 0 : i.includes(
130
130
  "*"
131
131
  /* Any */
132
132
  ) ? 1 : 2;
@@ -169,39 +169,39 @@ const o = class o {
169
169
  * Checks if any rule in a list matches fromAsset and toAsset.
170
170
  */
171
171
  matchesRuleList(e, t, s) {
172
- return s.some((i) => this.matchesRule(e, t, i));
172
+ return s.some((r) => this.matchesRule(e, t, r));
173
173
  }
174
174
  /**
175
175
  * Checks if a rule matches fromAsset and toAsset (forward or backward if bidirectional).
176
176
  */
177
177
  matchesRule(e, t, s) {
178
- const i = this.matchesAssetPattern(e, s.fromPattern) && this.matchesAssetPattern(t, s.toPattern);
178
+ const r = this.matchesAssetPattern(e, s.fromPattern) && this.matchesAssetPattern(t, s.toPattern);
179
179
  if (s.direction === "<->") {
180
- const r = this.matchesAssetPattern(e, s.toPattern) && this.matchesAssetPattern(t, s.fromPattern);
181
- return i || r;
180
+ const i = this.matchesAssetPattern(e, s.toPattern) && this.matchesAssetPattern(t, s.fromPattern);
181
+ return r || i;
182
182
  }
183
- return i;
183
+ return r;
184
184
  }
185
185
  /**
186
186
  * Checks if an asset string matches a rule's pattern (wildcards supported).
187
187
  */
188
188
  matchesAssetPattern(e, t) {
189
- const [s = "", i = ""] = t.split(":").map((a) => a.trim().toLowerCase()), r = s === "" || s === "*" || s === e.chain.toLowerCase(), n = i === "" || i === "*" || i === e.symbol.toLowerCase();
190
- return r && n;
189
+ const [s = "", r = ""] = t.split(":").map((o) => o.trim().toLowerCase()), i = s === "" || s === "*" || s === e.chain.toLowerCase(), n = r === "" || r === "*" || r === e.symbol.toLowerCase();
190
+ return i && n;
191
191
  }
192
192
  async buildRouteMatrix(e) {
193
193
  const t = {};
194
194
  for (const s of e) {
195
- const i = [];
196
- for (const r of e)
197
- await this.isValidRoute(s, r) && i.push(r);
198
- t[s.toString()] = i;
195
+ const r = [];
196
+ for (const i of e)
197
+ await this.isValidRoute(s, i) && r.push(i);
198
+ t[s.toString()] = r;
199
199
  }
200
200
  return t;
201
201
  }
202
202
  };
203
- o.POLICY_CACHE_KEY = "route_policy";
204
- let h = o;
203
+ a.POLICY_CACHE_KEY = "route_policy";
204
+ let h = a;
205
205
  export {
206
206
  h as RouteValidator
207
207
  };
package/dist/index12.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./index8.cjs");function c(m,e,t){var i;const r=(m??"").trim();if(!r)return{name:"",symbol:""};const s=r.split(":");if(s.length>=2){const o=((i=s[0])==null?void 0:i.trim())||"",p=s.slice(1).join(":").trim()||(t==null?void 0:t.trim())||"";return{name:o,symbol:p}}let n="";if(e)try{n=(typeof e=="string"?u.ChainAsset.from(e):e).symbol.toUpperCase()}catch{}return{name:r,symbol:n||(t==null?void 0:t.trim())||""}}exports.parseAssetNameSymbol=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@gardenfi/utils"),p=require("./index8.cjs");function d(n,t,e){var o;const r=(n??"").trim();if(!r)return{name:"",symbol:""};const i=r.split(":");if(i.length>=2){const u=((o=i[0])==null?void 0:o.trim())||"",m=i.slice(1).join(":").trim()||(e==null?void 0:e.trim())||"";return{name:u,symbol:m}}let s="";if(t)try{s=(typeof t=="string"?p.ChainAsset.from(t):t).symbol.toUpperCase()}catch{}return{name:r,symbol:s||(e==null?void 0:e.trim())||""}}function h(n){return n instanceof c.Url?n:new c.Url(n)}function A(n,t){const e=n.toString().replace(/\/+$/,""),r=t.startsWith("/")?t:`/${t}`;return`${e}${r}`}exports.buildDefaultEndpoint=A;exports.ensureUrl=h;exports.parseAssetNameSymbol=d;
package/dist/index12.js CHANGED
@@ -1,21 +1,31 @@
1
- import { ChainAsset as h } from "./index8.js";
2
- function A(m, r, t) {
3
- var s;
4
- const n = (m ?? "").trim();
5
- if (!n) return { name: "", symbol: "" };
6
- const e = n.split(":");
7
- if (e.length >= 2) {
8
- const o = ((s = e[0]) == null ? void 0 : s.trim()) || "", p = e.slice(1).join(":").trim() || (t == null ? void 0 : t.trim()) || "";
9
- return { name: o, symbol: p };
1
+ import { Url as p } from "@gardenfi/utils";
2
+ import { ChainAsset as c } from "./index8.js";
3
+ function $(r, t, n) {
4
+ var o;
5
+ const e = (r ?? "").trim();
6
+ if (!e) return { name: "", symbol: "" };
7
+ const i = e.split(":");
8
+ if (i.length >= 2) {
9
+ const m = ((o = i[0]) == null ? void 0 : o.trim()) || "", u = i.slice(1).join(":").trim() || (n == null ? void 0 : n.trim()) || "";
10
+ return { name: m, symbol: u };
10
11
  }
11
- let i = "";
12
- if (r)
12
+ let s = "";
13
+ if (t)
13
14
  try {
14
- i = (typeof r == "string" ? h.from(r) : r).symbol.toUpperCase();
15
+ s = (typeof t == "string" ? c.from(t) : t).symbol.toUpperCase();
15
16
  } catch {
16
17
  }
17
- return { name: n, symbol: i || (t == null ? void 0 : t.trim()) || "" };
18
+ return { name: e, symbol: s || (n == null ? void 0 : n.trim()) || "" };
19
+ }
20
+ function d(r) {
21
+ return r instanceof p ? r : new p(r);
22
+ }
23
+ function f(r, t) {
24
+ const n = r.toString().replace(/\/+$/, ""), e = t.startsWith("/") ? t : `/${t}`;
25
+ return `${n}${e}`;
18
26
  }
19
27
  export {
20
- A as parseAssetNameSymbol
28
+ f as buildDefaultEndpoint,
29
+ d as ensureUrl,
30
+ $ as parseAssetNameSymbol
21
31
  };
@@ -1,9 +1,14 @@
1
- import { AsyncResult, IAuth } from '@gardenfi/utils';
1
+ import { Url, AsyncResult, IAuth } from '@gardenfi/utils';
2
2
  import { RouteValidator } from './routeValidator/routeValidator';
3
3
  import { Assets, ChainData, Chains } from './types';
4
4
  import { ChainAsset } from '../chainAsset/chainAsset';
5
5
  import { Asset, Chain } from '../constants/asset.types';
6
6
 
7
+ type AssetManagerUrlConfig = {
8
+ baseUrl: string | Url;
9
+ assetsUrl?: string | Url;
10
+ policyUrl?: string | Url;
11
+ };
7
12
  /**
8
13
  * AssetManager
9
14
  *
@@ -18,9 +23,9 @@ export declare class AssetManager {
18
23
  routeMatrix: Record<string, ChainAsset[]> | null;
19
24
  isLoading: boolean;
20
25
  error: string | null;
21
- private readonly url;
26
+ private readonly urls;
22
27
  private auth;
23
- constructor(url: string, apiKey: IAuth | string);
28
+ constructor(urlConfig: AssetManagerUrlConfig, apiKey: IAuth | string);
24
29
  /**
25
30
  * Initialize the AssetManager by fetching all required data
26
31
  */
@@ -74,3 +79,4 @@ export declare class AssetManager {
74
79
  */
75
80
  refresh(): Promise<void>;
76
81
  }
82
+ export {};
@@ -1,6 +1,9 @@
1
+ import { Url } from '@gardenfi/utils';
1
2
  import { ChainAsset } from '../chainAsset/chainAsset';
2
3
 
3
4
  export declare function parseAssetNameSymbol(input: string | undefined, assetId?: string | ChainAsset, fallbackSymbol?: string): {
4
5
  name: string;
5
6
  symbol: string;
6
7
  };
8
+ export declare function ensureUrl(value: string | Url): Url;
9
+ export declare function buildDefaultEndpoint(baseUrl: Url, path: string): string;
@@ -172,7 +172,12 @@ type EvmTypedData = {
172
172
  domain: Record<string, unknown>;
173
173
  types: Record<string, unknown>;
174
174
  primaryType: string;
175
- message: Record<string, unknown>;
175
+ message: {
176
+ amount: string;
177
+ secretHash: string;
178
+ timelock: string;
179
+ redeemer: string;
180
+ };
176
181
  };
177
182
  export type EvmOrderResponse = WithTypedData<BaseCreateOrderResponse & {
178
183
  approval_transaction: EVMTransaction | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.5.3-beta.16",
3
+ "version": "2.5.3-beta.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@coral-xyz/anchor": "^0.31.1",
31
- "@gardenfi/utils": "2.5.3-beta.8",
31
+ "@gardenfi/utils": "2.5.3-beta.9",
32
32
  "bufferutil": "^4.0.8",
33
33
  "node-cache": "^5.1.2",
34
34
  "siwe": "^2.1.4",