Developer Docs
AppGitHub
  • Welcome!
  • Smart contracts
    • Core
      • Introduction
      • Deep Dive
      • Smart Contract Reference
        • PWN Hub
          • Tags
        • PWN Config
        • PWN Vault
        • Loan Types
          • Simple Loan
        • Proposals
          • Simple Loan Proposal
            • Simple Proposal
            • List Proposal
            • Elastic Proposal
            • Elastic Chainlink Proposal
            • Dutch Proposal
        • PWN Utilized Credit
        • PWN LOAN
        • PWN Revoked Nonce
        • Peripheral Contracts
          • Acceptor Controller
            • World ID
          • State Fingerprint Computer
            • UniV3
            • Chicken Bonds
          • Pool Adapter
            • Aave
            • Compound
            • ERC4626
        • Miscellaneous
          • PWN Fee Calculator
          • PWN Signature Checker
          • PWN Errors
          • PWN Periphery
          • Timelock
    • PWN DAO
      • Governance
        • Optimistic
        • Token
      • Tokens
        • PWN
        • stPWN
        • vePWN
          • Stake
          • Power
          • Metadata
      • Epoch Clock
      • Miscellaneous
        • Errors
        • EpochPowerLib
    • Tools
      • PWN Safe
        • Architecture
        • Security considerations
        • Smart Contract Reference
          • PWN Safe Factory
          • ATR Module
            • Tokenized Asset Manager
            • Recipient Permission Manager
          • Whitelist
          • ATR Guard
            • Operators context
      • Token Bundler
      • PWN Deployer
    • Libraries
      • MultiToken
    • Contract Addresses
  • More documentation
    • PWN Docs
    • FAQ
    • Audits
    • Using PWN without front-end
  • Deprecated
    • PWN Beta
      • Architecture
      • PWN
        • Off-chain signed offer
        • Offer types
      • PWN Vault
      • PWN LOAN
Powered by GitBook
On this page
  • 1. Summary
  • 2. Important links
  • 3. Contract Details
  • Features
  • Inherited Contracts
  • Functions
  • View functions
  • Events
Edit on GitHub
  1. Smart contracts
  2. Tools

Token Bundler

PreviousOperators contextNextPWN Deployer

Last updated 11 months ago

1. Summary

The contract enables bundling ERC20, ERC721, and/or ERC1155 tokens into a single ERC1155 token (the Bundle token).

2. Important links

3. Contract Details

  • TokenBundler.sol contract is written in Solidity version 0.8.16

Features

The owner of the bundle token has rights to:

  • Transferring ownership of the bundle token to another address

  • Unwrap the entire bundle resulting in burning the bundle token and gaining ownership over the wrapped tokens

Inherited Contracts

Token Bundler inherits other contracts and implements certain interfaces. Please see their reference for a complete overview.

Functions

create

Overview

This function mints a bundle token and transfers assets to the Bundler contract.

Make sure to approve all bundled assets towards the Token Bundler contract before calling this function.

This function takes one argument:

  • MultiToken.Asset[] memory_assets - List of assets to include in a bundle

The function returns the ID of the created bundle.

Implementation

function create(MultiToken.Asset[] memory _assets) override external returns (uint256 bundleId) {
    uint256 length = _assets.length;
    require(length > 0, "Need to bundle at least one asset");
    require(length <= type(uint256).max - _nonce, "Bundler out of capacity");

    bundleId = ++_id;
    uint256 _bundleNonce = _nonce;
    unchecked { _nonce += length; }

    for (uint i; i < length;) {
        unchecked { ++_bundleNonce; }

        _tokens[_bundleNonce] = _assets[i];
        _bundles[bundleId].push(_bundleNonce);

        _assets[i].transferAssetFrom(msg.sender, address(this));

        unchecked { ++i; }
    }

    _mint(msg.sender, bundleId, 1, "");

    emit BundleCreated(bundleId, msg.sender);
}
unwrap

Overview

This function burns the bundle token and transfers assets to the caller.

The caller has to be the bundle owner.

This function takes one argument:

  • uint256_bundleId - Bundle id to unwrap

Implementation

function unwrap(uint256 _bundleId) override external {
    require(balanceOf(msg.sender, _bundleId) == 1, "Sender is not bundle owner");

    uint256[] memory tokenList = _bundles[_bundleId];

    uint256 length = tokenList.length;
    for (uint i; i < length;) {
        _tokens[tokenList[i]].transferAsset(msg.sender);
        delete _tokens[tokenList[i]];

        unchecked { ++i; }
    }

    delete _bundles[_bundleId];

    _burn(msg.sender, _bundleId, 1);

    emit BundleUnwrapped(_bundleId);
}

View functions

token

Overview

This function takes one argument:

  • uint265 _tokenId - Token nonce from the bundle asset list.

Implementation

function token(uint256 _tokenId) override external view returns (MultiToken.Asset memory) {
    return _tokens[_tokenId];
}
bundle

Overview

Returns an array of asset IDs in a bundle as a uint256[].

This function takes one argument:

  • uint256_bundleId - Bundle id

Implementation

function bundle(uint256 _bundleId) override external view returns (uint256[] memory) {
    return _bundles[_bundleId];
}
tokensInBundle

Overview

This function takes one argument:

  • uint256_bundleId - Bundle id

Implementation

function tokensInBundle(uint256 _bundleId) override external view returns (MultiToken.Asset[] memory) {
    uint256[] memory tokenList = _bundles[_bundleId];
    uint256 length = tokenList.length;

    MultiToken.Asset[] memory tokens = new MultiToken.Asset[](length);

    for (uint256 i; i < length;) {
        tokens[i] = _tokens[tokenList[i]];

        unchecked { ++i; }
    }

    return tokens;
}

Events

event BundleCreated(uint256 indexed id, address indexed creator);
event BundleUnwrapped(uint256 indexed id);
BundleCreated

BundleCreated event is emitted when a new bundle is created.

This event has two parameters:

  • uint256 indexedid - Id of the bundle

  • address indexedcreator - Address of the bundle creator

BundleUnwrapped

BundleUnwrapped event is emitted when a bundle is unwrapped and burned.

This event has one parameter:

  • uint256 indexedid - Id of the unwrapped bundle.

See for more information about the argument type.

Each token has its nonce. This function returns an Asset struct (see ) for a provided token nonce.

Returns an array of assets in a bundle. Each asset is represented as an Asset struct (see ).

The Token Bundler contract doesn't define any events or custom errors and inherits events from , , and . We will cover events inherited from the interface. Please see the reference for and for a complete overview.

Ownable
ERC1155
IERC1155Receiver
IERC721Receiver
ITokenBundler
MultiToken
ITokenBundler
ERC1155
Ownable
ITokenBunder
ERC1155
Ownable
GitHub - PWNFinance/TokenBundlerGitHub
GitHub
17KB
TokenBundler.json
JSON ABI
Logo
MultiToken
MultiToken