Skip to content

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.

The ZPL Client is composed of three main modules:

  1. Account: Handles account derivation and data fetching
  2. Instruction: Creates instructions for various operations
  3. RpcClient: Manages transaction signing and submission
import { ZplClient } from "@/zplClient";
import { Connection, PublicKey } from "@solana/web3.js";
// Initialize ZPL Client
const 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
);

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 component
function App() {
return (
<ZplClientProvider>
<YourComponent />
</ZplClientProvider>
);
}
// In your component
function YourComponent() {
const zplClient = useZplClient();
// Now you can use zplClient to interact with ZPL
// ...
}

The ZPL Client provides the following capabilities:

  1. 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
  2. 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
  3. Transaction Submission (/zplClient/rpcClient.ts):

    • Sign and send transactions with multiple instructions