@gardenfi/core 2.5.2-beta.5 → 2.5.3-beta.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 (42) hide show
  1. package/dist/{ccip-DSGVoxhU.cjs → ccip-BixEUfCX.cjs} +1 -1
  2. package/dist/{ccip-Bg3f6Dwh.js → ccip-Cmo2J8uO.js} +1 -1
  3. package/dist/index-BsnXI660.js +33105 -0
  4. package/dist/index-Bx--llHe.cjs +106 -0
  5. package/dist/index.cjs +1 -1
  6. package/dist/index.js +35 -33
  7. package/dist/src/index.d.ts +12 -9
  8. package/dist/src/lib/bitcoin/bitcoinHtlc.d.ts +107 -0
  9. package/dist/src/lib/bitcoin/bitcoinhtlc.types.d.ts +53 -0
  10. package/dist/src/lib/blockNumberFetcher/blockNumber.d.ts +2 -2
  11. package/dist/src/lib/constants.d.ts +4 -8
  12. package/dist/src/lib/evm/htlc/evmHTLC.d.ts +27 -27
  13. package/dist/src/lib/evm/htlc.types.d.ts +4 -4
  14. package/dist/src/lib/evm/relay/evmRelay.d.ts +5 -4
  15. package/dist/src/lib/evm/relay/evmRelay.types.d.ts +2 -2
  16. package/dist/src/lib/garden/cache/GardenCache.d.ts +46 -0
  17. package/dist/src/lib/garden/executor/executor.d.ts +26 -0
  18. package/dist/src/lib/garden/garden.d.ts +44 -51
  19. package/dist/src/lib/garden/garden.types.d.ts +57 -100
  20. package/dist/src/lib/garden/utils.d.ts +4 -0
  21. package/dist/src/lib/orderStatus/orderStatus.d.ts +25 -0
  22. package/dist/src/lib/quote/quote.d.ts +4 -3
  23. package/dist/src/lib/quote/quote.types.d.ts +17 -8
  24. package/dist/src/lib/routeValidator/routeValidator.d.ts +30 -0
  25. package/dist/src/lib/solana/htlc/ISolanaHTLC.d.ts +4 -4
  26. package/dist/src/lib/solana/htlc/solanaHTLC.d.ts +7 -7
  27. package/dist/src/lib/solana/relayer/solanaRelay.d.ts +13 -25
  28. package/dist/src/lib/solana/solanaTypes.d.ts +3 -3
  29. package/dist/src/lib/starknet/htlc/starknetHTLC.d.ts +4 -4
  30. package/dist/src/lib/starknet/relay/starknetRelay.d.ts +8 -5
  31. package/dist/src/lib/starknet/starknetHTLC.types.d.ts +4 -4
  32. package/dist/src/lib/sui/htlc/suiHTLC.d.ts +7 -6
  33. package/dist/src/lib/sui/relay/suiRelay.d.ts +4 -3
  34. package/dist/src/lib/sui/suiHTLC.types.d.ts +4 -4
  35. package/dist/src/lib/switchOrAddNetwork.d.ts +1 -0
  36. package/dist/src/lib/utils.d.ts +26 -5
  37. package/package.json +5 -4
  38. package/dist/index-D-NHDZrP.js +0 -31936
  39. package/dist/index-s2tkcnpk.cjs +0 -105
  40. package/dist/src/lib/bitcoin/htlc.d.ts +0 -106
  41. package/dist/src/lib/garden/cache/executorCache.d.ts +0 -14
  42. package/dist/src/lib/orderStatus/orderStatusParser.d.ts +0 -37
