Skip to main content

IDerivative

Git Source

Interface for Derivative functionality

Derivatives provide a mechanism to create synthetic assets that are backed by collateral, such as base tokens from an auction.

Functions

tokenMetadata

The metadata for a derivative token

function tokenMetadata(
uint256 tokenId
)
external
view
returns (
bool exists,
address wrapped,
address underlyingToken,
uint256 supply,
bytes memory data
);

Parameters

NameTypeDescription
tokenIduint256The ID of the derivative token

Returns

NameTypeDescription
existsboolTrue if the token has been deployed
wrappedaddressNon-zero if an ERC20-wrapped derivative has been deployed
underlyingTokenaddressThe address of the underlying token
supplyuint256The total supply of the derivative token
databytesImplementation-specific data

deploy

Deploy a new derivative token. Optionally, deploys an ERC20 wrapper for composability.

function deploy(
address underlyingToken_,
bytes memory params_,
bool wrapped_
) external returns (uint256 tokenId_, address wrappedAddress_);

Parameters

NameTypeDescription
underlyingToken_addressThe address of the underlying token
params_bytesABI-encoded parameters for the derivative to be created
wrapped_boolWhether (true) or not (false) the derivative should be wrapped in an ERC20 token for composability

Returns

NameTypeDescription
tokenId_uint256The ID of the newly created derivative token
wrappedAddress_addressThe address of the ERC20 wrapped derivative token, if wrapped_ is true, otherwise, it's the zero address.

mint

Mint new derivative tokens.

Deploys the derivative token if it does not already exist.

The module is expected to transfer the collateral token to itself.

function mint(
address to_,
address underlyingToken_,
bytes memory params_,
uint256 amount_,
bool wrapped_
) external returns (uint256 tokenId_, address wrappedAddress_, uint256 amountCreated_);

Parameters

NameTypeDescription
to_addressThe address to mint the derivative tokens to
underlyingToken_addressThe address of the underlying token
params_bytesABI-encoded parameters for the derivative to be created
amount_uint256The amount of derivative tokens to create
wrapped_boolWhether (true) or not (false) the derivative should be wrapped in an ERC20 token for composability

Returns

NameTypeDescription
tokenId_uint256The ID of the newly created derivative token
wrappedAddress_addressThe address of the ERC20 wrapped derivative token, if wrapped_ is true, otherwise, it's the zero address.
amountCreated_uint256The amount of derivative tokens created

mint

Mint new derivative tokens for a specific token ID

function mint(
address to_,
uint256 tokenId_,
uint256 amount_,
bool wrapped_
) external returns (uint256, address, uint256);

Parameters

NameTypeDescription
to_addressThe address to mint the derivative tokens to
tokenId_uint256The ID of the derivative token
amount_uint256The amount of derivative tokens to create
wrapped_boolWhether (true) or not (false) the derivative should be wrapped in an ERC20 token for composability

Returns

NameTypeDescription
<none>uint256tokenId_ The ID of the derivative token
<none>addresswrappedAddress* The address of the ERC20 wrapped derivative token, if wrapped* is true, otherwise, it's the zero address.
<none>uint256amountCreated_ The amount of derivative tokens created

redeemMax

Redeem all available derivative tokens for underlying collateral

function redeemMax(uint256 tokenId_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to redeem

redeem

Redeem derivative tokens for underlying collateral

function redeem(uint256 tokenId_, uint256 amount_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to redeem
amount_uint256The amount of derivative tokens to redeem

redeemable

Determines the amount of redeemable tokens for a given derivative token

function redeemable(address owner_, uint256 tokenId_) external view returns (uint256 amount);

Parameters

NameTypeDescription
owner_addressThe owner of the derivative token
tokenId_uint256The ID of the derivative token

Returns

NameTypeDescription
amountuint256The amount of redeemable tokens

exercise

Exercise a conversion of the derivative token per the specific implementation logic

Used for options or other derivatives with convertible options, e.g. Rage vesting.

function exercise(uint256 tokenId_, uint256 amount) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to exercise
amountuint256The amount of derivative tokens to exercise

exerciseCost

Determines the cost to exercise a derivative token in the quoted token

Used for options or other derivatives with convertible options, e.g. Rage vesting.

function exerciseCost(uint256 tokenId_, uint256 amount) external view returns (uint256 cost);

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to exercise
amountuint256The amount of derivative tokens to exercise

Returns

NameTypeDescription
costuint256The cost to exercise the derivative token

reclaim

Reclaim posted collateral for a derivative token which can no longer be exercised

Access controlled: only callable by the derivative issuer via the auction house.

function reclaim(uint256 tokenId_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to reclaim

transform

Transforms an existing derivative issued by this contract into something else. Derivative is burned and collateral sent to the auction house.

Access controlled: only callable by the auction house.

function transform(uint256 tokenId_, address from_, uint256 amount_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to transform
from_addressThe address of the owner of the derivative token
amount_uint256The amount of derivative tokens to transform

wrap

Wrap an existing derivative into an ERC20 token for composability Deploys the ERC20 wrapper if it does not already exist

function wrap(uint256 tokenId_, uint256 amount_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to wrap
amount_uint256The amount of derivative tokens to wrap

unwrap

Unwrap an ERC20 derivative token into the underlying ERC6909 derivative

function unwrap(uint256 tokenId_, uint256 amount_) external;

Parameters

NameTypeDescription
tokenId_uint256The ID of the derivative token to unwrap
amount_uint256The amount of derivative tokens to unwrap

validate

Validate derivative params for the specific implementation The parameters should be the same as what is passed into deploy() or mint()

function validate(
address underlyingToken_,
bytes memory params_
) external view returns (bool isValid);

Parameters

NameTypeDescription
underlyingToken_addressThe address of the underlying token
params_bytesThe params to validate

Returns

NameTypeDescription
isValidboolWhether or not the params are valid

computeId

Compute a unique token ID, given the parameters for the derivative

function computeId(
address underlyingToken_,
bytes memory params_
) external pure returns (uint256 tokenId);

Parameters

NameTypeDescription
underlyingToken_addressThe address of the underlying token
params_bytesThe parameters for the derivative

Returns

NameTypeDescription
tokenIduint256The unique token ID

getTokenMetadata

Get the metadata for a derivative token

function getTokenMetadata(uint256 tokenId) external view returns (Token memory tokenData);

Parameters

NameTypeDescription
tokenIduint256The ID of the derivative token

Returns

NameTypeDescription
tokenDataTokenThe metadata for the derivative token

Errors

Derivative_NotImplemented

error Derivative_NotImplemented();

Structs

Token

Metadata for a derivative token

struct Token {
bool exists;
address wrapped;
address underlyingToken;
uint256 supply;
bytes data;
}

Properties

NameTypeDescription
existsboolTrue if the token has been deployed
wrappedaddressNon-zero if an ERC20-wrapped derivative has been deployed
underlyingTokenaddressThe address of the underlying token
supplyuint256The total supply of the derivative token
databytesImplementation-specific data