feat: deployment scripts fixed and lock fx unit tests added

This commit is contained in:
PedroCailleret
2022-12-07 12:43:57 -03:00
parent 1a4b4973d4
commit d541e7b70c
17 changed files with 585 additions and 96 deletions

View File

@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
// prettier-ignore
interface EventAndErrors {
/// ███ Events ████████████████████████████████████████████████████████████
@@ -25,16 +26,29 @@ interface EventAndErrors {
uint256 depositID,
uint256 amount
);
event LockReleased(address indexed buyer, bytes32 lockId);
event LockReturned(address indexed buyer, bytes32 lockId);
event FundsWithdrawn(address owner, uint256 amount);
event ReputationUpdated(address reputation);
event LockBlocksUpdated(uint256 blocks);
event ValidSignersUpdated(address[] signers);
event LockReleased(
address indexed buyer,
bytes32 lockId
);
event LockReturned(
address indexed buyer,
bytes32 lockId
);
event FundsWithdrawn(
address owner,
uint256 amount
);
event RootUpdated(
address seller,
bytes32 merkleRoot
);
event AllowedERC20Updated(
address indexed token,
bool indexed state
);
event ReputationUpdated(address reputation);
event LockBlocksUpdated(uint256 blocks);
event ValidSignersUpdated(address[] signers);
/// ███ Errors ████████████████████████████████████████████████████████████

View File

@@ -194,40 +194,29 @@ contract P2PIX is
msg.sender
);
mapLocks[lockID] = l;
d.remaining -= _amount;
emit LockAdded(
_buyerAddress,
lockID,
l.depositID,
_amount
);
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
} else {
uint256 userCredit = userRecord[
_castAddrToKey(msg.sender)
];
uint256 spendLimit;
(spendLimit) = _limiter(userCredit);
if (l.amount <= 1e2) {
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
} else {
uint256 userCredit = userRecord[
_castAddrToKey(msg.sender)
];
uint256 spendLimit;
(spendLimit) = _limiter(userCredit);
if (l.amount > spendLimit || l.amount > 1e6)
revert AmountNotAllowed();
if (l.amount > spendLimit || l.amount > 1e6)
revert AmountNotAllowed();
mapLocks[lockID] = l;
d.remaining -= _amount;
emit LockAdded(
_buyerAddress,
lockID,
l.depositID,
_amount
);
// Halt execution and output `lockID`.
return lockID;
_addLock(lockID, l, d);
// Halt execution and output `lockID`.
return lockID;
}
}
}
@@ -417,6 +406,10 @@ contract P2PIX is
sellerAllowList[
_castAddrToKey(addr)
] = merkleroot;
emit RootUpdated(
addr,
merkleroot
);
} else revert OnlySeller();
}
@@ -587,6 +580,22 @@ contract P2PIX is
revert DepositAlreadyExists();
}
function _addLock(
bytes32 _lockID,
DT.Lock memory _l,
DT.Deposit storage _d
) internal {
mapLocks[_lockID] = _l;
_d.remaining -= _l.amount;
emit LockAdded(
_l.buyerAddress,
_lockID,
_l.depositID,
_l.amount
);
}
/// @notice Private view auxiliar logic that encodes/returns
/// the `bytes32` identifier of an lock.
/// @dev reverts on a not expired lock with the same ID passed