5 Commits

Author SHA1 Message Date
hueso
98dda3c61f OZ v5.5.0 2025-11-03 13:59:01 -03:00
hueso
4d1a24ecdf bump OZ version to 5.5.0-rc.1 2025-10-24 21:52:45 -03:00
hueso
d9b93fe7d5 restore trustedForwarders as an OZ override 2025-10-24 21:50:21 -03:00
hueso
f56335d9b5 import ECDSA, ERC2771, ERC20, MerkleProofLib from @openzeppelin 2025-10-16 14:38:49 -03:00
hueso
407ea51d6a WIP: use openzeppelin contracts 2025-08-02 21:12:00 -03:00
19 changed files with 36 additions and 618 deletions

View File

@@ -3,9 +3,10 @@ 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 { MerkleProofLib as Merkle } from "contracts/lib/utils/MerkleProofLib.sol"; import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
import { ReentrancyGuard } from "contracts/lib/utils/ReentrancyGuard.sol"; import { MerkleProof as Merkle } from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
abstract contract BaseUtils is abstract contract BaseUtils is
OwnerSettings, OwnerSettings,
@@ -43,8 +44,8 @@ abstract contract BaseUtils is
if ( if (
!validBacenSigners( !validBacenSigners(
_castAddrToKey( _castAddrToKey(
ECDSA.recoverCalldata( ECDSA.recover(
ECDSA.toEthSignedMessageHash( MessageHashUtils.toEthSignedMessageHash(
_message _message
), ),
_signature _signature

View File

@@ -44,5 +44,4 @@ abstract contract Constants {
uint256 constant MAXBALANCE_UPPERBOUND = 1e8 ether; uint256 constant MAXBALANCE_UPPERBOUND = 1e8 ether;
uint256 constant REPUTATION_LOWERBOUND = 1e2 ether; uint256 constant REPUTATION_LOWERBOUND = 1e2 ether;
uint256 constant LOCKAMOUNT_UPPERBOUND = 1e6 ether; uint256 constant LOCKAMOUNT_UPPERBOUND = 1e6 ether;
uint256 constant BOND_DIVISOR = 4; // 6,25%
} }

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.19; pragma solidity ^0.8.19;
import { ERC20 } from "contracts/lib/tokens/ERC20.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
library DataTypes { library DataTypes {
@@ -13,7 +13,6 @@ library DataTypes {
ERC20 token; ERC20 token;
address buyerAddress; address buyerAddress;
address seller; address seller;
bool bond;
} }
// prettier-ignore // prettier-ignore

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.19; pragma solidity ^0.8.19;
import { ERC20 } from "contracts/lib/tokens/ERC20.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
// prettier-ignore // prettier-ignore
interface EventAndErrors { interface EventAndErrors {

View File

@@ -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 { ERC2771 } from "contracts/lib/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";

View File

@@ -1,87 +1,14 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >=0.8.4; pragma solidity ^0.8.20;
/// @author OpenZeppelin Contracts v4.4.1 (utils/Context.sol) import { ERC2771Context } from "@openzeppelin/contracts/metatx/ERC2771Context.sol";
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Context.sol)
/// @dev Provides information about the current execution context, including the abstract contract ERC2771 is ERC2771Context(address(0)) {
/// sender of the transaction and its data. While these are generally available
/// via msg.sender and msg.data, they should not be accessed in such a direct
/// manner, since when dealing with meta-transactions the account sending and
/// paying for execution may not be the actual sender (as far as an application
/// is concerned).
///
/// This contract is only required for intermediate, library-like contracts.
abstract contract Context {
function _msgSender()
internal
view
virtual
returns (address)
{
return msg.sender;
}
function _msgData()
internal
view
virtual
returns (bytes calldata)
{
return msg.data;
}
}
/// @author Modified from OpenZeppelin Contracts (last updated v4.7.0) (metatx/ERC2771Context.sol)
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/metatx/ERC2771Context.sol
/// @dev Context variant with ERC2771 support.
abstract contract ERC2771Context is Context {
// address private immutable _trustedForwarder;
mapping(address => bool) public trustedForwarders; mapping(address => bool) public trustedForwarders;
/// @custom:oz-upgrades-unsafe-allow constructor function isTrustedForwarder(address forwarder) public view override returns (bool) {
// constructor(address trustedForwarder) {
// _trustedForwarder = trustedForwarder;
// }
function _msgSender()
internal
view
virtual
override
returns (address sender)
{
if (trustedForwarders[msg.sender]) {
// The assembly code is more direct than the Solidity version using `abi.decode`.
/// @solidity memory-safe-assembly
assembly {
sender := shr(
96,
calldataload(sub(calldatasize(), 20))
)
}
} else {
return super._msgSender();
}
}
function isTrustedForwarder(address forwarder) public view virtual returns (bool) {
return trustedForwarders[forwarder]; return trustedForwarders[forwarder];
} }
function _msgData()
internal
view
virtual
override
returns (bytes calldata)
{
if (isTrustedForwarder(msg.sender)) {
return msg.data[:msg.data.length - 20];
} else {
return super._msgData();
}
}
} }

View File

@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity ^0.8.19; pragma solidity ^0.8.19;
import { ERC20 } from "../tokens/ERC20.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MockToken is ERC20 { contract MockToken is ERC20 {
constructor(uint256 supply) ERC20("MockBRL", "MBRL", 18) { constructor(uint256 supply) ERC20("MockBRL", "MBRL") {
_mint(msg.sender, supply); _mint(msg.sender, supply);
} }

View File

@@ -1,250 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(
address indexed from,
address indexed to,
uint256 amount
);
event Approval(
address indexed owner,
address indexed spender,
uint256 amount
);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256))
public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(
string memory _name,
string memory _symbol,
uint8 _decimals
) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(
address spender,
uint256 amount
) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(
address to,
uint256 amount
) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(
address from,
address to,
uint256 amount
) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max)
allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(
deadline >= block.timestamp,
"PERMIT_DEADLINE_EXPIRED"
);
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(
recoveredAddress != address(0) &&
recoveredAddress == owner,
"INVALID_SIGNER"
);
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR()
public
view
virtual
returns (bytes32)
{
return
block.chainid == INITIAL_CHAIN_ID
? INITIAL_DOMAIN_SEPARATOR
: computeDomainSeparator();
}
function computeDomainSeparator()
internal
view
virtual
returns (bytes32)
{
return
keccak256(
abi.encode(
keccak256(
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(
address to,
uint256 amount
) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(
address from,
uint256 amount
) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}

View File

@@ -1,95 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/// @notice Gas optimized ECDSA wrapper.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/ECDSA.sol)
/// @author Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/ECDSA.sol)
/// @author Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/ECDSA.sol)
library ECDSA {
/// @dev The signature is invalid.
error InvalidSignature();
/// @dev The number which `s` must not exceed in order for
/// the signature to be non-malleable.
bytes32 private constant _MALLEABILITY_THRESHOLD =
0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0;
/// @dev Recovers the signer's address from a message digest `hash`,
/// and the `signature`.
///
/// This function does NOT accept EIP-2098 short form signatures.
/// Use `recover(bytes32 hash, bytes32 r, bytes32 vs)` for EIP-2098
/// short form signatures instead.
function recoverCalldata(
bytes32 hash,
bytes calldata signature
) internal view returns (address result) {
/// @solidity memory-safe-assembly
assembly {
// Copy the free memory pointer so that we can restore it later.
let m := mload(0x40)
// Directly copy `r` and `s` from the calldata.
calldatacopy(0x40, signature.offset, 0x40)
// Store the `hash` in the scratch space.
mstore(0x00, hash)
// Compute `v` and store it in the scratch space.
mstore(
0x20,
byte(
0,
calldataload(add(signature.offset, 0x40))
)
)
pop(
staticcall(
gas(), // Amount of gas left for the transaction.
and(
// If the signature is exactly 65 bytes in length.
eq(signature.length, 65),
// If `s` in lower half order, such that the signature is not malleable.
lt(
mload(0x60),
add(_MALLEABILITY_THRESHOLD, 1)
)
), // Address of `ecrecover`.
0x00, // Start of input.
0x80, // Size of input.
0x00, // Start of output.
0x20 // Size of output.
)
)
result := mload(0x00)
// `returndatasize()` will be `0x20` upon success, and `0x00` otherwise.
if iszero(returndatasize()) {
// Store the function selector of `InvalidSignature()`.
mstore(0x00, 0x8baa579f)
// Revert with (offset, size).
revert(0x1c, 0x04)
}
// Restore the zero slot.
mstore(0x60, 0)
// Restore the free memory pointer.
mstore(0x40, m)
}
}
/// @dev Returns an Ethereum Signed Message, created from a `hash`.
/// This produces a hash corresponding to the one signed with the
/// [`eth_sign`](https://eth.wiki/json-rpc/API#eth_sign)
/// JSON-RPC method as part of EIP-191.
function toEthSignedMessageHash(
bytes32 hash
) internal pure returns (bytes32 result) {
/// @solidity memory-safe-assembly
assembly {
// Store into scratch space for keccak256.
mstore(0x20, hash)
mstore(
0x00,
"\x00\x00\x00\x00\x19Ethereum Signed Message:\n32"
)
// 0x40 - 0x04 = 0x3c
result := keccak256(0x04, 0x3c)
}
}
}

View File

@@ -1,58 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/// @notice Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.
/// @author Solady
/// (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from Solmate
/// (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)
/// @author Modified from OpenZeppelin
/// (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)
library MerkleProofLib {
/// @dev Returns whether `leaf` exists in the Merkle tree with `root`, given `proof`.
function verify(
bytes32[] calldata proof,
bytes32 root,
bytes32 leaf
) internal pure returns (bool isValid) {
/// @solidity memory-safe-assembly
assembly {
if proof.length {
// Left shift by 5 is equivalent to multiplying by 0x20.
let end := add(
proof.offset,
shl(5, proof.length)
)
// Initialize `offset` to the offset of `proof` in the calldata.
let offset := proof.offset
// Iterate over proof elements to compute root hash.
for {
} 1 {
} {
// Slot of `leaf` in scratch space.
// If the condition is true: 0x20, otherwise: 0x00.
let scratch := shl(
5,
gt(leaf, calldataload(offset))
)
// Store elements to hash contiguously in scratch space.
// Scratch space is 64 bytes (0x00 - 0x3f) and both elements are 32 bytes.
mstore(scratch, leaf)
mstore(
xor(scratch, 0x20),
calldataload(offset)
)
// Reuse `leaf` to store the hash to reduce stack operations.
leaf := keccak256(0x00, 0x40)
offset := add(offset, 0x20)
if iszero(lt(offset, end)) {
break
}
}
}
isValid := eq(leaf, root)
}
}
}

View File

@@ -1,34 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;
/// @notice Reentrancy protection for smart contracts.
/// @author z0r0z.eth
/// @author Modified from Seaport
/// (https://github.com/ProjectOpenSea/seaport/blob/main/contracts/lib/ReentrancyGuard.sol)
/// @author Modified from Solmate
/// (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)
abstract contract ReentrancyGuard {
error Reentrancy();
uint256 private guard = 1;
modifier nonReentrant() virtual {
setReentrancyGuard();
_;
clearReentrancyGuard();
}
/// @dev Check guard sentinel value and set it.
function setReentrancyGuard() internal virtual {
if (guard == 2) revert Reentrancy();
guard = 2;
}
/// @dev Unset sentinel value.
function clearReentrancyGuard() internal virtual {
guard = 1;
}
}

View File

@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >=0.8.4; pragma solidity >=0.8.4;
import { ERC20 } from "../tokens/ERC20.sol"; import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values. /// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol) /// @author Solady (https://github.com/vectorized/solady/blob/main/src/utils/SafeTransferLib.sol)

View File

@@ -135,8 +135,7 @@ contract P2PIX is BaseUtils {
ERC20 token, ERC20 token,
uint80 amount, uint80 amount,
bytes32[] calldata merkleProof, bytes32[] calldata merkleProof,
uint256[] calldata expiredLocks, uint256[] calldata expiredLocks
bool bond
) public nonReentrant returns (uint256 lockID) { ) public nonReentrant returns (uint256 lockID) {
unlockExpired(expiredLocks); unlockExpired(expiredLocks);
@@ -155,17 +154,10 @@ contract P2PIX is BaseUtils {
bytes32 _pixTarget = getPixTarget(seller, token); bytes32 _pixTarget = getPixTarget(seller, token);
if (bond){ // transaction forwarding must leave `merkleProof` empty;
SafeTransferLib.safeTransferFrom( // otherwise, the trustedForwarder must be previously added
token, // to a seller whitelist.
_msgSender(), if (merkleProof.length != 0) {
address(this),
amount >> BOND_DIVISOR
);
} else if (merkleProof.length != 0) {
// transaction forwarding must leave `merkleProof` empty;
// otherwise, the trustedForwarder must be previously added
// to a seller whitelist.
_merkleVerify( merkleProof, sellerAllowList(seller), _msgSender()); _merkleVerify( merkleProof, sellerAllowList(seller), _msgSender());
} else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) { } else if ( amount > REPUTATION_LOWERBOUND && msg.sender == _msgSender() ) {
@@ -186,8 +178,7 @@ contract P2PIX is BaseUtils {
amount, amount,
token, token,
_msgSender(), _msgSender(),
seller, seller
bond
); );
_addLock(bal, l); _addLock(bal, l);
@@ -246,7 +237,7 @@ contract P2PIX is BaseUtils {
SafeTransferLib.safeTransfer( SafeTransferLib.safeTransfer(
t, t,
l.buyerAddress, l.buyerAddress,
l.bond ? lockAmount + lockAmount >> BOND_DIVISOR : lockAmount lockAmount
); );
emit LockReleased(l.buyerAddress, lockID, lockAmount); emit LockReleased(l.buyerAddress, lockID, lockAmount);
@@ -275,7 +266,7 @@ contract P2PIX is BaseUtils {
if ((_sellerBalance + l.amount) > MAXBALANCE_UPPERBOUND) if ((_sellerBalance + l.amount) > MAXBALANCE_UPPERBOUND)
revert MaxBalExceeded(); revert MaxBalExceeded();
_addSellerBalance(l.seller, l.token, l.bond ? l.amount + l.amount >> BOND_DIVISOR : l.amount); _addSellerBalance(l.seller, l.token, l.amount);
l.amount = 0; l.amount = 0;

View File

@@ -94,9 +94,3 @@ uint256 REPUTATION_LOWERBOUND
uint256 LOCKAMOUNT_UPPERBOUND uint256 LOCKAMOUNT_UPPERBOUND
``` ```
### BOND_DIVISOR
```solidity
uint256 BOND_DIVISOR
```

View File

@@ -13,7 +13,6 @@ struct Lock {
contract ERC20 token; contract ERC20 token;
address buyerAddress; address buyerAddress;
address seller; address seller;
bool bond;
} }
``` ```

View File

@@ -67,7 +67,7 @@ _Function sighash: 0x6d82d9e0_
### lock ### lock
```solidity ```solidity
function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks, bool bond) public returns (uint256 lockID) function lock(address seller, contract ERC20 token, uint80 amount, bytes32[] merkleProof, uint256[] expiredLocks) public returns (uint256 lockID)
``` ```
Public method designed to lock an remaining amount of Public method designed to lock an remaining amount of
@@ -78,7 +78,7 @@ to a seller whitelist.
This method can be performed either by: This method can be performed either by:
- An user allowed via the seller's allowlist; - An user allowed via the seller's allowlist;
- An user with enough userRecord to lock the wished amount; - An user with enough userRecord to lock the wished amount;
There can only exist a lock per each `amount` partitioned There can only exist a lock per each `_amount` partitioned
from the total `remaining` value. from the total `remaining` value.
Locks can only be performed in valid orders. Locks can only be performed in valid orders.
@@ -93,7 +93,6 @@ _Function sighash: 0xdc43221c_
| amount | uint80 | The deposit's remaining amount wished to be locked. | | amount | uint80 | The deposit's remaining amount wished to be locked. |
| merkleProof | bytes32[] | Provided as a pass if the `msg.sender` is in the seller's allowlist; Left empty otherwise; | | merkleProof | bytes32[] | Provided as a pass if the `msg.sender` is in the seller's allowlist; Left empty otherwise; |
| expiredLocks | uint256[] | An array of identifiers to be provided so to unexpire locks using this transaction gas push. | | expiredLocks | uint256[] | An array of identifiers to be provided so to unexpire locks using this transaction gas push. |
| bond | bool | |
#### Return Values #### Return Values

View File

@@ -38,6 +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.5.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",

View File

@@ -615,7 +615,6 @@ describe("P2PIX", () => {
price, price,
[], [],
[], [],
false,
); );
const fail2 = p2pix.lock( const fail2 = p2pix.lock(
zero, zero,
@@ -623,7 +622,6 @@ describe("P2PIX", () => {
price, price,
[], [],
[], [],
false,
); );
expect(fail).to.be.revertedWithCustomError( expect(fail).to.be.revertedWithCustomError(
@@ -653,7 +651,6 @@ describe("P2PIX", () => {
price * 2n, price * 2n,
[], [],
[], [],
false,
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@@ -679,7 +676,6 @@ describe("P2PIX", () => {
1000n, 1000n,
[ethers.keccak256(ethers.toUtf8Bytes("wrong"))], [ethers.keccak256(ethers.toUtf8Bytes("wrong"))],
[], [],
false,
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@@ -707,7 +703,6 @@ describe("P2PIX", () => {
price * 2n, price * 2n,
[], [],
[], [],
false,
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@@ -715,42 +710,6 @@ describe("P2PIX", () => {
P2PixErrors.AmountNotAllowed, P2PixErrors.AmountNotAllowed,
); );
}); });
it("should override spend limit if buyer pays the bond", async () => {
await erc20.approve(
p2pix.address,
price.mul(3),
);
await p2pix.deposit(
"1",
merkleRoot,
erc20.address,
price.mul(3),
true,
);
await erc20
.transfer(
acc02.address,
price,
);
await erc20
.connect(acc02)
.approve(
p2pix.address,
price.mul(30000),
);
const bond = p2pix
.connect(acc02)
.lock(
owner.address,
erc20.address,
price.mul(2),
[],
[],
true,
);
await expect(bond).to.be.ok;
});
it("should create a lock, update storage and emit events via the allowlist path", async () => { it("should create a lock, update storage and emit events via the allowlist path", async () => {
const target = "333"; const target = "333";
await erc20.approve(p2pix.target, price); await erc20.approve(p2pix.target, price);
@@ -769,7 +728,6 @@ describe("P2PIX", () => {
price, price,
proof, proof,
[], [],
false,
); );
const storage: Lock = await p2pix.mapLocks.staticCall( const storage: Lock = await p2pix.mapLocks.staticCall(
1, 1,
@@ -814,7 +772,6 @@ describe("P2PIX", () => {
price, price,
[], [],
[], [],
false,
); );
const storage: Lock = await p2pix.mapLocks.staticCall( const storage: Lock = await p2pix.mapLocks.staticCall(
1, 1,
@@ -874,7 +831,6 @@ describe("P2PIX", () => {
price, price,
[], [],
[], [],
false,
); );
await p2pix await p2pix
.connect(acc01) .connect(acc01)
@@ -891,7 +847,6 @@ describe("P2PIX", () => {
price + 1n, price + 1n,
[], [],
[], [],
false,
); );
const storage: Lock = await p2pix.mapLocks.staticCall( const storage: Lock = await p2pix.mapLocks.staticCall(
2, 2,
@@ -942,7 +897,6 @@ describe("P2PIX", () => {
newPrice, newPrice,
proof, proof,
[], [],
false,
); );
const storage1: Lock = await p2pix.mapLocks.staticCall( const storage1: Lock = await p2pix.mapLocks.staticCall(
1, 1,
@@ -959,7 +913,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const storage2: Lock = await p2pix.mapLocks.staticCall( const storage2: Lock = await p2pix.mapLocks.staticCall(
2, 2,
@@ -976,7 +929,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const storage3: Lock = await p2pix.mapLocks.staticCall( const storage3: Lock = await p2pix.mapLocks.staticCall(
3, 3,
@@ -1253,7 +1205,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
await mine(13); await mine(13);
@@ -1295,7 +1246,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
await p2pix.release( await p2pix.release(
@@ -1340,7 +1290,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
await p2pix await p2pix
@@ -1358,7 +1307,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
@@ -1400,7 +1348,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
@@ -1457,7 +1404,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
const acc01Key = await p2pix._castAddrToKey.staticCall( const acc01Key = await p2pix._castAddrToKey.staticCall(
acc01.address, acc01.address,
@@ -1622,7 +1568,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[], [],
false,
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
@@ -1632,7 +1577,6 @@ describe("P2PIX", () => {
BigInt(50), BigInt(50),
[], [],
[], [],
false,
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
@@ -1642,7 +1586,6 @@ describe("P2PIX", () => {
BigInt(25), BigInt(25),
[], [],
[], [],
false,
); );
const lockStatus1 = const lockStatus1 =
@@ -1812,7 +1755,6 @@ describe("P2PIX", () => {
BigInt(1), BigInt(1),
[], [],
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
const fail = p2pix.unlockExpired([lockID]); const fail = p2pix.unlockExpired([lockID]);
@@ -1851,7 +1793,6 @@ describe("P2PIX", () => {
BigInt(1), BigInt(1),
[], [],
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
// await mine(10); // await mine(10);
@@ -1885,7 +1826,6 @@ describe("P2PIX", () => {
BigInt(1), BigInt(1),
[], [],
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
await mine(11); await mine(11);
@@ -1949,7 +1889,6 @@ describe("P2PIX", () => {
price, price,
proof, proof,
[], [],
false,
); );
// as return values of non view functions can't be accessed // as return values of non view functions can't be accessed
// outside the evm, we fetch the lockID from the emitted event. // outside the evm, we fetch the lockID from the emitted event.
@@ -1989,7 +1928,6 @@ describe("P2PIX", () => {
BigInt(100), BigInt(100),
[], [],
[lockID], [lockID],
false
); );
const remaining = await p2pix.getBalance.staticCall( const remaining = await p2pix.getBalance.staticCall(
owner.address, owner.address,
@@ -2023,7 +1961,6 @@ describe("P2PIX", () => {
price, price,
proof, proof,
[], [],
false,
); );
const lockID = BigInt(1); const lockID = BigInt(1);
// mine blocks to expire lock // mine blocks to expire lock

View File

@@ -988,6 +988,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@openzeppelin/contracts@npm:5.5.0":
version: 5.5.0
resolution: "@openzeppelin/contracts@npm:5.5.0"
checksum: 10/5eb1a201e2e324280292077f68c8a4a2e450762798d3c990741b540b1b218c4fed143901647f8519e9abe239017bd29a455cb7e43aff25918ef110e4cdea7013
languageName: node
linkType: hard
"@pkgjs/parseargs@npm:^0.11.0": "@pkgjs/parseargs@npm:^0.11.0":
version: 0.11.0 version: 0.11.0
resolution: "@pkgjs/parseargs@npm:0.11.0" resolution: "@pkgjs/parseargs@npm:0.11.0"
@@ -4563,6 +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.5.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"