Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article covers ERC7621, a proposal that uses an NFT called a Basket Token Standard (BTS) token to create collateralized tokenized funds with adjustable weights and reserves, and to issue and burn LP tokens.

This article translates, summarizes, and supplements the material below.

I have also covered various other EIPs.

Overview

This standard proposes implementing funds containing multiple ERC20 tokens using an NFT known as a Basket Token Standard (BTS) token.

A fund is a mechanism that pools capital collected from multiple investors, manages and invests that capital, and distributes investment returns to the investors. The term can also refer to the pooled capital itself.

BTS tokens are issued as NFTs and represent ownership of the fund. LP (liquidity provider) tokens are also issued to represent proportional contributions to the fund. They are created with mint and destroyed with burn whenever contributions or withdrawals occur.

BTS token owners can change the composition of the fund at any time by adding or removing individual ERC20 tokens. Because BTS tokens are based on the ERC721 standard, they can be managed and transferred onchain.

For more information about ERC20 tokens, see the following article.

https://chaldene.net/erc20

For more information about ERC721 tokens, see the following article.

https://chaldene.net/erc721

Motivation

There is currently no standardized infrastructure for creating and managing asset-backed tokenized investment funds on a blockchain. Providing such infrastructure makes it easier to implement traditional fund management onchain.

Previously proposed EIPs did not provide a mechanism for issuing LP tokens when other addresses contributed assets. This standard implements rebalancing for efficient fund management, LP token issuance when other addresses contribute assets, and a mechanism to burn LP tokens when withdrawals occur.

As an aside, Google Translate interpreted BTS as Bangtan Sonyeondan, the name of the music group. This has nothing to do with the BTS token proposed in this standard.

Specification

BTS

BTS is a contract for creating asset-backed onchain tokenized funds. Assets and liquidity can be managed using the following features.

  • Initialization
    • Creates a new fund and performs its initial configuration.
  • Contributions
    • Allows other addresses to add assets to the fund.
  • Withdrawals
    • Allows users to withdraw assets from the fund.
  • Rebalancing
    • Adjusts the proportions of assets within the fund.
  • Token distribution
    • Uses mint and burn for LP tokens when contributions or withdrawals occur.

Objective

BTS aims to enable anyone to build fully asset-backed onchain tokenized funds using onchain liquidity.

Main Features

initialize

Creates a new BTS and sets its basic information and initial token composition.

  • name
    • Fund name.
  • symbol
    • Fund symbol.
  • creator
    • Fund creator.
  • tokens
    • Array of addresses of the tokens included in the fund.
  • weights
    • Array of initial weights for each token.
  • token URI
    • Token metadata URI.
  • auto-rebalance
    • Automatic rebalancing configuration (optional).

contribute

  • Overview: Allows users to add ETH to the basket.
  • Behavior:
    • Users send ETH, which is used to buy the included tokens according to predefined weights.
  • Purpose: Facilitates new contributions to the fund.

withdraw(uint256 _liquidity)

Allows LP token holders to withdraw ERC20 tokens in proportion to their LP token amount.

  • _liquidity
    • Amount of LP tokens.

withdrawETH(uint256 _liquidity)

Allows LP token holders to withdraw ETH in proportion to their LP token amount.

  • _liquidity
    • Amount of LP tokens.

rebalance(address[] memory _newTokens, uint256[] memory _newWeights)

Allows the fund owner to manually adjust the types and amounts of tokens in the basket.

  • _newTokens
    • Array of new token addresses.
  • _newWeights
    • Array of new token weights.

getTokenDetails

Returns details about the token at a specified index.

  • index
    • Token index.
  • Return value
    • Token address and weight.

totalTokens

Returns the total number of tokens in the basket.

  • Return value
    • Total number of tokens.

BTS Token Distribution

BTS token distribution occurs when mint is executed. When a user sends ETH to the contract, the ETH is exchanged for specified ERC20 tokens according to predefined weights. Once the exchange is complete, the BTS contract's initialize function is used to mint a BTS token (NFT) for the sender. The BTS token represents ownership of the fund and provides BTS management capabilities. BTS LP tokens are also issued to the user through mint at the same time.

BTS LP Token Distribution

BTS LP tokens are distributed when the mint and contribute functions are executed. When a user sends ETH and that ETH is exchanged for the specified ERC20 tokens, the contract uses mint to issue BTS LP tokens to the user. These tokens represent the user's share of the BTS fund. The BTSPair contract executes mint for BTS LP tokens, reflecting the liquidity supplied by the user, and emits a ContributedToBTS event.

BTS LP Token burn

BTS LP token burn occurs when the withdraw function is executed. When a user specifies the amount of BTS LP tokens to withdraw, that amount is transferred from the user to the BTSPair contract (btsPair). The BTSPair contract's burn function is then called, reducing the user's BTS LP token balance. The array of withdrawn tokens is returned to the user, and a WithdrawnFromBTS event is emitted.

Events

ContributedToBTS(address indexed bts, uint256 amount)

Emitted when someone adds ETH to the basket.

WithdrawnFromBTS(address indexed bts, uint256[] amounts)

Emitted when a BTS LP holder withdraws tokens from the basket.

WithdrawnETHFromBTS(address indexed bts, uint256 amount)

Emitted when a BTS LP holder withdraws ETH from the basket.

RebalanceBTS(address indexed bts, uint256[] oldWeights, uint256[] newWeights)

Emitted when the owner manually rebalances the basket.

BTSPair

This is an ERC20 token contract representing liquidity in a BTS. It is used to manage assets in the fund and accurately reflect liquidity providers' shares.

initialize

Initializes a new BTSPair, setting the fund name and initial token configuration.

rebalance

Allows the fund owner to manually adjust the token types and weights within the pair.

updateTokens

Changes the types of tokens in the pair by adding new tokens or removing existing ones.

mint

Creates new BTS LP tokens and adjusts token reserves.

burn

Uses burn on BTS LP tokens to allow liquidity providers to withdraw assets from the fund.

Citation

Dominic Ryder dom@alvaraprotocol.io, Callum Mitchell-Clark (@AlvaraProtocol) callum@alvaraprotocol.io, Joey van Etten joe@alvaraprotocol.io, Michael Ryder mike@alvaraprotocol.io, "ERC-7621: Basket Token [DRAFT]," Ethereum Improvement Proposals, no. 7621, February 2024. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-7621.

Closing Remarks

This article covered ERC7621, a proposal for collateralized tokenized funds with adjustable weights and reserves, LP token issuance, and a mechanism to burn LP tokens. I hope it was helpful.

If you have any questions, feel free to reach out via Twitter DM.

Twitter @cardene777

I also publish on other platforms, which you can explore below.

https://chaldene.net/