How to build transaction to create a fixed rate loan
Guide to Build "Create Fixed Rate Loan" Transaction
Steps to Build Create Loan Transaction
Step 1: Get Required Parameters
Use the API to get necessary parameters for Create Loan.
Step 2. Understanding Redeemer Structure:
LendingAction Redeemer Structure
LendingAction redeemer structure for Create Loan:
Specific example for Create Loan:
Diagnostic Notation:
OraclePriceCalcRdmr Redeemer Structure
OraclePriceCalcRdmr redeemer structure:
Specific example:
Diagnostic Notation:
Step 3. Create Transaction:
Use the obtained parameters to create a fixed loan transaction.
Validity range: Set validity range for transaction
Ensure time to live <= 6 minutes.
Input:
PoolInUtxo: Pool you want to borrow from.
The information
outRef
,address
,coin
, andmultiAssets
is fully returned by the API.Spend redeemer: Build according to LendingAction redeemer structure for Create Loan, ensure correct index specification.
LiqwidInUtxo: Liqwid pool to withdraw base token for lending, returned from API.
The information
outRef
,address
,coin
, andmultiAssets
is fully returned by the API.Spend redeemer: Any redeemer structure. Simple example in Diagnostic Notation:
121([])
Input from wallet containing required tokens for collateral.
Note: After sorting inputs according to chain sort order, get correct index of
pool_in_idx
(PoolInUtxo) to specify in LendingAction redeemer.
Output:
PoolOutUtxo: Pool output after borrowing.
Complete pool output UTxO information returned from API.
LoanOutUtxo: Loan output.
Loan output UTxO information returned from API, except for
loanMaturity
andminAda
in datum.loanMaturity
: Loan maturity time. Calculated as lower bound + loanDuration in milliseconds.minAda
: Minimum ADA required to maintain UTxO, determined when creating UTxO, must be >= 2_000_000 (2 ADA).
Note: Address returned from API only includes loan script payment key, if you want to receive rewards from loan when delegating to pool, specify borrower's stake key for loan address.
FeeOutUtxo: Transaction fee output.
No need to create fee output if API does not return it.
Complete fee output UTxO information returned from API.
LiqwidOutUtxo: Liqwid output after withdrawing base token for lending.
Complete Liqwid output UTxO information returned from API.
Note: Get correct indices of
pool_ou_idx
(PoolOutUtxo),loan_ou_idx
(LoanOutUtxo), andfee_ou_idx
(FeeOutUtxo) to specify in LendingAction redeemer.
Reference Input:
Add all reference inputs returned from API.
Note: After sorting reference inputs according to chain sort order, get correct indices of:
protocol_script_idx
andprotocol_config_idx
to specify in LendingAction redeemer.oracle_idxs
,oracle_source_idx
, andoracle_path_idxs
to specify in OraclePriceCalcRdmr redeemer.
Withdrawal:
Add withdrawal to reward address with reward amount returned from API.
Reward redeemer: Has OraclePriceCalcRdmr redeemer structure:
prices
information returned from API. WithborrowToken
asToToken
andcollateralToken
asFromToken
.borrow_rates
information returned from API asborrowRateNum
andborrowRateDen
, convert toBasis
using formula:borrowRateNum
* 10_000 /borrowRateDen
oracle_idxs
,oracle_source_idx
, andoracle_path_idxs
information taken from reference inputs.For
oracle_idxs
, if UTxO is in output thenUTxOTarget
isOut
, if in reference input thenUTxOTarget
isRef
.
Mint:
API returns complete information for mint including
policyId
,assets
, andredeemerType
.For
redeemerType
:Liqwid
: Add mint withpolicyId
andassets
with any redeemer, example121([])
.Fixed
: Add mint withpolicyId
andassets
with LendingAction redeemer.
Auxiliary Data:
Add metadata for
loanOwnerNft
according to information returned from API. (Optional)
Last updated