@gardenfi/orderbook 2.4.5 → 2.4.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/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@gardenfi/utils"),a=require("./index5.cjs");class O{constructor(c){this.Url=c}async createOrder(c,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(c),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(c,n,t){const e=this.Url.endpoint(n?`/id/${c}/matched`:`/id/${c}/unmatched`);try{const s=await r.Fetcher.get(e,{...t});return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(s){return r.Err("GetOrder:",String(s))}}async getMatchedOrders(c,n,t,e){const s=a.ConstructUrl(this.Url,`/user/${c}/matched`,{...t,status:n});try{const u=await r.Fetcher.get(s,{...e});return u.error?r.Err(u.error):u.result?r.Ok(u.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(u){return r.Err("GetMatchedOrders:",String(u))}}async getUnMatchedOrders(c,n,t){const e=a.ConstructUrl(this.Url,`/user/${c}/unmatched`,n);try{const s=await r.Fetcher.get(e,{...t});return s.error?r.Err(s.error):s.result?r.Ok(s.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(s){return r.Err("GetUnMatchedOrders:",String(s))}}async getOrders(c,n,t,e){const s=c?"/matched":"/unmatched",u={page:t==null?void 0:t.page,per_page:t==null?void 0:t.per_page,...n},l=a.ConstructUrl(this.Url,s,u);try{const d=await r.Fetcher.get(l,{...e});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(c,n,t,e,s="all",u,l){let d=!1;const h=async()=>{if(!d){d=!0;try{const o=n?await this.getMatchedOrders(c,s,u,l):await this.getUnMatchedOrders(c,u,l);o.ok?await e(o.val):console.error("Error fetching orders:",o.error)}catch(o){console.error("Error fetching orders:",o)}finally{d=!1}}};await h();const i=setInterval(h,t);return()=>{clearInterval(i)}}async getOrdersCount(c,n){const t=this.Url.endpoint(`/user/${c}/count`);try{const e=await r.Fetcher.get(t,{...n});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=O;
|
package/dist/index2.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Err as
|
|
2
|
-
import { ConstructUrl as
|
|
1
|
+
import { Err as s, Fetcher as o, Ok as a, ApiStatus as U } from "@gardenfi/utils";
|
|
2
|
+
import { ConstructUrl as i } from "./index5.js";
|
|
3
3
|
class w {
|
|
4
|
-
constructor(
|
|
5
|
-
this.Url =
|
|
4
|
+
constructor(c) {
|
|
5
|
+
this.Url = c;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
8
|
* Creates an order
|
|
@@ -10,106 +10,113 @@ class w {
|
|
|
10
10
|
* @param {IAuth} auth - The auth object.
|
|
11
11
|
* @returns {string} The create order ID.
|
|
12
12
|
*/
|
|
13
|
-
async createOrder(
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
13
|
+
async createOrder(c, n) {
|
|
14
|
+
const e = await n.getAuthHeaders();
|
|
15
|
+
if (e.error)
|
|
16
|
+
return s(e.error);
|
|
17
17
|
try {
|
|
18
|
-
const r = await
|
|
19
|
-
body: JSON.stringify(
|
|
18
|
+
const r = await o.post(this.Url, {
|
|
19
|
+
body: JSON.stringify(c),
|
|
20
20
|
headers: {
|
|
21
|
-
...
|
|
21
|
+
...e.val,
|
|
22
22
|
"Content-Type": "application/json"
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
return r.error ?
|
|
25
|
+
return r.error ? s(r.error) : r.result ? a(r.result) : s("CreateOrder: Unexpected error, result is undefined");
|
|
26
26
|
} catch (r) {
|
|
27
|
-
return
|
|
27
|
+
return s("CreateOrder Err:", String(r));
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
|
-
async getOrder(
|
|
30
|
+
async getOrder(c, n, e) {
|
|
31
31
|
const r = this.Url.endpoint(
|
|
32
|
-
|
|
32
|
+
n ? `/id/${c}/matched` : `/id/${c}/unmatched`
|
|
33
33
|
);
|
|
34
34
|
try {
|
|
35
|
-
const
|
|
36
|
-
return
|
|
37
|
-
} catch (
|
|
38
|
-
return
|
|
35
|
+
const t = await o.get(r, { ...e });
|
|
36
|
+
return t.error ? s(t.error) : t.result ? a(t.result) : s("GetOrder: Unexpected error, result is undefined");
|
|
37
|
+
} catch (t) {
|
|
38
|
+
return s("GetOrder:", String(t));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
async getMatchedOrders(
|
|
42
|
-
const
|
|
43
|
-
...
|
|
44
|
-
status:
|
|
41
|
+
async getMatchedOrders(c, n, e, r) {
|
|
42
|
+
const t = i(this.Url, `/user/${c}/matched`, {
|
|
43
|
+
...e,
|
|
44
|
+
status: n
|
|
45
45
|
});
|
|
46
46
|
try {
|
|
47
|
-
const
|
|
48
|
-
|
|
47
|
+
const d = await o.get(
|
|
48
|
+
t,
|
|
49
49
|
{ ...r }
|
|
50
50
|
);
|
|
51
|
-
return
|
|
52
|
-
} catch (
|
|
53
|
-
return
|
|
51
|
+
return d.error ? s(d.error) : d.result ? a(d.result) : s("GetMatchedOrders: Unexpected error, result is undefined");
|
|
52
|
+
} catch (d) {
|
|
53
|
+
return s("GetMatchedOrders:", String(d));
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
async getUnMatchedOrders(
|
|
57
|
-
const r =
|
|
56
|
+
async getUnMatchedOrders(c, n, e) {
|
|
57
|
+
const r = i(
|
|
58
58
|
this.Url,
|
|
59
|
-
`/user/${
|
|
60
|
-
|
|
59
|
+
`/user/${c}/unmatched`,
|
|
60
|
+
n
|
|
61
61
|
);
|
|
62
62
|
try {
|
|
63
|
-
const
|
|
63
|
+
const t = await o.get(
|
|
64
64
|
r,
|
|
65
|
-
{ ...
|
|
65
|
+
{ ...e }
|
|
66
66
|
);
|
|
67
|
-
return
|
|
68
|
-
} catch (
|
|
69
|
-
return
|
|
67
|
+
return t.error ? s(t.error) : t.result ? a(t.result) : s("GetUnMatchedOrders: Unexpected error, result is undefined");
|
|
68
|
+
} catch (t) {
|
|
69
|
+
return s("GetUnMatchedOrders:", String(t));
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
async getOrders(
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
async getOrders(c, n, e, r) {
|
|
73
|
+
const t = c ? "/matched" : "/unmatched", d = {
|
|
74
|
+
page: e == null ? void 0 : e.page,
|
|
75
|
+
per_page: e == null ? void 0 : e.per_page,
|
|
76
|
+
...n
|
|
77
|
+
}, h = i(this.Url, t, d);
|
|
76
78
|
try {
|
|
77
|
-
const u = await
|
|
78
|
-
return u.error ?
|
|
79
|
+
const u = await o.get(h, { ...r });
|
|
80
|
+
return u.error ? s(u.error) : u.result ? a(u.result) : s("GetAllOrders: Unexpected error, result is undefined");
|
|
79
81
|
} catch (u) {
|
|
80
|
-
return
|
|
82
|
+
return s("GetAllOrders:", String(u));
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
|
-
async subscribeOrders(
|
|
84
|
-
let
|
|
85
|
+
async subscribeOrders(c, n, e, r, t = "all", d, h) {
|
|
86
|
+
let u = !1;
|
|
85
87
|
const O = async () => {
|
|
86
|
-
if (!
|
|
87
|
-
|
|
88
|
+
if (!u) {
|
|
89
|
+
u = !0;
|
|
88
90
|
try {
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
const l = n ? await this.getMatchedOrders(
|
|
92
|
+
c,
|
|
93
|
+
t,
|
|
94
|
+
d,
|
|
95
|
+
h
|
|
96
|
+
) : await this.getUnMatchedOrders(c, d, h);
|
|
97
|
+
l.ok ? await r(
|
|
98
|
+
l.val
|
|
99
|
+
) : console.error("Error fetching orders:", l.error);
|
|
100
|
+
} catch (l) {
|
|
101
|
+
console.error("Error fetching orders:", l);
|
|
95
102
|
} finally {
|
|
96
|
-
|
|
103
|
+
u = !1;
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
};
|
|
100
107
|
await O();
|
|
101
|
-
const
|
|
108
|
+
const y = setInterval(O, e);
|
|
102
109
|
return () => {
|
|
103
|
-
clearInterval(
|
|
110
|
+
clearInterval(y);
|
|
104
111
|
};
|
|
105
112
|
}
|
|
106
|
-
async getOrdersCount(
|
|
107
|
-
const
|
|
113
|
+
async getOrdersCount(c, n) {
|
|
114
|
+
const e = this.Url.endpoint(`/user/${c}/count`);
|
|
108
115
|
try {
|
|
109
|
-
const r = await
|
|
110
|
-
return r.error ?
|
|
116
|
+
const r = await o.get(e, { ...n });
|
|
117
|
+
return r.error ? s(r.error) : r.status === U.Ok && r.result !== void 0 ? a(r.result) : s("GetOrdersCount: Unexpected error, result is undefined");
|
|
111
118
|
} catch (r) {
|
|
112
|
-
return
|
|
119
|
+
return s("GetOrdersCount:", String(r));
|
|
113
120
|
}
|
|
114
121
|
}
|
|
115
122
|
}
|
|
@@ -20,7 +20,14 @@ export declare class Orderbook implements IOrderbook {
|
|
|
20
20
|
getOrder<T extends boolean>(id: string, matched: T, request?: UtilsRequest): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
|
|
21
21
|
getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<MatchedOrder>, string>;
|
|
22
22
|
getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<CreateOrder>, string>;
|
|
23
|
-
getOrders<T extends boolean>(matched: T,
|
|
23
|
+
getOrders<T extends boolean>(matched: T, filters: {
|
|
24
|
+
address?: string;
|
|
25
|
+
tx_hash?: string;
|
|
26
|
+
fromChain?: Chain;
|
|
27
|
+
toChain?: Chain;
|
|
28
|
+
status?: OrderStatus;
|
|
29
|
+
[key: string]: string | undefined;
|
|
30
|
+
}, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
24
31
|
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
32
|
getOrdersCount(address: string, request?: UtilsRequest): AsyncResult<number, string>;
|
|
26
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIResponse, AsyncResult, IAuth, IStore } from '@gardenfi/utils';
|
|
1
|
+
import { APIResponse, AsyncResult, IAuth, IStore, Request as UtilsRequest } from '@gardenfi/utils';
|
|
2
2
|
import { Asset, Chain } from '../asset';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -114,14 +114,19 @@ export interface IOrderbook {
|
|
|
114
114
|
/**
|
|
115
115
|
* Get all orders from the orderbook based on the match status.
|
|
116
116
|
* @param matched - If true, returns matched orders, else returns unmatched orders.
|
|
117
|
+
* @param filters - Object containing filter parameters like: `address`, `tx_hash`, `fromChain`, `toChain`, `status` and any additional key-value pairs for query parameters.
|
|
117
118
|
* @param paginationConfig - The configuration for the pagination.
|
|
118
|
-
* @param
|
|
119
|
-
* @param tx_hash - The tx hash to get the orders for (initiate_tx_hash, redeem_tx_hash, refund_tx_hash).
|
|
120
|
-
* @param fromChain - The source chain to filter orders by.
|
|
121
|
-
* @param toChain - The destination chain to filter orders by.
|
|
119
|
+
* @param request - Optional request configuration.
|
|
122
120
|
* @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>} A promise that resolves to the orders.
|
|
123
121
|
*/
|
|
124
|
-
getOrders<T extends boolean>(matched: T,
|
|
122
|
+
getOrders<T extends boolean>(matched: T, filters: {
|
|
123
|
+
address?: string;
|
|
124
|
+
tx_hash?: string;
|
|
125
|
+
fromChain?: Chain;
|
|
126
|
+
toChain?: Chain;
|
|
127
|
+
status?: OrderStatus;
|
|
128
|
+
[key: string]: string | undefined;
|
|
129
|
+
}, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
125
130
|
/**
|
|
126
131
|
* Polls for every provided interval and returns matched and unmatched orders associated on the account.
|
|
127
132
|
* @param account The account to subscribe to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/orderbook",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.6",
|
|
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.
|
|
30
|
+
"@gardenfi/utils": "2.4.6",
|
|
31
31
|
"bufferutil": "^4.0.8",
|
|
32
32
|
"siwe": "^2.1.4",
|
|
33
33
|
"utf-8-validate": "^6.0.3",
|