Settle loans
Pay back, claim or collect a loan through the contract, with only its funding transaction.
Every settlement call takes the loan's Loan struct, from its Opened event. Nothing else is needed: anyone can settle a loan from a block explorer or a script.
Without code
- Find the loan's funding transaction on a Robinhood Chain block explorer, or open the terms file saved from the loan page (see Track your loans).
- Copy the
loantuple from theOpenedevent exactly as recorded. A changed field gives a different loan ID, which the contract does not recognise. - To repay: approve the market contract for the payback amount of the loan token, then call
repay(loan). - To claim after the deadline: call
foreclose(loan). To collect a held payback: callcollectRepayment(loan). To get collateral back after someone else paid back: callreclaimCollateral(loan)from the borrower wallet.
With code
const [opened] = await client.getContractEvents({
address: MARKET, abi: loansAbi, eventName: "Opened", args: { id: loanId }, fromBlock: DEPLOY_BLOCK,
})
const loan = opened.args.loan
await wallet.writeContract({ account, address: loan.loanToken, abi: erc20Abi, functionName: "approve", args: [MARKET, loan.repayment] })
await wallet.writeContract({ account, address: MARKET, abi: loansAbi, functionName: "repay", args: [loan] })foreclose, collectRepayment and reclaimCollateral take the same loan.
Checking a loan first
| Call | Returns |
|---|---|
loanState(id) | Maturity, and whether it is paid back and its collateral released. |
repaymentDeadline(loan) | The current last second to repay, including any extension. Zero for unknown terms. |
heldRepayment(loan) | A payback held for a note holder that could not receive it. |
ownerOf(uint256(id)) | The current note holder, while the note exists. |
Last updated