@gardenfi/orderbook 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @gardenfi/orderbook
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 75c5b0c: Go open source
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ ## @catalogfi/orderbook
2
+
3
+ The `@catalogfi/orderbook` package is used to facilitate the creation of orders. It also provides functionality for listening to orders and retrieving orders created by a specific address.
4
+
5
+ ### Installation
6
+
7
+ ```
8
+ npm install @catalogfi/orderbook
9
+ ```
10
+
11
+ ### Usage
12
+
13
+ 1. Creating an order: ([should create an order with the valid configuration](https://github.com/catalogfi/catalog.js-v2/blob/3019559e8857bf0b54b0c3affcdcad580b868947/packages/orderbook/src/lib/orderbook.spec.ts#L61))
14
+ 2. Getting all orders created by an address: ([should return orders where the user is the maker](https://github.com/catalogfi/catalog.js-v2/blob/3019559e8857bf0b54b0c3affcdcad580b868947/packages/orderbook/src/lib/orderbook.spec.ts#L79))
15
+ 3. Listening to orders: ([should update when order is created](https://github.com/catalogfi/catalog.js-v2/blob/3019559e8857bf0b54b0c3affcdcad580b868947/packages/orderbook/src/lib/orderbook.spec.ts#L94))
16
+
17
+ ### Setup
18
+
19
+ Both CommonJs and ES imports are supported so there is not extra setup needed to use the library. To use the orderbook simply import it (using import or require statements) and perform your logic. Make sure to use a signer if you're using the library in an environment where you do not have access to the private keys.
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./index2.cjs"),e=require("./index3.cjs"),r=require("./index4.cjs"),i=require("./index5.cjs"),s=require("./index6.cjs");exports.Orderbook=t.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.CONTRACT_ADDRESS=i.CONTRACT_ADDRESS;exports.Actions=s.Actions;exports.parseStatus=s.parseStatus;
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
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 p, Chains as f, ChainsData as m, isMainnet as x } from "./index4.js";
4
+ import { CONTRACT_ADDRESS as d } from "./index5.js";
5
+ import { Actions as A, parseStatus as T } from "./index6.js";
6
+ export {
7
+ A as Actions,
8
+ p as Assets,
9
+ d as CONTRACT_ADDRESS,
10
+ f as Chains,
11
+ m as ChainsData,
12
+ e as Orderbook,
13
+ a as chainToId,
14
+ i as idToChain,
15
+ x as isMainnet,
16
+ s as orderPairGenerator,
17
+ T as parseStatus
18
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.AUTH_TOKEN="auth_token",e))(t||{});exports.StoreKeys=t;
@@ -0,0 +1,4 @@
1
+ var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
2
+ export {
3
+ t as StoreKeys
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class r{constructor(){this.memory=new Map}getItem(e){return this.memory.has(e)?this.memory.get(e):null}setItem(e,t){this.memory.set(e,t)}removeItem(e){this.memory.has(e)&&this.memory.delete(e)}}exports.MemoryStorage=r;
@@ -0,0 +1,17 @@
1
+ class m {
2
+ constructor() {
3
+ this.memory = /* @__PURE__ */ new Map();
4
+ }
5
+ getItem(e) {
6
+ return this.memory.has(e) ? this.memory.get(e) : null;
7
+ }
8
+ setItem(e, t) {
9
+ this.memory.set(e, t);
10
+ }
11
+ removeItem(e) {
12
+ this.memory.has(e) && this.memory.delete(e);
13
+ }
14
+ }
15
+ export {
16
+ m as MemoryStorage
17
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="https://api.garden.finance";exports.API=e;
@@ -0,0 +1,4 @@
1
+ const n = "https://api.garden.finance";
2
+ export {
3
+ n as API
4
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@catalogfi/utils"),O=require("./index7.cjs"),n=require("./index8.cjs"),y=require("./index6.cjs"),N=require("./index3.cjs"),h=require("./index9.cjs"),I=require("./index10.cjs"),l=require("./index11.cjs"),p=require("./index12.cjs");class c{constructor(t){var s;this.url=y.parseURL(t.url??p.API),this.orderSocket=new O.OrdersSocket(this.url.replace("https","wss")),this.url+=this.url.endsWith("/")?"":"/",this.auth=new n.Siwe(this.url,t.signer,{...t.opts,store:((s=t.opts)==null?void 0:s.store)||new l.MemoryStorage})}static async init(t){var r;const e=await new n.Siwe(t.url??p.API,t.signer,t.opts).getToken();return t.opts={...t.opts,store:((r=t==null?void 0:t.opts)==null?void 0:r.store)??new l.MemoryStorage},t.opts.store.setItem(I.StoreKeys.AUTH_TOKEN,e),new c(t)}async createOrder(t){const{sendAmount:s,secretHash:e,receiveAmount:r,fromAsset:u,toAsset:w,...i}=t;this.validateConfig(t);const A=N.orderPairGenerator(u,w),m=this.url+"orders",{orderId:S}=await a.Fetcher.post(m,{body:JSON.stringify({...i,sendAmount:s,receiveAmount:r,secretHash:a.trim0x(e),orderPair:A,userWalletBTCAddress:i.btcInputAddress}),headers:{Authorization:await this.auth.getToken()}});return S}async getOrders(t,s){const e=await a.Fetcher.get(this.url+"orders?"+new URLSearchParams({...s!=null&&s.taker?{taker:t}:{maker:t},verbose:s!=null&&s.verbose?"true":"false",...s!=null&&s.pending?{status:"2"}:{}}));return s!=null&&s.verbose,e}subscribeOrders(t,s){this.orderSocket.subscribe(t,s)}unsubscribeOrders(){this.orderSocket.unsubscribe()}validateConfig(t){const{sendAmount:s,receiveAmount:e}=t,r=+s,u=+e;if(isNaN(r)||r<=0||s.includes("."))throw new Error(h.OrderbookErrors.INVALID_SEND_AMOUNT);if(isNaN(u)||u<=0||e.includes("."))throw new Error(h.OrderbookErrors.INVALID_RECEIVE_AMOUNT)}}exports.Orderbook=c;
package/dist/index2.js ADDED
@@ -0,0 +1,92 @@
1
+ import { Fetcher as c, trim0x as S } from "@catalogfi/utils";
2
+ import { OrdersSocket as I } from "./index7.js";
3
+ import { Siwe as m } from "./index8.js";
4
+ import { parseURL as O } from "./index6.js";
5
+ import { orderPairGenerator as E } from "./index3.js";
6
+ import { OrderbookErrors as h } from "./index9.js";
7
+ import { StoreKeys as T } from "./index10.js";
8
+ import { MemoryStorage as p } from "./index11.js";
9
+ import { API as i } from "./index12.js";
10
+ class n {
11
+ /**
12
+ * Creates an instance of Orderbook. Does not login to the orderbook backend
13
+ * @constructor
14
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
15
+ *
16
+ */
17
+ constructor(t) {
18
+ var s;
19
+ this.url = O(t.url ?? i), this.orderSocket = new I(this.url.replace("https", "wss")), this.url += this.url.endsWith("/") ? "" : "/", this.auth = new m(this.url, t.signer, {
20
+ ...t.opts,
21
+ store: ((s = t.opts) == null ? void 0 : s.store) || new p()
22
+ });
23
+ }
24
+ /**
25
+ * Initializes the orderbook as well as logs in the orderbook and stores the auth token in the store.
26
+ *
27
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
28
+ */
29
+ static async init(t) {
30
+ var r;
31
+ const e = await new m(
32
+ t.url ?? i,
33
+ t.signer,
34
+ t.opts
35
+ ).getToken();
36
+ return t.opts = {
37
+ ...t.opts,
38
+ store: ((r = t == null ? void 0 : t.opts) == null ? void 0 : r.store) ?? new p()
39
+ }, t.opts.store.setItem(T.AUTH_TOKEN, e), new n(t);
40
+ }
41
+ async createOrder(t) {
42
+ const {
43
+ sendAmount: s,
44
+ secretHash: e,
45
+ receiveAmount: r,
46
+ fromAsset: a,
47
+ toAsset: l,
48
+ ...u
49
+ } = t;
50
+ this.validateConfig(t);
51
+ const w = E(a, l), A = this.url + "orders", { orderId: N } = await c.post(A, {
52
+ body: JSON.stringify({
53
+ ...u,
54
+ sendAmount: s,
55
+ receiveAmount: r,
56
+ secretHash: S(e),
57
+ orderPair: w,
58
+ userWalletBTCAddress: u.btcInputAddress
59
+ }),
60
+ headers: {
61
+ Authorization: await this.auth.getToken()
62
+ }
63
+ });
64
+ return N;
65
+ }
66
+ async getOrders(t, s) {
67
+ const e = await c.get(
68
+ this.url + "orders?" + new URLSearchParams({
69
+ ...s != null && s.taker ? { taker: t } : { maker: t },
70
+ verbose: s != null && s.verbose ? "true" : "false",
71
+ ...s != null && s.pending ? { status: "2" } : {}
72
+ })
73
+ );
74
+ return s != null && s.verbose, e;
75
+ }
76
+ subscribeOrders(t, s) {
77
+ this.orderSocket.subscribe(t, s);
78
+ }
79
+ unsubscribeOrders() {
80
+ this.orderSocket.unsubscribe();
81
+ }
82
+ validateConfig(t) {
83
+ const { sendAmount: s, receiveAmount: e } = t, r = +s, a = +e;
84
+ if (isNaN(r) || r <= 0 || s.includes("."))
85
+ throw new Error(h.INVALID_SEND_AMOUNT);
86
+ if (isNaN(a) || a <= 0 || e.includes("."))
87
+ throw new Error(h.INVALID_RECEIVE_AMOUNT);
88
+ }
89
+ }
90
+ export {
91
+ n as Orderbook
92
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index4.cjs"),c=require("./index5.cjs"),o=require("./index9.cjs"),s=(i,e)=>{if(i.chain===e.chain)throw new Error(o.OrderpairErrors.SAME_ASSET);if(i.chain===n.Chains.bitcoin||i.chain===n.Chains.bitcoin_testnet||i.chain===n.Chains.bitcoin_regtest){const t=r[e.chain];return`${n.Chains[i.chain]}-${n.Chains[e.chain]}:${c.CONTRACT_ADDRESS[t].AtomicSwap}`}else{const t=r[i.chain];return`${n.Chains[i.chain]}:${c.CONTRACT_ADDRESS[t].AtomicSwap}-${n.Chains[e.chain]}`}},r={ethereum:1,ethereum_sepolia:11155111,ethereum_arbitrum:42161},h=Object.entries(r).reduce((i,[e,a])=>(i[a]=e,i),{});exports.chainToId=r;exports.idToChain=h;exports.orderPairGenerator=s;
package/dist/index3.js ADDED
@@ -0,0 +1,25 @@
1
+ import { Chains as n } from "./index4.js";
2
+ import { CONTRACT_ADDRESS as a } from "./index5.js";
3
+ import { OrderpairErrors as o } from "./index9.js";
4
+ const u = (i, r) => {
5
+ if (i.chain === r.chain)
6
+ throw new Error(o.SAME_ASSET);
7
+ if (i.chain === n.bitcoin || i.chain === n.bitcoin_testnet || i.chain === n.bitcoin_regtest) {
8
+ const t = e[r.chain];
9
+ return `${n[i.chain]}-${n[r.chain]}:${a[t].AtomicSwap}`;
10
+ } else {
11
+ const t = e[i.chain];
12
+ return `${n[i.chain]}:${a[t].AtomicSwap}-${n[r.chain]}`;
13
+ }
14
+ }, e = {
15
+ ethereum: 1,
16
+ ethereum_sepolia: 11155111,
17
+ ethereum_arbitrum: 42161
18
+ }, d = Object.entries(
19
+ e
20
+ ).reduce((i, [r, c]) => (i[c] = r, i), {});
21
+ export {
22
+ e as chainToId,
23
+ d as idToChain,
24
+ u as orderPairGenerator
25
+ };
@@ -0,0 +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"},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:"0x3D1e56247033FE191DC789b5838E366dC04b1b73"}},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}},ethereum_arbitrum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_arbitrum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",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"}}},i=t=>!(t===e.ethereum_sepolia||t===e.bitcoin_testnet||t===e.bitcoin_regtest);exports.Assets=o;exports.Chains=e;exports.ChainsData=s;exports.isMainnet=i;
package/dist/index4.js ADDED
@@ -0,0 +1,115 @@
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
+ }, o = {
9
+ ethereum: {
10
+ WBTC: {
11
+ name: "Wrapped Bitcoin",
12
+ symbol: "WBTC",
13
+ decimals: 8,
14
+ chain: e.ethereum,
15
+ isToken: !0,
16
+ thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",
17
+ address: "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"
18
+ }
19
+ },
20
+ ethereum_sepolia: {
21
+ WBTC: {
22
+ name: "Wrapped Bitcoin",
23
+ symbol: "WBTC",
24
+ decimals: 8,
25
+ chain: e.ethereum_sepolia,
26
+ isToken: !0,
27
+ thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
28
+ address: "0x3D1e56247033FE191DC789b5838E366dC04b1b73"
29
+ }
30
+ },
31
+ bitcoin: {
32
+ BTC: {
33
+ name: "Bitcoin",
34
+ symbol: "BTC",
35
+ decimals: 8,
36
+ thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
37
+ chain: e.bitcoin,
38
+ isToken: !1
39
+ }
40
+ },
41
+ bitcoin_testnet: {
42
+ BTC: {
43
+ name: "Bitcoin Testnet",
44
+ symbol: "BTC",
45
+ decimals: 8,
46
+ thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg",
47
+ chain: e.bitcoin_testnet,
48
+ isToken: !1
49
+ }
50
+ },
51
+ ethereum_arbitrum: {
52
+ WBTC: {
53
+ name: "Wrapped Bitcoin",
54
+ symbol: "WBTC",
55
+ decimals: 8,
56
+ chain: e.ethereum_arbitrum,
57
+ isToken: !0,
58
+ thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",
59
+ address: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
60
+ }
61
+ }
62
+ }, i = {
63
+ bitcoin: {
64
+ nativeAsset: o.bitcoin.BTC
65
+ },
66
+ bitcoin_testnet: {
67
+ nativeAsset: o.bitcoin_testnet.BTC
68
+ },
69
+ bitcoin_regtest: {
70
+ nativeAsset: {
71
+ name: "Bitcoin Regtest",
72
+ symbol: "rBTC",
73
+ decimals: 8,
74
+ chain: e.bitcoin_regtest,
75
+ isToken: !1,
76
+ thumbnail: "https://cryptologos.cc/logos/bitcoin-btc-logo.svg"
77
+ }
78
+ },
79
+ ethereum: {
80
+ nativeAsset: {
81
+ name: "Ethereum",
82
+ symbol: "ETH",
83
+ decimals: 18,
84
+ chain: e.ethereum,
85
+ isToken: !1,
86
+ thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg"
87
+ }
88
+ },
89
+ ethereum_sepolia: {
90
+ nativeAsset: {
91
+ name: "Ethereum",
92
+ symbol: "ETH",
93
+ decimals: 18,
94
+ chain: e.ethereum_sepolia,
95
+ isToken: !1,
96
+ thumbnail: "https://cryptologos.cc/logos/ethereum-eth-logo.svg"
97
+ }
98
+ },
99
+ ethereum_arbitrum: {
100
+ nativeAsset: {
101
+ name: "Ethereum",
102
+ symbol: "ETH",
103
+ decimals: 18,
104
+ chain: e.ethereum_arbitrum,
105
+ isToken: !1,
106
+ thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg"
107
+ }
108
+ }
109
+ }, s = (t) => !(t === e.ethereum_sepolia || t === e.bitcoin_testnet || t === e.bitcoin_regtest);
110
+ export {
111
+ o as Assets,
112
+ e as Chains,
113
+ i as ChainsData,
114
+ s as isMainnet
115
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A={1:{AtomicSwap:"0xA5E38d098b54C00F10e32E51647086232a9A0afD"},11155111:{AtomicSwap:"0x130Ff59B75a415d0bcCc2e996acAf27ce70fD5eF"},42161:{AtomicSwap:"0x203DAC25763aE783Ad532A035FfF33d8df9437eE"}};exports.CONTRACT_ADDRESS=A;
package/dist/index5.js ADDED
@@ -0,0 +1,14 @@
1
+ const A = {
2
+ 1: {
3
+ AtomicSwap: "0xA5E38d098b54C00F10e32E51647086232a9A0afD"
4
+ },
5
+ 11155111: {
6
+ AtomicSwap: "0x130Ff59B75a415d0bcCc2e996acAf27ce70fD5eF"
7
+ },
8
+ 42161: {
9
+ AtomicSwap: "0x203DAC25763aE783Ad532A035FfF33d8df9437eE"
10
+ }
11
+ };
12
+ export {
13
+ A as CONTRACT_ADDRESS
14
+ };
@@ -0,0 +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"},a=e=>(e.startsWith("https://")||(e="https://"+e),e+=e.endsWith("/")?"":"/",e);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;exports.parseURL=a;
package/dist/index6.js ADDED
@@ -0,0 +1,10 @@
1
+ const n = (e) => {
2
+ const t = e.status * 100 + e.initiatorAtomicSwap.swapStatus * 10 + e.followerAtomicSwap.swapStatus;
3
+ 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";
4
+ }, a = (e) => (e.startsWith("https://") || (e = "https://" + e), e += e.endsWith("/") ? "" : "/", e);
5
+ var r = /* @__PURE__ */ ((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 || {});
6
+ export {
7
+ r as Actions,
8
+ n as parseStatus,
9
+ a as parseURL
10
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),k=require("ws"),i=typeof window<"u"&&window.WebSocket||typeof global<"u"&&global.WebSocket||typeof WebSocket<"u"&&WebSocket||k.WebSocket,o={OpenOrder:"rest.OpenOrder",UpdatedOrders:"rest.UpdatedOrders",UpdatedOrder:"rest.UpdatedOrder",WebsocketError:"rest.WebsocketError",Ping:"ping"},r=3001;class l{constructor(e){this.unsubscribe=()=>{var s;return(s=this.socket)==null?void 0:s.close()},this.url=e}subscribe(e,s){this.socket=new u(this.url),this.socket.onMsg((d,t)=>{t.type===o.UpdatedOrders?s(t.msg.orders):t.type===o.UpdatedOrder?s([t.msg.order]):t.type===o.WebsocketError&&d.close(r)}),this.socket.send("subscribe::"+e),this.socket.onClose(()=>{this.subscribe(e,s)})}}class u{constructor(e){this.socket=new i(e)}onMsg(e){this.socket.onmessage=s=>{this.pingTimeout&&clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{this.socket.close(r)},65e3),e(this,n.safeParseJson(s.data))}}onClose(e){this.socket.onclose=s=>{s.code===r&&e(s.reason)}}send(e){this.socket.readyState===i.OPEN?this.socket.send(e):this.socket.onopen=()=>{this.socket.send(e)}}close(e){clearTimeout(this.pingTimeout),this.socket.close(e)}}exports.OrdersSocket=l;
package/dist/index7.js ADDED
@@ -0,0 +1,52 @@
1
+ import { safeParseJson as n } from "@catalogfi/utils";
2
+ import { WebSocket as k } from "ws";
3
+ const i = typeof window < "u" && window.WebSocket || typeof global < "u" && global.WebSocket || typeof WebSocket < "u" && WebSocket || k, o = {
4
+ OpenOrder: "rest.OpenOrder",
5
+ UpdatedOrders: "rest.UpdatedOrders",
6
+ UpdatedOrder: "rest.UpdatedOrder",
7
+ WebsocketError: "rest.WebsocketError",
8
+ Ping: "ping"
9
+ }, r = 3001;
10
+ class a {
11
+ constructor(e) {
12
+ this.unsubscribe = () => {
13
+ var s;
14
+ return (s = this.socket) == null ? void 0 : s.close();
15
+ }, this.url = e;
16
+ }
17
+ subscribe(e, s) {
18
+ this.socket = new p(this.url), this.socket.onMsg((d, t) => {
19
+ t.type === o.UpdatedOrders ? s(t.msg.orders) : t.type === o.UpdatedOrder ? s([t.msg.order]) : t.type === o.WebsocketError && d.close(r);
20
+ }), this.socket.send("subscribe::" + e), this.socket.onClose(() => {
21
+ this.subscribe(e, s);
22
+ });
23
+ }
24
+ }
25
+ class p {
26
+ constructor(e) {
27
+ this.socket = new i(e);
28
+ }
29
+ onMsg(e) {
30
+ this.socket.onmessage = (s) => {
31
+ this.pingTimeout && clearTimeout(this.pingTimeout), this.pingTimeout = setTimeout(() => {
32
+ this.socket.close(r);
33
+ }, 65e3), e(this, n(s.data));
34
+ };
35
+ }
36
+ onClose(e) {
37
+ this.socket.onclose = (s) => {
38
+ s.code === r && e(s.reason);
39
+ };
40
+ }
41
+ send(e) {
42
+ this.socket.readyState === i.OPEN ? this.socket.send(e) : this.socket.onopen = () => {
43
+ this.socket.send(e);
44
+ };
45
+ }
46
+ close(e) {
47
+ clearTimeout(this.pingTimeout), this.socket.close(e);
48
+ }
49
+ }
50
+ export {
51
+ a as OrdersSocket
52
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("siwe"),a=require("@catalogfi/utils"),o=require("./index10.cjs"),h=require("./index11.cjs"),u=require("./index6.cjs"),m=require("./index12.cjs");class d{constructor(t,i,e){this.signingStatement="I'm signing in to Catalog",this.url=u.parseURL(t??m.API),this.signer=i,this.domain=(e==null?void 0:e.domain)||"catalog.fi",this.domain.startsWith("https://")&&(this.domain=this.domain.split("https://")[1]),this.store=(e==null?void 0:e.store)??new h.MemoryStorage}verifyToken(t,i){const e=w(t);if(!e)return!1;try{const r=Math.floor(Date.now()/1e3)+120;return e.exp>r&&e.userWallet.toLowerCase()===i.toLowerCase()}catch{return!1}}async getToken(){const t=this.store.getItem(o.StoreKeys.AUTH_TOKEN);if(t&&this.verifyToken(t,this.signer.address))return t;const{message:i,signature:e}=await this.signStatement(),{token:r}=await a.Fetcher.post(this.url+"verify",{body:JSON.stringify({message:i,signature:e})});if(!this.verifyToken(r,await this.signer.getAddress()))throw new Error("Token verification failed");return this.store.setItem(o.StoreKeys.AUTH_TOKEN,r),r}async signStatement(){if(!this.signer.provider)throw new Error("signer does not have a provider");const t=new Date,i=new Date(t.getTime()+300*1e3),{nonce:e}=await a.Fetcher.get(this.url+"nonce"),r=await this.signer.provider.getNetwork(),n=new c.SiweMessage({domain:this.domain,address:await this.signer.getAddress(),statement:this.signingStatement,nonce:e,uri:"https://"+this.domain,version:"1",chainId:+r.chainId.toString(),expirationTime:i.toISOString()}).prepareMessage(),g=await this.signer.signMessage(n);return{message:n,signature:g}}}const w=s=>{try{if(s.split(".").length<3)return;const t=s.split(".")[1];return t?JSON.parse(Buffer.from(t,"base64").toString("latin1")):void 0}catch{return}};exports.Siwe=d;
package/dist/index8.js ADDED
@@ -0,0 +1,70 @@
1
+ import { SiweMessage as h } from "siwe";
2
+ import { Fetcher as a } from "@catalogfi/utils";
3
+ import { StoreKeys as o } from "./index10.js";
4
+ import { MemoryStorage as m } from "./index11.js";
5
+ import { parseURL as c } from "./index6.js";
6
+ import { API as d } from "./index12.js";
7
+ class v {
8
+ constructor(e, i, t) {
9
+ this.signingStatement = "I'm signing in to Catalog", this.url = c(e ?? d), this.signer = i, this.domain = (t == null ? void 0 : t.domain) || "catalog.fi", this.domain.startsWith("https://") && (this.domain = this.domain.split("https://")[1]), this.store = (t == null ? void 0 : t.store) ?? new m();
10
+ }
11
+ verifyToken(e, i) {
12
+ const t = f(e);
13
+ if (!t)
14
+ return !1;
15
+ try {
16
+ const r = Math.floor(Date.now() / 1e3) + 120;
17
+ return t.exp > r && t.userWallet.toLowerCase() === i.toLowerCase();
18
+ } catch {
19
+ return !1;
20
+ }
21
+ }
22
+ async getToken() {
23
+ const e = this.store.getItem(o.AUTH_TOKEN);
24
+ if (e && this.verifyToken(e, this.signer.address))
25
+ return e;
26
+ const { message: i, signature: t } = await this.signStatement(), { token: r } = await a.post(
27
+ this.url + "verify",
28
+ {
29
+ body: JSON.stringify({
30
+ message: i,
31
+ signature: t
32
+ })
33
+ }
34
+ );
35
+ if (!this.verifyToken(r, await this.signer.getAddress()))
36
+ throw new Error("Token verification failed");
37
+ return this.store.setItem(o.AUTH_TOKEN, r), r;
38
+ }
39
+ async signStatement() {
40
+ if (!this.signer.provider)
41
+ throw new Error("signer does not have a provider");
42
+ const e = /* @__PURE__ */ new Date(), i = new Date(e.getTime() + 300 * 1e3), { nonce: t } = await a.get(this.url + "nonce"), r = await this.signer.provider.getNetwork(), n = new h({
43
+ domain: this.domain,
44
+ address: await this.signer.getAddress(),
45
+ statement: this.signingStatement,
46
+ nonce: t,
47
+ uri: "https://" + this.domain,
48
+ version: "1",
49
+ chainId: +r.chainId.toString(),
50
+ expirationTime: i.toISOString()
51
+ }).prepareMessage(), g = await this.signer.signMessage(n);
52
+ return {
53
+ message: n,
54
+ signature: g
55
+ };
56
+ }
57
+ }
58
+ const f = (s) => {
59
+ try {
60
+ if (s.split(".").length < 3)
61
+ return;
62
+ const e = s.split(".")[1];
63
+ return e ? JSON.parse(Buffer.from(e, "base64").toString("latin1")) : void 0;
64
+ } catch {
65
+ return;
66
+ }
67
+ };
68
+ export {
69
+ v as Siwe
70
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={INVALID_SEND_AMOUNT:"invalid send amount",INVALID_RECEIVE_AMOUNT:"invalid receive amount"},e={SAME_ASSET:"cannot create orderpair with the same assets"};exports.OrderbookErrors=r;exports.OrderpairErrors=e;
package/dist/index9.js ADDED
@@ -0,0 +1,10 @@
1
+ const r = {
2
+ INVALID_SEND_AMOUNT: "invalid send amount",
3
+ INVALID_RECEIVE_AMOUNT: "invalid receive amount"
4
+ }, e = {
5
+ SAME_ASSET: "cannot create orderpair with the same assets"
6
+ };
7
+ export {
8
+ r as OrderbookErrors,
9
+ e as OrderpairErrors
10
+ };
@@ -0,0 +1,7 @@
1
+ export { Orderbook } from './lib/orderbook';
2
+ export type { Order, Orders, AtomicSwap, IOrderbook, } from './lib/orderbook.types';
3
+ export { chainToId, idToChain, orderPairGenerator } from './lib/orderpair';
4
+ export type { Chain, EvmChain, Asset, ChainData } from './lib/asset';
5
+ export { Chains, Assets, ChainsData, isMainnet } from './lib/asset';
6
+ export { CONTRACT_ADDRESS } from './lib/contractAddress';
7
+ export { parseStatus, Actions } from './lib/utils';
@@ -0,0 +1 @@
1
+ export declare const API = "https://api.garden.finance";
@@ -0,0 +1,84 @@
1
+ export declare const Chains: {
2
+ readonly ethereum_sepolia: "ethereum_sepolia";
3
+ readonly ethereum: "ethereum";
4
+ readonly bitcoin: "bitcoin";
5
+ readonly bitcoin_testnet: "bitcoin_testnet";
6
+ readonly bitcoin_regtest: "bitcoin_regtest";
7
+ readonly ethereum_arbitrum: "ethereum_arbitrum";
8
+ };
9
+ export type Chain = keyof typeof Chains;
10
+ export type EvmChain = keyof Omit<typeof Chains, 'bitcoin' | 'bitcoin_testnet' | 'bitcoin_regtest'>;
11
+ export type AssetCommon = {
12
+ name: string;
13
+ symbol: string;
14
+ decimals: number;
15
+ chain: Chain;
16
+ isToken: boolean;
17
+ thumbnail: string;
18
+ };
19
+ export type AssetNative = AssetCommon;
20
+ export type AssetToken = AssetCommon & {
21
+ address: string;
22
+ isToken: true;
23
+ };
24
+ export type Asset = AssetToken | AssetNative;
25
+ export declare const Assets: {
26
+ ethereum: {
27
+ WBTC: {
28
+ name: string;
29
+ symbol: string;
30
+ decimals: number;
31
+ chain: "ethereum";
32
+ isToken: boolean;
33
+ thumbnail: string;
34
+ address: string;
35
+ };
36
+ };
37
+ ethereum_sepolia: {
38
+ WBTC: {
39
+ name: string;
40
+ symbol: string;
41
+ decimals: number;
42
+ chain: "ethereum_sepolia";
43
+ isToken: boolean;
44
+ thumbnail: string;
45
+ address: string;
46
+ };
47
+ };
48
+ bitcoin: {
49
+ BTC: {
50
+ name: string;
51
+ symbol: string;
52
+ decimals: number;
53
+ thumbnail: string;
54
+ chain: "bitcoin";
55
+ isToken: boolean;
56
+ };
57
+ };
58
+ bitcoin_testnet: {
59
+ BTC: {
60
+ name: string;
61
+ symbol: string;
62
+ decimals: number;
63
+ thumbnail: string;
64
+ chain: "bitcoin_testnet";
65
+ isToken: boolean;
66
+ };
67
+ };
68
+ ethereum_arbitrum: {
69
+ WBTC: {
70
+ name: string;
71
+ symbol: string;
72
+ decimals: number;
73
+ chain: "ethereum_arbitrum";
74
+ isToken: boolean;
75
+ thumbnail: string;
76
+ address: string;
77
+ };
78
+ };
79
+ };
80
+ export type ChainData = {
81
+ nativeAsset: Asset;
82
+ };
83
+ export declare const ChainsData: Record<Chain, ChainData>;
84
+ export declare const isMainnet: (chain: Chain) => boolean;
@@ -0,0 +1,4 @@
1
+ export interface IAuth {
2
+ getToken(): Promise<string>;
3
+ verifyToken(token: string, account: string): boolean;
4
+ }
@@ -0,0 +1,14 @@
1
+ import { JsonRpcSigner, Wallet } from 'ethers';
2
+ import { IAuth } from './auth.interface';
3
+ import { OrderbookOpts } from '../orderbook.types';
4
+ export declare class Siwe implements IAuth {
5
+ private readonly url;
6
+ private store;
7
+ private readonly signer;
8
+ private readonly signingStatement;
9
+ private readonly domain;
10
+ constructor(url: string, signer: JsonRpcSigner | Wallet, opts?: OrderbookOpts);
11
+ verifyToken(token: string, account: string): boolean;
12
+ getToken(): Promise<string>;
13
+ private signStatement;
14
+ }
@@ -0,0 +1,4 @@
1
+ export type ContractAddress = {
2
+ AtomicSwap: string;
3
+ };
4
+ export declare const CONTRACT_ADDRESS: Record<number, ContractAddress>;
@@ -0,0 +1,7 @@
1
+ export declare const OrderbookErrors: {
2
+ INVALID_SEND_AMOUNT: string;
3
+ INVALID_RECEIVE_AMOUNT: string;
4
+ };
5
+ export declare const OrderpairErrors: {
6
+ SAME_ASSET: string;
7
+ };
@@ -0,0 +1,30 @@
1
+ import { CreateOrderConfig, IOrderbook, Order, OrderConfig, OrderNonVerbose, OrderbookConfig } from './orderbook.types';
2
+ /**
3
+ * A class that allows you to create and manage orders with the backend url.
4
+ *
5
+ * @class
6
+ * @implements {IOrderbook}
7
+ */
8
+ export declare class Orderbook implements IOrderbook {
9
+ private orderSocket;
10
+ private url;
11
+ private auth;
12
+ /**
13
+ * Creates an instance of Orderbook. Does not login to the orderbook backend
14
+ * @constructor
15
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
16
+ *
17
+ */
18
+ constructor(orderbookConfig: OrderbookConfig);
19
+ /**
20
+ * Initializes the orderbook as well as logs in the orderbook and stores the auth token in the store.
21
+ *
22
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
23
+ */
24
+ static init(orderbookConfig: OrderbookConfig): Promise<Orderbook>;
25
+ createOrder(createOrderConfig: CreateOrderConfig): Promise<number>;
26
+ getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
27
+ subscribeOrders(account: string, cb: (orders: Order[]) => void): void;
28
+ unsubscribeOrders(): void;
29
+ private validateConfig;
30
+ }
@@ -0,0 +1,196 @@
1
+ import { MarkNonNullable } from '@catalogfi/utils';
2
+ import { Asset } from './asset';
3
+ import { JsonRpcSigner, Wallet } from 'ethers';
4
+ import { IStore } from './store/store.interface';
5
+ /**
6
+ * Type for the configuration of an Order.
7
+ *
8
+ * @typedef {Object} OrderConfig
9
+ *
10
+ * @template T extends boolean
11
+ *
12
+ * @property {T} verbose - Determines the verbosity of the order.
13
+ * @property {boolean} taker - True if the order is a taker order, false otherwise.
14
+ * @property {boolean} [pending] - True if the order is pending, false otherwise. Optional.
15
+ *
16
+ */
17
+ /**
18
+ * Configuration for the orders you want to receive
19
+ *
20
+ * @typeParam T - Determines the verbosity of the order.
21
+ */
22
+ export type OrderConfig<T extends boolean> = {
23
+ /**
24
+ * Determines the verbosity of the order.
25
+ */
26
+ verbose: T;
27
+ /**
28
+ * Set to true if the address should be a taker, else false if the address is the maker of the order.
29
+ */
30
+ taker: boolean;
31
+ /**
32
+ * Set to true if you want to receice pending orders
33
+ */
34
+ pending?: boolean;
35
+ };
36
+ /**
37
+ * Configuration for creating an order
38
+ *
39
+ */
40
+ export interface CreateOrderConfig {
41
+ /**
42
+ * The asset the user wants to send.
43
+ */
44
+ fromAsset: Asset;
45
+ /**
46
+ * The asset the user wants to receive.
47
+ */
48
+ toAsset: Asset;
49
+ /**
50
+ * The address from the which the user is sending funds from.
51
+ */
52
+ sendAddress: string;
53
+ /**
54
+ * The address at which the user wants to receive funds.
55
+ */
56
+ receiveAddress: string;
57
+ /**
58
+ * The input amount the user wants to send in it's lowest denomincation
59
+ */
60
+ sendAmount: string;
61
+ /**
62
+ * The amount you receive amount
63
+ */
64
+ receiveAmount: string;
65
+ /**
66
+ * The hash of the secret, which is the double hash of the signature
67
+ */
68
+ secretHash: string;
69
+ /**
70
+ * The funds are received at this address if specified, otherwise the funds are sent to the receive address.
71
+ */
72
+ btcInputAddress: string;
73
+ }
74
+ /**
75
+ * Additional configuration options for the orderbook
76
+ *
77
+ */
78
+ export type OrderbookOpts = {
79
+ /**
80
+ * The domain of your dApp. Optional.
81
+ */
82
+ domain?: string;
83
+ /**
84
+ * The store used for storing the auth token. Optional.
85
+ */
86
+ store?: IStore;
87
+ };
88
+ /**
89
+ * Interface for the configuration of an Orderbook.
90
+ *
91
+ */
92
+ export interface OrderbookConfig {
93
+ /**
94
+ *
95
+ */
96
+ url?: string;
97
+ /**
98
+ *
99
+ */
100
+ signer: JsonRpcSigner | Wallet;
101
+ /**
102
+ *
103
+ */
104
+ opts?: OrderbookOpts;
105
+ }
106
+ /**
107
+ * @interface IOrderbook
108
+ *
109
+ */
110
+ export interface IOrderbook {
111
+ /**
112
+ * Creates an order
113
+ * @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
114
+ * @returns {number} The order ID.
115
+ */
116
+ createOrder(orderConfig: CreateOrderConfig): Promise<number>;
117
+ /**
118
+ * Get orders based on the provided address and order configuration.
119
+ *
120
+ * @template {boolean} T
121
+ * @param {string} address - The address to get orders for.
122
+ * @param {Partial<OrderConfig<T>>} orderConfig - (Optional) The configuration for the orders.
123
+ * @returns {Promise<(T extends true ? Order : OrderNonVerbose)[]>} A promise that resolves to an array of orders.
124
+ */
125
+ getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
126
+ /**
127
+ *
128
+ *
129
+ * @param {string} account - The account to subscribe to. Currently each orderbook instance can connect with a single account.
130
+ * @param {(orders: Order[]) => void} cb - The callback to call when the orders are updated. The first response is all the orders created by this account.
131
+ * @returns {void}
132
+ */
133
+ subscribeOrders(account: string, cb: (orders: Order[]) => void): void;
134
+ /**
135
+ * Unsubscribes from order updates.
136
+ *
137
+ * @returns {void}
138
+ */
139
+ unsubscribeOrders(): void;
140
+ }
141
+ export type AtomicSwap = {
142
+ ID: number;
143
+ CreatedAt: string;
144
+ UpdatedAt: string;
145
+ DeletedAt: string;
146
+ swapStatus: number;
147
+ secret: string;
148
+ initiatorAddress: string;
149
+ redeemerAddress: string;
150
+ onChainIdentifier: string;
151
+ timelock: string;
152
+ chain: string;
153
+ asset: string;
154
+ currentConfirmation: number;
155
+ minimumConfirmations: number;
156
+ amount: string;
157
+ filledAmount: string;
158
+ priceByOracle: number;
159
+ initiateTxHash: string;
160
+ initiateBlockNumber: number;
161
+ redeemTxHash: string;
162
+ refundTxHash: string;
163
+ };
164
+ export type OrderNonVerbose = {
165
+ ID: number;
166
+ CreatedAt: string;
167
+ UpdatedAt: string;
168
+ DeletedAt: string;
169
+ maker: string;
170
+ taker: string;
171
+ orderPair: string;
172
+ InitiatorAtomicSwapID: number;
173
+ FollowerAtomicSwapID: number;
174
+ initiatorAtomicSwap: AtomicSwap | null;
175
+ followerAtomicSwap: AtomicSwap | null;
176
+ secretHash: string;
177
+ secret: string;
178
+ price: number;
179
+ status: number;
180
+ secretNonce: number;
181
+ userBtcWalletAddress: string;
182
+ RandomMultiplier: number;
183
+ RandomScore: number;
184
+ fee: number;
185
+ };
186
+ export type DecodedAuthToken = {
187
+ userWallet: string;
188
+ exp: number;
189
+ iat: number;
190
+ };
191
+ export type Order = MarkNonNullable<OrderNonVerbose, 'initiatorAtomicSwap' | 'followerAtomicSwap'>;
192
+ export type Orders = Order[];
193
+ export type GetOrdersOutput<T extends boolean> = (T extends true ? Order : OrderNonVerbose)[];
194
+ export type CreateOrderResponse = {
195
+ orderId: number;
196
+ };
@@ -0,0 +1,4 @@
1
+ import { Asset, EvmChain } from './asset';
2
+ export declare const orderPairGenerator: (from: Asset, to: Asset) => string;
3
+ export declare const chainToId: Record<EvmChain, number>;
4
+ export declare const idToChain: Record<number, EvmChain>;
@@ -0,0 +1,8 @@
1
+ import { Orders } from "./orderbook.types";
2
+ export declare class OrdersSocket {
3
+ private url;
4
+ private socket;
5
+ constructor(url: string);
6
+ subscribe(account: string, cb: (orders: Orders) => void): void;
7
+ unsubscribe: () => void | undefined;
8
+ }
@@ -0,0 +1,13 @@
1
+ import { IStore } from './store.interface';
2
+ /**
3
+ * In-memory storage implementation.
4
+ *
5
+ * @class
6
+ * @implements {IStore}
7
+ */
8
+ export declare class MemoryStorage implements IStore {
9
+ private memory;
10
+ getItem(key: string): string | null;
11
+ setItem(key: string, value: string): void;
12
+ removeItem(key: string): void;
13
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Interface for a Store.
3
+ *
4
+ * @interface IStore
5
+ *
6
+ */
7
+ export interface IStore {
8
+ /**
9
+ * Retrieves an item from the store using the provided key.
10
+ * @param {string} key - The key of the item to retrieve.
11
+ * @returns {string | number} The item associated with the key, or null if no item is found.
12
+ *
13
+ */
14
+ getItem(key: string): string | null;
15
+ /**
16
+ * @method setItem - Sets an item in the store with the provided key and value.
17
+ * @param {string} key - The key to associate with the item.
18
+ * @param {any} value - The value of the item to store.
19
+ * @returns {void}
20
+ *
21
+ */
22
+ setItem(key: string, value: any): void;
23
+ /**
24
+ * @method removeItem - Removes an item from the store using the provided key.
25
+ * @param {string} key - The key of the item to remove.
26
+ * @returns {void}
27
+ *
28
+ */
29
+ removeItem(key: string): void;
30
+ }
31
+ export declare enum StoreKeys {
32
+ AUTH_TOKEN = "auth_token"
33
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Order } from './orderbook.types';
2
+ export declare const parseStatus: (order: Order) => Actions;
3
+ export declare const parseURL: (url: string) => string;
4
+ export declare enum Actions {
5
+ UserCanInitiate = "user can initiate",
6
+ UserCanRedeem = "user can redeem",
7
+ UserCanRefund = "user can refund",
8
+ CounterpartyCanInitiate = "counterparty can initiate",
9
+ CounterpartyCanRedeem = "counterparty can redeem",
10
+ CounterpartyCanRefund = "counterparty can refund",
11
+ NoAction = "no action can be performed"
12
+ }
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@gardenfi/orderbook",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "dependencies": {
6
+ "@catalogfi/utils": "^0.1.0",
7
+ "bufferutil": "^4.0.8",
8
+ "ethers": "6.8.0",
9
+ "siwe": "^2.1.4",
10
+ "ts-jest": "^29.1.2",
11
+ "utf-8-validate": "^6.0.3",
12
+ "ws": "^8.14.2"
13
+ },
14
+ "scripts": {
15
+ "build": "vite build",
16
+ "test": "jest",
17
+ "dev": "vite build --watch"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "main": "./dist/index.cjs",
23
+ "module": "./dist/index.js",
24
+ "typings": "./dist/src/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "require": "./dist/index.cjs",
28
+ "import": "./dist/index.js",
29
+ "types": "./dist/src/index.d.ts"
30
+ },
31
+ "./package.json": "./package.json"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "devDependencies": {
38
+ "@types/jest": "^29.5.12",
39
+ "@types/ws": "^8.5.7",
40
+ "dotenv": "^16.3.1",
41
+ "jest": "^29.7.0",
42
+ "typescript": "^5.2.2",
43
+ "vite": "^5.1.6",
44
+ "vite-plugin-dts": "^3.7.3"
45
+ },
46
+ "sideEffects": false
47
+ }