BLOG — Use cases

325 days ago

Unlock DeFi Automation with Gelato's Web3 Functions

With its unparalleled potential, DeFi is transforming our financial world. Its open, decentralized nature democratizes access to financial services. Yet, this brave world is not without its complexities. The promise of DeFi comes with the challenge of managing intricate smart contract operations.This is where Gelato Network steps in, introducing a potent solution - Gelato's Web3 Functions.

In order to fully understand the paradigm shift that DeFi represents, let's compare it to its traditional counterpart, often known as CeFi or Centralized Finance:

  • Access: CeFi is permissioned and requires approval to participate. DeFi is permissionless and open to anyone with an internet connection.
  • Control over Assets: In CeFi, your assets are custodied by third parties. DeFi allows you to maintain direct control over your assets, removing the need for a trusted middleman.
  • Transparency: Traditional finance operates on centralized, often opaque systems. DeFi, powered by blockchain, is fully transparent and verifiable by anyone.
  • Governance: CeFi systems have a centralized body making decisions. DeFi is governed by its community, distributing power among users.
  • Privacy: CeFi requires disclosing real identity, leading to potential privacy concerns. DeFi allows pseudonymous transactions, offering a level of privacy while maintaining security and transparency.

However, despite these fantastic advantages, there are challenges in the DeFi realm that need tackling.

Challenges in DeFi

One of the critical issues in the DeFi space is the need for constant interaction with various protocols and platforms. These interactions could range from claiming staked rewards to rebalancing portfolio positions or even executing trades at certain market conditions. The necessity for consistent engagement often requires significant time, effort, and advanced knowledge from the users.

Furthermore, in DeFi a significant role is played by off-chain data in executing these tasks. Off-chain data refers to any data not natively stored on the blockchain, such as real-time market prices, event triggers, user-specific conditions, and much more. Without access to this off-chain data, it's difficult to create rules that react to real-world changes. Hence, the ability to acquire and integrate off-chain data is crucial for effective DeFi execution.

This is where Gelato Web3 Functions enters the picture, promising to revolutionize the way users interact with DeFi protocols. They could facilitate routine tasks, execute condition-based trades, manage yield farming strategies, and more bringing off-chain data and automation at the same time into the blockchain

Introducing Gelato's Web3 Functions

Gelato Network is at the forefront of this automation revolution with their innovative Web3 Functions. These tools enable developers to create robust, serverless, decentralized applications, blurring the line between on-chain and off-chain worlds.

Web3 Functions serve as the backbone of the on-chain and off-chain connection:

  • On-chain: Refers to the smart contracts that users aim to control and automate.
  • Off-chain: Refers to the Web3 Functions, capable of accessing necessary APIs and executing custom logic to determine the actions of smart contracts.

Linking these two entities is the Web3 Function Task, the mechanism that outlines the conditions triggering the Web3 Function and the target smart contract it controls.

Bridging the Gap

Gelato's Web3 Functions are perfectly positioned to address the DeFi automation challenge. They facilitate seamless integration of smart contracts with off-chain data, enabling automated responses to a variety of conditions. Whether it's yield farming, token swaps, liquidity management, oracles, or derivatives, automation can be applied across the DeFi spectrum.

Let's delve into the potential of the Gelato Web3 Functions in automating DeFi operations:

Yield Farming

Yield farming, at its core, is similar to depositing funds in a traditional savings account for interest but with much higher potential returns. Yield farming protocols incentivize liquidity providers (LP) to lock up their crypto assets in a smart contract-based liquidity pool.

While yield farming has proven highly lucrative, it's not without its challenges. Managing yield farming requires consistent monitoring and strategic interactions with DeFi protocols.

