BAMM Plugin
The BAMM Plugin enables you to interact with BAMM, a decentralized platform for borrowing, lending, and managing liquidity positions in Fraxswap-style pools.
Installation
-
Install the required package:
Terminal window npm i @iqai/plugin-bammTerminal window pnpm add @iqai/plugin-bammTerminal window yarn add @iqai/plugin-bamm -
Create a .env file with the following environment variable:
Terminal window WALLET_PRIVATE_KEY=your-wallet-private-keyNever commit your
.env
file or share your private key. Anyone with access to your private key can control your wallet and funds. Make sure to:- Add
.env
to your.gitignore
file - Never share your private key in any form
- Use a dedicated development wallet with limited funds
- Add
Basic Setup
Hereβs how to initialize and use the BAMM plugin:
import { createBAMMPlugin } from '@iqai/plugin-bamm';import { fraxtal } from 'viem/chains';
async function main() { // Initialize BAMM plugin const bammPlugin = await createBAMMPlugin({ walletPrivateKey: process.env.WALLET_PRIVATE_KEY, chain: fraxtal, });
// Now the plugin is ready to use}
Available Operations
The BAMM plugin allows the following operations:
- BAMM_BORROW: Borrow assets from BAMM pools using collateral.
- BAMM_LEND: Lend assets to BAMM pools.
- BAMM_ADD_COLLATERAL: Add collateral to your BAMM position.
- BAMM_REMOVE_COLLATERAL: Remove collateral from your BAMM position.
- BAMM_REPAY: Repay borrowed assets to a BAMM pool.
- BAMM_WITHDRAW: Withdraw LP tokens by redeeming BAMM tokens.
- BAMM_GET_POSITIONS: View current positions in BAMM pools.
- BAMM_GET_POOL_STATS: Get statistics for all BAMM pools.
Usage Examples
Either token address or token symbol can be provided in the query. Only the bamm address is must
Operation | Example Query |
---|---|
Borrow tokens | borrow 10k of CABU from this 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Lend LP tokens | lend 10k lp tokens to 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Add collateral | add 100k collateral of 0xCc3023635dF54FC0e43F47bc4BeB90c3d1fbDa9f to this 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Remove collateral | remove 10k collateral of IQT from this 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Repay borrowed tokens | repay 10k of CABU to this 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Withdraw LP tokens | withdraw 10k bamm tokens from this 0xC5B225cF058915BF28D7d9DFA3043BD53C63Ea84 bamm |
Get your positions | My Bamm postions |
Get available bamm pools | All bamm pools |
Configuration Options
The plugin requires the following configuration options:
interface BAMMActionParams { chain: Chain; // Blockchain network configuration walletPrivateKey: string; // Private key for transactions}
Error Handling
Handle errors gracefully by wrapping the plugin actions in try/catch
blocks:
try { const bammPlugin = await createBAMMPlugin({ walletPrivateKey: process.env.WALLET_PRIVATE_KEY, chain: fraxtal, });} catch (error) { console.error('Failed to initialize BAMM plugin:', error);}
Best Practices
- Security: Never expose your wallet private key.
- Amount Verification: Always verify the amounts and token addresses before interacting with the plugin.
- Rate Limits: Be mindful of rate limits and avoid excessive transactions in a short period.
Common Issues and Troubleshooting
- Insufficient Balance: Ensure that your wallet has enough balance to perform the requested operations.
- Transaction Failure: Confirm that the pool address is valid and your collateral is sufficient.
- Network Issues: Ensure you have a stable connection to the blockchain network.
- Token Approval: Check if the required tokens are approved for lending or borrowing.