@gardenfi/orderbook 2.5.3-beta.0 → 2.5.3-beta.2

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.
@@ -0,0 +1,37 @@
1
+ import { Network } from '@gardenfi/utils';
2
+ import { Config } from './asset';
3
+
4
+ export declare enum BlockchainType {
5
+ bitcoin = "bitcoin",
6
+ evm = "evm",
7
+ solana = "solana",
8
+ starknet = "starknet",
9
+ sui = "sui"
10
+ }
11
+ export type AssetCommon = {
12
+ name: string;
13
+ decimals: number;
14
+ symbol: string;
15
+ chain: Chain;
16
+ logo?: string;
17
+ atomicSwapAddress: string;
18
+ };
19
+ export type AssetToken = AssetCommon & {
20
+ tokenAddress: string;
21
+ };
22
+ export type Asset = AssetToken;
23
+ export type Chain = keyof typeof Config;
24
+ export type ChainsByNetwork<T extends Network> = {
25
+ [K in keyof typeof Config]: (typeof Config)[K]['network'] extends T ? K : never;
26
+ }[keyof typeof Config];
27
+ export type MainnetOnlyChains = ChainsByNetwork<Network.MAINNET>;
28
+ export type TestnetOnlyChains = ChainsByNetwork<Network.TESTNET>;
29
+ export type LocalnetOnlyChains = ChainsByNetwork<Network.LOCALNET>;
30
+ export type ChainsByBlockchainType<T extends BlockchainType> = {
31
+ [K in keyof typeof Config]: (typeof Config)[K]['type'] extends T ? K : never;
32
+ }[keyof typeof Config];
33
+ export type EVMChains = ChainsByBlockchainType<BlockchainType.evm>;
34
+ export type BitcoinChains = ChainsByBlockchainType<BlockchainType.bitcoin>;
35
+ export type SolanaChains = ChainsByBlockchainType<BlockchainType.solana>;
36
+ export type StarknetChains = ChainsByBlockchainType<BlockchainType.starknet>;
37
+ 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,5 +1,6 @@
1
- import { IOrderbook, CreateOrderResponse, Order, PaginatedData, CreateOrderRequest, GetOrderQueryParams } from './orderbook.types';
1
+ import { IOrderbook, CreateOrderResponse, PaginatedData, CreateOrderRequest, GetOrderQueryParams, OrderWithStatus } from './orderbook.types';
2
2
  import { AsyncResult, IAuth, Url, Request } from '@gardenfi/utils';
3
+ import { BlockchainType } from '../constants/asset.types';
3
4
 
4
5
  /**
5
6
  * A class that allows you to create and manage orders with the orderbook url.
@@ -9,9 +10,9 @@ import { AsyncResult, IAuth, Url, Request } from '@gardenfi/utils';
9
10
  export declare class Orderbook implements IOrderbook {
10
11
  private url;
11
12
  constructor(url: Url);
12
- createOrder(order: CreateOrderRequest, auth: IAuth): AsyncResult<CreateOrderResponse, string>;
13
- getOrder(id: string, request?: Request): AsyncResult<Order, string>;
14
- getOrders(queryParams: GetOrderQueryParams, request?: Request): AsyncResult<PaginatedData<Order>, string>;
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>;
15
16
  /**
16
17
  * Subscribe to orders
17
18
  * @param account - The account of the order
@@ -21,5 +22,5 @@ export declare class Orderbook implements IOrderbook {
21
22
  * @param paginationConfig - The pagination configuration
22
23
  * @returns {Promise<() => void>} A promise that resolves to the unsubscribe function.
23
24
  */
24
- subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<Order>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
25
+ subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<OrderWithStatus>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
25
26
  }
@@ -1,5 +1,6 @@
1
1
  import { AsyncResult, IAuth, Request } from '@gardenfi/utils';
2
- import { BlockchainType, Chain, OrderLifecycle } from '../asset';
2
+ import { OrderLifecycle, OrderStatus } from '../constants/asset';
3
+ import { BlockchainType, Chain } from '../constants/asset.types';
3
4
  import { Calldata, RawArgs, TypedData } from 'starknet';
4
5
  import { ChainAsset } from '../chainAsset/chainAsset';
5
6
 
@@ -16,14 +17,14 @@ export interface IOrderbook {
16
17
  * @param id - The create Id of the order
17
18
  * @returns {AsyncResult<Order, string>} A promise that resolves to the order.
18
19
  */
19
- getOrder(id: string, request?: Request): AsyncResult<Order, string>;
20
+ getOrder(id: string, request?: Request): AsyncResult<OrderWithStatus, string>;
20
21
  /**
21
22
  * Get all orders from the orderbook based on the provided filters.
22
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.
23
24
  * @param paginationConfig - The configuration for the pagination.
24
25
  * @returns {AsyncResult<PaginatedData<Order>, string>} A promise that resolves to the orders.
25
26
  */
26
- getOrders(queryParams: GetOrderQueryParams, request?: Request): AsyncResult<PaginatedData<Order>, string>;
27
+ getOrders(queryParams: GetOrderQueryParams, request?: Request): AsyncResult<PaginatedData<OrderWithStatus>, string>;
27
28
  /**
28
29
  * A wrapper around getOrders that polls for every provided interval and returns orders based on the provided filters.
29
30
  * @param {GetOrdersFilters} filters - The filters to get the orders for.
@@ -32,26 +33,28 @@ export interface IOrderbook {
32
33
  * @param {PaginationConfig} paginationConfig - The configuration for the pagination.
33
34
  * @returns {Promise<() => void>} A promise that resolves to a function to unsubscribe from the orders.
34
35
  */
35
- subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<Order>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
36
+ subscribeOrders(queryParams: GetOrderQueryParams, cb: (orders: PaginatedData<OrderWithStatus>) => Promise<void>, interval?: number, request?: Request): Promise<() => void>;
36
37
  }
