BLOG — Use cases

398 days ago

Revolutionizing DeFi Yield Optimization with Rysk Finance and Gelato Web3 Functions

Rysk Finance is a decentralized finance platform focused on providing uncorrelated, competitive yields through pure financial engineering.

Their Dynamic Hedging Vaults (DHVs) enable users to access high yields while managing risk effectively through delta-neutral positions. By leveraging Gelato's Web3 Functions, Rysk Finance automates the monitoring and management of collateral across vaults.

How Rysk Finance Uses Web3 Functions

Vault Collateral Management

Rysk Finance uses Gelato's Web3 Functions to automate the adjustVaults function within the VaultCollateralMulticall contract. This ensures efficient monitoring of vault health factors and timely execution of collateral adjustments when needed.

Gelato x Rysk Finance

The integration of Rysk Finance with Gelato's Web3 Functions is crucial for the effective management and automation of the adjustVaults function. By utilizing Web3 Functions, Rysk Finance can proficiently monitor and adjust vault collateral when necessary.

The Web3 Function is designed to periodically evaluate the health factors of various vaults. It starts by gathering the necessary data, such as the last checked block number, active vault IDs, and previous vault count.

lastQueryBlock = parseInt(await storage.get("lastQueryBlock") ?? "0");
activeVaultIds = JSON.parse(await storage.get("activeVaultIds") ?? "[]");
previousVaultCount = parseInt(await storage.get("previousVaultCount") ?? "0");

It then fetches the current block number and looks for vault settled and liquidated events on the blockchain.

const currentBlock = await provider.getBlockNumber();
settleEvents = await controller.queryFilter(controller.filters.VaultSettled(), lastQueryBlock);
liquidationEvents = await controller.queryFilter(controller.filters.VaultLiquidated(), lastQueryBlock);

By filtering the events and updating the active vault IDs, the function ensures that only active vaults are being monitored.

settledEventIds.push(liquidationEvents.filter((event) => event?.args?.vaultOwner == optionRegistryAddress).map((event) => event?.args?.vaultId.toNumber()));
activeVaultIds = activeVaultIds.filter((id) => !settledEventIds.includes(id));

Next, the function assesses the health factors of the remaining vaults to pinpoint those requiring collateral adjustments.

vaultsToAdjust = (await multicall.checkVaults(activeVaultIds)).map((id) => id.toNumber()).filter((id) => id != 0);

If any vaults need adjustments, the Web3 Function generates the essential call data to trigger the adjustVaults function within the smart contract, ensuring a seamless and efficient process for maintaining vault management.

if (vaultsToAdjust.length) {
  return {
    canExec: true,
    callData: multicall.interface.encodeFunctionData("adjustVaults", [vaultsToAdjust])
  };
}

This integration ensures a seamless and efficient process for maintaining vault management.

About Gelato's Web3 Functions

Web3 Functions provide an innovative solution for developers to create serverless, decentralized applications with ease. They enable seamless integration of smart contracts with off-chain data, bridging the gap between on-chain and off-chain worlds.

By leveraging Web3 Functions, developers can build robust, scalable, and decentralized web3 applications, supported by a reliable and resilient infrastructure.

Get Started in Minutes!

Join our community and developer discussion on Discord.

Web3 Functions are available today in private beta. For more information, please check out the Web3 Functions documentation. To learn how to write, test, and deploy your own Web3 Functions, use this Hardhat template

Apply here to be one of the first to test Web3 Functions!