Protecting DeFi.
The protocol for creating protected products.
Create Protection
Earn revenue by creating Protection Markets
Protection Markets let people provide and purchase protection against any condition you can define in a smart contract. The more popular your Protection Market, the more revenue you earn.*
Integrate Protection
Attract more users by adding protection to your products
Compose Cozy Protection Markets into your products to offer a protected-by-default experience. Risk averse people will feel more comfortable knowing their principal is protected.
Provide Protection
Put your idle assets to work by providing protection
Provide protection in Cozy Protection Markets to earn yield and subsidize protection for your users. Perfect for idle treasury or balance sheet assets.*
// Define the address of the market protected by your protection market
// here we use Yearn's yUSDC V2 vault
const protectedMarket = '0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9'
// Define the address of the underlying token (if USDC is underlying, you supply and borrow USDC)
const underlying = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48' // USDC address
Example
Create a protected market for
Ethereum
on
Yearn
Example
Create a protected market for Ethereum on Yearn
constructor(
string memory _name,
string memory _symbol,
string memory _description,
uint256[] memory _platformIds,
address _recipient,
address _market
) ITrigger(_name, _symbol, _description, _platformIds, _recipient) {
// Set vault
market = IYVaultV2(_market);
// Save current share price (immutables can't be read at construction,
// so we don't use `market` directly)
lastPricePerShare = IYVaultV2(_market).pricePerShare();
}
/**
* @dev Checks the yVault pricePerShare
*/
function checkTriggerCondition() internal override returns (bool) {
// Read this blocks share price
uint256 _currentPricePerShare = market.pricePerShare();
// Check if current share price is below current share price, accounting for tolerance
bool _status = _currentPricePerShare < ((lastPricePerShare * tolerance) / 1e18);
// Save the new share price
lastPricePerShare = _currentPricePerShare;
// Return status
return _status;
}
Trigger Explained
Example USDC/Yearn Logic
We want to protect USDC invested in the Yearn yUSDC V2 vault from a hack or exploit.
One way to do that is observing the vault's pricePerShare. After each vault harvest, the pricePerShare will decrease by a small amount, but it should never decrease by a significant amount. Therefore, if we see this value decrease by 50%, we consider the trigger toggled.
// Get deployer account
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL);
const deployer = new ethers.Wallet(process.env.PRIVATE_KEY, provider);
// Define constructor parameters for trigger
const triggerParams = [
'Yearn USDC V2 Vault Share Price Trigger', // name
'yUSDC-V2-SP-TRIG', // symbol
'Triggers when the Yearn USDC V2 vault share price decreases', // description
[1], // platform ID for Yearn
deployer.address, // subsidy recipient is deployer
protectedMarket, // This is the yUSDC vault protected by the trigger
];
// Get instance of the Trigger ContractFactory with our signer attached
const TriggerFactory: ContractFactory = await hre.ethers.getContractFactory(
'YearnV2SharePriceTrigger',
deployer,
);
// Deploy the trigger contract
const trigger: Contract = await MockTriggerFactory.deploy(...triggerParams);
await trigger.deployed();
console.log(`MockTrigger deployed to ${trigger.address}`);
// Create the protection market
const comptroller = new Contract(
'0x349f0A62CE40055b70557e1173287469d601A1e0',
comptrollerAbi,
deployer,
);
const tx = await comptroller.deployProtectionMarket(underlying, trigger.address);
await tx.wait();
console.log(`Protection Market created in transaction ${tx.hash}`);
Example below of your newly deployed Protection Market!
Asset
Protected Against
Market Size
ETH
Yearn
Yearn USDC V2 Vault Share Price Trigger
Triggers when the Yearn USDC V2 vault share price decreases
$0