@gardenfi/orderbook 0.1.11 → 0.2.0-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.
Files changed (49) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +15 -17
  3. package/dist/index2.cjs +1 -1
  4. package/dist/index2.js +124 -86
  5. package/dist/index3.cjs +1 -1
  6. package/dist/index3.js +14 -22
  7. package/dist/index4.cjs +1 -1
  8. package/dist/index4.js +81 -160
  9. package/dist/index5.cjs +1 -1
  10. package/dist/index5.js +58 -6
  11. package/dist/index6.cjs +1 -1
  12. package/dist/index6.js +11 -3
  13. package/dist/index7.cjs +1 -1
  14. package/dist/index7.js +2 -50
  15. package/dist/index8.cjs +1 -1
  16. package/dist/index8.js +6 -65
  17. package/dist/src/index.d.ts +7 -7
  18. package/dist/src/lib/asset.d.ts +32 -108
  19. package/dist/src/lib/constants.d.ts +8 -0
  20. package/dist/src/lib/errors.d.ts +4 -2
  21. package/dist/src/lib/orderbook/orderbook.d.ts +44 -0
  22. package/dist/src/lib/orderbook/orderbook.types.d.ts +200 -0
  23. package/dist/src/lib/orders/orders.types.d.ts +60 -0
  24. package/dist/src/lib/orders/ordersProvider.d.ts +15 -0
  25. package/dist/src/lib/utils.d.ts +10 -11
  26. package/package.json +19 -18
  27. package/dist/index10.cjs +0 -1
  28. package/dist/index10.js +0 -4
  29. package/dist/index11.cjs +0 -1
  30. package/dist/index11.js +0 -17
  31. package/dist/index12.cjs +0 -1
  32. package/dist/index12.js +0 -18
  33. package/dist/index9.cjs +0 -1
  34. package/dist/index9.js +0 -11
  35. package/dist/src/lib/auth/auth.interface.d.ts +0 -4
  36. package/dist/src/lib/auth/siwe.d.ts +0 -16
  37. package/dist/src/lib/orderbook.d.ts +0 -38
  38. package/dist/src/lib/orderbook.types.d.ts +0 -178
  39. package/dist/src/lib/orderpair.d.ts +0 -5
  40. package/dist/src/lib/ordersSocket.d.ts +0 -9
  41. package/dist/src/lib/pws/index.d.ts +0 -3
  42. package/dist/src/lib/pws/interface.d.ts +0 -79
  43. package/dist/src/lib/pws/service.d.ts +0 -33
  44. package/dist/src/lib/pws/utils.d.ts +0 -7
  45. package/dist/src/lib/store/memoryStorage.d.ts +0 -14
  46. package/dist/src/lib/store/store.interface.d.ts +0 -33
  47. package/dist/src/lib/testUtils.d.ts +0 -1
  48. package/dist/src/lib/url/Url.d.ts +0 -5
  49. package/dist/src/lib/url/index.d.ts +0 -1
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index2.cjs"),e=require("./index3.cjs"),r=require("./index4.cjs"),i=require("./index5.cjs"),s=require("./index6.cjs");exports.Orderbook=a.Orderbook;exports.chainToId=e.chainToId;exports.idToChain=e.idToChain;exports.orderPairGenerator=e.orderPairGenerator;exports.Assets=r.Assets;exports.Chains=r.Chains;exports.ChainsData=r.ChainsData;exports.isMainnet=r.isMainnet;exports.Actions=i.Actions;exports.parseStatus=i.parseStatus;exports.MAINNET_ORDERBOOK_API=s.MAINNET_ORDERBOOK_API;exports.TESTNET_ORDERBOOK_API=s.TESTNET_ORDERBOOK_API;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index2.cjs"),t=require("./index3.cjs"),s=require("./index4.cjs"),e=require("./index5.cjs");exports.Orderbook=r.Orderbook;exports.Chains=t.Chains;exports.isBitcoin=t.isBitcoin;exports.isEVM=t.isEVM;exports.isMainnet=t.isMainnet;exports.OrdersProvider=s.OrdersProvider;exports.ArbitrumLocalnet=e.ArbitrumLocalnet;exports.EthereumLocalnet=e.EthereumLocalnet;exports.WBTCArbitrumLocalnetAsset=e.WBTCArbitrumLocalnetAsset;exports.WBTCEthereumLocalnetAsset=e.WBTCEthereumLocalnetAsset;exports.bitcoinRegtestAsset=e.bitcoinRegtestAsset;
package/dist/index.js CHANGED
@@ -1,19 +1,17 @@
1
- import { Orderbook as e } from "./index2.js";
2
- import { chainToId as a, idToChain as i, orderPairGenerator as s } from "./index3.js";
3
- import { Assets as O, Chains as p, ChainsData as T, isMainnet as f } from "./index4.js";
4
- import { Actions as x, parseStatus as A } from "./index5.js";
5
- import { MAINNET_ORDERBOOK_API as d, TESTNET_ORDERBOOK_API as h } from "./index6.js";
1
+ import { Orderbook as t } from "./index2.js";
2
+ import { Chains as i, isBitcoin as s, isEVM as n, isMainnet as m } from "./index3.js";
3
+ import { OrdersProvider as c } from "./index4.js";
4
+ import { ArbitrumLocalnet as b, EthereumLocalnet as f, WBTCArbitrumLocalnetAsset as l, WBTCEthereumLocalnetAsset as p, bitcoinRegtestAsset as u } from "./index5.js";
6
5
  export {
7
- x as Actions,
8
- O as Assets,
9
- p as Chains,
10
- T as ChainsData,
11
- d as MAINNET_ORDERBOOK_API,
12
- e as Orderbook,
13
- h as TESTNET_ORDERBOOK_API,
14
- a as chainToId,
15
- i as idToChain,
16
- f as isMainnet,
17
- s as orderPairGenerator,
18
- A as parseStatus
6
+ b as ArbitrumLocalnet,
7
+ i as Chains,
8
+ f as EthereumLocalnet,
9
+ t as Orderbook,
10
+ c as OrdersProvider,
11
+ l as WBTCArbitrumLocalnetAsset,
12
+ p as WBTCEthereumLocalnetAsset,
13
+ u as bitcoinRegtestAsset,
14
+ s as isBitcoin,
15
+ n as isEVM,
16
+ m as isMainnet
19
17
  };
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),d=require("./index7.cjs"),i=require("./index8.cjs"),N=require("./index3.cjs"),o=require("./index9.cjs"),y=require("./index10.cjs"),h=require("./index11.cjs"),p=require("./index6.cjs"),l=require("./index12.cjs");class u{constructor(e){var t;this.supportedContracts={},this.url=new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),this.orderSocket=new d.OrdersSocket(this.url.socket()),this.auth=new i.Siwe(this.url,e.signer,{...e.opts,store:((t=e.opts)==null?void 0:t.store)||new h.MemoryStorage})}static async init(e){var c;const s=await new i.Siwe(new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),e.signer,e.opts).getToken(),r=((c=e.opts)==null?void 0:c.store)??new h.MemoryStorage;return e.opts={...e.opts,store:r},r.setItem(y.StoreKeys.AUTH_TOKEN,s),new u(e)}async getSupportedContracts(){if(Object.keys(this.supportedContracts).length>0)return this.supportedContracts;const e=this.url.endpoint("assets"),t=await n.Fetcher.get(e),s={};for(const r in t)s[r]=t[r][0];return this.supportedContracts=s,s}async getOrder(e){const t=this.url.endpoint(`orders/${e}`);return n.Fetcher.get(t)}async createOrder(e){const{sendAmount:t,secretHash:s,receiveAmount:r,fromAsset:c,toAsset:w,...a}=e;this.validateConfig(e);const O=await this.getSupportedContracts(),A=N.orderPairGenerator(c,w,O),S=this.url.endpoint("orders"),{orderId:m}=await n.Fetcher.post(S,{body:JSON.stringify({...a,sendAmount:t,receiveAmount:r,secretHash:n.trim0x(s),orderPair:A,userWalletBTCAddress:a.btcInputAddress}),headers:{Authorization:await this.auth.getToken()}});return m}async getOrders(e,t){const s=await n.Fetcher.get(this.url+"orders?"+new URLSearchParams({...t!=null&&t.taker?{taker:e}:{maker:e},verbose:t!=null&&t.verbose?"true":"false",...t!=null&&t.pending?{status:"2"}:{}}));return t!=null&&t.verbose,s}subscribeOrders(e,t){this.orderSocket.subscribe(e,t)}unsubscribeOrders(){this.orderSocket.unsubscribe()}validateConfig(e){const{sendAmount:t,receiveAmount:s}=e,r=+t,c=+s;if(isNaN(r)||r<=0||t.includes("."))throw new Error(o.OrderbookErrors.INVALID_SEND_AMOUNT);if(isNaN(c)||c<=0||s.includes("."))throw new Error(o.OrderbookErrors.INVALID_RECEIVE_AMOUNT)}}exports.Orderbook=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@catalogfi/utils"),c=require("./index6.cjs"),h=require("./index7.cjs"),u=require("@gardenfi/utils"),f=require("./index4.cjs"),O=require("./index3.cjs");class A extends f.OrdersProvider{constructor(r){var s;const t=new u.Url("/relayer",r.url??h.MAINNET_ORDERBOOK_API);super(t),this.Url=t,this.walletClient=r.walletClient,this.auth=new u.Siwe(this.Url,r.walletClient,{...r.opts,store:((s=r.opts)==null?void 0:s.store)||new u.MemoryStorage})}static async init(r){return await new u.Siwe(new u.Url("/relayer",r.url??h.MAINNET_ORDERBOOK_API),r.walletClient,r.opts).getToken(),new A(r)}async createOrder(r){const{sendAmount:t,secretHash:s,receiveAmount:n,fromAsset:i,toAsset:a,receiveAddress:o,sendAddress:_,minDestinationConfirmations:w=0,timelock:p,btcInputAddress:m}=r,E=this.validateConfig(r);if(E.error)return e.Err(E.error);const l=await this.auth.getToken();if(l.error)return e.Err(l.error);const S={additional_data:{bitcoin_optional_recipient:m??""}},I={nonce:r.nonce,source_amount:t,destination_amount:n,source_asset:i.atomicSwapAddress,destination_asset:a.atomicSwapAddress,secret_hash:e.trim0x(s),source_chain:i.chain,destination_chain:a.chain,initiator_source_address:_,initiator_destination_address:o,min_destination_confirmations:w,timelock:p,...S,fee:"1"};try{const d=await e.Fetcher.post(this.Url.endpoint("create-order"),{body:JSON.stringify(I),headers:{Authorization:u.Authorization(l.val),"Content-Type":"application/json"}});return d.error?e.Err(d.error):d.result?e.Ok(d.result):e.Err("CreateOrder: Unexpected error, result is undefined")}catch(d){return e.Err("CreateOrder:",String(d))}}async fetchOrders(r,t=!1,s){var i;const n=(i=this.walletClient.account)==null?void 0:i.address;return n?r?await super.getMatchedOrders(n,t,s):await super.getUnMatchedOrders(n,s):e.Err("Wallet client does not have an account")}async subscribeToOrders(r,t,s,n,i){var o;const a=(o=this.walletClient.account)==null?void 0:o.address;return a?await super.subscribeOrders(a,r,t,s,n,i):()=>{}}async getUserOrdersCount(){var t;const r=(t=this.walletClient.account)==null?void 0:t.address;return r?super.getOrdersCount(r):e.Err("Wallet client does not have an account")}validateConfig(r){const{sendAmount:t,receiveAmount:s,toAsset:n,fromAsset:i}=r;if(n.atomicSwapAddress.toLowerCase()===i.atomicSwapAddress.toLowerCase()&&n.chain===i.chain)return e.Err(c.OrderbookErrors.SAME_ASSET);if(!O.isBitcoin(n.chain)&&!n.atomicSwapAddress||!O.isBitcoin(i.chain)&&!i.atomicSwapAddress)return e.Err(c.OrderbookErrors.INVALID_AS_ADDRESS);if(!n.tokenAddress||!i.tokenAddress)return e.Err(c.OrderbookErrors.INVALID_TOKEN);const a=BigInt(t),o=BigInt(s);return t==null||a<=0n||t.includes(".")?e.Err(c.OrderbookErrors.INVALID_SEND_AMOUNT):s==null||o<=0n||s.includes(".")?e.Err(c.OrderbookErrors.INVALID_RECEIVE_AMOUNT):a<o?e.Err(c.OrderbookErrors.RECEIVE_AMOUNT_GREATER):e.Ok(e.Void)}}exports.Orderbook=A;
package/dist/index2.js CHANGED
@@ -1,107 +1,145 @@
1
- import { Fetcher as n, trim0x as S } from "@catalogfi/utils";
2
- import { OrdersSocket as d } from "./index7.js";
3
- import { Siwe as u } from "./index8.js";
4
- import { orderPairGenerator as y } from "./index3.js";
5
- import { OrderbookErrors as i } from "./index9.js";
6
- import { StoreKeys as E } from "./index10.js";
7
- import { MemoryStorage as o } from "./index11.js";
8
- import { MAINNET_ORDERBOOK_API as p } from "./index6.js";
9
- import { Url as h } from "./index12.js";
10
- class m {
1
+ import { Err as r, trim0x as y, Fetcher as D, Ok as A, Void as T } from "@catalogfi/utils";
2
+ import { OrderbookErrors as c } from "./index6.js";
3
+ import { MAINNET_ORDERBOOK_API as h } from "./index7.js";
4
+ import { Url as m, Siwe as p, MemoryStorage as U, Authorization as v } from "@gardenfi/utils";
5
+ import { OrdersProvider as C } from "./index4.js";
6
+ import { isBitcoin as _ } from "./index3.js";
7
+ class w extends C {
11
8
  /**
12
- * Creates an instance of Orderbook. Does not login to the orderbook backend
9
+ * Creates an instance of Orderbook. Does not login to the orderbook.
13
10
  * @constructor
14
11
  * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
15
- *
16
12
  */
17
- constructor(s) {
18
- var t;
19
- this.supportedContracts = {}, this.url = new h("/", s.url ?? p), this.orderSocket = new d(this.url.socket()), this.auth = new u(this.url, s.signer, {
20
- ...s.opts,
21
- store: ((t = s.opts) == null ? void 0 : t.store) || new o()
13
+ constructor(t) {
14
+ var s;
15
+ const e = new m(
16
+ "/relayer",
17
+ t.url ?? h
18
+ );
19
+ super(e), this.Url = e, this.walletClient = t.walletClient, this.auth = new p(this.Url, t.walletClient, {
20
+ ...t.opts,
21
+ store: ((s = t.opts) == null ? void 0 : s.store) || new U()
22
22
  });
23
23
  }
24
24
  /**
25
- * Initializes the orderbook as well as logs in the orderbook and stores the auth token in the store.
26
- *
25
+ * Initializes the orderbook as well as logs in the orderbook (fetches the auth token).
27
26
  * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
28
27
  */
29
- static async init(s) {
30
- var a;
31
- const e = await new u(
32
- new h("/", s.url ?? p),
33
- s.signer,
34
- s.opts
35
- ).getToken(), r = ((a = s.opts) == null ? void 0 : a.store) ?? new o();
36
- return s.opts = {
37
- ...s.opts,
38
- store: r
39
- }, r.setItem(E.AUTH_TOKEN, e), new m(s);
28
+ static async init(t) {
29
+ return await new p(
30
+ new m("/relayer", t.url ?? h),
31
+ t.walletClient,
32
+ t.opts
33
+ ).getToken(), new w(t);
40
34
  }
41
35
  /**
42
- * Returns the supported contracts from the orderbook.
36
+ * Creates an order
37
+ * @param {CreateOrderConfig} createOrderConfig - The configuration for the creating the order.
38
+ * @returns {string} The create order ID.
43
39
  */
44
- async getSupportedContracts() {
45
- if (Object.keys(this.supportedContracts).length > 0)
46
- return this.supportedContracts;
47
- const s = this.url.endpoint("assets"), t = await n.get(s), e = {};
48
- for (const r in t)
49
- e[r] = t[r][0];
50
- return this.supportedContracts = e, e;
51
- }
52
- async getOrder(s) {
53
- const t = this.url.endpoint(`orders/${s}`);
54
- return n.get(t);
55
- }
56
- async createOrder(s) {
40
+ async createOrder(t) {
57
41
  const {
58
- sendAmount: t,
59
- secretHash: e,
60
- receiveAmount: r,
61
- fromAsset: a,
62
- toAsset: l,
63
- ...c
64
- } = s;
65
- this.validateConfig(s);
66
- const w = await this.getSupportedContracts(), A = y(a, l, w), O = this.url.endpoint("orders"), { orderId: N } = await n.post(O, {
67
- body: JSON.stringify({
68
- ...c,
69
- sendAmount: t,
70
- receiveAmount: r,
71
- secretHash: S(e),
72
- orderPair: A,
73
- userWalletBTCAddress: c.btcInputAddress
74
- }),
75
- headers: {
76
- Authorization: await this.auth.getToken()
77
- }
78
- });
79
- return N;
42
+ sendAmount: e,
43
+ secretHash: s,
44
+ receiveAmount: n,
45
+ fromAsset: i,
46
+ toAsset: a,
47
+ receiveAddress: o,
48
+ sendAddress: f,
49
+ minDestinationConfirmations: O = 0,
50
+ timelock: S,
51
+ btcInputAddress: E
52
+ } = t, l = this.validateConfig(t);
53
+ if (l.error) return r(l.error);
54
+ const u = await this.auth.getToken();
55
+ if (u.error) return r(u.error);
56
+ const I = {
57
+ additional_data: { bitcoin_optional_recipient: E ?? "" }
58
+ }, N = {
59
+ nonce: t.nonce,
60
+ source_amount: e,
61
+ destination_amount: n,
62
+ source_asset: i.atomicSwapAddress,
63
+ destination_asset: a.atomicSwapAddress,
64
+ secret_hash: y(s),
65
+ source_chain: i.chain,
66
+ destination_chain: a.chain,
67
+ initiator_source_address: f,
68
+ initiator_destination_address: o,
69
+ min_destination_confirmations: O,
70
+ timelock: S,
71
+ ...I,
72
+ //signature:''
73
+ fee: "1"
74
+ };
75
+ try {
76
+ const d = await D.post(
77
+ this.Url.endpoint("create-order"),
78
+ {
79
+ body: JSON.stringify(N),
80
+ headers: {
81
+ Authorization: v(u.val),
82
+ "Content-Type": "application/json"
83
+ }
84
+ }
85
+ );
86
+ return d.error ? r(d.error) : d.result ? A(d.result) : r("CreateOrder: Unexpected error, result is undefined");
87
+ } catch (d) {
88
+ return r("CreateOrder:", String(d));
89
+ }
80
90
  }
81
- async getOrders(s, t) {
82
- const e = await n.get(
83
- this.url + "orders?" + new URLSearchParams({
84
- ...t != null && t.taker ? { taker: s } : { maker: s },
85
- verbose: t != null && t.verbose ? "true" : "false",
86
- ...t != null && t.pending ? { status: "2" } : {}
87
- })
88
- );
89
- return t != null && t.verbose, e;
91
+ async fetchOrders(t, e = !1, s) {
92
+ var i;
93
+ const n = (i = this.walletClient.account) == null ? void 0 : i.address;
94
+ return n ? t ? await super.getMatchedOrders(
95
+ n,
96
+ e,
97
+ s
98
+ ) : await super.getUnMatchedOrders(
99
+ n,
100
+ s
101
+ ) : r("Wallet client does not have an account");
90
102
  }
91
- subscribeOrders(s, t) {
92
- this.orderSocket.subscribe(s, t);
103
+ /**
104
+ * Wrapper for the subscribeOrders method in the OrdersProvider class to abstract the address parameter.
105
+ * @param matched - Whether to get matched or unmatched orders
106
+ * @param interval - The interval to poll for updates
107
+ * @param cb - The callback to be called when the orders are updated
108
+ * @param paginationConfig - The configuration for the pagination
109
+ * @returns {() => void} A function to unsubscribe from the order updates
110
+ */
111
+ async subscribeToOrders(t, e, s, n, i) {
112
+ var o;
113
+ const a = (o = this.walletClient.account) == null ? void 0 : o.address;
114
+ return a ? await super.subscribeOrders(
115
+ a,
116
+ t,
117
+ e,
118
+ s,
119
+ n,
120
+ i
121
+ ) : () => {
122
+ };
93
123
  }
94
- unsubscribeOrders() {
95
- this.orderSocket.unsubscribe();
124
+ async getUserOrdersCount() {
125
+ var e;
126
+ const t = (e = this.walletClient.account) == null ? void 0 : e.address;
127
+ return t ? super.getOrdersCount(t) : r("Wallet client does not have an account");
96
128
  }
97
- validateConfig(s) {
98
- const { sendAmount: t, receiveAmount: e } = s, r = +t, a = +e;
99
- if (isNaN(r) || r <= 0 || t.includes("."))
100
- throw new Error(i.INVALID_SEND_AMOUNT);
101
- if (isNaN(a) || a <= 0 || e.includes("."))
102
- throw new Error(i.INVALID_RECEIVE_AMOUNT);
129
+ validateConfig(t) {
130
+ const { sendAmount: e, receiveAmount: s, toAsset: n, fromAsset: i } = t;
131
+ if (n.atomicSwapAddress.toLowerCase() === i.atomicSwapAddress.toLowerCase() && n.chain === i.chain)
132
+ return r(c.SAME_ASSET);
133
+ if (!_(n.chain) && !n.atomicSwapAddress)
134
+ return r(c.INVALID_AS_ADDRESS);
135
+ if (!_(i.chain) && !i.atomicSwapAddress)
136
+ return r(c.INVALID_AS_ADDRESS);
137
+ if (!n.tokenAddress || !i.tokenAddress)
138
+ return r(c.INVALID_TOKEN);
139
+ const a = BigInt(e), o = BigInt(s);
140
+ return e == null || a <= 0n || e.includes(".") ? r(c.INVALID_SEND_AMOUNT) : s == null || o <= 0n || s.includes(".") ? r(c.INVALID_RECEIVE_AMOUNT) : a < o ? r(c.RECEIVE_AMOUNT_GREATER) : A(T);
103
141
  }
104
142
  }
105
143
  export {
106
- m as Orderbook
144
+ w as Orderbook
107
145
  };
package/dist/index3.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index4.cjs"),t=require("./index9.cjs"),o=(e,r,i)=>{if(!i[e.chain]||!i[r.chain]){let a=t.OrderbookErrors.UNSUPPORTED_CHAIN+": ";throw a+="only "+Object.keys(i).join(", ")+" are supported",new Error(a)}if(e.chain===r.chain)throw new Error(t.OrderpairErrors.SAME_ASSET);return e.chain===n.Chains.bitcoin||e.chain===n.Chains.bitcoin_testnet||e.chain===n.Chains.bitcoin_regtest?`${n.Chains[e.chain]}-${n.Chains[r.chain]}:${i[r.chain]}`:`${n.Chains[e.chain]}:${i[e.chain]}-${n.Chains[r.chain]}`},h={ethereum:1,ethereum_sepolia:11155111,ethereum_arbitrum:42161,ethereum_arbitrumlocalnet:31338,ethereum_localnet:31337},c=Object.entries(h).reduce((e,[r,i])=>(e[i]=r,e),{});exports.chainToId=h;exports.idToChain=c;exports.orderPairGenerator=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum:"ethereum",ethereum_arbitrum:"ethereum_arbitrum",ethereum_sepolia:"ethereum_sepolia",arbitrum_localnet:"arbitrum_localnet",ethereum_localnet:"ethereum_localnet"},r=e=>!(e===t.ethereum_sepolia||e===t.bitcoin_testnet||e===t.bitcoin_regtest||e===t.arbitrum_localnet||e===t.ethereum_localnet),i=e=>e===t.bitcoin||e===t.bitcoin_testnet||e===t.bitcoin_regtest,o=e=>e===t.ethereum||e===t.ethereum_arbitrum||e===t.ethereum_sepolia||e===t.ethereum_localnet||e===t.arbitrum_localnet;exports.Chains=t;exports.isBitcoin=i;exports.isEVM=o;exports.isMainnet=r;
package/dist/index3.js CHANGED
@@ -1,24 +1,16 @@
1
- import { Chains as n } from "./index4.js";
2
- import { OrderpairErrors as h, OrderbookErrors as a } from "./index9.js";
3
- const b = (e, r, i) => {
4
- if (!i[e.chain] || !i[r.chain]) {
5
- let t = a.UNSUPPORTED_CHAIN + ": ";
6
- throw t += "only " + Object.keys(i).join(", ") + " are supported", new Error(t);
7
- }
8
- if (e.chain === r.chain)
9
- throw new Error(h.SAME_ASSET);
10
- return e.chain === n.bitcoin || e.chain === n.bitcoin_testnet || e.chain === n.bitcoin_regtest ? `${n[e.chain]}-${n[r.chain]}:${i[r.chain]}` : `${n[e.chain]}:${i[e.chain]}-${n[r.chain]}`;
11
- }, c = {
12
- ethereum: 1,
13
- ethereum_sepolia: 11155111,
14
- ethereum_arbitrum: 42161,
15
- ethereum_arbitrumlocalnet: 31338,
16
- ethereum_localnet: 31337
17
- }, l = Object.entries(
18
- c
19
- ).reduce((e, [r, i]) => (e[i] = r, e), {});
1
+ const t = {
2
+ bitcoin: "bitcoin",
3
+ bitcoin_testnet: "bitcoin_testnet",
4
+ bitcoin_regtest: "bitcoin_regtest",
5
+ ethereum: "ethereum",
6
+ ethereum_arbitrum: "ethereum_arbitrum",
7
+ ethereum_sepolia: "ethereum_sepolia",
8
+ arbitrum_localnet: "arbitrum_localnet",
9
+ ethereum_localnet: "ethereum_localnet"
10
+ }, r = (e) => !(e === t.ethereum_sepolia || e === t.bitcoin_testnet || e === t.bitcoin_regtest || e === t.arbitrum_localnet || e === t.ethereum_localnet), i = (e) => e === t.bitcoin || e === t.bitcoin_testnet || e === t.bitcoin_regtest, o = (e) => e === t.ethereum || e === t.ethereum_arbitrum || e === t.ethereum_sepolia || e === t.ethereum_localnet || e === t.arbitrum_localnet;
20
11
  export {
21
- c as chainToId,
22
- l as idToChain,
23
- b as orderPairGenerator
12
+ t as Chains,
13
+ i as isBitcoin,
14
+ o as isEVM,
15
+ r as isMainnet
24
16
  };
package/dist/index4.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={ethereum_sepolia:"ethereum_sepolia",ethereum:"ethereum",bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum_arbitrum:"ethereum_arbitrum",ethereum_arbitrumlocalnet:"ethereum_arbitrumlocalnet",ethereum_localnet:"ethereum_localnet"},o={ethereum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",address:"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"}},ethereum_sepolia:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_sepolia,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0xaD9d14CA82d9BF97fFf745fFC7d48172A1c0969E"}},ethereum_arbitrumlocalnet:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_arbitrumlocalnet,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"}},ethereum_localnet:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_localnet,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0x5FbDB2315678afecb367f032d93F642f64180aa3"}},bitcoin:{BTC:{name:"Bitcoin",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin,isToken:!1}},bitcoin_testnet:{BTC:{name:"Bitcoin Testnet",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin_testnet,isToken:!1}},bitcoin_regtest:{BTC:{name:"Bitcoin Regtest",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin_regtest,isToken:!1}},ethereum_arbitrum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_arbitrum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",address:"0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"}}},s={bitcoin:{nativeAsset:o.bitcoin.BTC},bitcoin_testnet:{nativeAsset:o.bitcoin_testnet.BTC},bitcoin_regtest:{nativeAsset:{name:"Bitcoin Regtest",symbol:"rBTC",decimals:8,chain:e.bitcoin_regtest,isToken:!1,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg"}},ethereum:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}},ethereum_sepolia:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_sepolia,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}},ethereum_arbitrum:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_arbitrum,isToken:!1,thumbnail:"https://cryptologos.cc/logos/arbitrum-arb-logo.svg"}},ethereum_arbitrumlocalnet:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_arbitrumlocalnet,isToken:!1,thumbnail:"https://cryptologos.cc/logos/arbitrum-arb-logo.svg"}},ethereum_localnet:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_localnet,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}}},i=t=>!(t===e.ethereum_sepolia||t===e.bitcoin_testnet||t===e.bitcoin_regtest||t===e.ethereum_arbitrumlocalnet||t===e.ethereum_localnet);exports.Assets=o;exports.Chains=e;exports.ChainsData=s;exports.isMainnet=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@catalogfi/utils"),l=require("@gardenfi/utils"),d=require("./index8.cjs");class O{constructor(s){this.url=new l.Url("/orders",s)}async getOrder(s,c){const t=c?`/id/matched/${s}`:`/id/unmatched/${s}`,n=this.url.endpoint(t);try{const e=await r.Fetcher.get(n);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,c,t){const n=d.ConstructUrl(this.url,`/user/matched/${s}`,{...t,pending:c});try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetMatchedOrders:",String(e))}}async getUnMatchedOrders(s,c){const t=d.ConstructUrl(this.url,`/user/unmatched/${s}`,c);try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(n){return r.Err("GetUnMatchedOrders:",String(n))}}async getOrders(s,c){const t=s?"/matched":"/unmatched",n=d.ConstructUrl(this.url,t,c);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetAllOrders:",String(e))}}async subscribeOrders(s,c,t,n,e=!1,i){let o=!1;const a=async()=>{if(!o){o=!0;try{const u=c?await this.getMatchedOrders(s,e,i):await this.getUnMatchedOrders(s,i);u.ok?await n(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{o=!1}}};await a();const h=setInterval(a,t);return()=>{clearInterval(h)}}async getOrdersCount(s){const c=this.url.endpoint(`/user/count/${s}`);try{const t=await r.Fetcher.get(c);return t.error?r.Err(t.error):t.status===l.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.OrdersProvider=O;
package/dist/index4.js CHANGED
@@ -1,169 +1,90 @@
1
- const e = {
2
- ethereum_sepolia: "ethereum_sepolia",
3
- ethereum: "ethereum",
4
- bitcoin: "bitcoin",
5
- bitcoin_testnet: "bitcoin_testnet",
6
- bitcoin_regtest: "bitcoin_regtest",
7
- ethereum_arbitrum: "ethereum_arbitrum",
8
- ethereum_arbitrumlocalnet: "ethereum_arbitrumlocalnet",
9
- ethereum_localnet: "ethereum_localnet"
10
- }, o = {
11
- ethereum: {
12
- WBTC: {
13
- name: "Wrapped Bitcoin",
14
- symbol: "WBTC",
15
- decimals: 8,
16
- chain: e.ethereum,
17
- isToken: !0,
18
- thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",
19
- address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
20
- }
21
- },
22
- ethereum_sepolia: {
23
- WBTC: {
24
- name: "Wrapped Bitcoin",
25
- symbol: "WBTC",
26
- decimals: 8,
27
- chain: e.ethereum_sepolia,
28
- isToken: !0,
29
- thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
30
- address: "0xaD9d14CA82d9BF97fFf745fFC7d48172A1c0969E"
31
- }
32
- },
33
- ethereum_arbitrumlocalnet: {
34
- WBTC: {
35
- name: "Wrapped Bitcoin",
36
- symbol: "WBTC",
37
- decimals: 8,
38
- chain: e.ethereum_arbitrumlocalnet,
39
- isToken: !0,
40
- thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
41
- address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
42
- }
43
- },
44
- ethereum_localnet: {
45
- WBTC: {
46
- name: "Wrapped Bitcoin",
47
- symbol: "WBTC",
48
- decimals: 8,
49
- chain: e.ethereum_localnet,
50
- isToken: !0,
51
- thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
52
- address: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
53
- }
54
- },
55
- bitcoin: {
56
- BTC: {
57
- name: "Bitcoin",
58
- symbol: "BTC",
59
- decimals: 8,
60
- thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
61
- chain: e.bitcoin,
62
- isToken: !1
63
- }
64
- },
65
- bitcoin_testnet: {
66
- BTC: {
67
- name: "Bitcoin Testnet",
68
- symbol: "BTC",
69
- decimals: 8,
70
- thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
71
- chain: e.bitcoin_testnet,
72
- isToken: !1
73
- }
74
- },
75
- bitcoin_regtest: {
76
- BTC: {
77
- name: "Bitcoin Regtest",
78
- symbol: "BTC",
79
- decimals: 8,
80
- thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
81
- chain: e.bitcoin_regtest,
82
- isToken: !1
83
- }
84
- },
85
- ethereum_arbitrum: {
86
- WBTC: {
87
- name: "Wrapped Bitcoin",
88
- symbol: "WBTC",
89
- decimals: 8,
90
- chain: e.ethereum_arbitrum,
91
- isToken: !0,
92
- thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
93
- address: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
94
- }
1
+ import { Fetcher as u, Err as s, Ok as d } from "@catalogfi/utils";
2
+ import { Url as f, ApiStatus as g } from "@gardenfi/utils";
3
+ import { ConstructUrl as i } from "./index8.js";
4
+ class w {
5
+ constructor(t) {
6
+ this.url = new f("/orders", t);
95
7
  }
96
- }, s = {
97
- bitcoin: {
98
- nativeAsset: o.bitcoin.BTC
99
- },
100
- bitcoin_testnet: {
101
- nativeAsset: o.bitcoin_testnet.BTC
102
- },
103
- bitcoin_regtest: {
104
- nativeAsset: {
105
- name: "Bitcoin Regtest",
106
- symbol: "rBTC",
107
- decimals: 8,
108
- chain: e.bitcoin_regtest,
109
- isToken: !1,
110
- thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg"
111
- }
112
- },
113
- ethereum: {
114
- nativeAsset: {
115
- name: "Ethereum",
116
- symbol: "ETH",
117
- decimals: 18,
118
- chain: e.ethereum,
119
- isToken: !1,
120
- thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg"
8
+ async getOrder(t, o) {
9
+ const e = o ? `/id/matched/${t}` : `/id/unmatched/${t}`, n = this.url.endpoint(e);
10
+ try {
11
+ const r = await u.get(n);
12
+ return r.error ? s(r.error) : r.result ? d(r.result) : s("GetOrder: Unexpected error, result is undefined");
13
+ } catch (r) {
14
+ return s("GetOrder:", String(r));
121
15
  }
122
- },
123
- ethereum_sepolia: {
124
- nativeAsset: {
125
- name: "Ethereum",
126
- symbol: "ETH",
127
- decimals: 18,
128
- chain: e.ethereum_sepolia,
129
- isToken: !1,
130
- thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg"
16
+ }
17
+ async getMatchedOrders(t, o, e) {
18
+ const n = i(this.url, `/user/matched/${t}`, {
19
+ ...e,
20
+ pending: o
21
+ });
22
+ try {
23
+ const r = await u.get(
24
+ n
25
+ );
26
+ return r.error ? s(r.error) : r.result ? d(r.result) : s("GetMatchedOrders: Unexpected error, result is undefined");
27
+ } catch (r) {
28
+ return s("GetMatchedOrders:", String(r));
131
29
  }
132
- },
133
- ethereum_arbitrum: {
134
- nativeAsset: {
135
- name: "Ethereum",
136
- symbol: "ETH",
137
- decimals: 18,
138
- chain: e.ethereum_arbitrum,
139
- isToken: !1,
140
- thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg"
30
+ }
31
+ async getUnMatchedOrders(t, o) {
32
+ const e = i(
33
+ this.url,
34
+ `/user/unmatched/${t}`,
35
+ o
36
+ );
37
+ try {
38
+ const n = await u.get(
39
+ e
40
+ );
41
+ return n.error ? s(n.error) : n.result ? d(n.result) : s("GetUnMatchedOrders: Unexpected error, result is undefined");
42
+ } catch (n) {
43
+ return s("GetUnMatchedOrders:", String(n));
141
44
  }
142
- },
143
- ethereum_arbitrumlocalnet: {
144
- nativeAsset: {
145
- name: "Ethereum",
146
- symbol: "ETH",
147
- decimals: 18,
148
- chain: e.ethereum_arbitrumlocalnet,
149
- isToken: !1,
150
- thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg"
45
+ }
46
+ async getOrders(t, o) {
47
+ const e = t ? "/matched" : "/unmatched", n = i(this.url, e, o);
48
+ try {
49
+ const r = await u.get(n);
50
+ return r.error ? s(r.error) : r.result ? d(r.result) : s("GetAllOrders: Unexpected error, result is undefined");
51
+ } catch (r) {
52
+ return s("GetAllOrders:", String(r));
151
53
  }
152
- },
153
- ethereum_localnet: {
154
- nativeAsset: {
155
- name: "Ethereum",
156
- symbol: "ETH",
157
- decimals: 18,
158
- chain: e.ethereum_localnet,
159
- isToken: !1,
160
- thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg"
54
+ }
55
+ async subscribeOrders(t, o, e, n, r = !1, l) {
56
+ let a = !1;
57
+ const h = async () => {
58
+ if (!a) {
59
+ a = !0;
60
+ try {
61
+ const c = o ? await this.getMatchedOrders(t, r, l) : await this.getUnMatchedOrders(t, l);
62
+ c.ok ? await n(
63
+ c.val
64
+ ) : console.error("Error fetching orders:", c.error);
65
+ } catch (c) {
66
+ console.error("Error fetching orders:", c);
67
+ } finally {
68
+ a = !1;
69
+ }
70
+ }
71
+ };
72
+ await h();
73
+ const O = setInterval(h, e);
74
+ return () => {
75
+ clearInterval(O);
76
+ };
77
+ }
78
+ async getOrdersCount(t) {
79
+ const o = this.url.endpoint(`/user/count/${t}`);
80
+ try {
81
+ const e = await u.get(o);
82
+ return e.error ? s(e.error) : e.status === g.Ok && e.result !== void 0 ? d(e.result) : s("GetOrdersCount: Unexpected error, result is undefined");
83
+ } catch (e) {
84
+ return s("GetOrdersCount:", String(e));
161
85
  }
162
86
  }
163
- }, i = (t) => !(t === e.ethereum_sepolia || t === e.bitcoin_testnet || t === e.bitcoin_regtest || t === e.ethereum_arbitrumlocalnet || t === e.ethereum_localnet);
87
+ }
164
88
  export {
165
- o as Assets,
166
- e as Chains,
167
- s as ChainsData,
168
- i as isMainnet
89
+ w as OrdersProvider
169
90
  };
package/dist/index5.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=e=>{const t=e.status*100+e.initiatorAtomicSwap.swapStatus*10+e.followerAtomicSwap.swapStatus;return t===200?"user can initiate":t===222?"user can redeem":/\d3\d/.test(`${t}`)?"user can refund":t===220?"counterparty can initiate":t===224||t===226?"counterparty can redeem":/\d\d3/.test(`${t}`)?"counterparty can refund":"no action can be performed"};var r=(e=>(e.UserCanInitiate="user can initiate",e.UserCanRedeem="user can redeem",e.UserCanRefund="user can refund",e.CounterpartyCanInitiate="counterparty can initiate",e.CounterpartyCanRedeem="counterparty can redeem",e.CounterpartyCanRefund="counterparty can refund",e.NoAction="no action can be performed",e))(r||{});exports.Actions=r;exports.parseStatus=n;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index3.cjs"),t={id:31338,name:"Arbitrum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8546/"]}},testnet:!0},s={id:31337,name:"Ethereum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8545/"]}},testnet:!0},a={name:"Bitcoin Regtest",decimals:8,symbol:"BTC",chain:e.Chains.bitcoin_regtest,atomicSwapAddress:"primary",tokenAddress:"primary",isToken:!0},r={name:"WBTC Arbitrum Localnet",decimals:8,symbol:"WBTC",chain:e.Chains.arbitrum_localnet,atomicSwapAddress:"0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",tokenAddress:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",isToken:!0},n={name:"WBTC Ethereum Localnet",decimals:8,symbol:"WBTC",chain:e.Chains.ethereum_localnet,atomicSwapAddress:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",tokenAddress:"0x5FbDB2315678afecb367f032d93F642f64180aa3",isToken:!0};exports.ArbitrumLocalnet=t;exports.EthereumLocalnet=s;exports.WBTCArbitrumLocalnetAsset=r;exports.WBTCEthereumLocalnetAsset=n;exports.bitcoinRegtestAsset=a;