@gardenfi/orderbook 2.5.3 → 3.0.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 (44) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.js +56 -28
  3. package/dist/index10.cjs +1 -0
  4. package/dist/index10.js +188 -0
  5. package/dist/index11.cjs +1 -0
  6. package/dist/index11.js +219 -0
  7. package/dist/index12.cjs +1 -0
  8. package/dist/index12.js +31 -0
  9. package/dist/index2.cjs +1 -1
  10. package/dist/index2.js +78 -101
  11. package/dist/index3.cjs +1 -1
  12. package/dist/index3.js +2 -57
  13. package/dist/index4.cjs +1 -1
  14. package/dist/index4.js +925 -392
  15. package/dist/index5.cjs +1 -1
  16. package/dist/index5.js +91 -6
  17. package/dist/index6.cjs +1 -0
  18. package/dist/index6.js +18 -0
  19. package/dist/index7.cjs +1 -0
  20. package/dist/index7.js +46 -0
  21. package/dist/index8.cjs +1 -0
  22. package/dist/index8.js +28 -0
  23. package/dist/index9.cjs +1 -0
  24. package/dist/index9.js +31 -0
  25. package/dist/src/index.d.ts +13 -2
  26. package/dist/src/lib/api.d.ts +1 -1
  27. package/dist/src/lib/asset.d.ts +0 -81
  28. package/dist/src/lib/assetManager/AssetManager.d.ts +82 -0
  29. package/dist/src/lib/assetManager/index.d.ts +2 -0
  30. package/dist/src/lib/assetManager/routeValidator/routeValidator.d.ts +76 -0
  31. package/dist/src/lib/assetManager/types.d.ts +39 -0
  32. package/dist/src/lib/assetManager/utils.d.ts +9 -0
  33. package/dist/src/lib/chainAsset/chainAsset.d.ts +19 -0
  34. package/dist/src/lib/constants/asset.d.ts +2028 -0
  35. package/dist/src/lib/constants/asset.types.d.ts +43 -0
  36. package/dist/src/lib/constants/localnetConstants.d.ts +47 -0
  37. package/dist/src/lib/constants/utils.d.ts +15 -0
  38. package/dist/src/lib/orderStatus/orderStatus.d.ts +14 -0
  39. package/dist/src/lib/orderStatus/status.d.ts +0 -0
  40. package/dist/src/lib/orderbook/orderbook.d.ts +15 -22
  41. package/dist/src/lib/orderbook/orderbook.types.d.ts +150 -214
  42. package/dist/src/lib/utils.d.ts +37 -0
  43. package/package.json +3 -2
  44. package/dist/src/lib/constants.d.ts +0 -374
