@gardenfi/orderbook 0.1.10 → 0.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +15 -17
  3. package/dist/index2.cjs +1 -1
  4. package/dist/index2.js +124 -87
  5. package/dist/index3.cjs +1 -1
  6. package/dist/index3.js +14 -22
  7. package/dist/index4.cjs +1 -1
  8. package/dist/index4.js +81 -160
  9. package/dist/index5.cjs +1 -1
  10. package/dist/index5.js +58 -6
  11. package/dist/index6.cjs +1 -1
  12. package/dist/index6.js +11 -3
  13. package/dist/index7.cjs +1 -1
  14. package/dist/index7.js +2 -50
  15. package/dist/index8.cjs +1 -1
  16. package/dist/index8.js +6 -65
  17. package/dist/src/index.d.ts +7 -7
  18. package/dist/src/lib/asset.d.ts +32 -108
  19. package/dist/src/lib/constants.d.ts +8 -0
  20. package/dist/src/lib/errors.d.ts +4 -2
  21. package/dist/src/lib/orderbook/orderbook.d.ts +44 -0
  22. package/dist/src/lib/orderbook/orderbook.types.d.ts +200 -0
  23. package/dist/src/lib/orders/orders.types.d.ts +60 -0
  24. package/dist/src/lib/orders/ordersProvider.d.ts +15 -0
  25. package/dist/src/lib/utils.d.ts +10 -11
  26. package/package.json +20 -19
  27. package/dist/index10.cjs +0 -1
  28. package/dist/index10.js +0 -4
  29. package/dist/index11.cjs +0 -1
  30. package/dist/index11.js +0 -17
  31. package/dist/index12.cjs +0 -1
  32. package/dist/index12.js +0 -18
  33. package/dist/index9.cjs +0 -1
  34. package/dist/index9.js +0 -11
  35. package/dist/src/lib/auth/auth.interface.d.ts +0 -4
  36. package/dist/src/lib/auth/siwe.d.ts +0 -16
  37. package/dist/src/lib/orderbook.d.ts +0 -38
  38. package/dist/src/lib/orderbook.types.d.ts +0 -178
  39. package/dist/src/lib/orderpair.d.ts +0 -5
  40. package/dist/src/lib/ordersSocket.d.ts +0 -9
  41. package/dist/src/lib/pws/index.d.ts +0 -3
  42. package/dist/src/lib/pws/interface.d.ts +0 -79
  43. package/dist/src/lib/pws/service.d.ts +0 -33
  44. package/dist/src/lib/pws/utils.d.ts +0 -7
  45. package/dist/src/lib/store/memoryStorage.d.ts +0 -14
  46. package/dist/src/lib/store/store.interface.d.ts +0 -33
  47. package/dist/src/lib/testUtils.d.ts +0 -1
  48. package/dist/src/lib/url/Url.d.ts +0 -5
  49. package/dist/src/lib/url/index.d.ts +0 -1
package/dist/index5.js CHANGED
@@ -1,9 +1,61 @@
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";
1
+ import { Chains as e } from "./index3.js";
2
+ const a = {
3
+ id: 31338,
4
+ name: "Arbitrum Localnet",
5
+ nativeCurrency: {
6
+ name: "Ethereum",
7
+ symbol: "ETH",
8
+ decimals: 18
9
+ },
10
+ rpcUrls: {
11
+ default: {
12
+ http: ["http://localhost:8546/"]
13
+ }
14
+ },
15
+ testnet: !0
16
+ }, s = {
17
+ id: 31337,
18
+ name: "Ethereum Localnet",
19
+ nativeCurrency: {
20
+ name: "Ethereum",
21
+ symbol: "ETH",
22
+ decimals: 18
23
+ },
24
+ rpcUrls: {
25
+ default: {
26
+ http: ["http://localhost:8545/"]
27
+ }
28
+ },
29
+ testnet: !0
30
+ }, r = {
31
+ name: "Bitcoin Regtest",
32
+ decimals: 8,
33
+ symbol: "BTC",
34
+ chain: e.bitcoin_regtest,
35
+ atomicSwapAddress: "primary",
36
+ tokenAddress: "primary",
37
+ isToken: !0
38
+ }, n = {
39
+ name: "WBTC Arbitrum Localnet",
40
+ decimals: 8,
41
+ symbol: "WBTC",
42
+ chain: e.arbitrum_localnet,
43
+ atomicSwapAddress: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
44
+ tokenAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
45
+ isToken: !0
46
+ }, c = {
47
+ name: "WBTC Ethereum Localnet",
48
+ decimals: 8,
49
+ symbol: "WBTC",
50
+ chain: e.ethereum_localnet,
51
+ atomicSwapAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
52
+ tokenAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
53
+ isToken: !0
4
54
  };
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 || {});
6
55
  export {
7
- t as Actions,
8
- n as parseStatus
56
+ a as ArbitrumLocalnet,
57
+ s as EthereumLocalnet,
58
+ n as WBTCArbitrumLocalnetAsset,
59
+ c as WBTCEthereumLocalnetAsset,
60
+ r as bitcoinRegtestAsset
9
61
  };
