use ECDSA, ERC2771, ERC20 from @openzeppelin
This commit is contained in:
parent
407ea51d6a
commit
8222bdd084
@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
|||||||
|
|
||||||
import { ERC20, OwnerSettings } from "contracts/core/OwnerSettings.sol";
|
import { ERC20, OwnerSettings } from "contracts/core/OwnerSettings.sol";
|
||||||
|
|
||||||
import { ECDSA } from "contracts/lib/utils/ECDSA.sol";
|
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||||
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
|
||||||
import { MerkleProof as Merkle } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
|
import { MerkleProof as Merkle } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
|
||||||
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||||
@ -44,7 +44,7 @@ abstract contract BaseUtils is
|
|||||||
if (
|
if (
|
||||||
!validBacenSigners(
|
!validBacenSigners(
|
||||||
_castAddrToKey(
|
_castAddrToKey(
|
||||||
ECDSA.recoverCalldata(
|
ECDSA.recover(
|
||||||
MessageHashUtils.toEthSignedMessageHash(
|
MessageHashUtils.toEthSignedMessageHash(
|
||||||
_message
|
_message
|
||||||
),
|
),
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.8.19;
|
pragma solidity ^0.8.19;
|
||||||
|
|
||||||
import { ERC2771Context as ERC2771 } from "contracts/lib/metatx/ERC2771Context.sol";
|
import { ERC2771Context as ERC2771 } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
||||||
import { ERC20, SafeTransferLib } from "contracts/lib/utils/SafeTransferLib.sol";
|
import { ERC20, SafeTransferLib } from "contracts/lib/utils/SafeTransferLib.sol";
|
||||||
import { IReputation } from "contracts/lib/interfaces/IReputation.sol";
|
import { IReputation } from "contracts/lib/interfaces/IReputation.sol";
|
||||||
import { EventAndErrors } from "contracts/core/EventAndErrors.sol";
|
import { EventAndErrors } from "contracts/core/EventAndErrors.sol";
|
||||||
@ -42,48 +42,6 @@ abstract contract OwnerSettings is
|
|||||||
|
|
||||||
/// ███ Owner Only █████████████████████████████████████████████████████████
|
/// ███ Owner Only █████████████████████████████████████████████████████████
|
||||||
|
|
||||||
function setTrustedFowarders(
|
|
||||||
address[] memory forwarders,
|
|
||||||
bool[] memory states
|
|
||||||
) external onlyOwner {
|
|
||||||
assembly ("memory-safe") {
|
|
||||||
// first 32 bytes eq to array's length
|
|
||||||
let fLen := mload(forwarders)
|
|
||||||
// halts execution if forwarders.length eq 0
|
|
||||||
if iszero(fLen) {
|
|
||||||
invalid()
|
|
||||||
}
|
|
||||||
// revert with `LengthMismatch()`
|
|
||||||
if iszero(eq(fLen, mload(states))) {
|
|
||||||
mstore(0x00, 0xff633a38)
|
|
||||||
revert(0x1c, 0x04)
|
|
||||||
}
|
|
||||||
let fLoc := add(forwarders, 0x20)
|
|
||||||
let sLoc := add(states, 0x20)
|
|
||||||
for {
|
|
||||||
let end := add(fLoc, shl(5, fLen))
|
|
||||||
} iszero(eq(fLoc, end)) {
|
|
||||||
fLoc := add(fLoc, 0x20)
|
|
||||||
sLoc := add(sLoc, 0x20)
|
|
||||||
} {
|
|
||||||
// cache hashmap entry in scratch space
|
|
||||||
mstore(0x20, trustedForwarders.slot)
|
|
||||||
mstore(0x00, mload(fLoc))
|
|
||||||
// let mapSlot := keccak256(0x00, 0x40)
|
|
||||||
sstore(keccak256(0x00, 0x40), mload(sLoc))
|
|
||||||
|
|
||||||
// emit TrustedForwarderUpdated(address, bool)
|
|
||||||
log3(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
_TRUSTED_FORWARDER_UPDATED_EVENT_SIGNATURE,
|
|
||||||
mload(fLoc),
|
|
||||||
mload(sLoc)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @dev Contract's underlying balance withdraw method.
|
/// @dev Contract's underlying balance withdraw method.
|
||||||
/// @dev Function sighash: 0x5fd8c710.
|
/// @dev Function sighash: 0x5fd8c710.
|
||||||
function withdrawBalance() external onlyOwner {
|
function withdrawBalance() external onlyOwner {
|
||||||
|
|||||||
@ -9,6 +9,7 @@ pragma solidity ^0.8.19;
|
|||||||
///
|
///
|
||||||
|
|
||||||
import { OwnerSettings, ERC20, SafeTransferLib } from "contracts/core/OwnerSettings.sol";
|
import { OwnerSettings, ERC20, SafeTransferLib } from "contracts/core/OwnerSettings.sol";
|
||||||
|
import { ERC2771Context as ERC2771 } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
|
||||||
import { BaseUtils } from "contracts/core/BaseUtils.sol";
|
import { BaseUtils } from "contracts/core/BaseUtils.sol";
|
||||||
import { DataTypes as DT } from "contracts/core/DataTypes.sol";
|
import { DataTypes as DT } from "contracts/core/DataTypes.sol";
|
||||||
|
|
||||||
@ -33,8 +34,10 @@ contract P2PIX is BaseUtils {
|
|||||||
address[] memory validSigners,
|
address[] memory validSigners,
|
||||||
address _reputation,
|
address _reputation,
|
||||||
ERC20[] memory tokens,
|
ERC20[] memory tokens,
|
||||||
bool[] memory tokenStates
|
bool[] memory tokenStates,
|
||||||
|
address trustedForwarder
|
||||||
)
|
)
|
||||||
|
ERC2771(trustedForwarder)
|
||||||
OwnerSettings(
|
OwnerSettings(
|
||||||
defaultBlocks,
|
defaultBlocks,
|
||||||
validSigners,
|
validSigners,
|
||||||
|
|||||||
@ -38,7 +38,7 @@
|
|||||||
"@nomicfoundation/hardhat-verify": "^2.1.0",
|
"@nomicfoundation/hardhat-verify": "^2.1.0",
|
||||||
"@nomicfoundation/hardhat-viem": "^2.1.0",
|
"@nomicfoundation/hardhat-viem": "^2.1.0",
|
||||||
"@nomicfoundation/ignition-core": "^0.15.13",
|
"@nomicfoundation/ignition-core": "^0.15.13",
|
||||||
"@openzeppelin/contracts": "^5.4.0",
|
"@openzeppelin/contracts": "^5.5.0-rc.0",
|
||||||
"@typechain/ethers-v6": "^0.5.1",
|
"@typechain/ethers-v6": "^0.5.1",
|
||||||
"@typechain/hardhat": "^9.1.0",
|
"@typechain/hardhat": "^9.1.0",
|
||||||
"@types/chai": "^4.3.20",
|
"@types/chai": "^4.3.20",
|
||||||
|
|||||||
@ -29,6 +29,7 @@ const main = async () => {
|
|||||||
reputation.target,
|
reputation.target,
|
||||||
[deploysJson.token],
|
[deploysJson.token],
|
||||||
[true],
|
[true],
|
||||||
|
ethers.ZeroAddress,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
reputation = await reputation.waitForDeployment();
|
reputation = await reputation.waitForDeployment();
|
||||||
|
|||||||
@ -93,6 +93,7 @@ export async function p2pixFixture(): Promise<P2PixAndReputation> {
|
|||||||
reputation.target,
|
reputation.target,
|
||||||
[erc20.target],
|
[erc20.target],
|
||||||
[true],
|
[true],
|
||||||
|
ethers.ZeroAddress,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const multicall = await ethers.deployContract("Multicall");
|
const multicall = await ethers.deployContract("Multicall");
|
||||||
|
|||||||
10
yarn.lock
10
yarn.lock
@ -988,10 +988,10 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"@openzeppelin/contracts@npm:^5.4.0":
|
"@openzeppelin/contracts@npm:^5.5.0-rc.0":
|
||||||
version: 5.4.0
|
version: 5.5.0-rc.0
|
||||||
resolution: "@openzeppelin/contracts@npm:5.4.0"
|
resolution: "@openzeppelin/contracts@npm:5.5.0-rc.0"
|
||||||
checksum: 10/4f7f926ebd98279ba8223cae5d2cd38e0806e60e3e3a615c9d739ffab870ffab7a1e85f47092faa123c0f26d1699ca15252adea8bcdcaf360b21781acc93b218
|
checksum: 10/caa60a0963a4a0d1ee267ec99e4fda7b952fa8743a59dcbf3ea4a0b11b9cd6c93524b92939fd6482c52b8374ec68d6e6399626ea23e7c96730ada2d8452c4396
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
@ -4570,7 +4570,7 @@ __metadata:
|
|||||||
"@nomicfoundation/hardhat-verify": "npm:^2.1.0"
|
"@nomicfoundation/hardhat-verify": "npm:^2.1.0"
|
||||||
"@nomicfoundation/hardhat-viem": "npm:^2.1.0"
|
"@nomicfoundation/hardhat-viem": "npm:^2.1.0"
|
||||||
"@nomicfoundation/ignition-core": "npm:^0.15.13"
|
"@nomicfoundation/ignition-core": "npm:^0.15.13"
|
||||||
"@openzeppelin/contracts": "npm:^5.4.0"
|
"@openzeppelin/contracts": "npm:^5.5.0-rc.0"
|
||||||
"@typechain/ethers-v6": "npm:^0.5.1"
|
"@typechain/ethers-v6": "npm:^0.5.1"
|
||||||
"@typechain/hardhat": "npm:^9.1.0"
|
"@typechain/hardhat": "npm:^9.1.0"
|
||||||
"@types/chai": "npm:^4.3.20"
|
"@types/chai": "npm:^4.3.20"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user