Polygon DeFi 101: What Are Smart Contracts and How Will They Work in an Aggregated Network?

The best resource for learning about what smart contracts mean in an aggregated network

May 7, 2024
Aggregation
Image source: Dribbble

Smart contracts are the fuel of DeFi. 

They help put the “decentralized” in “decentralized finance” by executing various functions if certain conditions are met. Look in on any given network’s buzz and hum of dApps, and you’ll see these are powered by smart contracts, making DeFi a reality. 

But widen the scope from a single blockchain to many sovereign chains. What happens when you design DeFi across chains? What do smart contracts look like in this expanded network?

That’s what this DeFi explainer is all about.

Below, a refresher on aggregated blockchains; then a 101 explainer on how smart contracts work, and finally what they mean for this new aggregated paradigm. 

What are aggregated blockchains again? 

In short: A web of sovereign, connected chains, where liquidity and state are shared, with the feel and user experience of a single chain.

The AggLayer is being developed by core developers at Polygon Labs, in conjunction with a ton of community contributors. The first components are already live, with three chains already connected: OKX’s X Layer, Astar zkEVM, and Polygon zkEVM. 

Okay, cool. There’s a lot more to read and understand, including a Beginner’s Guide to Aggregated Blockchains and the Aggregated Thesis.

But you’re here to learn about smart contracts. 

What are smart contracts?

It’s a misnomer to think of a smart contract as either “smart” or “a contract.”

At a basic level, a smart contract is simply open source code that self-executes when specific conditions are met. The terms of what event will happen are dictated by software, without the intervention of any actor. A smart contract might be triggered by an external event (like the receipt of payment) or some other condition. 

The immutability and decentralization of blockchains allows smart contracts to be created with assurances that certain functions will be carried out when specific conditions are met. Many smart contracts can’t be modified after they’re deployed on a blockchain; this is a feature, rather than a bug, because immutability and predictability are the whole point.

However, some smart contracts can be modified through various governance mechanisms, such as shared admin keys. This allows updates to contracts that are continually in use, such as those that power L2s running atop Ethereum.

Note that while smart contracts execute code as written, the outcome of the event is only as reliable as the code itself. Errors and vulnerabilities can lead to unintended consequences. 

In either case, the point is transparency and a guarantee that code will execute whatever is enshrined in the smart contract. Instead of a promise from humans that could be broken, you get the assurances of code.

How do smart contracts work together?

Smart contracts don’t exist in isolation. They can interact with one another, in a dynamic called “composability,” or turn to oracles to determine the latest data, like prices or other external information. This composable capability is what builds complex dApps, such as DeFi protocols that require interactions between multiple smart contracts and underlying chains.

Most of what we love about blockchains relies on interactions between different smart contracts, from decentralized borrowing to DAO governance. Whenever you perform some action on a blockchain with the assurance that you’ll also be able to do something complementary yet different in the future–such as withdraw funds that you’re depositing in a DeFi lending protocol–you’re taking advantage of the power of smart contracts.

Smart contracts are the most important mechanism for making blockchains useful for more than just creating more blocks and updating state.

Unlocking cross-chain interoperability with bridgeAndCall(), a smart contract library for the aggregated network

Let’s bring it all together. Smart contracts in the AggLayer = bridgeAndCall(), a Solidity library that will allow distinctly streamlined composability across sovereign chains. 

So what is bridgeAndCall()? A powerful library that allows developers to program cross-chain logic in smart contracts. Imagine, for instance, a scenario where a user wants to: 

  1. transfer an asset from Chain A to Chain B; 
  2. swap for a new asset; 
  3. transfer the new asset from Chain B to Gaming Chain;
  4. and mint a gaming NFT.

With bridgeAndCall(), it can happen in a single click. It’s all one transaction.

Users can not only transfer assets seamlessly between chains (bridge), but also trigger contracts on a different chain after the asset has arrived (call). This means that developers can create complex, multi-chain workflows that were previously unimaginable—or which would require cumbersome bridging and excruciating fees. This improves the UX as you don’t need to sign multiple times or wait between transactions.

There’s a wide range of new use cases and applications unlocked with the dual realities of an aggregated network and smart contract execution. 

By providing a simple and intuitive way to bridge assets and trigger contracts across different chains, we’re looking down the barrel of new possibilities in DeFi. 

    * * * 

Tune into the blog and our social channels to keep up with updates about the Polygon.

The future of Web3 is aggregated.

Website | Twitter | Forum | Telegram | Discord | Instagram | LinkedIn | Polygon Knowledge Layer

More from blogs