Per-position ltvBps was the only check on how much a vault could lend out in aggregate -- a well-collateralized borrower (or several) could grow totalDebtPrincipal arbitrarily large with nothing else gating it, even though real risk management (oracle feed liquidity depth, how much collateral could actually be sold to cover simultaneous liquidations) bounds how large a single market can safely get. Adds an immutable borrowCap (0 = unlimited, exact pre-existing behavior) that borrow() checks against aggregate debt, same primitive Compound/Aave's per-market borrow caps already ship. - 5 new regression tests (sentinel disables feature, exact boundary, aggregate across multiple borrowers, interest accrual never blocked): 57 -> 62/62 pass, zero regressions. - New one-command scripts/borrow-cap-demo.sh proves the real boundary against real deployed bytecode on a disposable anvil. - Verified live on the persistent self-hosted demo chain (http://130.61.180.42:8647) against a separate throwaway vault so the public demo's own position was never touched: borrow() landing exactly on a 1,000 TUSD cap succeeded (tx 0xc71dd5c4...), the next unit over reverted with the real BorrowCapExceeded custom error. - Redeployed the public demo with a real 100,000 TUSD cap and surfaced it on /vault via a new "Borrow cap" stat, no wallet required.
289 lines
7.0 KiB
TypeScript
289 lines
7.0 KiB
TypeScript
/** Minimal ABIs for the real QieForge* contracts (packages/contracts) —
|
|
* same shapes used by the Python/Rust SDKs, just the subset the frontend
|
|
* actually calls. */
|
|
|
|
export const FACTORY_ABI = [
|
|
{
|
|
type: "function",
|
|
name: "getPair",
|
|
stateMutability: "view",
|
|
inputs: [
|
|
{ name: "tokenA", type: "address" },
|
|
{ name: "tokenB", type: "address" },
|
|
],
|
|
outputs: [{ name: "pair", type: "address" }],
|
|
},
|
|
] as const;
|
|
|
|
export const ROUTER_ABI = [
|
|
{
|
|
type: "function",
|
|
name: "getAmountsOut",
|
|
stateMutability: "view",
|
|
inputs: [
|
|
{ name: "amountIn", type: "uint256" },
|
|
{ name: "path", type: "address[]" },
|
|
],
|
|
outputs: [{ name: "", type: "uint256[]" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "swapExactTokensForTokens",
|
|
stateMutability: "nonpayable",
|
|
inputs: [
|
|
{ name: "amountIn", type: "uint256" },
|
|
{ name: "amountOutMin", type: "uint256" },
|
|
{ name: "path", type: "address[]" },
|
|
{ name: "to", type: "address" },
|
|
{ name: "deadline", type: "uint256" },
|
|
],
|
|
outputs: [{ name: "amounts", type: "uint256[]" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "addLiquidity",
|
|
stateMutability: "nonpayable",
|
|
inputs: [
|
|
{ name: "tokenA", type: "address" },
|
|
{ name: "tokenB", type: "address" },
|
|
{ name: "amountADesired", type: "uint256" },
|
|
{ name: "amountBDesired", type: "uint256" },
|
|
{ name: "amountAMin", type: "uint256" },
|
|
{ name: "amountBMin", type: "uint256" },
|
|
{ name: "to", type: "address" },
|
|
{ name: "deadline", type: "uint256" },
|
|
],
|
|
outputs: [
|
|
{ name: "amountA", type: "uint256" },
|
|
{ name: "amountB", type: "uint256" },
|
|
{ name: "liquidity", type: "uint256" },
|
|
],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "removeLiquidity",
|
|
stateMutability: "nonpayable",
|
|
inputs: [
|
|
{ name: "tokenA", type: "address" },
|
|
{ name: "tokenB", type: "address" },
|
|
{ name: "liquidity", type: "uint256" },
|
|
{ name: "amountAMin", type: "uint256" },
|
|
{ name: "amountBMin", type: "uint256" },
|
|
{ name: "to", type: "address" },
|
|
{ name: "deadline", type: "uint256" },
|
|
],
|
|
outputs: [
|
|
{ name: "amountA", type: "uint256" },
|
|
{ name: "amountB", type: "uint256" },
|
|
],
|
|
},
|
|
] as const;
|
|
|
|
/** QieForgePair — the LP token itself is a plain ERC20 (balance/allowance/
|
|
* approve come from ERC20_ABI below), plus the pool-specific reads the
|
|
* liquidity UI needs. */
|
|
export const PAIR_ABI = [
|
|
{
|
|
type: "function",
|
|
name: "getReserves",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [
|
|
{ name: "_reserve0", type: "uint112" },
|
|
{ name: "_reserve1", type: "uint112" },
|
|
{ name: "_blockTimestampLast", type: "uint32" },
|
|
],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "token0",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "address" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "totalSupply",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
] as const;
|
|
|
|
export const ERC20_ABI = [
|
|
{
|
|
type: "function",
|
|
name: "approve",
|
|
stateMutability: "nonpayable",
|
|
inputs: [
|
|
{ name: "spender", type: "address" },
|
|
{ name: "amount", type: "uint256" },
|
|
],
|
|
outputs: [{ name: "", type: "bool" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "allowance",
|
|
stateMutability: "view",
|
|
inputs: [
|
|
{ name: "owner", type: "address" },
|
|
{ name: "spender", type: "address" },
|
|
],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "balanceOf",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "account", type: "address" }],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
] as const;
|
|
|
|
export const VAULT_ABI = [
|
|
{
|
|
type: "function",
|
|
name: "positions",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "", type: "address" }],
|
|
outputs: [
|
|
{ name: "collateral", type: "uint128" },
|
|
{ name: "debtPrincipal", type: "uint128" },
|
|
{ name: "lastAccrual", type: "uint64" },
|
|
],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "healthFactor",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "user", type: "address" }],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "currentDebt",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "user", type: "address" }],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "depositCollateral",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "amount", type: "uint256" }],
|
|
outputs: [],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "borrow",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "amount", type: "uint256" }],
|
|
outputs: [],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "collateralAsset",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "address" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "withdrawCollateral",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "amount", type: "uint256" }],
|
|
outputs: [],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "repay",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "amount", type: "uint256" }],
|
|
outputs: [],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "deposit",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "amount", type: "uint256" }],
|
|
outputs: [{ name: "shares", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "withdraw",
|
|
stateMutability: "nonpayable",
|
|
inputs: [{ name: "shares", type: "uint256" }],
|
|
outputs: [{ name: "amount", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "lenderShares",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "", type: "address" }],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "totalLenderShares",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "totalAssets",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "totalDebtPrincipal",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "borrowAsset",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "address" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "totalReserves",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "reserveFactorBps",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "liquidationBonusBpsFor",
|
|
stateMutability: "view",
|
|
inputs: [{ name: "user", type: "address" }],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "liquidationBonusMaxBps",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
{
|
|
type: "function",
|
|
name: "borrowCap",
|
|
stateMutability: "view",
|
|
inputs: [],
|
|
outputs: [{ name: "", type: "uint256" }],
|
|
},
|
|
] as const;
|