Collateralize
Depositing ezETH as Collateral
Pre-flight checks
const marketManager = new ethers.Contract(
ADDRESSES.MARKET_MANAGER,
MARKET_MANAGER_ABI,
provider
);
const cToken = new ethers.Contract(ADDRESSES.EZETH_CTOKEN, CTOKEN_ABI, signer);
const ezETH = new ethers.Contract(ADDRESSES.EZETH, ERC20_ABI, signer);
const userAddress = await signer.getAddress();
const depositAmount = ethers.parseEther("10"); // 10 ezETH
// Pause check (returns [mintPaused, collateralizationPaused, borrowingPaused])
const [mintPaused, collateralizationPaused] =
await marketManager.actionsPaused(ADDRESSES.EZETH_CTOKEN);
if (mintPaused) throw new Error("Minting is paused");
if (collateralizationPaused) throw new Error("Collateralization is paused");
// Collateral cap check. Cap and posted values are cToken shares.
const expectedShares = await cToken.previewDeposit(depositAmount);
const cap = await marketManager.collateralCaps(ADDRESSES.EZETH_CTOKEN);
const posted = await cToken.marketCollateralPosted();
if (cap === 0n) throw new Error("Collateralization disabled for this cToken");
if (posted + expectedShares > cap) throw new Error("Collateral cap exceeded");Balance check
Approve and deposit
Depositing on behalf of another address
What happens when you deposit as collateral
Last updated
Was this helpful?