Skip to content

Commit fd9100f

Browse files
authored
Merge pull request #80 from Kiwari-Labs/develop/ERC7818B
refactor: reduce abstract level keep it minimal
2 parents 5dfd852 + 7d4d50c commit fd9100f

67 files changed

Lines changed: 1955 additions & 2677 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
uses: actions/setup-node@v4
5858
with:
5959
cache: "yarn"
60-
node-version: 18.x
60+
node-version: 22.x
6161
architecture: x64
6262
registry-url: https://registry.npmjs.org/
6363

README.md

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -16,56 +16,33 @@ Install via `yarn`
1616
yarn add --dev @kiwarilabs/contracts@stable
1717
```
1818

19-
## Usage
19+
## Example Usage
2020

2121
### ERC-7818
2222

23+
> [!IMPORTANT]
24+
> Some Layer 2 (L2) use precompiled contract or system contract for current block number instead of `block.number`.
25+
2326
```solidity
24-
// SPDX-License-Identifier: Apache-2.0
27+
// SPDX-License-Identifier: MIT
2528
pragma solidity ^0.8.0;
2629
27-
import {ERC20EXPBase} from "@kiwarilabs/contracts/tokens/ERC20/ERC20EXPBase.sol";
28-
import {ERC20BLSW} from "@kiwarilabs/contracts/tokens/ERC20/ERC20BLSW.sol";
30+
import {ERC7818} from "@kiwarilabs/contracts/tokens/ERC20/ERC20EXPBase.sol";
2931
30-
contract ExpirableERC20 is ERC20BLSW {
31-
constructor(
32+
contract MyToken is ERC7818 {
33+
constructor(
3234
string memory _name,
3335
string memory _symbol,
3436
uint40 blocksPerEpoch_,
3537
uint8 windowSize_
36-
) ERC20BLSW(_name, _symbol, block.number, blocksPerEpoch_, windowSize_, false) {}
37-
38-
function _epochType() internal pure virtual override(ERC20EXPBase, ERC20BLSW) returns (EPOCH_TYPE) {
39-
return super._epochType();
40-
}
41-
42-
function _getEpoch(uint256 pointer) internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint256) {
43-
return super._getEpoch(pointer);
44-
}
45-
46-
function _getWindowRage(
47-
uint256 pointer
48-
) internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint256 fromEpoch, uint256 toEpoch) {
49-
return super._getWindowRage(pointer);
50-
}
51-
52-
function _getWindowSize() internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint8) {
53-
return super._getWindowSize();
54-
}
38+
) ERC7818(_name, _symbol, block.number, blocksPerEpoch_, windowSize_, false) {}
5539
56-
function _getPointersInEpoch() internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint40) {
57-
return super._getPointersInEpoch();
40+
function epochType() internal pure virtual override returns (EPOCH_TYPE) {
41+
return EPOCH_TYPE.BLOCKS_BASED;
5842
}
5943
60-
function _getPointersInWindow() internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint40) {
61-
return super._getPointersInWindow();
62-
}
63-
64-
/// @notice In some Layer 2 (L2) use pre-compiled/system-contract to get block height instead of block.number.
65-
/// @dev Retrieve block.number as pointer in block-based lazy sliding window.
66-
/// @return uint256 return the current block height.
67-
function _pointerProvider() internal view virtual override(ERC20EXPBase, ERC20BLSW) returns (uint256) {
68-
return super._pointerProvider();
44+
function _pointerProvider() internal view virtual override returns (uint256) {
45+
return block.number;
6946
}
7047
}
7148
```
@@ -75,49 +52,55 @@ contract ExpirableERC20 is ERC20BLSW {
7552
#### Individual Expiration
7653

7754
``` Solidity
78-
// SPDX-License-Identifier: Apache-2.0
55+
// SPDX-License-Identifier: MIT
7956
pragma solidity ^0.8.0;
8057
81-
import {ERC7858BLSW} from "@kiwarilabs/contracts/tokens/ERC721/ERC7858BLSW.sol";
82-
import {ERC7858EXPBase} from "@kiwarilabs/contracts/tokens/ERC721/ERC7858EXPBase.sol";
58+
import {ERC7858} from "@kiwarilabs/contracts/tokens/ERC721/ERC7858.sol";
8359
84-
// Expirable ERC721 with individual expiration
85-
contract ExpirableERC721 is ERC7858BLSW {
60+
contract MyToken is ERC7858 {
61+
constructor (string memory name_, string memory symbol_) ERC7858(name_, symbol) {}
8662
87-
constructor (string memory name_, string memory symbol_) ERC7858BLSW(name_, symbol) {}
63+
function expiryType() public pure override returns (EXPIRY_TYPE) {
64+
return EXPIRY_TYPE.BLOCKS_BASED;
65+
}
8866
67+
function _pointerProvider() internal view virtual override returns (uint256) {
68+
return block.number;
69+
}
8970
}
9071
```
9172

9273
#### Epoch Expiration
9374

9475
``` Solidity
95-
// SPDX-License-Identifier: Apache-2.0
76+
// SPDX-License-Identifier: MIT
9677
pragma solidity ^0.8.0;
9778
98-
import {ERC7858EpochBLSW} from "@kiwarilabs/contracts/tokens/ERC721/extensions/ERC7858EpochBLSW.sol";
99-
import {ERC7858EXPEpochBase} from "@kiwarilabs/contracts/tokens/ERC721/extensions/ERC7858EXPEpochBase.sol";
79+
import {ERC7858Epoch} from "@kiwarilabs/contracts/tokens/ERC721/extensions/ERC7858Epoch.sol";
10080
101-
// Expirable ERC721 with epoch expiration
102-
contract ExpirableERC7858 is ERC7858EpochBLSW {
103-
81+
contract MyToken is ERC7858Epoch {
10482
constructor (
10583
string memory name_,
10684
string memory symbol_,
10785
uint256 initialBlockNumber_,
10886
uint40 blocksPerEpoch_,
109-
uint8 windowSize_,
110-
bool development_)
111-
ERC7858EpochBLSW(
87+
uint8 windowSize_)
88+
ERC7858Epoch(
11289
name_,
11390
symbol_,
11491
initialBlockNumber_,
11592
blocksPerEpoch_,
11693
windowSize_,
11794
development) {}
11895
119-
}
96+
function expiryType() public pure override returns (EXPIRY_TYPE) {
97+
return EXPIRY_TYPE.BLOCKS_BASED;
98+
}
12099
100+
function _pointerProvider() internal view virtual override returns (uint256) {
101+
return block.number;
102+
}
103+
}
121104
```
122105

123106
## Contribute

contracts/abstracts/AbstractBLSW.sol

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

contracts/abstracts/AbstractTLSW.sol

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

contracts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": false,
33
"name": "@kiwarilabs/contracts",
4-
"version": "1.0.2-rc2",
4+
"version": "2.0.0-rc1",
55
"license": "Apache-2.0",
66
"author": "kiwari-labs <kiwarilabs@protonmail.com> (https://github.com/Kiwari-Labs)",
77
"repository": {

contracts/tokens/ERC20/ERC20BLSW.sol

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

0 commit comments

Comments
 (0)