Lend
The lend
method allows you to lend paraUSD tokens to the Parabol protocol. This operation creates a note position representing your lending position.
Usage
import { ParabolAccount, SupportedChainIds } from "@parabolfi/core";
import { ParabolServer } from "@parabolfi/server";
const parabolServer = new ParabolServer({
apiKey,
});
async function lendParaUSD() {
const privateKey = "0x..."; // Your private key
const chainId = SupportedChainIds.ZKSYNC;
// Fetch Parabol data
const parabolData = await parabolServer.fetchLendParameters(chainId);
// Initialize ParabolAccount with Parabol data
const account = await ParabolAccount.fromPrivateKey({
privateKey,
chainId,
parabolData,
});
const lendParams = {
principal: "1000", // Amount to lend (in paraUSD)
maturity: 30, // Lending duration in days
};
try {
const txHash = await account.lend(lendParams);
console.log("Lending transaction hash:", txHash);
} catch (error) {
console.error("Error lending paraUSD:", error);
}
}
🕹️
Before lending, make sure to check the available maturities from the
parabolData.availableMaturities
.
Parameters
The lend method takes an object with the following properties:
principal
: string - The amount of paraUSD to lend (in ether units).maturity
: number - The lending duration in days.
Returns
Hex
- A promise that resolves to the transaction hash of the lending transaction.
Important Notes
- The
ParabolAccount
must be initialized with valid Parabol data before calling thelend
method. - The account must have sufficient paraUSD balance and allowance for the lending operation.
- If the allowance is insufficient, the method will automatically approve the required amount before lending.
Errors
This method may throw a ParabolSDKError
in the following cases:
- If the Parabol data is not initialized or invalid.
- If the provided maturity is not available in the current Parabol data.
- If the principal amount is below the minimum lending limit.
- If the transaction fails for any reason (e.g., insufficient balance, network issues).
Always wrap the call in a try-catch block to handle potential errors.