@gardenfi/core 0.2.0-beta.5 → 0.2.0-beta.50

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.
@@ -48,6 +48,7 @@ export type GardenEvents = {
48
48
  error: (order: MatchedOrder, error: string) => void;
49
49
  success: (order: MatchedOrder, action: OrderActions, result: string) => void;
50
50
  onPendingOrdersChanged: (orders: MatchedOrder[]) => void;
51
+ log: (id: string, message: string) => void;
51
52
  };
52
53
  export type EventCallback = (...args: any[]) => void;
53
54
  export interface IGardenJS {
@@ -68,12 +69,12 @@ export interface IGardenJS {
68
69
  export type OrderCacheValue = {
69
70
  txHash: string;
70
71
  timeStamp: number;
72
+ btcRedeemUTXO?: string;
71
73
  };
72
- export interface IOrderCache {
73
- getOrder(): MatchedOrder;
74
- set(action: OrderActions, txHash: string): void;
75
- get(action: OrderActions): OrderCacheValue | null;
76
- remove(action: OrderActions): void;
74
+ export interface IOrderExecutorCache {
75
+ set(order: MatchedOrder, action: OrderActions, txHash: string, utxo?: string): void;
76
+ get(order: MatchedOrder, action: OrderActions): OrderCacheValue | null;
77
+ remove(order: MatchedOrder, action: OrderActions): void;
77
78
  }
78
79
  /**
79
80
  * Actions that can be performed on the order.
@@ -26,3 +26,4 @@ export declare const ParseSwapStatus: (swap: Swap, currentBlockNumber: number) =
26
26
  * @returns {OrderActions} The action to be performed on the order
27
27
  */
28
28
  export declare const parseAction: (order: MatchedOrder, sourceChainCurrentBlockNumber: number, destChainCurrentBlockNumber: number) => OrderActions;
29
+ export declare const isExpired: (unixTime: number, tillHours?: number) => boolean;
@@ -1,5 +1,5 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
- import { IQuote, QuoteResponse } from './quote.types';
2
+ import { IQuote, QuoteResponse, Strategies } from './quote.types';
3
3
  import { CreateOrderRequestWithAdditionalData, CreateOrderReqWithStrategyId } from '@gardenfi/orderbook';
4
4
 
5
5
  export declare class Quote implements IQuote {
@@ -7,4 +7,5 @@ export declare class Quote implements IQuote {
7
7
  constructor(quoteUrl: string);
8
8
  getQuote(orderpair: string, amount: number, isExactOut?: boolean): Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<QuoteResponse, never>>;
9
9
  getAttestedQuote(order: CreateOrderReqWithStrategyId): AsyncResult<CreateOrderRequestWithAdditionalData, string>;
10
+ getStrategies(): Promise<import('@catalogfi/utils').Result<never, string> | import('@catalogfi/utils').Result<Strategies, never>>;
10
11
  }
@@ -1,5 +1,6 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
- import { CreateOrderRequestWithAdditionalData, CreateOrderReqWithStrategyId } from '@gardenfi/orderbook';
2
+ import { Chain, CreateOrderRequestWithAdditionalData, CreateOrderReqWithStrategyId } from '@gardenfi/orderbook';
3
+ import { APIResponse } from '@gardenfi/utils';
3
4
 
4
5
  export interface IQuote {
5
6
  /**
@@ -19,6 +20,11 @@ export interface IQuote {
19
20
  * @returns {string} The attestation signature
20
21
  */
21
22
  getAttestedQuote(order: CreateOrderReqWithStrategyId): AsyncResult<CreateOrderRequestWithAdditionalData, string>;
23
+ /**
24
+ * Get the strategies available for quoting
25
+ * @returns {Strategies} The strategies available
26
+ */
27
+ getStrategies(): AsyncResult<Strategies, string>;
22
28
  }
23
29
  export type QuoteResponse = {
24
30
  quotes: {
@@ -27,3 +33,27 @@ export type QuoteResponse = {
27
33
  input_token_price: number;
28
34
  output_token_price: number;
29
35
  };
36
+ export type Strategies = Record<string, {
37
+ id: string;
38
+ minAmount: string;
39
+ maxAmount: string;
40
+ }>;
41
+ export type StrategiesResponse = APIResponse<{
42
+ [strategy: string]: {
43
+ id: string;
44
+ min_amount: string;
45
+ max_amount: string;
46
+ source_chain: Chain;
47
+ dest_chain: Chain;
48
+ source_asset: {
49
+ asset: string;
50
+ token_id: string;
51
+ decimals: number;
52
+ };
53
+ dest_asset: {
54
+ asset: string;
55
+ token_id: string;
56
+ decimals: number;
57
+ };
58
+ };
59
+ }>;
@@ -85,11 +85,13 @@ export declare enum OrderStatus {
85
85
  CounterPartyRefunded = "CounterPartyRefunded",
86
86
  /**
87
87
  * - Order is cancelled
88
- * - There are some cases where the order is cancelled:
89
- * 1) Not matched within 1 hour.
90
- * 2) Both parties refund.
91
88
  */
92
- Cancelled = "Cancelled"
89
+ Cancelled = "Cancelled",
90
+ /**
91
+ * - DeadLine exceeded
92
+ * - Initiate not detected before 1 hour of deadline or initiate not confirmed before 12 hours of deadline
93
+ */
94
+ DeadLineExceeded = "DeadLineExceeded"
93
95
  }
94
96
  export declare enum SwapStatus {
95
97
  /**
@@ -2,6 +2,7 @@ import { Chain as viemChain } from 'viem/chains';
2
2
  import { IBaseWallet } from '@catalogfi/wallets';
3
3
  import { Chain, EvmChain } from '@gardenfi/orderbook';
4
4
  import { WalletClient } from 'viem';
5
+ import { AsyncResult } from '@catalogfi/utils';
5
6
 
6
7
  export declare const computeSecret: (fromChain: Chain, toChain: Chain, wallets: Partial<Record<Chain, IBaseWallet>>, nonce: number) => Promise<string>;
7
8
  export declare const isFromChainBitcoin: (chain: Chain) => chain is "bitcoin" | "bitcoin_testnet" | "bitcoin_regtest";
@@ -11,11 +12,11 @@ export declare const isFromChainBitcoin: (chain: Chain) => chain is "bitcoin" |
11
12
  export declare function xOnlyPubkey(pubkey: Buffer | string): Buffer;
12
13
  export declare function assert(condition: boolean, message: string): void;
13
14
  /**
14
- * concats the leaf version, the length of the script, and the script itself
15
+ * concat the leaf version, the length of the script, and the script itself
15
16
  */
16
17
  export declare function serializeScript(leafScript: Buffer): Buffer;
17
18
  /**
18
- * concats the length of the script and the script itself
19
+ * concat the length of the script and the script itself
19
20
  */
20
21
  export declare function prefixScriptLength(s: Buffer): Buffer;
21
22
  export declare function sortLeaves(leaf1: Buffer, leaf2: Buffer): Buffer[];
@@ -26,6 +27,10 @@ export declare const ChainToID: Record<EvmChain, viemChain>;
26
27
  * Switches or adds a network to the wallet
27
28
  * @param chain Garden supported chain
28
29
  * @param walletClient
29
- * @returns
30
+ * @returns new walletClient with updated chain
30
31
  */
31
- export declare const switchOrAddNetwork: (chain: Chain, walletClient: WalletClient) => Promise<import('@catalogfi/utils').Result<string, never> | import('@catalogfi/utils').Result<never, string>>;
32
+ export declare const switchOrAddNetwork: (chain: Chain, walletClient: WalletClient) => AsyncResult<{
33
+ message: string;
34
+ walletClient: WalletClient;
35
+ }, string>;
36
+ export declare const constructOrderPair: (sourceChain: Chain, sourceAsset: string, destChain: Chain, destAsset: string) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "0.2.0-beta.5",
3
+ "version": "0.2.0-beta.50",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -27,8 +27,10 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@catalogfi/utils": "^0.1.6",
30
- "@catalogfi/wallets": "^0.2.49",
31
- "@gardenfi/orderbook": "^0.2.0-beta.6",
30
+ "@catalogfi/wallets": "^0.2.50",
31
+ "@gardenfi/orderbook": "^0.2.0-beta.14",
32
+ "@gardenfi/utils": "^0.0.1-beta.18",
33
+ "bignumber.js": "^9.1.2",
32
34
  "bitcoinjs-lib": "^6.1.6",
33
35
  "tiny-secp256k1": "^2.2.3",
34
36
  "varuint-bitcoin": "^1.1.2",
@@ -1,13 +0,0 @@
1
- import { MatchedOrder } from '@gardenfi/orderbook';
2
- import { IStore } from '@gardenfi/utils';
3
- import { IOrderCache, OrderActions, OrderCacheValue } from './garden.types';
4
-
5
- export declare class OrderCache implements IOrderCache {
6
- private order;
7
- private store;
8
- constructor(order: MatchedOrder, store: IStore);
9
- getOrder(): MatchedOrder;
10
- set(action: OrderActions, txHash: string): void;
11
- get(action: OrderActions): OrderCacheValue | null;
12
- remove(action: OrderActions): void;
13
- }