@gardenfi/orderbook 0.1.11 → 0.2.0-beta.0
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/index.cjs +1 -1
- package/dist/index.js +15 -17
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +124 -86
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +14 -22
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +81 -160
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +58 -6
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +11 -3
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +2 -50
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +6 -65
- package/dist/src/index.d.ts +7 -7
- package/dist/src/lib/asset.d.ts +32 -108
- package/dist/src/lib/constants.d.ts +8 -0
- package/dist/src/lib/errors.d.ts +4 -2
- package/dist/src/lib/orderbook/orderbook.d.ts +44 -0
- package/dist/src/lib/orderbook/orderbook.types.d.ts +200 -0
- package/dist/src/lib/orders/orders.types.d.ts +60 -0
- package/dist/src/lib/orders/ordersProvider.d.ts +15 -0
- package/dist/src/lib/utils.d.ts +10 -11
- package/package.json +20 -19
- package/dist/index10.cjs +0 -1
- package/dist/index10.js +0 -4
- package/dist/index11.cjs +0 -1
- package/dist/index11.js +0 -17
- package/dist/index12.cjs +0 -1
- package/dist/index12.js +0 -18
- package/dist/index9.cjs +0 -1
- package/dist/index9.js +0 -11
- package/dist/src/lib/auth/auth.interface.d.ts +0 -4
- package/dist/src/lib/auth/siwe.d.ts +0 -16
- package/dist/src/lib/orderbook.d.ts +0 -38
- package/dist/src/lib/orderbook.types.d.ts +0 -178
- package/dist/src/lib/orderpair.d.ts +0 -5
- package/dist/src/lib/ordersSocket.d.ts +0 -9
- package/dist/src/lib/pws/index.d.ts +0 -3
- package/dist/src/lib/pws/interface.d.ts +0 -79
- package/dist/src/lib/pws/service.d.ts +0 -33
- package/dist/src/lib/pws/utils.d.ts +0 -7
- package/dist/src/lib/store/memoryStorage.d.ts +0 -14
- package/dist/src/lib/store/store.interface.d.ts +0 -33
- package/dist/src/lib/testUtils.d.ts +0 -1
- package/dist/src/lib/url/Url.d.ts +0 -5
- 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
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
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
|
|
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(
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
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(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
*
|
|
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
|
|
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:
|
|
59
|
-
secretHash:
|
|
60
|
-
receiveAmount:
|
|
61
|
-
fromAsset:
|
|
62
|
-
toAsset:
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
)
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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
|
-
|
|
95
|
-
|
|
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(
|
|
98
|
-
const { sendAmount:
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
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
|
-
|
|
144
|
+
w as Orderbook
|
|
107
145
|
};
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
}
|
|
87
|
+
}
|
|
164
88
|
export {
|
|
165
|
-
|
|
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
|
|
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;
|