-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* doc changes * generation config change * changeset
- Loading branch information
Showing
46 changed files
with
4,325 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'rankify-contracts': minor | ||
--- | ||
|
||
changed documentation generation system to be more readable and per file separated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
|
||
# CompositeERC1155 | ||
## Description | ||
|
||
An abstract contract that extends LockableERC1155 and provides functionality for composite ERC1155 tokens. | ||
Composite tokens can be "composed" from multiple underlying assets, which however do not change their owner | ||
and in contrast to that use LockableERC1155 standard, which allows to read locked asset BalanceOf, OwnerOf methods correctly | ||
|
||
## Implementation | ||
|
||
### internal function constructor | ||
|
||
```solidity | ||
constructor(string uri_, address[] dimensionTokens, uint256[] tokenWeights) internal | ||
``` | ||
|
||
### internal function _mint | ||
|
||
```solidity | ||
function _mint(address to, uint256 tokenId, uint256 value, bytes data) internal virtual | ||
``` | ||
|
||
### internal function _burn | ||
|
||
```solidity | ||
function _burn(address from, uint256 id, uint256 amount) internal | ||
``` | ||
|
||
*Destroys `amount` tokens of token type `id` from `from` | ||
|
||
Emits a {TransferSingle} event. | ||
|
||
Requirements: | ||
|
||
- `from` cannot be the zero address. | ||
- `from` must have at least `amount` tokens of token type `id`.* | ||
### public function decompose | ||
|
||
```solidity | ||
function decompose(address from, uint256 id, uint256 amount) public virtual | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `from` | `address` | The address from which the composite token is being decomposed. | | ||
| `id` | `uint256` | The ID of the composite token being decomposed. | | ||
| `amount` | `uint256` | The amount of the composite token to decompose. | | ||
|
||
*Decomposes a composite ERC1155 token into its individual components. | ||
This function unlocks the specified amount of the composite token from each dimension, | ||
and then burns the specified amount of the composite token from the caller's balance.* | ||
### public function burn | ||
|
||
```solidity | ||
function burn(address account, uint256 id, uint256 value) public virtual | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `account` | `address` | The address of the token owner. | | ||
| `id` | `uint256` | The ID of the token to burn. | | ||
| `value` | `uint256` | The amount of tokens to burn. | | ||
|
||
*Burns a specified amount of tokens from the given account. | ||
This will burn all underlying (composite) assets | ||
|
||
Requirements: | ||
- `account` must be the token owner or an approved operator. | ||
- `id` and `value` must be valid token ID and amount to burn. | ||
- All underlying "composite" assets implement burn as well* | ||
### public function getComponents | ||
|
||
```solidity | ||
function getComponents() public virtual returns (address[], uint256[]) | ||
``` | ||
|
||
| Output | Type | Description | | ||
| ------ | ---- | ----------- | | ||
| `0` | `address[]` | An array of component addresses and an array of component weights. | | ||
| `1` | `uint256[]` | | | ||
|
||
*Retrieves the components of the CompositeERC1155 contract.* | ||
<!--CONTRACT_END--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# | ||
## Description | ||
|
||
## Implementation | ||
|
||
### internal modifier nonReentrant | ||
|
||
```solidity | ||
modifier nonReentrant() | ||
``` | ||
|
||
<!--CONTRACT_END--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
# | ||
## Description | ||
|
||
## Implementation | ||
|
||
<!--CONTRACT_END--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
|
||
# | ||
### error insufficient | ||
|
||
```solidity | ||
error insufficient(uint256 id, uint256 balance, uint256 required) | ||
``` | ||
|
||
# LockableERC1155 | ||
## Description | ||
|
||
This is an abstract contract that extends the ERC1155 token contract and implements the ILockableERC1155 interface. | ||
It provides functionality to lock and unlock token amounts for specific accounts and IDs. | ||
|
||
## Implementation | ||
|
||
### internal variable lockedAmounts | ||
|
||
```solidity | ||
mapping(address => mapping(uint256 => uint256)) lockedAmounts | ||
``` | ||
|
||
### public function lock | ||
|
||
```solidity | ||
function lock(address account, uint256 id, uint256 amount) public virtual | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `account` | `address` | The address of the account to lock tokens for. | | ||
| `id` | `uint256` | The ID of the token to lock. | | ||
| `amount` | `uint256` | The amount of tokens to lock. | | ||
|
||
*Locks a specified amount of tokens for a given account and token ID. | ||
If the account does not have enough balance to lock the specified amount, | ||
the function will revert with an "insufficient" error message. | ||
Emits a `TokensLocked` event after successfully locking the tokens.* | ||
### public function unlock | ||
|
||
```solidity | ||
function unlock(address account, uint256 id, uint256 amount) public virtual | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `account` | `address` | The address of the account to unlock tokens for. | | ||
| `id` | `uint256` | The ID of the token to unlock. | | ||
| `amount` | `uint256` | The amount of tokens to unlock. | | ||
|
||
*Unlocks a specified amount of tokens for a given account and token ID. | ||
If the locked amount is less than the specified amount, it reverts with an "insufficient" error message. | ||
Emits a `TokensUnlocked` event after unlocking the tokens.* | ||
### public function unlockedBalanceOf | ||
|
||
```solidity | ||
function unlockedBalanceOf(address account, uint256 id) public view returns (uint256) | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `account` | `address` | The address of the account. | | ||
| `id` | `uint256` | The ID of the ERC1155 token. | | ||
| **Output** | | | ||
| `0` | `uint256` | The unlocked balance of the ERC1155 token for the account. | | ||
|
||
*Returns the unlocked balance of a specific ERC1155 token for an account. | ||
The unlocked balance is calculated by subtracting the locked amount from the total balance.* | ||
### internal function _beforeTokenTransfer | ||
|
||
```solidity | ||
function _beforeTokenTransfer(address operator, address from, address to, uint256[] ids, uint256[] amounts, bytes data) internal virtual | ||
``` | ||
|
||
| Input | Type | Description | | ||
|:----- | ---- | ----------- | | ||
| `operator` | `address` | The address performing the token transfer. | | ||
| `from` | `address` | The address from which the tokens are being transferred. | | ||
| `to` | `address` | The address to which the tokens are being transferred. | | ||
| `ids` | `uint256[]` | An array of token IDs being transferred. | | ||
| `amounts` | `uint256[]` | An array of token amounts being transferred. | | ||
| `data` | `bytes` | Additional data attached to the transfer. | | ||
|
||
*Hook function that is called before any token transfer. | ||
It checks if the transfer is allowed based on the locked amounts of the tokens. | ||
If the transfer is not allowed, it reverts with an error message.* | ||
<!--CONTRACT_END--> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
|
||
# | ||
## Description | ||
|
||
https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. | ||
|
||
The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, | ||
thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding | ||
they need in their contracts using a combination of `abi.encode` and `keccak256`. | ||
|
||
This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding | ||
scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA | ||
({_hashTypedDataV4}). | ||
|
||
The implementation of the domain separator was designed to be as efficient as possible while still properly updating | ||
the chain id to protect against replay attacks on an eventual fork of the chain. | ||
|
||
NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method | ||
https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. | ||
|
||
_Available since v3.4._ | ||
|
||
## Implementation | ||
|
||
### internal function constructor | ||
|
||
```solidity | ||
constructor() internal | ||
``` | ||
|
||
*Initializes the domain separator and parameter caches. | ||
|
||
The meaning of `name` and `version` is specified in | ||
https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: | ||
|
||
- `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. | ||
- `version`: the current major version of the signing domain. | ||
|
||
NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart | ||
contract upgrade].* | ||
### internal function _domainSeparatorV4 | ||
|
||
```solidity | ||
function _domainSeparatorV4() internal view returns (bytes32) | ||
``` | ||
|
||
*Returns the domain separator for the current chain.* | ||
### internal function _hashTypedDataV4 | ||
|
||
```solidity | ||
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) | ||
``` | ||
|
||
*Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this | ||
function returns the hash of the fully encoded EIP712 message for this domain. | ||
|
||
This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: | ||
|
||
```solidity | ||
bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( | ||
keccak256("Mail(address to,string contents)"), | ||
mailTo, | ||
keccak256(bytes(mailContents)) | ||
))); | ||
address signer = ECDSA.recover(digest, signature); | ||
```* | ||
<!--CONTRACT_END--> | ||
Oops, something went wrong.