restore function parameters. reverts 26a4952

This commit is contained in:
hueso 2024-02-13 15:13:36 -03:00
parent db7407e299
commit f02dad07c8
2 changed files with 51 additions and 66 deletions

View File

@ -4,27 +4,6 @@ pragma solidity 0.8.19;
import { ERC20 } from "contracts/lib/tokens/ERC20.sol"; import { ERC20 } from "contracts/lib/tokens/ERC20.sol";
library DataTypes { library DataTypes {
struct DepositArgs {
string pixTarget;
bytes32 allowlistRoot;
ERC20 token;
uint96 amount;
bool valid;
}
struct LockArgs {
address seller;
ERC20 token;
uint80 amount;
bytes32[] merkleProof;
uint256[] expiredLocks;
}
struct ReleaseArgs {
uint256 lockID;
bytes32 pixTimestamp;
bytes signature;
}
struct Lock { struct Lock {
uint256 counter; uint256 counter;

View File

@ -18,9 +18,6 @@ contract P2PIX is BaseUtils {
// solhint-disable no-inline-assembly // solhint-disable no-inline-assembly
// solhint-disable no-empty-blocks // solhint-disable no-empty-blocks
using DT for DT.DepositArgs;
using DT for DT.LockArgs;
using DT for DT.ReleaseArgs;
using DT for DT.Lock; using DT for DT.Lock;
using DT for DT.LockStatus; using DT for DT.LockStatus;
@ -55,50 +52,54 @@ contract P2PIX is BaseUtils {
/// @notice Creates a deposit order based on a seller's /// @notice Creates a deposit order based on a seller's
/// offer of an amount of ERC20 tokens. /// offer of an amount of ERC20 tokens.
/// @dev Seller needs to send his tokens to the P2PIX smart contract. /// @notice Seller needs to send his tokens to the P2PIX smart contract.
/* /// @param _pixTarget Pix key destination provided by the offer's seller. */ /// @param pixTarget Pix key destination provided by the offer's seller.
/* /// @param allowlistRoot Optional allow list merkleRoot update `bytes32` value. */ /// @param allowlistRoot Optional allow list merkleRoot update `bytes32` value.
/* /// as the deposit identifier. */ /// as the deposit identifier.
/// @dev Function sighash: 0xbfe07da6. /// @dev Function sighash: 0xbfe07da6.
function deposit( function deposit(
DT.DepositArgs calldata args string calldata pixTarget,
bytes32 allowlistRoot,
ERC20 token,
uint96 amount,
bool valid
) public { ) public {
if (bytes(args.pixTarget).length == 0) revert EmptyPixTarget(); if (bytes(pixTarget).length == 0) revert EmptyPixTarget();
if (!allowedERC20s(args.token)) revert TokenDenied(); if (!allowedERC20s(token)) revert TokenDenied();
uint256 _sellerBalance = __sellerBalance(msg.sender, args.token); uint256 _sellerBalance = __sellerBalance(msg.sender, token);
uint256 currBal = _sellerBalance & BITMASK_SB_ENTRY; uint256 currBal = _sellerBalance & BITMASK_SB_ENTRY;
uint256 _newBal = uint256(currBal + args.amount); uint256 _newBal = uint256(currBal + amount);
if (_newBal > MAXBALANCE_UPPERBOUND) if (_newBal > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded(); revert MaxBalExceeded();
setReentrancyGuard(); setReentrancyGuard();
if (args.allowlistRoot != 0) { if (allowlistRoot != 0) {
setRoot(msg.sender, args.allowlistRoot); setRoot(msg.sender, allowlistRoot);
} }
bytes32 pixTargetCasted = getStr(args.pixTarget); bytes32 pixTargetCasted = getStr(pixTarget);
uint256 validCasted = _castBool(args.valid); uint256 validCasted = _castBool(valid);
_setSellerBalance( _setSellerBalance(
msg.sender, msg.sender,
args.token, token,
(_newBal | (validCasted << BITPOS_VALID)), (_newBal | (validCasted << BITPOS_VALID)),
pixTargetCasted pixTargetCasted
); );
SafeTransferLib.safeTransferFrom( SafeTransferLib.safeTransferFrom(
args.token, token,
msg.sender, msg.sender,
address(this), address(this),
args.amount amount
); );
clearReentrancyGuard(); clearReentrancyGuard();
emit DepositAdded(msg.sender, args.token, args.amount); emit DepositAdded(msg.sender, token, amount);
} }
/// @notice Enables seller to invalidate future /// @notice Enables seller to invalidate future
@ -132,23 +133,26 @@ contract P2PIX is BaseUtils {
/// @dev There can only exist a lock per each `_amount` partitioned /// @dev There can only exist a lock per each `_amount` partitioned
/// from the total `remaining` value. /// from the total `remaining` value.
/// @dev Locks can only be performed in valid orders. /// @dev Locks can only be performed in valid orders.
/* /// @param _amount The deposit's remaining amount wished to be locked. */ /// @param amount The deposit's remaining amount wished to be locked.
/* /// @param merkleProof This value should be: */ /// @param merkleProof Provided as a pass if the `msg.sender` is in the
/* /// - Provided as a pass if the `msg.sender` is in the seller's allowlist; */ /// seller's allowlist; Left empty otherwise;
/* /// - Left empty otherwise; */ /// @param expiredLocks An array of `bytes32` identifiers to be
/* /// @param expiredLocks An array of `bytes32` identifiers to be */ /// provided so to unexpire locks using this transaction gas push.
/* /// provided so to unexpire locks using this transaction gas push. */
/// @return lockID The `bytes32` value returned as the lock identifier. /// @return lockID The `bytes32` value returned as the lock identifier.
/// @dev Function sighash: 0x03aaf306. /// @dev Function sighash: 0x03aaf306.
function lock( function lock(
DT.LockArgs calldata args address seller,
ERC20 token,
uint80 amount,
bytes32[] calldata merkleProof,
uint256[] calldata expiredLocks
) public nonReentrant returns (uint256 lockID) { ) public nonReentrant returns (uint256 lockID) {
unlockExpired(args.expiredLocks); unlockExpired(expiredLocks);
if (!getValid(args.seller, args.token)) revert InvalidDeposit(); if (!getValid(seller, token)) revert InvalidDeposit();
uint256 bal = getBalance(args.seller, args.token); uint256 bal = getBalance(seller, token);
if (bal < args.amount) revert NotEnoughTokens(); if (bal < amount) revert NotEnoughTokens();
unchecked { unchecked {
lockID = ++lockCounter; lockID = ++lockCounter;
@ -158,22 +162,22 @@ contract P2PIX is BaseUtils {
mapLocks[lockID].expirationBlock >= block.number mapLocks[lockID].expirationBlock >= block.number
) revert NotExpired(); ) revert NotExpired();
bytes32 _pixTarget = getPixTarget(args.seller, args.token); bytes32 _pixTarget = getPixTarget(seller, token);
// transaction forwarding must leave `merkleProof` empty; // transaction forwarding must leave `merkleProof` empty;
// otherwise, the trustedForwarder must be previously added // otherwise, the trustedForwarder must be previously added
// to a seller whitelist. // to a seller whitelist.
if (args.merkleProof.length != 0) { if (merkleProof.length != 0) {
_merkleVerify( args.merkleProof, sellerAllowList(args.seller), _msgSender()); _merkleVerify( merkleProof, sellerAllowList(seller), _msgSender());
} else if ( args.amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) { } else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) {
uint256 spendLimit; uint256 userCredit = uint256 spendLimit; uint256 userCredit =
userRecord[_castAddrToKey(_msgSender())]; userRecord[_castAddrToKey(_msgSender())];
(spendLimit) = _limiter(userCredit / WAD); (spendLimit) = _limiter(userCredit / WAD);
if ( if (
args.amount > (spendLimit * WAD) || amount > (spendLimit * WAD) ||
args.amount > LOCKAMOUNT_UPPERBOUND amount > LOCKAMOUNT_UPPERBOUND
) revert AmountNotAllowed(); ) revert AmountNotAllowed();
} }
@ -181,10 +185,10 @@ contract P2PIX is BaseUtils {
lockID, lockID,
(block.number + defaultLockBlocks), (block.number + defaultLockBlocks),
_pixTarget, _pixTarget,
args.amount, amount,
args.token, token,
_msgSender(), _msgSender(),
args.seller seller
); );
_addLock(bal, l); _addLock(bal, l);
@ -203,9 +207,11 @@ contract P2PIX is BaseUtils {
/// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit; /// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit;
/// @dev Function sighash: 0x4e1389ed. /// @dev Function sighash: 0x4e1389ed.
function release( function release(
DT.ReleaseArgs calldata args uint256 lockID,
bytes32 pixTimestamp,
bytes calldata signature
) public nonReentrant { ) public nonReentrant {
DT.Lock storage l = mapLocks[args.lockID]; DT.Lock storage l = mapLocks[lockID];
if (l.amount == 0) revert AlreadyReleased(); if (l.amount == 0) revert AlreadyReleased();
if (l.expirationBlock < block.number) if (l.expirationBlock < block.number)
@ -215,11 +221,11 @@ contract P2PIX is BaseUtils {
abi.encodePacked( abi.encodePacked(
l.pixTarget, l.pixTarget,
l.amount, l.amount,
args.pixTimestamp pixTimestamp
) )
); );
_signerCheck(message, args.signature); _signerCheck(message, signature);
ERC20 t = ERC20(l.token); ERC20 t = ERC20(l.token);
@ -244,7 +250,7 @@ contract P2PIX is BaseUtils {
lockAmount lockAmount
); );
emit LockReleased(l.buyerAddress, args.lockID, lockAmount); emit LockReleased(l.buyerAddress, lockID, lockAmount);
} }
/// @notice Unlocks expired locks. /// @notice Unlocks expired locks.