Contract Handlers
The SDK uses handlers for each Puffer contract to interact with it. Each handler exposes a set of methods that calls the related functions of the contract. It's also possible to get the original contract from the handler which can then be used to call any low-level contract function directly.
Existing Handlers
We currently have the following handlers.
- ERC20PermitHandler
For interacting with theERC20Permit
contract for any supported token. - PufLockerHandler
For interacting with Puffer'sPufLocker
contract. - PufferDepositorHandler
For interacting with Puffer'sPufferDepositor
contract. - PufferL2DepositorHandler
For interacting with Puffer'sPufferL2Depositor
contract. - PufferVaultHandler
For interacting with Puffer'sPufferVault
contract. - L1RewardManagerHandler
For interacting with Puffer'sL1RewardManager
contract. - L2RewardManagerHandler
For interacting with Puffer'sL2RewardManager
contract. - L2RewardManagerHandler
For interacting with Puffer'sL2RewardManager
contract. - NucleusBoringVaultHandler
For interacting with Nucleus'sBoringVault
contract. - NucleusTellerHandler
For interacting with Nucleus'sTeller
contract. - NucleusAccountantHandler
For interacting with Nucleus'sAccountant
contract.
More details about each handler can be found in their respective API documentation.
Using Handlers
There are two ways to use handlers.
1. Using the PufferClient
The PufferClient
is the entry point for the SDK and contains all handlers. See PufferClient#Properties for the full list of contract handlers PufferClient
has.
import {
PufferClientHelpers,
PufferClient,
Chain,
} from '@pufferfinance/puffer-sdk';
const walletClient = PufferClientHelpers.createWalletClient({
chain: Chain.Holesky,
provider: window.ethereum,
});
// Use the `PufferClient` to interact with `PufferVaultHandler`.
const pufferClient = new PufferClient(Chain.Holesky, walletClient);
const { transact } = pufferClient.vault.depositETH('0x123...');
const txHash = await transact(BigInt(1e18));
2. Using the Handler Directly
This is the optimal way to use handlers since this will only import code and ABI of the handler being used which will improve tree-shaking and reduce bundle size depending on the bundler used. The downside of this is that the code will be more verbose.
// Import the modules directly from their respective files.
import { Chain } from '@pufferfinance/puffer-sdk/dist/chains/constants';
import { PufferClientHelpers } from '@pufferfinance/puffer-sdk/dist/api/puffer-client-helpers';
import { PufferVaultHandler } from '@pufferfinance/puffer-sdk/handlers/puffer-vault-handler';
const walletClient = PufferClientHelpers.createWalletClient({
chain: Chain.Holesky,
provider: window.ethereum,
});
const publicClient = PufferClientHelpers.createPublicClient({
chain: Chain.Holesky,
provider: window.ethereum,
});
const pufferVaultHandler = new PufferVaultHandler(
Chain.Holesky,
walletClient,
publicClient,
);
const { transact } = pufferVaultHandler.depositETH('0x123...');
const txHash = await transact(BigInt(1e18));