58 lines
2.2 KiB
Solidity
58 lines
2.2 KiB
Solidity
|
// SPDX-License-Identifier: MIT
|
||
|
pragma solidity ^0.8.19;
|
||
|
|
||
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||
|
import { ERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
|
||
|
import { Test } from "@forge-std/Test.sol";
|
||
|
|
||
|
import { TornadoAddresses } from "@proprietary/TornadoAddresses.sol";
|
||
|
import { Mock } from "./Mock.sol";
|
||
|
import { MockProposal } from "./MockProposal.sol";
|
||
|
import { IGovernance } from "@interfaces/IGovernance.sol";
|
||
|
|
||
|
contract Utils is TornadoAddresses, Test, Mock, MockProposal {
|
||
|
address public constant VERIFIER_ADDRESS = tornTokenAddress;
|
||
|
|
||
|
bytes32 public constant PERMIT_TYPEHASH =
|
||
|
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
|
||
|
|
||
|
bytes32 public constant EIP712_DOMAIN = keccak256(
|
||
|
abi.encode(
|
||
|
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
|
||
|
keccak256(bytes("TornadoCash")),
|
||
|
keccak256(bytes("1")),
|
||
|
1,
|
||
|
VERIFIER_ADDRESS
|
||
|
)
|
||
|
);
|
||
|
|
||
|
uint16 public constant PERMIT_FUNC_SELECTOR = uint16(0x1901);
|
||
|
|
||
|
function retrieveAndLockBalance(uint256 privateKey, address voter, uint256 amount) public {
|
||
|
uint256 lockTimestamp = block.timestamp + PROPOSAL_DURATION;
|
||
|
uint256 accountNonce = ERC20Permit(tornTokenAddress).nonces(voter);
|
||
|
|
||
|
bytes32 messageHash = keccak256(
|
||
|
abi.encodePacked(
|
||
|
PERMIT_FUNC_SELECTOR,
|
||
|
EIP712_DOMAIN,
|
||
|
keccak256(abi.encode(PERMIT_TYPEHASH, voter, governanceAddress, amount, accountNonce, lockTimestamp))
|
||
|
)
|
||
|
);
|
||
|
|
||
|
/* ----------GOVERNANCE------- */
|
||
|
vm.startPrank(governanceAddress);
|
||
|
IERC20(tornTokenAddress).transfer(voter, amount);
|
||
|
vm.stopPrank();
|
||
|
/* ----------------------------*/
|
||
|
|
||
|
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, messageHash);
|
||
|
|
||
|
/* ----------VOTER------------ */
|
||
|
vm.startPrank(voter);
|
||
|
IGovernance(governanceAddress).lock(voter, amount, lockTimestamp, v, r, s);
|
||
|
vm.stopPrank();
|
||
|
/* ----------------------------*/
|
||
|
}
|
||
|
}
|