✨ Added ERC2771 support & Increased pixTarget max size
This commit is contained in:
@@ -2,10 +2,15 @@
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import { OwnerSettings } from "./OwnerSettings.sol";
|
||||
|
||||
import { ECDSA } from "../lib/utils/ECDSA.sol";
|
||||
import { MerkleProofLib as Merkle } from "../lib/utils/MerkleProofLib.sol";
|
||||
import { ReentrancyGuard } from "../lib/utils/ReentrancyGuard.sol";
|
||||
|
||||
abstract contract BaseUtils is OwnerSettings {
|
||||
abstract contract BaseUtils is
|
||||
OwnerSettings,
|
||||
ReentrancyGuard
|
||||
{
|
||||
/// ███ Storage ████████████████████████████████████████████████████████████
|
||||
|
||||
/// @dev List of Pix transactions already signed.
|
||||
@@ -67,26 +72,26 @@ abstract contract BaseUtils is OwnerSettings {
|
||||
) revert AddressDenied();
|
||||
}
|
||||
|
||||
function _castToUint(
|
||||
uint96 _amount,
|
||||
uint160 _pixTarget,
|
||||
function _castBool(
|
||||
bool _valid
|
||||
)
|
||||
internal
|
||||
pure
|
||||
returns (
|
||||
uint256 _amountCasted,
|
||||
uint256 _pixTargetCasted,
|
||||
uint256 _validCasted
|
||||
)
|
||||
{
|
||||
) internal pure returns (uint256 _validCasted) {
|
||||
assembly {
|
||||
_amountCasted := _amount
|
||||
_pixTargetCasted := _pixTarget
|
||||
_validCasted := _valid
|
||||
}
|
||||
}
|
||||
|
||||
function getStr(
|
||||
string memory str
|
||||
) public pure returns (bytes32 strEnc) {
|
||||
bytes memory enc = bytes(abi.encodePacked(str));
|
||||
assembly {
|
||||
if lt(0x20, mload(enc)) {
|
||||
invalid()
|
||||
}
|
||||
strEnc := mload(add(enc, 0x20))
|
||||
}
|
||||
}
|
||||
|
||||
/// @notice Public method that handles `address`
|
||||
/// to `uint256` safe type casting.
|
||||
/// @dev Function sighash: 0x4b2ae980.
|
||||
|
||||
@@ -8,6 +8,8 @@ abstract contract Constants {
|
||||
0x0b294da292f26e55fd442b5c0164fbb9013036ff00c5cfdde0efd01c1baaf632;
|
||||
uint256 constant _ALLOWED_ERC20_UPDATED_EVENT_SIGNATURE =
|
||||
0x5d6e86e5341d57a92c49934296c51542a25015c9b1782a1c2722a940131c3d9a;
|
||||
uint256 constant _TRUSTED_FORWARDER_UPDATED_EVENT_SIGNATURE =
|
||||
0xbee55516e29d3969d3cb8eb01351eb3c52d06f9e2435bd5a8bfe3647e185df92;
|
||||
|
||||
/// @dev Seller casted to key => Seller's allowlist merkleroot.
|
||||
/// mapping(uint256 => bytes32) public sellerAllowList;
|
||||
@@ -18,12 +20,12 @@ abstract contract Constants {
|
||||
|
||||
/// @dev `balance` max. value = 10**26.
|
||||
/// @dev `pixTarget` keys are restricted to 160 bits.
|
||||
/// mapping(uint256 => mapping(ERC20 => uint256)) public sellerBalance;
|
||||
/// mapping(uint256 => mapping(ERC20 => { `uint256`, `uint96` } )) public sellerBalance;
|
||||
|
||||
/// @dev Bits layout:
|
||||
/// `bytes32` [0...255] := pixTarget
|
||||
/// `uint96` [0...94] := balance
|
||||
/// `uint160` [95...254] := pixTarget
|
||||
/// `bool` [255] := valid
|
||||
/// `bool` [95] := valid
|
||||
|
||||
/// @dev Value in custom storage slot given by:
|
||||
/// mstore(0x20, token)
|
||||
@@ -34,12 +36,10 @@ abstract contract Constants {
|
||||
|
||||
/// @dev The bitmask of `sellerBalance` entry.
|
||||
uint256 constant BITMASK_SB_ENTRY = (1 << 94) - 1;
|
||||
/// @dev The bit position of `pixTarget` in `sellerBalance`.
|
||||
uint256 constant BITPOS_PIXTARGET = 95;
|
||||
/// @dev The bit position of `valid` in `sellerBalance`.
|
||||
uint256 constant BITPOS_VALID = 255;
|
||||
uint256 constant BITPOS_VALID = 95;
|
||||
/// @dev The bitmask of all 256 bits of `sellerBalance` except for the last one.
|
||||
uint256 constant BITMASK_VALID = (1 << 255) - 1;
|
||||
// uint256 constant BITMASK_VALID = (1 << 255) - 1;
|
||||
|
||||
/// @dev The scalar of BRZ token.
|
||||
uint256 constant WAD = 1e18;
|
||||
|
||||
@@ -3,15 +3,13 @@ pragma solidity 0.8.19;
|
||||
|
||||
library DataTypes {
|
||||
struct Lock {
|
||||
uint80 amount;
|
||||
uint160 pixTarget;
|
||||
address token;
|
||||
/// @dev Amount to be tranfered via PIX.
|
||||
address buyerAddress;
|
||||
uint256 sellerKey;
|
||||
uint256 counter;
|
||||
/// @dev If not paid at this block will be expired.
|
||||
uint256 expirationBlock;
|
||||
bytes32 pixTarget;
|
||||
uint80 amount;
|
||||
address token;
|
||||
address buyerAddress;
|
||||
}
|
||||
|
||||
// prettier-ignore
|
||||
|
||||
@@ -57,6 +57,11 @@ interface EventAndErrors {
|
||||
address indexed token,
|
||||
bool indexed state
|
||||
);
|
||||
/// @dev 0xbee55516e29d3969d3cb8eb01351eb3c52d06f9e2435bd5a8bfe3647e185df92
|
||||
event TrustedForwarderUpdated(
|
||||
address indexed forwarder,
|
||||
bool indexed state
|
||||
);
|
||||
/// @dev 0xe127cf589a3879da0156d4a24f43b44f65cfa3570de594806b0bfa2fcf06884f
|
||||
event ReputationUpdated(address reputation);
|
||||
/// @dev 0x70fa43ca70216ad905ade86b9e650a691b2ce5a01980d0a81bdd8324141b8511
|
||||
@@ -64,6 +69,7 @@ interface EventAndErrors {
|
||||
/// @dev 0x14a422d2412784a5749d03da98921fe468c98577b767851389a9f58ea5a363d7
|
||||
event ValidSignersUpdated(address[] signers);
|
||||
|
||||
|
||||
/// ███ Errors ████████████████████████████████████████████████████████████
|
||||
|
||||
/// @dev Only seller could call this function.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity 0.8.19;
|
||||
|
||||
import { ERC2771Context as ERC2771 } from "../lib/metatx/ERC2771Context.sol";
|
||||
import { ERC20, SafeTransferLib } from "../lib/utils/SafeTransferLib.sol";
|
||||
import { IReputation } from "../lib/interfaces/IReputation.sol";
|
||||
import { EventAndErrors } from "./EventAndErrors.sol";
|
||||
@@ -10,7 +11,8 @@ import { Owned } from "../lib/auth/Owned.sol";
|
||||
abstract contract OwnerSettings is
|
||||
Constants,
|
||||
EventAndErrors,
|
||||
Owned(msg.sender)
|
||||
Owned(msg.sender),
|
||||
ERC2771
|
||||
{
|
||||
/// ███ Storage ████████████████████████████████████████████████████████████
|
||||
|
||||
@@ -40,6 +42,48 @@ abstract contract OwnerSettings is
|
||||
|
||||
/// ███ Owner Only █████████████████████████████████████████████████████████
|
||||
|
||||
function setTrustedFowarders(
|
||||
address[] memory forwarders,
|
||||
bool[] memory states
|
||||
) external onlyOwner {
|
||||
assembly {
|
||||
// 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, isTrustedForwarder.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 Function sighash: 0x5fd8c710.
|
||||
function withdrawBalance() external onlyOwner {
|
||||
|
||||
Reference in New Issue
Block a user