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 theERC20Permitcontract for any supported token. - PufLockerHandler
For interacting with Puffer'sPufLockercontract. - PufferDepositorHandler
For interacting with Puffer'sPufferDepositorcontract. - PufferL2DepositorHandler
For interacting with Puffer'sPufferL2Depositorcontract. - PufferVaultHandler
For interacting with Puffer'sPufferVaultcontract. - L1RewardManagerHandler
For interacting with Puffer'sL1RewardManagercontract. - L2RewardManagerHandler
For interacting with Puffer'sL2RewardManagercontract. - L2RewardManagerHandler
For interacting with Puffer'sL2RewardManagercontract. - NucleusBoringVaultHandler
For interacting with Nucleus'sBoringVaultcontract. - NucleusTellerHandler
For interacting with Nucleus'sTellercontract. - NucleusAccountantHandler
For interacting with Nucleus'sAccountantcontract. - NucleusAtomicQueueHandler
For interacting with Nucleus'sAtomicQueuecontract. - CarrotStakingHandler
For interacting with Puffer'sCarrotStakercontract. - MtwCarrotHandler
For interacting with Merkl's Merkl Token Wrapper (mtw) CARROT contract. - PufferWithdrawalManagerHandler
For interacting with Puffer'sPufferWithdrawalManagercontract. - DistributorHandler
For interacting with Merkl'sDistributorcontract.
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));