37
38
  export type GetOrdersFilters = {
38
39
  address?: string;
39
40
  tx_hash?: string;
40
41
  from_chain?: Chain;
41
42
  to_chain?: Chain;
43
+ from_owner?: string;
44
+ to_owner?: string;
42
45
  status?: OrderLifecycle | OrderLifecycle[];
43
46
  [key: string]: string | string[] | number | undefined;
44
47
  };
45
48
  export type GetOrderQueryParams = GetOrdersFilters & PaginationConfig;
46
49
  export type CreateOrderRequest = {
47
50
  source: {
48
- asset: ChainAsset;
51
+ asset: string;
49
52
  owner: string;
50
53
  delegate: string | null;
51
54
  amount: string;
52
55
  };
53
56
  destination: {
54
- asset: ChainAsset;
57
+ asset: string;
55
58
  owner: string;
56
59
  delegate: string | null;
57
60
  amount: string;
@@ -101,6 +104,9 @@ export type Order = {
101
104
  integrator: string;
102
105
  version: string;
103
106
  };
107
+ export type OrderWithStatus = Order & {
108
+ status: OrderStatus;
109
+ };
104
110
  export type AssetHTLCInfo = {
105
111
  id: string;
106
112
  htlc: {
@@ -159,7 +165,7 @@ export type BitcoinOrderResponse = BaseCreateOrderResponse & {
159
165
  amount: number;
160
166
  };
161
167
  type WithTypedData<T, D> = T & {
162
- typed_data: D;
168
+ typed_data: D | null;
163
169
  };
164
170
  type EvmTypedData = {
165
171
  domain: Record<string, unknown>;
@@ -177,19 +183,19 @@ export type StarknetOrderResponse = WithTypedData<BaseCreateOrderResponse & {
177
183
  }, TypedData>;
178
184
  export type SolanaOrderResponse = BaseCreateOrderResponse & {
179
185
  versioned_tx: string;
186
+ versioned_tx_gasless: string | null;
180
187
  };
181
188
  export type SuiOrderResponse = BaseCreateOrderResponse & {
182
189
  ptb_bytes: number[];
183
190
  };
184
- export type CreateOrderResponse = ({
185
- type: BlockchainType.evm;
186
- } & EvmOrderResponse) | ({
187
- type: BlockchainType.bitcoin;
188
- } & BitcoinOrderResponse) | ({
189
- type: BlockchainType.starknet;
190
- } & StarknetOrderResponse) | ({
191
- type: BlockchainType.solana;
192
- } & SolanaOrderResponse) | ({
193
- type: BlockchainType.sui;
194
- } & SuiOrderResponse);
191
+ type OrderResponseMap = {
192
+ [BlockchainType.evm]: EvmOrderResponse;
193
+ [BlockchainType.bitcoin]: BitcoinOrderResponse;
194
+ [BlockchainType.starknet]: StarknetOrderResponse;
195
+ [BlockchainType.solana]: SolanaOrderResponse;
196
+ [BlockchainType.sui]: SuiOrderResponse;
197
+ };
198
+ export type CreateOrderResponse<T extends BlockchainType = BlockchainType> = {
199
+ type: T;
200
+ } & OrderResponseMap[T];
195
201
  export {};
@@ -1,6 +1,6 @@
1
1
  import { Url } from '@gardenfi/utils';
2
2
  import { BaseCreateOrderResponse, CreateOrderResponse, Order, StarknetOrderResponse, EvmOrderResponse, BitcoinOrderResponse, SolanaOrderResponse, SuiOrderResponse } from './orderbook/orderbook.types';
3
- import { BlockchainType } from './asset';
3
+ import { BlockchainType } from './constants/asset.types';
4
4
 
5
5
  /**
6
6
  * Constructs a URL with the given base URL, endpoint and parameters (query params)
@@ -40,7 +40,7 @@ export declare const isOrder: OrderResponseTypeGuard<Order>;
40
40
  * Discriminated union type guard that determines the specific order response type
41
41
  * and returns the appropriate typed response
42
42
  */
43
- export declare function discriminateOrderResponse(response: BaseCreateOrderResponse): CreateOrderResponse | null;
43
+ export declare function discriminateOrderResponse(response: BaseCreateOrderResponse): CreateOrderResponse<BlockchainType.evm> | CreateOrderResponse<BlockchainType.starknet> | CreateOrderResponse<BlockchainType.bitcoin> | CreateOrderResponse<BlockchainType.solana> | CreateOrderResponse<BlockchainType.sui> | null;
44
44
  /**
45
45
  * Utility function to get the blockchain type from an order response
46
46
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/orderbook",
3
- "version": "2.5.3-beta.0",
3
+ "version": "2.5.3-beta.2",
4
4
  "type": "module",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",