@@ -5,24 +5,28 @@ pragma solidity ^0.8.20;
55import "@openzeppelin/contracts/token/ERC20/ERC20.sol " ;
66import { IVioletID } from "@violetprotocol/violetid/contracts/IVioletID.sol " ;
77
8+
9+ error AccountWithoutVioletIDRequiredStatus ();
10+
811/**
912 * @dev ERC20 token contract that only allows wrapping and unwraping to valid VioletID holders
1013 *
1114 * Currently uses the VioletID status 1 representing enrollment, which includes initial screening and KYC/KYB.
1215 */
1316contract CompliantERC20 is ERC20 {
14- address nonCompliantERC20 ;
17+ IERC20 permissionlessERC20 ;
1518 uint256 public tokensWrapped;
16- IVioletID violetID;
19+ IVioletID violetID;
1720
1821 constructor (string memory name_ , string memory symbol_ , address violetID_ , address _nonCompliantERC20 ) ERC20 (name_, symbol_) {
1922 violetID = IVioletID (violetID_);
20- nonCompliantERC20 = _nonCompliantERC20;
23+ permissionlessERC20 = IERC20 ( _nonCompliantERC20) ;
2124 }
2225
2326 modifier onlyVioletIDHolders (address account ) {
2427 uint8 isEnrolledStatus = 1 ;
2528 require (violetID.hasStatus (account, isEnrolledStatus), "account does not have a VioletID " );
29+ if (! violetID.hasStatus (account, isEnrolledStatus)) revert AccountWithoutVioletIDRequiredStatus ();
2630 _;
2731 }
2832
@@ -41,7 +45,7 @@ contract CompliantERC20 is ERC20 {
4145 function wrap (
4246 uint256 amount
4347 ) public virtual onlyVioletIDHolders (msg .sender ) {
44- IERC20 (nonCompliantERC20) .transferFrom (msg .sender , address (this ), amount);
48+ permissionlessERC20 .transferFrom (msg .sender , address (this ), amount);
4549 tokensWrapped += amount;
4650 super ._mint (msg .sender , amount);
4751 }
@@ -50,9 +54,8 @@ contract CompliantERC20 is ERC20 {
5054 uint256 amount
5155 ) public virtual onlyVioletIDHolders (msg .sender ) {
5256 require (tokensWrapped >= amount, "cERC20_unwrap: amount to unwrap exceeds total wrapped " );
53- _burn (msg .sender , amount);
54-
55- IERC20 (nonCompliantERC20).transfer (msg .sender , amount);
5657 tokensWrapped -= amount;
58+ _burn (msg .sender , amount);
59+ permissionlessERC20.transfer (msg .sender , amount);
5760 }
5861}
0 commit comments