@gardenfi/orderbook 2.4.4 → 2.4.5

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/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),l=require("./index5.cjs");class h{constructor(s){this.Url=s}async createOrder(s,n){const t=await n.getAuthHeaders();if(t.error)return r.Err(t.error);try{const e=await r.Fetcher.post(this.Url,{body:JSON.stringify(s),headers:{...t.val,"Content-Type":"application/json"}});return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(e){return r.Err("CreateOrder Err:",String(e))}}async getOrder(s,n){const t=this.Url.endpoint(n?`/id/${s}/matched`:`/id/${s}/unmatched`);try{const e=await r.Fetcher.get(t);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrder:",String(e))}}async getMatchedOrders(s,n,t){const e=l.ConstructUrl(this.Url,`/user/${s}/matched`,{...t,status:n});try{const o=await r.Fetcher.get(e);return o.error?r.Err(o.error):o.result?r.Ok(o.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(o){return r.Err("GetMatchedOrders:",String(o))}}async getUnMatchedOrders(s,n){const t=l.ConstructUrl(this.Url,`/user/${s}/unmatched`,n);try{const e=await r.Fetcher.get(t);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetUnMatchedOrders:",String(e))}}async getOrders(s,n,t,e,o,a){const d=s?"/matched":"/unmatched",u={};n&&(u.page=n.page,u.per_page=n.per_page),t&&(u.address=t),e&&(u.tx_hash=e),o&&(u.from_chain=o),a&&(u.to_chain=a);const i=l.ConstructUrl(this.Url,d,u);try{const c=await r.Fetcher.get(i);return c.error?r.Err(c.error):c.result?r.Ok(c.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(c){return r.Err("GetAllOrders:",String(c))}}async subscribeOrders(s,n,t,e,o="all",a){let d=!1;const u=async()=>{if(!d){d=!0;try{const c=n?await this.getMatchedOrders(s,o,a):await this.getUnMatchedOrders(s,a);c.ok?await e(c.val):console.error("Error fetching orders:",c.error)}catch(c){console.error("Error fetching orders:",c)}finally{d=!1}}};await u();const i=setInterval(u,t);return()=>{clearInterval(i)}}async getOrdersCount(s){const n=this.Url.endpoint(`/user/${s}/count`);try{const t=await r.Fetcher.get(n);return t.error?r.Err(t.error):t.status===r.ApiStatus.Ok&&t.result!==void 0?r.Ok(t.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(t){return r.Err("GetOrdersCount:",String(t))}}}exports.Orderbook=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),O=require("./index5.cjs");class f{constructor(s){this.Url=s}async createOrder(s,c){const n=await c.getAuthHeaders();if(n.error)return r.Err(n.error);try{const e=await r.Fetcher.post(this.Url,{body:JSON.stringify(s),headers:{...n.val,"Content-Type":"application/json"}});return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("CreateOrder: Unexpected error, result is undefined")}catch(e){return r.Err("CreateOrder Err:",String(e))}}async getOrder(s,c,n){const e=this.Url.endpoint(c?`/id/${s}/matched`:`/id/${s}/unmatched`);try{const t=await r.Fetcher.get(e,{...n});return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(t){return r.Err("GetOrder:",String(t))}}async getMatchedOrders(s,c,n,e){const t=O.ConstructUrl(this.Url,`/user/${s}/matched`,{...n,status:c});try{const o=await r.Fetcher.get(t,{...e});return o.error?r.Err(o.error):o.result?r.Ok(o.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(o){return r.Err("GetMatchedOrders:",String(o))}}async getUnMatchedOrders(s,c,n){const e=O.ConstructUrl(this.Url,`/user/${s}/unmatched`,c);try{const t=await r.Fetcher.get(e,{...n});return t.error?r.Err(t.error):t.result?r.Ok(t.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(t){return r.Err("GetUnMatchedOrders:",String(t))}}async getOrders(s,c,n,e,t,o,i,l){const h=s?"/matched":"/unmatched",u={};c&&(u.page=c.page,u.per_page=c.per_page),n&&(u.address=n),e&&(u.tx_hash=e),t&&(u.from_chain=t),o&&(u.to_chain=o),i&&(u.status=i);const a=O.ConstructUrl(this.Url,h,u);try{const d=await r.Fetcher.get(a,{...l});return d.error?r.Err(d.error):d.result?r.Ok(d.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(d){return r.Err("GetAllOrders:",String(d))}}async subscribeOrders(s,c,n,e,t="all",o,i){let l=!1;const h=async()=>{if(!l){l=!0;try{const a=c?await this.getMatchedOrders(s,t,o,i):await this.getUnMatchedOrders(s,o,i);a.ok?await e(a.val):console.error("Error fetching orders:",a.error)}catch(a){console.error("Error fetching orders:",a)}finally{l=!1}}};await h();const u=setInterval(h,n);return()=>{clearInterval(u)}}async getOrdersCount(s,c){const n=this.Url.endpoint(`/user/${s}/count`);try{const e=await r.Fetcher.get(n,{...c});return e.error?r.Err(e.error):e.status===r.ApiStatus.Ok&&e.result!==void 0?r.Ok(e.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrdersCount:",String(e))}}}exports.Orderbook=f;
package/dist/index2.js CHANGED
@@ -1,6 +1,6 @@
1
- import { Err as t, Fetcher as d, Ok as u, ApiStatus as O } from "@gardenfi/utils";
2
- import { ConstructUrl as f } from "./index5.js";
3
- class U {
1
+ import { Err as t, Fetcher as i, Ok as l, ApiStatus as p } from "@gardenfi/utils";
2
+ import { ConstructUrl as g } from "./index5.js";
3
+ class w {
4
4
  constructor(s) {
5
5
  this.Url = s;
6
6
  }
@@ -10,107 +10,109 @@ class U {
10
10
  * @param {IAuth} auth - The auth object.
11
11
  * @returns {string} The create order ID.
12
12
  */
13
- async createOrder(s, n) {
14
- const e = await n.getAuthHeaders();
15
- if (e.error)
16
- return t(e.error);
13
+ async createOrder(s, c) {
14
+ const n = await c.getAuthHeaders();
15
+ if (n.error)
16
+ return t(n.error);
17
17
  try {
18
- const r = await d.post(this.Url, {
18
+ const r = await i.post(this.Url, {
19
19
  body: JSON.stringify(s),
20
20
  headers: {
21
- ...e.val,
21
+ ...n.val,
22
22
  "Content-Type": "application/json"
23
23
  }
24
24
  });
25
- return r.error ? t(r.error) : r.result ? u(r.result) : t("CreateOrder: Unexpected error, result is undefined");
25
+ return r.error ? t(r.error) : r.result ? l(r.result) : t("CreateOrder: Unexpected error, result is undefined");
26
26
  } catch (r) {
27
27
  return t("CreateOrder Err:", String(r));
28
28
  }
29
29
  }
30
- async getOrder(s, n) {
31
- const e = this.Url.endpoint(
32
- n ? `/id/${s}/matched` : `/id/${s}/unmatched`
30
+ async getOrder(s, c, n) {
31
+ const r = this.Url.endpoint(
32
+ c ? `/id/${s}/matched` : `/id/${s}/unmatched`
33
33
  );
34
34
  try {
35
- const r = await d.get(e);
36
- return r.error ? t(r.error) : r.result ? u(r.result) : t("GetOrder: Unexpected error, result is undefined");
37
- } catch (r) {
38
- return t("GetOrder:", String(r));
35
+ const e = await i.get(r, { ...n });
36
+ return e.error ? t(e.error) : e.result ? l(e.result) : t("GetOrder: Unexpected error, result is undefined");
37
+ } catch (e) {
38
+ return t("GetOrder:", String(e));
39
39
  }
40
40
  }
41
- async getMatchedOrders(s, n, e) {
42
- const r = f(this.Url, `/user/${s}/matched`, {
43
- ...e,
44
- status: n
41
+ async getMatchedOrders(s, c, n, r) {
42
+ const e = g(this.Url, `/user/${s}/matched`, {
43
+ ...n,
44
+ status: c
45
45
  });
46
46
  try {
47
- const o = await d.get(
48
- r
47
+ const o = await i.get(
48
+ e,
49
+ { ...r }
49
50
  );
50
- return o.error ? t(o.error) : o.result ? u(o.result) : t("GetMatchedOrders: Unexpected error, result is undefined");
51
+ return o.error ? t(o.error) : o.result ? l(o.result) : t("GetMatchedOrders: Unexpected error, result is undefined");
51
52
  } catch (o) {
52
53
  return t("GetMatchedOrders:", String(o));
53
54
  }
54
55
  }
55
- async getUnMatchedOrders(s, n) {
56
- const e = f(
56
+ async getUnMatchedOrders(s, c, n) {
57
+ const r = g(
57
58
  this.Url,
58
59
  `/user/${s}/unmatched`,
59
- n
60
+ c
60
61
  );
61
62
  try {
62
- const r = await d.get(
63
- e
63
+ const e = await i.get(
64
+ r,
65
+ { ...n }
64
66
  );
65
- return r.error ? t(r.error) : r.result ? u(r.result) : t("GetUnMatchedOrders: Unexpected error, result is undefined");
66
- } catch (r) {
67
- return t("GetUnMatchedOrders:", String(r));
67
+ return e.error ? t(e.error) : e.result ? l(e.result) : t("GetUnMatchedOrders: Unexpected error, result is undefined");
68
+ } catch (e) {
69
+ return t("GetUnMatchedOrders:", String(e));
68
70
  }
69
71
  }
70
- async getOrders(s, n, e, r, o, i) {
71
- const l = s ? "/matched" : "/unmatched", a = {};
72
- n && (a.page = n.page, a.per_page = n.per_page), e && (a.address = e), r && (a.tx_hash = r), o && (a.from_chain = o), i && (a.to_chain = i);
73
- const h = f(this.Url, l, a);
72
+ async getOrders(s, c, n, r, e, o, h, f) {
73
+ const O = s ? "/matched" : "/unmatched", a = {};
74
+ c && (a.page = c.page, a.per_page = c.per_page), n && (a.address = n), r && (a.tx_hash = r), e && (a.from_chain = e), o && (a.to_chain = o), h && (a.status = h);
75
+ const d = g(this.Url, O, a);
74
76
  try {
75
- const c = await d.get(h);
76
- return c.error ? t(c.error) : c.result ? u(c.result) : t("GetAllOrders: Unexpected error, result is undefined");
77
- } catch (c) {
78
- return t("GetAllOrders:", String(c));
77
+ const u = await i.get(d, { ...f });
78
+ return u.error ? t(u.error) : u.result ? l(u.result) : t("GetAllOrders: Unexpected error, result is undefined");
79
+ } catch (u) {
80
+ return t("GetAllOrders:", String(u));
79
81
  }
80
82
  }
81
- async subscribeOrders(s, n, e, r, o = "all", i) {
82
- let l = !1;
83
- const a = async () => {
84
- if (!l) {
85
- l = !0;
83
+ async subscribeOrders(s, c, n, r, e = "all", o, h) {
84
+ let f = !1;
85
+ const O = async () => {
86
+ if (!f) {
87
+ f = !0;
86
88
  try {
87
- const c = n ? await this.getMatchedOrders(s, o, i) : await this.getUnMatchedOrders(s, i);
88
- c.ok ? await r(
89
- c.val
90
- ) : console.error("Error fetching orders:", c.error);
91
- } catch (c) {
92
- console.error("Error fetching orders:", c);
89
+ const d = c ? await this.getMatchedOrders(s, e, o, h) : await this.getUnMatchedOrders(s, o, h);
90
+ d.ok ? await r(
91
+ d.val
92
+ ) : console.error("Error fetching orders:", d.error);
93
+ } catch (d) {
94
+ console.error("Error fetching orders:", d);
93
95
  } finally {
94
- l = !1;
96
+ f = !1;
95
97
  }
96
98
  }
97
99
  };
98
- await a();
99
- const h = setInterval(a, e);
100
+ await O();
101
+ const a = setInterval(O, n);
100
102
  return () => {
101
- clearInterval(h);
103
+ clearInterval(a);
102
104
  };
103
105
  }
104
- async getOrdersCount(s) {
106
+ async getOrdersCount(s, c) {
105
107
  const n = this.Url.endpoint(`/user/${s}/count`);
106
108
  try {
107
- const e = await d.get(n);
108
- return e.error ? t(e.error) : e.status === O.Ok && e.result !== void 0 ? u(e.result) : t("GetOrdersCount: Unexpected error, result is undefined");
109
- } catch (e) {
110
- return t("GetOrdersCount:", String(e));
109
+ const r = await i.get(n, { ...c });
110
+ return r.error ? t(r.error) : r.status === p.Ok && r.result !== void 0 ? l(r.result) : t("GetOrdersCount: Unexpected error, result is undefined");
111
+ } catch (r) {
112
+ return t("GetOrdersCount:", String(r));
111
113
  }
112
114
  }
113
115
  }
114
116
  export {
115
- U as Orderbook
117
+ w as Orderbook
116
118
  };
@@ -1,5 +1,5 @@
1
- import { CreateOrder, CreateOrderReqWithStrategyId, IOrderbook, MatchedOrder, PaginatedData, PaginationConfig, Status } from './orderbook.types';
2
- import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
1
+ import { CreateOrder, CreateOrderReqWithStrategyId, IOrderbook, MatchedOrder, OrderStatus, PaginatedData, PaginationConfig, Status } from './orderbook.types';
2
+ import { AsyncResult, IAuth, Url, Request as UtilsRequest } from '@gardenfi/utils';
3
3
  import { Chain } from '../asset';
4
4
 
5
5
  /**
@@ -17,10 +17,10 @@ export declare class Orderbook implements IOrderbook {
17
17
  * @returns {string} The create order ID.
18
18
  */
19
19
  createOrder(order: CreateOrderReqWithStrategyId, auth: IAuth): AsyncResult<MatchedOrder, string>;
20
- getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
21
- getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
22
- getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
23
- getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig, address?: string, tx_hash?: string, fromChain?: Chain, toChain?: Chain): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
24
- subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig): Promise<() => void>;
25
- getOrdersCount(address: string): AsyncResult<number, string>;
20
+ getOrder<T extends boolean>(id: string, matched: T, request?: UtilsRequest): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
21
+ getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<MatchedOrder>, string>;
22
+ getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<CreateOrder>, string>;
23
+ getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig, address?: string, tx_hash?: string, fromChain?: Chain, toChain?: Chain, status?: OrderStatus, request?: UtilsRequest): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
24
+ subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig, request?: UtilsRequest): Promise<() => void>;
25
+ getOrdersCount(address: string, request?: UtilsRequest): AsyncResult<number, string>;
26
26
  }
@@ -220,6 +220,8 @@ export type Swap = {
220
220
  swap_id: string;
221
221
  chain: Chain;
222
222
  asset: string;
223
+ htlc_address: string;
224
+ token_address: string;
223
225
  initiator: string;
224
226
  redeemer: string;
225
227
  timelock: number;
@@ -234,6 +236,10 @@ export type Swap = {
234
236
  redeem_block_number: string | null;
235
237
  refund_block_number: string | null;
236
238
  required_confirmations: number;
239
+ current_confirmations: number;
240
+ initiate_timestamp: string | null;
241
+ redeem_timestamp: string | null;
242
+ refund_timestamp: string | null;
237
243
  };
238
244
  export type MatchedOrder = {
239
245
  created_at: string;
@@ -256,3 +262,4 @@ export type PaginationConfig = {
256
262
  per_page?: number;
257
263
  };
258
264
  export type Status = 'all' | 'pending' | 'fulfilled';
265
+ export type OrderStatus = 'refunded' | 'expired' | 'completed' | 'in-progress' | 'not-initiated';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@coral-xyz/anchor": "^0.30.1",
30
- "@gardenfi/utils": "2.4.4",
30
+ "@gardenfi/utils": "2.4.5",
31
31
  "bufferutil": "^4.0.8",
32
32
  "siwe": "^2.1.4",
33
33
  "utf-8-validate": "^6.0.3",