# Wallets and lenders

For teams that run the loan themselves, without the SDK: a wallet taking a borrower through it, and a lender serving it.

## Wallet integration

A wallet needs a host-chain RPC and a Bitcoin node or indexer that returns raw transactions, headers and Merkle branches.

1. **Terms.** Exchange keys and hashes, agree amounts, and build each tranche's script from its hash, lock time and both keys. The contract cannot check a script's branches, so both parties must.
2. **Sign.** EIP-712 over `LoanTerms`.
3. **Fund.** One transaction, one output per tranche, exact amounts.
4. **Prove.** `submitFundingProof`, naming which output pays which tranche.
5. **Claim.** `claimPayout`.
6. **Repay.** `repayTranche`, then watch for `SecretRevealed`.
7. **Spend.** Broadcast the hash-lock spend promptly, before the lender's lock opens.

If the reveal deadline passes with no secret, call `triggerGhostLiquidation` and watch the settler.

Run a watcher: many calls are open to anyone, and a party that is offline at the wrong moment loses by it.

Every field, signature, event and revert reason: [MaxyLock documentation (PDF)](https://maxy.co/docs/_media/maxylock-guide/maxylock-documentation.pdf).

## Lender operations

In Maxy's loans, Maxy does this. If you lend, you need three credentials on separate systems.

| Credential | Does | If lost or stolen |
| --- | --- | --- |
| Host-chain key | Commits, reveals, claims | An attacker can claim the ledger balance |
| Bitcoin sweep key | Sweeps defaulted and interest tranches | An attacker can sweep tranches whose lock opened |
| Secret store | Holds each tranche's secret | Losing a secret costs as much as theft |

**Your duties.**

- **Reveal** at once on every `TrancheRepaid`. This is the duty that costs you if missed.
- **Prove** funding when it reaches its confirmations.
- **Sweep** defaulted and interest tranches after their locks.
- **Finalize** after `verificationDeadline` if a tranche is still `Pending`.

Use a fresh Bitcoin key and a fresh script for every loan. Never reuse a script hash.

**Alert on.**

- An `Escrowed` tranche with no `SecretRevealed` soon after repayment.
- A confirmed funding transaction with no `TrancheVerified`.
- A tranche near its last safe repayment time.
- The verifier falling more than a few blocks behind Bitcoin.

---
Source: https://maxy.co/docs/wallets-and-lenders (Maxy Docs › Loans (MaxyLock) › Build with it)
