Guide to Build Transaction Create Fixed Loan
Purpose
Guide on how to Build Transaction Create Fixed Rate Loan based on Danogo APIs
Steps to Build Transaction Create Loan
Step 1: Get Required Parameters
Use the API to get necessary parameters for Create Loan.
Step 2: Understand Redeemer Structure:
Fixed LendingAction Redeemer Structure
LendingAction redeemer structure for Create Loan:
pub type LendingAction {
indexers: RedeemerIndexer,
pool_in_idx: Int, // Required
loan_in_idx: Int, // Optional
protocol_script_idx: Int, // Required
protocol_config_idx: Int, // Required
fee_ou_idx: Int, // Required if fee > 0
}
pub type RedeemerIndexer {
CreatePool{..}
RedeemPool{..}
CreateLoan { pool_ou_idx: Int, loan_ou_idx: Int }
...
}Specific example for Create Loan:
LendingAction {
indexers: CreateLoan { pool_ou_idx: 1, loan_ou_idx: 2 },
pool_in_idx: 0,
loan_in_idx: -1,
protocol_script_idx: 1,
protocol_config_idx: 2,
fee_ou_idx: 0,
}Diagnostic Notation form:
121([_ 123([_ 1, 2]), 0, -1, 1, 2, 0])Leverage LendingAction Redeemer Structure
LendingAction redeemer structure for Topup Withdraw:
pub type LendingAction {
CreatePool {..}
UpdateMarketParam {..}
TopupWithdraw { protocol_cfg_ref_idx: Int, pools: List<PoolMarketIndexer> }
...
}
pub type PoolMarketIndexer {
pool_out_idx: Int,
fee_out_idx: Option<Int>,
market_ref_idx: Int,
}Specific example for Topup Withdraw:
TopupWithdraw {
protocol_cfg_ref_idx: 0,
pools: [
PoolMarketIndexer {
pool_out_idx: 0,
market_ref_idx: 1,
fee_out_idx: None,
},
],
}Diagnostic Notation form:
123([_ 0, [_ 121([_ 0, 122([]), 1])]])Staking Contract StakingContractAction Redeemer Structure
StakingContractAction redeemer structure for Topup Withdraw Staking:
pub type StakingContractAction {
CreateContract {..}
TopupWithdrawStaking(Int) // staking contract out_idx
...
}Specific example for Topup Withdraw Staking:
TopupWithdrawStaking(0)Diagnostic Notation form:
122([_ 0])OraclePriceCalcRdmr Redeemer Structure
OraclePriceCalcRdmr redeemer structure:
pub type OraclePriceCalcRdmr {
global_config_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
In
}
pub type OracleUtxoType {
TOrcfaxFsp
TOrcfaxFs
TLiqwidMarketState
TLiqwidMarketParam
TLiqwidOracleV2
TDanogoPool
TIndigo
TDjed
TDanogoStaking
TMinswapLP
TLiqwidOracleV1
TSplashLiquidityPoolCpammG1
TSplashLiquidityPoolCpammG2
TSplashLiquidityPoolCpammG3
TSplashLiquidityPoolStable
TCharli3
TMinswapLPStable
}
// Pairs<ToToken, Pairs<FromToken, PRational>>,
pub type OraclePriceInfo =
Pairs<TupleAsset, Pairs<TupleAsset, (CalcType, PRational)>>
// 0: Normal
// 1: Splash
pub type CalcType =
IntSpecific example:
OraclePriceCalcRdmr {
global_config_idx: 3,
oracle_path_idxs: [2],
oracle_idxs: [(Ref, TLiqwidMarketState, 1), (Ref, TLiqwidMarketParam, 0)],
// Price from qdjed to djed
prices: [Pair(djed, [Pair(qdjed, (0, PRational(3, 5)))])],
borrow_rates: [Pair(qdjed, 663)],
}Diagnostic Notation form:
121([_
3,
[_ 2],
[_
[_ 121([]), 123([]), 1],
[_ 121([]), 124([]), 0],
],
{_
[_
h'919d4c2c9455016289341b1a14dedf697687af31751170d56a31466e',
h'74444a4544',
]: {_
[_
h'6f262e859569d245aab15265a902dccf33f790a57227ea30edbbdef4',
h'',
]: [_ 0, 121([_ 3, 5])],
},
},
{_
[_
h'6f262e859569d245aab15265a902dccf33f790a57227ea30edbbdef4',
h'',
]: 663,
},
])Step 3: Create Transaction:
Use the obtained parameters to create transaction for fixed loan.
Validity range: Set validity range for transaction
Ensure time to live <= 6 minutes.
Input:
Note: Information like
outRef,address,coin,multiAssetsare fully returned from API.PoolInUtxo: Pool you want to borrow from.
Spend redeemer: Build according to Fixed LendingAction redeemer CreateLoan structure, ensure correct index specification.
leveragePoolInUtxo: Leverage pool to withdraw base token for lending, returned from API.
Spend redeemer: Build according to Leverage LendingAction redeemer TopupWithdraw structure, ensure correct index specification.
stakingContractInUtxo: Staking Contract pool to withdraw base token for lending, returned from API.
Spend redeemer: Build according to StakingContractAction redeemer TopupWithdrawStaking structure, ensure correct index specification.
Input from wallet containing tokens needed as collateral for the loan.
Output:
PoolOutUtxo: Pool output after borrowing.
Pool output UTxO information is fully returned from API.
LoanOutUtxo: Loan output.
Loan output UTxO information is returned from API, except for
loanMaturity.loanMaturity: Loan maturity time. Calculated as lower bound + loanDuration in milliseconds.
Note:
Address returned from API only includes loan script payment key, if you want to receive rewards from loan when delegating to pool, need to specify borrower's stake key for loan address.
FeeOutUtxo: Transaction fee output.
Fee output UTxO information is fully returned from API.
No need to create output if not returned by API.
leveragePoolOutUtxo: Leverage output after withdrawing base token for lending.
Leverage output UTxO information is fully returned from API.
No need to create output if not returned by API.
stakingContractOutUtxo: Staking Contract output after withdrawing base token for lending.
Staking Contract output UTxO information is fully returned from API.
No need to create output if not returned by API.
withdrawalFeeOutUtxo: Withdrawal fee output.
Withdrawal fee output UTxO information is fully returned from API.
No need to create output if not returned by API.
Reference Input:
Add all reference inputs returned from API.
Withdrawal:
OraclePriceCalcRdmr
Add withdrawal to reward address with reward amount as returned from API.
Reward redeemer: Has OraclePriceCalcRdmr redeemer structure:
pricesinformation returned from API. WithborrowTokenasToTokenandcollateralTokenasFromToken.global_config_idx,oracle_path_idxsandoracle_idxsinformation taken from reference inputs.For
oracle_idxs, if UTxO is in output thenUTxOTargetisOut, if in reference input thenUTxOTargetisRef, noIncase in Create Fixed Loan.CalcType in
prices: Always 0 in Create Fixed Loan case.
Withdraw Staking Reward (Optional)
Reward address with reward amount as returned from API.
Redeemer: Build according to StakingContractAction redeemer TopupWithdrawStaking structure.
Mint:
API returns complete mint information including
policyId,assetsandredeemerType.With
redeemerTypebeing:FIXED: Add mint withpolicyIdandassetsset with Fixed LendingAction CreateLoan redeemer.LEVERAGE: Add mint withpolicyIdandassetsset with Leverage LendingAction TopupWithdraw redeemer.STAKING: Add mint withpolicyIdandassetsset with StakingContractAction TopupWithdrawStaking redeemer.
Auxiliary Data:
Add metadata for
loanOwnerNftaccording to information returned from API. (Optional)
Note: After sorting inputs and reference inputs according to chain sort order, need to get correct index to specify in redeemers.
Last updated