@gardenfi/orderbook 0.1.5 → 0.1.7

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 CHANGED
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./index2.cjs"),e=require("./index3.cjs"),r=require("./index4.cjs"),i=require("./index5.cjs");exports.Orderbook=s.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;
package/dist/index.js CHANGED
@@ -1,18 +1,16 @@
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";
1
+ import { Orderbook as a } from "./index2.js";
2
+ import { chainToId as t, idToChain as i, orderPairGenerator as s } from "./index3.js";
3
+ import { Assets as p, Chains as d, ChainsData as f, isMainnet as h } from "./index4.js";
4
+ import { Actions as x, parseStatus as C } from "./index5.js";
6
5
  export {
7
- A as Actions,
6
+ x as Actions,
8
7
  p as Assets,
9
- d as CONTRACT_ADDRESS,
10
- f as Chains,
11
- m as ChainsData,
12
- e as Orderbook,
13
- a as chainToId,
8
+ d as Chains,
9
+ f as ChainsData,
10
+ a as Orderbook,
11
+ t as chainToId,
14
12
  i as idToChain,
15
- x as isMainnet,
13
+ h as isMainnet,
16
14
  s as orderPairGenerator,
17
- T as parseStatus
15
+ C as parseStatus
18
16
  };
package/dist/index10.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.AUTH_TOKEN="auth_token",e))(t||{});exports.StoreKeys=t;
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;
package/dist/index10.js CHANGED
@@ -1,4 +1,17 @@
1
- var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
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
+ }
2
15
  export {
3
- t as StoreKeys
16
+ m as MemoryStorage
4
17
  };
package/dist/index11.cjs CHANGED
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="https://api.garden.finance";exports.API=e;
package/dist/index11.js CHANGED
@@ -1,17 +1,4 @@
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
- }
1
+ const n = "https://api.garden.finance";
15
2
  export {
16
- m as MemoryStorage
3
+ n as API
17
4
  };
