Collateralize

Depositing WMON as Collateral

When depositing into the WMONCToken as collateral, you're also providing liquidity for lending if lending is enabled on the specific cToken.

First, check the user's balance and ensure they have enough MON:

const WMON = new ethers.Contract(ADDRESSES.WMON, ERC20_ABI, provider);
const balance = await WMON.balanceOf(userAddress);
const depositAmount = ethers.utils.parseEther("10"); // 10 WMON tokens

if (balance.lt(depositAmount)) {
  throw new Error("Insufficient WMON token balance");
}

Then approve and make the deposit by calling deposit() in the cToken contract, or depositAsCollateral() to both deposit and post as collateral all in one transaction.

Function arguments when:

calling deposit():

Type
Name
Description

uint256

assets

The amount of underlying assets to deposit.

address

receiver

The account that should receive the pToken shares.

calling depositAsCollateral():

Type
Name
Description

uint256

assets

The amount of underlying assets to deposit.

uint256

receiver

The account that should receive the pToken shares.

// Approve the cToken to spend WMON
await WMON.approve(ADDRESSES.WMON_CTOKEN, depositAmount);

// Get the cToken contract
const cToken = new ethers.Contract(
  ADDRESSES.WMON_CTOKEN,
  CTOKEN_ABI,
  signer
);

// Deposit as collateral or regular deposit
if (asCollateral) {
  await cToken.depositAsCollateral(depositAmount);
} else {
  await cToken.deposit(depositAmount, userAddress);
}

Alternatively, if your app requires users depositing for another address, you can use depositAsCollateralFor(). See our Plugin Integration quickstart guide for more information.

Last updated