Interact with ZeusLayer via ZPL Client
Interact with ZeusLayer via ZPL Client
Section titled “Interact with ZeusLayer via ZPL Client”The ZPL Client is the main entry point for interacting with the Zeus Program Library. It provides methods for account management, instruction creation, and transaction submission. The client abstracts the complexity of interacting with the Solana blockchain and the ZPL programs, making it easier for developers to build applications on top of ZPL.
Client Architecture
Section titled “Client Architecture”The ZPL Client is composed of three main modules:
- Account: Handles account derivation and data fetching
- Instruction: Creates instructions for various operations
- RpcClient: Manages transaction signing and submission
Initialization
Section titled “Initialization”import { ZplClient } from "@/zplClient";import { Connection, PublicKey } from "@solana/web3.js";
// Initialize ZPL Clientconst zplClient = new ZplClient( connection, // Solana connection walletPublicKey, // Connected wallet public key signTransaction, // Function to sign transactions twoWayPegProgramId, // Program ID for two-way peg liquidityManagementProgramId, // Program ID for liquidity management assetMint // Asset mint address);
Using ZplClient with React
Section titled “Using ZplClient with React”For React applications, you can use the provided ZplClientProvider
and useZplClient
hook to access the client throughout your application:
import { ZplClientProvider, useZplClient } from "@/contexts/ZplClientProvider";import { useConnection, useWallet } from "@solana/wallet-adapter-react";
// In your app's root componentfunction App() { return ( <ZplClientProvider> <YourComponent /> </ZplClientProvider> );}
// In your componentfunction YourComponent() { const zplClient = useZplClient();
// Now you can use zplClient to interact with ZPL // ...}
Client Capabilities
Section titled “Client Capabilities”The ZPL Client provides the following capabilities:
-
Account Management (/zplClient/account.ts):
- Deserialize on-chain hot reserve buckets, cold reserve buckets, positions, and two-way peg configuration into objects
- Derive program addresses, for example:
- TwoWayPeg/LiquidityManagement configuration, LiquidityManagementGuardianSetting, and SplTokenVaultAuthority address
- Hot/Cold reserve bucket address with/without user’s public key
- Interaction address given transaction ID and slot (we store each deposit/withdraw txns onchain to track their status)
- Position address given user’s public key
-
Instruction Creation (/zplClient/instruction.ts):
- Create/Reactivate hot reserve buckets for deposits
- Add zBTC to tBTC withdrawal requests
- Store/retrieve zBTC to/from the vault
-
Transaction Submission (/zplClient/rpcClient.ts):
- Sign and send transactions with multiple instructions