@gardenfi/core 0.2.0-beta.9 → 0.2.0-beta.90

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.
@@ -6,6 +6,7 @@ import { IAuth } from '@gardenfi/utils';
6
6
  import { IQuote } from '../quote/quote.types';
7
7
  import { WalletClient } from 'viem';
8
8
  import { IBitcoinWallet } from '@catalogfi/wallets';
9
+ import { IBlockNumberFetcher } from './blockNumber';
9
10
 
10
11
  export declare class Garden implements IGardenJS {
11
12
  private secretManager;
@@ -13,13 +14,13 @@ export declare class Garden implements IGardenJS {
13
14
  private orderBook;
14
15
  private quote;
15
16
  private getOrderThreshold;
16
- private pendingOrdersCount;
17
17
  private orderbookUrl;
18
18
  private auth;
19
19
  private useRelay;
20
20
  private wallets;
21
21
  private evmAddress;
22
- private store;
22
+ private orderExecutorCache;
23
+ private blockNumberFetcher;
23
24
  constructor(config: {
24
25
  orderbookURl: string;
25
26
  secretManager: ISecretManager;
@@ -29,19 +30,22 @@ export declare class Garden implements IGardenJS {
29
30
  evmWallet: WalletClient;
30
31
  btcWallet?: IBitcoinWallet;
31
32
  };
33
+ blockNumberFetcher?: IBlockNumberFetcher;
32
34
  });
33
- getPendingOrderCount(): number;
34
35
  setUseRelay(useRelay: boolean): void;
35
36
  swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
36
37
  private validateAndFillParams;
37
38
  private getAddresses;
38
39
  private validateAmount;
39
- private getTimelock;
40
40
  private pollOrder;
41
- private emit;
42
41
  execute(interval?: number): Promise<() => void>;
42
+ private evmRedeem;
43
+ private btcRedeem;
44
+ private btcRefund;
43
45
  private getWallet;
46
+ private emit;
44
47
  on<E extends keyof GardenEvents>(event: E, cb: GardenEvents[E]): void;
45
48
  off<E extends keyof GardenEvents>(event: E, cb: GardenEvents[E]): void;
46
49
  private fetchCurrentBlockNumbers;
50
+ private assignOrderStatus;
47
51
  }
@@ -1,5 +1,6 @@
1
1
  import { AsyncResult } from '@catalogfi/utils';
2
2
  import { Asset, MatchedOrder } from '@gardenfi/orderbook';
3
+ import { OrderStatus } from '../status';
3
4
 
4
5
  export type SwapParams = {
5
6
  /**
@@ -26,6 +27,10 @@ export type SwapParams = {
26
27
  * This will wait for the specified number of confirmations before redeeming the funds.
27
28
  */
28
29
  minDestinationConfirmations?: number;
30
+ /**
31
+ * Unique nonce for generating secret and secret hashes. If not provided, it will be generated as the total order count until now + 1.
32
+ */
33
+ nonce?: number;
29
34
  /**
30
35
  * Additional data for the order.
31
36
  */
@@ -40,14 +45,14 @@ export type SwapParams = {
40
45
  btcAddress?: string;
41
46
  };
42
47
  };
43
- export declare enum TimeLocks {
44
- evm = 14400,
45
- btc = 288
46
- }
48
+ export type OrderWithStatus = MatchedOrder & {
49
+ status: OrderStatus;
50
+ };
47
51
  export type GardenEvents = {
48
52
  error: (order: MatchedOrder, error: string) => void;
49
53
  success: (order: MatchedOrder, action: OrderActions, result: string) => void;
50
- onPendingOrdersChanged: (orders: MatchedOrder[]) => void;
54
+ onPendingOrdersChanged: (orders: OrderWithStatus[]) => void;
55
+ log: (id: string, message: string) => void;
51
56
  };
52
57
  export type EventCallback = (...args: any[]) => void;
53
58
  export interface IGardenJS {
@@ -62,18 +67,18 @@ export interface IGardenJS {
62
67
  * @param interval - Polling interval in milliseconds.
63
68
  */
64
69
  execute(): Promise<() => void>;
65
- getPendingOrderCount(): number;
66
70
  on<E extends keyof GardenEvents>(event: E, cb: GardenEvents[E]): void;
71
+ off<E extends keyof GardenEvents>(event: E, cb: GardenEvents[E]): void;
67
72
  }
68
73
  export type OrderCacheValue = {
69
74
  txHash: string;
70
75
  timeStamp: number;
76
+ btcRedeemUTXO?: string;
71
77
  };
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;
78
+ export interface IOrderExecutorCache {
79
+ set(order: MatchedOrder, action: OrderActions, txHash: string, utxo?: string): void;
80
+ get(order: MatchedOrder, action: OrderActions): OrderCacheValue | null;
81
+ remove(order: MatchedOrder, action: OrderActions): void;
77
82
  }
78
83
  /**
79
84
  * Actions that can be performed on the order.
@@ -26,3 +26,11 @@ 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
+ /**
30
+ * Parse the action to be performed on the order based on the order status.
31
+ * @param status Order status
32
+ * @returns {OrderActions} The action to be performed on the order
33
+ */
34
+ export declare const parseActionFromStatus: (status: OrderStatus) => OrderActions;
35
+ export declare const isExpired: (unixTime: number, tillHours?: number) => boolean;
36
+ export declare const filterDeadlineExpiredOrders: (orders: MatchedOrder[]) => MatchedOrder[];
@@ -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,29 @@ 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
+ fee: number;
41
+ }>;
42
+ export type StrategiesResponse = APIResponse<{
43
+ [strategy: string]: {
44
+ id: string;
45
+ min_amount: string;
46
+ max_amount: string;
47
+ fee: number;
48
+ source_chain: Chain;
49
+ dest_chain: Chain;
50
+ source_asset: {
51
+ asset: string;
52
+ token_id: string;
53
+ decimals: number;
54
+ };
55
+ dest_asset: {
56
+ asset: string;
57
+ token_id: string;
58
+ decimals: number;
59
+ };
60
+ };
61
+ }>;
@@ -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
  /**
@@ -1,7 +1,8 @@
1
1
  import { Chain as viemChain } from 'viem/chains';
2
2
  import { IBaseWallet } from '@catalogfi/wallets';
3
- import { Chain, EvmChain } from '@gardenfi/orderbook';
3
+ import { Chain, EvmChain, NetworkType } 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,21 +12,26 @@ 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[];
22
23
  export declare const toXOnly: (pubKey: string) => string;
23
24
  export declare const isValidBitcoinPubKey: (pubKey: string) => boolean;
24
- export declare const ChainToID: Record<EvmChain, viemChain>;
25
+ export declare const evmToViemChainMap: Record<EvmChain, viemChain>;
25
26
  /**
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;
37
+ export declare function validateBTCAddress(address: string, networkType: NetworkType): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gardenfi/core",
3
- "version": "0.2.0-beta.9",
3
+ "version": "0.2.0-beta.90",
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.50",
31
- "@gardenfi/orderbook": "^0.2.0-beta.9",
30
+ "@catalogfi/wallets": "^0.2.51",
31
+ "@gardenfi/orderbook": "^0.2.0-beta.27",
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
- }