@gardenfi/orderbook 0.1.10 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index2.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),m=require("./index7.cjs"),i=require("./index8.cjs"),N=require("./index3.cjs"),o=require("./index9.cjs"),y=require("./index10.cjs"),h=require("./index11.cjs"),p=require("./index6.cjs"),l=require("./index12.cjs");class u{constructor(e){var t;this.supportedContracts={},this.url=new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),this.orderSocket=new m.OrdersSocket(this.url.socket()),this.auth=new i.Siwe(this.url,e.signer,{...e.opts,store:((t=e.opts)==null?void 0:t.store)||new h.MemoryStorage})}static async init(e){var c;const s=await new i.Siwe(new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),e.signer,e.opts).getToken(),r=((c=e.opts)==null?void 0:c.store)??new h.MemoryStorage;return e.opts={...e.opts,store:r},r.setItem(y.StoreKeys.AUTH_TOKEN,s),new u(e)}async getSupportedContracts(){if(Object.keys(this.supportedContracts).length>0)return this.supportedContracts;const e=this.url.endpoint("assets"),t=await n.Fetcher.get(e),s={};for(const r in t)s[r]=t[r][0];return this.supportedContracts=s,s}async getOrder(e){const t=this.url.endpoint(`orders/${e}`);return n.Fetcher.get(t)}async createOrder(e){const{sendAmount:t,secretHash:s,receiveAmount:r,fromAsset:c,feeInSeed:E,toAsset:w,...a}=e;this.validateConfig(e);const O=await this.getSupportedContracts(),A=N.orderPairGenerator(c,w,O),S=this.url.endpoint("orders"),{orderId:d}=await n.Fetcher.post(S,{body:JSON.stringify({...a,sendAmount:t,receiveAmount:r,secretHash:n.trim0x(s),orderPair:A,userWalletBTCAddress:a.btcInputAddress}),headers:{Authorization:await this.auth.getToken()}});return d}async getOrders(e,t){const s=await n.Fetcher.get(this.url+"orders?"+new URLSearchParams({...t!=null&&t.taker?{taker:e}:{maker:e},verbose:t!=null&&t.verbose?"true":"false",...t!=null&&t.pending?{status:"2"}:{}}));return t!=null&&t.verbose,s}subscribeOrders(e,t){this.orderSocket.subscribe(e,t)}unsubscribeOrders(){this.orderSocket.unsubscribe()}validateConfig(e){const{sendAmount:t,receiveAmount:s}=e,r=+t,c=+s;if(isNaN(r)||r<=0||t.includes("."))throw new Error(o.OrderbookErrors.INVALID_SEND_AMOUNT);if(isNaN(c)||c<=0||s.includes("."))throw new Error(o.OrderbookErrors.INVALID_RECEIVE_AMOUNT)}}exports.Orderbook=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),d=require("./index7.cjs"),i=require("./index8.cjs"),N=require("./index3.cjs"),o=require("./index9.cjs"),y=require("./index10.cjs"),h=require("./index11.cjs"),p=require("./index6.cjs"),l=require("./index12.cjs");class u{constructor(e){var t;this.supportedContracts={},this.url=new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),this.orderSocket=new d.OrdersSocket(this.url.socket()),this.auth=new i.Siwe(this.url,e.signer,{...e.opts,store:((t=e.opts)==null?void 0:t.store)||new h.MemoryStorage})}static async init(e){var c;const s=await new i.Siwe(new l.Url("/",e.url??p.MAINNET_ORDERBOOK_API),e.signer,e.opts).getToken(),r=((c=e.opts)==null?void 0:c.store)??new h.MemoryStorage;return e.opts={...e.opts,store:r},r.setItem(y.StoreKeys.AUTH_TOKEN,s),new u(e)}async getSupportedContracts(){if(Object.keys(this.supportedContracts).length>0)return this.supportedContracts;const e=this.url.endpoint("assets"),t=await n.Fetcher.get(e),s={};for(const r in t)s[r]=t[r][0];return this.supportedContracts=s,s}async getOrder(e){const t=this.url.endpoint(`orders/${e}`);return n.Fetcher.get(t)}async createOrder(e){const{sendAmount:t,secretHash:s,receiveAmount:r,fromAsset:c,toAsset:w,...a}=e;this.validateConfig(e);const O=await this.getSupportedContracts(),A=N.orderPairGenerator(c,w,O),S=this.url.endpoint("orders"),{orderId:m}=await n.Fetcher.post(S,{body:JSON.stringify({...a,sendAmount:t,receiveAmount:r,secretHash:n.trim0x(s),orderPair:A,userWalletBTCAddress:a.btcInputAddress}),headers:{Authorization:await this.auth.getToken()}});return m}async getOrders(e,t){const s=await n.Fetcher.get(this.url+"orders?"+new URLSearchParams({...t!=null&&t.taker?{taker:e}:{maker:e},verbose:t!=null&&t.verbose?"true":"false",...t!=null&&t.pending?{status:"2"}:{}}));return t!=null&&t.verbose,s}subscribeOrders(e,t){this.orderSocket.subscribe(e,t)}unsubscribeOrders(){this.orderSocket.unsubscribe()}validateConfig(e){const{sendAmount:t,receiveAmount:s}=e,r=+t,c=+s;if(isNaN(r)||r<=0||t.includes("."))throw new Error(o.OrderbookErrors.INVALID_SEND_AMOUNT);if(isNaN(c)||c<=0||s.includes("."))throw new Error(o.OrderbookErrors.INVALID_RECEIVE_AMOUNT)}}exports.Orderbook=u;
package/dist/index2.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import { Fetcher as n, trim0x as S } from "@catalogfi/utils";
2
2
  import { OrdersSocket as d } from "./index7.js";
