superform-xyz / superform-core

Other
98 stars 37 forks source link

Overview

codecov

The Superform Protocol is a suite of non-upgradeable, non-custodial smart contracts that act as a central repository for yield and a router for users. It is modular, permissionless to list vaults, and enables intent-based transactions across chains that allow users to execute into an arbitrary number of tokens, chains, and vaults at once.

For DeFi protocols, it acts as an instant out-of-the-box distribution platform for ERC4626-compliant vaults. For users, it allows access to any vault listed on the platform from the chain and asset of their choice in a single transaction.

Core capabilities for protocols include:

Core capabilities for users include:

This repository includes all Superform contracts and can be split into two categories: Core and Periphery.

Superform__SuperformProtocol--DARK (2)

Resources

Project structure

.
├── script
├── security-review
├── src
  ├── crosschain-data
  ├── crosschain-liquidity
  ├── forms
  ├── interfaces
  ├── libraries
  ├── payments
  ├── settings
  ├── types
  ├── vendor
├── test
├── foundry.toml
└── README.md

Documentation

We recommend visiting technical documentation at https://docs.superform.xyz.

Contract Architecture

  1. All external actions, except Superform creation, start in SuperformRouter.sol. For each deposit or withdraw function the user has to provide the appropriate "StateRequest" found in DataTypes.sol
  2. All deposit and withdrawal actions can be to single or multiple destinations, single or multi vaults, and same-chain or cross-chain. Any token can be deposited from any chain into a vault with swapping and bridging handled in a single call. Sometimes it is also needed to perform another action on the destination chain for tokens with low bridge liquidity, through the usage of DstSwapper.sol. Similarly for withdraw actions, users can choose to receive a different token than the one redeemed for from the vault, but funds must go back directly to the user (i.e. no use of DstSwapper.sol).
  3. Any individual tx must be of a specific kind, either all deposits or all withdraws, for all vaults and destinations
  4. Vaults themselves can be added permissionlessly to Forms in SuperformFactory.sol by calling createSuperform(). Forms are code implementations that adapt to the needs of a given vault, currently all around the ERC-4626 Standard. Any user can wrap a vault into a Superform using the SuperformFactory but only the protocol may add new Form implementations.
  5. This wrapping action leads to the creation of Superforms which are assigned a unique id, made up of the superForm address, formId, and chainId.
  6. Users are minted SuperPositions on successful deposits, a type of ERC1155 modified called ERC1155A. On withdrawals these are burned. Users may also within each "StateRequest" deposit choose whether to retain4626 which sends the vault share directly to the user instead of holding in the appropriate Superform, but only SuperPositions can be withdrawn through SuperformRouter.

User Flow

In this section we will run through examples where users deposit and withdraw into vault(s) using Superform.

Screenshot 2023-11-24 at 9 47 38 AM

Same-chain Deposit Flow

Screenshot 2023-11-24 at 9 48 01 AM

Cross-chain Deposit Flow

Screenshot 2023-11-24 at 9 48 37 AM

Same-chain Withdrawal Flow

Screenshot 2023-11-24 at 9 48 55 AM

Cross-chain Withdrawal Flow

Tests

Step by step instructions on setting up the project and running it

  1. Make sure Foundry is installed with the following temporary workarounds (see: https://github.com/foundry-rs/foundry/issues/8014)
  1. Set the rpc variables in the makefile using your own nodes and disable any instances that run off 1password
POLYGON_RPC_URL=
AVALANCHE_RPC_URL=
FANTOM_RPC_URL=
BSC_RPC_URL=
ARBITRUM_RPC_URL=
OPTIMISM_RPC_URL=
ETHEREUM_RPC_URL=
BASE_RPC_URL=
FANTOM_RPC_URL=
  1. Install submodule dependencies:
forge install
  1. Run make ftest to run tests against the contracts
$ make ftest