33pragma solidity ^ 0.8.20 ;
44
55import "@openzeppelin/contracts/token/ERC20/ERC20.sol " ;
6- import { IVioletID } from "@violetprotocol/violetid/contracts/IVioletID.sol " ;
7-
6+ import {IVioletID} from "@violetprotocol/violetid/contracts/IVioletID.sol " ;
87
98error AccountWithoutVioletIDRequiredStatus ();
109
@@ -14,21 +13,30 @@ error AccountWithoutVioletIDRequiredStatus();
1413 * Currently uses the VioletID status 1 representing enrollment, which includes initial screening and KYC/KYB.
1514 */
1615contract CompliantERC20 is ERC20 {
17- IERC20 permissionlessERC20;
18- uint256 public tokensWrapped;
19- IVioletID violetID;
20-
21- constructor (string memory name_ , string memory symbol_ , address violetID_ , address _nonCompliantERC20 ) ERC20 (name_, symbol_) {
22- violetID = IVioletID (violetID_);
23- permissionlessERC20 = IERC20 (_nonCompliantERC20);
24- }
25-
26- modifier onlyVioletIDHolders (address account ) {
27- uint8 isEnrolledStatus = 1 ;
28- require (violetID.hasStatus (account, isEnrolledStatus), "account does not have a VioletID " );
29- if (! violetID.hasStatus (account, isEnrolledStatus)) revert AccountWithoutVioletIDRequiredStatus ();
30- _;
31- }
16+ IERC20 permissionlessERC20;
17+ uint256 public tokensWrapped;
18+ IVioletID violetID;
19+
20+ constructor (
21+ string memory name_ ,
22+ string memory symbol_ ,
23+ address violetID_ ,
24+ address _nonCompliantERC20
25+ ) ERC20 (name_, symbol_) {
26+ violetID = IVioletID (violetID_);
27+ permissionlessERC20 = IERC20 (_nonCompliantERC20);
28+ }
29+
30+ modifier onlyVioletIDHolders (address account ) {
31+ uint8 isEnrolledStatus = 1 ;
32+ require (
33+ violetID.hasStatus (account, isEnrolledStatus),
34+ "account does not have a VioletID "
35+ );
36+ if (! violetID.hasStatus (account, isEnrolledStatus))
37+ revert AccountWithoutVioletIDRequiredStatus ();
38+ _;
39+ }
3240
3341 // All customizations to transfers, mints, and burns should be done by overriding this function.
3442 // https://docs.openzeppelin.com/contracts/5.x/api/token/erc20#ERC20-_transfer-address-address-uint256-
@@ -37,25 +45,27 @@ contract CompliantERC20 is ERC20 {
3745 address from ,
3846 address to ,
3947 uint256 amount
40- ) internal virtual override onlyVioletIDHolders (to){
48+ ) internal virtual override onlyVioletIDHolders (to) {
4149 super ._update (from, to, amount);
4250 }
4351
52+ function wrap (
53+ uint256 amount
54+ ) public virtual onlyVioletIDHolders (msg .sender ) {
55+ permissionlessERC20.transferFrom (msg .sender , address (this ), amount);
56+ tokensWrapped += amount;
57+ super ._mint (msg .sender , amount);
58+ }
4459
45- function wrap (
46- uint256 amount
47- ) public virtual onlyVioletIDHolders (msg .sender ) {
48- permissionlessERC20.transferFrom (msg .sender , address (this ), amount);
49- tokensWrapped += amount;
50- super ._mint (msg .sender , amount);
51- }
52-
53- function unwrap (
54- uint256 amount
55- ) public virtual onlyVioletIDHolders (msg .sender ) {
56- require (tokensWrapped >= amount, "cERC20_unwrap: amount to unwrap exceeds total wrapped " );
57- tokensWrapped -= amount;
58- _burn (msg .sender , amount);
59- permissionlessERC20.transfer (msg .sender , amount);
60- }
60+ function unwrap (
61+ uint256 amount
62+ ) public virtual onlyVioletIDHolders (msg .sender ) {
63+ require (
64+ tokensWrapped >= amount,
65+ "cERC20_unwrap: amount to unwrap exceeds total wrapped "
66+ );
67+ tokensWrapped -= amount;
68+ _burn (msg .sender , amount);
69+ permissionlessERC20.transfer (msg .sender , amount);
70+ }
6171}
0 commit comments