@gardenfi/orderbook 2.4.2-beta.2 → 2.4.3-beta.1
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"),h=require("./index5.cjs");class O{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=h.ConstructUrl(this.Url,`/user/${s}/matched`,{...t,status:n});try{const c=await r.Fetcher.get(e);return c.error?r.Err(c.error):c.result?r.Ok(c.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(c){return r.Err("GetMatchedOrders:",String(c))}}async getUnMatchedOrders(s,n){const t=h.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,c,i,a){const l=s?"/matched":"/unmatched",o={};n&&(o.page=n.page,o.per_page=n.per_page),t&&(o.address=t),e&&(o.tx_hash=e),c&&(o.from_chain=c),i&&(o.to_chain=i),a&&(o.status=a);const u=h.ConstructUrl(this.Url,l,o);try{const d=await r.Fetcher.get(u);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,n,t,e,c="all",i){let a=!1;const l=async()=>{if(!a){a=!0;try{const u=n?await this.getMatchedOrders(s,c,i):await this.getUnMatchedOrders(s,i);u.ok?await e(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{a=!1}}};await l();const o=setInterval(l,t);return()=>{clearInterval(o)}}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=O;
|
package/dist/index2.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Err as t, Fetcher as
|
|
2
|
-
import { ConstructUrl as
|
|
3
|
-
class
|
|
1
|
+
import { Err as t, Fetcher as i, Ok as l, ApiStatus as g } from "@gardenfi/utils";
|
|
2
|
+
import { ConstructUrl as O } from "./index5.js";
|
|
3
|
+
class m {
|
|
4
4
|
constructor(s) {
|
|
5
5
|
this.Url = s;
|
|
6
6
|
}
|
|
@@ -15,14 +15,14 @@ class U {
|
|
|
15
15
|
if (e.error)
|
|
16
16
|
return t(e.error);
|
|
17
17
|
try {
|
|
18
|
-
const r = await
|
|
18
|
+
const r = await i.post(this.Url, {
|
|
19
19
|
body: JSON.stringify(s),
|
|
20
20
|
headers: {
|
|
21
21
|
...e.val,
|
|
22
22
|
"Content-Type": "application/json"
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
return r.error ? t(r.error) : r.result ?
|
|
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
|
}
|
|
@@ -32,85 +32,85 @@ class U {
|
|
|
32
32
|
n ? `/id/${s}/matched` : `/id/${s}/unmatched`
|
|
33
33
|
);
|
|
34
34
|
try {
|
|
35
|
-
const r = await
|
|
36
|
-
return r.error ? t(r.error) : r.result ?
|
|
35
|
+
const r = await i.get(e);
|
|
36
|
+
return r.error ? t(r.error) : r.result ? l(r.result) : t("GetOrder: Unexpected error, result is undefined");
|
|
37
37
|
} catch (r) {
|
|
38
38
|
return t("GetOrder:", String(r));
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
async getMatchedOrders(s, n, e) {
|
|
42
|
-
const r =
|
|
42
|
+
const r = O(this.Url, `/user/${s}/matched`, {
|
|
43
43
|
...e,
|
|
44
44
|
status: n
|
|
45
45
|
});
|
|
46
46
|
try {
|
|
47
|
-
const
|
|
47
|
+
const c = await i.get(
|
|
48
48
|
r
|
|
49
49
|
);
|
|
50
|
-
return
|
|
51
|
-
} catch (
|
|
52
|
-
return t("GetMatchedOrders:", String(
|
|
50
|
+
return c.error ? t(c.error) : c.result ? l(c.result) : t("GetMatchedOrders: Unexpected error, result is undefined");
|
|
51
|
+
} catch (c) {
|
|
52
|
+
return t("GetMatchedOrders:", String(c));
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
async getUnMatchedOrders(s, n) {
|
|
56
|
-
const e =
|
|
56
|
+
const e = O(
|
|
57
57
|
this.Url,
|
|
58
58
|
`/user/${s}/unmatched`,
|
|
59
59
|
n
|
|
60
60
|
);
|
|
61
61
|
try {
|
|
62
|
-
const r = await
|
|
62
|
+
const r = await i.get(
|
|
63
63
|
e
|
|
64
64
|
);
|
|
65
|
-
return r.error ? t(r.error) : r.result ?
|
|
65
|
+
return r.error ? t(r.error) : r.result ? l(r.result) : t("GetUnMatchedOrders: Unexpected error, result is undefined");
|
|
66
66
|
} catch (r) {
|
|
67
67
|
return t("GetUnMatchedOrders:", String(r));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
async getOrders(s, n, e, r,
|
|
71
|
-
const
|
|
72
|
-
n && (
|
|
73
|
-
const
|
|
70
|
+
async getOrders(s, n, e, r, c, h, d) {
|
|
71
|
+
const f = s ? "/matched" : "/unmatched", o = {};
|
|
72
|
+
n && (o.page = n.page, o.per_page = n.per_page), e && (o.address = e), r && (o.tx_hash = r), c && (o.from_chain = c), h && (o.to_chain = h), d && (o.status = d);
|
|
73
|
+
const a = O(this.Url, f, o);
|
|
74
74
|
try {
|
|
75
|
-
const
|
|
76
|
-
return
|
|
77
|
-
} catch (
|
|
78
|
-
return t("GetAllOrders:", String(
|
|
75
|
+
const u = await i.get(a);
|
|
76
|
+
return u.error ? t(u.error) : u.result ? l(u.result) : t("GetAllOrders: Unexpected error, result is undefined");
|
|
77
|
+
} catch (u) {
|
|
78
|
+
return t("GetAllOrders:", String(u));
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
-
async subscribeOrders(s, n, e, r,
|
|
82
|
-
let
|
|
83
|
-
const
|
|
84
|
-
if (!
|
|
85
|
-
|
|
81
|
+
async subscribeOrders(s, n, e, r, c = "all", h) {
|
|
82
|
+
let d = !1;
|
|
83
|
+
const f = async () => {
|
|
84
|
+
if (!d) {
|
|
85
|
+
d = !0;
|
|
86
86
|
try {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
) : console.error("Error fetching orders:",
|
|
91
|
-
} catch (
|
|
92
|
-
console.error("Error fetching orders:",
|
|
87
|
+
const a = n ? await this.getMatchedOrders(s, c, h) : await this.getUnMatchedOrders(s, h);
|
|
88
|
+
a.ok ? await r(
|
|
89
|
+
a.val
|
|
90
|
+
) : console.error("Error fetching orders:", a.error);
|
|
91
|
+
} catch (a) {
|
|
92
|
+
console.error("Error fetching orders:", a);
|
|
93
93
|
} finally {
|
|
94
|
-
|
|
94
|
+
d = !1;
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
|
-
await
|
|
99
|
-
const
|
|
98
|
+
await f();
|
|
99
|
+
const o = setInterval(f, e);
|
|
100
100
|
return () => {
|
|
101
|
-
clearInterval(
|
|
101
|
+
clearInterval(o);
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
104
|
async getOrdersCount(s) {
|
|
105
105
|
const n = this.Url.endpoint(`/user/${s}/count`);
|
|
106
106
|
try {
|
|
107
|
-
const e = await
|
|
108
|
-
return e.error ? t(e.error) : e.status ===
|
|
107
|
+
const e = await i.get(n);
|
|
108
|
+
return e.error ? t(e.error) : e.status === g.Ok && e.result !== void 0 ? l(e.result) : t("GetOrdersCount: Unexpected error, result is undefined");
|
|
109
109
|
} catch (e) {
|
|
110
110
|
return t("GetOrdersCount:", String(e));
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
export {
|
|
115
|
-
|
|
115
|
+
m as Orderbook
|
|
116
116
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateOrder, CreateOrderReqWithStrategyId, IOrderbook, MatchedOrder, PaginatedData, PaginationConfig, Status } from './orderbook.types';
|
|
1
|
+
import { CreateOrder, CreateOrderReqWithStrategyId, IOrderbook, MatchedOrder, OrderStatus, PaginatedData, PaginationConfig, Status } from './orderbook.types';
|
|
2
2
|
import { AsyncResult, IAuth, Url } from '@gardenfi/utils';
|
|
3
3
|
import { Chain } from '../asset';
|
|
4
4
|
|
|
@@ -20,7 +20,7 @@ export declare class Orderbook implements IOrderbook {
|
|
|
20
20
|
getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
|
|
21
21
|
getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
|
|
22
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>;
|
|
23
|
+
getOrders<T extends boolean>(matched: T, paginationConfig?: PaginationConfig, address?: string, tx_hash?: string, fromChain?: Chain, toChain?: Chain, status?: OrderStatus): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
24
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
25
|
getOrdersCount(address: string): 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.
|
|
3
|
+
"version": "2.4.3-beta.1",
|
|
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.3",
|
|
31
31
|
"bufferutil": "^4.0.8",
|
|
32
32
|
"siwe": "^2.1.4",
|
|
33
33
|
"utf-8-validate": "^6.0.3",
|