Skip to content

Commit 8cdf9b4

Browse files
committed
formatting
1 parent 0989d53 commit 8cdf9b4

3 files changed

Lines changed: 69 additions & 55 deletions

File tree

erc20-wrapper-registry/contracts/CompliantERC20.sol

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
pragma solidity ^0.8.20;
44

55
import "@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

98
error 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
*/
1615
contract 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
}

erc20-wrapper-registry/contracts/CompliantFactory.sol

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
pragma solidity ^0.8.20;
44

55
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6-
import { IVioletID } from "@violetprotocol/violetid/contracts/IVioletID.sol";
6+
import {IVioletID} from "@violetprotocol/violetid/contracts/IVioletID.sol";
77
import "./CompliantERC20.sol";
88

99
/**
@@ -12,21 +12,22 @@ import "./CompliantERC20.sol";
1212
* Saves the new wrapped token address on the erc20ToCompliantWrapped mapping
1313
*/
1414
contract CompliantFactory {
15+
mapping(address => address) public erc20ToCompliantWrapped;
1516

16-
mapping(address => address) public erc20ToCompliantWrapped;
17-
18-
function deployCompliantErc(address nonCompliantERC20, address violetId_) public payable {
19-
address compliantErc20 = address(
20-
new CompliantERC20
21-
{
22-
salt: keccak256(abi.encodePacked(nonCompliantERC20))
23-
}(
24-
string.concat("c", ERC20(nonCompliantERC20).name()),
25-
string.concat("c", ERC20(nonCompliantERC20).symbol()),
26-
violetId_,
27-
nonCompliantERC20
28-
)
29-
);
30-
erc20ToCompliantWrapped[nonCompliantERC20] = compliantErc20;
31-
}
17+
function deployCompliantErc(
18+
address nonCompliantERC20,
19+
address violetId_
20+
) public payable {
21+
address compliantErc20 = address(
22+
new CompliantERC20{
23+
salt: keccak256(abi.encodePacked(nonCompliantERC20))
24+
}(
25+
string.concat("c", ERC20(nonCompliantERC20).name()),
26+
string.concat("c", ERC20(nonCompliantERC20).symbol()),
27+
violetId_,
28+
nonCompliantERC20
29+
)
30+
);
31+
erc20ToCompliantWrapped[nonCompliantERC20] = compliantErc20;
32+
}
3233
}

erc20-wrapper-registry/contracts/MockERC20.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ pragma solidity ^0.8.14;
44
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
55

66
contract MockERC20 is ERC20 {
7-
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}
7+
constructor(
8+
string memory name_,
9+
string memory symbol_
10+
) ERC20(name_, symbol_) {}
811

9-
function mint(address account, uint256 amount) public virtual {
10-
_mint(account, amount);
11-
}
12+
function mint(address account, uint256 amount) public virtual {
13+
_mint(account, amount);
14+
}
1215
}

0 commit comments

Comments
 (0)