Lend Calldata (lend and permitLend)
The lendCalldata
and permitLendCalldata
methods generate the calldata required to lend paraUSD.
Lend (lendCalldata)
Usage
import { SupportedChainIds, lendCalldata } from "@parabolfi/core";
import { ParabolServer } from "@parabolfi/server";
async function generateLendCalldata() {
const parabolServer = new ParabolServer({
apiKey,
});
const chainId = SupportedChainIds.ZKSYNC;
const parabolData = await parabolServer.fetchLendParameters(chainId);
// Optional
const partnerConfig = {
id: "0xf86413094669713f8a2a804d93acd71249ed481ab264a5db88f52eac99dac159",
partnerFeeBPS: "100", // %1 fee
partnerOwner: walletAddress,
partnerVault: walletAddress,
};
const calldata = lendCalldata({
walletAddress,
maturity: 6, // 6 days
principal: "1000", // 1000 paraUSD
parabolData,
partnerConfig,
});
console.log("calldata", calldata);
}
Before specifying the maturity, make sure to check the available maturities
from the parabolData.availableMaturities
array. Also, it can be obtained
from the ParabolServer’s fetchParabolData
method.
Parameters
walletAddress
: Address - The wallet address of the lender.maturity
: number - The lending duration in days.principal
: string - The amount to lend in paraUSD.parabolData
:LendParameters
- The Parabol data for the lending operation.partnerConfig
:PartnerConfig
- The partner configuration for the lending operation. (optional)
Returns
string
- The generated calldata for the lending operation.
0x1949f17e...
Important Notes
- The principal amount must be greater than or equal to the minimum lending limit defined in the Parabol data.
- The maturity (lending duration) must be one of the available maturities in the Parabol data.
- The method validates the input parameters and throws a
ParabolSDKError
if they are invalid.
Permit Lend (permitLendCalldata)
Before using this method, you need to get a permit signature.
⚠️ Important Notes
To use Permit Lend, a signature must be obtained from the user. The required domain
, types
, and data
for this signature can be retrieved using the preparePermitLendSignature
helper function in the @parabolfi/core
SDK. However, the ParabolUSDName
, and ParabolUSDVersion
information required for this function must be fetched using the fetchParabolConfig
and nonce
from the fetchParabolUSDNonce functions in the ParabolServer class. All steps are outlined below.
Fetch server-side information from ParabolServer
import { ParabolServer } from "@parabolfi/server";
import { SupportedChainIds } from "@parabolfi/core";
const parabolServer = new ParabolServer({
apiKey,
});
const chainId = SupportedChainIds.ZKSYNC;
const parabolData = await parabolServer.fetchLendParameters(chainId);
const response = await parabolServer.fetchParabolConfig([chainId]);
const { ParabolUSDName, ParabolUSDVersion } = response[chainId];
const nonceResponse = await parabolServer.fetchParabolUSDNonce(walletAddress, [
chainId,
]);
const nonce = BigInt(nonceResponse[chainId]?.nonce) ?? 0n;
The ParabolUSDName
and ParabolUSDVersion
are used to construct the
domain
object in the preparePermitLendSignature
function. If you want, you
can leave this part hardcoded after fetching it once.
Generate the signature
import { preparePermitLendSignature } from "@parabolfi/core";
const { domain, types, data, deadline } = preparePermitLendSignature({
principal: "1000", // Amount to lend (in paraUSD)
walletAddress,
chainId,
nonce,
ParabolUSDName,
ParabolUSDVersion,
});
// viem account signTypedData
const permitSignature = await account.signTypedData({
domain,
types,
message: data,
primaryType: "Permit",
});
You can use any method to sign the typed data.
Generate the calldata
import { permitLendCalldata } from "@parabolfi/core";
// Optional
const partnerConfig = {
id: "0xf86413094669713f8a2a804d93acd71249ed481ab264a5db88f52eac99dac159",
partnerFeeBPS: "100", // %1 fee
partnerOwner: walletAddress,
partnerVault: walletAddress,
};
const calldata = permitLendCalldata({
walletAddress,
maturity: 30, // Lending duration in days
principal: "1000", // Amount to lend (in paraUSD)
permitSignature,
deadline,
parabolData,
partnerConfig, // Optional
});
Parameters
walletAddress
: Address - The wallet address of the lender.maturity
: number - The lending duration in days.principal
: string - The amount to lend in paraUSD.permitSignature
: Hex - The permit signature.deadline
: bigint - The deadline for the permit.parabolData
:LendParameters
- The Parabol data for the lending operation.partnerConfig
:PartnerConfig
- The partner configuration for the lending operation. (optional)
Returns
string
- The generated calldata for the permit lending operation.
0xaa121ea9...
Notes
- The principal amount must be greater than or equal to the minimum lending limit defined in the Parabol data.
- The maturity (lending duration) must be one of the available maturities in the Parabol data.
- The permit signature must be a valid Ethereum signature.
- The deadline is the timestamp at which the permit will expire. It is
calculated as
currentTimestamp + 1 hour
. - This method is used for gasless transactions where the user signs a permit instead of sending an approval transaction.
- The method validates the input parameters and throws a
ParabolSDKError
if they are invalid.
permitLend
calldata flow will be simplified in the future.