increased lock gas savings

This commit is contained in:
PedroCailleret 2023-06-05 22:04:46 -03:00
parent 631c1d5dfb
commit 1a91b64024
4 changed files with 15 additions and 14 deletions

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/811e76435f5423608b4f8fda7811bf8e.json" "buildInfo": "../../build-info/eceac9979aa58fac0d83cf0060ae7a91.json"
} }

File diff suppressed because one or more lines are too long

View File

@ -150,10 +150,12 @@ contract P2PIX is BaseUtils {
uint256 bal = getBalance(args.seller, args.token); uint256 bal = getBalance(args.seller, args.token);
if (bal < args.amount) revert NotEnoughTokens(); if (bal < args.amount) revert NotEnoughTokens();
uint256 c = lockCounter + 1; unchecked {
lockID = ++lockCounter;
}
if ( if (
mapLocks[c].expirationBlock >= block.number mapLocks[lockID].expirationBlock >= block.number
) revert NotExpired(); ) revert NotExpired();
address sender; uint256 forwarder; address sender; uint256 forwarder;
@ -161,7 +163,7 @@ contract P2PIX is BaseUtils {
bytes32 _pixTarget = getPixTarget(args.seller, args.token); bytes32 _pixTarget = getPixTarget(args.seller, args.token);
DT.Lock memory l = DT.Lock( DT.Lock memory l = DT.Lock(
c, lockID,
(block.number + defaultLockBlocks), (block.number + defaultLockBlocks),
_pixTarget, _pixTarget,
args.amount, args.amount,
@ -172,15 +174,16 @@ contract P2PIX is BaseUtils {
if (args.merkleProof.length != 0) { if (args.merkleProof.length != 0) {
_merkleVerify(args.merkleProof, sellerAllowList(args.seller), sender); _merkleVerify(args.merkleProof, sellerAllowList(args.seller), sender);
lockID = _addLock(bal, l); _addLock(bal, l);
} else { } else {
if (l.amount <= REPUTATION_LOWERBOUND) { if (l.amount <= REPUTATION_LOWERBOUND) {
lockID = _addLock(bal, l); _addLock(bal, l);
} else { } else {
if (forwarder != 0) { if (forwarder != 0) {
lockID = _addLock(bal, l); _addLock(bal, l);
} else { } else {
uint256 spendLimit; uint256 userCredit = uint256 spendLimit; uint256 userCredit =
userRecord[_castAddrToKey(msg.sender)]; userRecord[_castAddrToKey(msg.sender)];
@ -189,7 +192,7 @@ contract P2PIX is BaseUtils {
l.amount > (spendLimit * WAD) || l.amount > (spendLimit * WAD) ||
l.amount > LOCKAMOUNT_UPPERBOUND l.amount > LOCKAMOUNT_UPPERBOUND
) revert AmountNotAllowed(); ) revert AmountNotAllowed();
lockID = _addLock(bal, l); _addLock(bal, l);
/* */}/* */}/* */} /* */}/* */}/* */}
} }
@ -387,12 +390,10 @@ contract P2PIX is BaseUtils {
function _addLock( function _addLock(
uint256 _bal, uint256 _bal,
DT.Lock memory _l DT.Lock memory _l
) internal returns(uint256 counter){ ) internal {
mapLocks[_l.counter] = _l; mapLocks[_l.counter] = _l;
_decBal(_bal, _l.amount, ERC20(_l.token), _l.seller); _decBal(_bal, _l.amount, ERC20(_l.token), _l.seller);
++lockCounter;
counter = _l.counter;
emit LockAdded( emit LockAdded(
_l.buyerAddress, _l.buyerAddress,

File diff suppressed because one or more lines are too long