Skip to content

Commit

Permalink
added random in constructor and same pattern with a clone factory + w…
Browse files Browse the repository at this point in the history
…orking tests
  • Loading branch information
jatZama committed Jan 22, 2024
1 parent f24f200 commit 376dcab
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 323 deletions.
148 changes: 0 additions & 148 deletions contracts/ConfidentialERC20.sol

This file was deleted.

19 changes: 19 additions & 0 deletions contracts/RandomInConstructor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";

contract RandomInConstructor {
euint32 private random;

constructor() {
random = TFHE.rem(TFHE.randEuint32(),100);
}

// Returns the name of the token.
function result() public view virtual returns (uint32) {
return TFHE.decrypt(random);
}

}
23 changes: 23 additions & 0 deletions contracts/RandomInConstructorFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.20;

import "@openzeppelin/contracts/proxy/Clones.sol";
import { RandomInConstructorInitializable } from "./RandomInConstructorInitializable.sol";

contract RandomInConstructorFactory{
address private immutable implementation;

constructor(address _implementation) {
implementation = _implementation;
}

function clone(bytes32 salt) public returns (address cloneAdd){
cloneAdd = Clones.cloneDeterministic(implementation,salt);
RandomInConstructorInitializable(cloneAdd).initialize();
}

function predictAddress(bytes32 salt) public view returns (address predicted){
predicted = Clones.predictDeterministicAddress(implementation,salt);
}
}
24 changes: 24 additions & 0 deletions contracts/RandomInConstructorInitializable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: BSD-3-Clause-Clear

pragma solidity ^0.8.20;

import "fhevm/lib/TFHE.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";

contract RandomInConstructorInitializable is Initializable{
euint32 private random;

constructor() {
_disableInitializers();
}

function initialize() external initializer{
random = TFHE.randEuint32();
}

// Returns the name of the token.
function result() public view virtual returns (uint32) {
return TFHE.decrypt(random);
}

}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
"fhevm:faucet:dave": "docker exec -i fhevm faucet $(npx hardhat task:getEthereumAddressDave)"
},
"dependencies": {
"@openzeppelin/contracts": "^5.0.1"
"@openzeppelin-contracts-upgradeable": "link:@openzeppelin-contracts-upgradeable",
"@openzeppelin/contracts": "^5.0.1",
"@openzeppelin/contracts-upgradeable": "^5.0.1"
}
}
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions test/confidentialERC20/ConfidentialERC20.fixture.ts

This file was deleted.

Loading

0 comments on commit 376dcab

Please sign in to comment.