diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4fc9d25..798894d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,4 +27,4 @@ jobs: npm run fhevm:start &> fhevm.log & tail -f fhevm.log | sed '/Starting JSON WebSocket server/ q' npm run test - npm run fhevm:stop || true \ No newline at end of file + npm run fhevm:stop || true diff --git a/.github/workflows/testmock.yml b/.github/workflows/testmock.yml index fb553b4..7a69067 100644 --- a/.github/workflows/testmock.yml +++ b/.github/workflows/testmock.yml @@ -22,4 +22,4 @@ jobs: - name: "npm CI test" run: | # sometimes not created and is not tailed - npm run test:mock \ No newline at end of file + npm run test:mock diff --git a/contracts/DAO/Comp.sol b/contracts/DAO/Comp.sol index fef7afc..b376850 100644 --- a/contracts/DAO/Comp.sol +++ b/contracts/DAO/Comp.sol @@ -46,7 +46,7 @@ contract Comp is EncryptedERC20, Ownable2Step { * @notice Construct a new Comp token */ constructor() EncryptedERC20("Compound", "COMP") Ownable(msg.sender) { - _mint(1000000); + _mint(1000000, msg.sender); } /** diff --git a/contracts/token/ERC20/EncryptedERC20.sol b/contracts/token/ERC20/EncryptedERC20.sol index dd0b5cb..96c3bfa 100644 --- a/contracts/token/ERC20/EncryptedERC20.sol +++ b/contracts/token/ERC20/EncryptedERC20.sol @@ -57,10 +57,10 @@ abstract contract EncryptedERC20 is Reencrypt, EncryptedErrors { } // Increase sender's balance by the given `amount`. - function _mint(uint64 amount) internal virtual { - balances[msg.sender] = TFHE.add(balances[msg.sender], amount); // overflow impossible because of next line + function _mint(uint64 amount, address to) internal virtual { + balances[to] = TFHE.add(balances[to], amount); // overflow impossible because of next line _totalSupply = _totalSupply + amount; - emit Mint(msg.sender, amount); + emit Mint(to, amount); } // Transfers an encrypted amount from the message sender address to the `to` address. diff --git a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol index b0ea3ab..2afa0e5 100644 --- a/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol +++ b/contracts/token/ERC20/extensions/EncryptedERC20Mintable.sol @@ -13,7 +13,7 @@ contract EncryptedERC20Mintable is Ownable2Step, EncryptedERC20 { ) Ownable(owner) EncryptedERC20(name_, symbol_) {} // Increase owner's balance by the given `mintedAmount`. - function mint(uint64 mintedAmount) public virtual onlyOwner { - _mint(mintedAmount); + function mint(uint64 mintedAmount, address to) public virtual onlyOwner { + _mint(mintedAmount, to); } } diff --git a/package.json b/package.json index 16f4747..cec288e 100644 --- a/package.json +++ b/package.json @@ -66,14 +66,14 @@ "access": "public" }, "scripts": { - "clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && pnpm typechain", + "clean": "rimraf ./artifacts ./cache ./coverage ./types ./coverage.json && npm run typechain", "compile": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile", "deploy:contracts": "hardhat deploy", "docgen": "hardhat docgen", - "lint": "pnpm lint:sol && pnpm lint:ts && pnpm prettier:check", + "lint": "npm run lint:sol && npm run lint:ts && npm run prettier:check", "lint:sol": "solhint --max-warnings 10 \"contracts/**/*.sol\"", "lint:ts": "eslint --ignore-path ./.eslintignore --ext .js,.ts .", - "postinstall": "DOTENV_CONFIG_PATH=./.env.example pnpm typechain", + "postinstall": "DOTENV_CONFIG_PATH=./.env.example npm run typechain", "prettier:check": "prettier --check \"**/*.{js,json,md,sol,ts,yml}\"", "prettier:write": "prettier --write \"**/*.{js,json,md,sol,ts,yml}\"", "typechain": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat typechain", diff --git a/test/encryptedERC20/EncryptedERC20.ts b/test/encryptedERC20/EncryptedERC20.ts index b834ff1..84063ce 100644 --- a/test/encryptedERC20/EncryptedERC20.ts +++ b/test/encryptedERC20/EncryptedERC20.ts @@ -26,7 +26,7 @@ describe("EncryptedERC20", function () { }); it("should mint the contract", async function () { - const transaction = await this.erc20.mint(1000); + const transaction = await this.erc20.mint(1000, this.signers.alice.address); await transaction.wait(); // Call the method const token = this.instances.alice.getPublicKey(this.contractAddress) || { @@ -46,18 +46,20 @@ describe("EncryptedERC20", function () { it("non-owner should be unable to mint", async function () { if (network.name == "hardhat") { // mocked mode - await expect(this.erc20.connect(this.signers.bob).mint(1000)) + await expect(this.erc20.connect(this.signers.bob).mint(1000, this.signers.alice.address)) .to.be.revertedWithCustomError(this.erc20, "OwnableUnauthorizedAccount") .withArgs(this.signers.bob.address); } else { // fhevm-mode - const tx = await this.erc20.connect(this.signers.bob).mint(1000, { gasLimit: 1_000_000n }); + const tx = await this.erc20 + .connect(this.signers.bob) + .mint(1000, this.signers.alice.address, { gasLimit: 1_000_000n }); await expect(tx.wait()).to.throw; } }); it("should transfer tokens between two users", async function () { - const transaction = await this.erc20.mint(10000); + const transaction = await this.erc20.mint(10000, this.signers.alice.address); await transaction.wait(); const encryptedTransferAmount = this.instances.alice.encrypt64(1337); @@ -90,7 +92,7 @@ describe("EncryptedERC20", function () { }); it("should only be able to read hiw own balance", async function () { - const transaction = await this.erc20.mint(10000); + const transaction = await this.erc20.mint(10000, this.signers.alice.address); await transaction.wait(); const tokenAlice = this.instances.alice.getPublicKey(this.contractAddress)!; const encryptedBalanceAlice = await this.erc20.balanceOf( @@ -116,7 +118,7 @@ describe("EncryptedERC20", function () { it("balanceOfMe should recover own's balance handle", async function () { expect(await this.erc20.balanceOfMe()).to.be.eq(0n); // Alice's initial handle is 0 - const transaction = await this.erc20.mint(1000); + const transaction = await this.erc20.mint(1000, this.signers.alice.address); await transaction.wait(); if (network.name == "hardhat") { // mocked mode @@ -130,7 +132,7 @@ describe("EncryptedERC20", function () { }); it("should not transfer tokens between two users", async function () { - const transaction = await this.erc20.mint(1000); + const transaction = await this.erc20.mint(1000, this.signers.alice.address); await transaction.wait(); const encryptedTransferAmount = this.instances.alice.encrypt64(1337); @@ -163,7 +165,7 @@ describe("EncryptedERC20", function () { }); it("should be able to transferFrom only if allowance is sufficient", async function () { - const transaction = await this.erc20.mint(10000); + const transaction = await this.erc20.mint(10000, this.signers.alice.address); await transaction.wait(); const encryptedAllowanceAmount = this.instances.alice.encrypt64(1337); @@ -219,7 +221,7 @@ describe("EncryptedERC20", function () { }); it("only spender and owner could read their allowance", async function () { - const transaction = await this.erc20.mint(10000); + const transaction = await this.erc20.mint(10000, this.signers.alice.address); await transaction.wait(); const encryptedAllowanceAmount = this.instances.alice.encrypt64(1337); @@ -284,7 +286,7 @@ describe("EncryptedERC20", function () { it("should handle errors correctly", async function () { // case 1 succesful transfer - const transaction = await this.erc20.mint(10000); + const transaction = await this.erc20.mint(10000, this.signers.alice.address); await transaction.wait(); let encryptedTransferAmount = this.instances.alice.encrypt64(1337); const tx = await this.erc20["transfer(address,bytes)"](this.signers.bob.address, encryptedTransferAmount);