-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change rental product to access token
- Loading branch information
Showing
6 changed files
with
182 additions
and
217 deletions.
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,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import {IProduct} from "./interfaces/IProduct.sol"; | ||
|
||
contract AccessToken is ERC721 { | ||
IProduct public immutable PRODUCT; | ||
|
||
constructor( | ||
IProduct product, | ||
string memory name, | ||
string memory symbol | ||
) ERC721(name, symbol) { | ||
PRODUCT = product; | ||
} | ||
|
||
modifier onlyTokenOwner(uint256 tokenId) { | ||
require(msg.sender == PRODUCT.ownerOf(tokenId), "not token owner"); | ||
_; | ||
} | ||
|
||
function mint( | ||
address user, | ||
uint256 tokenId | ||
) external onlyTokenOwner(tokenId) { | ||
_mint(user, tokenId); | ||
} | ||
|
||
function burn(uint256 tokenId) external onlyTokenOwner(tokenId) { | ||
_burn(tokenId); | ||
} | ||
} |
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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.24; | ||
|
||
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol"; | ||
import {IProduct} from "./interfaces/IProduct.sol"; | ||
import {AccessToken} from "./AccessToken.sol"; | ||
|
||
contract AccessTokenFactory { | ||
mapping(address => address) public getAccessToken; | ||
|
||
function createAccessToken( | ||
address productAddress | ||
) external returns (address) { | ||
require( | ||
address(getAccessToken[productAddress]) == address(0), | ||
"existing access token" | ||
); | ||
|
||
AccessToken accessToken = new AccessToken( | ||
IProduct(productAddress), | ||
ERC721(productAddress).name(), | ||
ERC721(productAddress).symbol() | ||
); | ||
getAccessToken[productAddress] = address(accessToken); | ||
return address(accessToken); | ||
} | ||
} |
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
Oops, something went wrong.