test: 🚧 Added fixtures for new test schema

This commit is contained in:
PedroCailleret 2022-12-03 01:17:48 -03:00
parent 4403541660
commit c69d82ccee
49 changed files with 931 additions and 1126 deletions

View File

@ -26,7 +26,9 @@
├── p2pix.sol ├── p2pix.sol
└── Reputation.sol └── Reputation.sol
``` ```
## Callgraph ## Callgraph
![Callgraph](docs/callgraph.svg) ![Callgraph](docs/callgraph.svg)
## Usage ## Usage
@ -76,16 +78,15 @@ $ yarn clean
To import artifacts on the project use the following: To import artifacts on the project use the following:
```ts ```ts
import P2PIXArtifact from 'p2pix-smart-contracts/artifacts/contracts/p2pix.sol/P2PIX.json' import P2PIXArtifact from "p2pix-smart-contracts/artifacts/contracts/p2pix.sol/P2PIX.json";
``` ```
To grab deployment addresses you can just grab from deploys folder: To grab deployment addresses you can just grab from deploys folder:
```ts ```ts
import localhostDeploys from 'p2pix-smart-contracts/deploys/localhost.json' import localhostDeploys from "p2pix-smart-contracts/deploys/localhost.json";
``` ```
## Deploying to local environment ## Deploying to local environment
On the first teminal, use the following command and import some wallets to your Metamask, then connect to the network pointed: On the first teminal, use the following command and import some wallets to your Metamask, then connect to the network pointed:

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

@ -63,6 +63,11 @@
"name": "OnlySeller", "name": "OnlySeller",
"type": "error" "type": "error"
}, },
{
"inputs": [],
"name": "StaticCallFailed",
"type": "error"
},
{ {
"inputs": [], "inputs": [],
"name": "TokenDenied", "name": "TokenDenied",

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

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

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

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

View File

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

View File

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

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

View File

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

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/eddb8a89a5d02f0c81c1106939df9c5f.json" "buildInfo": "../../build-info/727fbe6b5a53dc5c0af688ab7bc65edd.json"
} }

File diff suppressed because one or more lines are too long

View File