Gelato's Web3 functions offer a solution to these challenges by automating yield farming operations:

  • Automated Reward Management: Gelato's Web3 Functions can automate the process of reinvesting earned rewards back into the liquidity pool. For instance, the off-chain Web3 Function might be set to access an API that monitors the accrued rewards in the smart contract (on-chain). When the rewards hit a certain threshold, the off-chain function triggers the smart contract to reinvest these rewards back into the liquidity pool, optimizing compound returns.
  • Smart Liquidity Management: Web3 Functions can also help manage assets across different liquidity pools in a more efficient manner. A Web3 Function (off-chain) could be set to pull real-time data on the yields of different liquidity pools from an API. When the data indicates a more profitable pool, the Web3 Function triggers the smart contract (on-chain) to shift assets to that pool, allowing for dynamic yield optimization without manual intervention.


Oracles are crucial bridges between off-chain and on-chain data, enabling smart contracts to access and interact with external information.This is necessary because smart contracts running on Ethereum cannot access information stored outside the blockchain network. In terms of automation, managing data feeds via oracles can be a demanding task that requires constant supervision to ensure the reliability and timeliness of data.

Gelato's Web3 functions solve this problem by:

  • Automated Oracle Updates: Web3 Functions can be set to monitor off-chain data sources, such as APIs or other data feeds. When changes are detected, they can trigger the on-chain oracle smart contract to update, ensuring smart contracts always have access to the most recent data.

  • Automated Synchronization: The off-chain Web3 Functions can also monitor multiple oracle contracts across different networks (like testnets and mainnets). When an update occurs in one, it can trigger an equivalent update in the others, ensuring synchronization across all networks.

Token Swaps

In the DeFi ecosystem, token swaps - the process of exchanging one cryptocurrency token for another - are fundamental. However, they pose challenges due to constant market fluctuations, complex balance management, and varied swap rates across different decentralized exchanges (DEXs).

Gelato's Web3 functions offer solutions to these challenges:

  • Automated Token Swaps with Dynamic Rate Monitoring: Gelato's Web3 Functions can be configured to actively monitor token balances and real-time exchange rates from various DEXs' APIs off-chain. When pre-set conditions such as a sufficient balance and a favorable exchange rate are met, the Web3 Function triggers the on-chain smart contract to execute the swap. This process not only eliminates the need for manual supervision but also ensures users consistently get the best possible swap rates, enhancing overall trading efficiency.

Crypto Derivatives

Crypto derivatives are contracts in the DeFi space, based on the future price of a cryptocurrency. Although they offer various trading and risk management opportunities, managing them involves challenges such as collateral tracking, vault monitoring, and timely adjustments to market fluctuations.

Gelato's Web3 functions are designed to address these challenges by offering automated solutions:

  • Automated Vault Monitoring and Collateral Management: Web3 Functions can be designed to track the status of multiple vaults and manage collateral assets off-chain. When pre-set conditions regarding vault health or collateral requirements are met, the Web3 Function triggers the on-chain contract to take necessary actions, minimizing the need for manual oversight and reducing the risk of human error.

Lending and Borrowing

DeFi lending platforms have revolutionized the way we lend and borrow by eliminating intermediaries and leveraging blockchain's trustless nature. However, such platforms face two key challenges:

  • Automated Liquidity and Position Monitoring: Web3 Functions can be designed to constantly monitor the liquidity of pools and the status of lending and borrowing positions off-chain. Based on pre-defined conditions such as pool liquidity thresholds or changes in loan health, the Web3 Function can trigger the on-chain contract to perform necessary actions like adding liquidity or adjusting a loan position.

By leveraging these functions, DeFi lending platforms can streamline operations, reduce manual intervention, and ensure an efficient borrowing and lending experience.

Gelato's Web3 Functions are revolutionizing the DeFi landscape by automating complex tasks and streamlining operations across various applications. From yield farming to oracles, token swaps to crypto derivatives, and lending to borrowing, Gelato's functions offer practical solutions to the challenges faced by DeFi users and developers.

By leveraging Gelato's Web3 Functions, users can automate routine tasks, optimize asset management, minimize manual intervention, and enhance overall efficiency. These functions enable seamless integration of on-chain smart contracts with off-chain data, ensuring timely execution based on predefined conditions.

Join the revolution!

Gelato's 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.

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 test Web3 Functions!