Skip to content

Commit

Permalink
feat: Add mint function
Browse files Browse the repository at this point in the history
  • Loading branch information
PacificYield committed Oct 29, 2024
1 parent b095982 commit 290517d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
11 changes: 11 additions & 0 deletions contracts/token/ERC20/EncryptedERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ abstract contract EncryptedERC20 is IEncryptedERC20 {
TFHE.allow(amount, spender);
}

/**
* @dev It does not incorporate any overflow check. It must be implemented
* by the function calling it.
*/
function _unsafeMint(address account, euint64 amount) internal virtual {
_balances[msg.sender] = TFHE.add(_balances[account], amount);
TFHE.allowThis(_balances[account]);
TFHE.allow(_balances[account], account);
emit Transfer(address(0), account);
}

function _transfer(address from, address to, euint64 amount, ebool isTransferable) internal virtual {
// Add to the balance of `to` and subract from the balance of `from`.
euint64 transferValue = TFHE.select(isTransferable, amount, TFHE.asEuint64(0));
Expand Down
4 changes: 1 addition & 3 deletions contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 {
* @param amount Amount of tokens to mint.
*/
function mint(uint64 amount) public onlyOwner {
_balances[msg.sender] = TFHE.add(_balances[msg.sender], amount);
TFHE.allow(_balances[msg.sender], address(this));
TFHE.allow(_balances[msg.sender], msg.sender);
_unsafeMint(msg.sender, TFHE.asEuint64(amount));
/// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender],
/// the next line contains an overflow check for the encrypted operation above.
_totalSupply = _totalSupply + amount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ contract EncryptedERC20WithErrorsMintable is Ownable2Step, EncryptedERC20WithErr
* @param amount Amount of tokens to mint.
*/
function mint(uint64 amount) public onlyOwner {
_balances[msg.sender] = TFHE.add(_balances[msg.sender], amount);
TFHE.allow(_balances[msg.sender], address(this));
TFHE.allow(_balances[msg.sender], msg.sender);
_unsafeMint(msg.sender, TFHE.asEuint64(amount));
/// @dev Since _totalSupply is not encrypted and _totalSupply >= balances[msg.sender],
/// the next line contains an overflow check for the encrypted operation above.
_totalSupply = _totalSupply + amount;
Expand Down

0 comments on commit 290517d

Please sign in to comment.