Welcome
Search…
ERC-1155 Controller

Polygon Contract Address

Source Code

Overview

The ERC1155Controller implements all of the functionality needed to mint, burn, approve, and transfer the ERC1155 option tokens (e.g. bTokens and wTokens). It inherits from the Open Zeppelin ERC1155PresetMinterPauser contract, which implements functions for minting, burning, approving, and transferring tokens, either as a single token or multiple tokens as a batch.
Any contract wishing to transfer SIREN option tokens will need the ERC1155Controller contract address.
We chose to use the ERC1155 interface instead of the more popular ERC20 standard because it provides us a more gas efficient way to create option series. Rather than deploy a new ERC20 contract with every new Series we create, we add an additional id to the same ERC1155 contract. It also standardizes the ERC1155.setApprovalForAll, which allows an owner address to make only a single onchain transaction in order to approve an operator account to transfer any/all of the option tokens, which is more gas efficient than an onchain transaction for each option token.

Functions

Modifiers

onlySeriesController

1
modifier onlySeriesController() {
2
require(
3
msg.sender == controller,
4
"ERC1155Controller: Sender must be the seriesController"
5
);
6
7
_;
8
}
Copied!
Certain functions can only be called by the associated SeriesController contract, such as the mint and burn functions. This is to ensure that no arbitrary address can inflate or deflate the supply of option tokens.

onlyOwner

1
modifier onlyOwner() {
2
require(
3
hasRole(DEFAULT_ADMIN_ROLE, msg.sender),
4
"ERC1155Controller: Caller is not the owner"
5
);
6
7
_;
8
}
Copied!
Certain functions can only be called by the SIREN protocol owner multisig address. The functions updateImplementation and transferOwnership exist so that the owners can update the contracts in the event of a critical vulnerability that puts user's funds at risk.

View/Pure Functions

uri

1
function uri(
2
uint256 _id
3
) public view override returns (string memory)
Copied!
This implementation returns the same URI for all token types. It relies on the token type ID substitution mechanism https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. Clients calling this function must replace the \{id\} substring with the actual token type ID.
Parameters
Name
Type
Description
_id
uint256
The ID of the ERC1155 token

balanceOf

1
function balanceOf(
2
address account,
3
uint256 id
4
) public view override returns (uint256)
Copied!
Returns the account's balance on the ERC1155 token id. In the ERC1155 standard, a single contract tracks multiple tokens using different ID's. This is similar to the ERC20 standard's balanceOf function, but the caller must also specify the ERC1155 token id.
Parameters
Name
Type
Description
account
address
The address of the user who's ERC1155 balance you wish to fetch
id
uint256
The ERC1155 token id

balanceOfBatch

1
function balanceOfBatch(
2
address[] memory accounts,
3
uint256[] memory ids
4
) public view override returns (uint256[] memory)
Copied!
Returns the balances of multiple accounts for multiple ERC1155 token ids. This is a more gas-efficient way to fetch multiple balances, compared to multiple calls to balanceOf. The length of the accounts array must equal the length of the ids array.
Parameters
Name
Type
Description
accounts
address[] memory
The addresses of the users who's ERC1155 balances you wish to fetch
ids
uint256[] memory
The ERC1155 token ids

isApprovedForAll

1
function isApprovedForAll(
2
address account,
3
address operator
4
) public view override returns (bool)
Copied!
Returns true if the account has approved operator to transfer all of account's bTokens and wTokens on its behalf, and false if the operator is not approved to transfer any of account's ERC1155 tokens. The ERC1155 standard does not expose a function for approving individual ERC1155 token ids, but does expose setApprovalForAll for approving the transfer of all account's ERC1155 tokens.
Parameters
Name
Type
Description
account
address
The address which owns the tokens and has approved the operator
operator
address
The address which has been delegated controll of account's funds

Mutating Functions

setApprovalForAll

1
function setApprovalForAll(
2
address operator,
3
bool approved
4
) public override
Copied!
If approved is true, allows the operator to transfer all of the caller's bTokens and wTokens on the caller's behalf. If false, the operator can no longer transfer tokens. This is similar to the ERC20's approve function, except in the ERC1155 standard you only need to call the approval function once and forever after the operator can transfer any amount of tokens. However, this is more dangerous than single token approvals, because the operator has control over all of the caller's balance of ERC1155 tokens.
Parameters
Name
Type
Description
account
address
The address which owns the tokens and is approving/disapproving the operator to be able to transfer tokens
approved
bool
true if the account is allowing the operator to transfer the account's tokens, and false if the operator is already approved and account no longer wants operator to be approved to transfer its tokens

safeTransferFrom

1
function safeTransferFrom(
2
address from,
3
address to,
4
uint256 id,
5
uint256 amount,
6
bytes memory data
7
) public override
Copied!
Transfers amount tokens of token type id from from to to. to cannot be the zero address, and if the caller is not from then prior to calling this function the from address must have called setApprovalForAll with the caller as the operator argument, or else this call will fail. If to refers to a smart contract, it must implement 'onERC1155Received'.
Parameters
Name
Type
Description
from
address
The address from which ERC1155 tokens will be transferred out of
to
address
The address into which the ERC1155 tokens will be transferred into
id
uint256
The identifier of the option token. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amount
uint256
The amount of option token to transfer, in base units. The decimals will always be the same as the Series' underlying token'
data
bytes memory
Arbitrary data to be used by the individual ERC1155 token. For the SIREN protocol this can always unused, so it can be an empty array

