Garden
The Garden
class serves as a high-level wrapper around the core modules of the system: quote
, orderbook
, secretManager
, and EVMRelay
. It provides a simplified interface with primary functionalities for creating and executing swaps.
Key Features
- Swap Creation: Facilitates the creation of new orders through the
swap
method. - Swap Execution: Allows for the execution of orders via the
execute
method. - Modular Access: Provides access to underlying modules (
quote
,orderbook
,secretManager
, andEVMRelay
) for advanced interactions if needed.
Usage
import { Garden } from '@gardenfi/core';
Constructor
new Garden(config: GardenConfig): IGarden
Parameters:
config
(GardenConfig): The configuration object for the Garden instance.
Returns:
Methods
swap
swap(params: SwapParams): AsyncResult<MatchedOrder, string>
The swap
function creates a new order based on the provided parameters. It validates the input, uses the secretManager to generate a secret and secret hash using a nonce, which is calculated as the user's number of orders plus one, and fetch attested quote from the quote module. After these steps, it posts the order to the orderbook to create a new order.
This function simplifies the process of creating a swap by handling validation, secret generation, and order creation automatically.
Parameters:
params
(SwapParams): The parameters for creating the swap.
Returns:
execute
execute(): Promise<() => void>
Executes the pending orders and provides a cancel function to stop the execution.
Returns:
Promise<() => void>
: A promise that resolves to a function for canceling the execution.
Readonly Properties
orderbook
get orderbook(): IOrderbook
Returns Orderbook instance.
evmRelay
get evmRelay(): IEVMRelay
Returns EvmRelay instance.
quote
get quote(): IQuote
Returns Quote instance.
btcWallet
get btcWallet(): IBitcoinWallet | undefined
The Bitcoin wallet, if available, for managing BTC transactions.
orderbookUrl
get orderbookUrl(): string
The URL of the orderbook for accessing and managing orders.
blockNumberFetcher
get blockNumberFetcher(): IBlockNumberFetcher
Returns BlockNumberFetcher instance.
secretManager
get secretManager(): ISecretManager
Returns SecretManager instance.
Events
The Garden class emits several events that you can subscribe to for monitoring order status and system operations:
error
Triggered when an error occurs during order processing.
Parameters:
order
(MatchedOrder): The order that encountered an errorerror
(string): Description of the error that occurred
success
Emitted when an order action is successfully completed.
Parameters:
order
(MatchedOrder): The successfully processed orderaction
(OrderActions): The type of action that was completedresult
(string): Details about the successful operation
onPendingOrdersChanged
Fired whenever the list of pending orders is updated.
Parameters:
orders
(OrderWithStatus[]): Array of current pending orders with their status
log
Emits logging information for debugging and monitoring purposes.
Parameters:
id
(string): Identifier for the log entrymessage
(string): The log message content