Guide to Create a Float Lending Protocol Transaction

Objective

Guide to create a loan transaction from the Float Lending protocol based on Danogo APIs

Steps

Step 1: Get Required Parameters

Use the provided API to get necessary information for the transaction.

Step 2: Understanding Redeemer Structures

Float LendingAction Redeemer Structure

  • LendingAction redeemer structure for Create Loan:

pub type LendingAction {
    CreatePool {..}
    UpdateMarketParam {..}
    TopupWithdraw {..}
    CreateLoan {
        pool_out_idx: Int, // Required
        loan_out_idx: Int, // Required
        fee_out_idx: Option<Int>, // Required if fee > 0
        protocol_cfg_ref_idx: Int, // Required
        market_ref_idx: Int, // Required
        pool_in_out_ref: OutputReference, // Required
    }
}
  • Concrete example for Create Loan:

CreateLoan {
        pool_out_idx: 2,
        loan_out_idx: 1,
        fee_out_idx: Some(0),
        protocol_cfg_ref_idx: 1,
        market_ref_idx: 0,
        pool_in_out_ref: pool_in.output_reference,
}
  • Diagnostic Notation form:

124_0([_
        2,
        1,
        121([_ 0]),
        1,
        0,
        121_0([_
                h'516a6e6806e9dc771c3dce9a5fa27a4e6ec994b4609839c4df42778e9bd63bc5',
                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,
}
  • Concrete 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
    ...
}
  • Concrete 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 =
    Int
  • Concrete 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

1. Validity Range

  • Ensure transaction time-to-live (TTL) <= 6 minutes

  • Transaction start time is set to value from PoolOutputUtxo.datum.interestTime

  • API returns data in milliseconds, convert to appropriate format for your tool

2. Inputs

  • Note: All outRef, address, coin, multiAssets information is provided by the API.

    • PoolInUtxo: Pool you want to borrow from.

      • Spend redeemer: Build according to Float's LendingAction redeemer Create Loan structure, ensure correct index specifications.

    • leveragePoolInUtxo: Leverage pool to withdraw base token for lending, returned by API.

      • Spend redeemer: Build according to Leverage's LendingAction redeemer Topup Withdraw structure, ensure correct index specifications.

    • stakingContractInUtxo: Staking Contract pool to withdraw base token for lending, returned by API.

      • Spend redeemer: Build according to StakingContractAction redeemer TopupWithdrawStaking structure, ensure correct index specifications.

    • Input from wallet containing tokens needed for loan collateral.

3. Outputs

  • PoolOutUtxo: Pool output after borrowing.

    • All pool output UTxO information is provided by API.

  • LoanOutUtxo: Loan output.

    • All loan output UTxO information is provided by API.

    • Note:

      • Address returned by 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.

    • All fee output UTxO information is provided by API.

    • Not required if API doesn't return it.

  • leveragePoolOutUtxo: Leverage output after withdrawing base token for lending.

    • All Leverage output UTxO information is provided by API.

    • Not required if API doesn't return it.

  • stakingContractOutUtxo: Staking Contract output after withdrawing base token for lending.

    • All Staking Contract output UTxO information is provided by API.

    • Not required if API doesn't return it.

  • withdrawalFeeOutUtxo: Withdrawal fee output.

    • All withdrawal fee output UTxO information is provided by API.

    • Not required if API doesn't return it.

4. Reference Inputs

Add all reference inputs returned in API

5. Withdrawal

  • OraclePriceCalcRdmr

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

    • Reward redeemer: Has OraclePriceCalcRdmr redeemer structure:

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

      • global_config_idx, oracle_path_idxs and oracle_idxs information 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 Float Loan.

      • CalcType in prices: Always 0 for Create Float Loan.

  • Withdraw Staking Reward (Optional)

    • Reward address with reward amount as returned by API.

    • Redeemer: Build according to StakingContractAction redeemer TopupWithdrawStaking structure.

6. Mint

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

  • For redeemerType:

    • FLOAT: Add mint with policyId and assets set with Float's LendingAction CreateLoan redeemer.

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

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

7. Auxiliary Data

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

Note: After sorting inputs and reference inputs according to chain sort order, ensure correct index specification in redeemers.

Last updated