Skip to content

Commit 8208b7f

Browse files
committed
token bundle documentation
1 parent a154071 commit 8208b7f

File tree

6 files changed

+31
-1114
lines changed

6 files changed

+31
-1114
lines changed

contracts/feature/TokenBundle.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ pragma solidity ^0.8.0;
44
import "./interface/ITokenBundle.sol";
55

66
abstract contract TokenBundle is ITokenBundle {
7+
/// @dev UID => asset count, bundle uri, and tokens contained in the bundle
78
mapping(uint256 => BundleInfo) private bundle;
89

9-
// function _getNextBundleId() internal virtual returns (uint256);
10-
10+
/// @dev Returns the count of assets in a bundle, given a bundle Id.
1111
function getTokenCount(uint256 _bundleId) public view returns (uint256) {
1212
return bundle[_bundleId].count;
1313
}
1414

15+
/// @dev Returns a token contained in a bundle, given a bundle Id and index of token.
1516
function getToken(uint256 _bundleId, uint256 index) public view returns (Token memory) {
1617
return bundle[_bundleId].tokens[index];
1718
}
1819

20+
/// @dev Returns the uri of bundle for a particular bundle Id.
1921
function getUri(uint256 _bundleId) public view returns (string memory) {
2022
return bundle[_bundleId].uri;
2123
}
2224

25+
/// @dev Lets the calling contract create/update a bundle, by passing in a list of tokens and a unique id.
2326
function _setBundle(Token[] calldata _tokensToBind, uint256 _bundleId) internal {
2427
// uint256 _bundleId = _getNextBundleId();
2528
require(_tokensToBind.length > 0, "no tokens to bind");
@@ -29,6 +32,7 @@ abstract contract TokenBundle is ITokenBundle {
2932
bundle[_bundleId].count = _tokensToBind.length;
3033
}
3134

35+
/// @dev Lets the calling contract set/update a token in a bundle for a unique bundle id and index.
3236
function _setBundleToken(
3337
Token memory _tokenToBind,
3438
uint256 _bundleId,
@@ -39,10 +43,12 @@ abstract contract TokenBundle is ITokenBundle {
3943
bundle[_bundleId].count += isUpdate ? 0 : 1;
4044
}
4145

46+
/// @dev Lets the calling contract set/update the bundle uri for a particular bundle id.
4247
function _setUri(string calldata _uri, uint256 _bundleId) internal {
4348
bundle[_bundleId].uri = _uri;
4449
}
4550

51+
/// @dev Lets the calling contract delete a bundle with a given id.
4652
function _deleteBundle(uint256 _bundleId) internal {
4753
delete bundle[_bundleId];
4854
}

contracts/feature/interface/ITokenBundle.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.0;
33

4+
/**
5+
* Group together arbitrary ERC20, ERC721 and ERC1155 tokens into a single bundle.
6+
*
7+
* This bundle of tokens is a generic list of tokens that can have multiple use cases,
8+
* such as mapping to an NFT, or put in an escrow, etc.
9+
*/
10+
411
interface ITokenBundle {
12+
/// @notice The type of assets that can be wrapped.
513
enum TokenType {
614
ERC20,
715
ERC721,
816
ERC1155
917
}
1018

19+
/**
20+
* @notice A generic interface to describe a token to be put in a bundle.
21+
*
22+
* @param assetContract The contract address of the asset to bind.
23+
* @param tokenType The token type (ERC20 / ERC721 / ERC1155) of the asset to bind.
24+
* @param tokenId The token Id of the asset to bind, if the asset is an ERC721 / ERC1155 NFT.
25+
* @param totalAmount The amount of the asset to bind, if the asset is an ERC20 / ERC1155 fungible token.
26+
*/
1127
struct Token {
1228
address assetContract;
1329
TokenType tokenType;
1430
uint256 tokenId;
1531
uint256 totalAmount;
1632
}
1733

34+
/**
35+
* @notice An internal data structure to track the contents of a bundle.
36+
*
37+
* @param count The total kinds of assets i.e. `Token` inside a bundle.
38+
* @param uri The (metadata) URI assigned to the bundle created
39+
* @param tokens Mapping from a UID -> to the asset i.e. `Token` at that UID.
40+
*/
1841
struct BundleInfo {
1942
uint256 count;
2043
string uri;

contracts/multiwrap/ITempMultiwrap.sol

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)