@@ -0,0 +1,43 @@
1
+ import { Network } from '@gardenfi/utils';
2
+ import { Config } from './asset';
3
+ import { ChainAsset } from '../chainAsset/chainAsset';
4
+
5
+ export declare enum BlockchainType {
6
+ bitcoin = "bitcoin",
7
+ evm = "evm",
8
+ solana = "solana",
9
+ starknet = "starknet",
10
+ sui = "sui"
11
+ }
12
+ export type AddressSchema = {
13
+ address: string;
14
+ schema: string | null;
15
+ };
16
+ export type Asset = {
17
+ id: ChainAsset | string;
18
+ name: string;
19
+ chain: Chain;
20
+ symbol: string;
21
+ icon?: string;
22
+ htlc: AddressSchema | null;
23
+ token: AddressSchema | null;
24
+ decimals: number;
25
+ min_amount?: string;
26
+ max_amount?: string;
27
+ price?: number;
28
+ };
29
+ export type Chain = keyof typeof Config;
30
+ export type ChainsByNetwork<T extends Network> = {
31
+ [K in keyof typeof Config]: (typeof Config)[K]['network'] extends T ? K : never;
32
+ }[keyof typeof Config];
33
+ export type MainnetOnlyChains = ChainsByNetwork<Network.MAINNET>;
34
+ export type TestnetOnlyChains = ChainsByNetwork<Network.TESTNET>;
35
+ export type LocalnetOnlyChains = ChainsByNetwork<Network.LOCALNET>;
36
+ export type ChainsByBlockchainType<T extends BlockchainType> = {
37
+ [K in keyof typeof Config]: (typeof Config)[K]['type'] extends T ? K : never;
38
+ }[keyof typeof Config];
39
+ export type EVMChains = ChainsByBlockchainType<BlockchainType.evm>;
40
+ export type BitcoinChains = ChainsByBlockchainType<BlockchainType.bitcoin>;
41
+ export type SolanaChains = ChainsByBlockchainType<BlockchainType.solana>;
42
+ export type StarknetChains = ChainsByBlockchainType<BlockchainType.starknet>;
43
+ export type SuiChains = ChainsByBlockchainType<BlockchainType.sui>;
@@ -0,0 +1,47 @@
1
+ import { Chain as viemChain } from 'viem';
2
+
3
+ export declare const StarknetLocalnet: viemChain;
4
+ export declare const ArbitrumLocalnet: viemChain;
5
+ export declare const EthereumLocalnet: viemChain;
6
+ export declare const SOLSolanaLocalnetAsset: {
7
+ name: string;
8
+ decimals: number;
9
+ symbol: string;
10
+ atomicSwapAddress: string;
11
+ tokenAddress: string;
12
+ };
13
+ export declare const bitcoinRegtestAsset: {
14
+ name: string;
15
+ decimals: number;
16
+ symbol: string;
17
+ atomicSwapAddress: string;
18
+ tokenAddress: string;
19
+ };
20
+ export declare const WBTCArbitrumLocalnetAsset: {
21
+ name: string;
22
+ decimals: number;
23
+ symbol: string;
24
+ atomicSwapAddress: string;
25
+ tokenAddress: string;
26
+ };
27
+ export declare const WBTCEthereumLocalnetAsset: {
28
+ name: string;
29
+ decimals: number;
30
+ symbol: string;
31
+ atomicSwapAddress: string;
32
+ tokenAddress: string;
33
+ };
34
+ export declare const STRKStarknetLocalnetAsset: {
35
+ name: string;
36
+ decimals: number;
37
+ symbol: string;
38
+ atomicSwapAddress: string;
39
+ tokenAddress: string;
40
+ };
41
+ export declare const ETHStarknetLocalnetAsset: {
42
+ name: string;
43
+ decimals: number;
44
+ symbol: string;
45
+ atomicSwapAddress: string;
46
+ tokenAddress: string;
47
+ };
@@ -0,0 +1,15 @@
1
+ import { Asset } from './asset.types';
2
+
3
+ /** Strip meta keys network & type from a chain object */
4
+ type StripMeta<T> = Omit<T, 'network' | 'type'>;
5
+ type ChainKeyOf<T extends Record<string, any>> = Extract<keyof T, string>;
6
+ type TokenNoChain = Omit<Asset, 'chain'>;
7
+ /** For a chain object T[C], produce a token map where each token is Asset<C> */
8
+ type WithChainForChainObj<ChainObj extends Record<string, TokenNoChain>> = {
9
+ readonly [TokenKey in keyof ChainObj]: Asset;
10
+ };
11
+ export type AssetsType<T extends Record<string, any>> = {
12
+ readonly [C in ChainKeyOf<T>]: WithChainForChainObj<StripMeta<T[C]>>;
13
+ };
14
+ export declare function buildAssetsWithChain<T extends Record<string, any>>(cfg: T): AssetsType<T>;
15
+ export {};
@@ -0,0 +1,14 @@
1
+ import { OrderStatus } from '../constants/asset';
2
+ import { Order } from '../orderbook/orderbook.types';
3
+
4
+ export declare const ParseOrderStatus: (order: Order) => OrderStatus;
5
+ export declare const isDeadlinePassed: (date: Date, tillHours?: number) => boolean;
6
+ export declare const isCompleted: (order: Order) => boolean;
7
+ export declare enum OrderAction {
8
+ Initiate = "Initiate",
9
+ PostRefundSACP = "PostRefundSACP",
10
+ Redeem = "Redeem",
11
+ Refund = "Refund",
12
+ Idle = "Idle"
13
+ }
14
+ export declare const parseAction: (order: Order) => OrderAction.Redeem | OrderAction.Idle;
File without changes
@@ -1,6 +1,6 @@
1
- import { CreateOrder, CreateOrderReqWithStrategyId, IOrderbook, MatchedOrder, OrderStatus, PaginatedData, PaginationConfig, Status } from './orderbook.types';
2
- import { AsyncResult, IAuth, Url, Request as UtilsRequest } from '@gardenfi/utils';
3
- import { Chain } from '../asset';
1
+ import { IOrderbook, CreateOrderResponse, PaginatedData, CreateOrderRequest, GetOrderQueryParams, OrderWithStatus } from './orderbook.types';
2
+ import { AsyncResult, IAuth, Url, Request } from '@gardenfi/utils';
3
+ import { BlockchainType } from '../constants/asset.types';
4
4
 