@@ -0,0 +1,46 @@
1
+ import { Order } from '@gardenfi/orderbook';
2
+ import { OrderAction } from 'src/lib/orderStatus/orderStatus';
3
+
4
+ export declare enum CacheType {
5
+ OrderExecutor = "orderExecutor",
6
+ BitcoinRedeem = "bitcoinRedeem",
7
+ RefundSacp = "refundSacp"
8
+ }
9
+ export type OrderExecutorCacheValue = {
10
+ txHash: string;
11
+ timeStamp: number;
12
+ btcRedeemUTXO?: string;
13
+ };
14
+ export type RefundSacpCacheValue = {
15
+ initTxHash: string;
16
+ };
17
+ export type BitcoinRedeemCacheValue = {
18
+ redeemedFromUTXO: string;
19
+ redeemedAt: number;
20
+ redeemTxHash: string;
21
+ };
22
+ interface CacheOptions {
23
+ max?: number;
24
+ ttl?: number;
25
+ }
26
+ export declare class GardenCache {
27
+ private cache;
28
+ constructor(options?: CacheOptions);
29
+ private makeKey;
30
+ set<T>(type: CacheType, key: string, value: T, ttl?: number): void;
31
+ get<T>(type: CacheType, key: string): T | undefined;
32
+ remove(type: CacheType, key: string): void;
33
+ clear(type?: CacheType): void;
34
+ setBitcoinRedeem(orderId: string, data: BitcoinRedeemCacheValue, ttl?: number): void;
35
+ getBitcoinRedeem(orderId: string): BitcoinRedeemCacheValue | undefined;
36
+ setOrderExecution(order: Order, action: OrderAction | string, txHash: string, utxo?: string, ttl?: number): void;
37
+ getOrderExecution(order: Order, action: OrderAction | string): OrderExecutorCacheValue | undefined;
38
+ removeOrderExecution(order: Order, action: OrderAction | string): void;
39
+ private makeOrderKey;
40
+ setSacpCache(orderId: string, data: RefundSacpCacheValue, ttl?: number): void;
41
+ getSacpCache(orderId: string): RefundSacpCacheValue | undefined;
42
+ has(type: CacheType, key: string): boolean;
43
+ peek<T>(type: CacheType, key: string): T | undefined;
44
+ getRemainingTTL(type: CacheType, key: string): number;
45
+ }
46
+ export {};
@@ -0,0 +1,26 @@
1
+ import { DigestKey, IAuth } from '@gardenfi/utils';
2
+ import { GardenEventEmitter, GardenHTLCModules } from './../garden.types';
3
+ import { IOrderbook } from '@gardenfi/orderbook';
4
+ import { Api } from '../../constants';
5
+
6
+ export declare class Executor {
7
+ #private;
8
+ private htlcs;
9
+ private events;
10
+ private isBackgroundServiceRunning;
11
+ private executorStop;
12
+ constructor(digestKey: DigestKey, htlcs: GardenHTLCModules, orderbook: IOrderbook, auth: IAuth, api: Api, events: GardenEventEmitter);
13
+ private getAddressesFromHTLCs;
14
+ startBackgroundService(interval: number | undefined, redeemServiceEnabled: boolean): void;
15
+ stopBackgroundService(): void;
16
+ execute(interval?: number): Promise<() => void>;
17
+ private processOrderActions;
18
+ private handleRedeemAction;
19
+ private evmRedeem;
20
+ private starknetRedeem;
21
+ private solRedeem;
22
+ private suiRedeem;
23
+ private btcRedeem;
24
+ private postRefundSACP;
25
+ private broadcastRedeemTx;
26
+ }
@@ -1,67 +1,60 @@
1
1
  import { ISecretManager } from './../secretManager/secretManager.types';
