Trustless token management with Set Protocol
How to integrate token sets in your contracts
With Set Protocol you can create baskets of tokens that give users different levels of exposure to underlying assets (currently only ERC-20 tokens).
Set Protocol and their TokenSet functionality is the perfect example for making use of the new paradigm of Defi and composability. You can let someone else manage your tokens for you, but they cannot steal all your funds. Of course there is some level of trust involved that the manager generally acts in the best interest of every Set participant, but since he receives fees from participants and has no direct monetary gain, the risk is minimized.

So what is Set Protocol?
With the Set Protocol you can enable passive managements for ERC-20 tokens on Ethereum. A given set is managed by one or multiple managers that can employ different strategies based on the functionality added to this set. The system is designed in a modular way allowing you to choose which functionality in the form of modules to add to a set. In the future all of the governance inside Set Protocol will be fully decentralized.

Let's explore the relevant components of the underlying protocol...

1. The main contract: SetToken
The ERC20 Token contract that allows privileged modules to make modifications to its positions and invoke function calls from the SetToken.
You would create a new SetToken with the SetTokenCreator factory. You can call create and pass
- a list of ERC-20 addresses (
_components) - a list of quantities for each given token (
_units) - a list of modules to be used (
_modules) - the manager address (
_manager) - the name of the set (
_name) - the symbol of the set (
_symbol)
function create(
address[] memory _components,
int256[] memory _units,
address[] memory _modules,
address _manager,
string memory _name,
string memory _symbol
) external returns (address)A concept of virtual and real quantities exist for efficient updating. It's essentially just a multiplier that exists inside the SetToken. A real unit value is calculated as realUnit = positionUnit * positionMultiplier. This would allow updating the multiplier to change the real values of each component very efficiently.
2. Additional data contracts: Resources
Resources are contracts that provide data, functionality, or permissions that can be drawn upon from.
Those include most notably the controller, registry and price oracle.
A. System Controller
The controller is the master manager contract and can be used to
- Add/Remove Modules
- Add/Remove Factories
- Add/Remove Resources
- Remove SetTokens
- Add/Edit/Change Fees
- Edit Fee Recipient
The owner of the controller will eventually be a DAO, thus allowing decentralized governance of sets. Currently it's still a multi-sig contract.
B. Integration Registry
The IntegrationRegistry is used to manage external integrations, like support for the Aave system or an external DEX.
Governance can use this to:
- Add/Edit/Remove Integrations
C. Price Oracle
The PriceOracle returns a price for a given token pair. The price is retrieved either directly from an oracle, calculated using common asset pairs, or retrieved from external data.
The governance is allowed to
- Add/Edit/Remove Oracles and Adapters
3. Modules
Modules can be added to a SetToken and enable extra functionality. Th modules are optional additions to a SetToken and can be added or removed from a set by the manager.
Let's take a look at three common modules.
A. Basic Issuance
The Basic Issuance module allows users to mint (issue) and redeem a SetToken. The basic flow for this module is:
For each component inside the _setToken, do
- Retrieve ERC-20 address.
- Retrieve required quantity given the passed
_quantity. - Transfer quantity of given ERC-20 to the SetToken address from sender.
Lastly mint _quantity SetToken tokens to the passed _to address.
The respective redeem function works similarly the other way around and burns the SetTokens again.
function issue(
ISetToken _setToken,
uint256 _quantity,
address _to
) external;function redeem(
ISetToken _setToken,
uint256 _quantity,
address _to
) external;B. Trade
The Trade module adds powerful trading functionality to a Set. However you will have to write your own integration for whichever market you want to trade on or you can use the existing Kyber integration.
The trade function can be called to execute a trade for a given SetToken. You will essentially sell the given sendToken in the sendQuantity for the receiveToken. Obviously the token you want to sell must actually exist in the SetToken in sufficient quantity.
Only the token manager may call the trade function.
If you want to write your own DEX integration, have a look at the KyberExchangeAdapter.
function trade(
ISetToken _setToken,
string memory _exchangeName,
address _sendToken,
uint256 _sendQuantity,
address _receiveToken,
uint256 _minReceiveQuantity,
bytes memory _data
)C. Tokenset Governance
Tokens these days are commonly used for governance as well, just remember when we look at the COMP governance. This is exactly what you can do with the Governance Module. Intended governance protocols are Compound, Uniswap and Maker, but theoretically any system that complies to the same functions could be used here.
The functionality includes
delegate: Delegate voting power.propose: Create a new proposal.vote: Cast a vote on a proposal.
For more details on those functions and governance, take a look at the above mentioned COMP governance article.
Once again only the manager of the TokenSet may call any of those functions.
4. Rebalancing Sets
One interesting feature of sets is rebalancing. Usually with any assets you have the ratio of exposure you get from them can change dramatically over time given the price changes. Just imagine you have three tokens of projects you really like. Let's call them SuperCoolToken, SuperInterestingToken and SuperUsefulToken. You think all projects at the time of investing are valued at equally good prices, so you choose an even split of 33%.
Now you create a TokenSet with
- 33% SuperCoolToken
- 33% SuperInterestingToken
- 33% SuperUsefulToken
Now after a few months, SuperCoolToken mooned and went 10x, while SuperInterestingToken stayed the same and SuperUsefulToken actually went down by 50%. Your ratio now would be
- 87% SuperCoolToken
- 9% SuperInterestingToken
- 4% SuperUsefulToken
But you might still think all projects are still equally promising. Or you just want a more diversified exposure. In this case, wouldn't it be useful to have a mechanism automatically rebalance it to the original ratio?
It's explained in further details inside the Whitepaper. However, I'm curious as to what the current state for this is.
According to the Whitepaper the rebalancing works either via automated trading on DEX's or a system internal dutch auction. I can already see a rebalance overview site on https://www.tokensets.com/rebalance which is in fact listing auctions. However I could not find any smart contract code in the repository which contains the auction code. So if you know what's going on, please let me know.
There is however one module called SingleIndexModule which can be used for rebalancing functionality. It doesn't start auctions, but uses the defined DEX's to initiate a rebalancing.
There you have it, I find Set Protocol a fascinating idea and looking forward to where this develops in the future. Have you used Set Protocol before as a user? Or have you even interacted with the contracts directly? Let me know in the comments below.
Solidity Developer
More great blog posts from Markus Waas
How to use ChatGPT with Solidity
Using the Solidity Scholar and other GPT tips
How to integrate Uniswap 4 and create custom hooks
Let's dive into Uniswap v4's new features and integration
How to integrate Wormhole in your smart contracts
Entering a New Era of Blockchain Interoperability
Solidity Deep Dive: New Opcode 'Prevrandao'
All you need to know about the latest opcode addition
How Ethereum scales with Arbitrum Nitro and how to use it
A blockchain on a blockchain deep dive
The Ultimate Merkle Tree Guide in Solidity
Everything you need to know about Merkle trees and their future
The New Decentralized The Graph Network
What are the new features and how to use it
zkSync Guide - The future of Ethereum scaling
How the zero-knowledge tech works and how to use it
Exploring the Openzeppelin CrossChain Functionality
What is the new CrossChain support and how can you use it.
Deploying Solidity Contracts in Hedera
What is Hedera and how can you use it.
Writing ERC-20 Tests in Solidity with Foundry
Blazing fast tests, no more BigNumber.js, only Solidity
ERC-4626: Extending ERC-20 for Interest Management
How the newly finalized standard works and can help you with Defi
Advancing the NFT standard: ERC721-Permit
And how to avoid the two step approve + transferFrom with ERC721-Permit (EIP-4494)
Moonbeam: The EVM of Polkadot
Deploying and onboarding users to Moonbeam or Moonriver
Advanced MultiSwap: How to better arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
Deploying Solidity Smart Contracts to Solana
What is Solana and how can you deploy Solidity smart contracts to it?
Smock 2: The powerful mocking tool for Hardhat
Features of smock v2 and how to use them with examples
How to deploy on Evmos: The first EVM chain on Cosmos
Deploying and onboarding users to Evmos
EIP-2535: A standard for organizing and upgrading a modular smart contract system.
Multi-Facet Proxies for full control over your upgrades
MultiSwap: How to arbitrage with Solidity
Making multiple swaps across different decentralized exchanges in a single transaction
The latest tech for scaling your contracts: Optimism
How the blockchain on a blockchain works and how to use it
Ultimate Performance: The Aurora Layer2 Network
Deploying and onboarding users to the Aurora Network powered by NEAR Protocol
What is ecrecover in Solidity?
A dive into the waters of signatures for smart contracts
How to use Binance Smart Chain in your Dapp
Deploying and onboarding users to the Binance Smart Chain (BSC)
Using the new Uniswap v3 in your contracts
What's new in Uniswap v3 and how to integrate Uniswap v3
What's coming in the London Hardfork?
Looking at all the details of the upcoming fork
Welcome to the Matrix of blockchain
How to get alerted *before* getting hacked and prevent it
The Ultimate Ethereum Mainnet Deployment Guide
All you need to know to deploy to the Ethereum mainnet
SushiSwap Explained!
Looking at the implementation details of SushiSwap
Solidity Fast Track 2: Continue Learning Solidity Fast
Continuing to learn Solidity fast with the advanced basics
What's coming in the Berlin Hardfork?
Looking at all the details of the upcoming fork
Using 1inch ChiGas tokens to reduce transaction costs
What are gas tokens and example usage for Uniswap v2
Openzeppelin Contracts v4 in Review
Taking a look at the new Openzeppelin v4 Release
EIP-3156: Creating a standard for Flash Loans
A new standard for flash loans unifying the interface + wrappers for existing ecosystems
Tornado.cash: A story of anonymity and zk-SNARKs
What is Tornado.cash, how to use it and the future
High Stakes Roulette on Ethereum
Learn by Example: Building a secure High Stakes Roulette
How to implement generalized meta transactions
We'll explore a powerful design for meta transactions based on 0x
Utilizing Bitmaps to dramatically save on Gas
A simple pattern which can save you a lot of money
Using the new Uniswap v2 as oracle in your contracts
How does the Uniswap v2 oracle function and how to integrate with it
Smock: The powerful mocking tool for Hardhat
Features of smock and how to use them with examples
How to build and use ERC-721 tokens in 2021
An intro for devs to the uniquely identifying token standard and its future
Exploring the new Solidity 0.8 Release
And how to upgrade your contracts to Solidity 0.8
How to build and use ERC-1155 tokens
An intro to the new standard for having many tokens in one
Leveraging the power of Bitcoins with RSK
Learn how RSK works and how to deploy your smart contracts to it
Solidity Fast Track: Learn Solidity Fast
'Learn X in Y minutes' this time with X = Solidity 0.7 and Y = 20
Sourcify: The future of a Decentralized Etherscan
Learn how to use the new Sourcify infrastructure today
Integrating the 0x API into your contracts
How to automatically get the best prices via 0x
How to build and use ERC-777 tokens
An intro to the new upgraded standard for ERC-20 tokens
COMP Governance Explained
How Compound's Decentralized Governance is working under the hood
How to prevent stuck tokens in contracts
And other use cases for the popular EIP-165
Understanding the World of Automated Smart Contract Analyzers
What are the best tools today and how can you use them?
A Long Way To Go: On Gasless Tokens and ERC20-Permit
And how to avoid the two step approve + transferFrom with ERC20-Permit (EIP-2612)!
Smart Contract Testing with Waffle 3
What are the features of Waffle and how to use them.
How to use xDai in your Dapp
Deploying and onboarding users to xDai to avoid the high gas costs
Stack Too Deep
Three words of horror
Integrating the new Chainlink contracts
How to use the new price feeder oracles
TheGraph: Fixing the Web3 data querying
Why we need TheGraph and how to use it
Adding Typescript to Truffle and Buidler
How to use TypeChain to utilize the powers of Typescript in your project
Integrating Balancer in your contracts
What is Balancer and how to use it
Navigating the pitfalls of securely interacting with ERC20 tokens
Figuring out how to securely interact might be harder than you think
Why you should automatically generate interests from user funds
How to integrate Aave and similar systems in your contracts
How to use Polygon (Matic) in your Dapp
Deploying and onboarding users to Polygon to avoid the high gas costs
Migrating from Truffle to Buidler
And why you should probably keep both.
Contract factories and clones
How to deploy contracts within contracts as easily and gas-efficient as possible
How to use IPFS in your Dapp?
Using the interplanetary file system in your frontend and contracts
Downsizing contracts to fight the contract size limit
What can you do to prevent your contracts from getting too large?
Using EXTCODEHASH to secure your systems
How to safely integrate anyone's smart contract
Using the new Uniswap v2 in your contracts
What's new in Uniswap v2 and how to integrate Uniswap v2
Solidity and Truffle Continuous Integration Setup
How to setup Travis or Circle CI for Truffle testing along with useful plugins.
Upcoming Devcon 2021 and other events
The Ethereum Foundation just announced the next Devcon in 2021 in Colombia
The Year of the 20: Creating an ERC20 in 2020
How to use the latest and best tools to create an ERC-20 token contract
How to get a Solidity developer job?
There are many ways to get a Solidity job and it might be easier than you think!
Design Pattern Solidity: Mock contracts for testing
Why you should make fun of your contracts
Kickstart your Dapp frontend development with create-eth-app
An overview on how to use the app and its features
The big picture of Solidity and Blockchain development in 2020
Overview of the most important technologies, services and tools that you need to know
Design Pattern Solidity: Free up unused storage
Why you should clean up after yourself
How to setup Solidity Developer Environment on Windows
What you need to know about developing on Windows
Avoiding out of gas for Truffle tests
How you do not have to worry about gas in tests anymore
Design Pattern Solidity: Stages
How you can design stages in your contract
Web3 1.2.5: Revert reason strings
How to use the new feature
Gaining back control of the internet
How Ocelot is decentralizing cloud computing
Devcon 5 - Review
Impressions from the conference
Devcon 5 - Information, Events, Links, Telegram
What you need to know
Design Pattern Solidity: Off-chain beats on-chain
Why you should do as much as possible off-chain
Design Pattern Solidity: Initialize Contract after Deployment
How to use the Initializable pattern
Consensys Blockchain Jobs Report
What the current blockchain job market looks like
Provable — Randomness Oracle
How the Oraclize random number generator works
Solidity Design Patterns: Multiply before Dividing
Why the correct order matters!
Devcon 5 Applications closing in one week
Devcon 5 Applications closing
Randomness and the Blockchain
How to achieve secure randomness for Solidity smart contracts?