5
5
  /**
6
6
  * A class that allows you to create and manage orders with the orderbook url.
@@ -8,26 +8,19 @@ import { Chain } from '../asset';
8
8
  * @implements {IOrderbook}
9
9
  */
10
10
  export declare class Orderbook implements IOrderbook {
11
- private Url;
11
+ private url;
12
12
  constructor(url: Url);
13
+ createOrder<T extends BlockchainType>(order: CreateOrderRequest, auth: IAuth): AsyncResult<CreateOrderResponse<T>, string>;
14
+ getOrder(id: string, request?: Request): AsyncResult<OrderWithStatus, string>;
15
+ getOrders(queryParams: GetOrderQueryParams, request?: Request): AsyncResult<PaginatedData<OrderWithStatus>, string>;
13
16
  /**
14
- * Creates an order
15
- * @param {CreateOrderRequestWithAdditionalData} order - The configuration for the creating the order.
16
- * @param {IAuth} auth - The auth object.
17
- * @returns {string} The create order ID.
17
+ * Subscribe to orders
18
+ * @param account - The account of the order
19
+ * @param interval - The interval of the order
20
+ * @param cb - The callback function
21
+ * @param status - The status of the order
22
+ * @param paginationConfig - The pagination configuration
23
+ * @returns {Promise<() => void>} A promise that resolves to the unsubscribe function.
18
24
  */
19
- createOrder(order: CreateOrderReqWithStrategyId, auth: IAuth): AsyncResult<MatchedOrder, string>;
20
- getOrder<T extends boolean>(id: string, matched: T, request?: UtilsRequest): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
21
- getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<MatchedOrder>, string>;
22
- getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<CreateOrder>, string>;
23
- getOrders<T extends boolean>(matched: T, filters: {
24
- address?: string;
25
- tx_hash?: string;
26
- from_chain?: Chain;
27
- to_chain?: Chain;
28
- status?: OrderStatus | OrderStatus[];
29
- [key: string]: string | string[] | undefined;
30
- }, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
31
- subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig, request?: UtilsRequest): Promise<() => void>;
32
- getOrdersCount(address: string, request?: UtilsRequest): AsyncResult<number, string>;
25
+ subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<OrderWithStatus>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
33
26
  }
@@ -1,223 +1,69 @@
1
- import { APIResponse, AsyncResult, IAuth, IStore, Request as UtilsRequest } from '@gardenfi/utils';
2
- import { Asset, Chain } from '../asset';
1
+ import { AsyncResult, IAuth, Request } from '@gardenfi/utils';
2
+ import { OrderLifecycle, OrderStatus } from '../constants/asset';
3
+ import { BlockchainType, Chain } from '../constants/asset.types';
4
+ import { Calldata, RawArgs, TypedData } from 'starknet';
5
+ import { ChainAsset } from '../chainAsset/chainAsset';
3
6
 
