Step-by-step guide to integrating Garden SDK for fetching quotes, executing swaps, and tracking them
GardenProvider
is the core of the SDK integration. It acts as a wrapper around your application, handling:
GardenProvider
. The provider requires walletClient
, which is provided by wagmi
. For this, you’ll need to:
walletClient
using the useWalletClient
hook.GardenProvider
configuration.walletClient
, you can use it to initialize the GardenProvider
. Before diving into swap, your app needs to fetch real-time quotes for their swap params fromAsset
, toAsset
, amount
.
The getQuote
hook from Garden SDK provides real-time USD values and exchange rates for any two supported assets. You’ll need to provide:
fromAsset
: The token you want to swap from.toAsset
: The token you want to receive.amount
: The amount you want to swap.isExactOut
: Whether you’re specifying the input or output amount.swapAndInitiate
hook that handles the entire swap process for you.
Here’s what it does:
ParseOrderStatus
function, which determines the order’s current state. By checking block numbers on both chains, it can identify if the order is:
Expired
- The user’s swap has expired, and they have to refund their funds.Initiated
- User initiated, waiting for counterparty to initiate.Redeemed
- User redeemed, counterparty has to redeem.Refunded
- User refunded.