2
- import { GardenEvents, IGardenJS, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets } from './garden.types';
3
- import { IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
4
- import { EventBroker, IAuth, DigestKey, AsyncResult } from '@gardenfi/utils';
2
+ import { IGardenJS, SwapParams, GardenConfigWithHTLCs, GardenConfigWithWallets, GardenEvents } from './garden.types';
3
+ import { CreateOrderRequest, IOrderbook, Orderbook } from '@gardenfi/orderbook';
4
+ import { IAuth, DigestKey, AsyncResult } from '@gardenfi/utils';
5
5
  import { IQuote } from '../quote/quote.types';
6
- import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
7
- import { IEVMHTLC } from '../evm/htlc.types';
8
- import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
9
- import { IBitcoinWallet } from '../bitcoin/wallet/wallet.interface';
10
- import { ISolanaHTLC } from '../solana/htlc/ISolanaHTLC';
11
- import { ISuiHTLC } from '../sui/suiHTLC.types';
6
+ import { Executor } from './executor/executor';
12
7
 
13
- export declare class Garden extends EventBroker<GardenEvents> implements IGardenJS {
14
- private environment;
15
- private _secretManager;
16
- private _orderbook;
8
+ export declare class Garden extends Orderbook implements IGardenJS {
9
+ private network;
17
10
  private _quote;
18
- private getOrderThreshold;
19
11
  private _auth;
20
- private orderExecutorCache;
21
- private _blockNumberFetcher;
22
- private refundSacpCache;
23
- private _evmHTLC;
24
- private _starknetHTLC;
25
- private _solanaHTLC;
26
- private _suiHTLC;
27
- private _btcWallet;
28
- private bitcoinRedeemCache;
29
- private _digestKey;
12
+ private _htlcs;
30
13
  private _api;
31
- private isSecretManagementEnabled;
14
+ private _executor;
15
+ private _events;
16
+ /**
17
+ * If true, the redeem service will be enabled.
18
+ */
19
+ private redeemServiceEnabled;
20
+ private _secretManager;
21
+ private _digestKey;
22
+ private executeInterval;
32
23
  constructor(config: GardenConfigWithHTLCs);
33
- handleSecretManagement(enabled: boolean): this;
24
+ /**
25
+ * Enables or disables the auto-redeem service provided by Garden API.
26
+ *
27
+ * If enabled, make sure to pass DigestKey to the constructor.
28
+ * @default true
29
+ * @param enabled - boolean
30
+ * @returns this
31
+ */
32
+ setRedeemServiceEnabled(enabled: boolean): this;
34
33
  static fromWallets(config: GardenConfigWithWallets): Garden;
35
- get evmHTLC(): IEVMHTLC | undefined;
36
- get starknetHTLC(): IStarknetHTLC | undefined;
37
- get solanaHTLC(): ISolanaHTLC | undefined;
38
- get suiHTLC(): ISuiHTLC | undefined;
34
+ get htlcs(): {
35
+ readonly evm: import('../..').IEVMHTLC | undefined;
36
+ readonly starknet: import('../..').IStarknetHTLC | undefined;
37
+ readonly solana: import('../..').ISolanaHTLC | undefined;
38
+ readonly sui: import('../sui/suiHTLC.types').ISuiHTLC | undefined;
39
+ readonly bitcoin: import('../bitcoin/bitcoinhtlc.types').IBitcoinHTLC | undefined;
40
+ };
39
41
  get quote(): IQuote;
40
- get btcWallet(): IBitcoinWallet | undefined;
41
42
  get orderbook(): IOrderbook;
42
- get blockNumberFetcher(): IBlockNumberFetcher;
43
43
  get secretManager(): ISecretManager;
44
44
  get auth(): IAuth;
45
- get digestKey(): DigestKey;
45
+ get digestKey(): DigestKey | undefined;
46
+ get executor(): Executor | undefined;
47
+ /**
48
+ * Creates an order for a swap operation and initiates the HTLC on the source chain.
49
+ * @param params SwapParams
50
+ * @returns AsyncResult<Order, string>
51
+ */
52
+ createSwap(params: SwapParams): AsyncResult<string, string>;
46
53
  /**
47
- * This method takes in the `SwapParams` and returns a placed order
48
- * It internally calls `getAttestedQuote`, `createOrder` and `pollOrder`
49
- * @param swapParams
50
- * @returns MatchedOrder
54
+ * Create an order
51
55
  */
52
- swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
53
- private withDefaultAffiliateFees;
56
+ createOrder(arg: CreateOrderRequest | SwapParams, auth?: IAuth): AsyncResult<any, string>;
54
57
  private validateAndFillParams;
55
- private getAddresses;
56
- private validateAmount;
57
- execute(interval?: number): Promise<() => void>;
58
- private solRedeem;
59
- private suiRedeem;
60
- private evmRedeem;
61
- private starknetRedeem;
62
- private btcRedeem;
63
- private btcRefund;
64
- private postRefundSACP;
65
- private assignStatus;
66
- private broadcastRedeemTx;
58
+ on<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
59
+ off<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
67
60
  }
@@ -1,29 +1,30 @@
1
- import { AffiliateFeeOptionalChainAsset, Asset, IOrderbook, MatchedOrder } from '@gardenfi/orderbook';
2
- import { OrderStatus } from '../orderStatus/status';
3
- import { AsyncResult, Environment, EventBroker, IAuth, DigestKey } from '@gardenfi/utils';
1
+ import { AffiliateFee, Asset, BlockchainType, ChainAsset, ChainAssetString, IOrderbook, Order } from '@gardenfi/orderbook';
2
+ import { OrderAction, OrderStatus } from '../orderStatus/orderStatus';
3
+ import { ApiKey, AsyncResult, IAuth, Network, DigestKey } from '@gardenfi/utils';
4
4
  import { ISecretManager } from '../secretManager/secretManager.types';
5
5
  import { IQuote } from '../quote/quote.types';
6
- import { IBlockNumberFetcher } from '../blockNumberFetcher/blockNumber';
7
6
  import { IEVMHTLC } from '../evm/htlc.types';
8
7
  import { IStarknetHTLC } from '../starknet/starknetHTLC.types';
9
8
  import { AccountInterface } from 'starknet';
10
9
  import { WalletClient } from 'viem';
11
- import { Api } from '../constants';
12
10
  import { IBitcoinWallet } from '../bitcoin/wallet/wallet.interface';
13
11
  import { ISolanaHTLC } from '../solana/htlc/ISolanaHTLC';
14
12
  import { AnchorProvider } from '@coral-xyz/anchor';
13
+ import { Api } from '../constants';
15
14
  import { ISuiHTLC } from '../sui/suiHTLC.types';
16
15
  import { WalletWithRequiredFeatures } from '@mysten/wallet-standard';
16
+ import { IBitcoinHTLC } from '../bitcoin/bitcoinhtlc.types';
17
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
17
18
 
18
19
  export type SwapParams = {
19
20
  /**
20
21
  * Asset to be sent.
21
22
  */
22
- fromAsset: Asset;
23
+ fromAsset: Asset | ChainAsset | ChainAssetString;
23
24
  /**
24
25
  * Asset to be received.
25
26
  */
26
- toAsset: Asset;
27
+ toAsset: Asset | ChainAsset | ChainAssetString;
27
28
  /**
28
29
  * Amount in lowest denomination of the sendAsset.
29
30
  */
@@ -33,101 +34,57 @@ export type SwapParams = {
33
34
  */
34
35
  receiveAmount: string;
35
36
  /**
36
- * Time lock for the swap.
37
+ * Slippage for the order.
37
38
  */
38
- timelock?: number;
39
+ slippage?: number;
39
40
  /**
40
- * This will wait for the specified number of confirmations before redeeming the funds.
41
+ * Addresses for the order.
41
42
  */
42
- minDestinationConfirmations?: number;
43
- /**
44
- * Unique nonce for generating secret and secret hashes. If not provided, it will be generated as the total order count until now + 1.
45
- */
46
- nonce?: number;
47
- /**
48
- * Additional data for the order.
49
- */
50
- additionalData: {
51
- /**
52
- * Get strategy id from the quote
53
- */
54
- strategyId: string;
55
- /**
56
- * Provide btcAddress if the destination or source chain is bitcoin. This address is used as refund address if source chain is bitcoin, and as redeem address if destination chain is bitcoin.
57
- */
58
- btcAddress?: string;
59
- };
43
+ addresses?: Partial<Record<BlockchainType, string>>;
60
44
  /**
61
45
  * Integrator fee for the order.
62
46
  */
63
- affiliateFee?: AffiliateFeeOptionalChainAsset[];
47
+ affiliateFee?: AffiliateFee[];
64
48
  };
65
- export type OrderWithStatus = MatchedOrder & {
49
+ export type OrderWithStatus = Order & {
66
50
  status: OrderStatus;
67
51
  };
68
52
  export type GardenEvents = {
69
- error: (order: MatchedOrder, error: string) => void;
70
- success: (order: MatchedOrder, action: OrderActions, result: string) => void;
53
+ error: (order: Order, error: string) => void;
54
+ success: (order: Order, action: OrderAction, result: string) => void;
71
55
  onPendingOrdersChanged: (orders: OrderWithStatus[]) => void;
72
56
  log: (id: string, message: string) => void;
73
- rbf: (order: MatchedOrder, result: string) => void;
57
+ rbf: (order: Order, result: string) => void;
58
+ };
59
+ export type GardenEventEmitter = {
60
+ emit: <K extends keyof GardenEvents>(event: K, ...args: Parameters<GardenEvents[K]>) => void;
74
61
  };
75
62
  export type EventCallback = (...args: any[]) => void;
76
63
  /**
77
64
  * Interface representing the GardenJS library.
78
65
  */
79
- export interface IGardenJS extends EventBroker<GardenEvents> {
66
+ export interface IGardenJS extends IOrderbook {
80
67
  /**
81
68
  * Create Order
82
69
  * @param {SwapParams} params - The parameters for creating the order.
83
- * @returns {AsyncResult<MatchedOrder, string>} The result of the swap operation.
84
- */
85
- swap(params: SwapParams): AsyncResult<MatchedOrder, string>;
86
- /**
87
- * Execute an action.
88
- * @returns {Promise<() => void>} A promise that resolves to a function to cancel the execution.
89
- */
90
- execute(): Promise<() => void>;
91
- /**
92
- * The EVM relay.
93
- * @readonly
94
- */
95
- get evmHTLC(): IEVMHTLC | undefined;
96
- /**
97
- * The Starknet relay.
98
- * @readonly
99
- */
100
- get starknetHTLC(): IStarknetHTLC | undefined;
101
- /**
102
- * The Solana relay.
103
- * @readonly
70
+ * @returns {AsyncResult<string, string>} The result of the swap operation.
104
71
  */
105
- get solanaHTLC(): ISolanaHTLC | undefined;
106
- /**
107
- * The Sui relay.
108
- * @readonly
109
- */
110
- get suiHTLC(): ISuiHTLC | undefined;
72
+ createSwap(params: SwapParams): AsyncResult<string, string>;
111
73
  /**
112
74
  * The current quote.
113
75
  * @readonly
114
76
  */
115
77
  get quote(): IQuote;
116
78
  /**
117
- * The BTC wallet.
79
+ * All HTLC modules at once.
118
80
  * @readonly
119
81
  */
120
- get btcWallet(): IBitcoinWallet | undefined;
82
+ get htlcs(): GardenHTLCModules;
121
83
  /**
122
84
  * The orderbook.
123
85
  * @readonly
124
86
  */
125
87
  get orderbook(): IOrderbook;
126
- /**
127
- * The block number fetcher.
128
- * @readonly
129
- */
130
- get blockNumberFetcher(): IBlockNumberFetcher;
131
88
  /**
132
89
  * The secret manager.
133
90
  * @readonly
@@ -142,7 +99,15 @@ export interface IGardenJS extends EventBroker<GardenEvents> {
142
99
  * The digest key.
143
100
  * @readonly
144
101
  */
145
- get digestKey(): DigestKey;
102
+ get digestKey(): DigestKey | undefined;
103
+ /**
104
+ * The events.
105
+ */
106
+ on<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
107
+ /**
108
+ * The events.
109
+ */
110
+ off<K extends keyof GardenEvents>(event: K, listener: GardenEvents[K]): this;
146
111
  }
147
112
  export type OrderCacheValue = {
148
113
  txHash: string;
@@ -150,51 +115,43 @@ export type OrderCacheValue = {
150
115
  btcRedeemUTXO?: string;
151
116
  };
152
117
  export interface IOrderExecutorCache {
153
- set(order: MatchedOrder, action: OrderActions, txHash: string, utxo?: string): void;
154
- get(order: MatchedOrder, action: OrderActions): OrderCacheValue | null;
155
- remove(order: MatchedOrder, action: OrderActions): void;
118
+ set(order: Order, action: OrderAction, txHash: string, utxo?: string): void;
119
+ get(order: Order, action: OrderAction): OrderCacheValue | null;
120
+ remove(order: Order, action: OrderAction): void;
156
121
  }
157
- export type ApiConfig = Environment | (Partial<Api> & {
158
- environment: Environment;
122
+ export type ApiConfig = Network | (Partial<Api> & {
123
+ network: Network;
159
124
  });
160
125
  export type GardenCoreConfig = {
161
126
  environment: ApiConfig;
162
- digestKey: string | DigestKey;
127
+ apiKey: string | ApiKey;
128
+ digestKey?: string | DigestKey;
163
129
  secretManager?: ISecretManager;
164
130
  auth?: IAuth;
165
131
  orderbook?: IOrderbook;
166
132
  quote?: IQuote;
167
- blockNumberFetcher?: IBlockNumberFetcher;
168
- btcWallet?: IBitcoinWallet;
169
133
  solanaProgramAddress?: {
170
134
  native?: string;
171
135
  spl?: string;
172
136
  };
173
137
  };
174
138
  export type GardenHTLCModules = {
175
- htlc: {
176
- evm?: IEVMHTLC;
177
- starknet?: IStarknetHTLC;
178
- solana?: ISolanaHTLC;
179
- sui?: ISuiHTLC;
180
- };
139
+ evm?: IEVMHTLC;
140
+ starknet?: IStarknetHTLC;
141
+ solana?: ISolanaHTLC;
142
+ sui?: ISuiHTLC;
143
+ bitcoin?: IBitcoinHTLC;
181
144
  };
182
145
  export type GardenWalletModules = {
183
- wallets: {
184
- evm?: WalletClient;
185
- starknet?: AccountInterface;
186
- solana?: AnchorProvider;
187
- sui?: WalletWithRequiredFeatures;
188
- };
146
+ evm?: WalletClient;
147
+ starknet?: AccountInterface;
148
+ solana?: AnchorProvider;
149
+ sui?: WalletWithRequiredFeatures | Ed25519Keypair;
150
+ bitcoin?: IBitcoinWallet;
151
+ };
152
+ export type GardenConfigWithWallets = GardenCoreConfig & {
153
+ wallets?: GardenWalletModules;
154
+ };
155
+ export type GardenConfigWithHTLCs = GardenCoreConfig & {
156
+ htlc?: GardenHTLCModules;
189
157
  };
190
- export type GardenConfigWithWallets = GardenCoreConfig & GardenWalletModules;
191
- export type GardenConfigWithHTLCs = GardenCoreConfig & GardenHTLCModules;
192
- /**
193
- * Actions that can be performed on the order.
194
- */
195
- export declare enum OrderActions {
196
- Idle = "Idle",
197
- Initiate = "Initiate",
198
- Redeem = "Redeem",
199
- Refund = "Refund"
200
- }
@@ -0,0 +1,4 @@
1
+ import { ApiKey, DigestKey } from '@gardenfi/utils';
2
+
3
+ export declare const resolveDigestKey: (digestKey: string | DigestKey | undefined) => DigestKey | undefined;
4
+ export declare const resolveApiKey: (apiKey: string | ApiKey) => ApiKey;
@@ -0,0 +1,25 @@
1
+ import { Order } from '@gardenfi/orderbook';
2
+
3
+ export declare enum OrderStatus {
4
+ Created = "Created",
5
+ InitiateDetected = "Initiate Detected",
6
+ Initiated = "Initiated",
7
+ AwaitingRedeem = "Awaiting Redeem",
8
+ RedeemDetected = "Redeem Detected",
9
+ Redeemed = "Redeemed",
10
+ AwaitingRefund = "Awaiting Refund",
11
+ RefundDetected = "Refund Detected",
12
+ Refunded = "Refunded",
13
+ Expired = "Expired"
14
+ }
15
+ export declare const ParseOrderStatus: (order: Order) => OrderStatus;
16
+ export declare const isDeadlinePassed: (date: Date, tillHours?: number) => boolean;
17
+ export declare const isCompleted: (order: Order) => boolean;
18
+ export declare enum OrderAction {
19
+ Initiate = "Initiate",
20
+ PostRefundSACP = "PostRefundSACP",
21
+ Redeem = "Redeem",
22
+ Refund = "Refund",
23
+ Idle = "Idle"
24
+ }
25
+ export declare const parseAction: (order: Order) => OrderAction.Redeem | OrderAction.Idle;
@@ -1,13 +1,14 @@
1
1
  import { Err, Ok, Request as UtilsRequest } from '@gardenfi/utils';
2
2
  import { IQuote, QuoteParamsForAssets, QuoteResponse, Strategies } from './quote.types';
3
+ import { ChainAsset } from '@gardenfi/orderbook';
3
4
 
4
5
  export declare class Quote implements IQuote {
5
6
  private quoteUrl;
6
7
  constructor(quoteUrl: string);
7
- getQuoteFromAssets({ fromAsset, toAsset, amount, isExactOut, options, }: QuoteParamsForAssets): Promise<Err<string> | Ok<QuoteResponse>>;
8
- getQuote(orderpair: string, amount: number, isExactOut?: boolean, options?: {
8
+ getQuoteFromAssets({ fromAsset, toAsset, amount, isExactOut, options, }: QuoteParamsForAssets): Promise<Err<string> | Ok<QuoteResponse[]>>;
9
+ getQuote(from: ChainAsset, to: ChainAsset, amount: number, isExactOut?: boolean, options?: {
9
10
  affiliateFee?: number;
10
11
  request?: UtilsRequest;
11
- }): Promise<Err<string> | Ok<QuoteResponse>>;
12
+ }): Promise<Err<string> | Ok<QuoteResponse[]>>;
12
13
  getStrategies(): Promise<Err<string> | Ok<Strategies>>;
13
14
  }
@@ -1,4 +1,4 @@
1
- import { Asset, Chain } from '@gardenfi/orderbook';
1
+ import { Asset, Chain, ChainAsset } from '@gardenfi/orderbook';
2
2
  import { APIResponse, AsyncResult, Request } from '@gardenfi/utils';
3
3
 
4
4
  export interface IQuote {
@@ -12,7 +12,7 @@ export interface IQuote {
12
12
  * @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
13
13
  *
14
14
  */
15
- getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse, string>;
15
+ getQuoteFromAssets(params: QuoteParamsForAssets): AsyncResult<QuoteResponse[], string>;
16
16
  /**
17
17
  * Get a quote for the given orderpair and amount
18
18
  * @param orderpair - A string representing the order pair for which the quote is requested.
@@ -24,7 +24,7 @@ export interface IQuote {
24
24
  * @param isExactOut - Whether the amount is exact out
25
25
  * @param options { affiliateFee?: number; request?: Request } - The options for the quote request, affiliate fee in bps and request object
26
26
  */
27
- getQuote(orderpair: string, amount: number, isExactOut: boolean, options?: QuoteOptions): AsyncResult<QuoteResponse, string>;
27
+ getQuote(from: ChainAsset, to: ChainAsset, amount: number, isExactOut: boolean, options?: QuoteOptions): AsyncResult<QuoteResponse[], string>;
28
28
  /**
29
29
  * Get the strategies available for quoting
30
30
  * @returns {Strategies} The strategies available
@@ -45,14 +45,23 @@ export type QuoteParamsForAssets = BaseQuoteParams & {
45
45
  toAsset: Asset;
46
46
  };
47
47
  export type QuoteParamsForOrderPair = BaseQuoteParams & {
48
- orderpair: string;
48
+ from: ChainAsset;
49
+ to: ChainAsset;
49
50
  };
50
51
  export type QuoteResponse = {
51
- quotes: {
52
- [strategy_id: string]: string;
52
+ source: {
53
+ asset: string;
54
+ amount: string;
55
+ display: string;
56
+ value: string;
53
57
  };
54
- input_token_price: number;
55
- output_token_price: number;
58
+ destination: {
59
+ asset: string;
60
+ amount: string;
61
+ display: string;
62
+ value: string;
63
+ };
64
+ solver_id: string;
56
65
  };
57
66
  export type Strategies = Record<string, {
58
67
  id: string;
@@ -0,0 +1,30 @@
1
+ import { ChainAsset } from '@gardenfi/orderbook';
2
+
3
+ interface RoutePolicy {
4
+ default: 'open' | 'closed';
5
+ isolation_groups: string[];
6
+ blacklist_pairs: string[];
7
+ whitelist_overrides: string[];
8
+ }
9
+ declare class RouteValidator {
10
+ private apiBaseUrl;
11
+ private apiKey;
12
+ private policy;
13
+ constructor(apiBaseUrl: string, apiKey: string);
14
+ loadPolicy(): Promise<void>;
15
+ isValidRoute(fromAsset: ChainAsset, toAsset: ChainAsset): boolean;
16
+ getValidDestinations(fromAsset: ChainAsset, allAssets: ChainAsset[]): ChainAsset[];
17
+ getAllValidRoutes(assets: ChainAsset[]): Array<{
18
+ from: ChainAsset;
19
+ to: ChainAsset;
20
+ }>;
21
+ private isInIsolationGroup;
22
+ private isValidIsolationGroup;
23
+ private isWhitelistOverride;
24
+ private isBlacklisted;
25
+ private parseIsolationGroup;
26
+ private matchesPattern;
27
+ private matchesAssetPattern;
28
+ }
29
+ declare function buildRouteMatrix(assets: ChainAsset[], validator: RouteValidator): Record<string, ChainAsset[]>;
30
+ export { RouteValidator, buildRouteMatrix, type RoutePolicy };
@@ -1,4 +1,4 @@
1
- import { MatchedOrder } from '@gardenfi/orderbook';
1
+ import { Order, SolanaOrderResponse } from '@gardenfi/orderbook';
2
2
  import { AsyncResult } from '@gardenfi/utils';
3
3
 
4
4
  export interface ISolanaHTLC {
@@ -11,18 +11,18 @@ export interface ISolanaHTLC {
11
11
  * @param order - The matched order.
12
12
  * @returns A promise resolving to the transaction hash of the initiation.
13
13
  */
14
- initiate(order: MatchedOrder): AsyncResult<string, string>;
14
+ initiate(order: Order | SolanaOrderResponse): AsyncResult<string, string>;
15
15
  /**
16
16
  * Redeems funds from the HTLC contract to the actor's address.
17
17
  * @param order - The matched order.
18
18
  * @param secret - The secret required to unlock the htlc.
19
19
  * @returns A promise resolving to the transaction hash of the redemption.
20
20
  */
21
- redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
21
+ redeem(order: Order, secret: string): AsyncResult<string, string>;
22
22
  /**
23
23
  * Refunds funds from the HTLC contract back to the actor's address upon expiration.
24
24
  * @param order - The matched order.
25
25
  * @returns A promise resolving to the transaction hash of the refund.
26
26
  */
27
- refund(order: MatchedOrder): AsyncResult<string, string>;
27
+ refund(order: Order): AsyncResult<string, string>;
28
28
  }
@@ -1,6 +1,6 @@
1
1
  import { AnchorProvider } from '@coral-xyz/anchor';
2
2
  import { ISolanaHTLC } from './ISolanaHTLC';
3
- import { MatchedOrder } from '@gardenfi/orderbook';
3
+ import { Order } from '@gardenfi/orderbook';
4
4
  import { AsyncResult } from '@gardenfi/utils';
5
5
 
6
6
  /**
@@ -30,27 +30,27 @@ export declare class SolanaHTLC implements ISolanaHTLC {
30
30
  get htlcActorAddress(): string;
31
31
  /**
32
32
  * Initiates a swap by creating a new swap account and locking funds.
33
- * @param {MatchedOrder} order - The matched order containing swap details
33
+ * @param {Order} order - The matched order containing swap details
34
34
  * @returns {Promise<AsyncResult<string, string>>} A promise that resolves to either:
35
35
  * - Ok with the transaction ID on success
36
36
  * - Err with an error message on failure
37
37
  */
38
- initiate(order: MatchedOrder): AsyncResult<string, string>;
38
+ initiate(order: Order): AsyncResult<string, string>;
39
39
  /**
40
40
  * Redeems a swap by providing the secret.
41
- * @param {MatchedOrder} order - Matched order object containing swap details
41
+ * @param {Order} order - Matched order object containing swap details
42
42
  * @param {string} secret - Secret key in hex format
43
43
  * @returns {AsyncResult<string, string>} A promise that resolves to either:
44
44
  * - Ok with the transaction ID on success
45
45
  * - Err with an error message on failure
46
46
  */
47
- redeem(order: MatchedOrder, secret: string): AsyncResult<string, string>;
47
+ redeem(order: Order, secret: string): AsyncResult<string, string>;
48
48
  /**
49
49
  * Refunds the swap back to the initiator.
50
- * @param {MatchedOrder} order - Matched order object
50
+ * @param {Order} order - Matched order object
51
51
  * @returns {AsyncResult<string, string>} A promise that resolves to either:
52
52
  * - Ok with the transaction ID on success
53
53
  * - Err with an error message on failure
54
54
  */
55
- refund(order: MatchedOrder): AsyncResult<string, string>;
55
+ refund(order: Order): AsyncResult<string, string>;
56
56
  }