@gardenfi/orderbook 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +14 -11
- package/dist/index10.cjs +1 -1
- package/dist/index10.js +2 -15
- package/dist/index11.cjs +1 -1
- package/dist/index11.js +15 -2
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +13 -13
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +1 -1
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +1 -1
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +3 -50
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +44 -60
- package/dist/index8.cjs +1 -1
- package/dist/index8.js +65 -8
- package/dist/index9.cjs +1 -1
- package/dist/index9.js +9 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/lib/api.d.ts +2 -1
- package/dist/src/lib/asset.d.ts +1 -1
- package/dist/src/lib/testUtils.d.ts +1 -1
- package/package.json +1 -4
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./index2.cjs"),e=require("./index3.cjs"),r=require("./index4.cjs"),i=require("./index5.cjs"),s=require("./index6.cjs");exports.Orderbook=a.Orderbook;exports.chainToId=e.chainToId;exports.idToChain=e.idToChain;exports.orderPairGenerator=e.orderPairGenerator;exports.Assets=r.Assets;exports.Chains=r.Chains;exports.ChainsData=r.ChainsData;exports.isMainnet=r.isMainnet;exports.Actions=i.Actions;exports.parseStatus=i.parseStatus;exports.MAINNET_ORDERBOOK_API=s.MAINNET_ORDERBOOK_API;exports.TESTNET_ORDERBOOK_API=s.TESTNET_ORDERBOOK_API;
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { chainToId as
|
|
3
|
-
import { Assets as
|
|
4
|
-
import { Actions as x, parseStatus as
|
|
1
|
+
import { Orderbook as e } from "./index2.js";
|
|
2
|
+
import { chainToId as a, idToChain as i, orderPairGenerator as s } from "./index3.js";
|
|
3
|
+
import { Assets as O, Chains as p, ChainsData as T, isMainnet as f } from "./index4.js";
|
|
4
|
+
import { Actions as x, parseStatus as A } from "./index5.js";
|
|
5
|
+
import { MAINNET_ORDERBOOK_API as d, TESTNET_ORDERBOOK_API as h } from "./index6.js";
|
|
5
6
|
export {
|
|
6
7
|
x as Actions,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
O as Assets,
|
|
9
|
+
p as Chains,
|
|
10
|
+
T as ChainsData,
|
|
11
|
+
d as MAINNET_ORDERBOOK_API,
|
|
12
|
+
e as Orderbook,
|
|
13
|
+
h as TESTNET_ORDERBOOK_API,
|
|
14
|
+
a as chainToId,
|
|
12
15
|
i as idToChain,
|
|
13
|
-
|
|
16
|
+
f as isMainnet,
|
|
14
17
|
s as orderPairGenerator,
|
|
15
|
-
|
|
18
|
+
A as parseStatus
|
|
16
19
|
};
|
package/dist/index10.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
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/index10.js
CHANGED
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
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
|
+
var t = /* @__PURE__ */ ((r) => (r.AUTH_TOKEN = "auth_token", r))(t || {});
|
|
15
2
|
export {
|
|
16
|
-
|
|
3
|
+
t as StoreKeys
|
|
17
4
|
};
|
package/dist/index11.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
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/index11.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
16
|
+
m as MemoryStorage
|
|
4
17
|
};
|
package/dist/index2.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@catalogfi/utils"),
|
|
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;
|
package/dist/index2.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Fetcher as n, trim0x as
|
|
2
|
-
import { OrdersSocket as
|
|
3
|
-
import { Siwe as u } from "./
|
|
4
|
-
import { orderPairGenerator as
|
|
5
|
-
import { OrderbookErrors as i } from "./
|
|
6
|
-
import { StoreKeys as
|
|
7
|
-
import { MemoryStorage as o } from "./
|
|
8
|
-
import {
|
|
1
|
+
import { Fetcher as n, trim0x as S } from "@catalogfi/utils";
|
|
2
|
+
import { OrdersSocket as d } from "./index7.js";
|
|
3
|
+
import { Siwe as u } from "./index8.js";
|
|
4
|
+
import { orderPairGenerator as I } from "./index3.js";
|
|
5
|
+
import { OrderbookErrors as i } from "./index9.js";
|
|
6
|
+
import { StoreKeys as y } from "./index10.js";
|
|
7
|
+
import { MemoryStorage as o } from "./index11.js";
|
|
8
|
+
import { MAINNET_ORDERBOOK_API as p } from "./index6.js";
|
|
9
9
|
import { Url as h } from "./index12.js";
|
|
10
10
|
class m {
|
|
11
11
|
/**
|
|
@@ -16,7 +16,7 @@ class m {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(s) {
|
|
18
18
|
var t;
|
|
19
|
-
this.supportedContracts = {}, this.url = new h("/", s.url ?? p), this.orderSocket = new
|
|
19
|
+
this.supportedContracts = {}, this.url = new h("/", s.url ?? p), this.orderSocket = new d(this.url.socket()), this.auth = new u(this.url, s.signer, {
|
|
20
20
|
...s.opts,
|
|
21
21
|
store: ((t = s.opts) == null ? void 0 : t.store) || new o()
|
|
22
22
|
});
|
|
@@ -36,7 +36,7 @@ class m {
|
|
|
36
36
|
return s.opts = {
|
|
37
37
|
...s.opts,
|
|
38
38
|
store: r
|
|
39
|
-
}, r.setItem(
|
|
39
|
+
}, r.setItem(y.AUTH_TOKEN, e), new m(s);
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Returns the supported contracts from the orderbook.
|
|
@@ -64,12 +64,12 @@ class m {
|
|
|
64
64
|
...c
|
|
65
65
|
} = s;
|
|
66
66
|
this.validateConfig(s);
|
|
67
|
-
const w = await this.getSupportedContracts(), A =
|
|
67
|
+
const w = await this.getSupportedContracts(), A = I(a, l, w), O = this.url.endpoint("orders"), { orderId: N } = await n.post(O, {
|
|
68
68
|
body: JSON.stringify({
|
|
69
69
|
...c,
|
|
70
70
|
sendAmount: t,
|
|
71
71
|
receiveAmount: r,
|
|
72
|
-
secretHash:
|
|
72
|
+
secretHash: S(e),
|
|
73
73
|
orderPair: A,
|
|
74
74
|
userWalletBTCAddress: c.btcInputAddress
|
|
75
75
|
}),
|
|
@@ -77,7 +77,7 @@ class m {
|
|
|
77
77
|
Authorization: await this.auth.getToken()
|
|
78
78
|
}
|
|
79
79
|
});
|
|
80
|
-
return
|
|
80
|
+
return N;
|
|
81
81
|
}
|
|
82
82
|
async getOrders(s, t) {
|
|
83
83
|
const e = await n.get(
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index4.cjs"),t=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./index4.cjs"),t=require("./index9.cjs"),o=(e,r,i)=>{if(!i[e.chain]||!i[r.chain]){let a=t.OrderbookErrors.UNSUPPORTED_CHAIN+": ";throw a+="only "+Object.keys(i).join(", ")+" are supported",new Error(a)}if(e.chain===r.chain)throw new Error(t.OrderpairErrors.SAME_ASSET);return e.chain===n.Chains.bitcoin||e.chain===n.Chains.bitcoin_testnet||e.chain===n.Chains.bitcoin_regtest?`${n.Chains[e.chain]}-${n.Chains[r.chain]}:${i[r.chain]}`:`${n.Chains[e.chain]}:${i[e.chain]}-${n.Chains[r.chain]}`},h={ethereum:1,ethereum_sepolia:11155111,ethereum_arbitrum:42161,ethereum_arbitrumlocalnet:31338,ethereum_localnet:31337},c=Object.entries(h).reduce((e,[r,i])=>(e[i]=r,e),{});exports.chainToId=h;exports.idToChain=c;exports.orderPairGenerator=o;
|
package/dist/index3.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chains as n } from "./index4.js";
|
|
2
|
-
import { OrderpairErrors as h, OrderbookErrors as a } from "./
|
|
2
|
+
import { OrderpairErrors as h, OrderbookErrors as a } from "./index9.js";
|
|
3
3
|
const b = (e, r, i) => {
|
|
4
4
|
if (!i[e.chain] || !i[r.chain]) {
|
|
5
5
|
let t = a.UNSUPPORTED_CHAIN + ": ";
|
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={ethereum_sepolia:"ethereum_sepolia",ethereum:"ethereum",bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum_arbitrum:"ethereum_arbitrum",ethereum_arbitrumlocalnet:"ethereum_arbitrumlocalnet",ethereum_localnet:"ethereum_localnet"},o={ethereum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",address:"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"}},ethereum_sepolia:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_sepolia,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0xaD9d14CA82d9BF97fFf745fFC7d48172A1c0969E"}},ethereum_arbitrumlocalnet:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={ethereum_sepolia:"ethereum_sepolia",ethereum:"ethereum",bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum_arbitrum:"ethereum_arbitrum",ethereum_arbitrumlocalnet:"ethereum_arbitrumlocalnet",ethereum_localnet:"ethereum_localnet"},o={ethereum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg?v=029",address:"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599"}},ethereum_sepolia:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_sepolia,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0xaD9d14CA82d9BF97fFf745fFC7d48172A1c0969E"}},ethereum_arbitrumlocalnet:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_arbitrumlocalnet,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"}},ethereum_localnet:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_localnet,isToken:!0,thumbnail:"https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",address:"0x5FbDB2315678afecb367f032d93F642f64180aa3"}},bitcoin:{BTC:{name:"Bitcoin",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin,isToken:!1}},bitcoin_testnet:{BTC:{name:"Bitcoin Testnet",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin_testnet,isToken:!1}},bitcoin_regtest:{BTC:{name:"Bitcoin Regtest",symbol:"BTC",decimals:8,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",chain:e.bitcoin_regtest,isToken:!1}},ethereum_arbitrum:{WBTC:{name:"Wrapped Bitcoin",symbol:"WBTC",decimals:8,chain:e.ethereum_arbitrum,isToken:!0,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg",address:"0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"}}},s={bitcoin:{nativeAsset:o.bitcoin.BTC},bitcoin_testnet:{nativeAsset:o.bitcoin_testnet.BTC},bitcoin_regtest:{nativeAsset:{name:"Bitcoin Regtest",symbol:"rBTC",decimals:8,chain:e.bitcoin_regtest,isToken:!1,thumbnail:"https://cryptologos.cc/logos/bitcoin-btc-logo.svg"}},ethereum:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}},ethereum_sepolia:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_sepolia,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}},ethereum_arbitrum:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_arbitrum,isToken:!1,thumbnail:"https://cryptologos.cc/logos/arbitrum-arb-logo.svg"}},ethereum_arbitrumlocalnet:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_arbitrumlocalnet,isToken:!1,thumbnail:"https://cryptologos.cc/logos/arbitrum-arb-logo.svg"}},ethereum_localnet:{nativeAsset:{name:"Ethereum",symbol:"ETH",decimals:18,chain:e.ethereum_localnet,isToken:!1,thumbnail:"https://cryptologos.cc/logos/ethereum-eth-logo.svg"}}},i=t=>!(t===e.ethereum_sepolia||t===e.bitcoin_testnet||t===e.bitcoin_regtest||t===e.ethereum_arbitrumlocalnet||t===e.ethereum_localnet);exports.Assets=o;exports.Chains=e;exports.ChainsData=s;exports.isMainnet=i;
|
package/dist/index4.js
CHANGED
|
@@ -35,7 +35,7 @@ const e = {
|
|
|
35
35
|
name: "Wrapped Bitcoin",
|
|
36
36
|
symbol: "WBTC",
|
|
37
37
|
decimals: 8,
|
|
38
|
-
chain: e.
|
|
38
|
+
chain: e.ethereum_arbitrumlocalnet,
|
|
39
39
|
isToken: !0,
|
|
40
40
|
thumbnail: "https://cryptologos.cc/logos/wrapped-bitcoin-wbtc-logo.svg",
|
|
41
41
|
address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
|
package/dist/index6.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t="https://api.garden.finance",e="https://orderbook-testnet.garden.finance";exports.MAINNET_ORDERBOOK_API=t;exports.TESTNET_ORDERBOOK_API=e;
|
package/dist/index6.js
CHANGED
|
@@ -1,52 +1,5 @@
|
|
|
1
|
-
|
|
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
|
-
}
|
|
1
|
+
const t = "https://api.garden.finance", n = "https://orderbook-testnet.garden.finance";
|
|
50
2
|
export {
|
|
51
|
-
|
|
3
|
+
t as MAINNET_ORDERBOOK_API,
|
|
4
|
+
n as TESTNET_ORDERBOOK_API
|
|
52
5
|
};
|
package/dist/index7.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const 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;
|
package/dist/index7.js
CHANGED
|
@@ -1,68 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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;
|
|
10
16
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} catch {
|
|
18
|
-
return !1;
|
|
19
|
-
}
|
|
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
|
+
});
|
|
20
23
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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;
|
|
24
|
+
}
|
|
25
|
+
class p {
|
|
26
|
+
constructor(e) {
|
|
27
|
+
this.socket = new i(e);
|
|
37
28
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
29
|
+
onMsg(e) {
|
|
30
|
+
this.socket.onmessage = (s) => {
|
|
31
|
+
this.pingTimeout && clearTimeout(this.pingTimeout), this.pingTimeout = setTimeout(() => {
|
|
32
|
+
this.socket.close(r);
|
|
33
|
+
}, 30 * 1e3), e(this, n(s.data));
|
|
54
34
|
};
|
|
55
35
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const e = s.split(".")[1];
|
|
61
|
-
return e ? JSON.parse(Buffer.from(e, "base64").toString("latin1")) : void 0;
|
|
62
|
-
} catch {
|
|
63
|
-
return;
|
|
36
|
+
onClose(e) {
|
|
37
|
+
this.socket.onclose = (s) => {
|
|
38
|
+
s.code === r && e(s.reason);
|
|
39
|
+
};
|
|
64
40
|
}
|
|
65
|
-
|
|
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
|
+
}
|
|
66
50
|
export {
|
|
67
|
-
|
|
51
|
+
a as OrdersSocket
|
|
68
52
|
};
|
package/dist/index8.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("siwe"),a=require("@catalogfi/utils"),o=require("./index10.cjs"),h=require("./index11.cjs"),d=require("./index6.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.MAINNET_ORDERBOOK_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/index8.js
CHANGED
|
@@ -1,11 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
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 { MAINNET_ORDERBOOK_API as c } from "./index6.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();
|
|
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
|
+
}
|
|
7
65
|
};
|
|
8
66
|
export {
|
|
9
|
-
|
|
10
|
-
e as OrderpairErrors
|
|
67
|
+
v as Siwe
|
|
11
68
|
};
|
package/dist/index9.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
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/index9.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
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"
|
|
7
|
+
};
|
|
2
8
|
export {
|
|
3
|
-
|
|
9
|
+
r as OrderbookErrors,
|
|
10
|
+
e as OrderpairErrors
|
|
4
11
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ 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
6
|
export { parseStatus, Actions } from './lib/utils';
|
|
7
|
+
export { MAINNET_ORDERBOOK_API, TESTNET_ORDERBOOK_API } from './lib/api';
|
package/dist/src/lib/api.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const MAINNET_ORDERBOOK_API = "https://api.garden.finance";
|
|
2
|
+
export declare const TESTNET_ORDERBOOK_API = "https://orderbook-testnet.garden.finance";
|
package/dist/src/lib/asset.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const startWsServer: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/orderbook",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@catalogfi/utils": "^0.1.6",
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"bufferutil": "^4.0.8",
|
|
9
9
|
"ethers": "6.8.0",
|
|
10
10
|
"siwe": "^2.1.4",
|
|
11
|
-
"ts-jest": "^29.1.2",
|
|
12
11
|
"utf-8-validate": "^6.0.3",
|
|
13
12
|
"ws": "^8.14.2"
|
|
14
13
|
},
|
|
@@ -36,10 +35,8 @@
|
|
|
36
35
|
"registry": "https://registry.npmjs.org/"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@types/jest": "^29.5.12",
|
|
40
38
|
"@types/ws": "^8.5.7",
|
|
41
39
|
"dotenv": "^16.3.1",
|
|
42
|
-
"jest": "^29.7.0",
|
|
43
40
|
"typescript": "^5.2.2",
|
|
44
41
|
"vite": "^5.1.6",
|
|
45
42
|
"vite-plugin-dts": "^3.7.3",
|