package/dist/index6.cjs CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={INVALID_SEND_AMOUNT:"invalid send amount",INVALID_RECEIVE_AMOUNT:"invalid receive amount",UNSUPPORTED_CHAIN:"unsupported chain",SAME_ASSET:"cannot create orderpair with the same assets",INVALID_AS_ADDRESS:"invalid atomic swap address",INVALID_TOKEN:"invalid token address",INVALID_AMOUNTS:"invalid amounts",RECEIVE_AMOUNT_GREATER:"receive amount is greater than send amount"};exports.OrderbookErrors=e;
package/dist/index6.js CHANGED
@@ -1,5 +1,13 @@
1
- const t = "https://api.garden.finance", n = "https://orderbook-testnet.garden.finance";
1
+ const a = {
2
+ INVALID_SEND_AMOUNT: "invalid send amount",
3
+ INVALID_RECEIVE_AMOUNT: "invalid receive amount",
4
+ UNSUPPORTED_CHAIN: "unsupported chain",
5
+ SAME_ASSET: "cannot create orderpair with the same assets",
6
+ INVALID_AS_ADDRESS: "invalid atomic swap address",
7
+ INVALID_TOKEN: "invalid token address",
8
+ INVALID_AMOUNTS: "invalid amounts",
9
+ RECEIVE_AMOUNT_GREATER: "receive amount is greater than send amount"
10
+ };
2
11
  export {
3
- t as MAINNET_ORDERBOOK_API,
4
- n as TESTNET_ORDERBOOK_API
12
+ a as OrderbookErrors
5
13
  };
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 e="https://api.garden.finance";exports.MAINNET_ORDERBOOK_API=e;
package/dist/index7.js CHANGED
@@ -1,52 +1,4 @@
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
- }, 30 * 1e3), 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 n = "https://api.garden.finance";
50
2
  export {
51
- a as OrdersSocket
3
+ n as MAINNET_ORDERBOOK_API
52
4
  };
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("./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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=(n,o,t)=>{const r=n.endpoint(o);return t&&Object.entries(t).forEach(([c,e])=>{e!==void 0&&r.searchParams.append(c,e.toString())}),r};exports.ConstructUrl=i;
package/dist/index8.js CHANGED
@@ -1,68 +1,9 @@
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
- }
1
+ const i = (o, e, t) => {
2
+ const r = o.endpoint(e);
3
+ return t && Object.entries(t).forEach(([c, n]) => {
4
+ n !== void 0 && r.searchParams.append(c, n.toString());
5
+ }), r;
65
6
  };
66
7
  export {
67
- v as Siwe
8
+ i as ConstructUrl
68
9
  };
