Provide protection programmatically
Learn how to provide protection by supplying assets to a protection market programmatically.
Supply assets to a protection market
// STEP 0: ENVIRONMENT SETUP
const supplyAmount = '1000'; // Amount of USDC we want to supply, in dollars (e.g. 1000 = $1000 = 1000 USDC)
// Since we are testing on a forked mainnet and our account has no
// funds, we need to initialize the account with the required tokens.
// This step is not needed when the private key in your .env file has
// funds on mainnet
const usdcAddress = getContractAddress('USDC', chainId);
await fundAccount(usdcAddress, supplyAmount, signer.address, hre);
// If the account also needed ETH, you could fund it as shown here
const ethAddress = getContractAddress('ETH', chainId);
await fundAccount(ethAddress, '10', signer.address, hre);
// STEP 1: VERIFY MARKET
// We know we'll need the Comptroller, so create an instance the Comptroller contract
const comptrollerAddress = getContractAddress('Comptroller', chainId);
const comptroller = new Contract(comptrollerAddress, comptrollerAbi, signer); // connect signer for sending transactions
// The first check is to make sure our protection market is a valid
// protection market that we can supply to
const yearnProtectionMarketAddress = getContractAddress('YearnProtectionMarket', chainId);
const allMarkets = await comptroller.getAllMarkets();
if (!allMarkets.includes(yearnProtectionMarketAddress)) {
logFailure("Provided Protection Market address not found in the Comptroller's list of all markets");
return;
}
logSuccess('Provided Protection Market address is valid');Verify transaction results
Last updated