Smart contracts

Approvals & allowances

The ERC-20 allowance the market needs before each action, and the infinite-approve pattern the app uses.

LendrMarket moves tokens with transferFrom, so every state-changing call that pulls funds from you needs a prior ERC-20 approve for at least that amount. This is a standard ERC-20 requirement, not something LendrMarket implements itself.

Which token gets approved, and for how much

ActionToken approvedMinimum amount
createListingThe collateral tokencollateralAmount
fillListingThe loan token (USDG)loanAmount
repayThe loan token (USDG)loanAmount + interestOwed(id)

How the app manages this

Before any of the three calls above, the app reads the caller's current allowance(owner, market) on the relevant token. If it already covers the required amount, no approval transaction is sent. If it doesn't, the app requests a single approve(market, maxUint256) — an infinite approval — and waits for that transaction to confirm before proceeding.

typescript
const allowance = await readContract({ address: token, abi: erc20Abi, functionName: "allowance", args: [owner, market] });
if (allowance >= amount) return; // already sufficient

await writeContract({ address: token, abi: erc20Abi, functionName: "approve", args: [market, maxUint256] });

This is a client convention, not a contract requirement

LendrMarket doesn't require an infinite approval — any allowance at or above the exact amount needed works. The app defaults to maxUint256 purely so a wallet that's already used a given collateral or USDG with the market once won't need to sign a fresh approval on every subsequent listing.