3
3
  import { Siwe as u } from "./index8.js";
4
- import { orderPairGenerator as I } from "./index3.js";
4
+ import { orderPairGenerator as y } from "./index3.js";
5
5
  import { OrderbookErrors as i } from "./index9.js";
6
- import { StoreKeys as y } from "./index10.js";
6
+ import { StoreKeys as E } from "./index10.js";
7
7
  import { MemoryStorage as o } from "./index11.js";
8
8
  import { MAINNET_ORDERBOOK_API as p } from "./index6.js";
9
9
  import { Url as h } from "./index12.js";
@@ -36,7 +36,7 @@ class m {
36
36
  return s.opts = {
37
37
  ...s.opts,
38
38
  store: r
39
- }, r.setItem(y.AUTH_TOKEN, e), new m(s);
39
+ }, r.setItem(E.AUTH_TOKEN, e), new m(s);
40
40
  }
41
41
  /**
42
42
  * Returns the supported contracts from the orderbook.
@@ -59,12 +59,11 @@ class m {
59
59
  secretHash: e,
60
60
  receiveAmount: r,
61
61
  fromAsset: a,
62
- feeInSeed: E,
63
62
  toAsset: l,
64
63
  ...c
65
64
  } = s;
66
65
  this.validateConfig(s);
67
- const w = await this.getSupportedContracts(), A = I(a, l, w), O = this.url.endpoint("orders"), { orderId: N } = await n.post(O, {
66
+ const w = await this.getSupportedContracts(), A = y(a, l, w), O = this.url.endpoint("orders"), { orderId: N } = await n.post(O, {
68
67
  body: JSON.stringify({
69
68
  ...c,
70
69
  sendAmount: t,
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)},30*1e3),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 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)},70*1e3),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 CHANGED
@@ -30,7 +30,7 @@ class p {
30
30
  this.socket.onmessage = (s) => {
31
31
  this.pingTimeout && clearTimeout(this.pingTimeout), this.pingTimeout = setTimeout(() => {
32
32
  this.socket.close(r);
33
- }, 30 * 1e3), e(this, n(s.data));
33
+ }, 70 * 1e3), e(this, n(s.data));
34
34
  };
35
35
  }
36
36
  onClose(e) {
@@ -23,11 +23,11 @@ export declare class PaymentChannelService implements IPaymentChannelService {
23
23
  private _getAuthToken;
24
24
  private getSignatureForConditionalPayment;
25
25
  private _lockChannel;
26
- payConditionally(request: Omit<ConditionalPaymentInitialRequest, "timeLock">): AsyncResult<void, string>;
26
+ payConditionally(request: Omit<ConditionalPaymentInitialRequest, 'timeLock'>): AsyncResult<void, string>;
27
27
  /**
28
28
  * Constructs a conditional payment request for backend to accept.
29
29
  *
30
30
  * Use .payConditionally() to actually pay conditionally.
31
31
  */
32
- createConditionalPayment(paymentRequest: Omit<ConditionalPaymentInitialRequest, "timeLock">): AsyncResult<ConditionalPaymentFinalRequest, string>;
32
+ createConditionalPayment(paymentRequest: Omit<ConditionalPaymentInitialRequest, 'timeLock'>): AsyncResult<ConditionalPaymentFinalRequest, string>;
33
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@catalogfi/utils": "^0.1.6",