@ -17,11 +17,11 @@ library DataTypes {
struct Lock { struct Lock {
uint256 depositID; uint256 depositID;
/// @dev Amount to be paid for relayer. /// @dev Amount to be paid for relayer.
uint256 relayerPremium; uint256 relayerPremium;
/// @dev Amount to be tranfered via PIX. /// @dev Amount to be tranfered via PIX.
uint256 amount; uint256 amount;
/// @dev If not paid at this block will be expired. /// @dev If not paid at this block will be expired.
uint256 expirationBlock; uint256 expirationBlock;
/// @dev Where the tokens are sent the when order gets validated. /// @dev Where the tokens are sent the when order gets validated.
address buyerAddress; address buyerAddress;
/// @dev Relayer's target address that receives `relayerPremium` funds. /// @dev Relayer's target address that receives `relayerPremium` funds.

View File

@ -2,7 +2,6 @@
pragma solidity 0.8.9; pragma solidity 0.8.9;
interface EventAndErrors { interface EventAndErrors {
/// Events /// Events
event DepositAdded( event DepositAdded(

View File

@ -5,41 +5,43 @@ import { IReputation } from "./lib/interfaces/IReputation.sol";
import { Owned } from "./lib/auth/Owned.sol"; import { Owned } from "./lib/auth/Owned.sol";
import { FixedPointMathLib as WADMath } from "./lib/utils/FixedPointMathLib.sol"; import { FixedPointMathLib as WADMath } from "./lib/utils/FixedPointMathLib.sol";
contract Reputation is IReputation, Owned(msg.sender) {
using WADMath for uint256;
contract Reputation is /// @dev Asymptote numerator constant value for the `limiter` fx.
IReputation, uint256 public constant maxLimit = 1e6;
Owned(msg.sender) /// @dev Denominator's constant operand for the `limiter` fx.
{ uint256 public constant magicValue = 2.5e11;
using WADMath for uint256; constructor() /* */ {
/* */
/// @dev Asymptote numerator constant value for the `limiter` fx.
uint256 constant public maxLimit = 1e6;
/// @dev Denominator's constant operand for the `limiter` fx.
uint256 constant public magicValue = 2.5e11;
constructor(/* */) {/* */}
function limiter(uint256 _userCredit)
external
pure
override(IReputation)
returns(uint256 _spendLimit)
{
// _spendLimit = 1 + ( ( maxLimit * _userCredit ) / sqrt( magicValue * ( _userCredit * _userCredit ) ) );
// return _spendLimit;
unchecked {
uint256 numeratorWad =
maxLimit.mulWadDown(_userCredit);
uint256 userCreditSquaredWad =
_userCredit.mulWadDown(_userCredit);
uint256 denominatorSqrtWad =
(userCreditSquaredWad.mulWadDown(magicValue)).sqrt();
_spendLimit = (1 + (numeratorWad).divWadDown(denominatorSqrtWad));
} }
}
function limiter(
uint256 _userCredit
)
external
pure
override(IReputation)
returns (uint256 _spendLimit)
{
// _spendLimit = 1 + ( ( maxLimit * _userCredit ) / sqrt( magicValue * ( _userCredit * _userCredit ) ) );
// return _spendLimit;
unchecked {
uint256 numeratorWad = maxLimit.mulWadDown(
_userCredit
);
uint256 userCreditSquaredWad = _userCredit
.mulWadDown(_userCredit);
uint256 denominatorSqrtWad = (
userCreditSquaredWad.mulWadDown(magicValue)
).sqrt();
_spendLimit = (1 +
(numeratorWad).divWadDown(
denominatorSqrtWad
));
}
}
} }

View File

@ -1,12 +1,8 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >=0.8.4; pragma solidity >=0.8.4;
interface IReputation { interface IReputation {
function limiter(
function limiter(uint256 _userCredit) uint256 _userCredit
external ) external pure returns (uint256 _spendLimit);
pure
returns(uint256 _spendLimit);
} }

View File

@ -4,22 +4,27 @@ pragma solidity >=0.8.4;
/// @notice Arithmetic library with operations for fixed-point numbers. /// @notice Arithmetic library with operations for fixed-point numbers.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol) /// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)
library FixedPointMathLib { library FixedPointMathLib {
/*////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////
SIMPLIFIED FIXED POINT OPERATIONS SIMPLIFIED FIXED POINT OPERATIONS
//////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////*/
/// @dev The scalar of ETH and most ERC20s. /// @dev The scalar of ETH and most ERC20s.
uint256 internal constant WAD = 1e18; uint256 internal constant WAD = 1e18;
function mulWadDown(uint256 x, uint256 y) internal pure returns (uint256) { function mulWadDown(
uint256 x,
uint256 y
) internal pure returns (uint256) {
// Equivalent to (x * y) / WAD rounded down. // Equivalent to (x * y) / WAD rounded down.
return mulDivDown(x, y, WAD); return mulDivDown(x, y, WAD);
} }
function divWadDown(uint256 x, uint256 y) internal pure returns (uint256) { function divWadDown(
uint256 x,
uint256 y
) internal pure returns (uint256) {
// Equivalent to (x * WAD) / y rounded down. // Equivalent to (x * WAD) / y rounded down.
return mulDivDown(x, WAD, y); return mulDivDown(x, WAD, y);
} }
/*////////////////////////////////////////////////////////////// /*//////////////////////////////////////////////////////////////
@ -36,7 +41,12 @@ library FixedPointMathLib {
z := mul(x, y) z := mul(x, y)
// Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y)) // Equivalent to require(denominator != 0 && (x == 0 || (x * y) / x == y))
if iszero(and(iszero(iszero(denominator)), or(iszero(x), eq(div(z, x), y)))) { if iszero(
and(
iszero(iszero(denominator)),
or(iszero(x), eq(div(z, x), y))
)
) {
revert(0, 0) revert(0, 0)
} }
@ -49,7 +59,9 @@ library FixedPointMathLib {
GENERAL NUMBER UTILITIES GENERAL NUMBER UTILITIES
//////////////////////////////////////////////////////////////*/ //////////////////////////////////////////////////////////////*/
function sqrt(uint256 x) internal pure returns (uint256 z) { function sqrt(
uint256 x
) internal pure returns (uint256 z) {
assembly { assembly {
let y := x // We start y at x, which will help us make our initial estimate. let y := x // We start y at x, which will help us make our initial estimate.
@ -60,7 +72,9 @@ library FixedPointMathLib {
// We check y >= 2^(k + 8) but shift right by k bits // We check y >= 2^(k + 8) but shift right by k bits
// each branch to ensure that if x >= 256, then y >= 256. // each branch to ensure that if x >= 256, then y >= 256.
if iszero(lt(y, 0x10000000000000000000000000000000000)) { if iszero(
lt(y, 0x10000000000000000000000000000000000)
) {
y := shr(128, y) y := shr(128, y)
z := shl(64, z) z := shl(64, z)
} }
@ -112,4 +126,4 @@ library FixedPointMathLib {
z := sub(z, lt(div(x, z), z)) z := sub(z, lt(div(x, z), z))
} }
} }
} }

View File

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

View File

@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
pragma solidity >=0.8.4; pragma solidity >=0.8.4;
/// @notice Reentrancy protection for smart contracts. /// @notice Reentrancy protection for smart contracts.
/// @author z0r0z.eth /// @author z0r0z.eth
@ -31,4 +31,4 @@ abstract contract ReentrancyGuard {
function clearReentrancyGuard() internal virtual { function clearReentrancyGuard() internal virtual {
guard = 1; guard = 1;
} }
} }

View File

@ -82,12 +82,7 @@ contract P2PIX is
uint256 _amount, uint256 _amount,
string calldata _pixTarget, string calldata _pixTarget,
bytes32 allowlistRoot bytes32 allowlistRoot
) ) public returns (uint256 depositID) {
public
returns (
uint256 depositID
)
{
ERC20 t = ERC20(_token); ERC20 t = ERC20(_token);
if (!allowedERC20s[t]) revert TokenDenied(); if (!allowedERC20s[t]) revert TokenDenied();
@ -143,9 +138,9 @@ contract P2PIX is
/// @notice Public method designed to lock an remaining amount of /// @notice Public method designed to lock an remaining amount of
/// the deposit order of a seller. /// the deposit order of a seller.
/// @dev This method can be performed either by: /// @dev 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;
/// @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.
@ -153,7 +148,7 @@ contract P2PIX is
/// @param _relayerTarget Target address entitled to the `relayerPremium`. /// @param _relayerTarget Target address entitled to the `relayerPremium`.
/// @param _relayerPremium The refund/premium owed to a relayer. /// @param _relayerPremium The refund/premium owed to a relayer.
/// @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 This value should be:
/// - Provided as a pass if the `msg.sender` is in the seller's allowlist; /// - Provided as a pass if the `msg.sender` is in the 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
@ -211,8 +206,7 @@ contract P2PIX is
// Halt execution and output `lockID`. // Halt execution and output `lockID`.
return lockID; return lockID;
} } else {
else {
uint256 userCredit = userRecord[ uint256 userCredit = userRecord[
_castAddrToKey(msg.sender) _castAddrToKey(msg.sender)
]; ];
@ -239,15 +233,15 @@ contract P2PIX is
/// @notice Lock release method that liquidate lock /// @notice Lock release method that liquidate lock
/// orders and distributes relayer fees. /// orders and distributes relayer fees.
/// @dev This method can be called by any public actor /// @dev This method can be called by any public actor
/// as long the signature provided is valid. /// as long the signature provided is valid.
/// @dev `relayerPremium` gets splitted equaly /// @dev `relayerPremium` gets splitted equaly
/// if `relayerTarget` addresses differ. /// if `relayerTarget` addresses differ.
/// @dev If the `msg.sender` of this method and `l.relayerAddress` are the same, /// @dev If the `msg.sender` of this method and `l.relayerAddress` are the same,
/// `msg.sender` accrues both l.amount and l.relayerPremium as userRecord credit. /// `msg.sender` accrues both l.amount and l.relayerPremium as userRecord credit.
/// In case of they differing: /// In case of they differing:
/// - `lock` caller gets accrued with `l.amount` as userRecord credit; /// - `lock` caller gets accrued with `l.amount` as userRecord credit;
/// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit; /// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit;
/// @param _relayerTarget Target address entitled to the `relayerPremim`. /// @param _relayerTarget Target address entitled to the `relayerPremim`.
/// @dev Function sighash: 0x4e1389ed. /// @dev Function sighash: 0x4e1389ed.
function release( function release(
@ -342,12 +336,12 @@ contract P2PIX is
/// @notice Unlocks expired locks. /// @notice Unlocks expired locks.
/// @dev Triggered in the callgraph by both `lock` and `withdraw` functions. /// @dev Triggered in the callgraph by both `lock` and `withdraw` functions.
/// @dev This method can also have any public actor as its `tx.origin`. /// @dev This method can also have any public actor as its `tx.origin`.
/// @dev For each successfull unexpired lock recovered, /// @dev For each successfull unexpired lock recovered,
/// `userRecord[_castAddrToKey(l.relayerAddress)]` is decreased by half of its value. /// `userRecord[_castAddrToKey(l.relayerAddress)]` is decreased by half of its value.
/// @dev Function sighash: 0x8e2749d6. /// @dev Function sighash: 0x8e2749d6.
function unlockExpired(bytes32[] calldata lockIDs) function unlockExpired(
public bytes32[] calldata lockIDs
{ ) public {
uint256 i; uint256 i;
uint256 locksSize = lockIDs.length; uint256 locksSize = lockIDs.length;
@ -359,13 +353,14 @@ contract P2PIX is
mapDeposits[l.depositID].remaining += l.amount; mapDeposits[l.depositID].remaining += l.amount;
l.amount = 0; l.amount = 0;
uint256 userKey = uint256 userKey = _castAddrToKey(
_castAddrToKey(l.relayerAddress); l.relayerAddress
uint256 _newUserRecord = );
(userRecord[userKey] >> 1); uint256 _newUserRecord = (userRecord[userKey] >>
1);
if (_newUserRecord <= 100) { if (_newUserRecord <= 100) {
userRecord[userKey] = 100; userRecord[userKey] = 100;
} else { } else {
userRecord[userKey] = _newUserRecord; userRecord[userKey] = _newUserRecord;
} }
@ -414,9 +409,10 @@ contract P2PIX is
emit DepositWithdrawn(msg.sender, depositID, amount); emit DepositWithdrawn(msg.sender, depositID, amount);
} }
function setRoot(address addr, bytes32 merkleroot) function setRoot(
public address addr,
{ bytes32 merkleroot
) public {
if (addr == msg.sender) { if (addr == msg.sender) {
sellerAllowList[ sellerAllowList[
_castAddrToKey(addr) _castAddrToKey(addr)
@ -434,30 +430,27 @@ contract P2PIX is
emit FundsWithdrawn(msg.sender, balance); emit FundsWithdrawn(msg.sender, balance);
} }
function setReputation(IReputation _reputation) function setReputation(
public IReputation _reputation
onlyOwner ) public onlyOwner {
{
assembly { assembly {
sstore(reputation.slot, _reputation) sstore(reputation.slot, _reputation)
} }
emit ReputationUpdated(address(_reputation)); emit ReputationUpdated(address(_reputation));
} }
function setDefaultLockBlocks(uint256 _blocks) function setDefaultLockBlocks(
public uint256 _blocks
onlyOwner ) public onlyOwner {
{
assembly { assembly {
sstore(defaultLockBlocks.slot, _blocks) sstore(defaultLockBlocks.slot, _blocks)
} }
emit LockBlocksUpdated(_blocks); emit LockBlocksUpdated(_blocks);
} }
function setValidSigners(address[] memory _validSigners) function setValidSigners(
public address[] memory _validSigners
onlyOwner ) public onlyOwner {
{
unchecked { unchecked {
uint256 i; uint256 i;
uint256 len = _validSigners.length; uint256 len = _validSigners.length;
@ -626,11 +619,9 @@ contract P2PIX is
) revert AddressDenied(); ) revert AddressDenied();
} }
function _limiter(uint256 _userCredit) function _limiter(
internal uint256 _userCredit
view ) internal view returns (uint256 _spendLimit) {
returns (uint256 _spendLimit)
{
// enconde the fx sighash and args // enconde the fx sighash and args
bytes memory encodedParams = abi.encodeWithSelector( bytes memory encodedParams = abi.encodeWithSelector(
IReputation.limiter.selector, IReputation.limiter.selector,
@ -670,11 +661,9 @@ contract P2PIX is
/// @notice Public method that handles `address` /// @notice Public method that handles `address`
/// to `uint256` safe type casting. /// to `uint256` safe type casting.
/// @dev Function sighash: 0x4b2ae980. /// @dev Function sighash: 0x4b2ae980.
function _castAddrToKey(address _addr) function _castAddrToKey(
public address _addr
pure ) public pure returns (uint256 _key) {
returns (uint256 _key)
{
_key = uint256(uint160(address(_addr))) << 12; _key = uint256(uint160(address(_addr))) << 12;
} }
} }

View File

@ -5,4 +5,4 @@
], ],
"p2pix": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee", "p2pix": "0x294003F602c321627152c6b7DED3EAb5bEa853Ee",
"token": "0x5BdEa33E2D14E3D4C66f9A7bbbc38Cd785D0C592" "token": "0x5BdEa33E2D14E3D4C66f9A7bbbc38Cd785D0C592"
} }

View File

@ -1,12 +1 @@
# DataTypes # DataTypes

View File

@ -1,14 +1,5 @@
# EventAndErrors # EventAndErrors
## Events ## Events
### AllowedERC20Updated ### AllowedERC20Updated
@ -17,16 +8,12 @@
event AllowedERC20Updated(address indexed token, bool indexed state) event AllowedERC20Updated(address indexed token, bool indexed state)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| token `indexed` | address | undefined | | token `indexed` | address | undefined |
| state `indexed` | bool | undefined | | state `indexed` | bool | undefined |
### DepositAdded ### DepositAdded
@ -36,16 +23,14 @@ event DepositAdded(address indexed seller, uint256 depositID, address token, uin
███ Events ████████████████████████████████████████████████████████████ ███ Events ████████████████████████████████████████████████████████████
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| token | address | undefined | | token | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### DepositClosed ### DepositClosed
@ -53,16 +38,12 @@ event DepositAdded(address indexed seller, uint256 depositID, address token, uin
event DepositClosed(address indexed seller, uint256 depositID) event DepositClosed(address indexed seller, uint256 depositID)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
### DepositWithdrawn ### DepositWithdrawn
@ -70,17 +51,13 @@ event DepositClosed(address indexed seller, uint256 depositID)
event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount) event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### FundsWithdrawn ### FundsWithdrawn
@ -88,16 +65,12 @@ event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount
event FundsWithdrawn(address owner, uint256 amount) event FundsWithdrawn(address owner, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| owner | address | undefined | | owner | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### LockAdded ### LockAdded
@ -105,18 +78,14 @@ event FundsWithdrawn(address owner, uint256 amount)
event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount) event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockID `indexed` | bytes32 | undefined | | lockID `indexed` | bytes32 | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### LockBlocksUpdated ### LockBlocksUpdated
@ -124,15 +93,11 @@ event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID
event LockBlocksUpdated(uint256 blocks) event LockBlocksUpdated(uint256 blocks)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| blocks | uint256 | undefined | | blocks | uint256 | undefined |
### LockReleased ### LockReleased
@ -140,16 +105,12 @@ event LockBlocksUpdated(uint256 blocks)
event LockReleased(address indexed buyer, bytes32 lockId) event LockReleased(address indexed buyer, bytes32 lockId)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined | | lockId | bytes32 | undefined |
### LockReturned ### LockReturned
@ -157,16 +118,12 @@ event LockReleased(address indexed buyer, bytes32 lockId)
event LockReturned(address indexed buyer, bytes32 lockId) event LockReturned(address indexed buyer, bytes32 lockId)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined | | lockId | bytes32 | undefined |
### ReputationUpdated ### ReputationUpdated
@ -174,15 +131,11 @@ event LockReturned(address indexed buyer, bytes32 lockId)
event ReputationUpdated(address reputation) event ReputationUpdated(address reputation)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------- | ------- | ----------- |
| reputation | address | undefined | | reputation | address | undefined |
### ValidSignersUpdated ### ValidSignersUpdated
@ -190,17 +143,11 @@ event ReputationUpdated(address reputation)
event ValidSignersUpdated(address[] signers) event ValidSignersUpdated(address[] signers)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------- | --------- | ----------- |
| signers | address[] | undefined | | signers | address[] | undefined |
## Errors ## Errors
@ -210,10 +157,7 @@ event ValidSignersUpdated(address[] signers)
error AddressDenied() error AddressDenied()
``` ```
_Address doesn&#39;t exist in a MerkleTree.Address not allowed as relayer.0x3b8474be_
*Address doesn&#39;t exist in a MerkleTree.Address not allowed as relayer.0x3b8474be*
### AlreadyReleased ### AlreadyReleased
@ -221,10 +165,7 @@ error AddressDenied()
error AlreadyReleased() error AlreadyReleased()
``` ```
_Lock already released or returned.0x63b4904e_
*Lock already released or returned.0x63b4904e*
### AmountNotAllowed ### AmountNotAllowed
@ -232,10 +173,7 @@ error AlreadyReleased()
error AmountNotAllowed() error AmountNotAllowed()
``` ```
_Wished amount to be locked exceeds the limit allowed.0x1c18f846_
*Wished amount to be locked exceeds the limit allowed.0x1c18f846*
### DepositAlreadyExists ### DepositAlreadyExists
@ -243,10 +181,7 @@ error AmountNotAllowed()
error DepositAlreadyExists() error DepositAlreadyExists()
``` ```
_Deposit already exist and it is still valid.0xc44bd765_
*Deposit already exist and it is still valid.0xc44bd765*
### InvalidDeposit ### InvalidDeposit
@ -254,10 +189,7 @@ error DepositAlreadyExists()
error InvalidDeposit() error InvalidDeposit()
``` ```
_Deposit not valid anymore.0xb2e532de_
*Deposit not valid anymore.0xb2e532de*
### InvalidSigner ### InvalidSigner
@ -265,10 +197,7 @@ error InvalidDeposit()
error InvalidSigner() error InvalidSigner()
``` ```
_Signer is not a valid signer.0x815e1d64_
*Signer is not a valid signer.0x815e1d64*
### LengthMismatch ### LengthMismatch
@ -276,10 +205,7 @@ error InvalidSigner()
error LengthMismatch() error LengthMismatch()
``` ```
_Arrays&#39; length don&#39;t match.0xff633a38_
*Arrays&#39; length don&#39;t match.0xff633a38*
### LoopOverflow ### LoopOverflow
@ -287,10 +213,7 @@ error LengthMismatch()
error LoopOverflow() error LoopOverflow()
``` ```
_Loop bounds have overflowed.0xdfb035c9_
*Loop bounds have overflowed.0xdfb035c9*
### NoTokens ### NoTokens
@ -298,10 +221,7 @@ error LoopOverflow()
error NoTokens() error NoTokens()
``` ```
_No tokens array provided as argument.0xdf957883_
*No tokens array provided as argument.0xdf957883*
### NotEnoughTokens ### NotEnoughTokens
@ -309,10 +229,7 @@ error NoTokens()
error NotEnoughTokens() error NotEnoughTokens()
``` ```
_Not enough token remaining on deposit.0x22bbb43c_
*Not enough token remaining on deposit.0x22bbb43c*
### NotExpired ### NotExpired
@ -320,10 +237,7 @@ error NotEnoughTokens()
error NotExpired() error NotExpired()
``` ```
_Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85_
*Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85*
### OnlySeller ### OnlySeller
@ -331,10 +245,7 @@ error NotExpired()
error OnlySeller() error OnlySeller()
``` ```
_Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726_
*Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726*
### TokenDenied ### TokenDenied
@ -342,10 +253,7 @@ error OnlySeller()
error TokenDenied() error TokenDenied()
``` ```
_Token address not allowed to be deposited.0x1578328e_
*Token address not allowed to be deposited.0x1578328e*
### TxAlreadyUsed ### TxAlreadyUsed
@ -353,9 +261,4 @@ error TokenDenied()
error TxAlreadyUsed() error TxAlreadyUsed()
``` ```
_Transaction already used to unlock payment.0xf490a6ea_
*Transaction already used to unlock payment.0xf490a6ea*

View File

@ -1,16 +1,8 @@
# P2PIX # P2PIX
## Methods ## Methods
### _castAddrToKey ### \_castAddrToKey
```solidity ```solidity
function _castAddrToKey(address _addr) external pure returns (uint256 _key) function _castAddrToKey(address _addr) external pure returns (uint256 _key)
@ -18,19 +10,19 @@ function _castAddrToKey(address _addr) external pure returns (uint256 _key)
Public method that handles `address` to `uint256` safe type casting. Public method that handles `address` to `uint256` safe type casting.
*Function sighash: 0x4b2ae980.* _Function sighash: 0x4b2ae980._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| _addr | address | undefined | | \_addr | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ----- | ------- | ----------- |
| _key | uint256 | undefined | | \_key | uint256 | undefined |
### allowedERC20s ### allowedERC20s
@ -38,21 +30,19 @@ Public method that handles `address` to `uint256` safe type casting.
function allowedERC20s(contract ERC20) external view returns (bool) function allowedERC20s(contract ERC20) external view returns (bool)
``` ```
_Tokens allowed to serve as the underlying amount of a deposit._
*Tokens allowed to serve as the underlying amount of a deposit.*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | -------------- | ----------- |
| _0 | contract ERC20 | undefined | | \_0 | contract ERC20 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### cancelDeposit ### cancelDeposit
@ -62,13 +52,13 @@ function cancelDeposit(uint256 depositID) external nonpayable
Enables seller to invalidate future locks made to his/her token offering order. Enables seller to invalidate future locks made to his/her token offering order.
*This function does not affect any ongoing active locks.Function sighash: 0x72fada5c.* _This function does not affect any ongoing active locks.Function sighash: 0x72fada5c._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------- | ------- | ----------- |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
### defaultLockBlocks ### defaultLockBlocks
@ -76,16 +66,13 @@ Enables seller to invalidate future locks made to his/her token offering order.
function defaultLockBlocks() external view returns (uint256) function defaultLockBlocks() external view returns (uint256)
``` ```
_Default blocks that lock will hold tokens._
*Default blocks that lock will hold tokens.*
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### deposit ### deposit
@ -95,21 +82,21 @@ function deposit(address _token, uint256 _amount, string _pixTarget, bytes32 all
Creates a deposit order based on a seller&#39;s offer of an amount of ERC20 tokens. Creates a deposit order based on a seller&#39;s offer of an amount of ERC20 tokens.
*Seller needs to send his tokens to the P2PIX smart contract.Function sighash: 0xbfe07da6.* _Seller needs to send his tokens to the P2PIX smart contract.Function sighash: 0xbfe07da6._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------- | ------- | ------------------------------------------------------- |
| _token | address | undefined | | \_token | address | undefined |
| _amount | uint256 | undefined | | \_amount | uint256 | undefined |
| _pixTarget | string | Pix key destination provided by the offer&#39;s seller. | | \_pixTarget | string | Pix key destination provided by the offer&#39;s seller. |
| allowlistRoot | bytes32 | Optional allow list merkleRoot update `bytes32` value. | | allowlistRoot | bytes32 | Optional allow list merkleRoot update `bytes32` value. |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------- | ------- | -------------------------------------------------------------- |
| depositID | uint256 | The `uint256` return value provided as the deposit identifier. | | depositID | uint256 | The `uint256` return value provided as the deposit identifier. |
### depositCount ### depositCount
@ -118,16 +105,11 @@ Creates a deposit order based on a seller&#39;s offer of an amount of ERC20 toke
function depositCount() external view returns (uint256 _val) function depositCount() external view returns (uint256 _val)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ----- | ------- | ----------- |
| _val | uint256 | undefined | | \_val | uint256 | undefined |
### lock ### lock
@ -137,24 +119,24 @@ function lock(uint256 _depositID, address _buyerAddress, address _relayerTarget,
Public method designed to lock an remaining amount of the deposit order of a seller. Public method designed to lock an remaining amount of the deposit order of a seller.
*This method can be performed either by: - An user allowed via the seller&#39;s allowlist; - An user with enough userRecord to lock the wished amount; There can only exist a lock per each `_amount` partitioned from the total `remaining` value.Locks can only be performed in valid orders.Function sighash: 0x03aaf306.* _This method can be performed either by: - An user allowed via the seller&#39;s allowlist; - An user with enough userRecord to lock the wished amount; There can only exist a lock per each `_amount` partitioned from the total `remaining` value.Locks can only be performed in valid orders.Function sighash: 0x03aaf306._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------ |
| _depositID | uint256 | undefined | | \_depositID | uint256 | undefined |
| _buyerAddress | address | The address of the buyer of a `_depositID`. | | \_buyerAddress | address | The address of the buyer of a `_depositID`. |
| _relayerTarget | address | Target address entitled to the `relayerPremim`. | | \_relayerTarget | address | Target address entitled to the `relayerPremim`. |
| _relayerPremium | uint256 | The refund/premium owed to a relayer. | | \_relayerPremium | uint256 | The refund/premium owed to a relayer. |
| _amount | uint256 | The deposit&#39;s remaining amount wished to be locked. | | \_amount | uint256 | The deposit&#39;s remaining amount wished to be locked. |
| merkleProof | bytes32[] | This value should be: - Provided as a pass if the `msg.sender` is in the seller&#39;s allowlist; - Left empty otherwise; | | merkleProof | bytes32[] | This value should be: - Provided as a pass if the `msg.sender` is in the seller&#39;s allowlist; - Left empty otherwise; |
| expiredLocks | bytes32[] | An array of `bytes32` identifiers to be provided so to unexpire locks using this transaction gas push. | | expiredLocks | bytes32[] | An array of `bytes32` identifiers to be provided so to unexpire locks using this transaction gas push. |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ---------------------------------------------------- |
| lockID | bytes32 | The `bytes32` value returned as the lock identifier. | | lockID | bytes32 | The `bytes32` value returned as the lock identifier. |
### mapDeposits ### mapDeposits
@ -163,25 +145,23 @@ Public method designed to lock an remaining amount of the deposit order of a sel
function mapDeposits(uint256) external view returns (uint256 remaining, string pixTarget, address seller, address token, bool valid) function mapDeposits(uint256) external view returns (uint256 remaining, string pixTarget, address seller, address token, bool valid)
``` ```
_Seller list of deposits_
*Seller list of deposits*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------- | ------- | ----------- |
| remaining | uint256 | undefined | | remaining | uint256 | undefined |
| pixTarget | string | undefined | | pixTarget | string | undefined |
| seller | address | undefined | | seller | address | undefined |
| token | address | undefined | | token | address | undefined |
| valid | bool | undefined | | valid | bool | undefined |
### mapLocks ### mapLocks
@ -189,27 +169,25 @@ function mapDeposits(uint256) external view returns (uint256 remaining, string p
function mapLocks(bytes32) external view returns (uint256 depositID, uint256 relayerPremium, uint256 amount, uint256 expirationBlock, address buyerAddress, address relayerTarget, address relayerAddress) function mapLocks(bytes32) external view returns (uint256 depositID, uint256 relayerPremium, uint256 amount, uint256 expirationBlock, address buyerAddress, address relayerTarget, address relayerAddress)
``` ```
_List of Locks._
*List of Locks.*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | bytes32 | undefined | | \_0 | bytes32 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| relayerPremium | uint256 | undefined | | relayerPremium | uint256 | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
| expirationBlock | uint256 | undefined | | expirationBlock | uint256 | undefined |
| buyerAddress | address | undefined | | buyerAddress | address | undefined |
| relayerTarget | address | undefined | | relayerTarget | address | undefined |
| relayerAddress | address | undefined | | relayerAddress | address | undefined |
### owner ### owner
@ -217,16 +195,11 @@ function mapLocks(bytes32) external view returns (uint256 depositID, uint256 rel
function owner() external view returns (address) function owner() external view returns (address)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
### release ### release
@ -236,18 +209,18 @@ function release(bytes32 lockID, address _relayerTarget, uint256 pixTimestamp, b
Lock release method that liquidate lock orders and distributes relayer fees. Lock release method that liquidate lock orders and distributes relayer fees.
*This method can be called by any public actor as long the signature provided is valid.`relayerPremium` gets splitted equaly if `relayerTarget` addresses differ.If the `msg.sender` of this method and `l.relayerAddress` are the same, `msg.sender` accrues both l.amount and l.relayerPremium as userRecord credit. In case of they differing: - `lock` caller gets accrued with `l.amount` as userRecord credit; - `release` caller gets accrued with `l.relayerPremium` as userRecord credit; Function sighash: 0x4e1389ed.* _This method can be called by any public actor as long the signature provided is valid.`relayerPremium` gets splitted equaly if `relayerTarget` addresses differ.If the `msg.sender` of this method and `l.relayerAddress` are the same, `msg.sender` accrues both l.amount and l.relayerPremium as userRecord credit. In case of they differing: - `lock` caller gets accrued with `l.amount` as userRecord credit; - `release` caller gets accrued with `l.relayerPremium` as userRecord credit; Function sighash: 0x4e1389ed._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------------------------------------------- |
| lockID | bytes32 | undefined | | lockID | bytes32 | undefined |
| _relayerTarget | address | Target address entitled to the `relayerPremim`. | | \_relayerTarget | address | Target address entitled to the `relayerPremim`. |
| pixTimestamp | uint256 | undefined | | pixTimestamp | uint256 | undefined |
| r | bytes32 | undefined | | r | bytes32 | undefined |
| s | bytes32 | undefined | | s | bytes32 | undefined |
| v | uint8 | undefined | | v | uint8 | undefined |
### reputation ### reputation
@ -257,14 +230,11 @@ function reputation() external view returns (contract IReputation)
███ Storage ████████████████████████████████████████████████████████████ ███ Storage ████████████████████████████████████████████████████████████
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | -------------------- | ----------- |
| _0 | contract IReputation | undefined | | \_0 | contract IReputation | undefined |
### sellerAllowList ### sellerAllowList
@ -272,21 +242,19 @@ function reputation() external view returns (contract IReputation)
function sellerAllowList(uint256) external view returns (bytes32) function sellerAllowList(uint256) external view returns (bytes32)
``` ```
_Seller casted to key =&gt; Seller&#39;s allowlist merkleroot._
*Seller casted to key =&gt; Seller&#39;s allowlist merkleroot.*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | bytes32 | undefined | | \_0 | bytes32 | undefined |
### setDefaultLockBlocks ### setDefaultLockBlocks
@ -294,15 +262,11 @@ function sellerAllowList(uint256) external view returns (bytes32)
function setDefaultLockBlocks(uint256 _blocks) external nonpayable function setDefaultLockBlocks(uint256 _blocks) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| _blocks | uint256 | undefined | | \_blocks | uint256 | undefined |
### setOwner ### setOwner
@ -310,15 +274,11 @@ function setDefaultLockBlocks(uint256 _blocks) external nonpayable
function setOwner(address newOwner) external nonpayable function setOwner(address newOwner) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| newOwner | address | undefined | | newOwner | address | undefined |
### setReputation ### setReputation
@ -326,15 +286,11 @@ function setOwner(address newOwner) external nonpayable
function setReputation(contract IReputation _reputation) external nonpayable function setReputation(contract IReputation _reputation) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | -------------------- | ----------- |
| _reputation | contract IReputation | undefined | | \_reputation | contract IReputation | undefined |
### setRoot ### setRoot
@ -342,16 +298,12 @@ function setReputation(contract IReputation _reputation) external nonpayable
function setRoot(address addr, bytes32 merkleroot) external nonpayable function setRoot(address addr, bytes32 merkleroot) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------- | ------- | ----------- |
| addr | address | undefined | | addr | address | undefined |
| merkleroot | bytes32 | undefined | | merkleroot | bytes32 | undefined |
### setValidSigners ### setValidSigners
@ -359,15 +311,11 @@ function setRoot(address addr, bytes32 merkleroot) external nonpayable
function setValidSigners(address[] _validSigners) external nonpayable function setValidSigners(address[] _validSigners) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------------- | --------- | ----------- |
| _validSigners | address[] | undefined | | \_validSigners | address[] | undefined |
### tokenSettings ### tokenSettings
@ -375,16 +323,12 @@ function setValidSigners(address[] _validSigners) external nonpayable
function tokenSettings(address[] _tokens, bool[] _states) external nonpayable function tokenSettings(address[] _tokens, bool[] _states) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | --------- | ----------- |
| _tokens | address[] | undefined | | \_tokens | address[] | undefined |
| _states | bool[] | undefined | | \_states | bool[] | undefined |
### unlockExpired ### unlockExpired
@ -394,13 +338,13 @@ function unlockExpired(bytes32[] lockIDs) external nonpayable
Unlocks expired locks. Unlocks expired locks.
*Triggered in the callgraph by both `lock` and `withdraw` functions.This method can also have any public actor as its `tx.origin`.For each successfull unexpired lock recovered, `userRecord[_castAddrToKey(l.relayerAddress)]` is decreased by half of its value.Function sighash: 0x8e2749d6.* _Triggered in the callgraph by both `lock` and `withdraw` functions.This method can also have any public actor as its `tx.origin`.For each successfull unexpired lock recovered, `userRecord[_castAddrToKey(l.relayerAddress)]` is decreased by half of its value.Function sighash: 0x8e2749d6._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------- | --------- | ----------- |
| lockIDs | bytes32[] | undefined | | lockIDs | bytes32[] | undefined |
### userRecord ### userRecord
@ -408,21 +352,19 @@ Unlocks expired locks.
function userRecord(uint256) external view returns (uint256) function userRecord(uint256) external view returns (uint256)
``` ```
_Stores an relayer&#39;s last computed credit._
*Stores an relayer&#39;s last computed credit.*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### validBacenSigners ### validBacenSigners
@ -430,21 +372,19 @@ function userRecord(uint256) external view returns (uint256)
function validBacenSigners(uint256) external view returns (bool) function validBacenSigners(uint256) external view returns (bool)
``` ```
_List of valid Bacen signature addresses_
*List of valid Bacen signature addresses*
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### withdraw ### withdraw
@ -454,14 +394,14 @@ function withdraw(uint256 depositID, bytes32[] expiredLocks) external nonpayable
Seller&#39;s expired deposit fund sweeper. Seller&#39;s expired deposit fund sweeper.
*A seller may use this method to recover tokens from expired deposits.Function sighash: 0x36317972.* _A seller may use this method to recover tokens from expired deposits.Function sighash: 0x36317972._
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | --------- | ----------- |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| expiredLocks | bytes32[] | undefined | | expiredLocks | bytes32[] | undefined |
### withdrawBalance ### withdrawBalance
@ -469,12 +409,7 @@ Seller&#39;s expired deposit fund sweeper.
function withdrawBalance() external nonpayable function withdrawBalance() external nonpayable
``` ```
_Contract&#39;s underlying balance withdraw method.Function sighash: 0x5fd8c710._
*Contract&#39;s underlying balance withdraw method.Function sighash: 0x5fd8c710.*
## Events ## Events
@ -484,16 +419,12 @@ function withdrawBalance() external nonpayable
event AllowedERC20Updated(address indexed token, bool indexed state) event AllowedERC20Updated(address indexed token, bool indexed state)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| token `indexed` | address | undefined | | token `indexed` | address | undefined |
| state `indexed` | bool | undefined | | state `indexed` | bool | undefined |
### DepositAdded ### DepositAdded
@ -503,16 +434,14 @@ event DepositAdded(address indexed seller, uint256 depositID, address token, uin
███ Events ████████████████████████████████████████████████████████████ ███ Events ████████████████████████████████████████████████████████████
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| token | address | undefined | | token | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### DepositClosed ### DepositClosed
@ -520,16 +449,12 @@ event DepositAdded(address indexed seller, uint256 depositID, address token, uin
event DepositClosed(address indexed seller, uint256 depositID) event DepositClosed(address indexed seller, uint256 depositID)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
### DepositWithdrawn ### DepositWithdrawn
@ -537,17 +462,13 @@ event DepositClosed(address indexed seller, uint256 depositID)
event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount) event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| seller `indexed` | address | undefined | | seller `indexed` | address | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### FundsWithdrawn ### FundsWithdrawn
@ -555,16 +476,12 @@ event DepositWithdrawn(address indexed seller, uint256 depositID, uint256 amount
event FundsWithdrawn(address owner, uint256 amount) event FundsWithdrawn(address owner, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| owner | address | undefined | | owner | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### LockAdded ### LockAdded
@ -572,18 +489,14 @@ event FundsWithdrawn(address owner, uint256 amount)
event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount) event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockID `indexed` | bytes32 | undefined | | lockID `indexed` | bytes32 | undefined |
| depositID | uint256 | undefined | | depositID | uint256 | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### LockBlocksUpdated ### LockBlocksUpdated
@ -591,15 +504,11 @@ event LockAdded(address indexed buyer, bytes32 indexed lockID, uint256 depositID
event LockBlocksUpdated(uint256 blocks) event LockBlocksUpdated(uint256 blocks)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| blocks | uint256 | undefined | | blocks | uint256 | undefined |
### LockReleased ### LockReleased
@ -607,16 +516,12 @@ event LockBlocksUpdated(uint256 blocks)
event LockReleased(address indexed buyer, bytes32 lockId) event LockReleased(address indexed buyer, bytes32 lockId)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined | | lockId | bytes32 | undefined |
### LockReturned ### LockReturned
@ -624,16 +529,12 @@ event LockReleased(address indexed buyer, bytes32 lockId)
event LockReturned(address indexed buyer, bytes32 lockId) event LockReturned(address indexed buyer, bytes32 lockId)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | --------------- | ------- | ----------- |
| buyer `indexed` | address | undefined | | buyer `indexed` | address | undefined |
| lockId | bytes32 | undefined | | lockId | bytes32 | undefined |
### OwnerUpdated ### OwnerUpdated
@ -641,16 +542,12 @@ event LockReturned(address indexed buyer, bytes32 lockId)
event OwnerUpdated(address indexed user, address indexed newOwner) event OwnerUpdated(address indexed user, address indexed newOwner)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------------ | ------- | ----------- |
| user `indexed` | address | undefined | | user `indexed` | address | undefined |
| newOwner `indexed` | address | undefined | | newOwner `indexed` | address | undefined |
### ReputationUpdated ### ReputationUpdated
@ -658,15 +555,11 @@ event OwnerUpdated(address indexed user, address indexed newOwner)
event ReputationUpdated(address reputation) event ReputationUpdated(address reputation)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---------- | ------- | ----------- |
| reputation | address | undefined | | reputation | address | undefined |
### ValidSignersUpdated ### ValidSignersUpdated
@ -674,17 +567,11 @@ event ReputationUpdated(address reputation)
event ValidSignersUpdated(address[] signers) event ValidSignersUpdated(address[] signers)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------- | --------- | ----------- |
| signers | address[] | undefined | | signers | address[] | undefined |
## Errors ## Errors
@ -694,10 +581,7 @@ event ValidSignersUpdated(address[] signers)
error AddressDenied() error AddressDenied()
``` ```
_Address doesn&#39;t exist in a MerkleTree.Address not allowed as relayer.0x3b8474be_
*Address doesn&#39;t exist in a MerkleTree.Address not allowed as relayer.0x3b8474be*
### AlreadyReleased ### AlreadyReleased
@ -705,10 +589,7 @@ error AddressDenied()
error AlreadyReleased() error AlreadyReleased()
``` ```
_Lock already released or returned.0x63b4904e_
*Lock already released or returned.0x63b4904e*
### AmountNotAllowed ### AmountNotAllowed
@ -716,10 +597,7 @@ error AlreadyReleased()
error AmountNotAllowed() error AmountNotAllowed()
``` ```
_Wished amount to be locked exceeds the limit allowed.0x1c18f846_
*Wished amount to be locked exceeds the limit allowed.0x1c18f846*
### DepositAlreadyExists ### DepositAlreadyExists
@ -727,10 +605,7 @@ error AmountNotAllowed()
error DepositAlreadyExists() error DepositAlreadyExists()
``` ```
_Deposit already exist and it is still valid.0xc44bd765_
*Deposit already exist and it is still valid.0xc44bd765*
### InvalidDeposit ### InvalidDeposit
@ -738,10 +613,7 @@ error DepositAlreadyExists()
error InvalidDeposit() error InvalidDeposit()
``` ```
_Deposit not valid anymore.0xb2e532de_
*Deposit not valid anymore.0xb2e532de*
### InvalidSigner ### InvalidSigner
@ -749,10 +621,7 @@ error InvalidDeposit()
error InvalidSigner() error InvalidSigner()
``` ```
_Signer is not a valid signer.0x815e1d64_
*Signer is not a valid signer.0x815e1d64*
### LengthMismatch ### LengthMismatch
@ -760,10 +629,7 @@ error InvalidSigner()
error LengthMismatch() error LengthMismatch()
``` ```
_Arrays&#39; length don&#39;t match.0xff633a38_
*Arrays&#39; length don&#39;t match.0xff633a38*
### LoopOverflow ### LoopOverflow
@ -771,10 +637,7 @@ error LengthMismatch()
error LoopOverflow() error LoopOverflow()
``` ```
_Loop bounds have overflowed.0xdfb035c9_
*Loop bounds have overflowed.0xdfb035c9*
### NoTokens ### NoTokens
@ -782,10 +645,7 @@ error LoopOverflow()
error NoTokens() error NoTokens()
``` ```
_No tokens array provided as argument.0xdf957883_
*No tokens array provided as argument.0xdf957883*
### NotEnoughTokens ### NotEnoughTokens
@ -793,10 +653,7 @@ error NoTokens()
error NotEnoughTokens() error NotEnoughTokens()
``` ```
_Not enough token remaining on deposit.0x22bbb43c_
*Not enough token remaining on deposit.0x22bbb43c*
### NotExpired ### NotExpired
@ -804,10 +661,7 @@ error NotEnoughTokens()
error NotExpired() error NotExpired()
``` ```
_Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85_
*Lock not expired or already released.Another lock with same ID is not expired yet.0xd0404f85*
### OnlySeller ### OnlySeller
@ -815,10 +669,7 @@ error NotExpired()
error OnlySeller() error OnlySeller()
``` ```
_Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726_
*Only seller could call this function.`msg.sender` and the seller differ.0x85d1f726*
### Reentrancy ### Reentrancy
@ -826,21 +677,13 @@ error OnlySeller()
error Reentrancy() error Reentrancy()
``` ```
### TokenDenied ### TokenDenied
```solidity ```solidity
error TokenDenied() error TokenDenied()
``` ```
_Token address not allowed to be deposited.0x1578328e_
*Token address not allowed to be deposited.0x1578328e*
### TxAlreadyUsed ### TxAlreadyUsed
@ -848,9 +691,4 @@ error TokenDenied()
error TxAlreadyUsed() error TxAlreadyUsed()
``` ```
_Transaction already used to unlock payment.0xf490a6ea_
*Transaction already used to unlock payment.0xf490a6ea*

View File

@ -1,13 +1,5 @@
# Reputation # Reputation
## Methods ## Methods
### limiter ### limiter
@ -16,21 +8,17 @@
function limiter(uint256 _userCredit) external pure returns (uint256 _spendLimit) function limiter(uint256 _userCredit) external pure returns (uint256 _spendLimit)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | ------- | ----------- |
| _userCredit | uint256 | undefined | | \_userCredit | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | ------- | ----------- |
| _spendLimit | uint256 | undefined | | \_spendLimit | uint256 | undefined |
### magicValue ### magicValue
@ -38,16 +26,13 @@ function limiter(uint256 _userCredit) external pure returns (uint256 _spendLimit
function magicValue() external view returns (uint256) function magicValue() external view returns (uint256)
``` ```
_Denominator&#39;s constant operand for the `limiter` fx. _
*Denominator&#39;s constant operand for the `limiter` fx. *
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### maxLimit ### maxLimit
@ -55,16 +40,13 @@ function magicValue() external view returns (uint256)
function maxLimit() external view returns (uint256) function maxLimit() external view returns (uint256)
``` ```
_Asymptote numerator constant value for the `limiter` fx._
*Asymptote numerator constant value for the `limiter` fx.*
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### owner ### owner
@ -72,16 +54,11 @@ function maxLimit() external view returns (uint256)
function owner() external view returns (address) function owner() external view returns (address)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
### setOwner ### setOwner
@ -89,17 +66,11 @@ function owner() external view returns (address)
function setOwner(address newOwner) external nonpayable function setOwner(address newOwner) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| newOwner | address | undefined | | newOwner | address | undefined |
## Events ## Events
@ -109,16 +80,9 @@ function setOwner(address newOwner) external nonpayable
event OwnerUpdated(address indexed user, address indexed newOwner) event OwnerUpdated(address indexed user, address indexed newOwner)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------------ | ------- | ----------- |
| user `indexed` | address | undefined | | user `indexed` | address | undefined |
| newOwner `indexed` | address | undefined | | newOwner `indexed` | address | undefined |

View File

@ -1,13 +1,9 @@
# Owned # Owned
*Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol)* _Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Owned.sol)_
Simple single owner authorization mixin. Simple single owner authorization mixin.
## Methods ## Methods
### owner ### owner
@ -16,16 +12,11 @@ Simple single owner authorization mixin.
function owner() external view returns (address) function owner() external view returns (address)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
### setOwner ### setOwner
@ -33,17 +24,11 @@ function owner() external view returns (address)
function setOwner(address newOwner) external nonpayable function setOwner(address newOwner) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| newOwner | address | undefined | | newOwner | address | undefined |
## Events ## Events
@ -53,16 +38,9 @@ function setOwner(address newOwner) external nonpayable
event OwnerUpdated(address indexed user, address indexed newOwner) event OwnerUpdated(address indexed user, address indexed newOwner)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------------ | ------- | ----------- |
| user `indexed` | address | undefined | | user `indexed` | address | undefined |
| newOwner `indexed` | address | undefined | | newOwner `indexed` | address | undefined |

View File

@ -1,13 +1,5 @@
# IReputation # IReputation
## Methods ## Methods
### limiter ### limiter
@ -16,22 +8,14 @@
function limiter(uint256 _userCredit) external pure returns (uint256 _spendLimit) function limiter(uint256 _userCredit) external pure returns (uint256 _spendLimit)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | ------- | ----------- |
| _userCredit | uint256 | undefined | | \_userCredit | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------------ | ------- | ----------- |
| _spendLimit | uint256 | undefined | | \_spendLimit | uint256 | undefined |

View File

@ -1,13 +1,5 @@
# MockToken # MockToken
## Methods ## Methods
### DOMAIN_SEPARATOR ### DOMAIN_SEPARATOR
@ -16,16 +8,11 @@
function DOMAIN_SEPARATOR() external view returns (bytes32) function DOMAIN_SEPARATOR() external view returns (bytes32)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | bytes32 | undefined | | \_0 | bytes32 | undefined |
### allowance ### allowance
@ -33,22 +20,18 @@ function DOMAIN_SEPARATOR() external view returns (bytes32)
function allowance(address, address) external view returns (uint256) function allowance(address, address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
| _1 | address | undefined | | \_1 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### approve ### approve
@ -56,22 +39,18 @@ function allowance(address, address) external view returns (uint256)
function approve(address spender, uint256 amount) external nonpayable returns (bool) function approve(address spender, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------- | ------- | ----------- |
| spender | address | undefined | | spender | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### balanceOf ### balanceOf
@ -79,21 +58,17 @@ function approve(address spender, uint256 amount) external nonpayable returns (b
function balanceOf(address) external view returns (uint256) function balanceOf(address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### decimals ### decimals
@ -101,16 +76,11 @@ function balanceOf(address) external view returns (uint256)
function decimals() external view returns (uint8) function decimals() external view returns (uint8)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ----- | ----------- |
| _0 | uint8 | undefined | | \_0 | uint8 | undefined |
### name ### name
@ -118,16 +88,11 @@ function decimals() external view returns (uint8)
function name() external view returns (string) function name() external view returns (string)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------ | ----------- |
| _0 | string | undefined | | \_0 | string | undefined |
### nonces ### nonces
@ -135,21 +100,17 @@ function name() external view returns (string)
function nonces(address) external view returns (uint256) function nonces(address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### permit ### permit
@ -157,21 +118,17 @@ function nonces(address) external view returns (uint256)
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| owner | address | undefined | | owner | address | undefined |
| spender | address | undefined | | spender | address | undefined |
| value | uint256 | undefined | | value | uint256 | undefined |
| deadline | uint256 | undefined | | deadline | uint256 | undefined |
| v | uint8 | undefined | | v | uint8 | undefined |
| r | bytes32 | undefined | | r | bytes32 | undefined |
| s | bytes32 | undefined | | s | bytes32 | undefined |
### symbol ### symbol
@ -179,16 +136,11 @@ function permit(address owner, address spender, uint256 value, uint256 deadline,
function symbol() external view returns (string) function symbol() external view returns (string)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------ | ----------- |
| _0 | string | undefined | | \_0 | string | undefined |
### totalSupply ### totalSupply
@ -196,16 +148,11 @@ function symbol() external view returns (string)
function totalSupply() external view returns (uint256) function totalSupply() external view returns (uint256)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### transfer ### transfer
@ -213,22 +160,18 @@ function totalSupply() external view returns (uint256)
function transfer(address to, uint256 amount) external nonpayable returns (bool) function transfer(address to, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| to | address | undefined | | to | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### transferFrom ### transferFrom
@ -236,25 +179,19 @@ function transfer(address to, uint256 amount) external nonpayable returns (bool)
function transferFrom(address from, address to, uint256 amount) external nonpayable returns (bool) function transferFrom(address from, address to, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| from | address | undefined | | from | address | undefined |
| to | address | undefined | | to | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
## Events ## Events
@ -264,17 +201,13 @@ function transferFrom(address from, address to, uint256 amount) external nonpaya
event Approval(address indexed owner, address indexed spender, uint256 amount) event Approval(address indexed owner, address indexed spender, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ----------------- | ------- | ----------- |
| owner `indexed` | address | undefined | | owner `indexed` | address | undefined |
| spender `indexed` | address | undefined | | spender `indexed` | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### Transfer ### Transfer
@ -282,17 +215,10 @@ event Approval(address indexed owner, address indexed spender, uint256 amount)
event Transfer(address indexed from, address indexed to, uint256 amount) event Transfer(address indexed from, address indexed to, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------------- | ------- | ----------- |
| from `indexed` | address | undefined | | from `indexed` | address | undefined |
| to `indexed` | address | undefined | | to `indexed` | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |

View File

@ -1,12 +1,10 @@
# ERC20 # ERC20
*Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)* _Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/tokens/ERC20.sol)Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)_
Modern and gas efficient ERC20 + EIP-2612 implementation. Modern and gas efficient ERC20 + EIP-2612 implementation.
*Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.* _Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it._
## Methods ## Methods
@ -16,16 +14,11 @@ Modern and gas efficient ERC20 + EIP-2612 implementation.
function DOMAIN_SEPARATOR() external view returns (bytes32) function DOMAIN_SEPARATOR() external view returns (bytes32)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | bytes32 | undefined | | \_0 | bytes32 | undefined |
### allowance ### allowance
@ -33,22 +26,18 @@ function DOMAIN_SEPARATOR() external view returns (bytes32)
function allowance(address, address) external view returns (uint256) function allowance(address, address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
| _1 | address | undefined | | \_1 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### approve ### approve
@ -56,22 +45,18 @@ function allowance(address, address) external view returns (uint256)
function approve(address spender, uint256 amount) external nonpayable returns (bool) function approve(address spender, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------- | ------- | ----------- |
| spender | address | undefined | | spender | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### balanceOf ### balanceOf
@ -79,21 +64,17 @@ function approve(address spender, uint256 amount) external nonpayable returns (b
function balanceOf(address) external view returns (uint256) function balanceOf(address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### decimals ### decimals
@ -101,16 +82,11 @@ function balanceOf(address) external view returns (uint256)
function decimals() external view returns (uint8) function decimals() external view returns (uint8)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ----- | ----------- |
| _0 | uint8 | undefined | | \_0 | uint8 | undefined |
### name ### name
@ -118,16 +94,11 @@ function decimals() external view returns (uint8)
function name() external view returns (string) function name() external view returns (string)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------ | ----------- |
| _0 | string | undefined | | \_0 | string | undefined |
### nonces ### nonces
@ -135,21 +106,17 @@ function name() external view returns (string)
function nonces(address) external view returns (uint256) function nonces(address) external view returns (uint256)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | address | undefined | | \_0 | address | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### permit ### permit
@ -157,21 +124,17 @@ function nonces(address) external view returns (uint256)
function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable function permit(address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) external nonpayable
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------- | ------- | ----------- |
| owner | address | undefined | | owner | address | undefined |
| spender | address | undefined | | spender | address | undefined |
| value | uint256 | undefined | | value | uint256 | undefined |
| deadline | uint256 | undefined | | deadline | uint256 | undefined |
| v | uint8 | undefined | | v | uint8 | undefined |
| r | bytes32 | undefined | | r | bytes32 | undefined |
| s | bytes32 | undefined | | s | bytes32 | undefined |
### symbol ### symbol
@ -179,16 +142,11 @@ function permit(address owner, address spender, uint256 value, uint256 deadline,
function symbol() external view returns (string) function symbol() external view returns (string)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------ | ----------- |
| _0 | string | undefined | | \_0 | string | undefined |
### totalSupply ### totalSupply
@ -196,16 +154,11 @@ function symbol() external view returns (string)
function totalSupply() external view returns (uint256) function totalSupply() external view returns (uint256)
``` ```
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ------- | ----------- |
| _0 | uint256 | undefined | | \_0 | uint256 | undefined |
### transfer ### transfer
@ -213,22 +166,18 @@ function totalSupply() external view returns (uint256)
function transfer(address to, uint256 amount) external nonpayable returns (bool) function transfer(address to, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| to | address | undefined | | to | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
### transferFrom ### transferFrom
@ -236,25 +185,19 @@ function transfer(address to, uint256 amount) external nonpayable returns (bool)
function transferFrom(address from, address to, uint256 amount) external nonpayable returns (bool) function transferFrom(address from, address to, uint256 amount) external nonpayable returns (bool)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ------ | ------- | ----------- |
| from | address | undefined | | from | address | undefined |
| to | address | undefined | | to | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
#### Returns #### Returns
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ---- | ---- | ----------- |
| _0 | bool | undefined | | \_0 | bool | undefined |
## Events ## Events
@ -264,17 +207,13 @@ function transferFrom(address from, address to, uint256 amount) external nonpaya
event Approval(address indexed owner, address indexed spender, uint256 amount) event Approval(address indexed owner, address indexed spender, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | ----------------- | ------- | ----------- |
| owner `indexed` | address | undefined | | owner `indexed` | address | undefined |
| spender `indexed` | address | undefined | | spender `indexed` | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |
### Transfer ### Transfer
@ -282,17 +221,10 @@ event Approval(address indexed owner, address indexed spender, uint256 amount)
event Transfer(address indexed from, address indexed to, uint256 amount) event Transfer(address indexed from, address indexed to, uint256 amount)
``` ```
#### Parameters #### Parameters
| Name | Type | Description | | Name | Type | Description |
|---|---|---| | -------------- | ------- | ----------- |
| from `indexed` | address | undefined | | from `indexed` | address | undefined |
| to `indexed` | address | undefined | | to `indexed` | address | undefined |
| amount | uint256 | undefined | | amount | uint256 | undefined |

View File

@ -1,14 +1,12 @@
# Counters # Counters
*buf0t9Modified from OpenZeppelin Contracts (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol)* _buf0t9Modified from OpenZeppelin Contracts (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Counters.sol)_
> Counters > Counters
Provides counters that can only be incremented, decrementedor reset. Provides counters that can only be incremented, decrementedor reset.
*Include with `using Counters for Counters.Counter;`* _Include with `using Counters for Counters.Counter;`_
## Errors ## Errors
@ -18,9 +16,4 @@ Provides counters that can only be incremented, decrementedor reset.
error DecOverflow() error DecOverflow()
``` ```
_0xce3a3d37_
*0xce3a3d37*

View File

@ -1,12 +1,5 @@
# FixedPointMathLib # FixedPointMathLib
*Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)* _Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/FixedPointMathLib.sol)_
Arithmetic library with operations for fixed-point numbers. Arithmetic library with operations for fixed-point numbers.

View File

@ -1,12 +1,5 @@
# MerkleProofLib # MerkleProofLib
*Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)* _Solady (https://github.com/vectorized/solady/blob/main/src/utils/MerkleProofLib.sol)Modified from Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/MerkleProofLib.sol)Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/MerkleProof.sol)_
Gas optimized verification of proof of inclusion for a leaf in a Merkle tree. Gas optimized verification of proof of inclusion for a leaf in a Merkle tree.

View File

@ -1,15 +1,9 @@
# ReentrancyGuard # ReentrancyGuard
*z0r0z.ethModified from Seaport (https://github.com/ProjectOpenSea/seaport/blob/main/contracts/lib/ReentrancyGuard.sol)Modified from Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)* _z0r0z.ethModified from Seaport (https://github.com/ProjectOpenSea/seaport/blob/main/contracts/lib/ReentrancyGuard.sol)Modified from Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/ReentrancyGuard.sol)_
Reentrancy protection for smart contracts. Reentrancy protection for smart contracts.
## Errors ## Errors
### Reentrancy ### Reentrancy
@ -17,10 +11,3 @@ Reentrancy protection for smart contracts.
```solidity ```solidity
error Reentrancy() error Reentrancy()
``` ```

View File

@ -1,12 +1,7 @@
# SafeTransferLib # SafeTransferLib
*Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)* _Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SafeTransferLib.sol)_
Safe ETH and ERC20 transfer library that gracefully handles missing return values. Safe ETH and ERC20 transfer library that gracefully handles missing return values.
*Caution! This library won&#39;t check that a token has code, responsibility is delegated to the caller.* _Caution! This library won&#39;t check that a token has code, responsibility is delegated to the caller._

View File

@ -1,12 +1,11 @@
import "@nomicfoundation/hardhat-chai-matchers"; import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox"; import "@nomicfoundation/hardhat-toolbox";
import { config as dotenvConfig } from "dotenv"; import { config as dotenvConfig } from "dotenv";
import "hardhat-tracer";
import { HardhatUserConfig } from "hardhat/config"; import { HardhatUserConfig } from "hardhat/config";
import { NetworkUserConfig } from "hardhat/types"; import { NetworkUserConfig } from "hardhat/types";
import { resolve } from "path"; import { resolve } from "path";
import "hardhat-tracer";
dotenvConfig({ path: resolve(__dirname, "./.env") }); dotenvConfig({ path: resolve(__dirname, "./.env") });
const mnemonic: string | undefined = process.env.MNEMONIC; const mnemonic: string | undefined = process.env.MNEMONIC;

View File

@ -2,6 +2,7 @@ import "@nomiclabs/hardhat-ethers";
import "@nomiclabs/hardhat-etherscan"; import "@nomiclabs/hardhat-etherscan";
import * as fs from "fs"; import * as fs from "fs";
import { ethers, network } from "hardhat"; import { ethers, network } from "hardhat";
// import hre from "hardhat"; // import hre from "hardhat";
interface Deploys { interface Deploys {

View File

@ -3,6 +3,7 @@ import "@nomiclabs/hardhat-etherscan";
import { BigNumber } from "ethers"; import { BigNumber } from "ethers";
import * as fs from "fs"; import * as fs from "fs";
import { ethers, network } from "hardhat"; import { ethers, network } from "hardhat";
// import hre from "hardhat"; // import hre from "hardhat";
interface Deploys { interface Deploys {

View File

@ -70,6 +70,11 @@ const _abi = [
name: "OnlySeller", name: "OnlySeller",
type: "error", type: "error",
}, },
{
inputs: [],
name: "StaticCallFailed",
type: "error",
},
{ {
inputs: [], inputs: [],
name: "TokenDenied", name: "TokenDenied",

File diff suppressed because one or more lines are too long

View File

@ -38,7 +38,7 @@
// const ownerKey = await p2pix._castAddrToKey(owner.address); // const ownerKey = await p2pix._castAddrToKey(owner.address);
// const wallet2Key = await p2pix._castAddrToKey(wallet2.address); // const wallet2Key = await p2pix._castAddrToKey(wallet2.address);
// // Verify values at deployment // // Verify values at deployment
// expect( // expect(
// await p2pix.callStatic.validBacenSigners(ownerKey), // await p2pix.callStatic.validBacenSigners(ownerKey),

View File

@ -286,7 +286,7 @@
// p2pix.unlockExpired([lockID]), // p2pix.unlockExpired([lockID]),
// ).to.be.revertedWithCustomError( // ).to.be.revertedWithCustomError(
// p2pix, P2PixErrors.NotExpired); // p2pix, P2PixErrors.NotExpired);
// await network.provider.send("evm_mine"); // await network.provider.send("evm_mine");
// await network.provider.send("evm_mine"); // await network.provider.send("evm_mine");
// await network.provider.send("evm_mine"); // await network.provider.send("evm_mine");
@ -302,4 +302,4 @@
// ).to.be.revertedWithCustomError( // ).to.be.revertedWithCustomError(
// p2pix, P2PixErrors.NotExpired); // p2pix, P2PixErrors.NotExpired);
// }); // });
// }); // });

149
test/p2pix.test.ts Normal file
View File

@ -0,0 +1,149 @@
import "@nomicfoundation/hardhat-chai-matchers";
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber, Wallet } from "ethers";
import { ethers, network } from "hardhat";
import { MockToken, P2PIX, Reputation } from "../src/types";
import { P2PixErrors } from "./utils/errors";
import { p2pixFixture } from "./utils/fixtures";
describe("P2PIX", () => {
type WalletWithAddress = Wallet & SignerWithAddress;
// contract deployer/admin
let owner: WalletWithAddress;
// extra EOAs
let acc01: WalletWithAddress;
let acc02: WalletWithAddress;
let acc03: WalletWithAddress;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let res: any;
let p2pix: P2PIX; // Contract instance
let erc20: MockToken; // Token instance
let reputation: Reputation; // Reputation Interface instance;
const fundAmount: BigNumber =
ethers.utils.parseEther("10000");
const price: BigNumber = ethers.utils.parseEther("100");
const zero = ethers.constants.AddressZero;
before("Set signers and reset network", async () => {
[owner, acc01, acc02, acc03] =
await // eslint-disable-next-line @typescript-eslint/no-explicit-any
(ethers as any).getSigners();
await network.provider.send("hardhat_reset");
});
beforeEach("Load deployment fixtures", async () => {
({ erc20, p2pix, reputation } = await loadFixture(
p2pixFixture,
));
});
describe("Init", async () => {
it("P2PIX, Reputation and ERC20 should initialize", async () => {
await p2pix.deployed();
await erc20.deployed();
await reputation.deployed();
expect(p2pix).to.be.ok;
expect(erc20).to.be.ok;
expect(reputation).to.be.ok;
const ownerKey = await p2pix._castAddrToKey(
owner.address,
);
const acc01Key = await p2pix._castAddrToKey(
acc01.address,
);
// storage checks
expect(
await p2pix.callStatic.defaultLockBlocks(),
).to.eq(4);
expect(await p2pix.callStatic.reputation()).to.eq(
reputation.address,
);
expect(await p2pix.callStatic.depositCount()).to.eq(0);
expect(
await p2pix.callStatic.validBacenSigners(ownerKey),
).to.eq(true);
expect(
await p2pix.callStatic.validBacenSigners(acc01Key),
).to.eq(true);
expect(
await p2pix.callStatic.allowedERC20s(erc20.address),
).to.eq(true);
// event emission
await expect(await p2pix.deployTransaction)
.to.emit(p2pix, "OwnerUpdated")
.withArgs(zero, owner.address)
.and.to.emit(p2pix, "LockBlocksUpdated")
.withArgs(4)
.and.to.emit(p2pix, "ReputationUpdated")
.withArgs(reputation.address)
.and.to.emit(p2pix, "ValidSignersUpdated")
.withArgs([owner.address, acc01.address])
.and.to.emit(p2pix, "AllowedERC20Updated")
.withArgs(erc20.address, true);
});
it("accounts have been funded", async () => {
// can't be eq to fundAmount due to contract deployment cost
res = await ethers.provider.getBalance(owner.address);
expect(res.toString()).to.have.lengthOf(22);
// console.log(res); // lengthOf = 22
// console.log(fundAmount); // lengthOf = 23
// those should eq to hardhat prefunded account's value
expect(
await ethers.provider.getBalance(acc01.address),
).to.eq(fundAmount);
expect(
await ethers.provider.getBalance(acc02.address),
).to.eq(fundAmount);
expect(
await ethers.provider.getBalance(acc03.address),
).to.eq(fundAmount);
});
});
// each describe tests a set of functionalities of the contract's behavior
describe("Owner Functions", async () => {
it("should allow contract's balance withdraw", async () => {
const oldBal = await p2pix.provider.getBalance(
p2pix.address,
);
const tx1 = await acc01.sendTransaction({
to: p2pix.address,
value: price,
});
const newBal = await p2pix.provider.getBalance(
p2pix.address,
);
expect(tx1).to.be.ok;
expect(oldBal).to.eq(0);
expect(newBal).to.eq(price);
await expect(
p2pix.withdrawBalance(),
).to.changeEtherBalances(
[owner.address, p2pix.address],
[price, "-100000000000000000000"],
);
await expect(
p2pix.connect(acc01).withdrawBalance(),
).to.be.revertedWith(
P2PixErrors.UNAUTHORIZED,
);
});
});
});

View File

@ -8,4 +8,5 @@ export enum P2PixErrors {
AlreadyReleased = "AlreadyReleased", AlreadyReleased = "AlreadyReleased",
TxAlreadyUsed = "TxAlreadyUsed", TxAlreadyUsed = "TxAlreadyUsed",
InvalidSigner = "InvalidSigner", InvalidSigner = "InvalidSigner",
} UNAUTHORIZED = "UNAUTHORIZED",
}

82
test/utils/fixtures.ts Normal file
View File

@ -0,0 +1,82 @@
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { Signer } from "ethers";
import { ethers } from "hardhat";
// import keccak256 from "keccak256";
// import { MerkleTree } from "merkletreejs";
import {
MockToken,
P2PIX,
Reputation,
} from "../../src/types";
// exported interfaces
export interface P2pixFixture {
p2pix: P2PIX;
reputation: Reputation;
erc20: MockToken;
// proof: string[];
// wrongProof: string[];
// merkleRoot: string;
}
// exported constants
export const getSignerAddrs = (
amount: number,
addrs: SignerWithAddress[],
): string[] => {
const signers: string[] = [];
const buffr = addrs.slice(0, amount);
for (let i = 0; i < amount; i++) {
signers.push(buffr[i].address);
}
return signers;
};
export const randomSigners = (amount: number): Signer[] => {
const signers: Signer[] = [];
for (let i = 0; i < amount; i++) {
signers.push(ethers.Wallet.createRandom());
}
return signers;
};
export const getError = (Error: string) =>
ethers.utils
.keccak256(ethers.utils.toUtf8Bytes(Error))
.slice(0, 10);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const padBuffer = (addr: any) => {
return Buffer.from(
addr.substr(2).padStart(32 * 2, 0),
"hex",
);
};
// exported async functions
export async function p2pixFixture(): Promise<P2pixFixture> {
const validSigners = getSignerAddrs(
2,
await ethers.getSigners(),
);
const Reputation = await ethers.getContractFactory(
"Reputation",
);
const reputation =
(await Reputation.deploy()) as Reputation;
const ERC20 = await ethers.getContractFactory("MockToken");
const erc20 = (await ERC20.deploy(
ethers.utils.parseEther("20000000"), // 20M
)) as MockToken;
const P2PIX = await ethers.getContractFactory("P2PIX");
const p2pix = (await P2PIX.deploy(
4,
validSigners,
reputation.address,
[erc20.address],
[true],
)) as P2PIX;
return { reputation, erc20, p2pix };
}

View File

@ -3175,7 +3175,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"bn.js@npm:^5.2.1": "bn.js@npm:^5.2.0, bn.js@npm:^5.2.1":
version: 5.2.1 version: 5.2.1
resolution: "bn.js@npm:5.2.1" resolution: "bn.js@npm:5.2.1"
checksum: 3dd8c8d38055fedfa95c1d5fc3c99f8dd547b36287b37768db0abab3c239711f88ff58d18d155dd8ad902b0b0cee973747b7ae20ea12a09473272b0201c9edd3 checksum: 3dd8c8d38055fedfa95c1d5fc3c99f8dd547b36287b37768db0abab3c239711f88ff58d18d155dd8ad902b0b0cee973747b7ae20ea12a09473272b0201c9edd3
@ -3291,6 +3291,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"buffer-reverse@npm:^1.0.1":
version: 1.0.1
resolution: "buffer-reverse@npm:1.0.1"
checksum: e350872a89b17af0a7e1bd7a73239a535164f3f010b0800add44f2e52bd0511548dc5b96c20309effba969868c385023d2d02a0add6155f6a76da7b3073b77bd
languageName: node
linkType: hard
"buffer-xor@npm:^1.0.3": "buffer-xor@npm:^1.0.3":
version: 1.0.3 version: 1.0.3
resolution: "buffer-xor@npm:1.0.3" resolution: "buffer-xor@npm:1.0.3"
@ -4146,6 +4153,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"crypto-js@npm:^3.1.9-1":
version: 3.3.0
resolution: "crypto-js@npm:3.3.0"
checksum: 193923143a4784b2f974366068d96fe8280168fd3fef2bfea9551a5c3e32096f5a8fa49ff4eeb5bd0b9716d325618d38cfbe6125e359a4ef488fbca93e600824
languageName: node
linkType: hard
"cz-conventional-changelog@npm:3.2.0": "cz-conventional-changelog@npm:3.2.0":
version: 3.2.0 version: 3.2.0
resolution: "cz-conventional-changelog@npm:3.2.0" resolution: "cz-conventional-changelog@npm:3.2.0"
@ -5067,7 +5081,7 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"ethers@npm:^5.7.2": "ethers@npm:^5.6.1, ethers@npm:^5.7.2":
version: 5.7.2 version: 5.7.2
resolution: "ethers@npm:5.7.2" resolution: "ethers@npm:5.7.2"
dependencies: dependencies:
@ -6035,6 +6049,19 @@ fsevents@~2.1.1:
languageName: node languageName: node
linkType: hard linkType: hard
"hardhat-tracer@npm:^1.2.0":
version: 1.2.0
resolution: "hardhat-tracer@npm:1.2.0"
dependencies:
ethers: ^5.6.1
peerDependencies:
chalk: 4.x
ethers: 5.x
hardhat: 2.x
checksum: 1d348fb3ed60cbde2287329730ccd37c73af80cc2cf4ccfb045f26af26c7efebd4a6fdf611035f34ca7fb75d0eb95985e8f5ed4f0537d2615fb6e126d1d035f0
languageName: node
linkType: hard
"hardhat@npm:^2.12.2": "hardhat@npm:^2.12.2":
version: 2.12.2 version: 2.12.2
resolution: "hardhat@npm:2.12.2" resolution: "hardhat@npm:2.12.2"
@ -7028,6 +7055,17 @@ fsevents@~2.1.1:
languageName: node languageName: node
linkType: hard linkType: hard
"keccak256@npm:^1.0.6":
version: 1.0.6
resolution: "keccak256@npm:1.0.6"
dependencies:
bn.js: ^5.2.0
buffer: ^6.0.3
keccak: ^3.0.2
checksum: decafb4b37adcfa6d06b6a5d28546d0d7a9f01ccf4b8cc8963cf8188fcc79a230d7e22988e860813623c602d764259734423e38fd7b9aadfeb409d6928a1d4cf
languageName: node
linkType: hard
"keccak@npm:^3.0.0": "keccak@npm:^3.0.0":
version: 3.0.1 version: 3.0.1
resolution: "keccak@npm:3.0.1" resolution: "keccak@npm:3.0.1"
@ -7456,6 +7494,19 @@ fsevents@~2.1.1:
languageName: node languageName: node
linkType: hard linkType: hard
"merkletreejs@npm:^0.2.32":
version: 0.2.32
resolution: "merkletreejs@npm:0.2.32"
dependencies:
bignumber.js: ^9.0.1
buffer-reverse: ^1.0.1
crypto-js: ^3.1.9-1
treeify: ^1.1.0
web3-utils: ^1.3.4
checksum: 041b235adde94de584fdf5ef60138baca8d6f16bb48b3b7f714b607eaa76e4207ed5fef501ee5967371c56c5876804c4ff6da4705707f8cc0362d5c1e0358425
languageName: node
linkType: hard
"micromatch@npm:^4.0.2, micromatch@npm:^4.0.4": "micromatch@npm:^4.0.2, micromatch@npm:^4.0.4":
version: 4.0.4 version: 4.0.4
resolution: "micromatch@npm:4.0.4" resolution: "micromatch@npm:4.0.4"
@ -8407,9 +8458,12 @@ fsevents@~2.1.1:
fs-extra: ^10.1.0 fs-extra: ^10.1.0
hardhat: ^2.12.2 hardhat: ^2.12.2
hardhat-gas-reporter: ^1.0.9 hardhat-gas-reporter: ^1.0.9
hardhat-tracer: ^1.2.0
husky: ^8.0.1 husky: ^8.0.1
keccak256: ^1.0.6
lint-staged: ^13.0.3 lint-staged: ^13.0.3
lodash: ^4.17.21 lodash: ^4.17.21
merkletreejs: ^0.2.32
mocha: ^10.1.0 mocha: ^10.1.0
pinst: ^3.0.0 pinst: ^3.0.0
prettier: ^2.7.1 prettier: ^2.7.1
@ -10295,6 +10349,13 @@ resolve@1.17.0:
languageName: node languageName: node
linkType: hard linkType: hard
"treeify@npm:^1.1.0":
version: 1.1.0
resolution: "treeify@npm:1.1.0"
checksum: aa00dded220c1dd052573bd6fc2c52862f09870851a284f0d3650d72bf913ba9b4f6b824f4f1ab81899bae29375f4266b07fe47cbf82343a1efa13cc09ce87af
languageName: node
linkType: hard
"trim-newlines@npm:^3.0.0": "trim-newlines@npm:^3.0.0":
version: 3.0.0 version: 3.0.0
resolution: "trim-newlines@npm:3.0.0" resolution: "trim-newlines@npm:3.0.0"
@ -10805,7 +10866,7 @@ resolve@1.17.0:
languageName: node languageName: node
linkType: hard linkType: hard
"web3-utils@npm:^1.3.6": "web3-utils@npm:^1.3.4, web3-utils@npm:^1.3.6":
version: 1.8.1 version: 1.8.1
resolution: "web3-utils@npm:1.8.1" resolution: "web3-utils@npm:1.8.1"
dependencies: dependencies: