FlashLoan Reciever Specification
This document defines the specification for contracts that receive flash loans in a decentralized environment, ensuring that the receiving contract can interact with flash loan protocols efficiently and securely.
The onloanrecieved
handler expects the following parameters within the msg
object:
msg.From
Type:
string
Description: The identifier of the entity sending the loan. This represents the account from which tokens will be transferred.
msg.Tags.Quantity
Type:
string
(converted tonumber
within the handler)Description: The amount of tokens to be transferred from
msg.From
to the contract. This value determines both the transfer quantity and the subsequent approval amount after fees.
msg.Tags.TokenProcessId
Type:
string
Description: The process ID of the token contract (
AOToken-Specification
). This ID is used to specify which token contract to interact with for theTransferFrom
andApprove
actions.
msg.Tags.Fee
Type:
string
(converted tonumber
within the handler)Description: The fee percentage to be applied to the transferred tokens. This percentage is used to calculate the fee amount, which is added to the approved quantity.
🚀 Explanation :
Parameter Extraction and Validation
Converts
Quantity
andFee
from strings to numbers.Validates the types of
quantity
,tokenProcessId
, andfeePercentage
Fee Calculation
Calculates the fee based on the provided percentage.
Determines the total amount to approve, which is the sum of the transferred quantity and the fee.
Token Transfer (
TransferFrom
)
Initiates a TransferFrom
action to move the specified quantity
of tokens from msg.From
to the contract (ao.id
).
Arbitage/Self-Liquidation/ Loan Refiance
Add specific calls to ensure what you want to perfrom gets performed.
Transfer back Tokens (Transfer
)
We must return the borrowed token back to the ArFlash
protocol otherwise the whole transaction might revert.
Grants msg.From
the permission to spend the totalApprove
amount of tokens on behalf of the contract. This includes both the transferred quantity and the calculated fee.
Granting this protocol will transferback the same number of tokens back to itself.
Last updated
Was this helpful?