@gardenfi/orderbook 0.2.0-beta.0 → 0.2.0-beta.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 +16 -13
- package/dist/index2.cjs +1 -1
- package/dist/index2.js +41 -96
- package/dist/index3.cjs +1 -1
- package/dist/index3.js +10 -2
- package/dist/index4.cjs +1 -1
- package/dist/index4.js +1 -1
- package/dist/index5.cjs +1 -1
- package/dist/index5.js +46 -16
- package/dist/index6.cjs +1 -1
- package/dist/index6.js +2 -11
- package/dist/index7.cjs +1 -1
- package/dist/index7.js +7 -2
- package/dist/src/index.d.ts +2 -2
- package/dist/src/lib/asset.d.ts +7 -2
- package/dist/src/lib/constants.d.ts +7 -0
- package/dist/src/lib/orderbook/orderbook.d.ts +2 -3
- package/dist/src/lib/orderbook/orderbook.types.d.ts +24 -7
- package/package.json +3 -4
- package/dist/index8.cjs +0 -1
- package/dist/index8.js +0 -9
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index2.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./index2.cjs"),e=require("./index3.cjs"),s=require("./index4.cjs"),t=require("./index5.cjs");exports.Orderbook=r.Orderbook;exports.BlockchainType=e.BlockchainType;exports.Chains=e.Chains;exports.getBlockchainType=e.getBlockchainType;exports.isBitcoin=e.isBitcoin;exports.isEVM=e.isEVM;exports.isMainnet=e.isMainnet;exports.OrdersProvider=s.OrdersProvider;exports.ArbitrumLocalnet=t.ArbitrumLocalnet;exports.EthereumLocalnet=t.EthereumLocalnet;exports.SupportedAssets=t.SupportedAssets;exports.WBTCArbitrumLocalnetAsset=t.WBTCArbitrumLocalnetAsset;exports.WBTCEthereumLocalnetAsset=t.WBTCEthereumLocalnetAsset;exports.bitcoinRegtestAsset=t.bitcoinRegtestAsset;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { Orderbook as
|
|
2
|
-
import { Chains as i, isBitcoin as
|
|
3
|
-
import { OrdersProvider as
|
|
4
|
-
import { ArbitrumLocalnet as
|
|
1
|
+
import { Orderbook as r } from "./index2.js";
|
|
2
|
+
import { BlockchainType as s, Chains as i, getBlockchainType as n, isBitcoin as c, isEVM as a, isMainnet as m } from "./index3.js";
|
|
3
|
+
import { OrdersProvider as l } from "./index4.js";
|
|
4
|
+
import { ArbitrumLocalnet as h, EthereumLocalnet as u, SupportedAssets as B, WBTCArbitrumLocalnetAsset as b, WBTCEthereumLocalnetAsset as d, bitcoinRegtestAsset as f } from "./index5.js";
|
|
5
5
|
export {
|
|
6
|
-
|
|
6
|
+
h as ArbitrumLocalnet,
|
|
7
|
+
s as BlockchainType,
|
|
7
8
|
i as Chains,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
n as
|
|
9
|
+
u as EthereumLocalnet,
|
|
10
|
+
r as Orderbook,
|
|
11
|
+
l as OrdersProvider,
|
|
12
|
+
B as SupportedAssets,
|
|
13
|
+
b as WBTCArbitrumLocalnetAsset,
|
|
14
|
+
d as WBTCEthereumLocalnetAsset,
|
|
15
|
+
f as bitcoinRegtestAsset,
|
|
16
|
+
n as getBlockchainType,
|
|
17
|
+
c as isBitcoin,
|
|
18
|
+
a as isEVM,
|
|
16
19
|
m as isMainnet
|
|
17
20
|
};
|
package/dist/index2.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 s=require("@catalogfi/utils"),d=require("./index6.cjs"),l=require("@gardenfi/utils"),o=require("./index4.cjs");class i extends o.OrdersProvider{constructor(r){const e=new l.Url("/relayer",r.url??d.MAINNET_ORDERBOOK_API);super(e),this.Url=e,this.walletClient=r.walletClient,this.auth=r.auth}static async init(r){return await r.auth.getToken(),new i(r)}async createOrder(r){const e=await this.auth.getToken();if(e.error)return s.Err(e.error);try{const t=await s.Fetcher.post(this.Url.endpoint("create-order"),{body:JSON.stringify(r),headers:{Authorization:l.Authorization(e.val),"Content-Type":"application/json"}});return t.error?s.Err(t.error):t.result?s.Ok(t.result):s.Err("CreateOrder: Unexpected error, result is undefined")}catch(t){return s.Err("CreateOrder:",String(t))}}async fetchOrders(r,e=!1,t){var n;const a=(n=this.walletClient.account)==null?void 0:n.address;return a?r?await super.getMatchedOrders(a,e,t):await super.getUnMatchedOrders(a,t):s.Err("Wallet client does not have an account")}async subscribeToOrders(r,e,t,a,n){var c;const u=(c=this.walletClient.account)==null?void 0:c.address;return u?await super.subscribeOrders(u,r,e,t,a,n):()=>{}}async getUserOrdersCount(){var e;const r=(e=this.walletClient.account)==null?void 0:e.address;return r?super.getOrdersCount(r):s.Err("Wallet client does not have an account")}}exports.Orderbook=i;
|
package/dist/index2.js
CHANGED
|
@@ -1,104 +1,62 @@
|
|
|
1
|
-
import { Err as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import { isBitcoin as _ } from "./index3.js";
|
|
7
|
-
class w extends C {
|
|
1
|
+
import { Err as s, Fetcher as o, Ok as l } from "@catalogfi/utils";
|
|
2
|
+
import { MAINNET_ORDERBOOK_API as d } from "./index6.js";
|
|
3
|
+
import { Url as h, Authorization as O } from "@gardenfi/utils";
|
|
4
|
+
import { OrdersProvider as p } from "./index4.js";
|
|
5
|
+
class c extends p {
|
|
8
6
|
/**
|
|
9
7
|
* Creates an instance of Orderbook. Does not login to the orderbook.
|
|
10
8
|
* @constructor
|
|
11
9
|
* @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
|
|
12
10
|
*/
|
|
13
|
-
constructor(
|
|
14
|
-
|
|
15
|
-
const e = new m(
|
|
11
|
+
constructor(r) {
|
|
12
|
+
const e = new h(
|
|
16
13
|
"/relayer",
|
|
17
|
-
|
|
14
|
+
r.url ?? d
|
|
18
15
|
);
|
|
19
|
-
super(e), this.Url = e, this.walletClient =
|
|
20
|
-
...t.opts,
|
|
21
|
-
store: ((s = t.opts) == null ? void 0 : s.store) || new U()
|
|
22
|
-
});
|
|
16
|
+
super(e), this.Url = e, this.walletClient = r.walletClient, this.auth = r.auth;
|
|
23
17
|
}
|
|
24
18
|
/**
|
|
25
19
|
* Initializes the orderbook as well as logs in the orderbook (fetches the auth token).
|
|
26
20
|
* @param {OrderbookConfig} orderbookConfig - The configuration object for the orderbook.
|
|
27
21
|
*/
|
|
28
|
-
static async init(
|
|
29
|
-
return await new
|
|
30
|
-
new m("/relayer", t.url ?? h),
|
|
31
|
-
t.walletClient,
|
|
32
|
-
t.opts
|
|
33
|
-
).getToken(), new w(t);
|
|
22
|
+
static async init(r) {
|
|
23
|
+
return await r.auth.getToken(), new c(r);
|
|
34
24
|
}
|
|
35
25
|
/**
|
|
36
26
|
* Creates an order
|
|
37
27
|
* @param {CreateOrderConfig} createOrderConfig - The configuration for the creating the order.
|
|
38
28
|
* @returns {string} The create order ID.
|
|
39
29
|
*/
|
|
40
|
-
async createOrder(
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
secretHash: s,
|
|
44
|
-
receiveAmount: n,
|
|
45
|
-
fromAsset: i,
|
|
46
|
-
toAsset: a,
|
|
47
|
-
receiveAddress: o,
|
|
48
|
-
sendAddress: f,
|
|
49
|
-
minDestinationConfirmations: O = 0,
|
|
50
|
-
timelock: S,
|
|
51
|
-
btcInputAddress: E
|
|
52
|
-
} = t, l = this.validateConfig(t);
|
|
53
|
-
if (l.error) return r(l.error);
|
|
54
|
-
const u = await this.auth.getToken();
|
|
55
|
-
if (u.error) return r(u.error);
|
|
56
|
-
const I = {
|
|
57
|
-
additional_data: { bitcoin_optional_recipient: E ?? "" }
|
|
58
|
-
}, N = {
|
|
59
|
-
nonce: t.nonce,
|
|
60
|
-
source_amount: e,
|
|
61
|
-
destination_amount: n,
|
|
62
|
-
source_asset: i.atomicSwapAddress,
|
|
63
|
-
destination_asset: a.atomicSwapAddress,
|
|
64
|
-
secret_hash: y(s),
|
|
65
|
-
source_chain: i.chain,
|
|
66
|
-
destination_chain: a.chain,
|
|
67
|
-
initiator_source_address: f,
|
|
68
|
-
initiator_destination_address: o,
|
|
69
|
-
min_destination_confirmations: O,
|
|
70
|
-
timelock: S,
|
|
71
|
-
...I,
|
|
72
|
-
//signature:''
|
|
73
|
-
fee: "1"
|
|
74
|
-
};
|
|
30
|
+
async createOrder(r) {
|
|
31
|
+
const e = await this.auth.getToken();
|
|
32
|
+
if (e.error) return s(e.error);
|
|
75
33
|
try {
|
|
76
|
-
const
|
|
34
|
+
const t = await o.post(
|
|
77
35
|
this.Url.endpoint("create-order"),
|
|
78
36
|
{
|
|
79
|
-
body: JSON.stringify(
|
|
37
|
+
body: JSON.stringify(r),
|
|
80
38
|
headers: {
|
|
81
|
-
Authorization:
|
|
39
|
+
Authorization: O(e.val),
|
|
82
40
|
"Content-Type": "application/json"
|
|
83
41
|
}
|
|
84
42
|
}
|
|
85
43
|
);
|
|
86
|
-
return
|
|
87
|
-
} catch (
|
|
88
|
-
return
|
|
44
|
+
return t.error ? s(t.error) : t.result ? l(t.result) : s("CreateOrder: Unexpected error, result is undefined");
|
|
45
|
+
} catch (t) {
|
|
46
|
+
return s("CreateOrder:", String(t));
|
|
89
47
|
}
|
|
90
48
|
}
|
|
91
|
-
async fetchOrders(
|
|
92
|
-
var
|
|
93
|
-
const
|
|
94
|
-
return
|
|
95
|
-
|
|
49
|
+
async fetchOrders(r, e = !1, t) {
|
|
50
|
+
var n;
|
|
51
|
+
const a = (n = this.walletClient.account) == null ? void 0 : n.address;
|
|
52
|
+
return a ? r ? await super.getMatchedOrders(
|
|
53
|
+
a,
|
|
96
54
|
e,
|
|
97
|
-
|
|
55
|
+
t
|
|
98
56
|
) : await super.getUnMatchedOrders(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
) :
|
|
57
|
+
a,
|
|
58
|
+
t
|
|
59
|
+
) : s("Wallet client does not have an account");
|
|
102
60
|
}
|
|
103
61
|
/**
|
|
104
62
|
* Wrapper for the subscribeOrders method in the OrdersProvider class to abstract the address parameter.
|
|
@@ -108,38 +66,25 @@ class w extends C {
|
|
|
108
66
|
* @param paginationConfig - The configuration for the pagination
|
|
109
67
|
* @returns {() => void} A function to unsubscribe from the order updates
|
|
110
68
|
*/
|
|
111
|
-
async subscribeToOrders(
|
|
112
|
-
var
|
|
113
|
-
const
|
|
114
|
-
return
|
|
115
|
-
|
|
116
|
-
|
|
69
|
+
async subscribeToOrders(r, e, t, a, n) {
|
|
70
|
+
var u;
|
|
71
|
+
const i = (u = this.walletClient.account) == null ? void 0 : u.address;
|
|
72
|
+
return i ? await super.subscribeOrders(
|
|
73
|
+
i,
|
|
74
|
+
r,
|
|
117
75
|
e,
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
76
|
+
t,
|
|
77
|
+
a,
|
|
78
|
+
n
|
|
121
79
|
) : () => {
|
|
122
80
|
};
|
|
123
81
|
}
|
|
124
82
|
async getUserOrdersCount() {
|
|
125
83
|
var e;
|
|
126
|
-
const
|
|
127
|
-
return
|
|
128
|
-
}
|
|
129
|
-
validateConfig(t) {
|
|
130
|
-
const { sendAmount: e, receiveAmount: s, toAsset: n, fromAsset: i } = t;
|
|
131
|
-
if (n.atomicSwapAddress.toLowerCase() === i.atomicSwapAddress.toLowerCase() && n.chain === i.chain)
|
|
132
|
-
return r(c.SAME_ASSET);
|
|
133
|
-
if (!_(n.chain) && !n.atomicSwapAddress)
|
|
134
|
-
return r(c.INVALID_AS_ADDRESS);
|
|
135
|
-
if (!_(i.chain) && !i.atomicSwapAddress)
|
|
136
|
-
return r(c.INVALID_AS_ADDRESS);
|
|
137
|
-
if (!n.tokenAddress || !i.tokenAddress)
|
|
138
|
-
return r(c.INVALID_TOKEN);
|
|
139
|
-
const a = BigInt(e), o = BigInt(s);
|
|
140
|
-
return e == null || a <= 0n || e.includes(".") ? r(c.INVALID_SEND_AMOUNT) : s == null || o <= 0n || s.includes(".") ? r(c.INVALID_RECEIVE_AMOUNT) : a < o ? r(c.RECEIVE_AMOUNT_GREATER) : A(T);
|
|
84
|
+
const r = (e = this.walletClient.account) == null ? void 0 : e.address;
|
|
85
|
+
return r ? super.getOrdersCount(r) : s("Wallet client does not have an account");
|
|
141
86
|
}
|
|
142
87
|
}
|
|
143
88
|
export {
|
|
144
|
-
|
|
89
|
+
c as Orderbook
|
|
145
90
|
};
|
package/dist/index3.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum:"ethereum",ethereum_arbitrum:"ethereum_arbitrum",ethereum_sepolia:"ethereum_sepolia",arbitrum_localnet:"arbitrum_localnet",ethereum_localnet:"ethereum_localnet"},
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var r=(e=>(e.Bitcoin="Bitcoin",e.EVM="EVM",e))(r||{});const t={bitcoin:"bitcoin",bitcoin_testnet:"bitcoin_testnet",bitcoin_regtest:"bitcoin_regtest",ethereum:"ethereum",ethereum_arbitrum:"ethereum_arbitrum",ethereum_sepolia:"ethereum_sepolia",arbitrum_localnet:"arbitrum_localnet",arbitrum_sepolia:"arbitrum_sepolia",ethereum_localnet:"ethereum_localnet"},n=e=>!(e===t.ethereum_sepolia||e===t.bitcoin_testnet||e===t.bitcoin_regtest||e===t.arbitrum_localnet||e===t.ethereum_localnet||e===t.arbitrum_sepolia),i=e=>e===t.bitcoin||e===t.bitcoin_testnet||e===t.bitcoin_regtest,o=e=>e===t.ethereum||e===t.ethereum_arbitrum||e===t.ethereum_sepolia||e===t.ethereum_localnet||e===t.arbitrum_localnet||e===t.arbitrum_sepolia,u=e=>{if(i(e))return"Bitcoin";if(o(e))return"EVM";throw new Error("Invalid or unsupported chain")};exports.BlockchainType=r;exports.Chains=t;exports.getBlockchainType=u;exports.isBitcoin=i;exports.isEVM=o;exports.isMainnet=n;
|
package/dist/index3.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var r = /* @__PURE__ */ ((e) => (e.Bitcoin = "Bitcoin", e.EVM = "EVM", e))(r || {});
|
|
1
2
|
const t = {
|
|
2
3
|
bitcoin: "bitcoin",
|
|
3
4
|
bitcoin_testnet: "bitcoin_testnet",
|
|
@@ -6,11 +7,18 @@ const t = {
|
|
|
6
7
|
ethereum_arbitrum: "ethereum_arbitrum",
|
|
7
8
|
ethereum_sepolia: "ethereum_sepolia",
|
|
8
9
|
arbitrum_localnet: "arbitrum_localnet",
|
|
10
|
+
arbitrum_sepolia: "arbitrum_sepolia",
|
|
9
11
|
ethereum_localnet: "ethereum_localnet"
|
|
10
|
-
},
|
|
12
|
+
}, u = (e) => !(e === t.ethereum_sepolia || e === t.bitcoin_testnet || e === t.bitcoin_regtest || e === t.arbitrum_localnet || e === t.ethereum_localnet || e === t.arbitrum_sepolia), i = (e) => e === t.bitcoin || e === t.bitcoin_testnet || e === t.bitcoin_regtest, o = (e) => e === t.ethereum || e === t.ethereum_arbitrum || e === t.ethereum_sepolia || e === t.ethereum_localnet || e === t.arbitrum_localnet || e === t.arbitrum_sepolia, n = (e) => {
|
|
13
|
+
if (i(e)) return "Bitcoin";
|
|
14
|
+
if (o(e)) return "EVM";
|
|
15
|
+
throw new Error("Invalid or unsupported chain");
|
|
16
|
+
};
|
|
11
17
|
export {
|
|
18
|
+
r as BlockchainType,
|
|
12
19
|
t as Chains,
|
|
20
|
+
n as getBlockchainType,
|
|
13
21
|
i as isBitcoin,
|
|
14
22
|
o as isEVM,
|
|
15
|
-
|
|
23
|
+
u as isMainnet
|
|
16
24
|
};
|
package/dist/index4.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@catalogfi/utils"),l=require("@gardenfi/utils"),d=require("./
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("@catalogfi/utils"),l=require("@gardenfi/utils"),d=require("./index7.cjs");class O{constructor(s){this.url=new l.Url("/orders",s)}async getOrder(s,c){const t=c?`/id/matched/${s}`:`/id/unmatched/${s}`,n=this.url.endpoint(t);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetOrder: Unexpected error, result is undefined")}catch(e){return r.Err("GetOrder:",String(e))}}async getMatchedOrders(s,c,t){const n=d.ConstructUrl(this.url,`/user/matched/${s}`,{...t,pending:c});try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetMatchedOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetMatchedOrders:",String(e))}}async getUnMatchedOrders(s,c){const t=d.ConstructUrl(this.url,`/user/unmatched/${s}`,c);try{const n=await r.Fetcher.get(t);return n.error?r.Err(n.error):n.result?r.Ok(n.result):r.Err("GetUnMatchedOrders: Unexpected error, result is undefined")}catch(n){return r.Err("GetUnMatchedOrders:",String(n))}}async getOrders(s,c){const t=s?"/matched":"/unmatched",n=d.ConstructUrl(this.url,t,c);try{const e=await r.Fetcher.get(n);return e.error?r.Err(e.error):e.result?r.Ok(e.result):r.Err("GetAllOrders: Unexpected error, result is undefined")}catch(e){return r.Err("GetAllOrders:",String(e))}}async subscribeOrders(s,c,t,n,e=!1,i){let o=!1;const a=async()=>{if(!o){o=!0;try{const u=c?await this.getMatchedOrders(s,e,i):await this.getUnMatchedOrders(s,i);u.ok?await n(u.val):console.error("Error fetching orders:",u.error)}catch(u){console.error("Error fetching orders:",u)}finally{o=!1}}};await a();const h=setInterval(a,t);return()=>{clearInterval(h)}}async getOrdersCount(s){const c=this.url.endpoint(`/user/count/${s}`);try{const t=await r.Fetcher.get(c);return t.error?r.Err(t.error):t.status===l.ApiStatus.Ok&&t.result!==void 0?r.Ok(t.result):r.Err("GetOrdersCount: Unexpected error, result is undefined")}catch(t){return r.Err("GetOrdersCount:",String(t))}}}exports.OrdersProvider=O;
|
package/dist/index4.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fetcher as u, Err as s, Ok as d } from "@catalogfi/utils";
|
|
2
2
|
import { Url as f, ApiStatus as g } from "@gardenfi/utils";
|
|
3
|
-
import { ConstructUrl as i } from "./
|
|
3
|
+
import { ConstructUrl as i } from "./index7.js";
|
|
4
4
|
class w {
|
|
5
5
|
constructor(t) {
|
|
6
6
|
this.url = new f("/orders", t);
|
package/dist/index5.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index3.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index3.cjs"),a={id:31338,name:"Arbitrum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8546/"]}},testnet:!0},n={id:31337,name:"Ethereum Localnet",nativeCurrency:{name:"Ethereum",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["http://localhost:8545/"]}},testnet:!0},r={name:"Bitcoin Regtest",decimals:8,symbol:"BTC",chain:e.Chains.bitcoin_regtest,atomicSwapAddress:"primary",tokenAddress:"primary"},t={name:"WBTC Arbitrum Localnet",decimals:8,symbol:"WBTC",chain:e.Chains.arbitrum_localnet,atomicSwapAddress:"0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",tokenAddress:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"},s={name:"WBTC Ethereum Localnet",decimals:8,symbol:"WBTC",chain:e.Chains.ethereum_localnet,atomicSwapAddress:"0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",tokenAddress:"0x5FbDB2315678afecb367f032d93F642f64180aa3"},c={localnet:{[e.Chains.arbitrum_localnet]:t,[e.Chains.ethereum_localnet]:s},testnet:{[e.Chains.bitcoin_testnet]:{name:"BTC",decimals:8,symbol:"BTC",chain:e.Chains.bitcoin_testnet,tokenAddress:"primary",atomicSwapAddress:"primary"},[e.Chains.ethereum_sepolia]:{name:"WBTC",decimals:8,symbol:"WBTC",chain:e.Chains.ethereum_sepolia,tokenAddress:"0x00ab86f54F436CfE15253845F139955ae0C00bAf",atomicSwapAddress:"0x1cd0bBd55fD66B4C5F7dfE434eFD009C09e628d1"},[e.Chains.arbitrum_sepolia]:{name:"WBTC",decimals:8,symbol:"WBTC",chain:e.Chains.ethereum_sepolia,tokenAddress:"0x4D68da063577F98C55166c7AF6955cF58a97b20A",atomicSwapAddress:"0x3C6a17b8cD92976D1D91E491c93c98cd81998265"}},mainnet:{}};exports.ArbitrumLocalnet=a;exports.EthereumLocalnet=n;exports.SupportedAssets=c;exports.WBTCArbitrumLocalnetAsset=t;exports.WBTCEthereumLocalnetAsset=s;exports.bitcoinRegtestAsset=r;
|
package/dist/index5.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Chains as e } from "./index3.js";
|
|
2
|
-
const
|
|
2
|
+
const c = {
|
|
3
3
|
id: 31338,
|
|
4
4
|
name: "Arbitrum Localnet",
|
|
5
5
|
nativeCurrency: {
|
|
@@ -13,7 +13,7 @@ const a = {
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
testnet: !0
|
|
16
|
-
},
|
|
16
|
+
}, r = {
|
|
17
17
|
id: 31337,
|
|
18
18
|
name: "Ethereum Localnet",
|
|
19
19
|
nativeCurrency: {
|
|
@@ -27,35 +27,65 @@ const a = {
|
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
testnet: !0
|
|
30
|
-
},
|
|
30
|
+
}, n = {
|
|
31
31
|
name: "Bitcoin Regtest",
|
|
32
32
|
decimals: 8,
|
|
33
33
|
symbol: "BTC",
|
|
34
34
|
chain: e.bitcoin_regtest,
|
|
35
35
|
atomicSwapAddress: "primary",
|
|
36
|
-
tokenAddress: "primary"
|
|
37
|
-
|
|
38
|
-
}, n = {
|
|
36
|
+
tokenAddress: "primary"
|
|
37
|
+
}, t = {
|
|
39
38
|
name: "WBTC Arbitrum Localnet",
|
|
40
39
|
decimals: 8,
|
|
41
40
|
symbol: "WBTC",
|
|
42
41
|
chain: e.arbitrum_localnet,
|
|
43
42
|
atomicSwapAddress: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
|
|
44
|
-
tokenAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
|
|
45
|
-
|
|
46
|
-
}, c = {
|
|
43
|
+
tokenAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512"
|
|
44
|
+
}, a = {
|
|
47
45
|
name: "WBTC Ethereum Localnet",
|
|
48
46
|
decimals: 8,
|
|
49
47
|
symbol: "WBTC",
|
|
50
48
|
chain: e.ethereum_localnet,
|
|
51
49
|
atomicSwapAddress: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
|
|
52
|
-
tokenAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
|
|
53
|
-
|
|
50
|
+
tokenAddress: "0x5FbDB2315678afecb367f032d93F642f64180aa3"
|
|
51
|
+
}, m = {
|
|
52
|
+
localnet: {
|
|
53
|
+
[e.arbitrum_localnet]: t,
|
|
54
|
+
[e.ethereum_localnet]: a
|
|
55
|
+
},
|
|
56
|
+
testnet: {
|
|
57
|
+
[e.bitcoin_testnet]: {
|
|
58
|
+
name: "BTC",
|
|
59
|
+
decimals: 8,
|
|
60
|
+
symbol: "BTC",
|
|
61
|
+
chain: e.bitcoin_testnet,
|
|
62
|
+
tokenAddress: "primary",
|
|
63
|
+
atomicSwapAddress: "primary"
|
|
64
|
+
},
|
|
65
|
+
[e.ethereum_sepolia]: {
|
|
66
|
+
name: "WBTC",
|
|
67
|
+
decimals: 8,
|
|
68
|
+
symbol: "WBTC",
|
|
69
|
+
chain: e.ethereum_sepolia,
|
|
70
|
+
tokenAddress: "0x00ab86f54F436CfE15253845F139955ae0C00bAf",
|
|
71
|
+
atomicSwapAddress: "0x1cd0bBd55fD66B4C5F7dfE434eFD009C09e628d1"
|
|
72
|
+
},
|
|
73
|
+
[e.arbitrum_sepolia]: {
|
|
74
|
+
name: "WBTC",
|
|
75
|
+
decimals: 8,
|
|
76
|
+
symbol: "WBTC",
|
|
77
|
+
chain: e.ethereum_sepolia,
|
|
78
|
+
tokenAddress: "0x4D68da063577F98C55166c7AF6955cF58a97b20A",
|
|
79
|
+
atomicSwapAddress: "0x3C6a17b8cD92976D1D91E491c93c98cd81998265"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
mainnet: {}
|
|
54
83
|
};
|
|
55
84
|
export {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
85
|
+
c as ArbitrumLocalnet,
|
|
86
|
+
r as EthereumLocalnet,
|
|
87
|
+
m as SupportedAssets,
|
|
88
|
+
t as WBTCArbitrumLocalnetAsset,
|
|
89
|
+
a as WBTCEthereumLocalnetAsset,
|
|
90
|
+
n as bitcoinRegtestAsset
|
|
61
91
|
};
|
package/dist/index6.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="https://api.garden.finance";exports.MAINNET_ORDERBOOK_API=e;
|
package/dist/index6.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
const
|
|
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
|
-
};
|
|
1
|
+
const n = "https://api.garden.finance";
|
|
11
2
|
export {
|
|
12
|
-
|
|
3
|
+
n as MAINNET_ORDERBOOK_API
|
|
13
4
|
};
|
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 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/index7.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
const
|
|
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;
|
|
6
|
+
};
|
|
2
7
|
export {
|
|
3
|
-
|
|
8
|
+
i as ConstructUrl
|
|
4
9
|
};
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { Orderbook } from './lib/orderbook/orderbook';
|
|
2
2
|
export type * from './lib/orderbook/orderbook.types';
|
|
3
3
|
export type { Chain, EvmChain, Asset } from './lib/asset';
|
|
4
|
-
export { Chains, isMainnet, isBitcoin, isEVM } from './lib/asset';
|
|
4
|
+
export { Chains, BlockchainType, isMainnet, isBitcoin, isEVM, getBlockchainType, } from './lib/asset';
|
|
5
5
|
export { OrdersProvider } from './lib/orders/ordersProvider';
|
|
6
6
|
export type { IOrderProvider } from './lib/orders/orders.types';
|
|
7
|
-
export { WBTCArbitrumLocalnetAsset, WBTCEthereumLocalnetAsset, ArbitrumLocalnet, EthereumLocalnet, bitcoinRegtestAsset, } from './lib/constants';
|
|
7
|
+
export { WBTCArbitrumLocalnetAsset, WBTCEthereumLocalnetAsset, ArbitrumLocalnet, EthereumLocalnet, bitcoinRegtestAsset, SupportedAssets, } from './lib/constants';
|
package/dist/src/lib/asset.d.ts
CHANGED
|
@@ -8,9 +8,12 @@ export type AssetCommon = {
|
|
|
8
8
|
};
|
|
9
9
|
export type AssetToken = AssetCommon & {
|
|
10
10
|
tokenAddress: string;
|
|
11
|
-
isToken: true;
|
|
12
11
|
};
|
|
13
12
|
export type Asset = AssetToken;
|
|
13
|
+
export declare enum BlockchainType {
|
|
14
|
+
Bitcoin = "Bitcoin",
|
|
15
|
+
EVM = "EVM"
|
|
16
|
+
}
|
|
14
17
|
export declare enum NetworkType {
|
|
15
18
|
mainnet = "mainnet",
|
|
16
19
|
testnet = "testnet",
|
|
@@ -34,10 +37,12 @@ export declare const Chains: {
|
|
|
34
37
|
readonly ethereum_arbitrum: "ethereum_arbitrum";
|
|
35
38
|
readonly ethereum_sepolia: "ethereum_sepolia";
|
|
36
39
|
readonly arbitrum_localnet: "arbitrum_localnet";
|
|
40
|
+
readonly arbitrum_sepolia: "arbitrum_sepolia";
|
|
37
41
|
readonly ethereum_localnet: "ethereum_localnet";
|
|
38
42
|
};
|
|
39
43
|
export type Chain = keyof typeof Chains;
|
|
40
44
|
export type EvmChain = keyof Omit<typeof Chains, 'bitcoin' | 'bitcoin_testnet' | 'bitcoin_regtest'>;
|
|
41
45
|
export declare const isMainnet: (chain: Chain) => chain is "bitcoin" | "ethereum" | "ethereum_arbitrum";
|
|
42
46
|
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";
|
|
47
|
+
export declare const isEVM: (chain: Chain) => chain is "ethereum" | "ethereum_arbitrum" | "ethereum_sepolia" | "arbitrum_localnet" | "arbitrum_sepolia" | "ethereum_localnet";
|
|
48
|
+
export declare const getBlockchainType: (chain: Chain) => BlockchainType;
|
|
@@ -6,3 +6,10 @@ export declare const EthereumLocalnet: Chain;
|
|
|
6
6
|
export declare const bitcoinRegtestAsset: Asset;
|
|
7
7
|
export declare const WBTCArbitrumLocalnetAsset: Asset;
|
|
8
8
|
export declare const WBTCEthereumLocalnetAsset: Asset;
|
|
9
|
+
type SupportedAssets = {
|
|
10
|
+
[chain: string]: {
|
|
11
|
+
[asset: string]: Asset;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const SupportedAssets: SupportedAssets;
|
|
15
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncResult } from '@catalogfi/utils';
|
|
2
|
-
import { CreateOrder,
|
|
2
|
+
import { CreateOrder, CreateOrderRequestWithAdditionalData, IOrderbook, MatchedOrder, OrderbookConfig, PaginatedData, PaginationConfig } from './orderbook.types';
|
|
3
3
|
import { OrdersProvider } from '../orders/ordersProvider';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -28,7 +28,7 @@ export declare class Orderbook extends OrdersProvider implements IOrderbook {
|
|
|
28
28
|
* @param {CreateOrderConfig} createOrderConfig - The configuration for the creating the order.
|
|
29
29
|
* @returns {string} The create order ID.
|
|
30
30
|
*/
|
|
31
|
-
createOrder(
|
|
31
|
+
createOrder(order: CreateOrderRequestWithAdditionalData): AsyncResult<string, string>;
|
|
32
32
|
fetchOrders<T extends boolean>(matched: T, pending?: boolean, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
|
|
33
33
|
/**
|
|
34
34
|
* Wrapper for the subscribeOrders method in the OrdersProvider class to abstract the address parameter.
|
|
@@ -40,5 +40,4 @@ export declare class Orderbook extends OrdersProvider implements IOrderbook {
|
|
|
40
40
|
*/
|
|
41
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
42
|
getUserOrdersCount(): AsyncResult<number, string>;
|
|
43
|
-
private validateConfig;
|
|
44
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WalletClient } from 'viem';
|
|
2
2
|
import { AsyncResult } from '@catalogfi/utils';
|
|
3
|
-
import { APIResponse, IStore } from '@gardenfi/utils';
|
|
3
|
+
import { APIResponse, IAuth, IStore } from '@gardenfi/utils';
|
|
4
4
|
import { Asset, Chain } from '../asset';
|
|
5
5
|
import { IOrderProvider } from '../orders/orders.types';
|
|
6
6
|
|
|
@@ -78,7 +78,7 @@ export type OrderbookOpts = {
|
|
|
78
78
|
export interface OrderbookConfig {
|
|
79
79
|
url?: string;
|
|
80
80
|
walletClient: WalletClient;
|
|
81
|
-
|
|
81
|
+
auth: IAuth;
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Configuration for the orders you want to receive
|
|
@@ -99,7 +99,7 @@ export interface IOrderbook extends IOrderProvider {
|
|
|
99
99
|
* @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
|
|
100
100
|
* @returns {number} The create order ID.
|
|
101
101
|
*/
|
|
102
|
-
createOrder(
|
|
102
|
+
createOrder(order: CreateOrderRequestWithAdditionalData): AsyncResult<string, string>;
|
|
103
103
|
/**
|
|
104
104
|
* Wrapper for the getOrder method in the OrdersProvider class to abstract the address parameter.
|
|
105
105
|
* @param matched - Whether to get matched or unmatched orders
|
|
@@ -132,6 +132,25 @@ export type Orders = {
|
|
|
132
132
|
unmatched: PaginatedData<CreateOrder[]>;
|
|
133
133
|
matched: PaginatedData<MatchedOrder[]>;
|
|
134
134
|
};
|
|
135
|
+
export type AdditionalData = {
|
|
136
|
+
additional_data: {
|
|
137
|
+
strategy_id: string;
|
|
138
|
+
sig: string;
|
|
139
|
+
input_token_price: number;
|
|
140
|
+
output_token_price: number;
|
|
141
|
+
deadline: string;
|
|
142
|
+
bitcoin_optional_recipient?: string;
|
|
143
|
+
[key: string]: any;
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
export type AdditionalDataWithStrategyId = {
|
|
147
|
+
additional_data: {
|
|
148
|
+
strategy_id: string;
|
|
149
|
+
bitcoin_optional_recipient?: string;
|
|
150
|
+
[key: string]: any;
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
export type CreateOrderReqWithStrategyId = CreateOrderRequest & AdditionalDataWithStrategyId;
|
|
135
154
|
export type CreateOrderRequest = {
|
|
136
155
|
source_chain: string;
|
|
137
156
|
destination_chain: string;
|
|
@@ -146,11 +165,9 @@ export type CreateOrderRequest = {
|
|
|
146
165
|
min_destination_confirmations: number;
|
|
147
166
|
timelock: number;
|
|
148
167
|
secret_hash: string;
|
|
149
|
-
additional_data?: {
|
|
150
|
-
bitcoin_optional_recipient: string;
|
|
151
|
-
};
|
|
152
168
|
};
|
|
153
|
-
export type
|
|
169
|
+
export type CreateOrderRequestWithAdditionalData = CreateOrderRequest & AdditionalData;
|
|
170
|
+
export type CreateOrder = CreateOrderRequestWithAdditionalData & {
|
|
154
171
|
created_at: string;
|
|
155
172
|
updated_at: string;
|
|
156
173
|
deleted_at: string | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gardenfi/orderbook",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -27,8 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@catalogfi/utils": "^0.1.6",
|
|
30
|
-
"@
|
|
31
|
-
"@gardenfi/utils": "workspace:^",
|
|
30
|
+
"@gardenfi/utils": "^0.0.1-beta.17",
|
|
32
31
|
"bufferutil": "^4.0.8",
|
|
33
32
|
"siwe": "^2.1.4",
|
|
34
33
|
"utf-8-validate": "^6.0.3",
|
|
@@ -44,4 +43,4 @@
|
|
|
44
43
|
"vitest": "^1.6.0"
|
|
45
44
|
},
|
|
46
45
|
"sideEffects": false
|
|
47
|
-
}
|
|
46
|
+
}
|
package/dist/index8.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;
|