Revolutionizing DeFi Yield Optimization with Rysk Finance and Gelato Web3 Functions

Gelato Team

May 17, 2023

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

Their Dynamic Hedging Vaults (DHVs) give users access to high yields while effectively managing risk via delta-neutral positions. 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 integrates Gelato’s Web3 Functions to automate the adjustVaults function within the VaultCollateralMulticall contract. This automation ensures efficient monitoring of vault health factors and executes timely collateral adjustments when necessary.

Gelato x Rysk Finance

The integration of Gelato’s Web3 Functions is crucial for automating vault collateral management. With Web3 Functions, Rysk Finance can continuously monitor and adjust vault collateral in a seamless and efficient manner.

The Web3 Function periodically evaluates vault health. It begins by retrieving stored data such as the last checked block, active vault IDs, and the 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 queries blockchain events for vault settlements and liquidations:

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

By filtering these events and updating vault IDs, the function ensures only active vaults are 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 checks the health of the remaining vaults to identify which need adjustments:

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

If vaults require adjustments, the function generates the calldata needed to trigger adjustVaults in the smart contract:

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

This ensures continuous, efficient vault health management — without manual oversight.

About Gelato's Web3 Functions

Web3 Functions allow developers to build serverless, decentralized applications that connect on-chain contracts with off-chain data. They bridge the gap between both worlds, enabling powerful automation and resilient infrastructure for Web3 applications.

Get Started in Minutes!

👉 Join our community and developer discussions on Discord.

👉 Try Web3 Functions today in private beta.

👉 Learn more in the documentation and explore the Hardhat template.

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

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.

Ready to build?

Start with a testnet, launch your mainnet in days, and scale with industry-leading UX.