helpers
This module contains all the supporting functions that are used by the validator scripts that compose the lending protocol.
Functions
Common
Get the global settings from the given list of tx reference inputs, the index of the settings UTXO, and the policy ID of the settings beacon token.
Get the global settings from the datum of the given settings UTXO.
Get the oracle settings from the datum of the given oracle settings UTXO.
Downcast a given collateral utxo datum into CollateralDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the CollateralDatum structure.
Downcast a given registry utxo datum into PositionRegistryDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the PositionRegistryDatum structure.
Check if a given input contains 1 and only 1 position token, and return the result
together with the position token name.
Check if a given input contains 1 and only 1 position token, and that it is the given asset class.
read_oracle_data(
oracle_input: Input,
quoted_asset: AssetClass,
denomination: AssetClass,
tx_validity_range: ValidityRange,
beacon_policy_id: PolicyId,
) -> (QuotePrice, Bool)
Read oracle data from a given oracle input. Checks for the following:
- That the given UTXO contains the official oracle price beacon token.
- That the quoted asset and denomination are as expected, and
- That the data age is within the validity period setting
calc_amt_user_can_borrow(
collateral_amt: Int,
collateral_ratio: Int,
quote_price: QuotePrice,
) -> Int
Calculate the amount of loanable asset that a user can borrow, given their collateral asset amount.
This takes into account the price of the collateral asset to determine its value, and then applies
the loan-to-value ratio to arrive at the amount the user can borrow.
Check if the given transaction validity range is within the pre-specified limit.
This is required for determining the maturity date of a loan. This is also used as basis
for determining the time of repayment, in the case of loan repayment transactions.
Settings
Check the given input against the given output if the assets are returned to the same address.
Only the tokens are checked for equality. The lovelace amount in the output is allowed to be greater or less than
in the input since only the minAda is expected here and in this case, it depends on the size of the datum.
Check if the given value contains minted beacon tokens global_cfg_token, oracle_cfg_token, and audit_token.
Check if the given value contains burned beacon tokens global_cfg_token, oracle_cfg_token, and audit_token.
Collateral
Parse collateral datum from given raw Data.
From a given CollateralDatum, check if it is used in an active loan.
validate_collateral_output_for_loan_req(
output: Output,
input: Input,
input_datum: CollateralDatum,
borrowed_amt: Int,
loan_term: Int,
loan_asset: AssetClass,
) -> Bool
Check the collateral output when submitting a loan request, for the following:
- That the datum is correctly updated with the status
LoanRequested and contains the loan request datum (LoanDatum).
- That the collateral amount locked is at the very least, the same as the input
validate_collateral_output_for_repayment_req(
collateral_output: Output,
collateral_input: Input,
registry_input: Input,
) -> Bool
Check the collateral output when submitting a loan repayment request, for the following:
- That the datum contains the correctly updated status
RepayRequested
- That the utxo contains both the collateral amount from the input, and the repayment asset in the correct amount.
is_for_liquidation(
loan: LoanDatum,
collateral_ratio: Int,
price: QuotePrice,
tx_validity_range: ValidityRange,
) -> Bool
Check if the given loan position is either undercollateralized or overdue.
validate_dex_output(
cfg: CfgGlobal,
dex: LiquidationDex,
dex_output: Output,
pos_token: AssetName,
collateral_asset: AssetClass,
collateral_amt: Int,
) -> Bool
Check the given output for the following:
- That the address is one of the supported dexes’ order contract
- That the datum is as expected
validate_minswap_order_datum(
order_datum: MinswapOrderDatum,
pos_token: AssetName,
cfg: CfgGlobal,
) -> Bool
Check the given Minswap order datum for the following:
- That the canceller is the admin, to be sure the swap order can be cancelled if needed
- That the refund and success receivers are the collateral contract
- That the Extra Order Datum (EOD) contains the hash of the position token name
validate_liquidation_registry_output(
output: Output,
input: Input,
pool_contract: ScriptHash,
pos_token: AssetName,
liquidator: Signer,
) -> Bool
When liquidating a position, check the given registry output for the following:
- That the position token pair is sent back to the position registry contract
- That the datum is updated with the liquidator’s hash
Position Registry
validate_collateral_registry_inputs_match(
tx: Transaction,
reg_input_idx: Int,
collat_input_idx: Int,
lp_contract: ScriptHash,
output_ref: OutputReference,
) -> Bool
From the given Transaction, check the given indeces for the registry and collateral input UTXOs;
confirm that the registry input matches with the given output reference; and then finally, check
that the collateral input contains the same position token that the registry input has.
Oracle
Get the oracle settings from the given list of tx inputs, the index of the oracle settings UTXO, and the policy ID of the settings beacon token.
Check the oracle output when updating oracle price UTXO, for the following:
- That the datum is of the expected structure
- That the output goes back to the oracle contract
- That the value is the same as in the input
Lending Pool
validate_collateral_input_for_loan_proc(
input: Input,
collateral_contract: ScriptHash,
loanable_asset: AssetClass,
) -> (Bool, Address, LoanRequest)
Check the collateral input when fulfilling a loan request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
LoanRequested
validate_collateral_input_for_repayment_proc(
input: Input,
global_cfg: CfgGlobal,
) -> (Bool, Address, AssetName)
Check the collateral input when fulfilling a repayment request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
RepayRequested
- That the input contains 1 and only 1 position token
validate_collateral_output_for_loan_proc(
output: Output,
input: Input,
owner: Address,
collateral_asset: AssetClass,
pool_contract: ScriptHash,
position_token: AssetName,
) -> Bool
Check the collateral output when fulfilling a loan request, for the following:
- That the datum contains the correctly updated status:
LoanIssued
- That the value locked in the collateral UTXO now includes one of the position token pair on top of the input value.
- That the collateral UTXO is returned to the
collateral contract.
validate_collateral_output_for_repayment_proc(
input: Input,
output: Output,
owner: Address,
collateral_asset: AssetClass,
) -> Bool
Check the collateral output when fulfilling a loan repayment request, for the following:
- That the output does go back to the collateral contract
- That the datum is correctly updated with the status
Available
- That the value contained in the utxo is as expected.
validate_lending_pool_output(
input: Input,
output: Output,
pool_datum: LendingPoolDatum,
borrowed_amt: Int,
interest_amt: Option<Int>,
redeemer: UnifiedRedeemer,
) -> Bool
Check the new lending pool output for the following:
- That the amount of loanable asset contained in the utxo is as expected
- That there is no change in the datum
validate_protocol_inputs_count(
redeemer: UnifiedRedeemer,
inputs: List<Input>,
global_cfg: CfgGlobal,
) -> Bool
From a given list of tx inputs, get the ones that come from the protocol contracts and then
check that there’s only one UTXO coming from each, in order to avoid double-satisfaction exploits.
validate_registry_output_for_loan_proc(
output: Output,
owner: Address,
collateral_amt: Int,
loan_req: LoanRequest,
pool_datum: LendingPoolDatum,
global_cfg: CfgGlobal,
position_token: AssetName,
tx_validity_range: ValidityRange,
) -> Bool
Check that when fulfilling a loan request, the position utxo created at the registry contract
contains one of the position token pair, and has the expected datum.
count_protocol_inputs(
inputs: List<Input>,
collateral_contract: ScriptHash,
registry_contract: ScriptHash,
pool_contract: ScriptHash,
) -> ProtocolInputs
From a given list of inputs, count the ones coming from each of the protocol’s component contracts.
get_common_utxos(
tx: Transaction,
collateral_idxs: (Int, Int),
pool_idxs: (Int, Int),
output_ref: OutputReference,
) -> CommonUtxos
Get the UTXOs needed by lending_pool spend validator that are common among multiple redeemer cases
Compute the position_token name from a given collateral input.
Downcast a given lending pool datum into LendingPoolDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the LendingPoolDatum structure.
Get the amount of the collateral asset contained in a given output.
Audit
validate_audit_output(
input: Input,
output: Output,
global_cfg: CfgGlobal,
price: QuotePrice,
pool_datum: LendingPoolDatum,
tx_validity_range: ValidityRange,
) -> Bool
Check the datum in the given audit output for the following:
- That the
timestamp is later than the timestamp in the input datum
- That the
collateral_asset indicated matches with the one in the lending_pool datum
- That the
loanable_asset indicated matches with the one in the lending_pool datum
- That the
collateral_ratio indicated matches with the one in the global settings datum
- That the
health_score given is correctly calculated
Get the global settings from the given list of tx reference inputs, the index of the settings UTXO, and the policy ID of the settings beacon token.
Get the global settings from the datum of the given settings UTXO.
Get the oracle settings from the datum of the given oracle settings UTXO.
Downcast a given collateral utxo datum into CollateralDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the CollateralDatum structure.
Downcast a given registry utxo datum into PositionRegistryDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the PositionRegistryDatum structure.
Check if a given input contains 1 and only 1 position token, and return the result together with the position token name.
Check if a given input contains 1 and only 1 position token, and that it is the given asset class.
read_oracle_data(
oracle_input: Input,
quoted_asset: AssetClass,
denomination: AssetClass,
tx_validity_range: ValidityRange,
beacon_policy_id: PolicyId,
) -> (QuotePrice, Bool)
Read oracle data from a given oracle input. Checks for the following:
- That the given UTXO contains the official oracle price beacon token.
- That the quoted asset and denomination are as expected, and
- That the data age is within the validity period setting
calc_amt_user_can_borrow(
collateral_amt: Int,
collateral_ratio: Int,
quote_price: QuotePrice,
) -> Int
Calculate the amount of loanable asset that a user can borrow, given their collateral asset amount. This takes into account the price of the collateral asset to determine its value, and then applies the loan-to-value ratio to arrive at the amount the user can borrow.
Check if the given transaction validity range is within the pre-specified limit.
This is required for determining the maturity date of a loan. This is also used as basis for determining the time of repayment, in the case of loan repayment transactions.
Check the given input against the given output if the assets are returned to the same address. Only the tokens are checked for equality. The lovelace amount in the output is allowed to be greater or less than in the input since only the minAda is expected here and in this case, it depends on the size of the datum.
Check if the given value contains minted beacon tokens global_cfg_token, oracle_cfg_token, and audit_token.
Check if the given value contains burned beacon tokens global_cfg_token, oracle_cfg_token, and audit_token.
Collateral
Parse collateral datum from given raw Data.
From a given CollateralDatum, check if it is used in an active loan.
validate_collateral_output_for_loan_req(
output: Output,
input: Input,
input_datum: CollateralDatum,
borrowed_amt: Int,
loan_term: Int,
loan_asset: AssetClass,
) -> Bool
Check the collateral output when submitting a loan request, for the following:
- That the datum is correctly updated with the status
LoanRequested and contains the loan request datum (LoanDatum).
- That the collateral amount locked is at the very least, the same as the input
validate_collateral_output_for_repayment_req(
collateral_output: Output,
collateral_input: Input,
registry_input: Input,
) -> Bool
Check the collateral output when submitting a loan repayment request, for the following:
- That the datum contains the correctly updated status
RepayRequested
- That the utxo contains both the collateral amount from the input, and the repayment asset in the correct amount.
is_for_liquidation(
loan: LoanDatum,
collateral_ratio: Int,
price: QuotePrice,
tx_validity_range: ValidityRange,
) -> Bool
Check if the given loan position is either undercollateralized or overdue.
validate_dex_output(
cfg: CfgGlobal,
dex: LiquidationDex,
dex_output: Output,
pos_token: AssetName,
collateral_asset: AssetClass,
collateral_amt: Int,
) -> Bool
Check the given output for the following:
- That the address is one of the supported dexes’ order contract
- That the datum is as expected
validate_minswap_order_datum(
order_datum: MinswapOrderDatum,
pos_token: AssetName,
cfg: CfgGlobal,
) -> Bool
Check the given Minswap order datum for the following:
- That the canceller is the admin, to be sure the swap order can be cancelled if needed
- That the refund and success receivers are the collateral contract
- That the Extra Order Datum (EOD) contains the hash of the position token name
validate_liquidation_registry_output(
output: Output,
input: Input,
pool_contract: ScriptHash,
pos_token: AssetName,
liquidator: Signer,
) -> Bool
When liquidating a position, check the given registry output for the following:
- That the position token pair is sent back to the position registry contract
- That the datum is updated with the liquidator’s hash
Position Registry
validate_collateral_registry_inputs_match(
tx: Transaction,
reg_input_idx: Int,
collat_input_idx: Int,
lp_contract: ScriptHash,
output_ref: OutputReference,
) -> Bool
From the given Transaction, check the given indeces for the registry and collateral input UTXOs;
confirm that the registry input matches with the given output reference; and then finally, check
that the collateral input contains the same position token that the registry input has.
Oracle
Get the oracle settings from the given list of tx inputs, the index of the oracle settings UTXO, and the policy ID of the settings beacon token.
Check the oracle output when updating oracle price UTXO, for the following:
- That the datum is of the expected structure
- That the output goes back to the oracle contract
- That the value is the same as in the input
Lending Pool
validate_collateral_input_for_loan_proc(
input: Input,
collateral_contract: ScriptHash,
loanable_asset: AssetClass,
) -> (Bool, Address, LoanRequest)
Check the collateral input when fulfilling a loan request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
LoanRequested
validate_collateral_input_for_repayment_proc(
input: Input,
global_cfg: CfgGlobal,
) -> (Bool, Address, AssetName)
Check the collateral input when fulfilling a repayment request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
RepayRequested
- That the input contains 1 and only 1 position token
validate_collateral_output_for_loan_proc(
output: Output,
input: Input,
owner: Address,
collateral_asset: AssetClass,
pool_contract: ScriptHash,
position_token: AssetName,
) -> Bool
Check the collateral output when fulfilling a loan request, for the following:
- That the datum contains the correctly updated status:
LoanIssued
- That the value locked in the collateral UTXO now includes one of the position token pair on top of the input value.
- That the collateral UTXO is returned to the
collateral contract.
validate_collateral_output_for_repayment_proc(
input: Input,
output: Output,
owner: Address,
collateral_asset: AssetClass,
) -> Bool
Check the collateral output when fulfilling a loan repayment request, for the following:
- That the output does go back to the collateral contract
- That the datum is correctly updated with the status
Available
- That the value contained in the utxo is as expected.
validate_lending_pool_output(
input: Input,
output: Output,
pool_datum: LendingPoolDatum,
borrowed_amt: Int,
interest_amt: Option<Int>,
redeemer: UnifiedRedeemer,
) -> Bool
Check the new lending pool output for the following:
- That the amount of loanable asset contained in the utxo is as expected
- That there is no change in the datum
validate_protocol_inputs_count(
redeemer: UnifiedRedeemer,
inputs: List<Input>,
global_cfg: CfgGlobal,
) -> Bool
From a given list of tx inputs, get the ones that come from the protocol contracts and then
check that there’s only one UTXO coming from each, in order to avoid double-satisfaction exploits.
validate_registry_output_for_loan_proc(
output: Output,
owner: Address,
collateral_amt: Int,
loan_req: LoanRequest,
pool_datum: LendingPoolDatum,
global_cfg: CfgGlobal,
position_token: AssetName,
tx_validity_range: ValidityRange,
) -> Bool
Check that when fulfilling a loan request, the position utxo created at the registry contract
contains one of the position token pair, and has the expected datum.
count_protocol_inputs(
inputs: List<Input>,
collateral_contract: ScriptHash,
registry_contract: ScriptHash,
pool_contract: ScriptHash,
) -> ProtocolInputs
From a given list of inputs, count the ones coming from each of the protocol’s component contracts.
get_common_utxos(
tx: Transaction,
collateral_idxs: (Int, Int),
pool_idxs: (Int, Int),
output_ref: OutputReference,
) -> CommonUtxos
Get the UTXOs needed by lending_pool spend validator that are common among multiple redeemer cases
Compute the position_token name from a given collateral input.
Downcast a given lending pool datum into LendingPoolDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the LendingPoolDatum structure.
Get the amount of the collateral asset contained in a given output.
Audit
validate_audit_output(
input: Input,
output: Output,
global_cfg: CfgGlobal,
price: QuotePrice,
pool_datum: LendingPoolDatum,
tx_validity_range: ValidityRange,
) -> Bool
Check the datum in the given audit output for the following:
- That the
timestamp is later than the timestamp in the input datum
- That the
collateral_asset indicated matches with the one in the lending_pool datum
- That the
loanable_asset indicated matches with the one in the lending_pool datum
- That the
collateral_ratio indicated matches with the one in the global settings datum
- That the
health_score given is correctly calculated
Parse collateral datum from given raw Data.
From a given CollateralDatum, check if it is used in an active loan.
validate_collateral_output_for_loan_req(
output: Output,
input: Input,
input_datum: CollateralDatum,
borrowed_amt: Int,
loan_term: Int,
loan_asset: AssetClass,
) -> Bool
Check the collateral output when submitting a loan request, for the following:
- That the datum is correctly updated with the status
LoanRequestedand contains the loan request datum (LoanDatum). - That the collateral amount locked is at the very least, the same as the input
validate_collateral_output_for_repayment_req(
collateral_output: Output,
collateral_input: Input,
registry_input: Input,
) -> Bool
Check the collateral output when submitting a loan repayment request, for the following:
- That the datum contains the correctly updated status
RepayRequested - That the utxo contains both the collateral amount from the input, and the repayment asset in the correct amount.
is_for_liquidation(
loan: LoanDatum,
collateral_ratio: Int,
price: QuotePrice,
tx_validity_range: ValidityRange,
) -> Bool
Check if the given loan position is either undercollateralized or overdue.
validate_dex_output(
cfg: CfgGlobal,
dex: LiquidationDex,
dex_output: Output,
pos_token: AssetName,
collateral_asset: AssetClass,
collateral_amt: Int,
) -> Bool
Check the given output for the following:
- That the address is one of the supported dexes’ order contract
- That the datum is as expected
validate_minswap_order_datum(
order_datum: MinswapOrderDatum,
pos_token: AssetName,
cfg: CfgGlobal,
) -> Bool
Check the given Minswap order datum for the following:
- That the canceller is the admin, to be sure the swap order can be cancelled if needed
- That the refund and success receivers are the collateral contract
- That the Extra Order Datum (EOD) contains the hash of the position token name
validate_liquidation_registry_output(
output: Output,
input: Input,
pool_contract: ScriptHash,
pos_token: AssetName,
liquidator: Signer,
) -> Bool
When liquidating a position, check the given registry output for the following:
- That the position token pair is sent back to the position registry contract
- That the datum is updated with the liquidator’s hash
validate_collateral_registry_inputs_match(
tx: Transaction,
reg_input_idx: Int,
collat_input_idx: Int,
lp_contract: ScriptHash,
output_ref: OutputReference,
) -> Bool
From the given Transaction, check the given indeces for the registry and collateral input UTXOs;
confirm that the registry input matches with the given output reference; and then finally, check
that the collateral input contains the same position token that the registry input has.
Oracle
Get the oracle settings from the given list of tx inputs, the index of the oracle settings UTXO, and the policy ID of the settings beacon token.
Check the oracle output when updating oracle price UTXO, for the following:
- That the datum is of the expected structure
- That the output goes back to the oracle contract
- That the value is the same as in the input
Lending Pool
validate_collateral_input_for_loan_proc(
input: Input,
collateral_contract: ScriptHash,
loanable_asset: AssetClass,
) -> (Bool, Address, LoanRequest)
Check the collateral input when fulfilling a loan request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
LoanRequested
validate_collateral_input_for_repayment_proc(
input: Input,
global_cfg: CfgGlobal,
) -> (Bool, Address, AssetName)
Check the collateral input when fulfilling a repayment request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
RepayRequested
- That the input contains 1 and only 1 position token
validate_collateral_output_for_loan_proc(
output: Output,
input: Input,
owner: Address,
collateral_asset: AssetClass,
pool_contract: ScriptHash,
position_token: AssetName,
) -> Bool
Check the collateral output when fulfilling a loan request, for the following:
- That the datum contains the correctly updated status:
LoanIssued
- That the value locked in the collateral UTXO now includes one of the position token pair on top of the input value.
- That the collateral UTXO is returned to the
collateral contract.
validate_collateral_output_for_repayment_proc(
input: Input,
output: Output,
owner: Address,
collateral_asset: AssetClass,
) -> Bool
Check the collateral output when fulfilling a loan repayment request, for the following:
- That the output does go back to the collateral contract
- That the datum is correctly updated with the status
Available
- That the value contained in the utxo is as expected.
validate_lending_pool_output(
input: Input,
output: Output,
pool_datum: LendingPoolDatum,
borrowed_amt: Int,
interest_amt: Option<Int>,
redeemer: UnifiedRedeemer,
) -> Bool
Check the new lending pool output for the following:
- That the amount of loanable asset contained in the utxo is as expected
- That there is no change in the datum
validate_protocol_inputs_count(
redeemer: UnifiedRedeemer,
inputs: List<Input>,
global_cfg: CfgGlobal,
) -> Bool
From a given list of tx inputs, get the ones that come from the protocol contracts and then
check that there’s only one UTXO coming from each, in order to avoid double-satisfaction exploits.
validate_registry_output_for_loan_proc(
output: Output,
owner: Address,
collateral_amt: Int,
loan_req: LoanRequest,
pool_datum: LendingPoolDatum,
global_cfg: CfgGlobal,
position_token: AssetName,
tx_validity_range: ValidityRange,
) -> Bool
Check that when fulfilling a loan request, the position utxo created at the registry contract
contains one of the position token pair, and has the expected datum.
count_protocol_inputs(
inputs: List<Input>,
collateral_contract: ScriptHash,
registry_contract: ScriptHash,
pool_contract: ScriptHash,
) -> ProtocolInputs
From a given list of inputs, count the ones coming from each of the protocol’s component contracts.
get_common_utxos(
tx: Transaction,
collateral_idxs: (Int, Int),
pool_idxs: (Int, Int),
output_ref: OutputReference,
) -> CommonUtxos
Get the UTXOs needed by lending_pool spend validator that are common among multiple redeemer cases
Compute the position_token name from a given collateral input.
Downcast a given lending pool datum into LendingPoolDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the LendingPoolDatum structure.
Get the amount of the collateral asset contained in a given output.
Audit
validate_audit_output(
input: Input,
output: Output,
global_cfg: CfgGlobal,
price: QuotePrice,
pool_datum: LendingPoolDatum,
tx_validity_range: ValidityRange,
) -> Bool
Check the datum in the given audit output for the following:
- That the
timestamp is later than the timestamp in the input datum
- That the
collateral_asset indicated matches with the one in the lending_pool datum
- That the
loanable_asset indicated matches with the one in the lending_pool datum
- That the
collateral_ratio indicated matches with the one in the global settings datum
- That the
health_score given is correctly calculated
Get the oracle settings from the given list of tx inputs, the index of the oracle settings UTXO, and the policy ID of the settings beacon token.
Check the oracle output when updating oracle price UTXO, for the following:
- That the datum is of the expected structure
- That the output goes back to the oracle contract
- That the value is the same as in the input
validate_collateral_input_for_loan_proc(
input: Input,
collateral_contract: ScriptHash,
loanable_asset: AssetClass,
) -> (Bool, Address, LoanRequest)
Check the collateral input when fulfilling a loan request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
LoanRequested
validate_collateral_input_for_repayment_proc(
input: Input,
global_cfg: CfgGlobal,
) -> (Bool, Address, AssetName)
Check the collateral input when fulfilling a repayment request, for the following:
- That the input does come from the collateral contract
- That the datum contains the status:
RepayRequested - That the input contains 1 and only 1 position token
validate_collateral_output_for_loan_proc(
output: Output,
input: Input,
owner: Address,
collateral_asset: AssetClass,
pool_contract: ScriptHash,
position_token: AssetName,
) -> Bool
Check the collateral output when fulfilling a loan request, for the following:
- That the datum contains the correctly updated status:
LoanIssued - That the value locked in the collateral UTXO now includes one of the position token pair on top of the input value.
- That the collateral UTXO is returned to the
collateralcontract.
validate_collateral_output_for_repayment_proc(
input: Input,
output: Output,
owner: Address,
collateral_asset: AssetClass,
) -> Bool
Check the collateral output when fulfilling a loan repayment request, for the following:
- That the output does go back to the collateral contract
- That the datum is correctly updated with the status
Available - That the value contained in the utxo is as expected.
validate_lending_pool_output(
input: Input,
output: Output,
pool_datum: LendingPoolDatum,
borrowed_amt: Int,
interest_amt: Option<Int>,
redeemer: UnifiedRedeemer,
) -> Bool
Check the new lending pool output for the following:
- That the amount of loanable asset contained in the utxo is as expected
- That there is no change in the datum
validate_protocol_inputs_count(
redeemer: UnifiedRedeemer,
inputs: List<Input>,
global_cfg: CfgGlobal,
) -> Bool
From a given list of tx inputs, get the ones that come from the protocol contracts and then check that there’s only one UTXO coming from each, in order to avoid double-satisfaction exploits.
validate_registry_output_for_loan_proc(
output: Output,
owner: Address,
collateral_amt: Int,
loan_req: LoanRequest,
pool_datum: LendingPoolDatum,
global_cfg: CfgGlobal,
position_token: AssetName,
tx_validity_range: ValidityRange,
) -> Bool
Check that when fulfilling a loan request, the position utxo created at the registry contract contains one of the position token pair, and has the expected datum.
count_protocol_inputs(
inputs: List<Input>,
collateral_contract: ScriptHash,
registry_contract: ScriptHash,
pool_contract: ScriptHash,
) -> ProtocolInputs
From a given list of inputs, count the ones coming from each of the protocol’s component contracts.
get_common_utxos(
tx: Transaction,
collateral_idxs: (Int, Int),
pool_idxs: (Int, Int),
output_ref: OutputReference,
) -> CommonUtxos
Get the UTXOs needed by lending_pool spend validator that are common among multiple redeemer cases
Compute the position_token name from a given collateral input.
Downcast a given lending pool datum into LendingPoolDatum type.
Returns None when the given datum is not an InlineDatum type, or if it doesn’t have the LendingPoolDatum structure.
Get the amount of the collateral asset contained in a given output.
Audit
validate_audit_output(
input: Input,
output: Output,
global_cfg: CfgGlobal,
price: QuotePrice,
pool_datum: LendingPoolDatum,
tx_validity_range: ValidityRange,
) -> Bool
Check the datum in the given audit output for the following:
- That the
timestamp is later than the timestamp in the input datum
- That the
collateral_asset indicated matches with the one in the lending_pool datum
- That the
loanable_asset indicated matches with the one in the lending_pool datum
- That the
collateral_ratio indicated matches with the one in the global settings datum
- That the
health_score given is correctly calculated
validate_audit_output(
input: Input,
output: Output,
global_cfg: CfgGlobal,
price: QuotePrice,
pool_datum: LendingPoolDatum,
tx_validity_range: ValidityRange,
) -> Bool
Check the datum in the given audit output for the following:
- That the
timestampis later than the timestamp in the input datum - That the
collateral_assetindicated matches with the one in the lending_pool datum - That the
loanable_assetindicated matches with the one in the lending_pool datum - That the
collateral_ratioindicated matches with the one in the global settings datum - That the
health_scoregiven is correctly calculated