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:

  • Diagnostic Notation form:

Leverage LendingAction Redeemer Structure

  • LendingAction redeemer structure for Topup Withdraw:

  • Specific example for Topup Withdraw:

  • Diagnostic Notation form:

Staking Contract StakingContractAction Redeemer Structure

  • StakingContractAction redeemer structure for Topup Withdraw Staking:

  • Specific example for Topup Withdraw Staking:

  • Diagnostic Notation form:

OraclePriceCalcRdmr Redeemer Structure

  • OraclePriceCalcRdmr redeemer structure:

  • Specific example:

  • Diagnostic Notation form:

Step 3: Create Transaction:

Use the obtained parameters to create transaction for fixed loan.

  1. Validity range: Set validity range for transaction

    • Ensure time to live <= 6 minutes.

  2. Input:

  • Note: Information like outRef, address, coin, multiAssets are 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.

  1. 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.

  2. Reference Input:

    • Add all reference inputs returned from API.

  3. Withdrawal:

  • OraclePriceCalcRdmr

    • Add withdrawal to reward address with reward amount as returned from API.

    • Reward redeemer: Has OraclePriceCalcRdmr redeemer structure:

      • prices information returned from API. With borrowToken as ToToken and collateralToken as FromToken.

      • global_config_idx, oracle_path_idxs and oracle_idxs information taken from reference inputs.

      • For oracle_idxs, if UTxO is in output then UTxOTarget is Out, if in reference input then UTxOTarget is Ref, no In case 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.

  1. Mint:

    • API returns complete mint information including policyId, assets and redeemerType.

    • With redeemerType being:

      • FIXED: Add mint with policyId and assets set with Fixed LendingAction CreateLoan redeemer.

      • LEVERAGE: Add mint with policyId and assets set with Leverage LendingAction TopupWithdraw redeemer.

      • STAKING: Add mint with policyId and assets set with StakingContractAction TopupWithdrawStaking redeemer.

  2. Auxiliary Data:

    • Add metadata for loanOwnerNft according 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