// STEP 2: PROVIDE PROTECTION
// We're now ready to supply collateral (i.e. provide protection) to
// the market, but there's some preparation we need to do beforehand.
// First, recall that USDC has 6 decimal places, so we need to take
// that into account. We'll do this programmatically by querying the
// USDC contract for the number of decimals it has
const usdc = new Contract(usdcAddress, erc20Abi, signer);
const decimals = await usdc.decimals();
const parsedSupplyAmount = parseUnits(supplyAmount, decimals); // scale amount based on number of decimals
// Next we need to approve the protection market contract to spend
// our USDC. We trust the contract, so approve it to spend the
// maximum possible amount to avoid future approvals and save gas
const approveTx = await usdc.approve(yearnProtectionMarketAddress, MaxUint256);
// Let's verify this approve transaction was successful
const allowance = await usdc.allowance(signer.address, yearnProtectionMarketAddress);
if (!allowance.eq(MaxUint256)) {
logFailure('CozyUSDC does not have sufficient allowance to spend our USDC. Exiting script');
logSuccess('Approval transaction successful. Ready to mint CozyUSDC with our USDC');
// Now we can supply funds to the protection market to provide
// protection. Just like with ordinary Money Markets, this mints a
// receipt token that is sent to our wallet
const yearnProtectionMarket = new Contract(yearnProtectionMarketAddress, cozyTokenAbi, signer);
const mintTx = await yearnProtectionMarket.mint(parsedSupplyAmount);
const { log: mintLog, receipt: mintReceipt } = await findLog(mintTx, yearnProtectionMarket, 'Mint', provider);
const yearnProtectionMarketSymbol = await yearnProtectionMarket.symbol();
const yearnProtectionMarketName = await yearnProtectionMarket.name();
`${yearnProtectionMarketName} (${yearnProtectionMarketSymbol}) successfully minted in transaction ${mintReceipt.transactionHash}`