4
- /**
5
- * Configuration for creating an order
6
- */
7
- export interface CreateOrderConfig {
8
- /**
9
- * The asset the user wants to send.
10
- */
11
- fromAsset: Asset;
12
- /**
13
- * The asset the user wants to receive.
14
- */
15
- toAsset: Asset;
16
- /**
17
- * The address from the which the user is sending funds from.
18
- */
19
- sendAddress: string;
20
- /**
21
- * The address at which the user wants to receive funds.
22
- */
23
- receiveAddress: string;
24
- /**
25
- * The input amount the user wants to send in it's lowest denomination
26
- */
27
- sendAmount: string;
28
- /**
29
- * The amount you receive amount
30
- */
31
- receiveAmount: string;
32
- /**
33
- * The hash of the secret the user wants to use for the swap.
34
- */
35
- secretHash: string;
36
- /**
37
- * The time lock for the swap. (current blocknumber + 48 hours)
38
- * @NOTE 7200 blocks per day in ethereum.
39
- * @NOTE 144 blocks per day in bitcoin.
40
- */
41
- timelock: number;
42
- /**
43
- * The nonce for the order.
44
- * This is used for secret generation.
45
- */
46
- nonce: string;
47
- /**
48
- * The address of the user's btc wallet. The funds will be sent to this address in case of a redeem or refund.
49
- * @NOTE This is only required if the destination chain is bitcoin.
50
- */
51
- btcInputAddress?: string;
52
- /**
53
- * The min number of confirmations required for the user before redeeming in the destination chain.
54
- * @default 0
55
- */
56
- minDestinationConfirmations?: number;
57
- }
58
- /**
59
- * Additional configuration options for the orderbook
60
- *
61
- */
62
- export type OrderbookOpts = {
63
- /**
64
- * The domain of your dApp. Optional.
65
- */
66
- domain?: string;
67
- /**
68
- * The store used for storing the auth token. Optional.
69
- */
70
- store?: IStore;
71
- };
72
- /**
73
- * Configuration for the orders you want to receive
74
- */
75
- export type OrderConfig = {
76
- isPending: boolean;
77
- pagination?: {
78
- page?: number;
79
- /**
80
- * default is 10
81
- */
82
- per_page?: number;
83
- };
84
- };
85
7
  export interface IOrderbook {
86
8
  /**
87
9
  * Creates an order
88
- * @param {CreateOrderConfig} orderConfig - The configuration for the creating the order.
89
- * @returns {number} The create order ID.
10
+ * @param {CreateOrderRequest} order - The configuration for the creating the order.
11
+ * @param {IAuth} auth - The auth object.
12
+ * @returns {CreateOrderResponse} The create order ID.
90
13
  */
91
- createOrder(order: CreateOrderReqWithStrategyId, auth: IAuth): AsyncResult<MatchedOrder, string>;
14
+ createOrder(order: CreateOrderRequest, auth: IAuth): AsyncResult<CreateOrderResponse, string>;
92
15
  /**
93
- * Get the order from orderbook based on provided Id and match status.
16
+ * Get the order from orderbook based on provided Id.
94
17
  * @param id - The create Id of the order
95
- * @template T - If true, returns matched order, else returns create order (unmatched Order).
96
- * @returns {AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>} A promise that resolves to the order.
97
- */
98
- getOrder<T extends boolean>(id: string, matched: T): AsyncResult<T extends true ? MatchedOrder : CreateOrder, string>;
99
- /**
100
- * Get all matched orders from the orderbook associated with the `address`.
101
- * @param address The address to get the orders for.
102
- * @param pending If true, returns pending orders, else returns all matched orders.
103
- * @param paginationConfig - The configuration for the pagination.
104
- * @returns {AsyncResult<PaginatedData<MatchedOrder>, string>} A promise that resolves to the orders.
105
- */
106
- getMatchedOrders(address: string, status: Status, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<MatchedOrder>, string>;
107
- /**
108
- * Get all unmatched orders from the orderbook associated with the `address`.
109
- * @param address The address to get the orders for.
110
- * @param paginationConfig - The configuration for the pagination.
111
- * @returns {AsyncResult<PaginatedData<CreateOrder>, string>} A promise that resolves to the orders.
18
+ * @returns {AsyncResult<Order, string>} A promise that resolves to the order.
112
19
  */
113
- getUnMatchedOrders(address: string, paginationConfig?: PaginationConfig): AsyncResult<PaginatedData<CreateOrder>, string>;
20
+ getOrder(id: string, request?: Request): AsyncResult<OrderWithStatus, string>;
114
21
  /**
115
- * Get all orders from the orderbook based on the match status.
116
- * @param matched - If true, returns matched orders, else returns unmatched orders.
117
- * @param filters - Object containing filter parameters like: `address`, `tx_hash`, `from_chain`, `to_chain`, `status` and any additional key-value pairs for query parameters.
22
+ * Get all orders from the orderbook based on the provided filters.
23
+ * @param {GetOrdersFilters} filters - Object containing filter parameters like: `address`, `tx_hash`, `from_chain`, `to_chain`, `status` and any additional key-value pairs for query parameters.
118
24
  * @param paginationConfig - The configuration for the pagination.
119
- * @param request - Optional request configuration.
120
- * @returns {AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>} A promise that resolves to the orders.
25
+ * @returns {AsyncResult<PaginatedData<Order>, string>} A promise that resolves to the orders.
121
26
  */
122
- getOrders<T extends boolean>(matched: T, filters: {
123
- address?: string;
124
- tx_hash?: string;
125
- from_chain?: Chain;
126
- to_chain?: Chain;
127
- status?: OrderStatus;
128
- [key: string]: string | undefined;
129
- }, paginationConfig?: PaginationConfig, request?: UtilsRequest): AsyncResult<PaginatedData<T extends true ? MatchedOrder : CreateOrder>, string>;
27
+ getOrders(queryParams: GetOrderQueryParams, request?: Request): AsyncResult<PaginatedData<OrderWithStatus>, string>;
130
28
  /**
131
- * Polls for every provided interval and returns matched and unmatched orders associated on the account.
132
- * @param account The account to subscribe to
133
- * @param matched If true, returns matched orders, else returns unmatched orders
134
- * @param cb Th ack to be called when the orders are updated
135
- * @param interval The interval to poll for updates
136
- *
137
- * Example usage:
138
- *
139
- * ```js
140
- * const unsubscribe =await orderbook.subscribeOrders(account, matched, interval, handleOrders, paginationConfig);
141
- *
142
- * // Unsubscribe after 20 seconds
143
- * setTimeout(() => {
144
- * unsubscribe();
145
- * console.log('Unsubscribed from orders');
146
- * }, 20000);
147
- * ```
29
+ * A wrapper around getOrders that polls for every provided interval and returns orders based on the provided filters.
30
+ * @param {GetOrdersFilters} filters - The filters to get the orders for.
31
+ * @param {function} cb - The callback to be called when the orders are updated.
32
+ * @param {number} interval - The interval to poll for updates. Default is 5000ms.
33
+ * @param {PaginationConfig} paginationConfig - The configuration for the pagination.
34
+ * @returns {Promise<() => void>} A promise that resolves to a function to unsubscribe from the orders.
148
35
  */
149
- subscribeOrders<T extends boolean>(account: string, matched: T, interval: number, cb: (orders: PaginatedData<T extends true ? MatchedOrder : CreateOrder>) => Promise<void>, status?: Status, paginationConfig?: PaginationConfig): Promise<() => void>;
150
- /**
151
- * Returns the current orders count associated with the provided address. Used to calculate nonce for secret generation.
152
- * @param address The address to get the orders count for.
153
- * @returns {AsyncResult<number, string>} A promise that resolves to the orders count.
154
- */
155
- getOrdersCount(address: string): AsyncResult<number, string>;
36
+ subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<OrderWithStatus>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
156
37
  }
157
- export type DecodedAuthToken = {
158
- userWallet: string;
159
- exp: number;
160
- iat: number;
161
- };
162
- export type Orders = {
163
- unmatched: PaginatedData<CreateOrder[]>;
164
- matched: PaginatedData<MatchedOrder[]>;
38
+ export type GetOrdersFilters = {
39
+ address?: string;
40
+ tx_hash?: string;
41
+ from_chain?: Chain;
42
+ to_chain?: Chain;
43
+ from_owner?: string;
44
+ to_owner?: string;
45
+ status?: OrderLifecycle | OrderLifecycle[];
46
+ [key: string]: string | string[] | number | undefined;
165
47
  };
166
- export type AdditionalData = {
167
- additional_data: {
168
- strategy_id: string;
169
- sig: string;
170
- input_token_price: number;
171
- output_token_price: number;
172
- deadline: number;
173
- bitcoin_optional_recipient?: string;
174
- [key: string]: any;
48
+ export type GetOrderQueryParams = GetOrdersFilters & PaginationConfig;
49
+ export type CreateOrderRequest = {
50
+ source: {
51
+ asset: string;
52
+ owner: string;
53
+ delegate: string | null;
54
+ amount: string;
175
55
  };
176
- };
177
- export type AdditionalDataWithStrategyId = {
178
- additional_data: {
179
- strategy_id: string;
180
- bitcoin_optional_recipient?: string;
181
- [key: string]: any;
56
+ destination: {
57
+ asset: string;
58
+ owner: string;
59
+ delegate: string | null;
60
+ amount: string;
182
61
  };
183
- };
184
- export type CreateOrderReqWithStrategyId = CreateOrderRequest & AdditionalDataWithStrategyId & AffiliateFeeList<AffiliateFee>;
185
- export type AffiliateFee = {
186
- fee: number;
187
- address: string;
188
- chain: string;
189
- asset: string;
190
- };
191
- export type AffiliateFeeWithAmount = AffiliateFee & {
192
- amount: string;
193
- };
194
- export type AffiliateFeeList<T extends AffiliateFee | AffiliateFeeWithAmount> = {
195
- affiliate_fees?: T[];
196
- };
197
- export type AffiliateFeeOptionalChainAsset = Omit<AffiliateFee, 'chain' | 'asset'> & Partial<Pick<AffiliateFee, 'chain' | 'asset'>>;
198
- export type CreateOrderRequest = {
199
- source_chain: string;
200
- destination_chain: string;
201
- source_asset: string;
202
- destination_asset: string;
203
- source_amount: string;
204
- destination_amount: string;
205
- nonce: string;
206
- initiator_source_address?: string;
207
- initiator_destination_address?: string;
62
+ solver_id: string;
63
+ slippage?: number;
208
64
  secret_hash?: string;
209
- };
210
- export type CreateOrderRequestWithAdditionalData = CreateOrderRequest & AdditionalData & AffiliateFeeList<AffiliateFeeWithAmount>;
211
- export type CreateOrder = CreateOrderRequestWithAdditionalData & {
212
- fee: string;
213
- min_destination_confirmations: number;
214
- timelock: number;
215
- created_at: string;
216
- updated_at: string;
217
- deleted_at: string | null;
218
- create_id: string;
219
- block_number: string;
220
- user_id: string;
65
+ nonce: number;
66
+ affiliate_fees?: AffiliateFee[];
221
67
  };
222
68
  export type Swap = {
223
69
  created_at: string;
@@ -226,8 +72,6 @@ export type Swap = {
226
72
  swap_id: string;
227
73
  chain: Chain;
228
74
  asset: string;
229
- htlc_address: string;
230
- token_address: string;
231
75
  initiator: string;
232
76
  redeemer: string;
233
77
  timelock: number;
@@ -242,18 +86,42 @@ export type Swap = {
242
86
  redeem_block_number: string | null;
243
87
  refund_block_number: string | null;
244
88
  required_confirmations: number;
89
+ delegate: string;
90
+ asset_price: number;
91
+ instant_refund_tx: string;
92
+ initiate_timestamp: string;
93
+ redeem_timestamp: string;
94
+ refund_timestamp: string;
245
95
  current_confirmations: number;
246
- initiate_timestamp: string | null;
247
- redeem_timestamp: string | null;
248
- refund_timestamp: string | null;
249
96
  };
250
- export type MatchedOrder = {
97
+ export type Order = {
98
+ order_id: string;
251
99
  created_at: string;
252
- updated_at: string;
253
- deleted_at: string | null;
254
100
  source_swap: Swap;
255
101
  destination_swap: Swap;
256
- create_order: CreateOrder;
102
+ slippage: number;
103
+ nonce: string;
104
+ affiliate_fees: AffiliateFee[];
105
+ integrator: string;
106
+ version: string;
107
+ };
108
+ export type OrderWithStatus = Order & {
109
+ status: OrderStatus;
110
+ };
111
+ export type AssetHTLCInfo = {
112
+ id: string;
113
+ htlc: {
114
+ address: string;
115
+ schema: string;
116
+ } | null;
117
+ token: {
118
+ address: string;
119
+ schema: string;
120
+ } | null;
121
+ decimals: number;
122
+ min_amount: string;
123
+ max_amount: string;
124
+ price: number;
257
125
  };
258
126
  export type PaginatedData<T> = {
259
127
  data: T[];
@@ -262,10 +130,78 @@ export type PaginatedData<T> = {
262
130
  total_items: number;
263
131
  per_page: number;
264
132
  };
265
- export type CreateOrderResponse = APIResponse<MatchedOrder>;
266
133
  export type PaginationConfig = {
267
134
  page?: number;
268
135
  per_page?: number;
269
136
  };
270
- export type Status = 'all' | 'pending' | 'fulfilled';
271
- export type OrderStatus = 'refunded' | 'expired' | 'completed' | 'in-progress' | 'not-initiated';
137
+ export type AffiliateFee = {
138
+ address: string;
139
+ asset: ChainAsset;
140
+ fee: number;
141
+ };
142
+ export type AffiliateFeeWithAmount = AffiliateFee & {
143
+ amount: string;
144
+ };
145
+ export type AffiliateFeeList<T extends AffiliateFee | AffiliateFeeWithAmount> = {
146
+ affiliate_fees?: T[];
147
+ };
148
+ export type AffiliateFeeOptionalAsset = Omit<AffiliateFee, 'asset'> & Partial<Pick<AffiliateFee, 'asset'>>;
149
+ export type EVMTransaction = {
150
+ to: string;
151
+ value: string;
152
+ data: string;
153
+ gas_limit: string;
154
+ chain_id: number;
155
+ };
156
+ export type StarknetCall = {
157
+ to: string;
158
+ calldata?: RawArgs | Calldata;
159
+ selector?: string;
160
+ };
161
+ export type BaseCreateOrderResponse = {
162
+ order_id: string;
163
+ };
164
+ export type BitcoinOrderResponse = BaseCreateOrderResponse & {
165
+ to: string;
166
+ amount: number;
167
+ };
168
+ type WithTypedData<T, D> = T & {
169
+ typed_data: D | null;
170
+ };
171
+ type EvmTypedData = {
172
+ domain: Record<string, unknown>;
173
+ types: Record<string, unknown>;
174
+ primaryType: string;
175
+ message: {
176
+ amount: string;
177
+ secretHash: string;
178
+ timelock: string;
179
+ redeemer: string;
180
+ };
181
+ };
182
+ export type EvmOrderResponse = WithTypedData<BaseCreateOrderResponse & {
183
+ approval_transaction: EVMTransaction | null;
184
+ initiate_transaction: EVMTransaction;
185
+ }, EvmTypedData>;
186
+ export type StarknetOrderResponse = WithTypedData<BaseCreateOrderResponse & {
187
+ approval_transaction: StarknetCall;
188
+ initiate_transaction: StarknetCall;
189
+ }, TypedData>;
190
+ export type SolanaOrderResponse = BaseCreateOrderResponse & {
191
+ versioned_tx: string;
192
+ versioned_tx_gasless: string | null;
193
+ };
194
+ export type SuiOrderResponse = BaseCreateOrderResponse & {
195
+ ptb_bytes: number[];
196
+ };
197
+ type OrderResponseMap = {
198
+ [BlockchainType.evm]: EvmOrderResponse;
199
+ [BlockchainType.bitcoin]: BitcoinOrderResponse;
200
+ [BlockchainType.starknet]: StarknetOrderResponse;
201
+ [BlockchainType.solana]: SolanaOrderResponse;
202
+ [BlockchainType.sui]: SuiOrderResponse;
203
+ };
204
+ export type CreateOrderResponse<T extends BlockchainType = BlockchainType> = {
205
+ type: T;
206
+ } & OrderResponseMap[T];
207
+ export {};
@@ -1,4 +1,6 @@
1
1
  import { Url } from '@gardenfi/utils';
2
+ import { BaseCreateOrderResponse, CreateOrderResponse, Order, StarknetOrderResponse, EvmOrderResponse, BitcoinOrderResponse, SolanaOrderResponse, SuiOrderResponse } from './orderbook/orderbook.types';
3
+ import { BlockchainType } from './constants/asset.types';
2
4
 
3
5
  /**
4
6
  * Constructs a URL with the given base URL, endpoint and parameters (query params)
@@ -9,3 +11,38 @@ import { Url } from '@gardenfi/utils';
9
11
  export declare const ConstructUrl: (baseUrl: Url, endPoint: string, params?: {
10
12
  [key: string]: string | string[] | number | boolean | undefined;
11
13
  }) => URL;
14
+ type OrderResponseTypeGuard<T> = (response: any) => response is T;
15
+ /**
16
+ * Type guard for EVM order responses
17
+ */
18
+ export declare const isEvmOrderResponse: OrderResponseTypeGuard<EvmOrderResponse>;
19
+ /**
20
+ * Type guard for Starknet order responses
21
+ */
22
+ export declare const isStarknetOrderResponse: OrderResponseTypeGuard<StarknetOrderResponse>;
23
+ /**
24
+ * Type guard for Bitcoin order responses
25
+ */
26
+ export declare const isBitcoinOrderResponse: OrderResponseTypeGuard<BitcoinOrderResponse>;
27
+ /**
28
+ * Type guard for Solana order responses
29
+ */
30
+ export declare const isSolanaOrderResponse: OrderResponseTypeGuard<SolanaOrderResponse>;
31
+ /**
32
+ * Type guard for Sui order responses
33
+ */
34
+ export declare const isSuiOrderResponse: OrderResponseTypeGuard<SuiOrderResponse>;
35
+ /**
36
+ * Type guard for Order objects (matched orders)
37
+ */
38
+ export declare const isOrder: OrderResponseTypeGuard<Order>;
39
+ /**
40
+ * Discriminated union type guard that determines the specific order response type
41
+ * and returns the appropriate typed response
42
+ */
43
+ export declare function discriminateOrderResponse(response: BaseCreateOrderResponse): CreateOrderResponse<BlockchainType.evm> | CreateOrderResponse<BlockchainType.starknet> | CreateOrderResponse<BlockchainType.bitcoin> | CreateOrderResponse<BlockchainType.solana> | CreateOrderResponse<BlockchainType.sui> | null;
44
+ /**
45
+ * Utility function to get the blockchain type from an order response
46
+ */
47
+ export declare function getOrderResponseType(response: any): BlockchainType | null;
48
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.5.3",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
@@ -28,8 +28,9 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@coral-xyz/anchor": "^0.31.1",
31
- "@gardenfi/utils": "2.5.3",
31
+ "@gardenfi/utils": "3.0.0",
32
32
  "bufferutil": "^4.0.8",
33
+ "node-cache": "^5.1.2",
33
34
  "siwe": "^2.1.4",
34
35
  "utf-8-validate": "^6.0.3",
35
36
  "ws": "^8.14.2"