diff --git a/contracts/test/token/ERC20/TestConfidentialERC20Wrapped.sol b/contracts/test/token/ERC20/TestConfidentialERC20Wrapped.sol new file mode 100644 index 0000000..dd83da3 --- /dev/null +++ b/contracts/test/token/ERC20/TestConfidentialERC20Wrapped.sol @@ -0,0 +1,10 @@ +// SPDX-License-Identifier: BSD-3-Clause-Clear +pragma solidity ^0.8.24; + +import { ConfidentialERC20Wrapped } from "../../../token/ERC20/ConfidentialERC20Wrapped.sol"; +import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; +import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol"; + +contract TestConfidentialERC20Wrapped is MockZamaFHEVMConfig, MockZamaGatewayConfig, ConfidentialERC20Wrapped { + constructor(address erc20_) ConfidentialERC20Wrapped(erc20_) {} +} diff --git a/contracts/test/token/ERC20/TestEncryptedWETH.sol b/contracts/test/token/ERC20/TestConfidentialWETH.sol similarity index 59% rename from contracts/test/token/ERC20/TestEncryptedWETH.sol rename to contracts/test/token/ERC20/TestConfidentialWETH.sol index 1bc4ebc..b893317 100644 --- a/contracts/test/token/ERC20/TestEncryptedWETH.sol +++ b/contracts/test/token/ERC20/TestConfidentialWETH.sol @@ -1,9 +1,9 @@ // SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.24; -import { EncryptedWETH } from "../../../token/ERC20/EncryptedWETH.sol"; +import { ConfidentialWETH } from "../../../token/ERC20/ConfidentialWETH.sol"; import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol"; /* solhint-disable no-empty-blocks*/ -contract TestEncryptedWETH is MockZamaFHEVMConfig, MockZamaGatewayConfig, EncryptedWETH {} +contract TestConfidentialWETH is MockZamaFHEVMConfig, MockZamaGatewayConfig, ConfidentialWETH {} diff --git a/contracts/test/token/ERC20/TestEncryptedERC20Wrapped.sol b/contracts/test/token/ERC20/TestEncryptedERC20Wrapped.sol deleted file mode 100644 index 50d1fad..0000000 --- a/contracts/test/token/ERC20/TestEncryptedERC20Wrapped.sol +++ /dev/null @@ -1,10 +0,0 @@ -// SPDX-License-Identifier: BSD-3-Clause-Clear -pragma solidity ^0.8.24; - -import { EncryptedERC20Wrapped } from "../../../token/ERC20/EncryptedERC20Wrapped.sol"; -import { MockZamaFHEVMConfig } from "fhevm/config/ZamaFHEVMConfig.sol"; -import { MockZamaGatewayConfig } from "fhevm/config/ZamaGatewayConfig.sol"; - -contract TestEncryptedERC20Wrapped is MockZamaFHEVMConfig, MockZamaGatewayConfig, EncryptedERC20Wrapped { - constructor(address erc20_) EncryptedERC20Wrapped(erc20_) {} -} diff --git a/contracts/token/ERC20/EncryptedERC20Wrapped.sol b/contracts/token/ERC20/ConfidentialERC20Wrapped.sol similarity index 91% rename from contracts/token/ERC20/EncryptedERC20Wrapped.sol rename to contracts/token/ERC20/ConfidentialERC20Wrapped.sol index e2cc4fc..b917910 100644 --- a/contracts/token/ERC20/EncryptedERC20Wrapped.sol +++ b/contracts/token/ERC20/ConfidentialERC20Wrapped.sol @@ -7,18 +7,18 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s import "fhevm/lib/TFHE.sol"; import "fhevm/gateway/GatewayCaller.sol"; -import { IEncryptedERC20Wrapped } from "./IEncryptedERC20Wrapped.sol"; -import { EncryptedERC20 } from "./EncryptedERC20.sol"; +import { IConfidentialERC20Wrapped } from "./IConfidentialERC20Wrapped.sol"; +import { ConfidentialERC20 } from "./ConfidentialERC20.sol"; /** - * @title EncryptedERC20Wrapped + * @title ConfidentialERC20Wrapped * @notice This contract allows users to wrap/unwrap trustlessly - * ERC20 tokens to EncryptedERC20 tokens. + * ERC20 tokens to ConfidentialERC20 tokens. * @dev This implementation does not support tokens with rebase functions or * tokens with a fee on transfer. All ERC20 tokens must have decimals * inferior or equal to 18 decimals but superior or equal to 6 decimals. */ -abstract contract EncryptedERC20Wrapped is EncryptedERC20, IEncryptedERC20Wrapped, GatewayCaller { +abstract contract ConfidentialERC20Wrapped is ConfidentialERC20, IConfidentialERC20Wrapped, GatewayCaller { using SafeERC20 for IERC20Metadata; /// @notice ERC20 token that is wrapped. @@ -41,7 +41,7 @@ abstract contract EncryptedERC20Wrapped is EncryptedERC20, IEncryptedERC20Wrappe constructor( address erc20_ ) - EncryptedERC20( + ConfidentialERC20( string(abi.encodePacked("Encrypted ", IERC20Metadata(erc20_).name())), string(abi.encodePacked("e", IERC20Metadata(erc20_).symbol())) ) @@ -50,7 +50,7 @@ abstract contract EncryptedERC20Wrapped is EncryptedERC20, IEncryptedERC20Wrappe } /** - * @notice Unwrap EncryptedERC20 tokens to standard ERC20 tokens. + * @notice Unwrap ConfidentialERC20 tokens to standard ERC20 tokens. * @param amount Amount to unwrap. */ function unwrap(uint64 amount) public virtual { diff --git a/contracts/token/ERC20/EncryptedWETH.sol b/contracts/token/ERC20/ConfidentialWETH.sol similarity index 88% rename from contracts/token/ERC20/EncryptedWETH.sol rename to contracts/token/ERC20/ConfidentialWETH.sol index 6350708..a25ab45 100644 --- a/contracts/token/ERC20/EncryptedWETH.sol +++ b/contracts/token/ERC20/ConfidentialWETH.sol @@ -1,19 +1,19 @@ // SPDX-License-Identifier: BSD-3-Clause-Clear pragma solidity ^0.8.24; -import { EncryptedERC20 } from "./EncryptedERC20.sol"; +import { ConfidentialERC20 } from "./ConfidentialERC20.sol"; import "fhevm/lib/TFHE.sol"; import "fhevm/gateway/GatewayCaller.sol"; -import { IEncryptedERC20Wrapped } from "./IEncryptedERC20Wrapped.sol"; +import { IConfidentialERC20Wrapped } from "./IConfidentialERC20Wrapped.sol"; /** - * @title EncryptedWETH + * @title ConfidentialWETH * @notice This contract allows users to wrap/unwrap trustlessly - * ETH (or other native tokens) to EncryptedERC20 tokens. + * ETH (or other native tokens) to ConfidentialERC20 tokens. */ -abstract contract EncryptedWETH is EncryptedERC20, IEncryptedERC20Wrapped, GatewayCaller { +abstract contract ConfidentialWETH is ConfidentialERC20, IConfidentialERC20Wrapped, GatewayCaller { /// @notice Returned if ETH transfer fails. error ETHTransferFail(); @@ -28,7 +28,7 @@ abstract contract EncryptedWETH is EncryptedERC20, IEncryptedERC20Wrapped, Gatew * @dev The name/symbol are autogenerated. */ constructor() - EncryptedERC20(string(abi.encodePacked("Encrypted Wrapped Ether")), string(abi.encodePacked("eWETH"))) + ConfidentialERC20(string(abi.encodePacked("Encrypted Wrapped Ether")), string(abi.encodePacked("eWETH"))) {} /** @@ -46,7 +46,7 @@ abstract contract EncryptedWETH is EncryptedERC20, IEncryptedERC20Wrapped, Gatew } /** - * @notice Unwrap EncryptedERC20 tokens to ether. + * @notice Unwrap ConfidentialERC20 tokens to ether. * @param amount Amount to unwrap. */ function unwrap(uint64 amount) public virtual { diff --git a/contracts/token/ERC20/IEncryptedERC20Wrapped.sol b/contracts/token/ERC20/IConfidentialERC20Wrapped.sol similarity index 92% rename from contracts/token/ERC20/IEncryptedERC20Wrapped.sol rename to contracts/token/ERC20/IConfidentialERC20Wrapped.sol index 8f78fb2..dee83a3 100644 --- a/contracts/token/ERC20/IEncryptedERC20Wrapped.sol +++ b/contracts/token/ERC20/IConfidentialERC20Wrapped.sol @@ -2,11 +2,11 @@ pragma solidity ^0.8.24; /** - * @title IEncryptedERC20Wrapped/ + * @title IConfidentialERC20Wrapped/ * @notice Interface that defines events, errors, and structs for * contrats that wrap native asset or ERC20 tokens. */ -interface IEncryptedERC20Wrapped { +interface IConfidentialERC20Wrapped { /// @notice Returned if the amount is greater than 2**64. error AmountTooHigh(); diff --git a/test/confidentialERC20/EncryptedERC20Wrapped.fixture.ts b/test/confidentialERC20/ConfidentialERC20Wrapped.fixture.ts similarity index 63% rename from test/confidentialERC20/EncryptedERC20Wrapped.fixture.ts rename to test/confidentialERC20/ConfidentialERC20Wrapped.fixture.ts index fd957f7..49e4212 100644 --- a/test/confidentialERC20/EncryptedERC20Wrapped.fixture.ts +++ b/test/confidentialERC20/ConfidentialERC20Wrapped.fixture.ts @@ -1,34 +1,34 @@ import { ethers } from "hardhat"; -import type { ERC20Mintable, EncryptedERC20Wrapped, TestEncryptedERC20Wrapped } from "../../types"; +import type { ConfidentialERC20Wrapped, ERC20Mintable, TestConfidentialERC20Wrapped } from "../../types"; import { Signers } from "../signers"; -export async function deployERC20AndEncryptedERC20WrappedFixture( +export async function deployERC20AndConfidentialERC20WrappedFixture( signers: Signers, name: string, symbol: string, decimals: number, -): Promise<[ERC20Mintable, TestEncryptedERC20Wrapped]> { +): Promise<[ERC20Mintable, TestConfidentialERC20Wrapped]> { const contractFactoryERC20Mintable = await ethers.getContractFactory("ERC20Mintable"); const contractERC20 = await contractFactoryERC20Mintable .connect(signers.alice) .deploy(name, symbol, decimals, signers.alice.address); await contractERC20.waitForDeployment(); - const contractFactoryEncryptedERC20Wrapped = await ethers.getContractFactory("TestEncryptedERC20Wrapped"); - const contractEncryptedERC20Wrapped = await contractFactoryEncryptedERC20Wrapped + const contractFactory = await ethers.getContractFactory("TestConfidentialERC20Wrapped"); + const contractConfidentialERC20Wrapped = await contractFactory .connect(signers.alice) .deploy(contractERC20.getAddress()); - await contractEncryptedERC20Wrapped.waitForDeployment(); + await contractConfidentialERC20Wrapped.waitForDeployment(); - return [contractERC20, contractEncryptedERC20Wrapped]; + return [contractERC20, contractConfidentialERC20Wrapped]; } export async function mintAndWrap( signers: Signers, user: string, plainToken: ERC20Mintable, - token: EncryptedERC20Wrapped, + token: ConfidentialERC20Wrapped, tokenAddress: string, amount: bigint, ): Promise { diff --git a/test/confidentialERC20/EncryptedERC20Wrapped.test.ts b/test/confidentialERC20/ConfidentialERC20Wrapped.test.ts similarity index 57% rename from test/confidentialERC20/EncryptedERC20Wrapped.test.ts rename to test/confidentialERC20/ConfidentialERC20Wrapped.test.ts index 1e25270..61d4946 100644 --- a/test/confidentialERC20/EncryptedERC20Wrapped.test.ts +++ b/test/confidentialERC20/ConfidentialERC20Wrapped.test.ts @@ -4,17 +4,17 @@ import { ethers } from "hardhat"; import { awaitAllDecryptionResults } from "../asyncDecrypt"; import { createInstances } from "../instance"; import { getSigners, initSigners } from "../signers"; -import { reencryptBalance } from "./EncryptedERC20.fixture"; -import { deployERC20AndEncryptedERC20WrappedFixture } from "./EncryptedERC20Wrapped.fixture"; +import { reencryptBalance } from "./ConfidentialERC20.fixture"; +import { deployERC20AndConfidentialERC20WrappedFixture } from "./ConfidentialERC20Wrapped.fixture"; -describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { +describe("ConfidentialERC20Wrapped using ERC20 with 6 decimals", function () { before(async function () { await initSigners(2); this.signers = await getSigners(); }); beforeEach(async function () { - const [erc20, encryptedERC20] = await deployERC20AndEncryptedERC20WrappedFixture( + const [erc20, confidentialERC20Wrapped] = await deployERC20AndConfidentialERC20WrappedFixture( this.signers, "Naraggara", "NARA", @@ -22,15 +22,15 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { ); this.erc20 = erc20; - this.encryptedERC20 = encryptedERC20; + this.confidentialERC20Wrapped = confidentialERC20Wrapped; this.erc20ContractAddress = await erc20.getAddress(); - this.encryptedERC20Address = await encryptedERC20.getAddress(); + this.confidentialERC20WrappedAddress = await confidentialERC20Wrapped.getAddress(); this.instances = await createInstances(this.signers); }); it("name/symbol are automatically set", async function () { - expect(await this.encryptedERC20.name()).to.eq("Encrypted Naraggara"); - expect(await this.encryptedERC20.symbol()).to.eq("eNARA"); + expect(await this.confidentialERC20Wrapped.name()).to.eq("Encrypted Naraggara"); + expect(await this.confidentialERC20Wrapped.symbol()).to.eq("eNARA"); }); it("can wrap", async function () { @@ -43,14 +43,20 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { expect(await this.erc20.balanceOf(this.signers.alice)).to.equal(amountToWrap); expect(await this.erc20.totalSupply()).to.equal(amountToWrap); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.wrap(amountToWrap); await tx.wait(); // Check encrypted balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20Wrapped, + this.confidentialERC20WrappedAddress, + ), ).to.equal(amountToWrap); }); @@ -60,12 +66,12 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); await awaitAllDecryptionResults(); @@ -74,7 +80,13 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { expect(await this.erc20.totalSupply()).to.equal(amountToWrap); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20Wrapped, + this.confidentialERC20WrappedAddress, + ), ).to.equal(amountToWrap - amountToUnwrap); }); @@ -85,25 +97,28 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput( + this.confidentialERC20WrappedAddress, + this.signers.alice.address, + ); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); await expect( - this.encryptedERC20 + this.confidentialERC20Wrapped .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof), - ).to.be.revertedWithCustomError(this.encryptedERC20, "CannotTransferOrUnwrap"); + ).to.be.revertedWithCustomError(this.confidentialERC20Wrapped, "CannotTransferOrUnwrap"); }); it("cannot call twice unwrap before decryption", async function () { @@ -112,18 +127,17 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); - await expect(this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap)).to.be.revertedWithCustomError( - this.encryptedERC20, - "CannotTransferOrUnwrap", - ); + await expect( + this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap), + ).to.be.revertedWithCustomError(this.confidentialERC20Wrapped, "CannotTransferOrUnwrap"); }); it("cannot unwrap more than balance", async function () { @@ -132,20 +146,26 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); await awaitAllDecryptionResults(); // Verify the balances have not changed - expect(await this.erc20.balanceOf(this.encryptedERC20Address)).to.equal(amountToWrap); - expect(await this.encryptedERC20.totalSupply()).to.equal(amountToWrap); + expect(await this.erc20.balanceOf(this.confidentialERC20WrappedAddress)).to.equal(amountToWrap); + expect(await this.confidentialERC20Wrapped.totalSupply()).to.equal(amountToWrap); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20Wrapped, + this.confidentialERC20WrappedAddress, + ), ).to.equal(amountToWrap); }); @@ -155,33 +175,36 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap); await tx.wait(); let transferAmount = ethers.parseUnits("3000", 6); - let input = this.instances.alice.createEncryptedInput(this.encryptedERC20Address, this.signers.alice.address); + let input = this.instances.alice.createEncryptedInput( + this.confidentialERC20WrappedAddress, + this.signers.alice.address, + ); input.add64(transferAmount); let encryptedTransferAmount = await input.encrypt(); - await this.encryptedERC20 + await this.confidentialERC20Wrapped .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); - tx = await this.encryptedERC20.connect(this.signers.bob).unwrap(amountToUnwrap); + tx = await this.confidentialERC20Wrapped.connect(this.signers.bob).unwrap(amountToUnwrap); await tx.wait(); await awaitAllDecryptionResults(); transferAmount = ethers.parseUnits("1000", 6); - input = this.instances.bob.createEncryptedInput(this.encryptedERC20Address, this.signers.bob.address); + input = this.instances.bob.createEncryptedInput(this.confidentialERC20WrappedAddress, this.signers.bob.address); input.add64(transferAmount); encryptedTransferAmount = await input.encrypt(); - await this.encryptedERC20 + await this.confidentialERC20Wrapped .connect(this.signers.bob) [ "transfer(address,bytes32,bytes)" @@ -194,47 +217,46 @@ describe("EncryptedERC20Wrapped using ERC20 with 6 decimals", function () { // @dev Verify 2**64 - 1 is fine. let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap - BigInt(1)); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap - BigInt(1)); await tx.wait(); // Unwrap all - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToWrap - BigInt(1)); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToWrap - BigInt(1)); await tx.wait(); await awaitAllDecryptionResults(); // @dev Verify 2**64 is not fine - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - await expect(this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap)).to.be.revertedWithCustomError( - this.encryptedERC20, - "AmountTooHigh", - ); + await expect( + this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap), + ).to.be.revertedWithCustomError(this.confidentialERC20Wrapped, "AmountTooHigh"); }); it("only gateway can call callback functions", async function () { - await expect(this.encryptedERC20.connect(this.signers.alice).callbackUnwrap(1, false)).to.be.reverted; + await expect(this.confidentialERC20Wrapped.connect(this.signers.alice).callbackUnwrap(1, false)).to.be.reverted; }); }); -describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { +describe("ConfidentialERC20Wrapped using ERC20 with 18 decimals", function () { before(async function () { await initSigners(2); this.signers = await getSigners(); }); beforeEach(async function () { - const [erc20, encryptedERC20] = await deployERC20AndEncryptedERC20WrappedFixture( + const [erc20, confidentialERC20Wrapped] = await deployERC20AndConfidentialERC20WrappedFixture( this.signers, "Naraggara", "NARA", 18, ); this.erc20 = erc20; - this.encryptedERC20 = encryptedERC20; + this.confidentialERC20Wrapped = confidentialERC20Wrapped; this.erc20ContractAddress = await erc20.getAddress(); - this.encryptedERC20Address = await encryptedERC20.getAddress(); + this.confidentialERC20WrappedAddress = await confidentialERC20Wrapped.getAddress(); this.instances = await createInstances(this.signers); }); @@ -250,14 +272,22 @@ describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { expect(await this.erc20.balanceOf(this.signers.alice)).to.equal(amountToWrap18Decimals); expect(await this.erc20.totalSupply()).to.equal(amountToWrap18Decimals); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap18Decimals); + tx = await this.erc20 + .connect(this.signers.alice) + .approve(this.confidentialERC20WrappedAddress, amountToWrap18Decimals); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap18Decimals); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap18Decimals); await tx.wait(); // Check encrypted balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20Wrapped, + this.confidentialERC20WrappedAddress, + ), ).to.equal(amountToWrap6Decimals); }); @@ -271,12 +301,14 @@ describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap18Decimals); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap18Decimals); + tx = await this.erc20 + .connect(this.signers.alice) + .approve(this.confidentialERC20WrappedAddress, amountToWrap18Decimals); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap18Decimals); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap18Decimals); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); await tx.wait(); await awaitAllDecryptionResults(); @@ -286,11 +318,17 @@ describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { // Check encrypted balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedERC20, this.encryptedERC20Address), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialERC20Wrapped, + this.confidentialERC20WrappedAddress, + ), ).to.equal(amountToWrap6Decimals - amountToUnwrap6Decimals); // Unwrap all - tx = await this.encryptedERC20.unwrap(amountToWrap6Decimals - amountToUnwrap6Decimals); + tx = await this.confidentialERC20Wrapped.unwrap(amountToWrap6Decimals - amountToUnwrap6Decimals); await tx.wait(); await awaitAllDecryptionResults(); @@ -304,15 +342,15 @@ describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { // @dev Verify 2**64 - 1 is fine. let tx = await this.erc20.connect(this.signers.alice).mint(amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.alice).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.alice).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - tx = await this.encryptedERC20.connect(this.signers.alice).wrap(amountToWrap - BigInt(1)); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).wrap(amountToWrap - BigInt(1)); await tx.wait(); - const totalSupply = await this.encryptedERC20.totalSupply(); + const totalSupply = await this.confidentialERC20Wrapped.totalSupply(); // Unwrap all - tx = await this.encryptedERC20.connect(this.signers.alice).unwrap(totalSupply); + tx = await this.confidentialERC20Wrapped.connect(this.signers.alice).unwrap(totalSupply); await tx.wait(); await awaitAllDecryptionResults(); @@ -322,12 +360,11 @@ describe("EncryptedERC20Wrapped using ERC20 with 18 decimals", function () { await tx.wait(); tx = await this.erc20.connect(this.signers.alice).transfer(this.signers.bob.address, amountToWrap); await tx.wait(); - tx = await this.erc20.connect(this.signers.bob).approve(this.encryptedERC20Address, amountToWrap); + tx = await this.erc20.connect(this.signers.bob).approve(this.confidentialERC20WrappedAddress, amountToWrap); await tx.wait(); - await expect(this.encryptedERC20.connect(this.signers.bob).wrap(amountToWrap)).to.be.revertedWithCustomError( - this.encryptedERC20, - "AmountTooHigh", - ); + await expect( + this.confidentialERC20Wrapped.connect(this.signers.bob).wrap(amountToWrap), + ).to.be.revertedWithCustomError(this.confidentialERC20Wrapped, "AmountTooHigh"); }); }); diff --git a/test/confidentialERC20/ConfidentialWETH.fixture.ts b/test/confidentialERC20/ConfidentialWETH.fixture.ts new file mode 100644 index 0000000..f1ed80b --- /dev/null +++ b/test/confidentialERC20/ConfidentialWETH.fixture.ts @@ -0,0 +1,12 @@ +import { ethers } from "hardhat"; + +import type { TestConfidentialWETH } from "../../types"; +import { Signers } from "../signers"; + +export async function deployConfidentialWETHFixture(signers: Signers): Promise { + const contractFactory = await ethers.getContractFactory("TestConfidentialWETH"); + const confidentialWETH = await contractFactory.connect(signers.alice).deploy(); + await confidentialWETH.waitForDeployment(); + + return confidentialWETH; +} diff --git a/test/confidentialERC20/EncryptedWETH.test.ts b/test/confidentialERC20/ConfidentialWETH.test.ts similarity index 62% rename from test/confidentialERC20/EncryptedWETH.test.ts rename to test/confidentialERC20/ConfidentialWETH.test.ts index 2c14ca9..6ec9adf 100644 --- a/test/confidentialERC20/EncryptedWETH.test.ts +++ b/test/confidentialERC20/ConfidentialWETH.test.ts @@ -5,10 +5,10 @@ import { ethers } from "hardhat"; import { awaitAllDecryptionResults } from "../asyncDecrypt"; import { createInstances } from "../instance"; import { getSigners, initSigners } from "../signers"; -import { reencryptBalance } from "./EncryptedERC20.fixture"; -import { deployEncryptedWETHFixture } from "./EncryptedWETH.fixture"; +import { reencryptBalance } from "./ConfidentialERC20.fixture"; +import { deployConfidentialWETHFixture } from "./ConfidentialWETH.fixture"; -describe("EncryptedWETH", function () { +describe("ConfidentialWETH", function () { before(async function () { await initSigners(3); this.signers = await getSigners(); @@ -16,15 +16,15 @@ describe("EncryptedWETH", function () { }); beforeEach(async function () { - const encryptedWETH = await deployEncryptedWETHFixture(this.signers); - this.encryptedWETH = encryptedWETH; - this.encryptedWETHAddress = await encryptedWETH.getAddress(); + const confidentialWETH = await deployConfidentialWETHFixture(this.signers); + this.confidentialWETH = confidentialWETH; + this.confidentialWETHAddress = await confidentialWETH.getAddress(); }); it("name/symbol are automatically set, totalSupply = 0", async function () { - expect(await this.encryptedWETH.name()).to.eq("Encrypted Wrapped Ether"); - expect(await this.encryptedWETH.symbol()).to.eq("eWETH"); - expect(await this.encryptedWETH.totalSupply()).to.eq("0"); + expect(await this.confidentialWETH.name()).to.eq("Encrypted Wrapped Ether"); + expect(await this.confidentialWETH.symbol()).to.eq("eWETH"); + expect(await this.confidentialWETH.totalSupply()).to.eq("0"); }); it("can wrap", async function () { @@ -35,12 +35,18 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap18Decimals + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - const tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); + const tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); await tx.wait(); // Check encrypted balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedWETH, this.encryptedWETHAddress), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialWETH, + this.confidentialWETHAddress, + ), ).to.equal(amountToWrap6Decimals); }); @@ -55,25 +61,37 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap18Decimals + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); await tx.wait(); - tx = await this.encryptedWETH.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); + tx = await this.confidentialWETH.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); await tx.wait(); await awaitAllDecryptionResults(); // Check encrypted balance expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedWETH, this.encryptedWETHAddress), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialWETH, + this.confidentialWETHAddress, + ), ).to.equal(amountToWrap6Decimals - amountToUnwrap6Decimals); // Unwrap all - tx = await this.encryptedWETH.unwrap(amountToWrap6Decimals - amountToUnwrap6Decimals); + tx = await this.confidentialWETH.unwrap(amountToWrap6Decimals - amountToUnwrap6Decimals); await tx.wait(); await awaitAllDecryptionResults(); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedWETH, this.encryptedWETHAddress), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialWETH, + this.confidentialWETHAddress, + ), ).to.equal(BigInt("0")); }); @@ -84,13 +102,13 @@ describe("EncryptedWETH", function () { await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); // @dev Verify 2**64 - 1 is fine. - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap - BigInt(1) }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap - BigInt(1) }); await tx.wait(); - const totalSupply = await this.encryptedWETH.totalSupply(); + const totalSupply = await this.confidentialWETH.totalSupply(); // Unwrap all - tx = await this.encryptedWETH.connect(this.signers.alice).unwrap(totalSupply); + tx = await this.confidentialWETH.connect(this.signers.alice).unwrap(totalSupply); await tx.wait(); await awaitAllDecryptionResults(); @@ -99,8 +117,8 @@ describe("EncryptedWETH", function () { await ethers.provider.send("hardhat_setBalance", [this.signers.bob.address, "0x" + amountToMint.toString(16)]); await expect( - this.encryptedWETH.connect(this.signers.bob).wrap({ value: amountToWrap }), - ).to.be.revertedWithCustomError(this.encryptedWETH, "AmountTooHigh"); + this.confidentialWETH.connect(this.signers.bob).wrap({ value: amountToWrap }), + ).to.be.revertedWithCustomError(this.confidentialWETH, "AmountTooHigh"); }); it("cannot transfer after unwrap has been called but decryption has not occurred", async function () { @@ -112,23 +130,23 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); await tx.wait(); - tx = await this.encryptedWETH.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialWETH.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); - const input = this.instances.alice.createEncryptedInput(this.encryptedWETHAddress, this.signers.alice.address); + const input = this.instances.alice.createEncryptedInput(this.confidentialWETHAddress, this.signers.alice.address); input.add64(transferAmount); const encryptedTransferAmount = await input.encrypt(); await expect( - this.encryptedWETH + this.confidentialWETH .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof), - ).to.be.revertedWithCustomError(this.encryptedWETH, "CannotTransferOrUnwrap"); + ).to.be.revertedWithCustomError(this.confidentialWETH, "CannotTransferOrUnwrap"); }); it("cannot call twice unwrap before decryption", async function () { @@ -138,16 +156,15 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); await tx.wait(); - tx = await this.encryptedWETH.connect(this.signers.alice).unwrap(amountToUnwrap); + tx = await this.confidentialWETH.connect(this.signers.alice).unwrap(amountToUnwrap); await tx.wait(); - await expect(this.encryptedWETH.connect(this.signers.alice).unwrap(amountToUnwrap)).to.be.revertedWithCustomError( - this.encryptedWETH, - "CannotTransferOrUnwrap", - ); + await expect( + this.confidentialWETH.connect(this.signers.alice).unwrap(amountToUnwrap), + ).to.be.revertedWithCustomError(this.confidentialWETH, "CannotTransferOrUnwrap"); }); it("cannot unwrap more than balance", async function () { @@ -160,17 +177,23 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap18Decimals + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap18Decimals }); await tx.wait(); - tx = await this.encryptedWETH.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); + tx = await this.confidentialWETH.connect(this.signers.alice).unwrap(amountToUnwrap6Decimals); await tx.wait(); await awaitAllDecryptionResults(); // Verify the balances have not changed - expect(await ethers.provider.getBalance(this.encryptedWETHAddress)).to.equal(amountToWrap18Decimals); - expect(await this.encryptedWETH.totalSupply()).to.equal(amountToWrap6Decimals); + expect(await ethers.provider.getBalance(this.confidentialWETHAddress)).to.equal(amountToWrap18Decimals); + expect(await this.confidentialWETH.totalSupply()).to.equal(amountToWrap6Decimals); expect( - await reencryptBalance(this.signers, this.instances, "alice", this.encryptedWETH, this.encryptedWETHAddress), + await reencryptBalance( + this.signers, + this.instances, + "alice", + this.confidentialWETH, + this.confidentialWETHAddress, + ), ).to.equal(amountToWrap6Decimals); }); @@ -181,30 +204,30 @@ describe("EncryptedWETH", function () { const amountToMint = amountToWrap + ethers.parseUnits("1", 18); await ethers.provider.send("hardhat_setBalance", [this.signers.alice.address, "0x" + amountToMint.toString(16)]); - let tx = await this.encryptedWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); + let tx = await this.confidentialWETH.connect(this.signers.alice).wrap({ value: amountToWrap }); await tx.wait(); let transferAmount = ethers.parseUnits("3000", 6); - let input = this.instances.alice.createEncryptedInput(this.encryptedWETHAddress, this.signers.alice.address); + let input = this.instances.alice.createEncryptedInput(this.confidentialWETHAddress, this.signers.alice.address); input.add64(transferAmount); let encryptedTransferAmount = await input.encrypt(); - await this.encryptedWETH + await this.confidentialWETH .connect(this.signers.alice) [ "transfer(address,bytes32,bytes)" ](this.signers.bob.address, encryptedTransferAmount.handles[0], encryptedTransferAmount.inputProof); - tx = await this.encryptedWETH.connect(this.signers.bob).unwrap(amountToUnwrap); + tx = await this.confidentialWETH.connect(this.signers.bob).unwrap(amountToUnwrap); await tx.wait(); await awaitAllDecryptionResults(); transferAmount = ethers.parseUnits("1000", 6); - input = this.instances.bob.createEncryptedInput(this.encryptedWETHAddress, this.signers.bob.address); + input = this.instances.bob.createEncryptedInput(this.confidentialWETHAddress, this.signers.bob.address); input.add64(transferAmount); encryptedTransferAmount = await input.encrypt(); - await this.encryptedWETH + await this.confidentialWETH .connect(this.signers.bob) [ "transfer(address,bytes32,bytes)" @@ -212,6 +235,6 @@ describe("EncryptedWETH", function () { }); it("only gateway can call callback functions", async function () { - await expect(this.encryptedWETH.connect(this.signers.alice).callbackUnwrap(1, false)).to.be.reverted; + await expect(this.confidentialWETH.connect(this.signers.alice).callbackUnwrap(1, false)).to.be.reverted; }); }); diff --git a/test/confidentialERC20/EncryptedWETH.fixture.ts b/test/confidentialERC20/EncryptedWETH.fixture.ts deleted file mode 100644 index 33092aa..0000000 --- a/test/confidentialERC20/EncryptedWETH.fixture.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { ethers } from "hardhat"; - -import type { TestEncryptedWETH } from "../../types"; -import { Signers } from "../signers"; - -export async function deployEncryptedWETHFixture(signers: Signers): Promise { - const contractFactoryEncryptedWETH = await ethers.getContractFactory("TestEncryptedWETH"); - const encryptedWETH = await contractFactoryEncryptedWETH.connect(signers.alice).deploy(); - await encryptedWETH.waitForDeployment(); - - return encryptedWETH; -}