@@ -1,7 +1,7 @@
1
- export { Orderbook } from './lib/orderbook';
2
- export type { Order, Orders, AtomicSwap, IOrderbook, } from './lib/orderbook.types';
3
- export { chainToId, idToChain, orderPairGenerator } from './lib/orderpair';
4
- export type { Chain, EvmChain, Asset, ChainData } from './lib/asset';
5
- export { Chains, Assets, ChainsData, isMainnet } from './lib/asset';
6
- export { parseStatus, Actions } from './lib/utils';
7
- export { MAINNET_ORDERBOOK_API, TESTNET_ORDERBOOK_API } from './lib/api';
1
+ export { Orderbook } from './lib/orderbook/orderbook';
2
+ export type * from './lib/orderbook/orderbook.types';
3
+ export type { Chain, EvmChain, Asset } from './lib/asset';
4
+ export { Chains, isMainnet, isBitcoin, isEVM } from './lib/asset';
5
+ export { OrdersProvider } from './lib/orders/ordersProvider';
6
+ export type { IOrderProvider } from './lib/orders/orders.types';
7
+ export { WBTCArbitrumLocalnetAsset, WBTCEthereumLocalnetAsset, ArbitrumLocalnet, EthereumLocalnet, bitcoinRegtestAsset, } from './lib/constants';
@@ -1,119 +1,43 @@
1
- export declare const Chains: {
2
- readonly ethereum_sepolia: "ethereum_sepolia";
3
- readonly ethereum: "ethereum";
4
- readonly bitcoin: "bitcoin";
5
- readonly bitcoin_testnet: "bitcoin_testnet";
6
- readonly bitcoin_regtest: "bitcoin_regtest";
7
- readonly ethereum_arbitrum: "ethereum_arbitrum";
8
- readonly ethereum_arbitrumlocalnet: "ethereum_arbitrumlocalnet";
9
- readonly ethereum_localnet: "ethereum_localnet";
10
- };
11
- export type Chain = keyof typeof Chains;
12
- export type EvmChain = keyof Omit<typeof Chains, "bitcoin" | "bitcoin_testnet" | "bitcoin_regtest">;
13
1
  export type AssetCommon = {
14
2
  name: string;
15
- symbol: string;
16
3
  decimals: number;
4
+ symbol: string;
17
5
  chain: Chain;
18
- isToken: boolean;
19
- thumbnail: string;
6
+ logo?: string;
7
+ atomicSwapAddress: string;
20
8
  };
21
- export type AssetNative = AssetCommon;
22
9
  export type AssetToken = AssetCommon & {
23
- address: string;
10
+ tokenAddress: string;
24
11
  isToken: true;
25
12
  };
