Danogo
  • INTRODUCTION
    • Danogo
    • Litepaper
      • Danogo Fixed Pool Lending
      • Danogo Flexible Pool Lending
  • Follow Us
  • Blogs
    • Cardano Smart Contract Composability Challenges
    • Danogo Multi-Source Oracle Aggregation
    • Handle concurrency in a market crash
    • Fixed Pool Lending Early Adopter Rewards Program
    • Prevent LP Price Manipulation
    • Danogo Flexible Pool Incentivized Testnet
  • HOW TO USE
    • Getting Started
      • Ready with your Cardano Wallet
      • Connecting Wallet
    • Guides
      • Yield Aggregator
        • How to find the most suitable yield products?
        • How to Supply Liquidity?
        • How to Withdraw Liquidity?
        • How to Borrow Tokens?
        • How to Repay a Loan?
      • Danogo Staking Bond
        • How to Borrow ADA Staking Rights?
        • How to Provide Liquidity?
      • Danogo Bond Dex
        • How to buy a Bond at Market price?
        • How to buy a Bond at your desired price (create Buy order)
        • How to sell a Bond at Market price?
        • How to sell a Bond at your desired price? (create Sell order)
        • How to update Sell order (Listing)?
      • Fixed Pool Lending
        • How to Create a Pool
        • How to Create a Loan
        • How To Repay a Loan
        • Top-up Collateral
        • How To Redeem
        • How To Perform Mass Liquidation
      • Flexible Pool Lending
        • How To Supply Assets
        • How To Withdraw Assets
        • How To Borrow
        • How To Modify Loans
        • How To Repay Loan
    • Video Guides
    • FAQ
      • Danogo Dex
      • Danogo Staking Bond
      • Yield Aggregator
      • Fixed Pool Lending
  • Developers
    • Integration
      • How to build transaction to create a fixed rate loan
      • APIs
        • Loan
        • Utility
        • Models
Powered by GitBook
On this page
  1. Developers
  2. Integration

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.

  1. Validity range: Set validity range for transaction

    • Ensure time to live <= 6 minutes.

  2. Input:

    • PoolInUtxo: Pool you want to borrow from.

      • The information outRef, address, coin, and multiAssets 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, and multiAssets 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.

  3. 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 and minAda 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), and fee_ou_idx (FeeOutUtxo) to specify in LendingAction redeemer.

  4. 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 and protocol_config_idx to specify in LendingAction redeemer.

      • oracle_idxs, oracle_source_idx, and oracle_path_idxs to specify in OraclePriceCalcRdmr redeemer.

  5. Withdrawal:

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

    • Reward redeemer: Has OraclePriceCalcRdmr redeemer structure:

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

      • borrow_rates information returned from API as borrowRateNum and borrowRateDen, convert to Basis using formula:

        • borrowRateNum * 10_000 / borrowRateDen

      • oracle_idxs, oracle_source_idx, and oracle_path_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.

  6. Mint:

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

    • For redeemerType:

      • Liqwid: Add mint with policyId and assets with any redeemer, example 121([]).

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

  7. Auxiliary Data:

    • Add metadata for loanOwnerNft according to information returned from API. (Optional)

PreviousIntegrationNextAPIs

Last updated 14 days ago