safeTransferFromBatch

1
function safeTransferFrom(
2
address from,
3
address to,
4
uint256[] memory ids,
5
uint256[] memory amounts,
6
bytes memory data
7
) public override
Copied!
Similar to safeTransferFrom, but more gas efficient when multiple transactions for different amounts of different token ids must be sent to the same to address. Use this function rather than safeTransferFrom when the caller wants to save gas while sending multiple tokens to the same recipient address.
Parameters
Name
Type
Description
from
address
The address from which ERC1155 tokens will be transferred out of
to
address
The address into which the ERC1155 tokens will be transferred into
ids
uint256[] memory
The identifiers of the option token. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amounts
uint256[] memory
The amounts of option token to transfer, in base units. The decimals will always be the same as the Series' underlying token'
data
bytes memory
Arbitrary data to be used by the individual ERC1155 token. For the SIREN protocol this can always unused, so it can be an empty array

mint

1
function mint(
2
address to,
3
uint256 id,
4
uint256 amount,
5
bytes memory data
6
) override(ERC1155PresetMinterPauserUpgradeable, IERC1155Controller)
7
onlySeriesController
Copied!
Creates amount tokens of token type id and sends them to address to. to cannot be the zero address, and if to refers to a smart contract, it must implement 'onERC1155Received'.
Parameters
Name
Type
Description
to
address
The address into which the newly minted ERC1155 tokens will be transferred into
id
uint256
The identifier of the option token. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amount
uint256
The amount of option token to mint, in base units. The decimals will always be the same as the Series' underlying token'
data
bytes memory
Arbitrary data to be used by the individual ERC1155 token. For the SIREN protocol this can always unused, so it can be an empty array

mintBatch

1
function mintBatch(
2
address to,
3
uint256[] memory ids,
4
uint256[] memory amounts,
5
bytes memory data
6
)
7
public
8
override(ERC1155PresetMinterPauserUpgradeable, IERC1155Controller)
9
onlySeriesController
Copied!
Similar to mint, but more gas efficient when multiple transactions for different amounts of different token ids must be minted to the same to address. Use this function rather than mint when the caller wants to save gas while minting multiple tokens to the same recipient address.
Parameters
Name
Type
Description
to
address
The address into which the newly minted ERC1155 tokens will be transferred into
ids
uint256[] memory
The identifiers of the option tokens. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amounts
uint256[] memory
The amounts of option tokens to mint, in base units. The decimals will always be the same as the Series' underlying token'
data
bytes memory
Arbitrary data to be used by the individual ERC1155 token. For the SIREN protocol this can always unused, so it can be an empty array

burn

1
function burn(
2
address account,
3
uint256 id,
4
uint256 amount
5
)
6
public
7
override(ERC1155BurnableUpgradeable, IERC1155Controller)
8
onlySeriesController
Copied!
Destroys amount tokens of token type id owned by the address account. account cannot be the zero address, and account must have at least amount of the tokens for this call to succeed. If the caller is not account, then account must have approved the caller using setApprovalForAll prior to calling burn.
Parameters
Name
Type
Description
to
account
The address which will have the option tokens removed from it
id
uint256
The identifier of the option token. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amount
uint256
The amount of option token to burn, in base units. The decimals will always be the same as the Series' underlying token'

burnBatch

1
function burnBatch(
2
address account,
3
uint256[] memory ids,
4
uint256[] memory amounts
5
)
6
public
7
override(ERC1155BurnableUpgradeable, IERC1155Controller)
8
onlySeriesController
Copied!
Similar to burn, but more gas efficient when multiple transactions for different amounts of different token ids must be removed from the same account address. Use this function rather than burn when the caller wants to save gas while burning multiple tokens from the same address.
Parameters
Name
Type
Description
to
account
The address which will have the option tokens removed from it
ids
uint256[] memory
The identifiers of the option token. Can be obtained by either SeriesController.bTokenIndex(_seriesId) or SeriesController.wTokenIndex(_seriesId)
amounts
uint256[] memory
The amounts of option token to burn, in base units. The decimals will always be the same as the Series' underlying token'

updateImplementation

1
function updateImplementation(
2
address _newImplementation
3
) external onlyOwner
Copied!
Updates this ERC1155Controller's logic contract. The SIREN protocol's contracts use the EIP-1822 standard for implementing upgradeable contracts. This allows us to update vulnerable contracts and keep users' option tokens safe. When the SIREN protocol has reached a certain level of stability, we can remove these safety guards and ensure no one on the Siren team can swap out the smart contract functionality.
Parameters
Name
Type
Description
_newImplementation
address
The address of the new logic contract to use for the ERC1155Controller's function implementations

transferOwnership

1
function transferOwnership(address _newAdmin) external onlyOwner
Copied!
Removes ownership from the current owner and assigns ownership to the _newAdmin address. See the onlyOwner modifier for the permissions granted to the protocol admin.
Parameters
Name
Type
Description
_newAdmin
address
The address of the new admin for this contract
Last modified 1mo ago