26
- export type Asset = AssetToken | AssetNative;
27
- export declare const Assets: {
28
- ethereum: {
29
- WBTC: {
30
- name: string;
31
- symbol: string;
32
- decimals: number;
33
- chain: "ethereum";
34
- isToken: boolean;
35
- thumbnail: string;
36
- address: string;
37
- };
38
- };
39
- ethereum_sepolia: {
40
- WBTC: {
41
- name: string;
42
- symbol: string;
43
- decimals: number;
44
- chain: "ethereum_sepolia";
45
- isToken: boolean;
46
- thumbnail: string;
47
- address: string;
48
- };
49
- };
50
- ethereum_arbitrumlocalnet: {
51
- WBTC: {
52
- name: string;
53
- symbol: string;
54
- decimals: number;
55
- chain: "ethereum_arbitrumlocalnet";
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
- };
72
- bitcoin: {
73
- BTC: {
74
- name: string;
75
- symbol: string;
76
- decimals: number;
77
- thumbnail: string;
78
- chain: "bitcoin";
79
- isToken: boolean;
80
- };
81
- };
82
- bitcoin_testnet: {
83
- BTC: {
84
- name: string;
85
- symbol: string;
86
- decimals: number;
87
- thumbnail: string;
88
- chain: "bitcoin_testnet";
89
- isToken: boolean;
90
- };
91
- };
92
- bitcoin_regtest: {
93
- BTC: {
94
- name: string;
95
- symbol: string;
96
- decimals: number;
97
- thumbnail: string;
98
- chain: "bitcoin_regtest";
99
- isToken: boolean;
100
- };
101
- };
102
- ethereum_arbitrum: {
103
- WBTC: {
104
- name: string;
105
- symbol: string;
106
- decimals: number;
107
- chain: "ethereum_arbitrum";
108
- isToken: boolean;
109
- thumbnail: string;
110
- address: string;
111
- };
13
+ export type Asset = AssetToken;
14
+ export declare enum NetworkType {
15
+ mainnet = "mainnet",
16
+ testnet = "testnet",
17
+ localnet = "localnet"
18
+ }
19
+ export type Network = {
20
+ [networkName: string]: {
21
+ chainId: number;
22
+ fillerAddresses: string[];
23
+ networkLogo: string;
24
+ explorer: string;
25
+ networkType: NetworkType;
26
+ assets?: Asset[];
112
27
  };
113
28
  };
114
- export type SupportedContracts = Partial<Record<Chain, string>>;
115
- export type ChainData = {
116
- nativeAsset: Asset;
29
+ export declare const Chains: {
30
+ readonly bitcoin: "bitcoin";
31
+ readonly bitcoin_testnet: "bitcoin_testnet";
32
+ readonly bitcoin_regtest: "bitcoin_regtest";
33
+ readonly ethereum: "ethereum";
34
+ readonly ethereum_arbitrum: "ethereum_arbitrum";
35
+ readonly ethereum_sepolia: "ethereum_sepolia";
36
+ readonly arbitrum_localnet: "arbitrum_localnet";
37
+ readonly ethereum_localnet: "ethereum_localnet";
117
38
  };
118
- export declare const ChainsData: Record<Chain, ChainData>;
119
- export declare const isMainnet: (chain: Chain) => chain is "ethereum" | "bitcoin" | "ethereum_arbitrum";
39
+ export type Chain = keyof typeof Chains;
40
+ export type EvmChain = keyof Omit<typeof Chains, 'bitcoin' | 'bitcoin_testnet' | 'bitcoin_regtest'>;
41
+ export declare const isMainnet: (chain: Chain) => chain is "bitcoin" | "ethereum" | "ethereum_arbitrum";
42
+ export declare const isBitcoin: (chain: Chain) => chain is "bitcoin" | "bitcoin_testnet" | "bitcoin_regtest";
43
+ export declare const isEVM: (chain: Chain) => chain is "ethereum" | "ethereum_arbitrum" | "ethereum_sepolia" | "arbitrum_localnet" | "ethereum_localnet";
@@ -0,0 +1,8 @@
1
+ import { Chain } from 'viem';
2
+ import { Asset } from './asset';
3
+
4
+ export declare const ArbitrumLocalnet: Chain;
5
+ export declare const EthereumLocalnet: Chain;
6
+ export declare const bitcoinRegtestAsset: Asset;
7
+ export declare const WBTCArbitrumLocalnetAsset: Asset;
8
+ export declare const WBTCEthereumLocalnetAsset: Asset;
@@ -2,7 +2,9 @@ export declare const OrderbookErrors: {
2
2
  INVALID_SEND_AMOUNT: string;
3
3
  INVALID_RECEIVE_AMOUNT: string;
4
4
  UNSUPPORTED_CHAIN: string;
5
- };
6
- export declare const OrderpairErrors: {
7
5
  SAME_ASSET: string;
6
+ INVALID_AS_ADDRESS: string;
7
+ INVALID_TOKEN: string;
8
+ INVALID_AMOUNTS: string;
9
+ RECEIVE_AMOUNT_GREATER: string;
8
10
  };
@@ -0,0 +1,44 @@
1
+ import { AsyncResult } from '@catalogfi/utils';
2
+ import { CreateOrder, CreateOrderConfig, IOrderbook, MatchedOrder, OrderbookConfig, PaginatedData, PaginationConfig } from './orderbook.types';
3
+ import { OrdersProvider } from '../orders/ordersProvider';
4
+
5
+ /**
6
+ * A class that allows you to create and manage orders with the orderbook url.
7
+ * @class
8
+ * @extends {OrdersProvider}
9
+ * @implements {IOrderbook}
10
+ */
11
+ export declare class Orderbook extends OrdersProvider implements IOrderbook {
12
+ private Url;
13
+ private auth;
14
+ private walletClient;
15
+ /**
16
+ * Creates an instance of Orderbook. Does not login to the orderbook.
17
+ * @constructor
18
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
19
+ */
20
+ constructor(orderbookConfig: OrderbookConfig);
21
+ /**
22
+ * Initializes the orderbook as well as logs in the orderbook (fetches the auth token).
23
+ * @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
24
+ */
25
+ static init(orderbookConfig: OrderbookConfig): Promise<Orderbook>;
26
+ /**
27
+ * Creates an order
28
+ * @param {CreateOrderConfig} createOrderConfig - The configuration for the creating the order.
29
+ * @returns {string} The create order ID.
30
+ */
31
+ createOrder(createOrderConfig: CreateOrderConfig): AsyncResult<string, string>;
32
+ fetchOrders<T extends boolean>(matched: T, pending?: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
33
+ /**
34
+ * Wrapper for the subscribeOrders method in the OrdersProvider class to abstract the address parameter.
35
+ * @param matched - Whether to get matched or unmatched orders
36
+ * @param interval - The interval to poll for updates
37
+ * @param cb - The callback to be called when the orders are updated
38
+ * @param paginationConfig - The configuration for the pagination
39
+ * @returns {() => void} A function to unsubscribe from the order updates
40
+ */
41
+ subscribeToOrders<T extends boolean>(matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
42
+ getUserOrdersCount(): AsyncResult<number, string>;
43
+ private validateConfig;
44
+ }
@@ -0,0 +1,200 @@
1
+ import { WalletClient } from 'viem';
2
+ import { AsyncResult } from '@catalogfi/utils';
3
+ import { APIResponse, IStore } from '@gardenfi/utils';
4
+ import { Asset, Chain } from '../asset';
5
+ import { IOrderProvider } from '../orders/orders.types';
6
+
7
+ /**
8
+ * Configuration for creating an order
9
+ */
10
+ export interface CreateOrderConfig {
11
+ /**
12
+ * The asset the user wants to send.
13
+ */
14
+ fromAsset: Asset;
15
+ /**
16
+ * The asset the user wants to receive.
17
+ */
18
+ toAsset: Asset;
19
+ /**
20
+ * The address from the which the user is sending funds from.
21
+ */
22
+ sendAddress: string;
23
+ /**
24
+ * The address at which the user wants to receive funds.
25
+ */
26
+ receiveAddress: string;
27
+ /**
28
+ * The input amount the user wants to send in it's lowest denomination
29
+ */
30
+ sendAmount: string;
31
+ /**
32
+ * The amount you receive amount
33
+ */
34
+ receiveAmount: string;
35
+ /**
36
+ * The hash of the secret the user wants to use for the swap.
37
+ */
38
+ secretHash: string;
39
+ /**
40
+ * The time lock for the swap. (current blocknumber + 48 hours)
41
+ * @NOTE 7200 blocks per day in ethereum.
42
+ * @NOTE 144 blocks per day in bitcoin.
43
+ */
44
+ timelock: number;
45
+ /**
46
+ * The nonce for the order.
47
+ * This is used for secret generation.
48
+ */
49
+ nonce: string;
50
+ /**
51
+ * The address of the user's btc wallet. The funds will be sent to this address in case of a redeem or refund.
52
+ * @NOTE This is only required if the destination chain is bitcoin.
53
+ */
54
+ btcInputAddress?: string;
55
+ /**
56
+ * The min number of confirmations required for the user before redeeming in the destination chain.
57
+ * @default 0
58
+ */
59
+ minDestinationConfirmations?: number;
60
+ }
61
+ /**
62
+ * Additional configuration options for the orderbook
63
+ *
64
+ */
65
+ export type OrderbookOpts = {
66
+ /**
67
+ * The domain of your dApp. Optional.
68
+ */
69
+ domain?: string;
70
+ /**
71
+ * The store used for storing the auth token. Optional.
72
+ */
73
+ store?: IStore;
74
+ };
75
+ /**
76
+ * Interface for the configuration of an Orderbook.
77
+ */
78
+ export interface OrderbookConfig {
79
+ url?: string;
80
+ walletClient: WalletClient;
81
+ opts?: OrderbookOpts;
82
+ }
83
+ /**
84
+ * Configuration for the orders you want to receive
85
+ */
86
+ export type OrderConfig = {
87
+ isPending: boolean;
88
+ pagination?: {
89
+ page?: number;
90
+ /**
91
+ * default is 10
92
+ */
93
+ per_page?: number;
94
+ };
95
+ };
96
+ export interface IOrderbook extends IOrderProvider {
97
+ /**
98
+ * Creates an order
99
+ * @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
100
+ * @returns {number} The create order ID.
101
+ */
102
+ createOrder(orderConfig: CreateOrderConfig): AsyncResult<string, string>;
103
+ /**
104
+ * Wrapper for the getOrder method in the OrdersProvider class to abstract the address parameter.
105
+ * @param matched - Whether to get matched or unmatched orders
106
+ * @param paginationConfig - The pagination configuration
107
+ * @param pending - Whether to get pending orders
108
+ * @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>}
109
+ */
110
+ fetchOrders<T extends boolean>(matched: T, pending?: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
111
+ /**
112
+ * Wrapper for the subscribeOrders method in the OrdersProvider class to abstract the address parameter.
113
+ * @param matched - Whether to get matched or unmatched orders
114
+ * @param interval - The interval to poll for updates
115
+ * @param cb - The callback to be called when the orders are updated
116
+ * @param paginationConfig - The configuration for the pagination
117
+ * @returns {() => void} A function to unsubscribe from the order updates
118
+ */
119
+ subscribeToOrders<T extends boolean>(matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, pending?: boolean, paginationConfig?: PaginationConfig): Promise<() => void>;
120
+ /**
121
+ * Get the current orders count associated with the provided address. Used to calculate nonce for secret generation.
122
+ * @returns {AsyncResult<number, string>} A promise that resolves to the orders count.
123
+ */
124
+ getUserOrdersCount(): AsyncResult<number, string>;
125
+ }
126
+ export type DecodedAuthToken = {
127
+ userWallet: string;
128
+ exp: number;
129
+ iat: number;
130
+ };
131
+ export type Orders = {
132
+ unmatched: PaginatedData<CreateOrder[]>;
133
+ matched: PaginatedData<MatchedOrder[]>;
134
+ };
135
+ export type CreateOrderRequest = {
136
+ source_chain: string;
137
+ destination_chain: string;
138
+ source_asset: string;
139
+ destination_asset: string;
140
+ initiator_source_address: string;
141
+ initiator_destination_address: string;
142
+ source_amount: string;
143
+ destination_amount: string;
144
+ fee: string;
145
+ nonce: string;
146
+ min_destination_confirmations: number;
147
+ timelock: number;
148
+ secret_hash: string;
149
+ additional_data?: {
150
+ bitcoin_optional_recipient: string;
151
+ };
152
+ };
153
+ export type CreateOrder = CreateOrderRequest & {
154
+ created_at: string;
155
+ updated_at: string;
156
+ deleted_at: string | null;
157
+ create_id: string;
158
+ block_number: string;
159
+ };
160
+ export type Swap = {
161
+ created_at: string;
162
+ updated_at: string;
163
+ deleted_at: string | null;
164
+ swap_id: string;
165
+ chain: Chain;
166
+ asset: string;
167
+ initiator: string;
168
+ redeemer: string;
169
+ timelock: number;
170
+ filled_amount: string;
171
+ amount: string;
172
+ secret_hash: string;
173
+ secret: string;
174
+ initiate_tx_hash: string;
175
+ redeem_tx_hash: string;
176
+ refund_tx_hash: string;
177
+ initiate_block_number: string | null;
178
+ redeem_block_number: string | null;
179
+ refund_block_number: string | null;
180
+ };
181
+ export type MatchedOrder = {
182
+ created_at: string;
183
+ updated_at: string;
184
+ deleted_at: string | null;
185
+ source_swap: Swap;
186
+ destination_swap: Swap;
187
+ create_order: CreateOrder;
188
+ };
189
+ export type PaginatedData<T> = {
190
+ data: T[];
191
+ page: number;
192
+ total_pages: number;
193
+ total_items: number;
194
+ per_page: number;
195
+ };
196
+ export type CreateOrderResponse = APIResponse<string>;
197
+ export type PaginationConfig = {
198
+ page?: number;
199
+ per_page?: number;
200
+ };