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:
pub type LendingAction {
indexers: RedeemerIndexer,
pool_in_idx: Option<Int>, // Required
loan_in_idx: Option<Int>, // Not required
protocol_script_idx: Option<Int>, // Required
protocol_config_idx: Int,
fee_ou_idx: Option<Int>, // Required if fee > 0
}
pub type RedeemerIndexer {
CreatePool(Int)
RedeemPool(List<(Int, Option<Int>)>)
CreateLoan { pool_ou_idx: Int, loan_ou_idx: Int } // Create Loan is at index 2
...
}
Specific example for Create Loan:
LendingAction {
indexers: CreateLoan { pool_ou_idx: 1, loan_ou_idx: 2 },
pool_in_idx: Some(0),
loan_in_idx: None,
protocol_script_idx: Some(1),
protocol_config_idx: 2,
fee_ou_idx: Some(0),
}
Diagnostic Notation:
121([_
123([_ 1, 2]), // Create loan index is 2
121([_ 0]),
122([]),
121([_ 1]),
2,
121([_ 0]),
])
OraclePriceCalcRdmr Redeemer Structure
OraclePriceCalcRdmr redeemer structure:
pub type OraclePriceCalcRdmr {
oracle_source_idx: Int,
oracle_path_idxs: List<Int>,
oracle_idxs: List<(UTxOTarget, OracleUtxoType, Int)>,
prices: OraclePriceInfo,
borrow_rates: Pairs<YieldToken, Basis>,
}
pub type UTxOTarget {
Ref
Out
}
pub type OracleUtxoType {
TOrcfaxFsp
TOrcfaxFs
TLiqwidMarketState
TLiqwidMarketParam
TLiqwidOracle
TDanogoFloatPool
TIndigo
TDjed
TDanogoStaking
TMinswapLP
}
// Pairs<ToToken, Pairs<FromToken, PRational>>,
pub type OraclePriceInfo =
Pairs<TupleAsset, Pairs<TupleAsset, PRational>>
Specific example:
OraclePriceCalcRdmr {
oracle_idxs: [(Ref, TLiqwidMarketState, 1), (Ref, TLiqwidMarketParam, 0)],
oracle_source_idx: 3,
oracle_path_idxs: [2],
// Price from qdjed to djed
prices: [Pair(djed, [Pair(qdjed, PRational(3, 5))])],
borrow_rates: [Pair(qdjed, 663)],
}
Diagnostic Notation:
121([_
3,
[_ 2],
[_
[_ 121([]), 123([]), 1],
[_ 121([]), 124([]), 0],
],
{_
[_
h'919d4c2c9455016289341b1a14dedf697687af31751170d56a31466e',
h'74444a4544',
]: {_
[_
h'6f262e859569d245aab15265a902dccf33f790a57227ea30edbbdef4',
h'',
]: 121([_ 3, 5]),
},
},
{_
[_
h'6f262e859569d245aab15265a902dccf33f790a57227ea30edbbdef4',
h'',
]: 663,
},
])
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