package/dist/index12.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="https://api.garden.finance";exports.API=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class e extends URL{constructor(t,r){super(t,r)}endpoint(t){return new e(t,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}}exports.Url=e;
package/dist/index12.js CHANGED
@@ -1,4 +1,18 @@
1
- const n = "https://api.garden.finance";
1
+ class r extends URL {
2
+ constructor(t, e) {
3
+ super(t, e);
4
+ }
5
+ endpoint(t) {
6
+ return new r(t, this);
7
+ }
8
+ socket() {
9
+ if (this.protocol === "https:")
10
+ return this.origin.replace("https", "wss");
11
+ if (this.protocol === "http:")
12
+ return this.origin.replace("http", "ws");
13
+ throw new Error("Invalid protocol");
14
+ }
15
+ }
2
16
  export {
3
- n as API
17
+ r as Url
4
18
  };
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@catalogfi/utils"),O=require("./index7.cjs"),i=require("./index8.cjs"),y=require("./index3.cjs"),h=require("./index9.cjs"),I=require("./index10.cjs"),l=require("./index11.cjs"),o=require("./index12.cjs"),w=require("./index13.cjs");class a{constructor(t){var e;this.url=new w.Url("/",t.url??o.API),this.orderSocket=new O.OrdersSocket(this.url.socket()),this.auth=new i.Siwe(this.url,t.signer,{...t.opts,store:((e=t.opts)==null?void 0:e.store)||new l.MemoryStorage})}static async init(t){var u;const s=await new i.Siwe(new w.Url("/",t.url??o.API),t.signer,t.opts).getToken(),r=((u=t.opts)==null?void 0:u.store)??new l.MemoryStorage;return t.opts={...t.opts,store:r},r.setItem(I.StoreKeys.AUTH_TOKEN,s),new a(t)}async createOrder(t){const{sendAmount:e,secretHash:s,receiveAmount:r,fromAsset:u,feeInSeed:N,toAsset:A,...n}=t;this.validateConfig(t);const S=y.orderPairGenerator(u,A),m=this.url.endpoint("orders"),{orderId:p}=await c.Fetcher.post(m,{body:JSON.stringify({...n,sendAmount:e,receiveAmount:r,secretHash:c.trim0x(s),orderPair:S,userWalletBTCAddress:n.btcInputAddress}),headers:{Authorization:await this.auth.getToken()}});return p}async getOrders(t,e){const s=await c.Fetcher.get(this.url+"orders?"+new URLSearchParams({...e!=null&&e.taker?{taker:t}:{maker:t},verbose:e!=null&&e.verbose?"true":"false",...e!=null&&e.pending?{status:"2"}:{}}));return e!=null&&e.verbose,s}subscribeOrders(t,e){this.orderSocket.subscribe(t,e)}unsubscribeOrders(){this.orderSocket.unsubscribe()}validateConfig(t){const{sendAmount:e,receiveAmount:s}=t,r=+e,u=+s;if(isNaN(r)||r<=0||e.includes("."))throw new Error(h.OrderbookErrors.INVALID_SEND_AMOUNT);if(isNaN(u)||u<=0||s.includes("."))throw new Error(h.OrderbookErrors.INVALID_RECEIVE_AMOUNT)}}exports.Orderbook=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),O=require("./index6.cjs"),i=require("./index7.cjs"),y=require("./index3.cjs"),o=require("./index8.cjs"),b=require("./index9.cjs"),h=require("./index10.cjs"),p=require("./index11.cjs"),l=require("./index12.cjs");class u{constructor(e){var t;this.supportedContracts={},this.url=new l.Url("/",e.url??p.API),this.orderSocket=new O.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.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(b.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,feeInSeed:I,toAsset:w,...a}=e;this.validateConfig(e);const S=await this.getSupportedContracts(),A=y.orderPairGenerator(c,w,S),d=this.url.endpoint("orders"),{orderId:m}=await n.Fetcher.post(d,{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;
package/dist/index2.js CHANGED
@@ -1,13 +1,13 @@
1
- import { Fetcher as c, trim0x as S } from "@catalogfi/utils";
2
- import { OrdersSocket as I } from "./index7.js";
3
- import { Siwe as n } from "./index8.js";
4
- import { orderPairGenerator as O } from "./index3.js";
5
- import { OrderbookErrors as m } from "./index9.js";
6
- import { StoreKeys as E } from "./index10.js";
7
- import { MemoryStorage as i } from "./index11.js";
8
- import { API as h } from "./index12.js";
9
- import { Url as p } from "./index13.js";
10
- class w {
1
+ import { Fetcher as n, trim0x as d } from "@catalogfi/utils";
2
+ import { OrdersSocket as N } from "./index6.js";
3
+ import { Siwe as u } from "./index7.js";
4
+ import { orderPairGenerator as y } from "./index3.js";
5
+ import { OrderbookErrors as i } from "./index8.js";
6
+ import { StoreKeys as I } from "./index9.js";
7
+ import { MemoryStorage as o } from "./index10.js";
8
+ import { API as p } from "./index11.js";
9
+ import { Url as h } from "./index12.js";
10
+ class m {
11
11
  /**
12
12
  * Creates an instance of Orderbook. Does not login to the orderbook backend
13
13
  * @constructor
@@ -16,9 +16,9 @@ class w {
16
16
  */
17
17
  constructor(s) {
18
18
  var t;
19
- this.url = new p("/", s.url ?? h), this.orderSocket = new I(this.url.socket()), this.auth = new n(this.url, s.signer, {
19
+ this.supportedContracts = {}, this.url = new h("/", s.url ?? p), this.orderSocket = new N(this.url.socket()), this.auth = new u(this.url, s.signer, {
20
20
  ...s.opts,
21
- store: ((t = s.opts) == null ? void 0 : t.store) || new i()
21
+ store: ((t = s.opts) == null ? void 0 : t.store) || new o()
22
22
  });
23
23
  }
24
24
  /**
@@ -28,15 +28,30 @@ class w {
28
28
  */
29
29
  static async init(s) {
30
30
  var a;
31
- const e = await new n(
32
- new p("/", s.url ?? h),
31
+ const e = await new u(
32
+ new h("/", s.url ?? p),
33
33
  s.signer,
34
34
  s.opts
35
- ).getToken(), r = ((a = s.opts) == null ? void 0 : a.store) ?? new i();
35
+ ).getToken(), r = ((a = s.opts) == null ? void 0 : a.store) ?? new o();
36
36
  return s.opts = {
37
37
  ...s.opts,
38
38
  store: r
39
- }, r.setItem(E.AUTH_TOKEN, e), new w(s);
39
+ }, r.setItem(I.AUTH_TOKEN, e), new m(s);
40
+ }
41
+ /**
42
+ * Returns the supported contracts from the orderbook.
43
+ */
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);
40
55
  }
41
56
  async createOrder(s) {
42
57
  const {
@@ -44,28 +59,28 @@ class w {
44
59
  secretHash: e,
45
60
  receiveAmount: r,
46
61
  fromAsset: a,
47
- feeInSeed: T,
62
+ feeInSeed: E,
48
63
  toAsset: l,
49
- ...u
64
+ ...c
50
65
  } = s;
51
66
  this.validateConfig(s);
52
- const A = O(a, l), o = this.url.endpoint("orders"), { orderId: N } = await c.post(o, {
67
+ const w = await this.getSupportedContracts(), A = y(a, l, w), S = this.url.endpoint("orders"), { orderId: O } = await n.post(S, {
53
68
  body: JSON.stringify({
54
- ...u,
69
+ ...c,
55
70
  sendAmount: t,
56
71
  receiveAmount: r,
57
- secretHash: S(e),
72
+ secretHash: d(e),
58
73
  orderPair: A,
59
- userWalletBTCAddress: u.btcInputAddress
74
+ userWalletBTCAddress: c.btcInputAddress
60
75
  }),
61
76
  headers: {
62
77
  Authorization: await this.auth.getToken()
63
78
  }
64
79
  });
65
- return N;
80
+ return O;
66
81
  }
67
82
  async getOrders(s, t) {
68
- const e = await c.get(
83
+ const e = await n.get(
69
84
  this.url + "orders?" + new URLSearchParams({
70
85
  ...t != null && t.taker ? { taker: s } : { maker: s },
71
86
  verbose: t != null && t.verbose ? "true" : "false",
@@ -83,11 +98,11 @@ class w {
83
98
  validateConfig(s) {
84
99
  const { sendAmount: t, receiveAmount: e } = s, r = +t, a = +e;
85
100
  if (isNaN(r) || r <= 0 || t.includes("."))
86
- throw new Error(m.INVALID_SEND_AMOUNT);
101
+ throw new Error(i.INVALID_SEND_AMOUNT);
87
102
  if (isNaN(a) || a <= 0 || e.includes("."))
88
- throw new Error(m.INVALID_RECEIVE_AMOUNT);
103
+ throw new Error(i.INVALID_RECEIVE_AMOUNT);
89
104
  }
90
105
  }
91
106
  export {
92
- w as Orderbook
107
+ m as Orderbook
93
108
  };
package/dist/index3.cjs CHANGED
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index4.cjs"),t=require("./index8.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;
package/dist/index3.js CHANGED
@@ -1,25 +1,24 @@
1
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]}`;
2
+ import { OrderpairErrors as h, OrderbookErrors as a } from "./index8.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);
13
7
  }
14
- }, e = {
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 = {
15
12
  ethereum: 1,
16
13
  ethereum_sepolia: 11155111,
17
- ethereum_arbitrum: 42161
18
- }, d = Object.entries(
19
- e
20
- ).reduce((i, [r, c]) => (i[c] = r, i), {});
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), {});
21
20
  export {
22
- e as chainToId,
23
- d as idToChain,
24
- u as orderPairGenerator
21
+ c as chainToId,
22
+ l as idToChain,
23
+ b as orderPairGenerator
25
24
  };
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"},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}},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"}}},i={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"}}},s=t=>!(t===e.ethereum_sepolia||t===e.bitcoin_testnet||t===e.bitcoin_regtest);exports.Assets=o;exports.Chains=e;exports.ChainsData=i;exports.isMainnet=s;
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_arbitrum,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;
package/dist/index4.js CHANGED
@@ -4,7 +4,9 @@ const e = {
4
4
  bitcoin: "bitcoin",
5
5
  bitcoin_testnet: "bitcoin_testnet",
6
6
  bitcoin_regtest: "bitcoin_regtest",
7
- ethereum_arbitrum: "ethereum_arbitrum"
7
+ ethereum_arbitrum: "ethereum_arbitrum",
8
+ ethereum_arbitrumlocalnet: "ethereum_arbitrumlocalnet",
9
+ ethereum_localnet: "ethereum_localnet"
8
10
  }, o = {
9
11
  ethereum: {
10
12
  WBTC: {
@@ -25,7 +27,29 @@ const e = {
25
27
  chain: e.ethereum_sepolia,
26
28
  isToken: !0,
27
29
  thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
28
- address: "0x3D1e56247033FE191DC789b5838E366dC04b1b73"
30
+ address: "0xaD9d14CA82d9BF97fFf745fFC7d48172A1c0969E"
31
+ }
32
+ },
33
+ ethereum_arbitrumlocalnet: {
34
+ WBTC: {
35
+ name: "Wrapped Bitcoin",
36
+ symbol: "WBTC",
37
+ decimals: 8,
38
+ chain: e.ethereum_arbitrum,
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"
29
53
  }
30
54
  },
31
55
  bitcoin: {
@@ -69,7 +93,7 @@ const e = {
69
93
  address: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
70
94
  }
71
95
  }
72
- }, i = {
96
+ }, s = {
73
97
  bitcoin: {
74
98
  nativeAsset: o.bitcoin.BTC
75
99
  },
@@ -115,11 +139,31 @@ const e = {
115
139
  isToken: !1,
116
140
  thumbnail: "https://cryptologos.cc/logos/arbitrum-arb-logo.svg"
117
141
  }
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"
151
+ }
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"
161
+ }
118
162
  }
119
- }, s = (t) => !(t === e.ethereum_sepolia || t === e.bitcoin_testnet || t === e.bitcoin_regtest);
163
+ }, i = (t) => !(t === e.ethereum_sepolia || t === e.bitcoin_testnet || t === e.bitcoin_regtest || t === e.ethereum_arbitrumlocalnet || t === e.ethereum_localnet);
120
164
  export {
121
165
  o as Assets,
122
166
  e as Chains,
123
- i as ChainsData,
124
- s as isMainnet
167
+ s as ChainsData,
168
+ i as isMainnet
125
169
  };
package/dist/index5.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A={1:{AtomicSwap:"0xA5E38d098b54C00F10e32E51647086232a9A0afD"},11155111:{AtomicSwap:"0x9ceD08aeE17Fbc333BB7741Ec5eB2907b0CA4241"},42161:{AtomicSwap:"0x203DAC25763aE783Ad532A035FfF33d8df9437eE"}};exports.CONTRACT_ADDRESS=A;
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;
package/dist/index5.js CHANGED
@@ -1,14 +1,9 @@
1
- const A = {
2
- 1: {
3
- AtomicSwap: "0xA5E38d098b54C00F10e32E51647086232a9A0afD"
4
- },
5
- 11155111: {
6
- AtomicSwap: "0x9ceD08aeE17Fbc333BB7741Ec5eB2907b0CA4241"
7
- },
8
- 42161: {
9
- AtomicSwap: "0x203DAC25763aE783Ad532A035FfF33d8df9437eE"
10
- }
1
+ const n = (e) => {
2
+ const r = e.status * 100 + e.initiatorAtomicSwap.swapStatus * 10 + e.followerAtomicSwap.swapStatus;
3
+ return r === 200 ? "user can initiate" : r === 222 ? "user can redeem" : /\d3\d/.test(`${r}`) ? "user can refund" : r === 220 ? "counterparty can initiate" : r === 224 || r === 226 ? "counterparty can redeem" : /\d\d3/.test(`${r}`) ? "counterparty can refund" : "no action can be performed";
11
4
  };
5
+ var t = /* @__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))(t || {});
12
6
  export {
13
- A as CONTRACT_ADDRESS
7
+ t as Actions,
8
+ n as parseStatus
14
9
  };
package/dist/index6.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 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/index6.js CHANGED
@@ -1,9 +1,52 @@
1
- const n = (e) => {
2
- const r = e.status * 100 + e.initiatorAtomicSwap.swapStatus * 10 + e.followerAtomicSwap.swapStatus;
3
- return r === 200 ? "user can initiate" : r === 222 ? "user can redeem" : /\d3\d/.test(`${r}`) ? "user can refund" : r === 220 ? "counterparty can initiate" : r === 224 || r === 226 ? "counterparty can redeem" : /\d\d3/.test(`${r}`) ? "counterparty can refund" : "no action can be performed";
4
- };
5
- var t = /* @__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))(t || {});
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
+ }
6
50
  export {
7
- t as Actions,
8
- n as parseStatus
51
+ a as OrdersSocket
9
52
  };
package/dist/index7.cjs CHANGED
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("siwe"),a=require("@catalogfi/utils"),o=require("./index9.cjs"),h=require("./index10.cjs"),d=require("./index11.cjs"),u=require("./index12.cjs");class m{constructor(t,i,e){this.signingStatement="I'm signing in to Catalog",this.url=new u.Url("/",t??d.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.endpoint("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.endpoint("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=m;
package/dist/index7.js CHANGED
@@ -1,52 +1,68 @@
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;
1
+ import { SiweMessage as h } from "siwe";
2
+ import { Fetcher as o } from "@catalogfi/utils";
3
+ import { StoreKeys as a } from "./index9.js";
4
+ import { MemoryStorage as m } from "./index10.js";
5
+ import { API as c } from "./index11.js";
6
+ import { Url as d } from "./index12.js";
7
+ class v {
8
+ constructor(e, r, t) {
9
+ this.signingStatement = "I'm signing in to Catalog", this.url = new d("/", e ?? c), this.signer = r, 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();
16
10
  }
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
- });
11
+ verifyToken(e, r) {
12
+ const t = f(e);
13
+ if (!t) return !1;
14
+ try {
15
+ const i = Math.floor(Date.now() / 1e3) + 120;
16
+ return t.exp > i && t.userWallet.toLowerCase() === r.toLowerCase();
17
+ } catch {
18
+ return !1;
19
+ }
23
20
  }
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
- };
21
+ async getToken() {
22
+ const e = this.store.getItem(a.AUTH_TOKEN);
23
+ if (e && this.verifyToken(e, this.signer.address))
24
+ return e;
25
+ const { message: r, signature: t } = await this.signStatement(), { token: i } = await o.post(
26
+ this.url.endpoint("verify"),
27
+ {
28
+ body: JSON.stringify({
29
+ message: r,
30
+ signature: t
31
+ })
32
+ }
33
+ );
34
+ if (!this.verifyToken(i, await this.signer.getAddress()))
35
+ throw new Error("Token verification failed");
36
+ return this.store.setItem(a.AUTH_TOKEN, i), i;
40
37
  }
41
- send(e) {
42
- this.socket.readyState === i.OPEN ? this.socket.send(e) : this.socket.onopen = () => {
43
- this.socket.send(e);
38
+ async signStatement() {
39
+ if (!this.signer.provider)
40
+ throw new Error("signer does not have a provider");
41
+ const e = /* @__PURE__ */ new Date(), r = new Date(e.getTime() + 300 * 1e3), { nonce: t } = await o.get(this.url.endpoint("nonce")), i = await this.signer.provider.getNetwork(), n = new h({
42
+ domain: this.domain,
43
+ address: await this.signer.getAddress(),
44
+ statement: this.signingStatement,
45
+ nonce: t,
46
+ uri: "https://" + this.domain,
47
+ version: "1",
48
+ chainId: +i.chainId.toString(),
49
+ expirationTime: r.toISOString()
50
+ }).prepareMessage(), g = await this.signer.signMessage(n);
51
+ return {
52
+ message: n,
53
+ signature: g
44
54
  };
45
55
  }
46
- close(e) {
47
- clearTimeout(this.pingTimeout), this.socket.close(e);
48
- }
49
56
  }
57
+ const f = (s) => {
58
+ try {
59
+ if (s.split(".").length < 3) return;
60
+ const e = s.split(".")[1];
61
+ return e ? JSON.parse(Buffer.from(e, "base64").toString("latin1")) : void 0;
62
+ } catch {
63
+ return;
64
+ }
65
+ };
50
66
  export {
51
- a as OrdersSocket
67
+ v as Siwe
52
68
  };
package/dist/index8.cjs CHANGED
@@ -1 +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"),d=require("./index12.cjs"),u=require("./index13.cjs");class m{constructor(t,i,e){this.signingStatement="I'm signing in to Catalog",this.url=new u.Url("/",t??d.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.endpoint("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.endpoint("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=m;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r={INVALID_SEND_AMOUNT:"invalid send amount",INVALID_RECEIVE_AMOUNT:"invalid receive amount",UNSUPPORTED_CHAIN:"unsupported chain"},e={SAME_ASSET:"cannot create orderpair with the same assets"};exports.OrderbookErrors=r;exports.OrderpairErrors=e;
package/dist/index8.js CHANGED
@@ -1,68 +1,11 @@
1
- import { SiweMessage as h } from "siwe";
2
- import { Fetcher as o } from "@catalogfi/utils";
3
- import { StoreKeys as a } from "./index10.js";
4
- import { MemoryStorage as m } from "./index11.js";
5
- import { API as c } from "./index12.js";
6
- import { Url as d } from "./index13.js";
7
- class v {
8
- constructor(e, r, t) {
9
- this.signingStatement = "I'm signing in to Catalog", this.url = new d("/", e ?? c), this.signer = r, 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, r) {
12
- const t = f(e);
13
- if (!t) return !1;
14
- try {
15
- const i = Math.floor(Date.now() / 1e3) + 120;
16
- return t.exp > i && t.userWallet.toLowerCase() === r.toLowerCase();
17
- } catch {
18
- return !1;
19
- }
20
- }
21
- async getToken() {
22
- const e = this.store.getItem(a.AUTH_TOKEN);
23
- if (e && this.verifyToken(e, this.signer.address))
24
- return e;
25
- const { message: r, signature: t } = await this.signStatement(), { token: i } = await o.post(
26
- this.url.endpoint("verify"),
27
- {
28
- body: JSON.stringify({
29
- message: r,
30
- signature: t
31
- })
32
- }
33
- );
34
- if (!this.verifyToken(i, await this.signer.getAddress()))
35
- throw new Error("Token verification failed");
36
- return this.store.setItem(a.AUTH_TOKEN, i), i;
37
- }
38
- async signStatement() {
39
- if (!this.signer.provider)
40
- throw new Error("signer does not have a provider");
41
- const e = /* @__PURE__ */ new Date(), r = new Date(e.getTime() + 300 * 1e3), { nonce: t } = await o.get(this.url.endpoint("nonce")), i = await this.signer.provider.getNetwork(), n = new h({
42
- domain: this.domain,
43
- address: await this.signer.getAddress(),
44
- statement: this.signingStatement,
45
- nonce: t,
46
- uri: "https://" + this.domain,
47
- version: "1",
48
- chainId: +i.chainId.toString(),
49
- expirationTime: r.toISOString()
50
- }).prepareMessage(), g = await this.signer.signMessage(n);
51
- return {
52
- message: n,
53
- signature: g
54
- };
55
- }
56
- }
57
- const f = (s) => {
58
- try {
59
- if (s.split(".").length < 3) return;
60
- const e = s.split(".")[1];
61
- return e ? JSON.parse(Buffer.from(e, "base64").toString("latin1")) : void 0;
62
- } catch {
63
- return;
64
- }
1
+ const r = {
2
+ INVALID_SEND_AMOUNT: "invalid send amount",
3
+ INVALID_RECEIVE_AMOUNT: "invalid receive amount",
4
+ UNSUPPORTED_CHAIN: "unsupported chain"
5
+ }, e = {
6
+ SAME_ASSET: "cannot create orderpair with the same assets"
65
7
  };
66
8
  export {
67
- v as Siwe
9
+ r as OrderbookErrors,
10
+ e as OrderpairErrors
68
11
  };
package/dist/index9.cjs CHANGED
@@ -1 +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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var t=(e=>(e.AUTH_TOKEN="auth_token",e))(t||{});exports.StoreKeys=t;
package/dist/index9.js CHANGED
@@ -1,10 +1,4 @@
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
- };
1
+ var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
7
2
  export {
8
- r as OrderbookErrors,
9
- e as OrderpairErrors
3
+ t as StoreKeys
10
4
  };
@@ -3,5 +3,4 @@ export type { Order, Orders, AtomicSwap, IOrderbook, } from './lib/orderbook.typ
3
3
  export { chainToId, idToChain, orderPairGenerator } from './lib/orderpair';
4
4
  export type { Chain, EvmChain, Asset, ChainData } from './lib/asset';
5
5
  export { Chains, Assets, ChainsData, isMainnet } from './lib/asset';
6
- export { CONTRACT_ADDRESS } from './lib/contractAddress';
7
6
  export { parseStatus, Actions } from './lib/utils';
@@ -5,6 +5,8 @@ export declare const Chains: {
5
5
  readonly bitcoin_testnet: "bitcoin_testnet";
6
6
  readonly bitcoin_regtest: "bitcoin_regtest";
7
7
  readonly ethereum_arbitrum: "ethereum_arbitrum";
8
+ readonly ethereum_arbitrumlocalnet: "ethereum_arbitrumlocalnet";
9
+ readonly ethereum_localnet: "ethereum_localnet";
8
10
  };
9
11
  export type Chain = keyof typeof Chains;
10
12
  export type EvmChain = keyof Omit<typeof Chains, "bitcoin" | "bitcoin_testnet" | "bitcoin_regtest">;
@@ -45,6 +47,28 @@ export declare const Assets: {
45
47
  address: string;
46
48
  };
47
49
  };
50
+ ethereum_arbitrumlocalnet: {
51
+ WBTC: {
52
+ name: string;
53
+ symbol: string;
54
+ decimals: number;
55
+ chain: "ethereum_arbitrum";
56
+ isToken: boolean;
57
+ thumbnail: string;
58
+ address: string;
59
+ };
60
+ };
61
+ ethereum_localnet: {
62
+ WBTC: {
63
+ name: string;
64
+ symbol: string;
65
+ decimals: number;
66
+ chain: "ethereum_localnet";
67
+ isToken: boolean;
68
+ thumbnail: string;
69
+ address: string;
70
+ };
71
+ };
48
72
  bitcoin: {
49
73
  BTC: {
50
74
  name: string;
@@ -87,6 +111,7 @@ export declare const Assets: {
87
111
  };
88
112
  };
89
113
  };
114
+ export type SupportedContracts = Partial<Record<Chain, string>>;
90
115
  export type ChainData = {
91
116
  nativeAsset: Asset;
92
117
  };
@@ -1,6 +1,7 @@
1
1
  export declare const OrderbookErrors: {
2
2
  INVALID_SEND_AMOUNT: string;
3
3
  INVALID_RECEIVE_AMOUNT: string;
4
+ UNSUPPORTED_CHAIN: string;
4
5
  };
5
6
  export declare const OrderpairErrors: {
6
7
  SAME_ASSET: string;
@@ -1,4 +1,5 @@
1
1
  import { CreateOrderConfig, IOrderbook, Order, OrderConfig, OrderNonVerbose, OrderbookConfig } from './orderbook.types';
2
+ import { SupportedContracts } from './asset';
2
3
 
3
4
  /**
4
5
  * A class that allows you to create and manage orders with the backend url.
@@ -10,6 +11,7 @@ export declare class Orderbook implements IOrderbook {
10
11
  private orderSocket;
11
12
  private url;
12
13
  private auth;
14
+ private supportedContracts;
13
15
  /**
14
16
  * Creates an instance of Orderbook. Does not login to the orderbook backend
15
17
  * @constructor
@@ -23,6 +25,11 @@ export declare class Orderbook implements IOrderbook {
23
25
  * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
24
26
  */
25
27
  static init(orderbookConfig: OrderbookConfig): Promise<Orderbook>;
28
+ /**
29
+ * Returns the supported contracts from the orderbook.
30
+ */
31
+ getSupportedContracts(): Promise<SupportedContracts>;
32
+ getOrder(orderId: number): Promise<Order>;
26
33
  createOrder(createOrderConfig: CreateOrderConfig): Promise<number>;
27
34
  getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
28
35
  subscribeOrders(account: string, cb: (orders: Order[]) => void): void;
@@ -1,5 +1,5 @@
1
1
  import { MarkNonNullable } from '@catalogfi/utils';
2
- import { Asset } from './asset';
2
+ import { Asset, SupportedContracts } from './asset';
3
3
  import { JsonRpcSigner, Wallet } from 'ethers';
4
4
  import { IStore } from './store/store.interface';
5
5
 
@@ -103,6 +103,7 @@ export interface IOrderbook {
103
103
  * @returns {Promise<(T extends true ? Order : OrderNonVerbose)[]>} A promise that resolves to an array of orders.
104
104
  */
105
105
  getOrders<T extends boolean>(address: string, orderConfig?: Partial<OrderConfig<T>>): Promise<(T extends true ? Order : OrderNonVerbose)[]>;
106
+ getOrder(orderId: number): Promise<Order>;
106
107
  /**
107
108
  *
108
109
  *
@@ -117,6 +118,7 @@ export interface IOrderbook {
117
118
  * @returns {void}
118
119
  */
119
120
  unsubscribeOrders(): void;
121
+ getSupportedContracts(): Promise<SupportedContracts>;
120
122
  }
121
123
  export type AtomicSwap = {
122
124
  ID: number;
@@ -1,5 +1,5 @@
1
- import { Asset, EvmChain } from './asset';
1
+ import { Asset, Chain, EvmChain } from './asset';
2
2
 
3
- export declare const orderPairGenerator: (from: Asset, to: Asset) => string;
3
+ export declare const orderPairGenerator: (from: Asset, to: Asset, contracts: Partial<Record<Chain, string>>) => string;
4
4
  export declare const chainToId: Record<EvmChain, number>;
5
5
  export declare const idToChain: Record<number, EvmChain>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@catalogfi/utils": "^0.1.6",
package/dist/index13.cjs DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class e extends URL{constructor(t,r){super(t,r)}endpoint(t){return new e(t,this)}socket(){if(this.protocol==="https:")return this.origin.replace("https","wss");if(this.protocol==="http:")return this.origin.replace("http","ws");throw new Error("Invalid protocol")}}exports.Url=e;
package/dist/index13.js DELETED
@@ -1,18 +0,0 @@
1
- class r extends URL {
2
- constructor(t, e) {
3
- super(t, e);
4
- }
5
- endpoint(t) {
6
- return new r(t, this);
7
- }
8
- socket() {
9
- if (this.protocol === "https:")
10
- return this.origin.replace("https", "wss");
11
- if (this.protocol === "http:")
12
- return this.origin.replace("http", "ws");
13
- throw new Error("Invalid protocol");
14
- }
15
- }
16
- export {
17
- r as Url
18
- };
@@ -1,4 +0,0 @@
1
- export type ContractAddress = {
2
- AtomicSwap: string;
3
- };
4
- export declare const CONTRACT_ADDRESS: Record<number, ContractAddress>;