Lista DAO 백서

Lista DAO

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 53쪽 중 22쪽

ction maxWithdraw(address owner) external view returns (uint256); function maxRedeem(address owner) external view returns (uint256); ``` Exceeding the reachable amount reverts `NotEnoughLiquidity()`. Both views can **under-report** because of share/asset rounding, so treat them as a safe lower bound. **Do not present a user's full share balance as withdrawable** — quote `maxWithdraw` instead. *** ## ERC-4626 surface Standard, with the usual semantics: ```solidity function asset() external view returns (address); function totalAssets() external view returns (uint256); function deposit(uint256 assets, address receiver) external returns (uint256 shares); function mint(uint256 shares, address receiver) external returns (uint256 assets); function withdraw(uint256 assets, address receiver, address owner) external returns (uint256 shares); function redeem(uint256 shares, address receiver, address owner) external returns (uint256 assets); ``` **Approve the vault itself** for `deposit` / `mint` — it pulls the asset with `transferFrom`. `withdraw` and `redeem` from an `owner` other than the caller consume the ERC-20 allowance on the *shares*, per the standard. The `convertTo*` / `preview*` conversions account for the not-yet-minted performance-fee shares, so a quote taken before a fee accrual can differ slightly from what settles. For an exact figure, simulate the call. `totalAssets` does **not** net out the fee — the fee is taken by minting shares to the fee recipient, not by reducing assets. It does subtract the broker interest lock buffer's `currentLocked()`, so it is not simply the sum of the vault's market positions. ### Two non-standard helpers ```solidity function withdrawFor(uint256 assets, address owner, address sender) external returns (uint256 shares); function redeemFor(uint256 shares, address owner, address sender) external returns (uint256 assets); ``` These exist for provider-routed flows — see [Providers](/for-developer/lista-lending/providers), which is how native BNB reaches a WBNB vault. *** ## Reading a vault's allocation ```solidity function supplyQueueLength() external view returns (uint256); function withdrawQueueLength() external view returns (uint256); ``` The supply queue determines where a deposit lands; the withdraw queue determines what a withdrawal can reach, in order. Both are allocator-managed (`setSupplyQueue`, `updateWithdrawQueue`, and `reallocate` — the last also callable by a bot role), while the per-market caps behind them are curator-managed (`setCap`, `setMarketRemoval`). All are role-gated, and all change without notice — read the queues rather than caching them. Per-market caps and queue changes are observable as events; see [Events & Callbacks](/for-developer/lista-lending/events-and-callbacks) for the vault event set, including `SetCap`, `SetSupplyQueue` and `SetWithdrawQueue`. *** ## Reverts | Error | Cause | | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | `NotWhiteList()` | The **receiver** is not on a non-empty vault whitelist. | | `AllCapsReached()` | Every market in the supply queue is at its cap. | | `SupplyCapExceeded(Id)` | A **reallocation** would push one market past its cap — an allocator error, not a deposit one. A deposit clamps to the cap instead and reverts `AllCapsReached()`. | | `NotEnoughLiquidity()` | The withdraw queue cannot reach enough liquidity right now. | | `MarketNotEnabled(Id)` · `UnauthorizedMarket(Id)` | The market is not enabled for this vault — relevant to curator calls, not to a plain deposit. | | `InconsistentAsset(Id)` | A market's loan token does not match the vault's `asset()`. | # Providers A **provider** is a contract registered against a market and token that takes over part of the flow. Where a collateral-token provider is set, Moolah makes it an **exclusive gate**: only the provider may call `supplyCollateral` / `withdrawCollateral` for that market, and a direct call reverts. So for those collaterals the provider *is* the integration surface. To find out which provider backs which collateral, see [Integration Patterns](/for-developer/lista-lending/integration-patterns); for deployed addresses, [Smart Contract](/for-developer/lista-lending/smart-contract). Check whether a market is provider-gated before building against it: ```solidity function providers(Id id, address token) external view returns (address); ``` A non-zero result for the collateral token means you must route through it. *** ## BNBProvider — native BNB Lista's BNB vaults hold **WBNB**. `BNBProvider` is the wrapper that lets a user deposit native BNB and receive vault shares in one call, and unwrap on the way out. Without it you must wrap to WBNB yourself first; sending BNB at the vault will not work. ```solidity function deposit(address receiver) external payable returns (uint256 shares); function mint(uint256 shares, address receiver) external payable returns (uint256 assets); function withdraw(uint256 assets, address payable receiver, address owner) external returns (uint256 shares); function redeem(uint256 shares, address payable receiver, address owner) external returns (uint256 assets); ``` The amount is `msg.value` — there is no assets argument on `deposit`. On `mint` you send at least the previewed cost (`msg.value >= previewAssets`, else `invalid BNB amount`) and the surplus is refunded. Each instance is **bound to one vault**, so pick the one deployed for the vault you are targeting. A newer implementation adds a multi-vault form, but **not every deployed provider runs it** — the calls below are absent from some of the listed addresses and revert with empty returndata there. Probe `vaults` first; if it reverts, you have a single-vault instance and only the four signatures above exist. ```solidity function deposit(address vault, address receiver) external payable returns (uint256 shares); function mint(address vault, uint256 shares, address receiver) external payable returns (uint256 assets); function vaults(address vault) external view returns (bool); ``` On that implementation `vaults(v)` must be `true` or the call reverts `vault not added` — including for the single-argument form, which routes through the provider's own `MOOLAH_VAULT`. So a default vault that was never registered makes even `deposit(receiver)` revert. The vault's own whitelist still applies to the **receiver** either way — see [Vault Reference](/for-developer/lista-lending/vault-reference). **On the way out, there is nothing to approve.** `withdraw` and `redeem` do not pull your shares: the provider calls the vault's `withdrawFor` / `redeemFor`, which only the registered provider may call, and the vault burns from `owner` directly. Withdrawing your own position needs no allowance at all. Withdrawing someone else's needs *that owner* to have granted **you** — the original caller, not the provider — an ERC-20 allowance on the vault's share token. *** ## SlisBNBProvider — slisBNB collateral slisBNB collateral is provider-gated, so these are the only ways *you* can voluntarily move it — liquidation is a separate path that seizes it directly, bypassing the provider entirely: ```solidity function supplyCollateral( MarketParams memory marketParams, uint256 assets, address onBehalf, bytes calldata data ) external; function withdrawCollateral( MarketParams memory marketParams, uint256 assets, address onBehalf, address receiver ) external; ``` **Approve the provider**, not Moolah — it pulls slisBNB from you with `transferFrom`. `marketParams.collateralToken` must be slisBNB (`invalid collateral token` otherwise), and `assets` must be non-zero. On withdrawal the caller must be `onBehalf` or authorized for it (`unauthorized sender`). Liquidation is the exception to the *user-facing* gate: Moolah transfers the seized collateral straight to the liquidator and then calls the provider's `liquidate(id, borrower)` hook. So collateral can leave a position without anyone calling `withdrawCollateral` — but the provider is still invoked, and on `SlisBNBProvider` that hook re-syncs the position and burns the corresponding `slisBNBx`, so Launchpool eligibility follows the liquidation. Supplying through this provider also mints the non-transferable `slisBNBx` certificate that carries Binance Launchpool eligibility, and withdrawing burns it. The delegatee that holds it, and how to change it, are covered in [slisBNBx Delegation](/for-developer/clisbnb/delegation) — including that the certificate covers the user's part only, not the fee slice. *** ## SmartProvider — StableSwap LP collateral For Smart Lending's provider, go to [Smart Lending & StableSwap](/for-developer/lista-lending/stableswap-integration) — it covers the supply/withdraw variants, the price-difference guard and the collateral token's transfer restrictions. *** ## See also * [Contract & Interface Reference](/for-developer/lista-lending/contract-reference) — the provider gate as Moolah enforces it. # Broker Reference A **broker** is registered per market and, where present, gates origination: only the broker may call `borrow` or `repay` on that market. So on a broker market the broker *is* the borrowing surface — a direct Moolah call reverts. Brokers are what add **fixed-term, fixed-rate** borrowing on top of Moolah's variable-rate markets. The deployed broker markets, with their LLTV, cap and market id, are on [BSC Lending Brokers](/for-developer/lista-lending/smart-contract/smart-contract-bsc-brokers). Check whether a market is broker-gated: ```solidity function brokers(Id id) external view returns (address); ``` > Lista Credit uses a different broker, `CreditBroker`, with credit-scoring gates on top. It has its own page: [Loan Lifecycle](/for-developer/credit-loans/loan-lifecycle). *** ## Terms A broker offers a set of fixed terms. Read them before borrowing — `termId` is what you pass to open a fixed position: ```solidity struct FixedTermAndRate { uint256 termId; uint256 duration; // seconds uint256 apr; } // IBroker.sol. CreditBroker declares a DIFFERENT struct of the same name with a // fourth field, `FixedTermType termType` — decoding one with the other's ABI // misreads the tuple. See Credit Loan Lifecycle. function getFixedTerms() external view returns (FixedTermAndRate[] memory); ``` `apr` is RAY-scaled as **`1e27 + rate`**, not as the rate itself. Divide by `1e27` and subtract 1 to get the annual figure: `1036821445287206735200000000` is **3.68%**, not 103.68%. A term whose `apr` is at or below `1e27` accrues nothing. On a `LendingBroker` term, interest accrues **linearly per second** on outstanding principal and stops at the position's `end` — it is not charged upfront. (`CreditBroker` terms carry a `termType` and one of its two modes *is* upfront — see [Credit Loan Lifecycle](/for-developer/credit-loans/loan-lifecycle).) Repaying before `end` adds an early-repay penalty, roughly half the remaining term's interest on the principal being repaid, which is what recovers the forgone term interest. ## Posting collateral first The broker gates **origination only**. Collateral goes into the underlying Moolah market directly: ```solidity MOOLAH.supplyCollateral(marketParams, assets, onBehalf, ""); // approve Moolah for the collateral token ``` The broker table gives you a market **id**, not `MarketParams` — read the struct with `MOOLAH.idToMarketParams(id)` first. If that market's collateral token is provider-gated (`MOOLAH.providers(id, collateralToken)` is non-zero), route the collateral through that provider instead; see [Providers](/for-developer/lista-lending/providers). ## Borrowing ```solidity function borrow(uint256 amount) external; // variable-rate ("dynamic") position function borrow(uint256 amount, uint256 termId) external; // fixed-term position ``` Both of these borrow against **`msg.sender`'s** position and send the loan token to the caller — **unwrapped to native BNB** where the broker supports it. A third overload borrows on someone else's behalf: ```solidity function borrow(uint256 amount, uint256 termId, address user, address receiver) external; ``` It opens the position on `user` and pays `receiver`, and requires `MOOLAH.isAuthorized(user, msg.sender)` — this is the path `PositionManager` uses. Unlike the two above, **this overload always pays in ERC-20, never native**, and it reverts `ZeroAddress()` on a zero `receiver`. All three are `nonReentrant`, require the market id to be set, and revert `ZeroAmount()` on a zero amount. They are additionally pausable in two independent ways — a global pause and a borrow-specific pause — so a broker can stop new borrowing while leaving repayment open. ## Repaying ```solidity function repay(uint256 amount, address onBehalf) external payable; // variable position function repay(uint256 amount, uint256 posId, address onBehalf) external payable; // one fixed position function repayAll(address onBehalf) external payable; // everything ``` **Approve the broker**, not Moolah: on an ERC-20 market the broker pulls the loan token from the caller with `transferFrom`. All three are `payable`, so a native-BNB market can instead be repaid by sending value — the broker wraps it for you and refunds the excess. `repayAll` pulls principal, accrued interest **and the full early-repay penalty on every open fixed position**. `getUserTotalDebt(onBehalf)` does **not** include that penalty, so an allowance sized at it reverts for any borrower holding an un-matured fixed position — the normal case. Sum `previewRepayFixedLoanPosition` across the open positions, or allow a buffer above `getUserTotalDebt`. The fixed-position form needs the `posId` from the user's positions (below). Preview what a partial repayment settles before sending it: ```solidity function previewRepayFixedLoanPosition(address user, uint256 amount, uint256 posId) external view returns (uint256 interestRepaid, uint256 penalty, uint256 principalRepaid); ``` Note the three-way split: interest comes first, a penalty may apply, and only the remainder reduces principal. ### Converting a variable position within one broker ```solidity function convertDynamicToFixed(uint256 amount, uint256 termId) external; ``` Moves part of your variable ("dynamic") position at this broker onto one of its fixed terms. It acts on `msg.sender` only — no authorization, no flash loan. To cross from a plain Moolah market into a broker-gated one, use [`PositionManager`](/for-developer/lista-lending/position-conversion) instead. ## Reading positions ```solidity function userFixedPositions(address user) external view returns (FixedLoanPosition[] memory); function userDynamicPosition(address user) external view returns (DynamicLoanPosition memory); function getUserTotalDebt(address user) external view returns (uint256 totalDebt); ``` `getUserTotalDebt` is the **borrower's** total across their fixed and variable positions, priced with the broker's current rate — not a market-wide figure. ## Pricing, and why it matters for liquidation ```solidity function peek(address token, address user) external view returns (uint256 price); ``` On a broker market, health is not computed the way it is elsewhere. `Moolah._isHealthy` prices the collateral at the **plain market price** but substitutes the **broker's** debt figure for the borrower's Moolah shares. The per-user `peek` price shapes the seize math once a liquidation runs. This is the reason [Liquidator Integration](/for-developer/lista-lending/liquidator-integration) warns that `PublicLiquidator.loanTokenAmountNeed` over-quotes on broker markets: that helper prices with `Moolah.getPrice(marketParams)`, which is the market price with `user = address(0)`, while the liquidation itself prices with the borrower. Use the broker's own `peek(token, user)` and `getUserTotalDebt(user)` to size a broker-market liquidation. *** ## See also * [Integration Patterns](/for-developer/lista-lending/integration-patterns) — how providers and brokers compose. # Position Conversion A borrower with a variable-rate position on a Moolah market can move it into a **fixed-term** market without unwinding it themselves. `PositionManager` does it atomically: it flash-loans the loan token from Moolah, repays the variable debt, moves the collateral, and re-borrows the same amount at the fixed term — all in one call. Before you offer the conversion, check two things that make the call revert: Moolah must have `borrowAmount` of the loan token free for the flash loan, and it must not be globally paused. Deployed addresses are on [BSC Core](/for-developer/lista-lending/smart-contract/smart-contract-bsc-core) and [Ethereum](/for-developer/lista-lending/smart-contract/smart-contract-ethereum). > **No borrower-callable reverse path.** Matured fixed positions are folded back into the broker's variable ("dynamic") position by a bot role calling `refinanceMaturedFixedPositions` — you cannot trigger it. To leave a fixed term early, repay the fixed position through its broker. See [Broker Reference](/for-developer/lista-lending/broker-reference) for the repay surface. > > **Check the lighter path first.** If you only want to move *variable debt you already hold at a broker* into one of that broker's fixed terms, `LendingBroker.convertDynamicToFixed(amount, termId)` does it within the one market — no `PositionManager`, no authorization, no flash loan. `PositionManager` is for crossing from a plain Moolah market into a different, broker-gated one. *** ## The call ```solidity function migrateCommonMarketToFixedTermMarket( MarketParams calldata outMarket, MarketParams calldata inMarket, uint256 collateralAmount, uint256 borrowAmount, uint256 borrowShares, uint256 termId ) external; ``` `outMarket` is the variable market you are leaving, `inMarket` the fixed-term market you are entering. ## Prerequisite: authorize PositionManager The manager moves your position on your behalf, so Moolah must be told to allow it. This is the standard authorization flag described in [Contract & Interface Reference](/for-developer/lista-lending/contract-reference): ```solidity // 1. check MOOLAH.isAuthorized(user, positionManager); // bool // 2. if false, the user signs this themselves MOOLAH.setAuthorization(positionManager, true); ``` Without it the call reverts `not-authorized`. ## Sizing it Exactly one of `borrowAmount` / `borrowShares` must be zero — the contract enforces `exactlyOneZero` and reverts `exactly-one-of-borrowAmount-or-borrowShares` otherwise. Pass the position's full `borrowShares` to move the whole debt; use `borrowAmount` to move a specific assets figure. `collateralAmount` must be non-zero (`zero-collateral-amount`). ## What must match Both markets must share the same pair: | Check | Revert | | ------------------------------------------------------- | --------------------------- | | `outMarket.loanToken == inMarket.loanToken` | `loan-token-mismatch` | | `outMarket.collateralToken == inMarket.collateralToken` | `collateral-token-mismatch` | | `inMarket.lltv >= outMarket.lltv` | `in-market-lltv-too-low` | | `inMarket` has a broker registered | `no-broker-for-market` | So a conversion stays within one asset pair — it changes the rate model, not the exposure. Broker markets run a wide LLTV spread, so migrating out of a high-LLTV variable market into a lower-LLTV fixed one reverts. Compare `lltv` on both [market rows](/for-developer/lista-lending/smart-contract/smart-contract-bsc-brokers) before offering the conversion. ## Finding the target market and term You have to supply these two yourself — the call cannot derive either: * **`inMarket`** — the fixed-term market paired with your variable one. Broker markets are listed with their market ids on [BSC Lending Brokers](/for-developer/lista
프로젝트로 돌아가기