Integration
Technical Information
Executing Functions Within the Protocol
Interacting with the protocol involves using the execute function, a central component of the protocol. This function is essential for carrying out all of the operations within the protocol. To effectively use the execute function, you must provide specific parameters, which are the following:
moduleName_ (string memory)
This represents the name of the module you intend to interact with.
value_ (uint256)
For most operations, you can set this to 0 ether
. It denotes the amount of Ether to be sent with the function call.
data_ (bytes memory)
This is the ABI-encoded data for the function call you wish to execute within the module.
operation_ (Enum.Operation)
This ENUM value indicates the type of call you're making. Use 0
for a regular call and 1
for a delegate call.
Interacting with Specific Modules
In the description above expressing the needed parameters to execute a module transaction you have a data field. This data field is broken down into 2 parts these parts is how a function is created inside the protocol. Below are the parts of a function to ensure a successful transaction:
Action Data:
The action data is comprised of the parameters needed to execute the specific action.
Module Data
The module data is comprised of the blueprint parameters.
Here's a step-by-step example utilizing the Loan Management Module to create a claim:
Loan Management - Create Claim
function createClaim(
bytes calldata claimData_, IClaim - claimAmount, claimToken
address user_,
uint256 loanId_,
uint256 proimisedAmount_,
address collateralToken_,
string memory lenderName_,
string memory pointer
)
public
{
bytes memory ltvProtectData = abi.encodeWithSignature(
"createClaim(bytes,address,uint256,uint256,address,string,string)",
claimData_,
user_,
loanId_,
proimisedAmount_,
collateralToken_,
lenderName_,
pointer
);
bool success = executeBlueprint("LTVProtectBlueprint", 0, ltvProtectData, Enum.Operation.Call);
require(success, "ERR: Blueprint Execution Failed");
}
Breaking down the above function
bytes memory ltvProtectData = abi.encodeWithSignature(
"createClaim(bytes,address,uint256,uint256,address,string,string)",
claimData_, -> THE ACTION DATA
user_,
loanId_,
proimisedAmount_,
collateralToken_,
lenderName_,
pointer
);
Inside each function sent to a blueprint you will see a bytes data parameter this is the parameter needed to send to the action. In the above breakdown of action data, this claim data is a representation of data inside the claim struct.
Action Encoding
bytes memory claimData = abi.encode(WETH, 100);
In this example, we're preparing data to create a claim action. The claim token is WETH and the amount of the claim is 100.
Breaking down module parameters
function createClaim(
bytes calldata claimData_,
address user_,
uint256 loanId_,
uint256 proimisedAmount_,
address collateralToken_,
string memory lenderName_,
string memory pointer
)
public
{}
Module Encoding
All parameters that are to be sent to the module need to be encoded.
bytes memory moduleData = abi.encode(claimData, address(0x2), 2, 10_000, WETH, "AaveBlueprint", "Contract.Address.Lender.AAVE")
Protocol Execution
Now that all data has been encoded we can take the ModuleData and pass that with the name of the module through the protocols execute function.
protocol.execute("LoanManagementModule", 0 ether, moduleData, Enum.Operation.Call);
Finally, we're using the execute
function of the protocol to interact with the LenderModule
.
Last updated